#!/bin/csh
#
#   30 Mar 2012 - configuration script to set up GAMESS' compile/link
#
#   1. This script asks questions about FORTRAN, math libraries, and
#   message passing libraries.  The answers to these questions are
#   used by 'compall' and 'comp' and 'compddi' and 'lked', so those
#   scripts should not require additional customizations.
#
#   2. This script does ** NOT ** set up the 'rungms' execution script!
#   That must be attended to by hand, following comments inside it.
#
#            the following will always be set by this script.
set GMS_VERSION=''
set GMS_BUILD_DIR=''
set GMS_TARGET=''
set GMS_PATH=''
set GMS_FORTRAN=''
set GMS_MATHLIB=''
set GMS_DDI_COMM=''
#            the following may optionally be set to non-blank below,
#            but will be left uninitialized in many cases.
set GMS_MATHLIB_PATH=''
set GMS_GFORTRAN_VERNO=''
set GMS_IFORT_VERNO=''
set GMS_MKL_VERNO=''
set GMS_MAC_OSX_VERNO=''
set GMS_SUN_OS_VERNO=''
set GMS_SUN_FORT_VERNO=''
# PGI/Intel flags\
# - Linux 64
set GMS_L64_OPT=''
set GMS_LIN_FLAGS=''
# - LIN/WIN
set GMS_INT_OPT=''
set GMS_IPO_OPT=''
set GMS_PGI_OPT=''
set GMS_IPA_OPT=''
# - Windows
set GMS_WIN_OPT=''
set GMS_WIN_FLAGS=''
set GMS_WIN_TP=''
# PGI/Intel flags/
set GMS_BG_MODEL=''
set GMS_MPI_LIB=''
set GMS_MPI_PATH=''
set GMS_OFED_PATH=''
set GMS_ARMCI_PATH=''
#
#    ----- Step 1: get GMS_TARGET and GMS_PATH values -----
#
echo "This script asks a few questions, depending on your computer system,"
echo "to set up compiler names, libraries, message passing libraries,"
echo "and so forth."
echo " "
echo "You can quit at any time by pressing control-C, and then <return>."
echo " "
echo "Please open a second window by logging into your target machine,"
echo "in case this script asks you to 'type' a command to learn something"
echo "about your system software situation.  All such extra questions will"
echo "use the word 'type' to indicate it is a command for the other window."
echo " "
echo -n "After the new window is open, please hit <return> to go on."
set reply=$<
tput clear
#
echo "   GAMESS can compile on the following 32 bit or 64 bit machines:"
echo "axp64    - Alpha chip, native compiler, running Tru64 or Linux"
echo "cray-xt  - Cray's massively parallel system, running CNL"
echo "hpux32   - HP PA-RISC chips (old models only), running HP-UX"
echo "hpux64   - HP Intel or PA-RISC chips, running HP-UX"
echo "ibm32    - IBM (old models only), running AIX"
echo "ibm64    - IBM, Power3 chip or newer, running AIX or Linux"
echo "ibm64-sp - IBM SP parallel system, running AIX"
echo "ibm-bg   - IBM Blue Gene (P or L model), these are 32 bit systems"
echo "linux32  - Linux (any 32 bit distribution), for x86 (old systems only)"
echo "linux64  - Linux (any 64 bit distribution), for x86_64 or ia64 chips"
echo "           AMD/Intel chip Linux machines are sold by many companies"
echo "mac32    - Apple Mac, any chip, running OS X 10.4 or older"
echo "mac64    - Apple Mac, any chip, running OS X 10.5 or newer"
echo "sgi32    - Silicon Graphics Inc., MIPS chip only, running Irix"
echo "sgi64    - Silicon Graphics Inc., MIPS chip only, running Irix"
echo "sun32    - Sun ultraSPARC chips (old models only), running Solaris"
echo "sun64    - Sun ultraSPARC or Opteron chips, running Solaris"
echo "win32    - Windows 32-bit (Windows XP, Vista, 7, Compute Cluster, HPC Edition)"
echo "win64    - Windows 64-bit (Windows XP, Vista, 7, Compute Cluster, HPC Edition)"
echo "winazure - Windows Azure Cloud Platform running Windows 64-bit"
echo "    type 'uname -a' to partially clarify your computer's flavor."
echo -n "please enter your target machine name: "
set GMS_TARGET=$<
tput clear

#  A number of targets in compall/comp/lked are omitted above.
#  They are for old systems and/or not well tested systems, namely
#      cray-x1, cray-pvp, cray-t3e, cray-xd1,
#      fuji-pp32, fuji-pp64, necsx
#  These could be tried by creating a gamess.config which sets only
#  the basic variables GMS_PATH and GMS_TARGET...no other values
#  are looked at by these old compiling clauses, so just this:
#      #!/bin/csh
#      setenv GMS_TARGET fuji-pp64
#      setenv GMS_PATH /u1/mike/gamess

badgmspath:
echo "Where is the GAMESS software on your system?"
echo "A typical response might be /u1/mike/gamess,"
echo "most probably the correct answer is `pwd`"
echo " "
echo -n "GAMESS directory? [`pwd`] "
set GMS_PATH=$<
if (null$GMS_PATH == null) set GMS_PATH=`pwd`
#
if (-d $GMS_PATH) then
   tput clear
else
   echo "That directory name doesn't seem to exist, please try again."
   goto badgmspath
endif

echo "Setting up GAMESS compile and link for GMS_TARGET=$GMS_TARGET"
echo "GAMESS software is located at GMS_PATH=$GMS_PATH"
echo " "
#
badbuilddir:
echo "Please provide the name of the build locaation."
echo "This may be the same location as the GAMESS directory."
echo " "
echo -n "GAMESS build directory? [`pwd`] "
set GMS_BUILD_DIR=$<
if (null$GMS_BUILD_DIR == null) set GMS_BUILD_DIR=`pwd`
if (! -d $GMS_BUILD_DIR) then
	mkdir $GMS_BUILD_DIR
endif
if (! -d $GMS_BUILD_DIR/object) then
	mkdir $GMS_BUILD_DIR/object
endif
if (! -d $GMS_BUILD_DIR/tools) then
	mkdir $GMS_BUILD_DIR/tools
endif
if (! -d $GMS_BUILD_DIR/ddi) then
	mkdir $GMS_BUILD_DIR/ddi
endif
if (! -d $GMS_BUILD_DIR/tests) then
	mkdir $GMS_BUILD_DIR/tests
endif
echo " "

echo "Please provide a version number for the GAMESS executable."
echo "This will be used as the middle part of the binary's name,"
echo "for example: gamess.00.x"
echo ""
echo -n "Version? [00] "
set GMS_VERSION=$<
if(null$GMS_VERSION == null) set GMS_VERSION=00

tput clear

#
#    ----- Step 2: get compiler and math library values -----
#
#    We must set GMS_FORTRAN and GMS_MATHLIB for each target.
#    For vendor Unix, these may not need to be very precise.  As an
#    example, IBM sets the math library to simply "essl" as 'lked'
#    knows how to spell the correct incantation such as  '-lessl'.
#    For Linux, we ask enough questions to get very precise values,
#    as 'comp' and 'lked' don't otherwise know what to do.
#
#    Depending on the situation, we may set a few other values as well.
#
switch ($GMS_TARGET)

case axp64:

echo "    Compiling on 'axp64' is straightforward."
echo "This target assumes the use of the Digital/Compaq/HP compiler."
echo "The FORTRAN compiler is named 'f77' under OSF1/Tru64/Digital Unix,"
echo "The FORTRAN compiler is named 'fort' if you are running under Linux."
echo "These are the same even though the names are different."
echo "The math library named CXML or DXML will be used if that is installed,"
echo "otherwise a simple FORTRAN substitute will be used."
echo "So, there are no further questions about FORTRAN or math libraries."
#      the actual choices can be made by the 'comp' script, no need to ask.
set GMS_FORTRAN="f90"
if (`uname` == Linux) set GMS_FORTRAN="fort"
set GMS_MATHLIB="DXML/CXML"
breaksw

#       the two Cray systems do not use directly GMS_FORTRAN or GMS_MATHLIB,
#       so set them only generically here.

case cray-x1:

echo "Compilation on the Cray-X1 will use Cray FORTRAN and Cray math libraries"
echo "There are no further configuration questions."
set GMS_FORTRAN=ftn
set GMS_MATHLIB='system math library'
breaksw

