#!/bin/bash
# Liejun Zhong / UMCES, 2007/05/15
# modified from John Wilkin's bulid_cblast.sh for C-shell
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# ROMS/TOMS Compiling Script                                            :::
#                                                                       :::
# Script to compile an user application where the application-specific  :::
# files are kept separate from the ROMS source code.                    :::
#                                                                       ::: 
# Q: How/why does this script work?                                     :::
#                                                                       :::
# A: The ROMS makefile configures user-defined options with a set of    :::
#    flags such as ROMS_APPLICATION. Browse the makefile to see these.  :::
#    If an option in the makefile uses the syntax ?= in setting the     :::
#    default, this means that make will check whether an environment    :::
#    variable by that name is set in the shell that calls make. If so   :::
#    the environment variable value overrides the default (and the      :::
#    user need not maintain separate makefiles, or frequently edit      :::
#    the makefile, to run separate applications).                       :::
#                                                                       :::
# An argument to make may be passed when executing this script.         :::
#                                                                       :::
# For example, you can use the -j flag to compile in parallel:          :::
#                                                                       :::
#    ./build.sh -j                                                      :::
# or                                                                    :::
#    ./build.sh -j4                                                     :::
#                                                                       :::
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

# Set the CPP option defining the particular application. This will
# determine the name of the ".h" header file with the application 
# CPP definitions. 
#
# Note that this value must match the parameter MyAppCPP in ocean.in

export ROMS_APPLICATION=CHESAPEAKE

# Set a local environmental variable to define the path to the directories
# where all this project's files are kept.

export MY_PROJECT_DIR=$PWD

# The path to the user's local current ROMS source code. 
#
# If using svn locally, this would be the user's Working Copy Path (WCPATH). 
# Note that one advantage of maintaining your source code locally with svn 
# is that when working simultaneously on multiple machines (e.g. a local 
# workstation, a local cluster and a remote supercomputer) you can checkout 
# the latest release and always get an up-to-date customized source on each 
# machine. This script is designed to more easily allow for differing paths 
# to the code and inputs on differing machines. 

export MY_ROMS_SRC=../ROMS/trunk_2009-08-31_SURA

# Other user defined environmental variables. See the ROMS makefile for
# details on other options the user might want to set here. 

export USE_MPI=on
export USE_MPIF90=on
export USE_OpenMP=
export USE_LARGE=on
export FORT=ifort

export NETCDF=/usr/local
export NETCDF_INCDIR=$NETCDF/include
export NETCDF_LIBDIR=$NETCDF/lib

export USE_DEBUG=
export USE_ARPACK=

# The rest of this script sets the path to the users header file and
# analytical source files, if any. See the templates in User/Functionals.

export MY_HEADER_DIR=${MY_PROJECT_DIR}


#export MY_ANALYTICAL_DIR=${MY_PROJECT_DIR}/Chesa/code

# Put the binary to execute in the following directory.

export BINDIR=${MY_PROJECT_DIR}

# Put the f90 files in a project specific Build directory to avoid conflict
# with other projects. 

export SCRATCH_DIR=${MY_PROJECT_DIR}/Build

# Go to the users source directory to compile. The options set above will
# pick up the application-specific code from the appropriate place.

 cd ${MY_ROMS_SRC}

# Remove build directory. 

  make clean

# Compile (the binary will go to BINDIR set above).  

if [ $# -eq 0 ]; then
  make
else
  make $1
fi
