#!/bin/csh
#
#  SCRIPT TO RUN G2/97 TEST SET
#  BY SEAN A. NEDD
#
#  C-shell script to execute GAMESS test jobs, one job after the next.
#  Each output is put in its own separate log file in the gamess root.
#  Invoke this by typing 'rung2set'.
#
#  The jobs are run in batch queues if DQS is found on the system.
#
#  A script to check the results is ~/gamess/tools/checktst/checktst,
#  Edit this file to set the base path to GAMESS, and execute it to be
#  sure all the jobs TERMINATED NORMALLY, and got correct numbers too.
#
#  This script will be modified to have arguments added for user GAMESS template
#  Assumptions:
#  All open-shell species have Multiplicity = 2 unless otherwise specified
#  All open-shell species can be treated with SCFTYP=ROHF
#
set GMS_DIR=~$USER/gamessmaster
chdir $GMS_DIR 
set VERNO=tst1
set GAMESS=$GMS_DIR
set G2=$GMS_DIR/tests/testsets/g2tC1
set SCR=~$USER/scr
set GMS=xgms
set QUEUE=$USER
set MUM=NUM
#
echo "Running G2'97 Test Set"
echo "var1 and var2 should be from 001 to 148"
echo "The default is to run all 148 files"
echo "var1 is $1"
echo "var2 is $2"
echo "Add template filename under main GAMESS directory as third variable"
echo "else the GAMESS template in ~sean/gamessnew/g2tC1/temp is used"
echo "Charges and Multiplicities are setup in test set structure files"
echo "in ~sean/gamessmaster/tests/testset/g2tC1/"
echo "pwd is `pwd`"
#
#  copying all benchmarks to G2#NUM format
#  cleared first
#  naming can be found in LIST.DOC
#
#  Keeping default GAMESS group headings
   cp -r $G2/temp $G2/template
   cp -r $G2/templast $G2/template1
#
   if(-f $GAMESS/$3) then 
   echo "Using Filename"
    cat $3 > $G2/temp
   else
   echo "Using Default Template"
   endif
   if(-f $GAMESS/$4) then 
   echo "Using Appending Filename"
    cat $4 > $G2/templast
   else
   echo "Using Default appending Template"
   endif
#
foreach NUM ( 001 002 003 004 005 006 007 \
              008 009 010 011 012 013 014 015 \
              016 017 018 019 020 021 022 023 \
              024 025 026 027 028 029 030 \
              031 032 033 034 035 036 037 038 \
              039 040 041 042 043 044 045 \
              046 047 048 049 050 051 052 053 \
              054 055 056 057 058 059 060 \
              061 062 063 064 065 066 067 068 \
              069 070 071 072 073 074 075 \
              076 077 078 079 080 081 082 083 \
              084 085 086 087 088 089 090 \
              091 092 093 094 095 096 097 098 \
              099 100 101 102 103 104 105 \
              106 107 108 109 110 111 112 113 114 115 \
              116 117 118 119 120 121 122 123 124 125 \
              126 127 128 129 130 131 132 133 134 135 \
              136 137 138 139 140 141 142 143 144 145 \
              146 147 148 )
#
   if($NUM == $1) set MUM=MUM
   if($MUM == MUM) goto 10
   goto 20
10:
#
   if(-e $GAMESS/g2testc$NUM.inp) then
      rm -r $GAMESS/g2testc$NUM.inp
   endif
#
   if(-e $SCR/g2testc$NUM.dat) then
      rm -r $SCR/g2testc$NUM.dat
    if(-e $SCR/g2testc$NUM.irc) then
      rm -r $SCR/g2testc$NUM.irc
    endif
   endif
  if($NUM == $2) break 
