;+ ; NAME: ; make_probe_state_cdf.pro ; ; PURPOSE: ; To create probe state CDF file from 1 day probe state ASCII file. ; ; CALLING SEQUENCE: ; make_probe_state_cdf, Filename ; ; INPUTS: ; Filename: Name of the ASCII file with the probe state data. ; Version: Either 0 or 2 to indicate whether the file is version V00 or V02 ; (V00=predictive, V02=definitive) ; ; OUTPUTS: ; None, but it creates CDF file in the directory that IDL is being run. ; ; PROCEDURE: ; Read in data from ASCII file; create CDF file using mastercdf/skeletoncdf ; ; EXAMPLE: ; make_probe_state_cdf, 'THEMIS_A.2007_023.EPHPRE60_SSL' ; ; MODIFICATION HISTORY: ; Written by: Matt Davis ; October 12, 2006 Initial version ; 7-mar-2007, jmm, Fixed bug with mismatched columns, so that ; att_eci does not include spin rate ,, also att_eci ; normalization is no longer needed, so that was commented out. ; 8-mar-2007, jmm, creates a file for each day with data ; ;NOTE: Run these two lines at IDL prompt to compile libraries ; @compile_cdaweb ; @compile_IDLmakecdf ;- pro make_probe_state_cdf,filename,version=version if not keyword_set(filename) then begin print, 'You need to select a 1 day ASCII state file! Try Again.' print, " Example: make_probe_state_cdf, 'THEMIS_A.2007_023.EPHPRE60_SSL'" return endif ;read the ascii data into IDL structures ;--------------------------------------------------------------------------------------------- ;get stored ascii template (also see make_ascii_template.pro) get_state_ascii_template,template ;now read the file with the template dat=read_ascii(filename,template=template) ;make some clearer arrays num_rec=n_elements(dat.field01) date = dat.field01 ;"Date (UTC)", the column in the state_ascii file time = dat.field02 ;"Time (UTC)" ;convert date and time to unix time (seconds since 1970) time_sec=dblarr(num_rec) year=strmid(date,0,4) doy=strmid(date,5,3) doy_to_month_date,year,doy,mm,dd mm=string(mm,format="(i2.2)") dd=string(dd,format="(i2.2)") for i=0.,num_rec-1. do begin ;if mm(i) le 9 then mm(i)=string('0',mm(i)) ;if dd(i) le 9 then dd(i)=string('0',dd(i)) datetimestr=strcompress(string(year(i),'-',mm(i),'-',dd(i),'/',time(i)),/remove_all) time_sec(i)=time_double(datetimestr) endfor pos_eci=fltarr(num_rec,3) pos_eci(*, 0) = dat.field03 ;"ECI TOD X [km]" pos_eci(*, 1) = dat.field04 ;"ECI TOD Y [km]" pos_eci(*, 2) = dat.field05 ;"ECI TOD Z [km]" vel_eci=fltarr(num_rec,3) vel_eci(*, 0) = dat.field06 ;"ECI TOD VX [km/s]" vel_eci(*, 1) = dat.field07 ;"ECI TOD VY [km/s]" vel_eci(*, 2) = dat.field08 ;"ECI TOD VZ [km/s]" ;jmm, 7-mar-2007, i don;t see a column for this in the ASCII file ;anom_orb=dat.field09 att_eci=fltarr(num_rec,3) att_eci(*, 0) = dat.field09 ;"ECI TOD AX [---]" att_eci(*, 1) = dat.field10 ;"ECI TOD AY [---]" att_eci(*, 2) = dat.field11 ;"ECI TOD AZ [---]" cdf_epoch,Epoch1970,1970,01,01,/COMPUTE_EPOCH ; Epoch of start of 1970 ;----------------------------------------------------------------- ;normalize attitude vector, Not needed, jmm, 7-mar-2007 ;att_eci(*,0)=att_eci(*,0)/sqrt(att_eci(*,0)^2.+att_eci(*,1)^2.+att_eci(*,2)^2.) ;att_eci(*,1)=att_eci(*,1)/sqrt(att_eci(*,0)^2.+att_eci(*,1)^2.+att_eci(*,2)^2.) ;att_eci(*,2)=att_eci(*,2)/sqrt(att_eci(*,0)^2.+att_eci(*,1)^2.+att_eci(*,2)^2.) ;calculate right ascension and declination from attitude vector index1=where(att_eci(*,0) ne 0.0) index2=where(att_eci(*,0) eq 0.0 and att_eci(*,1) gt 0.0) index3=where(att_eci(*,0) eq 0.0 and att_eci(*,1) lt 0.0) spin_ras=dblarr(num_rec) if index1(0) ne -1 then spin_ras(index1)=atan(att_eci(index1,1),att_eci(index1,0))/!dtor if index2(0) ne -1 then spin_ras(index3)=90. if index3(0) ne -1 then spin_ras(index4)=270. index4=where(spin_ras lt 0.0) if index4(0) ne -1 then spin_ras(index4)=spin_ras(index4)+360. index5=where(att_eci(*,2) gt 1.0) index6=where(att_eci(*,2) lt -1.0) if index5(0) ne -1 then att_eci(index5,2)=1. if index6(0) ne -1 then att_eci(index6,2)=-1. spin_dec=asin(att_eci(*,2))/!dtor ;for w=0,num_rec-1 do begin ;print, time_string(time_sec(w)),att_eci(w,0),att_eci(w,1),att_eci(w,2),spin_ras(w),spin_dec(w) ;endfor ;----------------------------------------------------------------- spin_rate = dat.field12 ;"Spin Rate [rpm]" ;Calculate spin period, jmm, 7-mar-2007 spin_per = spin_rate & spin_per[*] = 0 ok_rate = where(spin_rate Gt 0) If(ok_rate[0] Ne -1) Then spin_per = 60.0d0/spin_rate[ok_rate] total_mass = dat.field13 ;"Total Mass [kg]" fuel_mass = dat.field14 ;"Fuel Mass [kg]" ;A column not included in the original total_delta_v = dat.field15 ;"Total Delta V [m/s]" roi_flag = dat.field16 ;SE Region Status [---]" ;set region of interest flag to values (for now) **commented out on 2007-04-11** ;roi_flag(*)=1. ;roi_flag(0:n_elements(roi_flag)/2.)=0. man_flag = dat.field17 ;"Maneuver Status [---]" ;A column not included in the original orbit_rev = dat.field18 ;"Orbit [rev]" ;put data into CDF using a master CDF ;--------------------------------------------------------------------------------------------- stripped_file = strippath(filename) probe_letter=strtrim(strlowcase(strmid(stripped_file.file_name,7,1)),2) master_cdf='/disks/data/themis/th'+probe_letter+'/l1/state/0000'+$ '/th'+probe_letter+'_l1_state_00000000_v00.cdf' ;There are two days worth of data in the file, ssu = uniq(date) yydoy = date[ssu] year=strmid(yydoy,0,4) doy=strmid(yydoy,5,3) doy_to_month_date,year,doy,mm,dd mm=string(mm,format="(i2.2)") ;if mm le 9 then mm=string('0',mm) dd=string(dd,format="(i2.2)") ;if dd le 9 then dd=string('0',dd) datestring = year+mm+dd if version eq 0 then begin out_cdf=strcompress('th'+probe_letter+'_l1_state_'+string(datestring)+'_v00.cdf',/remove_all) endif else begin out_cdf=strcompress('th'+probe_letter+'_l1_state_'+string(datestring)+'_v02.cdf',/remove_all) endelse ndays = n_elements(yydoy) For j = 0, ndays-1 Do Begin sss = where(date Eq yydoy[j], nsss) If(nsss Gt 1) Then Begin ;if there is only one, don't print the file buf1 = read_master_cdf(master_cdf, out_cdf[j]) ;assign the data arrays to the data pointers a1 = '*buf1.th'+probe_letter+'_state_time.data=time_sec[sss]' a2 = '*buf1.th'+probe_letter+'_pos.data=transpose(pos_eci[sss,*])' a3 = '*buf1.th'+probe_letter+'_vel.data=transpose(vel_eci[sss,*])' a4 = '*buf1.th'+probe_letter+'_spinras.data=spin_ras[sss]' a5 = '*buf1.th'+probe_letter+'_spindec.data=spin_dec[sss]' a6 = '*buf1.th'+probe_letter+'_man.data=man_flag[sss]' a7 = '*buf1.th'+probe_letter+'_roi.data=roi_flag[sss]' a10 = '*buf1.th'+probe_letter+'_spinper.data=spin_per[sss]' filler_array = roi_flag[sss] filler_array(*) = 0 a8 = '*buf1.th'+probe_letter+'_spinalpha.data=filler_array' a9 = '*buf1.th'+probe_letter+'_spinbeta.data=filler_array' a11 = '*buf1.th'+probe_letter+'_spinphase.data=filler_array' ;Moved this into the loop, jmm, 23-mar-2007 file_erange = make_array(2, /double) file_erange(0) = 1000.d*min(time_sec[sss])+Epoch1970 file_erange(1) = 1000.d*max(time_sec[sss])+Epoch1970 a12 = '*buf1.range_epoch.data=file_erange' b1 = execute(a1) b2 = execute(a2) b3 = execute(a3) b4 = execute(a4) b5 = execute(a5) b6 = execute(a6) b7 = execute(a7) b8 = execute(a8) b9 = execute(a9) b10 = execute(a10) b11 = execute(a11) b12 = execute(a12) ;write the cdf result = write_data_to_cdf(out_cdf[j], buf1) ;insert generation date cdf_id = cdf_open(out_cdf[j]) gendate = strmid(time_string(systime(/seconds)-28800.), 0, 10) cdf_attput, cdf_id, 'Generation_date', 0, gendate cdf_attput, cdf_id, 'Data_version',0,strtrim(string(version),2) cdf_close, cdf_id print, 'Probe state CDF written: ', out_cdf[j] Endif Endfor end