;+ ; NAME: ; STORLOGS ; PURPOSE: ; To process log files produced by the Polar Camera, and to store ; them into the appropriate subdirectory. ; CATEGORY: ; Polar Camera data processing ; CALLING SEQUENCE: ; STORLOGS, YEAR, MONTH, DAY $ ; [, QUIET = QUIET] [, DEBUG = DEBUG] [, RMALL = RMALL] ; INPUTS: ; YEAR, MONTH, DAY: The date of operation to which the log files pertain. ; OPTIONAL INPUTS: ; None. ; KEYWORD PARAMETERS: ; /QUIET: If set, no explanatory messages are output, e.g., by rfindfile. ; /DEBUG: If set, PAUSE statements are inserted into the DOS batch file ; created to do the file processing and movement, so that ; the progress of the batch file can be monitored. Informational ; messages are also output as appropriate. ; /RMALL: If set, removes all files lying around after the specified ones ; have been stored. BE CAREFUL!! ; OUTPUTS: ; None. ; OPTIONAL OUTPUTS: ; None. ; COMMON BLOCKS: ; None. ; SIDE EFFECTS: ; As ASCII file is created from the temperature log file KI_TEMP1.###, ; and compressed with gzip. The operations log, the backup log, and the ; QLOOK.## file are all compressed similarly. KI_TEMP1.### is deleted, ; and the remaining files are moved to a subdirectory created specific- ; ally for the specified date. The subdirectory is created if necessary. ; RESTRICTIONS: ; The files must have fairly standard names. ; PROCEDURE: ; The subdirectory is created if it does not exist. Then a batch file ; is written by IDL to execute the format conversion, compression, and ; file deletion and moving commands. Finally the batch file is run ; using the SPAWN command. ; EXAMPLE: ; storlogs,1995,12,21 ; SEE ALSO: ; tlog.pro, plottlog.pro ; MODIFICATION HISTORY: ; Written by: DPS, ISR, early 1994. ; Generalized to Windows environment and documented: DPS, ISAS, Aug. '95. ;- PRO storlogs,year,month,day,quiet=quiet,debug=debug,rmall=rmall ; This procedure detects any log files in /jasper/cnsr3_data1/log ; for the given date, creates a subdirectory for them if necessary, ; and moves them into the subdirectory after compressing them with ; gzip (where appropriate). It makes extensive use of SPAWNed shell ; commands. ; ; Modified 950823 by DPS to use ISITDOS.PRO to harmonize between Windows ; and Unix. ; If no arguments specified, print the documentation. IF N_PARAMS() LT 3 THEN BEGIN doc_library,'storlogs' RETURN ENDIF ; Set up OS-specific parameters. @isitdos CD,!DIR ON_ERROR,2 pause='pause' ; Search for directory for the current year yrdir=logroot+dd+STRING(year MOD 100,FORMAT='(I2.2)') f=rfindfile(yrdir+dd+'.',count=df) ; If not found, we must create one IF df EQ 0 THEN BEGIN cmd=mkdircmd+yrdir SPAWN,cmd f=rfindfile(yrdir+dd+'.',count=df) IF df EQ 0 THEN BEGIN MESSAGE,'Could not create year directory',/INFORMATIONAL STOP RETURN ENDIF ENDIF ; Assume yrdir exists, and go on IF month LT 10 THEN hexmo=STRING(month,FORMAT='(I1)') $ ELSE hexmo=STRING(BYTE(month)+87B) decmo=STRING(month,FORMAT='(I2.2)') date=STRING(day,FORMAT='(I2.2)') hexdate=hexmo+date decdate=decmo+date logdir=yrdir+dd+hexdate f=rfindfile(logdir+dd+'.',count=df) IF df EQ 0 THEN BEGIN ; needed directory not there SPAWN,mkdircmd+logdir f=rfindfile(logdir+dd+'.',count=df) ENDIF IF df EQ 0 THEN BEGIN MESSAGE,"Couldn't build subdirectory for logs" RETURN ENDIF ELSE BEGIN ; Open a new file to receive the shell commands needed jobname=sroot+dd+'mv' $ +STRING(year MOD 100,month,day,FORMAT='(3I2.2,".bat")') OPENW,jobunit,jobname,/GET_LUN IF NOT dos THEN PRINTF,jobunit,'#/bin/csh -f' ; ASCIIize, gzip, and move the temperature log file. See whether ; temperature log file exists where we expect it to be. tlogfile=logroot+dd+'ki_temp*.'+hexdate tl=rfindfile(tlogfile,count=tlf) IF tlf EQ 0 THEN BEGIN IF KEYWORD_SET(debug) $ THEN MESSAGE,'Looking for any temperature logs now...' $ ,/INFORMATIONAL tlogfile=logroot+dd+'ki_temp*.*' tl=rfindfile(tlogfile,count=tlf) IF tlf GT 0 THEN BEGIN tli=WHERE((STRLEN(tl)-STRPOS(tl,date)) LT 3,ntli) CASE ntli OF 0: BEGIN MESSAGE,'No appropriate temperature logs found!' $ ,/INFORMATIONAL tlf=0 END 1: BEGIN tli=tli(0) tl=tl(tli) tlf=1 END ELSE: BEGIN FOR j=0,ntli-1 DO PRINT,j,tl(tli(j)) $ ,FORMAT='(I1,":",2X,A)' READ,'Enter the number of the correct log file: ',tlj tl=tl(tli(tlj)) tlf=1 END ENDCASE ENDIF ELSE MESSAGE,'Couldn''t find temperature log' $ ,/INFORMATIONAL ENDIF ELSE tl=tl(0) IF tlf GT 0 THEN BEGIN ; Temperature log file found! ; Convert the binary temperature log to ASCII. ascname='asctemp1.'+hexdate cmd=tasciize+tl+rd+logroot+dd+ascname IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDIF ; Compress the ASCII file. ascf=rfindfile(logroot+dd+'asctemp*.*',count=nascf) IF (tlf GT 0) OR (nascf GT 0) THEN BEGIN IF tlf LE 0 THEN BEGIN ascfp=Str_Sep(ascf(0),dd) ascname=ascfp(N_Elements(ascfp)-1) ENDIF cmd=gzipcmd+logroot+dd+ascname IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ; Move the compressed file to the right subdirectory. IF dos THEN gzipname=STRMID(ascname,0,STRLEN(ascname)-1)+'z' $ ELSE gzipname=ascname+'.gz' cmd=mvcmd+logroot+dd+gzipname+' '+logdir IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ; Finally delete the binary temperature log, cmd=rmcmd+tl IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' For jc=0,N_Elements(cmd)-1 DO PRINTF,jobunit,cmd(jc) IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ; and any ASCTEMP*.* files still kicking around. IF KEYWORD_SET(rmall) THEN BEGIN ascf=rfindfile(logroot+dd+'asctemp*.*',count=nascf) IF nascf GT 0 THEN BEGIN FOR j=0,nascf-1 DO BEGIN cmd=rmcmd+ascf(j) IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDFOR ENDIF ENDIF ENDIF ; Gzip and move the operations log file ologfile=logroot+dd+'ki_log*.'+hexdate ol=rfindfile(ologfile,count=olf) IF olf EQ 0 THEN BEGIN ologfile=logroot+dd+'ki_log*.*' ol=rfindfile(ologfile,count=olf) IF olf GT 0 THEN BEGIN oli=WHERE((STRLEN(ol)-STRPOS(ol,date)) LT 3,noli) CASE noli OF 0: BEGIN MESSAGE,'No appropriate operations logs found' $ ,/INFORMATIONAL olf=0 END 1: BEGIN oli=oli(0) ol=ol(oli) END ELSE: BEGIN FOR j=0,noli-1 DO PRINT,j,ol(oli(j)) $ ,FORMAT='(I1,":",2X,A)' READ,'Enter the number of the correct log file: ',olj ol=ol(oli(olj)) olf=1 END ENDCASE ENDIF ELSE MESSAGE,'Couldn''t find operations log' $ ,/INFORMATIONAL ENDIF ELSE ol=ol(0) IF olf GT 0 THEN BEGIN ; operations log file found! cmd=gzipcmd+ol IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause IF dos THEN gzipname=STRMID(ol,0,STRLEN(ol)-1)+'z' $ ELSE gzipname=ol+'.gz' cmd=mvcmd+gzipname+' '+logdir IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDIF ; Gzip and move any backup log files found blg=rfindfile(logroot+dd+'r'+decdate+'?.blg',COUNT=nblg) IF nblg GT 0 THEN BEGIN FOR i=0,nblg-1 DO BEGIN cmd=gzipcmd+blg(i) IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause IF dos THEN gzipname=STRMID(blg(i),0,STRLEN(blg(i))-1)+'z' $ ELSE gzipname=blg(i)+'.gz' cmd=mvcmd+gzipname+' '+logdir IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDFOR ENDIF ; Gzip and move any qlook.## files found ql=rfindfile(logroot+dd+'qlook.'+STRMID(decdate,2,2),COUNT=nql) IF nql GT 0 THEN BEGIN FOR i=0,nql-1 DO BEGIN cmd=gzipcmd+ql(i) IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause IF dos THEN BEGIN IF STRLEN(extension(ql(i))) GT 2 $ THEN gzipname=STRMID(ql(i),0,STRLEN(ql(i))-1)+'z' $ ELSE gzipname=ql(i)+'z' ENDIF ELSE gzipname=ql(i)+'.gz' cmd=mvcmd+gzipname+' '+logdir IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDFOR ENDIF ; Now move the boot log file if it's there bootlog=rfindfile(logroot+dd+'bootlog.'+hexdate,COUNT=nbootlog) IF nbootlog EQ 1 THEN BEGIN cmd=mvcmd+bootlog+' '+logdir IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDIF ; Now move the 'bkupdone' file if it's there bkupdone=rfindfile(logroot+dd+'bkupdone.'+hexdate,COUNT=nbkupdone) IF nbkupdone EQ 1 THEN BEGIN cmd=mvcmd+bkupdone+' '+logdir IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDIF ; Now delete the census file if it's there census=rfindfile(logroot+dd+'census.'+STRMID(hexdate,1,2),COUNT=ncensus) IF ncensus EQ 1 THEN BEGIN cmd=rmcmd+census IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDIF ; Now do the same for the 'kibklog*' files if they're there kibk=rfindfile(logroot+dd+'kibklog*',COUNT=nkibk) IF nkibk GE 1 THEN BEGIN FOR ik=0,nkibk-1 DO BEGIN cmd=rmcmd+kibk(ik) IF KEYWORD_SET(quiet) THEN $ IF NOT dos THEN cmd='('+cmd+') >& /dev/null' $ ELSE cmd=cmd+' > NUL' PRINTF,jobunit,cmd ENDFOR IF KEYWORD_SET(debug) THEN PRINTF,jobunit,pause ENDIF ; Now make the script executable and run it. FREE_LUN,jobunit IF NOT dos THEN SPAWN,'/usr/bsd43/bin/chmod 744 '+jobname SPAWN,jobname SPAWN,rmcmd+jobname ENDELSE ; We're done. RETURN END