20:
end
#
##############################################
#   G2-1 Test Set
##############################################
cp $G2/LiH.dat                   $G2/G2001.inp
cp $G2/BeH.dat                   $G2/G2002.inp
cp $G2/CH.dat                    $G2/G2003.inp
cp $G2/CH2.3.dat                 $G2/G2004.inp
cp $G2/CH2.1.dat                 $G2/G2005.inp
cp $G2/CH3.dat                   $G2/G2006.inp
cp $G2/CH4.dat                   $G2/G2007.inp
cp $G2/NH.dat                    $G2/G2008.inp
cp $G2/NH2.dat                   $G2/G2009.inp
cp $G2/NH3.dat                   $G2/G2010.inp
cp $G2/OH.dat                    $G2/G2011.inp
cp $G2/OH2.dat                   $G2/G2012.inp
cp $G2/FH.dat                    $G2/G2013.inp
cp $G2/SiH2.1.dat                $G2/G2014.inp
cp $G2/SiH2.3.dat                $G2/G2015.inp
cp $G2/SiH3.dat                  $G2/G2016.inp
cp $G2/SiH4.dat                  $G2/G2017.inp
cp $G2/PH2.dat                   $G2/G2018.inp
cp $G2/PH3.dat                   $G2/G2019.inp
cp $G2/SH2.dat                   $G2/G2020.inp
cp $G2/ClH.dat                   $G2/G2021.inp
cp $G2/Li2.dat                   $G2/G2022.inp
cp $G2/LiF.dat                   $G2/G2023.inp
cp $G2/C2H2.dat                  $G2/G2024.inp
cp $G2/C2H4.dat                  $G2/G2025.inp
cp $G2/C2H6.dat                  $G2/G2026.inp
cp $G2/CN.dat                    $G2/G2027.inp
cp $G2/HCN.dat                   $G2/G2028.inp
cp $G2/CO.dat                    $G2/G2029.inp
cp $G2/HCO.dat                   $G2/G2030.inp
cp $G2/H2CO.dat                  $G2/G2031.inp
cp $G2/H3COH.dat                 $G2/G2032.inp
cp $G2/N2.dat                    $G2/G2033.inp
cp $G2/H2NNH2.dat                $G2/G2034.inp
cp $G2/NO.dat                    $G2/G2035.inp
cp $G2/O2.dat                    $G2/G2036.inp
cp $G2/HOOH.dat                  $G2/G2037.inp
cp $G2/F2.dat                    $G2/G2038.inp
cp $G2/CO2.dat                   $G2/G2039.inp
cp $G2/Na2.dat                   $G2/G2040.inp
cp $G2/Si2.dat                   $G2/G2041.inp
cp $G2/P2.dat                    $G2/G2042.inp
cp $G2/S2.dat                    $G2/G2043.inp
cp $G2/Cl2.dat                   $G2/G2044.inp
cp $G2/NaCl.dat                  $G2/G2045.inp
cp $G2/SiO.dat                   $G2/G2046.inp
cp $G2/SC.dat                    $G2/G2047.inp
cp $G2/SO.dat                    $G2/G2048.inp
cp $G2/ClO.dat                   $G2/G2049.inp
cp $G2/FCl.dat                   $G2/G2050.inp
cp $G2/Si2H6.dat                 $G2/G2051.inp
cp $G2/CH3Cl.dat                 $G2/G2052.inp
cp $G2/H3CSH.dat                 $G2/G2053.inp
cp $G2/HOCl.dat                  $G2/G2054.inp
cp $G2/SO2.dat                   $G2/G2055.inp
##############################################
#   G2-2 Test Set
##############################################
cp $G2/BF3.dat                   $G2/G2056.inp
cp $G2/BCl3.dat                  $G2/G2057.inp
cp $G2/AlF3.dat                  $G2/G2058.inp
cp $G2/AlCl3.dat                 $G2/G2059.inp
cp $G2/CF4.dat                   $G2/G2060.inp
cp $G2/CCl4.dat                  $G2/G2061.inp
cp $G2/COS.dat                   $G2/G2062.inp
cp $G2/CS2.dat                   $G2/G2063.inp
cp $G2/CF2O.dat                  $G2/G2064.inp
cp $G2/SiF4.dat                  $G2/G2065.inp
cp $G2/SiCl4.dat                 $G2/G2066.inp
cp $G2/N2O.dat                   $G2/G2067.inp
cp $G2/ClNO.dat                  $G2/G2068.inp
cp $G2/NF3.dat                   $G2/G2069.inp
cp $G2/PF3.dat                   $G2/G2070.inp
cp $G2/O3.dat                    $G2/G2071.inp
cp $G2/F2O.dat                   $G2/G2072.inp
cp $G2/ClF3.dat                  $G2/G2073.inp
cp $G2/C2F4.dat                  $G2/G2074.inp
cp $G2/C2Cl4.dat                 $G2/G2075.inp
cp $G2/CF3CN.dat                 $G2/G2076.inp
cp $G2/propyne.dat               $G2/G2077.inp
cp $G2/allene.dat                $G2/G2078.inp
cp $G2/cyclopropene.dat          $G2/G2079.inp
cp $G2/propylene.dat             $G2/G2080.inp
cp $G2/cyclopropane.dat          $G2/G2081.inp
cp $G2/propane.dat               $G2/G2082.inp
cp $G2/butadiene.dat             $G2/G2083.inp
cp $G2/2-butyne.dat              $G2/G2084.inp
cp $G2/methylenecyclopropane.dat $G2/G2085.inp
cp $G2/bicyclobutane.dat         $G2/G2086.inp
cp $G2/cyclobutene.dat           $G2/G2087.inp
cp $G2/cyclobutane.dat           $G2/G2088.inp
cp $G2/isobutene.dat             $G2/G2089.inp
cp $G2/transbutane.dat           $G2/G2090.inp
cp $G2/isobutane.dat             $G2/G2091.inp
cp $G2/spiropentane.dat          $G2/G2092.inp
cp $G2/benzene.dat               $G2/G2093.inp
cp $G2/CH2F2.dat                 $G2/G2094.inp
cp $G2/CHF3.dat                  $G2/G2095.inp
cp $G2/CH2Cl2.dat                $G2/G2096.inp
cp $G2/CHCl3.dat                 $G2/G2097.inp
cp $G2/methylamine.dat           $G2/G2098.inp
cp $G2/methylcyanide.dat         $G2/G2099.inp
cp $G2/nitromethane.dat          $G2/G2100.inp
cp $G2/methylnitrite.dat         $G2/G2101.inp
cp $G2/methylsilane.dat          $G2/G2102.inp
cp $G2/formicacid.dat            $G2/G2103.inp
cp $G2/methylformate.dat         $G2/G2104.inp
cp $G2/acetamide.dat             $G2/G2105.inp
cp $G2/aziridine.dat             $G2/G2106.inp
cp $G2/cyanogen.dat              $G2/G2107.inp
cp $G2/dimethylamine.dat         $G2/G2108.inp
cp $G2/ethylamine.dat            $G2/G2109.inp
cp $G2/ketene.dat                $G2/G2110.inp
cp $G2/oxirane.dat               $G2/G2111.inp
cp $G2/acetaldehyde.dat          $G2/G2112.inp
cp $G2/glyoxal.dat               $G2/G2113.inp
cp $G2/ethanol.dat               $G2/G2114.inp
cp $G2/dimethylether.dat         $G2/G2115.inp
cp $G2/thiooxirane.dat           $G2/G2116.inp
cp $G2/dimethylsulfoxide.dat     $G2/G2117.inp
cp $G2/ethanethiol.dat           $G2/G2118.inp
cp $G2/dimethylsulfide.dat       $G2/G2119.inp
cp $G2/vinylfluoride.dat         $G2/G2120.inp
cp $G2/ethylchloride.dat         $G2/G2121.inp
cp $G2/vinylchloride.dat         $G2/G2122.inp
cp $G2/acrylonitrile.dat         $G2/G2123.inp
cp $G2/acetone.dat               $G2/G2124.inp
cp $G2/aceticacid.dat            $G2/G2125.inp
cp $G2/acetylfluoride.dat        $G2/G2126.inp
cp $G2/acetylchloride.dat        $G2/G2127.inp
cp $G2/propylchloride.dat        $G2/G2128.inp
cp $G2/isopropanol.dat           $G2/G2129.inp
cp $G2/methylethylether.dat      $G2/G2130.inp
cp $G2/trimethylamine.dat        $G2/G2131.inp
cp $G2/furan.dat                 $G2/G2132.inp
cp $G2/thiophene.dat             $G2/G2133.inp
cp $G2/pyrrole.dat               $G2/G2134.inp
cp $G2/pyridine.dat              $G2/G2135.inp
cp $G2/H2.dat                    $G2/G2136.inp
cp $G2/HS.dat                    $G2/G2137.inp
cp $G2/CCH.dat                   $G2/G2138.inp
cp $G2/C2H3.dat                  $G2/G2139.inp
cp $G2/CH3CO.dat                 $G2/G2140.inp
cp $G2/H2COH.dat                 $G2/G2141.inp
cp $G2/CH3O.dat                  $G2/G2142.inp
cp $G2/CH3CH2O.dat               $G2/G2143.inp
cp $G2/CH3S.dat                  $G2/G2144.inp
cp $G2/C2H5.dat                  $G2/G2145.inp
cp $G2/CH32CH.dat                $G2/G2146.inp
cp $G2/CH33C.dat                 $G2/G2147.inp
cp $G2/NO2.dat                   $G2/G2148.inp
#
##############################################
#
set MUM=NUM
foreach NUM ( 001 002 003 004 005 006 007 \
              008 009 010 011 012 013 014 015 \
              016 017 018 019 020 021 022 023 \
              024 025 026 027 028 029 030 \
              031 032 033 034 035 036 037 038 \
              039 040 041 042 043 044 045 \
              046 047 048 049 050 051 052 053 \
              054 055 056 057 058 059 060 \
              061 062 063 064 065 066 067 068 \
              069 070 071 072 073 074 075 \
              076 077 078 079 080 081 082 083 \
              084 085 086 087 088 089 090 \
              091 092 093 094 095 096 097 098 \
              099 100 101 102 103 104 105 \
              106 107 108 109 110 111 112 113 114 115 \
              116 117 118 119 120 121 122 123 124 125 \
              126 127 128 129 130 131 132 133 134 135 \
              136 137 138 139 140 141 142 143 144 145 \
              146 147 148 )
