PRO cmdb_load, file_name, FULL_XRCF=full_xrcf ; This procedure reads in a cmdb file and: ; puts each line into one-D array of strings: cmdb_lines(row) ; parses the fields into the two-D array: cmdb_fields(row,column) ; ; These arrays are kept in cmdb_common so that they can ; be available to many routines. ; cdb_common.pro defines the common variables ; ; 4/23/99 dd Added FULL_XRCF to reload the full XRCF CMDB... ; @cmdb_common print, '' ; Where is the file? ; The combination cmdb_file_path + cmdb_file gives the ; cmdb file to be read in. if n_elements(file_name) EQ 1 then begin ; use supplied name cmdb_file_path = '' cmdb_file = file_name end else begin if n_elements(cmdb_file) EQ 1 AND NOT(KEYWORD_SET(FULL_XRCF)) then begin ; use the already defined values end else begin ; use defaults from cmdb_start.pro cmdb_file_path = !DDCMDBDIR+'/' print, '' print, 'Using XRCF CMDB ...' print, '' cmdb_file = 'DRAFT_as_run.cmdb' end end ; --- Read in the CMDB file n_max = 5000 ;maximum entries line='' lines = STRARR(n_max) id = -1 OPENR, cmdb_unit, cmdb_file_path+cmdb_file, /GET_LUN WHILE(NOT EOF(cmdb_unit)) do begin READF, cmdb_unit, line ;; ; skip lines starting with a ; ;; if (strpos(line,';') NE 0) then begin id=id+1 lines(id) = line ;; end end CLOSE, cmdb_unit FREE_LUN, cmdb_unit n_rows = id+1 cmdb_lines = lines(0:id) ; Put all the fields into a STRING array, cmdb_fields ; delimiter is a TAB: TAB = STRING(9B) ; get number of columns from first row: pieces = STR_SEP(lines(0),TAB) n_cols = n_elements(pieces) print, '' print, 'CMDB_load:' print, ' File is '+cmdb_file_path+cmdb_file print, ' Number of rows = ', n_rows print, ' Number of columns = ', n_cols print, '' if STRPOS(cmdb_file, '.cal') GE 0 then begin integer_file = 'cmdb_cal_integers' cmdb_using_cal = (1 EQ 1) end else begin integer_file = 'cmdb_trw_integers' cmdb_using_cal = (1 EQ 0) end print, ' * Type @'+integer_file+' to have column ' print, ' integers available at command line.' print, '' ; Indices to fields are cmdb_fields(row, column) cmdb_fields = STRARR(n_rows, n_cols) ; Now load 'em in for ir=0,n_rows-1 do begin pieces = STR_SEP(lines(ir),TAB) npieces = n_elements(pieces) if npieces NE 92 then begin print, 'ir='+STRING(ir)+': npieces ='+STRING(npieces) end else begin for ic = 0, npieces-1 do begin cmdb_fields(ir,ic) = pieces(ic) end end end ; looping through the lines ; Define and load the cmdb_data structure ; CMDB_Entry = {cmdb_struct, ... } @cmdb_structure_defn ; Define the cmdb_data structure array: cmdb_data = REPLICATE(CMDB_Entry, n_elements(cmdb_lines)) ; Define the c_ integers if STRPOS(cmdb_file, '.cal') GE 0 then begin @cmdb_cal_integers end else begin @cmdb_trw_integers end ; Go through and set the values for il=0, n_elements(cmdb_data)-1 do begin ; Energy temp_real = 0.0 ; check for valid energy field... e_str = cmdb_fields(il, c_energy) if STRLEN(e_str) GE 1 AND e_str NE 'N/A' then begin READS, e_str, temp_real cmdb_data(il).Energy = temp_real end else begin ; energy string not valid... cmdb_data(il).Energy = 0.001 ; dummy value? end ; Flux temp_real = 0.0 ; check for valid flux field... f_str = cmdb_fields(il, c_flux) if STRLEN(f_str) GE 1 AND f_str NE 'N/A' then begin READS, f_str, temp_real cmdb_data(il).Flux = temp_real end else begin ; flux string not valid... cmdb_data(il).Flux = 0.0 ; dummy value? end ; Integration time temp_real = 0.0 READS, cmdb_fields(il, c_integ_time), temp_real cmdb_data(il).Integ_time = temp_real ; Estimated FP rate temp_real = 0.0 if cmdb_using_cal then begin if STRPOS(cmdb_fields(il, c_est_fp_rate), 'N') GE 0 then begin end else begin READS, cmdb_fields(il, c_est_fp_rate), temp_real end end cmdb_data(il).FP_rate = temp_real ; Voltage temp_real = 0.0 if STRPOS(cmdb_fields(il,c_voltage),'N') GE 0 then begin temp_real = 0.9 ; Penning end else begin READS, cmdb_fields(il, c_voltage), temp_real end cmdb_data(il).Voltage = temp_real ; Priority temp_int = 0 if STRPOS(cmdb_fields(il,c_priority),'N/A') GE 0 then begin temp_int = 0 end else begin READS, cmdb_fields(il, c_priority), temp_int end cmdb_data(il).Priority = temp_int ; Item temp_int = 0 READS, cmdb_fields(il, c_item), temp_int cmdb_data(il).Item = temp_int ; Suite temp_int = 0 READS, cmdb_fields(il, c_suite), temp_int cmdb_data(il).Suite = temp_int ; Order ; is an array of length 100 ; values of 999 indicate not set and value of 99 is ; for direct beam cmdb_data(il).Order = 999+intarr(100) if STRPOS(cmdb_fields(il,c_order),'N') GE 0 OR $ (cmdb_fields(il,c_order) EQ '') then begin ; order 99 is direct beam cmdb_data(il).Order = [99,999+intarr(99)] end else begin pieces = STR_SEP(cmdb_fields(il,c_order),',') temp_ord = INTARR(n_elements(pieces)) for ip = 0, n_elements(pieces)-1 do begin temp_int = 0 READS, pieces(ip), temp_int temp_ord(ip) = temp_int end cmdb_data(il).Order(0:n_elements(temp_ord)-1) = temp_ord end ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; *** Key Parameters *** ; ; periods of LEG, MEG, HEG: periods = [9912.50, 4008.00, 2000.00] ; Angstroms ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Set the period and angle for this measurement ; Period of -1.0 means we can't figure out the grating type or there ; is no grating present. CASE cmdb_fields(il, c_grating) OF 'NONE': begin period = -1.0 end 'LETG': begin period = periods(0) end 'HETG': begin period = -1.0 if STRPOS(cmdb_fields(il, c_shutter),'MEG') GE 0 then begin period = periods(1) end if STRPOS(cmdb_fields(il, c_shutter),'HEG') GE 0 then begin period = periods(2) end end ELSE: begin print, ' * unrecognized grating:'+cmdb_fields(il,c_grating) period = -1.0 end ENDCASE cmdb_data(il).period = period end ; Create ASC names from TRW names ; --> Add this to cmdb_load and to cmdb_common n_ids = n_elements(cmdb_fields(*,c_id)) cmdb_asc_ids = ' '+STRARR(n_ids) for id=0, n_ids-1 do begin trw_id = cmdb_fields(id,c_id) asc_id = STRLOWCASE(trw_id) ; remove "-" and "." s it = '.' where_is_it = STRPOS(asc_id,it) while where_is_it GE 0 do begin strput, asc_id, ' ', where_is_it where_is_it = STRPOS(asc_id,it) end it = '-' where_is_it = STRPOS(asc_id,it) while where_is_it GE 0 do begin strput, asc_id, ' ', where_is_it where_is_it = STRPOS(asc_id,it) end asc_id = STRCOMPRESS(asc_id,/REMOVE_ALL) ;; print, ' '+cmdb_fields(id,c_id)+' --> '+asc_id cmdb_asc_ids(id) = asc_id end RETURN END