#
# TCL utility to read parameter values from keyword=value ASCII param files
# 

###########################################################################
# Given a file name, and a string, open the file and look for
# a line which starts with the given string.  
# 
# Ignore lines which start with a pound sign "#"
# 
# Return 
#     the rest of the line        [if we found the given string]
#     NULL                        [if we didn't find the string]
#     
proc get_param { file param } {
  global debug

  # this will be the return value
  set ret {}

  set fid [open $file "r"]
  while { [gets $fid line] != -1 } {

    if { [regexp #.* $line] == 1 } {
      if { $debug > 2 } {
        puts "get_param: skipping this line: $line"
      } 
      continue
    }
    if { [llength $line] < 2 } {
      continue
    }

    if { $debug > 2 } {
      puts "get_param: try this: $line"
    }

    set this_param [lindex $line 0]
    if { [string compare $param $this_param] != 0 } {
      continue
    }

    # okay, if we get here, then this line contains our desired parameter
    #   now, we need to figure out its value, and put that into "ret"
    set len [llength $line]
    set index 1
    while { $index < $len } {
      lappend ret [lindex $line $index]
      incr index
    }
    if { $debug > 2 } {
      puts "get_param: value is ..$ret.."
    }
    break

  }
  close $fid

  return $ret

}


