03-regtests文件夹(官方给的ww3运行例子)


03-regtests文件夹(官方给的ww3运行例子)

参考资料

在手册 5.11 Running test cases 的相关介绍;

waves-workshop-exercise-regtest (我的 zotero海洋数值模式文库 WavaWatch3/wave-workshop-exercise文件夹);

回归测试(regression tests)

在regtests目录下有以下回归测试(regression tests)。

ww3_tp1.1:一维传播,沿赤道(无陆地)环绕世界。

ww3_tp1.2:一维传播,沿子午线(无陆地)。

ww3_tp1.3:一维传播,浅滩试验(shoaling test.)。

WW3_tp1.4: 一维传播,光谱折射(X)。

WW3_tp1.5: 一维传播,光谱折射(Y)。

ww3_tp1.6: 一维传播,流阻挡波(wave blocking by current)。

ww3_tp1.7: 一维传播,IG波的产生。

ww3_tp1.8: 一维传播,波浪在海滩上的破裂。

ww3_tp1.9: 一维传播,Beji 和 Battjes (1993)的有障碍水槽案例。

ww3_tp2.1: 角度下的二维传播,带网格。

ww3_tp2.2: 在没有陆地的情况下,在半个地球上进行二维传播(有方向性传播)。

ww3_tp2.3: 二维传播,GSE测试。

ww3_tp2.4: 二维传播,东太平洋曲线网格测试。

ww3_tp2.5: 二维传播,北极网格,曲线网格测试。

ww3_tp2.6: 二维传播,利蒙港非结构化网格测试。

ww3_tp2.7: 二维非结构网格上的反射。

ww3_tp2.8: 二维规则网格上的潮汐成分。

ww3_tp2.9: 障碍物网格的测试。

ww3_tp2.10: SMC网格的测试。

ww3_tp2.11: 旋转网格的测试。

ww3_tp2.12: 系统跟踪的测试。

ww3_tp2.13: 与网格成角度的传播测试(三极)。

ww3_tp2.14: 使用OASIS耦合器进行玩具模型测试。

ww3_tp2.15: 测试时空极值参数。

ww3_tp2.16: 使用ARC选项在SMC网格上进行二维传播。

ww3_tp2.17: 非结构化网格与明式方案与隐式方案的卡片式与域分解式(Card Deck vs Domain Decompostion )的比较

ww3_tp2.16: 带有北极点处理的二维SMC传播测试。(是2.16还是2.18?)

ww3_ts1:源项测试,限时增长。

ww3_ts2:源项测试,取数有限增长。

ww3_ts3:源项试验,飓风与单一移动网格。

ww3_ts4: 源术语测试,未解决的障碍。

ww3_tic1.1: 波-冰相互作用,Sice的一维测试。

ww3_tic1.2: 波浪-冰的相互作用,一维测试 “搁浅 “效应。

ww3_tic1.3: 波-冰相互作用,折射效应的一维测试。

ww3_tic1.4: 波与冰的相互作用,用浮冰和冰的厚度进行一维测试。

ww3_tic2.1: 波-冰相互作用,Sice的二维测试。

ww3_tic2.2: 波-冰相互作用,非均匀冰的二维试验。

ww3_tic2.3:波-冰相互作用,厚度增加的均匀冰的二维试验。

ww3_tbt1.1: 波-泥相互作用,Smud的一维试验。

ww3_tbt2.1: 波-泥相互作用,Smud的二维试验。

ww3_tpt1.1: 替代光谱划分方法的测试。

ww3_ta1: ww3_uprstrt,更新同质条件下的重启文件(1点模型)。

mww3_test_01: 测试带湿润和干燥的扩展网格掩模,等等。

mww3_test_02: 单一内网格的双向嵌套测试。

mww3_test_03: 重叠网格和双向嵌套试验(6个网格的版本,有高分辨率网格的海滩。)

mww3_test_04: 静止海浪条件下的海流或海山双向嵌套试验。

mww3_test_05: 三个嵌套的飓风网格与移动网格测试。

mww3_test_06: 不规则网格的测试 ww3_multi。

mww3_test_07: 对非结构化网格的测试 w/w3_multi。

mww3_test_08: 风和冰输入的测试。


run_test 脚本

这些回归测试现在使用regtests/bin目录下的run_test脚本运行(主要作者:Tim Campbell)。如何运行这个脚本,包括选项,可以通过运行 “run_test -h “来显示。

在每个回归测试文件夹,都有一个 info 文件教你用 run_test 如何运行,例如,

此外,回归测试文件夹还包含 input 文件夹(包含测试用例的输入文件) ,work 文件夹(一个用于模型输出的草稿目录(scratch directory))

强烈建议把 run_test 脚本弄懂,这样,user 可以根据自己的需求,把自己例子融入进 regtests这个体系。


未注释

#!/bin/bash
# --------------------------------------------------------------------------- #
#                                                                             #
# Script for running WW-III tests.                                            #
#                                                                             #
#                    Last update :         27-Jan-2014                        #
# --------------------------------------------------------------------------- #
#    Modification history
#    27-Jan-2014 : Adapts ww3_ounf section for multigrid  ( version 4.18 )
#
# Limitations:
#  - For each ww3_grid_*.inp, run_test process *all* ww3_prep_*.inp files.
#    For example, when processing ww3_grid_1.inp, it does not know that
#    it needs to process ww3_prep_a.inp and *not* process ww3_prep_b.inp.
#    This can be addressed in the future by adding instructions for prep
#    to the grdset file.
#  - When running through ww3_prep, run_test is not smart enough to process
#    multiple input files of the same type. For example, for wind it wants
#    a file ww3_prep_wind.inp and does not know what to do if you have two 
#    files, ww3_prep_wind_hwna_15m.inp and ww3_prep_wind_gfs_30m.inp. 
#    It needs to rename wind.ww3 as wind.wind_gfs_30m, for example, but
#    looks for wind_gfs_30m.ww3 where it should look for wind.ww3. Another
#    loop is needed to make this work.

# --------------------------------------------------------------------------- #
# 1. Function definitions                                                     #
# --------------------------------------------------------------------------- #

# 1.a Error message function
errmsg ()
{
  echo "" 2>&1
  while [ $# != 0 ]
  do
    echo "ERROR: $1" 2>&1
    shift
  done
  echo "" 2>&1
}

# 1.b Usage function
myname="`basename $0`"  #name of script
optstr="a:c:C:defg:Ghi:m:n:No:Op:q:r:s:t:Sw:"  #option string for getopt function
usage ()
{

cat 2>&1 << EOF

Usage: $myname [options] source_dir test_name
Required:
  source_dir : path to top-level of WW3 source
  test_name  : name of test case (directory)
Options:
  -a ww3_env       : use WW3 environment setup file <ww3_env>
                   :   *default is <source_dir>/bin/wwatch3.env
                   :   *file will be created if it does not already exist
  -c cmplr         : setup comp & link files for specified cmplr
  -C coupl         : invoke test using <coupl> coupled application
                   :   OASIS : OASIS3-mct ww3_shel coupled application
                   :   ESMF  : ESMF ww3_multi coupled application
  -d               : invoke main program using gdb (non-parallel)
  -e               : prompt for changes to existing WW3 environment
  -f               : force pre- and post-processing programs to be compiled
                   : non-MPI (i.e., with SHRD switch); default is all programs
                   : compiled with unmodified switch settings
  -g grid_string   : use ww3_grid_<grid_string>.inp
  -G               : create GrADS data files using gx_outX.inp
  -h               : print usage and exit
  -i inpdir        : use inputs in test_name/<inpdir> (default  test_name/input)
  -m grid_set      : execute multi-model test
                   :   *grid names are obtained from input/<grid_set>
                   :   *ww3_multi_<grid_set> will execute instead of ww3_shel
                   :   *to execute a single model test case with ww3_multi use
                   :    grid_set = none
  -n nproc         : specify <nproc> processors for parallel run
                   :   *some <runcmd> programs do not require <nproc>
                   :   *ignored if -p <runcmd> or -O is not specified
  -N               : use namelist (.nml) input instead of .inp (if available)
  -o outopt        : limit output post-processing based on <outopt>
                   :   native : post-process only native output
                   :   netcdf : post-process only NetCDF output
                   :   both   : post-process both native and NetCDF output
                   :   * default is native
                   :   * note that required input files must be present for
                   :     selected output post-processing to occur
  -O               : parallel run using OpenMP paradigm and OMP_NUM_THREADS
                     environment variable and number of processors defined with
                     the -n np option
  -p runcmd        : run in parallel using <runcmd> to start program
                   :   *MPICH or OpenMPI: mpirun or mpiexec (default <nproc> = 1)
                   :   *IBM with Loadleveler: poe (no <nproc> required)
                   :   *LSF: mpirun.lsf (no <nproc> required)
  -q program       : exit script after program <program> executes
  -r program       : only execute program <program>
  -s switch_string : use switch_<switch_string>
  -S               : create stub file <finished>. with end data and time.
                     tests not executed if file is found.
  -t nthrd         : Threading option. (this is system dependant and can be used
                   : only for the hybrid option)
  -w work_dir      : run test case in test_name/work_dir (default test_name/work)

EOF
}


# --------------------------------------------------------------------------- #
# 2. Preparations                                                             #
# --------------------------------------------------------------------------- #

# 2.a Setup array of command-line arguments
args=`getopt $optstr $*`
if [ $? != 0 ]
then
  usage
  exit 1
fi
set -- $args

# 2.b Process command-line options
exit_p=none
exec_p=none
multi=0
dist=0
inpdir=input
outopt=native
grads=0
coupl=none
while :
do
  case "$1" in
  -a) shift; ww3_env="$1" ;;
  -c) shift; cmplr="$1" ;;
  -C) shift; coupl="$1" ;;
  -d) use_gdb=1 ;;
  -e) prompt=1 ;;
  -f) force_shrd=1 ;;
  -g) shift; grdstr="$1" ;;
  -G) grads=1 ;;
  -h) help=1 ;;
  -i) shift; inpdir="$1" ;;
  -m) shift; grdset="$1" ;
      if [ $grdset = none ]
      then
        multi=1
      else
        multi=2
      fi ;;
  -n) shift; nproc="$1" ;;
  -N) nml_input=1 ;;
  -o) shift; outopt="$1" ;;
  -O) pomp=1 ;;
  -p) shift; runcmd="$1" ; runcmd1=$runcmd ; pmpi=1 ;;
  -q) shift; exit_p="$1" ;;
  -r) shift; exec_p="$1" ;;
  -s) shift; swtstr="$1" ;;
  -S) stub=1 ;;
  -t) shift; nthrd="$1" ;;
  -w) shift; wrkdir="$1" ;;
  --) break ;;
  esac
  shift
done
shift #remove the trailing --
if [ $help ]
then
  usage
  exit 1
fi
#uncomment next line to add S & T switches to every test 
#testST=1  
if [ ! $exec_p = "none" ]
then
  exit_p=$exec_p
fi
case $outopt in
  native|netcdf|both) ;;
  *) errmsg "outopt = $outopt not supported" ; usage ; exit 1 ;;
esac
case $coupl in
  none) ;;
  OASIS)
    if [ $multi -ne 0 ]
    then
      errmsg "coupl = $coupl with ww3_multi is not supported"
      usage
      exit 1
    fi
  ;;
  ESMF)
    if [ $multi -eq 0 ]
    then
      errmsg "coupl = $coupl with ww3_shel is not supported"
      usage
      exit 1
    fi
    if [ -z "$ESMFMKFILE" ]
    then
      errmsg "ESMFMKFILE must be defined with coupl = $coupl"
      usage
      exit 1
    fi
  ;;
  *) errmsg "coupl = $coupl not supported" ; usage ; exit 1 ;;
esac

