pro remove_newer_entries ;+ ; This routine removes entries from the CDS as-run catalog where the start ; time is many days after the start time of the program as a whole. This is ; how re-use of previously used program numbers is handled. ; ; Before running this program, one must first enter in the command !PRIV=3. ; This is to keep the program from being run accidently. At the end of the ; program, !PRIV will be reset to 0. ; ; You must also be in the directory containing the database files main*, ; experiment*, and fexperiment*. ; ; The first thing the program does is to create backups of the affected ; files, in case of problems. Normally, this should only be done once, and ; the program will ask whether you want to overwrite them if they already ; exist. ; ; The program first scans the main.db* database to look for entries where the ; begin and end times are more than 1e7 seconds apart. It will then look for ; these entries in the experiment2.db* and fexperiment2.db* databases, and ; delete any which start more than 1e7 seconds after the start of the ; observation as a whole. The [f]experiment1.db* and [f]experiment.db* files ; are untouched to keep the pointer system working correctly; orphaned entries ; in these databases are harmless. ; ; Finally, the start and end times for the revelant entries in the main.db* ; database are recalculated. If no relevant entries can be found, then the ; start time is set equal to the end time. ; ;- ; ; Make sure that !PRIV=3, and that the databases are in the current directory. ; if !priv lt 3 then message, '!PRIV must be 3 or greater' if not file_exist('main.dbd') then message, 'Must be in catalog directory' ; ; First, if not already done, make backup copies of the affected files. ; files = ['main.dbf', 'main.dbx', 'experiment2.dbf', 'experiment2.dbx', $ 'fexperiment2.dbf', 'fexperiment2.dbx'] if file_exist(files[0]+'.sav') then begin if xanswer('Do you want to overwrite the backup files?') then $ file_copy, files, files+'.sav', overwrite=1 end else file_copy, files, files+'.sav', overwrite=0 ; ; First, find entries in the MAIN database with anomalously long durations. ; dbopen, 'main' dbext, -1, 'prog_num,date_obs,date_end', prog_num, date_obs, date_end w = where((date_end-date_obs) gt 1e7) prog_num0 = prog_num[w] date_obs0 = date_obs[w] date_end0 = date_end[w] ; ; Step through the two varieties of database files. ; experfile = 'experiment2' for iloop = 0,1 do begin delvarx, entry1 dbopen, experfile[0], 1 dbext, -1, 'prog_num,date_obs', prog_num, date_obs ; ; Step through the program numbers, and find entries with anomalously delayed ; start times. ; for iprog=0,n_elements(prog_num0)-1 do begin w = where((prog_num eq prog_num0[iprog]) and $ ((date_obs-date_obs0[iprog]) gt 1e7), count) if count gt 0 then begin if n_elements(entry1) eq 0 then entry1 = w + 1 else $ entry1 = [entry1, w + 1] endif endfor ;iprog ; ; Delete the anomalous entries. ; dbdelete, entry1 dbclose ; ; Step to the next set of files. ; experfile = 'f' + experfile endfor ;iloop ; ; Step through the program numbers, and step again through the two varieties ; of database files to collect all the start and stop times. ; for iprog=0,n_elements(prog_num0)-1 do begin experfile = 'experiment2' delvarx, dmin, dmax for iloop = 0,1 do begin dbopen, experfile entry = dbfind('prog_num='+ntrim(prog_num0[iprog]), count=count) if count gt 0 then begin dbext, entry, 'date_obs,date_end', date_obs, date_end if n_elements(dmin) eq 0 then begin dmin = min(date_obs) dmax = max(date_end) end else begin dmin = dmin < min(date_obs) dmax = dmax > max(date_end) endelse endif ; ; Step to the next set of files. ; experfile = 'f' + experfile endfor ;iloop ; ; Update the entry in the MAIN database. ; dbopen, 'main', 1 entry = dbfind('prog_num='+ntrim(prog_num0[iprog])) if n_elements(dmin) eq 1 then $ dbupdate, entry, 'date_obs,date_end', dmin, dmax else begin dbext, entry, 'date_end', date_end dbupdate, entry, 'date_obs', date_end endelse dbclose endfor ;iprog ; !priv = 0 return end