function read_amie_pipeline_cfg, cfg_file, logname ;+ ;$Log: ; ; NAME: ; read_amie_pipeline_cfg ; ; PURPOSE: ; Read into an array the AMIE pipeline configuration file ; ; CATEGORY: ; AMIE Calibration - part of 'amie_pipeline' ; ; CALLING SEQUENCE: ; cfg_contents = read_amie_pipeline_cfg (configuration_file, logname) ; ; INPUTS: ; configuration_file: string with the path and file name of the configuration file ; logname: path and name of the log file ; ; OPTIONAL INPUT PARAMETERS: ; None. ; ; OUTPUTS: ; array with configuration parameters ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; Hopefully none. ; ; RESTRICTIONS: ; None ; ; MODIFICATION HISTORY: ; 2004 Feb 06, MA: First version ; ; (c) 2004, Miguel Almeida, ESA/RSSD ;- ;------------------------------------------------------------------------------------------------------------------------- ; ;Reports the entry in the read_amie_pipeline_cfg module ; ;------------------------------------------------------------------------------------------------------------------------- create_log_entry, logname, '[CONFIGURATION READER] AMIE Pipeline entered configuration reader module' ;------------------------------------------------------------------------------------------------------------------------- ; ;initialize input and output directories array ; ;------------------------------------------------------------------------------------------------------------------------- cfg_content = strarr(8) ;------------------------------------------------------------------------------------------------------------------------- ; ;checks if the configuration file exits ; ;------------------------------------------------------------------------------------------------------------------------- if file_test(cfg_file) eq 0 then begin create_log_entry, logname, '[CONFIGURATION READER] [ERROR] NO CONFIGURATION FILE PRESENT' message, '[CONFIGURATION READER][ERROR] No configuration file present' endif ;------------------------------------------------------------------------------------------------------------------------- ; ;reads in config file and puts its values into a string array ; ;------------------------------------------------------------------------------------------------------------------------- openr, cfg_unit, cfg_file,/GET_LUN ;--------------------------------------------------------------------------------------------------------------------- ;counts the number of lines in the configuration file n_lines = file_lines(cfg_file) ;--------------------------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------------------------- ;creates array to store all the configuration file content cfg_array =strarr(n_lines) ;--------------------------------------------------------------------------------------------------------------------- readf, cfg_unit, cfg_array ;--------------------------------------------------------------------------------------------------------------------- ;Checks for the status of the file and report that it the configuration file was opened correctly cfg_file = fstat(cfg_unit) create_log_entry, logname, '[CONFIGURATION READER] Config file ' + cfg_file.name + ' read successfully.' ;--------------------------------------------------------------------------------------------------------------------- ;------------------------------------------------------------------------------------------------------------------------- ; ;Identifies the config file name, date and input and output directories for the pipeline ; ;------------------------------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------------------------- ;Cycle trough all the lines of the configuration file to search for the necessary information needed in the pipeline ; File name of the configuration file: for consistency porposes ; Configuration file date: for consistency porposes ; Raw Data directory: directory where the raw data to be calibrated is located ; Calibrated data directory: directory where the calibrated data will be located ; Master Dark Directory: directory where the master dark files are located ; Master Dark Index file: index file where all the master dark files are listed ; Index file Template: IDL template to read the the master dark files index ; Master Flat file: Master flat file to be used in the calibration pipeline ;--------------------------------------------------------------------------------------------------------------------- for line = 0, (n_lines - 1) do begin ;----------------------------------------------------------------------------------------------------------------- ;Explanation valid for all keywords ; In each of the lines, the program looks for the keyword, and if it finds it puts the value in an array ; variable or string array. ; ATTENTION: The keyword must be unique and its name shouldn't be contained in any of the other keyords ;----------------------------------------------------------------------------------------------------------------- cfg_filename_pos = strpos(cfg_array(line), 'NAME:') + 5 if cfg_filename_pos gt 4 then begin cfg_filename = strtrim(strmid(cfg_array(line), cfg_filename_pos),2) endif date_pos = strpos(cfg_array(line), 'DATE:') + 5 if date_pos gt 4 then begin cfg_file_date = strtrim(strmid(cfg_array(line), date_pos),2) create_log_entry, logname, '[CONFIGURATION READER] Configuration file date ' + cfg_file_date endif raw_pos = strpos(cfg_array(line), 'RAW DATA DIRECTORY:') + 19 if raw_pos gt 18 then begin cfg_content(0) = strtrim(strmid(cfg_array(line), raw_pos),2) create_log_entry, logname, '[CONFIGURATION READER] The pipeline calibrated data found on ' + cfg_content(0) endif cal_pos = strpos(cfg_array(line), 'CALIBRATED DATA DIRECTORY:') + 26 if cal_pos gt 25 then begin cfg_content(1) = strtrim(strmid(cfg_array(line), cal_pos),2) create_log_entry, logname, '[CONFIGURATION READER] The output directory for the calibrated data is ' + cfg_content(1) endif darkdir_pos = strpos(cfg_array(line), 'MASTER DARK DIRECTORY:') + 22 if darkdir_pos gt 21 then begin cfg_content(2) = strtrim(strmid(cfg_array(line), darkdir_pos),2) create_log_entry, logname, '[CONFIGURATION READER] The Master Darks directory is ' + cfg_content(2) endif darkind_pos = strpos(cfg_array(line), 'MASTER DARK INDEX FILE:') + 23 if darkind_pos gt 22 then begin cfg_content(3) = strtrim(strmid(cfg_array(line), darkind_pos),2) create_log_entry, logname, '[CONFIGURATION READER] The Master Dark index file is ' + cfg_content(3) endif ind_temp_pos = strpos(cfg_array(line), 'INDEX FILE TEMPLATE:') + 20 if ind_temp_pos gt 19 then begin cfg_content(4) = strtrim(strmid(cfg_array(line), ind_temp_pos),2) create_log_entry, logname, '[CONFIGURATION READER] The Master Dark index file template is ' + cfg_content(4) endif flat_pos = strpos(cfg_array(line), 'MASTER FLAT FILE:') + 17 if flat_pos gt 16 then begin cfg_content(5) = strtrim(strmid(cfg_array(line), flat_pos),2) create_log_entry, logname, '[CONFIGURATION READER] The Master Flat file is ' + cfg_content(5) endif ;; 2008 Jan 08, sm. MASTER BIAS DIRECTORY and TEMPERATURE DIRECTORY added ;; 2008 Jan 23, bg. changed MASTER BIAS DIRECTORY to FLIGHT DARK DIRECTORY biasdir_pos = strpos(cfg_array(line), 'FLIGHT DARK DIRECTORY:') + (strlen('FLIGHT DARK DIRECTORY:') + 1) if biasdir_pos gt strlen('FLIGHT DARK DIRECTORY:') then begin cfg_content(6) = strtrim(strmid(cfg_array(line), biasdir_pos),2) create_log_entry, logname, '[CONFIGURATION READER] The Master Bias and Dark Current directory is ' + cfg_content(6) endif temperaturedir_pos = strpos(cfg_array(line), 'TEMPERATURE DIRECTORY:') + (strlen('TEMPERATURE DIRECTORY:') + 1) if temperaturedir_pos gt strlen('TEMPERATURE DIRECTORY:') then begin cfg_content(7) = strtrim(strmid(cfg_array(line), temperaturedir_pos),2) create_log_entry, logname, '[CONFIGURATION READER] The Temperature Tables directory is ' + cfg_content(7) endif endfor ;------------------------------------------------------------------------------------------------------------------------- ; ;Test for configuration file consistency and write log entries ; ;------------------------------------------------------------------------------------------------------------------------- ;--------------------------------------------------------------------------------------------------------------------- ;Compare the configuration file loaded with the name of the file contained in the configuration file ; If the name is diferent flag with a warning in the log file ;--------------------------------------------------------------------------------------------------------------------- if cfg_file.name ne cfg_filename then begin create_log_entry, logname, '[WARNING] Configuration file name read INCONSISTENT with configuration file content' endif ;--------------------------------------------------------------------------------------------------------------------- ;Check the date in the configuration file ;--------------------------------------------------------------------------------------------------------------------- if strlen(cfg_file_date) ne 10 then begin create_log_entry, logname, '[WARNING] NO or INVALID date in the configuration file' cfg_file_date = '"N/A"' endif ;--------------------------------------------------------------------------------------------------------------------- ;Check if the raw images directory exits ;--------------------------------------------------------------------------------------------------------------------- if strlen(expand_path('+' + cfg_content(0), /all_dirs)) eq 0 then begin create_log_entry, logname, '[CONFIGURATION READER][ERROR] THE RAW IMAGES DIRECTORY SPECIFIED IN THE CONFIGURATION FILE DOES NOT EXIST' message, '[CONFIGURATION READER][ERROR] The raw images directory specified in the configuration file does not exist' endif ;There's no constraint to the output directory as it is created by the pipeline ;--------------------------------------------------------------------------------------------------------------------- ;Check the contents of the array containing the configuration file information to see if there's any information ;missing. If so, a long entry is created flagging it. ;--------------------------------------------------------------------------------------------------------------------- for content_line = 0, 5 do begin if cfg_content(content_line) eq '' then begin case content_line of 0: create_log_entry, logname, '[CONFIGURATION READER][ERROR] NO RAW DATA DIRECTORY DEFINED IN CONFIGURATION FILE' 1: create_log_entry, logname, '[CONFIGURATION READER][ERROR] NO CALIBRATED DATA DIRECTORY DEFINED IN CONFIGURATION FILE' 2: create_log_entry, logname, '[CONFIGURATION READER][ERROR] NO MASTER DARK DIRECTORY DEFINED IN CONFIGURATION FILE' 3: create_log_entry, logname, '[CONFIGURATION READER][ERROR] NO MASTER DARK INDEX DIRECTORY DEFINED IN CONFIGURATION FILE' 4: create_log_entry, logname, '[CONFIGURATION READER][ERROR] NO INDEX FILE TEMPLATE DEFINED IN CONFIGURATION FILE' 5: create_log_entry, logname, '[CONFIGURATION READER][ERROR] NO MASTER FLAT FILE DEFINED IN THE CONFIGURATION FILE' endcase message, '[CONFIGURATION READER][ERROR] The configuration file is incomplete, see log file for more details' endif endfor ;--------------------------------------------------------------------------------------------------------------------- ;Check if the configuration file contents are valid. If not flag it in the log file ;--------------------------------------------------------------------------------------------------------------------- ;TO COME ;------------------------------------------------------------------------------------------------------------------------- ; ;Return the directory names to the main program ; ;------------------------------------------------------------------------------------------------------------------------- close, cfg_unit free_lun, cfg_unit return, cfg_content end