;+ ;Procedure: thm_cotrans ;Purpose: Transform between various THEMIS and geophysical coordinate systems ;keywords: ; probe = Probe name. The default is 'all', i.e., transform data for all ; available probes. ; This can be an array of strings, e.g., ['a', 'b'] or a ; single string delimited by spaces, e.g., 'a b' ; datatype = The type of data to be transformed, can take any of the values ; allowed for datatype for the various thm_load routines. You ; can use wildcards like ? and [lh]. ; 'all' is not accepted. You can use '*', but you may get unexpected ; results if you are using suffixes. ; in_coord = 'spg', 'ssl', 'dsl', 'gse', 'gsm', or 'gei' ; coordinate system of input. ; This keyword is optional if the coord_sys attribute ; is present for the tplot variable, and if present, it must match ; the value of that attribute. See cotrans_set_coord, cotrans_get_coord ; out_coord = 'spg', 'ssl', 'dsl', 'gse', 'gsm', or 'gei' ; coordinate system of output. ; in_suffix = optional suffix needed to generate the input data quantity name: ; 'th'+probe+'_'datatype+in_suffix ; out_suffix = optional suffix to add to output data quantity name. If ; in_suffix is present, then in_suffix will be replaced by out_suffix ; in the output data quantity name. ; valid_names:return valid coordinate system names in named varibles supplied to ; in_coord and/or out_coord keywords. ;Optional Input Parameters: ; in_name Name(s) of input tplot varabiable(s) (or glob patern) (space-separated; string list or array of strings.) ; out_name Name(s) of output tplot variable(s). glob patterns not accepted. ; Number of output names must match number of input names (after glob ; expansion of input names). (single string, or array of strings.) ; ;Example: ; thm_cotrans, probe='a', datatype='fgl', out_coord='gsm', out_suffix='_gsm' ; ; $LastChangedBy: kramer $ ; $LastChangedDate: 2007-07-18 13:03:55 -0700 (Wed, 18 Jul 2007) $ ; $LastChangedRevision: 1152 $ ; $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/tags/tdas_2_02/idl/themis/state/thm_cotrans.pro $ ;- ; in_coord is optional if dlimits includs a thm_att.coord element. pro thm_cotrans, probe=probe, datatype=datatype, valid_names=valid_names, $ in_coord=in_coord, out_coord=out_coord, verbose=verbose, $ in_suffix=in_suf, out_suffix=out_suf, in_name, out_name thm_init ; If verbose keyword is defined, override !themis.verbose vb = size(verbose, /type) ne 0 ? verbose : !themis.verbose vprobes = ['a','b','c','d','e'] vcoord = ['spg', 'ssl', 'dsl', 'gse', 'gsm', 'gei'] if keyword_set(valid_names) then begin in_coord = vcoord out_coord = vcoord probe=vprobes if keyword_set(vb) then begin message, /info, string(strjoin(vcoord, ','), $ format = '( "Valid coords:",X,A,".")') message, /info, string(strjoin(vprobes, ','), $ format = '( "Valid probes:",X,A,".")') message, /info, 'Valid datatypes: Anything goes!' endif return endif ; validate in_coord and out_coord if not keyword_set(out_coord) then begin print, 'thm_cotrans: must specify out_coord' return endif else out_coord = thm_check_valid_name(strlowcase(out_coord), vcoord) if not keyword_set(out_coord) then return if n_elements(out_coord) gt 1 then begin print, 'thm_cotrans: can only specify one out_coord' return endif if keyword_set(in_coord) then begin in_coord = thm_check_valid_name(strlowcase(in_coord), vcoord) if not keyword_set(in_coord) then return if n_elements(in_coord) gt 1 then begin print, 'thm_cotrans: can only specify one in_coord' return endif endif if not keyword_set(in_suf) then in_suf = '' if not keyword_set(out_suf) then out_suf = '' ; do 'standard' THEMIS name conventions to get tplot names if n_params() eq 0 then begin if not keyword_set(probe) then probe = vprobes $ else probe = thm_check_valid_name(strlowcase(probe), vprobes, /include_all) if not keyword_set(probe) then begin message, /info, 'probe keyword required if no positional args present' return endif if not keyword_set(datatype) then begin message, /info, 'datatype keyword required if no positional args present' return endif if n_elements(datatype) eq 1 then datatype=strsplit(datatype, ' ', /extract) datatype=strlowcase(datatype) for i = 0, n_elements(probe)-1 do begin for j = 0, n_elements(datatype)-1 do begin in_name='th'+probe[i]+'_'+datatype[j] out_name='th'+probe[i]+'_'+datatype[j] thm_cotrans, in_name, $ in_coord=in_coord, out_coord=out_coord, $ in_suf=in_suf, out_suf=out_suf, verbose=verbose endfor endfor return endif else if n_params() gt 2 then begin print, 'usage: thm_cotrans, probe=probe, datatype=datatype, $' print, ' in_coord=in_c, out_coord=out_c, $' print, ' in_suffix=in_suf, out_suffix=out_suff' print, 'or: thm_cotrans, in_name[, out_name], in_coord=in_c, out_coord=out_c' return endif ; allow for globbing on the input parameters , deal with in_suf and out_suf, ; figure out probe, if necessary. in_names = tnames(in_name+in_suf, n) if n eq 0 then begin print, 'thm_cotrans: no match: '+in_name+in_suf return endif if n_params() eq 1 || $ n_params() eq 2 && n_elements(in_names) ne n_elements(out_name) then begin if n_params() eq 2 then print, 'thm_cotrans: warning: ignoring out_names' ;; generate output names based on out_suffix if in_suf ne '' then $ base_len = strpos(in_names,in_suf,/reverse_search) $ else $ base_len = strlen(in_names) out_names = strmid(in_names,0,transpose(base_len))+out_suf endif else out_names = out_name + out_suf if n_elements(in_names) ne n_elements(out_names) then begin message, 'thm_cotrans: number of input variables does not match number of output variables' endif if not keyword_set(probe) then begin if n_elements(where(strmatch(in_names,'th?_*'))) ne n_elements(in_names) $ then begin printdat, in_names printdat, strmatch(in_names,'th?_') print, 'thm_cotrans: not a standard THEMIS tplot name, must use probe keyword' return endif else probe = strmid(in_names, 2,1) endif for i = 0, n_elements(in_names)-1 do begin in_nam = in_names[i] out_nam = out_names[i] prb = probe[i < (n_elements(probe)-1)] get_data,in_nam,data=in,dl=in_dl sizein=size(in.y) if sizein[0] ne 2 then begin if sizein(2) ne 3 then begin message,/info,'input tplot variable is not a 3-vector' return endif endif data_in_coord = cotrans_get_coord(in_dl) if keyword_set(in_coord) then begin in_c = in_coord if ~strmatch(data_in_coord, 'unknown') then begin if not strmatch(data_in_coord, in_coord) then begin message, "coord. system of input "+in_nam+": "+data_in_coord+ $ " differs from in_coord="+in_coord endif endif endif else in_c = data_in_coord print, 'thm_cotrans: coord. system of input '+in_nam+': '+in_c spinras = 'th'+prb+'_state_spinras' spindec = 'th'+prb+'_state_spindec' spinper = 'th'+prb+'_state_spinper' spinphase = 'th'+prb+'_state_spinphase' case in_c of 'ssl': case out_coord of 'ssl': if in_nam ne out_nam then copy_data, in_nam, out_nam 'dsl': ssl2dsl, in_nam, spinper, spinphase, out_nam 'gse': begin ssl2dsl, in_nam, spinper, spinphase, out_nam dsl2gse, out_nam, spinras, spindec, out_nam end 'gsm': begin ssl2dsl, in_nam, spinper, spinphase, out_nam dsl2gse, out_nam, spinras, spindec, out_nam cotrans, out_nam, out_nam, /gse2gsm end 'gei': begin ssl2dsl, in_nam, spinper, spinphase, out_nam dsl2gse, out_nam, spinras, spindec, out_nam cotrans, out_nam, out_nam, /gse2gei end 'spg':spg2ssl,out_nam,out_nam,/ssl2spg endcase 'dsl': case out_coord of 'ssl': ssl2dsl, in_nam, spinper, spinphase, out_nam, /dsl2ssl 'dsl': if in_nam ne out_nam then copy_data, in_nam, out_nam 'gse': dsl2gse, in_nam, spinras, spindec, out_nam 'gsm': begin dsl2gse, in_nam, spinras, spindec, out_nam cotrans, out_nam, out_nam, /gse2gsm end 'gei': begin dsl2gse, in_nam, spinras, spindec, out_nam cotrans, out_nam, out_nam, /gse2gei end 'spg':begin ssl2dsl,in_nam,spinper,spinphase,out_nam,/dsl2ssl spg2ssl,out_nam,out_nam,/ssl2spg end endcase 'gse': case out_coord of 'ssl': begin dsl2gse, in_nam, spinras, spindec, out_nam, /gse2dsl ssl2dsl, out_nam, spinper, spinphase, out_nam, /dsl2ssl end 'dsl': dsl2gse, in_nam, spinras, spindec, out_nam, /gse2dsl 'gse': if in_nam ne out_nam then copy_data, in_nam, out_nam 'gsm': cotrans, in_nam, out_nam, /gse2gsm 'gei': cotrans, in_nam, out_nam, /gse2gei 'spg': begin dsl2gse,in_name,spinras,spindec,out_nam,/gse2dsl ssl2dsl,out_nam,spinper,spinphase,out_nam,/dsl2ssl spg2ssl,out_nam,out_nam,/ssl2spg end endcase 'gsm': case out_coord of 'ssl': begin cotrans, in_nam, out_nam, /gsm2gse dsl2gse, out_nam, spinras, spindec, out_nam, /gse2dsl ssl2dsl, out_nam, spinper, spinphase, out_nam, /dsl2ssl end 'dsl': begin cotrans, in_nam, out_nam, /gsm2gse dsl2gse, out_nam, spinras, spindec, out_nam, /gse2dsl end 'gse': cotrans, in_nam, out_nam, /gsm2gse 'gsm': if in_nam ne out_nam then copy_data, in_nam, out_nam 'gei': begin cotrans, in_nam, out_nam, /gsm2gse cotrans, out_nam, out_nam, /gse2gei end 'spg': begin cotrans, in_nam, out_nam, /gsm2gse dsl2gse, out_nam, spinras, spindec, out_nam, /gse2dsl ssl2dsl, out_nam, spinper, spinphase, out_nam, /dsl2ssl spg2ssl,out_nam,out_nam,/ssl2spg end endcase 'gei': case out_coord of 'ssl': begin cotrans, in_nam, out_nam, /gei2gse dsl2gse, out_nam, spinras, spindec, out_nam, /gse2dsl ssl2dsl, out_nam, spinper, spinphase, out_nam, /dsl2ssl end 'dsl': begin cotrans, in_nam, out_nam, /gei2gse dsl2gse, out_nam, spinras, spindec, out_nam, /gse2dsl end 'gse': cotrans, in_nam, out_nam, /gei2gse 'gsm': begin cotrans, in_nam, out_nam, /gei2gse cotrans, out_nam, out_nam, /gse2gsm end 'gei': if in_nam ne out_nam then copy_data, in_nam, out_nam 'spg': begin cotrans, in_nam, out_nam, /gei2gse dsl2gse, out_nam, spinras, spindec, out_nam, /gse2dsl ssl2dsl, out_nam, spinper, spinphase, out_nam, /dsl2ssl spg2ssl,out_nam,out_nam,/ssl2spg end endcase 'spg': case out_coord of 'ssl': spg2ssl,in_nam,out_nam 'dsl': begin spg2ssl,in_nam,out_nam ssl2dsl,out_nam,spinper,spinphase,out_nam end 'gse': begin spg2ssl,in_nam,out_nam ssl2dsl, out_nam, spinper, spinphase, out_nam dsl2gse, out_nam, spinras, spindec, out_nam end 'gsm': begin spg2ssl,in_nam,out_nam ssl2dsl, out_nam, spinper, spinphase, out_nam dsl2gse, out_nam, spinras, spindec, out_nam cotrans, out_nam, out_nam, /gse2gsm end 'gei': begin spg2ssl,in_nam,out_nam ssl2dsl,out_nam,spinper,spinphase,out_nam dsl2gse, out_nam, spinras, spindec, out_nam cotrans, out_nam, out_nam, /gse2gei end 'spg': if in_nam ne out_nam then copy_data, in_nam, out_nam endcase else: begin message, /info,"thm_cotrans: don't know how to transform "+in_c+" to " $ + out_coord end endcase if in_c ne out_coord then $ print, 'thm_cotrans: '+out_coord+' output placed in '+out_nam endfor end