#         'comp' and 'lked' show several compiler choices and arch choices.
#         It might be useful to set GMS_FORTRAN to the specific compiler,
#         and hardwire the 'ftn' alias to that instead?  The 'comp' script
#         shows richer choices than 'lked', not sure we know enough to try
#         this yet.  But most importantly, the DDI that works on the XT
#         line has not been merged into the main DDI development line, so
#         the DDI distributed with GAMESS simply DOES NOT WORK ON THE XT.
#
#         It may be useful to set a GMS_XT_MODEL to 3, 4, 5, or 6 here,
#         again to avoid hand-editing in comp/lked.
#         Probably I don't understand the math library choice, either,
#         is the ACML the only possibility?  It seems to be searched
#         for without any need to ask for its location, amen to that.
#
case cray-xt:

tput clear
echo "Compilation on the Cray-XT has no further questions."
echo " "
echo "The 'ftn' compiler is selected based on your module settings."
echo "This is best tested if your modules pick Portland Group compilers."
echo "The math library will be ACML.  DDI will run over Cray's MPI."
echo " "
echo "You probably should review the machine dimensions in 'compddi' to"
echo "match your number of nodes (MAXNODES), and cores/node (MAXCPUS)."
echo " "
echo -n "hit <return> after you have read this message."
set reply=$<
set GMS_FORTRAN=ftn
set GMS_MATHLIB=acml
set GMS_MPI_LIB=CrayXT
breaksw

#       it seems unlikely anyone has a PA-RISC box old enough to be hpux32,
#       but allow it, with a reminder that hpux64 might be a better choice.
#       GMS_FORTRAN and GMS_MATHLIB need be set only generically here.

case hpux32:

echo "Any HP-UX system is likely to function properly as 'hpux64'."
echo "Chances are that you should have selected the 64 bit target, to use"
echo "more than 2 GBytes of memory in a run.   Please rerun this script"
echo "if you decide to change your mind and choose 'hpux64'."
echo -n "hit <return> after you have read this message."
set reply=$<
#
case hpux64:

echo "    Compiling for $GMS_TARGET is straightforward."
echo "This target assumes the use of the HP's FORTRAN compiler: f90"
if ($GMS_TARGET == hpux32) echo "HP's math library will be used: libblas"
if ($GMS_TARGET == hpux64) echo "HP's math library will be used: veclib"
echo "So, there are no further questions about FORTRAN or math libraries."
#       the actual exact library names are chosen by the 'comp' script
set GMS_FORTRAN="f90"
if ($GMS_TARGET == hpux32) set GMS_MATHLIB="libblas"
if ($GMS_TARGET == hpux64) set GMS_MATHLIB="veclib"
breaksw

#       it seems unlikely anyone would have a machine old enough to be ibm32,
#       so warn that ibm32 is silly, then let it fall into the ibm64 stuff.
#       GMS_FORTRAN and GMS_MATHLIB need be set only generically here.

case ibm32:

echo "Any Power3 or newer chip is likely to function properly as 'ibm64'."
echo "Chances are that you should have selected the 64 bit target, to use"
echo "more than 2 GBytes of memory in a run.  This script is now changing"
echo "to 'ibm64' instead."
echo -n "hit <return> after you have read this message."
set reply=$<

case ibm64:

echo "    Compiling on IBM equipment is straightforward."
echo "The operating system may be AIX or Linux, either one will work."
echo "This target assumes the use of IBM's compiler, xlf"
echo "This target will use the ESSL math library, if that is installed,"
echo "or a slow FORTRAN substitute otherwise."
echo "So, there are no further questions about FORTRAN or math libraries."
set GMS_FORTRAN=xlf
set GMS_MATHLIB=essl
breaksw

#       the SP platform's scripting uses only GMS_PATH and GMS_TARGET,
#       and probably doesn't ever need to know anything else.
#       GMS_FORTRAN and GMS_MATHLIB need be set only generically here.

case ibm64-sp:

echo "The SP platform will use IBM's FORTRAN compiler xlf,"
echo "IBM's math library essl, and IBM's MPI/LAPI product poe."
echo "there are no further questions about this system."
set GMS_FORTRAN=mpxlf
set GMS_MATHLIB=essl
breaksw

#    IBM Blue Gene.  original model was L, current is P, but Q is coming.
#       Perhaps the only L model left is the one on ISU's campus, so L
#       scripting is pretty much specific to ours.
#       The P model is Intrepid at Argonne, but we certainly hope that
#       the scripting for the P works more generically.
case ibm-bg:

badbgmodel:
echo "The Blue Gene platform has two models, L (older) and P."
echo -n "Which model do you have? "
set GMS_BG_MODEL=$<
if ($GMS_BG_MODEL == l) set GMS_BG_MODEL=L
if ($GMS_BG_MODEL == p) set GMS_BG_MODEL=P
#
switch ($GMS_BG_MODEL)
   case L:
      echo "Scripting for BG/L is customized to Iowa State's old L model,"
      echo "which does not have the ESSL library, so we use Goto's BLAS."
      set GMS_FORTRAN=blrts_xlf
      set GMS_BG_C=blrts_xlc
      set GMS_MATHLIB=goto
      echo " "
      echo "The messaging layer will be ARMCI 1.4, built by the user (you),"
      echo "after obtaining the ARMCI software from PNNL:"
      echo "    http://www.emsl.pnl.gov/docs/parsoft/armci/download.htm"
      echo "The ARMCI library is created by executing this command:"
      echo "    make TARGET=BGL ARMCI_NETWORK=BGMLMPI MSGCOMMS=MPI CC=mpicc"
      echo "Where did you install ARMCI?  The location is something like"
      echo "    /some/path/leading/up/to/armci-1-4"
      echo -n "ARMCI path name? "
      set GMS_ARMCI_PATH=$<
      #  note, ARMCI include files are located at $GMS_ARMCI_PATH/src
      if (-e $GMS_ARMCI_PATH/lib/BGL/libarmci.a) then
         echo "The ARMCI library already exists, good."
      else
         echo " "
         echo "The ARMCI library does not yet exist, unfortunately."
         echo "The command above should create an ARMCI library named"
         echo "    $GMS_ARMCI_PATH/lib/BGL/libarmci.a"
         echo "Please build ARMCI immediately after running this 'config',"
         echo "before proceeding to GAMESS' compall/compddi/lked steps."
         echo " "
         echo -n "hit <return> to continue after digesting this message."
         set reply=$<
      endif
      breaksw
   case P:
      echo "Scripting for BG/P uses IBM's node-specific FORTRAN,"
      echo "IBM's ESSL math library, and IBM's MPI library."
      set GMS_FORTRAN=bgxlf_r
      set GMS_BG_C=bgxlc_r
      set GMS_MATHLIB=essl
      breaksw
   default:
      echo "You didn't provide a valid Blue Gene model name, try again."
      echo " "
      goto badbgmodel
      breaksw
endsw
echo " "
echo "You may wish to execute the following script"
echo "     chdir ~/gamess"
echo "     ./machines/ibm-bg/ibmbg.size"
echo "to remove memory for EFP and PCM solvation models from the binary,"
echo "before proceeding to GAMESS' compall/compddi/lked steps."
echo "This saves memory on the BG nodes for gas phase calculations,"
echo "if you do not intend to run solvated systems."
echo " "
echo -n "hit <return> to continue after digesting this message."
set reply=$<
#
echo " "
echo "The Blue Gene platform will use IBM's FORTRAN compiler, $GMS_FORTRAN"
echo "The Blue Gene platform will use IBM's C compiler, $GMS_BG_C"
if ($GMS_BG_MODEL == L) then
   echo "The math library will be Goto's BLAS library"
else
   echo "The math library will be IBM's $GMS_MATHLIB"
endif
echo " "
echo "You probably should review the machine dimensions in 'compddi' to"
echo "match your number of nodes (MAXNODES)."
echo "There are no further questions about this system."
#         next one is just for purpose of printing inside this script.
unset GMS_BG_C
breaksw

case linux32:
case linux64:

#
#    for Linux, we have to get a FORTRAN choice, and a math library choice.
#        The lack of a single compiler or library choice in Linux is in
#        fact the major motivation for this configuration script.
badlinuxfortran:
echo "Linux offers many choices for FORTRAN compilers, including the GNU"
echo "compiler set ('g77' in old versions of Linux, or 'gfortran' in"
echo "current versions), which are included for free in Unix distributions."
echo " "
echo "There are also commercial compilers, namely Intel's 'ifort',"
echo "Portland Group's 'pgfortran', and Pathscale's 'pathf90'.  The last"
echo "two are not common, and aren't as well tested as the others."
echo " "
echo "type 'rpm -aq | grep gcc' to check on all GNU compilers, including gcc"
echo "type 'which gfortran'  to look for GNU's gfortran (a very good choice),"
echo "type 'which g77'       to look for GNU's g77,"
echo "type 'which ifort'     to look for Intel's compiler,"
echo "type 'which pgfortran' to look for Portland Group's compiler,"
echo "type 'which pathf90'   to look for Pathscale's compiler."
echo -n "Please enter your choice of FORTRAN: "
set GMS_FORTRAN=$<
echo " "

