#!/bin/csh
#
#  13 Mar 06 - script to compile one GAMESS source file
#
#  Invoke this script by './comp MODULE >& MODULE.log &'.
#
#        ----- The next two lines require your attention -----
#  1. Choose your machine, the legal values for TARGET are
#      amd64,axp64,compaq-sc,cray-pvp,cray-t3e,cray-x1,cray-xd1,cray-xt3,
#      fuji-pp32,fuji-pp64,hpux32,hpux64,ibm32,ibm64,ibm64-sp,ibm-bg,
#      linux-ia64,linux-pc,mac32,macG5,necsx,sgi32,sgi64,sun32,sun64
#  2. Choose your GAMESS directory tree.
#
set TARGET=ibm64
chdir /u1/mike/gamess
#
#    ---- and now the script begins...
#
unset echo
set MODULE=$1
set ACTONLY=$2   # this argument is almost always omitted
if (null$MODULE == null) then
   echo No compile module name given...
   exit
endif
#
echo ======================== $MODULE ==============================
date
#
#   let's be sure they typed the intended target correctly
#
set OK=false
if ($TARGET == amd64)      set OK=true
if ($TARGET == axp64)      set OK=true
if ($TARGET == compaq-sc)  set OK=true
if ($TARGET == cray-pvp)   set OK=true
if ($TARGET == cray-t3e)   set OK=true
if ($TARGET == cray-x1)    set OK=true
if ($TARGET == cray-xd1)   set OK=true
if ($TARGET == cray-xt3)   set OK=true
if ($TARGET == fuji-pp32)  set OK=true
if ($TARGET == fuji-pp64)  set OK=true
if ($TARGET == hpux32)     set OK=true
if ($TARGET == hpux64)     set OK=true
if ($TARGET == ibm32)      set OK=true
if ($TARGET == ibm64)      set OK=true
if ($TARGET == ibm64-sp)   set OK=true
if ($TARGET == ibm64-bg)   set OK=true
if ($TARGET == linux-ia64) set OK=true
if ($TARGET == linux-pc)   set OK=true
if ($TARGET == mac32)      set OK=true
if ($TARGET == macG5)      set OK=true
if ($TARGET == necsx)      set OK=true
if ($TARGET == sgi32)      set OK=true
if ($TARGET == sgi64)      set OK=true
if ($TARGET == sun32)      set OK=true
if ($TARGET == sun64)      set OK=true
if ($OK == false) then
   echo The comp script does not select a correct TARGET machine type.
   echo What you typed when editing this script was $TARGET
   exit 4
endif
#
#   ----- Is this a vector machine? -----
#
set VECTORIZE=false
if ($TARGET == cray-pvp) set VECTORIZE=true
if ($TARGET == cray-x1)  set VECTORIZE=true
if ($TARGET == necsx)    set VECTORIZE=true
#
#   ----- Are level 3 BLAS in a system library? -----
#   If so, some matrix multiplies in MTHLIB.SRC can use DGEMM calls
#   If not, print a warning to try to get people to find a BLAS library.
#
#   N.B.  Machines that use vector.src accomplish this business in a
#   different manner, so ignore this part.
#
set BLAS3=false
if ($MODULE == mthlib) then
#
if  ($TARGET == amd64)        set BLAS3=true
if (($TARGET == axp64)  && \
    ((-e /usr/lib/libdxml.a)||(-e /usr/lib/libcxml.a))) set BLAS3=true
if  ($TARGET == compaq-sc)    set BLAS3=true
if  ($TARGET == cray-t3e)     set BLAS3=true
if  ($TARGET == cray-x1)      set BLAS3=true
if (($TARGET == cray-xd1)||($TARGET == cray-xt3)) then
    if (-e $ACML_DIR) set BLAS3=true
    if (-e $PGI/linux86-64/$PGI_VERS_STR/lib/libblas.a) set BLAS3=true
endif
if  ($TARGET == fuji-pp32)    set BLAS3=true
if  ($TARGET == fuji-pp64)    set BLAS3=true
if  ($TARGET == hpux32)       set BLAS3=true
if  ($TARGET == hpux64)       set BLAS3=true
if  ($TARGET == ibm32)        set BLAS3=true
if  ($TARGET == ibm64)        set BLAS3=true
if  ($TARGET == ibm64-sp)     set BLAS3=true
if  ($TARGET == ibm-bg)       set BLAS3=true  # math lib not actually used!
#      1st is Fedora Core's, 2nd is ASCI download from ORNL, 3rd is Atlas
#      the names of the latter two files on your system might well be
#      different from these, edit here and in 'lked' to match your paths.
if (($TARGET == linux-pc) && (-e /usr/lib/libblas.a))            set BLAS3=true
if (($TARGET == linux-pc) && (-e /usr/local/bin/libblas-asci.a)) set BLAS3=true
if (($TARGET == linux-pc) && (-e /usr/local/lib/libatlas.a))     set BLAS3=true
#      The standard BLAS library for Itanium2 is Intel's MKL,
#      but both NEC and SGI have their own custom libraries.
if  ($TARGET == linux-ia64) then
  if (-e /opt/intel) then
    if(q`cd /opt/intel ; ls | grep mkl` =~ qmkl* ) set BLAS3=true
  endif
  if (-e /opt/MathKeisan/lib/libblas.a) set BLAS3=true
  if (-e /opt/sgi) then
    if(q`cd /opt/sgi ; ls | grep scsl` =~ qscsl* ) set BLAS3=true
  endif
endif
if  ($TARGET == mac32)        set BLAS3=true
if  ($TARGET == macG5)        set BLAS3=true
if  ($TARGET == sgi32)        set BLAS3=true
if  ($TARGET == sgi64)        set BLAS3=true
if (($TARGET == sun32) && (-e /opt/SUNWspro/lib/libsunperf.so)) set BLAS3=true
if (($TARGET == sun64) && (-e /opt/SUNWspro/lib/libsunperf.so)) set BLAS3=true
#
if ($BLAS3 == true) then
  echo Compiling matrix multiply routines to use a system BLAS library...
else
  echo "--------------------------------------------------------------"
  echo '        Warning\!  Warning\!  Warning\!  Warning\!'
  echo "No mathematical library containing the BLAS has been detected."
  echo "Use of a DGEMM from a good library will speed up computations"
  echo "at the MP2, CCSD, or similar correlated levels, perhaps a lot."
  echo "In the meantime, mthlib.src and all other calls to DGEMM will"
  echo "rely on the slower blas.src provided with GAMESS."
  echo "--------------------------------------------------------------"
endif
endif
#
#        Normally we are sitting above the source code and objects,
#        and want to make sure they go in their normal directory.
#
#        N.B.  A few places below prepare temporary copies of the
#        code being compiled in the current directory level (.),
#        and these are always deleted at the end of this script.
#        These places are vector, valence bond, and sed hacking.
#
set SRCDIR=source
set OBJDIR=object
#
#        a few source files are kept in non-standard places, defined here
#
if ($MODULE == blaswrap) set SRCDIR=misc
if ($MODULE == ddi)      set SRCDIR=ddi/oldsrc
if ($MODULE == ddishm)   set SRCDIR=ddi/shmem
if ($MODULE == ddio3k)   set SRCDIR=ddi/shmem
#
#   ----- delete scalar code before compiling on vector systems -----
#   UNIX's 'ld' loader is incapable of loading two copies of the
#   object code for a routine, and simply using the first one.
#   So, if we are using VECTOR.SRC on this machine, we must split
#   up some of the modules, delete the scalar code for the routines
#   which are found in VECTOR.SRC, and then recombine the rest of
#   the code in that module.  Ugh!
#   Note that some of Cray's fsplit's are no longer able to work
#   with any extension except .f.
#
if ($VECTORIZE == true) then
   rm -f *.f
   if ($TARGET == cray-x1) alias fsplit ftnsplit
   switch ($MODULE)
      case int2a:
         echo Deleting scalar code forms, genral
         cp source/int2a.src xxxxxx.f
         fsplit xxxxxx.f
         rm -f xxxxxx.f
         if (-e forms.f) rm forms.f genral.f 
         if (-e FORMS.f) rm FORMS.f GENRAL.f
         cat *.f > int2a.src
         rm -f *.f
         set SRCDIR=.
         breaksw
      case grd2c:
         echo Deleting scalar code dspdfv, jdxyzv, jkgnmv, jkxyzv
         cp source/grd2c.src xxxxxx.f
         fsplit xxxxxx.f
         rm -f xxxxxx.f
         if (-e dspdfv.f) rm -f dspdfv.f jdxyzv.f jkgnmv.f jkxyzv.f
         if (-e DSPDFV.f) rm -f DSPDFV.f JDXYZV.f JKGNMV.f JKXYZV.f
         cat *.f > grd2c.src
         rm -f *.f
         set SRCDIR=.
         breaksw
      case hss2b:
         echo Deleting scalar code jddspd.f
         cp source/hss2b.src xxxxxx.f
         fsplit xxxxxx.f
         rm -f xxxxxx.f
         if (-e jddspd.f) rm -f jddspd.f
         if (-e JDDSPD.f) rm -f JDDSPD.f
         cat *.f > hss2b.src
         rm -f *.f
         set SRCDIR=.
         breaksw
      case eigen:
         echo Deleting scalar code gldiag.f
         cp source/eigen.src xxxxxx.f
         fsplit xxxxxx.f
         rm -f xxxxxx.f
         if (-e gldiag.f) rm -f gldiag.f
         if (-e GLDIAG.f) rm -f GLDIAG.f
         cat *.f > eigen.src
         rm -f *.f
         set SRCDIR=.
         breaksw
      case mthlib:
         echo Deleting scalar code mtarbr, tfsqb, tftri.
         cp source/mthlib.src xxxxxx.f
         fsplit xxxxxx.f
         rm -f xxxxxx.f
         if (-e mtarbr.f) rm -f mtarbr.f tfsqb.f tftri.f
         if (-e MTARBR.f) rm -f MTARBR.f TFSQB.f TFTRI.f
         cat *.f > mthlib.src
         rm -f *.f
         set SRCDIR=.
         breaksw
      case scflib:
         echo Deleting scalar code dirfck.
         cp source/scflib.src xxxxxx.f
         fsplit xxxxxx.f
         rm -f xxxxxx.f
         if (-e dirfck.f) rm -f dirfck.f
         if (-e DIRFCK.f) rm -f DIRFCK.f
         cat *.f > scflib.src
         rm -f *.f
         set SRCDIR=.
         breaksw
      default:
         breaksw
   endsw
