| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# Purpose: Climatology script tailored to E3SM (and hence CESM'ish) input and E3SM output guidelines |
| 4 |
# Produces (and optionally regrids) climatological monthly means, seasonal means, annual means, CMIP6-style timeseries, global-mean timeseries, diurnal cycles |
| 5 |
|
| 6 |
# Copyright (C) 2015--present Charlie Zender |
| 7 |
# This file is part of NCO, the netCDF Operators. NCO is free software. |
| 8 |
# You may redistribute and/or modify NCO under the terms of the |
| 9 |
# 3-Clause BSD License. |
| 10 |
|
| 11 |
# You are permitted to link NCO with the HDF, netCDF, OPeNDAP, and UDUnits |
| 12 |
# libraries and to distribute the resulting executables under the terms |
| 13 |
# of the BSD, but in addition obeying the extra stipulations of the |
| 14 |
# HDF, netCDF, OPeNDAP, and UDUnits licenses. |
| 15 |
|
| 16 |
# This program is distributed in the hope that it will be useful, |
| 17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 19 |
# See the 3-Clause BSD License for more details. |
| 20 |
|
| 21 |
# The original author of this software, Charlie Zender, seeks to improve |
| 22 |
# it with your suggestions, contributions, bug-reports, and patches. |
| 23 |
# Please contact the NCO project at http://nco.sf.net or write to |
| 24 |
# Charlie Zender |
| 25 |
# Department of Earth System Science |
| 26 |
# University of California, Irvine |
| 27 |
# Irvine, CA 92697-3100 |
| 28 |
|
| 29 |
# Prerequisites: Bash, NCO |
| 30 |
# Script could use other shells, e.g., dash (Debian default) after rewriting function definitions and loops |
| 31 |
# Debug with 'bash -x ncclimo --dbg=dbg_lvl' where 0 <= dbg_lvl <= 5 |
| 32 |
|
| 33 |
# Source: https://github.com/nco/nco/tree/master/data/ncclimo |
| 34 |
# Documentation: http://nco.sf.net/nco.html#ncclimo |
| 35 |
# Additional Documentation: |
| 36 |
# ncclimo HowTo: https://e3sm.atlassian.net/wiki/spaces/DOC/pages/31129737/Generate+Regrid+and+Split+Climatologies+climo+files+with+ncclimo |
| 37 |
# E3SM Climatology Requirements: https://acme-climate.atlassian.net/wiki/display/ATM/Climo+Files+-+v0.3+AMIP+runs |
| 38 |
|
| 39 |
# Insta-install: |
| 40 |
# scp ~/nco/data/ncclimo andes.olcf.ornl.gov:bin_andes |
| 41 |
# scp ~/nco/data/ncclimo [email protected]:bin |
| 42 |
# scp ~/nco/data/ncclimo [email protected]:bin_chrysalis |
| 43 |
# scp ~/nco/data/ncclimo compy.pnl.gov:bin |
| 44 |
# scp ~/nco/data/ncclimo derecho.hpc.ucar.edu:bin |
| 45 |
# scp ~/nco/data/ncclimo dust.ess.uci.edu:bin |
| 46 |
# scp ~/nco/data/ncclimo e3sm.ess.uci.edu:bin |
| 47 |
# scp ~/nco/data/ncclimo imua.ess.uci.edu:bin |
| 48 |
# scp ~/nco/data/ncclimo perlmutter-p1.nersc.gov:bin_perlmutter |
| 49 |
# scp ~/nco/data/ncclimo spectral.ess.uci.edu:bin |
| 50 |
# scp dust.ess.uci.edu:bin/ncclimo ~/bin |
| 51 |
# scp dust.ess.uci.edu:bin/ncclimo ${MY_BIN_DIR} |
| 52 |
# scp [email protected]:bin/ncclimo ${MY_BIN_DIR} |
| 53 |
|
| 54 |
# Set script name, directory, PID, run directory |
| 55 |
drc_pwd=${PWD} |
| 56 |
# Security: Explicitly unset IFS before wordsplitting, so Bash uses default IFS=<space><tab><newline> |
| 57 |
unset IFS |
| 58 |
# Set these before 'module' command which can overwrite ${BASH_SOURCE[0]} |
| 59 |
# NB: dash supports $0 syntax, not ${BASH_SOURCE[0]} syntax |
| 60 |
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in |
| 61 |
spt_src="${BASH_SOURCE[0]}" |
| 62 |
[[ -z "${spt_src}" ]] && spt_src="${0}" # Use ${0} when BASH_SOURCE is unavailable (e.g., dash) |
| 63 |
while [ -h "${spt_src}" ]; do # Recursively resolve ${spt_src} until file is no longer a symlink |
| 64 |
drc_spt="$( cd -P "$( dirname "${spt_src}" )" && pwd )" |
| 65 |
spt_src="$(readlink "${spt_src}")" |
| 66 |
[[ ${spt_src} != /* ]] && spt_src="${drc_spt}/${spt_src}" # If ${spt_src} was relative symlink, resolve it relative to path where symlink file was located |
| 67 |
done |
| 68 |
cmd_ln="${spt_src} ${@}" |
| 69 |
drc_spt="$( cd -P "$( dirname "${spt_src}" )" && pwd )" |
| 70 |
spt_nm=$(basename ${spt_src}) # [sng] Script name (unlike $0, ${BASH_SOURCE[0]} works well with 'source <script>') |
| 71 |
spt_pid=$$ # [nbr] Script PID (process ID) |
| 72 |
|
| 73 |
# 20200110 Qi Tang reports his batch scripts on Cori that use netCDF4 map-files fail unless he sets this |
| 74 |
if [ -z "${HDF5_USE_FILE_LOCKING}" ]; then |
| 75 |
export HDF5_USE_FILE_LOCKING='FALSE' |
| 76 |
fi # HDF5_USE_FILE_LOCKING |
| 77 |
|
| 78 |
# 20221108: Passing environment variable NCO_PATH_OVERRIDE (NPO) to ncremap in batch queues fails on Cori |
| 79 |
# Approaches that fail include: 1. export NPO='Yes';ncremap ... 2. export NPO='Yes' ncremap ... |
| 80 |
# Direct approach that works is to pass NPO flag to ncremap via command-line switch |
| 81 |
# Require that path-override switch to be first command-line option (i.e., $1) found with shell syntax |
| 82 |
# ncremap/ncclimo implement NPO (though not getopt) logic prior to invoking NCO |
| 83 |
# This switch is a no-op in main getopt() block below (since it has already been parsed here) |
| 84 |
hrd_pth='No' # [sng] Hard-code machine-dependent paths/modules if HOSTNAME in database |
| 85 |
if [ -n "${1}" ]; then |
| 86 |
if [ "${1}" = '--hrd_pth' ] || [ "${1}" = '--npo' ] || [ "${1}" = '--nco_path_override' ] || [ "${1}" = '--NCO_PATH_OVERRIDE' ]; then |
| 87 |
hrd_pth='Yes' |
| 88 |
NCO_PATH_OVERRIDE='Yes' |
| 89 |
fi # !hrd_pth |
| 90 |
fi # !$1 |
| 91 |
|
| 92 |
# Configure paths at High-Performance Computer Centers (HPCCs) based on ${HOSTNAME} |
| 93 |
if [ -z "${HOSTNAME}" ]; then |
| 94 |
if [ -f /bin/hostname ] && [ -x /bin/hostname ]; then |
| 95 |
export HOSTNAME=`/bin/hostname` |
| 96 |
elif [ -f /usr/bin/hostname ] && [ -x /usr/bin/hostname ]; then |
| 97 |
export HOSTNAME=`/usr/bin/hostname` |
| 98 |
fi # !hostname |
| 99 |
fi # HOSTNAME |
| 100 |
# Default input and output directory is ${DATA} |
| 101 |
if [ -z "${DATA}" ]; then |
| 102 |
case "${HOSTNAME}" in |
| 103 |
andes* ) DATA="/gpfs/alpine/world-shared/cli115/${USER}" ; ;; # OLCF andes compute nodes named andesNNN, 256 GB/node |
| 104 |
bebop* | blogin* | b[0123456789][0123456789][0123456789] ) DATA="/lcrc/group/e3sm/${USER}" ; ;; # ANL/LCRC bebop compute nodes named bNNN, 36|64 cores|GB/node |
| 105 |
chrysalis* | chrlogin* | chr-[0123456789][0123456789][0123456789][0123456789] ) DATA="/lcrc/group/e3sm/${USER}" ; ;; # ANL/LCRC chrysalis compute nodes named chr-NNNN, 64|256 cores|GB/node |
| 106 |
compy* | n[0123456789][0123456789][0123456789][0123456789] ) DATA="/qfs/people/${USER}/data" ; ;; # PNNL compy compute nodes all named nNNNN, 40|192 cores|GB/node (compy login nodes also 192 GB) |
| 107 |
constance* | node* ) DATA='/scratch' ; ;; # PNNL |
| 108 |
derecho* ) DATA="/glade/p/work/${USER}" ; ;; # NCAR derecho compute nodes named, e.g., r8i0n8, r5i3n16, r12i5n29 ... 18|(64/256) cores|GB/node (derecho login nodes 512 GB) |
| 109 |
frontier* ) DATA="/lustre/orion/cli115/world-shared/${USER}" ; ;; # OLCF frontier compute nodes named frontier01276 64|512 cores|GB/node |
| 110 |
ilogin* | i[0123456789][0123456789][0123456789] ) DATA="/lcrc/group/e3sm/${USER}" ; ;; # ANL/LCRC improv compute nodes named iNNN, 128|256 cores|GB/node |
| 111 |
login[0123456789][0123456789] ) # 20230831 Frontier and Perlmutter login nodes share this name :( |
| 112 |
if [ "${LMOD_SYSTEM_NAME}" = 'frontier' ]; then |
| 113 |
DATA="/lustre/orion/cli115/world-shared/${USER}" |
| 114 |
elif [ "${LMOD_SYSTEM_NAME}" = 'perlmutter' ]; then |
| 115 |
DATA="${SCRATCH}" |
| 116 |
fi # !LMOD_SYSTEM_NAME |
| 117 |
;; # !login |
| 118 |
perlmutter* | nid[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789] ) DATA="${SCRATCH}" ; ;; # NERSC perlmutter compute nodes named nidNNNNNN (CPU) with (128)|(512) cores|GB/node (cpu) (login nodes 512 GB) |
| 119 |
* ) DATA='/tmp' ; ;; # Other |
| 120 |
esac # !HOSTNAME |
| 121 |
fi # DATA |
| 122 |
# 20190423 Speed-up OpenMP processes on Cori KNL Intel builds (and possibly others) |
| 123 |
# Environmental settings (e.g., OMP_PROC_BIND=spread or KMP_PROC_BIND=intel) may place all threads on same hardware core |
| 124 |
# Problem only known to manifest when multiple instances of NCO are spawned on single node |
| 125 |
OMP_PROC_BIND=false |
| 126 |
|
| 127 |
# Ensure batch jobs access correct 'mpirun' (or, with SLURM, 'srun') command, netCDF library, and NCO executables and library |
| 128 |
# 20170914 Entire block is identical between ncclimo and ncremap---keep it that way! |
| 129 |
# 20190421 Change override default from opt-out to opt-in |
| 130 |
# 20221108 Implement hrd_pth in block above prior to getopt() |
| 131 |
# 20250903 Simplify code: Always define then re-use E3SMU_ROOT, then add E3SMU_ROOT/bin to path only for ncremap |
| 132 |
# 20260416 Andes does not include personal Anaconda because I never installed one there |
| 133 |
# Leave NCO_PATH_OVERRIDE unset or set to 'No' to prevent NCO from executing next block that overrides PATH |
| 134 |
# Set NCO_PATH_OVERRIDE to 'Yes' in environment to cause NCO to execute next block and to override PATH: |
| 135 |
# export NCO_PATH_OVERRIDE='Yes' |
| 136 |
if [ "${hrd_pth}" = 'Yes' ] && [ "${NCO_PATH_OVERRIDE}" = 'Yes' ]; then |
| 137 |
# If HOSTNAME is not in database, change hrd_pth_fnd to 'No' in case-statement default fall-through |
| 138 |
hrd_pth_fnd='Yes' # [sng] Machine-dependent paths/modules for HOSTNAME found in database |
| 139 |
case "${HOSTNAME}" in |
| 140 |
andes* ) |
| 141 |
# 20190827: Must guarantee finding mpirun |
| 142 |
source ${MODULESHOME}/init/sh # 20150607: PMC Ensures find module commands will be found |
| 143 |
if [ -d '/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 144 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco/andes' |
| 145 |
else |
| 146 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/base/envs/e3sm_unified_latest' |
| 147 |
fi |
| 148 |
export PATH='/ccs/home/zender/bin_andes'\:${PATH} |
| 149 |
export LD_LIBRARY_PATH='/ccs/home/zender/lib_andes'\:${E3SMU_ROOT}/lib\:${LD_LIBRARY_PATH} ; ;; |
| 150 |
bebop* | blogin* | b[0123456789][0123456789][0123456789] ) |
| 151 |
if [ -d '/lcrc/soft/climate/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 152 |
E3SMU_ROOT='/lcrc/soft/climate/e3sm-unified/e3smu_latest_for_nco/anvil' |
| 153 |
else |
| 154 |
E3SMU_ROOT='/lcrc/soft/climate/e3sm-unified/base/envs/e3sm_unified_latest' |
| 155 |
fi |
| 156 |
export PATH='/home/zender/bin'\:${PATH} |
| 157 |
export LD_LIBRARY_PATH='/home/zender/lib'\:${E3SMU_ROOT}/lib\:${LD_LIBRARY_PATH} ; ;; |
| 158 |
chrysalis* | chrlogin* | chr-[0123456789][0123456789][0123456789][0123456789] | ilogin* | i[0123456789][0123456789][0123456789] ) |
| 159 |
if [ -d '/lcrc/soft/climate/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 160 |
E3SMU_ROOT='/lcrc/soft/climate/e3sm-unified/e3smu_latest_for_nco/chrysalis' |
| 161 |
else |
| 162 |
E3SMU_ROOT='/lcrc/soft/climate/e3sm-unified/base/envs/e3sm_unified_latest' |
| 163 |
fi |
| 164 |
export PATH='/home/ac.zender/bin_chrysalis'\:${PATH} |
| 165 |
export LD_LIBRARY_PATH='/home/ac.zender/lib_chrysalis:/home/ac.zender/anaconda/lib'\:${E3SMU_ROOT}/lib\:${LD_LIBRARY_PATH} ; ;; |
| 166 |
compy* | n[0123456789][0123456789][0123456789][0123456789] ) |
| 167 |
module purge |
| 168 |
module load gcc/10.2.0 |
| 169 |
# 20210519: This script takes significant time (5-10 seconds) to load |
| 170 |
# 20230914: Deprecate special MOAB paths, rely on E3SMU |
| 171 |
# source /compyfs/software/mbtempest.envs.sh |
| 172 |
if [ -d '/share/apps/E3SM/conda_envs/e3smu_latest_for_nco' ]; then |
| 173 |
E3SMU_ROOT='/share/apps/E3SM/conda_envs/e3smu_latest_for_nco/compy' |
| 174 |
else |
| 175 |
E3SMU_ROOT='/share/apps/E3SM/conda_envs/base/envs/e3sm_unified_latest' |
| 176 |
fi |
| 177 |
export PATH='/qfs/people/zender/bin:/qfs/people/zender/anaconda/bin'\:${PATH} |
| 178 |
export LD_LIBRARY_PATH='/qfs/people/zender/lib:/qfs/people/zender/anaconda/lib'\:${LD_LIBRARY_PATH} ; ;; |
| 179 |
derecho* ) |
| 180 |
# 20240107: Derecho support not yet tested in batch mode |
| 181 |
if [ ${spt_nm} = 'ncremap' ]; then |
| 182 |
# On cheyenne, module load ncl installs ERWG in /glade/u/apps/ch/opt/ncl/6.4.0/intel/17.0.1/bin (i.e., ${NCARG_ROOT}/bin) |
| 183 |
module load ncl |
| 184 |
fi # !ncremap |
| 185 |
if [ -n "${NCARG_ROOT}" ]; then |
| 186 |
export PATH="${PATH}:/glade/u/apps/ch/opt/ncl/6.6.2/gnu/8.3.0/bin" |
| 187 |
fi # !NCARG_ROOT |
| 188 |
export PATH='/glade/u/home/zender/bin'\:${PATH} |
| 189 |
export LD_LIBRARY_PATH='/glade/u/apps/derecho/23.06/spack/opt/spack/netcdf/4.9.2/gcc/12.2.0/ok4t/lib:/glade/u/apps/derecho/23.06/spack/opt/spack/udunits/2.2.28/gcc/12.2.0/vls2/lib:/glade/u/apps/ch/opt/gsl/2.7/gnu/12.1.0/lib:/glade/u/home/zender/lib'\:${LD_LIBRARY_PATH} ; ;; |
| 190 |
e3sm* ) |
| 191 |
export PATH='/home/zender/bin:/home/zender/anaconda/bin'\:${PATH} |
| 192 |
export LD_LIBRARY_PATH='/home/zender/lib:/home/zender/anaconda/lib'\:${LD_LIBRARY_PATH} ; ;; |
| 193 |
frontier* ) |
| 194 |
if [ ${spt_nm} = 'ncremap' ]; then |
| 195 |
if [ -d '/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 196 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco/frontier' |
| 197 |
else |
| 198 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/base/envs/e3sm_unified_latest' |
| 199 |
fi |
| 200 |
fi # !ncremap |
| 201 |
export PATH='/ccs/home/zender/bin_frontier:/ccs/home/zender/anaconda/bin'\:${PATH} |
| 202 |
export LD_LIBRARY_PATH='/ccs/home/zender/lib_frontier:/ccs/home/zender/anaconda/lib'\:${LD_LIBRARY_PATH} ; ;; |
| 203 |
login[0123456789][0123456789] ) # 20230831 Frontier and Perlmutter login nodes share this name :( |
| 204 |
if [ "${LMOD_SYSTEM_NAME}" = 'frontier' ]; then |
| 205 |
if [ -d '/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 206 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco/frontier' |
| 207 |
else |
| 208 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/base/envs/e3sm_unified_latest' |
| 209 |
fi |
| 210 |
export PATH='/ccs/home/zender/bin_frontier:/ccs/home/zender/anaconda/bin'\:${PATH} |
| 211 |
export LD_LIBRARY_PATH='/ccs/home/zender/lib_frontier:/ccs/home/zender/anaconda/lib'\:${LD_LIBRARY_PATH} |
| 212 |
elif [ "${LMOD_SYSTEM_NAME}" = 'perlmutter' ]; then |
| 213 |
# 20221103 Add build environment modules |
| 214 |
# 20260317 Test removing these modules |
| 215 |
#module load PrgEnv-gnu |
| 216 |
#module load cray-hdf5/1.12.2.9 |
| 217 |
#module load cray-netcdf/4.9.0.9 |
| 218 |
if [ -d '/global/common/software/e3sm/anaconda_envs/e3smu_latest_for_nco' ]; then |
| 219 |
E3SMU_ROOT='/global/common/software/e3sm/anaconda_envs/e3smu_latest_for_nco/pm-cpu' |
| 220 |
else |
| 221 |
E3SMU_ROOT='/global/common/software/e3sm/anaconda_envs/base/envs/e3sm_unified_latest' |
| 222 |
fi # !E3SMU-NCO |
| 223 |
if [ -n "${NCARG_ROOT}" ]; then |
| 224 |
export PATH="${PATH}:${NCARG_ROOT}/bin" |
| 225 |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${NCARG_ROOT}/lib" |
| 226 |
fi # !NCARG_ROOT |
| 227 |
export PATH='/global/cfs/cdirs/e3sm/zender/bin_perlmutter:/global/cfs/cdirs/e3sm/zender/anaconda/bin'\:${PATH} |
| 228 |
export LD_LIBRARY_PATH='/global/cfs/cdirs/e3sm/zender/lib_perlmutter:/global/cfs/cdirs/e3sm/zender/anaconda/lib'\:${LD_LIBRARY_PATH} |
| 229 |
fi # !LMOD_SYSTEM_NAME |
| 230 |
;; # !login |
| 231 |
perlmutter* | nid[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789] ) |
| 232 |
# 20221103 Add build environment modules |
| 233 |
# 20260317 Test removing these modules |
| 234 |
#module load PrgEnv-gnu |
| 235 |
#module load cray-hdf5/1.12.2.9 |
| 236 |
#module load cray-netcdf/4.9.0.9 |
| 237 |
if [ -d '/global/common/software/e3sm/anaconda_envs/e3smu_latest_for_nco' ]; then |
| 238 |
E3SMU_ROOT='/global/common/software/e3sm/anaconda_envs/e3smu_latest_for_nco/pm-cpu' |
| 239 |
else |
| 240 |
E3SMU_ROOT='/global/common/software/e3sm/anaconda_envs/base/envs/e3sm_unified_latest' |
| 241 |
fi # !E3SMU-NCO |
| 242 |
if [ -n "${NCARG_ROOT}" ]; then |
| 243 |
export PATH="${PATH}:${NCARG_ROOT}/bin" |
| 244 |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${NCARG_ROOT}/lib" |
| 245 |
fi # !NCARG_ROOT |
| 246 |
export PATH='/global/cfs/cdirs/e3sm/zender/bin_perlmutter:/global/cfs/cdirs/e3sm/zender/anaconda/bin'\:${PATH} |
| 247 |
export LD_LIBRARY_PATH='/global/cfs/cdirs/e3sm/zender/lib_perlmutter:/global/cfs/cdirs/e3sm/zender/anaconda/lib'\:${E3SMU_ROOT}/lib\:${LD_LIBRARY_PATH} ; ;; |
| 248 |
* ) # Default fall-through |
| 249 |
hrd_pth_fnd='No' ; ;; |
| 250 |
esac # !HOSTNAME |
| 251 |
# 20210519: E3SM-U supplies many uncommon executables and libraries, e.g., libantlr, ESMF_RegridWeightGen |
| 252 |
# 20241220: Now that ncclimo also regularly uses ncap2 executable for global timeseries, must modify its path too |
| 253 |
# ncclimo only needs access to E3SM_U libraries (e.g., libgsl, libantlr), already implemented above |
| 254 |
# ncremap needs access to E3SM_U binaries (ESMF_RegridWeightGen, ...) _and_ libraries |
| 255 |
# Append E3SM-U binaries to _end_ of PATH so NCO binaries not redirected, e.g., from CSZ's development directory to E3SM-U |
| 256 |
if [ -n "${E3SMU_ROOT}" ] && [ ${spt_nm} = 'ncremap' ]; then |
| 257 |
export PATH="${PATH}:${E3SMU_ROOT}/bin" |
| 258 |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${E3SMU_ROOT}/lib" |
| 259 |
fi # !E3SMU_ROOT |
| 260 |
fi # !hrd_pth && !NCO_PATH_OVERRIDE |
| 261 |
|
| 262 |
# Test cases ($DATA/[grids/maps] refers to ~zender/data/[grids/maps] on Charlie's test machines) |
| 263 |
# Production usage: |
| 264 |
# ncclimo -P cam -c famipc5_ne30_v0.3_00003 -s 1979 -e 1983 -r ${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -O ${DATA}/ne30/rgr # LR |
| 265 |
# ncclimo -P cam -c fxm -s 1 -e 127 -i fxm -o ${DATA}/ne120/clm # HR |
| 266 |
|
| 267 |
# Incremental climo testing: |
| 268 |
# ncclimo -v FSNT,AODVIS -c famipc5_ne30_v0.3_00003 -s 1980 -e 1981 -i ${DATA}/ne30/raw -o ${DATA}/ne30/prv -r ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc |
| 269 |
# ncclimo -v FSNT,AODVIS -c famipc5_ne30_v0.3_00003 -s 1982 -e 1983 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -r ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc -x ${DATA}/ne30/prv -X ${DATA}/ne30/xtn -S 1980 |
| 270 |
# Binary climo testing: |
| 271 |
# ncclimo -v FSNT,AODVIS -c famipc5_ne30_v0.3_00003 -S 1980 -E 1981 -x ${DATA}/ne30/prv -s 1982 -e 1983 -i ${DATA}/ne30/clm -X ${DATA}/ne30/xtn |
| 272 |
|
| 273 |
# Annual climo testing: |
| 274 |
# ncclimo -C ann -m cism -h h -c b.e10.BG20TRCN.f09_g16.002 -s 1851 -e 2006 -i /gpfs/alpine/cli115/proj-shared/4ue/data/for_charlie -o ${DATA}/ne30/clm |
| 275 |
# ncclimo -C ann -m cism -h h -c b.e10.BG20TRCN.f09_g16.002 -s 1851 -e 1852 -i /gpfs/alpine/cli115/proj-shared/4ue/data/for_charlie -o ${DATA}/ne30/clm > ~/ncclimo.out 2>&1 & |
| 276 |
# ncclimo -C ann -m mpas -s 1851 -e 1852 -i ${DATA}/hdf/mpasLIoutput.nc -o ${DATA}/mpas/clm > ~/ncclimo.out 2>&1 & |
| 277 |
|
| 278 |
# High-frequency climos: |
| 279 |
# drc_in=${DATA}/ne30/raw |
| 280 |
# caseid=famipc5_ne30_v0.3_00007.cam.h4 # 3-hour resolution |
| 281 |
# cd ${drc_in};ls ${caseid}*.nc | ncclimo --var=PRECT --clm_md=hfc --caseid=hfc --yr_srt=2001 --yr_end=2002 --drc_out=${HOME} --map=${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc # Multi-file input |
| 282 |
# ncclimo --var=PRECT --clm_md=hfc --caseid=hfc --yr_srt=2001 --yr_end=2002 --drc_out=${HOME} --map=${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc ~/PRECT_200101_200212.nc # Single file input |
| 283 |
|
| 284 |
# Debugging and Benchmarking: |
| 285 |
# E3SM v3: |
| 286 |
# ncclimo -7 --cmp='gbr|shf|zst' -P eam -v FSNT,AODVIS,TREFHT -c v3.LR.piControl -s 460 -e 461 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -O ${DATA}/ne30/rgr -r ${DATA}/maps/map_ne30pg2_to_cmip6_180x360_traave.20231201.nc # Compression! |
| 287 |
# E3SM v2: |
| 288 |
# ncclimo -7 --cmp='gbr|shf|zst' -P eam -v FSNT,AODVIS,TREFHT -c v2.LR.historical_0101 -s 2013 -e 2014 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -O ${DATA}/ne30/rgr -r ${DATA}/maps/map_ne30pg2_to_cmip6_180x360_nco.20200901.nc # Compression! |
| 289 |
# ncclimo -P eam -v FSNT,AODVIS,TREFHT -c v2.LR.historical_0101 -s 2013 -e 2014 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -O ${DATA}/ne30/rgr -r ${DATA}/maps/map_ne30pg2_to_cmip6_180x360_nco.20200901.nc |
| 290 |
# cd ${DATA}/ne30/raw;ls v2.LR*eam*201[34]-??*.nc | ncclimo --split --dbg=1 --rgn_avg -s 2013 -e 2014 --var=TREFHT,FSNT,AODVIS --drc_out=${DATA}/ne30/clm |
| 291 |
# cd ${DATA}/ne30/raw;ls v2.LR*elm*201[34]-??*.nc | ncclimo -P elm --split --dbg=1 --rgn_avg -s 2013 -e 2014 --var=FSDS,TBOT --drc_out=${DATA}/ne30/clm |
| 292 |
# ncclimo -P eam --var_lst=FSNT,AODVIS,TREFHT --caseid=v2.LR.historical_0101 --yr_srt=2013 --yr_end=2014 --drc_in=${DATA}/ne30/raw --drc_out=${DATA}/ne30/clm --map=${DATA}/maps/map_ne30pg2_to_cmip6_180x360_nco.20200901.nc |
| 293 |
# E3SM v1: |
| 294 |
# ncclimo -P eam -m cam -v FSNT,AODVIS,TREFHT -c 20180129.DECKv1b_piControl.ne30_oEC.edison -s 1 -e 2 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -O ${DATA}/ne30/rgr -r ${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc |
| 295 |
# ncclimo -P eam -m cam --var_lst=FSNT,AODVIS,TREFHT --caseid=20180129.DECKv1b_piControl.ne30_oEC.edison --yr_srt=1 --yr_end=2 --drc_in=${DATA}/ne30/raw --drc_out=${DATA}/ne30/clm --map=${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc |
| 296 |
# ncclimo -v TOTEXTTAU -c merra2_198001.nc4 -s 1980 -e 2015 -i ${DATA}/merra2/raw -o ${DATA}/merra2/clm |
| 297 |
# ncclimo > ~/ncclimo.out 2>&1 & |
| 298 |
# ncclimo -c B1850C5e1_ne30 -s 2 -e 199 > ~/ncclimo.out 2>&1 & |
| 299 |
# ncclimo -c ne30_gx1.B1850c5d -s 6 -e 7 > ~/ncclimo.out 2>&1 & |
| 300 |
# ncclimo -d 2 -v FSNT -m cam2 -c essgcm14 -s 1 -e 20 -i ${DATA}/essgcm14 -o ${DATA}/anl > ~/ncclimo.out 2>&1 & |
| 301 |
# MPAS: Prior to running ncclimo on MPAS output, annotate missing values of input with, e.g., |
| 302 |
# for fl in `ls hist.*` ; do |
| 303 |
# ncatted -O -t -a _FillValue,,o,d,-9.99999979021476795361e+33 ${fl} |
| 304 |
# done |
| 305 |
# New MPAS filename conventions (as of ~201612): |
| 306 |
# ncclimo --vars=timeMonthly_avg_iceAreaCell --yr_srt=2 --yr_end=3 --mdl=mpasseaice --d2f --drc_in=/p/user_pub/work/E3SM/1_0/piControl/1deg_atm_60-30km_ocean/sea-ice/native/model-output/mon/ens1/v1 --map=${DATA}/maps/map_oEC60to30v3_to_cmip6_180x360_aave.20181001.nc --drc_out=${DATA}/ne30/clm --drc_rgr=${DATA}/ne30/rgr > ~/ncclimo.out 2>&1 & |
| 307 |
# ncclimo --vars=timeMonthly_avg_activeTracers_temperature --yr_srt=2 --yr_end=3 --mdl=mpaso --d2f --dpt_fl=${DATA}/grids/mpas_refBottomDepth_60lyr.nc --drc_in=/p/user_pub/work/E3SM/1_0/piControl/1deg_atm_60-30km_ocean/ocean/native/model-output/mon/ens1/v1 --map=${DATA}/maps/map_oEC60to30v3_to_cmip6_180x360_aave.20181001.nc --drc_out=${DATA}/ne30/clm --drc_rgr=${DATA}/ne30/rgr > ~/ncclimo.out 2>&1 & |
| 308 |
# Old MPAS filename conventions (until ~201609):: |
| 309 |
# ncclimo -v temperature -c hist -s 2 -e 3 -m ocn -i /gpfs/alpine/cli112/proj-shared/golaz/ACME_simulations/20160121.A_B2000ATMMOD.ne30_oEC.titan.a00/run -r ${DATA}/maps/map_oEC60to30_to_t62_bilin.20160301.nc -o ${DATA}/mpas/clm > ~/ncclimo.out 2>&1 & |
| 310 |
# ncclimo -v iceAreaCell -c hist -s 2 -e 3 -m ice -i /gpfs/alpine/cli112/proj-shared/golaz/ACME_simulations/20160121.A_B2000ATMMOD.ne30_oEC.titan.a00/run -r ${DATA}/maps/map_oEC60to30_to_t62_bilin.20160301.nc -o ${DATA}/mpas/clm > ~/ncclimo.out 2>&1 & |
| 311 |
# Split pipe: |
| 312 |
# cd ${DATA}/ne30/raw;ls *piControl*000[12]-??*.nc | ncclimo --split --dbg=1 -s 1 -e 2 --var=FSNT,AODVIS --drc_out=${DATA}/ne30/clm |
| 313 |
# Split redirection: |
| 314 |
# cd ${DATA}/ne30/raw;ls *piControl*000[12]-??*.nc > ~/foo;ncclimo --split --dbg=1 -s 1 -e 2 --var=FSNT,AODVIS --drc_out=${DATA}/ne30/clm < ~/foo |
| 315 |
# Split stdin switch: |
| 316 |
# cd ${DATA}/ne30/raw;ls *piControl*000[12]-??*.nc | ncclimo --split --dbg=1 --stdin -s 1 -e 2 --var=FSNT,AODVIS --drc_out=${DATA}/ne30/clm |
| 317 |
# Split positional arguments: |
| 318 |
# ncclimo --split --dbg=1 -s 1 -e 1 --var=FSNT,AODVIS,T --drc_out=${DATA}/ne30/clm ${DATA}/ne30/raw/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-??.nc |
| 319 |
# Split directory: |
| 320 |
# ncclimo --dbg=1 --ypf=50 -s 1 -e 2 --var=FSNT,AODVIS --drc_in=${DATA}/ne30/raw --drc_out=${DATA}/ne30/clm |
| 321 |
# Split global mean |
| 322 |
# cd ${DATA}/ne30/raw;ls 2018*000[12]-??*.nc | ncclimo --split --dbg=1 --rgn_avg -s 1 -e 2 --var=FSNT,AODVIS,TREFHT --drc_out=${DATA}/ne30/clm |
| 323 |
# Split global sum |
| 324 |
# ncclimo -P elm --split --rgn_stt=sum --sum_scl=1.0e6*3600*24*365/1.0e12 -v GPP -c v3.LR.piControl -s 460 -e 461 --var=GPP --drc_in=${DATA}/ne30/raw --drc_out=${DATA}/ne30/clm |
| 325 |
# Split all: |
| 326 |
# cd ${DATA}/ne30/raw;ls *piControl*000[12]-??*.nc | ncclimo --split --dbg=1 -s 1 -e 2 --drc_out=${DATA}/ne30/clm |
| 327 |
# Split ELM: |
| 328 |
# ncclimo --split --dbg=1 -s 2000 -e 2000 --var=FSDS,TBOT --drc_out=${DATA}/ne30/clm ${DATA}/ne30/raw/F_acmev03_enso_camse_clm45bgc_ne30_co2cycle.clm2.h0.2000-??.nc |
| 329 |
# Split vertical: |
| 330 |
# cd ${DATA}/ne30/raw;ls *piControl*000[12]-??*.nc | ncclimo --split --dbg=1 -s 1 -e 2 --var=T --vrt_out=${DATA}/grids/vrt_prs_ncep_L17.nc --drc_out=${DATA}/ne30/clm |
| 331 |
# cd ${DATA}/ne30/raw;ls *piControl*000[12]-??*.nc | ncclimo --split --dbg=1 -s 1 -e 2 --var=T --vrt_out=${DATA}/grids/vrt_prs_ncep_L17.nc --vrt_xtr=mss_val --drc_out=${DATA}/ne30/clm # Missing value interpolation |
| 332 |
# Split production: |
| 333 |
# cd /scratch2/scratchdirs/golaz/ACME_simulations/20161117.beta0.A_WCYCL1850S.ne30_oEC_ICG.edison/run;ls *cam.h0.000[1-9]* | ncclimo --split --dbg=1 --yr_srt=1 --yr_end=9 --var=FSNT,AODVIS,T --map=${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc --drc_out=${DATA}/ne30/clm > ~/ncclimo.out 2>&1 & |
| 334 |
# cd /scratch2/scratchdirs/golaz/ACME_simulations/20161117.beta0.A_WCYCL1850S.ne30_oEC_ICG.edison/run;ls *cam.h0.0[012]??* | ncclimo --split --dbg=1 --yr_srt=1 --yr_end=250 --var=FSNT,AODVIS,T --map=${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc --drc_out=${DATA}/ne30/clm > ~/ncclimo.out 2>&1 & |
| 335 |
# Daily pipe: |
| 336 |
# cd ${DATA}/ne30/raw;ls *h1*.nc | ncclimo --dbg=1 --job_nbr=8 --caseid=famipc5_ne30_v0.3_00007 --clm_md=dly -s 2001 -e 2002 --var=PRECT,TREFHT --drc_out=${DATA}/ne30/clm > ~/ncclimo.out 2>&1 & |
| 337 |
# Diurnal pipe: |
| 338 |
# cd ${DATA}/ne30/raw;ls *h4*.nc | ncclimo --dbg=1 --job_nbr=8 --caseid=famipc5_ne30_v0.3_00007 --clm_md=dly --tpd=8 -s 2001 -e 2002 --var=PRECT,TS,FSDS --drc_out=${DATA}/ne30/clm > ~/ncclimo.out 2>&1 & |
| 339 |
# SGS: |
| 340 |
# ncclimo -P elm -m clm2 -d 1 -v TBOT,FSDS -c essgcm14 -s 1 -e 1 -i ${DATA}/essgcm14 -o ${DATA}/ne30/rgr --map=${DATA}/maps/map_t42_to_fv129x256_aave.20150901.nc --sgs_frc=${DATA}/grids/clm2_landfrac_t42.nc/landfrac |
| 341 |
# ncclimo -P elm -m clm2 -d 1 -v TBOT,FSDS -c F_acmev03_enso_camse_clm45bgc_ne30_co2cycle -s 2000 -e 2000 -i ${DATA}/ne30/raw -o ${DATA}/ne30/rgr --map=${DATA}/maps/map_ne30np4_to_cmip6_180x360_aave.20181001.nc --sgs_frc=${DATA}/grids/elm_landfrac_ne30np4.nc/landfrac |
| 342 |
# ncclimo -P elm -d 1 -v TBOT,FSDS -c v2.LR.historical_0101 -s 2013 -e 2014 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -O ${DATA}/ne30/rgr --map=${DATA}/maps/map_ne30pg2_to_cmip6_180x360_nco.20200901.nc --sgs_frc=${DATA}/grids/elm_landfrac_ne30pg2.nc/landfrac |
| 343 |
# Seasons: |
| 344 |
# ncclimo -d 1 --csn_lst=mam,jja,son,djf,jfm,on -v FSNT -c 20180129.DECKv1b_piControl.ne30_oEC.edison -s 1 -e 2 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -r ${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc |
| 345 |
# ncclimo -d 1 --csn_lst=jfm,jas,ann -v FSNT -c 20180129.DECKv1b_piControl.ne30_oEC.edison -s 1 -e 2 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -r ${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc |
| 346 |
# Compy Jobs or MPI: |
| 347 |
# ncclimo -c 20180215.DECKv1b_H1.ne30_oEC.edison -s 2010 -e 2014 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -O ${DATA}/ne30/rgr -r ${DATA}/maps/map_ne30np4_to_cmip6_180x360_aave.20181001.nc # ne30 climo on 1 node in full-background (12 jobs) mode |
| 348 |
# ncclimo --jobs=3 -c 20180410.A_WCYCL1950_HR.ne120_oRRS18v3_ICG.theta -s 1 -e 5 -i ${DATA}/ne120/raw -o ${DATA}/ne120/clm -r ${DATA}/maps/map_ne120np4_to_cmip6_720x1440_aave.20181001.nc # ne120 climo on 1 node in background mode with 3-jobs (to stay under 192 GB RAM limit) |
| 349 |
# echo '#!/bin/bash' > ~/ncclimo.slurm |
| 350 |
# echo "ncclimo -p mpi -c 20180410.A_WCYCL1950_HR.ne120_oRRS18v3_ICG.theta -s 1 -e 5 -i ${DATA}/ne120/raw -o ${DATA}/ne120/clm -O ${DATA}/ne120/rgr -r ${DATA}/maps/map_ne120np4_to_cmip6_720x1440_aave.20181001.nc" >> ~/ncclimo.slurm;chmod a+x ~/ncclimo.slurm # ne120 climo on 4 nodes, MPI mode: |
| 351 |
# sbatch -A e3sm --nodes=4 --time=00:30:00 --job-name=ncclimo --mail-type=fail,end [email protected] --output=${HOME}/ncclimo.out ~/ncclimo.slurm |
| 352 |
|
| 353 |
# Best performance on resolutions finer than ne30 (~1x1 degree) requires a job scheduler/batch processor |
| 354 |
# SLURM (andes,chrysalis,compy,perlmutter), Maui (a PBS-variant) (blues), Torque (a PBS-variant) (hopper), and PBS Pro (improv,other) schedulers allow both interactive and non-interactive (i.e., script) batch jobs |
| 355 |
# ALCF PBSPro: |
| 356 |
# https://docs.lcrc.anl.gov/improv/running-jobs-improv |
| 357 |
# NCAR PBSPro: |
| 358 |
# https://arc.ucar.edu/knowledge_base/124518554 |
| 359 |
# https://www2.cisl.ucar.edu/resources/computational-systems/cheyenne/quick-start-cheyenne |
| 360 |
# NERSC SLURM: |
| 361 |
# https://slurm.schedmd.com/sbatch.html # sbatch man page |
| 362 |
# https://slurm.schedmd.com/salloc.html # salloc man page |
| 363 |
# OLCF SLURM (after 20190903, PBS until 20190903): |
| 364 |
# https://docs.olcf.ornl.gov/systems/andes_user_guide.html |
| 365 |
# https://docs.olcf.ornl.gov/systems/frontier_user_guide.html |
| 366 |
# Requesting interactive nodes, Submitting non-interactive batch jobs, Monitoring queues, Deleting jobs: |
| 367 |
# LSF: bsub -I, bsub,jobstat, qdel, jsrun |
| 368 |
# PBS: qsub -I, qsub, qstat, qdel, mpirun |
| 369 |
# PBSPro: qsub -I, qsub, qstat, qdel, mpirun |
| 370 |
# SLURM: salloc, sbatch, squeue, scancel, srun |
| 371 |
# Interactive queue: a) Reserve nodes and acquire prompt on control node b) Execute ncclimo command interactively |
| 372 |
# Andes: salloc -A CLI115 --nodes=1 --time=00:30:00 --job-name=ncclimo # Bigmem: --partition=gpu |
| 373 |
# Bebop: qsub -I -A E3SM -l select=1:ncpus=128:mpiprocs=128,walltime=00:10:00 -N ncclimo |
| 374 |
# Chrysalis: salloc -A e3sm --nodes=1 --partition=debug --time=00:30:00 --job-name=ncclimo # Use compute queue instead if debug is slow to grant resources |
| 375 |
# Compy: salloc -A e3sm --nodes=1 --time=00:30:00 --job-name=ncclimo |
| 376 |
# Derecho: qsub -I -A SCSG0002 -l select=1:ncpus=36:mpiprocs=1 -l walltime=00:30:00 -q regular -N ncclimo |
| 377 |
# Frontier:salloc -A CLI115 --nodes=1 --time=00:30:00 --job-name=ncclimo |
| 378 |
# Improv: qsub -I -A E3SM -l select=1:ncpus=128:mpiprocs=128,walltime=00:10:00 -q compute -N ncclimo |
| 379 |
# Perl: salloc -A e3sm --constraint=cpu --nodes=1 --partition=debug --time=00:30:00 --job-name=ncclimo # NB: 30 minute limit |
| 380 |
# Non-interactive batch procedure: a) Store ncclimo command in ncclimo.[pbs|slurm] b) qsub ncclimo.[pbs|slurm] |
| 381 |
# Non-interactive batch queue differences (besides argument syntax): |
| 382 |
# 1. SLURM requires initial 'shebang' line to specify the shell interpreter (not required on PBS) |
| 383 |
# 2. PBS overwrites existing files |
| 384 |
# 3. PBS (and PBSPro) use ${PBS_NODEFILE} and ${PBS_NUM_PPN}, respectively, and SLURM uses ${SLURM_NODELIST} and ${SLURM_CPUS_ON_NODE}, respectively |
| 385 |
# 4. SLURM automatically combines stdout and stderr, yet does not understand tilde (~ = home directory) expansion in error/output filenames |
| 386 |
# Differences 1 & 2 impose slightly different invocations; difference 3 requires abstracting environment variables; difference 4 requires omitting ~'s |
| 387 |
# Andes a): echo '#!/bin/bash' > ~/ncclimo.slurm |
| 388 |
# echo "ncclimo -a djf -d 1 -p mpi -c famipc5_ne120_v0.3_00003 -s 1 -e 2 -i ${DATA}/ne120/raw -o ${DATA}/ne120/clm -r ${DATA}/maps/map_ne120np4_to_fv257x512_aave.20150901.nc" >> ~/ncclimo.slurm;chmod a+x ~/ncclimo.slurm |
| 389 |
# Bebop a): echo "ncclimo -a djf -d 1 -p mpi -c 20180129.DECKv1b_piControl.ne30_oEC.edison -s 1 -e 2 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -r ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc" > ~/ncclimo.pbs;chmod a+x ~/ncclimo.pbs |
| 390 |
# Compy a): echo '#!/bin/bash' > ~/ncclimo.slurm |
| 391 |
# echo "ncclimo -d 1 -p mpi -c 20180215.DECKv1b_H1.ne30_oEC.edison -s 2010 -e 2010 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -r ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc" >> ~/ncclimo.slurm;chmod a+x ~/ncclimo.slurm |
| 392 |
# Derec a): echo "ncclimo -a djf -d 1 -p mpi -c 20180129.DECKv1b_piControl.ne30_oEC.edison -s 1 -e 2 -i ${DATA}/ne30/raw -o ${DATA}/ne30/clm -r ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc" > ~/ncclimo.pbs;chmod a+x ~/ncclimo.pbs |
| 393 |
# Front a): echo '#!/bin/bash' > ~/ncclimo.slurm |
| 394 |
# echo "ncclimo -a djf -d 1 -p mpi -c famipc5_ne120_v0.3_00003 -s 1 -e 2 -i ${DATA}/ne120/raw -o ${DATA}/ne120/clm -r ${DATA}/maps/map_ne120np4_to_fv257x512_aave.20150901.nc" >> ~/ncclimo.slurm;chmod a+x ~/ncclimo.slurm |
| 395 |
# Andes b): sbatch -A CLI115 --nodes=12 --time=00:30:00 --job-name=ncclimo --mail-type=fail,end [email protected] --output=${HOME}/ncclimo.out ~/ncclimo.slurm |
| 396 |
# Bebop b): qsub -A ACME -q acme -l nodes=1 -l walltime=00:30:00 -N ncclimo -j oe -m e -o ~/ncclimo.out ~/ncclimo.pbs |
| 397 |
# Compy b): sbatch -A e3sm --nodes=12 --time=00:30:00 --job-name=ncclimo --mail-type=fail,end [email protected] --output=${HOME}/ncclimo.out ~/ncclimo.slurm |
| 398 |
# Derec b): qsub -A SCSG0002 -l select=12:ncpus=36:mpiprocs=1 -l walltime=00:30:00 -q regular -N ncclimo -j oe -m e -o ~/ncclimo.out ~/ncclimo.pbs |
| 399 |
# Front b): sbatch -A CLI115 --nodes=12 --time=00:30:00 --job-name=ncclimo --mail-type=fail,end [email protected] --output=${HOME}/ncclimo.out ~/ncclimo.slurm |
| 400 |
# Perlm b): sbatch -A e3sm --constraint=cpu --nodes=12 --time=00:30:00 --qos=debug --job-name=ncclimo --mail-type=fail,end [email protected] --output=${HOME}/ncclimo.out ~/ncclimo.slurm |
| 401 |
# NB: stdout/stderr files returned from batch jobs are read-protected, need 'chmod 644 ~/ncclimo.out' afterwards |
| 402 |
|
| 403 |
# Normal use: Set five "mandatory" inputs (caseid, yr_srt, yr_end, drc_in, drc_out), and possibly rgr_map, on command line |
| 404 |
# caseid: Simulation name (filenames must start with ${caseid}) |
| 405 |
# drc_in: Input directory for raw data |
| 406 |
# Years outside yr_srt and yr_end are ignored |
| 407 |
# yr_srt should, and for JFD mode must, contain complete year of output |
| 408 |
# DJF mode ignores Jan-Nov of yr_srt |
| 409 |
# Dec of yr_end is excluded from the seasonal and monthly analysis in DJF mode |
| 410 |
# yr_end should, and for JFD mode must, contain complete year of output |
| 411 |
# drc_out: Output directory for processed native grid climatology ("climo files") |
| 412 |
# User needs write permission for ${drc_out} |
| 413 |
# rgr_map: Horizontal regridding map, if non-NULL, invoke regridder with specified map on output datasets |
| 414 |
# Pass options intended exclusively for the NCO regridder as arguments to the -R switch |
| 415 |
# yr_srt: Year of first January to analyze |
| 416 |
# yr_end: Year of last January to analyze |
| 417 |
|
| 418 |
# Other options (often their default settings work well): |
| 419 |
# wnt_md: wnd_md was dropped on 20260325 (NCO 5.3.7) and is no longer supported |
| 420 |
# The same functionality is now accessed by starting climos in December |
| 421 |
# The following wnt_md documentation is retained for forensic purposes: |
| 422 |
# Winter mode aka December mode, i.e., how to treat December in (NH) Winter seasons. One of two options: |
| 423 |
# Seasonally-contiguous-december (SCD or DJF) mode (wnt_md=scd|djf) (default through 4.9.4) |
| 424 |
# Seasonally-discontiguous-december (SDD or JFD) mode (wnt_md=sdd|jfd) (default starting 4.9.5) |
| 425 |
# Both modes use an integral multiple of 12 months, and _never alter any input files_ |
| 426 |
# DJF climatologies begin in Dec of yr_srt-1, and end in Nov of yr_end |
| 427 |
# JFD climatologies begin in Jan of yr_srt, and end in Dec of yr_end |
| 428 |
# DJF excludes Jan-Nov of yr_srt-1 and Dec of yr_end (i.e., DJF excludes 12 months of available data) |
| 429 |
# JFD uses all months of yr_srt through yr_end (i.e., JFD can use all available data) |
| 430 |
# DJF seasonal averages are inconsistent with (calendar-year-based) annual averages, but better capture seasonal the "natural" (not calendar-year-based) climate year |
| 431 |
# JFD seasonal averages are fully consistent with (calendar-year-based) annual averages |
| 432 |
# drc_rgr: Regridding directory---store regridded files, if any, in drc_rgr rather than drc_out |
| 433 |
# lnk_flg: Link E3SM-climo to AMWG-climo filenames |
| 434 |
# AMWG omits the YYYYMM components of climo filenames, resulting in shorter names |
| 435 |
# This switch (on by default) symbolically links the full (E3SM) filename to the shorter (AMWG) name |
| 436 |
# AMWG diagnostics scripts can produce plots directly from these linked filenames |
| 437 |
# par_typ: Parallelism type for files |
| 438 |
# bck = Background: Spawn children (basic blocks) as background processes on control node then wait() |
| 439 |
# Works best when available RAM > 12*4*sizeof(monthly input file), otherwise jobs swap-to-disk |
| 440 |
# mpi = MPI: Spawn children (basic blocks) as MPI processes (one per node in batch environment) then wait() |
| 441 |
# Requires batch system with PBS and MPI. Use when available RAM/node < 12*2.5*sizeof(monthly input file). |
| 442 |
# Optimized for batch with 12 nodes. Factors thereof (6, 4, 3, 2 nodes) should also work. |
| 443 |
# Remember to request 12 nodes if possible! |
| 444 |
# srl = Serial: Execute script in serial mode on single node |
| 445 |
# Works best when available RAM < 12*4*sizeof(monthly input file), otherwise jobs swap-to-disk |
| 446 |
# var_lst: Variables to include, or, with nco_opt='-x', to exclude, in comma-separated list format, e.g., |
| 447 |
# 'FSNT,AODVIS'. Regular expressions work, too: 'AOD.?' |
| 448 |
|
| 449 |
# Infrequently used options: |
| 450 |
# dbg_lvl: 0 = Quiet, print basic status during evaluation |
| 451 |
# 1 = Print configuration, full commands, and status to output during evaluation |
| 452 |
# 2 = As in dbg_lvl=1, but do not evaluate commands |
| 453 |
# 3 = As in dbg_lvl=2, with additional information (mainly for batch queues) |
| 454 |
# fml_nm: Family name (nickname) of output files referring to $fml_nm character sequence used in output climo file names: |
| 455 |
# fml_nm_XX_YYYYMM_YYYYMM.nc (examples include '' (default), 'control', 'experiment') |
| 456 |
# By default, fml_nm=$caseid. Use fml_nm instead of $caseid to simplify long names, avoid overlap, etc. |
| 457 |
# hst_nm: History volume name string, i.e., $hst_nm character sequence used in history tape names: |
| 458 |
# caseid.mdl_nm.hst_nm.YYYY-MM.nc (examples include 'h0' (default, works for cam, clm), 'h1', 'h' (for cism), 'hist' (for mpasocean, mpasseaice) |
| 459 |
# mdl_nm: Model name string in output filenames, i.e., character sequence $mdl_nm in standard names: |
| 460 |
# caseid.mdl_nm.h0.YYYY-MM.nc (examples include 'cam' (default), 'clm2', 'cam2', 'cice', 'cism', 'eam', 'elm', 'mosart', 'mpasocean', 'mpaso', 'mpasseaice', 'mpassi', 'pop') |
| 461 |
# nco_opt: String of options to pass-through to NCO, e.g., |
| 462 |
# '-D 2 -7 -L 1' for NCO debugging level 2, netCDF4-classic output, compression level 1 |
| 463 |
# '--no_tmp_fl -x' to skip temporary files, turn extraction into exclusion list |
| 464 |
# rgr_opt: String of options (besides thread-number) to pass-through exclusively to NCO regridder, e.g., |
| 465 |
# ncclimo -m clm2 ... -R col_nm=lndgrid -r map.nc ... |
| 466 |
# thr_nbr: Thread number to use in NCO regridder, '-t 1' for one thread, '-t 2' for two threads... |
| 467 |
|
| 468 |
# 20220131 ncclimo/ncremap commands within scripts that open E3SMU environment |
| 469 |
# (e.g., zppy-generated scripts) must be told where to find NCO binaries. |
| 470 |
# Only necessary on login nodes since Spack handles this fine on compute nodes |
| 471 |
if [ "${E3SMU_MPI}" = 'NOMPI' ] && [ -n "${E3SMU_SCRIPT}" ] && [ -n "${CONDA_PREFIX}" ]; then |
| 472 |
export PATH="${CONDA_PREFIX}/bin"\:${PATH} |
| 473 |
fi # !E3SMU_MPI |
| 474 |
# Set NCO version and directory |
| 475 |
nco_exe=`which ncks` |
| 476 |
if [ -z "${nco_exe}" ]; then |
| 477 |
echo "${spt_nm}: ERROR Unable to find NCO, \${nco_exe} = ${nco_exe}" |
| 478 |
echo "${spt_nm}: HINT Carefully examine your environment setup (e.g., .bashrc) to avoid inadvertently overriding (with, e.g., conda-initialization) paths intended to be provided by an analysis-package environment (e.g., E3SM-Unified)" |
| 479 |
exit 1 |
| 480 |
fi # !nco_exe |
| 481 |
# StackOverflow method finds NCO directory |
| 482 |
while [ -h "${nco_exe}" ]; do |
| 483 |
drc_nco="$( cd -P "$( dirname "${nco_exe}" )" && pwd )" |
| 484 |
nco_exe="$(readlink "${nco_exe}")" |
| 485 |
[[ ${nco_exe} != /* ]] && nco_exe="${drc_nco}/${nco_exe}" |
| 486 |
done |
| 487 |
drc_nco="$( cd -P "$( dirname "${nco_exe}" )" && pwd )" |
| 488 |
nco_vrs=$(ncks --version 2>&1 > /dev/null | grep NCO | awk '{print $5}') |
| 489 |
# 20190218: Die quickly when NCO is found yet cannot run, e.g., due to linker errors |
| 490 |
if [ -z "${nco_vrs}" ]; then |
| 491 |
echo "${spt_nm}: ERROR ${nco_exe} dies with error message on next line:" |
| 492 |
$(ncks --version) |
| 493 |
# 20250905: Additional information for debugging link issues |
| 494 |
if [ "${NCO_PATH_OVERRIDE}" = 'Yes' ]; then |
| 495 |
echo "${spt_nm}: DEBUG Next line shows contents of \$LD_LIBRARY_PATH:" |
| 496 |
echo "${LD_LIBRARY_PATH}" |
| 497 |
echo "${spt_nm}: DEBUG Next line shows contents of \$PATH:" |
| 498 |
echo "${PATH}" |
| 499 |
else # !NCO_PATH_OVERRIDE |
| 500 |
printf "HINT: Run-time error due to link issues (e.g., libraries missing or not found) might be solved at supported national labs (ALCF, NCAR, NERSC, OLCF, PNNL) by employing machine-dependent hardcoded paths/modules. To try this, re-run command with \"--npo\" as first option, i.e., \"${spt_src} --npo ...\" or after setting \"export NCO_PATH_OVERRIDE=Yes\".\n" |
| 501 |
fi # !NCO_PATH_OVERRIDE |
| 502 |
exit 1 |
| 503 |
fi # !nco_vrs |
| 504 |
nco_sng=$(ncks --version 2>&1 > /dev/null | grep NCO | awk -F '"' '{print $2}') |
| 505 |
lbr_vrs=$(ncks --library 2>&1 > /dev/null | awk '{print $6}') |
| 506 |
|
| 507 |
# Detect and warn about mixed modules (for Qi Tang 20170531) |
| 508 |
if [ "${drc_spt}" != "${drc_nco}" ]; then |
| 509 |
echo "INFO: Mixture of NCO scripts and binaries from different locations. Script ${spt_nm} is from directory ${drc_spt} while NCO binaries are from directory ${drc_nco}. Normally this script and the binaries are from the same executables directory. This INFO may be safely ignored for customized scripts and/or binaries that the user has intentionally split into different directories." |
| 510 |
echo "HINT (All-users): Conflicting script and binary directories may result from 1) Hardcoding an NCO script and/or binary pathnames, 2) Incomplete NCO installations in one or more directories in the \$PATH environment variable, 3) (Re-)Installing or (re-)building NCO without issuing a \"hash -r\" command afterward to update the executable pathnames that the shell remembers from before." |
| 511 |
echo "HINT (E3SM-only): In a Conda-based NCO environment, such as E3SM-Unified (which uses NCO in MPAS Analysis and E3SM-Diags), it is possible that some features may be unavailable because the upstream packages (e.g., UDUnits) were not properly linked by Conda. The ncclimo and ncremap scripts contain a mechanism to access the (presumably correctly linked) NCO binary executable and library paths in C. Zender's home directories on the major E3SM machines. Users may turn-on the machine-dependent, hard-coded path by invoking ncclimo and/or ncremap after altering their environment with: \"export NCO_PATH_OVERRIDE=Yes\"." |
| 512 |
fi # drc_spt |
| 513 |
|
| 514 |
# When running in a terminal window (not in an non-interactive batch queue)... |
| 515 |
if [ -n "${TERM}" ]; then |
| 516 |
# Set fonts for legibility |
| 517 |
if [ -x /usr/bin/tput ] && tput setaf 1 &> /dev/null; then |
| 518 |
fnt_bld=`tput bold` # Bold |
| 519 |
fnt_nrm=`tput sgr0` # Normal |
| 520 |
fnt_rvr=`tput smso` # Reverse |
| 521 |
fnt_tlc=`tput sitm` # Italic |
| 522 |
else |
| 523 |
fnt_bld="\e[1m" # Bold |
| 524 |
fnt_nrm="\e[0m" # Normal |
| 525 |
fnt_rvr="\e[07m" # Reverse |
| 526 |
fnt_tlc="\e[3m" # Italic |
| 527 |
fi # !tput |
| 528 |
fi # !TERM |
| 529 |
|
| 530 |
# Pre-define enumerated types used in defaults |
| 531 |
par_bck='background' # [sng] Parallelism: background |
| 532 |
par_mpi='mpi' # [sng] Parallelism: MPI |
| 533 |
par_srl='serial' # [sng] Parallelism: serial |
| 534 |
rtn_yyyy_frs=1 # [enm] Key for csn_nfo_get() to echo yyyy_frs |
| 535 |
rtn_yyyy_lst=2 # [enm] Key for csn_nfo_get() to echo yyyy_lst |
| 536 |
rtn_yyyymm_frs=3 # [enm] Key for csn_nfo_get() to echo yyyymm_frs |
| 537 |
rtn_yyyymm_lst=4 # [enm] Key for csn_nfo_get() to echo yyyymm_lst |
| 538 |
rtn_yyyymm_rng=5 # [enm] Key for csn_nfo_get() to echo yyyymm_rng |
| 539 |
rtn_clm_bnd_arg=6 # [enm] Key for csn_nfo_get() to echo clm_bnd_arg |
| 540 |
rtn_yyyy_rng=7 # [enm] Key for csn_nfo_get() to echo yyyy_rng |
| 541 |
|
| 542 |
# Defaults for command-line options and some derived variables |
| 543 |
# Modify these defaults to save typing later |
| 544 |
ann_sfx='01-01-00000' # [sng] Annual file suffix (MPAS, e.g., uses '01-01-00000') |
| 545 |
area_nm='area' # [sng] Name of variable containing gridcell area |
| 546 |
bch_pbs='No' # [sng] PBS batch (non-interactive) job |
| 547 |
bch_slr='No' # [sng] SLURM batch (non-interactive) job |
| 548 |
bfr_sz=33554432 # [B] Buffer size for netCDF-classic I/O (ignored and harmless for netCDF4) |
| 549 |
bnr_flg='No' # [sng] Binary method |
| 550 |
caseid='' # [sng] Case ID |
| 551 |
#caseid_xmp='20180129.DECKv1b_piControl.ne30_oEC.edison' # [sng] Case ID for v1 examples |
| 552 |
caseid_xmp='v2.LR.historical_0101' # [sng] Case ID for v2 examples |
| 553 |
caseid_xmp_eamxx='output.scream.decadal.monthlyAVG_ne30pg2.AVERAGE.nmonths_x1' # [sng] Case ID for EAMXX examples |
| 554 |
cf_flg='Yes' # [sng] Produce CF climatology attribute? |
| 555 |
clm_flg='Yes' # [sng] Generate climatology |
| 556 |
clm_hfc_or_mth='No' # [sng] Generate monthly output climatology from monthly or HFC input |
| 557 |
clm_md='mth' # [sng] Climatology mode ('ann', 'dly', 'hfc', 'hfs', or 'mth') |
| 558 |
cmp_sng='' # [sng] Compression string |
| 559 |
csn_flg='No' # [flg] Trigger season-processing code |
| 560 |
csn_lst='mam,jja,son,djf' # [sng] Seasons to output (subset of mam,jja,son,djf,jfm,amj,jas,ond,fm,on) |
| 561 |
d2f_flg='No' # [flg] Convert double-precision fields to single-precision |
| 562 |
d2f_opt='--d2f' # [sng] Option string to convert double-precision fields to single-precision |
| 563 |
dpt_fl='' # [sng] Depth file with refBottomDepth for MPAS ocean |
| 564 |
dpt_opt='' # [sng] Option string to add depth coordinate to regridded MPAS files |
| 565 |
dbg_lvl=0 # [nbr] Debugging level |
| 566 |
dfl_lvl='' # [enm] Deflate level |
| 567 |
drc_in='' # [sng] Input file directory |
| 568 |
drc_in_xmp="${DATA}/ne30/raw" # [sng] Input file directory for examples |
| 569 |
drc_in_mps="${DATA}/mpas/raw" # [sng] Input file directory for MPAS examples |
| 570 |
drc_out="${drc_pwd}" # [sng] Output file directory |
| 571 |
drc_out_xmp="${DATA}/ne30/clm" # [sng] Output file directory for examples |
| 572 |
drc_out_mps="${DATA}/mpas/clm" # [sng] Output file directory for MPAS examples |
| 573 |
drc_prv='' # [sng] Directory containing previous climatology to extend with current data |
| 574 |
drc_rgr='' # [sng] Regridded file directory |
| 575 |
drc_rgr_prv='' # [sng] Regridded file directory for previous climatology |
| 576 |
drc_rgr_xmp="${DATA}/ne30/rgr" # [sng] Regrid file directory for examples |
| 577 |
drc_rgr_xtn='' # [sng] Regridded file directory for for extended climatology |
| 578 |
drc_xtn='' # [sng] Directory containing extended climatology |
| 579 |
dpy=365 # [nbr] Days-per-year (noleap calendar) |
| 580 |
fl_fmt='' # [enm] Output file format |
| 581 |
fl_nbr=0 # [nbr] Number of files to split |
| 582 |
fl_rmd=0 # [nbr] Number of files/months beyond an integral number of years |
| 583 |
fml_nm='' # [sng] Family name (i.e., nickname, e.g., 'amip', 'control', 'experiment') |
| 584 |
gaa_sng_std="--gaa climo_script=${spt_nm} --gaa climo_command=\"'${cmd_ln}'\" --gaa climo_hostname=${HOSTNAME} --gaa climo_version=${nco_vrs}" # [sng] Global attributes to add to climos |
| 585 |
#gaa_sng_tms="--gaa climo_script=${spt_nm} --gaa climo_hostname=${HOSTNAME} --gaa climo_version=${nco_vrs}" # [sng] Global attributes to add to timeseries |
| 586 |
gaa_sng_tms='' # [sng] Global attributes to add to timeseries |
| 587 |
hdr_pad='10000' # [B] Pad at end of header section |
| 588 |
hrz_dmn='ncol' # [sng] Name of horizontal dimension(s) (e.g., 'lndgrid' and comma-separated if 2-D, e.g. 'lat,lon') |
| 589 |
hst_nm='h0' # [sng] History volume (e.g., 'h0', 'h1', 'h') |
| 590 |
inp_aut='No' # [sng] Input file list automatically generated |
| 591 |
inp_glb='No' # [sng] Input file list from globbing directory |
| 592 |
inp_psn='No' # [sng] Input file list from positional arguments |
| 593 |
inp_std='No' # [sng] Input file list from stdin |
| 594 |
job_nbr=12 # [nbr] Job simultaneity for parallelism |
| 595 |
job_nbr_wrn=150 # [nbr] Maximum number of simultaneous jobs before WARNING is printed |
| 596 |
lat_nm='lat' # [sng] Latitude variable name (e.g., 'lat') |
| 597 |
lnk_flg='No' # [sng] Link E3SM-climo to AMWG-climo filenames |
| 598 |
map_opt='' # [sng] Map-file options (e.g., '--map=map.nc') |
| 599 |
mdl_nm='eam' # [sng] Model name string in history output (e.g., 'cam', 'cam2', 'cice', 'cism', 'clm', 'clm2', 'eam', 'elm', 'mali', 'mosart', 'mpascice', 'mpasseaice', 'mpassi', 'mpaso', 'mpasocean') |
| 600 |
mdl_nm_usr='' # [sng] Model name string in history output (e.g., 'cam', 'cam2', 'cice', 'cism', 'clm', 'clm2', 'eam', 'elm', 'mali', 'mosart', 'mpascice', 'mpasseaice', 'mpassi', 'mpaso', 'mpasocean') |
| 601 |
mdl_typ='cesm' # [sng] Model type ('cesm', 'mpas') (for regridding) |
| 602 |
mem_mb=0 # [MB] Megabytes of RAM per srun job in Cori SLURM in MPI mode (0 indicates unlimited RAM) |
| 603 |
mpi_flg='No' # [sng] Parallelize over nodes |
| 604 |
mth_end='12' # [yr] End month |
| 605 |
mth_flg='No' # [flg] Timeseries is not from Jan->Dec |
| 606 |
mth_srt='1' # [yr] Start month |
| 607 |
nco_opt='--no_tmp_fl' # [sng] NCO options (e.g., '-7 -D 1 -L 1') |
| 608 |
ncr_flg='No' # [sng] Incremental method |
| 609 |
nd_nbr=1 # [nbr] Number of nodes |
| 610 |
nm_typ='cesm' # [sng] Name type ('cesm', 'mpas', 'yyyymm', 'yyyy-mm', 'yyyy-mm-01', 'yyyy-mm-01-00000') (for filenames) |
| 611 |
no_ntv_tms='No' # [flg] Omit native-grid split timeseries |
| 612 |
par_opt='' # [sng] Parallel options to shell |
| 613 |
par_typ="${par_bck}" # [sng] Parallelism type for files |
| 614 |
prc_typ='' # [sng] Procedure type (e.g., 'cam', 'cam2', 'cice', 'cism', 'clm', 'clm2', 'cpl', 'eam', 'eamxx', 'elm', 'mali', 'mosart', 'mpas', 'mpasa', 'mpasatmosphere', 'mpaso', 'mpasocean', 'mpascice', 'mpasseaice', 'mpassi') |
| 615 |
qnt_prc='' # [nbr] Quantization precision |
| 616 |
rgn_avg='No' # [sng] Regional/global average timeseries |
| 617 |
rgn_stt='No' # [sng] Regional/global statistics |
| 618 |
rgr_map='' # [sng] Regridding (horizontal) map |
| 619 |
rgr_opt='' # [sng] Regridding options (e.g., '--rgr col_nm=lndgrid', '--rgr col_nm=nCells') |
| 620 |
spl_opt='' # [sng] Splitter options (non-MPAS only) (e.g., '--no_cll_msr') |
| 621 |
spl_rgr_opt='--no_stagger' # [sng] Splitter regridding options |
| 622 |
sgs_frc='' # [sng] Sub-grid fraction variable |
| 623 |
std_chk='Yes' # [sng] Check stdin for input file list |
| 624 |
sum_scl='1.0f' # Factor to convert area, time units ([sr], [km2], [s]) to desired units (e.g., [m2], [yr]) in sums |
| 625 |
thr_nbr=2 # [nbr] Thread number for regridder |
| 626 |
tm_bnd_flg='Yes' # [sng] Time coordinate contains valid bounds variable |
| 627 |
tms_flg='No' # [sng] Split (subset into timeseries) climatologies |
| 628 |
tpd_out=1 # [nbr] Timesteps-per-day in output |
| 629 |
#var_lst='FSNT,AODVIS' # [sng] Variables to process (empty means all) |
| 630 |
var_lst='' # [sng] Variables to process (empty means all) |
| 631 |
var_xtr='' # [sng] Extra variables for splitter timeseries |
| 632 |
vrs_prn='No' # [sng] Print version information |
| 633 |
vrt_out='' # [sng] Vertical grid file for output |
| 634 |
vrt_opt='' # [sng] Vertical interpolation options (e.g., '--vrt_out=vrt_grd.nc') |
| 635 |
vrt_xtr='' # [sng] Vertical extrapolation type (mss_val|nrs_ngh) |
| 636 |
xcl_flg='No' # [sng] Exclude rather than extract variable list |
| 637 |
xtn_flg='No' # [sng] Produce extended climatology |
| 638 |
ypf_max=50 # [yr] Years-per-output-file |
| 639 |
yr_end='2' # [yr] End year |
| 640 |
yr_srt='1' # [yr] Start year |
| 641 |
|
| 642 |
function fnc_usg_prn { # NB: dash supports fnc_nm (){} syntax, not function fnc_nm{} syntax |
| 643 |
# Print usage |
| 644 |
printf "${fnt_rvr}Basic usage:\n${fnt_nrm}${fnt_bld}${spt_nm} -c caseid -s yr_srt -e yr_end -i drc_in -o drc_out -r rgr_map${fnt_nrm} # Generate & regrid climatology\n" |
| 645 |
printf "${fnt_bld}${spt_nm} --split -v var_lst -s yr_srt -e yr_end -o drc_out -r rgr_map in1.nc in2.nc ... inN.nc${fnt_nrm} # Split, reshape, & regrid timeseries\n" |
| 646 |
printf "${fnt_bld}${spt_nm} --case=caseid --start=yr_srt --end=yr_end --input=drc_in --output=drc_out --map=rgr_map${fnt_nrm} # Long options (NB: '=' is REQUIRED)\n\n" |
| 647 |
echo "Command-line options [long-option synonyms in ${fnt_tlc}italics${fnt_nrm}]:" |
| 648 |
echo "${fnt_rvr}-3${fnt_nrm} Output file format CLASSIC (netCDF3 classic CDF1) [${fnt_tlc}fl_fmt, file_format=classic${fnt_nrm}]" |
| 649 |
echo "${fnt_rvr}-4${fnt_nrm} Output file format NETCDF4 (netCDF4 extended HDF5) [${fnt_tlc}fl_fmt, file_format=netcdf4${fnt_nrm}]" |
| 650 |
echo "${fnt_rvr}-5${fnt_nrm} Output file format 64BIT_DATA (netCDF3/PnetCDF CDF5) [${fnt_tlc}fl_fmt, file_format=64bit_data${fnt_nrm}]" |
| 651 |
echo "${fnt_rvr}-6${fnt_nrm} Output file format 64BIT_OFFSET (netCDF3 64bit CDF2) [${fnt_tlc}fl_fmt, file_format=64bit_offset${fnt_nrm}]" |
| 652 |
echo "${fnt_rvr}-7${fnt_nrm} Output file format NETCDF4_CLASSIC (netCDF4 classic HDF5) [${fnt_tlc}fl_fmt, file_format=netcdf4_classic${fnt_nrm}]" |
| 653 |
# echo "${fnt_rvr}-a${fnt_nrm} ${fnt_bld}wnt_md${fnt_nrm} Winter mode (default ${fnt_bld}${wnt_md}${fnt_nrm}) [${fnt_tlc}wnt_md, dcm_md, dec_md, december_mode, winter_mode${fnt_nrm}] [${fnt_tlc}scd,djf | sdd,jfd${fnt_nrm}]" # wnt_md discontinued in 202603 |
| 654 |
echo " ${fnt_bld}--amwg_lnk${fnt_nrm} Link E3SM-climo to AMWG-climo filenames [${fnt_tlc}amwg_links, AMWG_link${fnt_nrm}]" |
| 655 |
echo " ${fnt_bld}--area_nm${fnt_nrm} Area-variable name (default ${fnt_bld}${area_nm}${fnt_nrm}) [${fnt_tlc}area_nm, area_name, area${fnt_nrm}]" |
| 656 |
echo " ${fnt_bld}--bfr_sz${fnt_nrm} Buffer size for netCDF-classic I/O (default ${fnt_bld}determined by system/library${fnt_nrm}) [${fnt_tlc}bfr_sz, buffer_size_hint${fnt_nrm}]" |
| 657 |
echo "${fnt_rvr}-C${fnt_nrm} ${fnt_bld}clm_md${fnt_nrm} Climatology mode (default ${fnt_bld}${clm_md}${fnt_nrm}) [${fnt_tlc}clm_md, climatology_mode, climo_mode${fnt_nrm}] [${fnt_tlc}ann | dly | hfc | hfs | mth${fnt_nrm}]" |
| 658 |
echo "${fnt_rvr}-c${fnt_nrm} ${fnt_bld}caseid${fnt_nrm} Case ID string to generate input names or to name HFC output (default ${fnt_bld}${caseid}${fnt_nrm}) [${fnt_tlc}caseid, case_id, case${fnt_nrm}]" |
| 659 |
echo " ${fnt_bld}--cmp_sng${fnt_nrm} Compression string (empty means none) (default ${fnt_bld}${cmp_sng}${fnt_nrm}) [${fnt_tlc}cmp, cmp_sng, compress, compression, cpr, cdc, codec ${fnt_nrm}]" |
| 660 |
echo "${fnt_rvr}-d${fnt_nrm} ${fnt_bld}dbg_lvl${fnt_nrm} Debug level (default ${fnt_bld}${dbg_lvl}${fnt_nrm}) [${fnt_tlc}dbg_lvl, dbg, debug, debug_level${fnt_nrm}]" |
| 661 |
echo " ${fnt_bld}--d2f${fnt_nrm} Convert double-precision fields to single-precision (default ${fnt_bld}${d2f_flg}${fnt_nrm}) [${fnt_tlc}d2f | d2s | dbl_flt | dbl_sgl | double_float${fnt_nrm}]" |
| 662 |
echo " ${fnt_bld}--dpf${fnt_nrm} Days-per-file in every high-frequency splitter input file [${fnt_tlc}dpf, days_per_file${fnt_nrm}]" |
| 663 |
echo " ${fnt_bld}--dpt_fl${fnt_nrm} Depth file with refBottomDepth for MPAS ocean (empty means none) (default ${fnt_bld}${dpt_fl}${fnt_nrm}) [${fnt_tlc}dpt_fl, mpas_fl, mpas_depth, depth_file${fnt_nrm}]" |
| 664 |
echo "${fnt_rvr}-E${fnt_nrm} ${fnt_bld}yr_end${fnt_nrm} End year previous climo (empty means none) (default ${fnt_bld}${yr_end_prv}${fnt_nrm}) [${fnt_tlc}yr_end_prv, prv_yr_end, previous_end${fnt_nrm}]" |
| 665 |
echo "${fnt_rvr}-e${fnt_nrm} ${fnt_bld}yr_end${fnt_nrm} End year (default ${fnt_bld}${yr_end}${fnt_nrm}) [${fnt_tlc}yr_end, end_yr, year_end, end_year, end${fnt_nrm}]" |
| 666 |
echo "${fnt_rvr}-f${fnt_nrm} ${fnt_bld}fml_nm${fnt_nrm} Family name (nickname) (empty means none) (default ${fnt_bld}${fml_nm}${fnt_nrm}) [${fnt_tlc}fml_nm, fml, family_name${fnt_nrm}]" |
| 667 |
echo " ${fnt_bld}--fl_fmt${fnt_nrm} File format (empty is inherited from input) (default ${fnt_bld}${fl_fmt}${fnt_nrm}) [${fnt_tlc}fl_fmt, fmt_out, file_format, format_out${fnt_nrm}]" |
| 668 |
echo "${fnt_rvr}-h${fnt_nrm} ${fnt_bld}hst_nm${fnt_nrm} History volume name (default ${fnt_bld}${hst_nm}${fnt_nrm}) [${fnt_tlc}hst_nm, history_name, history${fnt_nrm}]" |
| 669 |
echo " ${fnt_bld}--hrd_pth${fnt_nrm} Use CSZ's hard-coded paths on known machines (e.g., chrysalis, compy, perlmutter) NB: Must be first option! [${fnt_tlc}hrd_pth, hard_path, npo, nco_path_override${fnt_nrm}]" |
| 670 |
echo "${fnt_rvr}-i${fnt_nrm} ${fnt_bld}drc_in${fnt_nrm} Input directory (default ${fnt_bld}${drc_in}${fnt_nrm}) [${fnt_tlc}drc_in, in_drc, dir_in, in_dir, input${fnt_nrm}]" |
| 671 |
echo "${fnt_rvr}-j${fnt_nrm} ${fnt_bld}job_nbr${fnt_nrm} Job simultaneity for parallelism (default ${fnt_bld}${job_nbr}${fnt_nrm}) [${fnt_tlc}job_nbr, job_number, jobs${fnt_nrm}]" |
| 672 |
echo "${fnt_rvr}-L${fnt_nrm} ${fnt_bld}dfl_lvl${fnt_nrm} Deflate level (empty is none) (default ${fnt_bld}${dfl_lvl}${fnt_nrm}) [${fnt_tlc}dfl_lvl, dfl, deflate${fnt_nrm}]" |
| 673 |
echo "${fnt_rvr}-l${fnt_nrm} ${fnt_bld}lnk_flg${fnt_nrm} Link E3SM-climo to AMWG-climo filenames (default ${fnt_bld}${lnk_flg}${fnt_nrm}) [${fnt_tlc}lnk_flg, link_flag${fnt_nrm}]" |
| 674 |
echo "${fnt_rvr}-m${fnt_nrm} ${fnt_bld}mdl_nm${fnt_nrm} Model name string in output filenames (default ${fnt_bld}${mdl_nm}${fnt_nrm}) [${fnt_tlc}mdl_nm, mdl, model_name, model${fnt_nrm}]" |
| 675 |
echo " ${fnt_bld}--mth_end${fnt_nrm} End month (default ${fnt_bld}${mth_end}${fnt_nrm}) [${fnt_tlc}mth_end, end_mth, month_end, end_month${fnt_nrm}]" |
| 676 |
echo " ${fnt_bld}--mth_srt${fnt_nrm} Start month (default ${fnt_bld}${mth_srt}${fnt_nrm}) [${fnt_tlc}mth_srt, start_mth, month_start, start_month${fnt_nrm}]" |
| 677 |
echo "${fnt_rvr}-n${fnt_nrm} ${fnt_bld}nco_opt${fnt_nrm} NCO options (empty means none) (default ${fnt_bld}${nco_opt}${fnt_nrm}) [${fnt_tlc}nco_opt, nco, nco_options${fnt_nrm}]" |
| 678 |
echo " ${fnt_bld}--no_lnk${fnt_nrm} Do not link E3SM-climo to AMWG-climo filenames [${fnt_tlc}no_links, no_amwg_links, no_amwg, no_AMWG_link${fnt_nrm}]" |
| 679 |
echo " ${fnt_bld}--no_cll_msr${fnt_nrm} Omit cell_measures variables (e.g., 'area') [${fnt_tlc}no_area, no_cll_msr, no_cell_measures${fnt_nrm}]" |
| 680 |
echo " ${fnt_bld}--no_frm_trm${fnt_nrm} Omit formula_terms variables (e.g., 'hyba', 'PS') [${fnt_tlc}no_frm_trm, no_frm, no_formula_terms${fnt_nrm}]" |
| 681 |
echo " ${fnt_bld}--no_ntv_tms${fnt_nrm} Omit native-grid timeseries (splitter only) [${fnt_tlc}no_ntv_tms, no_ntv, no_native${fnt_nrm}]" |
| 682 |
echo " ${fnt_bld}--no_stg_grd${fnt_nrm} Omit staggered grid variables ('slat, slon, w_stag') [${fnt_tlc}no_stg_grd, no_stg, no_stagger, no_staggered_grid${fnt_nrm}]" |
| 683 |
echo " ${fnt_bld}--no_stdin${fnt_nrm} Do not check stdin for input file list [${fnt_tlc}no_stdin, no_inp_std, no_redirect, no_standard_input${fnt_nrm}]" |
| 684 |
echo "${fnt_rvr}-O${fnt_nrm} ${fnt_bld}drc_rgr${fnt_nrm} Regridded directory (default ${fnt_bld}${drc_rgr}${fnt_nrm}) [${fnt_tlc}drc_rgr, rgr_drc, dir_regrid, regrid${fnt_nrm}]" |
| 685 |
echo "${fnt_rvr}-o${fnt_nrm} ${fnt_bld}drc_out${fnt_nrm} Output directory (default ${fnt_bld}${drc_out}${fnt_nrm}) [${fnt_tlc}drc_out, out_drc, dir_out, out_dir, output${fnt_nrm}]" |
| 686 |
echo "${fnt_rvr}-P${fnt_nrm} ${fnt_bld}prc_typ${fnt_nrm} Procedure type (empty means none) (default ${fnt_bld}${prc_typ}${fnt_nrm}) [${fnt_tlc}prc_typ, procedure${fnt_nrm}] (cpl|eam|eamxx|elm|mpaso|mpassi|cam|clm|pop|...)" |
| 687 |
echo "${fnt_rvr}-p${fnt_nrm} ${fnt_bld}par_typ${fnt_nrm} Parallelism type for files (default ${fnt_bld}${par_typ}${fnt_nrm}) [${fnt_tlc}par_typ, par_md, parallel_type, parallel_mode, parallel${fnt_nrm}] [${fnt_tlc}serial | background | mpi${fnt_nrm}]" |
| 688 |
echo " ${fnt_bld}--qnt_prc${fnt_nrm} Quantization precision (empty means none) (default ${fnt_bld}${qnt_prc}${fnt_nrm}) [${fnt_tlc}qnt, qnt_prc, ppc, ppc_prc, precision, quantize${fnt_nrm}]" |
| 689 |
echo "${fnt_rvr}-R${fnt_nrm} ${fnt_bld}rgr_opt${fnt_nrm} Regrid options (empty means none) (default ${fnt_bld}${rgr_opt}${fnt_nrm}) [${fnt_tlc}rgr_opt, regrid_options${fnt_nrm}]" |
| 690 |
echo "${fnt_rvr}-r${fnt_nrm} ${fnt_bld}rgr_map${fnt_nrm} Regrid map-file (horizontal) (empty means none) (default ${fnt_bld}${rgr_map}${fnt_nrm}) [${fnt_tlc}rgr_map, regrid_map, map, map_fl, map_file${fnt_nrm}]" |
| 691 |
echo " ${fnt_bld}--rgn_avg${fnt_nrm} Regional/global average timeseries (default ${fnt_bld}${rgn_avg}${fnt_nrm}) [${fnt_tlc}rgn_avg, glb_avg, hms_avg, regional_average${fnt_nrm}]" |
| 692 |
echo " ${fnt_bld}--rgn_stt${fnt_nrm} Regional/global statistical timeseries (default ${fnt_bld}${rgn_stt}${fnt_nrm}) [${fnt_tlc}rgn_stt, glb_stt, hms_stt, regional_statistic, global_statistic${fnt_nrm}] (avg|sum)" |
| 693 |
echo "${fnt_rvr}-S${fnt_nrm} ${fnt_bld}yr_srt${fnt_nrm} Start year previous climo (empty means none) (default ${fnt_bld}${yr_srt_prv}${fnt_nrm}) [${fnt_tlc}yr_srt_prv, prv_yr_srt, previous_start${fnt_nrm}]" |
| 694 |
echo "${fnt_rvr}-s${fnt_nrm} ${fnt_bld}yr_srt${fnt_nrm} Start year (default ${fnt_bld}${yr_srt}${fnt_nrm}) [${fnt_tlc}yr_srt, start_yr, year_start, start_year, start${fnt_nrm}]" |
| 695 |
echo " ${fnt_bld}--seasons${fnt_nrm} Seasons to output ('none' means none) (default ${fnt_bld}${csn_lst}${fnt_nrm}, also available: jfm,amj,jas,ond,on,fm) [${fnt_tlc}csn_lst, csn, seasons${fnt_nrm}]" |
| 696 |
echo " ${fnt_bld}--sgs_frc${fnt_nrm} Sub-grid fraction variable (empty means none) (default ${fnt_bld}${sgs_frc}${fnt_nrm}) [${fnt_tlc}sgs_frc, ice_frc, lnd_frc, ocn_frc, subgrid_fraction${fnt_nrm}]" |
| 697 |
echo " ${fnt_bld}--split${fnt_nrm} Split input files into single-variable timeseries (default ${fnt_bld}${tms_flg}${fnt_nrm} [${fnt_tlc}splitter, tms_flg, timeseries${fnt_nrm}]" |
| 698 |
echo " ${fnt_bld}--sum_scl${fnt_nrm} Scale factor to convert global sum timeseries to desired area units, timescale (empty means none) (default ${fnt_bld}${sum_scl}${fnt_nrm}) [${fnt_tlc}sum_scl, scl_fct, sum_scale, scale_factor${fnt_nrm}]" |
| 699 |
echo "${fnt_rvr}-t${fnt_nrm} ${fnt_bld}thr_nbr${fnt_nrm} Thread number for regridder (default ${fnt_bld}${thr_nbr}${fnt_nrm}) [${fnt_tlc}thr_nbr, thr, thread_number, thread, threads${fnt_nrm}]" |
| 700 |
echo " ${fnt_bld}--tpd_out${fnt_nrm} Timesteps-per-day in output (default ${fnt_bld}${tpd_out}${fnt_nrm}) [${fnt_tlc}tpd_out, tpd, timesteps_per_day${fnt_nrm}]" |
| 701 |
echo " ${fnt_bld}--uio${fnt_nrm} Unbuffered I/O (NC_SHARE) for netCDF3 files [${fnt_tlc}uio, unbuffered, share${fnt_nrm}]" |
| 702 |
echo "${fnt_rvr}-v${fnt_nrm} ${fnt_bld}var_lst${fnt_nrm} Variable list (empty means all) (default ${fnt_bld}${var_lst}${fnt_nrm}) [${fnt_tlc}var_lst, variable_list, var, vars, variable, variables${fnt_nrm}]" |
| 703 |
echo " ${fnt_bld}--var_xtr${fnt_nrm} Extra variables for splitter timeseries (empty means none) (default ${fnt_bld}${var_xtr}${fnt_nrm}) [${fnt_tlc}var_xtr, var_extra, variables_extra, extra_variables${fnt_nrm}]" |
| 704 |
echo " ${fnt_bld}--version${fnt_nrm} Version and configuration information [${fnt_tlc}version, vrs, config, configuration, cnf${fnt_nrm}]" |
| 705 |
echo " ${fnt_bld}--vrt_out${fnt_nrm} Vertical grid file for output (empty means none) (default ${fnt_bld}${vrt_out}${fnt_nrm}) [${fnt_tlc}vrt_out, vrt_fl, vrt, vrt_crd, vrt_grd_out${fnt_nrm}]" |
| 706 |
echo " ${fnt_bld}--vrt_xtr${fnt_nrm} Vertical extrapolation type (empty means none) (default ${fnt_bld}${vrt_xtr}${fnt_nrm}) [${fnt_tlc}vrt_xtr, xtr_mth, extrapolation_type, extrapolation_method${fnt_nrm}] (mss_val|nrs_ngh)" |
| 707 |
echo "${fnt_rvr}-X${fnt_nrm} ${fnt_bld}drc_xtn${fnt_nrm} Extended climo directory (default ${fnt_bld}${drc_xtn}${fnt_nrm}) [${fnt_tlc}drc_xtn, xtn_drc, extended_dir, extended_climo, extended${fnt_nrm}]" |
| 708 |
echo "${fnt_rvr}-x${fnt_nrm} ${fnt_bld}drc_prv${fnt_nrm} Previous climo directory (default ${fnt_bld}${drc_prv}${fnt_nrm}) [${fnt_tlc}drc_prv, prv_drc, previous_dir, previous_climo, previous${fnt_nrm}]" |
| 709 |
echo " ${fnt_bld}--xcl_var${fnt_nrm} Exclude rather than extract var_lst [${fnt_tlc}xcl_var, xcl, exclude, exclude_variables${fnt_nrm}]" |
| 710 |
echo "${fnt_rvr}-Y${fnt_nrm} ${fnt_bld}rgr_xtn${fnt_nrm} Regridded extended climo directory (default ${fnt_bld}${drc_rgr_xtn}${fnt_nrm}) [${fnt_tlc}drc_rgr_xtn, drc_xtn_rgr, regridded_extended, extended_regridded${fnt_nrm}]" |
| 711 |
echo "${fnt_rvr}-y${fnt_nrm} ${fnt_bld}rgr_prv${fnt_nrm} Regridded previous climo directory (default ${fnt_bld}${drc_rgr_prv}${fnt_nrm}) [${fnt_tlc}drc_rgr_prv, drc_prv_rgr, regridded_previous, previous_regridded${fnt_nrm}]" |
| 712 |
echo " ${fnt_bld}--ypf_max${fnt_nrm} Years-per-output-file maximum (default ${fnt_bld}${ypf_max}${fnt_nrm}) [${fnt_tlc}ypf_max, ypf, years, years_per_file${fnt_nrm}]" |
| 713 |
printf "\n" |
| 714 |
printf "${fnt_rvr}Examples:${fnt_nrm}\n${fnt_bld}${spt_nm} -P eam -c ${caseid_xmp} -s 2013 -e 2014 -i ${drc_in_xmp} -o ${drc_out_xmp} -r ~zender/data/maps/map_ne30pg2_to_cmip6_180x360_nco.20200901.nc ${fnt_nrm}# EAMv2 climo\n" |
| 715 |
printf "${fnt_bld}${spt_nm} -P eamxx -v SW_flux_dn_at_model_bot,T_2m,wind_speed_10m -c ${caseid_xmp_eamxx} -f foo -s 1 -e 2 -i ${drc_in_xmp} -o ${drc_out_xmp} -r ~zender/data/maps/map_ne30pg2_to_cmip6_180x360_nco.20200901.nc ${fnt_nrm}# EAMXX climo\n" |
| 716 |
printf "${fnt_bld}${spt_nm} -P elm -m clm2 -c control -s ${yr_srt} -e ${yr_end} -i ${drc_in_xmp} -o ${drc_out_xmp} -r ~zender/data/maps/map_ne30pg2_to_cmip6_180x360_nco.20200901.nc ${fnt_nrm}# ELMv2 climo\n" |
| 717 |
printf "${fnt_bld}${spt_nm} -P mpaso -v timeMonthly_avg_activeTracers_temperature -s 1 -e 2 -i ${drc_in_mps} -o ${drc_out_mps} -r ~zender/data/maps/map_oEC60to30v3_to_cmip6_180x360_aave.20181001.nc ${fnt_nrm}# MPAS-Ocean v1 climo\n" |
| 718 |
printf "${fnt_bld}${spt_nm} -P mpasseaice -v timeMonthly_avg_iceAreaCell -s ${yr_srt} -e ${yr_end} -i ${drc_in_mps} -o ${drc_out_mps} -r ~zender/data/maps/map_oRRS18to6v3_to_cmip6_720x1440_nco.20200601.nc ${fnt_nrm}# MPAS-Seaice v2 climo\n" |
| 719 |
printf "${fnt_bld}cd output;ls *eam*19??-??*.nc | ${spt_nm} -P eam -v FSNT,TREFHT -s 1900 -e 1999 -o ${drc_out_xmp} -r ~zender/data/maps/map_ne30pg2_to_cmip6_180x360_nco.20200901.nc ${fnt_nrm}# EAM timeseries\n" |
| 720 |
printf "${fnt_bld}ncclimo -c ${caseid_xmp} -S 41 -E 50 -x ${drc_rgr_xmp}/0041-0050 -s 51 -e 60 -i ${drc_rgr_xmp}/0051-0060 -X ${drc_rgr_xmp}/0041-0060 ${fnt_nrm}# Combine two EAM climos\n\n" |
| 721 |
# 20210831: NB: Alternative access to interactive batch queues via, e.g., "salloc -A e3sm --constraint=knl --nodes=1 --time=00:30:00 --job-name=ncclimo" works well everywhere except Compy |
| 722 |
printf "${fnt_rvr}Interactive batch queues:${fnt_nrm}\n" |
| 723 |
printf "andes: salloc -A CLI115 --nodes=1 --time=00:30:00 --job-name=ncclimo\n" |
| 724 |
printf "bebop: qsub -I -A E3SM -l select=1:ncpus=128:mpiprocs=128,walltime=00:30:00\n" # No queue argument |
| 725 |
printf "chrys: salloc -A e3sm --nodes=1 --time=00:30:00 --job-name=ncclimo\n" |
| 726 |
printf "compy: salloc -A e3sm --nodes=1 --time=00:30:00 --job-name=ncclimo\n" |
| 727 |
printf "derec: qsub -I -A SCSG0002 -l select=1:ncpus=36:mpiprocs=1 -l walltime=00:30:00 -q regular -N ncclimo\n" |
| 728 |
printf "front: salloc -A CLI115 --nodes=1 --time=00:30:00 --job-name=ncclimo\n" |
| 729 |
printf "impro: qsub -I -A E3SM -l select=1:ncpus=128:mpiprocs=128,walltime=00:30:00 -q compute\n" |
| 730 |
printf "perlm: salloc -A e3sm --constraint=cpu --nodes=1 --time=00:30:00 --qos=debug --job-name=ncclimo\n" |
| 731 |
printf "\nComplete documentation at http://nco.sf.net/nco.html#${spt_nm}\n\n" |
| 732 |
exit 1 |
| 733 |
} # !fnc_usg_prn() |
| 734 |
|
| 735 |
function bsh_mjr_vrs_lt_4 { |
| 736 |
# Purpose: Return true if major version of Bash shell is < 4 |
| 737 |
# Usage: if bsh_mjr_vrs_lt_4 ; then ...; fi |
| 738 |
local vrs |
| 739 |
if [ -n ${BASH_VERSION} ]; then |
| 740 |
let vrs=${BASH_VERSION%%.*} # NeR98 p. 100 |
| 741 |
if [ ${vrs} -lt 4 ] ; then # NeR98 p. 153 |
| 742 |
return 0; # 0 is true in shell-ese |
| 743 |
fi # !vrs |
| 744 |
fi # !BASH_VERSION |
| 745 |
# By default, functions return exit status of last command executed |
| 746 |
return 1; # 1 is false in shell-ese |
| 747 |
} # !bsh_mjr_vrs_lt_4() |
| 748 |
|
| 749 |
function trim_leading_zeros { |
| 750 |
# Purpose: Trim leading zeros from string representing an integer |
| 751 |
# Why, you ask? Because Bash treats zero-padded integers as octal! |
| 752 |
# This is surprisingly hard to workaround |
| 753 |
# My workaround is to remove leading zeros prior to arithmetic |
| 754 |
# Usage: trim_leading zeros ${sng} |
| 755 |
sng_trm=${1} # [sng] Trimmed string |
| 756 |
# Use Bash 2.X pattern matching to remove up to three leading zeros, one at a time |
| 757 |
sng_trm=${sng_trm##0} # NeR98 p. 99 |
| 758 |
sng_trm=${sng_trm##0} |
| 759 |
sng_trm=${sng_trm##0} |
| 760 |
# If all zeros removed, replace with single zero |
| 761 |
if [ "${sng_trm}" = '' ]; then |
| 762 |
sng_trm='0' |
| 763 |
fi # !sng_trm |
| 764 |
} # !trim_leading_zeros() |
| 765 |
|
| 766 |
csn_nfo_get() |
| 767 |
{ |
| 768 |
# Usage: |
| 769 |
# csn_nfo_get 2013 7 2014 6 6 8 5 returns "201307_201406" |
| 770 |
# csn_nfo_get 2013 7 2014 6 6 8 6 returns "2013,2014,07,06" |
| 771 |
|
| 772 |
# [fnc] Parse seasonal information and compute date strings |
| 773 |
# [sng] Input: Seven positional integer arguments |
| 774 |
# [sng] Output: Requested date string based on rtn_enm |
| 775 |
|
| 776 |
local fnc_nm="csn_nfo_get()" # [sng] Function name |
| 777 |
|
| 778 |
local yr_srt="${1}" # [yr] Starting year |
| 779 |
local mth_srt="${2}" # [mth] Starting month |
| 780 |
local yr_end="${3}" # [yr] Ending year |
| 781 |
local mth_end="${4}" # [mth] Ending month |
| 782 |
local csn_srt_idx="${5}" # [idx] Seasonal start index |
| 783 |
local csn_end_idx="${6}" # [idx] Seasonal end index |
| 784 |
local rtn_enm="${7}" # [enm] Enumerated return variable |
| 785 |
|
| 786 |
local yyyy_frs # [yr] First year in seasonal range |
| 787 |
local yyyy_lst # [yr] Last year in seasonal range |
| 788 |
local yyyymm_frs # [yyyymm] Earliest year-month in season |
| 789 |
local yyyymm_lst # [yyyymm] Latest year-month in season |
| 790 |
local mm_frs # [mth] First month in seasonal range |
| 791 |
local mm_lst # [mth] Last month in seasonal range |
| 792 |
|
| 793 |
local yyyy_frs_sng # [sng] First year string (YYYY format) |
| 794 |
local yyyy_lst_sng # [sng] Last year string (YYYY format) |
| 795 |
local yyyymm_frs_sng # [sng] First year-month string (YYYYMM format) |
| 796 |
local yyyymm_lst_sng # [sng] Last year-month string (YYYYMM format) |
| 797 |
local yyyymm_rng_sng # [sng] Year-month range string (YYYYMM_YYYYMM format) |
| 798 |
local clm_bnd_arg # [sng] Column boundary argument string (yyyy_frs,yyyy_lst,mm_frs,mm_lst) |
| 799 |
local yyyy_rng # [sng] Year range string (YYYY or YYYY-YYYY format) |
| 800 |
local rtn_sng # [sng] String to return |
| 801 |
|
| 802 |
local mth_crr # [mth] Current month in data range |
| 803 |
local yr_crr # [yr] Current year in data range |
| 804 |
local yyyymm_crr # [yyyymm] Current year-month |
| 805 |
local yyyymm_srt # [yyyymm] Starting year-month of data range |
| 806 |
local yyyymm_end # [yyyymm] Ending year-month of data range |
| 807 |
|
| 808 |
local mth_in_csn # [flg] Month is in seasonal range |
| 809 |
|
| 810 |
# Check syntax |
| 811 |
if [[ -z "${yr_srt}" ]] || [[ -z "${mth_srt}" ]] || [[ -z "${yr_end}" ]] || [[ -z "${mth_end}" ]] || [[ -z "${csn_srt_idx}" ]] || [[ -z "${csn_end_idx}" ]] || [[ -z "${rtn_enm}" ]]; then |
| 812 |
echo "${fnc_nm}: ERROR Missing required parameters" >&2 |
| 813 |
return 1 |
| 814 |
fi |
| 815 |
|
| 816 |
# Validate and convert to base-10 to avoid octal interpretation |
| 817 |
yr_srt=$((10#${yr_srt})) |
| 818 |
mth_srt=$((10#${mth_srt})) |
| 819 |
yr_end=$((10#${yr_end})) |
| 820 |
mth_end=$((10#${mth_end})) |
| 821 |
csn_srt_idx=$((10#${csn_srt_idx})) |
| 822 |
csn_end_idx=$((10#${csn_end_idx})) |
| 823 |
rtn_enm=$((10#${rtn_enm})) |
| 824 |
|
| 825 |
# Compute data range boundaries |
| 826 |
yyyymm_srt=$((yr_srt*100+mth_srt)) |
| 827 |
yyyymm_end=$((yr_end*100+mth_end)) |
| 828 |
|
| 829 |
# Find earliest and latest year-month in seasonal range |
| 830 |
yyyymm_frs=-1 |
| 831 |
yyyymm_lst=-1 |
| 832 |
|
| 833 |
# Iterate through months in data range |
| 834 |
mth_crr=${mth_srt} |
| 835 |
yr_crr=${yr_srt} |
| 836 |
while true; do |
| 837 |
yyyymm_crr=$((yr_crr*100+mth_crr)) |
| 838 |
|
| 839 |
# Check if current month is in seasonal range |
| 840 |
mth_in_csn=0 |
| 841 |
if [[ ${csn_srt_idx} -le ${csn_end_idx} ]]; then |
| 842 |
# Non-wrapping case (e.g., 6 to 8) |
| 843 |
if [[ ${mth_crr} -ge ${csn_srt_idx} ]] && [[ ${mth_crr} -le ${csn_end_idx} ]]; then |
| 844 |
mth_in_csn=1 |
| 845 |
fi |
| 846 |
else |
| 847 |
# Wrapping case (e.g., 12 to 2) |
| 848 |
if [[ ${mth_crr} -ge ${csn_srt_idx} ]] || [[ ${mth_crr} -le ${csn_end_idx} ]]; then |
| 849 |
mth_in_csn=1 |
| 850 |
fi |
| 851 |
fi |
| 852 |
|
| 853 |
if [[ ${mth_in_csn} -eq 1 ]]; then |
| 854 |
if [[ ${yyyymm_frs} -lt 0 ]]; then |
| 855 |
yyyymm_frs=${yyyymm_crr} |
| 856 |
fi |
| 857 |
yyyymm_lst=${yyyymm_crr} |
| 858 |
fi |
| 859 |
|
| 860 |
# Check if we've reached the end |
| 861 |
if [[ ${mth_crr} -eq ${mth_end} ]] && [[ ${yr_crr} -eq ${yr_end} ]]; then |
| 862 |
break |
| 863 |
fi |
| 864 |
|
| 865 |
# Advance to next month, wrapping 12->1 |
| 866 |
mth_crr=$((mth_crr+1)) |
| 867 |
if [[ ${mth_crr} -gt 12 ]]; then |
| 868 |
mth_crr=1 |
| 869 |
yr_crr=$((yr_crr+1)) |
| 870 |
fi |
| 871 |
done |
| 872 |
|
| 873 |
# Extract year components from computed yyyymm values |
| 874 |
yyyy_frs=$((yyyymm_frs/100)) |
| 875 |
yyyy_lst=$((yyyymm_lst/100)) |
| 876 |
|
| 877 |
# Extract month components from computed yyyymm values |
| 878 |
mm_frs=$((yyyymm_frs%100)) |
| 879 |
mm_lst=$((yyyymm_lst%100)) |
| 880 |
|
| 881 |
# Format output date strings |
| 882 |
printf -v yyyy_frs_sng "%04d" ${yyyy_frs} |
| 883 |
printf -v yyyy_lst_sng "%04d" ${yyyy_lst} |
| 884 |
printf -v yyyymm_frs_sng "%06d" ${yyyymm_frs} |
| 885 |
printf -v yyyymm_lst_sng "%06d" ${yyyymm_lst} |
| 886 |
printf -v yyyymm_rng_sng "%06d_%06d" ${yyyymm_frs} ${yyyymm_lst} |
| 887 |
printf -v clm_bnd_arg "%04d,%04d,%02d,%02d" ${yyyy_frs} ${yyyy_lst} ${mm_frs} ${mm_lst} |
| 888 |
|
| 889 |
# Format year range string |
| 890 |
if [[ ${yyyy_frs} -eq ${yyyy_lst} ]]; then |
| 891 |
printf -v yyyy_rng "%04d" ${yyyy_frs} |
| 892 |
else |
| 893 |
printf -v yyyy_rng "%04d-%04d" ${yyyy_frs} ${yyyy_lst} |
| 894 |
fi |
| 895 |
|
| 896 |
# Select and return requested string |
| 897 |
case ${rtn_enm} in |
| 898 |
1) rtn_sng="${yyyy_frs_sng}" ;; |
| 899 |
2) rtn_sng="${yyyy_lst_sng}" ;; |
| 900 |
3) rtn_sng="${yyyymm_frs_sng}" ;; |
| 901 |
4) rtn_sng="${yyyymm_lst_sng}" ;; |
| 902 |
5) rtn_sng="${yyyymm_rng_sng}" ;; |
| 903 |
6) rtn_sng="${clm_bnd_arg}" ;; |
| 904 |
7) rtn_sng="${yyyy_rng}" ;; |
| 905 |
*) echo "${fnc_nm}: ERROR Return enumeration must be 1, 2, 3, 4, 5, 6, or 7" >&2; return 1 ;; |
| 906 |
esac |
| 907 |
|
| 908 |
echo "${rtn_sng}" |
| 909 |
return 0 |
| 910 |
} # !csn_nfo_get() |
| 911 |
|
| 912 |
# Check argument number and complain accordingly |
| 913 |
arg_nbr=$# |
| 914 |
#printf "\ndbg: Number of arguments: ${arg_nbr}" |
| 915 |
if [ ${arg_nbr} -eq 0 ]; then |
| 916 |
fnc_usg_prn |
| 917 |
fi # !arg_nbr |
| 918 |
|
| 919 |
# Parse command-line options: |
| 920 |
# http://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-line-options (see method by Adam Katz) |
| 921 |
# http://tuxtweaks.com/2014/05/bash-getopts |
| 922 |
while getopts :34567a:C:c:d:E:e:f:h:i:j:L:l:m:n:O:o:P:p:R:r:S:s:t:v:X:x:Y:y:-: OPT; do |
| 923 |
case ${OPT} in |
| 924 |
3) fl_fmt='3' ;; # File format |
| 925 |
4) fl_fmt='4' ;; # File format |
| 926 |
5) fl_fmt='5' ;; # File format |
| 927 |
6) fl_fmt='6' ;; # File format |
| 928 |
7) fl_fmt='7' ;; # File format |
| 929 |
a) wnt_md_usr="${OPTARG}" ;; # Winter mode |
| 930 |
C) clm_md_usr="${OPTARG}" ;; # Climatology mode |
| 931 |
c) caseid="${OPTARG}" ;; # CASEID |
| 932 |
d) dbg_lvl="${OPTARG}" ;; # Debugging level |
| 933 |
E) yr_end_prv="${OPTARG}" ;; # End year previous |
| 934 |
e) yr_end="${OPTARG}" ;; # End year |
| 935 |
f) fml_nm_usr="${OPTARG}" ;; # Family name |
| 936 |
h) hst_nm="${OPTARG}" ;; # History tape name |
| 937 |
i) drc_in="${OPTARG}" ;; # Input directory |
| 938 |
j) job_usr="${OPTARG}" ;; # Job simultaneity |
| 939 |
L) dfl_lvl="${OPTARG}" ;; # Deflate level |
| 940 |
l) lnk_flg="${OPTARG}" ;; # Link E3SM to AMWG name |
| 941 |
m) mdl_nm_usr="${OPTARG}" ;; # Model name string |
| 942 |
n) nco_opt="${OPTARG} ${nco_opt}" ;; # NCO options |
| 943 |
o) drc_out_usr="${OPTARG}" ;; # Output directory |
| 944 |
O) drc_rgr_usr="${OPTARG}" ;; # Regridded directory |
| 945 |
P) prc_typ="${OPTARG}" ;; # Procedure type |
| 946 |
p) par_typ="${OPTARG}" ;; # Parallelism type for files |
| 947 |
R) rgr_opt_usr="${OPTARG}" ;; # Regridding options |
| 948 |
r) rgr_map="${OPTARG}" ;; # Regridding map (horizontal) |
| 949 |
S) yr_srt_prv="${OPTARG}" ;; # Start year previous |
| 950 |
s) yr_srt="${OPTARG}" ;; # Start year |
| 951 |
t) thr_usr="${OPTARG}" ;; # Thread number |
| 952 |
v) var_lst="${OPTARG}" ;; # Variables |
| 953 |
X) drc_xtn="${OPTARG}" ;; # Extended climo directory |
| 954 |
x) drc_prv="${OPTARG}" ;; # Previous climo directory |
| 955 |
Y) drc_rgr_xtn="${OPTARG}" ;; # Regridded extended climo directory |
| 956 |
y) drc_rgr_prv="${OPTARG}" ;; # Regridded previous climo directory |
| 957 |
z) ypf_max_usr="${OPTARG}" ;; # Years-per-output-file maximum |
| 958 |
-) LONG_OPTARG="${OPTARG#*=}" |
| 959 |
case ${OPTARG} in |
| 960 |
# Hereafter ${OPTARG} is long argument key, and ${LONG_OPTARG}, if any, is long argument value |
| 961 |
# Long options with no argument, no short option counterpart |
| 962 |
# Long options with argument, no short option counterpart |
| 963 |
# Long options with short counterparts, ordered by short option key |
| 964 |
area_nm=?* | area_name=?* | area=?* ) area_nm="${LONG_OPTARG}" ;; # # Area-variable name |
| 965 |
bfr_sz=?* | bfr=?* | buffer_size_hint=?* ) bfr_sz="${LONG_OPTARG}" ;; # # Buffer size for netCDF-classic I/O |
| 966 |
clm_md=?* | climatology_mode=?* | climo_mode=?* ) clm_md_usr="${LONG_OPTARG}" ;; # -C # Climatology mode |
| 967 |
caseid=?* | case_id=?* | case=?* ) caseid="${LONG_OPTARG}" ;; # -c # CASEID |
| 968 |
cmp=?* | cmp_sng=?* | compress=? | compression=?* | cpr=?* | cdc=?* | codec=?* ) cmp_sng="${LONG_OPTARG}" ;; # # Compression string |
| 969 |
d2f | d2s | dbl_flt | dbl_sgl | double_float ) d2f_flg='Yes'; d2f_opt='--d2f' ;; # # Convert double-precision fields to single-precision |
| 970 |
d2f=?* | d2s=?* | dbl_flt=?* | dbl_sgl=?* | double_float=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # D2F |
| 971 |
wnt_md=?* | dcm_md=? | december_mode=?* | winter_mode=?* | dec_md=?* ) wnt_md_usr="${LONG_OPTARG}" ;; # -a # Winter mode |
| 972 |
dbg_lvl=?* | dbg=?* | debug=?* | debug_level=?* ) dbg_lvl="${LONG_OPTARG}" ;; # -d # Debugging level |
| 973 |
dfl_lvl=?* | deflate=?* | dfl=?* ) dfl_lvl="${LONG_OPTARG}" ;; # -L # Deflate level |
| 974 |
dpf=?* | days_per_file=?* ) dpf="${LONG_OPTARG}" ;; # # Days-per-file |
| 975 |
dpt_fl=?* | mpas_fl=?* | mpas_file=?* | depth_file=?* ) dpt_opt="--dpt_fl=${LONG_OPTARG}" ;; # # Depth file with refBottomDepth for MPAS ocean |
| 976 |
yr_end_prv=?* | prv_yr_end=?* | previous_end=?* ) yr_end_prv="${LONG_OPTARG}" ;; # -E # End year previous |
| 977 |
yr_end=?* | end_yr=?* | year_end=?* | end_year=?* | end=?* ) yr_end="${LONG_OPTARG}" ;; # -e # End year |
| 978 |
fml_nm=?* | fml=?* | family_name=?* | family=?* ) fml_nm_usr="${LONG_OPTARG}" ;; # -f # Family name |
| 979 |
hst_nm=?* | history_name=?* | history=?* ) hst_nm="${LONG_OPTARG}" ;; # -h # History tape name |
| 980 |
drc_in=?* | in_drc=?* | dir_in=?* | in_dir=?* | input=?* ) drc_in="${LONG_OPTARG}" ;; # -i # Input directory |
| 981 |
fl_fmt=?* | fmt_out=?* | file_format=?* | format_out=?* ) fl_fmt="${LONG_OPTARG}" ;; # # Output file format |
| 982 |
hrd_pth | hard_path | npo | nco_path_override | NCO_PATH_OVERRIDE ) hrd_pth='Yes' ;; # # Use hard-coded paths on known machines (intentional no-op because already handled prior to getopt()) |
| 983 |
hrd_pth=?* | hard_path=?* | npo=?* | nco_path_override=?* | NCO_PATH_OVERRIDE=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Use hard-coded paths on known machines |
| 984 |
job_nbr=?* | job_number=?* | jobs=?* ) job_usr="${LONG_OPTARG}" ;; # -j # Job simultaneity |
| 985 |
lnk_flg=?* | link_flag=?* ) lnk_flg="${LONG_OPTARG}" ;; # -l # Link E3SM to AMWG name |
| 986 |
amwg_link | amwg_links | AMWG_link | AMWG_links ) lnk_flg='Yes' ;; # # Link E3SM to AMWG name |
| 987 |
amwg_link=?* | amwg_links=?* | AMWG_link=?* | AMWG_links=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Link E3SM to AMWG name |
| 988 |
no_amwg_link | no_amwg_links | no_amwg | no_AMWG_link | no_AMWG_links ) lnk_flg='No' ;; # # Link E3SM to AMWG name |
| 989 |
no_amwg_link=?* | no_amwg_links=?* | no_amwg=?* | no_AMWG_link=?* | no_AMWG_links=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # -l # Link E3SM to AMWG name |
| 990 |
mdl_nm=?* | mdl=?* | model_name=?* | model=?* ) mdl_nm_usr="${LONG_OPTARG}" ;; # -m # Model name string |
| 991 |
mem_mb=?* | mmr_mb=?* | memory_mb=? | memory_megabytes=?* ) mem_mb="${LONG_OPTARG}" ;; # # Megabytes of RAM per srun job in Cori SLURM in MPI mode |
| 992 |
mth_end=?* | end_mth=?* | month_end=?* | end_month=?* ) mth_end="${LONG_OPTARG}" ;; # # End month |
| 993 |
mth_srt=?* | start_mth=?* | month_start=?* | start_month=?* ) mth_srt="${LONG_OPTARG}" ;; # # Start month |
| 994 |
nco_opt=?* | nco=?* | nco_options=?* ) nco_opt="${LONG_OPTARG} ${nco_opt}" ;; # -n # NCO options |
| 995 |
no_area | no_cll_msr | no_cell_measures ) no_cll_msr='Yes' ;; # # Omit cell_measures variables |
| 996 |
no_area=?* | no_cell_msr=?* | no_cell_measures=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Omit cell_measures variables |
| 997 |
no_frm_trm | no_frm | no_formula_terms ) no_frm_trm='Yes' ;; # # Omit formula_terms variables |
| 998 |
no_frm_trm=?* | no_frm=?* | no_formula_terms=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Omit formula_terms variables |
| 999 |
no_ntv_tms | no_ntv | no_native | no_native_timeseries | delete_native ) no_ntv_tms='Yes' ;; # # Omit native-grid split files |
| 1000 |
no_ntv_tms=?* | no_ntv=?* | no_native=?* | no_native_timeseries=?* | delete_native=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Omit native-grid split files |
| 1001 |
no_stg_grd | no_stg | no_stagger | no_staggered_grid ) no_stg_grd='Yes' ;; # # Omit staggered grid variables |
| 1002 |
no_stg_grd=?* | no_stg=?* | no_stagger=?* | no_staggered_grid ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Omit staggered grid variables |
| 1003 |
drc_out=?* | out_drc=?* | dir_out=?* | out_dir=?* | output=?* ) drc_out_usr="${LONG_OPTARG}" ;; # -o # Output directory |
| 1004 |
drc_rgr=?* | rgr_drc=?* | dir_regrid=?* | regrid_dir=?* | regrid=?* ) drc_rgr_usr="${LONG_OPTARG}" ;; # -O # Regridded directory |
| 1005 |
prc_typ=?* | procedure=?* ) prc_typ="${LONG_OPTARG}" ;; # -P # Procedure type |
| 1006 |
par_typ=?* | par_md=?* | parallel_type=?* | parallel_mode=?* | parallel=?* ) par_typ="${LONG_OPTARG}" ;; # -p # Parallelism type for files |
| 1007 |
qnt=?* | qnt_prc=?* | precision=?* | ppc=?* | ppc_prc=?* | quantize=?* ) qnt_prc="${LONG_OPTARG}" ;; # # Quantization precision |
| 1008 |
rgn_avg | glb_avg | hms_avg | regional_average ) rgn_avg='Yes'; rgn_stt='avg' ;; # # Regional/global average timeseries |
| 1009 |
rgn_avg=?* | glb_avg=?* | hms_avg=?* | regional_average=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Regional average timeseries |
| 1010 |
rgn_stt=?* | glb_stt=?* | hms_stt=?* | global_statistic=?* | regional_statistic=?* ) rgn_stt="${LONG_OPTARG}" ;; # # Regional/global statistical timeseries |
| 1011 |
rgr_opt=?* | regrid_options=?* ) rgr_opt_usr="${LONG_OPTARG}" ;; # -R # Regridding options |
| 1012 |
rgr_map=?* | regrid_map=?* | map=?* | map_fl=?* | map_file=?* ) rgr_map="${LONG_OPTARG}" ;; # -r # Regridding map (horizontal) |
| 1013 |
yr_srt_prv=?* | prv_yr_srt=?* | previous_start=?* ) yr_srt_prv="${LONG_OPTARG}" ;; # -S # Start year previous |
| 1014 |
yr_srt=?* | start_yr=?* | year_start=?* | start_year=?* | start=?* ) yr_srt="${LONG_OPTARG}" ;; # -s # Start year |
| 1015 |
seasons=?* | csn_lst=?* | csn=?* | season=?* ) csn_lst="${LONG_OPTARG}" ;; # # Seasons to output |
| 1016 |
sgs_frc=?* | ice_frc=?* | lnd_frc=?* | ocn_frc=?* | subgrid_fraction=?* ) sgs_frc="${LONG_OPTARG}" ;; # # Sub-grid fraction variable |
| 1017 |
split | splitter | tms_flg | timeseries ) tms_flg='Yes' ;; # # Split input files into single-variable timeseries |
| 1018 |
split=?* | splitter=?* | tms_flg=?* | timeseries=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Split input files into single-variable timeseries |
| 1019 |
sum_scl=?* | scl_fct=?* | sum_scale=?* | scale_factor=?* ) sum_scl="${LONG_OPTARG}" ;; # # Factor to convert area, time units ([sr], [km2], [s]) to desired units (e.g., [m2], [yr]) in sums |
| 1020 |
stdin | inp_std | std_flg | redirect | standard_input ) printf "ERROR: ncclimo deprecated --stdin in version 5.0.4.\nHINT: Use --split to unambiguously invoke the splitter. This supercedes the old use for --stdin in ncclimo." ; exit 1 ;; # # Input file list from stdin |
| 1021 |
no_stdin | no_inp_std | no_redirect | no_standard_input ) std_chk='No' ;; # # Do not check stdin for input file list |
| 1022 |
no_stdin=?* | no_inp_std=?* | no_redirect=?* | no_standard_input=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Do not check stdin for input file list |
| 1023 |
thr_nbr=?* | thr=?* | thread_number=?* | thread=?* | threads=?* ) thr_usr="${LONG_OPTARG}" ;; # -t # Thread number |
| 1024 |
tpd_out=?* | tpd=?* | timesteps_per_day=?* ) tpd_usr="${LONG_OPTARG}" ;; # # Timesteps-per-day in output |
| 1025 |
uio | unbuffered | share ) uio_flg='Yes' ;; # # Unbuffered I/O (NC_SHARE) for netCDF3 files |
| 1026 |
uio=?* | unbuffered=?* | share=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Unbuffered I/O (NC_SHARE) for netCDF3 files |
| 1027 |
var_lst=?* | variable_list=?* | var=?* | vars=?* | variable=?* | variables=?* ) var_lst="${LONG_OPTARG}" ;; # -v # Variables |
| 1028 |
var_xtr=?* | var_extra=?* | variables_extra=?* | extra_variables=?* ) var_xtr=",${LONG_OPTARG}" ;; # # Extra variables for splitter timeseries (NB: initial comma is required/intentional" |
| 1029 |
version | vrs | config | configuration | cnf ) vrs_prn='Yes' ;; # # Print version information |
| 1030 |
version=?* | vrs=?* | config=?* | configuration=?* | cnf=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Print version information |
| 1031 |
vrt_out=?* | vrt_fl=?* | vrt=?* | vrt_crd=?* | vrt_grd_out=?* ) vrt_out="${LONG_OPTARG}" ;; # # Vertical grid file for output |
| 1032 |
vrt_xtr=?* | xtr_mth=?* | extrapolation_type=?* | extrapolation_method=?* ) vrt_xtr="${LONG_OPTARG}" ;; # # Vertical extrapolation type (mss_val|nrs_ngh) |
| 1033 |
drc_xtn=?* | xtn_drc=?* | extended_dir=?* | extended_climo=?* | extended=?* ) drc_xtn="${LONG_OPTARG}" ;; # -X # Extended climo directory |
| 1034 |
drc_prv=?* | prv_drc=?* | previous_dir=?* | previous_climo=?* | previous=?* ) drc_prv="${LONG_OPTARG}" ;; # -x # Previous climo directory |
| 1035 |
drc_rgr_xtn=?* | drc_xtn_rgr=?* | regridded_extended=?* | extended_regridded=?* ) drc_rgr_xtn="${LONG_OPTARG}" ;; # -Y # Regridded extended climo directory |
| 1036 |
drc_rgr_prv=?* | drc_prv_rgr=?* | regridded_previous=?* | previous_regridded=?* ) drc_rgr_prv="${LONG_OPTARG}" ;; # -y # Regridded previous climo directory |
| 1037 |
xcl_var | xcl | exclude | exclude_variables ) xcl_flg='Yes' ;; # # Exclude rather than extract variable list |
| 1038 |
xcl_var=?* | xcl=?* | exclude=?* | exclude_variables=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Exclude rather than extract variable list |
| 1039 |
ypf_max=?* | ypf=?* | years=?* | years_per_file=?* ) ypf_max_usr="${LONG_OPTARG}" ;; # -z # Years-per-output-file maximum |
| 1040 |
'' ) break ;; # "--" terminates argument processing |
| 1041 |
* ) printf "\nERROR: Unrecognized option ${fnt_bld}--${OPTARG}${fnt_nrm}\n" >&2; fnc_usg_prn ;; |
| 1042 |
esac ;; # !OPTARG |
| 1043 |
\?) # Unrecognized option |
| 1044 |
printf "\nERROR: Option ${fnt_bld}-${OPTARG}${fnt_nrm} not recognized\n" >&2 |
| 1045 |
fnc_usg_prn ;; |
| 1046 |
esac # !OPT |
| 1047 |
done # !getopts |
| 1048 |
shift $((OPTIND-1)) # Advance one argument |
| 1049 |
psn_nbr=$# |
| 1050 |
if [ ${psn_nbr} -ge 1 ]; then |
| 1051 |
inp_psn='Yes' |
| 1052 |
# 20200430 Input files on command-line mean we need not check standard-input |
| 1053 |
std_chk='No' |
| 1054 |
fi # !psn_nbr |
| 1055 |
|
| 1056 |
if [ ${vrs_prn} = 'Yes' ]; then |
| 1057 |
printf "${spt_nm}, the NCO climatology operator, version ${nco_vrs} \"${nco_sng}\"\n" |
| 1058 |
printf "Copyright (C) 2016--present Charlie Zender\n" |
| 1059 |
printf "This program is part of NCO, the netCDF Operators\n" |
| 1060 |
printf "NCO is free software and comes with a BIG FAT KISS and ABSOLUTELY NO WARRANTY\n" |
| 1061 |
printf "You may redistribute and/or modify NCO under the terms of the\n" |
| 1062 |
printf "3-Clause BSD License with exceptions described in the LICENSE file\n" |
| 1063 |
printf "BSD: https://opensource.org/licenses/BSD-3-Clause\n" |
| 1064 |
printf "LICENSE: https://github.com/nco/nco/tree/master/LICENSE\n" |
| 1065 |
printf "Config: ${spt_nm} script located in directory ${drc_spt}\n" |
| 1066 |
printf "Config: NCO binaries located in directory ${drc_nco}, linked to netCDF library version ${lbr_vrs}\n" |
| 1067 |
if [ "${hrd_pth_fnd}" = 'Yes' ]; then |
| 1068 |
printf "Config: Employ NCO machine-dependent hardcoded paths/modules for ${HOSTNAME}. (If desired, turn-off NCO hardcoded paths with \"export NCO_PATH_OVERRIDE=No\").\n" |
| 1069 |
else |
| 1070 |
printf "Config: No hardcoded machine-dependent path/module overrides. (If desired, turn-on NCO hardcoded paths at supported national labs with \"export NCO_PATH_OVERRIDE=Yes\").\n" |
| 1071 |
fi # !hrd_pth_fnd |
| 1072 |
exit 0 |
| 1073 |
fi # !vrs_prn |
| 1074 |
|
| 1075 |
# Detect input on pipe to stdin: |
| 1076 |
# http://stackoverflow.com/questions/2456750/detect-presence-of-stdin-contents-in-shell-script |
| 1077 |
# http://unix.stackexchange.com/questions/33049/check-if-pipe-is-empty-and-run-a-command-on-the-data-if-it-isnt |
| 1078 |
# 20170119 "if [ ! -t 0 ]" tests whether unit 0 (stdin) is connected to terminal, not whether pipe has data |
| 1079 |
# Non-interactive batch mode (e.g., qsub, sbatch) disconnects stdin from terminal and triggers false-positives with ! -t 0 |
| 1080 |
# 20170123 "if [ -p foo ]" tests whether foo exists and is a pipe or named pipe |
| 1081 |
# Non-interactive batch mode (i.e., sbatch) behaves as desired for -p /dev/stdin on SLURM |
| 1082 |
# Non-interactive batch mode (e.g., qsub) always returns true for -p /dev/stdin on PBS, leads to FALSE POSITIVES! |
| 1083 |
# This is because PBS uses stdin to set the job name |
| 1084 |
# Hence -p /dev/stdin test works everywhere tested except PBS non-interactive batch environment |
| 1085 |
# Check stdin if user has not explicitly disallowed it with --no_stdin |
| 1086 |
if [ "${std_chk}" = 'Yes' ]; then |
| 1087 |
if [ -n "${PBS_ENVIRONMENT}" ]; then |
| 1088 |
if [ "${PBS_ENVIRONMENT}" = 'PBS_BATCH' ]; then |
| 1089 |
# PBS batch detection suggested by OLCF ticket CCS #338970 on 20170127 |
| 1090 |
bch_pbs='Yes' |
| 1091 |
fi # !PBS_ENVIRONMENT |
| 1092 |
fi # !PBS |
| 1093 |
if [ -n "${SLURM_JOBID}" ] && [ -z "${SLURM_PTY_PORT}" ]; then |
| 1094 |
# SLURM batch detection suggested by NERSC ticket INC0096873 on 20170127 |
| 1095 |
bch_slr='Yes' |
| 1096 |
fi # !SLURM |
| 1097 |
if [ ${bch_pbs} = 'Yes' ] || [ ${bch_slr} = 'Yes' ]; then |
| 1098 |
# Batch environment |
| 1099 |
if [ ${bch_pbs} = 'Yes' ]; then |
| 1100 |
if [ ! -p /dev/stdin ]; then |
| 1101 |
# PBS batch jobs cause -p to return true except for stdin redirection |
| 1102 |
# When -p returns true we do not know whether stdin pipe contains any input |
| 1103 |
# User must explicitly indicate use of stdin pipes with --stdin option |
| 1104 |
# Redirection in PBS batch jobs unambiguously causes -p to return false |
| 1105 |
inp_std='Yes' |
| 1106 |
fi # !stdin |
| 1107 |
fi # !bch_slr |
| 1108 |
if [ ${bch_slr} = 'Yes' ]; then |
| 1109 |
if [ -p /dev/stdin ]; then |
| 1110 |
# SLURM batch jobs cause -p to return true for stdin pipes |
| 1111 |
# When -p returns false we do not know whether output was redirected |
| 1112 |
# User must explicitly indicate use of redirection with --stdin option |
| 1113 |
# Stdin pipes in SLURM batch jobs unambiguously cause -p to return true |
| 1114 |
inp_std='Yes' |
| 1115 |
fi # !stdin |
| 1116 |
fi # !bch_slr |
| 1117 |
else # !bch |
| 1118 |
# Interactive environment |
| 1119 |
if [ -p /dev/stdin ] || [ ! -t 0 ]; then |
| 1120 |
# Interactive environments unambiguously cause -p to return true for stdin pipes |
| 1121 |
# Interactive environments unambiguously cause -t 0 to return false for stdin redirection |
| 1122 |
inp_std='Yes' |
| 1123 |
fi # !stdin |
| 1124 |
fi # !bch |
| 1125 |
if [ ${inp_std} = 'Yes' ] && [ ${inp_psn} = 'Yes' ]; then |
| 1126 |
echo "${spt_nm}: ERROR expecting input from both stdin and positional command-line arguments" |
| 1127 |
exit 1 |
| 1128 |
fi # !inp_std |
| 1129 |
fi # !std_chk |
| 1130 |
|
| 1131 |
# Determine mode first (this helps determine other defaults) |
| 1132 |
if [ -n "${yr_srt_prv}" ]; then |
| 1133 |
# Specifying only yr_srt_prv implies incremental method |
| 1134 |
# Specifying both yr_srt_prv and yr_end_prv implies binary method |
| 1135 |
xtn_flg='Yes' |
| 1136 |
if [ -n "${yr_end_prv}" ]; then |
| 1137 |
bnr_flg='Yes' |
| 1138 |
else # !yr_end_prv binary method |
| 1139 |
ncr_flg='Yes' |
| 1140 |
fi # !yr_end_prv binary method |
| 1141 |
fi # !yr_srt_prv extended climo |
| 1142 |
# Utilize user-specified model name, if any |
| 1143 |
if [ -n "${prc_typ}" ]; then |
| 1144 |
# 20201016: Supercede mdl_nm with prc_typ so both need not be explicitly invoked? |
| 1145 |
# EAM/ELM are difficult since history file name can be *cam*/*clm2* or *eam*/*elm* |
| 1146 |
# Instinct is to change mdl_nm so it only refers to name string in history file |
| 1147 |
# and must be provided only when that name string differs from default name string for prc_typ |
| 1148 |
prc_opt="-P ${prc_typ}" |
| 1149 |
mdl_nm="${prc_typ}" |
| 1150 |
# Exceptions to rule that mdl_nm == prc_typ |
| 1151 |
[[ "${prc_typ}" = 'clm' ]] && mdl_nm='clm2' |
| 1152 |
[[ "${prc_typ}" = 'sgs' ]] && mdl_nm='elm' |
| 1153 |
fi # !prc_typ |
| 1154 |
if [ -n "${mdl_nm_usr}" ]; then |
| 1155 |
mdl_nm="${mdl_nm_usr}" |
| 1156 |
fi # !mdl_nm_usr |
| 1157 |
if [ -n "${wnt_md_usr}" ]; then |
| 1158 |
printf "${spt_nm}: WARNING Winter mode (-a or --wnt_md) is no longer supported as of 202603 (NCO 5.3.7), and invoking it acts as a no-op for backwards compatibility to older scripts. Please alter your scripts to not invoke it. The same functionality is now accessed by providing datasets that start in December and invoking the --mth_srt=12 option.\n" |
| 1159 |
fi # !wnt_md_usr |
| 1160 |
if [ -n "${clm_md_usr}" ]; then |
| 1161 |
# Climo mode must be explicitly selected with --clm_md when climo input files are from stdin or positional |
| 1162 |
if [ "${clm_md_usr}" = 'ann' ] || [ "${clm_md_usr}" = 'annual' ] || [ "${clm_md_usr}" = 'yearly' ] || [ "${clm_md_usr}" = 'year' ]; then |
| 1163 |
clm_md_usr='ann' |
| 1164 |
fi # !clm_md_usr |
| 1165 |
if [ "${clm_md_usr}" = 'dly' ] || [ "${clm_md_usr}" = 'daily' ] || [ "${clm_md_usr}" = 'doy' ] || [ "${clm_md_usr}" = 'day' ]; then |
| 1166 |
clm_md_usr='dly' |
| 1167 |
fi # !clm_md_usr |
| 1168 |
if [ "${clm_md_usr}" = 'hfc' ] || [ "${clm_md_usr}" = 'high_frequency_climo' ] || [ "${clm_md_usr}" = 'hgh_frq_clm' ]; then |
| 1169 |
clm_md_usr='hfc' |
| 1170 |
fi # !clm_md_usr |
| 1171 |
if [ "${clm_md_usr}" = 'hfs' ] || [ "${clm_md_usr}" = 'high_frequency_splitter' ] || [ "${clm_md_usr}" = 'hgh_frq_spl' ]; then |
| 1172 |
clm_md_usr='hfs' |
| 1173 |
fi # !clm_md_usr |
| 1174 |
if [ "${clm_md_usr}" = 'mth' ] || [ "${clm_md_usr}" = 'month' ] || [ "${clm_md_usr}" = 'monthly' ]; then |
| 1175 |
clm_md_usr='mth' |
| 1176 |
fi # !clm_md_usr |
| 1177 |
clm_md="${clm_md_usr}" |
| 1178 |
fi # !clm_md_usr |
| 1179 |
if [ "${clm_md}" = 'hfc' ] || [ "${clm_md}" = 'mth' ]; then |
| 1180 |
clm_hfc_or_mth='Yes' |
| 1181 |
fi # !clm_md |
| 1182 |
if [ "${clm_md}" = 'dly' ] || [ "${clm_md}" = 'hfc' ]; then |
| 1183 |
unset dpm # Days per month |
| 1184 |
declare -a dpm |
| 1185 |
dpm=(0 31 28 31 30 31 30 31 31 30 31 30 31) # noleap 365-day calendar, 1-based indexing |
| 1186 |
fi # !clm_md |
| 1187 |
if [ -z "${drc_in}" ]; then |
| 1188 |
drc_in="${drc_pwd}" |
| 1189 |
else # !drc_in |
| 1190 |
if [ ! -d "${drc_in}" ]; then |
| 1191 |
echo "${spt_nm}: ERROR specified input directory \"${drc_in}\" does not exist" |
| 1192 |
exit 1 |
| 1193 |
fi # !drc_in |
| 1194 |
drc_in_usr_flg='Yes' |
| 1195 |
fi # !drc_in |
| 1196 |
|
| 1197 |
# Derived variables |
| 1198 |
if [ -n "${drc_out_usr}" ]; then |
| 1199 |
# Fancy %/ syntax removes trailing slash (e.g., from $TMPDIR) |
| 1200 |
drc_out="${drc_out_usr%/}" |
| 1201 |
fi # !drc_out_usr |
| 1202 |
if [ -n "${drc_rgr_usr}" ]; then |
| 1203 |
if [ -z "${rgr_map}" ]; then |
| 1204 |
printf "${spt_nm}: ERROR specified directory for regridded files without supplying map-file name for regridding\n" |
| 1205 |
printf "${spt_nm}: HINT Provide a map-file name with -m map.nc or --map=map.nc or remove the option (-O or --drc_rgr) that sets the directory for regridded files\n" |
| 1206 |
exit 1 |
| 1207 |
fi # !err |
| 1208 |
drc_rgr="${drc_rgr_usr%/}" |
| 1209 |
else |
| 1210 |
drc_rgr="${drc_out%/}" |
| 1211 |
fi # !drc_rgr_usr |
| 1212 |
if [ -n "${drc_prv}" ]; then |
| 1213 |
drc_prv="${drc_prv%/}" |
| 1214 |
else |
| 1215 |
if [ "${bnr_flg}" = 'Yes' ]; then |
| 1216 |
drc_prv="${drc_in}" |
| 1217 |
fi # !bnr_flg |
| 1218 |
if [ "${ncr_flg}" = 'Yes' ]; then |
| 1219 |
drc_prv="${drc_out}" |
| 1220 |
fi # !ncr_flg |
| 1221 |
fi # !drc_prv |
| 1222 |
if [ -n "${drc_xtn}" ]; then |
| 1223 |
drc_xtn="${drc_xtn%/}" |
| 1224 |
else |
| 1225 |
drc_xtn="${drc_prv}" |
| 1226 |
fi # !drc_xtn |
| 1227 |
|
| 1228 |
# Doubly-derived variables |
| 1229 |
if [ -n "${drc_rgr_prv}" ]; then |
| 1230 |
drc_rgr_prv="${drc_rgr_prv%/}" |
| 1231 |
else |
| 1232 |
drc_rgr_prv="${drc_prv%/}" |
| 1233 |
fi # !drc_rgr_prv |
| 1234 |
if [ -n "${drc_rgr_xtn}" ]; then |
| 1235 |
drc_rgr_xtn="${drc_rgr_xtn%/}" |
| 1236 |
else |
| 1237 |
drc_rgr_xtn="${drc_xtn%/}" |
| 1238 |
fi # !drc_rgr_xtn |
| 1239 |
|
| 1240 |
# Create output directories |
| 1241 |
if [ -n "${drc_out}" ] && [ ! -d "${drc_out}" ]; then |
| 1242 |
chr_fst=${drc_out:0:1} |
| 1243 |
if [ "${chr_fst}" = '-' ]; then |
| 1244 |
echo "${spt_nm}: ERROR Attempting to mkdir user-specified output directory \"${drc_out}\" will fail because directory name begins with '-' which is an option indicator" |
| 1245 |
echo "${spt_nm}: HINT Specify output directory name that does not begin with '-'" |
| 1246 |
exit 1 |
| 1247 |
fi # !chr_fst |
| 1248 |
cmd_mkd="mkdir -p ${drc_out}" |
| 1249 |
eval ${cmd_mkd} |
| 1250 |
if [ "$?" -ne 0 ]; then |
| 1251 |
printf "${spt_nm}: ERROR Failed to create output directory. Debug this:\n${cmd_mkd}\n" |
| 1252 |
printf "${spt_nm}: HINT Creating a directory requires proper write permissions\n" |
| 1253 |
exit 1 |
| 1254 |
fi # !err |
| 1255 |
fi # !drc_out |
| 1256 |
if [ -n "${drc_rgr}" ] && [ ! -d "${drc_rgr}" ]; then |
| 1257 |
chr_fst=${drc_rgr:0:1} |
| 1258 |
if [ "${chr_fst}" = '-' ]; then |
| 1259 |
echo "${spt_nm}: ERROR Attempting to mkdir user-specified regrid directory \"${drc_rgr}\" will fail because directory name begins with '-' which is an option indicator" |
| 1260 |
echo "${spt_nm}: HINT Specify regrid directory name that does not begin with '-'" |
| 1261 |
exit 1 |
| 1262 |
fi # !chr_fst |
| 1263 |
cmd_mkd="mkdir -p ${drc_rgr}" |
| 1264 |
eval ${cmd_mkd} |
| 1265 |
if [ "$?" -ne 0 ]; then |
| 1266 |
printf "${spt_nm}: ERROR Attempt to create regrid directory. Debug this:\n${cmd_mkd}\n" |
| 1267 |
printf "${spt_nm}: HINT Creating a directory requires proper write permissions\n" |
| 1268 |
exit 1 |
| 1269 |
fi # !err |
| 1270 |
fi # !drc_rgr |
| 1271 |
|
| 1272 |
# Define calendar |
| 1273 |
# Determine first full year |
| 1274 |
trim_leading_zeros ${yr_srt} |
| 1275 |
yr_srt_rth=${sng_trm} |
| 1276 |
yyyy_srt=`printf "%04d" ${yr_srt_rth}` |
| 1277 |
let yr_srtm1=${yr_srt_rth}-1 |
| 1278 |
let yr_srtp1=${yr_srt_rth}+1 |
| 1279 |
yyyy_srtp1=`printf "%04d" ${yr_srtp1}` |
| 1280 |
trim_leading_zeros ${yr_end} |
| 1281 |
yr_end_rth=${sng_trm} |
| 1282 |
yyyy_end=`printf "%04d" ${yr_end_rth}` |
| 1283 |
let yr_endm1=${yr_end_rth}-1 |
| 1284 |
let yr_endp1=${yr_end_rth}+1 |
| 1285 |
yyyy_endm1=`printf "%04d" ${yr_endm1}` |
| 1286 |
|
| 1287 |
if [ ${mth_srt} -eq '0' ]; then |
| 1288 |
echo "${spt_nm}: ERROR User-defined start month is ${mth_srt}. Please use 1-based (not 0-based) indexing for months, where [Jan..Dec] = [1..12]" |
| 1289 |
exit 1 |
| 1290 |
fi # !mth_srt |
| 1291 |
trim_leading_zeros ${mth_srt} |
| 1292 |
mth_srt_rth=${sng_trm} |
| 1293 |
mm_srt=`printf "%02d" ${mth_srt_rth}` |
| 1294 |
trim_leading_zeros ${mth_end} |
| 1295 |
mth_end_rth=${sng_trm} |
| 1296 |
mm_end=`printf "%02d" ${mth_end_rth}` |
| 1297 |
let mth_nbr=${yr_end_rth}*12+${mth_end_rth}-${yr_srt_rth}*12-${mth_srt_rth}+1 |
| 1298 |
let yr_nbr=${mth_nbr}/12 |
| 1299 |
# How many files/months from first month to first January? |
| 1300 |
if [ ${mth_srt_rth} -eq 1 ]; then |
| 1301 |
jan_fst=0 # [nbr] Offset of January from starting month |
| 1302 |
else |
| 1303 |
jan_fst=$(( 12 - ${mth_srt_rth} + 1 )) |
| 1304 |
fi # mth_srt_rth |
| 1305 |
let mth_srtm1=${mth_srt_rth}-1 # [idx] 1-based index of month preceding start month |
| 1306 |
let mth_endp1=${mth_end_rth}+1 |
| 1307 |
if [ ${mth_srtm1} -eq 0 ]; then |
| 1308 |
let mth_srtm1=12 |
| 1309 |
mm_srtm1='12' |
| 1310 |
else # !mth_srtm1 |
| 1311 |
mm_srtm1=`printf "%02d" ${mth_srtm1}` |
| 1312 |
fi # !mth_srtm1 |
| 1313 |
if [ ${mth_endp1} -eq 13 ]; then |
| 1314 |
let mth_endp1=1 |
| 1315 |
mm_endp1='01' |
| 1316 |
else # !mth_endp1 |
| 1317 |
mm_endp1=`printf "%02d" ${mth_endp1}` |
| 1318 |
fi # !mth_endp1 |
| 1319 |
if [ "${mm_srt}" != '01' ] || [ "${mm_end}" != '12' ]; then |
| 1320 |
mth_flg='Yes' |
| 1321 |
fi # !mm_srt |
| 1322 |
[ ${mth_flg} = 'Yes' ] && let yr_cln=${yr_nbr}+1 || yr_cln=${yr_nbr} |
| 1323 |
|
| 1324 |
# 20260323 |
| 1325 |
# Determine starting and ending year string for each month |
| 1326 |
for ((mth_idx=1;mth_idx<=12;mth_idx++)); do |
| 1327 |
if [ ${mth_idx} -ge ${mth_srt_rth} ]; then |
| 1328 |
yyyy_srt_mth[${mth_idx}]=${yyyy_srt} |
| 1329 |
else # !mth_idx |
| 1330 |
yyyy_srt_mth[${mth_idx}]=${yyyy_srtp1} |
| 1331 |
fi # !mth_idx |
| 1332 |
if [ ${mth_idx} -le ${mth_end_rth} ]; then |
| 1333 |
yyyy_end_mth[${mth_idx}]=${yyyy_end} |
| 1334 |
else # !mth_idx |
| 1335 |
yyyy_end_mth[${mth_idx}]=${yyyy_endm1} |
| 1336 |
fi # !mth_idx |
| 1337 |
done # !mth_idx |
| 1338 |
|
| 1339 |
# Define actions based on standard options |
| 1340 |
if [ -n "${caseid}" ]; then |
| 1341 |
out_nm=${caseid} |
| 1342 |
fi # !caseid |
| 1343 |
if [ "${caseid}" = 'hist' ] || [ "${mdl_nm}" = 'mali' ] || [ "${mdl_nm}" = 'mpas' ] || [ "${mdl_nm}" = 'mpaso' ] || [ "${mdl_nm}" = 'mpas-ocean' ] || [ "${mdl_nm}" = 'mpascice' ] || [ "${mdl_nm}" = 'mpasseaice' ] || [ "${mdl_nm}" = 'mpas-seaice' ] || [ "${mdl_nm}" = 'mpassi' ] || [ "${prc_typ}" = 'mali' ] || [ "${prc_typ}" = 'mpas' ] || [ "${prc_typ}" = 'mpasa' ] || [ "${prc_typ}" = 'mpasatmosphere' ] || [ "${prc_typ}" = 'mpaso' ] || [ "${prc_typ}" = 'mpas-ocean' ] || [ "${prc_typ}" = 'mpascice' ] || [ "${prc_typ}" = 'mpasseaice' ] || [ "${prc_typ}" = 'mpas-seaice' ] || [ "${prc_typ}" = 'mpassi' ]; then |
| 1344 |
mdl_typ='mpas' |
| 1345 |
nm_typ='mpas' |
| 1346 |
out_nm="${mdl_nm}" |
| 1347 |
hst_nm='hist' |
| 1348 |
fi # !caseid |
| 1349 |
if [ "${prc_typ}" = 'mpascice' ] || [ "${prc_typ}" = 'mpasseaice' ] || [ "${prc_typ}" = 'mpassi' ]; then |
| 1350 |
prc_mpas='Yes' |
| 1351 |
prc_mpasseaice='Yes' |
| 1352 |
fi # !prc_typ |
| 1353 |
if [ "${mdl_typ}" = 'mpas' ] && [ -z "${prc_opt}" ]; then |
| 1354 |
prc_typ='mpas' |
| 1355 |
prc_opt='-P mpas' |
| 1356 |
fi # !mdl_typ && prc_opt |
| 1357 |
# http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash |
| 1358 |
# http://stackoverflow.com/questions/17420994/bash-regex-match-string |
| 1359 |
# NB: Order and 'elif' ensure name matches only fullest rx |
| 1360 |
if [[ "${caseid}" =~ ^(.*)([0-9][0-9][0-9][0-9][01][0-9].nc.?)$ ]]; then |
| 1361 |
nm_typ='yyyymm' |
| 1362 |
elif [[ "${caseid}" =~ ^(.*)([0-9][0-9][0-9][0-9]-[01][0-9]-01.nc.?)$ ]]; then |
| 1363 |
nm_typ='yyyy-mm-01' |
| 1364 |
elif [[ "${caseid}" =~ ^(.*)([0-9][0-9][0-9][0-9]-[01][0-9]-01-00000.nc.?)$ ]]; then |
| 1365 |
nm_typ='yyyy-mm-01-00000' |
| 1366 |
elif [[ "${caseid}" =~ ^(.*)([0-9][0-9][0-9][0-9]-[01][0-9].nc.?)$ ]]; then |
| 1367 |
nm_typ='yyyy-mm' |
| 1368 |
fi # !caseid |
| 1369 |
if [ "${nm_typ}" = 'yyyymm' ] || [ "${nm_typ}" = 'yyyy-mm' ] || [ "${nm_typ}" = 'yyyy-mm-01' ] || [ "${nm_typ}" = 'yyyy-mm-01-00000' ]; then |
| 1370 |
bs_nm="${BASH_REMATCH[1]}" |
| 1371 |
bs_nm="$(basename ${bs_nm})" |
| 1372 |
bs_nm="${bs_nm%.*}" |
| 1373 |
[[ ${prc_typ} != 'eamxx' ]] && bs_nm="${bs_nm%_*}" |
| 1374 |
out_nm=${bs_nm} |
| 1375 |
# https://stackoverflow.com/questions/12426659/how-extract-last-part-of-string-in-bash |
| 1376 |
bs_sfx="${caseid##*.}" |
| 1377 |
fi # !nm_typ |
| 1378 |
if [ -n "${fml_nm_usr}" ]; then |
| 1379 |
fml_nm="${fml_nm_usr}" |
| 1380 |
out_nm="${fml_nm}" |
| 1381 |
fi # !fml_nm |
| 1382 |
|
| 1383 |
# Determine whether to compute climos or to split |
| 1384 |
# Original behavior: |
| 1385 |
# Until 20211109, stdin and positional always indicated splitter even when ypf was not set |
| 1386 |
# New ability to do monthly climos with filenames provided by stdin, positional, or globbing necessitated modifications to original algorithm to determine climo vs. splitter |
| 1387 |
# As of 20211129, default behavior is to compute climo |
| 1388 |
# One of three methods may be used to invoke the splitter: |
| 1389 |
# 1) Use --split flag. 2) Select clm_md=hfs. 3) Set ypf_max. |
| 1390 |
# NB: clm_md='mth' indicates only the averaging period of a single input file |
| 1391 |
# clm_md='mth' is true for both monthly splitter and monthly climo :( |
| 1392 |
# Rest of code relies on (mutually exclusive) clm_flg to compute climo and tms_flg to invoke splitter |
| 1393 |
if [ "${tms_flg}" = 'Yes' ] || [ "${clm_md}" = 'hfs' ] || [ -n "${ypf_max_usr}" ]; then |
| 1394 |
tms_flg='Yes' |
| 1395 |
clm_flg='No' |
| 1396 |
if [ -n "${ypf_max_usr}" ]; then |
| 1397 |
ypf_max=${ypf_max_usr} |
| 1398 |
fi # !ypf_max_usr |
| 1399 |
fi # !tms_flg |
| 1400 |
|
| 1401 |
# Determine input method, if not already known |
| 1402 |
if [ ${inp_psn} = 'No' ] && [ ${inp_std} = 'No' ] && [ "${drc_in_usr_flg}" = 'Yes' ]; then |
| 1403 |
# 20220129 Determine whether to construct (use inp_aut) or glob files |
| 1404 |
# Daily (or finer) resolution filenames are never constructible |
| 1405 |
# Monthly input filenames are constructable with caseid |
| 1406 |
# Assume user wishes to glob unless both are provided caseid for monthly files |
| 1407 |
# 20211207 Specifying mpas name type (like MPAS-Analysis does) also implies inp_aut |
| 1408 |
if [[ ( ${clm_md} = 'mth' && -n "${caseid}" ) || ${nm_typ} = 'mpas' ]]; then |
| 1409 |
inp_aut='Yes' |
| 1410 |
else # !mth |
| 1411 |
inp_glb='Yes' |
| 1412 |
fi # !caseid |
| 1413 |
fi # !inp_* |
| 1414 |
if [ ${clm_flg} = 'Yes' ] && [ ${clm_md} = 'ann' ]; then |
| 1415 |
inp_aut='Yes' |
| 1416 |
inp_glb='No' |
| 1417 |
inp_std='No' # fxm: 20170123 hack for false positives in non-interactive batch mode on PBS |
| 1418 |
fi # !clm_flg |
| 1419 |
if [ ${clm_flg} = 'Yes' ] && [ ${clm_md} = 'dly' ] && [ ${inp_psn} = 'No' ] && [ ${inp_std} = 'No' ] && [ "${drc_in_usr_flg}" = 'Yes' ]; then |
| 1420 |
inp_aut='No' |
| 1421 |
inp_glb='Yes' |
| 1422 |
fi # !clm_flg, !dly |
| 1423 |
# One of these input file options must be true, or else... |
| 1424 |
if [ ${inp_aut} = 'No' ] && [ ${inp_glb} = 'No' ] && [ ${inp_psn} = 'No' ] && [ ${inp_std} = 'No' ]; then |
| 1425 |
echo "${spt_nm}: ERROR No input data files found" |
| 1426 |
echo "${spt_nm}: HINT Specify input file(s) by providing option \"-i \$drc_in\" with (for automatic filename construction) or without (for globbing entire directory) \"-c \$caseid\", or provide names via positional argument(s) or stdin" |
| 1427 |
if [ ${bch_pbs} = 'Yes' ]; then |
| 1428 |
echo "${spt_nm}: HINT PBS batch job environment detected, pipe to stdin not allowed, try positional arguments instead" |
| 1429 |
else # !bch_pbs |
| 1430 |
echo "${spt_nm}: HINT Provide a list of lengthy or complex filenames as a pipe to stdin with, e.g., 'ls *.nc | ${spt_nm}'" |
| 1431 |
fi # !bch_pbs |
| 1432 |
exit 1 |
| 1433 |
fi # !tms_flg |
| 1434 |
if [ "${inp_aut}" != 'Yes' ] && [ -z "${mdl_nm_usr}" ]; then |
| 1435 |
mdl_nm='nil' # Unset default model name for stdin pipe and positional arguments, otherwise default mdl_nm could be used to add model-specific variables to var_xtr |
| 1436 |
fi # !inp_aut !mdl_nm_usr |
| 1437 |
# clm_flg and tms_flg and all input file pre-requisite parameters are now set. Ready to gather input filenames. |
| 1438 |
|
| 1439 |
# Obtain filenames from automatic generation, directory glob, positional arguments, or stdin pipe |
| 1440 |
#printf "dbg: inp_aut = ${inp_aut}, inp_glb = ${inp_glb}, inp_psn = ${inp_psn}, inp_std = ${inp_std}\n" |
| 1441 |
# End input mode determination block |
| 1442 |
|
| 1443 |
if [ "${clm_flg}" = 'Yes' ] && [ -z "${out_nm}" ] && [ -z "${fml_nm}" ]; then |
| 1444 |
printf "${spt_nm}: ERROR ${spt_nm} User requested climatology generation yet invoked neither \$caseid nor \$fml_nm options nor specified a supported automatic name-generation option (e.g., --mdl=mpaso for MPAS) so ${spt_nm} does not know what to name the output files\n" |
| 1445 |
printf "${spt_nm}: HINT Use \"--caseid=name\" or \"--fml_nm=name\" to provide a name for the output files. If the input files are provided via stdin, positional arguments, or globbing then the name string will only be used for output names and need not be present in any of the input filenames\n" |
| 1446 |
fi # !out_nm |
| 1447 |
if [ "${clm_md}" != 'ann' ] && [ "${clm_md}" != 'dly' ] && [ "${clm_md}" != 'hfc' ] && [ "${clm_md}" != 'hfs' ] && [ "${clm_md}" != 'mth' ]; then |
| 1448 |
echo "${spt_nm}: ERROR User-defined climatology mode is ${clm_md}. Valid options are 'ann', 'dly', hfc', 'hfs', and 'mth' (default)" |
| 1449 |
exit 1 |
| 1450 |
fi # !clm_md |
| 1451 |
if [ "${clm_md}" = 'ann' ]; then |
| 1452 |
clm_nbr=1 |
| 1453 |
elif [ "${clm_md}" = 'dly' ]; then |
| 1454 |
clm_nbr=${dpy} |
| 1455 |
elif [ "${clm_hfc_or_mth}" = 'Yes' ]; then |
| 1456 |
clm_nbr=12 |
| 1457 |
csn_flg='Yes' |
| 1458 |
if [ ${csn_lst} = 'none' ]; then |
| 1459 |
csn_nbr=0 |
| 1460 |
csn_flg='No' |
| 1461 |
fi # !csn_lst |
| 1462 |
fi # !clm_md |
| 1463 |
if [ -z "${gaa_sng_std}" ]; then |
| 1464 |
if [ "${clm_flg}" = 'Yes' ]; then |
| 1465 |
echo "${spt_nm}: INFO User-defined global attributes string is empty. Diagnostics routines (such as E3SM Diagnostics) that depend on these attributes may not work." |
| 1466 |
fi # !clm_flg |
| 1467 |
fi # !gaa_sng_std |
| 1468 |
if [ -n "${job_usr}" ]; then |
| 1469 |
job_nbr="${job_usr}" |
| 1470 |
fi # !job_usr |
| 1471 |
if [ -n "${fl_fmt}" ]; then |
| 1472 |
if [ "${fl_fmt}" = '3' ] || [ "${fl_fmt}" = 'classic' ] || [ "${fl_fmt}" = 'netcdf3' ]; then |
| 1473 |
nco_fl_fmt='--fl_fmt=classic' |
| 1474 |
elif [ "${fl_fmt}" = '4' ] || [ "${fl_fmt}" = 'netcdf4' ] || [ "${fl_fmt}" = 'hdf5' ]; then |
| 1475 |
nco_fl_fmt='--fl_fmt=netcdf4' |
| 1476 |
elif [ "${fl_fmt}" = '5' ] || [ "${fl_fmt}" = '64bit_data' ] || [ "${fl_fmt}" = 'cdf5' ]; then |
| 1477 |
nco_fl_fmt='--fl_fmt=64bit_data' |
| 1478 |
elif [ "${fl_fmt}" = '6' ] || [ "${fl_fmt}" = '64bit_offset' ] || [ "${fl_fmt}" = '64' ]; then |
| 1479 |
nco_fl_fmt='--fl_fmt=64bit_offset' |
| 1480 |
elif [ "${fl_fmt}" = '7' ] || [ "${fl_fmt}" = 'netcdf4_classic' ]; then |
| 1481 |
nco_fl_fmt='--fl_fmt=netcdf4_classic' |
| 1482 |
else |
| 1483 |
echo "${spt_nm}: ERROR User-supplied file-format specifier fl_fmt='${fl_fmt}' is invalid" |
| 1484 |
echo "${spt_nm}: HINT Valid format-specifiers include '3', '4', '5', '6', and '7'" |
| 1485 |
exit 1 |
| 1486 |
fi # !fl_fmt |
| 1487 |
nco_opt="${nco_fl_fmt} ${nco_opt}" |
| 1488 |
fi # !fl_fmt |
| 1489 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 1490 |
nco_opt="--dbg_lvl=${dbg_lvl} ${nco_opt}" |
| 1491 |
fi # !dbg_lvl |
| 1492 |
# 20240617 var_lst for timeseries mode must be and is processed separately in timeseries block |
| 1493 |
if [ -n "${var_lst}" ] && [ "${tms_flg}" != 'Yes' ]; then |
| 1494 |
if [ "${xcl_flg}" = 'Yes' ]; then |
| 1495 |
nco_opt="${nco_opt} -x" |
| 1496 |
fi # !xcl_flg |
| 1497 |
nco_opt="${nco_opt} -v ${var_lst}" |
| 1498 |
fi # !var_lst |
| 1499 |
if [ -n "${bfr_sz}" ]; then |
| 1500 |
nco_opt="${nco_opt} --bfr_sz=${bfr_sz}" |
| 1501 |
fi # !bfr_sz |
| 1502 |
if [ -n "${cmp_sng}" ]; then |
| 1503 |
# 20230623: Insert backslashes to protect pipe characters from shell |
| 1504 |
nco_opt="${nco_opt} --cmp=${cmp_sng//\|/\\|}" |
| 1505 |
fi # !cmp_sng |
| 1506 |
if [ -n "${dfl_lvl}" ]; then |
| 1507 |
nco_opt="${nco_opt} --dfl_lvl=${dfl_lvl}" |
| 1508 |
fi # !dfl_lvl |
| 1509 |
if [ -n "${qnt_prc}" ]; then |
| 1510 |
nco_opt="${nco_opt} --qnt default=${qnt_prc}" |
| 1511 |
fi # !qnt_prc |
| 1512 |
if [ -n "${hdr_pad}" ]; then |
| 1513 |
nco_opt="${nco_opt} --hdr_pad=${hdr_pad}" |
| 1514 |
fi # !hdr_pad |
| 1515 |
if [ -n "${uio_flg}" ]; then |
| 1516 |
nco_opt="${nco_opt} --unbuffered_io" |
| 1517 |
fi # !uio_flg |
| 1518 |
if [ "${no_cll_msr}" = 'Yes' ]; then |
| 1519 |
spl_opt="${spl_opt} --no_cll_msr" |
| 1520 |
fi # !no_cll_msr |
| 1521 |
if [ "${no_frm_trm}" = 'Yes' ]; then |
| 1522 |
spl_opt="${spl_opt} --no_frm_trm" |
| 1523 |
fi # !no_frm_trm |
| 1524 |
if [ "${no_stg_grd}" = 'Yes' ]; then |
| 1525 |
spl_rgr_opt='' |
| 1526 |
fi # !no_stg_grd |
| 1527 |
if [ "${par_typ}" = ${par_bck} ] || [[ "${par_typ}" =~ [bB]ck ]] || [[ "${par_typ}" =~ [bB]ackground ]]; then |
| 1528 |
par_typ=${par_bck} |
| 1529 |
par_opt=' &' |
| 1530 |
elif [ "${par_typ}" = ${par_mpi} ] || [[ "${par_typ}" =~ (mpi|MPI) ]]; then |
| 1531 |
par_typ=${par_mpi} |
| 1532 |
par_opt=' &' |
| 1533 |
mpi_flg='Yes' |
| 1534 |
elif [ "${par_typ}" = ${par_srl} ] || [ "${par_typ}" = 'srl' ] || [[ "${par_typ}" =~ [sS]erial ]] || [[ "${par_typ}" =~ [nN]il ]] || [[ "${par_typ}" =~ [nN]one ]]; then |
| 1535 |
par_typ=${par_srl} |
| 1536 |
else |
| 1537 |
echo "ERROR: Invalid -p par_typ option = ${par_typ}" |
| 1538 |
echo "HINT: Valid par_typ arguments for file-level parallelism include '${par_bck}' (or 'bck'), '${par_mpi}' (or 'MPI'), and '${par_srl}' (or 'srl' or 'nil' or 'none'). For background parallelism, select '${par_bck}' which causes ${spt_nm} to spawn parallel processes as background tasks on a single node. For MPI parallelism, select '${par_mpi}' which causes ${spt_nm} to spawn parallel processes on across available cluster nodes. For no parallelism (aka serial mode), select '${par_srl}', which causes ${spt_nm} to spawn all processes serially on a single compute node." |
| 1539 |
exit 1 |
| 1540 |
fi # !par_typ |
| 1541 |
if [ -n "${rgr_opt_usr}" ]; then |
| 1542 |
rgr_opt="${rgr_opt_usr}" |
| 1543 |
rmp_opt="-R \'${rgr_opt_usr}\'" |
| 1544 |
fi # !rgr_opt_usr |
| 1545 |
if [ -n "${rgr_map}" ]; then |
| 1546 |
if [ ! -f "${rgr_map}" ] && [ ! -L "${rgr_map}" ]; then |
| 1547 |
echo "${spt_nm}: ERROR Unable to find specified regrid map ${rgr_map}" |
| 1548 |
echo "${spt_nm}: HINT Supply the full path-name for the regridding map" |
| 1549 |
exit 1 |
| 1550 |
fi # ! -f |
| 1551 |
if [ "${mdl_nm}" = 'clm2' ] || [ "${mdl_nm}" = 'elm' ] && [ -z "${sgs_frc}" ]; then |
| 1552 |
printf "${spt_nm}: WARNING ${spt_nm} CLM/ELM output typically uses sub-gridscale (SGS) fractions that can only be properly renormalized if the SGS variable option to ncclimo is invoked, but that option was not invoked\n" |
| 1553 |
printf "${spt_nm}: HINT Provide ${spt_nm} with the SGS fraction variable using the \"--sgs_frc=\${sgs_frc_nm}\" option, otherwise the regridded data will likely not be properly or conservatively regridded\n" |
| 1554 |
fi # !mdl_nm |
| 1555 |
map_opt="--map=${rgr_map}" |
| 1556 |
rgr_opt="${rgr_opt} ${map_opt}" |
| 1557 |
rmp_opt="${rmp_opt} ${map_opt}" |
| 1558 |
else # !rgr_map |
| 1559 |
if [ -n "${dpt_opt}" ]; then |
| 1560 |
echo "${spt_nm}: ERROR Cannot add depth coordinate unless horizontal regridding is invoked" |
| 1561 |
echo "${spt_nm}: HINT Specify a regridding map or run add_depth.py on these files yourself. To request that add_depth.py work directly in ncclimo, contact Charlie." |
| 1562 |
exit 1 |
| 1563 |
fi # !dpt_opt |
| 1564 |
fi # !rgr_map |
| 1565 |
if [ "${tms_flg}" = 'Yes' ]; then |
| 1566 |
# 20190419: Splitter typically writes 1--3 multi-dimensional fields into each output file |
| 1567 |
# OpenMP incurs significant RAM overhead that may not be worthwhile |
| 1568 |
# New default is 1 regridding thread for splitter |
| 1569 |
# Users can override this splitter-only default by explicitly requesting multiple threads |
| 1570 |
thr_nbr=1 # [nbr] Thread number for regridder |
| 1571 |
fi # !tms_flg |
| 1572 |
if [ -n "${sgs_frc}" ]; then |
| 1573 |
sgs_opt="--rgr sgs_frc_nm=${sgs_frc}" |
| 1574 |
rgr_opt="${rgr_opt} ${sgs_opt}" |
| 1575 |
rmp_opt="--sgs_frc=${sgs_frc} ${rmp_opt}" |
| 1576 |
fi # !sgs_frc |
| 1577 |
if [ -n "${thr_usr}" ]; then |
| 1578 |
thr_nbr="${thr_usr}" |
| 1579 |
fi # !thr_usr |
| 1580 |
if [ -n "${tpd_usr}" ]; then |
| 1581 |
tpd_out="${tpd_usr}" |
| 1582 |
fi # !tpd_usr |
| 1583 |
if [ -n "${vrt_out}" ]; then |
| 1584 |
if [ ! -f "${vrt_out}" ] && [ ! -L "${vrt_out}" ]; then |
| 1585 |
echo "ERROR: Unable to find specified vertical coordinate file ${vrt_out}" |
| 1586 |
exit 1 |
| 1587 |
fi # ! -f |
| 1588 |
vrt_opt="--vrt_out=${vrt_out}" |
| 1589 |
rmp_opt="--vrt_out=${vrt_out} ${rmp_opt}" |
| 1590 |
if [ -n "${vrt_xtr}" ]; then |
| 1591 |
if [ ${vrt_xtr} = 'mss_val' ] || [ ${vrt_xtr} = 'missing_value' ] || [ ${vrt_xtr} = 'msv' ]; then |
| 1592 |
vrt_opt="--rgr xtr_mth=mss_val ${vrt_opt}" |
| 1593 |
rmp_opt="--xtr_mth=mss_val ${rmp_opt}" |
| 1594 |
elif [ ${vrt_xtr} = 'nrs_ngh' ] || [ ${vrt_xtr} = 'nearest_neighbor' ] || [ ${vrt_xtr} = 'nn' ]; then |
| 1595 |
vrt_opt="--rgr xtr_mth=nrs_ngh ${vrt_opt}" |
| 1596 |
rmp_opt="--xtr_mth=nrs_ngh ${rmp_opt}" |
| 1597 |
else |
| 1598 |
echo "${spt_nm}: ERROR ${vrt_xtr} is not a valid extrapolation method" |
| 1599 |
echo "${spt_nm}: HINT Valid vertical extrapolation methods and synonyms are mss_val,missing_value,msv | nrs_ngh,nearest_neighbor,nn" |
| 1600 |
exit 1 |
| 1601 |
fi # !vrt_xtr |
| 1602 |
fi # !vrt_xtr |
| 1603 |
rgr_opt="${rgr_opt} ${vrt_opt}" |
| 1604 |
fi # !vrt_out |
| 1605 |
yyyy_clm_srt=${yyyy_srt} |
| 1606 |
yyyy_clm_end=${yyyy_end} |
| 1607 |
yyyy_clm_srt_dec=${yyyy_srt} |
| 1608 |
yyyy_clm_end_dec=${yyyy_end} |
| 1609 |
mm_ann_srt='01' # [idx] First month used in annual climatology |
| 1610 |
mm_ann_end='12' # [idx] Last month used in annual climatology |
| 1611 |
mm_djf_srt='01' # [idx] First month used in DJF climatology |
| 1612 |
mm_djf_end='12' # [idx] Last month used in DJF climatology |
| 1613 |
|
| 1614 |
# 20231221: Automatically generate input filename list based on command-line options |
| 1615 |
if [ ${inp_aut} = 'Yes' ] && [ ${clm_md} = 'mth' ] || [ ${clm_md} = 'ann' ]; then |
| 1616 |
fl_nbr=0 |
| 1617 |
yr_srt_all=${yyyy_srt} |
| 1618 |
yr_end_all=${yyyy_end} |
| 1619 |
# Bash brace expansion like {1..12} only works with naked numbers. Variables must use seq(). |
| 1620 |
for yr in `seq ${yr_srt_all} ${yr_end_all}`; do |
| 1621 |
YYYY=`printf "%04d" ${yr}` |
| 1622 |
clm_idx=0 |
| 1623 |
if [ "${clm_md}" = 'ann' ]; then |
| 1624 |
fl_in[${fl_nbr}]="${caseid}.${mdl_nm}.${hst_nm}.${YYYY}-${ann_sfx}.nc" |
| 1625 |
let fl_nbr=${fl_nbr}+1; |
| 1626 |
continue; |
| 1627 |
fi # !ann |
| 1628 |
for mth in {01..12}; do |
| 1629 |
let clm_idx=${clm_idx}+1 |
| 1630 |
MM=`printf "%02d" ${clm_idx}` |
| 1631 |
# Only construct filenames for months that are used |
| 1632 |
# 20260410 this statements should be triggered during climos! |
| 1633 |
if [ ${mth_flg} = 'Yes' ] && [ ${yr} -eq ${yr_srt_all} ] && [ ${MM} -lt ${mth_srt_rth} ]; then continue; fi |
| 1634 |
if [ ${mth_flg} = 'Yes' ] && [ ${yr} -eq ${yr_end_all} ] && [ ${MM} -gt ${mth_end_rth} ]; then continue; fi |
| 1635 |
if [ ${nm_typ} = 'cesm' ]; then |
| 1636 |
fl_in[${fl_nbr}]="${caseid}.${mdl_nm}.${hst_nm}.${YYYY}-${MM}.nc" |
| 1637 |
elif [ ${nm_typ} = 'mpas' ]; then # Use MPAS not CESM conventions |
| 1638 |
if [ ${mdl_nm} = 'mali' ]; then |
| 1639 |
fl_in[${fl_nbr}]="${mdl_nm}.${hst_nm}.${YYYY}-${MM}-01_00000.nc" |
| 1640 |
else # !mdl_nm |
| 1641 |
# 20161130: Really old MPAS rule until today (for pre-v1 data) |
| 1642 |
# fl_in[${fl_nbr}]="${caseid}.${mdl_nm}.${YYYY}-${MM}-01_00.00.00.nc" |
| 1643 |
# 20240619: Newer though still old MPAS rule until today (for v1 data) |
| 1644 |
# Example file: /scratch2/scratchdirs/golaz/ACME_simulations/20161117.beta0.A_WCYCL1850S.ne30_oEC_ICG.edison/run/mpascice.hist.am.timeSeriesStatsMonthly.0001-02-01.nc |
| 1645 |
fl_in[${fl_nbr}]="${mdl_nm}.hist.am.timeSeriesStatsMonthly.${YYYY}-${MM}-01.nc" |
| 1646 |
# 20240619: Latest MPAS rule (for v2+ data) prepends caseid |
| 1647 |
if [ "${caseid}" != '' ]; then |
| 1648 |
fl_in[${fl_nbr}]="${caseid}.${fl_in[${fl_nbr}]}" |
| 1649 |
fi # !caseid |
| 1650 |
fi # !mdl_nm |
| 1651 |
elif [ ${nm_typ} = 'yyyymm' ]; then # Generate from caseid + YYYYMM |
| 1652 |
fl_in[${fl_nbr}]="${bs_nm}_${YYYY}${MM}.${bs_sfx}" |
| 1653 |
elif [ ${nm_typ} = 'yyyy-mm' ]; then # Generate from caseid + YYYY-MM |
| 1654 |
fl_in[${fl_nbr}]="${bs_nm}.${YYYY}-${MM}.${bs_sfx}" |
| 1655 |
elif [ ${nm_typ} = 'yyyy-mm-01' ]; then # Generate from caseid + YYYY-MM-01 |
| 1656 |
fl_in[${fl_nbr}]="${bs_nm}.${YYYY}-${MM}-01.${bs_sfx}" |
| 1657 |
elif [ ${nm_typ} = 'yyyy-mm-01-00000' ]; then # Generate from caseid + YYYY-MM-01-00000 |
| 1658 |
# fl_in[${fl_nbr}]="${caseid}.${mdl_nm}.${hst_nm}.${YYYY}-${MM}-01-00000.${bs_sfx}" |
| 1659 |
fl_in[${fl_nbr}]="${bs_nm}.${YYYY}-${MM}-01-00000.${bs_sfx}" |
| 1660 |
fi # !cesm |
| 1661 |
let fl_nbr=${fl_nbr}+1 |
| 1662 |
done # !mth |
| 1663 |
done # !yr |
| 1664 |
fi # !inp_aut |
| 1665 |
if [ ${inp_glb} = 'Yes' ]; then |
| 1666 |
for fl in "${drc_in}"/*.nc "${drc_in}"/*.nc3 "${drc_in}"/*.nc4 "${drc_in}"/*.nc5 "${drc_in}"/*.nc6 "${drc_in}"/*.nc7 "${drc_in}"/*.cdf "${drc_in}"/*.hdf "${drc_in}"/*.he5 "${drc_in}"/*.h5 ; do |
| 1667 |
if [ -f "${fl}" ] || [ -L "${fl}" ]; then |
| 1668 |
fl_in[${fl_nbr}]=$(basename ${fl}) # NB: ncclimo uses basename($fl) here, and ppn_opt later, unlike ncremap |
| 1669 |
let fl_nbr=${fl_nbr}+1 |
| 1670 |
fi # !file |
| 1671 |
done |
| 1672 |
fi # !inp_glb |
| 1673 |
if [ ${inp_psn} = 'Yes' ]; then |
| 1674 |
# Read any positional arguments |
| 1675 |
for ((psn_idx=1;psn_idx<=psn_nbr;psn_idx++)); do |
| 1676 |
fl_in[(${psn_idx}-1)]=${!psn_idx} |
| 1677 |
fl_nbr=${psn_nbr} |
| 1678 |
done # !psn_idx |
| 1679 |
fi # !inp_psn |
| 1680 |
if [ ${inp_std} = 'Yes' ]; then |
| 1681 |
# Input awaits on unit 0, i.e., on stdin |
| 1682 |
while read -r line; do # NeR05 p. 179 |
| 1683 |
fl_in[${fl_nbr}]=${line} |
| 1684 |
let fl_nbr=${fl_nbr}+1 |
| 1685 |
done < /dev/stdin |
| 1686 |
fi # !inp_std |
| 1687 |
|
| 1688 |
# Sanity check that input files were found |
| 1689 |
if [ ${fl_nbr} -eq 0 ] || [ -z ${fl_in[0]} ]; then |
| 1690 |
printf "${spt_nm}: ERROR No input files were found: \$fl_nbr=${fl_nbr}, \${fl_in[0]}=\"${fl_in[0]}\". At least one input file is required. Please re-examine your input file specification.\n" |
| 1691 |
printf "The input method employed is the one whose value is \"Yes\": inp_aut = ${inp_aut}, inp_glb = ${inp_glb}, inp_psn = ${inp_psn}, inp_std = ${inp_std}.\n" |
| 1692 |
if [ ${inp_std} = 'Yes' ]; then |
| 1693 |
printf "${spt_nm}: HINT Expecting input from stdin. If you did not intend to provide input files on stdin, then perhaps ${spt_nm} a parent process (e.g., batch queue system or parent script) is controlling stdin. This can lead ${spt_nm} to expect input filenames on stdin. To prevent this from occurring, trying invoking with the --no_stdin switch, i.e., \'${spt_nm} --no_stdin ...\'.\n" |
| 1694 |
fi # inp_std |
| 1695 |
exit 1 |
| 1696 |
fi # !fl_nbr |
| 1697 |
|
| 1698 |
# Sanity check that monthly climatologies received a multiple of twelve files |
| 1699 |
# Automatically generated filenames have always adhered to this requirement |
| 1700 |
# 20250509: Provision of filenames via other methods never checked this until NCO 5.3.4 |
| 1701 |
if [ ${clm_flg} = 'Yes' ] && [ ${clm_md} = 'mth' ]; then |
| 1702 |
fpy=12 |
| 1703 |
let fl_rmd=${fl_nbr}%${fpy} |
| 1704 |
if [ ${fl_rmd} -ne 0 ]; then |
| 1705 |
printf "${spt_nm}: ERROR User requested climatology of monthly files and supplied ${fl_nbr} (not a multiple of 12) input files.\n" |
| 1706 |
printf "${spt_nm}: HINT Climatologies of monthly resolution data are only supported for whole numbers of years, not partial years. Provide monthly input files in multiples of 12. Use the --mth_srt (default 1) and --mth_end (default 12) options to indicate the starting and ending months if the first year does not start in January.\n" |
| 1707 |
exit 1 |
| 1708 |
fi # !fl_rmn |
| 1709 |
fi # !clm_flg, !clm_md |
| 1710 |
|
| 1711 |
# Prepend drc_in to fl_in in MFOs (ncra, ncrcat) |
| 1712 |
# 20240401 Also prepend drc_in to fl_in in SFOs (ncks, ncap2) used in hfc/hfs modes and in rgn_stt |
| 1713 |
# Otherwise operators will fail to find input files when cwd != drc_in |
| 1714 |
ppn_opt="-p ${drc_in}" |
| 1715 |
# 20220111 If input files include absolute path, then use fl_in as-is later on |
| 1716 |
if [ "${fl_in[0]}" ]; then |
| 1717 |
if [ "$(basename ${fl_in[0]})" != "${fl_in[0]}" ] || [ "${fl_in[0]:0:1}" = '/' ]; then |
| 1718 |
ppn_opt='' |
| 1719 |
fi # !basename |
| 1720 |
fi # !fl_in[0] |
| 1721 |
|
| 1722 |
if [ ${clm_md} = 'hfc' ] || [ ${clm_md} = 'hfs' ]; then |
| 1723 |
if [ -z "${tpd_usr}" ]; then |
| 1724 |
# User requested high-frequency mode and did not specify tpd so (try to) infer it |
| 1725 |
# Examine bounds of second timestep in case first timestep is instantaneous (e.g., restart values) |
| 1726 |
tm_var='time' |
| 1727 |
tm_bnd=`ncks --trd -M -m -v ${tm_var} ${ppn_opt} ${fl_in[0]} | grep -E -i "^${tm_var} attribute [0-9]+: bounds" | cut -f 11- -d ' ' | sed 's/^ *//g'` |
| 1728 |
if [ -z "${tm_bnd}" ]; then |
| 1729 |
# 20250509 Use time-coordinate values when time bounds DNE |
| 1730 |
tm_bnd_flg='No' |
| 1731 |
#printf "${spt_nm}: ERROR High-frequency mode needs but failed to find bounds variable for record coordinate named \"${tm_var}\" in input file \"${fl_in[0]}\". CF requires bounds variable name to be specified as value of \"bounds\" attribute of coordinate used for time-mean output. Typically record bounds variable is named \"time_bnds\" or \"time_bounds\".\nHINT: A workaround, that also works for temporally instantaneous data (e.g., cell_methods=\"time: point\") that lacks a time bounds variable, is to explicitly specify the number of timesteps-per-day in every input file with the --tpd=\$tpd option.\n" |
| 1732 |
#exit 1 |
| 1733 |
fi # !tm_bnd |
| 1734 |
# 20201220: Using %g not %f in format results in tpd=10 not tpd=8 for 3-hourly EAM data! |
| 1735 |
# 20210815: Prefer to hyperslab second time index since some files contain an "instantaneous" (i.e., zero-duration) first timestep. |
| 1736 |
# However this presumes file has multiple timesteps---fails with monthly data |
| 1737 |
# 20210902: Use first time index if file has only one timestep |
| 1738 |
tm_nbr=`ncks --trd -M ${ppn_opt} ${fl_in[0]} | grep -E -i "^Root record dimension 0:" | cut -f 10- -d ' '` |
| 1739 |
if [ "${tm_bnd_flg}" = 'Yes' ]; then |
| 1740 |
[ "${tm_nbr}" -gt 1 ] 2>/dev/null && tm_idx='1' || tm_idx='0' |
| 1741 |
tpd_out=`ncks --trd -H -s '%25.15f ' -v ${tm_bnd} -d ${tm_var},${tm_idx} -C ${ppn_opt} ${fl_in[0]} | awk '{ print 1.0/($2-$1); exit }'` |
| 1742 |
else # !tm_bnd_flg |
| 1743 |
if [ "${tm_nbr}" -le 1 ]; then |
| 1744 |
printf "${spt_nm}: ERROR High-frequency mode needs to know temporal resolution in timesteps-per-day and user did not did not explicitly specify the number of timesteps-per-day with the --tpd=\$tpd option. Therefore ${spt_nm} attempted to infer it. No time bounds variable was found for the record coordinate named \"${tm_var}\" in input file \"${fl_in[0]}\", therefore ${spt_nm} attempted to infer tpd from the interval between the first two values of \"${tm_var}\". However the time coordinate has only one value in the first input file so no time interval could be computed.\nHINT: Put multiple timesteps in the first input file and/or add a time bounds variable to it.\n" |
| 1745 |
exit 1 |
| 1746 |
fi # !tm_nbr |
| 1747 |
tpd_out=`ncks --trd -H -s '%25.15f ' -v ${tm_var} -d ${tm_var},0,1 -C ${ppn_opt} ${fl_in[0]} | awk '{ print 1.0/($2-$1); exit }'` |
| 1748 |
fi # !tm_bnd_flg |
| 1749 |
# Ensure result is positive integer |
| 1750 |
[ "${tpd_out}" -ge 0 ] 2>/dev/null && tpd_ntg='Yes' || tpd_ntg='No' |
| 1751 |
if [ "${tpd_ntg}" != 'Yes' ]; then |
| 1752 |
printf "${spt_nm}: ERROR Inferred value of tpd=${tpd_out} is not a positive integer. User requested high-frequency climatology or splitter operations without specifying the number of timesteps per day (tpd) in the input files, so ${spt_nm} tried to infer tpd from the first input file. This operation resulted in a nonsense value. This is not surprising since a number of assumptions must hold true for the inferral to work correctly.\nHINT: Explicitly specify the number of timesteps-per-day in every input file with the --tpd=\$tpd option.\n" |
| 1753 |
exit 1 |
| 1754 |
fi # !tpd_ntg |
| 1755 |
fi # !tpd_usr |
| 1756 |
fi # !hfc && !hfs |
| 1757 |
|
| 1758 |
# Parse grid/map arguments before in_fl arguments so we know whether this could be a map-only invocation |
| 1759 |
if [ "${tms_flg}" = 'Yes' ]; then |
| 1760 |
|
| 1761 |
if [ -n "${var_lst}" ]; then |
| 1762 |
# 20210823: Pre-process extraction list if it contains a regular expression character |
| 1763 |
# Match var_lst against first file contents to create real extraction list |
| 1764 |
# Only necessary in subset mode to extract distinct timeseries |
| 1765 |
# https://stackoverflow.com/questions/26621736/how-to-check-if-a-string-contains-a-special-character |
| 1766 |
if [[ "${var_lst}" == *[\^\$\+\?\.\&\(\)\[\]\{\}\|]* ]]; then |
| 1767 |
var_lst=`ncks -C -v ${var_lst} --lst_xtr ${ppn_opt} ${fl_in[0]}` |
| 1768 |
fi # !rx |
| 1769 |
|
| 1770 |
# Turn var_lst into array of excluded variables if so requested |
| 1771 |
if [ "${xcl_flg}" = 'Yes' ]; then |
| 1772 |
var_lst_xcl=( ${var_lst//,/ } ) |
| 1773 |
fi # !xcl_flg |
| 1774 |
fi # !var_lst |
| 1775 |
|
| 1776 |
# Create list of all variables when none specified, and array of all variables to construct exclusion list |
| 1777 |
if [ -z "${var_lst}" ] && [ "${xcl_flg}" = 'Yes' ]; then |
| 1778 |
echo "${spt_nm}: ERROR Exclude option (--xcl_var | --xcl | --exclude | --exclude_variables) only works in conjunction with explicitly specified variable extraction list" |
| 1779 |
echo "${spt_nm}: HINT Re-run with explicitly specified variable list (-v var_lst)" |
| 1780 |
exit 1 |
| 1781 |
fi # !var_lst |
| 1782 |
if [ -z "${var_lst}" ] || [ "${xcl_flg}" = 'Yes' ]; then |
| 1783 |
if [ -z "${var_lst}" ]; then |
| 1784 |
echo "${spt_nm}: WARNING Splitter mode without explicitly specified variable list (i.e., -v var_lst) splits all variables of rank >= 2 into separate files, thus doubling the on-disk data amount" |
| 1785 |
fi # !var_lst |
| 1786 |
if [ "${rgn_stt}" != 'No' ]; then |
| 1787 |
# 20250327 Restrict regional statistics to horizontal-only (lat, lon, ncol) timeseries |
| 1788 |
# ncap2 regional timeseries will break when extra (e.g., vertical) dimensions are present |
| 1789 |
var_lst_flg_opt='--lst_hrz' |
| 1790 |
else # !rgn_stt |
| 1791 |
# Timeseries of any rank >= 2 are OK |
| 1792 |
var_lst_flg_opt='--lst_rnk_ge2' |
| 1793 |
fi # !rgn_stt |
| 1794 |
var_lst=`ncks ${var_lst_flg_opt} ${ppn_opt} ${fl_in[0]}` |
| 1795 |
if [ "${xcl_flg}" = 'Yes' ]; then |
| 1796 |
var_lst_all=( ${var_lst//,/ } ) |
| 1797 |
fi # !xcl_flg |
| 1798 |
fi # !var_lst |
| 1799 |
|
| 1800 |
# 20240617 Handle --xcl_flg for timeseries mode |
| 1801 |
if [ "${xcl_flg}" = 'Yes' ]; then |
| 1802 |
|
| 1803 |
if bsh_mjr_vrs_lt_4; then |
| 1804 |
echo "${spt_nm}: ERROR Exclude flag (--xcl_var | --xcl | --exclude | --exclude_variables) in timeseries mode only works with Bash v. 4.0+ and this Bash is version ${BASH_VERSION}" |
| 1805 |
echo "${spt_nm}: HINT Re-run in Bash v. 4.0+ shell" |
| 1806 |
exit 1 |
| 1807 |
fi # !bsh_mjr_vrs_lt_4() |
| 1808 |
|
| 1809 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 1810 |
printf "var_lst_all=" |
| 1811 |
for var in ${var_lst_all[@]}; do |
| 1812 |
printf "${var}," |
| 1813 |
done # !var_lst_all |
| 1814 |
printf "\n" |
| 1815 |
fi # !dbg |
| 1816 |
|
| 1817 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 1818 |
printf "var_lst_xcl=" |
| 1819 |
for var in ${var_lst_xcl[@]}; do |
| 1820 |
printf "${var}," |
| 1821 |
done # !var_lst_xcl |
| 1822 |
printf "\n" |
| 1823 |
fi # !dbg |
| 1824 |
|
| 1825 |
# https://stackoverflow.com/questions/48791859/removing-items-from-one-list-when-present-in-another-in-bash |
| 1826 |
# Create associative array with variable names as keys, and a fixed value |
| 1827 |
declare -A var_lst_xtr=( ) # Requires Bash 4.0 or later |
| 1828 |
for var in "${var_lst_all[@]}"; do |
| 1829 |
var_lst_xtr[${var}]=1 |
| 1830 |
done # !var_lst_all |
| 1831 |
|
| 1832 |
# Remove keys associated with excluded variables |
| 1833 |
for var in "${var_lst_xcl[@]}"; do |
| 1834 |
unset "var_lst_xtr[${var}]" |
| 1835 |
done # !var_lst_xcl |
| 1836 |
|
| 1837 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 1838 |
printf "var_lst_xtr=" |
| 1839 |
# Extraction list is the keys (not values) of this array |
| 1840 |
for var in ${!var_lst_xtr[@]}; do |
| 1841 |
printf "${var}," |
| 1842 |
done # !var_lst_xtr |
| 1843 |
printf "\n" |
| 1844 |
fi # !dbg |
| 1845 |
|
| 1846 |
# Re-assemble extraction array into standard list |
| 1847 |
var_nbr=0 # [sng] Number of split (subset into timeseries) files |
| 1848 |
var_lst='' # [sng] Variables to process |
| 1849 |
for var in "${!var_lst_xtr[@]}"; do |
| 1850 |
var_lst="${var_lst},${var}" |
| 1851 |
let var_nbr=${var_nbr}+1 |
| 1852 |
done # !var_lst_xtr |
| 1853 |
# Remove leading comma from list |
| 1854 |
var_lst="${var_lst:1}" |
| 1855 |
|
| 1856 |
fi # !xcl_flg |
| 1857 |
|
| 1858 |
# http://stackoverflow.com/questions/27702452/loop-through-a-comma-separated-shell-variable |
| 1859 |
var_nbr=0 # [sng] Number of split (subset into timeseries) files. 'sbs' stands for 'subset'. |
| 1860 |
for var in ${var_lst//,/ }; do |
| 1861 |
# NB: |
| 1862 |
var_sbs[${var_nbr}]=${var} |
| 1863 |
let var_nbr=${var_nbr}+1 |
| 1864 |
done # !var_lst |
| 1865 |
|
| 1866 |
if [ -z "${job_usr}" ]; then |
| 1867 |
job_nbr=${var_nbr} |
| 1868 |
fi # !job_usr |
| 1869 |
|
| 1870 |
# Input files per year |
| 1871 |
flg_dct='Yes' # [flg] Double-check time in years against file count |
| 1872 |
if [ "${clm_md}" = 'ann' ]; then |
| 1873 |
fpy=1 |
| 1874 |
elif [ "${clm_md}" = 'dly' ]; then |
| 1875 |
dpf=1 |
| 1876 |
let fpy=${dpy}/${dpf} |
| 1877 |
elif [ "${clm_md}" = 'hfc' ]; then |
| 1878 |
fpy=12 |
| 1879 |
flg_dct='No' |
| 1880 |
elif [ "${clm_md}" = 'hfs' ]; then |
| 1881 |
# CESM/E3SM high-frequency output often employs noleap calendar and 30 days per file (no matter how many timesteps per day) |
| 1882 |
if [ -z "${dpf}" ]; then |
| 1883 |
# 20210329 Automatically infer dpf from first input file |
| 1884 |
# E3SM/CESM high-frequency timeseries (e.g., h4 files) are all equal # timesteps, not duration |
| 1885 |
# First timestep in first file (often? always?) is of zero duration and contains the IC |
| 1886 |
# Remaining timesteps in first file, and all timesteps in following files, are of normal duration |
| 1887 |
# For example 3-hourly E3SM/CESM output files of 120 timesteps length are each 30 days duration except the first file which is only 29.875 days because its first timestep is of zero duration |
| 1888 |
# Solution: Base dpf on second file, not first file, if it exists |
| 1889 |
fl_idx=$((fl_nbr > 1 ? 1 : 0)) |
| 1890 |
tm_var='time' |
| 1891 |
tm_bnd=`ncks --trd -M -m -v ${tm_var} ${ppn_opt} ${fl_in[${fl_idx}]} | grep -E -i "^${tm_var} attribute [0-9]+: bounds" | cut -f 11- -d ' ' | sed 's/^ *//g'` |
| 1892 |
if [ -z "${tm_bnd}" ]; then |
| 1893 |
# 20250509 Use time-coordinate values when time bounds DNE |
| 1894 |
tm_bnd_flg='No' |
| 1895 |
fi # !tm_bnd |
| 1896 |
if [ "${tm_bnd_flg}" = 'Yes' ]; then |
| 1897 |
dpf=`ncks --trd -H -s '%25.15f ' -v ${tm_bnd} -d ${tm_var},0 -d ${tm_var},-1 -C ${ppn_opt} ${fl_in[${fl_idx}]} | awk '{ print $4-$1; exit }'` |
| 1898 |
else # !tm_bnd_flg |
| 1899 |
dpf=`ncks --trd -H -s '%25.15f ' -v ${tm_var} -d ${tm_var},0 -d ${tm_var},-1 -C ${ppn_opt} ${fl_in[${fl_idx}]} | awk '{ printf "%.0f\n",$2-$1; exit }'` |
| 1900 |
# This is a time coordinate not a time bounds so last-first value is often a decimal fraction not an integer |
| 1901 |
# For example, output files at 3 hourly resolution often have multiples of 8 timesteps with first at |
| 1902 |
# dayM day-fraction 0.0, last at dayN day-fraction 0.875, and difference is integer N-M plus 0.875. |
| 1903 |
# When difference > 0.5 it is often correct to round-up, i.e., to integer dpf=1. |
| 1904 |
fi # !tm_bnd_flg |
| 1905 |
|
| 1906 |
# Ensure result is positive integer |
| 1907 |
[ "${dpf}" -ge 0 ] 2>/dev/null && dpf_ntg='Yes' || dpf_ntg='No' |
| 1908 |
if [ "${dpf_ntg}" != 'Yes' ]; then |
| 1909 |
printf "${spt_nm}: ERROR Inferred value of dpf=${dpf} is not a positive integer. User requested high-frequency splitter operations without specifying the number of days-per-file (dpf) in the input files, so ${spt_nm} tried to infer dpf from the first input file. This operation resulted in a nonsense value. This is not surprising since a number of assumptions must hold true for the inferral to work correctly.\nHINT: Explicitly specify the number of days-per-file in every input file with the --dpf option.\n" |
| 1910 |
exit 1 |
| 1911 |
fi # !dpf_ntg |
| 1912 |
fi # !dpf |
| 1913 |
# 20220818 |
| 1914 |
let fpy=${dpy}/${dpf} |
| 1915 |
#fpy=$(echo "${dpy}/${dpf}" | bc -l) # NB: dpy/dpf more accurate than fpy |
| 1916 |
flg_dct='No' |
| 1917 |
# !clm_md=hfs |
| 1918 |
elif [ "${clm_md}" = 'mth' ]; then |
| 1919 |
fpy=12 |
| 1920 |
fi # !clm_md |
| 1921 |
if [ "${clm_md}" = 'hfs' ]; then |
| 1922 |
let yr_sbs=${yr_cln} |
| 1923 |
else |
| 1924 |
let yr_sbs=${fl_nbr}/${fpy} |
| 1925 |
let fl_rmd=${fl_nbr}%${fpy} |
| 1926 |
fi # !clm_md |
| 1927 |
if [ "${flg_dct}" = 'Yes' ]; then |
| 1928 |
if [ "${mth_flg}" = 'Yes' ]; then |
| 1929 |
if [ ${mth_nbr} -ne ${fl_nbr} ]; then |
| 1930 |
printf "${spt_nm}: ERROR Number of input files = ${fl_nbr} differs from number of months = ${mth_nbr} computed from calendar inputs\n" |
| 1931 |
printf "${spt_nm}: HINT In this mode (clm_md=${clm_md}) splitter expects one monthly file per calendar month\n" |
| 1932 |
exit 1 |
| 1933 |
fi # !mth_nbr |
| 1934 |
else # !mth_flg |
| 1935 |
if [ ${fl_rmd} -ne 0 ]; then |
| 1936 |
printf "${spt_nm}: ERROR ${fl_nbr} files of clm_md=${clm_md} input contain non-integral number of years, ${fl_rmd} files leftover in final year\n" |
| 1937 |
printf "${spt_nm}: HINT Provide input filenames in multiples of ${fpy}\n" |
| 1938 |
exit 1 |
| 1939 |
fi # !fl_rmd |
| 1940 |
if [ ${yr_sbs} -ne ${yr_nbr} ]; then |
| 1941 |
# Sanity check that number of files specified matches number expected from date switches |
| 1942 |
printf "${spt_nm}: ERROR The ${fl_nbr} files specified (via stdin pipe, positional, or input directory) are expected to contain ${yr_sbs} years of data whereas the date options specify ${yr_nbr} years of data\n" |
| 1943 |
printf "${spt_nm}: HINT Number of files at ${fpy} files-per-year must match number of years implied by arguments to start- and end-year switches (--yr_srt=${yr_srt} and --yr_end=${yr_end}, respectively). Check that the stdin pipe, positional arguments, or globbed input directory contain the intended number of filenames.\n" |
| 1944 |
exit 1 |
| 1945 |
fi # !yr_sbs |
| 1946 |
fi # !mth_flg |
| 1947 |
fi # !flg_dct |
| 1948 |
|
| 1949 |
# How many segments of output? |
| 1950 |
if [ "${mth_flg}" = 'Yes' ]; then |
| 1951 |
# NB: When start/end months are not Jan/Dec, sgm_rmd measured in months |
| 1952 |
let mpf_max=${fpy}*${ypf_max} |
| 1953 |
let sgm_nbr=${mth_nbr}/${mpf_max} |
| 1954 |
let sgm_rmd=${mth_nbr}%${mpf_max} |
| 1955 |
if [ ${sgm_rmd} -ne 0 ]; then |
| 1956 |
let sgm_nbr=${sgm_nbr}+1 |
| 1957 |
rmd_flg='Yes' |
| 1958 |
else # !sgm_rmd |
| 1959 |
rmd_flg='No' |
| 1960 |
fi # !sgm_rmd |
| 1961 |
else # !mth_flg |
| 1962 |
# NB: When start/end months are Jan/Dec, sgm_rmd measured in years |
| 1963 |
let sgm_nbr=${yr_sbs}/${ypf_max} |
| 1964 |
let sgm_rmd=${yr_sbs}%${ypf_max} |
| 1965 |
if [ ${sgm_rmd} -ne 0 ]; then |
| 1966 |
let sgm_nbr=${sgm_nbr}+1 |
| 1967 |
rmd_flg='Yes' |
| 1968 |
else # !sgm_rmd |
| 1969 |
rmd_flg='No' |
| 1970 |
fi # !sgm_rmd |
| 1971 |
fi # !mth_flg |
| 1972 |
let sgm_nbrm1=${sgm_nbr}-1 |
| 1973 |
|
| 1974 |
if [ "${rgn_stt}" != 'No' ]; then |
| 1975 |
# Export timeseries of regional/global statistics |
| 1976 |
|
| 1977 |
# MUST pass rgn_stt to cmd_rgn script as an enum/flag (i.e., flg_sum) not a string. Sigh... |
| 1978 |
if [ "${rgn_stt}" = 'sum' ] || [ "${rgn_stt}" = 'ttl' ] || [ "${rgn_stt}" = 'total' ] || [ "${rgn_stt}" = 'integral' ]; then |
| 1979 |
rgn_stt='sum' |
| 1980 |
flg_sum=1 |
| 1981 |
elif [ "${rgn_stt}" = 'avg' ] || [ "${rgn_stt}" = 'average' ] || [ "${rgn_stt}" = 'mean' ]; then |
| 1982 |
rgn_stt='avg' |
| 1983 |
flg_sum=0 |
| 1984 |
else |
| 1985 |
echo "${spt_nm}: ERROR \"${rgn_stt}\" is an invalid value for regional_statistic" |
| 1986 |
echo "${spt_nm}: HINT The valid values for regional_statistic are \"avg\" (or synonyms \"average\", and \"mean\") and \"sum\" (or synonyms \"ttl\", \"total\", and \"integral\")" |
| 1987 |
exit 1 |
| 1988 |
fi # !rgn_stt |
| 1989 |
|
| 1990 |
if [ "${prc_mpas}" = 'Yes' ]; then |
| 1991 |
# 20240619 |
| 1992 |
# MPAS-LI, MPAS-O, MPAS-SI v2+ datasets omit latitude variable |
| 1993 |
lat_nm='latCell' # Generic MPAS latitude variable |
| 1994 |
# MPAS-A, MPAS-LI, MPAS-O, MPAS-SI v2+ datasets omit (time-constant) area variable |
| 1995 |
# NB: areaCell is full gridcell area on MPAS mesh, and does not account for landfrac/ocnfrac |
| 1996 |
# Hence, area_wgt variable diagnosed below will be inaccurate for MPAS-O unless 'ocnfrac' is given and applied as sgs_frc |
| 1997 |
area_nm='areaCell' # Generic MPAS fixed grid area variable |
| 1998 |
if [ "${prc_mpasseaice}" = 'Yes' ]; then |
| 1999 |
# MPAS-SI v2+ datasets omit latitude though include (time-varying) area variable |
| 2000 |
sgs_frc='timeMonthly_avg_iceAreaCell' |
| 2001 |
fi # !prc_mpasseaice |
| 2002 |
echo "WARNING: Regional average timeseries option requires latitude and area variables. These variables are not present in many MPAS datasets." |
| 2003 |
echo "HINT: First append latitude and area variables to raw timeseries datasets with, e.g., ncks -C -v ${lat_nm},${area_nm} in.nc out.nc" |
| 2004 |
fi # !prc_mpas |
| 2005 |
|
| 2006 |
# 20191217 Regional average timeseries require area and latitude variables |
| 2007 |
var_xtr="${var_xtr},${area_nm},${lat_nm}" |
| 2008 |
|
| 2009 |
if [ "${prc_typ}" = 'clm' ] || [ "${prc_typ}" = 'elm' ]; then |
| 2010 |
sgs_frc='landfrac' |
| 2011 |
fi # !prc_typ |
| 2012 |
if [ -n "${sgs_frc}" ]; then |
| 2013 |
area_wgt="${area_nm}*${sgs_frc}" |
| 2014 |
var_xtr="${var_xtr},${sgs_frc}" |
| 2015 |
else |
| 2016 |
area_wgt="${area_nm}" |
| 2017 |
fi # !sgs_frc |
| 2018 |
|
| 2019 |
# 20240329 Simplify life by automatically determining hrz_dmn from area_nm in first file |
| 2020 |
# Works for EAM, ELM, unstructured, structured, ... |
| 2021 |
# https://unix.stackexchange.com/questions/108250/print-the-string-between-two-parentheses |
| 2022 |
#hrz_dmn=`ncks -C -m -v ${area_nm} ${ppn_opt} ${fl_in[0]} | grep "${area_nm}\(" | sed 's/^.*(//;s/) ;$//'` # Works at prompt, not in script |
| 2023 |
hrz_dmn=`ncks -C -m -v ${area_nm} ${ppn_opt} ${fl_in[0]} | grep -E "float.*${area_nm}|double.*${area_nm}" | sed 's/^.*(//;s/) ;$//'` |
| 2024 |
if [ -n "${hrz_dmn}" ]; then |
| 2025 |
# 20240329 Prepend string literal '$' to each horizontal dimension for use in argument to ncap2 avg() function (e.g., 'lat,lon' -> '$lat,$lon') |
| 2026 |
hrz_arg="\$${hrz_dmn/,/,\$}" |
| 2027 |
fi # !hrz_dmn |
| 2028 |
fi # !rgn_stt |
| 2029 |
|
| 2030 |
else # !tms_flg |
| 2031 |
|
| 2032 |
if [ ${clm_md} = 'mth' ]; then |
| 2033 |
|
| 2034 |
# Duplicate a check from monthly timeseries mode |
| 2035 |
if [ ${mth_nbr} -ne ${fl_nbr} ]; then |
| 2036 |
printf "${spt_nm}: ERROR Number of input files = ${fl_nbr} differs from number of months = ${mth_nbr} computed from calendar inputs\n" |
| 2037 |
printf "${spt_nm}: HINT In this mode (clm_md=${clm_md}) ${spt_nm} expects one monthly file per calendar month\n" |
| 2038 |
exit 1 |
| 2039 |
fi # !mth_nbr |
| 2040 |
|
| 2041 |
fi # !clm_md |
| 2042 |
|
| 2043 |
if [ "${rgn_stt}" != 'No' ]; then |
| 2044 |
echo "${spt_nm}: ERROR Regional/global statistical timeseries functionality is supported for time-series (splitting) mode only. If you would like ${spt_nm} to provide global and regional statistical output for other types of climatologies, please talk to Charlie." |
| 2045 |
echo "${spt_nm}: HINT Create global statistics of climos with, e.g., \"ncwa -w ${area_nm} in.nc out.nc\"" |
| 2046 |
echo "${spt_nm}: HINT See averaging documentation at http://nco.sf.net/nco.html#ncwa" |
| 2047 |
exit 1 |
| 2048 |
fi # !rgn_stt |
| 2049 |
|
| 2050 |
if [ -z "${out_nm}" ]; then |
| 2051 |
echo "${spt_nm}: ERROR Missing information needed to generate output filenames" |
| 2052 |
echo "${spt_nm}: HINT Generating input filenames for climos requires that users specify a case ID with -c \$caseid or specify with -m \$mdl_nm a recognized MPAS model name (like \"mpaso\"). Output filenames for climos are based on these inputs as well, or on the family name if specified with --fml_nm=\$fml_nm. When input filenames are not internally generated, but instead provided via stdin, positional arguments, or globbing, then the output filenames will be based on the family name or caseid, or model name, in that order of precedence." |
| 2053 |
echo "${spt_nm}: HINT ${spt_nm} needs this information to generate output filenames" |
| 2054 |
echo "${spt_nm}: HINT See invocation examples at http://nco.sf.net/nco.html#ncclimo" |
| 2055 |
exit 1 |
| 2056 |
fi # out_nm |
| 2057 |
|
| 2058 |
# 20211118 fxm: re-do these messages? |
| 2059 |
if [ ${inp_std} = 'Yes' ] && [ ${clm_md} = 'ann' ]; then |
| 2060 |
echo "${spt_nm}: ERROR Detected input on pipe to stdin in annual climatology generation mode" |
| 2061 |
echo "${spt_nm}: HINT Piping filenames to ${spt_nm} only works when splitting files or in daily, monthly, or high-frequency climatology mode" |
| 2062 |
echo "${spt_nm}: HINT In annual climo generation mode, one must specify the year/month boundaries and ${caseid}, and from these ${spt_nm} will automatically generate the correct input file names" |
| 2063 |
echo "${spt_nm}: HINT See invocation examples at http://nco.sf.net/nco.html#ncclimo" |
| 2064 |
exit 1 |
| 2065 |
fi # !stdin |
| 2066 |
|
| 2067 |
fi # !tms_flg |
| 2068 |
|
| 2069 |
# 20170807 Custom seasons |
| 2070 |
if [ "${csn_flg}" = 'Yes' ]; then |
| 2071 |
|
| 2072 |
if [ "${clm_md}" != 'hfc' ] && [ "${clm_md}" != 'mth' ]; then |
| 2073 |
echo "${spt_nm}: ERROR Custom seasons available only in high-frequency or monthly climatology mode" |
| 2074 |
echo "${spt_nm}: HINT Re-run with --clm_md=hfc or --clm_md=mth or without --csn_lst/--seasons" |
| 2075 |
exit 1 |
| 2076 |
fi # !mth |
| 2077 |
|
| 2078 |
# Standard and custom season definitions |
| 2079 |
# Index into season definition table |
| 2080 |
csn_idx_srt=0 # [idx] Starting index for season definitions |
| 2081 |
csn_mam=0 |
| 2082 |
csn_jja=1 |
| 2083 |
csn_son=2 |
| 2084 |
csn_djf=3 |
| 2085 |
csn_jfm=4 |
| 2086 |
csn_amj=5 |
| 2087 |
csn_jas=6 |
| 2088 |
csn_ond=7 |
| 2089 |
csn_on=8 |
| 2090 |
csn_fm=9 |
| 2091 |
csn_fma=10 |
| 2092 |
csn_mjj=11 |
| 2093 |
csn_aso=12 |
| 2094 |
csn_ndj=13 |
| 2095 |
csn_jf=14 |
| 2096 |
csn_ma=15 |
| 2097 |
csn_am=16 |
| 2098 |
csn_mj=17 |
| 2099 |
csn_jj=18 |
| 2100 |
csn_ja=19 |
| 2101 |
csn_as=20 |
| 2102 |
csn_so=21 |
| 2103 |
csn_nd=22 |
| 2104 |
csn_dj=23 |
| 2105 |
csn_ann=24 |
| 2106 |
csn_nbr_max=25 # [nbr] Maximum number of seasons in definitions database |
| 2107 |
|
| 2108 |
# Seasonal abbreviations, uppercase |
| 2109 |
csn_abb[${csn_mam}]='MAM' |
| 2110 |
csn_abb[${csn_jja}]='JJA' |
| 2111 |
csn_abb[${csn_son}]='SON' |
| 2112 |
csn_abb[${csn_djf}]='DJF' |
| 2113 |
csn_abb[${csn_jfm}]='JFM' |
| 2114 |
csn_abb[${csn_amj}]='AMJ' |
| 2115 |
csn_abb[${csn_jas}]='JAS' |
| 2116 |
csn_abb[${csn_ond}]='OND' |
| 2117 |
csn_abb[${csn_on}]='ON' |
| 2118 |
csn_abb[${csn_fm}]='FM' |
| 2119 |
csn_abb[${csn_fma}]='FMA' |
| 2120 |
csn_abb[${csn_mjj}]='MJJ' |
| 2121 |
csn_abb[${csn_aso}]='ASO' |
| 2122 |
csn_abb[${csn_ndj}]='NDJ' |
| 2123 |
csn_abb[${csn_jf}]='JF' |
| 2124 |
csn_abb[${csn_ma}]='MA' |
| 2125 |
csn_abb[${csn_am}]='AM' |
| 2126 |
csn_abb[${csn_mj}]='MJ' |
| 2127 |
csn_abb[${csn_jj}]='JJ' |
| 2128 |
csn_abb[${csn_ja}]='JA' |
| 2129 |
csn_abb[${csn_as}]='AS' |
| 2130 |
csn_abb[${csn_so}]='SO' |
| 2131 |
csn_abb[${csn_nd}]='ND' |
| 2132 |
csn_abb[${csn_dj}]='DJ' |
| 2133 |
csn_abb[${csn_ann}]='ANN' |
| 2134 |
|
| 2135 |
# Seasonal abbreviations, lowercase |
| 2136 |
csn_abb_lc[${csn_mam}]='mam' |
| 2137 |
csn_abb_lc[${csn_jja}]='jja' |
| 2138 |
csn_abb_lc[${csn_son}]='son' |
| 2139 |
csn_abb_lc[${csn_djf}]='djf' |
| 2140 |
csn_abb_lc[${csn_jfm}]='jfm' |
| 2141 |
csn_abb_lc[${csn_amj}]='amj' |
| 2142 |
csn_abb_lc[${csn_jas}]='jas' |
| 2143 |
csn_abb_lc[${csn_ond}]='ond' |
| 2144 |
csn_abb_lc[${csn_on}]='on' |
| 2145 |
csn_abb_lc[${csn_fm}]='fm' |
| 2146 |
csn_abb_lc[${csn_fma}]='fma' |
| 2147 |
csn_abb_lc[${csn_mjj}]='mjj' |
| 2148 |
csn_abb_lc[${csn_aso}]='aso' |
| 2149 |
csn_abb_lc[${csn_ndj}]='ndj' |
| 2150 |
csn_abb_lc[${csn_jf}]='jf' |
| 2151 |
csn_abb_lc[${csn_ma}]='ma' |
| 2152 |
csn_abb_lc[${csn_am}]='am' |
| 2153 |
csn_abb_lc[${csn_mj}]='mj' |
| 2154 |
csn_abb_lc[${csn_jj}]='jj' |
| 2155 |
csn_abb_lc[${csn_ja}]='ja' |
| 2156 |
csn_abb_lc[${csn_as}]='as' |
| 2157 |
csn_abb_lc[${csn_so}]='so' |
| 2158 |
csn_abb_lc[${csn_nd}]='nd' |
| 2159 |
csn_abb_lc[${csn_dj}]='dj' |
| 2160 |
csn_abb_lc[${csn_ann}]='ann' |
| 2161 |
|
| 2162 |
# Seasonal start-month index (1-based calendar) |
| 2163 |
csn_srt_idx[${csn_mam}]=3 |
| 2164 |
csn_srt_idx[${csn_jja}]=6 |
| 2165 |
csn_srt_idx[${csn_son}]=9 |
| 2166 |
csn_srt_idx[${csn_djf}]=12 |
| 2167 |
csn_srt_idx[${csn_jfm}]=1 |
| 2168 |
csn_srt_idx[${csn_amj}]=4 |
| 2169 |
csn_srt_idx[${csn_jas}]=7 |
| 2170 |
csn_srt_idx[${csn_ond}]=10 |
| 2171 |
csn_srt_idx[${csn_on}]=10 |
| 2172 |
csn_srt_idx[${csn_fm}]=2 |
| 2173 |
csn_srt_idx[${csn_fma}]=2 |
| 2174 |
csn_srt_idx[${csn_mjj}]=5 |
| 2175 |
csn_srt_idx[${csn_aso}]=8 |
| 2176 |
csn_srt_idx[${csn_ndj}]=11 |
| 2177 |
csn_srt_idx[${csn_jf}]=1 |
| 2178 |
csn_srt_idx[${csn_ma}]=3 |
| 2179 |
csn_srt_idx[${csn_am}]=4 |
| 2180 |
csn_srt_idx[${csn_mj}]=5 |
| 2181 |
csn_srt_idx[${csn_jj}]=6 |
| 2182 |
csn_srt_idx[${csn_ja}]=7 |
| 2183 |
csn_srt_idx[${csn_as}]=8 |
| 2184 |
csn_srt_idx[${csn_so}]=9 |
| 2185 |
csn_srt_idx[${csn_nd}]=11 |
| 2186 |
csn_srt_idx[${csn_dj}]=12 |
| 2187 |
csn_srt_idx[${csn_ann}]=1 |
| 2188 |
|
| 2189 |
# Seasonal end-month index (1-based calendar) |
| 2190 |
csn_end_idx[${csn_mam}]=5 |
| 2191 |
csn_end_idx[${csn_jja}]=8 |
| 2192 |
csn_end_idx[${csn_son}]=11 |
| 2193 |
csn_end_idx[${csn_djf}]=2 |
| 2194 |
csn_end_idx[${csn_jfm}]=3 |
| 2195 |
csn_end_idx[${csn_amj}]=6 |
| 2196 |
csn_end_idx[${csn_jas}]=9 |
| 2197 |
csn_end_idx[${csn_ond}]=12 |
| 2198 |
csn_end_idx[${csn_on}]=11 |
| 2199 |
csn_end_idx[${csn_fm}]=3 |
| 2200 |
csn_end_idx[${csn_fma}]=4 |
| 2201 |
csn_end_idx[${csn_mjj}]=7 |
| 2202 |
csn_end_idx[${csn_aso}]=10 |
| 2203 |
csn_end_idx[${csn_ndj}]=1 |
| 2204 |
csn_end_idx[${csn_jf}]=2 |
| 2205 |
csn_end_idx[${csn_ma}]=4 |
| 2206 |
csn_end_idx[${csn_am}]=5 |
| 2207 |
csn_end_idx[${csn_mj}]=6 |
| 2208 |
csn_end_idx[${csn_jj}]=7 |
| 2209 |
csn_end_idx[${csn_ja}]=8 |
| 2210 |
csn_end_idx[${csn_as}]=9 |
| 2211 |
csn_end_idx[${csn_so}]=10 |
| 2212 |
csn_end_idx[${csn_nd}]=12 |
| 2213 |
csn_end_idx[${csn_dj}]=1 |
| 2214 |
csn_end_idx[${csn_ann}]=12 |
| 2215 |
|
| 2216 |
for ((csn_idx=0;csn_idx<${csn_nbr_max};csn_idx++)); do |
| 2217 |
csn_srt_mm[${csn_idx}]=`printf "%02d" ${csn_srt_idx[${csn_idx}]}` |
| 2218 |
csn_end_mm[${csn_idx}]=`printf "%02d" ${csn_end_idx[${csn_idx}]}` |
| 2219 |
done # !csn_idx |
| 2220 |
|
| 2221 |
# Seasonal number of months |
| 2222 |
csn_nom[${csn_mam}]=3 |
| 2223 |
csn_nom[${csn_jja}]=3 |
| 2224 |
csn_nom[${csn_son}]=3 |
| 2225 |
csn_nom[${csn_djf}]=3 |
| 2226 |
csn_nom[${csn_jfm}]=3 |
| 2227 |
csn_nom[${csn_amj}]=3 |
| 2228 |
csn_nom[${csn_jas}]=3 |
| 2229 |
csn_nom[${csn_ond}]=3 |
| 2230 |
csn_nom[${csn_on}]=2 |
| 2231 |
csn_nom[${csn_fm}]=2 |
| 2232 |
csn_nom[${csn_fma}]=3 |
| 2233 |
csn_nom[${csn_mjj}]=3 |
| 2234 |
csn_nom[${csn_aso}]=3 |
| 2235 |
csn_nom[${csn_ndj}]=3 |
| 2236 |
csn_nom[${csn_jf}]=2 |
| 2237 |
csn_nom[${csn_ma}]=2 |
| 2238 |
csn_nom[${csn_am}]=2 |
| 2239 |
csn_nom[${csn_mj}]=2 |
| 2240 |
csn_nom[${csn_jj}]=2 |
| 2241 |
csn_nom[${csn_ja}]=2 |
| 2242 |
csn_nom[${csn_as}]=2 |
| 2243 |
csn_nom[${csn_so}]=2 |
| 2244 |
csn_nom[${csn_nd}]=2 |
| 2245 |
csn_nom[${csn_dj}]=2 |
| 2246 |
csn_nom[${csn_ann}]=12 |
| 2247 |
|
| 2248 |
# Seasonal monthly weights (ncra/nces -w argument), assumes noleap calendar = 365 dpy |
| 2249 |
csn_wgt[${csn_mam}]='31,30,31' |
| 2250 |
csn_wgt[${csn_jja}]='30,31,31' |
| 2251 |
csn_wgt[${csn_son}]='30,31,30' |
| 2252 |
csn_wgt[${csn_djf}]='31,31,28' |
| 2253 |
csn_wgt[${csn_jfm}]='31,28,31' |
| 2254 |
csn_wgt[${csn_amj}]='30,31,30' |
| 2255 |
csn_wgt[${csn_jas}]='31,31,30' |
| 2256 |
csn_wgt[${csn_ond}]='31,30,31' |
| 2257 |
csn_wgt[${csn_on}]='31,30' |
| 2258 |
csn_wgt[${csn_fm}]='28,31' |
| 2259 |
csn_wgt[${csn_fma}]='28,31,30' |
| 2260 |
csn_wgt[${csn_mjj}]='31,30,31' |
| 2261 |
csn_wgt[${csn_aso}]='31,30,31' |
| 2262 |
csn_wgt[${csn_ndj}]='30,31,31' |
| 2263 |
csn_wgt[${csn_jf}]='31,28' |
| 2264 |
csn_wgt[${csn_ma}]='31,30' |
| 2265 |
csn_wgt[${csn_am}]='30,31' |
| 2266 |
csn_wgt[${csn_mj}]='31,30' |
| 2267 |
csn_wgt[${csn_jj}]='30,31' |
| 2268 |
csn_wgt[${csn_ja}]='31,31' |
| 2269 |
csn_wgt[${csn_as}]='31,30' |
| 2270 |
csn_wgt[${csn_so}]='30,31' |
| 2271 |
csn_wgt[${csn_nd}]='30,31' |
| 2272 |
csn_wgt[${csn_dj}]='31,31' |
| 2273 |
csn_wgt[${csn_ann}]='31,28,31,30,31,30,31,31,30,31,30,31' |
| 2274 |
|
| 2275 |
# Which seasons are requested? |
| 2276 |
# http://stackoverflow.com/questions/27702452/loop-through-a-comma-separated-shell-variable |
| 2277 |
csn_nbr=0 # [sng] Number of seasons to compute |
| 2278 |
for csn in ${csn_lst//,/ }; do |
| 2279 |
csn_rqs[${csn_nbr}]=${csn} |
| 2280 |
# NB: Requested seasons are 0-based, defined seasons are 0-based |
| 2281 |
for ((csn_dfn_idx=${csn_idx_srt};csn_dfn_idx<${csn_nbr_max};csn_dfn_idx++)); do |
| 2282 |
if [[ "${csn}" =~ "${csn_abb[${csn_dfn_idx}]}" ]] || [[ "${csn}" =~ "${csn_abb_lc[${csn_dfn_idx}]}" ]]; then |
| 2283 |
# Map requested to defined (r2d) seasons and inverse (d2r) |
| 2284 |
# map_r2d[0]=3 means first season that user requested (i.e., in csn_lst) is fourth defined in table |
| 2285 |
# map_d2r[3]=0 means fourth defined season is first requested |
| 2286 |
map_r2d[${csn_nbr}]=${csn_dfn_idx} |
| 2287 |
map_d2r[${csn_dfn_idx}]=${csn_nbr} |
| 2288 |
let csn_nbr=${csn_nbr}+1 |
| 2289 |
break |
| 2290 |
fi # !match |
| 2291 |
done # !csn_dfn_idx |
| 2292 |
if [ "${csn_dfn_idx}" -eq "${csn_nbr_max}" ]; then |
| 2293 |
printf "${spt_nm}: ERROR Requested season ${csn} not defined\n" |
| 2294 |
exit 1 |
| 2295 |
fi # !match |
| 2296 |
done # !csn_lst |
| 2297 |
|
| 2298 |
# Were all four standard seasons requested so annual mean can be computed from seasons? |
| 2299 |
ann_flg='No' |
| 2300 |
ann_nbr=0 |
| 2301 |
if [[ ${csn_lst} =~ 'mam' ]] || [[ ${csn_lst} =~ 'MAM' ]]; then |
| 2302 |
let clm_csn_mam_idx=${map_d2r[${csn_mam}]}+12+1 |
| 2303 |
if [[ ${csn_lst} =~ 'jja' ]] || [[ ${csn_lst} =~ 'JJA' ]]; then |
| 2304 |
let clm_csn_jja_idx=${map_d2r[${csn_jja}]}+12+1 |
| 2305 |
if [[ ${csn_lst} =~ 'son' ]] || [[ ${csn_lst} =~ 'SON' ]]; then |
| 2306 |
let clm_csn_son_idx=${map_d2r[${csn_son}]}+12+1 |
| 2307 |
if [[ ${csn_lst} =~ 'djf' ]] || [[ ${csn_lst} =~ 'DJF' ]]; then |
| 2308 |
let clm_csn_djf_idx=${map_d2r[${csn_djf}]}+12+1 |
| 2309 |
ann_flg='Yes' |
| 2310 |
ann_nbr=1 |
| 2311 |
fi # !djf |
| 2312 |
fi # !son |
| 2313 |
fi # !jja |
| 2314 |
fi # !mam |
| 2315 |
|
| 2316 |
# Account for season number in climatology command number and parallelism |
| 2317 |
let clm_csn_srt_idx=12+1 |
| 2318 |
let clm_csn_end_idx=12+${csn_nbr} |
| 2319 |
let clm_nbr=12+${csn_nbr}+${ann_nbr} |
| 2320 |
|
| 2321 |
fi # !csn_flg |
| 2322 |
|
| 2323 |
if [ "${mpi_flg}" = 'Yes' ]; then |
| 2324 |
if [ -n "${PBS_NODEFILE}" ]; then |
| 2325 |
nd_fl="${PBS_NODEFILE}" |
| 2326 |
elif [ -n "${SLURM_NODELIST}" ]; then |
| 2327 |
# SLURM returns compressed lists (e.g., "nid00[076-078,559-567]") |
| 2328 |
# Convert this to file with uncompressed list (like PBS) |
| 2329 |
# http://www.ceci-hpc.be/slurm_faq.html#Q12 |
| 2330 |
# Save file in writable directory |
| 2331 |
nd_fl="${drc_out}/${spt_nm}.slurm_nodelist.pid${spt_pid}.tmp" |
| 2332 |
nd_lst=`scontrol show hostname ${SLURM_NODELIST}` |
| 2333 |
echo ${nd_lst} > ${nd_fl} |
| 2334 |
else |
| 2335 |
echo "${spt_nm}: ERROR MPI master process unable to find node-list for distributing jobs" |
| 2336 |
echo "${spt_nm}: ${spt_nm} uses first node-list found in \$PBS_NODEFILE or \$SLURM_NODELIST" |
| 2337 |
echo "${spt_nm}: However, none of these environment variables are set so there is no node-list for distributing MPI jobs" |
| 2338 |
echo "${spt_nm}: HINT: Requesting MPI-parallelism (i.e., invoking ${spt_nm} with \"-p mpi\") in a non-MPI environment will trigger this error. Use \"-p mpi\" only when one of the preceding schedulers has allocated (for interactive use) or will allocate (for non-interactive use) the compute nodes. Otherwise use the default background parallelism (use \"-p bck\" or omit the option completely) or use serial mode (use \"-p serial\"). See http://nco.sf.net/nco.html#par_typ for more information on parallelism." |
| 2339 |
exit 1 |
| 2340 |
fi # !PBS |
| 2341 |
if [ "${tms_flg}" = 'Yes' ]; then |
| 2342 |
mpi_nbr=${var_nbr} |
| 2343 |
else |
| 2344 |
mpi_nbr=${clm_nbr} |
| 2345 |
fi # !tms_flg |
| 2346 |
# 20210310 MPI run command may need/use thr_nbr so set it first |
| 2347 |
if [ -z "${thr_usr}" ]; then |
| 2348 |
if [ -n "${PBS_NUM_PPN}" ]; then |
| 2349 |
# NB: use export OMP_NUM_THREADS when thr_nbr > 8 |
| 2350 |
# thr_nbr=${PBS_NUM_PPN} |
| 2351 |
thr_nbr=$((PBS_NUM_PPN > 8 ? 8 : PBS_NUM_PPN)) |
| 2352 |
fi # !pbs |
| 2353 |
fi # !thr_usr |
| 2354 |
if [ -n "${nd_fl}" ]; then |
| 2355 |
# NB: nodes are always 0-based, e.g., [0..11] |
| 2356 |
# For climo generation MPI index loops over months and is 1-based, e.g., [1..17] (December is 12 and ANN is 17) |
| 2357 |
# For climo subsetting MPI index loops over variables and is 0-based, e.g., [0..5], as are input files |
| 2358 |
nd_idx=0 |
| 2359 |
for nd in `cat ${nd_fl} | uniq` ; do |
| 2360 |
nd_nm[${nd_idx}]=${nd} |
| 2361 |
let nd_idx=${nd_idx}+1 |
| 2362 |
done # !nd |
| 2363 |
nd_nbr=${#nd_nm[@]} |
| 2364 |
if [ "${nd_nbr}" -eq 0 ]; then |
| 2365 |
echo "${spt_nm}: ERROR MPI-mode node number nd_nbr = ${nd_nbr}" |
| 2366 |
echo "${spt_nm}: HINT Parsing the node-list for distributing MPI jobs failed" |
| 2367 |
exit 1 |
| 2368 |
fi # !nd_nbr |
| 2369 |
# NB: ncclimo and ncremap employ different node-allocation algorithms: |
| 2370 |
# ncclimo (monthly climatology mode) assigns monthly regridding and seasonal climos to different nodes (i.e., load-balances), and likewise for seasonal-regridding and annual climo |
| 2371 |
# ncclimo (splitter mode) uses simple round robin based on position in variable list |
| 2372 |
# ncremap uses simple round-robin allocation based on position in input file list |
| 2373 |
# Only ncclimo monthly climatology-mode uses 1-based cmd_mpi array |
| 2374 |
# ncclimo splitter-mode, and daily and annual climatology-mode, and ncremap all use 0-based cmd_mpi array |
| 2375 |
# Copy host-specific mpirun syntax but not node-allocation algorithms or loop indices between ncclimo and ncremap |
| 2376 |
# 20160502: Remove tasks-per-node limits (ntasks, npernode) so round-robin algorithm can schedule multiple jobs on same node |
| 2377 |
for ((mpi_idx_zro=0;mpi_idx_zro<mpi_nbr;mpi_idx_zro++)); do |
| 2378 |
mpi_idx=${mpi_idx_zro} |
| 2379 |
if [ "${clm_flg}" = 'Yes' ] && [ "${clm_hfc_or_mth}" = 'Yes' ]; then |
| 2380 |
# Offset MPI index from 0- to 1-based for traditional monthly-based climo generation |
| 2381 |
let mpi_idx=${mpi_idx_zro}+1 |
| 2382 |
fi # !tms_flg |
| 2383 |
case "${HOSTNAME}" in |
| 2384 |
andes* | chrysalis* | chrlogin* | chr-[0123456789][0123456789][0123456789][0123456789] | compy* | constance* | frontier* | login[0123456789][0123456789] | n[0123456789][0123456789][0123456789][0123456789] | nid* | node* | perlmutter* ) |
| 2385 |
# 20220518: Non-interactive batch jobs at NERSC/Perlmutter return HOSTNAME as login??, and nodes as nid?????? |
| 2386 |
# 20160803: Non-interactive batch jobs at PNNL constance return HOSTNAME as node*, not constance* |
| 2387 |
# 20190526: Non-interactive batch jobs at PNNL compy return HOSTNAME as n????, not compy* |
| 2388 |
# 20210310: srun option<->long option equivalences are -N = --nodes, -n = --ntasks, -c = --cpus-per-task |
| 2389 |
# NB: NERSC staff say srun automatically assigns to unique nodes even without "-L $node" argument? |
| 2390 |
cmd_mpi[${mpi_idx}]="srun --nodelist ${nd_nm[$((${mpi_idx_zro} % ${nd_nbr}))]} --nodes=1" ; ;; # SLURM |
| 2391 |
# cmd_mpi[${mpi_idx}]="srun --nodelist ${nd_nm[$((${mpi_idx_zro} % ${nd_nbr}))]} --nodes=1 --ntasks=1" ; ;; # SLURM |
| 2392 |
# cmd_mpi[${mpi_idx}]="srun --nodelist ${nd_nm[$((${mpi_idx_zro} % ${nd_nbr}))]} --nodes=1 --ntasks=1 --cpus-per-task=1" ; ;; # SLURM |
| 2393 |
bebop* | blogin* | b[0123456789][0123456789][0123456789] | derecho* | ilogin* | i[0123456789][0123456789][0123456789] ) |
| 2394 |
# 20180120: Non-interactive batch jobs at NCAR return HOSTNAME as derecho? |
| 2395 |
# Derecho prefers 'mpiexec_mpt dplace -s 1 ncclimo ...' |
| 2396 |
# Unsure how to specify nd_nm to mpiexec_mpt |
| 2397 |
# mpirun from SGI MPT does not accept '-H nd_nm', unlike regular PBS |
| 2398 |
# PBSPro considers ncclimo a 'non-MPT application' so must set MPI_SHEPHERD=true |
| 2399 |
export MPI_SHEPHERD=true |
| 2400 |
# PBSPro on Bebop and Improv are untested |
| 2401 |
# cmd_mpi[${mpi_idx}]="mpiexec_mpt dplace ${nd_nm[$((${mpi_idx_zro} % ${nd_nbr}))]} -n 1" ; ;; # PBSPro |
| 2402 |
cmd_mpi[${mpi_idx}]="mpirun ${nd_nm[$((${mpi_idx_zro} % ${nd_nbr}))]} -n 1" ; ;; # PBSPro |
| 2403 |
* ) |
| 2404 |
# 20250122: Shift default node manager from mpirun to srun |
| 2405 |
cmd_mpi[${mpi_idx}]="srun --nodelist ${nd_nm[$((${mpi_idx_zro} % ${nd_nbr}))]} --nodes=1" ; ;; # SLURM |
| 2406 |
# cmd_mpi[${mpi_idx}]="mpirun -H ${nd_nm[$((${mpi_idx_zro} % ${nd_nbr}))]} -n 1" ; ;; # Other (PBS) |
| 2407 |
# cmd_mpi[${mpi_idx}]="mpirun -H ${nd_nm[$((${mpi_idx_zro} % ${nd_nbr}))]} -npernode 1 -n 1" ; ;; # Other |
| 2408 |
esac # !HOSTNAME |
| 2409 |
case "${HOSTNAME}" in |
| 2410 |
perlmutter* | login[0123456789][0123456789] | nid* ) |
| 2411 |
# 20210319: Multiple srun commands cannot run concurrently on single Cori node without special options |
| 2412 |
# --gres=craynetwork:0 --mem=20000 tested by me, Noel Keen documented here: |
| 2413 |
# https://docs.nersc.gov/jobs/examples/#multiple-parallel-jobs-while-sharing-nodes |
| 2414 |
# These options are only expected to work on NERSC Cori |
| 2415 |
# craynetwork:0 (instead of, e.g., :1) allows any number of MPI jobs to run |
| 2416 |
# 20240406 Deprecate --gres=craynetwork:0 since not available on Perlmutter, and keep --mem option |
| 2417 |
# Argument to --mem is requested number of MB RAM per job so 96 GB Cori node with 4 MPI processes can use ~20000 MB RAM per job, and, I think, jobs in excess of that will queue until more RAM becomes available as old jobs finish |
| 2418 |
# 20210319: --zonesort=off tested by me does eliminate zonesort messages like these: |
| 2419 |
# slurmstepd: error: Detected zonesort setup failure: zonesort interface write failure (40558186.7) |
| 2420 |
# However, using zonesort option appears to slow-down throughput considerably |
| 2421 |
cmd_mpi[${mpi_idx}]="${cmd_mpi[${mpi_idx}]} --mem=${mem_mb}" ; ;; # SLURM |
| 2422 |
# cmd_mpi[${mpi_idx}]="${cmd_mpi[${mpi_idx}]} --nodes=1 --gres=craynetwork:0 --mem=${mem_mb} --zonesort=off" ; ;; # SLURM |
| 2423 |
esac # !HOSTNAME |
| 2424 |
done # !mpi_idx_zro |
| 2425 |
if [ -n "${SLURM_NODELIST}" ]; then |
| 2426 |
/bin/rm -f ${nd_fl} |
| 2427 |
fi # !SLURM |
| 2428 |
else # !nd_fl |
| 2429 |
mpi_flg='No' |
| 2430 |
for ((mpi_idx=0;mpi_idx<=mpi_nbr;mpi_idx++)); do |
| 2431 |
cmd_mpi[${mpi_idx}]='' |
| 2432 |
done # !mpi_idx |
| 2433 |
fi # !nd_fl |
| 2434 |
if [ -z "${job_usr}" ]; then |
| 2435 |
job_nbr=${nd_nbr} |
| 2436 |
fi # !job_usr |
| 2437 |
fi # !mpi_flg |
| 2438 |
|
| 2439 |
if [ "${clm_flg}" = 'Yes' ] && [ "${clm_hfc_or_mth}" = 'Yes' ] && [ "${bnr_flg}" = 'No' ]; then |
| 2440 |
# For regular monthly climos, override default job_nbr (2) with months-per-year |
| 2441 |
# If user does not explicitly set job number then, for monthly climos, base it on parallelism type |
| 2442 |
if [ -z "${job_usr}" ]; then |
| 2443 |
if [ "${par_typ}" = ${par_bck} ]; then |
| 2444 |
# Background mode will run one batch with all twelve months |
| 2445 |
job_nbr=12 |
| 2446 |
elif [ "${par_typ}" = ${par_mpi} ]; then |
| 2447 |
# MPI mode is conservative and will only use one job-per-node unless told otherwise |
| 2448 |
job_nbr=${nd_nbr} |
| 2449 |
elif [ "${par_typ}" = 'nil' ] || [ -z "${par_typ}" ]; then |
| 2450 |
# Serial mode equates to job_nbr=1, full serial |
| 2451 |
job_nbr=1 |
| 2452 |
fi # !job_usr |
| 2453 |
fi # !job_usr |
| 2454 |
fi # !clm_md !bnr_flg |
| 2455 |
|
| 2456 |
# Print initial state |
| 2457 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2458 |
printf "dbg: area_nm = ${area_nm}\n" |
| 2459 |
printf "dbg: area_wgt = ${area_wgt}\n" |
| 2460 |
printf "dbg: bfr_sz = ${bfr_sz}\n" |
| 2461 |
printf "dbg: bnr_flg = ${bnr_flg}\n" |
| 2462 |
printf "dbg: bs_nm = ${bs_nm}\n" |
| 2463 |
printf "dbg: bs_sfx = ${bs_sfx}\n" |
| 2464 |
printf "dbg: caseid = ${caseid}\n" |
| 2465 |
printf "dbg: cf_flg = ${cf_flg}\n" |
| 2466 |
printf "dbg: clm_flg = ${clm_flg}\n" |
| 2467 |
printf "dbg: clm_md = ${clm_md}\n" |
| 2468 |
printf "dbg: clm_nbr = ${clm_nbr}\n" |
| 2469 |
printf "dbg: cmp_sng = ${cmp_sng}\n" |
| 2470 |
printf "dbg: csn_lst = ${csn_lst}\n" |
| 2471 |
printf "dbg: csn_nbr = ${csn_nbr}\n" |
| 2472 |
printf "dbg: d2f_flg = ${d2f_flg}\n" |
| 2473 |
printf "dbg: d2f_opt = ${d2f_opt}\n" |
| 2474 |
printf "dbg: dbg_lvl = ${dbg_lvl}\n" |
| 2475 |
printf "dbg: dfl_lvl = ${dfl_lvl}\n" |
| 2476 |
printf "dbg: dpt_opt = ${dpt_opt}\n" |
| 2477 |
printf "dbg: drc_in = ${drc_in}\n" |
| 2478 |
printf "dbg: drc_nco = ${drc_nco}\n" |
| 2479 |
printf "dbg: drc_out = ${drc_out}\n" |
| 2480 |
printf "dbg: drc_prv = ${drc_prv}\n" |
| 2481 |
printf "dbg: drc_pwd = ${drc_pwd}\n" |
| 2482 |
printf "dbg: drc_rgr = ${drc_rgr}\n" |
| 2483 |
printf "dbg: drc_spt = ${drc_spt}\n" |
| 2484 |
printf "dbg: drc_xtn = ${drc_xtn}\n" |
| 2485 |
printf "dbg: fl_fmt = ${fl_fmt}\n" |
| 2486 |
printf "dbg: fl_nbr = ${fl_nbr}\n" |
| 2487 |
printf "dbg: flg_sum = ${flg_sum}\n" |
| 2488 |
printf "dbg: fml_nm = ${fml_nm}\n" |
| 2489 |
printf "dbg: gaa_sng = ${gaa_sng_std}\n" |
| 2490 |
printf "dbg: hdr_pad = ${hdr_pad}\n" |
| 2491 |
printf "dbg: hrd_pth = ${hrd_pth}\n" |
| 2492 |
printf "dbg: hrz_arg = ${hrz_arg}\n" |
| 2493 |
printf "dbg: hrz_dmn = ${hrz_dmn}\n" |
| 2494 |
printf "dbg: hst_nm = ${hst_nm}\n" |
| 2495 |
printf "dbg: inp_aut = ${inp_aut}\n" |
| 2496 |
printf "dbg: inp_glb = ${inp_glb}\n" |
| 2497 |
printf "dbg: inp_psn = ${inp_psn}\n" |
| 2498 |
printf "dbg: inp_std = ${inp_std}\n" |
| 2499 |
printf "dbg: job_nbr = ${job_nbr}\n" |
| 2500 |
printf "dbg: lnk_flg = ${lnk_flg}\n" |
| 2501 |
printf "dbg: mdl_nm = ${mdl_nm}\n" |
| 2502 |
printf "dbg: mdl_typ = ${mdl_typ}\n" |
| 2503 |
printf "dbg: mpi_flg = ${mpi_flg}\n" |
| 2504 |
printf "dbg: mpi_nbr = ${mpi_nbr}\n" |
| 2505 |
printf "dbg: mth_srt = ${mth_srt}\n" |
| 2506 |
printf "dbg: mth_end = ${mth_end}\n" |
| 2507 |
printf "dbg: mth_srt_rth = ${mth_srt_rth}\n" |
| 2508 |
printf "dbg: mth_end_rth = ${mth_end_rth}\n" |
| 2509 |
printf "dbg: mth_nbr = ${mth_nbr}\n" |
| 2510 |
printf "dbg: nco_opt = ${nco_opt}\n" |
| 2511 |
printf "dbg: ncr_flg = ${ncr_flg}\n" |
| 2512 |
printf "dbg: nd_nbr = ${nd_nbr}\n" |
| 2513 |
printf "dbg: nm_typ = ${nm_typ}\n" |
| 2514 |
printf "dbg: no_ntv = ${no_ntv_tms}\n" |
| 2515 |
printf "dbg: out_nm = ${out_nm}\n" |
| 2516 |
printf "dbg: par_typ = ${par_typ}\n" |
| 2517 |
printf "dbg: ppn_opt = ${ppn_opt}\n" |
| 2518 |
printf "dbg: prc_opt = ${prc_opt}\n" |
| 2519 |
printf "dbg: prc_typ = ${prc_typ}\n" |
| 2520 |
printf "dbg: qnt_prc = ${qnt_prc}\n" |
| 2521 |
printf "dbg: rgn_avg = ${rgn_avg}\n" |
| 2522 |
printf "dbg: rgn_stt = ${rgn_stt}\n" |
| 2523 |
printf "dbg: rgr_map = ${rgr_map}\n" |
| 2524 |
printf "dbg: rgr_opt = ${rgr_opt}\n" |
| 2525 |
printf "dbg: rgr_sfx = ${rgr_sfx}\n" |
| 2526 |
printf "dbg: sgm_nbr = ${sgm_nbr}\n" |
| 2527 |
printf "dbg: sgm_rmd = ${sgm_rmd}\n" |
| 2528 |
printf "dbg: sgs_frc = ${sgs_frc}\n" |
| 2529 |
printf "dbg: sum_scl = ${sum_scl}\n" |
| 2530 |
printf "dbg: thr_nbr = ${thr_nbr}\n" |
| 2531 |
printf "dbg: tm_bnd = ${tm_bnd}\n" |
| 2532 |
printf "dbg: tm_nbr = ${tm_nbr}\n" |
| 2533 |
printf "dbg: tm_var = ${tm_var}\n" |
| 2534 |
printf "dbg: tms_flg = ${tms_flg}\n" |
| 2535 |
printf "dbg: tpd_out = ${tpd_out}\n" |
| 2536 |
printf "dbg: uio_flg = ${uio_flg}\n" |
| 2537 |
printf "dbg: var_lst = ${var_lst}\n" |
| 2538 |
printf "dbg: var_xtr = ${var_xtr}\n" |
| 2539 |
printf "dbg: vrt_out = ${vrt_out}\n" |
| 2540 |
printf "dbg: vrt_xtr = ${vrt_xtr}\n" |
| 2541 |
printf "dbg: xcl_flg = ${xcl_flg}\n" |
| 2542 |
printf "dbg: xtn_flg = ${xtn_flg}\n" |
| 2543 |
printf "dbg: ypf_max = ${ypf_max}\n" |
| 2544 |
printf "dbg: yr_cln = ${yr_cln}\n" |
| 2545 |
printf "dbg: yr_nbr = ${yr_nbr}\n" |
| 2546 |
printf "dbg: yr_sbs = ${yr_sbs}\n" |
| 2547 |
printf "dbg: yyyy_end = ${yyyy_end}\n" |
| 2548 |
printf "dbg: yyyy_srt = ${yyyy_srt}\n" |
| 2549 |
printf "dbg: yyyy_srt = ${yyyy_srt}\n" |
| 2550 |
printf "dbg: yr_srt_rth = ${yr_srt_rth}\n" |
| 2551 |
printf "dbg: yr_end_rth = ${yr_end_rth}\n" |
| 2552 |
printf "dbg: yr_srtm1 = ${yr_srtm1}\n" |
| 2553 |
printf "dbg: yr_endm1 = ${yr_endm1}\n" |
| 2554 |
if [ "${csn_flg}" = 'Yes' ]; then |
| 2555 |
for ((csn_idx=0;csn_idx<${csn_nbr};csn_idx++)); do |
| 2556 |
printf "dbg: Requested season index ${csn_idx} (\"${csn_rqs[${csn_idx}]}\") is defined season index ${map_r2d[${csn_idx}]} (\"${csn_abb[${map_r2d[${csn_idx}]}]}\")\n" |
| 2557 |
idx_dtb=${map_r2d[${csn_idx}]} |
| 2558 |
printf "dbg: csn_idx = ${csn_idx}, idx_dtb = ${idx_dtb}, abb = ${csn_abb[${idx_dtb}]}, abb_lc = ${csn_abb_lc[${idx_dtb}]}, srt_idx = ${csn_srt_idx[${idx_dtb}]}, end_idx = ${csn_end_idx[${idx_dtb}]}, nom = ${csn_nom[${idx_dtb}]}, wgt = ${csn_wgt[${idx_dtb}]}\n" |
| 2559 |
done # !csn_idx |
| 2560 |
fi # !csn |
| 2561 |
fi # !dbg |
| 2562 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2563 |
if [ ${mpi_flg} = 'Yes' ]; then |
| 2564 |
for ((nd_idx=0;nd_idx<${nd_nbr};nd_idx++)); do |
| 2565 |
printf "dbg: nd_nm[${nd_idx}] = ${nd_nm[${nd_idx}]}\n" |
| 2566 |
done # !nd |
| 2567 |
fi # !mpi |
| 2568 |
fi # !dbg |
| 2569 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2570 |
psn_nbr=$# |
| 2571 |
printf "dbg: Found ${psn_nbr} positional parameters (besides \$0):\n" |
| 2572 |
for ((psn_idx=1;psn_idx<=psn_nbr;psn_idx++)); do |
| 2573 |
printf "dbg: psn_arg[${psn_idx}] = ${!psn_idx}\n" |
| 2574 |
done # !psn_idx |
| 2575 |
fi # !dbg |
| 2576 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2577 |
if [ ${inp_aut} = 'Yes' ] || [ ${inp_glb} = 'Yes' ] || [ ${inp_std} = 'Yes' ]; then |
| 2578 |
printf "dbg: Obtained or generated ${fl_nbr} input files:\n" |
| 2579 |
for ((fl_idx=0;fl_idx<fl_nbr;fl_idx++)); do |
| 2580 |
printf "dbg: fl_in[${fl_idx}] = ${fl_in[${fl_idx}]}\n" |
| 2581 |
done # !fl_idx |
| 2582 |
fi # !inp_aut |
| 2583 |
fi # !dbg |
| 2584 |
|
| 2585 |
# Human-readable summary |
| 2586 |
date_srt=$(date +"%s") |
| 2587 |
if [ ${dbg_lvl} -ge 0 ]; then |
| 2588 |
printf "Climatology operations invoked with command:\n" |
| 2589 |
echo "${cmd_ln}" |
| 2590 |
fi # !dbg |
| 2591 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2592 |
printf "************************************************************************\n" |
| 2593 |
printf "IMPORTANT: This output shows a SIMULATION of a production run\n" |
| 2594 |
printf "The metadata values are real, but the printed commands are NOT executed\n" |
| 2595 |
printf "This output is for debugging purpose only since dbg_lvl = ${dbg_lvl} >= 2\n" |
| 2596 |
printf "The elapsed time should be near 0m0s since there is very little disk I/O\n" |
| 2597 |
printf "Set dbg_lvl <= 1 for a PRODUCTION RUN that executes these commands\n" |
| 2598 |
printf "************************************************************************\n" |
| 2599 |
fi # !dbg |
| 2600 |
if [ "${tms_flg}" = 'Yes' ]; then |
| 2601 |
printf "Started climatology splitting at `date`\n" |
| 2602 |
else |
| 2603 |
printf "Started climatology generation at `date`\n" |
| 2604 |
fi # !tms_flg |
| 2605 |
printf "Running climatology script ${spt_nm} from directory ${drc_spt}\n" |
| 2606 |
printf "NCO binaries version ${nco_vrs} from directory ${drc_nco}\n" |
| 2607 |
printf "Parallelism mode for files = ${par_typ}\n" |
| 2608 |
if [ "${tms_flg}" = 'Yes' ]; then |
| 2609 |
if [ ${var_nbr} -gt 1 ]; then |
| 2610 |
printf "Timeseries will be created for each of ${var_nbr} variables\n" |
| 2611 |
if [ "${par_typ}" = ${par_bck} ]; then |
| 2612 |
printf "Background parallelism processing variables in var_nbr/job_nbr = ${var_nbr}/${job_nbr} = $((var_nbr / job_nbr)) sequential batches each concurrently processing job_nbr = ${job_nbr} jobs (1 per variable), then remaining $((var_nbr % job_nbr)) jobs/variables simultaneously\n" |
| 2613 |
elif [ "${par_typ}" = ${par_mpi} ]; then |
| 2614 |
printf "MPI parallelism dividing processing of ${var_nbr} variables onto nd_nbr = ${nd_nbr} nodes simultaneously\n" |
| 2615 |
fi # !par_typ |
| 2616 |
if [ "${par_typ}" = ${par_bck} ] || [ "${par_typ}" = ${par_mpi} ]; then |
| 2617 |
if [ "${job_nbr}" -gt ${job_nbr_wrn} ] && [ ${var_nbr} -gt ${job_nbr_wrn} ]; then |
| 2618 |
printf "WARNING: Requested number of simultaneous jobs = job_nbr = ${job_nbr} exceeds threshold number = job_nbr_wrn = ${job_nbr_wrn}. This command will start an unusually (and possibly inadvertently) large number of splitter tasks for most computers. Consequences may include insufficient RAM that leads to swapping, slow performance due to I/O contention when reading/writing data.\n" |
| 2619 |
printf "HINT: If undesirable performance occurs, use the --job_nbr option to reduce the number of simultaneous jobs, e.g., ${spt_nm} --job_nbr=100 ...\n" |
| 2620 |
fi # !job_nbr |
| 2621 |
fi # !par_typ |
| 2622 |
else # !var_nbr |
| 2623 |
printf "Timeseries will be created for only one variable\n" |
| 2624 |
fi # !var_nbr |
| 2625 |
rmd_units='year' |
| 2626 |
if [ "${mth_flg}" = 'Yes' ]; then |
| 2627 |
rmd_units='month' |
| 2628 |
fi # !mth_flg |
| 2629 |
sgm_sng='0' |
| 2630 |
if [ ${sgm_rmd} -ne 0 ]; then |
| 2631 |
sgm_sng='1' |
| 2632 |
fi # !sgm_rmd |
| 2633 |
if [ ${sgm_nbr} -gt 1 ]; then |
| 2634 |
printf "All this occurs within an outer loop of (yr_sbs/ypf_max) + (remainder, if any) = ${yr_sbs}/${ypf_max} + ${sgm_sng} = ${sgm_nbr} time segments\n" |
| 2635 |
if [ ${rmd_flg} = 'Yes' ]; then |
| 2636 |
printf "Will split data for each variable into ${sgm_nbrm1} timeseries segment(s) of length ${ypf_max} years and 1 segment of length ${sgm_rmd} ${rmd_units}(s)\n" |
| 2637 |
else # !rmd_flg |
| 2638 |
printf "Will split data for each variable into ${sgm_nbr} timeseries segment(s) of length ${ypf_max} years\n" |
| 2639 |
fi # !rmd_flg |
| 2640 |
else # !sgm_nbr |
| 2641 |
if [ ${mth_nbr} -eq 12 ]; then |
| 2642 |
printf "Will split data for each variable into one timeseries of length ${yr_sbs} years\n" |
| 2643 |
else |
| 2644 |
if [ ${clm_md} = 'hfs' ]; then |
| 2645 |
printf "Will split data for each variable into one timeseries of length ${yr_sbs} years\n" |
| 2646 |
else |
| 2647 |
if [ "${mth_flg}" = 'Yes' ]; then |
| 2648 |
printf "Will split data for each variable into one timeseries of length ${yr_sbs} years and ${sgm_rmd} months\n" |
| 2649 |
else |
| 2650 |
printf "Will split data for each variable into one timeseries of length ${yr_sbs} years and ${fl_rmd} months\n" |
| 2651 |
fi # !mth_flg |
| 2652 |
fi # !clm_md |
| 2653 |
fi # !mth_nbr |
| 2654 |
fi # !sgm_nbr |
| 2655 |
if [ ${inp_std} = 'No' ]; then |
| 2656 |
if [ "${drc_in_usr_flg}" = 'Yes' ]; then |
| 2657 |
printf "Splitting climatology from ${fl_nbr} raw input files in directory ${drc_in}\n" |
| 2658 |
else # !drc_in |
| 2659 |
printf "Splitting climatology from ${fl_nbr} raw input files specified as positional arguments\n" |
| 2660 |
fi # !drc_in |
| 2661 |
else |
| 2662 |
printf "Splitting climatology from list of ${fl_nbr} raw input files piped to stdin\n" |
| 2663 |
fi # !stdin |
| 2664 |
if [ ${clm_md} = 'ann' ]; then |
| 2665 |
printf "Each input file assumed to contain statistics for one year\n" |
| 2666 |
elif [ ${clm_md} = 'dly' ]; then |
| 2667 |
printf "Each input file assumed to contain statistics for one day\n" |
| 2668 |
elif [ ${clm_md} = 'hfs' ]; then |
| 2669 |
printf "Each input file assumed to contain statistics for ${dpf} days each comprising ${tpd_out} timesteps\n" |
| 2670 |
elif [ ${clm_md} = 'mth' ]; then |
| 2671 |
printf "Each input file assumed to contain statistics for one month\n" |
| 2672 |
fi # !mth |
| 2673 |
if [ "${rgn_stt}" != 'No' ]; then |
| 2674 |
if [ "${rgn_stt}" = 'avg' ]; then |
| 2675 |
printf "Hemispherically and globally averaged timeseries files to be saved to directory ${drc_out}\n" |
| 2676 |
elif [ "${rgn_stt}" = 'sum' ]; then |
| 2677 |
printf "Hemispherically and globally integrated (summed) timeseries files to be saved to directory ${drc_out}\n" |
| 2678 |
fi # !rgn_stt |
| 2679 |
else |
| 2680 |
printf "Native-grid timeseries files to be saved to directory ${drc_out}\n" |
| 2681 |
fi # !rgn_stt |
| 2682 |
if [ -n "${rgr_opt}" ]; then |
| 2683 |
printf "Regridded split files to directory ${drc_rgr}\n" |
| 2684 |
if [ "${thr_nbr}" -ne 1 ]; then |
| 2685 |
printf "Regridder will request ${thr_nbr} OpenMP threads to parallelize weight application across variables\n" |
| 2686 |
fi # !thr_nbr |
| 2687 |
else |
| 2688 |
printf "Split files will not be regridded\n" |
| 2689 |
fi # !rgr |
| 2690 |
fi # !tms_flg |
| 2691 |
if [ "${clm_flg}" = 'Yes' ]; then |
| 2692 |
if [ "${clm_hfc_or_mth}" = 'Yes' ] && [ "${bnr_flg}" = 'No' ]; then |
| 2693 |
if [ "${par_typ}" = ${par_bck} ]; then |
| 2694 |
printf "Background parallelism processing monthly climos in 12/job_nbr = 12/${job_nbr} = $((12 / job_nbr)) sequential batches each handling job_nbr = ${job_nbr} months concurrently\n" |
| 2695 |
elif [ "${par_typ}" = ${par_mpi} ]; then |
| 2696 |
printf "MPI parallelism processing monthly climos in 12/job_nbr = 12/${job_nbr} = $((12 / job_nbr)) sequential batches. Each batch is distributed to ${nd_nbr} nodes via round-robin scheduling and handles job_nbr = ${job_nbr} months concurrently. Load-balancing occurs with unused nodes, if any.\n" |
| 2697 |
fi # !par_typ |
| 2698 |
fi # !clm_md |
| 2699 |
if [ "${xtn_flg}" = 'No' ]; then |
| 2700 |
printf "Producing standard climatology from raw input files in directory ${drc_in}\n" |
| 2701 |
printf "Output files to directory ${drc_out}\n" |
| 2702 |
fi # !xtn_flg |
| 2703 |
if [ "${bnr_flg}" = 'Yes' ]; then |
| 2704 |
printf "Producing extended climatology in binary mode: Will combine pre-computed climatology in directory ${drc_prv} with pre-computed climatology in directory ${drc_in}\n" |
| 2705 |
printf "Output files to directory ${drc_xtn}\n" |
| 2706 |
fi # !bnr_flg |
| 2707 |
if [ "${ncr_flg}" = 'Yes' ]; then |
| 2708 |
printf "Producing extended climatology in incremental mode: Pre-computed climatology in directory ${drc_prv} will be incremented by raw input files in directory ${drc_in}\n" |
| 2709 |
printf "Output files to directory ${drc_xtn}\n" |
| 2710 |
fi # !ncr_flg |
| 2711 |
if [ "${bnr_flg}" = 'No' ]; then |
| 2712 |
printf "Climatology from ${yr_nbr} years of contiguous raw data touching ${yr_cln} calendar years from YYYYMM = ${yyyy_srt}${mm_srt} to ${yyyy_end}${mm_end}\n" |
| 2713 |
fi # !bnr_flg |
| 2714 |
if [ "${inp_aut}" = 'Yes' ]; then |
| 2715 |
if [ "${nm_typ}" = 'yyyymm' ]; then |
| 2716 |
printf "Input filenames will be constructed with generic conventions as ${bs_nm}_YYYYMM.${bs_sfx}\n" |
| 2717 |
elif [ "${nm_typ}" = 'yyyy-mm' ]; then |
| 2718 |
printf "Input filenames will be constructed with generic conventions as ${bs_nm}.YYYY-MM.${bs_sfx}\n" |
| 2719 |
elif [ "${nm_typ}" = 'yyyy-mm-01' ]; then |
| 2720 |
printf "Input filenames will be constructed with generic conventions as ${bs_nm}.YYYY-MM-01.${bs_sfx}\n" |
| 2721 |
elif [ "${nm_typ}" = 'yyyy-mm-01-00000' ]; then |
| 2722 |
printf "Input filenames will be constructed with generic conventions as ${bs_nm}.YYYY-MM-01-00000.${bs_sfx}\n" |
| 2723 |
elif [ "${nm_typ}" = 'mpas' ]; then |
| 2724 |
printf "Input filenames will be constructed with MPAS conventions\n" |
| 2725 |
else |
| 2726 |
printf "Input filenames will be constructed with CESM'ish or E3SM'ish conventions\n" |
| 2727 |
fi # !nm_typ |
| 2728 |
else |
| 2729 |
printf "Input filenames will be read (not constructed) from globbing, positional arguments, or stdin\n" |
| 2730 |
fi # !inp_aut |
| 2731 |
if [ ${clm_md} = 'ann' ]; then |
| 2732 |
printf "Each input file assumed to contain statistic for one year\n" |
| 2733 |
elif [ ${clm_md} = 'dly' ]; then |
| 2734 |
printf "Each input file assumed to contain statistics for one or more daily or sub-daily (e.g., 3-hourly) means\n" |
| 2735 |
elif [ ${clm_md} = 'hfc' ]; then |
| 2736 |
printf "Each input file assumed to contain statistics for an integer number of days each comprising ${tpd_out} timesteps\n" |
| 2737 |
elif [ ${clm_md} = 'mth' ]; then |
| 2738 |
printf "Each input file assumed to contain statistic for one month\n" |
| 2739 |
fi # !mth |
| 2740 |
if [ "${clm_hfc_or_mth}" = 'Yes' ]; then |
| 2741 |
if [ ${csn_flg} = 'No' ]; then |
| 2742 |
printf "Seasons and therefore annual means derived from seasonal means have been turned-off and will not be computed\n" |
| 2743 |
elif [ ${mth_srt_rth} = '12' ]; then |
| 2744 |
printf "Winter statistics based on seasonally contiguous December (djf-mode): DJF-means formed from consecutive DJF months that cross calendar-year boundaries\n" |
| 2745 |
elif [ ${mth_srt_rth} = '1' ]; then |
| 2746 |
printf "Winter statistics based on seasonally discontiguous December (jfd-mode): Means labeled as \"DJF\" are formed from JFD months from the same calendar year\n" |
| 2747 |
elif [ ${mth_srt_rth} = '2' ]; then |
| 2748 |
printf "Winter statistics based on seasonally discontiguous December (fdj-mode): Means labeled as \"DJF\" are formed from FDJ that cross calendar-year boundaries\n" |
| 2749 |
fi # !csn_flg |
| 2750 |
fi # !mth |
| 2751 |
if [ ${cf_flg} = 'Yes' ]; then |
| 2752 |
printf "Annotation for CF climatology attribute and climatology_bounds variable will be performed\n" |
| 2753 |
else |
| 2754 |
printf "Annotation for CF climatology attribute and climatology_bounds variable will not be performed\n" |
| 2755 |
fi # !cf |
| 2756 |
if [ -n "${rgr_opt}" ]; then |
| 2757 |
printf "This climatology will also be regridded\n" |
| 2758 |
printf "Regridder will request ${thr_nbr} OpenMP threads to parallelize weight application across variables\n" |
| 2759 |
else |
| 2760 |
printf "This climatology will not be regridded\n" |
| 2761 |
fi # !rgr |
| 2762 |
fi # !clm_flg |
| 2763 |
|
| 2764 |
# Block 1: Generate, check, and store (but do not yet execute) commands |
| 2765 |
|
| 2766 |
# Block 1 Loop 1: Produce monthly-mean climatology output |
| 2767 |
if [ "${clm_flg}" = 'Yes' ] && [ "${clm_hfc_or_mth}" = 'Yes' ]; then |
| 2768 |
clm_idx=0 |
| 2769 |
for mth in {01..12}; do |
| 2770 |
let clm_idx=${clm_idx}+1 |
| 2771 |
MM=`printf "%02d" ${clm_idx}` |
| 2772 |
# The same month-of-year appears every twelve filenames in input list |
| 2773 |
if [ ${clm_md} = 'mth' ]; then |
| 2774 |
fl_all='' |
| 2775 |
for ((yr_idx=0;yr_idx<yr_nbr;yr_idx++)); do |
| 2776 |
# Initialize fl_idx as if first supplied month were January |
| 2777 |
let fl_idx=$((clm_idx - 1)) |
| 2778 |
# 20260323 Adjust fl_idx by January offset, then use modulo twelve to point fl_idx to first occurence of MM in file list |
| 2779 |
let fl_idx=$(( (fl_idx + jan_fst) % 12)) |
| 2780 |
# Adjust fl_idx by 12 per year to the current year |
| 2781 |
let fl_idx=$(( fl_idx + yr_idx * 12)) |
| 2782 |
|
| 2783 |
fl_all="${fl_all} ${fl_in[${fl_idx}]}" |
| 2784 |
done # !yr_idx |
| 2785 |
|
| 2786 |
# Check for existence of raw input only when file will be used |
| 2787 |
if [ "${bnr_flg}" = 'No' ]; then |
| 2788 |
for fl_crr in ${fl_all} ; do |
| 2789 |
if [ ! -f "${drc_in}/${fl_crr}" ] && [ ! -L "${drc_in}/${fl_crr}" ]; then |
| 2790 |
echo "${spt_nm}: ERROR Unable to find required input file ${drc_in}/${fl_crr}" |
| 2791 |
echo "${spt_nm}: HINT All files implied to exist by the climatology bounds (start/end year/month) and by the specified (with -P or -m) or default model type, must be in ${drc_in} before ${spt_nm} will proceed" |
| 2792 |
exit 1 |
| 2793 |
fi # ! -f |
| 2794 |
done # !fl_crr |
| 2795 |
else # !bnr_flg |
| 2796 |
# In binary mode drc_out is actually used to locate input files from climatology B (same as output files in incremental mode) |
| 2797 |
drc_out="${drc_in}" |
| 2798 |
fi # !bnr_flg |
| 2799 |
|
| 2800 |
fi # !clm_md |
| 2801 |
|
| 2802 |
# Common to both high-frequency and monthly-input climos |
| 2803 |
yyyy_rng=$(csn_nfo_get ${yr_srt} ${mth_srt} ${yr_end} ${mth_end} ${clm_idx} ${clm_idx} ${rtn_yyyy_rng}) |
| 2804 |
if [ -n "${gaa_sng_std}" ]; then |
| 2805 |
# NB: E3SM diagnostics (e3sm_diagnostics) relies on this attribute |
| 2806 |
gaa_sng[${clm_idx}]="${gaa_sng_std} --gaa yrs_averaged=${yyyy_rng}" |
| 2807 |
fi # !gaa_sng |
| 2808 |
fl_out[${clm_idx}]="${drc_out}/${out_nm}_${MM}_${yyyy_srt_mth[${clm_idx}]}${MM}_${yyyy_end_mth[${clm_idx}]}${MM}_climo.nc" |
| 2809 |
|
| 2810 |
if [ ${clm_md} = 'hfc' ]; then |
| 2811 |
# Computing climos from high-freqency data requires many steps: |
| 2812 |
# A primary goal is to re-use not re-write code, especially existing monthly frequency climo code |
| 2813 |
# Otherwise code maintainability significantly suffers |
| 2814 |
# Code-reuse all-but-requires same existing parallelization as monthly frequency climos |
| 2815 |
# Difficulty is that traditionally monthly mean climos equally weight all input records using ncra |
| 2816 |
# Proposed Algorithm: |
| 2817 |
# 1. Re-use splitter option ypf for intermediate files so users can prevent excessive intermediate filesizes |
| 2818 |
# 2. Generate month-aligned intermediate segments containing ypf instances of a single month (and no other months) for all variables |
| 2819 |
# 2a. To subset repeated appearances of given month and skip intervening 11 months, command must have form ncrcat -d time,srt_sng,end_sng,srd,ssc where srd=dpy*tpd and ssc=dpm*tpd |
| 2820 |
# 2b. Same as draft annual-mean HFS feature for diurnal cycle, except srt_sng/end_sng are "yyyy_srt_sgm-MM-01 00:00:01/yyyy_end_sgm-(MMp1)-01 00:00:00" instead of "yyyy_srt_sgm-01-01 00:00:01/yyyy_endp1_sgm-01-01 00:00:00" |
| 2821 |
# 2c. Intermediate monthly segments sgm_yyyy_srt_yyyy_end_MM.nc have ypf instances of given month, except last segment may be ragged |
| 2822 |
# 2d. Evaluate mean diurnal cycle of monthly-segment using ncra --d time,srt,end,srd=ssc,ssc=dpm*tpd,tpd |
| 2823 |
# 2c. Ragged numbers of ypf in last segment suggests using ncra climatological monthly diurnal-mean output |
| 2824 |
# 2d. Parallelize this over month (probably) using job_nbr algorithm? or over segment (unlikely)? |
| 2825 |
# 2e. Parallelization is difficult/tedious due to number of basic blocks (3? 4? 5?) |
| 2826 |
# 3. Intermediate files of shape (time=min(actual,ypf),hour,space) are nearly interchangeable with monthly-frequency output in stage-1 ncra |
| 2827 |
# 4. Use climatological monthly diurnal-mean output to create climatological seasonal diurnal-mean output |
| 2828 |
# 5. Use climatological monthly seasonal-mean output to create climatological annual diurnal-mean output |
| 2829 |
# 6. Final output climo format: (time=1,hour,space) (or convert to (time=hour,space)?) |
| 2830 |
# Advantages: |
| 2831 |
# 1. Code-reuse and maintainability |
| 2832 |
# 2. Scales to any length o simulation (intermediate files can be a single month) |
| 2833 |
# 3. Output similar to existing monthly-frequency climos with new, fixed-length 'hour' dimension |
| 2834 |
# 4. Climatology bounds attributes correct for time variable(?) |
| 2835 |
# Disadvantages: |
| 2836 |
# 1. E3SM-diags post-processing may not like new 'hour' dimension |
| 2837 |
# 2. No corresponding examples in CF Conventions |
| 2838 |
# 3. Any utility in multiple-variables per output file, e.g., TS, PRECT? Would single variables suffice? |
| 2839 |
DD=`printf "%02d" ${dpm[${clm_idx}]}` |
| 2840 |
tm_srt="${yyyy_clm_srt}-${MM}-01T00:00:01" |
| 2841 |
let mthp1=$((clm_idx + 1)) |
| 2842 |
MMp1=`printf "%02d" ${mthp1}` |
| 2843 |
tm_end="${yyyy_clm_end}-${MMp1}-01T00:00:00" |
| 2844 |
yyyy_clm_endp1=`printf "%04d" ${yr_endp1}` |
| 2845 |
if [ ${clm_idx} -eq 12 ]; then |
| 2846 |
tm_srt="${yyyy_clm_srt_dec}-${MM}-01T00:00:01" |
| 2847 |
yyyy_clm_endp1=`printf "%04d" ${yr_endp1}` |
| 2848 |
tm_end="${yyyy_clm_endp1}-01-01T00:00:00" |
| 2849 |
fi # !December |
| 2850 |
let srd=${dpy}*${tpd_out} |
| 2851 |
let ssc=${dpm[${clm_idx}]}*${tpd_out} |
| 2852 |
|
| 2853 |
# Cull this month from interannual climatology into interannual diurnal file |
| 2854 |
fl_mth[${clm_idx}]="${drc_out}/${out_nm}_${MM}_tms_foo_${yyyy_clm_srt}_${yyyy_clm_end}.nc" |
| 2855 |
|
| 2856 |
# Command to produce interleaved monthly climos |
| 2857 |
if [ "${fl_nbr}" -eq 1 ]; then |
| 2858 |
# Compute interleaved mean of single-file input (e.g., CMIP timeseries format) |
| 2859 |
#cmd_clm[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncra -O ${nco_opt} ${gaa_sng[${clm_idx}]} -d time,${tm_srt},${tm_end},${srd},${ssc},${tpd_out} ${fl_in} ${fl_out[${clm_idx}]}" |
| 2860 |
tm_nbr=`ncks --trd -M ${ppn_opt} ${fl_in} | grep -E -i "^Root record dimension 0:" | cut -f 10- -d ' '` |
| 2861 |
let ssc2=${tm_nbr}*${tpd_out}/${srd} |
| 2862 |
# Ensure result is positive integer |
| 2863 |
[ "${ssc2}" -ge 0 ] 2>/dev/null && ssc2_ntg='Yes' || ssc2_ntg='No' |
| 2864 |
if [ "${ssc2_ntg}" != 'Yes' ]; then |
| 2865 |
printf "${spt_nm}: ERROR Inferred value of ssc2=${ssc2} is not a positive integer. User requested high-frequency climatology with one input file. ${spt_nm} attempted to divine the sub-cycle length based on the assumption that the file contains and integral number of years (at any temporal resolution) of input data. The divination resulted in a non-integral sub-cycle length. This is not surprising since a number of assumptions must hold true for the inferral to work correctly.\nHINT: Clip the input timeseries to an integral number of years.\n" |
| 2866 |
exit 1 |
| 2867 |
fi # !ssc2_ntg |
| 2868 |
|
| 2869 |
cmd_cll[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncra -O ${nco_opt} ${gaa_sng[${clm_idx}]} -d time,${tm_srt},${tm_end},${srd},${ssc},${tpd_out} ${fl_in} ${fl_mth[${clm_idx}]}" |
| 2870 |
|
| 2871 |
cmd_clm[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncra --clm_bnd=${yyyy_srt_mth[${clm_idx}]},${yyyy_end_mth[${clm_idx}]},${clm_idx},${clm_idx},${tpd_out} -O ${nco_opt} ${gaa_sng[${clm_idx}]} -d time,,,,${ssc2},${tpd_out} ${fl_mth[${clm_idx}]} ${fl_out[${clm_idx}]}" |
| 2872 |
|
| 2873 |
else # !fl_nbr |
| 2874 |
# Concatenate means of each interleaved index of multi-file input (e.g., raw history output or multiple segments) |
| 2875 |
|
| 2876 |
cmd_cll[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncrcat -O ${nco_opt} ${gaa_sng[${clm_idx}]} -d time,${tm_srt},${tm_end},${srd},${ssc} ${ppn_opt} ${fl_in[*]} ${fl_mth[${clm_idx}]}" |
| 2877 |
|
| 2878 |
# Take mean value of each diurnal timestep across all instances of this month |
| 2879 |
fl_tpd_tpl[${clm_idx}]="${drc_out}/${out_nm}_${MM}_tpdTPDTT_${yyyy_clm_srt}_${yyyy_clm_end}.nc" |
| 2880 |
cmd_tpd_tpl[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncra -O ${nco_opt} ${gaa_sng[${clm_idx}]} -d time,TPDidx,,${tpd_out} ${fl_mth[${clm_idx}]} ${fl_tpd_tpl[${clm_idx}]}" |
| 2881 |
|
| 2882 |
# Concatenate individual timestep means into full diurnal timeseries |
| 2883 |
cmd_clm[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncrcat -O --clm_bnd=${yyyy_srt_mth[${clm_idx}]},${yyyy_end_mth[${clm_idx}]},${clm_idx},${clm_idx},${tpd_out} ${nco_opt} ${gaa_sng[${clm_idx}]} ${drc_out}/${out_nm}_${MM}_tpd* ${fl_out[${clm_idx}]}" |
| 2884 |
fi # !fl_nbr |
| 2885 |
# Combine monthly into seasonal and annual means with nces (preserving diurnal timesteps) |
| 2886 |
cmd_mth2csn='nces' |
| 2887 |
cmd_csn2ann='nces' |
| 2888 |
elif [ ${clm_md} = 'mth' ]; then |
| 2889 |
clm_bnd[${clm_idx}]=${yyyy_srt_mth[${clm_idx}]},${yyyy_end_mth[${clm_idx}]},${clm_idx},${clm_idx},0 |
| 2890 |
cmd_clm[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncra --clm_bnd=${clm_bnd[${clm_idx}]} -O ${nco_opt} ${gaa_sng[${clm_idx}]} ${ppn_opt} ${fl_all} ${fl_out[${clm_idx}]}" |
| 2891 |
# Combine monthly into seasonal and annual means with ncra |
| 2892 |
cmd_mth2csn='ncra' |
| 2893 |
cmd_csn2ann='ncra' |
| 2894 |
fi # !clm_md |
| 2895 |
done # !mth |
| 2896 |
|
| 2897 |
if [ ${clm_md} = 'hfc' ]; then |
| 2898 |
|
| 2899 |
if [ "${fl_nbr}" -gt 1 ]; then |
| 2900 |
printf "Cull each month from interannual climatology into interannual diurnal file...\n" |
| 2901 |
else |
| 2902 |
printf "Create interannual timeseries of monthly diurnal timestep means from single file...\n" |
| 2903 |
fi # !fl_nbr |
| 2904 |
[[ ${dbg_lvl} -ge 1 ]] && date_cll=$(date +"%s") |
| 2905 |
|
| 2906 |
if [ ${job_nbr} -eq 1 ] || [ ${job_nbr} -eq 2 ] || [ ${job_nbr} -eq 3 ] || [ ${job_nbr} -eq 4 ] || [ ${job_nbr} -eq 6 ] || [ ${job_nbr} -eq 12 ]; then |
| 2907 |
echo "Successful match of job_nbr to list of permissible values" > /dev/null |
| 2908 |
else |
| 2909 |
echo "${spt_nm}: ERROR Job number job_nbr=${job_nbr} is invalid in monthly climo mode. Must be a factor of 12. Valid values are 1, 2, 3, 4, 6, and 12. Please re-submit with valid job_nbr." |
| 2910 |
exit 1 |
| 2911 |
fi # !job_nbr |
| 2912 |
|
| 2913 |
# Batch number is inverse to job number, so job_nbr=1->bch_nbr=12 (serial mode, slowest), job_nbr=2->bch_nbr=6, ... job_nbr=12->bch_nbr=1 (full background mode, fastest) |
| 2914 |
let bch_nbr=$((12 / job_nbr)) |
| 2915 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 2916 |
# clm_idx is 1-based, bch_idx is 0-based |
| 2917 |
let clm_idx_srt=$(((bch_idx * job_nbr) + 1)) |
| 2918 |
let clm_idx_end=$((clm_idx_srt + job_nbr - 1)) |
| 2919 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 2920 |
printf "Cull climatological monthly timeseries for month ${clm_idx} ...\n" |
| 2921 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2922 |
echo ${cmd_cll[${clm_idx}]} |
| 2923 |
fi # !dbg |
| 2924 |
if [ ${dbg_lvl} -le 1 ]; then |
| 2925 |
if [ -z "${par_opt}" ]; then |
| 2926 |
eval ${cmd_cll[${clm_idx}]} |
| 2927 |
if [ "$?" -ne 0 ]; then |
| 2928 |
printf "${spt_nm}: ERROR monthly cull cmd_cll[${clm_idx}] failed. Debug this:\n${cmd_cll[${clm_idx}]}\n" |
| 2929 |
exit 1 |
| 2930 |
fi # !err |
| 2931 |
else # !par_opt |
| 2932 |
eval ${cmd_cll[${clm_idx}]} ${par_opt} # eval always returns 0 on backgrounded processes |
| 2933 |
cll_pid[${clm_idx}]=$! |
| 2934 |
fi # !par_opt |
| 2935 |
fi # !dbg |
| 2936 |
done # !clm_idx |
| 2937 |
if [ -n "${par_opt}" ]; then |
| 2938 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 2939 |
wait ${cll_pid[${clm_idx}]} |
| 2940 |
if [ "$?" -ne 0 ]; then |
| 2941 |
printf "${spt_nm}: ERROR monthly cull cmd_cll[${clm_idx}] failed. Debug this:\n${cmd_cll[${clm_idx}]}\n" |
| 2942 |
# 20200805: exiting parent here creates orphans, kill live children then exit |
| 2943 |
for ((kid_idx=clm_idx+1;kid_idx<=clm_idx_end;kid_idx++)); do |
| 2944 |
kill -9 ${cll_pid[${kid_idx}]} |
| 2945 |
done # !kid_idx |
| 2946 |
exit 1 |
| 2947 |
fi # !err |
| 2948 |
done # !clm_idx |
| 2949 |
fi # !par_opt |
| 2950 |
done # !bch_idx |
| 2951 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2952 |
date_crr=$(date +"%s") |
| 2953 |
date_dff=$((date_crr-date_cll)) |
| 2954 |
echo "Elapsed time to cull monthly timeseries $((date_dff/60))m$((date_dff % 60))s" |
| 2955 |
fi # !dbg |
| 2956 |
|
| 2957 |
if [ "${fl_nbr}" -gt 1 ]; then |
| 2958 |
|
| 2959 |
printf "Take mean value of each diurnal timestep across all instances of every month...\n" |
| 2960 |
[[ ${dbg_lvl} -ge 1 ]] && date_tpd=$(date +"%s") |
| 2961 |
|
| 2962 |
for ((tpd_idx=0;tpd_idx<tpd_out;tpd_idx++)); do |
| 2963 |
TT=`printf "%02d" ${tpd_idx}` |
| 2964 |
printf "Compute monthly means for diurnal timestep ${tpd_idx}...\n" |
| 2965 |
let bch_nbr=$((12 / job_nbr)) |
| 2966 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 2967 |
# clm_idx is 1-based, bch_idx is 0-based |
| 2968 |
let clm_idx_srt=$(((bch_idx * job_nbr) + 1)) |
| 2969 |
let clm_idx_end=$((clm_idx_srt + job_nbr - 1)) |
| 2970 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 2971 |
printf "De-interleave and average diurnal timestep ${tpd_idx} for month ${clm_idx} ...\n" |
| 2972 |
cmd_tpd[${clm_idx}]=${cmd_tpd_tpl[${clm_idx}]/TPDTT/${TT}} |
| 2973 |
cmd_tpd[${clm_idx}]=${cmd_tpd[${clm_idx}]/TPDidx/${tpd_idx}} |
| 2974 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2975 |
echo ${cmd_tpd[${clm_idx}]} |
| 2976 |
fi # !dbg |
| 2977 |
if [ ${dbg_lvl} -le 1 ]; then |
| 2978 |
if [ -z "${par_opt}" ]; then |
| 2979 |
eval ${cmd_tpd[${clm_idx}]} |
| 2980 |
if [ "$?" -ne 0 ]; then |
| 2981 |
printf "${spt_nm}: ERROR monthly de-interleave and average command cmd_tpd[${clm_idx}] failed. Debug this:\n${cmd_tpd[${clm_idx}]}\n" |
| 2982 |
exit 1 |
| 2983 |
fi # !err |
| 2984 |
else # !par_opt |
| 2985 |
eval ${cmd_tpd[${clm_idx}]} ${par_opt} # eval always returns 0 on backgrounded processes |
| 2986 |
tpd_pid[${clm_idx}]=$! |
| 2987 |
fi # !par_opt |
| 2988 |
fi # !dbg |
| 2989 |
done # !clm_idx |
| 2990 |
if [ -n "${par_opt}" ]; then |
| 2991 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 2992 |
wait ${tpd_pid[${clm_idx}]} |
| 2993 |
if [ "$?" -ne 0 ]; then |
| 2994 |
printf "${spt_nm}: ERROR monthly de-interleave and average command cmd_tpd[${clm_idx}] failed. Debug this:\n${cmd_tpd[${clm_idx}]}\n" |
| 2995 |
# 20200805: exiting parent here creates orphans, kill live children then exit |
| 2996 |
for ((kid_idx=clm_idx+1;kid_idx<=clm_idx_end;kid_idx++)); do |
| 2997 |
kill -9 ${tpd_pid[${kid_idx}]} |
| 2998 |
done # !kid_idx |
| 2999 |
exit 1 |
| 3000 |
fi # !err |
| 3001 |
done # !clm_idx |
| 3002 |
fi # !par_opt |
| 3003 |
done # !bch_idx |
| 3004 |
done # !tpd_idx |
| 3005 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3006 |
date_crr=$(date +"%s") |
| 3007 |
date_dff=$((date_crr-date_tpd)) |
| 3008 |
echo "Elapsed time to de-interleave and average all timesteps $((date_dff/60))m$((date_dff % 60))s" |
| 3009 |
fi # !dbg |
| 3010 |
|
| 3011 |
# Clean-up monthly inputs (important since these file can be huge) |
| 3012 |
for ((clm_idx=1;clm_idx<=12;clm_idx++)); do |
| 3013 |
/bin/rm -f ${fl_mth[${clm_idx}]} |
| 3014 |
done # !clm_idx |
| 3015 |
|
| 3016 |
fi # !fl_nbr |
| 3017 |
|
| 3018 |
fi # !clm_md |
| 3019 |
|
| 3020 |
if [ ${clm_md} = 'mth' ]; then |
| 3021 |
tpd_out=0 |
| 3022 |
fi # !tpd_out |
| 3023 |
# Monthly output filenames constructed above; specify remaining (seasonal, annual) output names |
| 3024 |
for ((csn_idx=0;csn_idx<${csn_nbr};csn_idx++)); do |
| 3025 |
# Produce names like "${out_nm}_MAM_${yyyy_srt}03_${yyyy_end}05_climo.nc" |
| 3026 |
# What should JJA name for yr_srt=2013, mth_srt=7, yr_end=2014, mth_end=6 be? |
| 3027 |
# Normal climos use 201306-201408 but there is no 201306 or 201408 in this dataset! |
| 3028 |
# Alternative 201406-201308 is non-chronological (though maybe OK)? |
| 3029 |
# Alternative 201307-201406 is chronological. No August indicator in date string. |
| 3030 |
# People prefer the chronological option alternative, which we call yyyymm_rng |
| 3031 |
let clm_idx=1+12+${csn_idx} |
| 3032 |
# 20260323 Start and end years now depend on start and end months |
| 3033 |
csn_srt_idx_crr=${csn_srt_idx[${map_r2d[${csn_idx}]}]} |
| 3034 |
csn_end_idx_crr=${csn_end_idx[${map_r2d[${csn_idx}]}]} |
| 3035 |
yyyymm_frs=$(csn_nfo_get ${yr_srt_rth} ${mth_srt_rth} ${yr_end_rth} ${mth_end_rth} ${csn_srt_idx_crr} ${csn_end_idx_crr} ${rtn_yyyymm_frs}) |
| 3036 |
yyyymm_lst=$(csn_nfo_get ${yr_srt_rth} ${mth_srt_rth} ${yr_end_rth} ${mth_end_rth} ${csn_srt_idx_crr} ${csn_end_idx_crr} ${rtn_yyyymm_lst}) |
| 3037 |
yyyymm_rng=$(csn_nfo_get ${yr_srt_rth} ${mth_srt_rth} ${yr_end_rth} ${mth_end_rth} ${csn_srt_idx_crr} ${csn_end_idx_crr} ${rtn_yyyymm_rng}) |
| 3038 |
yyyy_rng=$(csn_nfo_get ${yr_srt_rth} ${mth_srt_rth} ${yr_end_rth} ${mth_end_rth} ${csn_srt_idx_crr} ${csn_end_idx_crr} ${rtn_yyyy_rng}) |
| 3039 |
clm_bnd_arg=$(csn_nfo_get ${yr_srt_rth} ${mth_srt_rth} ${yr_end_rth} ${mth_end_rth} ${csn_srt_idx_crr} ${csn_end_idx_crr} ${rtn_clm_bnd_arg}) |
| 3040 |
clm_bnd[${clm_idx}]="--clm_bnd=${clm_bnd_arg},${tpd_out}" |
| 3041 |
if [ -n "${gaa_sng_std}" ]; then |
| 3042 |
# NB: E3SM diagnostics (e3sm_diagnostics) relies on this attribute |
| 3043 |
gaa_sng[${clm_idx}]="${gaa_sng_std} --gaa yrs_averaged=${yyyy_rng}" |
| 3044 |
fi # !gaa_sng |
| 3045 |
fl_out[${clm_idx}]="${drc_out}/${out_nm}_${csn_abb[${map_r2d[${csn_idx}]}]}_${yyyymm_rng}_climo.nc" |
| 3046 |
done # !csn_idx |
| 3047 |
# fl_out[13]="${drc_out}/${out_nm}_MAM_${yyyy_srt}03_${yyyy_end}05_climo.nc" |
| 3048 |
# fl_out[14]="${drc_out}/${out_nm}_JJA_${yyyy_srt}06_${yyyy_end}08_climo.nc" |
| 3049 |
# fl_out[15]="${drc_out}/${out_nm}_SON_${yyyy_srt}09_${yyyy_end}11_climo.nc" |
| 3050 |
# fl_out[16]="${drc_out}/${out_nm}_DJF_${yyyy_clm_srt_dec}${mm_djf_srt}_${yyyy_end}${mm_djf_end}_climo.nc" |
| 3051 |
if [ "${ann_flg}" = 'Yes' ]; then |
| 3052 |
yyyy_rng=$(csn_nfo_get ${yr_srt_rth} ${mth_srt_rth} ${yr_end_rth} ${mth_end_rth} 1 12 ${rtn_yyyy_rng}) |
| 3053 |
if [ -n "${gaa_sng_std}" ]; then |
| 3054 |
# NB: E3SM diagnostics (e3sm_diagnostics) relies on this attribute |
| 3055 |
gaa_sng[${clm_nbr}]="${gaa_sng_std} --gaa yrs_averaged=${yyyy_rng}" |
| 3056 |
fi # !gaa_sng |
| 3057 |
fl_out[${clm_nbr}]="${drc_out}/${out_nm}_ANN_${yyyy_srt}${mm_srt}_${yyyy_end}${mm_end}_climo.nc" |
| 3058 |
clm_bnd[${clm_nbr}]="--clm_bnd=${yyyy_srt},${yyyy_end},${mm_srt},${mm_end},${tpd_out}" |
| 3059 |
fi # !ann_flg |
| 3060 |
# Derive all regridded and AMWG names from output names |
| 3061 |
for ((clm_idx=1;clm_idx<=clm_nbr;clm_idx++)); do |
| 3062 |
fl_amwg[${clm_idx}]=`expr match "${fl_out[${clm_idx}]}" '\(.*\)_.*_.*_climo.nc'` # Prune _YYYYYMM_YYYYMM_climo.nc |
| 3063 |
fl_amwg[${clm_idx}]="${fl_amwg[${clm_idx}]}_climo.nc" # Replace with _climo.nc |
| 3064 |
fl_amwg[${clm_idx}]="${fl_amwg[${clm_idx}]/${drc_out}\//}" # Delete prepended path to ease symlinking |
| 3065 |
if [ -n "${rgr_opt}" ]; then |
| 3066 |
fl_rgr[${clm_idx}]="${fl_out[${clm_idx}]/${drc_out}/${drc_rgr}}" |
| 3067 |
if [ "${drc_out}" = "${drc_rgr}" ]; then |
| 3068 |
# Append geometry suffix to regridded files in same directory as native climo |
| 3069 |
# http://tldp.org/LDP/abs/html/string-manipulation.html |
| 3070 |
dfl_sfx='rgr' |
| 3071 |
rgr_sfx=`expr match "${rgr_map}" '.*_to_\(.*\).nc'` |
| 3072 |
if [ "${#rgr_sfx}" -eq 0 ]; then |
| 3073 |
printf "${spt_nm}: WARNING Unable to extract geometric suffix from mapfile, will suffix regridded files with \"${dfl_sfx}\" instead\n" |
| 3074 |
rgr_sfx=${dfl_sfx} |
| 3075 |
else |
| 3076 |
yyyymmdd_sng=`expr match "${rgr_sfx}" '.*\(\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)'` # Find YYYYYMMDD |
| 3077 |
if [ "${#yyyymmdd_sng}" -ne 0 ]; then |
| 3078 |
rgr_sfx=${rgr_sfx%%${yyyymmdd_sng}} # Delete YYYYYMMDD |
| 3079 |
fi # !strlen |
| 3080 |
fi # !strlen |
| 3081 |
# rgr_sfx=`expr match "${rgr_sfx}" '\(.*\)\.[0-9][0-9][0-9][0-9][0-9][0-9]'` # |
| 3082 |
fl_rgr[${clm_idx}]="${fl_rgr[${clm_idx}]/.nc/_${rgr_sfx}.nc}" |
| 3083 |
fi # !drc_rgr |
| 3084 |
fi # !rgr_opt |
| 3085 |
done # !clm_idx |
| 3086 |
fi # !clm_md |
| 3087 |
|
| 3088 |
# Block 1 Loop N: Split |
| 3089 |
if [ "${tms_flg}" = 'Yes' ]; then |
| 3090 |
|
| 3091 |
# Populate input file arguments fl_sgm with all files necessary to bracket each segment |
| 3092 |
for ((sgm_idx=0;sgm_idx<sgm_nbr;sgm_idx++)); do |
| 3093 |
fl_sgm[${sgm_idx}]='' |
| 3094 |
|
| 3095 |
if [ "${clm_md}" != 'hfs' ]; then |
| 3096 |
# Non-high-frequency timeseries receive exact file-lists to hyperslab by index (not by time-coordinate) |
| 3097 |
if [ "${mth_flg}" = 'Yes' ]; then |
| 3098 |
let fl_idx_srt=${sgm_idx}*${ypf_max}*${fpy} # NB: 0-based |
| 3099 |
let fl_idx_end=${fl_idx_srt}+${ypf_max}*${fpy} # NB: 1-based |
| 3100 |
let yr_srt_sgm=${yr_srt_rth}+${sgm_idx}*${ypf_max} |
| 3101 |
let yr_end_sgm=${yr_srt_sgm}+${ypf_max} |
| 3102 |
if [ ${sgm_rmd} -ne 0 ] && [ ${sgm_idx} -eq ${sgm_nbrm1} ]; then |
| 3103 |
let fl_idx_end=${fl_idx_srt}+${sgm_rmd} # NB: 1-based |
| 3104 |
let yr_end_sgm=${yr_end_rth} |
| 3105 |
fi # !sgm_nbrm1 |
| 3106 |
else # !mth_flg |
| 3107 |
let fl_idx_srt=${sgm_idx}*${ypf_max}*${fpy} # NB: 0-based |
| 3108 |
let fl_idx_end=${fl_idx_srt}+${ypf_max}*${fpy} # NB: 1-based |
| 3109 |
let yr_srt_sgm=${yr_srt_rth}+${sgm_idx}*${ypf_max} |
| 3110 |
let yr_end_sgm=${yr_srt_sgm}+${ypf_max}-1 |
| 3111 |
if [ ${sgm_rmd} -ne 0 ] && [ ${sgm_idx} -eq ${sgm_nbrm1} ]; then |
| 3112 |
let fl_idx_end=${fl_idx_srt}+${sgm_rmd}*${fpy} # NB: 1-based |
| 3113 |
let yr_end_sgm=${yr_srt_sgm}+${sgm_rmd}-1 |
| 3114 |
fi # !sgm_nbrm1 |
| 3115 |
fi # !mth_flg |
| 3116 |
else # !clm_md |
| 3117 |
# High-frequency timeseries are hyperslabbed by date and so need fuzzy file-lists |
| 3118 |
# that may contain an extra file or two in case year-boundaries are intermediate records. |
| 3119 |
# 20210331: Prior to now, output high-frequency timeseries always start/end on year boundaries |
| 3120 |
# 20210331: Support high-frequency splitter mode mth_srt/end != Jan/Dec |
| 3121 |
# However, the number of files to read in each segment may differ, and is not known a priori |
| 3122 |
# NB: High-frequency timeseries underestimate fpy by [0,1) when fpy=dpy/dpf is non-integral |
| 3123 |
# 20210329: Current formulation assumes manual minimal file list is specified |
| 3124 |
# Extraneous (more than one non-overlapping) files at beginning of list will cause failure |
| 3125 |
# fxm: Omit extraneous files at start of list (extraneous at end are OK now) |
| 3126 |
let fpyp1=${fpy}+1 |
| 3127 |
# 20220818: User Jinbo Xie has hfs files with dpf=36.5. Bash chokes on FP arithmetic |
| 3128 |
let fl_idx_srt=${sgm_idx}*${ypf_max}*${dpy}/${dpf} # NB: dpy/dpf more accurate than fpy |
| 3129 |
#fl_idx_srt=$(echo "${sgm_idx}*${ypf_max}*${dpy}/${dpf}" | bc -l) # NB: dpy/dpf more accurate than fpy |
| 3130 |
#echo "dbg: fl_idx_srt = ${fl_idx_srt}" |
| 3131 |
let fl_idx_end=${fl_idx_srt}+${ypf_max}*${fpyp1} # NB: use fpyp1 to overestimate fl_idx_end |
| 3132 |
#echo "dbg: fl_idx_end = ${fl_idx_end}" |
| 3133 |
let yr_srt_sgm=${yr_srt_rth}+${sgm_idx}*${ypf_max} |
| 3134 |
let yr_end_sgm=${yr_srt_sgm}+${ypf_max}-1 |
| 3135 |
if [ ${sgm_rmd} -ne 0 ] && [ ${sgm_idx} -eq ${sgm_nbrm1} ]; then |
| 3136 |
if [ "${mth_flg}" = 'Yes' ]; then |
| 3137 |
# 20210331 Peings |
| 3138 |
let fl_idx_end=${fl_idx_srt}+${sgm_rmd} |
| 3139 |
let yr_end_sgm=${yr_end_rth} |
| 3140 |
else # !mth_flg |
| 3141 |
let fl_idx_end=${fl_idx_srt}+${sgm_rmd}*${fpyp1} # NB: use fpyp1 to overestimate fl_idx_end |
| 3142 |
let yr_end_sgm=${yr_srt_sgm}+${sgm_rmd}-1 |
| 3143 |
fi # !mth_flg |
| 3144 |
fi # !sgm_rmd || !sgm_nbrm1 |
| 3145 |
# Fuzzify list by including files nominally before and after first and last expected files |
| 3146 |
if [ ${fl_idx_srt} -ne 0 ]; then |
| 3147 |
let fl_idx_srt=${fl_idx_srt}-1 |
| 3148 |
fi # !fl_idx_srt |
| 3149 |
# Fuzziness may generate indices that are too large |
| 3150 |
if [ ${fl_idx_end} -gt ${fl_nbr} ]; then |
| 3151 |
let fl_idx_end=${fl_nbr} |
| 3152 |
fi # !fl_idx_end |
| 3153 |
if [ ${fl_idx_end} -lt ${fl_nbr} ]; then |
| 3154 |
let fl_idx_end=${fl_idx_end}+1 |
| 3155 |
fi # !fl_idx_end |
| 3156 |
fi # !clm_md |
| 3157 |
|
| 3158 |
# NB: fl_idx_srt is zero-based while fl_idx_end one-based, i.e., the count, one more than the index |
| 3159 |
for ((fl_idx=fl_idx_srt;fl_idx<fl_idx_end;fl_idx++)); do |
| 3160 |
fl_sgm[${sgm_idx}]="${fl_sgm[${sgm_idx}]} ${fl_in[${fl_idx}]}" |
| 3161 |
done # !fl_idx |
| 3162 |
yyyy_srt_sgm[${sgm_idx}]=`printf "%04d" ${yr_srt_sgm}` |
| 3163 |
yyyy_end_sgm[${sgm_idx}]=`printf "%04d" ${yr_end_sgm}` |
| 3164 |
# 202401001: fxm: presumably could cause value too great for base error? |
| 3165 |
let yr_endp1_sgm=${yr_end_sgm}+1 |
| 3166 |
yyyy_endp1_sgm[${sgm_idx}]=`printf "%04d" ${yr_endp1_sgm}` |
| 3167 |
|
| 3168 |
mm_srt_sgm[${sgm_idx}]='01' |
| 3169 |
mm_end_sgm[${sgm_idx}]='12' |
| 3170 |
mm_srt_sgm[${sgm_idx}]=${mm_srt} |
| 3171 |
if [ ${sgm_idx} -eq ${sgm_nbrm1} ]; then |
| 3172 |
let mth_end_sgm=${mth_end_rth} |
| 3173 |
mm_end_sgm[${sgm_idx}]=${mm_end} |
| 3174 |
else # !sgm_idx |
| 3175 |
let mth_end_sgm=${mth_srtm1} |
| 3176 |
mm_end_sgm[${sgm_idx}]=${mm_srtm1} |
| 3177 |
fi # !sgm_idx |
| 3178 |
# 202401001: fxm: Causes error "value too great for base (error token is "08")" |
| 3179 |
let mm_endp1_sgm=${mth_end_sgm}+1 |
| 3180 |
mm_endp1_sgm[${sgm_idx}]=`printf "%02d" ${mm_endp1_sgm}` |
| 3181 |
|
| 3182 |
# Sanity check that all files exist before wasting time and space on concatenation |
| 3183 |
for fl_crr in ${fl_sgm[${sgm_idx}]} ; do |
| 3184 |
if [ ! -f "${drc_in}/${fl_crr}" ] && [ ! -L "${drc_in}/${fl_crr}" ]; then |
| 3185 |
echo "${spt_nm}: ERROR Unable to find required input file ${drc_in}/${fl_crr}" |
| 3186 |
echo "${spt_nm}: HINT All files implied to exist by the climatology bounds (start/end year/month) and by the specified (with -P or -m) or default model type, must be in ${drc_in} before ${spt_nm} will proceed" |
| 3187 |
exit 1 |
| 3188 |
fi # ! -f |
| 3189 |
done # !fl_crr |
| 3190 |
|
| 3191 |
done # !sgm_idx |
| 3192 |
|
| 3193 |
if [ "${clm_md}" = 'hfs' ]; then |
| 3194 |
|
| 3195 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3196 |
printf "dbg: HFS variable(s):\n" |
| 3197 |
printf "dpf = ${dpf}\n" |
| 3198 |
printf "dpy = ${dpy}\n" |
| 3199 |
printf "fl_idx_srt = ${fl_idx_srt}\n" |
| 3200 |
printf "fl_idx_end = ${fl_idx_end}\n" |
| 3201 |
printf "fl_nbr = ${fl_nbr}\n" |
| 3202 |
printf "fpy = ${fpy}\n" |
| 3203 |
printf "fpyp1 = ${fpyp1}\n" |
| 3204 |
printf "nco_opt = ${nco_opt}\n" |
| 3205 |
printf "ppn_opt = ${ppn_opt}\n" |
| 3206 |
printf "sgm_nbr = ${sgm_nbr}\n" |
| 3207 |
printf "sgm_rmd = ${sgm_rmd}\n" |
| 3208 |
printf "spl_opt = ${spl_opt}\n" |
| 3209 |
printf "tpd_out = ${tpd_out}\n" |
| 3210 |
printf "var_xtr = ${var_xtr}\n" |
| 3211 |
printf "ypf_max = ${ypf_max}\n" |
| 3212 |
printf "yr_nbr = ${yr_nbr}\n" |
| 3213 |
printf "yr_sbs = ${yr_sbs}\n" |
| 3214 |
fi # !dbg |
| 3215 |
|
| 3216 |
fi # !clm_md |
| 3217 |
|
| 3218 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 3219 |
printf "dbg: Will split into files for ${var_nbr} variable(s):\n" |
| 3220 |
for ((var_idx=0;var_idx<${var_nbr};var_idx++)); do |
| 3221 |
printf "${var_sbs[${var_idx}]}\n" |
| 3222 |
done # !var_idx |
| 3223 |
printf "dbg: Will split timeseries into ${sgm_nbr} segment(s):\n" |
| 3224 |
for ((sgm_idx=0;sgm_idx<${sgm_nbr};sgm_idx++)); do |
| 3225 |
printf "Segment ${sgm_idx} months: ${yyyy_srt_sgm[${sgm_idx}]}${mm_srt_sgm[${sgm_idx}]}--${yyyy_end_sgm[${sgm_idx}]}${mm_end_sgm[${sgm_idx}]}\n" |
| 3226 |
done # !sgm_idx |
| 3227 |
# printf "dbg: Will split ${fl_nbr} files into ${sgm_nbr} segment(s):\n" |
| 3228 |
# for ((sgm_idx=0;sgm_idx<${sgm_nbr};sgm_idx++)); do |
| 3229 |
# printf "${fl_sgm[${sgm_idx}]}\n" |
| 3230 |
# done # !sgm_idx |
| 3231 |
fi # !dbg |
| 3232 |
|
| 3233 |
# Create template output filenames (to avoid Bash 2D string arrays) |
| 3234 |
for ((sgm_idx=0;sgm_idx<sgm_nbr;sgm_idx++)); do |
| 3235 |
if [ -z "${fml_nm_usr}" ]; then |
| 3236 |
fl_out_tpl[${sgm_idx}]="${drc_out}/var_nm_tpl_${yyyy_srt_sgm[${sgm_idx}]}${mm_srt_sgm[${sgm_idx}]}_${yyyy_end_sgm[${sgm_idx}]}${mm_end_sgm[${sgm_idx}]}.nc" |
| 3237 |
else # !fml_nm_usr |
| 3238 |
fl_out_tpl[${sgm_idx}]="${drc_out}/var_nm_tpl_${fml_nm}_${yyyy_srt_sgm[${sgm_idx}]}${mm_srt_sgm[${sgm_idx}]}_${yyyy_end_sgm[${sgm_idx}]}${mm_end_sgm[${sgm_idx}]}.nc" |
| 3239 |
fi # !fml_nm_usr |
| 3240 |
if [ -n "${rgr_opt}" ]; then |
| 3241 |
fl_rgr_tpl[${sgm_idx}]="${fl_out_tpl[${sgm_idx}]/${drc_out}/${drc_rgr}}" |
| 3242 |
if [ "${drc_out}" = "${drc_rgr}" ]; then |
| 3243 |
# Append geometry suffix to regridded files in same directory as native climo |
| 3244 |
# http://tldp.org/LDP/abs/html/string-manipulation.html |
| 3245 |
dfl_sfx='rgr' |
| 3246 |
rgr_sfx=`expr match "${rgr_map}" '.*_to_\(.*\).nc'` |
| 3247 |
if [ "${#rgr_sfx}" -eq 0 ]; then |
| 3248 |
printf "${spt_nm}: WARNING Unable to extract geometric suffix from mapfile, will suffix regridded files with \"${dfl_sfx}\" instead\n" |
| 3249 |
rgr_sfx=${dfl_sfx} |
| 3250 |
else |
| 3251 |
yyyymmdd_sng=`expr match "${rgr_sfx}" '.*\(\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)'` # Find YYYYYMMDD |
| 3252 |
if [ "${#yyyymmdd_sng}" -ne 0 ]; then |
| 3253 |
rgr_sfx=${rgr_sfx%%${yyyymmdd_sng}} # Delete YYYYYMMDD |
| 3254 |
fi # !strlen |
| 3255 |
fi # !strlen |
| 3256 |
# rgr_sfx=`expr match "${rgr_sfx}" '\(.*\)\.[0-9][0-9][0-9][0-9][0-9][0-9]'` # |
| 3257 |
fl_rgr_tpl[${sgm_idx}]="${fl_rgr_tpl[${sgm_idx}]/.nc/_${rgr_sfx}.nc}" |
| 3258 |
fi # !drc_rgr |
| 3259 |
fi # !rgr_opt |
| 3260 |
done # !sgm_idx |
| 3261 |
|
| 3262 |
# Begin outer loop over time segments |
| 3263 |
for ((sgm_idx=0;sgm_idx<sgm_nbr;sgm_idx++)); do |
| 3264 |
|
| 3265 |
# Begin loop over variables to split |
| 3266 |
let bch_nbr=$((var_nbr / job_nbr)) |
| 3267 |
let bch_flg=$((var_nbr % job_nbr)) |
| 3268 |
if [ ${bch_nbr} -eq 0 ]; then |
| 3269 |
let bch_nbr=$((bch_nbr+1)) |
| 3270 |
elif [ ${bch_flg} -ne 0 ]; then |
| 3271 |
let bch_nbr=$((bch_nbr+1)) |
| 3272 |
fi # !bch_flg |
| 3273 |
let bch_nbrm1=$((bch_nbr-1)) |
| 3274 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 3275 |
# var_idx is 0-based, bch_idx is 0-based |
| 3276 |
let var_idx_srt=$((bch_idx * job_nbr)) |
| 3277 |
let var_idx_end=$((var_idx_srt + job_nbr - 1)) |
| 3278 |
if [ ${bch_idx} -eq ${bch_nbrm1} ] && [ ${bch_flg} -ne 0 ]; then |
| 3279 |
let var_idx_srt=$((bch_idx * job_nbr)) |
| 3280 |
let var_idx_end=$((var_nbr - 1)) |
| 3281 |
fi # !bch_flg |
| 3282 |
for ((var_idx=var_idx_srt;var_idx<=var_idx_end;var_idx++)); do |
| 3283 |
fl_out[${var_idx}]="${fl_out_tpl[${sgm_idx}]/var_nm_tpl/${var_sbs[${var_idx}]}}" |
| 3284 |
if [ "${clm_md}" = 'hfs' ]; then |
| 3285 |
# 20200619 High-frequency output requires time-coordinate hyperslabs |
| 3286 |
if [ "${mth_flg}" = 'Yes' ]; then |
| 3287 |
tm_srt="${yyyy_srt_sgm[${sgm_idx}]}-${mm_srt_sgm[${sgm_idx}]}-01T00:00:01" |
| 3288 |
tm_end="${yyyy_end_sgm[${sgm_idx}]}-${mm_endp1_sgm[${sgm_idx}]}-01T00:00:00" |
| 3289 |
else # !mth_flg |
| 3290 |
tm_srt="${yyyy_srt_sgm[${sgm_idx}]}-01-01T00:00:01" |
| 3291 |
tm_end="${yyyy_endp1_sgm[${sgm_idx}]}-01-01T00:00:00" |
| 3292 |
fi # !mth_flg |
| 3293 |
if [ ${tpd_out} -lt 3600 ]; then |
| 3294 |
cmd_sbs[${var_idx}]="${cmd_mpi[${var_idx}]} OMP_PROC_BIND=false ncrcat -O -v ${var_sbs[${var_idx}]}${var_xtr} ${nco_opt} ${spl_opt} ${gaa_sng_tms} -d time,${tm_srt},${tm_end} ${ppn_opt} ${fl_sgm[${sgm_idx}]} ${fl_out[${var_idx}]}" |
| 3295 |
else |
| 3296 |
# Deprecated code to output in sub-average periods or different shapes |
| 3297 |
fl_rcat[${var_idx}]="${drc_out}/${var_sbs[${var_idx}]}_${yyyy_srt_sgm[${sgm_idx}]}01_${yyyy_end_sgm[${sgm_idx}]}12_ncrcat.nc" |
| 3298 |
fl_ecat[${var_idx}]="${drc_out}/${var_sbs[${var_idx}]}_${yyyy_srt_sgm[${sgm_idx}]}01_${yyyy_end_sgm[${sgm_idx}]}12_ncecat.nc" |
| 3299 |
fl_pdq[${var_idx}]="${drc_out}/${var_sbs[${var_idx}]}_${yyyy_srt_sgm[${sgm_idx}]}01_${yyyy_end_sgm[${sgm_idx}]}12_ncpdq.nc" |
| 3300 |
fl_tpd_tpl="${drc_out}/${var_sbs[${var_idx}]}_${yyyy_srt_sgm[${sgm_idx}]}01_${yyyy_end_sgm[${sgm_idx}]}12_tpd" |
| 3301 |
fl_tpd_all='' |
| 3302 |
for ((tpd_idx=0;tpd_idx<tpd_out;tpd_idx++)); do |
| 3303 |
fl_tpd[${tpd_idx}]="${drc_out}/${var_sbs[${var_idx}]}_${yyyy_srt_sgm[${sgm_idx}]}01_${yyyy_end_sgm[${sgm_idx}]}12_tpd${tpd_idx}.nc" |
| 3304 |
fl_tpd_all="${fl_tpd_all} ${fl_tpd[${tpd_idx}]}" |
| 3305 |
done # !tpd_idx |
| 3306 |
# 20200627: Average all timesteps into one climatological record as data(time,space) |
| 3307 |
# cmd_sbs[${var_idx}]="${cmd_mpi[${var_idx}]} OMP_PROC_BIND=false ncrcat -O -v ${var_sbs[${var_idx}]}${var_xtr} ${nco_opt} ${spl_opt} ${gaa_sng_tms} -d time,${tm_srt},${tm_end} ${ppn_opt} ${fl_sgm[${sgm_idx}]} ${fl_rcat[${var_idx}]};/bin/rm -f ${fl_out[${var_idx}]};for srt in `seq 0 $((tpd_out-1))`; do ncra --rec_apn -d time,\${srt},,${tpd_out} ${nco_opt} ${fl_rcat[${var_idx}]} ${fl_out[${var_idx}]};done;/bin/rm -f ${fl_rcat[${var_idx}]}" |
| 3308 |
# 20200628: Output one record per year as data(time,tpd,space), easier to regrid |
| 3309 |
cmd_sbs[${var_idx}]="${cmd_mpi[${var_idx}]} OMP_PROC_BIND=false ncrcat -O -v ${var_sbs[${var_idx}]}${var_xtr} ${nco_opt} ${spl_opt} ${gaa_sng_tms} -d time,${tm_srt},${tm_end} ${ppn_opt} ${fl_sgm[${sgm_idx}]} ${fl_rcat[${var_idx}]};/bin/rm -f ${fl_out[${var_idx}]};for srt in `seq 0 $((tpd_out-1))`; do ncrcat -O -v ${var_sbs[${var_idx}]}${var_xtr} -d time,\${srt},,${tpd_out} ${ppn_opt} ${fl_rcat[${var_idx}]} ${fl_tpd_tpl}\${srt}.nc;ncra -O --mro -d time,,,${dpy},${dpy} ${fl_tpd_tpl}\${srt}.nc ${fl_tpd_tpl}\${srt}.nc;done;/bin/rm -f ${fl_rcat[${var_idx}]};ncecat -O -u hour ${nco_opt} ${fl_tpd_all} ${fl_ecat[${var_idx}]};/bin/rm -f ${fl_tpd_all};ncap2 -O ${nco_opt} -s 'hour=array(0.0,24/\$hour.size,\$hour);*hr_dlt=(hour(1)-hour(0))/2;hour+=hr_dlt;hour@units=\"hours\";hour@long_name=\"Hour of Day\";hour_bnds=make_bounds(hour,\$nbnd,\"hour_bnds\")' ${fl_ecat[${var_idx}]} ${fl_pdq[${var_idx}]};/bin/rm -f ${fl_ecat[${var_idx}]};ncpdq -O ${nco_opt} -a time,hour ${fl_pdq[${var_idx}]} ${fl_out[${var_idx}]};/bin/rm -f ${fl_pdq[${var_idx}]}" |
| 3310 |
fi # !tpd_out |
| 3311 |
else |
| 3312 |
# Normal splitting, non-high-frequency |
| 3313 |
cmd_sbs[${var_idx}]="${cmd_mpi[${var_idx}]} OMP_PROC_BIND=false ncrcat -O -v ${var_sbs[${var_idx}]}${var_xtr} ${nco_opt} ${spl_opt} ${gaa_sng_tms} ${ppn_opt} ${fl_sgm[${sgm_idx}]} ${fl_out[${var_idx}]}" |
| 3314 |
fi # !clm_md |
| 3315 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3316 |
echo ${cmd_sbs[${var_idx}]} |
| 3317 |
fi # !dbg |
| 3318 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3319 |
if [ -z "${par_opt}" ]; then |
| 3320 |
eval ${cmd_sbs[${var_idx}]} |
| 3321 |
if [ "$?" -ne 0 ]; then |
| 3322 |
printf "${spt_nm}: ERROR subset cmd_sbs[${var_idx}] failed. Debug this:\n${cmd_sbs[${var_idx}]}\n" |
| 3323 |
exit 1 |
| 3324 |
fi # !err |
| 3325 |
else # !par_opt |
| 3326 |
eval ${cmd_sbs[${var_idx}]} ${par_opt} |
| 3327 |
sbs_pid[${var_idx}]=$! |
| 3328 |
fi # !par_opt |
| 3329 |
fi # !dbg |
| 3330 |
done # !var_idx |
| 3331 |
|
| 3332 |
# Block NNN: Wait |
| 3333 |
# Parallel splitting (both Background and MPI) spawns simultaneous processes in batches of ${job_nbr} |
| 3334 |
# Once ${job_nbr} jobs are running, wait() for all to finish before issuing another batch |
| 3335 |
if [ -n "${par_opt}" ]; then |
| 3336 |
#printf "${spt_nm}: DEBUG var_idx = ${var_idx}, bch_idx = ${bch_idx}, bch_flg = ${bch_flg}\n" |
| 3337 |
for ((var_idx=var_idx_srt;var_idx<=var_idx_end;var_idx++)); do |
| 3338 |
wait ${sbs_pid[${var_idx}]} |
| 3339 |
if [ "$?" -eq 0 ]; then |
| 3340 |
printf "`date`: Generated ${cmd_sbs[${var_idx}]##* }\n" |
| 3341 |
else |
| 3342 |
printf "${spt_nm}: ERROR Failed to split. cmd_sbs[${var_idx}] failed. Debug this:\n${cmd_sbs[${var_idx}]}\n" |
| 3343 |
# 20190323: exiting parent here creates orphans, kill live children then exit |
| 3344 |
for ((kid_idx=var_idx+1;kid_idx<=var_idx_end;kid_idx++)); do |
| 3345 |
kill -9 ${sbs_pid[${kid_idx}]} |
| 3346 |
done # !kid_idx |
| 3347 |
exit 1 |
| 3348 |
fi # !err |
| 3349 |
done # !var_idx |
| 3350 |
fi # !par_opt |
| 3351 |
|
| 3352 |
if [ "${rgn_stt}" != 'No' ]; then |
| 3353 |
for ((var_idx=var_idx_srt;var_idx<=var_idx_end;var_idx++)); do |
| 3354 |
# 20250610: Until today we always computed regional statistics of all variables in splitter list |
| 3355 |
# However, regional statistics are fragile and break on non-horozontal variables |
| 3356 |
# Moreover, it is difficult for users to know which of the potentially hundreds of variables are not horizontal |
| 3357 |
# Starting today we always check first and skip regional statistics for non-horizontal variables |
| 3358 |
is_hrz[${var_idx}]=`ncks --is_hrz ${var_sbs[${var_idx}]} ${fl_out[${var_idx}]}` |
| 3359 |
if [ ${is_hrz[${var_idx}]} = 'No' ]; then |
| 3360 |
echo "${spt_nm}: WARNING Splitter is skipping regional statistics for variable ${var_sbs[${var_idx}]} which is not a purely horizontal timeseries" |
| 3361 |
continue; |
| 3362 |
fi # !is_hrz |
| 3363 |
|
| 3364 |
cmd_rgn="*rgn_nbr=3;defdim(\"rgn\",rgn_nbr);*${var_sbs[${var_idx}]}_tmp=0.0f*${var_sbs[${var_idx}]}.avg(${hrz_arg});*${var_sbs[${var_idx}]}_rgn[time,rgn]=${var_sbs[${var_idx}]}_tmp;${var_sbs[${var_idx}]}_rgn@coordinates=\"region_name\";*${lat_nm}_area=${lat_nm}+0.0*${area_nm};*msk_sth=0*${lat_nm}_area.int();delete_miss(msk_sth);*msk_nrt=0*${lat_nm}_area.int();delete_miss(msk_nrt);*idx_glb=0;*idx_nrt=1;*idx_sth=2;*rgn_len=19;defdim(\"rgn_len\",rgn_len);region_name[rgn,rgn_len]=\" \";region_name(idx_glb,0:5)=\"Global\";region_name(idx_nrt,:)=\"Northern Hemisphere\";region_name(idx_sth,:)=\"Southern Hemisphere\";if(${flg_sum}) region_name@long_name=\"${var_sbs[${var_idx}]} timeseries array contains area-weighted sums over these regions\"; else region_name@long_name=\"${var_sbs[${var_idx}]} timeseries array contains area-weighted averages over these regions\";where(${lat_nm}_area < 0.0) msk_sth=1; elsewhere msk_nrt=1;${var_sbs[${var_idx}]}_rgn(:,idx_glb)=((${var_sbs[${var_idx}]}*${area_wgt}).avg(${hrz_arg})/(${area_wgt}).avg(${hrz_arg})).float();${var_sbs[${var_idx}]}_rgn(:,idx_nrt)=((${var_sbs[${var_idx}]}*${area_wgt}*msk_nrt).avg(${hrz_arg})/(${area_wgt}*msk_nrt).avg(${hrz_arg})).float();${var_sbs[${var_idx}]}_rgn(:,idx_sth)=((${var_sbs[${var_idx}]}*${area_wgt}*msk_sth).avg(${hrz_arg})/(${area_wgt}*msk_sth).avg(${hrz_arg})).float();if(${flg_sum}){${var_sbs[${var_idx}]}_rgn(:,idx_glb)=${var_sbs[${var_idx}]}_rgn(:,idx_glb)*(${area_wgt}).total(${hrz_arg}).float()*${sum_scl};${var_sbs[${var_idx}]}_rgn(:,idx_nrt)=${var_sbs[${var_idx}]}_rgn(:,idx_nrt)*(${area_wgt}*msk_nrt).total(${hrz_arg}).float()*${sum_scl};${var_sbs[${var_idx}]}_rgn(:,idx_sth)=${var_sbs[${var_idx}]}_rgn(:,idx_sth)*(${area_wgt}*msk_sth).total(${hrz_arg}).float()*${sum_scl};}${var_sbs[${var_idx}]}=${var_sbs[${var_idx}]}_rgn;push(&${var_sbs[${var_idx}]}@cell_methods,\" area: mean\");if(exists(time_bnds)) time_bnds=time_bnds;if(exists(time_bounds)) time_bounds=time_bounds;valid_area_per_gridcell=${area_wgt};" |
| 3365 |
# NB: We do not pass nco_opt to ncap2 here |
| 3366 |
# nco_opt might contain switches like -x that have different meanings in ncap2 |
| 3367 |
# File format is inherited from timeseries file, so no need to pass that |
| 3368 |
# One option to consider passing by default here is --no_tmp_fl |
| 3369 |
# 20240411: Do not append history for rgn_stt computation---too much like encoding a program in a dataset |
| 3370 |
# 20241218: Behavior before today was to pass -v to ncap2 in rgn_stt computation |
| 3371 |
# However, this prevented output of --var_xtr fields. We omit '-v' as of NCO 5.3.0. |
| 3372 |
# Pros: More flexible, allows users to request e.g., --var_xtr=area,landfrac for scaling |
| 3373 |
# Cons: Larger files, and users might pollute --var_xtr with timeseries other timeseries |
| 3374 |
cmd_stt[${var_idx}]="${cmd_mpi[${var_idx}]} OMP_PROC_BIND=false ncap2 -h -O -s '${cmd_rgn}' ${fl_out[${var_idx}]} ${fl_out[${var_idx}]}" |
| 3375 |
# 20220817: Prior to today, --glb_avg used ncwa for global average |
| 3376 |
# As of NCO 5.1.1, --glb_avg is a deprecated synonym for --rgn_avg |
| 3377 |
# As of NCO 5.2.8, --rgn_avg is a synonym for --rgn_stt=avg |
| 3378 |
# Both produce (currently three) regional timeseries |
| 3379 |
# The original --glb_avg implementation was: |
| 3380 |
# cmd_stt[${var_idx}]="${cmd_mpi[${var_idx}]} OMP_PROC_BIND=false ncwa -O -w ${area_nm} -a ${hrz_dmn} ${fl_out[${var_idx}]} ${fl_out[${var_idx}]}" |
| 3381 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3382 |
echo ${cmd_stt[${var_idx}]} |
| 3383 |
fi # !dbg |
| 3384 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3385 |
if [ -z "${par_opt}" ]; then |
| 3386 |
eval ${cmd_stt[${var_idx}]} |
| 3387 |
if [ "$?" -ne 0 ]; then |
| 3388 |
printf "${spt_nm}: ERROR global and regional statistics cmd_stt[${var_idx}] failed. Debug this:\n${cmd_stt[${var_idx}]}\n" |
| 3389 |
exit 1 |
| 3390 |
fi # !err |
| 3391 |
else # !par_opt |
| 3392 |
eval ${cmd_stt[${var_idx}]} ${par_opt} # eval always returns 0 on backgrounded processes |
| 3393 |
avg_pid[${var_idx}]=$! |
| 3394 |
fi # !par_opt |
| 3395 |
fi # !dbg |
| 3396 |
done # !var_idx |
| 3397 |
|
| 3398 |
# Once ${job_nbr} jobs are running, wait() for all to finish before issuing another batch |
| 3399 |
if [ -n "${par_opt}" ]; then |
| 3400 |
for ((var_idx=var_idx_srt;var_idx<=var_idx_end;var_idx++)); do |
| 3401 |
if [ ${is_hrz[${var_idx}]} = 'Yes' ]; then |
| 3402 |
wait ${avg_pid[${var_idx}]} |
| 3403 |
if [ "$?" -eq 0 ]; then |
| 3404 |
printf "`date`: Global and regional statistics ${cmd_stt[${var_idx}]##* }\n" |
| 3405 |
else |
| 3406 |
printf "${spt_nm}: ERROR Failed in global and regional statistics. cmd_stt[${var_idx}] failed. Debug this:\n${cmd_stt[${var_idx}]}\n" |
| 3407 |
# 20190323: exiting parent here creates orphans, kill live children then exit |
| 3408 |
for ((kid_idx=var_idx+1;kid_idx<=var_idx_end;kid_idx++)); do |
| 3409 |
kill -9 ${avg_pid[${kid_idx}]} |
| 3410 |
done # !kid_idx |
| 3411 |
exit 1 |
| 3412 |
fi # !err |
| 3413 |
fi # !is_hrz |
| 3414 |
done # !var_idx |
| 3415 |
fi # !par_opt |
| 3416 |
|
| 3417 |
fi # !rgn_stt |
| 3418 |
|
| 3419 |
done # !bch_idx |
| 3420 |
|
| 3421 |
# Begin loop over variables to regrid |
| 3422 |
if [ -n "${rgr_opt}" ]; then |
| 3423 |
let bch_nbr=$((var_nbr / job_nbr)) |
| 3424 |
let bch_flg=$((var_nbr % job_nbr)) |
| 3425 |
if [ ${bch_nbr} -eq 0 ]; then |
| 3426 |
let bch_nbr=$((bch_nbr+1)) |
| 3427 |
elif [ ${bch_flg} -ne 0 ]; then |
| 3428 |
let bch_nbr=$((bch_nbr+1)) |
| 3429 |
fi # !bch_flg |
| 3430 |
let bch_nbrm1=$((bch_nbr-1)) |
| 3431 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 3432 |
# var_idx is 0-based, bch_idx is 0-based |
| 3433 |
let var_idx_srt=$((bch_idx * job_nbr)) |
| 3434 |
let var_idx_end=$((var_idx_srt + job_nbr - 1)) |
| 3435 |
if [ ${bch_idx} -eq ${bch_nbrm1} ] && [ ${bch_flg} -ne 0 ]; then |
| 3436 |
let var_idx_srt=$((bch_idx * job_nbr)) |
| 3437 |
let var_idx_end=$((var_nbr - 1)) |
| 3438 |
fi # !bch_flg |
| 3439 |
for ((var_idx=var_idx_srt;var_idx<=var_idx_end;var_idx++)); do |
| 3440 |
fl_rgr[${var_idx}]="${fl_rgr_tpl[${sgm_idx}]/var_nm_tpl/${var_sbs[${var_idx}]}}" |
| 3441 |
#cmd_rgr[${var_idx}]="${cmd_mpi[${var_idx}]} ncks -O -t ${thr_nbr} ${nco_opt} ${rgr_opt} ${spl_opt} ${spl_rgr_opt} ${fl_out[${var_idx}]} ${fl_rgr[${var_idx}]}" |
| 3442 |
cmd_rgr[${var_idx}]="${cmd_mpi[${var_idx}]} ncremap -u .pid${spt_pid}.split.${var_idx}.tmp --nco_opt=\"${nco_opt}\" -t ${thr_nbr} ${spl_opt} ${spl_rgr_opt} ${prc_opt} ${rmp_opt} ${fl_out[${var_idx}]} ${fl_rgr[${var_idx}]}" |
| 3443 |
if [ "${mdl_typ}" = 'mpas' ]; then |
| 3444 |
# 20181114: Remove '-C' argument from ncremap invocation for MPAS splitter only |
| 3445 |
# This ensures CMIP6 MPAS timeseries will have _FillValue |
| 3446 |
cmd_rgr[${var_idx}]="${cmd_mpi[${var_idx}]} ncremap -u .pid${spt_pid}.split.${var_idx}.tmp ${prc_opt} ${d2f_opt} ${dpt_opt} --nco_opt=\"${nco_opt}\" ${spl_opt} ${spl_rgr_opt} -t ${thr_nbr} ${map_opt} ${vrt_opt} ${fl_out[${var_idx}]} ${fl_rgr[${var_idx}]}" |
| 3447 |
fi # !mdl_typ |
| 3448 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3449 |
echo ${cmd_rgr[${var_idx}]} |
| 3450 |
fi # !dbg |
| 3451 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3452 |
if [ -z "${par_opt}" ]; then |
| 3453 |
eval ${cmd_rgr[${var_idx}]} |
| 3454 |
if [ "$?" -ne 0 ]; then |
| 3455 |
printf "${spt_nm}: ERROR regrid cmd_rgr[${var_idx}] failed. Debug this:\n${cmd_rgr[${var_idx}]}\n" |
| 3456 |
exit 1 |
| 3457 |
fi # !err |
| 3458 |
else # !par_opt |
| 3459 |
eval ${cmd_rgr[${var_idx}]} ${par_opt} |
| 3460 |
rgr_pid[${var_idx}]=$! |
| 3461 |
fi # !par_opt |
| 3462 |
fi # !dbg |
| 3463 |
done # !var_idx |
| 3464 |
|
| 3465 |
# Block NNN: Wait |
| 3466 |
# Parallel regridding (both Background and MPI) spawns simultaneous processes in batches of ${job_nbr} |
| 3467 |
# Once ${job_nbr} jobs are running, wait() for all to finish before issuing another batch |
| 3468 |
if [ -n "${par_opt}" ]; then |
| 3469 |
for ((var_idx=var_idx_srt;var_idx<=var_idx_end;var_idx++)); do |
| 3470 |
wait ${rgr_pid[${var_idx}]} |
| 3471 |
if [ "$?" -eq 0 ]; then |
| 3472 |
printf "`date`: Regridded ${cmd_rgr[${var_idx}]##* }\n" |
| 3473 |
else |
| 3474 |
printf "${spt_nm}: ERROR Failed to regrid. cmd_rgr[${var_idx}] failed. Debug this:\n${cmd_rgr[${var_idx}]}\n" |
| 3475 |
# 20190323: exiting parent here creates orphans, kill live children then exit |
| 3476 |
for ((kid_idx=var_idx+1;kid_idx<=var_idx_end;kid_idx++)); do |
| 3477 |
kill -9 ${rgr_pid[${kid_idx}]} |
| 3478 |
done # !kid_idx |
| 3479 |
exit 1 |
| 3480 |
fi # !err |
| 3481 |
done # !var_idx |
| 3482 |
fi # !par_opt |
| 3483 |
|
| 3484 |
done # !bch_idx |
| 3485 |
|
| 3486 |
if [ "${no_ntv_tms}" = 'Yes' ]; then |
| 3487 |
# Omit native-grid split timeseries by overwriting fl_out with fl_rgr |
| 3488 |
for ((var_idx=0;var_idx<var_nbr;var_idx++)); do |
| 3489 |
/bin/mv -f ${fl_rgr[${var_idx}]} ${fl_out[${var_idx}]} |
| 3490 |
printf "`date`: Overwrote native timeseries with regridded for ${var_sbs[${var_idx}]}\n" |
| 3491 |
done # !var_idx |
| 3492 |
fi # !no_ntv_tms |
| 3493 |
|
| 3494 |
fi # !rgr_opt |
| 3495 |
|
| 3496 |
done # !sgm_idx |
| 3497 |
|
| 3498 |
fi # !tms_flg |
| 3499 |
|
| 3500 |
# Block 1 Loop 2: Climatologies based on annual means |
| 3501 |
if [ "${clm_flg}" = 'Yes' ] && [ "${clm_md}" = 'ann' ]; then |
| 3502 |
clm_idx=1 |
| 3503 |
fl_all='' |
| 3504 |
for ((fl_idx=0;fl_idx<fl_nbr;fl_idx++)); do |
| 3505 |
fl_all="${fl_all} ${fl_in[${fl_idx}]}" |
| 3506 |
done # !fl |
| 3507 |
# Check for existence of raw input only when file will be used (NB: next ~12 lines duplicate monthly code) |
| 3508 |
if [ "${bnr_flg}" = 'No' ]; then |
| 3509 |
for fl_crr in ${fl_all} ; do |
| 3510 |
if [ ! -f "${drc_in}/${fl_crr}" ] && [ ! -L "${drc_in}/${fl_crr}" ]; then |
| 3511 |
echo "${spt_nm}: ERROR Unable to find required input file ${drc_in}/${fl_crr}" |
| 3512 |
echo "${spt_nm}: HINT All files implied to exist by the climatology bounds (start/end year/month) and by the specified (with -P or -m) or default model type, must be in ${drc_in} before ${spt_nm} will proceed" |
| 3513 |
exit 1 |
| 3514 |
fi # ! -f |
| 3515 |
done # !fl_crr |
| 3516 |
else # !bnr_flg |
| 3517 |
# In binary mode drc_out is actually used to locate input files from climatology B (same as output files in incremental mode) |
| 3518 |
drc_out="${drc_in}" |
| 3519 |
fi # !bnr_flg |
| 3520 |
fl_out[${clm_idx}]="${drc_out}/${out_nm}_ANN_${yyyy_srt}01_${yyyy_end}12_climo.nc" |
| 3521 |
cmd_clm[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncra -O ${nco_opt} ${gaa_sng[${clm_idx}]} -p ${drc_in} ${fl_all} ${fl_out[${clm_idx}]} ${par_opt}" |
| 3522 |
|
| 3523 |
# Block 1 Loop 2: Climatological annual mean |
| 3524 |
printf "Climatological annual mean...\n" |
| 3525 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3526 |
echo ${cmd_clm[${clm_idx}]} |
| 3527 |
fi # !dbg |
| 3528 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3529 |
eval ${cmd_clm[${clm_idx}]} |
| 3530 |
if [ "$?" -ne 0 ]; then |
| 3531 |
printf "${spt_nm}: ERROR annual climo cmd_clm[${clm_idx}] failed\n" |
| 3532 |
exit 1 |
| 3533 |
fi # !err |
| 3534 |
fi # !dbg |
| 3535 |
wait |
| 3536 |
|
| 3537 |
# Block 2: Regrid climatological annual mean |
| 3538 |
if [ -n "${rgr_opt}" ]; then |
| 3539 |
printf "Regrid annual data...\n" |
| 3540 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncks -O -t ${thr_nbr} ${nco_opt} ${rgr_opt} ${fl_out[${clm_idx}]} ${fl_out[${clm_idx}]/.nc/.rgr.nc}" |
| 3541 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3542 |
echo ${cmd_rgr[${clm_idx}]} ${par_opt} |
| 3543 |
fi # !dbg |
| 3544 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3545 |
eval ${cmd_rgr[${clm_idx}]} ${par_opt} |
| 3546 |
if [ "$?" -ne 0 ]; then |
| 3547 |
printf "${spt_nm}: ERROR annual regrid cmd_rgr[${clm_idx}] failed\n" |
| 3548 |
exit 1 |
| 3549 |
fi # !err |
| 3550 |
fi # !dbg |
| 3551 |
wait |
| 3552 |
printf "Done with regridding\n" |
| 3553 |
fi # !rgr_opt |
| 3554 |
|
| 3555 |
fi # !ann |
| 3556 |
|
| 3557 |
# Block 1 Loop 2: Climatologies based on daily means |
| 3558 |
if [ "${clm_flg}" = 'Yes' ] && [ "${clm_md}" = 'dly' ]; then |
| 3559 |
|
| 3560 |
fl_all='' |
| 3561 |
for ((fl_idx=0;fl_idx<fl_nbr;fl_idx++)); do |
| 3562 |
fl_all="${fl_all} ${fl_in[${fl_idx}]}" |
| 3563 |
done # !fl |
| 3564 |
|
| 3565 |
let srd=${dpy}*${tpd_out} |
| 3566 |
drn=${tpd_out} |
| 3567 |
|
| 3568 |
yyyy_srt=`printf "%04d" ${yr_srt}` |
| 3569 |
yyyy_end=`printf "%04d" ${yr_end}` |
| 3570 |
# 20200625 Off-by-one bug? |
| 3571 |
# let yr_endp1=${yr_end}+1 |
| 3572 |
# yyyy_endp1=`printf "%04d" ${yr_endp1}` |
| 3573 |
clm_idx=0 |
| 3574 |
for mth in `seq 1 12`; do |
| 3575 |
MM=`printf "%02d" ${mth}` |
| 3576 |
for day in `seq 1 ${dpm[${mth}]}`; do |
| 3577 |
DD=`printf "%02d" ${day}` |
| 3578 |
fl_out[${clm_idx}]="${drc_out}/${out_nm}_${yyyy_srt}${MM}${DD}_${yyyy_end}${MM}${DD}_climo.nc" |
| 3579 |
fl_cat[${clm_idx}]="${drc_out}/${out_nm}_${yyyy_srt}${MM}${DD}_${yyyy_end}${MM}${DD}_ncrcat.nc" |
| 3580 |
fl_rgr[${clm_idx}]="${fl_out[${clm_idx}]/${drc_out}/${drc_rgr}}" |
| 3581 |
tm_srt="${yyyy_srt}-${MM}-${DD}T00:00:00" |
| 3582 |
tm_end="${yyyy_end}-${MM}-${DD}T23:59:59" |
| 3583 |
if [ ${tpd_out} -eq 1 ]; then |
| 3584 |
cmd_clm[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncra -O ${nco_opt} ${gaa_sng[${clm_idx}]} -d time,${tm_srt},${tm_end},${srd},1 ${ppn_opt} ${fl_all} ${fl_out[${clm_idx}]}" |
| 3585 |
else |
| 3586 |
# 20170619: Diurnal mode is really slow on MacOS (UDUnits parsing sluggishness?) |
| 3587 |
cmd_clm[${clm_idx}]="${cmd_mpi[${clm_idx}]} OMP_PROC_BIND=false ncrcat -O ${nco_opt} ${gaa_sng[${clm_idx}]} -d time,${tm_srt},${tm_end},${srd},${drn} ${ppn_opt} ${fl_all} ${fl_cat[${clm_idx}]};/bin/rm -f ${fl_out[${clm_idx}]};for srt in `seq 0 $((tpd_out-1))`; do ncra --rec_apn -d time,\${srt},,${tpd_out} ${nco_opt} ${gaa_sng[${clm_idx}]} ${fl_cat[${clm_idx}]} ${fl_out[${clm_idx}]};done;/bin/rm -f ${fl_cat[${clm_idx}]}" |
| 3588 |
fi # !tpd |
| 3589 |
let clm_idx=${clm_idx}+1 |
| 3590 |
done # !day |
| 3591 |
done # !mth |
| 3592 |
|
| 3593 |
if [ -n "${rgr_opt}" ]; then |
| 3594 |
for ((clm_idx=0;clm_idx<clm_nbr;clm_idx++)); do |
| 3595 |
fl_rgr[${clm_idx}]="${fl_out[${clm_idx}]/${drc_out}/${drc_rgr}}" |
| 3596 |
if [ "${drc_out}" = "${drc_rgr}" ]; then |
| 3597 |
# Append geometry suffix to regridded files in same directory as native climo |
| 3598 |
# http://tldp.org/LDP/abs/html/string-manipulation.html |
| 3599 |
dfl_sfx='rgr' |
| 3600 |
rgr_sfx=`expr match "${rgr_map}" '.*_to_\(.*\).nc'` |
| 3601 |
if [ "${#rgr_sfx}" -eq 0 ]; then |
| 3602 |
printf "${spt_nm}: WARNING Unable to extract geometric suffix from mapfile, will suffix regridded files with \"${dfl_sfx}\" instead\n" |
| 3603 |
rgr_sfx=${dfl_sfx} |
| 3604 |
else |
| 3605 |
yyyymmdd_sng=`expr match "${rgr_sfx}" '.*\(\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)'` # Find YYYYYMMDD |
| 3606 |
if [ "${#yyyymmdd_sng}" -ne 0 ]; then |
| 3607 |
rgr_sfx=${rgr_sfx%%${yyyymmdd_sng}} # Delete YYYYYMMDD |
| 3608 |
fi # !strlen |
| 3609 |
fi # !strlen |
| 3610 |
# rgr_sfx=`expr match "${rgr_sfx}" '\(.*\)\.[0-9][0-9][0-9][0-9][0-9][0-9]'` # |
| 3611 |
fl_rgr[${clm_idx}]="${fl_rgr[${clm_idx}]/.nc/_${rgr_sfx}.nc}" |
| 3612 |
fi # !drc_rgr |
| 3613 |
done # !clm_idx |
| 3614 |
fi # !rgr_opt |
| 3615 |
|
| 3616 |
# Begin loop over days to climatologize |
| 3617 |
printf "Climatological daily mean...\n" |
| 3618 |
let bch_nbr=$((clm_nbr / job_nbr)) |
| 3619 |
let bch_flg=$((clm_nbr % job_nbr)) |
| 3620 |
if [ ${bch_nbr} -eq 0 ]; then |
| 3621 |
let bch_nbr=$((bch_nbr+1)) |
| 3622 |
elif [ ${bch_flg} -ne 0 ]; then |
| 3623 |
let bch_nbr=$((bch_nbr+1)) |
| 3624 |
fi # !bch_flg |
| 3625 |
let bch_nbrm1=$((bch_nbr-1)) |
| 3626 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 3627 |
# clm_idx is 0-based, bch_idx is 0-based |
| 3628 |
let clm_idx_srt=$((bch_idx * job_nbr)) |
| 3629 |
let clm_idx_end=$((clm_idx_srt + job_nbr - 1)) |
| 3630 |
if [ ${bch_idx} -eq ${bch_nbrm1} ] && [ ${bch_flg} -ne 0 ]; then |
| 3631 |
let clm_idx_srt=$((bch_idx * job_nbr)) |
| 3632 |
let clm_idx_end=$((clm_nbr - 1)) |
| 3633 |
fi # !bch_flg |
| 3634 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 3635 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3636 |
echo ${cmd_clm[${clm_idx}]} |
| 3637 |
fi # !dbg |
| 3638 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3639 |
if [ -z "${par_opt}" ]; then |
| 3640 |
eval ${cmd_clm[${clm_idx}]} |
| 3641 |
if [ "$?" -ne 0 ]; then |
| 3642 |
printf "${spt_nm}: ERROR daily cmd_clm[${clm_idx}] failed. Debug this:\n${cmd_clm[${clm_idx}]}\n" |
| 3643 |
exit 1 |
| 3644 |
fi # !err |
| 3645 |
else # !par_opt |
| 3646 |
eval ${cmd_clm[${clm_idx}]} ${par_opt} |
| 3647 |
clm_pid[${clm_idx}]=$! |
| 3648 |
fi # !par_opt |
| 3649 |
fi # !dbg |
| 3650 |
done # !fl_idx |
| 3651 |
|
| 3652 |
# Block NNN: Wait |
| 3653 |
# Parallel splitting (both Background and MPI) spawns simultaneous processes in batches of ${job_nbr} |
| 3654 |
# Once ${job_nbr} jobs are running, wait() for all to finish before issuing another batch |
| 3655 |
if [ -n "${par_opt}" ]; then |
| 3656 |
if [ ${dbg_lvl} -ge 1 ] && [ ${clm_idx_srt} -le ${clm_idx_end} ]; then |
| 3657 |
printf "${spt_nm}: Waiting for batch ${bch_idx} to finish at clm_idx = ${clm_idx}...\n" |
| 3658 |
fi # !dbg |
| 3659 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 3660 |
wait ${clm_pid[${clm_idx}]} |
| 3661 |
if [ "$?" -ne 0 ]; then |
| 3662 |
printf "${spt_nm}: ERROR Failed daily average. cmd_clm[${clm_idx}] failed. Debug this:\n${cmd_clm[${clm_idx}]}\n" |
| 3663 |
exit 1 |
| 3664 |
fi # !err |
| 3665 |
done # !clm_idx |
| 3666 |
fi # !par_opt |
| 3667 |
|
| 3668 |
done # !bch_idx |
| 3669 |
|
| 3670 |
# Begin loop over days to regrid |
| 3671 |
if [ -n "${rgr_opt}" ]; then |
| 3672 |
let bch_nbr=$((clm_nbr / job_nbr)) |
| 3673 |
let bch_flg=$((clm_nbr % job_nbr)) |
| 3674 |
if [ ${bch_nbr} -eq 0 ]; then |
| 3675 |
let bch_nbr=$((bch_nbr+1)) |
| 3676 |
elif [ ${bch_flg} -ne 0 ]; then |
| 3677 |
let bch_nbr=$((bch_nbr+1)) |
| 3678 |
fi # !bch_flg |
| 3679 |
let bch_nbrm1=$((bch_nbr-1)) |
| 3680 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 3681 |
# clm_idx is 0-based, bch_idx is 0-based |
| 3682 |
let clm_idx_srt=$((bch_idx * job_nbr)) |
| 3683 |
let clm_idx_end=$((clm_idx_srt + job_nbr - 1)) |
| 3684 |
if [ ${bch_idx} -eq ${bch_nbrm1} ] && [ ${bch_flg} -ne 0 ]; then |
| 3685 |
let clm_idx_srt=$((bch_idx * job_nbr)) |
| 3686 |
let clm_idx_end=$((clm_nbr - 1)) |
| 3687 |
fi # !bch_flg |
| 3688 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 3689 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncks -O -t ${thr_nbr} ${nco_opt} ${rgr_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 3690 |
if [ "${mdl_typ}" = 'mpas' ]; then |
| 3691 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncremap -C -u .pid${spt_pid}.daily.${clm_idx}.tmp ${prc_opt} ${d2f_opt} ${dpt_opt} --nco_opt=\"${nco_opt}\" -t ${thr_nbr} ${map_opt} ${vrt_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 3692 |
fi # !mdl_typ |
| 3693 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3694 |
echo ${cmd_rgr[${clm_idx}]} |
| 3695 |
fi # !dbg |
| 3696 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3697 |
if [ -z "${par_opt}" ]; then |
| 3698 |
eval ${cmd_rgr[${clm_idx}]} |
| 3699 |
if [ "$?" -ne 0 ]; then |
| 3700 |
printf "${spt_nm}: ERROR regrid cmd_rgr[${clm_idx}] failed. Debug this:\n${cmd_rgr[${clm_idx}]}\n" |
| 3701 |
exit 1 |
| 3702 |
fi # !err |
| 3703 |
else # !par_opt |
| 3704 |
eval ${cmd_rgr[${clm_idx}]} ${par_opt} |
| 3705 |
rgr_pid[${clm_idx}]=$! |
| 3706 |
fi # !par_opt |
| 3707 |
fi # !dbg |
| 3708 |
done # !clm_idx |
| 3709 |
|
| 3710 |
# Block NNN: Wait |
| 3711 |
# Parallel regridding (both Background and MPI) spawns simultaneous processes in batches of ${job_nbr} |
| 3712 |
# Once ${job_nbr} jobs are running, wait() for all to finish before issuing another batch |
| 3713 |
if [ -n "${par_opt}" ]; then |
| 3714 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 3715 |
wait ${rgr_pid[${clm_idx}]} |
| 3716 |
if [ "$?" -eq 0 ]; then |
| 3717 |
printf "`date`: Regridded ${cmd_rgr[${clm_idx}]##* }\n" |
| 3718 |
else |
| 3719 |
printf "${spt_nm}: ERROR Failed to regrid. cmd_rgr[${clm_idx}] failed. Debug this:\n${cmd_rgr[${clm_idx}]}\n" |
| 3720 |
# 20190323: exiting parent here creates orphans, kill live children then exit |
| 3721 |
for ((kid_idx=clm_idx+1;kid_idx<=clm_idx_end;kid_idx++)); do |
| 3722 |
kill -9 ${rgr_pid[${kid_idx}]} |
| 3723 |
done # !kid_idx |
| 3724 |
exit 1 |
| 3725 |
fi # !err |
| 3726 |
done # !clm_idx |
| 3727 |
fi # !par_opt |
| 3728 |
|
| 3729 |
done # !bch_idx |
| 3730 |
fi # !rgr_opt |
| 3731 |
fi # !dly |
| 3732 |
|
| 3733 |
# Many subsequent blocks only execute for normal and incremental monthly climos, not for binary climos, or non-monthly climos |
| 3734 |
if [ "${clm_flg}" = 'Yes' ] && [ "${clm_hfc_or_mth}" = 'Yes' ] && [ "${bnr_flg}" = 'No' ]; then |
| 3735 |
|
| 3736 |
# Block 1 Loop 2: Execute and/or echo monthly climatology commands |
| 3737 |
printf "Generating climatology...\n" |
| 3738 |
[[ ${dbg_lvl} -ge 1 ]] && date_clm=$(date +"%s") |
| 3739 |
|
| 3740 |
if [ ${job_nbr} -eq 1 ] || [ ${job_nbr} -eq 2 ] || [ ${job_nbr} -eq 3 ] || [ ${job_nbr} -eq 4 ] || [ ${job_nbr} -eq 6 ] || [ ${job_nbr} -eq 12 ]; then |
| 3741 |
echo "Successful match of job_nbr to list of permissible values" > /dev/null |
| 3742 |
else |
| 3743 |
echo "${spt_nm}: ERROR Job number job_nbr=${job_nbr} is invalid in monthly climo mode. Must be a factor of 12. Valid values are 1, 2, 3, 4, 6, and 12. Please re-submit with valid job_nbr." |
| 3744 |
exit 1 |
| 3745 |
fi # !job_nbr |
| 3746 |
|
| 3747 |
# Batch number is inverse to job number, so job_nbr=1->bch_nbr=12 (serial mode, slowest), job_nbr=2->bch_nbr=6, ... job_nbr=12->bch_nbr=1 (full background mode, fastest) |
| 3748 |
let bch_nbr=$((12 / job_nbr)) |
| 3749 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 3750 |
# clm_idx is 1-based, bch_idx is 0-based |
| 3751 |
let clm_idx_srt=$(((bch_idx * job_nbr) + 1)) |
| 3752 |
let clm_idx_end=$((clm_idx_srt + job_nbr - 1)) |
| 3753 |
#printf "${spt_nm}: DEBUG job_nbr = ${job_nbr}, bch_nbr = ${bch_nbr}, bch_idx = ${bch_idx}, clm_idx_srt = ${clm_idx_end}, clm_idx_end = ${clm_idx_end}\n" |
| 3754 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 3755 |
printf "Climatological monthly mean for month ${clm_idx} ...\n" |
| 3756 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3757 |
echo ${cmd_clm[${clm_idx}]} |
| 3758 |
fi # !dbg |
| 3759 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3760 |
if [ -z "${par_opt}" ]; then |
| 3761 |
eval ${cmd_clm[${clm_idx}]} |
| 3762 |
if [ "$?" -ne 0 ]; then |
| 3763 |
printf "${spt_nm}: ERROR monthly climo cmd_clm[${clm_idx}] failed. Debug this:\n${cmd_clm[${clm_idx}]}\n" |
| 3764 |
exit 1 |
| 3765 |
fi # !err |
| 3766 |
else # !par_opt |
| 3767 |
eval ${cmd_clm[${clm_idx}]} ${par_opt} # eval always returns 0 on backgrounded processes |
| 3768 |
clm_pid[${clm_idx}]=$! |
| 3769 |
# Potential alternatives to eval: |
| 3770 |
# eval "${cmd_clm[${clm_idx}]}" # borken |
| 3771 |
# ${cmd_clm[${clm_idx}]} # borken |
| 3772 |
# "${cmd_clm[${clm_idx}]}" # borken |
| 3773 |
# exec "${cmd_clm[${clm_idx}]}" # borken |
| 3774 |
# $(${cmd_clm[${clm_idx}]}) # borken |
| 3775 |
# $("${cmd_clm[${clm_idx}]}") # works (when & inside cmd quotes) |
| 3776 |
fi # !par_opt |
| 3777 |
fi # !dbg |
| 3778 |
done # !clm_idx |
| 3779 |
if [ -n "${par_opt}" ]; then |
| 3780 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 3781 |
wait ${clm_pid[${clm_idx}]} |
| 3782 |
if [ "$?" -ne 0 ]; then |
| 3783 |
printf "${spt_nm}: ERROR monthly climo cmd_clm[${clm_idx}] failed. Debug this:\n${cmd_clm[${clm_idx}]}\n" |
| 3784 |
exit 1 |
| 3785 |
fi # !err |
| 3786 |
done # !clm_idx |
| 3787 |
fi # !par_opt |
| 3788 |
done # !bch_idx |
| 3789 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3790 |
date_crr=$(date +"%s") |
| 3791 |
date_dff=$((date_crr-date_clm)) |
| 3792 |
echo "Elapsed time to generate monthly climos $((date_dff/60))m$((date_dff % 60))s" |
| 3793 |
fi # !dbg |
| 3794 |
# Clean-up monthly inputs (important since these file can be huge) |
| 3795 |
if [ ${clm_md} = 'hfc' ]; then |
| 3796 |
# printf "quark1: Temporarily not deleting HFC output files!!!!!!!!!!\n" |
| 3797 |
# if false; then |
| 3798 |
if [ "${fl_nbr}" -eq 1 ]; then |
| 3799 |
/bin/rm -f ${drc_out}/${out_nm}_[01][0-9]_tms_foo_${yyyy_clm_srt}_${yyyy_clm_end}.nc |
| 3800 |
else |
| 3801 |
/bin/rm -f ${drc_out}/${out_nm}_[01][0-9]_tpd[0-9][0-9]_*.nc |
| 3802 |
fi # !fl_nbr |
| 3803 |
# fi # !false |
| 3804 |
fi # !clm_md |
| 3805 |
|
| 3806 |
# Block 1: Loop 4: Regrid first twelve files. Load-balance by using idle nodes (nodes not used for seasonal climatologies). |
| 3807 |
if [ -n "${rgr_opt}" ]; then |
| 3808 |
printf "Regrid monthly data...\n" |
| 3809 |
[[ ${dbg_lvl} -ge 1 ]] && date_rgr=$(date +"%s") |
| 3810 |
for ((clm_idx=1;clm_idx<=12;clm_idx++)); do |
| 3811 |
# NB: Months, seasons, files are 1-based ([1..12], [13..16], [1..17]), nodes are 0-based ([0..11]) |
| 3812 |
let nd_idx=$(((clm_idx-1+csn_nbr) % nd_nbr)) |
| 3813 |
if [ ${nd_idx} -lt ${csn_nbr} ]; then |
| 3814 |
let nd_idx=${nd_idx}+${csn_nbr} |
| 3815 |
# 20190315: Not necessary to modulo final result by nd_nbr to handle csn_nbr > nd_nbr |
| 3816 |
# because (1-based) cmd_mpi array is always at least 13 elements long and each element is |
| 3817 |
# already round-robin'ed onto existing nodes |
| 3818 |
fi # !nd |
| 3819 |
# printf "dbg: clm_idx = ${clm_idx}, nd_idx = ${nd_idx}, csn_nbr = ${csn_nbr}, nd_nbr = ${nd_nbr}\n" |
| 3820 |
#cmd_rgr[${clm_idx}]="${cmd_mpi[${nd_idx}]} ncks -O -t ${thr_nbr} ${nco_opt} ${rgr_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 3821 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${nd_idx}]} ncremap -u .pid${spt_pid}.climo.${clm_idx}.tmp --nco_opt=\"${nco_opt}\" -t ${thr_nbr} ${prc_opt} ${rmp_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 3822 |
if [ "${mdl_typ}" = 'mpas' ]; then |
| 3823 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${nd_idx}]} ncremap -C -u .pid${spt_pid}.climo.${clm_idx}.tmp ${prc_opt} ${d2f_opt} ${dpt_opt} --nco_opt=\"${nco_opt}\" -t ${thr_nbr} ${map_opt} ${vrt_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 3824 |
fi # !mdl_typ |
| 3825 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3826 |
echo ${cmd_rgr[${clm_idx}]} |
| 3827 |
fi # !dbg |
| 3828 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3829 |
if [ -z "${par_opt}" ]; then |
| 3830 |
eval ${cmd_rgr[${clm_idx}]} |
| 3831 |
if [ "$?" -ne 0 ]; then |
| 3832 |
printf "${spt_nm}: ERROR monthly regrid cmd_rgr[${clm_idx}] failed. Debug this:\n${cmd_rgr[${clm_idx}]}\n" |
| 3833 |
exit 1 |
| 3834 |
fi # !err |
| 3835 |
else # !par_opt |
| 3836 |
eval ${cmd_rgr[${clm_idx}]} ${par_opt} |
| 3837 |
rgr_pid[${clm_idx}]=$! |
| 3838 |
fi # !par_opt |
| 3839 |
fi # !dbg |
| 3840 |
done # !clm_idx |
| 3841 |
# Start seasonal means first, then wait() for monthly regridding to finish |
| 3842 |
fi # !rgr_opt |
| 3843 |
|
| 3844 |
# Block 2: Climatological seasonal means |
| 3845 |
if [ "${csn_flg}" = 'Yes' ]; then |
| 3846 |
# Block 2 Loop 1: Generate seasonal commands |
| 3847 |
[[ ${dbg_lvl} -ge 1 ]] && date_clm=$(date +"%s") |
| 3848 |
for ((csn_idx=0;csn_idx<${csn_nbr};csn_idx++)); do |
| 3849 |
let clm_idx=1+12+${csn_idx} |
| 3850 |
fl_lst='' |
| 3851 |
for (( mth_ctr=0;mth_ctr<${csn_nom[${map_r2d[${csn_idx}]}]};mth_ctr++ )); do |
| 3852 |
let mth_idx=${csn_srt_idx[${map_r2d[${csn_idx}]}]}+${mth_ctr} |
| 3853 |
[[ ${mth_idx} -gt 12 ]] && mth_idx=$((mth_idx % 12)) |
| 3854 |
fl_lst="${fl_lst} ${fl_out[${mth_idx}]}" |
| 3855 |
done # !mth_idx |
| 3856 |
cmd_clm[${clm_idx}]="${cmd_mpi[${clm_idx}]} ${cmd_mth2csn} ${clm_bnd[${clm_idx}]} -O -w ${csn_wgt[${map_r2d[${csn_idx}]}]} ${nco_opt} ${gaa_sng[${clm_idx}]} ${fl_lst} ${fl_out[${clm_idx}]}" |
| 3857 |
done # !csn_idx |
| 3858 |
# cmd_clm[13]="${cmd_mpi[13]} ncra --cb -O -w 31,30,31 ${nco_opt} ${gaa_sng[${clm_idx}]} ${fl_out[3]} ${fl_out[4]} ${fl_out[5]} ${fl_out[13]}" |
| 3859 |
# cmd_clm[14]="${cmd_mpi[14]} ncra --cb -O -w 30,31,31 ${nco_opt} ${gaa_sng[${clm_idx}]} ${fl_out[6]} ${fl_out[7]} ${fl_out[8]} ${fl_out[14]}" |
| 3860 |
# cmd_clm[15]="${cmd_mpi[15]} ncra --cb -O -w 30,31,30 ${nco_opt} ${gaa_sng[${clm_idx}]} ${fl_out[9]} ${fl_out[10]} ${fl_out[11]} ${fl_out[15]}" |
| 3861 |
# cmd_clm[16]="${cmd_mpi[16]} ncra --cb -O -w 31,31,28 ${nco_opt} ${gaa_sng[${clm_idx}]} ${fl_out[12]} ${fl_out[1]} ${fl_out[2]} ${fl_out[16]}" |
| 3862 |
|
| 3863 |
# Block 2 Loop 2: Execute and/or echo seasonal climatology commands |
| 3864 |
let bch_nbr=$((csn_nbr / job_nbr)) |
| 3865 |
let bch_flg=$((csn_nbr % job_nbr)) |
| 3866 |
if [ ${bch_nbr} -eq 0 ]; then |
| 3867 |
let bch_nbr=$((bch_nbr+1)) |
| 3868 |
elif [ ${bch_flg} -ne 0 ]; then |
| 3869 |
let bch_nbr=$((bch_nbr+1)) |
| 3870 |
fi # !bch_flg |
| 3871 |
let bch_nbrm1=$((bch_nbr-1)) |
| 3872 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 3873 |
# clm_idx is 1-based, bch_idx is 0-based |
| 3874 |
let clm_idx_srt=$((12 + (bch_idx * job_nbr) + 1)) |
| 3875 |
let clm_idx_end=$((clm_idx_srt + job_nbr - 1)) |
| 3876 |
if [ ${bch_idx} -eq ${bch_nbrm1} ] && [ ${bch_flg} -ne 0 ]; then |
| 3877 |
let clm_idx_srt=$((12 + (bch_idx * job_nbr) + 1)) |
| 3878 |
let clm_idx_end=${clm_csn_end_idx} |
| 3879 |
fi # !bch_flg |
| 3880 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 3881 |
let csn_idx=$((clm_idx - 12 - 1)) |
| 3882 |
printf "Climatological seasonal mean for ${csn_abb[${map_r2d[${csn_idx}]}]} ...\n" |
| 3883 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3884 |
echo ${cmd_clm[${clm_idx}]} |
| 3885 |
fi # !dbg |
| 3886 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3887 |
if [ -z "${par_opt}" ]; then |
| 3888 |
eval ${cmd_clm[${clm_idx}]} |
| 3889 |
if [ "$?" -ne 0 ]; then |
| 3890 |
printf "${spt_nm}: ERROR seasonal climo cmd_clm[${clm_idx}] failed. Debug this:\n${cmd_clm[${clm_idx}]}\n" |
| 3891 |
exit 1 |
| 3892 |
fi # !err |
| 3893 |
else # !par_opt |
| 3894 |
eval ${cmd_clm[${clm_idx}]} ${par_opt} |
| 3895 |
clm_pid[${clm_idx}]=$! |
| 3896 |
fi # !par_opt |
| 3897 |
fi # !dbg |
| 3898 |
done # !clm_idx |
| 3899 |
if [ -n "${par_opt}" ]; then |
| 3900 |
for ((clm_idx=clm_idx_srt;clm_idx<=clm_idx_end;clm_idx++)); do |
| 3901 |
wait ${clm_pid[${clm_idx}]} |
| 3902 |
if [ "$?" -ne 0 ]; then |
| 3903 |
printf "${spt_nm}: ERROR seasonal climo cmd_clm[${clm_idx}] failed. Debug this:\n${cmd_clm[${clm_idx}]}\n" |
| 3904 |
exit 1 |
| 3905 |
fi # !err |
| 3906 |
done # !clm_idx |
| 3907 |
fi # !par_opt |
| 3908 |
done # !bch_idx |
| 3909 |
# wait() for seasonal climatologies to finish |
| 3910 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3911 |
date_crr=$(date +"%s") |
| 3912 |
date_dff=$((date_crr-date_clm)) |
| 3913 |
echo "Elapsed time to generate seasonal climos $((date_dff/60))m$((date_dff % 60))s" |
| 3914 |
fi # !dbg |
| 3915 |
fi # !csn_flg |
| 3916 |
# wait() for monthly regridding, if any, to finish |
| 3917 |
if [ -n "${rgr_opt}" ]; then |
| 3918 |
if [ -n "${par_opt}" ]; then |
| 3919 |
for ((clm_idx=1;clm_idx<=12;clm_idx++)); do |
| 3920 |
wait ${rgr_pid[${clm_idx}]} |
| 3921 |
if [ "$?" -ne 0 ]; then |
| 3922 |
printf "${spt_nm}: ERROR monthly regrid cmd_rgr[${clm_idx}] failed. Debug this:\n${cmd_rgr[${clm_idx}]}\n" |
| 3923 |
exit 1 |
| 3924 |
fi # !err |
| 3925 |
done # !clm_idx |
| 3926 |
fi # !par_opt |
| 3927 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3928 |
date_crr=$(date +"%s") |
| 3929 |
date_dff=$((date_crr-date_rgr)) |
| 3930 |
echo "Elapsed time to regrid monthly climos $((date_dff/60))m$((date_dff % 60))s" |
| 3931 |
fi # !dbg |
| 3932 |
fi # !rgr_opt |
| 3933 |
|
| 3934 |
# Block 2: Loop 4: Regrid seasonal files. Load-balance by using idle nodes (nodes not used for annual mean). |
| 3935 |
if [ "${csn_flg}" = 'Yes' ]; then |
| 3936 |
if [ -n "${rgr_opt}" ]; then |
| 3937 |
printf "Regrid seasonal data...\n" |
| 3938 |
[[ ${dbg_lvl} -ge 1 ]] && date_rgr=$(date +"%s") |
| 3939 |
for ((clm_idx=${clm_csn_srt_idx};clm_idx<=${clm_csn_end_idx};clm_idx++)); do |
| 3940 |
let nd_idx=$(((clm_idx-1+csn_nbr) % nd_nbr)) |
| 3941 |
if [ ${nd_idx} -lt ${csn_nbr} ]; then |
| 3942 |
let nd_idx=${nd_idx}+${csn_nbr} |
| 3943 |
fi # !nd |
| 3944 |
#cmd_rgr[${clm_idx}]="${cmd_mpi[${nd_idx}]} ncks -O -t ${thr_nbr} ${nco_opt} ${rgr_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 3945 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${nd_idx}]} ncremap -u .pid${spt_pid}.climo.${clm_idx}.tmp --nco_opt=\"${nco_opt}\" -t ${thr_nbr} ${prc_opt} ${rmp_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 3946 |
if [ "${mdl_typ}" = 'mpas' ]; then |
| 3947 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${nd_idx}]} ncremap -C -u .pid${spt_pid}.climo.${clm_idx}.tmp ${prc_opt} ${d2f_opt} ${dpt_opt} --nco_opt=\"${nco_opt}\" -t ${thr_nbr} ${map_opt} ${vrt_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 3948 |
fi # !mdl_typ |
| 3949 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3950 |
echo ${cmd_rgr[${clm_idx}]} |
| 3951 |
fi # !dbg |
| 3952 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3953 |
if [ -z "${par_opt}" ]; then |
| 3954 |
eval ${cmd_rgr[${clm_idx}]} |
| 3955 |
if [ "$?" -ne 0 ]; then |
| 3956 |
printf "${spt_nm}: ERROR seasonal regrid cmd_rgr[${clm_idx}] failed. Debug this:\n${cmd_rgr[${clm_idx}]}\n" |
| 3957 |
exit 1 |
| 3958 |
fi # !err |
| 3959 |
else # !par_opt |
| 3960 |
eval ${cmd_rgr[${clm_idx}]} ${par_opt} |
| 3961 |
rgr_pid[${clm_idx}]=$! |
| 3962 |
fi # !par_opt |
| 3963 |
fi # !dbg |
| 3964 |
done # !clm_idx |
| 3965 |
# Start annual mean first, then wait() for seasonal regridding to finish |
| 3966 |
fi # !rgr_opt |
| 3967 |
fi # !csn_flg |
| 3968 |
|
| 3969 |
# Block 3: Climatological annual mean |
| 3970 |
if [ "${ann_flg}" = 'Yes' ]; then |
| 3971 |
printf "Climatological annual mean...\n" |
| 3972 |
[[ ${dbg_lvl} -ge 1 ]] && date_clm=$(date +"%s") |
| 3973 |
fl_lst="${fl_out[${clm_csn_mam_idx}]} ${fl_out[${clm_csn_jja_idx}]} ${fl_out[${clm_csn_son_idx}]} ${fl_out[${clm_csn_djf_idx}]}" |
| 3974 |
cmd_clm[${clm_nbr}]="${cmd_mpi[${clm_nbr}]} ${cmd_csn2ann} ${clm_bnd[${clm_nbr}]} -O -w 92,92,91,90 ${nco_opt} ${gaa_sng[${clm_nbr}]} ${fl_lst} ${fl_out[${clm_nbr}]}" |
| 3975 |
# cmd_clm[17]="${cmd_mpi[17]} ncra --c2b -O -w 92,92,91,90 ${nco_opt} ${gaa_sng[${clm_idx}]} ${fl_out[13]} ${fl_out[14]} ${fl_out[15]} ${fl_out[16]} ${fl_out[17]}" |
| 3976 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3977 |
echo ${cmd_clm[${clm_nbr}]} |
| 3978 |
fi # !dbg |
| 3979 |
if [ ${dbg_lvl} -le 1 ]; then |
| 3980 |
if [ -z "${par_opt}" ]; then |
| 3981 |
eval ${cmd_clm[${clm_nbr}]} |
| 3982 |
if [ "$?" -ne 0 ]; then |
| 3983 |
printf "${spt_nm}: ERROR annual climo cmd_clm[${clm_nbr}] failed. Debug this:\n${cmd_clm[${clm_nbr}]}\n" |
| 3984 |
exit 1 |
| 3985 |
fi # !err |
| 3986 |
else # !par_opt |
| 3987 |
eval ${cmd_clm[${clm_nbr}]} ${par_opt} |
| 3988 |
clm_pid[${clm_nbr}]=$! |
| 3989 |
fi # !par_opt |
| 3990 |
fi # !dbg |
| 3991 |
fi # !ann_flg |
| 3992 |
# wait() for seasonal regridding, if any, to finish |
| 3993 |
if [ "${csn_flg}" = 'Yes' ]; then |
| 3994 |
if [ -n "${rgr_opt}" ]; then |
| 3995 |
if [ -n "${par_opt}" ]; then |
| 3996 |
for ((clm_idx=${clm_csn_srt_idx};clm_idx<=${clm_csn_end_idx};clm_idx++)); do |
| 3997 |
wait ${rgr_pid[${clm_idx}]} |
| 3998 |
if [ "$?" -ne 0 ]; then |
| 3999 |
printf "${spt_nm}: ERROR seasonal regrid cmd_rgr[${clm_idx}] failed. Debug this:\n${cmd_rgr[${clm_idx}]}\n" |
| 4000 |
exit 1 |
| 4001 |
fi # !err |
| 4002 |
done # !clm_idx |
| 4003 |
fi # !par_opt |
| 4004 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 4005 |
date_crr=$(date +"%s") |
| 4006 |
date_dff=$((date_crr-date_rgr)) |
| 4007 |
echo "Elapsed time to regrid seasonal climos $((date_dff/60))m$((date_dff % 60))s" |
| 4008 |
fi # !dbg |
| 4009 |
fi # !rgr_opt |
| 4010 |
fi # !csn_flg |
| 4011 |
if [ "${ann_flg}" = 'Yes' ]; then |
| 4012 |
clm_idx=${clm_nbr} |
| 4013 |
# wait() for annual climatology to finish |
| 4014 |
if [ -n "${par_opt}" ]; then |
| 4015 |
wait ${clm_pid[${clm_idx}]} |
| 4016 |
if [ "$?" -ne 0 ]; then |
| 4017 |
printf "${spt_nm}: ERROR annual climo cmd_clm[${clm_idx}] failed. Debug this:\n${cmd_clm[${clm_idx}]}\n" |
| 4018 |
exit 1 |
| 4019 |
fi # !err |
| 4020 |
fi # !par_opt |
| 4021 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 4022 |
date_crr=$(date +"%s") |
| 4023 |
date_dff=$((date_crr-date_clm)) |
| 4024 |
echo "Elapsed time to generate annual climos $((date_dff/60))m$((date_dff % 60))s" |
| 4025 |
fi # !dbg |
| 4026 |
|
| 4027 |
# Block 5: Regrid climatological annual mean |
| 4028 |
if [ -n "${rgr_opt}" ]; then |
| 4029 |
printf "Regrid annual data...\n" |
| 4030 |
[[ ${dbg_lvl} -ge 1 ]] && date_rgr=$(date +"%s") |
| 4031 |
#cmd_rgr[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncks -O -t ${thr_nbr} ${nco_opt} ${rgr_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 4032 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncremap -u .pid${spt_pid}.climo.${clm_idx}.tmp --nco_opt=\"${nco_opt}\" -t ${thr_nbr} ${prc_opt} ${rmp_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 4033 |
if [ "${mdl_typ}" = 'mpas' ]; then |
| 4034 |
cmd_rgr[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncremap -C -u .pid${spt_pid}.climo.${clm_idx}.tmp ${prc_opt} ${d2f_opt} ${dpt_opt} --nco_opt=\"${nco_opt}\" -t ${thr_nbr} ${map_opt} ${vrt_opt} ${fl_out[${clm_idx}]} ${fl_rgr[${clm_idx}]}" |
| 4035 |
fi # !mdl_typ |
| 4036 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 4037 |
echo ${cmd_rgr[${clm_idx}]} |
| 4038 |
fi # !dbg |
| 4039 |
if [ ${dbg_lvl} -le 1 ]; then |
| 4040 |
# NB: Do not background climatological mean regridding since it is last step |
| 4041 |
eval ${cmd_rgr[${clm_idx}]} |
| 4042 |
if [ "$?" -ne 0 ]; then |
| 4043 |
printf "${spt_nm}: ERROR annual regrid cmd_rgr[${clm_idx}] failed. Debug this:\n${cmd_rgr[${clm_idx}]}\n" |
| 4044 |
exit 1 |
| 4045 |
fi # !err |
| 4046 |
fi # !dbg |
| 4047 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 4048 |
date_crr=$(date +"%s") |
| 4049 |
date_dff=$((date_crr-date_rgr)) |
| 4050 |
echo "Elapsed time to regrid annual climo $((date_dff/60))m$((date_dff % 60))s" |
| 4051 |
fi # !dbg |
| 4052 |
fi # !rgr_opt |
| 4053 |
fi # !ann_flg |
| 4054 |
|
| 4055 |
# Link E3SM-climo to AMWG-climo filenames |
| 4056 |
# drc_pwd is always fully qualified path but drc_out and drc_rgr may be relative paths |
| 4057 |
# Strategy: Start in drc_pwd, cd to drc_rgr, then link so return code comes from ln not cd |
| 4058 |
if [ ${lnk_flg} = 'Yes' ]; then |
| 4059 |
printf "Link E3SM-climo to AMWG-climo filenames...\n" |
| 4060 |
for ((clm_idx=1;clm_idx<=clm_nbr;clm_idx++)); do |
| 4061 |
if [ -n "${rgr_opt}" ]; then |
| 4062 |
cmd_lnk[${clm_idx}]="cd ${drc_pwd};cd ${drc_rgr};ln -s -f ${fl_rgr[${clm_idx}]/${drc_rgr}\//} ${fl_amwg[${clm_idx}]/${drc_rgr}\//}" |
| 4063 |
else |
| 4064 |
cmd_lnk[${clm_idx}]="cd ${drc_pwd};cd ${drc_out};ln -s -f ${fl_out[${clm_idx}]/${drc_out}\//} ${fl_amwg[${clm_idx}]/${drc_out}\//}" |
| 4065 |
fi # !rgr_opt |
| 4066 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 4067 |
echo ${cmd_lnk[${clm_idx}]} |
| 4068 |
fi # !dbg |
| 4069 |
if [ ${dbg_lvl} -le 1 ]; then |
| 4070 |
eval ${cmd_lnk[${clm_idx}]} |
| 4071 |
if [ "$?" -ne 0 ]; then |
| 4072 |
printf "${spt_nm}: ERROR linking E3SM to AMWG filename cmd_lnk[${clm_idx}] failed. Debug this:\n${cmd_lnk[${clm_idx}]}\n" |
| 4073 |
exit 1 |
| 4074 |
fi # !err |
| 4075 |
fi # !dbg |
| 4076 |
done # !clm_idx |
| 4077 |
cd ${drc_pwd} |
| 4078 |
fi # !lnk_flg |
| 4079 |
fi # !clm_md !bnr_flg |
| 4080 |
|
| 4081 |
# Extended climos |
| 4082 |
if [ "${clm_flg}" = 'Yes' ] && [ "${xtn_flg}" = 'Yes' ]; then |
| 4083 |
if [ -n "${drc_prv}" ] && [ ! -d "${drc_prv}" ]; then |
| 4084 |
cmd_mkd="mkdir -p ${drc_prv}" |
| 4085 |
eval ${cmd_mkd} |
| 4086 |
if [ "$?" -ne 0 ]; then |
| 4087 |
printf "${spt_nm}: ERROR Failed to create previous climatology directory. Debug this:\n${cmd_mkd}\n" |
| 4088 |
printf "${spt_nm}: HINT Creating a directory requires proper write permissions\n" |
| 4089 |
exit 1 |
| 4090 |
fi # !err |
| 4091 |
fi # !drc_prv |
| 4092 |
if [ -n "${drc_xtn}" ] && [ ! -d "${drc_xtn}" ]; then |
| 4093 |
cmd_mkd="mkdir -p ${drc_xtn}" |
| 4094 |
eval ${cmd_mkd} |
| 4095 |
if [ "$?" -ne 0 ]; then |
| 4096 |
printf "${spt_nm}: ERROR Failed to create extended climatology directory. Debug this:\n${cmd_mkd}\n" |
| 4097 |
printf "${spt_nm}: HINT Creating a directory requires proper write permissions\n" |
| 4098 |
exit 1 |
| 4099 |
fi # !err |
| 4100 |
fi # !drc_xtn |
| 4101 |
|
| 4102 |
trim_leading_zeros ${yr_srt_prv} |
| 4103 |
yr_srt_rth_prv=${sng_trm} |
| 4104 |
yyyy_srt_prv=`printf "%04d" ${yr_srt_rth_prv}` |
| 4105 |
yyyy_clm_srt_dec_prv=${yyyy_srt_prv} |
| 4106 |
let yr_srtm1_prv=${yr_srt_rth_prv}-1 |
| 4107 |
if [ "${ncr_flg}" = 'Yes' ]; then |
| 4108 |
let yr_end_prv=${yr_srt_rth}-1 |
| 4109 |
fi # !ncr_flg |
| 4110 |
trim_leading_zeros ${yr_end_prv} |
| 4111 |
yr_end_rth_prv=${sng_trm} |
| 4112 |
yyyy_end_prv=`printf "%04d" ${yr_end_rth_prv}` |
| 4113 |
let yr_endm1_prv=${yr_end_rth_prv}-1 |
| 4114 |
let yr_nbr_prv=${yr_end_rth_prv}-${yr_srt_rth_prv}+1 |
| 4115 |
let yr_nbr_xtn=${yr_nbr_prv}+${yr_nbr} |
| 4116 |
|
| 4117 |
wgt_prv=$(echo "${yr_nbr_prv}/${yr_nbr_xtn}" | bc -l) |
| 4118 |
wgt_crr=$(echo "${yr_nbr}/${yr_nbr_xtn}" | bc -l) |
| 4119 |
if [ "${bnr_flg}" = 'Yes' ]; then |
| 4120 |
printf "Produce extended climatology as weighted average of two previously computed climatologies:\n" |
| 4121 |
else # !bnr_flg |
| 4122 |
printf "Produce extended climatology as weighted average of previously computed and incremental/new climatologies:\n" |
| 4123 |
fi # !bnr_flg |
| 4124 |
|
| 4125 |
# Replace yr_srt by yr_srt_prv in "yrs_averaged" attribute |
| 4126 |
nco_opt="${nco_opt/${yr_srt}-/${yr_srt_prv}-}" |
| 4127 |
|
| 4128 |
if [ "${clm_md}" = 'ann' ]; then |
| 4129 |
printf "Previous/first climatology is ${yr_nbr_prv} years from ${yyyy_srt_prv} to ${yyyy_end_prv}, weight = ${wgt_prv}\n" |
| 4130 |
printf "Current/second climatology is ${yr_nbr} years from ${yyyy_srt} to ${yyyy_end}, weight = ${wgt_crr}\n" |
| 4131 |
printf "Extended climatology is ${yr_nbr_xtn} years from ${yyyy_srt_prv} to ${yyyy_end}\n" |
| 4132 |
fi # !clm_md |
| 4133 |
|
| 4134 |
if [ "${clm_md}" = 'mth' ]; then |
| 4135 |
|
| 4136 |
printf "Previous/first climatology is ${yr_nbr_prv} years from ${yyyy_clm_srt_dec_prv}${mm_ann_srt} to ${yyyy_end_prv}${mm_ann_end}, weight = ${wgt_prv}\n" |
| 4137 |
printf "Current/second climatology is ${yr_nbr} years from ${yyyy_clm_srt_dec}${mm_ann_srt} to ${yyyy_end}${mm_ann_end}, weight = ${wgt_crr}\n" |
| 4138 |
printf "Extended climatology is ${yr_nbr_xtn} years from ${yyyy_clm_srt_dec_prv}${mm_ann_srt} to ${yyyy_end}${mm_ann_end}\n" |
| 4139 |
|
| 4140 |
clm_idx=0 |
| 4141 |
for mth in {01..12}; do |
| 4142 |
let clm_idx=${clm_idx}+1 |
| 4143 |
MM=`printf "%02d" ${clm_idx}` |
| 4144 |
fl_prv[${clm_idx}]="${drc_prv}/${out_nm}_${MM}_${yyyy_srt_prv}${MM}_${yyyy_end_prv}${MM}_climo.nc" |
| 4145 |
fl_xtn[${clm_idx}]="${drc_xtn}/${out_nm}_${MM}_${yyyy_srt_prv}${MM}_${yyyy_end}${MM}_climo.nc" |
| 4146 |
done # !mth |
| 4147 |
|
| 4148 |
for ((csn_idx=0;csn_idx<${csn_nbr};csn_idx++)); do |
| 4149 |
# Produce names like "${out_nm}_MAM_${yyyy_srt_prv}03_${yyyy_end_prv}05_climo.nc" |
| 4150 |
let clm_idx=1+12+${csn_idx} |
| 4151 |
fl_prv[${clm_idx}]="${drc_prv}/${out_nm}_${csn_abb[${map_r2d[${csn_idx}]}]}_${yyyy_srt_prv}${csn_srt_mm[${map_r2d[${csn_idx}]}]}_${yyyy_end_prv}${csn_end_mm[${map_r2d[${csn_idx}]}]}_climo.nc" |
| 4152 |
fl_xtn[${clm_idx}]="${drc_xtn}/${out_nm}_${csn_abb[${map_r2d[${csn_idx}]}]}_${yyyy_srt_prv}${csn_srt_mm[${map_r2d[${csn_idx}]}]}_${yyyy_end}${csn_end_mm[${map_r2d[${csn_idx}]}]}_climo.nc" |
| 4153 |
if [ "${csn_abb[${map_r2d[${csn_idx}]}]}" = 'DJF' ]; then |
| 4154 |
fl_prv[${clm_idx}]="${drc_prv}/${out_nm}_${csn_abb[${map_r2d[${csn_idx}]}]}_${yyyy_clm_srt_dec_prv}${mm_djf_srt}_${yyyy_end_prv}${mm_djf_end}_climo.nc" |
| 4155 |
fl_xtn[${clm_idx}]="${drc_xtn}/${out_nm}_${csn_abb[${map_r2d[${csn_idx}]}]}_${yyyy_clm_srt_dec_prv}${mm_djf_srt}_${yyyy_end}${mm_djf_end}_climo.nc" |
| 4156 |
fi # !DJF |
| 4157 |
if [ "${csn_abb[${map_r2d[${csn_idx}]}]}" = 'ANN' ]; then |
| 4158 |
fl_prv[${clm_idx}]="${drc_prv}/${out_nm}_${csn_abb[${map_r2d[${csn_idx}]}]}_${yyyy_clm_srt_dec_prv}${mm_ann_srt}_${yyyy_end_prv}${mm_ann_end}_climo.nc" |
| 4159 |
fl_xtn[${clm_idx}]="${drc_xtn}/${out_nm}_${csn_abb[${map_r2d[${csn_idx}]}]}_${yyyy_clm_srt_dec_prv}${mm_ann_srt}_${yyyy_end}${mm_ann_end}_climo.nc" |
| 4160 |
fi # !DJF |
| 4161 |
done # !csn_idx |
| 4162 |
|
| 4163 |
# fl_prv[13]="${drc_prv}/${out_nm}_MAM_${yyyy_srt_prv}03_${yyyy_end_prv}05_climo.nc" |
| 4164 |
# fl_prv[14]="${drc_prv}/${out_nm}_JJA_${yyyy_srt_prv}06_${yyyy_end_prv}08_climo.nc" |
| 4165 |
# fl_prv[15]="${drc_prv}/${out_nm}_SON_${yyyy_srt_prv}09_${yyyy_end_prv}11_climo.nc" |
| 4166 |
# fl_prv[16]="${drc_prv}/${out_nm}_DJF_${yyyy_clm_srt_dec_prv}${mm_djf_srt}_${yyyy_end_prv}${mm_djf_end}_climo.nc" |
| 4167 |
# fl_xtn[13]="${drc_xtn}/${out_nm}_MAM_${yyyy_srt_prv}03_${yyyy_end}05_climo.nc" |
| 4168 |
# fl_xtn[14]="${drc_xtn}/${out_nm}_JJA_${yyyy_srt_prv}06_${yyyy_end}08_climo.nc" |
| 4169 |
# fl_xtn[15]="${drc_xtn}/${out_nm}_SON_${yyyy_srt_prv}09_${yyyy_end}11_climo.nc" |
| 4170 |
# fl_xtn[16]="${drc_xtn}/${out_nm}_DJF_${yyyy_clm_srt_dec_prv}${mm_djf_srt}_${yyyy_end}${mm_djf_end}_climo.nc" |
| 4171 |
|
| 4172 |
if [ "${ann_flg}" = 'Yes' ]; then |
| 4173 |
fl_prv[${clm_nbr}]="${drc_prv}/${out_nm}_ANN_${yyyy_clm_srt_dec_prv}${mm_ann_srt}_${yyyy_end_prv}${mm_ann_end}_climo.nc" |
| 4174 |
fl_xtn[${clm_nbr}]="${drc_xtn}/${out_nm}_ANN_${yyyy_clm_srt_dec_prv}${mm_ann_srt}_${yyyy_end}${mm_ann_end}_climo.nc" |
| 4175 |
fi # !ann_flg |
| 4176 |
|
| 4177 |
# Derive all regridded and AMWG names from output names |
| 4178 |
for ((clm_idx=1;clm_idx<=clm_nbr;clm_idx++)); do |
| 4179 |
fl_rgr_prv[${clm_idx}]="${fl_rgr[${clm_idx}]/${drc_rgr}/${drc_rgr_prv}}" |
| 4180 |
fl_rgr_prv[${clm_idx}]="${fl_rgr_prv[${clm_idx}]/_${yyyy_srt}/_${yyyy_srt_prv}}" |
| 4181 |
fl_rgr_prv[${clm_idx}]="${fl_rgr_prv[${clm_idx}]/_${yyyy_end}/_${yyyy_end_prv}}" |
| 4182 |
|
| 4183 |
fl_rgr_xtn[${clm_idx}]="${fl_rgr[${clm_idx}]/${drc_rgr}/${drc_rgr_xtn}}" |
| 4184 |
fl_rgr_xtn[${clm_idx}]="${fl_rgr_xtn[${clm_idx}]/_${yyyy_srt}/_${yyyy_srt_prv}}" |
| 4185 |
|
| 4186 |
fl_amwg_xtn[${clm_idx}]=`expr match "${fl_xtn[${clm_idx}]}" '\(.*\)_.*_.*_climo.nc'` # Prune _YYYYYMM_YYYYMM_climo.nc |
| 4187 |
fl_amwg_xtn[${clm_idx}]="${fl_amwg[${clm_idx}]}_climo.nc" # Replace with _climo.nc |
| 4188 |
fl_amwg_xtn[${clm_idx}]="${fl_amwg[${clm_idx}]/${drc_xtn}\//}" # Delete prepended path to ease symlinking |
| 4189 |
done # !clm_idx |
| 4190 |
|
| 4191 |
printf "Weight input climos to produce extended climo...\n" |
| 4192 |
for ((clm_idx=1;clm_idx<=clm_nbr;clm_idx++)); do |
| 4193 |
cmd_xtn[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncflint -O ${nco_opt} ${gaa_sng[${clm_idx}]} -w ${wgt_prv},${wgt_crr} ${fl_prv[${clm_idx}]} ${fl_out[${clm_idx}]} ${fl_xtn[${clm_idx}]}" |
| 4194 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 4195 |
echo ${cmd_xtn[${clm_idx}]} |
| 4196 |
fi # !dbg |
| 4197 |
if [ ${dbg_lvl} -le 1 ]; then |
| 4198 |
if [ -z "${par_opt}" ]; then |
| 4199 |
eval ${cmd_xtn[${clm_idx}]} |
| 4200 |
if [ "$?" -ne 0 ]; then |
| 4201 |
printf "${spt_nm}: ERROR extended climo cmd_xtn[${clm_idx}] failed. Debug this:\n${cmd_xtn[${clm_idx}]}\n" |
| 4202 |
exit 1 |
| 4203 |
fi # !err |
| 4204 |
else # !par_opt |
| 4205 |
eval ${cmd_xtn[${clm_idx}]} ${par_opt} # eval always returns 0 on backgrounded processes |
| 4206 |
xtn_pid[${clm_idx}]=$! |
| 4207 |
fi # !par_opt |
| 4208 |
fi # !dbg |
| 4209 |
done # !clm_idx |
| 4210 |
if [ -n "${par_opt}" ]; then |
| 4211 |
for ((clm_idx=1;clm_idx<=clm_nbr;clm_idx++)); do |
| 4212 |
wait ${xtn_pid[${clm_idx}]} |
| 4213 |
if [ "$?" -ne 0 ]; then |
| 4214 |
printf "${spt_nm}: ERROR extended climo cmd_xtn[${clm_idx}] failed. Debug this:\n${cmd_xtn[${clm_idx}]}\n" |
| 4215 |
exit 1 |
| 4216 |
fi # !err |
| 4217 |
done # !clm_idx |
| 4218 |
fi # !par_opt |
| 4219 |
wait |
| 4220 |
|
| 4221 |
if [ -n "${rgr_opt}" ]; then |
| 4222 |
printf "Weight input climos to produce extended regridded climo...\n" |
| 4223 |
for ((clm_idx=1;clm_idx<=clm_nbr;clm_idx++)); do |
| 4224 |
cmd_rgr_xtn[${clm_idx}]="${cmd_mpi[${clm_idx}]} ncflint -O ${nco_opt} -w ${wgt_prv},${wgt_crr} ${fl_rgr_prv[${clm_idx}]} ${fl_rgr[${clm_idx}]} ${fl_rgr_xtn[${clm_idx}]}" |
| 4225 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 4226 |
echo ${cmd_rgr_xtn[${clm_idx}]} |
| 4227 |
fi # !dbg |
| 4228 |
if [ ${dbg_lvl} -le 1 ]; then |
| 4229 |
if [ -z "${par_opt}" ]; then |
| 4230 |
eval ${cmd_rgr_xtn[${clm_idx}]} |
| 4231 |
if [ "$?" -ne 0 ]; then |
| 4232 |
printf "${spt_nm}: ERROR extended climo cmd_rgr_xtn[${clm_idx}] failed. Debug this:\n${cmd_rgr_xtn[${clm_idx}]}\n" |
| 4233 |
exit 1 |
| 4234 |
fi # !err |
| 4235 |
else # !par_opt |
| 4236 |
eval ${cmd_rgr_xtn[${clm_idx}]} ${par_opt} # eval always returns 0 on backgrounded processes |
| 4237 |
rgr_xtn_pid[${clm_idx}]=$! |
| 4238 |
fi # !par_opt |
| 4239 |
fi # !dbg |
| 4240 |
done # !clm_idx |
| 4241 |
if [ -n "${par_opt}" ]; then |
| 4242 |
for ((clm_idx=1;clm_idx<=clm_nbr;clm_idx++)); do |
| 4243 |
wait ${rgr_xtn_pid[${clm_idx}]} |
| 4244 |
if [ "$?" -ne 0 ]; then |
| 4245 |
printf "${spt_nm}: ERROR extended climo cmd_rgr_xtn[${clm_idx}] failed. Debug this:\n${cmd_rgr_xtn[${clm_idx}]}\n" |
| 4246 |
exit 1 |
| 4247 |
fi # !err |
| 4248 |
done # !clm_idx |
| 4249 |
fi # !par_opt |
| 4250 |
wait |
| 4251 |
fi # !rgr_opt |
| 4252 |
|
| 4253 |
# Link E3SM-climo to AMWG-climo filenames |
| 4254 |
# drc_pwd is always fully qualified path but drc_out and drc_rgr may be relative paths |
| 4255 |
# Strategy: Start in drc_pwd, cd to drc_rgr, then link so return code comes from ln not cd |
| 4256 |
if [ ${lnk_flg} = 'Yes' ]; then |
| 4257 |
printf "Link extended E3SM-climo to AMWG-climo filenames...\n" |
| 4258 |
for ((clm_idx=1;clm_idx<=clm_nbr;clm_idx++)); do |
| 4259 |
if [ -n "${rgr_opt}" ]; then |
| 4260 |
cmd_lnk_xtn[${clm_idx}]="cd ${drc_pwd};cd ${drc_rgr_xtn};ln -s -f ${fl_rgr_xtn[${clm_idx}]/${drc_rgr_xtn}\//} ${fl_amwg[${clm_idx}]/${drc_rgr_xtn}\//}" |
| 4261 |
else |
| 4262 |
cmd_lnk_xtn[${clm_idx}]="cd ${drc_pwd};cd ${drc_xtn};ln -s -f ${fl_xtn[${clm_idx}]/${drc_xtn}\//} ${fl_amwg[${clm_idx}]/${drc_xtn}\//}" |
| 4263 |
fi # !rgr_opt |
| 4264 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 4265 |
echo ${cmd_lnk_xtn[${clm_idx}]} |
| 4266 |
fi # !dbg |
| 4267 |
if [ ${dbg_lvl} -le 1 ]; then |
| 4268 |
eval ${cmd_lnk_xtn[${clm_idx}]} |
| 4269 |
if [ "$?" -ne 0 ]; then |
| 4270 |
printf "${spt_nm}: ERROR linking E3SM to AMWG filename cmd_lnk_xtn[${clm_idx}] failed. Debug this:\n${cmd_lnk_xtn[${clm_idx}]}\n" |
| 4271 |
exit 1 |
| 4272 |
fi # !err |
| 4273 |
fi # !dbg |
| 4274 |
done # !clm_idx |
| 4275 |
cd ${drc_pwd} |
| 4276 |
fi # !lnk_flg |
| 4277 |
fi # !clm_md |
| 4278 |
|
| 4279 |
else # !xtn_flg extended climos |
| 4280 |
|
| 4281 |
yr_nbr_xtn=${yr_nbr} |
| 4282 |
|
| 4283 |
fi # !xtn_flg extended climos |
| 4284 |
|
| 4285 |
if [ "${clm_flg}" = 'Yes' ]; then |
| 4286 |
if [ "${clm_md}" = 'dly' ]; then |
| 4287 |
echo "Quick plots of last climatological daily mean:" |
| 4288 |
let idx_lst=${clm_nbr}-1 |
| 4289 |
else |
| 4290 |
echo "Quick plots of last computed climatology:" |
| 4291 |
let idx_lst=${clm_nbr} |
| 4292 |
fi # !dly |
| 4293 |
|
| 4294 |
if [ -n "${yr_srt_prv}" ]; then |
| 4295 |
if [ -n "${rgr_opt}" ]; then |
| 4296 |
echo "ncvis ${fl_rgr_xtn[${idx_lst}]} &" |
| 4297 |
else |
| 4298 |
echo "ncvis ${fl_xtn[${idx_lst}]} &" |
| 4299 |
fi # !rgr_opt |
| 4300 |
else |
| 4301 |
if [ -n "${rgr_opt}" ]; then |
| 4302 |
echo "ncvis ${fl_rgr[${idx_lst}]} &" |
| 4303 |
else |
| 4304 |
echo "ncvis ${fl_out[${idx_lst}]} &" |
| 4305 |
fi # !rgr_opt |
| 4306 |
fi # !yr_srt_prv |
| 4307 |
fi # !clm_flg |
| 4308 |
if [ "${tms_flg}" = 'Yes' ]; then |
| 4309 |
echo "Quick plots of last timeseries segment of last variable split:" |
| 4310 |
let idx_lst=${var_nbr}-1 |
| 4311 |
if [ -n "${rgr_opt}" ] && [ ${no_ntv_tms} = 'No' ]; then |
| 4312 |
echo "ncvis ${fl_rgr[${idx_lst}]} &" |
| 4313 |
else |
| 4314 |
echo "ncvis ${fl_out[${idx_lst}]} &" |
| 4315 |
fi # !rgr_opt |
| 4316 |
fi # !tms_flg |
| 4317 |
date_end=$(date +"%s") |
| 4318 |
if [ -n "${caseid}" ]; then |
| 4319 |
printf "Completed ${yr_nbr_xtn}-year climatology operations for dataset with caseid = ${caseid} at `date`\n" |
| 4320 |
else # !caseid |
| 4321 |
printf "Completed ${yr_nbr_xtn}-year climatology operations for input data at `date`\n" |
| 4322 |
fi # !caseid |
| 4323 |
date_dff=$((date_end-date_srt)) |
| 4324 |
echo "Elapsed time $((date_dff/60))m$((date_dff % 60))s" |
| 4325 |
|
| 4326 |
exit 0 |