switch ($GMS_FORTRAN)
   case g77:
      #       we expect this choice only on rather old 32 bit kernels
      set GMS_TARGET=linux32
      echo "g77 does not support unit numbers higher than 99,"
      echo "    so runtyp=tdhfx jobs will fail"
      echo "g77 does not support quadruple precision,"
      echo "    so heavy element DK3 resolution of the identity will fail"
      echo "but everything else will work."
      echo "g77 will use target=linux32."
      breaksw
   case gfortran:
      echo "gfortran is very robust, so this is a wise choice."
      echo " "
      echo "Please type 'gfortran -dumpversion' or else 'gfortran -v' to"
      echo "detect the version number of your gfortran."
      echo "This reply should be a string with at least two decimal points,"
      echo "such as 4.1.2 or 4.6.1, or maybe even 4.4.2-12."
      echo "The reply may be labeled as a 'gcc' version,"
      echo "but it is really your gfortran version."
      echo -n "Please enter only the first decimal place, such as 4.1 or 4.6: "
      echo " "
      set GMS_GFORTRAN_VERNO=$<
      #
      switch ($GMS_GFORTRAN_VERNO)
         case 4.1:
         case 4.2:
         case 4.3:
         case 4.4:
         case 4.5:
            echo "   Alas, your version of gfortran does not support REAL*16,"
            echo "   so relativistic integrals cannot use quadruple precision."
            echo "   Other than this, everything will work properly."
            breaksw
         case 4.6:
            echo "   Good, the newest gfortran can compile REAL*16 data type."
            breaksw
         default:
            echo "The gfortran version number is not recognized."
            echo "It should only have one decimal place, such as 4.x"
            exit 4
            breaksw
      endsw
      breaksw
   case ifort:
      #  ifort was called ifc or efc before version 8, lets ignore that now.
      #  -assume byterecl compile flag appeared at version 8
      #  -vec-report0 compile flag appeared at version 10
      #  -Vaxlib library disappeared at version 10
      #  compilers and math library were bundled together at version 11,
      #  under completely different path names.
      #  version 12 in 2011: "composerxe" bundles which can include Intel MPI!
      echo "Use of 'ifort' requires additional information since library"
      echo "names, and compiler flags, are very version number specific."
      echo "note: ifort's directory tree is typically"
      echo "         /opt/intel/fc"
      echo "         /opt/intel/fce"
      echo "         /opt/intel/Compiler"
      echo "         /opt/intel/composerxe     (et cetera)."
      echo " "
      echo "Type 'which ifort' and note the version number in its pathname."
      echo "In case of the newer 'composerxe' bundles, the version is not"
      echo "shown in the pathname, but can be obtained by 'ifort -V'."
      echo " "
      echo "Enter only the main version number, such as 8, 9, 10, 11, 12."
      echo -n "Version? "
      set GMS_IFORT_VERNO=$<
      if ($GMS_IFORT_VERNO == 12) then
         echo "Caution: ifort 12.0 fails to read MOINTS disk file correctly."
         echo "Please update to 12.0.1 if 'ifort -V' replies just 12.0"
         echo -n "hit <return> to continue after digesting this message."
         set reply=$<
         echo " "
      endif
      breaksw
   case pgfortran:
   case pgf77:
      echo "pgfortran does not support quadruple precision,"
      echo "      so heavy element DK3 resolution of the identity will fail"
      echo "but everything else should work."
      echo " "
      echo "This compiler is not commonly used with GAMESS, so"
      echo "please be careful verifying the test examples all work."
      echo "pgfortran will use target=linux64."
      echo " "
      set GMS_LIN_FLAGS="'-V '"
      echo " "
      echo "Compiler Optimization Level"
      echo "---------------------------"
      echo "'default'     - default optimization settings -fastsse -Mipa=fast,safe "
      echo "'testing'     - for testing and development"
      echo -n "Compiler Optimization Level?: "
      set GMS_L64_OPT=$<
      if ($GMS_L64_OPT == testing) then
        echo "Testing"
        echo "-------"
        echo " "
        echo " "
        echo "'testing'  - modify variables GMS_PGI_OPT, GMS_IPA_OPT in install.info to"
        echo "             your needs."
        echo " "
        set GMS_PGI_OPT="'-O3            '    #default optimization flag, add/change if desired"
        set GMS_IPA_OPT="'-Mipa=fast,safe'    #default optimization flag, add/change if desired"
        echo " "
      else
        set GMS_L64_OPT='default'
        echo " "
      endif
      breaksw
   case pathf90:
      #       we only know how to use this one for 64 bit kernels
      echo "This compiler is not commonly used with GAMESS, so"
      echo "please be careful verifying the test examples all work."
      echo "pathf90 will use target=linux64."
      set GMS_TARGET=linux64
      breaksw
   default:
      echo "You didn't provide a valid FORTRAN compiler name, try again."
      echo " "
      goto badlinuxfortran
      breaksw
endsw
echo -n "hit <return> to continue to the math library setup."
set reply=$<
#
#         we are still doing linux32/linux64, now choosing math library
tput clear
badlinuxmathlib:
echo "Linux distributions do not include a standard math library."
echo " "
echo "There are several reasonable add-on library choices,"
echo "       MKL from Intel           for 32 or 64 bit Linux (very fast)"
echo "      ACML from AMD             for 32 or 64 bit Linux (free)"
echo "     ATLAS from www.rpmfind.net for 32 or 64 bit Linux (free)"
echo "and one very unreasonable option, namely 'none', which will use"
echo "some slow FORTRAN routines supplied with GAMESS.  Choosing 'none'"
echo "will run MP2 jobs 2x slower, or CCSD(T) jobs 5x slower."
echo " "
echo "Some typical places (but not the only ones) to find math libraries are"
   echo "Type 'ls /opt/intel/mkl'                 to look for MKL"
   echo "Type 'ls /opt/intel/Compiler/mkl'        to look for MKL"
   echo "Type 'ls /opt/intel/composerxe/mkl'      to look for MKL"
   echo "Type 'ls -d /opt/acml*'                  to look for ACML"
   echo "Type 'ls -d /usr/local/acml*'            to look for ACML"
if ($GMS_TARGET == linux32) then
   echo "Type 'ls /usr/lib/atlas'                 to look for Atlas"
else
   echo "Type 'ls /usr/lib64/atlas'               to look for Atlas"
endif
echo " "
echo -n "Enter your choice of 'mkl' or 'atlas' or 'acml' or 'none': "
set GMS_MATHLIB=$<
#
switch ($GMS_MATHLIB)
   case none:
      set GMS_MATHLIB_PATH=''
      breaksw
   case mkl:
      echo " "
      #
      badmkl:
      echo "The exact MKL libraries needed depend on its version number."
      echo "First, where is your MKL software installed?  For example"
      echo "            /opt/intel/mkl                    -or-"
      echo "            /opt/intel/Compiler/mkl           -or-"
      echo "            /opt/intel/composerxe/mkl         -or-"
      echo "            /your/sites/nonstandard/path/mkl"
      echo "Don't enter anything past the mkl subdirectory pathname."
      echo -n "MKL pathname? "
      set mklhead=$<
      if (!(-d $mklhead)) then
         echo " "
         echo "The directory $mklhead does not exist."
         echo " "
         goto badmkl
      endif
      #
      echo "Second, it is possible to have multiple version of MKL"
      echo "installed, but often there is only one version installed."
      echo "Your system seems to have the following version(s):"
      echo " "
      ls $mklhead
      echo " "
      echo "a) If the above output contains one or more version number,"
      echo "enter the specific version you prefer, giving all decimals."
      echo "b) If the above output contains paths like 'bin' and 'lib',"
      echo "enter the word 'skip' next."
      echo -n "MKL version (or 'skip')? "
      set version=$<
      if ($version == skip) then
