pro remove_date_range, date1, date2 ;+ ; This routine removes entries from the CDS as-run catalog between two ; date/times to allow FITSGEN a clean slate to work from. ; ; 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 within the ; specified begin and end times. It will then look for these entries in the ; experiment2.db* and fexperiment2.db* databases, and delete them. 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 program number in the main database is set to a negative ; number, which is treated as a deletion. ; ;- ; on_error, 2 if n_params() ne 2 then message, 'Syntax: remove_date_range, date1, date2' tai1 = anytim2tai(date1) tai2 = anytim2tai(date2) ; ; 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 within the ; dbopen, 'main' dbext, -1, 'prog_num,date_obs,date_end', prog_num, date_obs, date_end w = where((date_obs lt tai2) and (date_end gt tai1) and (prog_num gt 0), count) if count eq 0 then message, 'No results found' 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. ; for iprog=0,n_elements(prog_num0)-1 do begin w = where(prog_num eq prog_num0[iprog], 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. ; if n_elements(entry1) gt 0 then dbdelete, entry1 dbclose ; ; Step to the next set of files. ; experfile = 'f' + experfile endfor ;iloop ; ; Step through the program numbers, and set the program numbers to be ; negative. ; dbopen, 'main', 1 for iprog=0,n_elements(prog_num0)-1 do begin entry = dbfind('prog_num='+ntrim(prog_num0[iprog])) dbupdate, entry, 'prog_num', -prog_num0[iprog] endfor ;iprog dbclose ; !priv = 0 return end