TABLE OF CONTENTS


::pwtk::environ::environ

SYNOPSIS

proc ::pwtk::environ::environ {{mode {}}} {

PURPOSE

Activate or deactivate the ENVIRON plugin. If the SWITCH argument is omitted, the current ENVIRON status is queried, which can be "on" or "off".

USAGE

    environ on
 or
    environ off
 or
    environ restart
 or
    environ from_scratch
 or
    environ

DESCRIPTION

The 'environ' command can be called as:

environ on implies adding -environ to POSTFIX (e.g., pw.x --environ)

environ off implies removing -environ from POSTFIX

environ restart implies adding -environ to POSTFIX and setting ENVIRON { environ_restart = .true. }

environ from_scratch implies adding -environ to POSTFIX and setting ENVIRON { environ_restart = .false. }

WARNINGS

To use ENVIRON, QE needs to be compiled with Environ.

SOURCE

    if { ! [info exists ::pwtk::state(environ)] } {
        set ::pwtk::state(environ) off
    }
 
    if { $mode != {} } {
        if { $mode == "restart" } {
            ::pwtk::print "ENVIRON restart activated (environ_restart = .true.)\n"
            ENVIRON { environ_restart = .true. }
            set mode on
        } elseif { [string match *scratch $mode] } {
            ::pwtk::print "ENVIRON restart disabled (environ_restart = .false.)\n"
            ENVIRON { environ_restart = .false. }
            set mode on
        }
        if { ! [::pwtk::type::number fboolean $mode] } {
            pwtk::error "environ mode must be boolean, but got mode = $mode" 1
        }
        
        set postfix {}
        if { [info exists ::pwtk::RUNopt(POSTFIX)] } {
            set postfix $::pwtk::RUNopt(POSTFIX)
        }
        set ind [lsearch -regexp $postfix ^-+environ]
        
        if { $mode } {                        
            ::pwtk::print "ENVIRON mode is ON\n"
            set ::pwtk::state(environ) on
            # add -environ flag to POSTFIX
            if { $ind < 0 } {
                lappend ::pwtk::RUNopt(POSTFIX) -environ
            }                
        } else {
            ::pwtk::print "ENVIRON mode is OFF\n"
            set ::pwtk::state(environ) off
            set ::pwtk::RUNopt(POSTFIX) [lsearch -inline -all -not -regexp $postfix ^-+environ]            
        }
    }
    return $::pwtk::state(environ)
}