;+ ;Procedure: tt89 ; ;Purpose: tplot wrapper for the functional interface to the idl ;geopack implementation of the Tsyganenko 1989 and IGRF fields model. ; ;Keywords: ; pos_gsm_tvar: the tplot variable storing the position in ; gsm coordinates(can use standard globbing) ; kp(optional): the requested value of the kp ; parameter(default: 2) can also be a tplot variable name ; if it is a tplot variable name the kp values stored in the ; variable will be interpolated to match the time grid of the ; position input values ; ; period(optional): the amount of time between recalculations of ; geodipole tilt in seconds(default: 600) increase this ; value to decrease run time ; ; newname(optional):the name of the output variable. ; (default: pos_gsm_tvar+'_bt89') This option is ignored if ; globbing is used. ; ; error(optional): named variable in which to return the ; error state of this procedure call. 1 = success, 0 = failure ; ; igrf_only(optional): Set this keyword to turn off the t89 component of ; the model and return only the igrf component ; ; ; Output: Stores the result of the field model calculations in tplot variables ; ; Notes: 1, converts from normal gsm to rgsm by dividing vectors by earth's ; radius(6374 km) ie inputs should be in km ; 2. Input must be in GSM coordinates ; 3. Haje Korth's IDL/Geopack DLM must be installed for this ; procedure to work ; ; $LastChangedBy: pcruce $ ; $LastChangedDate: 2009-04-22 18:05:37 -0700 (Wed, 22 Apr 2009) $ ; $LastChangedRevision: 5721 $ ; $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/idl_socware/tags/tdas_5_11/external/IDL_GEOPACK/t89/tt89.pro $ ;- pro tt89, pos_gsm_tvar, kp = kp, period = period, newname = newname, error = error,igrf_only=igrf_only error = 0 if not keyword_set(pos_gsm_tvar) then begin message, /continue, 'pos_gsm_tvar must be set' return endif var_names = tnames(pos_gsm_tvar) if(var_names[0] eq '') then begin message, /continue, 'No valid tplot_variables match pos_gsm_tvar' return endif if keyword_set(kp) then begin ;if kp is a string, assume kp is stored in a tplot variable if size(kp,/type) eq 7 then begin if tnames(kp) eq '' then begin message,/continue,'kp is of type string but no tplot variable of that name exists' return endif ;for the sake of simplicity if n_elements(var_names) gt 1 then begin message,/continue,'cannot use globbing AND arrayed kp values' return endif ;make sure there are an appropriate number of kp values in the array tinterpol_mxn,kp,var_names[0],newname='kp_int_temp',error=e if e ne 0 then begin get_data,'kp_int_temp',data=d_kp kp_dat = d_kp.y endif else begin message,/continue,'error interpolating kp onto position data' return endelse endif else kp_dat = kp endif for i = 0, n_elements(var_names)-1L do begin get_data, var_names[i], data = d, dlimits = dl, limits = l ;several nested ifs to check this ;variable's coordinate system in a ;safe way(ie won't reference any struct elements that don't exist) if not keyword_set(dl) then begin message, /continue, 'dlimits structure not set, make sure input variables are in gsm coordinates or results will be invalid' endif else begin str_element, dl, 'data_att', success = s if s eq 0 then begin message, /continue, 'dlimits.data_att structure not set, make sure input variables are in gsm coordinates or results will be invalid' endif else begin str_element, dl.data_att, 'coord_sys', success = s if s eq 0 then begin message, /continue, 'dlimits.data_att.coord_sys value not set, make sure input variables are in gsm coordinates or results will be invalid' endif else if dl.data_att.coord_sys ne 'gsm' then begin message, /continue, 'input variable is in the wrong coordinate system, returning' return ;definitely wrong coordinate system=error endif endelse endelse ;do the calculation, division converts position into earth radii units mag_array = t89(d.x, d.y/6374, kp = kp_dat, period = period,igrf_only=keyword_set(igrf_only)) if size(mag_array, /n_dim) eq 0 && mag_array[0] eq -1L then begin message, /continue, 'Tysganenko model query failed, returning' return endif ;sometimes v element is present, sometimes not ;if it is around it is stored in output so information is not lost str_element, d, 'v', success = s if s eq 1 then $ d_out = {x:d.x, y:mag_array, v:d.v} $ else $ d_out = {x:d.x, y:mag_array} if keyword_set(newname) && n_elements(var_names) eq 1 then $ store_data, newname, data = d_out, dlimits = dl, limits = l $ else $ store_data, var_names[i]+'_bt89', data = d_out, dlimits = dl, limits = l endfor ;signal success error = 1 return end