;+ ; This is a new routine that needs further testing, development, and enhancements. ; PROCEDURE: cdf2tplot, cdfi ; Purpose: Creates TPLOT variables from a CDF structure (obtained from "CDF_LOAD_VAR") ; This routine will only work well if the underlying CDF file follows the SPDF standard. ; ; Written by Davin Larson ; ; $LastChangedBy: davin-win $ ; $LastChangedDate: 2007-02-07 04:31:07 -0800 (Wed, 07 Feb 2007) $ ; $LastChangedRevision: 313 $ ; $URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/ssl_general/trunk/CDF/cdf_info_to_tplot.pro $ ;- pro cdf_info_to_tplot,cdfi,varnames,prefix=prefix,all=all,verbose=verbose,get_support_data=get_support_data if size(prefix,/type) ne 7 then prefix='' vbs = keyword_set(verbose) ? verbose : 0 if size(cdfi,/type) ne 8 then begin if vbs ge 1 then print,ptrace(),'Must provide a CDF structure' return endif if keyword_set(all) or n_elements(varnames) eq 0 or 1 then varnames=cdfi.vars.name nv =n_elements(varnames) for i=0,nv-1 do begin v=cdfi.vars[i] if vbs ge 5 then print,ptrace(),v.name attr = *v.attrptr var_type = struct_value(attr,'var_type',def= keyword_set(all) ? 'data':'') depend_time = struct_value(attr,'depend_time',def='time') depend_0 = struct_value(attr,'depend_0',def='Epoch') depend_1 = struct_value(attr,'depend_1',def='') depend_2 = struct_value(attr,'depend_2',def='') depend_3 = struct_value(attr,'depend_3',def='') depend_4 = struct_value(attr,'depend_4',def='') display_type = struct_value(attr,'display_type',def='time_series') scaletyp = struct_value(attr,'scaletyp',def='linear') fillval = struct_value(attr,'fillval',def=!values.f_nan) fieldnam = struct_value(attr,'fieldnam',def=v.name) if strcmp( v.name , 'Epoch',5, /fold_case) and (v.datatype ne 'CDF_S1970') then begin *(v.dataptr) =time_double(/epoch, *(v.dataptr) ) ; convert to UNIX_time cdfi.vars[i].datatype = 'CDF_S1970' continue endif if finite(fillval) and keyword_set(v.dataptr) and (v.type eq 4 or v.type eq 5) then begin w = where(*v.dataptr eq fillval,nw) if nw gt 0 then (*v.dataptr)[w] = !values.f_nan endif plottable_data = strcmp( var_type , 'data',/fold_case) if keyword_set(get_support_data) then plottable_data or= strcmp( var_type, 'support',7,/fold_case) if plottable_data eq 0 then begin if vbs ge 5 then print,ptrace(),'Skipping variable: "'+v.name+'" ('+var_type+')' continue endif j = (where(strcmp(varnames , depend_time,/fold_case),nj))[0] if nj gt 0 then tvar = cdfi.vars[j] else begin j = (where(strcmp(varnames ,depend_0,/fold_case),nj))[0] if nj gt 0 then tvar = cdfi.vars[j] endelse if nj eq 0 then begin if vbs ge 5 then print,ptrace(),'Skipping variable: "'+v.name+'" ('+var_type+')' continue endif j = (where(strcmp(varnames , depend_1,/fold_case),nj))[0] if nj gt 0 then var_1 = cdfi.vars[j] j = (where(strcmp(varnames , depend_2,/fold_case),nj))[0] if nj gt 0 then var_2 = cdfi.vars[j] j = (where(strcmp(varnames , depend_3,/fold_case),nj))[0] if nj gt 0 then var_3 = cdfi.vars[j] j = (where(strcmp(varnames , depend_4,/fold_case),nj))[0] if nj gt 0 then var_4 = cdfi.vars[j] spec = strcmp(display_type,'spectrogram',/fold_case) log = strcmp(scaletyp,'log',3,/fold_case) if keyword_set(tvar.dataptr) then begin cdfstuff={filename:cdfi.filename,gatt:cdfi.g_attributes,vname:v.name,vatt:attr} ;stop if keyword_set(var_2) then data = {x:tvar.dataptr,y:v.dataptr,v1:var_1.dataptr, v2:var_2.dataptr} $ else if keyword_set(var_1) then data = {x:tvar.dataptr,y:v.dataptr, v:var_1.dataptr} $ else data = {x:tvar.dataptr,y:v.dataptr} dlimit = {cdf:cdfstuff,spec:spec,log:log} store_data,prefix+v.name,data=data,dlimit=dlimit endif var_1=0 var_2=0 var_3=0 var_4=0 endfor end