#           for now there is only one 'composerxe' release, i.e. 2011,
#           The MKL version in compozserxe-2011 was '9', but that
#           was shown only during the installation process.
#           I do not know how to dig it up later on, by a normal user.
#               In future, maybe the MKL and ifort versions match?
#           At least, that is a trick we used here, 'v12' MKL is fictitious,
#           but later scripts will use it as a label for 2011's composerxe!
         set mklroot=$mklhead/lib
         set version=12
      else
      set mklroot=undefined
      if ($mklhead == /opt/intel/Compiler) then
                # when MKL is installed with the compilers.
                # I haven't seen one of these yet, it could be that the
                # number below /opt/intel/Compiler is the compiler version,
                # and the next number is the MKL version itself???
         echo "New MKL libraries include a minor version as well,"
         echo "which is/are the following on your machine:"
         ls $mklhead/$version
         echo -n "Enter one of the minor versions listed above: "
         set minor=$<
         set mklroot=$mklhead/$version/$minor/mkl/lib
      else
                # when MKL is installed as a separate product.
         set mklroot=$mklhead/$version/lib
      endif
      endif
      #            either way, we have now found the spot, be certain!
      if (!(-d $mklroot)) then
         echo "Your choices say MKL software should exist at"
         echo "      $mklroot"
         echo "but this does not seem to exist on your system."
         echo " "
         echo "Please try again..."
         goto badmkl
      endif
      #    The library files needed depend only on the major version number.
      #    get major version number, as many as three decimal places may exist
      set GMS_MKL_VERNO=$version:r
      set GMS_MKL_VERNO=$GMS_MKL_VERNO:r
      set GMS_MKL_VERNO=$GMS_MKL_VERNO:r
      #
      #    lib path for MKL also has chip-specific parts
      #    Ubuntu uses the non-standard -m flag, its -p replies "unknown"
                            set chip=`uname -p`
      if ($chip == unknown) set chip=`uname -m`
      switch ($chip)
         case i386:
         case i686:
            set GMS_MATHLIB_PATH=$mklroot/32
            breaksw
         case x86_64:
            set GMS_MATHLIB_PATH=$mklroot/em64t
            if ($GMS_MKL_VERNO >= 12) set GMS_MATHLIB_PATH=$mklroot/intel64
            breaksw
         case ia64:
            set GMS_MATHLIB_PATH=$mklroot/64
            breaksw
         default:
            echo "Something went wrong with automatic chip type detection"
            exit
            breaksw
      endsw
      #
      #    as of MKL version 10, we can explicitly link serial-only libraries.
      if($GMS_MKL_VERNO <= 9) then
         echo " "
         echo "MKL, up to and including version 9, requires the following"
         echo "setting at run time:   setenv MKL_SERIAL yes   (in 'rungms')"
         echo "in order to defeat openMP thread usage by the MKL library."
         echo " "
         echo -n "hit <return> after you have digested this warning. "
         set reply=$<
         endif
      breaksw

   case atlas:
      #    suggest the install dir for Fedora RPMs as likely spots...
      badatlas:
      echo "Where is your Atlas math library installed?  A likely place is"
      if ($GMS_TARGET == linux32) echo "   /usr/lib/atlas"
      if ($GMS_TARGET == linux64) echo "   /usr/lib64/atlas"
      echo -n "Please enter the Atlas subdirectory on your system: "
      set GMS_MATHLIB_PATH=$<
      if (-d $GMS_MATHLIB_PATH) then
      else
         echo " "
         echo "The directory $GMS_MATHLIB_PATH does not exist."
         echo " "
         goto badatlas
      endif
      #
      if (-e $GMS_MATHLIB_PATH/libatlas.so) then
      else
         echo " "
         echo "The linking step in GAMESS assumes that a softlink exists"
         echo "within the system's $GMS_MATHLIB_PATH"
         echo "   from libatlas.so   to a specific file like libatlas.so.3.0"
         echo "   from libf77blas.so to a specific file like libf77blas.so.3.0"
         echo "config can carry on for the moment, but the 'root' user should"
         echo "   chdir $GMS_MATHLIB_PATH"
         echo "   ln -s libf77blas.so.3.0 libf77blas.so"
         echo "   ln -s libatlas.so.3.0   libatlas.so"
         echo "prior to the linking of GAMESS to a binary executable."
         echo " "
      endif
      breaksw

#         note: acml5.0.0 requires gfortran 4.6
#               acml4.4.0 can work with gfortran 4.4
#      this compiler/library compatibility requirement is not tested for here!
#
   case acml:
      badacml:
      echo "Type 'ls -d /opt/acml*' or 'ls -d /usr/local/acml*'"
      echo "and note the the full path, which includes a version number."
      echo -n "enter this full pathname: "
      set acmlpath=$<
      if (!(-d $acmlpath)) then
         echo " "
         echo "The directory $acmlpath does not exist."
         echo " "
         goto badacml
      endif
      #     ACML pathnames involve the compiler and the bits, for example:
      #       /opt/acml4.4.0/gfortran32/lib         for 32 bits
      #       /opt/acml4.4.0/gfortran64_int64/lib   for 64 bits
      switch ($GMS_FORTRAN)
         case gfortran:
            set GMS_MATHLIB_PATH=$acmlpath/gfortran
            breaksw
         case ifort:
            set GMS_MATHLIB_PATH=$acmlpath/ifort
            breaksw
         case pathf90:
            set GMS_MATHLIB_PATH=$acmlpath/pathscale
            breaksw
         case pgfortran:
         case pgf77:
            set GMS_MATHLIB_PATH=$acmlpath/pgi
            breaksw
         default:
            echo "unknown FORTRAN compiler at ACML setup"
            exit
            breaksw
      endsw
#         32 bits is simple, but for 64 bits we require
#         both 64 bit address space and 64 bit args.
      if ($GMS_TARGET == linux32) then
         set GMS_MATHLIB_PATH=${GMS_MATHLIB_PATH}32
      else
         set GMS_MATHLIB_PATH=${GMS_MATHLIB_PATH}64_int64
      endif
#         and then the final component of the path name is just 'lib'.
      set GMS_MATHLIB_PATH=$GMS_MATHLIB_PATH/lib
      if (!(-d $GMS_MATHLIB_PATH)) then
         echo "The target=$GMS_TARGET and FORTRAN compiler=$GMS_FORTRAN"
         echo "requires ACML libraries in directory $GMS_MATHLIB_PATH,"
         echo "but this does not seem to exist."
         echo "Please download this from www.amd.com/acml, then try again."
         exit 33
      endif
      breaksw

   default:
      echo "You didn't provide a valid math library name, try again."
      echo " "
      goto badlinuxmathlib
      breaksw
#
endsw
echo "Math library '$GMS_MATHLIB' will be taken from $GMS_MATHLIB_PATH"
breaksw
#       just above has finally ended the very long linux32/linux64 section

#       Apple 32/64 bit, using Gnu compilers and Framework
#       the GMS_MATHLIB string is set only generically for Apple.
case mac32:

echo "Compiling on Apple equipment is straightforward."
echo "Information about installing FORTRAN can be found in the 'comp' script."
echo " "
echo "32 bit compilation can use 'gfortran' under 10.5, or 'g77' under any."
echo -n "Please enter your choice 'g77' or 'gfortran': "
set GMS_FORTRAN=$<
echo " "
echo "This target will use the vecLib framework math library, standard in OS X."
echo "If your OS X is 10.5 or higher, consider switching to the 'mac64' target."
set GMS_MATHLIB=vecLib
breaksw

case mac64:

tput clear

echo "Compiling on Apple equipment is straightforward."
echo " "
echo "This target assumes the use of the GNU compilers, gfortran/gcc."
echo "Information about first installing xcode from Apple, to get gcc,"
echo "and then obtaining a precompiled gfortran for your Apple OS X version"
echo "can be found in the 'comp' script."
echo " "
set GMS_FORTRAN=gfortran
set GMS_MATHLIB=vecLib
#
echo "Please type 'gfortran -dumpversion' or else 'gfortran -v' to"
echo "detect the version number of your gfortran."
echo "This reply should be a string with at least two decimal points,"
echo "such as 4.1.2 or 4.6.1, or maybe even 4.4.2-12."
echo "The reply may be labeled as a 'gcc' version,"
echo "but it is really your gfortran version."
echo -n "Please enter only the first decimal place, such as 4.1 or 4.6: "
echo " "
set GMS_GFORTRAN_VERNO=$<
#
switch ($GMS_GFORTRAN_VERNO)
   case 4.1:
   case 4.2:
   case 4.3:
   case 4.4:
   case 4.5:
      echo "   Alas, your version of gfortran does not support REAL*16,"
      echo "   so relativistic integrals cannot use quadruple precision."
      echo "   Other than this, everything will work properly."
      breaksw
   case 4.6:
      echo "   Good, the newest gfortran can compile REAL*16 data type."
      breaksw
   default:
      echo "The gfortran version number is not recognized."
      echo "It should only have one decimal place, such as 4.x"
      exit 4
      breaksw
endsw
#
set osxver=`/usr/bin/sw_vers -productVersion`
set osxver=$osxver:r
#
switch ($osxver)
   case 10.0:
   case 10.1:
   case 10.2:
   case 10.3:
