pro record_metadata_all, output_fullpath, site_list_fullpath, mastercdf_basedir ;; ; The format should be the following: ; site.variablename/global.attribute.index| ;; output_file=output_fullpath infile=site_list_fullpath site_array=READ_CSV(infile) OPENW,1,output_file foreach site,site_array.FIELD1 do begin if mastercdf_basedir.LastIndexOf('/') eq STRLEN(mastercdf_basedir) then begin cdf_file=mastercdf_basedir+'thg_l2_mag_' + site + '_00000000_v01.cdf' endif else begin cdf_file=mastercdf_basedir+'/thg_l2_mag_' + site + '_00000000_v01.cdf' endelse id_cdf=CDF_OPEN(cdf_file) cdf=CDF_READCDF(id_cdf, /STRING, /ENCODING) foreach attr,cdf['GlobalAttrs'].keys() do begin attr_hash=cdf['GlobalAttrs',attr] foreach i,attr_hash.keys() do begin println=site+'.'+'global'+'.'+attr+'.'+STRTRIM(STRING(i),2)+'|'+STRTRIM(STRING(attr_hash[i]),2) if attr eq "LINK_TEXT" then begin println=println+" " endif PRINTF,1,println endforeach endforeach foreach var,cdf['Variables'].keys() do begin foreach attr,cdf['Variables',var,"VarAttrs"].keys() do begin attr_val=cdf['Variables',var,"VarAttrs",attr] if N_ELEMENTS(attr_val) gt 1 then begin arraystr='[' foreach arrayelement,attr_val do begin arraystr=arraystr+STRTRIM(STRING(arrayelement),2)+',' endforeach ; remove the last comma arraystr=STRMID(arraystr,0,STRLEN(arraystr)-1) arraystr=arraystr+']' println=site+'.'+var+'.'+attr+'|'+arraystr endif else begin println=site+'.'+var+'.'+attr+'|'+STRTRIM(STRING(attr_val),1) endelse PRINTF,1,println endforeach endforeach CDF_CLOSE, id_cdf endforeach CLOSE,1 end