;+ ;Procedure: THM_LOAD_XXX ; ;Purpose: Generic THEMIS Data File Loading routine, meant to be called by ; type specific thm_load procedures. ; ;keywords: ; post_process_proc: name of procedure to call after cdf2tplot is called ; will be called w/ keywords sname, dt (datatype), lvl, ; and _extra. ; relpath_funct: name of routine to call in place of file_dailynames ; may simply be a wrapper. ; will be called w/ keywords sname, dt (datatype), lvl, ; and _extra. ; cdf_to_tplot: user-supplied procedure to override cdf2tplot ; sname = site or probe name. The default is 'all', ; type_sname = string, set to 'probe' or 'site' ; vsnames = space-separated list of valid probes/sites ; datatype = The type of data to be loaded, for this case, there is only ; one option, the default value of 'fgm', so this is a ; placeholder should there be more that one data type. 'all' ; can be passed in also, to get all variables. ; vdatatypes = space-separated list of valid data types ; TRANGE= (Optional) Time range of interest (2 element array), if ; this is not set, the default is to prompt the user. Note ; that if the input time range is not a full day, a full ; day's data is loaded ; level = the level of the data, the default is 'l1', or level-1 ; data. A string (e.g., 'l2') or an integer can be used. 'all' ; can be passed in also, to get all levels. ; vlevels ; CDF_DATA: named variable in which to return cdf data structure: only works ; for a single spacecraft and datafile name. ; VARNAMES: names of variables to load from cdf: default is all. ; /GET_SUPPORT_DATA: load support_data variables as well as data variables ; into tplot variables. ; /DOWNLOADONLY: download file but don't read it. ; /valid_names, if set, then this routine will return the valid probe, datatype ; and/or level options in named variables supplied as ; arguments to the corresponding keywords. ; files named varible for output of pathnames of local files. ; /VERBOSE set to output some useful info ; ;Notes: ; This routine is (should be) platform independent. ; ; $LastChangedBy: kenb-mac $ ; $LastChangedDate: 2007-02-08 09:48:04 -0800 (Thu, 08 Feb 2007) $ ; $LastChangedRevision: 328 $ ; $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/trunk/idl/themis/common/thm_load_xxx.pro $ ;- pro thm_load_xxx,sname=sname, datatype=datatype, trange=trange, $ level=level, verbose=verbose, downloadonly=downloadonly, $ cdf_data=cdf_data,get_cdf_data=get_cdf_data, $ get_support_data=get_support_data, $ varnames=varnames, valid_names = valid_names, files=files, $ type_sname=type_sname, $ vsnames=vsnames, vdatatypes=vdatatypes, vlevels=vlevels, $ deflevel=deflevel, version=version, $ relpath_funct=relpath_funct, $ cdf_to_tplot=cdf_to_tplot, $ post_process_proc=post_process_proc, $ addmaster=addmaster, $ _ref_extra = _extra thm_init ; If verbose keyword is defined, override !themis.verbose vb = size(verbose, /type) ne 0 ? verbose : !themis.verbose ; Valid sname names vsnames = strsplit(vsnames, ' ', /extract) ; Valid data names vdatatypes = strsplit(vdatatypes, ' ', /extract) ;for completeness ;valid data levels vlevels = strsplit(vlevels, ' ', /extract) ;If valid_names is set, return the options if keyword_set(valid_names) then begin sname = vsnames message, /info, string(strjoin(sname, ','), format = '( "Valid '+type_sname+'s:",X,A,".")') datatype = vdatatypes message, /info, string(strjoin(datatype, ','), format = '( "Valid datatypes:",X,A,".")') level = vlevels message, /info, string(strjoin(level, ','), format = '( "Valid levels:",X,A,".")') return endif ;parse out snames if not keyword_set(sname) then snames = vsnames $ else snames = thm_check_valid_name(strlowcase(sname), vsnames, /include_all) if not keyword_set(snames) then return if keyword_set(vb) then printdat, snames, /value, type_sname+'s' ;datatype if not keyword_set(datatype) then dts = vdatatypes $ else dts = thm_check_valid_name(strlowcase(datatype), vdatatypes, /include_all) if not keyword_set(dts) then return if keyword_set(vb) then printdat, dts, /value, 'Datatypes' ;data level if n_elements(level) gt 0 then begin if is_string(level) then lvl = strlowcase(level) $ else if is_number(level) then lvl = 'l'+strcompress(string(fix(level)), /remove_all) $ else lvl = deflevel endif else lvl = deflevel lvls = thm_check_valid_name(strlowcase(lvl), vlevels, /include_all) if not keyword_set(lvls) then return if keyword_set(vb) then printdat, lvls, /value, 'Level' if vb ge 7 then printdat,!themis nlvls = n_elements(lvls) ndts = n_elements(dts) nsnames = n_elements(snames) if get_cdf_data && nlvls*ndts*nsnames gt 1 then begin print, 'can only get cdf_data for a single datatype' return endif my_themis = !themis my_themis.no_download = 1 my_themis.verbose=vb ;get file names, loop over all snames, levels and datatypes files_ptrarr = ptrarr(nsnames,ndts,nlvls) for k = 0, nlvls-1 do $ for j = 0, ndts-1 do $ for i = 0, nsnames-1 do begin snamei = snames[i] dtj = dts[j] lvlk = lvls[k] if keyword_set(relpath_funct) then begin ;; call a datatype specific pathname function, because ;; we don't want to write one-box-fits-all heuristics relpathnames = call_function(relpath_funct, sname=snamei, $ dt=dtj, lvl=lvlk, $ version=version, trange=trange, $ addmaster=addmaster, _extra = _extra) endif else begin ;; use standard heuristics to determine pathname ;; if these don't work, plese consider using your own relpath_funct ;; before adding code which may affect the other instrument load routines if strcmp(strlowcase(type_sname), 'probe') then begin relpath = 'th'+snamei+'/'+lvlk+'/'+ dtj+'/' prefix = 'th'+snamei+'_'+lvlk+'_'+dtj+'_' dir = 'YYYY/' endif else if strcmp(strlowcase(type_sname), 'site') then begin relpath = 'thg/'+lvlk+'/'+dtj+'/'+snamei + '/' prefix = 'thg_'+lvlk+'_'+dtj+'_'+snamei + '_' dir = 'YYYY/' endif ending = '_'+version+'.cdf' relpathnames = file_dailynames(relpath, prefix, ending, dir=dir, $ trange = trange,addmaster=addmaster) endelse ; get the full path name, save it for later for reading the cdf. files_ptrarr[i,j,k] = $ ptr_new(file_retrieve(relpathnames, _extra = my_themis)) ; build an array with all relpathnames, so all files can be downloaded ; with one call to file_retrieve. if i+j+k eq 0 then relpathnames_all = relpathnames else $ relpathnames_all = [relpathnames_all, relpathnames] if vb ge 7 then print, 'files', *files_ptrarr[i,j,k] endfor ;end of loop over all snames, levels and datatypes. ;download files for all snames, levels, and datatypes if not !themis.no_download then begin if vb ge 7 then print, 'relpathnames', relpathnames_all files = file_retrieve(relpathnames_all, _extra=!themis) endif if keyword_set(downloadonly) then begin ptr_free, files_ptrarr return endif if get_cdf_data then begin cdf_data = cdf_load_vars(*files_ptrarr[0,0,0],varnames=varnames, $ verbose=vb,/all) ptr_free, files_ptrarr return endif ; load data into tplot variables loop over all snames, levels and datatypes for k = 0, nlvls-1 do $ for j = 0, ndts-1 do $ for i = 0, nsnames-1 do begin files = *files_ptrarr[i,j,k] if keyword_set(cdf_to_tplot) then begin call_procedure, cdf_to_tplot, file=files, $ all=all,verbose=vb, varnames=varnames, $ get_support_data=get_support_data, _extra=_extra endif else begin if keyword_set(verbose) then print,transpose(['Loading...',files]) cdf2tplot,file=files,all=all,verbose=vb, $ get_support_data=get_support_data, varnames=varnames endelse if keyword_set(post_process_proc) then $ call_procedure, post_process_proc, sname=snames[i], dt=dts[j], $ lvl=lvls[k], verbose=vb, _extra = _extra endfor ;end of loop over all snames, levels and datatypes. ptr_free, files_ptrarr end