# environment_variables -- settings for running Quantum ESPRESSO examples

######## YOU MUST EDIT THIS FILE TO MATCH YOUR CONFIGURATION ########

# BIN_DIR = path of compiled executables
#     Usually this is $TOPDIR/bin, where $TOPDIR is the root of the
#     Quantum ESPRESSO source tree.
# PSEUDO_DIR = path of pseudopotentials required by the examples
#     If you have downloaded the full distribution, they should already
#     be in $TOPDIR/pseudo; otherwise you may download them from the
#     www.quantum-espresso.org web site
# TMP_DIR = temporary directory to be used by the examples
#     Make sure that it exists, is writable by you, and doesn't
#     contain any valuable data (everything there will be destroyed!).

# The following should be good in many cases 

PREFIX=`cd ../../.. ; pwd`
BIN_DIR=$PREFIX/bin
PSEUDO_DIR=$PREFIX/pseudo
NETWORK_PSEUDO=http://www.quantum-espresso.org/wp-content/uploads/upf_files/

# Beware: everything in $TMP_DIR will be destroyed !
TMP_DIR=$HOME/tmp

# wget or curl needed if some PP has to be downloaded from web site
# script wizard will surely find a better way to find what is available
if test "`which curl`" = "" ; then
   if test "`which wget`" = "" ; then
      echo "wget or curl not found: will not be able to download missing PP"
   else
      WGET="wget -O"
      # echo "wget found"
   fi
else
   WGET="curl -o"
   # echo "curl found"
fi

# To run the ESPRESSO programs on a parallel machine, you may have to
# add the appropriate commands (poe, mpirun, mpprun...) and/or options
# (specifying number of processors, pools...) before and after the
# executable's name.  That depends on how your machine is configured.
# For example on an IBM SP4:
#
#     poe             pw.x -procs 4              < file.in > file.out
#     ^^^ PARA_PREFIX      ^^^^^^^^ PARA_POSTFIX
#
# To run on a single processor, you can usually leave them empty.
# BEWARE: most tests and examples are devised to be run serially or on
# a small number of processors; do not use tests and examples to benchmark
# parallelism, do not run on too many processors

PARA_PREFIX="mpirun -np 8"
PARA_PREFIX=" "
#
# available flags: 
#                  -nimage n        number of images         (or -nimages)
#                  -npool  n        number of pools          (or -npools)
#                  -nband  n        number of band groups    (or -nb, -nbgrp,
#                                                            -nband_group )
#                  -ntask_groups n  number of task groups    (or -ntg)
#                  -ndiag n         number of processors for linear algebra 
#                                            (or -nproc_ortho, -northo, 
#                                                -nproc_diag) 
#
PARA_POSTFIX=" -nband 1 -ntg 1 "
#
# The following variables are used for image parallelization. 
# (See for instance PHonon/examples/Image_example) 
# NB: the number of processors in PARA_IMAGE_PREFIX is the product of the
# number of processors in PARA_PREFIX and the number of images in
# PARA_IMAGE_POSTFIX
#
PARA_IMAGE_PREFIX="mpirun -np 8"
PARA_IMAGE_POSTFIX="-nimage 4 $PARA_POSTFIX"

# function to test the exit status of a job
check_failure () {
    # usage: check_failure $?
    if test $1 != 0
    then
        $ECHO "Error condition encountered during test: exit status = $1"
        $ECHO "Aborting"
        exit 1
    fi
}