endif
#
#        optional SIMOMM method using Tinker MM program
#        Do not edit this part, even if you want to use Tinker.
#        == === ==== ==== ====
#        Note that Tinker compiles down inside its own directory.
set TINKER=false
if ($MODULE == Libtad)  set TINKER=true
if ($MODULE == Libteac) set TINKER=true
if ($MODULE == Libtedl) set TINKER=true
if ($MODULE == Libtemo) set TINKER=true
if ($MODULE == Libterx) set TINKER=true
if ($MODULE == Libtfi)  set TINKER=true
if ($MODULE == Libtjo)  set TINKER=true
if ($MODULE == Libtpr)  set TINKER=true
if ($MODULE == Libtsx)  set TINKER=true
if ($MODULE == Tdrive)  set TINKER=true
if ($MODULE == Tinkin)  set TINKER=true
if ($MODULE == Toys)    set TINKER=true
#       We must compile directly out of the Tinker directory
#       so that its ghastly INCLUDE statements will work.
#       Note that Tinker must skip the code deletion at end!
if ($TINKER == true) then
   chdir tinker
   set SRCDIR=.   
   set OBJDIR=../object
   goto cmp
endif
#
#        optional Valence Band method using VB2000
#        You may need to set the variable VBPATH just below.
set VB2000=false
if ($MODULE == vb2000) set VB2000=true
if ($MODULE == vb2gms) set VB2000=true
#        compiling in the top level directory means code is erased later
if ($VB2000 == true ) then
   set VBPATH=~/VB/SRC
   echo Copying $MODULE.src from VB2000 directory named $VBPATH
   set SRCDIR=.
   if ($MODULE == vb2000) then
#        Some messy sed stuff to set up.
      sed "s/^CTMAP/     /g" $VBPATH/vb2000.src | \
      sed "s/^CGMS/    /g"  > vb2000.src
   endif
   if ($MODULE == vb2gms) cp $VBPATH/vb2gms.src .
endif
#
#   ----- Does this module need to be activated? -----
#
#   Machines where "DOUBLE PRECISION" translates to more than a 64
#   bit floating point quantity must be passed into the activation
#   to ensure the source is made single precision.
#
if ($TARGET == cray-pvp) goto act
if ($TARGET == cray-t3e) goto act
if ($TARGET == cray-x1)  goto act
if ($TARGET == necsx)    goto act
#
#   Machines needing the 64->32 bit BLAS wrappers must activate everything
#   This depends on whether or not the BLAS library is OK with 64 bit
#   integers in its argument, or not (in which case a sed hack to use
#   a 64 to 32 bit wrapper file is needed, by always branching here).
#
if ($TARGET == fuji-pp64) goto act
if ($TARGET == ibm64)     goto act
if ($TARGET == ibm64-sp)  goto act
if ($TARGET == sgi64)     goto act
if ($TARGET == sun64)     goto act
#
#   Any module with machine dependent code must be activated...
#
if ($MODULE == aldeci) goto act
if ($MODULE == ccsdt)  goto act
if ($MODULE == cisgrd) goto act
if ($MODULE == cphf)   goto act
if ($MODULE == cpmchf) goto act
if ($MODULE == cprohf) goto act
if ($MODULE == ddi)    goto act
if ($MODULE == ddishm) goto act
if ($MODULE == dft)    goto act
if ($MODULE == dftint) goto act
if ($MODULE == grd2a)  goto act
if ($MODULE == gugdga) goto act
if ($MODULE == gugdgb) goto act
if ($MODULE == gugdm2) goto act
if ($MODULE == gugem)  goto act
if ($MODULE == gugsrt) goto act
if ($MODULE == gvb)    goto act
if ($MODULE == gvvpt2) goto act
if ($MODULE == hss2a)  goto act
if ($MODULE == int2a)  goto act
if ($MODULE == iolib)  goto act
if ($MODULE == lagran) goto act
if ($MODULE == local)  goto act
if ($MODULE == locpol) goto act
if ($MODULE == mccas)  goto act
if ($MODULE == mcqdpt) goto act
if ($MODULE == mcqud)  goto act
if ($MODULE == mcscf)  goto act
if ($MODULE == mctwo)  goto act
if ($MODULE == morokm) goto act
if ($MODULE == mp2)    goto act
if ($MODULE == mp2grd) goto act
if ($MODULE == nmr)    goto act
if ($MODULE == ordint) goto act
if ($MODULE == rhfuhf) goto act
if ($MODULE == tdhf)   goto act
if ($MODULE == trans)  goto act
if ($MODULE == trfdm2) goto act
if ($MODULE == unport) goto act
if ($MODULE == vb2gms) goto act
if ($MODULE == vector) goto act
#
#   We may need to do a hack below on the matrix multiply routines
#
if (($BLAS3 == true) && ($MODULE == mthlib)) goto act
#
#   All other modules are straight FORTRAN, just copy them.
#
echo Copying source code, $MODULE.src does not require activation.
cp $SRCDIR/$MODULE.src $MODULE.f
goto cmp
#
#   ----- Choose which version is to be activated -----
#   The setting for 'ddi' applies to the possible use of the first version
#   of the Distributed Data Interface, and probably should be sockets only.
#   Most machines use the 2nd version of DDI, implemented entirely in C,
#   and compiled by the separate 'compddi' script.
#   In contrast, machines using the SHMEM library will compile ddishm.src
#
act:
#
if ($TARGET == amd64) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*AMD'
endif
#
if ($TARGET == axp64) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*DEC'
endif
#       SHMEM on Compaq has to activate its particular type
if ($TARGET == compaq-sc) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddishm) setenv MACHIN '*DEC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*DEC'
endif
#       the old Cray vector systems would use TCP/IP sockets in DDI
if ($TARGET == cray-pvp) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*CRY'
   if ($MODULE == vector) setenv MACHIN '*CRY'
endif
#       the CRAY T3E has a special SHMEM implementation of DDI
if ($TARGET == cray-t3e) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddishm) setenv MACHIN '*T3E'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*T3E'
endif
#       the CRAY X1 has a special SHMEM implementation of DDI
if ($TARGET == cray-x1) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddishm) setenv MACHIN '*CX1'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*CX1'
   if ($MODULE == vector) setenv MACHIN '*CRY'
endif
#       the CRAY XD1 uses TCP/IP sockets, until GPSHMEM is working
if ($TARGET == cray-xd1) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddishm) setenv MACHIN '*XD1'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*AMD'
endif
#       the CRAY XT3 is using pure MPI, from the old version of DDI
if ($TARGET == cray-xt3) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*MPI'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*XT3'
endif
if (($TARGET == fuji-pp32) || ($TARGET == fuji-pp64)) then
                             setenv MACHIN '*I32'
   if ($TARGET == fuji-pp64) setenv MACHIN '*I64'
   if ($MODULE == ddi)       setenv MACHIN '*SOC'
   if ($MODULE == iolib)     setenv MACHIN '*UNX'
   if ($MODULE == unport)    setenv MACHIN '*SUN'
