#! /bin/ksh PROGRAM=$0 # System settings set -eu export PATH=/home/m/m300966/CDRSynTra-mpiesm-1.2.01p7/util/running/functions:$PATH # Configured constants EXP_ID=esm-ssp585-ocn-alk_EXP2 INTERVAL_MONTHS=12 CALENDAR=1 # Derived constants inidate=20200101 findate=21001231 # Read command line options function usage { cat >&2 << EOT Usage: $(basename $PROGRAM) [OPTION]... JOB_ID... Create job scripts for given date range and job identifiers. Options: -f DATE set first date to DATE, formatted as YYYYMMD. Defaults to the latest experiment run if it was already started, else initial date of the experiment -l DATE set last date to DATE, formatted as YYYYMMDD. Defaults to end date corresponding to the first date (first date plus interval months minus one day) -i MONTHS override the experiment's starting interval. Do not use unless you know what you are doing EOT exit } while getopts hi:f:l: OPTOPT do case $OPTOPT in h) usage;; i) INTERVAL_MONTHS=$OPTARG;; f) firstdate=$OPTARG;; l) lastdate=$OPTARG;; *) exit 1;; esac done shift $((OPTIND - 1)) # Compute first start date and job number startdate=$inidate jobnum=1 if [[ -s $EXP_ID.date ]] then read nextdate nextjob < $EXP_ID.date startdate=$(calc_date minus -c$CALENDAR -M$INTERVAL_MONTHS -- ${nextdate}_) jobnum=$((nextjob - 1)) fi if [[ "${firstdate:-}" ]] then startdate=$firstdate months=$(time_between -c$CALENDAR $inidate $startdate months) jobnum=$((months/INTERVAL_MONTHS + 1)) fi # Compute last date if [[ -z "${lastdate:-}" ]] then lastdate=$(calc_date plus -c$CALENDAR -M$INTERVAL_MONTHS -- ${startdate}_) lastdate=$(calc_date minus -c$CALENDAR -D1 -- ${lastdate}_) fi # For all intervals while [[ $(later_date -- $startdate $lastdate) == $lastdate ]] do # Compute next and end date nextdate=$(calc_date plus -c$CALENDAR -M$INTERVAL_MONTHS -- ${startdate}_) enddate=$(calc_date minus -c$CALENDAR -D1 -- ${nextdate}_) # Create job scripts for job do template=${EXP_ID}.${job} script=${template}.${nextdate} temporary=$script.tmp sed " s/Jobnum/${jobnum}/ s/Startdate/${startdate}/ s/Nextdate/${nextdate}/ s/Findate/${findate}/ s/Inidate/${inidate}/ " $template > $temporary chmod +x $temporary mv $temporary $script echo "created ${job} job for $startdate-$enddate ($script)" done # Re-compute start date and job number startdate=$nextdate jobnum=$((jobnum + 1)) done