#          10.4 was partly 64-bit, but it didn't work very well,
#          so this is placed with the older 32 bit systems.
   case 10.4:
     echo "you appear to be running Mac OS X version $osxver"
     echo "this is too old to allow 64-bit GAMESS compilation."
     echo "Please select the 'mac32' target instead..."
     exit
     breaksw
   case 10.5:
   case 10.6:
     echo " "
     echo "This target will use the vecLib framework math library,"
     echo "which is standard in OS X."
     breaksw
   case 10.7:
     echo " "
     echo "Alas, you are running Lion."
     echo "This target will not use Apple's vecLib math library,"
     echo "since Lion versions up to at least 10.7.2 fail to work."
     echo "Some slow but correct FORTRAN code will be used instead,"
     echo "with significant performance penalties for MP2/CC runs."
     set GMS_MATHLIB='blas.o'
     breaksw
   default:
     echo " "
     echo "OS X version number is unrecognized: $osxver"
     echo "You may experience problems, will attempt to build for Lion."
     set osxver='10.7'
     breaksw
endsw
set GMS_MAC_OSX_VERNO=$osxver
#

breaksw

#       GMS_MATHLIB need be set only generically for SGI.
case sgi32:
case sgi64:

echo "This compiling target means a MIPS-based computer running IRIX."
echo "These old systems have names like Indy or Origin or Challenge."
echo "         SGI has not sold these in many years! "
echo "If you have a newer system from SGI, named Altix or XE or ICE,"
echo "with Intel processors, it will be running a version of Linux."
echo "For these current SGI systems, the correct target is 'linux64'."
echo " "
echo "Please hit <control-C>, then <return> to exit, to change to 'linux64'."
echo -n "Please hit just <return> if you really have a IRIX/MIPS system. "
set reply=$<
echo "    Compiling for $GMS_TARGET is straightforward."
echo "Please type 'which f77'  or  'which f90' to learn your compiler's name."
echo -n "Compiler? "
set GMS_FORTRAN=$<
echo "SGI's math library will be used: blas"
echo "There are no further questions about FORTRAN or math libraries."
set GMS_MATHLIB="blas"
breaksw

#       GMS_MATHLIB need be set only generically for Sun Solaris.
case sun32:
case sun64:

echo "Type 'uname -sr' to detect your Solaris version...this will show as 5.x"
echo "The 5 part is meaningless, so please ignore it."
echo "The decimal place is the major Solaris release number, please give it."
echo "Hence your reply will be 6 or 7 or 8 or 9 or 10, just an integer."
echo -n "Solaris version? "
set GMS_SUN_OS_VERNO=$<
#
#    1998's Solaris 7 was the first release with reliable 64-bit software,
#    so let's make sure any Sun bought since then does a 64 bit compile.
if ($GMS_SUN_OS_VERNO <= 6) then
   set GMS_FORTRAN=f77
   if ($GMS_TARGET == sun64) then
      echo "Compile target is being reset to sun32 on this very old Solaris."
      set GMS_TARGET=sun32
   endif
else
   set GMS_FORTRAN=f90
   if ($GMS_TARGET == sun32) then
      echo "Compile target is being reset to sun64 on this Solaris platform."
      set GMS_TARGET=sun64
   endif
endif
#
set GMS_MATHLIB=sunperf
#
echo " "
echo "Sun's compiler suite is named WorkShop, Forte, or Sun Studio,"
echo "depending on your Solaris version's age."
echo "It contains a math library which will be used by GAMESS, automatically."
echo "The FORTRAN compiler will be f77 for Solaris 6 or older systems."
echo "The FORTRAN compiler will be f90 for Solaris 7 or newer systems."
if ($GMS_FORTRAN == f90) then
   echo "Sun changed the flags for 64 bit compilation at f90 version 8.3"
   echo "Type 'f90 -V' (capital vee) to display your FORTRAN's version number."
   echo "The version appears somewhere on the first line of the response,"
   echo "and is a value like 2.0 in 1998, 7.0 in 2002, and 8.3 in 2009."
   echo -n "Please enter full version number, including decimal point: "
   set GMS_SUN_FORT_VERNO=$<
endif
breaksw

#
#  Currently, Windows only supports the Portland Group compilers (PGI)
#
case win32:
case win64:
case winazure:
#      GMS_WIN_OPT   will be set below, to user's optimization level
#      GMS_WIN_FLAGS adds extra flags for purposes of testing,
#                    but will be set to a null string,
#                    unless a user hand-edits install.info to add something.
#      GMS_WIN_TP    will be a processor type compiler flag,
#                    and will be set to a null string, unless
#                    user's environment has one specified as TP.
setenv GMS_WIN_FLAGS "''"

if ($?TP) then
   setenv GMS_WIN_TP "-tp $TP"
else
   setenv GMS_WIN_TP "''"
endif
badwinfortran:
tput clear
echo "/===============================================================================\"
echo "|         AVAILABLE OPTIONS UNDER MICROSOFT WINDOWS OPERATING SYSTEMS           |"
echo "|===============================================================================|"
echo "| Compiler   | Math Library | 32-bit | 64-bit |            Comments             |"
echo "|===============================================================================|"
echo "|            | NONE         |  YES   |  YES   | Fortran 95 compiler. pgf77 used |"
echo "|            |--------------------------------| for source that may not be F95  |"
echo "|            | PGI BLAS     |  YES   |  YES   | compatible.                     |"
echo "| pgfortran  |------------------------------------------------------------------|"
echo "| (12.4)     | ACML         |  YES   |  YES   |                                 |"
echo "|            |------------------------------------------------------------------|"
echo "|            | MKL          |  YES   |  YES   |                                 |"
echo "| ------------------------------------------------------------------------------|"
echo "|            | NONE         |   NO   |  YES   |                                 |"
echo "| ifort      |------------------------------------------------------------------|"
echo "| (XE SP1.2) | MKL          |   NO   |  YES   |                                 |"
echo "\===============================================================================/"
echo " "
echo "Windows Fortran Compiler"
echo "------------------------"
echo " "
echo "'pgfortran' - Portland Group Fortran 95 compiler (PGI)"
echo "              Last version tested:"
echo "                Workstation 12.4"
echo "                Visual Fortran 12.4"
echo " "
echo "'ifort'     - Intel Fortran compiler (Intel)"
echo "              Last version tested: "
echo "                Parallel Studio XE 2011 SP1 for Windows* Update 2 consisting of:"
echo "                - C++ Composer XE 2011 Update 9"
echo "                - Visual Fortran Composer XE 2011 Update 9"
echo " "
echo -n "Enter your Fortran compiler choice: "
set GMS_FORTRAN=$<

switch ($GMS_FORTRAN)
   case ifort:
      echo " "
      echo "Use of 'ifort' requires additional information since library"
      echo "names, and compiler flags, are version number specific."
      echo "note: ifort is typically installed at"
      echo "      C:\Program Files (x86)\Intel\ComposerXE-2011\"
      echo " "
      echo "Type 'ifort' and note the version number in the reply."
      echo "Please enter only the main version number, such as 8, 9, 10, 11, 12"
      echo -n "Version? "
      set GMS_IFORT_VERNO=$<
      breaksw
   case pgfortran:
      echo " "
      echo "'pgfortran' - does not support quadruple precision, so heavy "
      echo "              element DK3 resolution of the identity will fail"
      echo "              but everything else should work."
      echo " "
      set GMS_WIN_FLAGS="'-V '"
      echo " "
      echo "This compiler is not commonly used with GAMESS, so"
      echo "please be careful verifying the test examples all work."
      echo "pgfortran will use target=$GMS_TARGET."
      echo " "
      breaksw
   default:
      echo "You didn't provide a valid FORTRAN compiler name."
      echo -n "Please hit <return> to try again."
      set reply=$<
      goto badwinfortran
      breaksw
endsw

echo -n "Please hit <return> to set up the compiler optimization level."
set reply=$<