endif
if (($TARGET == hpux32) || ($TARGET == hpux64)) then
                          setenv MACHIN '*I32'
   if ($TARGET == hpux64) setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*HP '
endif
if (($TARGET == ibm32) || ($TARGET == ibm64) || ($TARGET == ibm64-sp)) then
                          setenv MACHIN '*I64'
   if ($TARGET == ibm32)  setenv MACHIN '*I32'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*AIX'
endif
#     Blue Gene uses the old DDI toolkit, in pure MPI mode.
if ($TARGET == ibm-bg) then
   setenv MACHIN '*I32'
   if ($MODULE == ddi)    setenv MACHIN '*MPI'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*AIX'
endif
if ($TARGET == linux-ia64) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*ITA'
endif
if ($TARGET == linux-pc) then
                          setenv MACHIN '*I32'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*F2C'
endif
if (($TARGET == mac32) || ($TARGET == macG5)) then
                          setenv MACHIN '*I32'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*F2C'
endif
if ($TARGET == necsx) then
                          setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*MPI'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*NEC'
   if ($MODULE == vector) setenv MACHIN '*NEC'
endif
if (($TARGET == sgi32) || ($TARGET == sgi64)) then
                          setenv MACHIN '*I32'
   if ($TARGET == sgi64)  setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*SGI'
endif
if (($TARGET == sun32) || ($TARGET == sun64)) then
                          setenv MACHIN '*I32'
   if ($TARGET == sun64)  setenv MACHIN '*I64'
   if ($MODULE == ddi)    setenv MACHIN '*SOC'
   if ($MODULE == iolib)  setenv MACHIN '*UNX'
   if ($MODULE == unport) setenv MACHIN '*SUN'
endif
#
#   ----- Activate the source code to produce FORTRAN -----
#
set echo
setenv   SRCIN $SRCDIR/$MODULE.src
setenv CODEOUT $MODULE.f
#
tools/actvte.x
unset echo
#
#   --------------- special machine "sed hacks" --------------------
#   Not everything can be done with ACTVTE, so we use "sed" (ugh!).
#
#    Direct access record length is measured in bytes on most Unix,
#    but some kinds insist in measuring 4-byte words.  This changes
#    only one line in RAOPEN and one line in OPENDA in IOLIB.SRC.
#    SGI's f90 should not execute the following, but SGI's f77 must.
#
if (($MODULE == iolib) && \
   ($TARGET == axp64 || $TARGET == compaq-sc || \
    $TARGET == sgi32 || $TARGET == sgi64)) then
   mv iolib.f iolib.junk
   sed -e "s/     \*      RECL=8\*IRECLN/     *      RECL=2*IRECLN/" \
     iolib.junk > iolib.f
   rm -f iolib.junk
endif
#
#   Use DGEMM matrix multiply if possible.
#
if (($MODULE == mthlib) && ($BLAS3 == true)) then
   mv mthlib.f mthlib.junk
   sed -e "s/\*BL3/    /" mthlib.junk > mthlib.f
   rm -f mthlib.junk
endif
#
#   For 64 bit machines which also have a traditional 32 bit product
#   line, the source code typically assumes 32 bits.  This hack lets
#   the source code know it is going to be running as a 64 bit machine.
#
if (($MODULE == unport) && \
    (($TARGET == fuji-pp64) || \
     ($TARGET == hpux64)    || \
     ($TARGET == ibm64)     || \
     ($TARGET == ibm64-sp)  || \
     ($TARGET == sgi64)     || \
     ($TARGET == sun64))) then
   mv unport.f unport.junk
   sed -e "s/      NWDVAR = 2/      NWDVAR = 1/" unport.junk > unport.f
   rm -f unport.junk
endif
#
#   This hack is necessary only if compiler flags below request the
#   use of 64 bit integers in GAMESS, and if the vendor's BLAS library
#   insists that its integer arguments be 32 bit quantities.
#   There is a special wrapper file gamess/misc/blaswrap.src that deals
#   with this problem, provided we hack the source to call the wrappers.
#   Not a perfect strategy, imagine an unrelated routine named MDSCAL,
#   but there may not be spaces in front of all of these, especially DDOT.
#
if (($MODULE != blaswrap) && ($MODULE != blas) && \
   (($TARGET == fuji-pp64) || ($TARGET == ibm64) || ($TARGET == ibm64-sp) || \
    ($TARGET == sgi64)     || ($TARGET == sun64))) then
   sed -e "s/DASUM/XASUM/g"   -e "s/dasum/XASUM/g" \
       -e "s/DAXPY/XAXPY/g"   -e "s/daxpy/XAXPY/g" \
       -e "s/DCOPY/XCOPY/g"   -e "s/dcopy/XCOPY/g" \
       -e "s/DDOT/XDOT/g"     -e "s/ddot/XDOT/g"   \
       -e "s/DNRM2/XNRM2/g"   -e "s/dnrm2/XNRM2/g" \
       -e "s/DROT/XROT/g"     -e "s/drot/XROT/g"   \
       -e "s/DROTG/XROTG/g"   -e "s/drotg/XROTG/g" \
       -e "s/DSCAL/XSCAL/g"   -e "s/dscal/XSCAL/g" \
       -e "s/DSWAP/XSWAP/g"   -e "s/dswap/XSWAP/g" \
       -e "s/IDAMAX/IXAMAX/g" -e "s/idamax/IXAMAX/g" \
       -e "s/DGER/XGER/g"     -e "s/dger/XGER/g"   \
       -e "s/DTRMM/XTRMM/g"   -e "s/dtrmm/XTRMM/g" \
       -e "s/DTRMV/XTRMV/g"   -e "s/dtrmv/XTRMV/g" \
       -e "s/DTRSM/XTRSM/g"   -e "s/dtrsm/XTRSM/g" \
       -e "s/DGEMV/XGEMV/g"   -e "s/dgemv/XGEMV/g" \
       -e "s/DGEMM/XGEMM/g"   -e "s/dgemm/XGEMM/g" \
       $MODULE.f > $MODULE.munged
   mv $MODULE.munged $MODULE.f
endif
#
#   The following hack makes an Apple version print a different banner.
#   The Apple version is source code identical to Linux, but it should
#   print something to keep it from looking like a PC!
#
if (($TARGET == mac32) || ($TARGET == macG5)) then
   if ($MODULE == unport) then
      mv unport.f unport.junk
      sed -e "s/PC-UNIX VERSION/ APPLE VERSION /" unport.junk > unport.f
      rm -f unport.junk
   endif
endif
#
#   The following hack selects AOINTS=DIST as the default on high end
#   Compaq and IBM systems, where we know we have a high quality network.
#
if (($MODULE == unport) &&  \
   (($TARGET == compaq-sc) || ($TARGET == ibm64-sp))) then
   mv unport.f unport.junk
   sed -e "s/\*TRF/    /" unport.junk > unport.f
   rm -f unport.junk
endif
#
#    HP has a FORTRAN callable delay, we just have to change to HP's name
#
if (($TARGET == hpux32) || ($TARGET == hpux64)) then
   if ($MODULE == unport) then
      mv unport.f unport.junk
      sed -e "s/NAPTIME(IDELAY)/SLEEP(IDELAY)/" \
          unport.junk > unport.f
      rm -f unport.junk
   endif
endif
#
#   ...and this is the end of the ugly "sed hack"s.
#
#   --------- Now we are ready to compile on the target machine ----------
#
cmp:
#
#   Optionally, save pure FORTRAN in temporary directory for
#   syntax scan by the nifty FORTRAN analysis program FTNCHEK.
#
if ($ACTONLY == true) then
   mv $MODULE.f ~/scr
   exit