# 2.c Get required arguments
if [ ! $# = 0 ]
then
  path_s="$1" ; shift
else
  usage
  exit 1
fi
if [ ! $# = 0 ]
then
  testnm="$1" ; shift
else
  usage
  exit 1
fi

# 2.d Convert source path from "relative" to "absolute"
if [ ! -d $path_s ]
then
  errmsg "$path_s not found"
  usage
  exit 1
fi
path_s="`cd $path_s 1>/dev/null 2>&1 && pwd`"

# 2.e Path to test directory
path_t="`pwd`/$testnm"
if [ ! -d $path_t ]
then
  errmsg "$path_t not found"
  usage
  exit 1
fi

# 2.f Path to input files
path_i="$path_t/$inpdir"
if [ ! -d $path_i ]
then
  errmsg "$path_i not found"
  usage
  exit 1
fi

# 2.g Path to working directory
if [ $wrkdir ]
then
  path_w="$path_t/$wrkdir"
else
  path_w="$path_t/work"
fi

# 2.h Paths to source subdirectories
path_e="$path_s/exe"
path_a="$path_s/aux"
path_b="$path_s/bin"
if [ ! -d $path_a ]
then
  errmsg "$path_a not found"
  exit 1
fi
if [ ! -d $path_b ]
then
  errmsg "$path_b not found"
  exit 1
fi

# 2.i Check for switch file
if [ $swtstr ]
then
  file_c="$path_i/switch_$swtstr"
else
  file_c="$path_i/switch"
fi
if [ ! -f $file_c ]
then
  errmsg "switch file $file_c not found"
  exit 1
fi

# 2.j If parallel execution, then check for proper switches
#     Also, set default run command
if [ $pmpi ]
then
  if [ "`grep MPI $file_c`" ]
  then :
  else
    errmsg "Improper switch setup for MPI run"
    exit 1
  fi
else
  if [ $use_gdb ]
  then
    runcmd='gdb'
  else
    runcmd=''
  fi
fi

if [ $pomp ]
then
  if [ "`grep OMP $file_c`" ]
  then :
  else
    errmsg "Improper switch setup for OpenMP run"
    exit 1
  fi
fi

# 2.k Setup for multi-model (and defaults for non-multi-model)
gu=""
if [ $multi -eq 2 ]
then
  if [ -f $path_i/$grdset ]
  then
    model_grids="`awk '/^MODEL:/' $path_i/$grdset | sed 's/MODEL\://'`"
    input_grids="`awk '/^INPUT:/' $path_i/$grdset | sed 's/INPUT\://'`"
    point_grids="`awk '/^POINT:/' $path_i/$grdset | sed 's/POINT\://'`"
    intgl_grids="`awk '/^INTGL:/' $path_i/$grdset | sed 's/INTGL\://'`"
  else
    errmsg "grid_set file $path_i/$grdset not found"
    exit 1
  fi
else
  model_grids="none"
  input_grids="none"
  point_grids="none"
  intgl_grids="none"
fi
all_grids=$model_grids
for g in $input_grids $point_grids $intgl_grids
do
  if [ -z "`echo $all_grids | grep $g`" ]
  then
    all_grids="$all_grids $g"
  fi
done

# 2.l Setup WW3
if [ $ww3_env ]
then
  d="`dirname $ww3_env`"; b="`basename $ww3_env`";
  export WWATCH3_ENV="`cd $d 1>/dev/null 2>&1 && pwd`/$b"
else
  export WWATCH3_ENV="$path_b/wwatch3.env"
fi
if [ -f $path_b/w3_setup ]
then
  args="-t $path_s/tmp $path_s"
  if [ $cmplr ]
  then
    args="-c $cmplr $args"
  fi
  if [ $prompt ]
  then :
  else
    args="-q $args"
  fi
  if $path_b/w3_setup "$args"
  then :
  else
    errmsg "Error occured during w3_setup"
    exit 1
  fi
else
  errmsg "WW3 setup script $path_b/w3_setup not found"
  exit 1
fi

#if [ ! -e $path_b/w3adc ]
#then
#  $path_b/w3_setup $path_s -q
#fi
#
#if [ ! -e $path_b/comp ] || [ ! -e $path_b/link ]
#then
#  errmsg "No comp/link file found in $path_b. Use option -c"
#  exit 1
#fi  
#
#if [ ! -e $path_b/switch ]
#then
#  $path_b/w3_setup $path_s -s $file_c -q
#fi


# --------------------------------------------------------------------------- #
# 3. Execute Test                                                             #
# --------------------------------------------------------------------------- #
# 3.a Go to work directory and clean-up
mkdir -p $path_w
cd $path_w
if [ $exec_p = "none" ]
then
  ncfiles=`\ls *.nc 2>/dev/null | grep -v rmp_`
  if [ ! $stub ]
  then
    # restart, nest, etc. may have been placed there manually, so don't remove them
    \rm -f *.inp *.out *.txt $ncfiles finished
    \ls *.ww3  2>/dev/null | grep -v 'restart.ww3' | grep -v 'nest.ww3' | grep -v 'wind.ww3' | grep -v 'ice.ww3' | grep -v 'ice1.ww3' | xargs \rm 2>/dev/null
  fi
fi

if [ $multi -eq 0 ] && [ $coupl = "OASIS" ]
then
  if $path_i/prep_env.sh $path_i $path_w $cmplr $swtstr
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi
  export OASISDIR=$path_i/../work_oasis3-mct
fi

# 3.b Header
echo ' ' ; echo ' '
echo '                    ==================================   '
echo '                  ======> TEST RUN WAVEWATCH III <====== '
echo '                    ==================================   '
echo ' '
if [ -f $path_t/info ]
then
  cat $path_t/info
fi
echo ' '
echo " Input directory: $path_i"
echo " Switch file: $file_c"
echo ' '

if [ $stub ] && [ -f finished ]
then
  echo " Test already finished, skipping ..."
  echo ' '
  exit 0
fi

# 3.c Grid pre-processor ---------------------------------------------------- #

prog=ww3_grid
if [ $exec_p = $prog -o $exec_p = "none" ]
then

  echo ' '
  echo '+--------------------+'
  echo '|  Grid preprocessor |'
  echo '+--------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ] 
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  for g in $all_grids
  do

    if [ $multi -eq 2 ]
    then
      gu="_$g"
    fi

    if [ $grdstr ]
    then
      fileconf="${prog}_${grdstr}${gu}"
    else
      fileconf="${prog}${gu}"
    fi

    # select inp/nml files
    if [ $nml_input ] && [ ! -z "`ls ${path_i}/${fileconf}.nml 2>/dev/null`" ]
    then
      ifile="`ls ${path_i}/${fileconf}.nml 2>/dev/null`"
    else
      ifile="`ls $path_i/${fileconf}.inp 2>/dev/null`"
    fi


    if [ ! -f $path_e/$prog ]
    then
      errmsg "$path_e/$prog not found"
      exit 1
    fi
    if [ ! -f $ifile ]
    then
      errmsg "$ifile not found"
      exit 1
    fi

    # link conf file
    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
    then
      \rm -f $prog.nml
      \ln -s $ifile $prog.nml
      ofile="$path_w/`basename $ifile .nml`.out"
    else
      \rm -f $prog.inp
      \ln -s $ifile $prog.inp
      ofile="$path_w/`basename $ifile .inp`.out"
    fi

    echo "   Processing $ifile"
    echo "   Screen output routed to $ofile"

    if $path_e/$prog > $ofile
    then
      \rm -f $prog.inp
      \rm -f $prog.nml
      if [ $multi -eq 2 ]
      then
        mv mod_def.ww3 mod_def.$g
        if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
        then
          mv $prog.nml.log ${prog}_$g.nml.log
        fi
      fi
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi

  done

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.d Initial conditions ---------------------------------------------------- #

prog=ww3_strt
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
then
  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
else
  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
fi

if [ $? = 0 ]
then

  echo ' '
  echo '+--------------------+'
  echo '| Initial conditions |'
  echo '+--------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch

  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $model_grids
  do

    if [ $multi -eq 2 ]
    then
      gu="_$g"
    fi

    # link conf file
    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
    then
      \rm -f $prog.nml
      \ln -s $ifile $prog.nml
      ofile="$path_w/`basename $ifile .nml`${gu}.out"
    else
      \rm -f $prog.inp
      \ln -s $ifile $prog.inp
      ofile="$path_w/`basename $ifile .inp`${gu}.out"
    fi

    echo "   Processing $ifile"
    echo "   Screen output routed to $ofile"

    if [ $multi -eq 2 ]
    then
      \rm -f mod_def.ww3
      \ln -s mod_def.$g mod_def.ww3
    fi
    if $path_e/$prog > $ofile
    then
      \rm -f $prog.inp
      \rm -f $prog.nml
      if [ $multi -eq 2 ]
      then
        mv restart.ww3 restart.$g
        \rm -f mod_def.ww3
        if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
        then
          mv $prog.nml.log ${prog}_$g.nml.log
        fi
      fi
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi

  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.d boundary conditions -------------------------------------------------- #

prog=ww3_bound
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
then
  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
else
  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
fi

if [ $? = 0 ]
then

  echo ' '
  echo '+---------------------+'
  echo '| Boundary conditions |'
  echo '+---------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $model_grids
  do
    if [ $multi -eq 2 ]
    then
      gu="_$g"
    fi

    # link conf file
    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
    then
      \rm -f $prog.nml
      \ln -s $ifile $prog.nml
      ofile="$path_w/`basename $ifile .nml`${gu}.out"
    else
      \rm -f $prog.inp
      \ln -s $ifile $prog.inp
      ofile="$path_w/`basename $ifile .inp`${gu}.out"
    fi

    echo "   Processing $ifile"
    echo "   Screen output routed to $ofile"

    if [ $multi -eq 2 ]
    then
      \rm -f mod_def.ww3
      \ln -s mod_def.$g mod_def.ww3
    fi
    if $path_e/$prog > $ofile
    then
      \rm -f $prog.inp
      \rm -f $prog.nml
      if [ $multi -eq 2 ]
      then
        mv nest.ww3 nest.$g
        \rm -f mod_def.ww3
        if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
        then
          mv $prog.nml.log ${prog}_$g.nml.log
        fi
      fi
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi

  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.d boundary conditions -------------------------------------------------- #

prog=ww3_bounc
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
then
  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
else
  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
fi

if [ $? = 0 ]
then

  echo ' '
  echo '+---------------------+'
  echo '| Boundary conditions |'
  echo '+---------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $model_grids
  do
    if [ $multi -eq 2 ]
    then
      gu="_$g"
    fi

    # link conf file
    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
    then
      \rm -f $prog.nml
      \ln -s $ifile $prog.nml
      ofile="$path_w/`basename $ifile .nml`${gu}.out"
    else
      \rm -f $prog.inp
      \ln -s $ifile $prog.inp
      ofile="$path_w/`basename $ifile .inp`${gu}.out"
    fi

    echo "   Processing $ifile"
    echo "   Screen output routed to $ofile"

    if [ $multi -eq 2 ]
    then
      \rm -f mod_def.ww3
      \ln -s mod_def.$g mod_def.ww3
    fi
    if $path_e/$prog > $ofile
    then
      \rm -f $prog.inp
      \rm -f $prog.nml
      if [ $multi -eq 2 ]
      then
        mv nest.ww3 nest.$g
        \rm -f mod_def.ww3
        if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
        then
          mv $prog.nml.log ${prog}_$g.nml.log
        fi
      fi
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi

  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.e Prep forcing fields --------------------------------------------------- #

prog=ww3_prep
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
then
  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
else
  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
fi

if [ $? = 0 ]
then
  echo ' '
  echo '+---------------------+'
  echo '| Prep forcing fields |'
  echo '+---------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $input_grids
  do

    if [ $multi -eq 2 ]
    then
      gu="_$g"
    fi

    for ifile in $inputs
    do

      # link conf file
      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
      then
        \rm -f $prog.nml
        \ln -s $ifile $prog.nml
        otype="`basename $ifile .nml | sed s/^${prog}_//`"
        ofile="$path_w/`basename $ifile .nml`.out"
      else
        \rm -f $prog.inp
        \ln -s $ifile $prog.inp
        otype="`basename $ifile .inp | sed s/^${prog}_//`"
        ofile="$path_w/`basename $ifile .inp`.out"
      fi

      echo "   Processing $ifile for $otype"
      echo "   Screen output routed to $ofile"

      if [ $multi -eq 2 ]
      then
        \rm -f mod_def.ww3
        \ln -s mod_def.$g mod_def.ww3
      fi
      if $path_e/$prog > $ofile
      then
        \rm -f $prog.inp
        \rm -f $prog.nml
        if [ $multi -eq 2 ]
        then
          \rm -f mod_def.ww3
          mv $otype.ww3 $otype.$g
          if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
          then
            mv $prog.nml.log ${prog}_$g.nml.log
          fi
        fi
      else
        errmsg "Error occured during $path_e/$prog execution"
        exit 1
      fi

    done

  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.e Prep forcing fields --------------------------------------------------- #

prog=ww3_prnc
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
then
  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
else
  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
fi

if [ $? = 0 ]
then
  echo ' '
  echo '+-------------------------------+'
  echo '| Prep of NetCDF forcing fields |'
  echo '+-------------------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $input_grids
  do

    if [ $multi -eq 2 ]
    then
      gu="_$g"
    fi

    for ifile in $inputs
    do

      # link conf file
      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
      then
        \rm -f $prog.nml
        \ln -s $ifile $prog.nml
        otype="`basename $ifile .nml | sed s/^${prog}_//`"
        ofile="$path_w/`basename $ifile .nml`.out"
      else
        \rm -f $prog.inp
        \ln -s $ifile $prog.inp
        otype="`basename $ifile .inp | sed s/^${prog}_//`"
        ofile="$path_w/`basename $ifile .inp`.out"
      fi

      echo "   Processing $ifile"
      echo "   Screen output routed to $ofile"

      if [ $multi -eq 2 ]
      then
        \rm -f mod_def.ww3
        \ln -s mod_def.$g mod_def.ww3
      fi
      if $path_e/$prog > $ofile
      then
        \rm -f $prog.inp
        \rm -f $prog.nml
        if [ $multi -eq 2 ]
        then
          \rm -f mod_def.ww3
          mv $otype.ww3 $otype.$g
          if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
          then
            mv $prog.nml.log ${prog}_$g.nml.log
          fi
        fi
      else
        errmsg "Error occured during $path_e/$prog execution"
        exit 1
      fi

    done

  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.f Main program ---------------------------------------------------------- #

if [ -e $path_i/bottomspectrum.inp ]
then  
  cp $path_i/bottomspectrum.inp .
fi

if [ $multi -ge 1 ]
then
  prog=ww3_multi
  if [ $coupl = "ESMF" ]
  then
    prgb=ww3_multi_esmf
  else
    prgb=ww3_multi
  fi
else
  prog=ww3_shel
  prgb=ww3_shel
fi
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# track file - multigrid option (ge 1)
if [ $multi -ge 1 ]
then
  for g in $all_grids
  do
    ifile="`ls $path_i/track_i.$g 2>/dev/null`"
    if [ $? = 0 ]
    then
      \rm -f track_i.$g
      \ln -s $ifile
    fi
  done
else
  ifile="`ls $path_i/track_i.ww3 2>/dev/null`"
  if [ $? = 0 ]
  then
    \rm -f track_i.ww3
    \ln -s $ifile
  fi
fi

# config filename - gridset option (eq 2)
if [ $multi -eq 2 ]
then
  fileconf="${prog}_${grdset}"
else
  fileconf="${prog}"
fi

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${fileconf}.nml 2>/dev/null`" ]
then
  ifile="`ls ${path_i}/${fileconf}.nml 2>/dev/null`"
else
  ifile="`ls $path_i/${fileconf}.inp 2>/dev/null`"
fi


if [ $? = 0 ]
then

  echo ' '
  echo '+--------------------+'
  echo '|    Main program    |'
  echo '+--------------------+'
  echo ' '

  \cp -f $file_c $path_b/switch
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prgb
  then :
  else
    errmsg "Error occured during WW3 $prgb build"
    exit 1
  fi
  if [ $multi -ge 1 ] && [ $coupl = "ESMF" ]
  then
    if [ $cmplr ]
    then
      export WW3_COMP=$cmplr
    fi
    if make -C $path_s/esmf $prgb
    then :
    else
      errmsg "Error occured during WW3 ESMF build"
      exit 1
    fi
  fi

  if [ ! -f $path_e/$prgb ]
  then
    errmsg "$path_e/$prgb not found"
    exit 1
  fi

  ofile="$path_w/$prog.out"

  # link conf file
  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
  then
    \rm -f $prog.nml
    \ln -s $ifile $prog.nml
  else
    \rm -f $prog.inp
    \ln -s $ifile $prog.inp
  fi

  if [ $multi -ge 1 ] && [ $coupl = "ESMF" ]
  then
    \rm -f PET*.ESMF_LogFile
    \rm -f ww3_esmf.rc
    \cp -f ${path_i}/ww3_esmf.rc ww3_esmf.rc
    if [ ! -z "`echo ${ifile} | grep -o nml`" ]
    then
      echo "WAV_input_file_name: $prog.nml" >> ww3_esmf.rc
    fi
    if [ $nproc ]
    then
      echo "pet_count: $nproc" >> ww3_esmf.rc
    else
      echo "pet_count: 1" >> ww3_esmf.rc
    fi
  fi

  echo "   Processing $ifile"
  echo "   Screen output copied to $ofile"
  if [ $pmpi ]
  then
    if [ $nproc ]
    then
      runcmd="$runcmd -np $nproc"
    fi
    if [ $nthrd ]
    then
      if ( which omplace ) ; then
        runcmd="$runcmd omplace -nt $nthrd"
      else
        runcmd="$runcmd /usr/bin/env OMP_NUM_THREADS=$nthrd"
      fi
    fi
  fi
  if [ $pomp ]
  then
    if [ $nproc ]
    then
      export OMP_NUM_THREADS=$nproc
    fi
  fi

  if [ $multi -eq 0 ] && [ $coupl = "OASIS" ]
  then
    halfnproc=$(($nproc / 2))
    if $runcmd1 -np $halfnproc $path_e/$prgb : -np $halfnproc $path_w/toy_model | tee $ofile
    then
      \rm -f track_i.ww3
      \rm -f $prog.inp
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi
  else
    if $runcmd $path_e/$prgb | tee $ofile
    then
      \rm -f track_i.ww3
      \rm -f $prog.inp
      \rm -f $prog.nml
      for file_p in ${files_p}
      do
        \rm -f ${file_p}
      done
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi
  fi
fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.g Grid integration ------------------------------------------------------- #

prog=ww3_gint
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# config filename - gridset option (eq 2)
if [ $multi -eq 2 ]
then
  fileconf="${prog}_${grdset}"
else
  fileconf="${prog}"
fi

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${fileconf}.nml 2>/dev/null`" ]
then
  ifile="`ls ${path_i}/${fileconf}.nml 2>/dev/null`"
else
  ifile="`ls $path_i/${fileconf}.inp 2>/dev/null`"
fi


if [ $? = 0 ]
then

  echo ' '
  echo '+-------------------------+'
  echo '|    Integrated output    |'
  echo '+-------------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi


  # link conf file
  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
  then
    \rm -f $prog.nml
    \ln -s $ifile $prog.nml
    ofile="$path_w/`basename $ifile .nml`.out"
  else
    \rm -f $prog.inp
    \ln -s $ifile $prog.inp
    ofile="$path_w/`basename $ifile .inp`.out"
  fi

  echo "   Processing $ifile"
  echo "   Screen output copied to $ofile"

  if $path_e/$prog > $ofile
  then
    \rm -f $prog.inp
    \rm -f $prog.nml
    for g in $intgl_grids
    do
      if [ -f "out_grd.$g" ]
      then
        model_grids="$model_grids $g"
      fi
    done
  else
    errmsg "Error occured during $path_e/$prog execution"
    exit 1
  fi

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.g Gridded output -------------------------------------------------------- #

case $outopt in
  native) out_progs="ww3_outf" ;;
  netcdf) out_progs="ww3_ounf" ;;
  both)   out_progs="ww3_outf ww3_ounf" ;;
  *)      out_progs="" ;;
