#!/bin/sh
###############################################################################
#                                                                             #
# Script Name: estofs_tide_fac.sh                                             #
#                                                                             #
# Technical Contact(s): Name: Yuji Funakoshi       Org: NOS/OCS/CSDL/MMAP     #
#                       Phone: 301-7132809 ext.113                            #
#                       E-Mail: yuji.funakoshi@noaa.gov                       #
#                                                                             #
# Abstract:                                                                   #
# This program is used to calculate nodal factors and equilibium argument     #
#                                                                             #
# Usage: ./estofs_tide_fac.sh ${time_spi}                                     #
#                                                                             #
# Input Parameters:                                                           #
# time_spi:  start time for 6.75 days tidal spin-up run , e.g., YMDH          #
#                                                                             #
# Language:   Bourne Shell Script                                             #
#                                                                             #
# Target Computer: CIRRUS/STRATUS at NCEP                                     #
#                                                                             #
# Estimated Execution Time: < 10 seconds                                      #
#                                                                             #
# Suboutines/Functions Called:                                                #
# Name               Directory Location            Description                #
# estofs_tide_fac    /exec                         calculate nodal factor and #
#                                                  equilibium argument        #
#                                                                             #
# Input Files:                                                                #
# Name               Directory Location            Description                #
# tide_fac.ctl       /work                         tide_fac control file      #
#                                                                             #
# Output Files:                                                               #
# Name               Directory Location            Description                #
# estofs_modID       /fix                          nodal factor and           # 
# nod_equi                                         equilibium argument        #
#                                                                             #
# Libraries Used: see the makefile                                            #
#                                                                             #
# Author Name: Yuji Funakoshi                      Creation Date: Dec, 2011   #
#                                                                             #
# Revisions:                                                                  #
# Date               Author                        Description                #
#                                                                             #
# Remarks:                                                                    #
# estofs_modID_nod_equi is save at /fix                                       #
#                                                                             #
###############################################################################
set -x
# Start of estofs_tide_fac.sh script ---------------------------------------- #
# 1. Set times

  time_spi=$1

# --------------------------------------------------------------------------- #
# 2. Compute nodal factors and equilibium arguments 

  rm -f tide_fac.ctl tide_fac.log
  run_day=365 # assume 1 year
  output_file=${RUN}_${modID}_nod_equi
  echo $output_file >> tide_fac.ctl  
  echo $run_day >> tide_fac.ctl 

  yyyy=`echo $time_spi | cut -c1-4 `
  mm=`echo $time_spi |cut -c5-6 `
  dd=`echo $time_spi |cut -c7-8 `
  cycle=`echo $time_spi |cut -c9-10 `
  echo $cycle $dd $mm $yyyy >> tide_fac.ctl

# --------------------------------------------------------------------------- #
# 2. Execute estofs_tide_fac

  export pgm="estofs_tide_fac"
  prep_step
  startmsg
  $EXECestofs/estofs_tide_fac < tide_fac.ctl > tide_fac.log 2>errfile
  export err=$?; err_chk

# End of estofs_tide_fac.sh script ------------------------------------------ #
