#!/bin/sh
#=======================================================================
# seasonal pool of model diagnostic files               --- pool_sea ---
# $Id: pool_sea_jobdef 656 2011-12-28 19:51:43Z acrnrls $
#=======================================================================
#
# Files pooled will be of the form
#    ${pool_sea_model_prefix}_${year}_${month[123]}_[gx]p
# where month[123] are the 3 months in the current season either named
# or numbered (e.g. named: mar,apr,may  or numbered: m03,m04,m05). The
# month format is controlled by the variable use_month_names.
# The pooled files that are created will be named
#    ${pool_sea_flabel_prefix}_${year}_${season}_[gx]p
#=======================================================================
#     keyword :: pool_sea
# description :: seasonal pooling of diagnostic files

#******************************
#********* WARNING ************
#******************************
#
# auto, nonqs, nextjob, flabel, RCMRUN, runid, run, nqsext, crawork,
# mdest, [sgd]time, nnodex, nprocx, initmem, sv, vic, memory[0-9],
# queue, jobname, gcmjcl
#
# These variables are special in that they are extracted from the
# submission script prior to execution and used to parse file names,
# among other things. Therefore any of these variables whose definition
# depends on another variable that is not in this list will be improperly
# defined in this preprocessing step. This could lead to file names being
# incorrectly specified. The variables are extracted by copying the entire
# line on which they are defined from the submission script. Therefore
# variables that are used to define any of these variables must be defined
# on the same line as that variable and prior to it or on a previous line
# that contains any of these variables.
#
#******************************
set -a
. betapath2

#  *     Job to pool seasonal diagnostic files

#  * ........................... Parmsub Parameters ............................

 # These variables are set when the job string is created
 run_start_year=NotSet   # memory99=1
 run_start_month=NotSet  # memory99=1
 run_stop_year=NotSet    # memory99=1
 run_stop_month=NotSet   # memory99=1
 current_year=NotSet     # memory99=1
 current_month=NotSet    # memory99=1
 previous_year=NotSet    # memory99=1
 previous_month=NotSet   # memory99=1
 next_year=NotSet        # memory99=1
 next_month=NotSet       # memory99=1

 days="MAM"

 runid=aaa; uxxx=uxxx;
 pool_uxxx=$uxxx; pool_sea_flabel_uxxx=$pool_uxxx         # memory99=1
 diag_uxxx=$uxxx; pool_sea_model_uxxx=$diag_uxxx          # memory99=1
 pool_sea_flabel_prefix=${pool_sea_flabel_uxxx}_${runid}  # memory99=1
 pool_sea_model_prefix=${pool_sea_model_uxxx}_${runid}    # memory99=1
 year=000; season=sea; flabel="${pool_sea_flabel_prefix}_${year}_${season}_"

 jobname=pool_sea;
 crawork=${runid}_pool_sea; username="acrnxxx"; user="XXX"
 nqsprfx="${runid}_"; nqsext='';

 # pool_suffix_list is used by poolseas4
 pool_sea_suffix_list=''
 pool_suffix_list=${pool_sea_suffix_list:=''}

 # mm?? are the month names for this season in the form m01,m02,m03,...
 memory99=1; mm01=xxx; mm02=yyy; mm03=zzz

 # mn?? are the month names for this season in the form jan,feb,mar,...
 memory99=1; mn01=xxx; mn02=yyy; mn03=zzz

 # use_month_names will flag the use of jan,feb,mar,... rather than m01,m02,m03,...
 memory99=1; use_month_names=0

 if [ x"$mm01" = x"m12" -o x"$mn01" = x"dec" ]; then
   year1=`echo $year|awk '{printf "%3.3d",$1-1}' -`
 else
   year1=$year
 fi
 if [ $use_month_names -eq 1 ]; then
   model1="${pool_sea_model_prefix}_${year1}_${mn01}_";
   model2="${pool_sea_model_prefix}_${year}_${mn02}_";
   model3="${pool_sea_model_prefix}_${year}_${mn03}_";
 else
   model1="${pool_sea_model_prefix}_${year1}_${mm01}_";
   model2="${pool_sea_model_prefix}_${year}_${mm02}_";
   model3="${pool_sea_model_prefix}_${year}_${mm03}_";
 fi

# number of days in each month used for seasonal pooling
 ml01="   31";
 ml02="   30";
 ml03="   31";

 memory1="800mb"; memory2="800mb"; memory3="800mb";
 dtime="1800"; gptime="1800"; stime="1800";

 lopgm=lopgm

 # Allow the user to reset CCRNTMP and/or RUNPATH
 pool_RUNPATH=''
 RUNPATH=${pool_RUNPATH:=$RUNPATH}
 pool_CCRNTMP=''
 CCRNTMP=${pool_CCRNTMP:=$CCRNTMP}

 # Alternate path to a directory where .queue/.crawork will be found
 JHOME=''

 if [ -n "$JHOME" -a x"$JHOME" != x"$HOME" ]; then
   # Allow optional reset of DATAPATH/RUNPATH
   JHOME_DATA=''
   DATAPATH=${JHOME_DATA:=$DATAPATH}
   RUNPATH=${JHOME_DATA:=$RUNPATH}
   # Allow optional reset of CCRNTMP
   JHOME_RUN=''
   CCRNTMP=${JHOME_RUN:=$CCRNTMP}
 fi

#  * ............................ Condef Parameters ............................

 join=3
 nextjob=on
 noprint=on
 # pool_var=on means pool variances as well as means
 pool_sea_pool_var=off
 pool_var=$pool_sea_pool_var
 # poolabort=off means do not abort when variables are missing
 poolabort=off

#  * ............................. Deck Definition .............................

 . poolseas4.dk

#end_of_job