esac

if [ "$grads" = '1' ]
then
  out_progs="$out_progs gx_outf"
  if [ `ls $path_i | grep '.gs' | wc -l` -gt '0' ]
  then
    cp $path_i/*.gs .
    cp $path_a/cbarn.gs .
    cp $path_a/colorset.gs .
  fi
fi

for prog in $out_progs
do

rline='|   Gridded output   |'
if [ $prog = ww3_ounf ]
then
  rline='| NC Gridded output  |'
fi
if [ $prog = gx_outf ]
then
  rline='|GrADS Gridded output|'
fi

if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
then
  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
else
  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
fi


if [ $? = 0 ]
then

  echo ' '
  echo '+--------------------+'
  echo "$rline"
  echo '+--------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $model_grids
  do

    if [ $multi -eq 2 ]
    then
      if [ ! -e out_grd.$g ]
      then
        continue
      fi
      gu="_$g"
    fi

    for ifile in $inputs
    do

      # link conf file
      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
      then
        \rm -f $prog.nml
        \ln -s $ifile $prog.nml
        otype="`basename $ifile .nml | sed s/^${prog}_//`"
        ofile="$path_w/`basename $ifile .nml`${gu}.out"
      else
        \rm -f $prog.inp
        \ln -s $ifile $prog.inp
        otype="`basename $ifile .inp | sed s/^${prog}_//`"
        ofile="$path_w/`basename $ifile .inp`${gu}.out"
      fi

      echo "   Processing $ifile"
      echo "   Screen output routed to $ofile"

      if [ $multi -eq 2 ]
      then
        \rm -f mod_def.ww3
        \rm -f out_grd.ww3
        \ln -s mod_def.$g mod_def.ww3
        \ln -s out_grd.$g out_grd.ww3
        \rm -f ww3.????????.*
        \rm -fr ${otype}_$g
      fi
      if $path_e/$prog > $ofile
      then
        \rm -f $prog.inp
        \rm -f $prog.nml
        if [ $multi -eq 2 ]
        then
          \rm -f mod_def.ww3
          \rm -f out_grd.ww3
          if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
          then
            mv $prog.nml.log ${prog}_$g.nml.log
          fi
          ofiles="`ls ww3.????????.* 2>/dev/null`"
          if [ $? = 0 ]
          then
            mkdir ${otype}_$g
            mv -f $ofiles ${otype}_$g/.
            echo "   ASCII output files moved to ${otype}_$g"
          fi
          ofiles="`ls ww3.????*.nc 2>/dev/null`"
          if [ $? = 0 ]
          then
            mkdir ${otype}_$g
            mv -f $ofiles ${otype}_$g/.
            echo "   NetCDF output files moved to ${otype}_$g"
          fi
#
          if [ "$prog" = 'gx_outf' ]
          then
            case $g in
              'grd2' )  sed -e "s/ww3\.grads/ww3\.$g/g" \
                            -e "s/37\.5/3\.75/g" \
                            -e "s/1\.50/0\.15/g" \
                                                  ww3.ctl > $g.ctl ;;
              'grd3' )  sed -e "s/ww3\.grads/ww3\.$g/g" \
                            -e "s/12\.5/1\.25/g" \
                            -e "s/0\.50/0\.05/g" \
                                                  ww3.ctl > $g.ctl ;;
                *    )  sed -e "s/ww3\.grads/ww3\.$g/g" \
                            -e "s/0\.25/2\.50/g" ww3.ctl > $g.ctl ;;
            esac
            rm -f ww3.ctl
            echo "   ww3.ctl moved to $g.ctl"
            mv ww3.grads ww3.$g
            echo "   ww3.grads moved to ww3.$g"
          fi
        fi
      else
        errmsg "Error occured during $path_e/$prog execution"
        exit 1
      fi

    done

  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

done # end of loop on progs

# 3.h Point output ---------------------------------------------------------- #

case $outopt in
  native) out_progs="ww3_outp" ;;
  netcdf) out_progs="ww3_ounp" ;;
  both)   out_progs="ww3_outp ww3_ounp" ;;
  *)      out_progs="" ;;
esac

if [ "$grads" = '1' ]
then
  out_progs="$out_progs gx_outp"
  if [ `ls $path_i | grep 'gx_outp' | wc -l` -gt '0' ]
  then
    cp $path_a/cbarn.gs .
    cp $path_a/colorset.gs .
    cp $path_a/source.gs .
    cp $path_a/1source.gs .
    cp $path_a/spec.gs .
  fi
fi

for prog in $out_progs
do

rline='|    Point output    |'
if [ $prog = ww3_ounp ]
then
  rline='| NC Point output    |'
fi

if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml format for input file to program $prog
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
then
  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
else
  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
fi


if [ $? = 0 ]
then

  echo ' '
  echo '+--------------------+'
  echo "$rline"
  echo '+--------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $point_grids
  do

    if [ $multi -eq 2 ]
    then
      if [ ! -e out_pnt.$g ]
      then
        continue
      fi
      gu="_$g"
    fi

    for ifile in $inputs
    do

      # link conf file
      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
      then
        \rm -f $prog.nml
        \ln -s $ifile $prog.nml
        otype="`basename $ifile .nml | sed s/^${prog}_//`"
        ofile="$path_w/`basename $ifile .nml`${gu}.out"
      else
        \rm -f $prog.inp
        \ln -s $ifile $prog.inp
        otype="`basename $ifile .inp | sed s/^${prog}_//`"
        ofile="$path_w/`basename $ifile .inp`${gu}.out"
      fi

      echo "   Processing $ifile"
      echo "   Screen output routed to $ofile"

      if [ $multi -eq 2 ]
      then
        \rm -f mod_def.ww3
        \rm -f out_pnt.ww3
        \ln -s mod_def.$g mod_def.ww3
        \ln -s out_pnt.$g out_pnt.ww3
      fi
      if $path_e/$prog > $ofile
      then
        \rm -f $prog.inp
        \rm -f $prog.nml
        if [ $multi -eq 2 ]
        then
          \rm -f mod_def.ww3
          \rm -f out_pnt.ww3
          if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
          then
            mv $prog.nml.log ${prog}_$g.nml.log
          fi
        fi
      else
        errmsg "Error occured during $path_e/$prog execution"
        exit 1
      fi

    done

  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

done # end of loop on progs

# 3.i Track output ---------------------------------------------------------- #

case $outopt in
  native) out_progs="ww3_trck" ;;
  netcdf) out_progs="ww3_trnc" ;;
  both)   out_progs="ww3_trck ww3_trnc" ;;
  *)      out_progs="" ;;
esac

for prog in $out_progs
do

if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
then
  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
else
  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
fi


if [ $? = 0 ]
then

  echo ' '
  echo '+--------------------+'
  echo '|    Track output    |'
  echo '+--------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch
  fi
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $point_grids
  do

    if [ $multi -eq 2 ]
    then
      if [ ! -e track_o.$g ]
      then
        continue
      fi
      gu="_$g"
      fileconf="$prog${gu}"
    else
      fileconf="$prog"
    fi

    # select inp/nml files
    if [ $nml_input ] && [ ! -z "`ls ${path_i}/${fileconf}.nml 2>/dev/null`" ]
    then
      ifile="`ls ${path_i}/${fileconf}.nml 2>/dev/null`"
    else
      ifile="`ls $path_i/${fileconf}.inp 2>/dev/null`"
    fi

    if [ ! -f $ifile ]
    then
      errmsg "$ifile not found"
      exit 1
    fi

    # link conf file
    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
    then
      \rm -f $prog.nml
      \ln -s $ifile $prog.nml
      otype="`basename $ifile .nml | sed s/^${prog}_//`"
      ofile="$path_w/`basename $ifile .nml`.out"
    else
      \rm -f $prog.inp
      \ln -s $ifile $prog.inp
      otype="`basename $ifile .inp | sed s/^${prog}_//`"
      ofile="$path_w/`basename $ifile .inp`.out"
    fi

    echo "   Processing $ifile"
    echo "   Screen output routed to $ofile"

    if [ $multi -eq 2 ]
    then
      \rm -f track_o.ww3
      \ln -s track_o.$g track_o.ww3
    fi
    if $path_e/$prog > $ofile
    then
      \rm -f $prog.inp
      \rm -f $prog.nml
      if [ $multi -eq 2 ]
      then
        \rm -f track_o.ww3
        if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
        then
          mv $prog.nml.log ${prog}_$g.nml.log
        fi
        if [ -e track.ww3 ]
        then
          mv track.ww3 track.$g
        elif [ -e track.nc ]
        then
          mv track.nc track_$g.nc
        fi    
      fi
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi
  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

done # end of loop on progs

# 3.j Wave system tracking -------------------------------------------------- #

prog=ww3_systrk
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
then
  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
else
  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
fi


if [ $? = 0 ]
then

  echo ' '
  echo '+-------------------------+'
  echo '|  Wave system tracking   |'
  echo '+-------------------------+'
  echo ' '

    \cp -f $file_c $path_b/switch
#  if [ $force_shrd ]
#  then # build pre- & post-processing programs with SHRD only
#    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
#                  sed 's/OMPG //'    | sed 's/OMPX //'| \
#                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switchh
#  else
#    \cp -f $file_c $path_b/switch
#  fi  
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch 
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi


  # link conf file
  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
  then
    \rm -f $prog.nml
    \ln -s $ifile $prog.nml
    ofile="$path_w/`basename $ifile .nml`.out"
  else
    \rm -f $prog.inp
    \ln -s $ifile $prog.inp
    ofile="$path_w/`basename $ifile .inp`.out"
  fi

  echo "   Processing $ifile"
  echo "   Screen output copied to $ofile"

  if [ $pmpi ]
  then
    if [ $nproc ]
    then
      runcmd="$runcmd -np $nproc"
    fi
  fi
  if $runcmd $path_e/$prog | tee $ofile
  then
    \rm -f $prog.inp
    \rm -f $prog.nml
  else
    errmsg "Error occured during $path_e/$prog execution"
    exit 1
  fi
#  if $path_e/$prog > $ofile
#  then
#    \rm -f $prog.inp
#    for g in $intgl_grids
#    do
#      if [ -f "out_grd.$g" ]
#      then
#        model_grids="$model_grids $g"
#      fi
#    done
#  else
#    errmsg "Error occured during $path_e/$prog execution"
#    exit 1
#  fi

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.k Update Restart File ------------------------------------------ #

prog=ww3_uprstr
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# Check for input file

# select inp/nml files
#if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
#then
#  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
#else
  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
#fi

if [ $? = 0 ]
then

  echo ' '
  echo '+-------------------------+'
  echo '|   Update Restart File   |'
  echo '+-------------------------+'
  echo ' '

  \cp -f $file_c $path_b/switch
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  # link conf file
  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
  then
    \rm -f $prog.nml
    \ln -s $ifile $prog.nml
    ofile="$path_w/`basename $ifile .nml`.out"
  else
    \rm -f $prog.inp
    \ln -s $ifile $prog.inp
    ofile="$path_w/`basename $ifile .inp`.out"
  fi

  echo "   Processing $ifile"
  echo "   Screen output copied to $ofile"
  
# Additional Files
   \rm -f anl.grbtxt
   \ln -s "$path_i/anl.grbtxt" anl.grbtxt
   
  mv -f restart001.ww3 restart.ww3
  
  if [ $pmpi ]
  then
    if [ $nproc ]
    then
      runcmd="$runcmd -np $nproc"
    fi
  fi
  if $runcmd $path_e/$prog | tee $ofile
  then
    \rm -f $prog.inp
    \rm -f $prog.nml
  else
    errmsg "Error occured during $path_e/$prog execution"
    exit 1
  fi

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi



# 3.k End ------------------------------------------------------------------- #

if [ "$stub" ]
then
  date > finished
fi

echo ' ' ; echo ' ' ; echo "Files in `pwd` :" ; echo ' '
ls -l

echo ' ' ; echo ' '
echo '                    ==================================   '
echo '                  ======>  END OF WAVEWATCH III  <====== '
echo '                    ==================================   '
echo ' '

# --------------------------------------------------------------------------- #
# End of script                                                               #
# --------------------------------------------------------------------------- #

注释

#!/bin/bash
# --------------------------------------------------------------------------- #
#                                                                             #
# Script for running WW-III tests.                                            #
#                                                                             #
#                    Last update :         27-Jan-2014                        #
# --------------------------------------------------------------------------- #
#    Modification history
#    27-Jan-2014 : Adapts ww3_ounf section for multigrid  ( version 4.18 )
#
# Limitations:
#  - For each ww3_grid_*.inp, run_test process *all* ww3_prep_*.inp files.
#    For example, when processing ww3_grid_1.inp, it does not know that
#    it needs to process ww3_prep_a.inp and *not* process ww3_prep_b.inp.
#    This can be addressed in the future by adding instructions for prep
#    to the grdset file.
#  - When running through ww3_prep, run_test is not smart enough to process
#    multiple input files of the same type. For example, for wind it wants
#    a file ww3_prep_wind.inp and does not know what to do if you have two 
#    files, ww3_prep_wind_hwna_15m.inp and ww3_prep_wind_gfs_30m.inp. 
#    It needs to rename wind.ww3 as wind.wind_gfs_30m, for example, but
#    looks for wind_gfs_30m.ww3 where it should look for wind.ww3. Another
#    loop is needed to make this work.

# --------------------------------------------------------------------------- #
# 1. Function definitions                                                     #
# --------------------------------------------------------------------------- #

# 1.a Error message function
errmsg ()
{
  echo "" 2>&1
  while [ $# != 0 ]
  do
    echo "ERROR: $1" 2>&1
    shift
  done
  echo "" 2>&1
}

# 1.b Usage function
myname="`basename $0`"  #name of script
optstr="a:c:C:defg:Ghi:m:n:No:Op:q:r:s:t:Sw:"  #option string for getopt function
usage ()
{

cat 2>&1 << EOF

Usage: $myname [options] source_dir test_name
Required:
  source_dir : path to top-level of WW3 source
  test_name  : name of test case (directory)
Options:
  -a ww3_env       : use WW3 environment setup file <ww3_env>			#model/bin/wwatch.env 文件			ww3_env
                   :   *default is <source_dir>/bin/wwatch3.env
                   :   *file will be created if it does not already exist
  -c cmplr         : setup comp & link files for specified cmplr			#comp 和 link 的更改				cmplr
  -C coupl         : invoke test using <coupl> coupled application			#						coupl=none
                   :   OASIS : OASIS3-mct ww3_shel coupled application
                   :   ESMF  : ESMF ww3_multi coupled application
  -d               : invoke main program using gdb (non-parallel)
  -e               : prompt for changes to existing WW3 environment			#对存在的ww3环境进行更改			prompt
  -f               : force pre- and post-processing programs to be compiled								force_shrd
                   : non-MPI (i.e., with SHRD switch); default is all programs
                   : compiled with unmodified switch settings
  -g grid_string   : use ww3_grid_<grid_string>.inp					#inp文件					grdstr
  -G               : create GrADS data files using gx_outX.inp			#创建grads数据文件				grads=0
  																	grads=1
  -h               : print usage and exit
  -i inpdir        : use inputs in test_name/<inpdir> (default  test_name/input)	#输入数据文件夹名称				inpdir=input
  -m grid_set      : execute multi-model test						#						multi=0?????????
                   :   *grid names are obtained from input/<grid_set>
                   :   *ww3_multi_<grid_set> will execute instead of ww3_shel
                   :   *to execute a single model test case with ww3_multi use
                   :    grid_set = none
  -n nproc         : specify <nproc> processors for parallel run			#指定<nproc>处理器用于并行运行			nproc
                   :   *some <runcmd> programs do not require <nproc>
                   :   *ignored if -p <runcmd> or -O is not specified
  -N               : use namelist (.nml) input instead of .inp (if available)	#使用 .nml					nml_input
  -o outopt        : limit output post-processing based on <outopt>			#						outopt=native
                   :   native : post-process only native output
                   :   netcdf : post-process only NetCDF output
                   :   both   : post-process both native and NetCDF output
                   :   * default is native
                   :   * note that required input files must be present for
                   :     selected output post-processing to occur
  -O               : parallel run using OpenMP paradigm and OMP_NUM_THREADS		#OMP						pomp
                     environment variable and number of processors defined with
                     the -n np option
  -p runcmd        : run in parallel using <runcmd> to start program			#MPI						pmpi=1
  																	runcmd
  																	runcmd1=$runcmd
                   :   *MPICH or OpenMPI: mpirun or mpiexec (default <nproc> = 1)
                   :   *IBM with Loadleveler: poe (no <nproc> required)
                   :   *LSF: mpirun.lsf (no <nproc> required)
  -q program       : exit script after program <program> executes			#在程序运行后退出脚本????怎么理解????	exit_p=none
  -r program       : only execute program <program>					#仅仅执行某个脚本				exec_p=none
  																	prog=ww3_grid
  																	prog=ww3_strt
  																	prog=ww3_bound
  																	prog=ww3_bounc
  																	prog=ww3_prep
  																	prog=ww3_prnc
  																	prog=ww3_shel
  																	prog=ww3_multi
  																	prog=ww3_gint
  																	prog=ww3_outf	native文件
  																	prog=ww3_ounf	nc文件
  																	prog=gx_outf	GrADS文件
  																	prog=ww3_outp	native文件
  																	prog=ww3_ounp	nc文件
  																	prog=gx_outp	GrADS文件
  																	prog=trck	native文件
  																	prog=trnc	nc文件
  																	prog=ww3_systrk
  																	prog=ww3_uprstr
  															
  -s switch_string : use switch_<switch_string>					#switch的选择					swtstr=PR1时,即选择的switch_PR1
  -S               : create stub file <finished>. with end data and time.		#创建存根文件??????			stub
                     tests not executed if file is found.
  -t nthrd         : Threading option. (this is system dependant and can be used	#线程选项。(这取决于系统,只能用于混合选项的nthrd)	nthrd
                   : only for the hybrid option)
  -w work_dir      : run test case in test_name/work_dir (default test_name/work)

EOF
}


# --------------------------------------------------------------------------- #
# 2. Preparations                                                             #
# --------------------------------------------------------------------------- #

# 2.a Setup array of command-line arguments
args=`getopt $optstr $*`	#optstr="a:c:C:defg:Ghi:m:n:No:Op:q:r:s:t:Sw:"	#option string for getopt function;
											#参数的命名,等号左右不能有空格;                                   
											#字母后面有冒号的,说明需要输入参数,例如a,c,w;
											#字母后面没有冒号的,说明不需要输入参数,例如d,e,f;
				#我的执行命令为:./bin1/run_test_try_tp1.1 -s PR1 -w work_try ../model ww3_tp1.1
				#echo $*						#输出为:-s PR1 -w work_try ../model ww3_tp1.1
				#echo `getopt $optstr $*`				#输出为:-s PR1 -w work_try -- ../model ww3_tp1.1,
									
if [ $? != 0 ]			# $? != 0 表示上一条语句执行失败,即 args=`getopt $optstr $*` 中 getopt 失败
				#getopt失败的执行命令:./bin1/run_test_try_tp1.1 -L -s PR1 -w work_try ../model ww3_tp1.1
				#输出为:getopt: 不适用的选项 -- L
then
  usage
  exit 1
fi

set -- $args			#有人说 getopts 函数会好用很多~~
				#这一段体现作用的执行命令:./bin1/run_test_try_tp1.1 -de -s PR1 -w work_try ../model ww3_tp1.1
				#参考:https://stackoverflow.com/questions/12982441/what-is-the-purpose-of-set-args-after-getopt
		


# 2.b Process command-line options
exit_p=none
exec_p=none
multi=0
dist=0
inpdir=input
outopt=native
grads=0
coupl=none
while :
do
  case "$1" in
  -a) shift; ww3_env="$1" ;;
  -c) shift; cmplr="$1" ;;
  -C) shift; coupl="$1" ;;
  -d) use_gdb=1 ;;
  -e) prompt=1 ;;
  -f) force_shrd=1 ;;
  -g) shift; grdstr="$1" ;;
  -G) grads=1 ;;
  -h) help=1 ;;
  -i) shift; inpdir="$1" ;;
  -m) shift; grdset="$1" ;
      if [ $grdset = none ]
      then
        multi=1
      else
        multi=2
      fi ;;
  -n) shift; nproc="$1" ;;
  -N) nml_input=1 ;;
  -o) shift; outopt="$1" ;;
  -O) pomp=1 ;;
  -p) shift; runcmd="$1" ; runcmd1=$runcmd ; pmpi=1 ;;
  -q) shift; exit_p="$1" ;;
  -r) shift; exec_p="$1" ;;
  -s) shift; swtstr="$1" ;;
  -S) stub=1 ;;
  -t) shift; nthrd="$1" ;;
  -w) shift; wrkdir="$1" ;;
  --) break ;;			#这个才是case的while语句的出口,即出现 -- ,case才会停止;
  esac
  shift
done
				#echo $args
					#输出为:-s PR1 -w work_try -- ../model ww3_tp1.1
shift 				#remove the trailing --
				#echo $args
					#输出为:-s PR1 -w work_try -- ../model ww3_tp1.1
if [ $help ]
then
  usage
  exit 1
fi

#uncomment next line to add S & T switches to every test 
#testST=1  

if [ ! $exec_p = "none" ]
then
  exit_p=$exec_p
fi

case $outopt in		#看outopt参数输入是否正确
  native|netcdf|both) ;;
  *) errmsg "outopt = $outopt not supported" ; usage ; exit 1 ;;
esac

case $coupl in			#看coupl参数输入是否正确
  none) ;;
  OASIS)
    if [ $multi -ne 0 ]	# -ne表示不等于	#https://blog.csdn.net/u010735147/article/details/85102277 (含有各种等式不等式符号)
    then
      errmsg "coupl = $coupl with ww3_multi is not supported"
      usage
      exit 1
    fi
  ;;
  ESMF)
    if [ $multi -eq 0 ]	# -eq表示等于
    then
      errmsg "coupl = $coupl with ww3_shel is not supported"
      usage
      exit 1
    fi
    if [ -z "$ESMFMKFILE" ]	# 不理解??????????????????????
    then
      errmsg "ESMFMKFILE must be defined with coupl = $coupl"
      usage
      exit 1
    fi
  ;;
  *) errmsg "coupl = $coupl not supported" ; usage ; exit 1 ;;
esac




# 2.c Get required arguments
if [ ! $# = 0 ]
then
  path_s="$1" ; shift		#model的路径
  				#echo $path_s
  					#输出:../model
else
  usage
  exit 1
fi
if [ ! $# = 0 ]
then
  testnm="$1" ; shift		#regtests下测试文件的路径,
else
  usage
  exit 1
fi



# 2.d Convert source path from "relative" to "absolute"
				#[-d $path_s]	#判断是否存在此文件夹:-d filename 如果 filename为目录,则为真 
						#解决:https://blog.csdn.net/superbfly/article/details/49274889 :linux 下shell中if的“-e,-d,-f”是什么意思
if [ ! -d $path_s ]
then
  errmsg "$path_s not found"
  usage
  exit 1
fi
path_s="`cd $path_s 1>/dev/null 2>&1 && pwd`"	#相对路径转换为绝对路径的好方法~~~~
				#echo `pwd`
					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/regtests
				#echo $path_s
					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/model
				#echo `pwd`
					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/regtests
			
			
# 2.e Path to test directory
path_t="`pwd`/$testnm"
				#echo $path_t
					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/ww3_tp1.1
if [ ! -d $path_t ]
then
  errmsg "$path_t not found"
  usage
  exit 1
fi


# 2.f Path to input files
path_i="$path_t/$inpdir"
				#echo $path_i
					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/ww3_tp1.1/input
if [ ! -d $path_i ]
then
  errmsg "$path_i not found"
  usage
  exit 1
fi


# 2.g Path to working directory
if [ $wrkdir ]
then
  path_w="$path_t/$wrkdir"
  				#echo $path_w
  					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/ww3_tp1.1/work_try
else
  path_w="$path_t/work"
fi

# 2.h Paths to source subdirectories
path_e="$path_s/exe"
path_a="$path_s/aux"
				#echo $path_a
					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/model/aux
path_b="$path_s/bin"
				#echo $path_b
					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/model/bin
if [ ! -d $path_a ]
then
  errmsg "$path_a not found"
  exit 1
fi
if [ ! -d $path_b ]
then
  errmsg "$path_b not found"
  exit 1
fi



# 2.i Check for switch file
if [ $swtstr ]
then
  file_c="$path_i/switch_$swtstr"
  				#echo $file_c
  					#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/ww3_tp1.1/input/switch_PR1
else
  file_c="$path_i/switch"
fi
if [ ! -f $file_c ]
then
  errmsg "switch file $file_c not found"
  exit 1
fi



# 2.j If parallel execution, then check for proper switches		#对并行化方案的switch的检验
#     Also, set default run command
if [ $pmpi ]
then
  if [ "`grep MPI $file_c`" ]
  then :
  else
    errmsg "Improper switch setup for MPI run"
    exit 1
  fi
else
  if [ $use_gdb ]
  then
    runcmd='gdb'
  else
    runcmd=''
  fi
fi

if [ $pomp ]
then
  if [ "`grep OMP $file_c`" ]
  then :
  else
    errmsg "Improper switch setup for OpenMP run"
    exit 1
  fi
fi



# 2.k Setup for multi-model (and defaults for non-multi-model)	#多模型网格的建立??????????
gu=""
if [ $multi -eq 2 ]
then
  if [ -f $path_i/$grdset ]						#-f filename 如果 filename为常规文件,则为真
  										#解决:https://blog.csdn.net/superbfly/article/details/49274889 :linux 下shell中if的“-e,-d,-f”是什么意思
  										#常规文件是什么:https://www.coder.work/article/6650012
  then
    model_grids="`awk '/^MODEL:/' $path_i/$grdset | sed 's/MODEL\://'`"
    									#awk命令:AWK 是一种处理文本文件的语言,是一个强大的文本分析工具。
    										#https://www.runoob.com/linux/linux-comm-awk.html
    									#sed命令:sed 命令是利用脚本来处理文本文件。
    										#https://www.runoob.com/linux/linux-comm-sed.html
    input_grids="`awk '/^INPUT:/' $path_i/$grdset | sed 's/INPUT\://'`"
    point_grids="`awk '/^POINT:/' $path_i/$grdset | sed 's/POINT\://'`"
    intgl_grids="`awk '/^INTGL:/' $path_i/$grdset | sed 's/INTGL\://'`"
  else
    errmsg "grid_set file $path_i/$grdset not found"
    exit 1
  fi
else
  model_grids="none"
  input_grids="none"
  point_grids="none"
  intgl_grids="none"
fi

all_grids=$model_grids
for g in $input_grids $point_grids $intgl_grids
do
  if [ -z "`echo $all_grids | grep $g`" ]				#if  [ -z $string  ]             如果string 为空,则为真
  									#解决:https://blog.csdn.net/superbfly/article/details/49274889 :linux 下shell中if的“-e,-d,-f”是什么意思
  then
    all_grids="$all_grids $g"
  fi
done





# 2.l Setup WW3
if [ $ww3_env ]
then
  d="`dirname $ww3_env`"; b="`basename $ww3_env`";			#dirname 命令
  									#basename 命令
  export WWATCH3_ENV="`cd $d 1>/dev/null 2>&1 && pwd`/$b"
else
  export WWATCH3_ENV="$path_b/wwatch3.env"				#即 model/bin/wwatch.env
  										#echo $path_b/wwatch3.env
  										#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/model/bin/wwatch3.env
  									#Linux export 命令用于设置或显示环境变量。
  									#在 shell 中执行程序时,shell 会提供一组环境变量。export 可新增,修改或删除环境变量,供后续执行的程序使用。export 的效力仅限于该次登陆操作。
  										#https://www.runoob.com/linux/linux-comm-export.html
fi
if [ -f $path_b/w3_setup ]
then
										#echo $args
											#输出为:-s PR1 -w work_try -- ../model ww3_tp1.1
  args="-t $path_s/tmp $path_s"					#这里可以将 args 进行覆盖,是因为之前的输入参数信息已经用来生成了其他的参数,这很重要~~
  										#echo $args
  											#输出为:-t /home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/model/tmp /home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/model
  
  if [ $cmplr ]							#对ww3 建立的comp和link进行选择
  then
    args="-c $cmplr $args"
  fi
  if [ $prompt ]							#是否对ww3 建立的之前环境进行修改
  then :
  else
    args="-q $args"
  fi
  if $path_b/w3_setup "$args"						#./w3_setup
  then :
  else
    errmsg "Error occured during w3_setup"
    exit 1
  fi
else
  errmsg "WW3 setup script $path_b/w3_setup not found"
  exit 1
fi

#if [ ! -e $path_b/w3adc ]
#then
#  $path_b/w3_setup $path_s -q
#fi
#
#if [ ! -e $path_b/comp ] || [ ! -e $path_b/link ]
#then
#  errmsg "No comp/link file found in $path_b. Use option -c"
#  exit 1
#fi  
#
#if [ ! -e $path_b/switch ]
#then
#  $path_b/w3_setup $path_s -s $file_c -q
#fi





# --------------------------------------------------------------------------- #
# 3. Execute Test                                                             #
# --------------------------------------------------------------------------- #
# 3.a Go to work directory and clean-up
mkdir -p $path_w							# -p 可以实现多层级的目录创建
cd $path_w

if [ $exec_p = "none" ]						# 
then
  ncfiles=`\ls *.nc 2>/dev/null | grep -v rmp_`	
  									#echo `ls`
  									#echo $ncfiles
  									# grep -v 的用法:https://blog.csdn.net/gaochao1995/article/details/42675889 
  if [ ! $stub ]
  then
    # restart, nest, etc. may have been placed there manually, so don't remove them
    \rm -f *.inp *.out *.txt $ncfiles finished
    \ls *.ww3  2>/dev/null | grep -v 'restart.ww3' | grep -v 'nest.ww3' | grep -v 'wind.ww3' | grep -v 'ice.ww3' | grep -v 'ice1.ww3' | xargs \rm 2>/dev/null
    									# xargs 命令 :之所以能用到这个命令,关键是由于很多命令不支持|管道来传递参数,而日常工作中有有这个必
    										#要,所以就有了 xargs 命令
    										#xargs 解释:https://www.runoob.com/linux/linux-comm-xargs.html
  fi
fi

if [ $multi -eq 0 ] && [ $coupl = "OASIS" ]
then
  if $path_i/prep_env.sh $path_i $path_w $cmplr $swtstr
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi
  export OASISDIR=$path_i/../work_oasis3-mct
fi


# 3.b Header
echo ' ' ; echo ' '
echo '                    ==================================   '
echo '                  ======> TEST RUN WAVEWATCH III <====== '
echo '                    ==================================   '
echo ' '
if [ -f $path_t/info ]
then
  cat $path_t/info							# 厉害了~~
fi
echo ' '
echo " Input directory: $path_i"
echo " Switch file: $file_c"
echo ' '

if [ $stub ] && [ -f finished ]
then
  echo " Test already finished, skipping ..."
  echo ' '
  exit 0
fi





# 3.c Grid pre-processor ---------------------------------------------------- #

prog=ww3_grid


if [ $exec_p = $prog -o $exec_p = "none" ]				#逻辑或 -o                   条件表达式的或
										#https://blog.csdn.net/superbfly/article/details/49274889
										#这里if语句面对的需求是,你仅仅执行代码中的某一块~~
then

  echo ' '
  echo '+--------------------+'
  echo '|  Grid preprocessor |'
  echo '+--------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
  else
    \cp -f $file_c $path_b/switch					# ww3 setup时,comp和link已选择有,没有对switch进行选择,此处实现了
  fi
  
  if [ $testST ] 
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  
  if $path_b/w3_make $prog						# 这里实现了单独make的功能,所以可以在开始的时候,对model进行clean和new
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  for g in $all_grids
  do
    #多网格模型
    if [ $multi -eq 2 ]
    then
      gu="_$g"
    fi
    #inp文件
    if [ $grdstr ]
    then
      fileconf="${prog}_${grdstr}${gu}"
    else
      fileconf="${prog}${gu}"
    fi
    									#echo $fileconf
    										#输出为:ww3_grid

    # select inp/nml files
    if [ $nml_input ] && [ ! -z "`ls ${path_i}/${fileconf}.nml 2>/dev/null`" ]
    then
      ifile="`ls ${path_i}/${fileconf}.nml 2>/dev/null`"
    else
      ifile="`ls $path_i/${fileconf}.inp 2>/dev/null`"
    fi
    									#echo $ifile
    										#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/ww3_tp1.1/input/ww3_grid.inp


    if [ ! -f $path_e/$prog ]
    then
      errmsg "$path_e/$prog not found"
      exit 1
    fi
  
    if [ ! -f $ifile ]
    then
      errmsg "$ifile not found"
      exit 1
    fi

    # link conf file
    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
    									#echo ${ifile}
    										#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/
    										#2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/ww3_tp1.1/input/ww3_grid.inp
    									#grep -o ?????????????????
    then
      \rm -f $prog.nml
      \ln -s $ifile $prog.nml
      ofile="$path_w/`basename $ifile .nml`.out"
    else
    									#echo `pwd`
    										#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/
    										#2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/ww3_tp1.1/work_try
    								
      \rm -f $prog.inp							#\rm -f 强制删除
      										#这是为了下面创建软连接做的准备,因为创建软连接 $prog.inp,这个文件必须是原先不存在的;
      \ln -s $ifile $prog.inp						#\ln -s 创建软(符号)链接而非硬链接
  
      ofile="$path_w/`basename $ifile .inp`.out"			#神奇的实现了 .inp 后缀的去除~~
      #echo helloworld!
    fi
    									#echo $ofile
    										#输出为:/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/
    										#2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/ww3_tp1.1/work_try/ww3_grid.out

    echo "   Processing $ifile"
    echo "   Screen output routed to $ofile"
    									#Screen output routed to /home/jincanliu/BaiduNetdiskWorkspace/
    										#WaveModel2/2021-12-03~~regtests/2021-11-29~~WW3-6.07-regtests-tp-1D/regtests/
    										#ww3_tp1.1/#work_try/ww3_grid.out
    									#echo "$path_e/$prog" #/home/jincanliu/BaiduNetdiskWorkspace/WaveModel2/2021-12-03~~regtests/
    										#2021-11-29~~WW3-6.07-regtests-tp-1D/model/exe/ww3_grid
    									#echo "$path_e/$prog > $ofile"??????????????????
    									#echo "`$path_e/$prog > $ofile`"?????????????????
    # 将ww3_grid.inp 执行所需的文件放到work里面(软连接)
    #echo "   Needed files for right-running: maine_0125.bot  maine_0125.mask_nobound  maine_0125.obst"
    #\ln -s $path_i/maine_0125.bot maine_0125.bot
    #\ln -s $path_i/maine_0125.mask_nobound maine_0125.mask_nobound
    #\ln -s $path_i/maine_0125.obst maine_0125.obst
  
  
  
  
    if $path_e/$prog > $ofile #0 #$path_e/$prog > $ofile		#说明:> $ofile 是 .out 文件,这里的意思是,将 ww3_grid 运行过程中的标准输出文件定向到
    										# .out 文件里面;
    										# 所以,出错的可能性是处在 ww3_grid 执行过程中缺少了某些文件,那么就需要将这些文件
    										# 也创建软连接。
    										# 这里也把 .out 文件的生成是什么给讲清楚了,神奇的世界!
    								
    then
      \rm -f $prog.inp
      \rm -f $prog.nml
      #echo helloworld!
      # 多网格模型
      if [ $multi -eq 2 ]
      then
        mv mod_def.ww3 mod_def.$g
        if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
        then
          mv $prog.nml.log ${prog}_$g.nml.log
        fi
      fi
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi
  
    #\ln -s $ifile $prog.inp

  done

fi

if [ $exit_p = $prog ]
then
  exit
fi





# 3.d Initial conditions ---------------------------------------------------- #

prog=ww3_strt
if [ $exec_p = $prog -o $exec_p = "none" ]
then

# select inp/nml files
if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
then
  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
else
  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
fi

if [ $? = 0 ]
then

  echo ' '
  echo '+--------------------+'
  echo '| Initial conditions |'
  echo '+--------------------+'
  echo ' '

  if [ $force_shrd ]
  then # build pre- & post-processing programs with SHRD only
    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                  sed 's/OMPG //'    | sed 's/OMPX //'| \
                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch

  else
    \cp -f $file_c $path_b/switch
  fi
  
  if [ $testST ]
  then #add S T switches 
    \cp -f $path_b/switch $path_b/switch_noST
    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
    rm $path_b/switch_noST
  fi
  
  if $path_b/w3_make $prog
  then :
  else
    errmsg "Error occured during WW3 $prog build"
    exit 1
  fi

  if [ ! -f $path_e/$prog ]
  then
    errmsg "$path_e/$prog not found"
    exit 1
  fi

  for g in $model_grids
  do

    if [ $multi -eq 2 ]
    then
      gu="_$g"
    fi

    # link conf file
    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
    then
      \rm -f $prog.nml
      \ln -s $ifile $prog.nml
      ofile="$path_w/`basename $ifile .nml`${gu}.out"
    else
      \rm -f $prog.inp
      \ln -s $ifile $prog.inp
      ofile="$path_w/`basename $ifile .inp`${gu}.out"
    fi

    echo "   Processing $ifile"
    echo "   Screen output routed to $ofile"

    if [ $multi -eq 2 ]
    then
      \rm -f mod_def.ww3
      \ln -s mod_def.$g mod_def.ww3
    fi
  
    # 将ww3_strt.inp .nml 执行所需的文件放到work里面(软连接)
    # echo "   Needed files for right-running: "
    #\ln -s $path_i/
  
    if $path_e/$prog > $ofile
    then
      \rm -f $prog.inp
      \rm -f $prog.nml
      if [ $multi -eq 2 ]
      then
        mv restart.ww3 restart.$g
        \rm -f mod_def.ww3
        if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
        then
          mv $prog.nml.log ${prog}_$g.nml.log
        fi
      fi
    else
      errmsg "Error occured during $path_e/$prog execution"
      exit 1
    fi

  done

fi

fi

if [ $exit_p = $prog ]
then
  exit
fi




# 3.d boundary conditions -------------------------------------------------- #

prog=ww3_bound
if [ $exec_p = $prog -o $exec_p = "none" ]
then

  # select inp/nml files
  							
  if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
  then
    ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
  else
    ifile="`ls $path_i/$prog.inp 2>/dev/null`"			#
    									#echo $ifile
    										#输出是错误的
  fi
									#echo $?
										#输出是显示失败的
										#原因出在 ifile 参数定义上,没有对应的 ww3_bound.inp 和 .nml 文件
								
  if [ $? = 0 ]
  then

    echo ' '
    echo '+---------------------+'
    echo '| Boundary conditions |'
    echo '+---------------------+'
    echo ' '

    if [ $force_shrd ]
    then # build pre- & post-processing programs with SHRD only
      cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
                    sed 's/OMPG //'    | sed 's/OMPX //'| \
                    sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
    else
      \cp -f $file_c $path_b/switch
    fi
  
    if [ $testST ]
    then #add S T switches 
      \cp -f $path_b/switch $path_b/switch_noST
      cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
      rm $path_b/switch_noST
    fi
    if $path_b/w3_make $prog
    then :
    else
      errmsg "Error occured during WW3 $prog build"
      exit 1
    fi

    if [ ! -f $path_e/$prog ]
    then
      errmsg "$path_e/$prog not found"
      exit 1
    fi

    for g in $model_grids
    do
      if [ $multi -eq 2 ]
      then
        gu="_$g"
      fi

      # link conf file
      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
      then
        \rm -f $prog.nml
        \ln -s $ifile $prog.nml
        ofile="$path_w/`basename $ifile .nml`${gu}.out"
      else
        \rm -f $prog.inp
        \ln -s $ifile $prog.inp
        ofile="$path_w/`basename $ifile .inp`${gu}.out"
      fi

      echo "   Processing $ifile"
      echo "   Screen output routed to $ofile"

      if [ $multi -eq 2 ]
      then
        \rm -f mod_def.ww3
        \ln -s mod_def.$g mod_def.ww3
      fi
  
      # 将ww3_bound.inp .nml 执行所需的文件放到work里面 (软连接)
      # echo "   Needed files for right-running: "
      #\ln -s $path_i/
  
      if $path_e/$prog > $ofile
      then
        \rm -f $prog.inp
        \rm -f $prog.nml
        if [ $multi -eq 2 ]
        then
          mv nest.ww3 nest.$g
          \rm -f mod_def.ww3
          if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
          then
            mv $prog.nml.log ${prog}_$g.nml.log
          fi
        fi
      else
        errmsg "Error occured during $path_e/$prog execution"
        exit 1
      fi

    done

  fi

fi

if [ $exit_p = $prog ]
then
  exit
fi




# 3.d boundary conditions -------------------------------------------------- #

prog=ww3_bounc
if [ $exec_p = $prog -o $exec_p = "none" ]
then
	# select inp/nml files
	if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
	then
	  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
	else
	  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
	fi

	if [ $? = 0 ]							#if在这里的意思,判断ifile是否被赋值成功,即有没有ww3_bounc.inp .nml 文件
	then

	  echo ' '
	  echo '+---------------------+'
	  echo '| Boundary conditions |'
	  echo '+---------------------+'
	  echo ' '

	  if [ $force_shrd ]
	  then # build pre- & post-processing programs with SHRD only
	    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
		          sed 's/OMPG //'    | sed 's/OMPX //'| \
		          sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
	  else
	    \cp -f $file_c $path_b/switch
	  fi
	  
	  if [ $testST ]
	  then #add S T switches 
	    \cp -f $path_b/switch $path_b/switch_noST
	    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
	    rm $path_b/switch_noST
	  fi
	  
	  if $path_b/w3_make $prog
	  then :
	  else
	    errmsg "Error occured during WW3 $prog build"
	    exit 1
	  fi

	  if [ ! -f $path_e/$prog ]
	  then
	    errmsg "$path_e/$prog not found"
	    exit 1
	  fi

	  for g in $model_grids
	  do
	    if [ $multi -eq 2 ]
	    then
	      gu="_$g"
	    fi

	    # link conf file
	    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
	    then
	      \rm -f $prog.nml
	      \ln -s $ifile $prog.nml
	      ofile="$path_w/`basename $ifile .nml`${gu}.out"
	    else
	      \rm -f $prog.inp
	      \ln -s $ifile $prog.inp
	      ofile="$path_w/`basename $ifile .inp`${gu}.out"
	    fi

	    echo "   Processing $ifile"
	    echo "   Screen output routed to $ofile"

	    if [ $multi -eq 2 ]
	    then
	      \rm -f mod_def.ww3
	      \ln -s mod_def.$g mod_def.ww3
	    fi
	  
	    # 将ww3_bounc.inp .nml 执行所需的文件放到work里面 (软连接)
            # echo "   Needed files for right-running: "
            #\ln -s $path_i/
	  
	    if $path_e/$prog > $ofile
	    then
	      \rm -f $prog.inp
	      \rm -f $prog.nml
	      if [ $multi -eq 2 ]
	      then
		mv nest.ww3 nest.$g
		\rm -f mod_def.ww3
		if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
		then
		  mv $prog.nml.log ${prog}_$g.nml.log
		fi
	      fi
	    else
	      errmsg "Error occured during $path_e/$prog execution"
	      exit 1
	    fi

	  done

	fi

fi

if [ $exit_p = $prog ]
then
  exit
fi

# 3.e Prep forcing fields --------------------------------------------------- #

prog=ww3_prep
if [ $exec_p = $prog -o $exec_p = "none" ]
then

	# select inp/nml files
	if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
	then
	  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
	else
	  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
	fi

	if [ $? = 0 ]
	then
	  echo ' '
	  echo '+---------------------+'
	  echo '| Prep forcing fields |'
	  echo '+---------------------+'
	  echo ' '

	  if [ $force_shrd ]
	  then # build pre- & post-processing programs with SHRD only
	    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
		          sed 's/OMPG //'    | sed 's/OMPX //'| \
		          sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
	  else
	    \cp -f $file_c $path_b/switch
	  fi
	  
	  if [ $testST ]
	  then #add S T switches 
	    \cp -f $path_b/switch $path_b/switch_noST
	    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
	    rm $path_b/switch_noST
	  fi
	  
	  if $path_b/w3_make $prog
	  then :
	  else
	    errmsg "Error occured during WW3 $prog build"
	    exit 1
	  fi

	  if [ ! -f $path_e/$prog ]
	  then
	    errmsg "$path_e/$prog not found"
	    exit 1
	  fi

	  for g in $input_grids
	  do

	    if [ $multi -eq 2 ]
	    then
	      gu="_$g"
	    fi

	    for ifile in $inputs
	    do

	      # link conf file
	      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
	      then
		\rm -f $prog.nml
		\ln -s $ifile $prog.nml
		otype="`basename $ifile .nml | sed s/^${prog}_//`"
		ofile="$path_w/`basename $ifile .nml`.out"
	      else
		\rm -f $prog.inp
		\ln -s $ifile $prog.inp
		otype="`basename $ifile .inp | sed s/^${prog}_//`"
		ofile="$path_w/`basename $ifile .inp`.out"
	      fi

	      echo "   Processing $ifile for $otype"
	      echo "   Screen output routed to $ofile"

	      if [ $multi -eq 2 ]
	      then
		\rm -f mod_def.ww3
		\ln -s mod_def.$g mod_def.ww3
	      fi
	  
	      # 将ww3_prep.inp .nml 执行所需的文件放到work里面 (软连接)
              # echo "   Needed files for right-running: "
              #\ln -s $path_i/
	  
	      if $path_e/$prog > $ofile
	      then
		\rm -f $prog.inp
		\rm -f $prog.nml
		if [ $multi -eq 2 ]
		then
		  \rm -f mod_def.ww3
		  mv $otype.ww3 $otype.$g
		  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
		  then
		    mv $prog.nml.log ${prog}_$g.nml.log
		  fi
		fi
	      else
		errmsg "Error occured during $path_e/$prog execution"
		exit 1
	      fi

	    done

	  done

	fi

fi

if [ $exit_p = $prog ]
then
  exit
fi


# 3.e Prep forcing fields --------------------------------------------------- #

prog=ww3_prnc
if [ $exec_p = $prog -o $exec_p = "none" ]
then

	# select inp/nml files
	if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
	then
	  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
	else
	  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
	fi

	if [ $? = 0 ]
	then
	  echo ' '
	  echo '+-------------------------------+'
	  echo '| Prep of NetCDF forcing fields |'
	  echo '+-------------------------------+'
	  echo ' '

	  if [ $force_shrd ]
	  then # build pre- & post-processing programs with SHRD only
	    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
		          sed 's/OMPG //'    | sed 's/OMPX //'| \
		          sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
	  else
	    \cp -f $file_c $path_b/switch
	  fi
	  if [ $testST ]
	  then #add S T switches 
	    \cp -f $path_b/switch $path_b/switch_noST
	    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
	    rm $path_b/switch_noST
	  fi
	  
	  if $path_b/w3_make $prog
	  then :
	  else
	    errmsg "Error occured during WW3 $prog build"
	    exit 1
	  fi

	  if [ ! -f $path_e/$prog ]
	  then
	    errmsg "$path_e/$prog not found"
	    exit 1
	  fi

	  for g in $input_grids
	  do

	    if [ $multi -eq 2 ]
	    then
	      gu="_$g"
	    fi

	    for ifile in $inputs
	    do

	      # link conf file
	      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
	      then
		\rm -f $prog.nml
		\ln -s $ifile $prog.nml
		otype="`basename $ifile .nml | sed s/^${prog}_//`"
		ofile="$path_w/`basename $ifile .nml`.out"
	      else
		\rm -f $prog.inp
		\ln -s $ifile $prog.inp
		otype="`basename $ifile .inp | sed s/^${prog}_//`"
		ofile="$path_w/`basename $ifile .inp`.out"
	      fi

	      echo "   Processing $ifile"
	      echo "   Screen output routed to $ofile"

	      if [ $multi -eq 2 ]
	      then
		\rm -f mod_def.ww3
		\ln -s mod_def.$g mod_def.ww3
	      fi
	  
	      # 将ww3_prnc.inp .nml 执行所需的文件放到work里面 (软连接)
              # echo "   Needed files for right-running: "
              #\ln -s $path_i/
	  
	      if $path_e/$prog > $ofile
	      then
		\rm -f $prog.inp
		\rm -f $prog.nml
		if [ $multi -eq 2 ]
		then
		  \rm -f mod_def.ww3
		  mv $otype.ww3 $otype.$g
		  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
		  then
		    mv $prog.nml.log ${prog}_$g.nml.log
		  fi
		fi
	      else
		errmsg "Error occured during $path_e/$prog execution"
		exit 1
	      fi

	    done

	  done

	fi

fi

if [ $exit_p = $prog ]
then
  exit
fi




# 3.f Main program ---------------------------------------------------------- #涉及到并行,多网格问题

if [ -e $path_i/bottomspectrum.inp ]
then  
  cp $path_i/bottomspectrum.inp .
fi

# 是ww3_multi, 还是ww3_shel, 选择
if [ $multi -ge 1 ]								# -ge 大于等于
then
  prog=ww3_multi
  if [ $coupl = "ESMF" ]
  then
    prgb=ww3_multi_esmf
  else
    prgb=ww3_multi
  fi
else
  prog=ww3_shel
  prgb=ww3_shel
fi


if [ $exec_p = $prog -o $exec_p = "none" ]
then
	# track file - multigrid option (ge 1)
	if [ $multi -ge 1 ]
	then
	  for g in $all_grids
	  do
	    ifile="`ls $path_i/track_i.$g 2>/dev/null`"
	    if [ $? = 0 ]
	    then
	      \rm -f track_i.$g
	      \ln -s $ifile
	    fi
	  done
	else
	  ifile="`ls $path_i/track_i.ww3 2>/dev/null`"
	  if [ $? = 0 ]
	  then
	    \rm -f track_i.ww3
	    \ln -s $ifile
	  fi
	fi

	# config filename - gridset option (eq 2)
	if [ $multi -eq 2 ]
	then
	  fileconf="${prog}_${grdset}"
	else
	  fileconf="${prog}"
	fi

	# select inp/nml files
	if [ $nml_input ] && [ ! -z "`ls ${path_i}/${fileconf}.nml 2>/dev/null`" ]
	then
	  ifile="`ls ${path_i}/${fileconf}.nml 2>/dev/null`"
	else
	  ifile="`ls $path_i/${fileconf}.inp 2>/dev/null`"
	fi


	if [ $? = 0 ]								# 判断是否有 ww3_shel  或者 ww3_multi 的 .inp 和 .multi 文件
	then

	  echo ' '
	  echo '+--------------------+'
	  echo '|    Main program    |'
	  echo '+--------------------+'
	  echo ' '

	  \cp -f $file_c $path_b/switch
	  if [ $testST ]
	  then #add S T switches 
	    \cp -f $path_b/switch $path_b/switch_noST
	    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
	    rm $path_b/switch_noST
	  fi
	  
	  
	  if $path_b/w3_make $prgb
	  then :
	  else
	    errmsg "Error occured during WW3 $prgb build"
	    exit 1
	  fi
	  
	  
	  if [ $multi -ge 1 ] && [ $coupl = "ESMF" ]
	  then
	    if [ $cmplr ]
	    then
	      export WW3_COMP=$cmplr
	    fi
	    if make -C $path_s/esmf $prgb
	    then :
	    else
	      errmsg "Error occured during WW3 ESMF build"
	      exit 1
	    fi
	  fi

	  if [ ! -f $path_e/$prgb ]
	  then
	    errmsg "$path_e/$prgb not found"
	    exit 1
	  fi

	  ofile="$path_w/$prog.out"

	  # link conf file
	  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
	  then
	    \rm -f $prog.nml
	    \ln -s $ifile $prog.nml
	  else
	    \rm -f $prog.inp
	    \ln -s $ifile $prog.inp
	  fi
	  
	  
	  

	  if [ $multi -ge 1 ] && [ $coupl = "ESMF" ]
	  then
	    \rm -f PET*.ESMF_LogFile
	    \rm -f ww3_esmf.rc
	    \cp -f ${path_i}/ww3_esmf.rc ww3_esmf.rc
	    if [ ! -z "`echo ${ifile} | grep -o nml`" ]
	    then
	      echo "WAV_input_file_name: $prog.nml" >> ww3_esmf.rc
	    fi
	    if [ $nproc ]
	    then
	      echo "pet_count: $nproc" >> ww3_esmf.rc
	    else
	      echo "pet_count: 1" >> ww3_esmf.rc
	    fi
	  fi

	  echo "   Processing $ifile"
	  echo "   Screen output copied to $ofile"
	  
	  
	  # 将ww3_shel ww3_multi .inp .nml 执行所需的文件放到work里面 (软连接)
          # echo "   Needed files for right-running: "
          #\ln -s $path_i/
	  
	  
	  if [ $pmpi ]
	  then
	    if [ $nproc ]
	    then
	      runcmd="$runcmd -np $nproc"
	    fi
	    if [ $nthrd ]
	    then
	      if ( which omplace ) ; then
		runcmd="$runcmd omplace -nt $nthrd"
	      else
		runcmd="$runcmd /usr/bin/env OMP_NUM_THREADS=$nthrd"
	      fi
	    fi
	  fi
	  
	  
	  if [ $pomp ]
	  then
	    if [ $nproc ]
	    then
	      export OMP_NUM_THREADS=$nproc
	    fi
	  fi

	  if [ $multi -eq 0 ] && [ $coupl = "OASIS" ]
	  then
	    halfnproc=$(($nproc / 2))
	    if $runcmd1 -np $halfnproc $path_e/$prgb : -np $halfnproc $path_w/toy_model | tee $ofile	#向.out输入内容,说明正在执行;
	    then
	      \rm -f track_i.ww3
	      \rm -f $prog.inp
	    else
	      errmsg "Error occured during $path_e/$prog execution"
	      exit 1
	    fi
	  else
	    if $runcmd $path_e/$prgb | tee $ofile								 #向.out输入内容,说明正在执行;
	    													#echo $runcmd
	    													#echo helloworld!
	    													#tee 命令:tee指令会从标准输入设备读取数据,
	    														#将其内容输出到标准输出设备,同时保存成文件。
	    													#https://www.runoob.com/linux/linux-comm-tee.html
	    then
	      \rm -f track_i.ww3
	      \rm -f $prog.inp
	      \rm -f $prog.nml
	      for file_p in ${files_p}
	      do
		\rm -f ${file_p}
	      done
	    else
	      errmsg "Error occured during $path_e/$prog execution"
	      exit 1
	    fi
	  fi
	fi

fi

if [ $exit_p = $prog ]
then
  exit
fi




# 3.g Grid integration ------------------------------------------------------- # 网格集成?

prog=ww3_gint
if [ $exec_p = $prog -o $exec_p = "none" ]
then

	# config filename - gridset option (eq 2)
	if [ $multi -eq 2 ]
	then
	  fileconf="${prog}_${grdset}"
	else
	  fileconf="${prog}"
	fi

	# select inp/nml files
	if [ $nml_input ] && [ ! -z "`ls ${path_i}/${fileconf}.nml 2>/dev/null`" ]
	then
	  ifile="`ls ${path_i}/${fileconf}.nml 2>/dev/null`"
	else
	  ifile="`ls $path_i/${fileconf}.inp 2>/dev/null`"
	fi


	if [ $? = 0 ]
	then

	  echo ' '
	  echo '+-------------------------+'
	  echo '|    Integrated output    |'
	  echo '+-------------------------+'
	  echo ' '

	  if [ $force_shrd ]
	  then # build pre- & post-processing programs with SHRD only
	    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
		          sed 's/OMPG //'    | sed 's/OMPX //'| \
		          sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
	  else
	    \cp -f $file_c $path_b/switch
	  fi
	  
	  if [ $testST ]
	  then #add S T switches 
	    \cp -f $path_b/switch $path_b/switch_noST
	    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
	    rm $path_b/switch_noST
	  fi
	  
	  if $path_b/w3_make $prog
	  then :
	  else
	    errmsg "Error occured during WW3 $prog build"
	    exit 1
	  fi


	  # link conf file
	  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
	  then
	    \rm -f $prog.nml
	    \ln -s $ifile $prog.nml
	    ofile="$path_w/`basename $ifile .nml`.out"
	  else
	    \rm -f $prog.inp
	    \ln -s $ifile $prog.inp
	    ofile="$path_w/`basename $ifile .inp`.out"
	  fi

	  echo "   Processing $ifile"
	  echo "   Screen output copied to $ofile"

	  # 将ww3_gint .inp .nml 执行所需的文件放到work里面 (软连接)
          # echo "   Needed files for right-running: "
          #\ln -s $path_i/

	  if $path_e/$prog > $ofile
	  then
	    \rm -f $prog.inp
	    \rm -f $prog.nml
	    for g in $intgl_grids
	    do
	      if [ -f "out_grd.$g" ]
	      then
		model_grids="$model_grids $g"
	      fi
	    done
	  else
	    errmsg "Error occured during $path_e/$prog execution"
	    exit 1
	  fi

	fi

fi

if [ $exit_p = $prog ]
then
  exit
fi




# 3.g Gridded output -------------------------------------------------------- #

case $outopt in
  native) out_progs="ww3_outf" ;;
  netcdf) out_progs="ww3_ounf" ;;
  both)   out_progs="ww3_outf ww3_ounf" ;;
  *)      out_progs="" ;;
esac

if [ "$grads" = '1' ]								#GrADS 数据文件
then
  out_progs="$out_progs gx_outf"
  if [ `ls $path_i | grep '.gs' | wc -l` -gt '0' ]
  then
    cp $path_i/*.gs .
    cp $path_a/cbarn.gs .
    cp $path_a/colorset.gs .
  fi
fi

for prog in $out_progs
do

	rline='|   Gridded output   |'
	if [ $prog = ww3_ounf ]
	then
	  rline='| NC Gridded output  |'
	fi


	if [ $prog = gx_outf ]
	then
	  rline='|GrADS Gridded output|'
	fi


	if [ $exec_p = $prog -o $exec_p = "none" ]
	then

		# select inp/nml files
		if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
		then
		  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
		else
		  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
		fi


		if [ $? = 0 ]
		then

		  echo ' '
		  echo '+--------------------+'
		  echo "$rline"
		  echo '+--------------------+'
		  echo ' '

		  if [ $force_shrd ]
		  then # build pre- & post-processing programs with SHRD only
		    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
				  sed 's/OMPG //'    | sed 's/OMPX //'| \
				  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
		  else
		    \cp -f $file_c $path_b/switch
		  fi
		  if [ $testST ]
		  then #add S T switches 
		    \cp -f $path_b/switch $path_b/switch_noST
		    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
		    rm $path_b/switch_noST
		  fi
		  if $path_b/w3_make $prog
		  then :
		  else
		    errmsg "Error occured during WW3 $prog build"
		    exit 1
		  fi

		  if [ ! -f $path_e/$prog ]
		  then
		    errmsg "$path_e/$prog not found"
		    exit 1
		  fi

		  for g in $model_grids
		  do

		    if [ $multi -eq 2 ]
		    then
		      if [ ! -e out_grd.$g ]
		      then
			continue
		      fi
		      gu="_$g"
		    fi

		    for ifile in $inputs
		    do

		      # link conf file
		      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
		      then
			\rm -f $prog.nml
			\ln -s $ifile $prog.nml
			otype="`basename $ifile .nml | sed s/^${prog}_//`"
			ofile="$path_w/`basename $ifile .nml`${gu}.out"
		      else
			\rm -f $prog.inp
			\ln -s $ifile $prog.inp
			otype="`basename $ifile .inp | sed s/^${prog}_//`"
			ofile="$path_w/`basename $ifile .inp`${gu}.out"
		      fi

		      echo "   Processing $ifile"
		      echo "   Screen output routed to $ofile"
		      # 将ww3_outf ww3_ounf  .inp .nml  gx_outf执行所需的文件放到work里面 (软连接)
		      # echo "   Needed files for right-running: "
		      #\ln -s $path_i/
		      if [ $multi -eq 2 ]
		      then
			\rm -f mod_def.ww3
			\rm -f out_grd.ww3
			\ln -s mod_def.$g mod_def.ww3
			\ln -s out_grd.$g out_grd.ww3
			\rm -f ww3.????????.*
			\rm -fr ${otype}_$g
		      fi
		      if $path_e/$prog > $ofile						#执行
		      then
			\rm -f $prog.inp
			\rm -f $prog.nml
			if [ $multi -eq 2 ]
			then
			  \rm -f mod_def.ww3
			  \rm -f out_grd.ww3
			  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
			  then
			    mv $prog.nml.log ${prog}_$g.nml.log
			  fi
			  ofiles="`ls ww3.????????.* 2>/dev/null`"
			  if [ $? = 0 ]
			  then
			    mkdir ${otype}_$g
			    mv -f $ofiles ${otype}_$g/.
			    echo "   ASCII output files moved to ${otype}_$g"
			  fi
			  ofiles="`ls ww3.????*.nc 2>/dev/null`"
			  if [ $? = 0 ]
			  then
			    mkdir ${otype}_$g
			    mv -f $ofiles ${otype}_$g/.
			    echo "   NetCDF output files moved to ${otype}_$g"
			  fi
		#
			  if [ "$prog" = 'gx_outf' ]
			  then
			    case $g in
			      'grd2' )  sed -e "s/ww3\.grads/ww3\.$g/g" \
				            -e "s/37\.5/3\.75/g" \
				            -e "s/1\.50/0\.15/g" \
				                                  ww3.ctl > $g.ctl ;;
			      'grd3' )  sed -e "s/ww3\.grads/ww3\.$g/g" \
				            -e "s/12\.5/1\.25/g" \
				            -e "s/0\.50/0\.05/g" \
				                                  ww3.ctl > $g.ctl ;;
				*    )  sed -e "s/ww3\.grads/ww3\.$g/g" \
				            -e "s/0\.25/2\.50/g" ww3.ctl > $g.ctl ;;
			    esac
			    rm -f ww3.ctl
			    echo "   ww3.ctl moved to $g.ctl"
			    mv ww3.grads ww3.$g
			    echo "   ww3.grads moved to ww3.$g"
			  fi
			fi
		      else
			errmsg "Error occured during $path_e/$prog execution"
			exit 1
		      fi

		    done

		  done

		fi

	fi

	if [ $exit_p = $prog ]
	then
	  exit
	fi

done # end of loop on progs



# 3.h Point output ---------------------------------------------------------- #

case $outopt in
  native) out_progs="ww3_outp" ;;
  netcdf) out_progs="ww3_ounp" ;;
  both)   out_progs="ww3_outp ww3_ounp" ;;
  *)      out_progs="" ;;
esac

if [ "$grads" = '1' ]
then
  out_progs="$out_progs gx_outp"
  if [ `ls $path_i | grep 'gx_outp' | wc -l` -gt '0' ]
  then
    cp $path_a/cbarn.gs .
    cp $path_a/colorset.gs .
    cp $path_a/source.gs .
    cp $path_a/1source.gs .
    cp $path_a/spec.gs .
  fi
fi

for prog in $out_progs
do

	rline='|    Point output    |'
	if [ $prog = ww3_ounp ]
	then
	  rline='| NC Point output    |'
	fi

	if [ $exec_p = $prog -o $exec_p = "none" ]
	then

		# select inp/nml format for input file to program $prog
		if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
		then
		  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
		else
		  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
		fi


		if [ $? = 0 ]
		then

		  echo ' '
		  echo '+--------------------+'
		  echo "$rline"
		  echo '+--------------------+'
		  echo ' '

		  if [ $force_shrd ]
		  then # build pre- & post-processing programs with SHRD only
		    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
				  sed 's/OMPG //'    | sed 's/OMPX //'| \
				  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
		  else
		    \cp -f $file_c $path_b/switch
		  fi
		  
		  
		  if [ $testST ]
		  then #add S T switches 
		    \cp -f $path_b/switch $path_b/switch_noST
		    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
		    rm $path_b/switch_noST
		  fi
		  
		  
		  if $path_b/w3_make $prog
		  then :
		  else
		    errmsg "Error occured during WW3 $prog build"
		    exit 1
		  fi


		  if [ ! -f $path_e/$prog ]
		  then
		    errmsg "$path_e/$prog not found"
		    exit 1
		  fi


		  for g in $point_grids
		  do

		    if [ $multi -eq 2 ]
		    then
		      if [ ! -e out_pnt.$g ]
		      then
			continue
		      fi
		      gu="_$g"
		    fi

		    for ifile in $inputs
		    do

		      # link conf file
		      if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
		      then
			\rm -f $prog.nml
			\ln -s $ifile $prog.nml
			otype="`basename $ifile .nml | sed s/^${prog}_//`"
			ofile="$path_w/`basename $ifile .nml`${gu}.out"
		      else
			\rm -f $prog.inp
			\ln -s $ifile $prog.inp
			otype="`basename $ifile .inp | sed s/^${prog}_//`"
			ofile="$path_w/`basename $ifile .inp`${gu}.out"
		      fi

		      echo "   Processing $ifile"
		      echo "   Screen output routed to $ofile"

		      if [ $multi -eq 2 ]
		      then
			\rm -f mod_def.ww3
			\rm -f out_pnt.ww3
			\ln -s mod_def.$g mod_def.ww3
			\ln -s out_pnt.$g out_pnt.ww3
		      fi
		      if $path_e/$prog > $ofile
		      then
			\rm -f $prog.inp
			\rm -f $prog.nml
			if [ $multi -eq 2 ]
			then
			  \rm -f mod_def.ww3
			  \rm -f out_pnt.ww3
			  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
			  then
			    mv $prog.nml.log ${prog}_$g.nml.log
			  fi
			fi
		      else
			errmsg "Error occured during $path_e/$prog execution"
			exit 1
		      fi

		    done

		  done

		fi

	fi

	if [ $exit_p = $prog ]
	then
	  exit
	fi

done # end of loop on progs





# 3.i Track output ---------------------------------------------------------- #

case $outopt in
  native) out_progs="ww3_trck" ;;
  netcdf) out_progs="ww3_trnc" ;;
  both)   out_progs="ww3_trck ww3_trnc" ;;
  *)      out_progs="" ;;
esac

for prog in $out_progs
do

	if [ $exec_p = $prog -o $exec_p = "none" ]
	then

		# select inp/nml files
		if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}*.nml 2>/dev/null`" ]
		then
		  inputs="`ls ${path_i}/${prog}*.nml 2>/dev/null`"
		else
		  inputs="`ls $path_i/$prog*.inp 2>/dev/null`"
		fi


		if [ $? = 0 ]
		then

		  echo ' '
		  echo '+--------------------+'
		  echo '|    Track output    |'
		  echo '+--------------------+'
		  echo ' '

		  if [ $force_shrd ]
		  then # build pre- & post-processing programs with SHRD only
		    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
				  sed 's/OMPG //'    | sed 's/OMPX //'| \
				  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switch
		  else
		    \cp -f $file_c $path_b/switch
		  fi
		  if [ $testST ]
		  then #add S T switches 
		    \cp -f $path_b/switch $path_b/switch_noST
		    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
		    rm $path_b/switch_noST
		  fi
		  if $path_b/w3_make $prog
		  then :
		  else
		    errmsg "Error occured during WW3 $prog build"
		    exit 1
		  fi

		  if [ ! -f $path_e/$prog ]
		  then
		    errmsg "$path_e/$prog not found"
		    exit 1
		  fi

		  for g in $point_grids
		  do

		    if [ $multi -eq 2 ]
		    then
		      if [ ! -e track_o.$g ]
		      then
			continue
		      fi
		      gu="_$g"
		      fileconf="$prog${gu}"
		    else
		      fileconf="$prog"
		    fi

		    # select inp/nml files
		    if [ $nml_input ] && [ ! -z "`ls ${path_i}/${fileconf}.nml 2>/dev/null`" ]
		    then
		      ifile="`ls ${path_i}/${fileconf}.nml 2>/dev/null`"
		    else
		      ifile="`ls $path_i/${fileconf}.inp 2>/dev/null`"
		    fi

		    if [ ! -f $ifile ]
		    then
		      errmsg "$ifile not found"
		      exit 1
		    fi

		    # link conf file
		    if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
		    then
		      \rm -f $prog.nml
		      \ln -s $ifile $prog.nml
		      otype="`basename $ifile .nml | sed s/^${prog}_//`"
		      ofile="$path_w/`basename $ifile .nml`.out"
		    else
		      \rm -f $prog.inp
		      \ln -s $ifile $prog.inp
		      otype="`basename $ifile .inp | sed s/^${prog}_//`"
		      ofile="$path_w/`basename $ifile .inp`.out"
		    fi

		    echo "   Processing $ifile"
		    echo "   Screen output routed to $ofile"

		    if [ $multi -eq 2 ]
		    then
		      \rm -f track_o.ww3
		      \ln -s track_o.$g track_o.ww3
		    fi
		    if $path_e/$prog > $ofile
		    then
		      \rm -f $prog.inp
		      \rm -f $prog.nml
		      if [ $multi -eq 2 ]
		      then
			\rm -f track_o.ww3
			if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
			then
			  mv $prog.nml.log ${prog}_$g.nml.log
			fi
			if [ -e track.ww3 ]
			then
			  mv track.ww3 track.$g
			elif [ -e track.nc ]
			then
			  mv track.nc track_$g.nc
			fi    
		      fi
		    else
		      errmsg "Error occured during $path_e/$prog execution"
		      exit 1
		    fi
		  done

		fi

	fi

	if [ $exit_p = $prog ]
	then
	  exit
	fi

done # end of loop on progs




# 3.j Wave system tracking -------------------------------------------------- #

prog=ww3_systrk
if [ $exec_p = $prog -o $exec_p = "none" ]
then

	# select inp/nml files
	if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
	then
	  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
	else
	  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
	fi


	if [ $? = 0 ]
	then

	  echo ' '
	  echo '+-------------------------+'
	  echo '|  Wave system tracking   |'
	  echo '+-------------------------+'
	  echo ' '

	    \cp -f $file_c $path_b/switch
	#  if [ $force_shrd ]
	#  then # build pre- & post-processing programs with SHRD only
	#    cat $file_c | sed 's/DIST/SHRD/' | sed 's/MPI //' | \
	#                  sed 's/OMPG //'    | sed 's/OMPX //'| \
	#                  sed 's/OMPH //'    | sed 's/PDLIB //'  > $path_b/switchh
	#  else
	#    \cp -f $file_c $path_b/switch
	#  fi  
	  if [ $testST ]
	  then #add S T switches 
	    \cp -f $path_b/switch $path_b/switch_noST
	    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch 
	    rm $path_b/switch_noST
	  fi
	  if $path_b/w3_make $prog
	  then :
	  else
	    errmsg "Error occured during WW3 $prog build"
	    exit 1
	  fi


	  # link conf file
	  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
	  then
	    \rm -f $prog.nml
	    \ln -s $ifile $prog.nml
	    ofile="$path_w/`basename $ifile .nml`.out"
	  else
	    \rm -f $prog.inp
	    \ln -s $ifile $prog.inp
	    ofile="$path_w/`basename $ifile .inp`.out"
	  fi

	  echo "   Processing $ifile"
	  echo "   Screen output copied to $ofile"

	  if [ $pmpi ]
	  then
	    if [ $nproc ]
	    then
	      runcmd="$runcmd -np $nproc"
	    fi
	  fi
	  if $runcmd $path_e/$prog | tee $ofile
	  then
	    \rm -f $prog.inp
	    \rm -f $prog.nml
	  else
	    errmsg "Error occured during $path_e/$prog execution"
	    exit 1
	  fi
	#  if $path_e/$prog > $ofile
	#  then
	#    \rm -f $prog.inp
	#    for g in $intgl_grids
	#    do
	#      if [ -f "out_grd.$g" ]
	#      then
	#        model_grids="$model_grids $g"
	#      fi
	#    done
	#  else
	#    errmsg "Error occured during $path_e/$prog execution"
	#    exit 1
	#  fi

	fi

fi

if [ $exit_p = $prog ]
then
  exit
fi



# 3.k Update Restart File ------------------------------------------ #

prog=ww3_uprstr
if [ $exec_p = $prog -o $exec_p = "none" ]
then

	# Check for input file

	# select inp/nml files
	#if [ $nml_input ] && [ ! -z "`ls ${path_i}/${prog}.nml 2>/dev/null`" ]
	#then
	#  ifile="`ls ${path_i}/${prog}.nml 2>/dev/null`"
	#else
	  ifile="`ls $path_i/$prog.inp 2>/dev/null`"
	#fi

	if [ $? = 0 ]
	then

	  echo ' '
	  echo '+-------------------------+'
	  echo '|   Update Restart File   |'
	  echo '+-------------------------+'
	  echo ' '

	  \cp -f $file_c $path_b/switch
	  if [ $testST ]
	  then #add S T switches 
	    \cp -f $path_b/switch $path_b/switch_noST
	    cat $path_b/switch_noST | sed 's/F90/F90 S T /' > $path_b/switch
	    rm $path_b/switch_noST
	  fi
	  if $path_b/w3_make $prog
	  then :
	  else
	    errmsg "Error occured during WW3 $prog build"
	    exit 1
	  fi

	  # link conf file
	  if [ $nml_input ] && [ ! -z "`echo ${ifile} | grep -o nml`" ]
	  then
	    \rm -f $prog.nml
	    \ln -s $ifile $prog.nml
	    ofile="$path_w/`basename $ifile .nml`.out"
	  else
	    \rm -f $prog.inp
	    \ln -s $ifile $prog.inp
	    ofile="$path_w/`basename $ifile .inp`.out"
	  fi

	  echo "   Processing $ifile"
	  echo "   Screen output copied to $ofile"
	  
	# Additional Files
	   \rm -f anl.grbtxt
	   \ln -s "$path_i/anl.grbtxt" anl.grbtxt
	   
	  mv -f restart001.ww3 restart.ww3
	  
	  if [ $pmpi ]
	  then
	    if [ $nproc ]
	    then
	      runcmd="$runcmd -np $nproc"
	    fi
	  fi
	  if $runcmd $path_e/$prog | tee $ofile
	  then
	    \rm -f $prog.inp
	    \rm -f $prog.nml
	  else
	    errmsg "Error occured during $path_e/$prog execution"
	    exit 1
	  fi

	fi

fi

if [ $exit_p = $prog ]
then
  exit
fi





# 3.k End ------------------------------------------------------------------- #

if [ "$stub" ]
then
  date > finished
fi

echo ' ' ; echo ' ' ; echo "Files in `pwd` :" ; echo ' '
ls -l

echo ' ' ; echo ' '
echo '                    ==================================   '
echo '                  ======>  END OF WAVEWATCH III  <====== '
echo '                    ==================================   '
echo ' '

# --------------------------------------------------------------------------- #
# End of script                                                               #
# --------------------------------------------------------------------------- #

run_test 运行老师给的运行例子

为什么要用 run_test 这一方式运行例子,与之前那样单独一个一个运行 .inp 文件相比有什么优势?

  1. 将所有输入文件统一放在文件夹 input,主要的操作只是更改 run_test 代码进行相关操作。
  2. 运行的输出文件在文件夹 work (可以自己定义),输入文件和输出文件隔开。这很重要,可以允许我们修改 input 里的文件,创建对应的也许是 work2 文件夹。

如何用 run_test 运行自己的例子?

  1. 例子文件夹必须是在 regtests 文件夹下创建;
  2. 例子文件夹下创建 input 文件夹,将所有输入文件放在里面;
  3. 复制已经存在的 run_test 脚本,粘贴在 例子文件夹下,根据 input 文件夹下的文件(以及其它需求)修改脚本;(每个例子有一个 run_test 脚本,因为对于不同的输入文件夹,可能在脚本里添加软连接不太一样)
  4. regtests 文件夹下打开终端,运行 ./例子文件夹/run_test ...,具体的参数需要自己去了解,也可以自己设置,输出位置设置在路径即可。
  5. 复制已经存在的 info 文件,粘贴在 例子文件夹下,修改文件内容,给出这个 例子文件夹在做什么,如何使用;

这样的运行体系是很好的,作为以后建立项目的一个参考框架。

用这一方法对 老师给的运行例子输入文件进行一个框架建立,得到下面的文件夹,即对应的 例子文件夹

链接: https://pan.baidu.com/s/1IH6qgTI1eHOygB-BeA6bJA 密码: clte


ww3_ta1: ww3_uprstrt,更新同质条件下的重启文件(1点模型),「2022-05-09」「2022-05-15」


Author: Jincan
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Jincan !
  TOC