endif
#
if (-e $OBJDIR/$MODULE.o) rm -f $OBJDIR/$MODULE.o
#
#  Version for Opteron and other 64 bit Athlon chips made by AMD.
#  See 'linux-pc' if you have 32 bit Athlon chips made by AMD.
#                Typical software requirement:
#  Fedora Core 2/64 bit version, pgf77, pgcc, and ACML math library.
#
#  The amd64 target was constructed by putting together advice from
#  Shiro Koseki, Hiroaki Umeda, and Ted Packwood.  This version relies
#  upon commercially marketed compilers, and a freely available BLAS
#  library.  This means that there is no "totally free" version based
#  on (for example) a g77 compiler.  Please note that you should just
#  select a target of 'amd64' and ignore PGI's web page information
#  about porting (everything needed is now included in these scripts).
#
#  The compiler is marketed by the Portland Group, see www.pgroup.com.
#  What GAMESS requires is the pgf77 and pgcc packages, not the pgf90
#  products.  A pgf77/pgcc bundle is priced at $499 for academic users,
#  as of November 2004.  Be sure to set up the use of this compiler in
#  your .cshrc or other login script, for example
#     setenv PATH $PATH\:/usr/pgi/linux86-64/bin
#     setenv PGI /usr/pgi
#
#  The BLAS library is the AMD Core Math Library, developed by AMD and
#  the NAG group.  ACML is available most easily as an option while
#  installing pgf77, but it is also a free download, see
#    http://www.amd.com/us-en/Processors/DevelopWithAMD/0,,30_2252,00.html
#  so the amd64 version assumes that you have obtained this library.
#
if ($TARGET == amd64) then
   if (($MODULE == qeigen) || ($MODULE == int2c)) then
      mv $MODULE.f $MODULE.junk
      sed -e "s/Q-/D-/g" \
          -e "s/Q+00/D+00/g" \
          -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE.f
      rm -f $MODULE.junk
   endif
   set OPT = '-fastsse -Mipa=fast,safe -Mprof=func'
   if ($MODULE == int2b) set OPT = "$OPT -Mnounroll"
   if (($MODULE == mpcdat) || ($MODULE == mpcgrd) || ($MODULE == mpcint) || \
       ($MODULE == mpcmol) || ($MODULE == mpcmsc)) set OPT = '-Mprof=func -O0'
   if ($MODULE == zheev) set OPT='-Mprof=func -O0'  # defensive compiling
   set echo
   pgf77 -c -i8 -i8storage $OPT $MODULE.f
   unset echo
endif
#
#  Options for the Compaq AXP FORTRAN 5.2 compiler under Tru64 V4.0F are
#     -O0 turns off all optimization
#     -O1 does local optimizations
#     -O2 also does global optimizations
#     -O3 also does additional global optimizations
#     -O4 also does routine inlining (default)
#     -O5 also does software pipelining
#     -fast implies less accurate but faster libraries, etc. and -O4.
#     -c means compile only
#     -i8 selects use of 64 bit integers
#     -v gives compiler phase information, and timings
#     -automatic and -static use/avoid stack for local variables
#     -col72 chops source lines past 72 columns
#     -stand nosemantic means don't warn of nonANSI usage (default)
#     -stand nosource_form means don't warn of tabs/lowercase (default)
#     -stand nosyntax means don't warn of nonANSI syntax (default)
#
#  Note that we've tried f77 3.3, 3.7, 3.8, and 5.2, but nothing in between.
#  This is an excellent compiler, and probably all versions work.
#  Under AXP Linux, it has a different name, but is the same great compiler.
#
if ($TARGET == axp64) then
   set OPT = '-O4'
   set FORT='f77'
   if (`uname` == Linux) set FORT='fort'
   set echo
   $FORT -c -i8 -v -automatic -col72 $OPT $MODULE.f
   unset echo
endif
#      The SuperCluster assumes a specific AXP chip...
if ($TARGET == compaq-sc) then
   set OPT = '-fast -tune ev67 -arch ev67'
   if ($MODULE == zheev) set OPT='-O0'
   set echo
   f77 -c -i8 -v -col72 $OPT $MODULE.f
   unset echo
endif
#
#    Cray parallel vector processor (e.g. T90, J90, SV1...)
#    Cray T90 tested in February of 2000
#    Cray SV1 rev C with CF90 3.4.0.0.4 tested in March of 2000
#    Note that all Cray clauses now use f90 compiler only.
#
if ($TARGET == cray-pvp) then
   set OPT = '-O2 '
   if ($MODULE == int2a)  set OPT='-Ovector0,scalar3 '
   if ($MODULE == grd2a)  set OPT='-Ovector0,scalar2 '  # Jerry says
   if ($MODULE == grd2b)  set OPT='-Ovector0,scalar3 '
   if ($MODULE == grd2c)  set OPT='-Ovector0,scalar3 '
   if ($MODULE == gugem)  set OPT='-Ovector0,scalar3 '
   if ($MODULE == vector) set OPT='-O1 '
   if ($MODULE == gvb)    set OPT='-O1 '   # use -O0 if exam15,16,21 fail
   if ($MODULE == gamess) set OPT='-O0 '
   if ($MODULE == efinp)  set OPT='-O0 '
   if ($MODULE == efinta) set OPT='-Ovector0,scalar3 '
   if ($MODULE == efintb) set OPT='-Ovector0,scalar3 '
   if ($MODULE == efgrda) set OPT='-Ovector0,scalar3 '
   if ($MODULE == efgrdb) set OPT='-Ovector0,scalar3 '
   if ($MODULE == efgrdc) set OPT='-Ovector0,scalar3 '
   if ($MODULE == efgrd2) set OPT='-Ovector0,scalar3 '
   if ($MODULE == ormas1) set OPT='-O0 '   # also from Jerry
   set echo
   f90 -c -V $OPT $MODULE.f
   unset echo
endif
#
#  Compiler flags for Cray T3E under UNICOS/mk 2.0.3.18, cf90 3.1.0.3
#  -Oscalarn is various scalar optimizations (n=0,1,2,3)
#  -Oaggress increases table sizes used during optimizations
#  -O[no]msgs,[no]negmsgs [disables]enables compiler optimization messages
#  -dp disables double precision
#
if ($TARGET == cray-t3e) then
   set OPT = '-Oscalar3,aggress'
   if ($MODULE == grd2c) set OPT='-O1'   # for cf90 3.1.0.3 and others
   if ($MODULE == hss1b) set OPT='-O1'   # for cf90 3.4.0.0
   set echo
   env TARGET=cray-t3e f90 -c $OPT -dp -Onomsgs,nonegmsgs $MODULE.f
   unset echo
endif
#
#  Compiler flags for Cray X1 under UNICOS/mp 2.5+, ftn 5.3+
#  -O[no]msgs,[no]negmsgs [disables]enables compiler optimization messages.
#  -Oscalarn is various scalar optimizations (n=0,1,2,3)
#  -Ovectorn is various vector optimizations (n=0,1,2,3)
#  -Oaggress causes the compiler to treat each subroutine as a single
#       optimization region.
#  -Ossp will build GAMESS in SSP (single-streaming processor) mode.
#        remove -Ossp to use multi-streaming processor mode (discouraged)
#  -dp disables double precision.
#  -rm generates listing files.
#  -xomp disables all OpenMP statements.
#  -sdefault64 uses default 64-bit integers and reals (among others).
#
if ($TARGET == cray-x1) then
   set OPT = '-O2'
   set LST = ' '         # change to '-rm -Omsgs,negmsgs' for listing file
   if ($MODULE == int2a) set OPT='-O1' 
   if ($MODULE == vector) set OPT='-Oscalar3,vector3' 
   set echo
   ftn -c -V $OPT $LST -Ossp,aggress -xomp -dp -sdefault64 $MODULE.f
   unset echo
endif
#
#  Compiler flags for Cray XD1/XT3 using PGI F90 6.0.* and MPICH 1.2.6. 
#  For the XD1, make sure your "mpif90" script points to pgf90 and not a
#    different compiler.  Note: F90 is required due to ddi/shmem/ddigpshm.src.
#  'setenv PGI' should not be needed as this should be done automatically
#    by modules.  If you do not have $PGI environment variable set,
#    uncomment these 2 lines (first change /usr/pgi to wherever the
#    PGI compiler is installed):
#    setenv PGI /usr/pgi
#    setenv PATH $PATH\:$PGI/linux86-64/bin 
#
if (($TARGET == cray-xd1)||($TARGET == cray-xt3)) then

   if ($TARGET == cray-xt3) then
      set USE_FTN = ftn
   else  # if ($TARGET == cray-xd1) then   
      set USE_FTN = 'mpif90' 
   endif

   if (($MODULE == qeigen) || ($MODULE == int2c)) then
      mv $MODULE.f $MODULE.junk
      sed -e "s/Q-/D-/g" \
          -e "s/Q+00/D+00/g" \
          -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE.f
      rm -f $MODULE.junk
   endif
   set echo
   set OPT = '-fastsse -Munroll'
   if ($MODULE == int2b) set OPT = '-fast -Mnounroll'
   if (($MODULE == mpcdat) || ($MODULE == mpcgrd) || ($MODULE == mpcint) || \
       ($MODULE == mpcmol) || ($MODULE == mpcmsc)) set OPT = '-O0'
   set echo 
   $USE_FTN -c $OPT -Mnosecond_underscore -tp amd64 -i8 -Minfo=all $MODULE.f
   unset echo
