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
- fileChannel -- QE input file to read
- nmlOrigName -- name of the namelist to read from the fileChannel
- nmlPWTKname -- (optional) if not empty, replace nmlOrigName with nmlPWTKname in the returned PWTK formated namelist
- nmlList -- (optional) list of namelist names (use to query the end of affix); if empty, the affix card is assumed to extend till the EOF
- cardList -- (optional) list of card names (use to query the end of affix); if empty,
- must_exist -- (optional) must the namelists exist (default = no)
- match_first -- (optional) if true then the first non-empty line must start with the $nmlName word (default = 0)
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 "" } } }