#!/bin/csh -f
set verbose

###----------------------
### specifics of the test
###----------------------

setenv POPEXEDIR .
setenv POPSOURCEDIR ../../..
setenv POPSOURCEDIR2 ./source
setenv POPDRIVERNONEDIR ../../../drivers/cpl_none
setenv POPDIR .
setenv POPARCH ibm 

###------------------------------
### copy this tag's source/ files
###------------------------------
set SOURCE_FILES = ( time_management kinds_mod constants blocks domain grid  exit_mod registry POP_KindsMod POP_IOUnitsMod POP_ErrorMod POP_BlocksMod POP_DistributionMod spacecurve_mod POP_FieldMod POP_GridDimMod POP_GridHorzMod POP_GridVertMod distribution POP_DomainSizeMod )
foreach file ($SOURCE_FILES)
 if !(-e ${file}.F90) /bin/cp -p $POPSOURCEDIR/source/${file}.F90 .
end

###----------------------------------------
### copy this tag's drivers/cpl_none/ files
###----------------------------------------
set SOURCE_FILES2 = ( io io_tools io_types io_netcdf io_binary)
foreach file ($SOURCE_FILES2)
 if !(-e ${file}.F90) /bin/cp -p $POPDRIVERNONEDIR/${file}.F90 .
end

###----------------------------------------
### copy this tag's serial/ files
###----------------------------------------
set SERIAL_FILES = ( broadcast communicate  POP_CommMod POP_HaloMod gather_scatter global_reductions )
foreach file ($SERIAL_FILES)
 if !(-e ${file}.F90) /bin/cp -p $POPSOURCEDIR/serial/${file}.F90 .
end

###----------------------------------------
### copy this test's driver files
###----------------------------------------
cp $POPSOURCEDIR2/*.F90 .

###----------------------------------------
### copy this test's SourceMods files
###----------------------------------------
cp ./SourceMods/src.pop2/*.F90 .

set optimize yes

if ($optimize == yes) then
  if (-e pop) rm pop
else
  if (-e pop_db) rm pop_db
endif

###----------------------------------------
### build
###----------------------------------------

/bin/cp ../../../build/GNUmakefile .

mkdir build
/bin/cp -r ../../../build/*.awk build
/bin/cp -r ../../../build/*.mk  build
/bin/cp -r ../../../build/*.gnu build

###----------------------------------------
### test time management
###----------------------------------------

if ($optimize == yes) then
  gmake OPTIMIZE=yes
  pop
else
  gmake OPTIMIZE=no
  pop_db
endif

######
exit
######

if ($optimize == yes) then
  /bin/rm pop
else
  /bin/rm pop_db
endif

/bin/rm compile/*.f90 *.o

/bin/rm -r build
/bin/rm -r compile
/bin/rm GNUmakefile
foreach file ($SOURCE_FILES)
/bin/rm $file.F90
end

foreach file ($SERIAL_FILES)
/bin/rm $file.F90
end