endif
#
#   Fujitsu PrimePower
#   Split into 32bit and 64bit versions, since the 32bit executable is
#   slightly (~5%) faster but cannot use larger than 2Gbyte memory.
#   From Roger Amos at ANU Supercomputer Facility, 1/2005
#
#   Compilation options: do not use -O5 or FMADD as code is slower. 
#   More complicated cache optimisation does not improve performance.
#
#   64bit version tested with largepage=1, and largepage=2, the
#   program executes correctly but there is no performance advantage.
#
#   tested with Solaris8 and Solaris9 and compiler
#   Fujitsu Fortran 5.5 (Feb 19 2004 17:23:48)
#   note: the compiler has two names, f90 and frt, which are the same.
#
if ($TARGET == fuji-pp32) then
   set OPT = '-Kfast_GP2=3,prefetch=5'
   set echo
   f90 -c -fs $OPT $MODULE.f
   unset echo
endif

#   -KV9 allows large memory space
#   -CcdII8 causes all generic integer variables to be 64 bit
#
if ($TARGET == fuji-pp64) then
   set OPT = '-Kfast_GP2=3,prefetch=5,largepage=2'
   if ($MODULE == gamess) set OPT='-O0'  # only fails in 64 bit mode
   set echo
   f90 -c -fs $OPT -KV9 -CcdII8  $MODULE.f
   unset echo
endif
#
#  HP-UX systems,
#         the latest tested version numbers are
#  HP-UX B.11.0,  using f90 2.4.10  on PA-RISC  32 bit
#  HP-UX B.11.23, using f90 2.8     on Itanium2 64 bit
#       (f90 +version reports version number)
#
#  The f90 options apply to both 32 and 64 bit compilations, and mean:
#    +On   selects optimization level; n=0,1,2,3,4  (-O means +O2)
#          0 is none
#          1 is block transforms
#          2 is full within subprograms
#          3 crosses subprograms (includes inlining) also loop transforms
#          4 is link time iptimizations, applies only to Itanium processors.
#
#    +Oaggressive selects the following four additions to +O2:
#    +Oentrysched  = instruction scheduling on entry/exit
#    +Olibcalls    = special trig and power functions (lacking error hand.)
#    +Onofltacc    = permits use of a faster single multiply/add instruction.
#    +Onoinitcheck = disable initialization of any unitialized datum
#         other optimizations include
#    +Onolimit     = ignores time and memory limits when optimizing
#    +Ofastaccess  = gives fast access to global data
#
#    +Oaggressive is a decremented optimization, to be replaced in newer
#    systems by +Ofast.  +Ofast selects the combination +O2, +Olibcalls,
#    +Onolimit, +Ofltacc=relaxed, +FPD, +DSnative (on IPF), +Oshortdata
#    and requires f90 2.5 or higher.
#
#    +[no]save governs automatic variable allocation strategy
#    +[no]ppu governs postpend underscores on names of external refs.
#    +U77 gives access to BSD's 3F library
#    +DD64 uses the LP64 data model.
#    +i8 treats all integer or logical data as 64 bits
#
if ($TARGET == hpux32) then
   set OPT='+O2 +Oaggressive +Onolimit +Ofastaccess'
   if ($MODULE == unport) set OPT="$OPT +U77"
   set echo
   f90 -c $OPT +nosave +noppu $MODULE.f
   unset echo
endif
#
if ($TARGET == hpux64) then
#
#    the 64 bit libraries have a name conflict with ICOPY, XERBLA, and LSAME.
#
   if ($MODULE == guess) then
      mv guess.f guess.junk
      sed -e "s/SUBROUTINE ICOPY/SUBROUTINE IYPOC/" \
          guess.junk > guess.f
      rm -f guess.junk
   endif
   if ($MODULE == zheev) then
      mv zheev.f zheev.junk
      sed -e "s/SUBROUTINE XERBLA/SUBROUTINE XALBRE/" \
          -e "s/FUNCTION LSAME/FUNCTION LEMAS/" \
          -e "s/LSAME = CA.EQ.CB/LEMAS = CA.EQ.CB/" \
          -e "s/IF( LSAME )/IF( LEMAS )/" \
          -e "s/LSAME = INTA.EQ.INTB/LEMAS = INTA.EQ.INTB/" \
         zheev.junk > zheev.f
      rm -f zheev.junk
   endif
#      +O3 failed to run 9 of 37 example jobs correctly, so +O2 is safer.
   set OPT='+O2'
   if ($MODULE == unport) set OPT="$OPT +U77"
   if ($MODULE == trfdm2) set OPT="+O1"   # for CI gradients, exam05
   set echo
   f90 -c $OPT +DD64 +i8 +nosave +noppu $MODULE.f
   unset echo
endif
#
#   For IBM 32 or 64 bit RS/6000 workstations or SP parallel systems,
#   the options for XL FORTRAN 7.1.0 and AIX 4.3.3 are
#       -c means compile only
#       -O2 and -O3 choose optimization levels (there is no -O1)
#       -qarch=com,601,pwr,pwr2,pwr3 (see also -qtune)
#       -qflag requests I,L,W,E,S,Q (information, language,
#              warning, error, severe, quiet) messages
#       -qflttrap=ov:zero:inv:inex:enable traps bad arithmetic
#       -qhalt stops compiler after certain error level
#       -qnosave forces non-static storage
#       -qinitauto=ff initializes non-static storage (useful if debugging)
#       -qextchk checks calling args and common lengths at link
#       -qsource requests a printable .lst file.
#       -qtune selects target chip
#
#   The following clause requires XL FORTRAN 3.2 or higher.
#   Use of 64 bit integers requires XL FORTRAN 6.1 or higher.
#   The command to find your FORTRAN version level depends on your
#   AIX version: v3 is "lslpp -h xlfcmp.obj", v4/v5="lslpp -h xlfcmp".
#
#   To look for XLF optimization problems in one routine, place
#          @PROCESS OPT(0) SAVE
#   above the suspect routine.  Note that the directive remains in
#   force for only one subprogram, and must be above its first line.
#
#   To profile code during development stages,
#     1. "comp" desired modules with -pg added to the xlf flags
#     2. "lked" after adding -p to the xlf flags.
#     3. execute to completion, generating 'mon.out' file.
#     4. generate results by 'prof gamess.00.x mon.out'.
#
#   A possible way to look for memory allocation problems is VALGRIND.
#   Compile with the -p flag, and then be sure to look at child's
#   memory use: "valgrind --trace-children=yes rungms".  This program
#   is available for Linux (not AIX) at valgrind.org.  Untried by MWS.
#
if (($TARGET == ibm32) || ($TARGET == ibm64) || ($TARGET == ibm64-sp)) then
   set FORT='xlf'
   if ($TARGET == ibm64-sp) set FORT='mpxlf_r'
#         old 32 bit workstations, whether Power, Power2, or PowerPC
#         should all select plain vanilla common architecture.  It is
#         faster, and runs on any combination of these chips you own.
#         under xlf 4.1.0 a few files won't fully optimize
   if ($TARGET == ibm32) then
      set  OPT='-O3'
      if ($MODULE == grd2b)  set OPT='-O3 -qspillsize=1500'
      if ($MODULE == gugdm)  set OPT='-O2'
      if ($MODULE == gugem)  set OPT='-O2'
      if ($MODULE == qrel)   set OPT='-O2'
      if ($MODULE == trnstn) set OPT='-O2'
      set ARCH='com'
      set TUNE='604'   # PowerPC tuning makes even Power1 run faster
   endif
#         64 bit workstations or SP is sure to be Power3 or higher chip.
#         everything optimizes under xlf 5.1.1 and 6.1.0 and 7.1.0
#         our AIX systems are a mix of Power3 and Power4, while
#         our Linux systems are all Power5.  Please change the
#         architecture/tuning to match your case!
   if (($TARGET == ibm64) || ($TARGET == ibm64-sp)) then
      set  OPT='-O3 -q64 -qintsize=8 -qspillsize=1500'
      if (`uname` == AIX) then
         set ARCH='pwr3'
         set TUNE='pwr3'
      else
         set ARCH='pwr5'
         set TUNE='pwr5'
      endif
   endif
   if ($MODULE == fmoint) set OPT="$OPT -qstrict"
   set echo
   $FORT -c $OPT -qarch=$ARCH -qtune=$TUNE \
         -qflag=W:W -qhalt=W -qnosave $MODULE.f
   unset echo
