;+ ; NAME: ; RDTLOG ; PURPOSE: ; Read temperature data from Polar Camera ASCII temperature log ; files. ; CATEGORY: ; Image processing support. ; CALLING SEQUENCE: ; rdtlog,year,month,day,infile=infile,showtime=showtime ; INPUTS: ; YEAR, MONTH, DAY: Numeric date parameters. YEAR can be either 2 ; or 4 digits. ; OPTIONAL INPUTS: ; None. ; KEYWORD PARAMETERS: ; INFILE: May contain the name (only; no path) of the file to be ; read. ; /SHOWTIME: If set, the routine displays the time taken to read ; the file. ; OUTPUTS: ; None. ; OPTIONAL OUTPUTS: ; None. ; COMMON BLOCKS: ; None. ; SIDE EFFECTS: ; Temporary files are created in the subdirectory containing the ; ASCTEMP?.??? file, to hold the time history of all measured ; temperatures. ; RESTRICTIONS: ; The needed ASCTEMP1.??? file must exist in the appropriate ; directory, and be readable after being un-gzipped. ; PROCEDURE: ; Straightforward. ; EXAMPLE: ; ; SEE ALSO: ; ; MODIFICATION HISTORY: ; Written by: DPSteele, ISAS, Aug.-Sep., 1995 ; Documented by: DPSteele, ISAS, May 1996. ;- PRO rdtlog,year,month,day,infile=infile,showtime=showtime ; Set up OS-specific parameters @isitdos ; Form name of source log file IF month LT 10 THEN hexmo=STRING(month,FORMAT='(I1)') $ ELSE hexmo=STRING(BYTE(month)-10B+BYTE('a')) hexdate=hexmo+STRING(day,FORMAT='(I2.2)') path=logroot+dd+STRING(year MOD 100,FORMAT='(I2.2)') $ +dd+hexdate+dd IF N_ELEMENTS(infile) EQ 0 THEN infile=path+'ASCTEMP1.'+hexdate ; Show execution time? IF KEYWORD_SET(showtime) THEN t0=SYSTIME(1) ; load data from the ASCTEMP1.### file s=qgetfile(infile) ns=N_Elements(s) ; locate action points names=['AFB','tfw','tei','td','tee','tcf','heater'] n_names=N_ELEMENTS(names) ; First locate AFB identification lines w=WHERE(STRPOS(s,names(0)) EQ 0,n) ; Check for bad AFB id's, indicating a corrupt KI_TEMP file ids=INTARR(n) FOR j=0,n-1 DO ids(j)=FIX(getwrd(s(w(j)),2)) uids=ids(uniq(ids,SORT(ids))) nuids=N_Elements(uids) CASE 1 OF (4 LT nuids): BEGIN MESSAGE,'More than 4 AFB ids; aborting',/INFORMATIONAL RETURN END (2 LT nuids) AND (nuids LE 4): BEGIN idformat='(I0," AFB ids found: ",'+StrTrim(nuids,2)+'I5)' Print,nuids,uids,Format=idformat ; Select the most popular ID ... id_h=Histogram(ids) Print,Long(uids),id_h(uids) nmost=Max(id_h,uidmost) ; ... and the most logical association with it. IF odd(uidmost) $ THEN uids=[uidmost-1,uidmost] $ ELSE uids=[uidmost,uidmost+1] Print,'AFB ids selected: '+String(uids,Format='(2I3)') END (nuids LT 2): BEGIN Print,'Too few AFB ids; making some up' IF odd(uids(0)) $ THEN uids=[uids(0)-1,uids(0)] $ ELSE uids=[uids(0),uids(0)+1] Print,'AFB ids selected: '+uids END ELSE: ENDCASE cam0id=uids(0) ; Form array indicating sensor type to speed up later processing senstype=REPLICATE(255B,ns) senstype(w)=0 ; 0 => 'AFB' ; Locate records for all entries in 'names' wall=LONARR(n+10,n_names) ; include a safety margin nall=LONARR(n_names) wall(0,0)=w nall(0)=n FOR i=1,n_names-1 DO BEGIN w=WHERE(STRPOS(s,names(i)) EQ 0,n) wall(0,i)=w nall(i)=n senstype(w)=BYTE(i) ENDFOR ; create STRING array to hold measurement times for all lines ut=STRARR(ns) src=INTARR(ns) hr=INTARR(MAX(nall)) mn=hr sec=hr cam=hr ; Process AFB entries one at a time (sigh) FOR i=0,nall(0)-1 DO BEGIN t=s(wall(i,0)) t=repchr(t,'/',' ') t=repchr(t,':',' ') hr(i)=FIX(getwrd(t,8)) mn(i)=FIX(getwrd(t,9)) sec(i)=ROUND(FLOAT(getwrd(t,10))) cam(i)=(getwrd(t,2) EQ cam0id) ENDFOR ; Detect and correct any 24-hour wraparounds (except at last entry) dhr=SHIFT(hr,-1)-hr dhr(nall(0)-1)=dhr(nall(0)-2) ; kludge to avoid spurious neg. value inchr=WHERE(dhr LT 0,ninchr) IF ninchr GT 0 THEN hr(inchr+1)=hr(inchr+1)+24 ; Form time array (in fractional hours) time=(sec/60.+mn)/60.+hr HELP,time hlp,time ; Save measurement time and source AFB id for all measurements wall(nall(0))=ns FOR i=0,nall(0)-1 DO BEGIN ut(wall(i,0):wall(i+1,0)-1)=STRING(time(i),FORMAT='(F8.4)') src(wall(i,0):wall(i+1,0)-1)=cam(i) ENDFOR ; Form STRARR of measurement times and results for each sensor FOR i=1,n_names-1 DO BEGIN ; loop over all sensor types IF i LT (n_names-1) THEN valpos=31 ELSE valpos=13 FOR j=0,1 DO BEGIN ; loop over both AFB id's w=WHERE((senstype EQ BYTE(i)) AND (src EQ j),n) val=STRMID(s(w),valpos,6) outtext=REFORM(REFORM(ut(w),1,n)+REFORM(val,1,n)) outfile=path+STRING(names(i),uids(j),FORMAT='(A,I1)') mputfile,outfile,outtext ENDFOR ENDFOR IF KEYWORD_SET(showtime) $ THEN PRINT,STRING(SYSTIME(1)-t0 $ ,FORMAT='("Execution took ",F5.1," sec.")') RETURN END