PRO cmdb_load, file_name ; 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 @cmdb_common print, '' ; Where is the file? ; The combination cmdb_file_path + cmdb_file gives the ; cmdb file to be read in. ; Wire in defaults ; default path is ... if n_elements(cmdb_file_path) LE 0 then cmdb_file_path = $ '/nfs/wiwaxia/h1/dd/idl/cmdb/Phase1/' if n_elements(file_name) EQ 1 then begin ; use supplied name cmdb_file = file_name end else begin if n_elements(cmdb_file) EQ 1 then begin ; use already defined value end else begin ; use default cmdb_file = 'grating_1a.trw' 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) for ic = 0, npieces-1 do begin cmdb_fields(ir,ic) = pieces(ic) end end ; looping through the lines RETURN END