TABLE OF CONTENTS
::pwtk::nebi::getImageCharge
SYNOPSIS
proc ::pwtk::nebi::getImageCharge {args} {
USAGE
::pwtk::nebi::getImageCharge [-k] index
OPTIONS
- -k ... prepend the "TOTAL_CHARGE" keyword
PURPOSE
Return the total_charge of the image #index (if it was specified, else an empty string is returned).
REMARK
This command is not related to the "num_of_images" variable!
ARGUMENTS
- index -- index of the image (index can be also "first" and "last"; the 1st image has index of 1)
RETURN VALUE
If -k option is specified, then getImageCharge returns:
TOTAL_CHARGE tot_charge
otherwise it returns:
tot_charge
If TOTAL_CHARGE is not defined, an empty string is returned/
SOURCE
set options { {k "include the TOTAL_CHARGE keyword line in the result"} } set usage ": ::pwtk::nebi::getImageCharge \[-k] index" array set opt [::cmdline::getoptions args $options $usage] if { [llength $args] != 1 } { ::pwtk::error "Usage $usage" 1 } set index [lindex $args 0] set nimages [getNImages] if { $nimages == 0 } { # no image specified ::pwtk::error "cannot get any image charge because POSITIONS/ATOMIC_POSITIONS card is undefined" 1 } set index [image_in_range_ $index $nimages] set iimage 0 set record 0 set charge {} foreach line [split [::pwtk::input::cardGetContent POSITIONS] \n] { if { [regexp {IMAGE} $line] } { incr iimage set record 0 } elseif { [regexp {ATOMIC_POSITIONS} $line] } { set record 0 } elseif { [regexp {CHARGE} $line] && $iimage == $index } { set record 1 if { $opt(k) } { append charge $line\n } continue } if { $record } { append charge $line\n } } return $charge }