#!/bin/csh

echo ''
      ./configure
source .configure

set fname = time_ave

if( -e ${fname}_${ARCH}.x | -e ${fname}_${ARCH}_nompi.x ) /bin/rm ${fname}_${ARCH}*.x

echo ''
echo Compiling ${fname}.F ...

set mpiflags = `echo mpi nompi`
foreach mpiflag ($mpiflags)

if( -e test.o ) /bin/rm test.o
if( -e test.F ) /bin/rm test.F
cat $fname.F timer.F > test.F

# SGI Compilation
# ---------------
if( ${ARCH} == 'IRIX64' ) then
     f90 -c -fixedform -extend_source -O3 -64 -r8 -i4 -mips4 -I $BASEDIR/include -Dopenmp -mp -OPT:Olimit=0 test.F
     f90 -o test.x -O3 -64 -r8 -i4 -mips4 -I . -mp test.o \
            -L$GFIODIR -L$BASEDIR/lib \
            -lgfio -lmfhdf -ldf -lz -lm
endif


# Linux Compilation
# -----------------
if( ${ARCH} == 'Linux' ) then

     set gfio = GMAO_gfio_r4
     set cfio = MAPL_cfio_r4
     set hdf  = GMAO_mfhdf3

ifort -c -extend_source -O2 -I. -D$mpiflag dynamics_lattice_module.F
ifort -c -extend_source -O2 -I. -D$mpiflag mpi_util.F
ifort -c -extend_source -O2 -I. -D$mpiflag mymalloc.F

ifort -c -DESMA  -I$BASEDIR/$ARCH/include/esmf \
         -O3 -assume byterecl  -extend_source -fpe0  -align dcommons -D$mpiflag -I . test.F

ifort -L$BASEDIR/$ARCH/lib \
      -o test.x test.o dynamics_lattice_module.o mpi_util.o mymalloc.o \
      -L$GFIODIR/$ARCH/lib \
      -l$cfio -l$gfio -l$hdf \
      -lmfhdf -ldf -ljpeg -lz -lsz -ldl -lc -lrt -lcprts -lunwind -lfmpi -lmpi -lmpio -lesmf

endif

/bin/rm test.F
/bin/rm test.o
if( -e  test.x ) then

   if( $mpiflag == 'mpi' ) then
       /bin/mv test.x  ${fname}_${ARCH}.x
   else
       /bin/mv test.x  ${fname}_${ARCH}_nompi.x
   endif

endif
end

echo "Created: "
/bin/ls -lat ${fname}_${ARCH}*.x
echo " "
if( -e  ${fname}_${ARCH}_nompi.x ) ./${fname}_${ARCH}_nompi.x