#
   if($NUM == $1) set MUM=MUM 
   if($MUM == MUM) goto 100
   goto 200
100:
#
   if(-e $SCR/g2testc$NUM.dat) then
      rm -r $SCR/g2testc$NUM.dat
    if(-e $SCR/g2testc$NUM.irc) then
      rm -r $SCR/g2testc$NUM.irc
    endif
   endif
#
#  Molecule listing in $G2/LIST.DOC
#  GAMESS template and geometry copied into input file
#
    cat $G2/temp $G2/G2$NUM.inp $G2/templast > $G2/g2testc$NUM.inp
    rm -r $G2/G2$NUM.inp
#
#  Input file read from the GAMESS directory
#
    mv $G2/g2testc$NUM.inp $GAMESS/g2testc$NUM.inp
#  
   if($NUM == $2) break
200:
#############
   end
#############
#
# Second foreach stops running input files that are not present
#
cp -r $G2/template $G2/temp
cp -r $G2/template1 $G2/templast
#
set MUM=NUM
foreach NUM ( 001 002 003 004 005 006 007 \
              008 009 010 011 012 013 014 015 \
              016 017 018 019 020 021 022 023 \
              024 025 026 027 028 029 030 \
              031 032 033 034 035 036 037 038 \
              039 040 041 042 043 044 045 \
              046 047 048 049 050 051 052 053 \
              054 055 056 057 058 059 060 \
              061 062 063 064 065 066 067 068 \
              069 070 071 072 073 074 075 \
              076 077 078 079 080 081 082 083 \
              084 085 086 087 088 089 090 \
              091 092 093 094 095 096 097 098 \
              099 100 101 102 103 104 105 \
              106 107 108 109 110 111 112 113 114 115 \
              116 117 118 119 120 121 122 123 124 125 \
              126 127 128 129 130 131 132 133 134 135 \
              136 137 138 139 140 141 142 143 144 145 \
              146 147 148 )