endif
#
#   Blue Gene is a 32 bit processor based on the PPC440 embedded CPU
#   with the addition of a dual FPU.  
#   Blue Gene uses MPI in our older DDI toolkit for parallelization.
#   Blue Gene is rather specialized, let's not mix with other IBM,
#   even though the xlf arguments are clearly rather similar.
#   Not sure why compiler path is hardcoded...
#
if ($TARGET == ibm-bg) then
   set FORT="/opt/ibmcmp/xlf/9.1/bin/blrts_xlf"
   set INCL="-I/bgl/BlueLight/ppcfloor/bglsys/include"
   set ARCH='440'
   set TUNE='440'
   set OPT='-O3 -qmaxmem=-1'
   if ($MODULE == grd2b)  set OPT='-O3 -qspillsize=1500'
   if ($MODULE == gugdm)  set OPT='-O2'
   if ($MODULE == gugem)  set OPT='-O2'
   if ($MODULE == qrel)   set OPT='-O2'
   if ($MODULE == trnstn) set OPT='-O2'
   if ($MODULE == ormas1) set OPT='-O2'
   if ($MODULE == zheev)  set OPT='-O2'
   if ($MODULE == qeigen) set OPT="$OPT -qstrict"
   if ($MODULE == fmoint) set OPT="$OPT -qstrict"
   if ($MODULE == ddi)    set OPT="$OPT $INCL"

   set echo
   $FORT -c $OPT -qarch=$ARCH -qtune=$TUNE \
         -qflag=W:W -qhalt=W -qnosave $MODULE.f
   unset echo
endif
#
#   ------ RedHat Linux on "PC" (Pentium/Athlon chips)  -----
#   There are no less than four compilers for Linux included here!
#   They are g77, Intel's ifort, Portland's pgf77, and the obsolete
#   combination of f2c/gcc.  The default compiler is g77, but many
#   people use the Intel compiler.  It is a little faster, and it
#   supports quadruple precision, compared to the default of g77.
#
#   If you want to use one of the other three, just make sure that the
#   one you prefer is uncommented.  In addition, you will need to edit
#   the link-edit script 'lked' if you pick a different compiler here,
#   and possibly you will ned to change 'compddi' as well.
#
#   Note that we have only used Redhat, so this is not necessarily
#   correct for Slackware, SUSE, FreeBSD, Debian, ..., although
#   many people have been able to get these others to work.
#
#   1. Using g77 compiler.     compiler version query: rpm -q gcc-g77
#   If your RedHat is older than 6.0, see the f2c/gcc clause below.
#
#   There is an I/O library problem in g77, found in RedHat 6.0 -> 7.1,
#   which is not present in any of the 3.x GNU compilers.  Thus, if
#   your RedHat is newer than 7.1, you can forget this, but if not,
#   you can find a fix for the I/O bug on our web page:
#       www.msg.ameslab.gov/GAMESS/GAMESS.html,
#   then check the bottom of the "how to get a copy of GAMESS" page.
#   It is crucial to install this, as it works around a very serious
#   error in the g77 2.x I/O library.
#   This bug does not exist in any of the 3.x GNU compiler releases.
#
#   The meaning of g77's flags are
#      -O0, -O1, -O2, -O3 are the optimization levels, -O means -O1
#      -Wno-globals -fno-globals together suppress argument type checking.
#      -fautomatic defeats use of static storage
#      -malign-double uses 64 bit data alignment
#   Tests on a representative GAMESS test suite (executing energy, gradient
#   hessian code, as well as various SCF, MCSCF, MP2 runs, show that each
#   of the more aggressive optimizations -ffast-math, -march=i586, and -O3
#   gave speedups of less than 1% each.  (-march=i686 slows a Celeron type
#   Pentium II fractionally).  None of these optimizations are used below.
#
if ($TARGET == linux-pc) then
   set OPT = '-O2'
   if ($MODULE == ormas1) set OPT='-O2 -fno-move-all-movables' # RH9, g77 3.3
   if ($MODULE == zheev)  set OPT='-O0'  # defensive compiling, for exam19
#
#   g77 does not support FORTRAN logical units above 99, or 128 bit math.
#
   if (($MODULE == qeigen) || ($MODULE == int2c)) then
      mv $MODULE.f $MODULE.junk
      sed -e "s/Q-/D-/g" \
          -e "s/Q+00/D+00/g" \
          -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE.f
      rm -f $MODULE.junk
   endif
   if (($MODULE == iolib) || ($MODULE == inputa)) then
      mv $MODULE.f $MODULE.junk
      sed -e "s/MXUNIT=299/MXUNIT=99/g" $MODULE.junk > $MODULE.f
      rm -f $MODULE.junk
   endif
   set echo
   g77 -c $OPT -malign-double -fautomatic \
           -Wno-globals -fno-globals $MODULE.f
   unset echo
