PRO eae_fill_runids, in_rdb_file, out_rdb_file, VERBOSE = verbose ; ; ; Needed common when using cmdb... @cmdb_common ; Hardwired things: ; . . . . . . . . . . . . . . . . . . . . . . ; mapping from TRW_ID to run_id and date code eae_runid_file = !DDIDL+'/xrcf/eae_trw_mod.rdb' missing_ids_file = !DDHETGCAL+'/cmp/eae/missing_ids.list' ; . . . . . . . . . . . . . . . . . . . . . . ; Now go through this rdb file and add in the values of ; the MST date and run id ; Get cmdb integers if cmdb_using_cal then begin @cmdb_cal_integers end else begin @cmdb_trw_integers end ; load it in: if KEYWORD_SET(VERBOSE) then begin eae_rdb = rdb_read(in_rdb_file) end else begin eae_rdb = rdb_read(in_rdb_file,/SILENT) end if KEYWORD_SET(VERBOSE) then begin mst_runids = rdb_read(eae_runid_file) end else begin mst_runids = rdb_read(eae_runid_file,/SILENT) end ; Open file to list missing TRW IDs OPENW, missing_unit, missing_ids_file, /GET_LUN ; Check for valid lines in mst id file up front irig_ok = STRPOS(mst_runids.irig_start,'NULL') LT 0 ; Keep count of any new lines to be added: new_lines = 0 for ir=0,n_elements(eae_rdb)-1 do begin trwid = eae_rdb(ir).trw_id ; Find the matching TRW ID(s) where the irig_start is not NULL match = where(trwid EQ mst_runids.trwid AND $ irig_ok , n_match) if n_match GE 1 then begin if n_match EQ 1 then begin mst_index = match(0) end else begin ; ACTION if multiple: ; for multiple ones that are -EE- use most recent, ; otherwise add new lines if STRPOS(eae_rdb(ir).trw_id,'-EE-') GE 0 then begin mst_index = match(n_match-1) end else begin ; Here for multiple run ids ; load the first one the usual way mst_index = match(0) ; and create lines for the other trw ids eae_more = REPLICATE(eae_rdb(ir),n_elements(match)-1) for il=0,n_elements(eae_more)-1 do begin ; Now transfer the runid and date code eae_more(il).run_id = STRCOMPRESS(STRING(LONG(mst_runids(match(1+il)).runid)),/REMOVE) irig_str = mst_runids(match(1+il)).irig_start pieces = STR_SEP(irig_str,' ') date_pieces = STR_SEP(pieces(0),'/') if n_elements(date_pieces) EQ 3 then begin d_m = date_pieces(0) if STRLEN(d_m) EQ 1 then d_m = '0'+date_pieces(0) d_d = date_pieces(1) if STRLEN(d_d) EQ 1 then d_d = '0'+date_pieces(1) d_y = STRMID(date_pieces(2),2,2) date_str = d_y + d_m + d_d end else begin if STRPOS(pieces(0),'9') EQ 0 then begin date_str = pieces(0) end else begin print, 'For '+trwid+" didn't get 3 pieces from irig date: "+irig_str date_str = 'NULL' end end eae_more(il).mst_date = date_str if STRPOS(trwid,'C-') EQ 0 OR $ STRPOS(trwid,'D-') EQ 0 OR $ STRPOS(trwid,'E-') EQ 0 then begin eae_more(il).irig = mst_runids(match(il+1)).irig_start end end ; save these to be appended... if new_lines EQ 0 then begin eae_extra = eae_more end else begin eae_extra = [ eae_extra, eae_more ] end new_lines = new_lines + n_elements(eae_more) end ; PRINTING if multiple ; multiple TRW ID here if KEYWORD_SET(VERBOSE) then begin ; tell about multiple finds print, 'Found TRW ID ['+trwid+'] '+ $ STRCOMPRESS(STRING(n_match))+' times:' for im=0,n_match-1 do begin print, mst_runids(match(im)).trwid, mst_runids(match(im)).runid, $ mst_runids(match(im)).irig_start end ; if it is EE find and print the CMDB aperture string (for ; comparison with number of runids) if STRPOS(trwid,'-EE-') GE 0 then begin ap_str = '' cmdb_row = where(cmdb_fields(*,c_id) EQ trwid, nrow) if nrow GE 1 then begin ap_str = cmdb_fields(cmdb_row(nrow-1),c_hxda_aplist) ap_str = STRMID(ap_str,1,STRLEN(ap_str)-2) print, ' Aplist is: '+ap_str end end end else begin ; what WARNING to print if not verbose ; show multiple ones found that are not EE (which should be multiple) if NOT(STRPOS(eae_rdb(ir).trw_id,'-EE-') GE 0) then begin print, 'Found TRW ID ['+trwid+'] '+ $ STRCOMPRESS(STRING(n_match))+' times:' for im=0,n_match-1 do begin print, mst_runids(match(im)).trwid, mst_runids(match(im)).runid, $ mst_runids(match(im)).irig_start end end end end ; Now transfer the runid and date code eae_rdb(ir).run_id = STRCOMPRESS(STRING(LONG(mst_runids(mst_index).runid)),/REMOVE) irig_str = mst_runids(mst_index).irig_start pieces = STR_SEP(irig_str,' ') date_pieces = STR_SEP(pieces(0),'/') ; The string may be just the date code (970117) or it ; may be in 1997/03/01 format: if n_elements(date_pieces) EQ 3 then begin d_m = date_pieces(0) if STRLEN(d_m) EQ 1 then d_m = '0'+date_pieces(0) d_d = date_pieces(1) if STRLEN(d_d) EQ 1 then d_d = '0'+date_pieces(1) d_y = STRMID(date_pieces(2),2,2) date_str = d_y + d_m + d_d end else begin if STRPOS(pieces(0),'9') EQ 0 then begin date_str = pieces(0) end else begin print, 'For '+trwid+" didn't get 3 pieces from irig date: "+irig_str date_str = 'NULL' end end eae_rdb(ir).mst_date = date_str if STRPOS(trwid,'C-') EQ 0 OR $ STRPOS(trwid,'D-') EQ 0 OR $ STRPOS(trwid,'E-') EQ 0 then begin eae_rdb(ir).irig = mst_runids(mst_index).irig_start end end else begin ; if not found print warning in any case print, 'Could not find TRW ID ['+eae_rdb(ir).trw_id+'] in MST runid file' ; and add it to the missing file printf, missing_unit, eae_rdb(ir).trw_id end end ; Close the missing ids file CLOSE, missing_unit FREE_LUN, missing_unit if new_lines GT 0 then eae_rdb = [ eae_rdb , eae_extra ] ; all done so write it back out if KEYWORD_SET(VERBOSE) then begin rdb_write, out_rdb_file, eae_rdb end else begin rdb_write, out_rdb_file, eae_rdb, /SILENT end RETURN END