#
   if($NUM == $1) set MUM=MUM
   if($MUM == MUM) goto 1000
   goto 2000
1000:
#
 if(-e $G2/g2testc$NUM.log) then
   rm -r $G2/g2testc$NUM.log
 endif
#
echo 'starting g2testc'$NUM
  if (-e /usr/local/bin/dqs_execd) then
#  if($5 == null) then
#  if($5) then
#  if( -n $5) then
   if($5 == null) then
    $GAMESS/tools/$GMS -v $VERNO -q $QUEUE -l $G2/g2testc$NUM.log g2testc$NUM
   else
    $GAMESS/tools/$GMS -v $VERNO -q $QUEUE -l $G2/g2testc$NUM.log g2testc$NUM
#   $GAMESS/tools/$GMS -v $VERNO -q $5 -l $G2/g2testc$NUM.log g2testc$NUM
   endif
      sleep 3
  else
    $GAMESS/rungms $G2/g2testc$NUM  $VERNO 1 >&  $G2/g2testc$NUM.log
  endif
  if($NUM == $2) break
2000:
end
#
# Removing all G2$NUM.inp
#
foreach NUM ( 001 002 003 004 005 006 007 \
              008 009 010 011 012 013 014 015 \
              016 017 018 019 020 021 022 023 \
              024 025 026 027 028 029 030 \
              031 032 033 034 035 036 037 038 \
              039 040 041 042 043 044 045 \
              046 047 048 049 050 051 052 053 \
              054 055 056 057 058 059 060 \
              061 062 063 064 065 066 067 068 \
              069 070 071 072 073 074 075 \
              076 077 078 079 080 081 082 083 \
              084 085 086 087 088 089 090 \
              091 092 093 094 095 096 097 098 \
              099 100 101 102 103 104 105 \
              106 107 108 109 110 111 112 113 114 115 \
              116 117 118 119 120 121 122 123 124 125 \
              126 127 128 129 130 131 132 133 134 135 \
              136 137 138 139 140 141 142 143 144 145 \
              146 147 148 )
   if(-e $G2/G2$NUM.inp) then
    rm -r $G2/G2$NUM.inp
   endif 
end
#
echo "All done"