badwinoptimizationlevel:
tput clear
echo "Compiler Optimization Level"
echo "---------------------------"
echo " "
echo "'baseline'    - Do not apply compiler optimization '-O0'    flag (slow)"
echo "'linux'       - Apply compiler optimizations using '-O2'    flag (safe)"
echo "'samara'      - Apply compiler optimizations using '-O3'    flag (un-tested for accuracy)"
echo "'fast'        - Apply compiler optimizations using: "
echo "                                            PGI  : '-fastsse -Mipa=fast,inline,safe'"
echo "                                            INTEL: '-fast'"
echo " "
echo "                                                            flag (un-tested for accuracy)"
echo "'testing'     - For testing"
echo "'testing-ipa' - For testing with -Mipa=fast,safe"
echo " "
echo -n "Enter your compiler optimization level choice: "
set GMS_WIN_OPT=$<
switch ($GMS_WIN_OPT)
  case baseline:
    echo " "
    echo "'baseline' - will result in a quick build process for GAMESS but at the cost "
    echo "             of a slow running GAMESS binary."
    echo " "
    breaksw
  case linux:
    echo " "
    echo "'linux'    - will result in a safe build process for GAMESS using settings that "
    echo "             have been verified to work on Linux systems."
    echo " "
    echo "The linking step will take a while."
    echo " "
    breaksw
  case samara:
    echo " "
    echo "'samara'   - will result in a GAMESS build that has not be tested for accuracy."
    echo " "
    echo "The linking step will take a while."
    echo " "
    breaksw
  case fast:
    echo " "
    echo "'fast'     - will result in a GAMESS build that has not be tested for accuracy."
    echo " ifort     - applies: -fast"
    echo " pgfortran - applies: -fastsse -Mipa=fast,safe"
    echo " pgf77     - applies: -fastsse -Mipa=fast,safe"
    echo " "
    echo "The linking step will take a while."
    echo " "
    breaksw
  case testing:
    echo " "
    if ($GMS_FORTRAN == ifort) then
      echo "'testing'  - modify variables GMS_INT_OPT, GMS_IPO_OPT, GMS_WIN_FLAGS in"
      echo "             install.info to your needs."
      echo " "
      set GMS_INT_OPT="'-O3              '  #default optimization flag, add/change if desired"
      set GMS_IPO_OPT="'-Qipo -Qprec-div-'  #default optimization flag, add/change if desired"
    else
      echo "'testing'  - modify variables GMS_PGI_OPT, GMS_IPA_OPT, GMS_WIN_FLAGS in"
      echo "             install.info to your needs."
      echo " "
      set GMS_PGI_OPT="'-O3            '    #default optimization flag, add/change if desired"
      set GMS_IPA_OPT="'-Mipa=fast,safe'    #default optimization flag, add/change if desired"
    endif
    breaksw
  default:
    echo " "
    echo "You did not provide a valid compiler optimization level."
    echo -n "Please hit <return> try again."
    set reply=$<
    goto badwinoptimizationlevel
    breaksw
endsw

echo -n "Please hit <return> to continue to the math library setup."
set reply=$<
#
#  Currently, Windows math library selection limited to what is offered
#  by the PGI compilers.
#
badwinmathlib:
tput clear
echo "Windows Math Library Selection"
echo "-------------------------------"
echo " "
echo "'blas' to use PGI Compiler's BLAS library"
echo "'acml' to use AMD's ACML BLAS library"
echo "'mkl'  to Intel's math library"
echo "'none' to use GAMESS's BLAS routine (much slower)"
echo " "
echo -n "Enter your math library choice: "
set GMS_MATHLIB=$<
#
switch ($GMS_MATHLIB)
   case blas:
      echo "$GMS_FORTRAN compiler's BLAS library will be used"
      echo " "
      breaksw
   case acml:
      echo "ACML math library will be used. $GMS_FORTRAN will use the"
      echo "'-Bdynamic -Macml' flags during linking."
      echo " "
      breaksw
   case mkl:
      set GMS_MATHLIB_PATH='C:\Program Files (x86)\Intel\Composer XE 2011 SP1\mkl\lib\intel64'
      echo "The standard MKL installation is typically in:"
      echo "    $GMS_MATHLIB_PATH"
      echo "Normally the Intel compiler is automatically able to find the MKL library"
      echo "and you don't need to specify the MKL library path."; echo
      echo "If you have the library installed in a different or non-standard location,"
      echo -n "please enter the directory, else just hit Enter: "
      set reply="$<"
      if ("$reply" != "") set GMS_MATHLIB_PATH="$reply"
      echo " "
      echo -n "Enter $GMS_MATHLIB library main version (10 for example): "
      set GMS_MKL_VERNO=$<
      echo "MKL version $GMS_MKL_VERNO will be used from the directory:"
      echo "$GMS_MATHLIB_PATH"
      echo " "
      breaksw
   case blas:
      echo "$GMS_FORTRAN compiler's BLAS library will be used"
      echo " "
      breaksw
   case none:
      echo "GAMESS's BLAS routine will be used"
      echo " "
      breaksw
   case acml:
      echo "ACML math library will be used. $GMS_FORTRAN will use the"
      echo "'-Bstatic -lacml' flags during linking."
      echo " "
      breaksw
   default:
      echo "You didn't provide a valid math library name."
      echo -n "Please hit <return> try again."
      set reply=$<
      goto badlinuxmathlib
      breaksw
endsw
#
if ($GMS_FORTRAN == pgfortran) then
  echo -n "Please hit <return> to continue to the target platform setup."
  set reply=$<
  tput clear
  echo "PGI Target Platform"
  echo "-------------------"
  echo "Select a target platform for your system below:"
  echo " "
  echo "32-bit AMD"
  echo "=========="
  echo "'athlon'       : generate 32-bit code for AMD Athlon XP/MP and compatible processors."
  echo "'barcelona-32' : generate 32-bit code for AMD Opteron/Quadcore and compatible processors."
  echo "'istanbul-32'  : generate 32-bit code that is usable on any Istanbul processor-based system."
  echo "'k8-32'        : generate 32-bit code for AMD Athlon64, AMD Opteron and compatible processors."
  echo "'shanghai-32'  : generate 32-bit code that is usable on any AMD Shanghai processor-based system."
  echo " "
  echo "64-bit AMD"
  echo "=========="
  echo "'barcelona-64' : generate 64-bit code for AMD Opteron/Quadcore and compatible processors."
  echo "'k8-64'        : generate 64-bit code for AMD Athlon64, AMD Opteron and compatible processors."
  echo "'k8-64e'       : generate 64-bit code for AMD Opteron Revision E, AMD Turion, and compatible processors."
  echo "'istanbul-64'  : generate 64-bit code that is usable on any Istanbul processor-based system."
  echo "'shanghai-64'  : generate 64-bit code that is usable on any AMD Shanghai processor-based system."
  echo " "
  echo "32-bit Intel"
  echo "============"
  echo "'core2-32'     : generate 32-bit code for Intel Core 2 Duo and compatible processors."
  echo "'nehalem-32'   : generate 32-bit code that is usable on any Nehalem processor-based system."
  echo "'p7-32'        : generate 32-bit code for Pentium 4 and compatible processors."
  echo "'penryn-32'    : generate 32-bit code for Intel Penryn Architecture and compatible processors."
  echo "'piii'         : generate 32-bit code for Pentium III and compatible processors."
  echo " "
  echo "64-bit Intel"
  echo "============"
  echo "'core2-64'     : generate 64-bit code for Intel Core 2 Duo EM64T and compatible processors."
  echo "'nehalem-64'   : generate 64-bit code that is usable on any Nehalem processor-based system."
  echo "'p7-64'        : generate 64-bit code for Intel P4/Xeon EM64T and compatible processors."
  echo "'penryn-64'    : generate 64-bit code for Intel Penryn Architecture and compatible processors."
  echo " "
  echo "Unified Binary options"
  echo "======================"
  echo "'p6'           : generate 32-bit code for Pentium Pro/II/III and AthlonXP compatible processors."
  echo "'px-32'        : generate 32-bit code that is usable on any x86 processor-based system."
  echo "'x64'          : generate 64-bit unified binary code for both AMD and Intel x64 processors."
  echo " "
  echo "If you wish to leave this option up to the compiler then just hit <enter>."
  echo -n "Enter your target platform choice CAREFULLY (no checks will follow): "
  set TP=$<
  echo " "
  if (null$TP != null) then
      set GMS_WIN_TP="'-tp $TP'"
      echo "Target Platform:" $TP
  else
      set GMS_WIN_TP=""
      echo "Target Platform:" $TP
  endif
endif
#
#  End of win32/win64/winzaure section
#
breaksw

default:
echo "There is no support for compiling on $GMS_TARGET,"
echo "probably you typed the target name incorrectly."
exit 12
breaksw
endsw

#
#    ----- Step 3: test the user's compiler setup by creating actvte.x -----
#
#####if (-e $GMS_BUILD_DIR/tools/actvte.x) goto skip_actvte
#
echo " "
echo -n "please hit <return> to compile the GAMESS source code activator "
set reply=$<
tput clear
#
if (-e tools/actvte.code) then
#
   sed -e "s/^\*UNX/    /" tools/actvte.code > actvte.f
#
#              Cray vectors need to pick at least *SNG and maybe *PSX lines.
#              note that Cray-XT should not do this, only old Cray systems
#              where a 64 bit floating point is a REAL data type.
   if ($GMS_TARGET == cray-x1) then
      mv -f actvte.f temp.f
      sed -e "s/^\*SNG/    /" -e "s/^\*PSX/    /" temp.f > actvte.f
      rm -f temp.f
   endif
