PRO cleanup,year,month,day,force=force ; Set up OS-dependent parameters. @isitdos date=STRING(year MOD 100,month,day,FORMAT='(3I2.2)') ; Have quick-look data files been produced yet? qlfound=rfindfile(qlroot+dd+date+'*.ql',COUNT=nql) IF nql EQ 0 THEN BEGIN MESSAGE,'Make quick-look data files for '+date+' first!' $ ,/INFORMATIONAL RETURN ENDIF ; Do quick-look data files contain data from the files currently ; on disk? rdilist,0,year,month,day,0,0,0,nfiles,filetimes,filenames IF nfiles GT 0 THEN BEGIN ; Reject 'cal', 'non', and 'dk' images from imagelist before ; comparing time spans calfiles=WHERE(STRPOS(filenames,'cal') NE -1) goodfiles=setminus(INDGEN(nfiles),calfiles) nonfiles=WHERE(STRPOS(filenames,'No_') NE -1) goodfiles=setminus(goodfiles,nonfiles) dkfiles=WHERE(STRPOS(filenames,'dk') NE -1) goodfiles=setminus(goodfiles,dkfiles) filetimes=filetimes(goodfiles) rdcols,qlroot+dd+date+'02.ql',n,qlt,qli,qlsd PRINT,MIN(filetimes,MAX=maxft),maxft $ ,FORMAT='("Files on disk cover ",2F9.1," s UT")' PRINT,MIN(qlt,MAX=maxqt),maxqt $ ,FORMAT='("Quick-look files cover",2F9.1," s UT")' ql_done=((MIN(qlt)-MIN(filetimes) LT 40) AND $ (MAX(qlt)-MAX(filetimes) GT 0)) ; If not all data represented in quick-look files, and user wants ; to know about it, prompt for decision on cleaning up. IF NOT KEYWORD_SET(force) THEN BEGIN IF NOT ql_done THEN BEGIN PRINT,'Do you still want to remove the image files for ' $ +date+' from disk? (Y/[N])' resp='' READ,resp IF STRUPCASE(resp) NE 'Y' THEN RETURN ENDIF ENDIF ENDIF ELSE BEGIN MESSAGE,'No image list files found; going ahead in case files exist' $ ,/INFORMATIONAL ENDELSE ; Quick-look data files are up to date; go ahead with cleanup PRINT,'Making image lists for '+date wrilist,year,month,day ; Copy image list for future reference ilistname=ilist_root+dd+date+'_2'+ilist_suffix ilist_keep_name=ilist_root+dd+date+'_2'+ilist_keep_suffix SPAWN,cpcmd+ilistname+' '+ilist_keep_name ; If a gzipped image list already exists for this date, compare ; the number of lines in the two lists, and retain the longer list. oldfile=rfindfile(ilist_root+dd+date+'_2'+ilist_zip_suffix,count=noldfile) ; oldfile=FINDFILE(ilistname+'.f.gz',COUNT=noldfile) IF noldfile EQ 1 THEN BEGIN ; Count the number of lines in the new file... ; SPAWN,'wc -l '+ilistname+'.f',newlen ; newlines=FIX(newlen(0)) newlines=n_lines(ilist_keep_name) ; and the old file ; SPAWN,'gzcat '+ilistname+'.f.gz | wc -l',oldlen ; oldlines=FIX(oldlen(0)) SPAWN,mvcmd+oldfile(0)+' '+tmproot moldfile=rfindfile(tmproot+dd+date+'_2.*',count=nmoldfile) IF nmoldfile EQ 1 THEN BEGIN SPAWN,gzipcmd+'-d '+moldfile(0) moldfile=rfindfile(tmproot+dd+date+'_2.*',count=nmoldfile) oldlines=n_lines(moldfile(0)) SPAWN,gzipcmd+moldfile(0) SPAWN,mvcmd+moldfile+' '+ilist_root ENDIF ELSE BEGIN MESSAGE,'Couldn''t find gzipped ilist file in '+tmproot $ ,/INFORMATIONAL STOP ENDELSE IF newlines GT oldlines THEN BEGIN ; SPAWN,'/usr/bsd43/bin/rm '+ilistname+'.f.gz' ; SPAWN,'/usr/local/bin/gzip -v '+ilistname+'.f' SPAWN,gzipcmd+ilist_keep_name ENDIF ELSE SPAWN,rmcmd+ilist_keep_name ; SPAWN,'/usr/bsd43/bin/rm '+ilistname+'.f' ENDIF ELSE SPAWN,gzipcmd+ilist_keep_name PRINT,'Reading image lists for '+date kill_list='' ; il=FINDFILE('/jasper/cnsr3_data1/ilist/'+date+'.?.ilist',COUNT=nil) il=rfindfile(ilist_root+dd+date+dc+'?'+ilist_suffix,COUNT=nil) IF nil NE 0 THEN BEGIN FOR cam=0,1 DO BEGIN rdilist,cam,year,month,day,0,0,0,nfiles,times,names goodfile=WHERE(STRPOS(names,'___') EQ -1) IF MAX(goodfile) GE 0 THEN kill_list=[kill_list,names(goodfile)] ENDFOR ENDIF IF N_ELEMENTS(kill_list) GT 1 THEN BEGIN kill_list=kill_list(1:N_ELEMENTS(kill_list)-1) kill_list=rmcmd+kill_list PRINT,'Writing image deletion script for '+date ; rmname='/jasper/cnsr3_data1/rm'+date rmname=sroot+dd+'rm'+date+s_suffix OPENW,outunit,rmname,/GET_LUN IF dos $ THEN PRINTF,outunit,'@ECHO OFF' $ ELSE PRINTF,outunit,'#! /bin/csh -f' FOR i=0,N_ELEMENTS(kill_list)-1 DO PRINTF,outunit,kill_list(i) FREE_LUN,outunit IF NOT dos THEN BEGIN chmodcmd='chmod 0700 '+rmname SPAWN,chmodcmd ENDIF PRINT,'Deleting images from '+date SPAWN,rmname PRINT,'Checking whether script worked' wrilist,year,month,day PRINT,'Deleting script' SPAWN,rmcmd+rmname ENDIF ELSE BEGIN MESSAGE,'No image files found for '+date+'!',/INFORMATIONAL ENDELSE RETURN END