TABLE OF CONTENTS


::pwtk::input::namelistGetVarValue

SYNOPSIS

proc ::pwtk::input::namelistGetVarValue {name args} {

USAGE

   ::pwtk::input::namelistGetVarValue name ?-nocase? varName ?trim?

PURPOSE

Get a value of a given namelist variable.

OPTION

ARGUMENTS

EXAMPLE

   set my_outdir [::pwtk::input::namelistGetVarValue CONTROL outdir]

RETURN VALUE

The value of the namelist "varName" variable or an empty string if the variable does not exist

SOURCE

    global pwtk::input::namelist
    
    if { ! [info exists pwtk::input::namelist($name) ] } { 
        # the $name namelist does not even exist !
        return "" 
    }

    set nocase 0
    if { [lindex $args 0] eq "-nocase" } {
        set nocase 1
        set args [lrange $args 1 end]
    }
    lassign $args varName trim

    if { $nocase } {
        # a nocase search of a variable
        set varName [::pwtk::input::namelistGetVarNoCase $name $varName]        
    }

    if { [info exists pwtk::input::namelist($name,var=$varName)] } {

        set value $pwtk::input::namelist($name,var=$varName)

        # check if the variables should be math-parsed as to evaluate
        # the math-expressions

        if { $value != {} && [::pwtk::queryMathParsing $name $varName] } {
            
            # parse only if $value is not yet double
            
            if { ! [string is double $value] } {
                set value [::pwtk::evalExpr $value]
            }
        } else {
            set value [trimValue_ $value $trim]
        }
        
        return $value
    }

    return ""
}