#!/bin/sh
cd ..
HOMEnos=`pwd`
#HOMEnos=/nos/save/wx21az/nosofs_shared.v2.0.0
export SORCnos=$HOMEnos/sorc
export EXECnos=$HOMEnos/exec
export LIBnos=$HOMEnos/lib
#export EXECofs=/nos/save/wx21az/ngofs.v1.0.0/exec
export EXECofs=$HOMEnos/../ngofs.v2.0.0/exec
export EXECcreofs=$HOMEnos/../creofs.v1.0.0/exec
export EXECcbofs=$HOMEnos/../cbofs.v2.0.0/exec
export EXECtbofs=$HOMEnos/../tbofs.v2.0.0/exec
export EXECdbofs=$HOMEnos/../dbofs.v2.0.0/exec

if [ ! -s $EXECnos ]
then
  mkdir -p $EXECnos
fi
export LIBnos=$HOMEnos/lib

if [ ! -s $EXECnos ]
then
  mkdir -p $EXECnos
fi

if [ ! -s $EXECofs ]
then
  mkdir -p $EXECofs
  mkdir -p $EXECcreofs
  mkdir -p $EXECcbofs
  mkdir -p $EXECtbofs
  mkdir -p $EXECdbofs
fi

if [ ! -s $LIBnos ]
then
  mkdir -p $LIBnos
fi


cd $SORCnos

cd $SORCnos/nos_ofs_utility.fd
rm -f *.o *.a
gmake -f makefile
if [ -s $SORCnos/nos_ofs_utility.fd/libnosutil.a ]
then
  chmod 755 $SORCnos/nos_ofs_utility.fd/libnosutil.a
  mv $SORCnos/nos_ofs_utility.fd/libnosutil.a ${LIBnos}
fi

cd $SORCnos/nos_ofs_combine_field_netcdf_selfe.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_combine_station_netcdf_selfe.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_combine_hotstart_out_selfe.fd
rm -f *.o *.a
gmake -f makefile


cd $SORCnos/nos_ofs_create_forcing_met.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_create_forcing_met_fvcom.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_create_forcing_obc_tides.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_create_forcing_obc.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_create_forcing_obc_fvcom.fd
rm -f *.o *.a
gmake -f makefile
gmake -f makefile1

cd $SORCnos/nos_ofs_create_forcing_obc_selfe.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_create_forcing_river.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_met_file_search.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_read_restart.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_read_restart_fvcom.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_read_restart_selfe.fd
rm -f *.o *.a
gmake -f makefile

cd $SORCnos/nos_ofs_reformat_ROMS_CTL.fd
rm -f *.o *.a
gmake -f makefile

##  Compile ocean model of FVCOM for NGOFS
cd  $SORCnos/FVCOM3.1.6/FVCOM3.1.6_source/libs/julian
gmake clean
gmake -f makefile
rm -f *.o
cd $SORCnos/FVCOM3.1.6/METIS_source
gmake clean
gmake -f makefile

cd $SORCnos/FVCOM3.1.6/FVCOM3.1.6_source
gmake clean
gmake -f makefile_NGOFS
if [ -s  fvcom_NGOFS ]; then
  mv fvcom_NGOFS $EXECofs/.
#  mv fvcom_NGOFS /nos/save/wx21az/ngofs.v1.0.0/exec
else
  echo 'fvcom executable is not created'
fi  
##  Compile ocean model of SELFE for CREOFS
cd $SORCnos/SELFE
gmake -f makefile
if [ -s  selfe_CREOFS ]; then
  mv selfe_CREOFS $EXECcreofs/.
#  mv selfe_CREOFS /nos/save/wx21az/creofs.v1.0.0/exec
else
  echo 'selfe executable is not created'
fi  

##  Compile ocean model of ROMS for CBOFS
cd $SORCnos/roms.mpi.fd/ROMS.Version619
gmake -f makefile_cbofs
if [ -s  cbofs_roms_mpi ]; then
  mv cbofs_roms_mpi $EXECcbofs/.
#  mv cbofs_roms_mpi /nos/save/wx21az/cbofs.v2.0.0/exec
else
  echo 'roms executable for CBOFS is not created'
fi  
##  Compile ocean model of ROMS for DBOFS
cd $SORCnos/roms.mpi.fd/ROMS.Version619
gmake -f makefile_dbofs
if [ -s  dbofs_roms_mpi ]; then
  mv dbofs_roms_mpi $EXECdbofs/.
#  mv dbofs_roms_mpi /nos/save/wx21az/dbofs.v2.0.0/exec
else
  echo 'roms executable for CBOFS is not created'
fi  
##  Compile ocean model of ROMS for TBOFS
cd $SORCnos/roms.mpi.fd/ROMS.Version619
gmake -f makefile_tbofs
if [ -s  tbofs_roms_mpi ]; then
  mv tbofs_roms_mpi $EXECtbofs/.
#  mv tbofs_roms_mpi /nos/save/wx21az/tbofs.v2.0.0/exec
else
  echo 'roms executable for CBOFS is not created'
fi  
