#!/bin/csh
#
#   Run FTNCHEK, a FORTRAN syntax checker, on GAMESS.
#   This is meant to be stored permanently in 'tools' subdirectory,
#   but when used, it must be copied to 'source' and used from there!
#   The copy in 'source' will never be put into the repository, and
#   thus you may freely edit the individually checked file list below.
#
#   Option 1 is to test individual source code in the directory TestDir,
#   by the command 'checkgms'.
#
#   Option 2 is to test source code in the directory TestDir, plus the
#   remaining parts of GAMESS in the production code directory ProdDir,
#   as a total program, by the command 'checkgms all'.  In order to
#   run the second option, you must redimension a table in FTNCHEK,
#   namely, raise HASHSZ from 20930 to 40930 in ftnchek.h, as GAMESS
#   is now too big to fit in the default space.
#
#   FTNCHEK is available from its point of origin, Fordham University,
#   by anonymous FTP to ftp.dsm.fordham.edu, directory /pub/ftnchek.
#   or see http:/www.dsm.fordham.edu/~ftnchek/ftp-index.html
#   This program is also available at netlib and sunsite, typically.
#   The author, Robert Moniot, is a hero!
#
#   Note that in addition to the dimension change just noted, we suppress
#   a few of the warning messages issued by FTNCHEK for argument testing.
#   A list of these modifications can be sent to you, if you wish.
#
#   If used in a full 'git' clone, everything is in this place.
#
set TestDir=`pwd`
set ProdDir=`pwd`
#
#   If working on a just a few files, the full repository might be in a
#   different place.
#
#--set TestDir='/u1/mike/testgms/source'
#--set ProdDir='/u1/mike/webgms/source'
#
if ($1 == all) goto do_it_all_together
#
#   ----- this section tests each module separately -----
#
#   The 2nd argument to "comp" causes source activation only,
#   placing the pure FORTRAN in your ~/scr directory for checking.
#   -noextern suppresses messages about unresolved references
#   -common=2 ensures commons agree in type and length
#   -arguments=1 checks only number of args
#   -arguments=2 also ensures arguments agree in data type
#   -array=0 suppresses most array dimension checking
#   -calltree=1 generates who calls whom list, 0 disables this.
#   -crossref generates who is called by whom list, including commons
#
chdir $TestDir
#
#--foreach file (*.src)
#--foreach file (dft*.src)
foreach file (cphf.src gamess.src)
   set file=$file:r
   if ($file == ddi)    continue
   if ($file == ddishm) continue
   if ($file == ddio3k) continue
   if ($file == unport) continue
   if ($file == vector) continue
   ../comp $file true
   mv ../object/$file.f ~/scr
   ftnchek -noextern -common=2 -arguments=1 -array=0 \
           -calltree=0 -nocrossref -portability=tab \
           -f77=automatic-array,relops,cycle-exit,case-construct \
       ~/scr/$file.f >& ~/scr/$file.lis
   rm ~/scr/$file.f
   echo FTNCHEK output for this module is now in ~/scr/$file.lis
end
exit
#
#   ----- this section tests the entire program -----
#
do_it_all_together:
#
#   Here, we will analyze all sources, together.
#
#   Any source found in the working directory is taken as a priority,
#   otherwise we use a standard copy from the production code directory.
#   If new source module names are being developed, you must expand
#   the list of all GAMESS source modules as shown.
#
#         a) get a complete list of the production code,
#            including NEO and VB2000 plug-ins.
chdir $ProdDir
set module_list=(*.src)
chdir $ProdDir:h/qmnuc/neo
set module_list=($module_list *.src)
set module_list=($module_list vb2000.src vb2gms.src)
#         b) optionally, hand edit below to add any new module names
#            under development to the list
#--set module_list=(xxx.src yyy.src $module_list)
#
#        check new version if found in the development directory,
#        else make a temporary copy of the standard file to check.
chdir $TestDir
#
foreach file ($module_list)
   set file=$file:r
   if ($file == blas)   continue
   if ($file == neostb) continue
   if ($file == vector) continue
   if ($file == cchem)  continue
   if ($file == ga)     continue
   if (-e $file.src) then
      ../comp $file true
      mv ../object/$file.f ~/scr
   else
      set eraseSRC=true
      switch ($file)
         case vb2000:
         case vb2gms:
            if (-e ../vb2000/SRC/$file.src) then
               set eraseSRC=false
            else
               if (!(-d ../vb2000/SRC))  mkdir -p ../vb2000/SRC
               cp $ProdDir:h/vb2000/SRC/$file.src ../vb2000/SRC
            endif
            breaksw
         case neo:
         case neobas:
         case neocas:
         case neoden:
         case neofci:
         case neog2a:
         case neog2b:
         case neog2c:
         case neogrd:
         case neohf:
         case neohss:
         case neoint:
         case neomp2:
         case neonci:
         case neoopt:
         case neopos:
         case neoprp:
         case neosym:
         case neotrn:
         case neovib:
            cp $ProdDir:h/qmnuc/neo/$file.src .
            breaksw
         default:
            cp $ProdDir/$file.src .
            breaksw
      endsw
      ../comp $file true
      mv ../object/$file.f ~/scr
      if ($eraseSRC == true) then
         switch ($file)
            case vb2000:
            case vb2gms:
               rm ../vb2000/SRC/$file.src
               breaksw
            default:
               rm $file.src
               breaksw
         endsw
      endif
   endif
end
#
echo " "
echo Beginning FTNCHEK of the entire program, stand by...
date
chdir ~/scr
ftnchek -noextern -common=2 -arguments=1 -array=0 \
        -calltree=0 -nocrossref -resources=yes \
        -f77=automatic-array,relops -portability=tab \
        *.f >& gamess.lis
echo FTNCHEK diagnostic messages are now in ~/scr/gamess.lis
rm *.f
date
exit
