;+ ; NAME: ; FINDCALS ; PURPOSE: ; Locate references to non-trivial calibration files in NovaStor ; tape summary files. ; CATEGORY: ; Tape processing utility. ; CALLING SEQUENCE: ; FINDCALS, template, matches ; INPUTS: ; TEMPLATE: string (possibly including wildcards) to be compared ; with all available .SUM files. ; OPTIONAL INPUTS: ; None. ; KEYWORD PARAMETERS: ; None. ; OUTPUTS: ; MATCHES: Listing of tape name, file number, date, and number of ; calibration files found. ; OPTIONAL OUTPUTS: ; OUTPUT: If specified, returns a STRARR containing a tabular ; representation of the search results. ; COMMON BLOCKS: ; None. ; SIDE EFFECTS: ; None. ; RESTRICTIONS: ; None. ; PROCEDURE: ; ; EXAMPLE: ; ; SEE ALSO: ; ; MODIFICATION HISTORY: ; Written by: Your name here, Date. ;- PRO findcals,template,matches,output IF STRUPCASE(STRMID(template,STRLEN(template)-3,3)) NE 'SUM' THEN BEGIN MESSAGE,'Template must select .SUM files!',/INFORMATIONAL RETURN ENDIF sf=rfindfile('c:\data\tapes\'+template,count=nsf) sf=sf(SORT(sf)) sflen=STRLEN(sf) IF nsf EQ 0 THEN BEGIN MESSAGE,'No matching tapes found.',/INFORMATIONAL matches='' RETURN ENDIF ELSE BEGIN entry={match, tape:'', set:0, date:'', files:0} FOR i=0,nsf-1 DO BEGIN messtr=STRING(sf(i),i+1,nsf $ ,FORMAT='("Processing ",A,": ",I0," of ",I0)') MESSAGE,messtr,/INFORMATIONAL ; Read in .sum file tapename=STRMID(sf(i),sflen(i)-10,6) contents=qgetfile(sf(i)) ; Locate first lines of backup set summaries. settop=WHERE((STRPOS(contents,'Dataset') GT 0) AND $ (STRPOS(contents,'Created') GT 0),nsettop) ; Find calibration file summary. caltot=WHERE(STRPOS(contents,'CALIB\ (total)') GE 0,ncals) IF ncals GT 0 THEN BEGIN ; How many calibration files saved endline=STRPOS(contents(caltot),'__ ')+2 IF TOTAL(ABS(endline-MEDIAN(endline))) EQ 0 THEN BEGIN endline=MEDIAN(endline) numcalfiles=FIX(STRMID(contents(caltot),endline,5)) ENDIF ELSE BEGIN numcalfiles=endline-endline FOR j=0,N_ELEMENTS(endline)-1 DO $ numcalfiles(j)=FIX(STRMID(contents(caltot(j)) $ ,endline(j),5)) ENDELSE ; Need at least 10 files for a calibration. didcal=WHERE(numcalfiles GT 10,ndone) IF ndone GT 0 THEN BEGIN candidate=caltot(didcal) ; Interpolate in first line positions to identify sets ; containing calibration records. calset=FLOOR(INTERPOL(INDGEN(nsettop),settop,candidate)) ncalset=N_ELEMENTS(calset) ; Extract information about sets. latest=REPLICATE({match},ncalset) FOR j=0,ncalset-1 DO BEGIN calsettop=contents(settop(calset(j))) latest(j).tape=tapename latest(j).set=FIX(calset(j)+1) latest(j).date=getwrd(calsettop,3)+' '+getwrd(calsettop,4) latest(j).files=numcalfiles(didcal(j)) ENDFOR IF N_ELEMENTS(matches) EQ 0 $ THEN matches=latest $ ELSE matches=[matches,latest] MESSAGE,STRTRIM(ncalset,2)+' possible calibrations found on tape '+tapename $ ,/INFORMATIONAL ENDIF ELSE MESSAGE,'No calibrations on tape '+tapename,/INFORMATIONAL ENDIF ELSE MESSAGE,'No calibrations on tape '+tapename,/INFORMATIONAL ENDFOR ENDELSE IF N_PARAMS() EQ 3 THEN BEGIN output=STRARR(N_ELEMENTS(matches)) FOR i=0,N_ELEMENTS(matches)-1 DO $ output(i)=STRING(matches(i).tape,matches(i).set,matches(i).date,matches(i).files $ ,FORMAT='(A6,I4,A20,I4)') ENDIF RETURN END