TABLE OF CONTENTS
::pwtk::pwo::listing
SYNOPSIS
proc ::pwtk::pwo::listing {args} {
USAGE
::pwtk::pwo::listing [-by energy|force|totmag|press|dipole|COMMAND] [-increasing|-decreasing] filePattern ?filePattern ...?
PURPOSE
Return a sorted list, where each list element is a pair of output pw.x filename and the corresponding value extracted from the output file via the -by option, which is the criterion used for sorting.
EXAMPLE
The command: ::pwtk::pwo::listing -by energy -increasing relax.*out returns: {relax.rot_X-35_Z-40.out -229.09690231} {relax.rot_X-35_Z40.out -229.09687168} {relax.rot_X-35_Z35.out -229.09664108} ... where the numbers correspond to total energies.
OPTIONS
- -by CRITERIA ... by which criterion to sort (possibilities are energy, force, press, dipole, or user supplied COMMAND; defualt = energy); COMMAND specified with the -by option must be of the form analogous to ::pwtk::pwo::totene
- -increasing ... sort in increasing order
- -decreasing ... sort in decreasing order
The user COMMAND command specified by the -by option must be of the form analogous to ::pwtk::pwo::totene
ARGUMENTS
- filePattern ... a glob-style pattern for pw.x output files; it can also be a list of files
SOURCE
set options { {by.arg energy "criteria for sorting, allowed values are energy, force, totmag, press, dipole, or COMMAND"} {increasing "sort in increasing order"} {decreasing "sort in decreasing order"} } set usage ": pwtk::pwo::sortFiles \[-by energy|force|press|dipole] \[-increasing|-decreasing] filelist" array set opt [::cmdline::getoptions args $options $usage] set sort increasing if { $opt(increasing) && $opt(decreasing) } { ::pwtk::error "both -increasing and -decreasing option specified, please use only one" 1 } elseif { $opt(decreasing) } { set sort decreasing } switch -glob -- $opt(by) { ene* { set cmd ::pwtk::pwo::totene } for* { set cmd ::pwtk::pwo::totfor } totmag - mag* { set cmd ::pwtk::pwo::totmag } pre* { set cmd ::pwtk::pwo::press } dip* { set cmd ::pwtk::pwo::dipole } default { if { [info command $opt(by)] eq {} } { ::pwtk::error "the \"$opt(by)\" command specified with the -by option does not exist" 1 } set cmd $opt(by) } } if { [llength $args] == 1 } { set args {*}$args } set unsorted {} # construct and sort the "value pwo" list foreach pattern $args { foreach pwo [glob -nocomplain $pattern] { lappend unsorted [list $pwo [$cmd $pwo]] } } return [lsort -real -index 1 -$sort $unsorted] }