FUNCTION time_to_int,s ; typical calling secqunce: ; t = time_to_int,'hh:mm:ss' ; this procedure takes a string of 8 chars in hours : minutes : seconds format ; and converts it to a long integer number of seconds hours = LONG(STRMID(s,0,2)) ; get number of hours minutes = LONG(STRMID(s,3,2)) ; and minutes seconds = LONG(STRMID(s,6,2)) ; and seconds time = hours*3600l + minutes*60l + seconds ; make a long int return,time end ; of time_to_int pro p,dir ;pro post_post_cal,dir ; typical calling sequence: ; replay a full days worth of data ; post_post_cal,'/opt1/22Jun95/' ; This program will read all the log files taken on a given date (date defined ; by the directory specified in dir), corrolate cal computer to mission time ; for each log file, and insert cal log file data into the headers of all ; data files collected in the specified file. @c_header.inc ; read in names for each defined header slot !error = 0 ; clear all previous errors start_time = systime(1) ; report total time to execute cd,dir+"/Log",current = olddir ; go to directory of test logs spawn,'ls',tests ; capture file names of all test logs s=size(tests) ntests = s(1) blank = " " close,1 ; make sure lun is available clk_count = 0 time_count = 0 time = fltarr(100,3) ; coefficients to convert cal time to mission time y=fltarr(100) ; y(*) RTGSE times x=fltarr(100) ; x(*) cal computer times for i=0,ntests-1 do begin cd,dir+"/Log/"+tests(i) openr,1,'idx' ; find mission zero times while (not EOF(1)) do begin line = blank ; force to be string type readf,1,line,FORMAT="(A80)" if STRPOS(line,'START_SCENARIO Out') GT 0 then begin time(time_count,0) = time_to_int(STRMID(line,9,8)) time(time_count,1) = 0.0 ; curve has not been fitted yet time(time_count,2) = 0.0 time_count = time_count + 1 endif endwhile close,1 openr,1,'ogse_log' ; find mission zero times while (not EOF(1)) do begin line = blank ; force to be string type readf,1,line,FORMAT="(A80)" pos = STRPOS(line,'System clock time') if pos GT 0 then begin cal_time = time_to_int(STRMID(line,pos+30,8)) rtgse_time = time_to_int(STRMID(lasts,11,8)) y(clk_count) = rtgse_time x(clk_count) = cal_time clk_count = clk_count + 1 endif lasts=line endwhile close,1 endfor for i=0,time_count-2 do for j=0,time_count-2-i do if time(j,0) GT time(j+1,0) then begin t = time(j+1,0) time(j+1,0) = time(j,0) time(j,0) = t endif ; bubble sort list of scenario re-start times ; earliest times first coef = fltarr(2) if (clk_count GT 1) then begin ; create polynomial to convert cal time to rtgse time coef = poly_fit(x,y,1) endif $ else if (clk_count EQ 1) then begin coef(1) = 1.0 coef(0) = y(0) - x(0) endif $ else if (clk_count LT 1) then begin coef(1) = 1.0 coef(0) = 0.0 endif for i=0,time_count-1 do begin time(i,1) = coef(0) - time(i,0) ; convert to mission time zero time(i,2) = coef(1) ; and time scale factor endfor cal_files = strarr(100) ; find all cal log files for this day cal_times = fltarr(100) ; sort the list by log file start time cal_count = 0 for i=0,ntests-1 do begin cd,dir+"/Log/"+tests(i) spawn,'grep -l "DISR Cal" *',cal_logs s = size(cal_logs) if s(0) EQ 1 then begin for j=0,s(1)-1 do begin cal_files(cal_count) = dir+"/Log/"+tests(i)+"/"+cal_logs(j) openr,1,cal_files(cal_count) ; get start time if NOT EOF(1) then readf,1,line ; first two lines are skipped if NOT EOF(1) then readf,1,line if NOT EOF(1) then begin ; don't save if no data line = blank+blank+blank ; need large string area readf,1,line,FORMAT="(300x,a240)" pos = STRPOS(line,':')-2 cal_times(cal_count) = time_to_int(STRMID(line,pos,8)) cal_count = cal_count + 1 endif close,1 endfor endif endfor for i=0,cal_count-2 do for j=0,cal_count-2-i do if cal_times(j) GT cal_times(j+1) then begin t = cal_times(j+1) cal_times(j+1) = cal_times(j) cal_times(j) = t t = cal_files(j+1) cal_files(j+1) = cal_files(j) cal_files(j) = t endif ; bubble sort list of cal log file start times ; earliest times first print for i=0,cal_count-1 do print,cal_files(i),cal_times(i) ;*************** Time base is now established. Next, find each data file and fix headers ******** subs=strarr(30) ; names of all data subdirectories under DB sirectory test_fs=strarr(10000) ; names of each test file test_times=lonarr(30) for test=0,ntests-1 do begin cd,dir+"/Log/"+tests(test) ; find log file start time openr,1,'ogse_log' line = blank ; force to be string type if NOT EOF(1) then begin readf,1,line,FORMAT="(A80)" rtgse_time = time_to_int(STRMID(line,11,8)) test_times(test) = rtgse_time endif else test_times(test) = 0 ; no data, no valid time stamp print,tests(test),rtgse_time close,1 cd,'DB' ; find all sub directories spawn,'ls',subs s=size(subs) nsubs = s(1) for sub=0,nsubs-1 do begin cd,dir+"/Log/"+tests(test)+"/DB/"+subs(sub) ; find all test files print,FORMAT="(' ',a,$)",subs(sub) test_fs = t_getfil('V_*') ; that might have header files ;if(subs(sub) EQ 'Violet') then stop s=size(test_fs) nfs = s(1) print,FORMAT="(' ',i,$)",s(0)*nfs if ((s(0) NE 0) AND (nfs GT 0)) then begin cal=0 while ((cal_times(cal) LT rtgse_time) AND (cal LT cal_count)) do cal = cal + 1 if cal GT 0 then cal = cal - 1 ; largest time small than rtgse time close,2 ; make sure ready for cal log file openr,2,cal_files(cal) ; open best guess cal file, where ever it is ; print,'opening cal log file ',cal_files(cal) readf,2,line ; skip first two lines readf,2,line readf,2,line line=strtrim(line,2) ; remove leading and trailing white space pos=0 tab=' ' while(pos GE 0) do begin pos=STRPOS(line,tab,pos+1) if pos GT 0 then STRPUT,line,',',pos endwhile line=strcompress(line,/remove_all) pos=STRPOS(line,':',1) ; make sure not partial line if pos GT 80 then reads,line,orec,owave,osi,oge,ofilter,ogain,ortime, $ ograting,oturret,ospsi,ospflsi,ospingas,ospdtemp, $ ocolsi,ocolflsi,ocolingas,ocoltemp,obeamsi,osslingas, $ ounused_temp,oamb_prt,oprt2,oprt3,oprt4, $ ogastemp,oambtemp,osptemp,oboxtemp,ochmbrtemp,ocldstraptemp,$ otemp1,osparetemp,oelevation,oazimuth,opolarizor, $ oshutter, $ FORMAT="(i,f,2e,2i,f,2i,2(3i,f),2i,13f,3f,i)" ot=strmid(line,strlen(line)-30,30) ;print,'rec ',orec,' wave ',owave,' si ',osi,' ge ',oge,' fltr ',ofilter,' gain ',$ ;ogain,' rt ',ortime,' grat ',ograting,' tur ',oturret,' spsi ',ospsi,' spflsi ',ospflsi,$ ;' spingas ',ospingas,' sptemp ',ospdtemp,' colsi ',ocolsi,' colflsi ',ocolflsi, $ ;' colingas ',ocolingas,' coltemp ',ocoltemp,' beamsi ',obeamsi,' sslingas ',osslingas, $ ;' utemp ',ounused_temp,' ambprt ',oamb_prt,' prt2 ',oprt2,' prt3 ',oprt3,' prt4 ',oprt4, $ ;' gastemp ',ogastemp,' ambtemp ',oambtemp,' sptemp ',osptemp,' box temp',oboxtemp ;print,' chmbrtemp ',ochmbrtemp,' coldstrap ',ocldstraptemp,' temp1 ',otemp1,' spare1 ',osparetemp, $ ;' el ',oelevation,' az ',oazimuth,' pol ',opolorizor, ' shutter ',oshutter,' time ',ot pos = STRPOS(ot,':')-2 ; print,STRMID(ot,pos,8) otime = time_to_int(STRMID(ot,pos,8)) ;print,otime ;cd,olddir ;stop scenario = 0 while (( rtgse_time GT time(scenario,0) AND scenario LT time_count)) do $ scenario = scenario + 1 if scenario GT 0 then scenario = scenario - 1 otime = time(scenario,1) + otime*time(scenario,2) ; convert to mission time readf,2,line line=strtrim(line,2) ; remove leading and trailing white space pos=0 tab=' ' while(pos GE 0) do begin ; remove tabs pos=STRPOS(line,tab,pos+1) if pos GT 0 then STRPUT,line,',',pos endwhile line=strcompress(line,/remove_all) ; remove all white space pos=STRPOS(line,':',1) ; make sure not partial line if pos GT 80 then reads,line,rec,wave,si,ger,filter,gain,rtime,grating,turret, $ spsi,spflsi,spingas,spdtemp, $ colsi,colflsi,colingas,coltemp,beamsi,sslingas, $ unused_temp,amb_prt,prt2,prt3,prt4, $ gastemp,ambtemp,sptemp,boxtemp,chmbrtemp,cldstraptemp,$ temp1,sparetemp,elevation,azimuth,polarizor, $ shutter, $ FORMAT="(i,f,2e,2i,f,2i,2(3i,f),2i,13f,3f,i)" t=strmid(line,strlen(line)-30,30) pos = STRPOS(t,':')-2 ; print,STRMID(t,pos,8) mtime = time_to_int(STRMID(t,pos,8)) mtime = time(scenario,1) + mtime*time(scenario,2) ; convert to mission time f_steps = nfs/50 if f_steps LT 1 then f_steps = 1 for f=0,nfs-1 do begin if subs(sub) EQ 'Ir' then begin d_irread,test_fs(f),h,p,g,status ; get ir data endif else begin d_read,test_fs(f),h,p,status ; get header endelse ; if !error EQ -167 then begin ; print,FORMAT="('+',a,$)",status ; !error = 0 ; if subs(sub) EQ 'Ir' then begin ; d_irread,test_fs(f),h,p,g ; get ir data ; endif else begin ; d_read,test_fs(f),h,p ; get header ; endelse ; endif ; if !error EQ -167 then begin ; print,' error opening file ',test_fs(f) ; !error = 0 ; stop ; endif if (h(88) NE ' ') then $ data_time=d_value(h,88)$ ; get mission time for this data set else $ data_time=rtgse_time while ((mtime LT data_time) AND cal LT cal_count) do begin ; save current values into old values orec=rec & owave = wave & osi = si & oge = ger & ofilter = filter ogain = gain & ortime = rtime & ograting = grating oturret = turret & ospsi = spsi & ospflsi = spflsi ospingas = spingas & ospdtemp = spdtemp ocolsi = colsi & ocolflsi = colflsi & ocolingas = colingas ocoltemp = coltemp & obeamsi = beamsi & osslingas = sslingas ounused_temp = unused_temp & oamb_prt = amb_prt oprt2 = prt2 & oprt3 = prt3 & oprt4 = prt4 ogastemp = gastemp & oambtemp = ambtemp osptemp = sptemp & oboxtemp = boxtemp ochmbrtemp = chmbrtemp & ocldstraptemp = cldstraptemp otemp1 = temp1 & osparetemp = sparetemp oelevation = elevation & oazimuth = azimuth opolarizor = polarizor & oshutter = shutter otime = mtime while ((cal LT cal_count) AND EOF(2)) do begin cal = cal + 1 if cal LT cal_count then begin close,2 ; only close if we can open next openr,2,cal_files(cal) ; open best guess cal file, where ever it is ; print,'opening cal log file ',cal_files(cal) if NOT EOF(2) then readf,2,line ; skip first two lines if NOT EOF(2) then readf,2,line endif endwhile if cal LT cal_count then begin readf,2,line line=strtrim(line,2) ; remove leading and trailing white space pos=0 tab=' ' while(pos GE 0) do begin ; remove tabs pos=STRPOS(line,tab,pos+1) if pos GT 0 then STRPUT,line,',',pos endwhile line=strcompress(line,/remove_all) ; remove all white space ps=STRPOS(line,':',1) ; make sure not partial line if ps GT 80 then begin reads,line,rec,wave,si,ger,filter,gain,rtime,grating,turret, $ spsi,spflsi,spingas,spdtemp, $ colsi,colflsi,colingas,coltemp,beamsi,sslingas, $ unused_temp,amb_prt,prt2,prt3,prt4, $ gastemp,ambtemp,sptemp,boxtemp,chmbrtemp,cldstraptemp,$ temp1,sparetemp,elevation,azimuth,polarizor, $ shutter, $ FORMAT="(i,f,2e,2i,f,2i,2(3i,f),2i,13f,3f,i)" t=strmid(line,strlen(line)-30,30) pos = STRPOS(t,':')-2 mtime = time_to_int(STRMID(t,pos,8)) if !error EQ -69 then begin print,' error ',line,' ',ps !error = 0 endif while (( mtime GT time(scenario,0) AND scenario LT time_count)) do $ scenario = scenario + 1 if scenario GT 0 then scenario = scenario - 1 mtime = time(scenario,1) + mtime*time(scenario,2) ; convert to mission time endif ;if log file line is complete endif endwhile ; ready to write data values into header ; first make header array long enough by d_inserting the last element d_insert,h,h,otime,H_LAST_CALTIME,'V' ; mission time of last log entry ; then do quick insert of the remaining elements ; d_insert,h,h,wave,255,'V' ; monochomator wavelength h(H_MONO_WAVL)='CS 14 '+STRING(FORMAT='(f11.2)',owave) ; d_insert,h,h,si,256,'V' ; monochomator Silicon detector h(H_MONO_SI)='CS 14 '+STRING(FORMAT='(g15.2)',osi) ; d_insert,h,h,ger,257,'V' ; monochomator Germainium det. h(H_MONO_GE)='CS 14 '+STRING(FORMAT='(g15.2)',oge) ; d_insert,h,h,filter,258,'V' ; monochomator filter possition h(H_MONO_FLTR)='CS 12 '+STRING(FORMAT='(i2)',ofilter) ; d_insert,h,h,gain,H_MONO_G,'V' ; monochomator det. gain h(H_MONO_G)='CS 12 '+STRING(FORMAT='(i3)',ogain) ; d_insert,h,h,rtime,H_MONO_RT,'V' ; monochomator response time h(H_MONO_RT)='CS 14 '+STRING(FORMAT='(f8.2)',ortime) ; d_insert,h,h,grating,H_MONO_GRAT,'V' ; monochomator grating num h(H_MONO_GRAT)='CS 12 '+STRING(FORMAT='(i1)',ograting) ; d_insert,h,h,turret,H_MONO_TUR,'V' ; monochomator turret h(H_MONO_TUR)='CS 12 '+STRING(FORMAT='(i1)',oturret) ; d_insert,h,h,spsi,H_SPSI,'V' ; integrating sphere silicon h(H_SPSI)='CS 13 '+STRING(FORMAT='(i10)',ospsi) ; d_insert,h,h,spflsi,H_SPFLSI,'V' ; integrating sphere filtered si h(H_SPFLSI)='CS 13 '+STRING(FORMAT='(i10)',ospflsi) ; d_insert,h,h,spingas,H_SPINGAS,'V' ; integrating sphere IndGalArs h(H_SPINGAS)='CS 13 '+STRING(FORMAT='(i10)',ospingas) ; d_insert,h,h,spdtemp,266,'V' ; integrating sphere det. temp h(H_SP_DETTMP)='CS 14 '+STRING(FORMAT='(f12.3)',ospdtemp) ; d_insert,h,h,colsi,H_COSI,'V' ; collimator silicon h(H_COSI)='CS 13 '+STRING(FORMAT='(i10)',ocolsi) ; d_insert,h,h,colflsi,H_COFLSI,'V' ; collimator filtered si h(H_COFLSI)='CS 13 '+STRING(FORMAT='(i10)',ocolflsi) ; d_insert,h,h,colingas,H_COINGAS,'V' ; collimator IndGalArs h(H_COINGAS)='CS 13 '+STRING(FORMAT='(i10)',ocolingas) ; d_insert,h,h,coltemp,270,'V' ; collimator det. temp h(H_COTMP)='CS 14 '+STRING(FORMAT='(f10.3)',ocoltemp) ; d_insert,h,h,beamsi,H_PLMTMP,'V','(f)',status ; beam silicon detector h(H_PLMTMP)='CS 14 '+STRING(FORMAT='(f10.3)',obeamsi) ; d_insert,h,h,sslingas,H_PLMINGAS,'V' ; surface science lamp InGalArs h(H_PLMINGAS)='CS 13 '+STRING(FORMAT='(i10)',owave) ; d_insert,h,h,unused_temp,H_CAL_D1,'V' ; unused temperature channel ; h(H_CAL_D1)='CS 12 '+STRING(FORMAT='(i3)',ounused_temp) ; d_insert,h,h,amb_prt,H_CAL_D2,'V' ; ambient prt, not used h(H_CAL_D2)='CS 13 '+STRING(FORMAT='(i10)',oamb_prt) ; d_insert,h,h,prt2,H_CAL_D3,'V' ; prt2, not connected h(H_CAL_D3)='CS 13 '+STRING(FORMAT='(i10)',oprt2) ; d_insert,h,h,prt3,H_CAL_D4,'V' ; prt3, not connected h(H_CAL_D4)='CS 13 '+STRING(FORMAT='(i10)',oprt3) ; d_insert,h,h,prt4,H_CAL_D5,'V' ; prt4, not connected h(H_CAL_D5)='CS 13 '+STRING(FORMAT='(i10)',oprt4) ; d_insert,h,h,gastemp,H_CPGASTEMP,'V' ; c&p gas temp @ thermax output h(H_CPGASTEMP)='CS 14 '+STRING(FORMAT='(f12.3)',ogastemp) ; d_insert,h,h,ambtemp,H_AMBTEMP,'V' ; ambient temp in clean room h(H_AMBTEMP)='CS 14 '+STRING(FORMAT='(f12.3)',oambtemp) ; d_insert,h,h,sptemp,H_SPTEMP,'V' ; integrating sphere temp. h(H_SPTEMP)='CS 14 '+STRING(FORMAT='(f12.3)',osptemp) ; d_insert,h,h,boxtemp,H_BOXTEMP,'V' ; dry box external purge temp. h(H_BOXTEMP)='CS 14 '+STRING(FORMAT='(f12.3)',oboxtemp) ; d_insert,h,h,chmbrtemp,H_CHMBTEMP,'V' ; envirnmental chamber temp. h(H_CHMBTEMP)='CS 14 '+STRING(FORMAT='(f12.3)',ochmbrtemp) ; d_insert,h,h,cldstraptemp,H_CAL_T1,'V' ; cold strap temp. h(H_CAL_T1)='CS 14 '+STRING(FORMAT='(f12.3)',ocldstraptemp) ; d_insert,h,h,temp1,H_CAL_T2,'V' ; interface ring temp. h(H_CAL_T2)='CS 14 '+STRING(FORMAT='(f12.3)',otemp1) ; d_insert,h,h,sparetemp,H_CAL_T3,'V' ; spare temp channel h(H_CAL_T3)='CS 14 '+STRING(FORMAT='(f12.3)',osparetemp) ; d_insert,h,h,elevation,H_CAL_EL,'V' ; el/az mount elevation angle h(H_CAL_EL)='CS 14 '+STRING(FORMAT='(f12.3)',oelevation) ; d_insert,h,h,azimuth,H_CAL_AZ,'V' ; el/az mount azimuth angle h(H_CAL_AZ)='CS 14 '+STRING(FORMAT='(f12.3)',oazimuth) ; d_insert,h,h,polarizor,H_CAL_POL,'V' ; polarizor angle h(H_CAL_POL)='CS 14 '+STRING(FORMAT='(f12.3)',opolarizor) ; d_insert,h,h,shutter,H_CAL_SHUT,'V' ; shutter open/close bit h(H_CAL_SHUT)='CS 12 '+STRING(FORMAT='(i1)',oshutter) ; h(H_LAST_CALTIME)='CS 17 '+STRING(FORMAT='(i10)',omtime) if subs(sub) EQ 'HKeeping' then begin spawn,'mv '+test_fs(f)+' temp' d_write,test_fs(f),h,p,status,/headonly d_delim,'temp',status endif $ else if subs(sub) EQ 'Ir' then begin spawn,'mv '+test_fs(f)+' temp' d_irwrit,test_fs(f),h,p,status d_delim,'temp',status endif $ else begin spawn,'mv '+test_fs(f)+' temp' d_write,test_fs(f),h,p,status d_delim,'temp',status endelse if (nfs GT 100) then begin if (f/f_steps)*f_steps EQ f then print,FORMAT="('*',$)" endif else print,FORMAT="('.',$)" ; endif ; check to see if header big enough endfor ; end of F loop endif ; skipping if no files in this directory print ; go to new line for start of next sub directory endfor ; end of SUB loop endfor ; end of test loop print,' Run time in seconds = ',long(systime(1) - start_time) cd,olddir stop end