#
   switch ($GMS_FORTRAN)
      case ifort:
         if (($GMS_TARGET == win32) || ($GMS_TARGET == win64) || ($GMS_TARGET == winazure)) then
           if (! $?VCINSTALLDIR) then
             echo "Set VCINSTALLDIR to the installation directory of Visual C++ and try again."
             echo "Normally, VC++ is installed in: "
             echo "C:\Program Files (x86)\Microsoft Visual Studio #.#\VC"
             exit 1
           endif 
           set echo
           $GMS_FORTRAN -Qlocation,link,"$VCINSTALLDIR/bin" -o actvte.exe actvte.f
           mv -fv actvte.exe tools/actvte.x
           if (-e actvte.obj) rm -f actvte.obj
           unset echo
           breaksw
         endif
         if ($GMS_IFORT_VERNO <= 9) then
            set ifortlibs='-Vaxlib'
         else
            set ifortlibs=''
         endif
         set echo
         $GMS_FORTRAN -o $GMS_BUILD_DIR/tools/actvte.x actvte.f $ifortlibs
         unset echo
         breaksw
#                 IBM BG uses a different compiler for interactive programs
#                 on the front end, compared to code running on nodes
#                 For 'command not found' errors from the following,
#                 add explicit path like /opt/ibmcmp/xlf/9.1/bin below,
#                 or better yet, take action to have this on your path.
      case blrts_xlf:
      case bgxlf_r:
         xlf -o $GMS_BUILD_DIR/tools/actvte.x actvte.f
         if (!(-x tools/actvte.x)) then
            echo "IBM BG/L uses a different compiler on the front end, xlf,"
            echo "than on the back end, $GMS_FORTRAN"
            echo "Since the actvte.x program failed to compile, you probably"
            echo "do not have the correct PATH set to find xlf.  Please fix."
            exit 13
         endif
         breaksw
      default:
         set echo
         $GMS_FORTRAN -o $GMS_BUILD_DIR/tools/actvte.x actvte.f
         unset echo
         breaksw
   endsw
   rm -f actvte.f
   if (-e actvte.o) rm -f actvte.o
#            windows doesn't necessarily mark binaries as Unix executables
   if (($GMS_TARGET == win32) || ($GMS_TARGET == win64) || ($GMS_TARGET == winazure)) then
      if (-e tools/actvte.x) chmod +rx tools/actvte.x
   endif
   if (-x $GMS_BUILD_DIR/tools/actvte.x) then
      echo "Source code activator was successfully compiled."
   else
      echo "Something went wrong building tools/actvte.x"
      echo "Typing mistakes in your responses to this script?"
      echo "Your path setup doesn't find the FORTRAN compiler?"
      echo "Check .tcshrc or .cshrc's execution path and/or library path setup."
      echo "fatal error, exiting."
      exit
   endif
else
   echo "Warning...source code activation program does not exist."
   echo "please provide $GMS_PATH/tools/actvte.code,"
   echo "or a pre-compiled binary for it: $GMS_BUILD_DIR/tools/actvte.x"
   echo "fatal error, exiting."
   exit
endif
#
#####skip_actvte:
#
#    ----- Step 4: acquire data necessary to use MPI instead of sockets -----
#                             Note:
#    a) We try asking about MPI choices only for linux64 clusters.
#    b) For now, vendor workstations fall back to TCP/IP sockets.
#    c) High end machines using MPI or other sophisticated libraries force
#       their usage inside 'compddi', but it looks good if we generate the
#       right name for the config file for what is going to be hardwired.
#
                             set GMS_DDI_COMM='sockets'
if ($GMS_TARGET == cray-x1)  set GMS_DDI_COMM='shmem'
if ($GMS_TARGET == cray-xt)  set GMS_DDI_COMM='mpi'
if ($GMS_TARGET == ibm-bg) then
   if ($GMS_BG_MODEL == L)   set GMS_DDI_COMM='armci'
   if ($GMS_BG_MODEL == P)   set GMS_DDI_COMM='mpi'
endif
if ($GMS_TARGET == ibm-sp)   set GMS_DDI_COMM='lapi'
if ($GMS_TARGET == sgi64)    set GMS_DDI_COMM='shmem'
#
if ($GMS_TARGET == linux64) then
   echo " "
   echo -n "please hit <return> to set up your network for Linux clusters."
   set reply=$<
   tput clear
   top_of_comm_choice:
   echo " "
   echo "If you have a slow network, like Gigabit Ethernet (GE), or"
   echo "if you have so few nodes you won't run extensively in parallel, or"
   echo "if you have no MPI library installed, or"
   echo "if you want a fail-safe compile/link and easy execution,"
   echo "     choose 'sockets'"
   echo "to use good old reliable standard TCP/IP networking."
   echo " "
   echo "If you have an expensive but fast network like Infiniband (IB), and"
   echo "if you have an MPI library correctly installed,"
   echo "     choose 'mpi'."
   echo " "
   echo -n "communication library ('sockets' or 'mpi')? "
   set GMS_DDI_COMM=$<
   switch ($GMS_DDI_COMM)
      case sockets:
         breaksw
      case mpi:
#               Although not listed below, other choices can be made:
#                   openmpi, mpich2
#               See readme.ddi for their status, which can be summarized as
#                 mpich2 has not been able to be tested on IB,
#                        but has been found to be usable on 10GE.
#                 openMPI does --not-- work properly.
         tput clear
         echo "The MPI libraries which work well on linux64/Infiniband are"
         echo "      Intel's MPI (impi)"
         echo "      MVAPICH2"
         echo "      SGI's mpt from ProPack, on Altix/ICE systems"
         echo "Other libraries may work, please see 'readme.ddi' for info."
         echo "The choices listed above will compile and link easily,"
         echo "and are known to run correctly and efficiently."
         echo ""
         echo "Enter 'sockets' if you just changed your mind about trying MPI."
         echo ""
         echo -n "Enter MPI library (impi, mvapich2, mpt, sockets): "
         set GMS_MPI_LIB=$<
         if ($GMS_MPI_LIB == sockets) then
            set GMS_DDI_COMM=sockets
            unset GMS_MPI_LIB
         endif
         breaksw
      default:
         echo "the only two choices are 'sockets' and 'mpi', try again..."
         goto top_of_comm_choice
         breaksw
   endsw

   if ($GMS_DDI_COMM == sockets) goto done_with_comm_choice

   #      make sure everything after this works with lower case names
   if ($GMS_MPI_LIB == iMPI)     set GMS_MPI_LIB=impi
   if ($GMS_MPI_LIB == MVAPICH2) set GMS_MPI_LIB=mvapich2
   if ($GMS_MPI_LIB == openMPI)  set GMS_MPI_LIB=openmpi
   if ($GMS_MPI_LIB == MPICH2)   set GMS_MPI_LIB=mpich2
   if ($GMS_MPI_LIB == MPT)      set GMS_MPI_LIB=mpt
   #
   #      Your sys/op might have put the MPI library almost anywhere!
   #      Both /opt and /usr/local are very reasonable places to hunt.
   #      We show some known locations of MPI libraries below, and
   #          'mpich2'  could be at /opt/mpich2/gnu
   #          'openmpi' could be at /usr/mpi/intel/openmpi-1.4.3
   tput clear
   top_enter_mpi_path:
   echo " "
   echo "MPI can be installed in many places, so let's find $GMS_MPI_LIB."
   echo "The person who installed your MPI can tell you where it really is."
   echo " "
   echo "impi     is probably located at a directory like"
   echo "              /opt/intel/impi/3.2"
   echo "              /opt/intel/impi/4.0.1.007"
   echo "              /opt/intel/impi/4.0.2.003"
   echo "         include iMPI's version numbers in your reply below."
   echo "mvapich2 could be almost anywhere, perhaps some directory like"
   echo "              /usr/mpi/gcc/mvapich2-1.6"
   if ($GMS_MPI_LIB == openmpi) then
   echo "openmpi  could be almost anywhere, perhaps some directory like"
   echo "              /usr/mpi/openmpi-1.4.3"
   endif
   echo "mpt      is probably located at a directory like"
   echo "              /opt/sgi/mpt/mpt-1.26"
   echo -n "Please enter your ${GMS_MPI_LIB}'s location: "
   set GMS_MPI_PATH=$<
   if (!(-d $GMS_MPI_PATH)) then
      echo "pathname $GMS_MPI_PATH does not exist.  please try again"
      goto top_enter_mpi_path
   endif
   #
   #     in principle, MPI libraries using Infiniband or iWarp need
   #     a lower level library "Open Fabrics Enterprise Distribution"
   #     to handle communications on the device.
   #                    This is a bit murky!
   #     On our system, we needed to explicitly link OFED for MVAPICH2,
   #     but iMPI and openMPI either don't need OFED, or found it w/o
   #     needing to specify the libraries.
   #     For now, we'll ask about OFED only for MVAPICH2...
   #
                                 set ofedlibs=false
   if ($GMS_MPI_LIB == mvapich2) set ofedlibs=true
   if ($ofedlibs == true) then
      echo " "
      echo "$GMS_MPI_LIB requires a lower level library named OFED to handle"
      echo "the network device.  The 'Open Fabrics Enterprise Distribution'"
      echo "handles Infiniband and other fast network connections."
      echo "   See www.openfabrics.org for more information."
      echo "Typical places to find OFED's libraries might include"
      echo "        /usr/lib64"
      echo "        /opt/ofed/lib64"
      echo "One of the OFED libraries you are looking for is libibverbs.so"
      echo " "
      echo -n "Please enter your OFED's location: "
      set GMS_OFED_PATH=$<
      if (!(-d $GMS_OFED_PATH)) then
         echo "The pathname $GMS_OFED_PATH does not exist."
         echo "Please install OFED, and then try 'config' again."
         exit 44
      endif
   endif