endif
#
#    2. Intel Fortran Compiler for Linux
#    This compiler can be downloaded for free for non-commercial purposes,
#        http://developer.intel.com/software/products/compilers/linux
#    and for-profit users can purchase this software for a reasonable price.
#    You need to get FORTRAN, C, and the MKL math library.
#
#    Remember to set up using the compiler by executing the proper
#    setup script for your shell, e.g.
#            . /opt/intel/compiler50/ia32/bin/ifcvars.sh
#
#    You must compile DDI to have only one trailing underscore in the
#    DDI routine names, namely edit 'compddi' to say -D_UNDERSCORES=1
#    in its linux-pc definitions, rather than the 2 that g77 requires.
#    Otherwise 'lked' will get unresolved references to DDI_BCAST, etc.
#
#    Prior to version 8.0, this compiler is spelled "ifc" rather than "ifort".
#    -O3  is the most aggressive optimization, the default is -O2.
#    -cm  turn off printing of informational messages (f90 syntax, etc)
#    -w   turn off all warnings
#    Dmitri likes to use "-O3 -xN -ssp -unroll8 -ip -pad -opt_report",
#    but that may cause certain ifort versions to fail on some files.
#
#--if ($TARGET == linux-pc) then
#--   set OPT = '-O3'
#--   if ($MODULE == delocl) set OPT='-O0'  # from Cheol
#--   if ($MODULE == zheev)  set OPT='-O0'
#--   set echo
#--   ifort -c $OPT -cm -w $MODULE.f
#--   unset echo
#--endif
#
#    3. Portland Group compiler.
#    This is a synthesis of recommendations from Fred Arnold and Brian
#    Salter-Duke.  -fast means -O2 -Munroll -Mnoframe, the latter option
#    seems to be the source of several incorrect results.  It is said that
#    "-Munroll" and "-tp p6" gives no significant improvement in run times.
#    The -Mlfs flag is supposed to cure the 2 GB file size limit.
#    exam19 may hang when using this compiler.  -Mlfs at link-time
#    enables large file support.  Your login script must set
#    up the use of this compiler, along the lines of
#          setenv PATH $PATH\:/usr/pgi/linux86/bin
#          setenv PGI /usr/pgi
#
#--if ($TARGET == linux-pc) then
#--   if (($MODULE == qfmm) || ($MODULE == solib) || ($MODULE == zheev)) then
#--       mv $MODULE.f $MODULE.junk
#--       sed -e s/DREAL/DBLE/g $MODULE.junk > $MODULE.f
#--       rm -f $MODULE.junk
#--   endif
#--   if (($MODULE == qeigen) || ($MODULE == int2c)) then
#--      mv $MODULE.f $MODULE.junk
#--      sed -e "s/Q-/D-/g" \
#--          -e "s/Q+00/D+00/g" \
#--          -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE.f
#--      rm -f $MODULE.junk
#--   endif
#--   set OPT = '-O2'
#--   if ($MODULE == zheev)  set OPT = '-O2 -Kieee'
#--   if ($MODULE == bassto) set OPT = '-O0'  # Takako
#--   set echo
#--   pgf77 -c $OPT -Msecond_underscore $MODULE.f
#--   unset echo
#--endif
#
#   4. RedHat 4.x and 5.x's FORTRAN compiler was f2c/gcc, and early
#   releases of g77 that were present in some of these distributions
#   do not run GAMESS correctly.  If you have RedHat 6.0 or higher,
#   which do not contain the f2c interpreter, see just above.  If your
#   RedHat is older than 6.0, use f2c/gcc instead of buggy old g77's.
#   This is a totally obsolete option, actually.
#
#--if ($TARGET == linux-pc) then
#--   if (($MODULE == qfmm) || ($MODULE == solib) || ($MODULE == zheev)) then
#--       mv $MODULE.f $MODULE.junk
#--       sed -e s/DREAL/DBLE/g $MODULE.junk > $MODULE.f
#--       rm -f $MODULE.junk
#--   endif
#--   if (($MODULE == qeigen) || ($MODULE == int2c)) then
#--      mv $MODULE.f $MODULE.junk
#--      sed -e "s/Q-/D-/g" \
#--          -e "s/Q+00/D+00/g" \
#--          -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE.f
#--      rm -f $MODULE.junk
#--   endif
#--   if (($MODULE == iolib) || ($MODULE == inputa)) then
#--      mv $MODULE.f $MODULE.junk
#--      sed -e "s/MXUNIT=299/MXUNIT=99/g" $MODULE.junk > $MODULE.f
#--      rm -f $MODULE.junk
#--   endif
#--   set OPT = '-O3 -malign-double'
#--   set echo
#--   f2c -w66 -a -Nn1604 -Nx800 $MODULE.f
#--   gcc -c $OPT $MODULE.c
#--   rm -f $MODULE.c
#--   unset echo
#--endif
#
#     Linux on IA-64 (Itanium or Pentium 4/EM64T), using Intel FORTRAN and C.
#     By omitting chip specific compiler options like "-mcpu=itanium2 -tpp2",
#     this version is able to run on Pentium 4/EM64T as well as Itanium2.
#
#     We run this on a SGI Altix system, using the following software:
#       linux kernel:  2.4.21-sgi230r3 (aka Propack 2.3)
#       Intel efc/ecc compilers: Version 7.1, Build 20030307
#       libraries: libgcc-3.0.4-1
#     We run this on HP rx2600 workstations, using the following software:
#       linux kernel: 2.4.18-e.12smp (aka RedHat 2.1AS (Derry))
#       Intel ifort/icc compilers: Version 8.0, Build 20031017
#     Fred Arnold and Jan Fredin have used various older compilers,
#     such as 6.0 and 7.0, and older kernels and glibc's as well.
#
#     At version 8.0, Intel changed the names of these compilers
#     to ifort and icc.  To deal with this, we have used the newer
#     names in the scripts, and placed softlinks in /bin pointing
#     from ifort to efc and icc to ecc on our old 7.0 machine.
#     Or, you could change the script names back to the originals.
#
#     Intel's compilers are commercially licensed software, but Intel allows
#     downloads of a "non-commercial unsupported version" at no charge:
#         http://developer.intel.com/software/products/compilers
#     Oddly, the Intel Math Kernel Library (MKL) which contains the BLAS
#     is marketed at a reduced cost (e.g. about $39) to academic sites,
#     rather than being free, but you can download a 30-day trial version
#     from Intel's site while obtaining a permanent license.  A suggested
#     source for this license is Programmer's Paradise,
#         http://www.pparadise.com
#     who also sell the Intel compilers if you are a commercial site.
#     Note that the MKL library should be used only serially, by adding
#     this to 'rungms': setenv MKL_SERIAL YES
#
#     Like all other compilers, this script assumes that you have set up
#     its paths and library specifications externally, not here.
#     For example, your .cshrc might need to add to the path
#         /opt/intel_fc_80/bin      and     /opt/intel_cc_80/bin
#     and define library locations by
#        setenv LD_LIBRARY_PATH /opt/intel_fc_80/lib:/opt/intel_cc_80/lib:\
#             /opt/intel/mkl61/lib/64
#     Similarly, you need to be sure that 'lked' finds Intel's MKL library.
#     Intel changes these paths around, indeed they even changed the name
#     of the compilers from efc/ecc to ifort/icc, although the old namess
#     still work and are therefore kept here for backward compatibility.
#
#     -cm means suppress comments
#     -w95 suppresses Hollerith initialization warnings
#     -WB means warn but don't fail on out-of-bounds array references
#     -On can have n=1,2,3.  Use of 3 caused problems with earlier
#          compilers, so it isn't being used here.  Try it if you like.
#
#   We have heard that one of the 8.1 compilers required degradation of
#   optimization for cpmchf to -O0 to run exam36 correctly.
#
if ($TARGET == linux-ia64) then
   set OPT = '-O2'
   if ($MODULE == morokm) set OPT='-O0' # Jan Fredin
   if ($MODULE == zheev)  set OPT='-O0' # Fred Arnold
   set echo
   ifort $OPT -w95 -cm -WB -i8 -c $MODULE.f
   unset echo
endif
#
#   Apple Macintosh G4 or G5 system using OS X (Tiger, 10.4) and g77 3.4.
#
#   This will run on any G4 or G5 system under 10.1, 10.2, 10.3, or 10.4,
#   but under 10.1, you'll need to run the old DDI version in 'compddi'.
#
#   Step 1 is install the "Xcode" software to get a C compiler, gcc.
#   This is available for download at Apple's web site,
#          http://developer.apple.com/tools/xcode/index.html
#   but Xcode can also be found on the Tiger Install DVD.
#   The compiler toolkit must match your OS X version (in 10.1 and in
#   10.2, the compiler suite was called the Apple Developer's Toolkit).
#
#   Step 2 is to download the Fink binary installer from the FINK project
#          http://fink.sourceforge.net
#   and install it using the directions on that web page.
#
#   Step 3 is to install g77 as superuser:
#       su (requires that root account has been enabled in NetInfo Manager)
#       source /sw/bin/init.sh or init.csh or add /sw/bin,/sw/sbin to path
#       apt-get update
#       apt-get upgrade
#       apt-get install g77
#   The installation of Atlas BLAS library is optional, Apple's library
#   is almost as good as Atlas, and the next step may be rather lengthy:
#       apt-get install atlas
#
#   On a 10.2 system with g77 3.1 and gcc 3.1, grd2b needed to be -O1
#
#
if ($TARGET == mac32) then
   set OPT = '-O2'
   #--if ($MODULE == grd2b) set OPT='-O1'
   if (($MODULE == qeigen) || ($MODULE == int2c)) then
      mv $MODULE.f $MODULE.junk
      sed -e "s/Q-/D-/g" \
          -e "s/Q+00/D+00/g" \
          -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE.f
      rm -f $MODULE.junk
   endif
   if (($MODULE == iolib) || ($MODULE == inputa)) then
      mv $MODULE.f $MODULE.junk
      sed -e "s/MXUNIT=299/MXUNIT=99/g" $MODULE.junk > $MODULE.f
      rm -f $MODULE.junk
   endif
   set echo
   g77 -c $OPT -fautomatic -Wno-globals -fno-globals $MODULE.f
   unset echo
endif
#
#   Apple Macintosh G5 system using OS X, xlf 8.1, and gcc.
#
#   This should work for Panther or Tiger, but it is a 32 bit version.
#   The xlf compiler does not yet support the 64 bit address space of
#   the new Tiger OS, sunt lacrimae rerum.
#
#   Why would you want to buy xlf in spite of being blocked from full
#   64 bit computing?   Some representative tests show that it is good
#   good to use a compiler that knows the chip's instruction set, these
#   are from a 2.3 GHz G5 Xserve running Tiger,
#                        g77 3.4      xlf 8.1
#       RHF gradient       371          238 CPU seconds
#       MP2 gradient       622          523
#        GVB hessian       667          572
#     MCSCF gradient       890          523
#   The xlf FORTRAN compiler is marketed by Absoft, at www.absoft.com.
#   Absoft's initial pricing (as of 2/2004) for this compiler was
#      $399 academic, $599 government, and $999 commercial.
#   Note that the macG5 version uses gcc, so you do not need to buy xlc.
#   See the mac32 target just above about obtaining Apple's gcc.
#
#   The G5 version is essentially an IBM AIX version, due to the compiler
#   being the same one.  See the 'ibm32' comments for compiler options.
#   -qextname lets us access the BLAS routines found in Apple's vecLib.
#
if ($TARGET == macG5) then
   set  OPT='-O3 -qarch=g5 -qtune=g5'
   set echo
   xlf -c $OPT -qintsize=4 -qnosave -qspillsize=1500 -qextname \
       -qflag=W:W -qhalt=W $MODULE.f
   unset echo
endif
#
# Options for f90 under SUPER-UX on the NEC SX Series are
#      -ebw enable passing scalar arguments and set all word size 64bit
#      -size_t64 flags 64bit size_t and associated libraries
#      -pvtcl noassume vwork=stack sets vectorization temporaries parameters
#      -Nv  vectorization is turned off
#
if ($TARGET == necsx) then
   set OPT = '-Wf"-v -pvctl noassume vwork=stack"'
   if ($MODULE == mcqdpt) \
       set OPT='-Wf"-v -pvctl noassume vwork=stack noaltcode nodivloop -NO"'
   if ($MODULE == ddi) \
       set OPT='-Wf"-v -pvctl noassume vwork=stack -I /usr/include"'
