TABLE OF CONTENTS


::pwtk::qe2pwtk

SYNOPSIS

proc ::pwtk::qe2pwtk {args} {

USAGE

   qe2pwtk ?-p program? inputFile

OPTION

ARGUMENT

PURPOSE

Transform a QE input into a PWTK script.

If the QE program is not explicitly specified with the -p option, PWTK attempts to make a best guess in converting the QE input into the PWTK script.

In contrast, if the program is explicitly specified, then an error is thrown if the syntax of the input file does not match.

RETURN VALUE

A QE input converted to a PWTK script

SOURCE

    variable prog2inNN
    variable plugin

    # parse command-line
    
    set narg 1
    set usage "?-p program? inputFile"
    set options {
        {p.arg {} "the name of the QE program (e.g. pw.x, pp.x...)"}
    }
    parseOpt_

    set inpFile $args
    ::pwtk::fileMustExist $inpFile [string trim "$opt(p) input"]

    # convert QE input to PWTK script
    
    ::pwtk::input::pushpop {
        if { $opt(p) ne {} } {
            # the -p option was specified
            
            set fullList [string tolower [concat [lsort [array names prog2inNN]] [lsort $plugin(list)]]]
            if { [string tolower $opt(p)] ni $fullList } {
                ::pwtk::error "\"$opt(p)\" is a non-supported QE program or plugin, must be one of [join $fullList {, }]" 1
            }

            if { $opt(p) eq "neb.x" } {
                # it's a neb.x input
                if { [catch {::pwtk::readNamelists $inpFile PATH 1}] } {
                    ::pwtk::error "input file \"$inpFile\" does not appear to be a neb.x input file" 1
                }
                return [qe2pwtk_nebi_ $inpFile]
            } else {
                # other input file
                load_from $opt(p) $inpFile

                if { [info exists ::pwtk::prog2inNN($opt(p)) ] } {
                    upvar $::pwtk::prog2inNN($opt(p))::input_flow_list_specs specs
                } else {
                    # plugin
                    upvar ::pwtk::${opt(p)}::input_flow_list_specs specs
                }
            }        
        } else {
            # implicit conversion via best guess
            
            if { ! [catch {::pwtk::readNamelists $inpFile PATH 1}] } {
                # it's a neb.x input
                return [qe2pwtk_nebi_ $inpFile]
            } else {
                # read input for all programs and plugins, except neb.x               
                foreach prog [array names prog2inNN] {
                    if { $prog ne "neb.x" } { lappend ilist $prog2inNN($prog) }
                }
                
                foreach x [concat $ilist $plugin(list)] {
                    set x ::pwtk::[namespace tail $x]

                    append QEnml_flow_list     "[varvalue ${x}::QEnml_flow_list] "
                    append QEcard_flow_list    "[varvalue ${x}::QEcard_flow_list] "
                    append QEcard_closing_list "[varvalue ${x}::QEcard_closing_list] "
                    
                    append namelist_flow_list  "[varvalue ${x}::namelist_flow_list] "
                    append card_flow_list      "[varvalue ${x}::card_flow_list] "
                    
                    append input_flow_list_specs "[varvalue ${x}::input_flow_list_specs] "
                    
                    array set QE2PWTKcard [array get ${x}::QE2PWTKcard]
                }
                ::pwtk::read_QEinput_ $inpFile \
                    $QEnml_flow_list $QEcard_flow_list $QEcard_closing_list \
                    $namelist_flow_list $card_flow_list $input_flow_list_specs \
                    QE2PWTKcard

                # this is a bit complicated, but preserves the order of input_flow_list
                set names {}
                foreach type_name $input_flow_list_specs {
                    lassign $type_name type name
                    if { [lsearch $names $name] < 0 } {
                        lappend names $name
                        lappend specs [list $type $name]
                    }
                }            
            }
        }
        
        foreach elem $specs {
            lassign $elem type name
            switch -glob $type {
                namelist* { append result [::pwtk::input::namelistGetPWTK $name] }
                card*     { append result [::pwtk::input::cardGetPWTK $name] }
            }
        }
    }
    return $result
}