endif

if (($GMS_TARGET == win32) || ($GMS_TARGET == win64) || ($GMS_TARGET == winazure)) then
    echo " "
    echo -n "please hit <return> to to set up your network."
    set reply=$<
    windows_mpi_selection:
    tput clear
    echo "Options"
    echo "-----------"
    echo " "
    echo "'mpich2' - use Argonne National Lab's MPI-2 (MPICH2)."
    echo "'msmpi'  - use Microsoft's implementation of MPI-2 (MS-MPI)."
    echo "'serial' - no communication."
    echo " "
    echo -n "Please enter your communication choice: "
    set GMS_MPI_LIB=$<
    set GMS_DDI_COMM='mpi'
    switch ($GMS_MPI_LIB)
      case mpich2:
        echo " "
        echo "Using Argonne National Laboratory's implementation of MPI-2 (MPICH2)"
        echo "The default install path for MPICH2 will be assumed:"
        echo "C:\Program Files\MPICH2"
        breaksw
      case msmpi:
        echo " "
        echo "Using Microsoft's implemtation of MPI-2 (MS-MPI)."
        if ($GMS_FORTRAN == pgfortran) echo "The following PGI flag will be used: '-Mmpi=msmpi'"
        if ($GMS_FORTRAN == ifort) then
          echo "MS-MPI variables, MSMPI_INC and MSMPI_LIB64/MSMPI_LIB32, will be used."
          echo "Make sure they are set before proceeding further."
          echo " "
          if ($?MSMPI_INC) echo "MPI header path: $MSMPI_INC"
          if (($GMS_TARGET == win64) && $?MSMPI_LIB64) echo "64-bit MPI lib path: $MSMPI_LIB64"
          if (($GMS_TARGET == win32) && $?MSMPI_LIB32) echo "32-bit MPI lib path: $MSMPI_LIB32"
        endif
        breaksw
      case serial:
        echo " "
        echo "serial.src will be compiled"
        set GMS_MPI_LIB='none'
        set GMS_DDI_COMM='serial'
        breaksw
      default:
        echo "$GMS_MPI_PATH is not a valid option."
        echo -n "Please hit <return> to try again."
        set reply=$<
        goto windows_mpi_selection
        breaksw
    endsw
endif
#
done_with_comm_choice:
#
#    ----- Step 5: output what we learned into a 'configuration file' -----
#
set cf=$GMS_BUILD_DIR/install.info
#
echo '#\!/bin/csh' > $cf
echo "#   compilation configuration for GAMESS" >> $cf
echo "#   generated on `hostname`"              >> $cf
echo "#   generated at `date`"                  >> $cf
echo "setenv GMS_PATH            $GMS_PATH"           >> $cf
echo "setenv GMS_BUILD_DIR       $GMS_BUILD_DIR"      >> $cf
#
echo "#         machine type"                         >> $cf
echo "setenv GMS_TARGET          $GMS_TARGET"         >> $cf
    if (null$GMS_BG_MODEL != null) \
echo "setenv GMS_BG_MODEL        $GMS_BG_MODEL"       >> $cf
    if (null$GMS_SUN_OS_VERNO != null) \
echo "setenv GMS_SUN_OS_VERNO    $GMS_SUN_OS_VERNO"   >> $cf
    if (null$GMS_MAC_OSX_VERNO != null) \
echo "setenv GMS_MAC_OSX_VERNO   $GMS_MAC_OSX_VERNO"  >> $cf
#
echo "#         FORTRAN compiler setup"               >> $cf
echo "setenv GMS_FORTRAN         $GMS_FORTRAN"        >> $cf
    if (null$GMS_GFORTRAN_VERNO != null) \
echo "setenv GMS_GFORTRAN_VERNO  $GMS_GFORTRAN_VERNO" >> $cf
    if (null$GMS_IFORT_VERNO != null) \
echo "setenv GMS_IFORT_VERNO     $GMS_IFORT_VERNO"    >> $cf
    if (null$GMS_SUN_FORT_VERNO != null) \
echo "setenv GMS_SUN_FORT_VERNO  $GMS_SUN_FORT_VERNO" >> $cf
    if (null$GMS_L64_OPT != null)  then
echo "#         PGI/Linux 64 optimization level"      >> $cf
echo "setenv GMS_L64_OPT         $GMS_L64_OPT"        >> $cf
echo "#         PGI/Linux 64 compiler flags"          >> $cf
echo "setenv GMS_LIN_FLAGS       $GMS_LIN_FLAGS"      >> $cf
    endif
    if ($GMS_L64_OPT == testing)  then
echo "#         PGI specific compiler flags"          >> $cf
echo "setenv GMS_PGI_OPT         $GMS_PGI_OPT"        >> $cf
echo "setenv GMS_IPA_OPT         $GMS_IPA_OPT"        >> $cf
    endif
    if (($GMS_TARGET == win32) || ($GMS_TARGET == win64) || ($GMS_TARGET == winazure)) then
echo "#         Windows optimization level"           >> $cf
echo "setenv GMS_WIN_OPT         $GMS_WIN_OPT"        >> $cf
echo "#         Windows compiler flags"               >> $cf
echo "setenv GMS_WIN_FLAGS       $GMS_WIN_FLAGS"      >> $cf
echo "setenv GMS_WIN_TP          $GMS_WIN_TP"         >> $cf
      if ($GMS_FORTRAN == ifort) then
echo "#         INTEL specific compiler flags"        >> $cf
echo "setenv GMS_INT_OPT         $GMS_INT_OPT"        >> $cf
echo "setenv GMS_IPO_OPT         $GMS_IPO_OPT"        >> $cf
      else
echo "#         PGI specific compiler flags"          >> $cf
echo "setenv GMS_PGI_OPT         $GMS_PGI_OPT"        >> $cf
echo "setenv GMS_IPA_OPT         $GMS_IPA_OPT"        >> $cf
      endif
    endif
echo "#         mathematical library setup"           >> $cf
echo "setenv GMS_MATHLIB         $GMS_MATHLIB"        >> $cf
if ((($GMS_TARGET == win32) || ($GMS_TARGET  == win64) || ($GMS_TARGET  == winazure))\
                            && ($GMS_MATHLIB == mkl)) then
    if (null"$GMS_MATHLIB_PATH" != null) \
      echo 'setenv GMS_MATHLIB_PATH    "'"$GMS_MATHLIB_PATH"'"'   >> $cf
else    
     if (null$GMS_MATHLIB_PATH != null) \
 echo "setenv GMS_MATHLIB_PATH    $GMS_MATHLIB_PATH"   >> $cf
endif 
    if (null$GMS_MKL_VERNO != null) \
echo "setenv GMS_MKL_VERNO       $GMS_MKL_VERNO"      >> $cf
echo "#         parallel message passing model setup" >> $cf
echo "setenv GMS_DDI_COMM        $GMS_DDI_COMM"       >> $cf
    if (null$GMS_MPI_LIB != null) \
echo "setenv GMS_MPI_LIB         $GMS_MPI_LIB"        >> $cf
    if (null$GMS_MPI_PATH != null) \
echo "setenv GMS_MPI_PATH        $GMS_MPI_PATH"       >> $cf
    if (null$GMS_OFED_PATH != null) \
echo "setenv GMS_OFED_PATH       $GMS_OFED_PATH"      >> $cf
    if (null$GMS_ARMCI_PATH != null) \
echo "setenv GMS_ARMCI_PATH      $GMS_ARMCI_PATH"     >> $cf
#
echo " "
echo "Your configuration for GAMESS compilation is now in"
echo "     $cf"
echo "Now, please follow the directions in"
echo "     $GMS_PATH/machines/readme.unix"

#   generate a Makefile in $GMS_BUILD_DIR
set makef=$GMS_BUILD_DIR/Makefile
echo "GMS_PATH = $GMS_PATH" > $makef
echo "GMS_VERSION = $GMS_VERSION" >> $makef
echo "GMS_BUILD_PATH = $GMS_BUILD_DIR" >> $makef
echo 'include $(GMS_PATH)/Makefile.in' >> $makef
