TABLE OF CONTENTS


::pwtk::readNml_w_affix

SYNOPSIS

proc ::pwtk::readNml_w_affix {fileChannel nmlOrigName {nmlPWTKname {}} {nmlList {}} {cardList {}} {must_exist 0} {match_first 0}} {

PURPOSE

Read the namelist.affix from the fileChannel of an opened QE input file and return its content in the PWTK syntax. The fileChannel is incremented to the point just after the namelist.

This routine is used internally by PWTK in load_from*** set of commands.

ARGUMENTS

REMARK

If both nmlList and cardList are empty, the affix card is assumed to extend till the EOF.

SIDE EFFECTS

If namelist is not present an error will be raised if $must_exist == true

RETURN VALUE

Namelist with affix in the PWTK syntax, e.g.,:

      NAMELIST { ... } { ... }    if affix exists

or

      NAMELIST { ... } { ... }    otherwise

SOURCE

    # read the namelist
    
    if { $nmlPWTKname eq {} } {
        set nmlName [string toupper $nmlOrigName]
    } else {
        set nmlName [string toupper $nmlPWTKname]
    }
    set nmlContent [::fnml::getContent $nmlOrigName $fileChannel $must_exist $match_first]
    # N.B. if the namelist is not found, $fileChannel is at [eof],
    # hence affix will be {}, which is correct !
    
    # prepare for reading the affix
    
    set nml_re  [::pwtk::nmlL2regexp $nmlList]
    set card_re [::pwtk::cardL2regexp $cardList]

    # read till the EOF or the first keyword
    
    set affix {}
    set offset [tell $fileChannel]
    while { ! [eof $fileChannel] } {
        set line [::pwtk::getNonEmptyLine $fileChannel]
        set first [::pwtk::firstWord $line]

        if { ($nml_re ne {} && [regexp -nocase $nml_re $first]) \
                 || ($card_re ne {} && [regexp $card_re $first]) } {
            seek $fileChannel $offset
            break
        }
        append affix $line\n
        set offset [tell $fileChannel]        
    }
    
    if { $affix ne {} } {
        return "$nmlName { [string trim $nmlContent] } { [string trim $affix] }\n"
    } else {
        if { $nmlContent ne {} } {
            return "$nmlName { [string trim $nmlContent] }\n"
        } else {
            return ""
        }
    }
}