;+ ;======================================================================== ;;; ;;; FILE NAME: @(#)par_get.pro 1.2 ;;; ;;; DESCRIPTION: A function to extract a parameter from an FTOOLS-style ;;; parameter file. ;;; ;;; AUTHOR: Scott Koch (tsk@astro.psu.edu) ;;; Copyright (C) 1999, Pennsylvania State University ;;; ;;; NOTES: Name of parameter is case sensitive. ;;; ;;; Status is set to 0 on success. ;;; ;;; If the name parameter is not found, a blank string ;;; is returned and status is set to -1. ;;; ;- ;======================================================================== FUNCTION Par_Get, parameter_file, parameter_name, status status = -1 ret = '' openr,unit,parameter_file,/GET_LUN, ERROR=err if (err NE 0) then $ message, 'Error opening parameter file: ' + parameter_file n = numlines(parameter_file) if (n EQ -1) then begin free_lun,unit message,'Parameter file is empty: ' + parameter_file endif lines = strarr(n) readf,unit,lines free_lun,unit ; Loop over each line in the parameter file. Lines which begin with '#' are comments. ; Each line should also have seven comma-separated fields. When we find a line where ; the parameter name matches the requested parameter EXACTLY, then extract ; the value of that parameter, convert it to the correct type, and return. for ii=0,n-1 do begin firstchar = strmid(lines[ii],0,1) if (firstchar NE '#') then begin tokens = str_sep(lines[ii],',') s = size(tokens) if (s[0] NE 1) then begin free_lun,unit message, 'Unrecognized format of parameter file' endif if (s[1] NE 7) then begin free_lun,unit message, 'Unrecognized format of parameter file' endif if(tokens[0] EQ parameter_name) then begin ret = tokens[3] ; Convert the return value to the correct data type case tokens[1] of 'b': ret = fix(ret) 'i': ret = fix(ret) 'r': ret = float(ret) 's': begin ; Strip quotes len = strlen(ret) pos = strpos(ret,'"') if (pos EQ 0) then ret = strmid(ret,1,len-1) len = strlen(ret) pos = strpos(ret,'"') if (pos EQ len-1) then ret = strmid(ret,0,len-1) end 'f': begin ; Strip quotes len = strlen(ret) pos = strpos(ret,'"') if (pos EQ 0) then ret = strmid(ret,1,len-1) len = strlen(ret) pos = strpos(ret,'"') if (pos EQ len-1) then ret = strmid(ret,0,len-1) end else: $ message,'Invalid parameter type found in parameter file: '+tokens[3] endcase status = 0 endif endif endfor RETURN, ret END