TABLE OF CONTENTS
::pwtk::write
SYNOPSIS
proc ::pwtk::write {args} {
USAGE
::pwtk::write ?-a? DATAFILE LINE
OPTION
- -a --- in the first call of write on a given datafile, open the datafile in append mode (default = "w", i.e., truncate-and-write)
ARGUMENTS
- DATAFILE --- name of the file for writing the data
- LINE --- line-of-data to write to the datafile
PURPOSE
"write" writes a line-of-data to a data file. If "write" is executed within the "scanpar" loops, the content of the line is prefixed with the list of scanning parameters. For example, the snipptet:
scanpar k {4 8} { scanpar ecut {20 30} { write energy.dat [pwo_totene scf.k$k.ecut$ecut.out] } }
writes the lines in the form: $k $ecut energy
SOURCE
variable write_fid variable scanpar variable scanparList # parse args set narg 2 set usage "?-a? datafile line" set options { {a "open the datafile in the append mode"} } parseOpt_ set mode [expr { $opt(a) ? "a" : "w"}] set datafile [lindex $args 0] set line [lindex $args 1] # write to datafile ifnotexist write_fid($datafile) { set write_fid($datafile) [open $datafile $mode] if { [info exists scanparList] } { # write the first line as a comment documenting what columns are" puts $write_fid($datafile) "# columns are: $scanparList data" } } if { [info exists scanparList] && [string trim $line] ne {} } { # do not write "$params {}" line foreach pn $scanparList { upvar $pn p ifexist p { append params "$p " } else { ifexist scanpar($pn) { append params "$scanpar($pn) " } } } set line [concat $params $line] } puts $write_fid($datafile) $line flush $write_fid($datafile) return $datafile }