#PBS -N runhistory_aqm_emission_%TIME%
#PBS -S /bin/bash
#PBS -j oe
#PBS -A %PROJ%-%PROJENVIR%
#PBS -q %QUEUE%
#PBS -l walltime=14:00:00
#PBS -l select=1:ncpus=1:mem=1GB
#PBS -l debug=true

export model=runhistory
%include <head.h>
%include <envir-p1.h>

export njob=%TASK%

aqm_ver=%aqm_ver%
export aqm_v2d=$(echo $aqm_ver | sed 's|\(.*\)\..*|\1|')

export active_server=%ECF_LOGHOST%
export active_port=%ECF_PORT%

export cyc=%CYC%

export RSYNC_MAXTIME=%RSYNC_MAXTIME:30%
export LOG_DAYS_KEEP=%LOG_DAYS_KEEP:5%
export WRITE_LOG_DIR=%WRITE_LOG_DIR:YES%
export RSYNC_LOG_DIR=%RSYNC_LOG_DIR:YES%
export READ_LOG_DIR=%READ_LOG_DIR:YES%
export CHECK_HPSS_IDX=%CHECK_HPSS_IDX:YES%
export DRY_RUN_ONLY=%DRY_RUN_ONLY:NO%

${HOMErunhistory}/jobs/JRHIST_AQM_EMISSION

if [ $? -ne 0 ]; then
  ecflow_client --abort
  exit
fi

%include <tail.h>
%manual
################################################################################
TASKSCRIPT DOCUMENTATION BLOCK

TASKSCRIPT:     jrunhistory_aqm_emission
LAST MODIFIER:  Gregory Mott (Gregory.Mott@noaa.gov)
DATE:           Jun 2022

FULL NAME:    /prod/primary/cron/runhistory/v?.?/jrunhistory_aqm_emission
TRIGGERED BY: time trigger
TRIGGERS:     cron 12:00

PURPOSE:  To execute the job that archives the aqm_emission data, it actually do the archive once per month on day of 17 in the month

JOB SCRIPT CALLED: .../packages/runhistory.v?.?.?/jobs/JRHIST_AQM_EMISSION ==>
                   .../packages/runhistory.v?.?.?/scripts/exrhist_aqm_emission.sh.ecf

JOB SPECIFIC VARIABLES WITH DEFAULT VALUES (can be changed through ecFlow):

RSYNC_MAXTIME=30 # timeout for rsync in seconds                                                                                                                             
LOG_DAYS_KEEP=5 # $LOGrunhistory entries older than this are deleted at the beginning of every run                                                                                     
WRITE_LOG_DIR=YES # YES: create a log entry in $LOGrunhistory for each successful ush/rhist_save* run                                                                            
RSYNC_LOG_DIR=YES # YES: synchronize $LOGrunhistory (with the superset of all files) between Gyre and Tide at the beginning of every run                                               
READ_LOG_DIR=YES # YES: use $LOGrunhistory to decide if archiving should be skipped                                                                                               
CHECK_HPSS_IDX=YES # YES: check *.idx files on HPSS (file present: archiving is skipped)                                                                                   
DRY_RUN_ONLY=NO # YES: do not write to the archive (useful for checking the script logic and the list of archived files)                                                     
                #      but do clean/synchronize $LOGrunhistory                                                                                                                    
                # use with READ_LOG_DIR=NO and CHECK_HPSS_IDX=NO to get full info even if archiving done before                                                              

#################################################################################
%end