#         compiler character problem
   if ($MODULE == inputc) set OPT='-Wf"-Nv"'
#         next ones are faster in scalar
   if ($MODULE == int2a)  set OPT='-Wf"-Nv"'
   if ($MODULE == int2b)  set OPT='-Wf"-Nv"'
   if ($MODULE == grd2a)  set OPT='-Wf"-Nv"'
   if ($MODULE == grd2b)  set OPT='-Wf"-Nv"'
   if ($MODULE == grd2c)  set OPT='-Wf"-Nv"'
   if ($MODULE == gugem)  set OPT='-Wf"-Nv"'
   if ($MODULE == gugdrt) set OPT='-Wf"-Nv"'
#
   set echo
   f90 -c -ebw -size_t64 $OPT $MODULE.f
   unset echo
endif
#
#  Options for SGI f77 under Irix, this pertains only to MIPS processors.
#  If you have an Altix from SGI, please use target 'linux-ia64'.
#
#  Different versions of the SGI compiler may not work with the fairly
#  aggressive -O3 optimization used below.  If you experience any numerical
#  problems, please try using -O2 rather than -O3 below.  It is unsafe to
#  use very aggressive optimizations like "-OPT:IEEE_arith=3:roundoff=3".
#
#  If you use f90, do not reset the units for RECL in the sed hacks above.
#
#  -i8/-i4 selects 8/4 byte integer and logical data types.
#  -show would add verbose printing of compiler phase information.
#  -automatic is the opposite of -static storage allocation.
#  -OPT:Olimit=0 removes subroutine size optimization limits.
#  -woff suppresses warnings (2290=type checking on calling args).
#
if (($TARGET == sgi32) || ($TARGET == sgi64)) then
   set OPT='-O3'
   if ($MODULE == grd2c)  set OPT='-O2'
   if ($MODULE == rxncrd) set OPT='-O2'
   if ($MODULE == gmsnbo) set OPT='-O2 -backslash'
   if ($TARGET == sgi64) set INTS=' -64 -i8'
   if ($TARGET == sgi32) set INTS='-n32 -i4'
   set FLAGS='-automatic -G0 -woff 2290 -OPT:Olimit=0'
   set echo
   f77 -c $OPT $INTS $FLAGS $MODULE.f
   unset echo
endif
#
#  There is a united clause for UltraSPARC and Opteron chips!
#  Options for UltraSPARC Sun f90 7.0 under Solaris  9, and
#  options for    Opteron Sun f90 8.1 under Solaris 10.
#  See also a f77 compiling clause for older systems commented out below.
#
#     -c        compile only
#     -v        print verbose information on compiler phases and options
#     -stackvar forces non-static storage
#     -fast     is a smorgasbord of all the below, if you wish to
#               override one you must *follow* the -fast with it.
#         -xtarget=native  (optimize for chip being compiled upon)
#         -O5        (see below)
#         -libmil    (inline some math routines)
#         -fsimple=2 (0,1,2 control floating point simplifications)
#         -dalign    (double word alignment and instructions)
#         -xlibmopt  (link to optimized math library)
#         -depend    (DO loop data dependency analysis)
#         -fns       (fast underflow handling)
#         -ftrap=common   (floating point error handling)
#         -xvector=yes    (select vectorized math library)
#         -xprefetch=yes  (auto generation of instruction prefetching)
#     -O1 = minimal optimization (must turn off -depend to use this)
#            you may want to set this a particular chip if you run
#            more times on a different system than you compile on.
#     -O2 = basic local and global optimizations (must turn off -depend)
#     -O3 = loop unrolling and additional global optimizations
#     -O4 = automatic inlining
#     -O5 = aggressive optimizations
#  Experience suggests that setting OPT to '-fast -O2 -nodepend' is
#  normally very safe, for any Solaris/f90 versions.
#
#  Chip selection is by -xarch=nnn, where nnn can be (among other values),
#     v8plus        any UltraSPARC, using 32 bit instructions
#     v9            any UltraSPARC, using 64 bit instruction set
#     pentium_pro   most Intel chips, using 32 bits
#     amd64         Opteron, using 64 bits
#  "uname -p" says the processor is sparc or i386, as a generic reply,
#  allowing us to distinguish the families, e.g. Opteron replies "i386"!
#  N.B.  We have not tested the "pentium_pro" 32 bit stuff below.
#
#  If you change -xarch, change it in all scripts: compall/comp/compddi/lked
#
if ($TARGET == sun32) then
   set BITS=32
   if (`uname -p` == sparc) set ARCH='-xarch=v8plus'
   if (`uname -p` == i386)  set ARCH='-xarch=pentium_pro'
endif
if ($TARGET == sun64) then
   set BITS=64
   if (`uname -p` == sparc) set ARCH='-xarch=v9'
#         the Opteron does not support quadruple precision.
   if (`uname -p` == i386) then
                            set ARCH='-xarch=amd64'
      if (($MODULE == qeigen) || ($MODULE == int2c)) then
         mv $MODULE.f $MODULE.junk
         sed -e "s/Q-/D-/g" \
             -e "s/Q+00/D+00/g" \
             -e "s/REAL\*16/DOUBLE PRECISION/" $MODULE.junk > $MODULE.f
         rm -f $MODULE.junk
      endif
   endif
endif
if (($TARGET == sun32) || ($TARGET == sun64)) then
   set OPT='-fast -O4'
#       next are detunings for f90 7.5 under Solaris 9 on SPARC
   if ($MODULE == grd2c)  set OPT='-fast -O4 -nodepend'
   if ($MODULE == gugdrt) set OPT='-fast -O2 -nodepend'
   if ($MODULE == grd2c)  set OPT='-fast -O2 -nodepend' # prcivc
   if ($MODULE == trnstn) set OPT='-fast -O2 -nodepend'
#       next are detunings for f90 8.1 under Solaris 10 on Opteron
   if ($MODULE == mp2ddi) set OPT='-fast -O4 -nodepend'
   if ($MODULE == umpddi) set OPT='-fast -O4 -nodepend'
   if ($MODULE == zheev)  set OPT='-fast -O2 -nodepend'
   set WARN='-erroff=WARNING_1278,WARNING_1279,WARNING_1615'
   set echo
   f90 -c -stackvar -xtypemap=integer:$BITS $OPT $WARN $ARCH $MODULE.f
   unset echo
endif
#
#  Following is a potted history of Solaris versions that support
#  UltraSPARC chips.  64 bit O/S support came with Solaris 7, and
#  support for the UltraSPARC III chip came with Forte/f90 6.1.
#      year  Solaris   compilers      FORTRAN
#      1997   2.6      WorkShop 3.0   f77 4.2
#      1998     7      WorkShop 5.0   f90 2.0
#      2000     8      Forte 6        f90 6.0
#      2002     9      Forte 7        f90 7.0
#      2005    10      Sun Studio 10  f90 8.1
#  Version of   Solaris: "uname -sr", reply of 5.6 means 2.6, 5.9 means 9.
#  Version runs  64 bit: "isainfo -v"
#  Version of   FORTRAN: "f77 -V" or "f90 -V"
#  Version of processor: "fpversion", look at the -xtarget response.
#
#  We ran a E450 for many years with f77 4.2 under Solaris 2.6,
#  never using Solaris 7 or 8, instead we jumped directly to 9.
#  It would appear that the compiling clause above should be used for
#  Solaris 7, 8, or 9, so the below is relevant only to Solaris 2.6.
#
#  If you use the following old clause, change LDR to f77 in "lked".
#
#  If you have a pre-ultraSPARC system, try OPT='-O2' or '-O3' while
#  eliminating the -xarch flag, and you might also need -Nl30.
#
#--if ($TARGET == sun32) then
#--   set OPT='-fast -O4 -xarch=v8plus'
#--   if ($MODULE == ddi)    set OPT='-fast -O4 -nodepend -xarch=v8plus'
#--   if ($MODULE == grd2c)  set OPT='-fast -O4 -nodepend -xarch=v8plus'
#--   if ($MODULE == ormas1) set OPT='-fast -O4 -nodepend -xarch=v8plus'
#--   if ($MODULE == symslc) set OPT='-fast -O4 -nodepend -xarch=v8plus'
#--   set echo
#--   f77 -c $OPT -stackvar $MODULE.f
#--   unset echo
#--endif
#
#  Store the generated object code, clean up, and quit
#
mv $MODULE.o $OBJDIR/$MODULE.o
if ($TINKER == true) exit
rm -f $MODULE.f
if ($SRCDIR == .) rm -f $MODULE.src    # delete copy with no scalar code
unset echo
date
time
