; ; read_mfi_cdf_h0.pro ; ; Purpose: an example to convert cdf files to ascii with selected columns ; ; Functions and subroutines: ; Requires CDF (Common Data Format) library v2.5 or above ; The library can be obtained at the National Space ; Science Center, NASA/Goddard Space Flight Center, ; Greenbelt, Maryland ; ; see: http://nssdc.gsfc.nasa.gov/cdf ; ; CDF input : wind/mfi high res. data in cdf format ; ; ASCII outputs : ; ; (1) On screen: brief description of the content of the cdf file. ; ; (2) The ascii file (e.g., ascii_outputfile) contains: ; ; long yr Year (e.g., 1996) ; long mon Month (e.g. 1-January...12-December) ; long day Day of Month (1...28/29/30/31) ; long hr Hour (1 -24) ; long min Minute (0-59) ; float sec second of the minute (0.0-59.9999) ; float BGSE(0) X component of B in GSE coordinate in nT ; float BGSE(1) Y component of B in GSE coordinate in nT ; float BGSE(2) Z component of B in GSE coordinate in nT ; float BGSM(1) Y component of B in GSM coordinate in nT ; float BGSM(2) Z component of B in GSM coordinate in nT ; float BF1 Total magnetic flux in nT ; float BRMSGSM(0) X component of the rms of B in nT ; float BRMSGSM(1) Y component of the rms of B in nT ; float BRMSGSM(2) Z component of the rms of B in nT ; float BRMSF1 Total magnitude of the RMS of B in nT ; long NUM_PTS Number of points in averaging ; float PGSE(0) X component of s/c position in GSE coordinate in Re ; float PGSE(1) Y component of s/c position in GSE coordinate in Re ; float PGSE(2) Z component of s/c position in GSE coordinate in Re ; float PGSM(1) Y component of s/c position in GSM coordinate in Re ; float PGSM(2) Z component of s/c position in GSM coordinate in Re ; ; Format used for ascii output: ; ; format="(I4,4I3,F5.1,10G13.6,I10,5G13.6)" ; ; Note: ; The information of s/c position has only 1-min resolution. ; Each minute of the position data is duplicated 20 times to fill ; the 3-s records. ; ; Created by Sean (Sheng-Hsien) Chen, Hughes STX Corporation, ; Greenbelt, Maryland ; ; October 24, 1997 ; ;******************************************************************** ; ; convert day of year to month and date or vice versa ; ; SHC 10/24/97 ;******************************************************************** pro doy_month,yr,doy,month,day,index ; ; if 1997, yr is 1997 not 97 ; doy start at 1 ; month 1-January...12-December ; day : day of month starting at 1 ; dom=lonarr(13) dom(0)=0 dom(1)=31 dom(2)=59 dom(3)=90 dom(4)=120 dom(5)=151 dom(6)=181 dom(7)=212 dom(8)=243 dom(9)=273 dom(10)=304 dom(11)=334 dom(12)=365 if (((yr mod 4) eq 0) and ((yr mod 100) ne 0)) or $ ((yr mod 400) eq 0) then begin for i=2,12 do begin dom(i)=dom(i)+1 endfor endif if(index gt 0) then begin for i=0,11 do begin if(doy gt dom(i)) and (doy le dom(i+1)) then begin month=i+1 day=doy-dom(i) return endif endfor print,' wrong parameter doy given in doy_month' endif else begin if(month ge 1) and (month le 12) then begin doy=dom(month-1)+day return endif endelse end ;******************************************************************** ; ; pro WriteAscii,CDFname,unit_asc ; ; SHC 10/24/97 ;******************************************************************** pro WriteAscii,CDFname,unit_asc i=0L j=0L yr=0L month=0L day=0L hr=0L sec=0.0 Time=lonarr(3) BGSM=fltarr(3) BGSE=fltarr(3) BF1=0.0 BRMSGSM=fltarr(3) BRMSF1=0.0 NUM_PTS=0L PGSM=fltarr(3) PGSE=fltarr(3) ; ; Open CDF input file ; id=CDF_open(CDFname) ; ; Get CDF metadata ; cdf_doc,id,version,release,cpr cdf_info=cdf_inquire(id) ; ; Print CDF metadata ; print,'CDF name: ',CDFname print,'CDF version',version print,'CDF release',release print,'Data Encoding: ', cdf_info.encoding print,'Variable Majority: ',cdf_info.majority print,'Number of dimensions: ', cdf_info.nDims print,'Number of R variables: ',cdf_info.nvars print,'Number of Z variables: ',cdf_info.nZvars NumRec=28800L ; for 3-s variables print,'Total number of records for 3-s data: ',NumRec ; ; ; Note: to increase the conversion speed, read all the records ; at a time and store in a larger array for each component ; instead of one record at a time if the memory is not a concern. ; ; examples; ; cdf_varget,id,'Time3_PB5',Time,count=3,rec_start=0,rec_count=NumRec ; cdf_varget,id,'B3GSE',BGSE,count=3,rec_start=0,rec_count=NumRec ; where Time or BGSE has a size of [3,NumRec]. ; ; for i=0,NumRec-1 do begin cdf_varget,id,'Time3_PB5',Time,count=3,rec_start=i cdf_varget,id,'B3GSE',BGSE,count=3,rec_start=i cdf_varget,id,'B3GSM',BGSM,count=3,rec_start=i cdf_varget,id,'B3F1',BF1,count=1,rec_start=i cdf_varget,id,'B3RMSGSM',BRMSGSM,count=3,rec_start=i cdf_varget,id,'B3RMSF1',BRMSF1,count=1,rec_start=i cdf_varget,id,'NUM3_PTS',NUM_PTS,count=1,rec_start=i if((i mod 20) eq 0) then begin j=long(i/20) cdf_varget,id,'PGSE',PGSE,count=3,rec_start=j cdf_varget,id,'PGSM',PGSM,count=3,rec_start=j endif yr=Time(0) doy_month,Time(0),Time(1),month,day,1 sec=Time(2)*0.001 hr=long(sec/3600) min=long((sec-hr*3600)/60) sec=sec-hr*3600.0-min*60.0 printf,unit_asc,format="(I4,4I3,F5.1,10G13.6,I8,5G13.6)",$ yr,month,day,hr,min,sec,$ BGSE(0),BGSE(1),BGSE(2),BGSM(1),BGSM(2),BF1,$ BRMSGSM(0),BRMSGSM(1),BRMSGSM(2),BRMSF1,NUM_PTS,$ PGSE(0),PGSE(1),PGSE(2),PGSM(1),PGSM(2) endfor ; ; Close CDF ; CDF_close,id return end ;******************************************************************** ; ; Main ; ; SHC 10/24/97 ;******************************************************************** close,/all CDFname='wi_h0_mfi_yyyymmdd_vnn.cdf' output='test.asc' read,'Input cdf file name? ',CDFname read,'Output file ascii? ',output openw,unit_asc,output,/get_lun WriteAscii,CDFname,unit_asc close,unit_asc free_lun,unit_asc end