| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# ncremap, the NCO regridder and grid-file, map-file, and weight-generator |
| 4 |
|
| 5 |
# Purpose: Generate weights (i.e., map-files) for and regrid (subsets of) netCDF files between different Swath, Curvilinear, Rectangular, and Unstructured data (SCRUD) horizontal grids, generate any required/requested global or regional rectangular grid, output SCRIP, UGRID, and/or skeleton data formats, and interpolate between any specified pure pressure or hybrid sigma/pressure grids |
| 6 |
|
| 7 |
# Copyright (C) 2015--present Charlie Zender |
| 8 |
# This file is part of NCO, the netCDF Operators. NCO is free software. |
| 9 |
# You may redistribute and/or modify NCO under the terms of the |
| 10 |
# 3-Clause BSD License. |
| 11 |
|
| 12 |
# You are permitted to link NCO with the HDF, netCDF, OPeNDAP, and UDUnits |
| 13 |
# libraries and to distribute the resulting executables under the terms |
| 14 |
# of the BSD, but in addition obeying the extra stipulations of the |
| 15 |
# HDF, netCDF, OPeNDAP, and UDUnits licenses. |
| 16 |
|
| 17 |
# This program is distributed in the hope that it will be useful, |
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 20 |
# See the 3-Clause BSD License for more details. |
| 21 |
|
| 22 |
# The original author of this software, Charlie Zender, seeks to improve |
| 23 |
# it with your suggestions, contributions, bug-reports, and patches. |
| 24 |
# Please contact the NCO project at http://nco.sf.net or write to |
| 25 |
# Charlie Zender |
| 26 |
# Department of Earth System Science |
| 27 |
# University of California, Irvine |
| 28 |
# Irvine, CA 92697-3100 |
| 29 |
|
| 30 |
# Prerequisites: Bash, NCO (also ESMF_RegridWeightGen and/or TempestRemap for full functionality) |
| 31 |
# Script could use other shells, e.g., dash (Debian default) after rewriting function definitions and loops |
| 32 |
# Debug with 'bash -x ncremap --dbg=dbg_lvl' where 0 <= dbg_lvl <= 5 |
| 33 |
|
| 34 |
# Source: https://github.com/nco/nco/tree/master/data/ncremap |
| 35 |
# Documentation: http://nco.sf.net/nco.html#ncremap |
| 36 |
# Additional Documentation: |
| 37 |
# ncremap HowTo: https://e3sm.atlassian.net/wiki/spaces/DOC/pages/754286611/Regridding+E3SM+Data+with+ncremap |
| 38 |
# ncclimo HowTo: https://e3sm.atlassian.net/wiki/spaces/DOC/pages/31129737/Generate+Regrid+and+Split+Climatologies+climo+files+with+ncclimo |
| 39 |
# E3SM Climatology Requirements: https://acme-climate.atlassian.net/wiki/display/ATM/Climo+Files+-+v0.3+AMIP+runs (includes useful discussion of normalization in comments section) |
| 40 |
# Benchmarks: https://acme-climate.atlassian.net/wiki/spaces/ATM/pages/25231711/Validation+and+Benchmarking+of+Regridders |
| 41 |
|
| 42 |
# Regridder works in one of four modes: |
| 43 |
# 1. Free-will: Infer source and destination grids to generate map-file, then regrid |
| 44 |
# 2. Old Grid: Use known-good destination grid to generate map-file then regrid |
| 45 |
# 3. New Grid: Generate source-grid from ncks parameter string |
| 46 |
# 4. Pre-Destination: Apply supplied map-file to all input files |
| 47 |
# By default, ncremap deletes any intermediate grids and map-file that it generates |
| 48 |
# Use Free-Will, Old-Grid, or New-Grid mode to process Swath-Like-Data (SLD) where each input may be a granule on a new grid, yet all inputs are to be regridded to the same output grid |
| 49 |
# Use Pre-Destination mode to post-process models or analyses where all files are converted from the same source grid to the same destination grid so the map-file can be pre-generated and never change |
| 50 |
|
| 51 |
# Insta-install: |
| 52 |
# scp ~/nco/data/ncremap andes.olcf.ornl.gov:bin_andes |
| 53 |
# scp ~/nco/data/ncremap [email protected]:bin |
| 54 |
# scp ~/nco/data/ncremap [email protected]:bin_chrysalis |
| 55 |
# scp ~/nco/data/ncremap compy.pnl.gov:bin |
| 56 |
# scp ~/nco/data/ncremap derecho.hpc.ucar.edu:bin |
| 57 |
# scp ~/nco/data/ncremap dust.ess.uci.edu:bin |
| 58 |
# scp ~/nco/data/ncremap e3sm.ess.uci.edu:bin |
| 59 |
# scp ~/nco/data/ncremap frontier.olcf.ornl.gov:bin_frontier |
| 60 |
# scp ~/nco/data/ncclimo imua.ess.uci.edu:bin |
| 61 |
# scp ~/nco/data/ncclimo perlmutter-p1.nersc.gov:bin_perlmutter |
| 62 |
# scp ~/nco/data/ncremap spectral.ess.uci.edu:bin |
| 63 |
# scp dust.ess.uci.edu:bin/ncremap ~/bin |
| 64 |
# scp dust.ess.uci.edu:bin/ncremap ${MY_BIN_DIR} |
| 65 |
# scp [email protected]:bin/ncremap ${MY_BIN_DIR} |
| 66 |
|
| 67 |
# Set script name, directory, PID, run directory |
| 68 |
drc_pwd=${PWD} |
| 69 |
# Security: Explicitly unset IFS before wordsplitting, so Bash uses default IFS=<space><tab><newline> |
| 70 |
unset IFS |
| 71 |
# Set these before 'module' command which can overwrite ${BASH_SOURCE[0]} |
| 72 |
# NB: dash supports $0 syntax, not ${BASH_SOURCE[0]} syntax |
| 73 |
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in |
| 74 |
spt_src="${BASH_SOURCE[0]}" |
| 75 |
[[ -z "${spt_src}" ]] && spt_src="${0}" # Use ${0} when BASH_SOURCE is unavailable (e.g., dash) |
| 76 |
while [ -h "${spt_src}" ]; do # Recursively resolve ${spt_src} until file is no longer a symlink |
| 77 |
drc_spt="$( cd -P "$( dirname "${spt_src}" )" && pwd )" |
| 78 |
spt_src="$(readlink "${spt_src}")" |
| 79 |
[[ ${spt_src} != /* ]] && spt_src="${drc_spt}/${spt_src}" # If ${spt_src} was relative symlink, resolve it relative to path where symlink file was located |
| 80 |
done |
| 81 |
cmd_ln="${spt_src} ${@}" |
| 82 |
drc_spt="$( cd -P "$( dirname "${spt_src}" )" && pwd )" |
| 83 |
spt_nm=$(basename ${spt_src}) # [sng] Script name (unlike $0, ${BASH_SOURCE[0]} works well with 'source <script>') |
| 84 |
spt_pid=$$ # [nbr] Script PID (process ID) |
| 85 |
|
| 86 |
# https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.1/src/hdf5-1.10.1-RELEASE.txt |
| 87 |
# "The file locking calls used in HDF5 1.10.0 (including patch1) will fail when the underlying file system does not support file locking or where locks have been disabled. To disable all file locking operations, an environment variable named HDF5_USE_FILE_LOCKING can be set to the five-character string 'FALSE'." |
| 88 |
# 20200110 Qi Tang reports Cori batch scripts to generate map-files fail unless he sets this |
| 89 |
# 20200131 Necessary whenever using OpenMP and netCDF4-linked library on any non-locking filesystem? |
| 90 |
if [ -z "${HDF5_USE_FILE_LOCKING}" ]; then |
| 91 |
export HDF5_USE_FILE_LOCKING='FALSE' |
| 92 |
fi # HDF5_USE_FILE_LOCKING |
| 93 |
|
| 94 |
# 20221108: Passing environment variable NCO_PATH_OVERRIDE (NPO) to ncremap in batch queues fails on Cori |
| 95 |
# Approaches that fail include: 1. export NPO='Yes';ncremap ... 2. export NPO='Yes' ncremap ... |
| 96 |
# Direct approach that works is to pass NPO flag to ncremap via command-line switch |
| 97 |
# Require that path-override switch to be first command-line option (i.e., $1) found with shell syntax |
| 98 |
# ncremap/ncclimo implement NPO (though not getopt) logic prior to invoking NCO |
| 99 |
# This switch is a no-op in main getopt() block below (since it has already been parsed here) |
| 100 |
hrd_pth='No' # [sng] Hard-code machine-dependent paths/modules if HOSTNAME in database |
| 101 |
if [ -n "${1}" ]; then |
| 102 |
if [ "${1}" = '--hrd_pth' ] || [ "${1}" = '--npo' ] || [ "${1}" = '--nco_path_override' ] || [ "${1}" = '--NCO_PATH_OVERRIDE' ]; then |
| 103 |
hrd_pth='Yes' |
| 104 |
NCO_PATH_OVERRIDE='Yes' |
| 105 |
fi # !hrd_pth |
| 106 |
fi # !$1 |
| 107 |
|
| 108 |
# Configure paths at High-Performance Computer Centers (HPCCs) based on ${HOSTNAME} |
| 109 |
if [ -z "${HOSTNAME}" ]; then |
| 110 |
if [ -f /bin/hostname ] && [ -x /bin/hostname ]; then |
| 111 |
export HOSTNAME=`/bin/hostname` |
| 112 |
elif [ -f /usr/bin/hostname ] && [ -x /usr/bin/hostname ]; then |
| 113 |
export HOSTNAME=`/usr/bin/hostname` |
| 114 |
fi # !hostname |
| 115 |
fi # HOSTNAME |
| 116 |
# Default input and output directory is ${DATA} |
| 117 |
if [ -z "${DATA}" ]; then |
| 118 |
case "${HOSTNAME}" in |
| 119 |
andes* ) DATA="/gpfs/alpine/world-shared/cli115/${USER}" ; ;; # OLCF andes compute nodes named andesNNN, 256 GB/node |
| 120 |
bebop* | blogin* | b[0123456789][0123456789][0123456789] ) DATA="/lcrc/group/e3sm/${USER}" ; ;; # ANL/LCRC bebop compute nodes named bNNN, 36|64 cores|GB/node |
| 121 |
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 |
| 122 |
*cheyenne* ) DATA="/glade/p/work/${USER}" ; ;; # NCAR cheyenne compute nodes named, e.g., r8i0n8, r5i3n16, r12i5n29 ... 18|(64/128) cores|GB/node (cheyenne login nodes 256 GB) |
| 123 |
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) |
| 124 |
constance* | node* ) DATA='/scratch' ; ;; # PNNL |
| 125 |
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) |
| 126 |
frontier* ) DATA="/lustre/orion/cli115/world-shared/${USER}" ; ;; # OLCF frontier compute nodes named frontier01276 64|512 cores|GB/node |
| 127 |
ilogin* | i[0123456789][0123456789][0123456789] ) DATA="/lcrc/group/e3sm/${USER}" ; ;; # ANL/LCRC improv compute nodes named iNNN, 128|256 cores|GB/node |
| 128 |
login[0123456789][0123456789] ) # 20230831 Frontier and Perlmutter login nodes share this name :( |
| 129 |
if [ "${LMOD_SYSTEM_NAME}" = 'frontier' ]; then |
| 130 |
DATA="/lustre/orion/cli115/world-shared/${USER}" |
| 131 |
elif [ "${LMOD_SYSTEM_NAME}" = 'perlmutter' ]; then |
| 132 |
DATA="${SCRATCH}" |
| 133 |
fi # !LMOD_SYSTEM_NAME |
| 134 |
;; # !login |
| 135 |
perlmutter* | nid[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789] ) DATA="${SCRATCH}" ; ;; # NERSC perlmutter compute nodes named nidNNNNNN (CPU) with (64)|(512) cores|GB/node (cpu) (login nodes 512 GB) |
| 136 |
* ) DATA='/tmp' ; ;; # Other |
| 137 |
esac # !HOSTNAME |
| 138 |
fi # DATA |
| 139 |
|
| 140 |
# 20190423 Speed-up OpenMP processes on Cori KNL Intel builds (and possibly others) |
| 141 |
# Environmental settings (e.g., OMP_PROC_BIND=spread or KMP_PROC_BIND=intel) may place all threads on same hardware core |
| 142 |
# Problem only known to manifest when multiple instances of NCO are spawned on single node |
| 143 |
OMP_PROC_BIND=false |
| 144 |
|
| 145 |
# Ensure batch jobs access correct 'mpirun' (or, with SLURM, 'srun') command, netCDF library, and NCO executables and library |
| 146 |
# 20170914 Entire block is identical between ncclimo and ncremap---keep it that way! |
| 147 |
# 20190421 Change override default from opt-out to opt-in |
| 148 |
# 20221108 Implement hrd_pth in block above prior to getopt() |
| 149 |
# 20250903 Simplify code: Always define then re-use E3SMU_ROOT, then add E3SMU_ROOT/bin to path only for ncremap |
| 150 |
# 20260416 Andes does not include personal Anaconda because I never installed one there |
| 151 |
# Leave NCO_PATH_OVERRIDE unset or set to 'No' to prevent NCO from executing next block that overrides PATH |
| 152 |
# Set NCO_PATH_OVERRIDE to 'Yes' in environment to cause NCO to execute next block and to override PATH: |
| 153 |
# export NCO_PATH_OVERRIDE='Yes' |
| 154 |
if [ "${hrd_pth}" = 'Yes' ] && [ "${NCO_PATH_OVERRIDE}" = 'Yes' ]; then |
| 155 |
# If HOSTNAME is not in database, change hrd_pth_fnd to 'No' in case-statement default fall-through |
| 156 |
hrd_pth_fnd='Yes' # [sng] Machine-dependent paths/modules for HOSTNAME found in database |
| 157 |
case "${HOSTNAME}" in |
| 158 |
andes* ) |
| 159 |
# 20190827: Must guarantee finding mpirun |
| 160 |
source ${MODULESHOME}/init/sh # 20150607: PMC Ensures find module commands will be found |
| 161 |
if [ -d '/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 162 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco/andes' |
| 163 |
else |
| 164 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/base/envs/e3sm_unified_latest' |
| 165 |
fi |
| 166 |
export PATH='/ccs/home/zender/bin_andes'\:${PATH} |
| 167 |
export LD_LIBRARY_PATH='/ccs/home/zender/lib_andes'\:${E3SMU_ROOT}/lib\:${LD_LIBRARY_PATH} ; ;; |
| 168 |
bebop* | blogin* | b[0123456789][0123456789][0123456789] ) |
| 169 |
if [ -d '/lcrc/soft/climate/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 170 |
E3SMU_ROOT='/lcrc/soft/climate/e3sm-unified/e3smu_latest_for_nco/anvil' |
| 171 |
else |
| 172 |
E3SMU_ROOT='/lcrc/soft/climate/e3sm-unified/base/envs/e3sm_unified_latest' |
| 173 |
fi |
| 174 |
export PATH='/home/zender/bin'\:${PATH} |
| 175 |
export LD_LIBRARY_PATH='/home/zender/lib'\:${E3SMU_ROOT}/lib\:${LD_LIBRARY_PATH} ; ;; |
| 176 |
chrysalis* | chrlogin* | chr-[0123456789][0123456789][0123456789][0123456789] | ilogin* | i[0123456789][0123456789][0123456789] ) |
| 177 |
if [ -d '/lcrc/soft/climate/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 178 |
E3SMU_ROOT='/lcrc/soft/climate/e3sm-unified/e3smu_latest_for_nco/chrysalis' |
| 179 |
else |
| 180 |
E3SMU_ROOT='/lcrc/soft/climate/e3sm-unified/base/envs/e3sm_unified_latest' |
| 181 |
fi |
| 182 |
export PATH='/home/ac.zender/bin_chrysalis'\:${PATH} |
| 183 |
export LD_LIBRARY_PATH='/home/ac.zender/lib_chrysalis:/home/ac.zender/anaconda/lib'\:${E3SMU_ROOT}/lib\:${LD_LIBRARY_PATH} ; ;; |
| 184 |
compy* | n[0123456789][0123456789][0123456789][0123456789] ) |
| 185 |
module purge |
| 186 |
module load gcc/10.2.0 |
| 187 |
# 20210519: This script takes significant time (5-10 seconds) to load |
| 188 |
# 20230914: Deprecate special MOAB paths, rely on E3SMU |
| 189 |
# source /compyfs/software/mbtempest.envs.sh |
| 190 |
if [ -d '/share/apps/E3SM/conda_envs/e3smu_latest_for_nco' ]; then |
| 191 |
E3SMU_ROOT='/share/apps/E3SM/conda_envs/e3smu_latest_for_nco/compy' |
| 192 |
else |
| 193 |
E3SMU_ROOT='/share/apps/E3SM/conda_envs/base/envs/e3sm_unified_latest' |
| 194 |
fi |
| 195 |
export PATH='/qfs/people/zender/bin:/qfs/people/zender/anaconda/bin'\:${PATH} |
| 196 |
export LD_LIBRARY_PATH='/qfs/people/zender/lib:/qfs/people/zender/anaconda/lib'\:${LD_LIBRARY_PATH} ; ;; |
| 197 |
derecho* ) |
| 198 |
# 20240107: Derecho support not yet tested in batch mode |
| 199 |
if [ ${spt_nm} = 'ncremap' ]; then |
| 200 |
# 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) |
| 201 |
module load ncl |
| 202 |
fi # !ncremap |
| 203 |
if [ -n "${NCARG_ROOT}" ]; then |
| 204 |
export PATH="${PATH}:/glade/u/apps/ch/opt/ncl/6.6.2/gnu/8.3.0/bin" |
| 205 |
fi # !NCARG_ROOT |
| 206 |
export PATH='/glade/u/home/zender/bin'\:${PATH} |
| 207 |
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} ; ;; |
| 208 |
e3sm* ) |
| 209 |
export PATH='/home/zender/bin:/home/zender/anaconda/bin'\:${PATH} |
| 210 |
export LD_LIBRARY_PATH='/home/zender/lib:/home/zender/anaconda/lib'\:${LD_LIBRARY_PATH} ; ;; |
| 211 |
frontier* ) |
| 212 |
if [ ${spt_nm} = 'ncremap' ]; then |
| 213 |
if [ -d '/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 214 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco/frontier' |
| 215 |
else |
| 216 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/base/envs/e3sm_unified_latest' |
| 217 |
fi |
| 218 |
fi # !ncremap |
| 219 |
export PATH='/ccs/home/zender/bin_frontier:/ccs/home/zender/anaconda/bin'\:${PATH} |
| 220 |
export LD_LIBRARY_PATH='/ccs/home/zender/lib_frontier:/ccs/home/zender/anaconda/lib'\:${LD_LIBRARY_PATH} ; ;; |
| 221 |
login[0123456789][0123456789] ) # 20230831 Frontier and Perlmutter login nodes share this name :( |
| 222 |
if [ "${LMOD_SYSTEM_NAME}" = 'frontier' ]; then |
| 223 |
if [ -d '/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco' ]; then |
| 224 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/e3smu_latest_for_nco/frontier' |
| 225 |
else |
| 226 |
E3SMU_ROOT='/ccs/proj/cli115/software/e3sm-unified/base/envs/e3sm_unified_latest' |
| 227 |
fi |
| 228 |
export PATH='/ccs/home/zender/bin_frontier:/ccs/home/zender/anaconda/bin'\:${PATH} |
| 229 |
export LD_LIBRARY_PATH='/ccs/home/zender/lib_frontier:/ccs/home/zender/anaconda/lib'\:${LD_LIBRARY_PATH} |
| 230 |
elif [ "${LMOD_SYSTEM_NAME}" = 'perlmutter' ]; then |
| 231 |
# 20221103 Add build environment modules |
| 232 |
# 20260317 Test removing these modules |
| 233 |
#module load PrgEnv-gnu |
| 234 |
#module load cray-hdf5/1.12.2.9 |
| 235 |
#module load cray-netcdf/4.9.0.9 |
| 236 |
if [ -d '/global/common/software/e3sm/anaconda_envs/e3smu_latest_for_nco' ]; then |
| 237 |
E3SMU_ROOT='/global/common/software/e3sm/anaconda_envs/e3smu_latest_for_nco/pm-cpu' |
| 238 |
else |
| 239 |
E3SMU_ROOT='/global/common/software/e3sm/anaconda_envs/base/envs/e3sm_unified_latest' |
| 240 |
fi # !E3SMU-NCO |
| 241 |
if [ -n "${NCARG_ROOT}" ]; then |
| 242 |
export PATH="${PATH}:${NCARG_ROOT}/bin" |
| 243 |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${NCARG_ROOT}/lib" |
| 244 |
fi # !NCARG_ROOT |
| 245 |
export PATH='/global/cfs/cdirs/e3sm/zender/bin_perlmutter:/global/cfs/cdirs/e3sm/zender/anaconda/bin'\:${PATH} |
| 246 |
export LD_LIBRARY_PATH='/global/cfs/cdirs/e3sm/zender/lib_perlmutter:/global/cfs/cdirs/e3sm/zender/anaconda/lib'\:${LD_LIBRARY_PATH} |
| 247 |
fi # !LMOD_SYSTEM_NAME |
| 248 |
;; # !login |
| 249 |
perlmutter* | nid[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789] ) |
| 250 |
# 20221103 Add build environment modules |
| 251 |
# 20260317 Test removing these modules |
| 252 |
#module load PrgEnv-gnu |
| 253 |
#module load cray-hdf5/1.12.2.9 |
| 254 |
#module load cray-netcdf/4.9.0.9 |
| 255 |
if [ -d '/global/common/software/e3sm/anaconda_envs/e3smu_latest_for_nco' ]; then |
| 256 |
E3SMU_ROOT='/global/common/software/e3sm/anaconda_envs/e3smu_latest_for_nco/pm-cpu' |
| 257 |
else |
| 258 |
E3SMU_ROOT='/global/common/software/e3sm/anaconda_envs/base/envs/e3sm_unified_latest' |
| 259 |
fi # !E3SMU-NCO |
| 260 |
if [ -n "${NCARG_ROOT}" ]; then |
| 261 |
export PATH="${PATH}:${NCARG_ROOT}/bin" |
| 262 |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${NCARG_ROOT}/lib" |
| 263 |
fi # !NCARG_ROOT |
| 264 |
export PATH='/global/cfs/cdirs/e3sm/zender/bin_perlmutter:/global/cfs/cdirs/e3sm/zender/anaconda/bin'\:${PATH} |
| 265 |
export LD_LIBRARY_PATH='/global/cfs/cdirs/e3sm/zender/lib_perlmutter:/global/cfs/cdirs/e3sm/zender/anaconda/lib'\:${E3SMU_ROOT}/lib\:${LD_LIBRARY_PATH} ; ;; |
| 266 |
* ) # Default fall-through |
| 267 |
hrd_pth_fnd='No' ; ;; |
| 268 |
esac # !HOSTNAME |
| 269 |
# 20210519: E3SM-U supplies many uncommon executables and libraries, e.g., libantlr, ESMF_RegridWeightGen |
| 270 |
# 20241220: Now that ncclimo also regularly uses ncap2 executable for global timeseries, must modify its path too |
| 271 |
# ncclimo only needs access to E3SM_U libraries (e.g., libgsl, libantlr), already implemented above |
| 272 |
# ncremap needs access to E3SM_U binaries (ESMF_RegridWeightGen, ...) _and_ libraries |
| 273 |
# Append E3SM-U binaries to _end_ of PATH so NCO binaries not redirected, e.g., from CSZ's development directory to E3SM-U |
| 274 |
if [ -n "${E3SMU_ROOT}" ] && [ ${spt_nm} = 'ncremap' ]; then |
| 275 |
export PATH="${PATH}:${E3SMU_ROOT}/bin" |
| 276 |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${E3SMU_ROOT}/lib" |
| 277 |
fi # !E3SMU_ROOT |
| 278 |
fi # !hrd_pth && !NCO_PATH_OVERRIDE |
| 279 |
|
| 280 |
# Test cases (${DATA]/[grids/maps] refers to ~zender/data/[grids/maps] on Charlie's test machines) |
| 281 |
# Debugging: |
| 282 |
# ncremap --dbg=1 --var=FSDS --map=${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc ${DATA}/bm/eamv1_ne30np4l72.nc ~/foo.nc 2>&1 | m |
| 283 |
# ncks -O --dbg=1 --var=FSDS --map=${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco.20190601.nc ${DATA}/bm/eamv1_ne30np4l72.nc ~/foo.nc 2>&1 | m |
| 284 |
# ncks -O --dbg=1 --var=TREFHT --map=${DATA}/maps/map_ne30pg2_to_cmip6_180x360_aave.20200201.nc ${DATA}/bm/eamv2_ne30pg2l72.nc ~/foo.nc 2>&1 | m |
| 285 |
# ncks -O --dbg=1 --var=FSDS --map=${DATA}/maps/map_ne30pg2_to_r05_traave.20240701.nc --nlm=${DATA}/maps/map_ne30pg2_to_r05_trfv2.20240701.nc ${DATA}/bm/eamv3_ne30pg2l80.nc ~/foo.nc 2>&1 | m |
| 286 |
# Map-only, threading: |
| 287 |
# ncremap --dbg=1 --thr_nbr=6 --vrb=3 --devnull=No --nco='--dbg=5' --alg_typ=ncoaave --grd_src=${DATA}/grids/ne30pg2.nc --grd_dst=${DATA}/grids/cmip6_180x360_scrip.20181001.nc --map=${HOME}/map.nc |
| 288 |
# ncks -O --dbg=5 --thr_nbr=6 --grd_src=${DATA}/grids/ne30np4_pentagons.20190501.nc --grd_dst=${DATA}/grids/cmip6_180x360_scrip.20181001.nc --map=${HOME}/map.nc ~/nco/data/in.nc ~/foo.nc |
| 289 |
# ncremap --dbg=1 --vrb=3 --devnull=No --nco='--dbg=1' --alg_typ=ncoidw --xtr_nsp=8 --xtr_xpn=2.0 --grd_src=${DATA}/grids/ne30np4_pentagons.20190501.nc --grd_dst=${DATA}/grids/cmip6_180x360_scrip.20181001.nc --map=${HOME}/map.nc |
| 290 |
# ncremap --dbg=1 --alg_typ=bilin --grd_src=${DATA}/grids/oEC60to30.SCRIP.150729.nc --grd_dst=${DATA}/grids/t62_scrip.20181001.nc --map=${HOME}/map.nc |
| 291 |
# ncremap --dbg=1 --alg_typ=traave --grd_src=${DATA}/grids/oEC60to30.SCRIP.150729.nc --grd_dst=${DATA}/grids/t62_scrip.20181001.nc --map=${HOME}/map.nc |
| 292 |
# ncremap --dbg=1 --alg_typ=traave --grd_src=${DATA}/grids/oEC60to30.SCRIP.150729.nc --tpl=${DATA}/dstmch90/dstmch90_clm.nc --map=${HOME}/map.nc |
| 293 |
# ncremap --dbg=1 --alg_typ=traave --grd_src=${DATA}/grids/128x256_SCRIP.20160301.nc --tpl=${DATA}/dstmch90/dstmch90_clm.nc --map=${HOME}/map.nc |
| 294 |
# Regression: |
| 295 |
# ncremap -P eam -7 -L 1 -m ${DATA}/maps/map_ne30np4_to_cmip6_180x360_aave.20181001.nc ${DATA}/bm/eamv1_ne30np4l72.nc ~/foo_eamv1.nc |
| 296 |
# ncremap -P eam -7 -L 1 -m ${DATA}/maps/map_ne30pg2_to_cmip6_180x360_aave.20200201.nc ${DATA}/bm/eamv2_ne30pg2l72.nc ~/foo_eamv2.nc |
| 297 |
# ncremap -P eam -7 -L 1 -m ${DATA}/maps/map_ne30pg2_to_cmip6_180x360_traave.20231201.nc ${DATA}/bm/eamv3_ne30pg2l80.nc ~/foo_eamv3.nc |
| 298 |
# ncremap -P elm -7 -L 1 -m ${DATA}/maps/map_ne30np4_to_cmip6_180x360_aave.20181001.nc ${DATA}/bm/elmv1_ne30np4l15.nc ~/foo_elmv1.nc |
| 299 |
# ncremap -P elm -7 -L 1 -m ${DATA}/maps/map_ne30pg2_to_cmip6_180x360_aave.20200201.nc ${DATA}/bm/elmv2_ne30pg2l15.nc ~/foo_elmv2.nc |
| 300 |
# ncremap -P elm -7 -L 1 -m ${DATA}/maps/map_r05_to_cmip6_180x360_traave.20240901.nc ${DATA}/bm/elmv3_r05l15.nc ~/foo_elmv3.nc |
| 301 |
# ncremap -P mpasseaice -7 -L 1 -m ${DATA}/maps/map_oEC60to30v3_to_cmip6_180x360_aave.20181001.nc ${DATA}/bm/msiv1_oEC60to30v3.nc ~/foo_msiv1.nc |
| 302 |
# ncremap -P mpasseaice -7 -L 1 -m ${DATA}/maps/map_EC30to60E2r2_to_cmip6_180x360_aave.20220301.nc ${DATA}/bm/msiv2_EC30to60E2r2l5.nc ~/foo_msiv2.nc |
| 303 |
# ncremap -P mpasseaice -7 -L 1 -m ${DATA}/maps/map_IcoswISC30E3r5_to_cmip6_180x360_traave.20231201.nc ${DATA}/bm/msiv3_IcoswISC30E3r5l5.nc ~/foo_msiv3.nc |
| 304 |
# ncremap -P mpasocean -7 -L 1 -m ${DATA}/maps/map_oEC60to30v3_to_cmip6_180x360_aave.20181001.nc ${DATA}/bm/mpov1_oEC60to30v3l60.nc ~/foo_mpov1.nc |
| 305 |
# ncremap -P mpasocean -7 -L 1 -m ${DATA}/maps/map_EC30to60E2r2_to_cmip6_180x360_aave.20220301.nc ${DATA}/bm/mpov2_EC30to60E2r2l60.nc ~/foo_mpov2.nc |
| 306 |
# ncremap -P mpasocean -7 -L 1 -m ${DATA}/maps/map_IcoswISC30E3r5_to_cmip6_180x360_traave.20231201.nc ${DATA}/bm/mpov3_IcoswISC30E3r5l64.nc ~/foo_mpov3.nc |
| 307 |
# ncremap -P eamxx -7 -L 1 -m ${DATA}/maps/map_ne1024pg2_to_fv256x512_mono.20201201.nc ${DATA}/bm/screamv1_ne1024pg2l128.nc ~/foo_eamxx.nc |
| 308 |
# ncremap --ps_nm=lnsp -v asn,t --vrt_out=${DATA}/grids/vrt_hyb_L72.nc ${DATA}/hdf/ecmwf_ifs_f640L137.nc ~/foo.nc |
| 309 |
# Regrid: |
| 310 |
# ls ${DATA}/ne30/raw/*1979*.nc | ncremap -m ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc -O ${DATA}/ne30/rgr |
| 311 |
# ls ${DATA}/ne30/raw/*1979*.nc | ncremap -j 3 -m ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc -O ${DATA}/ne30/rgr # Batch-parallelism |
| 312 |
# ncremap -a esmfaave -v FSNT -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -d ${DATA}/dstmch90/dstmch90_clm.nc -I ${DATA}/ne30/raw -O ${DATA}/ne30/rgr |
| 313 |
# ls ${DATA}/essgcm14/essgcm14*cam*0007*.nc | ncremap -a esmfaave -M -d ${DATA}/dstmch90/dstmch90_clm.nc -O ${DATA}/ne30/rgr |
| 314 |
# ncremap -a esmfaave -v FSNT -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -d ${DATA}/dstmch90/dstmch90_clm.nc -I ${DATA}/ne30/raw -O ${DATA}/ne30/rgr |
| 315 |
# ncremap -P airs -v TSurfAir -g ${DATA}/grids/180x360_SCRIP.20150901.nc ${DATA}/hdf/AIRS.2014.10.01.202.L2.RetStd.v6.0.11.0.G14275134307.hdf ~/airs_out.nc |
| 316 |
# ncremap -v CloudFrc_A -g ${DATA}/grids/180x360_SCRIP.20150901.nc ${DATA}/hdf/AIRS.2002.08.01.L3.RetStd_H031.v4.0.21.0.G06104133732.hdf ~/foo.nc |
| 317 |
# ncremap -g ${DATA}/grids/180x360_SCRIP.20150901.nc ${DATA}/hdf/MOD04_L2.A2000055.0005.006.2014307165927.hdf ~/foo.nc |
| 318 |
# ncremap -g ${DATA}/grids/180x360_SCRIP.20150901.nc ${DATA}/hdf/OMI-Aura_L2-OMIAuraSO2_2012m1222-o44888_v01-00-2014m0107t114720.h5 ~/foo.nc |
| 319 |
# ncremap -v T -g ${DATA}/grids/180x360_SCRIP.20150901.nc ${DATA}/hdf/wrfout_v2_Lambert_notime.nc ~/foo.nc |
| 320 |
# ncremap -v StepTwoO3 -d ${DATA}/hdf/cam_time.nc ${DATA}/hdf/OMI-Aura_L2-OMTO3_2015m0731t0034-o58727_v003-2015m0731t080836.he5.nc ~/foo.nc |
| 321 |
# ncremap -v TSurfStd -G "--rgr grd_ttl='Default internally-generated grid' --rgr grid=${HOME}/rgr/ncremap_tmp_grd_dst.nc --rgr latlon=100,100 --rgr snwe=30.0,70.0,-130.0,-90.0" ${DATA}/sld/raw/AIRS.2014.10.01.202.L2.TSurfStd.Regrid010.1DLatLon.hole.nc ~/foo.nc |
| 322 |
# ncremap -x TSurfStd_ct -g ${DATA}/grids/180x360_SCRIP.20150901.nc ${DATA}/sld/raw/AIRS.2014.10.01.202.L2.TSurfStd.Regrid010.1DLatLon.hole.nc ~/foo.nc |
| 323 |
# CESM & E3SM: |
| 324 |
# ncremap -s ${DATA}/grids/ne120np4_pentagons.100310.nc -g ${DATA}/grids/180x360_SCRIP.20150901.nc ${DATA}/ne120/raw/b1850c5_m2a.cam.h0.0060-01.nc ~/foo.nc |
| 325 |
# Old MPAS filename conventions (until ~201609):: |
| 326 |
# ncremap -P mpas -m ${DATA}/maps/map_oEC60to30_to_t62_bilin.20160301.nc ${DATA}/hdf/hist.ocn.0003-12-01_00.00.00.nc ~/foo.nc |
| 327 |
# ncremap -P mpas -m ${DATA}/maps/map_mpas120_TO_T62_aave.121116.nc ${DATA}/hdf/hist.ice.0003-12-01_00.00.00.nc ~/foo.nc |
| 328 |
# New MPAS filename conventions (as of ~201612): |
| 329 |
# ncremap -P mpas -m ${DATA}/maps/map_oEC60to30_to_t62_bilin.20160301.nc ${DATA}/hdf/mpaso.hist.am.timeSeriesStatsMonthly.0001-01-01.nc ~/foo.nc |
| 330 |
# ncremap -P mpas -m ${DATA}/maps/map_oEC60to30_to_t62_bilin.20160301.nc ${DATA}/hdf/mpascice.hist.am.timeSeriesStatsMonthly.0251-01-01.nc ~/foo.nc |
| 331 |
# ncremap -P mpas --mss_val=-1.0e36 -s ${DATA}/grids/ais20km.150910.SCRIP.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/hdf/ais20km.20180117.nc ~/foo.nc |
| 332 |
# ncremap -P mpas --mss_val=-1.0e36 -s ${DATA}/grids/ais20km.150910.SCRIP.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/hdf/mpasLIoutput.nc ~/foo.nc |
| 333 |
# ncremap -P mali -m ${DATA}/maps/map_mali_gis_to_greenland_r025_105x401_aave.20210301.nc ${DATA}/mpas/raw/mali.hist.0001-01-01_00000.nc ~/foo.nc |
| 334 |
# E3SM benchmarks: |
| 335 |
# ncremap -v FSNT,AODVIS -m ${DATA}/maps/map_ne30np4_to_fv129x256_nco.20190601.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 336 |
# ncremap -v FSNT,AODVIS -m ${DATA}/maps/map_ne30np4_to_cmip6_180x360_nco_idw.20200901.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 337 |
# ncremap -v FSNT,AODVIS -m ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 338 |
# ncremap -v FSNT,AODVIS -m ${DATA}/maps/map_ne30np4_to_fv129x256_mono.20190401.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 339 |
# ncremap -v FSNT,AODVIS -m ${DATA}/maps/map_ne30np4_to_fv129x256_highorder.20190401.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 340 |
# ncremap -v FSNT,AODVIS -m ${DATA}/maps/map_ne30np4_to_fv129x256_intbilin.20190401.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 341 |
# ncremap -v FSNT,AODVIS -a esmfaave -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 342 |
# ncremap -v FSNT,AODVIS -a conserve2nd -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 343 |
# ncremap -v FSNT,AODVIS --rnr=0.99 --esmf_mth=idavg -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 344 |
# ncremap -v FSNT,AODVIS -a ncoaave -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 345 |
# ncremap -v FSNT,AODVIS -a trintbilin -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 346 |
# OpenMP: |
| 347 |
# ncremap --dbg=1 --thr_nbr=8 --vrb=3 --devnull=No --nco='--dbg=0' --map=${DATA}/maps/map_ne30pg2_to_r05_traave.20240701.nc ${DATA}/bm/eamv3_ne30pg2l80.nc ~/foo.nc # Horizontal |
| 348 |
# ncremap --dbg=1 --thr_nbr=8 --vrb=3 --devnull=No --nco='--dbg=0' --vrt_xtr=mss_val --vrt_out=${DATA}/grids/vrt_hyb_L72.nc ${DATA}/bm/eamv3_ne30pg2l80.nc ~/foo.nc # Vertical |
| 349 |
# ncremap --dbg=1 --thr_nbr=8 --vrb=3 --devnull=No --nco='--dbg=5' --ps_nm=lnsp --vrt_out=${DATA}/grids/vrt_hyb_L72.nc ${DATA}/hdf/ecmwf_ifs_f640L137.nc ~/foo.nc |
| 350 |
# Positional arguments: |
| 351 |
# ncremap --var=FSNT,AODVIS --map=${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc --drc_out=${DATA}/ne30/rgr ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-??.nc |
| 352 |
# Omit cell_measures: |
| 353 |
# ncremap --no_cll_msr --var=FSNT,AODVIS -i ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc -m ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc -o ~/foo.nc |
| 354 |
# SGS (201909): |
| 355 |
# ncremap --sgs_frc=${DATA}/grids/elm_landfrac_ne30np4.nc/landfrac -m ${DATA}/maps/map_ne30np4_to_cmip6_180x360_aave.20181001.nc ${DATA}/bm/elmv1_ne30np4l15.nc ~/foo.nc # External sgs_frc |
| 356 |
# ncremap --vrb=3 --sgs_frc=landfrac --var=area,FSDS,landfrac,landmask,TBOT -m ${DATA}/maps/map_ne30np4_to_fv129x256_aave.20150901.nc ${DATA}/bm/elmv1_ne30np4l15.nc ~/elm_sgs.nc # 20190918 1D->2D works |
| 357 |
# ncremap --vrb=3 --sgs_frc=landfrac --var=area,FSDS,landfrac,landmask,TBOT -m ${DATA}/maps/map_t42_to_fv129x256_aave.20150901.nc ${DATA}/essgcm14/essgcm14.clm2.h0.0000-01.nc ~/t42_rgr.nc # 20190918 2D->2D |
| 358 |
# ncremap --vrb=3 -p serial --sgs_frc=landfrac -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc -O ${DATA}/ne30/rgr ${DATA}/ne30/raw/F_acmev03_enso_camse_clm45bgc_ne30_co2cycle.clm2.h0.2000-??.nc > ~/ncremap.out 2>&1 & |
| 359 |
# ncremap --vrb=3 -a esmfaave --sgs_frc=aice --sgs_msk=tmask --sgs_nrm=100 --var=hi,uvel,aice,aisnap,albsno,blkmask,evap,evap_ai,fswabs,fswabs_ai,fswdn,fswthru,fswthru_ai,ice_present,snow,snow_ai,tarea,tmask,uarea -s ${DATA}/grids/gx1v7_151008.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/hdf/ctl_brcp85c5cn_deg1.enm.cice.h.2050-07.nc ~/foo.nc # 20170525 normalization required to get mask right |
| 360 |
# ncremap --vrb=3 -a esmfaave -P cice --var=hi,uvel,aice,aisnap,albsno,blkmask,evap,evap_ai,fswabs,fswabs_ai,fswdn,fswthru,fswthru_ai,ice_present,snow,snow_ai,tarea,tmask,uarea -s ${DATA}/grids/gx1v7_151008.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/hdf/ctl_brcp85c5cn_deg1.enm.cice.h.2050-07.nc ~/foo.nc # 20170525 cice short-cut |
| 361 |
# CICE/CESM on POP grid: full grid inferral (and thus conservative remapping) fails because masked vertices/cells missing, must use bilinear or supply grid-file for conservative |
| 362 |
# ncremap -a bilinear -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/hdf/ctl_brcp85c5cn_deg1.enm.cice.h.2050-07.nc ~/foo.nc # 20170515: grid centers/bounds in non-masked regions suffice for bilinear interpolation |
| 363 |
# ncremap -a esmfaave -s ${DATA}/grids/gx1v7_151008.nc -g ${DATA}/grids/129x256_SCRIP.20150901.nc ${DATA}/hdf/ctl_brcp85c5cn_deg1.enm.cice.h.2050-07.nc ~/foo.nc # 20170521: conservative requires supplied tri-pole grid for centers/bounds in masked regions |
| 364 |
# File-format |
| 365 |
# ncremap -v FSNT,AODVIS -s ${DATA}/grids/ne30np4_pentagons.20190501.nc -d ${DATA}/dstmch90/dstmch90_clm.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo.nc |
| 366 |
# TempestRemap boutique: |
| 367 |
# GenerateCSMesh --alt --res 30 --file ${DATA}/grids/ne30.g (really should be ne30np4.g) |
| 368 |
# ncremap --dbg=1 -a se2fv_flx --src_grd=${DATA}/grids/ne30.g --dst_grd=${DATA}/grids/129x256_SCRIP.20150901.nc -m ~/map_ne30np4_to_fv129x256_mono.20180301.nc |
| 369 |
# ncremap --dbg=1 -m ~/map_ne30np4_to_fv129x256_mono.20180301.nc ${DATA}/bm/20180129.DECKv1b_piControl.ne30_oEC.edison.cam.h0.0001-01.nc ~/foo_fv129x256.nc |
| 370 |
# ncremap --dbg=1 -a fv2se_stt --src_grd=${DATA}/grids/129x256_SCRIP.20150901.nc --dst_grd=${DATA}/grids/ne30.g -m ~/map_fv129x256_to_ne30np4_highorder.20180301.nc |
| 371 |
# ncremap --dbg=1 -a fv2se_flx --src_grd=${DATA}/grids/129x256_SCRIP.20150901.nc --dst_grd=${DATA}/grids/ne30.g -m ~/map_fv129x256_to_ne30np4_monotr.20180301.nc |
| 372 |
# ncremap --dbg=1 -m ~/map_fv129x256_to_ne30np4_highorder.20180301.nc ~/foo_fv129x256.nc ~/foo_ne30.nc |
| 373 |
# Atmosphere->Ocean: |
| 374 |
# ncremap --dbg=1 --a2o -a se2fv_flx --src_grd=${DATA}/grids/ne30.g --dst_grd=${DATA}/grids/129x256_SCRIP.20150901.nc -m ~/map_ne30np4_to_fv129x256_mono.20180301.nc |
| 375 |
# Atmosphere->Atmosphere: |
| 376 |
# ncremap --dbg=1 -a se2se --src_grd=${DATA}/grids/ne30.g --dst_grd=${DATA}/grids/ne30.g -m ~/map_ne30np4_to_ne30np4_se2se.20190301.nc |
| 377 |
# RRG (201807): |
| 378 |
# ncremap -D 1 -a esmfaave --rnm_sng='_128e_to_134e_9s_to_16s' --bb_wesn='128.0,134.0,-16.0,-9.0' --dat_glb=${HOME}/dat_glb.nc --grd_glb=${HOME}/grd_glb.nc --grd_rgn=${HOME}/grd_rgn.nc ~/dat_rgn.nc ~/foo.nc > ~/ncremap.out 2>&1 & |
| 379 |
# ncremap -D 0 --vrb=1 -a esmfaave --rnm_sng='_128e_to_134e_9s_to_16s' --bb_wesn='128.0,134.0,-16.0,-9.0' --dat_glb=${HOME}/dat_glb.nc --grd_glb=${HOME}/grd_glb.nc --grd_dst=${HOME}/grd_rgn.nc --grd_src=${HOME}/grd_src.nc --map=${HOME}/map.nc ~/dat_rgn.nc ~/foo.nc |
| 380 |
# ncremap -D 0 --vrb=1 -a esmfaave --dat_glb=${HOME}/dat_glb.nc --grd_glb=${HOME}/grd_glb.nc --grd_dst=${HOME}/grd_rgn.nc --grd_src=${HOME}/grd_src.nc --map=${HOME}/map.nc ~/dat_rgn.nc ~/foo.nc |
| 381 |
# ncremap -D 0 --vrb=1 -a esmfaave --dat_glb=${HOME}/dat_glb.nc --grd_glb=${HOME}/grd_glb.nc -g ${HOME}/grd_rgn.nc ~/dat_rgn.nc ~/foo.nc |
| 382 |
# MWF (202401): |
| 383 |
# ncremap -D 1 -P mwf -s ${DATA}/grids/ocean.QU.240km.scrip.181106.nc -g ${DATA}/grids/ne11np4.g --nm_src=QU240 --nm_dst=ne11np4 --dt_sng=20240201 --drc_out=$TMPDIR > ~/ncremap.out 2>&1 & |
| 384 |
# ncremap -D 2 -P mwf --grd_src=${DATA}/grids/ocean.IcoswISC30E3r5.mask.scrip.20231120.nc --grd_dst=${DATA}/grids/ne30pg2.g --nm_src=IcoswISC30E3r5 --nm_dst=ne30pg2 --dt_sng=20240201 --drc_out=$TMPDIR > ~/ncremap.out 2>&1 & |
| 385 |
# ncremap -D 2 -P mwf --alg_lst='traave,trbilin,trfv2' --grd_src=${DATA}/grids/ocean.IcoswISC30E3r5.mask.scrip.20231120.nc --grd_dst=${DATA}/grids/ne30pg2.g --nm_src=IcoswISC30E3r5 --nm_dst=ne30pg2 --dt_sng=20240201 --drc_out=$TMPDIR > ~/ncremap.out 2>&1 & |
| 386 |
# ncremap -D 2 -P mwf --grd_src=${DATA}/grids/ocean.IcoswISC30E3r5.mask.scrip.20231120.nc --grd_dst=${DATA}/grids/cmip6_180x360_scrip.nc --nm_src=IcoswISC30E3r5 --nm_dst=cmip6_180x360 --dt_sng=20240201 --drc_out=$TMPDIR > ~/ncremap.out 2>&1 & |
| 387 |
# ncremap -D 2 -P mwf --grd_src=${DATA}/grids/ocean.IcoswISC30E3r5.mask.scrip.20231120.nc --grd_dst=${DATA}/grids/cmip6_180x360.g --nm_src=IcoswISC30E3r5 --nm_dst=cmip6_180x360 --dt_sng=20240201 --drc_out=$TMPDIR > ~/ncremap.out 2>&1 & |
| 388 |
# ncremap -D 2 -P mwf --grd_src=${DATA}/grids/ne30pg2.g --grd_dst=${DATA}/grids/cmip6_180x360.g --nm_src=ne30pg2 --nm_dst=cmip6_180x360 --dt_sng=20240201 --drc_out=${DATA}/maps > ~/ncremap.out 2>&1 & |
| 389 |
# ncremap -D 2 -P mwf --wgt_cmd='mpirun -np 12 ESMF_RegridWeightGen' --grd_src=${DATA}/grids/ocean.IcoswISC30E3r5.mask.scrip.20231120.nc --grd_dst=${DATA}/grids/cmip6_180x360.nc --nm_src=IcoswISC30E3r5 --nm_dst=cmip6_180x360 --dt_sng=20240201 --drc_out=$TMPDIR > ~/ncremap.out 2>&1 & |
| 390 |
# Add depth (201901): |
| 391 |
# ncremap -P mpas --dpt_fl=${DATA}/grids/mpas_refBottomDepth_L60.nc -m ${DATA}/maps/map_oEC60to30v3_to_cmip6_180x360_aave.20181001.nc ${DATA}/hdf/mpaso.lrz.hist.am.timeSeriesStatsMonthly.0001-12-01.nc ~/foo.nc |
| 392 |
# Vertical interpolation (201903): |
| 393 |
# ncremap -v lat,lon,FSNT,AODVIS,T,Q,U,V,Z3 --vrt_out=${DATA}/grids/vrt_hyb_ne30np4l72_ps.nc ${DATA}/bm/eamv1_ne30np4l72.nc ~/foo.nc # PS in "fat" template file |
| 394 |
# ncremap -v lat,lon,FSNT,AODVIS,T,Q,U,V,Z3 --vrt_out=${DATA}/grids/vrt_hyb_L72.nc ${DATA}/bm/eamv2_ne30pg2l72.nc ~/foo.nc # skinny template file |
| 395 |
# Missing-value extrapolation (mss_val|nrs_ngh) |
| 396 |
# ncremap -v lat,lon,FSNT,AODVIS,T,Q,U,V,Z3 --vrt_xtr=mss_val --vrt_out=${DATA}/grids/vrt_hyb_L72.nc ${DATA}/bm/eamv2_ne30pg2l72.nc ~/foo.nc |
| 397 |
# ncremap -v lat,lon,FSNT,AODVIS,T,Q,U,V,Z3 --vrt_xtr=mss_val --vrt_out=${DATA}/grids/vrt_prs_ncep_L19.nc ${DATA}/bm/eamv2_ne30pg2l72.nc ~/foo.nc |
| 398 |
# Pressure->Pressure |
| 399 |
# ncremap -v lat,lon,FSNT,AODVIS,T,Q,U,V,Z3 --vrt_xtr=mss_val --vrt_out=${DATA}/grids/vrt_prs_ncep_L19.nc ${DATA}/bm/eamv2_ne30pg2l72.nc ~/foo_L19.nc |
| 400 |
# ncremap --vrt_xtr=mss_val --vrt_out=${DATA}/grids/vrt_prs_L3.nc ~/foo_L19.nc ~/foo.nc |
| 401 |
# Simultaneous horizontal/vertical regridding L72->L30 |
| 402 |
# ncremap -v lat,lon,FSNT,AODVIS,T,Q,U,V,Z3 --map=${DATA}/maps/map_ne30pg2_to_cmip6_180x360_aave.20200201.nc --vrt_out=${DATA}/grids/vrt_hyb_L30.nc ${DATA}/bm/eamv2_ne30pg2l72.nc ~/foo.nc |
| 403 |
# ncremap -P mpasocean -v timeMonthly_avg_activeTracers_temperature,timeMonthly_avg_zMid --map=${DATA}/maps/map_EC30to60E2r2_to_cmip6_180x360_nco.20220301.nc --vrt_out=${DATA}/grids/vrt_dpt_L10.nc ${DATA}/bm/mpov2_EC30to60E2r2l60.nc ~/foo.nc # borken 20230222 since vrt_ntp (correctly) does not propagate timeMonthly_avg_zMid, yet horizontal regridder expects it |
| 404 |
# ncremap -P mpasocean --map=${DATA}/maps/map_EC30to60E2r2_to_r025_nco.20230101.nc --vrt_out=${DATA}/hdf/woa18_ANN_T_S_z_vol_20200514.nc ${DATA}/bm/mpov2_EC30to60E2r2l60.nc ~/foo.nc |
| 405 |
# SCREAM external surface pressure and input vertical grid (202211): |
| 406 |
# ncremap -v T_mid --ps_nm=${DATA}/bm/screamv1_ne1024pg2l128_QrPsPsl.nc/ps --vrt_in=${DATA}/grids/vrt_hyb_L128.nc --vrt_out=${DATA}/grids/vrt_prs_ncep_L17.nc ${DATA}/bm/screamv1_ne1024pg2l128_QvT.nc ~/foo.nc |
| 407 |
# ncremap -6 -P eamxx --map=${DATA}/maps/map_ne1024pg2_to_fv256x512_mono.20201201.nc ${DATA}/bm/screamv1_ne1024pg2l128.nc ~/foo.nc # Panoply breaks on CDF5 input |
| 408 |
# Interpolate time-varying hybrid input |
| 409 |
# ncremap -v FSNT,AODVIS,T,Q,U,V,Z3 --map=${DATA}/maps/map_ne30pg2_to_cmip6_180x360_aave.20200201.nc --drc_out=${DATA}/ne30/rgr ${DATA}/ne30/raw/v2.LR.historical_0101.eam.h0.2013-0[123].nc |
| 410 |
# ncrcat -O -v FSNT,AODVIS,T,Q,U,V,Z3 ${DATA}/ne30/rgr/v2.LR.historical_0101.eam.h0.2013-0[12].nc ${DATA}/ne30/rgr/v2.LR.historical_0101.eam.h0.201301_201302.nc |
| 411 |
# ncremap --dbg=3 -v FSNT,AODVIS,T,Q,U,V,Z3 --vrt_out=${DATA}/grids/vrt_prs_ncep_L17.nc ${DATA}/ne30/rgr/v2.LR.historical_0101.eam.h0.201301_201302.nc ~/foo.nc |
| 412 |
# MOAB |
| 413 |
# ncremap --mpi_nbr=8 -v FSNT,AODVIS --dbg=1 --vrb=3 --devnull=No --alg_typ=traave --grd_src=${DATA}/grids/ne30pg2.nc --grd_dst=${DATA}/grids/cmip6_180x360_scrip.20181001.nc --map=${HOME}/map.nc ${DATA}/bm/eamv2_ne30pg2l72.nc ~/foo.nc |
| 414 |
# CDO |
| 415 |
# cdo verifygrid grid_CMN-5x5.nc |
| 416 |
# ncremap --dbg=1 --vrb=3 --devnull=No --alg_typ=cdo_bil --in_fl=${DATA}/grids/t42_skl.nc --dst_fl=${DATA}/ne30/rgr/hfc_ANN_200001_200012_climo.nc --map=${DATA}/maps/map_t42_to_cmip6_180x360_cdo.20210701.nc |
| 417 |
# add_fll |
| 418 |
# ncremap --dbg=1 --thr_nbr=6 --vrb=3 --devnull=No --nco='--dbg=1' --add_fll --map=${DATA}/maps/map_racmo_566x438_icemask_to_greenland_r025_100x250_nco.20210701.nc ${HOME}/racmo.smb.nofill.nc ~/foo_nco.nofill.nc |
| 419 |
# msk_apl |
| 420 |
# ncremap --dbg=1 --thr_nbr=6 --vrb=3 --devnull=No --nco='--dbg=1' --msk_apl --map=${DATA}/maps/map_racmo_566x438_icemask_to_greenland_r025_100x250_nco.20210701.nc ${HOME}/racmo.smb.nofill.nc ~/foo_nco.nofill.nc |
| 421 |
|
| 422 |
# dbg_lvl: 0 = Quiet, print basic status during evaluation |
| 423 |
# 1 = Print configuration, full commands, and status to output during evaluation |
| 424 |
# 2 = As in dbg_lvl=1, but DO NOT EXECUTE COMMANDS (i.e., pretend to run but do not regrid anything) |
| 425 |
# 3 = As in dbg_lvl=1, and pass debug level through to NCO/ncks |
| 426 |
|
| 427 |
# 20220131 ncclimo/ncremap commands within scripts that open E3SMU environment |
| 428 |
# (e.g., zppy-generated scripts) must be told where to find NCO binaries. |
| 429 |
# Only necessary on login nodes since Spack handles this fine on compute nodes |
| 430 |
if [ "${E3SMU_MPI}" = 'NOMPI' ] && [ -n "${E3SMU_SCRIPT}" ] && [ -n "${CONDA_PREFIX}" ]; then |
| 431 |
export PATH="${CONDA_PREFIX}/bin"\:${PATH} |
| 432 |
fi # !E3SMU_MPI |
| 433 |
# Set NCO version and directory |
| 434 |
nco_exe=`which ncks` |
| 435 |
if [ -z "${nco_exe}" ]; then |
| 436 |
echo "ERROR: Unable to find NCO, nco_exe = ${nco_exe}" |
| 437 |
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)" |
| 438 |
exit 1 |
| 439 |
fi # !nco_exe |
| 440 |
# StackOverflow method finds NCO directory |
| 441 |
while [ -h "${nco_exe}" ]; do |
| 442 |
drc_nco="$( cd -P "$( dirname "${nco_exe}" )" && pwd )" |
| 443 |
nco_exe="$(readlink "${nco_exe}")" |
| 444 |
[[ ${nco_exe} != /* ]] && nco_exe="${drc_nco}/${nco_exe}" |
| 445 |
done |
| 446 |
drc_nco="$( cd -P "$( dirname "${nco_exe}" )" && pwd )" |
| 447 |
nco_vrs=$(ncks --version 2>&1 > /dev/null | grep NCO | awk '{print $5}') |
| 448 |
# 20190218: Die quickly when NCO is found yet cannot run, e.g., due to linker errors |
| 449 |
if [ -z "${nco_vrs}" ]; then |
| 450 |
echo "${spt_nm}: ERROR ${nco_exe} dies with error message on next line:" |
| 451 |
$(ncks --version) |
| 452 |
# 20250905: Additional information for debugging link issues |
| 453 |
if [ "${NCO_PATH_OVERRIDE}" = 'Yes' ]; then |
| 454 |
echo "${spt_nm}: DEBUG Next line shows contents of \$LD_LIBRARY_PATH:" |
| 455 |
echo "${LD_LIBRARY_PATH}" |
| 456 |
echo "${spt_nm}: DEBUG Next line shows contents of \$PATH:" |
| 457 |
echo "${PATH}" |
| 458 |
else # !NCO_PATH_OVERRIDE |
| 459 |
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" |
| 460 |
fi # !NCO_PATH_OVERRIDE |
| 461 |
exit 1 |
| 462 |
fi # !nco_vrs |
| 463 |
nco_sng=$(ncks --version 2>&1 > /dev/null | grep NCO | awk -F '"' '{print $2}') |
| 464 |
lbr_vrs=$(ncks --library 2>&1 > /dev/null | awk '{print $6}') |
| 465 |
|
| 466 |
# Detect and warn about mixed modules (for Qi Tang 20170531) |
| 467 |
if [ "${drc_spt}" != "${drc_nco}" ]; then |
| 468 |
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 the script and 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." |
| 469 |
echo "HINT: 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." |
| 470 |
fi # drc_spt |
| 471 |
|
| 472 |
# When running in a terminal window (not in an non-interactive batch queue)... |
| 473 |
if [ -n "${TERM}" ]; then |
| 474 |
# Set fonts for legibility |
| 475 |
if [ -x /usr/bin/tput ] && tput setaf 1 &> /dev/null; then |
| 476 |
fnt_bld=`tput bold` # Bold |
| 477 |
fnt_nrm=`tput sgr0` # Normal |
| 478 |
fnt_rvr=`tput smso` # Reverse |
| 479 |
fnt_tlc=`tput sitm` # Italic |
| 480 |
else |
| 481 |
fnt_bld="\e[1m" # Bold |
| 482 |
fnt_nrm="\e[0m" # Normal |
| 483 |
fnt_rvr="\e[07m" # Reverse |
| 484 |
fnt_tlc="\e[3m" # Italic |
| 485 |
fi # !tput |
| 486 |
fi # !TERM |
| 487 |
|
| 488 |
# Pre-define enumerated types used in defaults |
| 489 |
par_bck='background' # [sng] Parallelism: background |
| 490 |
par_mpi='mpi' # [sng] Parallelism: MPI |
| 491 |
par_srl='serial' # [sng] Parallelism: serial |
| 492 |
vrb_0=0 # [enm] Verbosity level: Quiet |
| 493 |
vrb_1=1 # [enm] Verbosity level: Standard, minimal file I/O |
| 494 |
vrb_2=2 # [enm] Verbosity level: All file I/O |
| 495 |
vrb_3=3 # [enm] Verbosity level: English |
| 496 |
vrb_4=4 # [enm] Verbosity level: Pedantic |
| 497 |
fmt_sng_nc3='CLASSIC (netCDF3 classic CDF1)' |
| 498 |
fmt_sng_nc4='NETCDF4 (netCDF4 extended HDF5)' |
| 499 |
fmt_sng_nc5='64BIT_DATA (netCDF3/pnetCDF CDF5)' |
| 500 |
fmt_sng_nc6='64BIT_OFFSET (netCDF3 64bit CDF2)' |
| 501 |
fmt_sng_nc7='NETCDF4_CLASSIC (netCDF4 classic HDF5)' |
| 502 |
|
| 503 |
# Defaults for command-line options and some derived variables |
| 504 |
# Modify these defaults to save typing later |
| 505 |
a2o_flg='No' # [flg] Atmosphere-to-ocean (only used by Tempest mesh generator) |
| 506 |
add_fll='No' # [flg] Add _FillValue to fields with empty destination cells |
| 507 |
alg_lst='esmfaave,esmfbilin,ncoaave,ncoidw,traave,trbilin,trfv2,trintbilin' # [sng] Algorithm list for MWF mode |
| 508 |
alg_typ='ncoaave' # [sng] Algorithm for remapping (esmfaave|esmfbilin|bilinear|conserve|conserve2nd|nearestdtos|neareststod|patch|traave|trbilin|trfv2|trintbilin|se2fv_flx|se2fv_stt|se2fv_alt|se2se|fv2se_flx|fv2se_stt|fv2se_alt|fv2fv_flx|fv2fv_stt|ncoaave|nco_con|ncoidw|ncoidw) |
| 509 |
att_flg='No' # [flg] Add/alter attributes (e.g., _FillValue) before regridding |
| 510 |
bch_pbs='No' # [sng] PBS batch (non-interactive) job |
| 511 |
bch_slr='No' # [sng] SLURM batch (non-interactive) job |
| 512 |
bfr_sz=33554432 # [B] Buffer size for netCDF-classic I/O (ignored and harmless for netCDF4) |
| 513 |
chk_map='Yes' # [flg] Check map-file quality |
| 514 |
cln_flg='Yes' # [flg] Clean-up (remove) intermediate files before exiting |
| 515 |
clm_flg='No' # [flg] Assume MPAS attributes have already been fiddled with (e.g., ncremap was invoked by ncclimo in climo mode) |
| 516 |
cmp_sng='' # [sng] Compression string |
| 517 |
cnv_exe_mbt='mbconvert' # [sng] MOAB-Tempest SCRIP/Exodus conversion to H5M executable |
| 518 |
cnv_exe_hnt="${spt_nm}: HINT ${cnv_exe_mbt} can fail for a number of reasons including 1) SCRIP and standard Exodus grid-files are read in parallel, but only if they are in netCDF3 file format. The parallel reader will fail with netCDF4 input grids. This can be worked-around in two ways. First, you could rename the grid file to end with a .g suffix, spoofing a TempestRemap Exodus file. Then ncremap will invoke the serial (not parallel) grid reader. Second, you could convert the input grid from netCDF4 to netCDF3 using, e.g., ncks -5 in.nc out.nc. 2) ncremap invokes mbconvert in parallel (i.e., with srun or mpirun) unless the grid name ends in \".g\". Be sure you are on a node with access to working srun or mpi_run commands. 3) mbconvert must support the -B option for TempestRemap Exodus grids. Older versions of mbconvert do not. 4) mbconvert must support the PARALLEL option. Serial versions of mbconvert do not.\n${spt_nm}: HINT a simple way to install a MOAB compatible with ncremap is install them both into their own environment, e.g., \n\tconda create -n moab_nco -c conda-forge moab=5.6.0=*mpich_tempest* nco\n" |
| 519 |
#cnv_exe_tps='ConvertSCRIPToExodus' # Command was deprecated in 2022 |
| 520 |
cnv_exe_tps='ConvertMeshToExodus' # [sng] TempestRemap SCRIP and Mesh-to-Exodus conversion executable |
| 521 |
cnv_opt_srl_e2m='-B' # [sng] Recommended options to serial mbconvert for (high-resolution, Tempest-compatible *.g files) Exodus to MOAB grids |
| 522 |
cnv_opt_prl_n2m='-o PARALLEL=WRITE_PART -O PARALLEL=BCAST_DELETE -O PARTITION=TRIVIAL -O PARALLEL_RESOLVE_SHARED_ENTS' # [sng] Recommended options to mbconvert for parallel conversion of (high-resolution) SCRIP to MOAB grids https://acme-climate.atlassian.net/wiki/spaces/ED/pages/932380820/Offline+remapping+workflow+with+mbtempest |
| 523 |
col_dmn='' # [sng] Name of unstructured (column) dimension (for coupler files) |
| 524 |
d2f_flg='No' # [flg] Convert double-precision fields to single-precision |
| 525 |
d2f_opt='-M dbl_flt' # [sng] Option string to convert double-precision fields to single-precision |
| 526 |
dbg_lvl=0 # [nbr] Debugging level |
| 527 |
dfl_lvl='' # [enm] Deflate level |
| 528 |
dpt_exe_mpas='add_depth.py' # [sng] Depth coordinate addition command for MPAS |
| 529 |
dpt_flg='No' # [flg] Add depth coordinate to MPAS files |
| 530 |
dpt_fl='' # [sng] Depth file with refBottomDepth for MPAS ocean |
| 531 |
dpt_nm='' # [sng] Name of variable containing 3D depth/height in input file |
| 532 |
#drc_in="${drc_pwd}" # [sng] Input file directory |
| 533 |
drc_in='' # [sng] Input file directory |
| 534 |
drc_in_xmp='~/drc_in' # [sng] Input file directory for examples |
| 535 |
drc_out="${drc_pwd}" # [sng] Output file directory |
| 536 |
drc_out_xmp="~/rgr" # [sng] Output file directory for examples |
| 537 |
dst_fl='' # [sng] Destination file |
| 538 |
dst_xmp='dst.nc' # [sng] Destination file for examples |
| 539 |
dt_sng=`date +%Y%m%d` # [sng] Date string for MWF map names |
| 540 |
dvn_flg='Yes' # [flg] Send internal NCO regridder output to /dev/null |
| 541 |
esmf_typ='' # [sng] ESMF extrapolation type (nearestidavg|neareststod|none) |
| 542 |
fl_fmt='' # [enm] Output file format |
| 543 |
fl_nbr=0 # [nbr] Number of files to remap |
| 544 |
flg_grd_only='No' # [flg] Create grid then exit before regridding |
| 545 |
flg_hrz='No' # [flg] Perform horizontal regridding |
| 546 |
# 20200119 appending attribute containing remap_command causes ncatted to fail, temporarily remove it |
| 547 |
#gaa_sng="--gaa remap_script=${spt_nm} --gaa remap_command=\"'${cmd_ln}'\" --gaa remap_hostname=${HOSTNAME} --gaa remap_version=${nco_vrs}" # [sng] Global attributes to add |
| 548 |
gaa_sng="--gaa remap_script=${spt_nm} --gaa remap_hostname=${HOSTNAME} --gaa remap_version=${nco_vrs}" # [sng] Global attributes to add |
| 549 |
gad_sng='' # [sng] Global attributes to delete |
| 550 |
grd_dst='' # [sng] Destination grid-file |
| 551 |
grd_dst_xmp='grd_dst.nc' # [sng] Destination grid-file for examples |
| 552 |
grd_sng='' # [sng] Grid string |
| 553 |
grd_src='' # [sng] Source grid-file |
| 554 |
grd_src_xmp='grd_src.nc' # [sng] Source grid-file for examples |
| 555 |
grd_vrt_xmp='grd_vrt.nc' # [sng] Vertical grid-file for examples |
| 556 |
hdr_pad='10000' # [B] Pad at end of header section |
| 557 |
hnt_dst='' # [sng] ERWG hint for destination grid |
| 558 |
hnt_src='' # [sng] ERWG hint for source grid |
| 559 |
in_fl='' # [sng] Input file |
| 560 |
in_xmp='in.nc' # [sng] Input file for examples |
| 561 |
inp_aut='No' # [sng] Input file list automatically generated (in ncclimo, or specified with -i in ncremap) |
| 562 |
inp_glb='No' # [sng] Input file list from globbing directory |
| 563 |
inp_psn='No' # [sng] Input file list from positional arguments |
| 564 |
inp_std='No' # [sng] Input file list from stdin |
| 565 |
job_nbr=2 # [nbr] Job simultaneity for parallelism |
| 566 |
map_fl='' # [sng] Map-file |
| 567 |
map_nfo_sng='' # [sng] Informational string about map-file |
| 568 |
map_rsl_fl='' # [sng] File containing results of weight-generation command (i.e., map_fl or map_trn_fl for monotr) |
| 569 |
map_trn_fl='' # [sng] Map-file transpose (for Tempest) |
| 570 |
map_mk='No' # [flg] Generate map-file (i.e., map does not yet exist) |
| 571 |
map_usr_flg='No' # [flg] User supplied argument to --map option |
| 572 |
map_xmp='map.nc' # [sng] Map-file for examples |
| 573 |
mbt_grd_nc4='No' # [sng] Either grid for MOAB mbconvert to read is netCDF4 format |
| 574 |
mbt_grd_rd_srl='No' # [sng] MOAB mbconvert is to read grids in serial |
| 575 |
mbt_typ_grd=0 # [flg] mbtempest mesh type (CS=0, RLL=1, ICO=2, OVERLAP_FILES=3, OVERLAP_MEMORY=4, OVERLAP_MOAB=5]) |
| 576 |
mbt_typ_map=5 # [flg] mbtempest mesh type (CS=0, RLL=1, ICO=2, OVERLAP_FILES=3, OVERLAP_MEMORY=4, OVERLAP_MOAB=5]) |
| 577 |
mem_mb=0 # [MB] Megabytes of RAM per srun job in Cori SLURM in MPI mode (0 indicates unlimited RAM) |
| 578 |
mlt_map_flg='Yes' # [sng] Multi-map flag |
| 579 |
mpaso_var_zmid='timeMonthly_avg_zMid' # [sng] Name of MPAS-O 3D depth variable |
| 580 |
mpi_flg='No' # [sng] Parallelize over nodes |
| 581 |
mpi_nbr=1 # [sng] Number of tasks-per-node that MPI-enabled weight generators will request (should be >= prt_nbr) |
| 582 |
mpt_mss='No' # [flg] Set empty (sgs_frc==0.0) SGS cells to missing value |
| 583 |
msh_exe_tps='GenerateOverlapMesh' # [sng] TempestRemap mesh-generation executable |
| 584 |
msh_fl='' # [sng] Mesh-file (for Tempest) |
| 585 |
msk_apl='No' # [flg] Apply msk_out to variables after regridding |
| 586 |
msk_dst='' # [sng] Mask-template variable in destination file |
| 587 |
msk_out='No' # [flg] Put mask variable in regridded file |
| 588 |
msk_src='' # [sng] Mask-template variable in source file |
| 589 |
mss_val='-9.99999979021476795361e+33' # [frc] Missing value for MPAS (ocean+seaice) |
| 590 |
#mss_val='-1.0e36' # [frc] Missing value (MALI) |
| 591 |
nco_opt='--no_tmp_fl' # [sng] NCO options (e.g., '-6 -t 1') |
| 592 |
nd_nbr=1 # [nbr] Number of nodes |
| 593 |
nsx_alg='' # [enm] Intersection algorithm (mbtempest only) |
| 594 |
out_fl='' # [sng] Output file |
| 595 |
out_xmp='out.nc' # [sng] Output file for examples |
| 596 |
par_typ="${par_srl}" # [sng] Parallelism type for files |
| 597 |
pdq_flg='Yes' # [sng] Permute dimensions before regridding |
| 598 |
pdq_opt='' # [sng] ncpdq dimension permutation option |
| 599 |
prc_sgs='No' # [sng] SGS requested |
| 600 |
prc_typ='' # [sng] Procedure type |
| 601 |
prt_alg='zoltan' # [sng] MOAB-Tempest H5M partition algorithm |
| 602 |
prt_exe_mbt='mbpart' # [sng] MOAB-Tempest H5M partition executable |
| 603 |
prt_nbr=8 # [nbr] Partition number for mbpart (should be > 1 and <= mpi_nbr) |
| 604 |
prs_stt='' # [sng] Preserved statistic ('integral' or 'mean') |
| 605 |
ps_nm='' # [sng] Name of variable containing surface pressure in input file |
| 606 |
ps_nm_dfl='PS' # [sng] Name of variable containing surface pressure in input file |
| 607 |
ps_rtn='No' # [flg] Retain surface pressure variable in vertical interpolation output |
| 608 |
qea_flg='No' # [sng] Quasi-equal area mode for TempestRemap |
| 609 |
qnt_prc='' # [nbr] Quantization precision |
| 610 |
rgr_opt='--rgr lat_nm_out=lat --rgr lon_nm_out=lon' # [sng] Regridding options |
| 611 |
#rgr_opt='--rgr lat_dnm_nm=x --rgr lon_dmn_nm=y' # [sng] Regridding options for projection grid |
| 612 |
rnr_thr='' # [frc] Renormalization option |
| 613 |
se_np_nbr=4 # [nbr] Spectral Element polynomial order of discretization (for TempestRemap SE grids) |
| 614 |
sgs_frc='' # [sng] Sub-grid fraction variable |
| 615 |
sgs_frc_usr='' # [sng] Sub-grid fraction variable (user-defined) |
| 616 |
sgs_msk='' # [sng] Sub-grid mask variable |
| 617 |
sgs_nrm='1.0' # [frc] Sub-grid normalization |
| 618 |
skl_fl='' # [sng] Skeleton file |
| 619 |
std_chk='Yes' # [sng] Check stdin for input file list |
| 620 |
std_flg='No' # [sng] Input available from pipe to stdin |
| 621 |
stg_grd='No' # [flg] Include staggered grid variables |
| 622 |
thr_nbr=2 # [nbr] Thread number for regridder |
| 623 |
trn_map='No' # [flg] Tempest transpose map (i.e., fv2se_flx == monotr) |
| 624 |
ugrid_fl='' # [sng] UGRID file |
| 625 |
unq_sfx=".pid${spt_pid}" # [sng] Unique suffix |
| 626 |
#var_lst='FSNT,AODVIS' # [sng] Variables to process (empty means all) |
| 627 |
var_lst='' # [sng] Variables to process (empty means all) |
| 628 |
var_rgr='' # [sng] CF template variable |
| 629 |
var_xmp='FSNT' # [sng] Variable list for examples |
| 630 |
vrb_lvl=${vrb_2} # [enm] Verbosity level |
| 631 |
vrs_prn='No' # [sng] Print version information |
| 632 |
vrt_in='' # [sng] Vertical grid file for input |
| 633 |
vrt_nm='' # [sng] Vertical coordinate name |
| 634 |
vrt_opt='' # [sng] Vertical options (e.g., '--rgr xtr_mth=mss_val') |
| 635 |
vrt_out='' # [sng] Vertical grid file for output |
| 636 |
vrt_ntp='' # [sng] Vertical interpolation type (lin|log) |
| 637 |
vrt_xtr='' # [sng] Vertical extrapolation type (linear|mss_val|nrs_ngh|zero) |
| 638 |
wgt_exe_cdo='cdo' # [sng] ESMF executable (weight generation only) |
| 639 |
wgt_exe_esmf='ESMF_RegridWeightGen' # [sng] ESMF executable (weight generation only) |
| 640 |
wgt_exe_mbt='mbtempest' # [sng] MOAB-Tempest executable (both mesh- and weight-generation) |
| 641 |
wgt_exe_nco='ncks' # [sng] NCO executable (both mesh- and weight-generation) |
| 642 |
wgt_exe_tps='GenerateOfflineMap' # [sng] TempestRemap weight-generation executable |
| 643 |
wgt_typ='' # [sng] Weight-generator program ('esmf', 'mbtempest', 'nco', or 'tempest') |
| 644 |
wgt_opt='' # [sng] Weight-generator options |
| 645 |
wgt_opt_cdo='' # [sng] CDO weight-generation options |
| 646 |
wgt_opt_esmf='--no_log --ignore_unmapped' # [sng] ESMF_RegridWeightGen weight-generation options (ESMF < 7.1.0r). --ignore_unmapped tells ESMF to ignore cells on the destination grid which are not fully covered by cells on the source grid (because that would require extrapolation) |
| 647 |
#wgt_opt_esmf='--ignore_unmapped --ignore_degenerate' # [sng] ESMF_RegridWeightGen weight-generation options (ESMF >= 7.1.0r) (ignore_degenerate is required for CICE regridding with ESMF >= 7.1.0r, and is not supported or required with ESMF < 7.1.0r) |
| 648 |
wgt_opt_nco='-O --dmm_in_mk' # [sng] NCO weight-generation options |
| 649 |
wgt_opt_tps='' # [sng] TempestRemap weight-generation options |
| 650 |
msh_opt_tps='--allow_no_overlap' # [sng] TempestRemap mesh-generation options (20210421: add allow_no_overlap required by regional-to-regional grids like GrIS) |
| 651 |
xcl_flg='No' # [sng] Exclude rather than extract variable list |
| 652 |
xtn_var='' # [sng] Extensive variables (e.g., 'TSurfStd_ct') |
| 653 |
xtr_nsp=8 # [nbr] Extrapolation number of source points (for ESMF & NCO only) |
| 654 |
xtr_xpn=2.0 # [frc] Extrapolation inverse-distance exponent (absolute value) (for ESMF & NCO only) |
| 655 |
|
| 656 |
# Set temporary-file directory (must be writable by user) |
| 657 |
if [ -d "${TMPDIR}" ]; then |
| 658 |
# Fancy %/ syntax removes trailing slash (e.g., from $TMPDIR) |
| 659 |
drc_tmp="${TMPDIR%/}" |
| 660 |
elif [ -d '/tmp' ]; then |
| 661 |
drc_tmp='/tmp' |
| 662 |
else |
| 663 |
drc_tmp=${PWD} |
| 664 |
fi # !gpfs |
| 665 |
|
| 666 |
function fnc_usg_prn { # NB: dash supports fnc_nm (){} syntax, not function fnc_nm{} syntax |
| 667 |
# Print usage |
| 668 |
printf "${fnt_rvr}Basic usage:\n" |
| 669 |
printf "${fnt_nrm} ${fnt_bld}${spt_nm} --map=map.nc in_fl out_fl${fnt_nrm} # Apply existing map from in->out\n" |
| 670 |
printf "${fnt_nrm} ${fnt_bld}${spt_nm} -d dst_fl in_fl out_fl${fnt_nrm} # Construct map in->dst, regrid to out\n" |
| 671 |
printf "${fnt_nrm} ${fnt_bld}${spt_nm} --destination=dst_fl --input_file=in_fl --output_file=out_fl${fnt_nrm} # Long options (NB: '='is REQUIRED)\n\n" |
| 672 |
echo "Command-line options [long-option synonyms in ${fnt_tlc}italics${fnt_nrm}]:" |
| 673 |
echo "${fnt_rvr}-3${fnt_nrm} Output file format ${fmt_sng_nc3} [${fnt_tlc}fl_fmt, file_format=classic${fnt_nrm}]" |
| 674 |
echo "${fnt_rvr}-4${fnt_nrm} Output file format ${fmt_sng_nc4} [${fnt_tlc}fl_fmt, file_format=netcdf4${fnt_nrm}]" |
| 675 |
echo "${fnt_rvr}-5${fnt_nrm} Output file format ${fmt_sng_nc5} [${fnt_tlc}fl_fmt, file_format=64bit_data${fnt_nrm}]" |
| 676 |
echo "${fnt_rvr}-6${fnt_nrm} Output file format ${fmt_sng_nc6} [${fnt_tlc}fl_fmt, file_format=64bit_offset${fnt_nrm}]" |
| 677 |
echo "${fnt_rvr}-7${fnt_nrm} Output file format ${fmt_sng_nc7} [${fnt_tlc}fl_fmt, file_format=netcdf4_classic${fnt_nrm}]" |
| 678 |
echo "${fnt_rvr}-a${fnt_nrm} ${fnt_bld}alg_typ${fnt_nrm} Algorithm for weight generation (default ${fnt_bld}${alg_typ}${fnt_nrm}) [${fnt_tlc}alg_typ, algorithm, regrid_algorithm${fnt_nrm}]" |
| 679 |
echo " CDO algorithms: cdo_bilinear|cdo_conservative (same as ESMF)" |
| 680 |
echo " ESMF algorithms: esmfbilin,bilinear|esmfaave,aave,conserve|conserve2nd|nearestdtos|neareststod|patch" |
| 681 |
echo " NCO algorithms: ncoaave,nco,nco_con|ncoidw,nco_dwe (inverse-distance-weighted interpolation/extrapolation)" |
| 682 |
echo " Tempest (and MOAB-Tempest) algorithms: traave,fv2fv_flx|trbilin|trfv2|trintbilin|fv2fv|fv2fv_stt|fv2se_flx|fv2se_stt|fv2se_alt|se2fv_flx|se2fv_stt|se2fv_alt|se2se" |
| 683 |
echo " ${fnt_bld}--a2o${fnt_nrm} Atmosphere-to-ocean remap (for Tempest only) (default ${fnt_bld}${a2o_flg}${fnt_nrm}) [${fnt_tlc}a2o, atm2ocn, b2l, big2ltl, l2s, lrg2sml${fnt_nrm}]" |
| 684 |
echo " ${fnt_bld}--add_fll${fnt_nrm} Add _FillValue to fields with empty destination cells (default ${fnt_bld}${add_fll}${fnt_nrm}) [${fnt_tlc}add_fll, add_fill_value, fll_mpt, fill_empty${fnt_nrm}]" |
| 685 |
echo " ${fnt_bld}--alg_lst${fnt_nrm} Algorithms to generate maps with in MWF mode (default ${fnt_bld}${alg_lst}${fnt_nrm}) [${fnt_tlc}alg_lst, algorithm_list${fnt_nrm}]" |
| 686 |
echo " ${fnt_bld}--area_dgn${fnt_nrm} Diagnose (rather than copy) grid_area to inferred grid-file (default ${fnt_bld}No${fnt_nrm}) [${fnt_tlc}area_diagnose, dgn_area, diagnose_area${fnt_nrm}]" |
| 687 |
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}]" |
| 688 |
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}]" |
| 689 |
echo " ${fnt_bld}--col_dmn${fnt_nrm} Column (unstructured) dimension name for coupler files (empty means none) (default ${fnt_bld}${col_dmn}${fnt_nrm}) [${fnt_tlc}col_dmn, col_nm, column_dimension, unstructured_dimension${fnt_nrm}]" |
| 690 |
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}]" |
| 691 |
echo "${fnt_rvr}-d${fnt_nrm} ${fnt_bld}dst_fl${fnt_nrm} Data file to infer destination grid from (empty means none, i.e., use grd_fl, grd_sng, or map_fl)) (default ${fnt_bld}${dst_fl}${fnt_nrm}) [${fnt_tlc}dst_fl, destination_file, tpl, tpl_fl, template, template_file${fnt_nrm}]" |
| 692 |
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}]" |
| 693 |
echo " ${fnt_bld}--devnull${fnt_nrm} Send NCO weight-generator messages to /dev/null (default ${fnt_bld}${dvn_flg}${fnt_nrm}) [${fnt_tlc}devnull, dev_nll, dvn_flg${fnt_nrm}]" |
| 694 |
echo " ${fnt_bld}--dpt${fnt_nrm} Add depth coordinate to MPAS files (default ${fnt_bld}${dpt_flg}${fnt_nrm}) [${fnt_tlc}dpt | depth | add_dpt | add_depth${fnt_nrm}]" |
| 695 |
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}]" |
| 696 |
echo " ${fnt_bld}--dpt_nm${fnt_nrm} 3D-Depth/height variable name (default ${fnt_bld}${dpt_nm}${fnt_nrm}) [${fnt_tlc}dpt_nm, depth_name, vrt_dpt${fnt_nrm}]" |
| 697 |
echo " ${fnt_bld}--dt_sng${fnt_nrm} Date string (for MWF map names) (default ${fnt_bld}${dt_sng}${fnt_nrm}) [${fnt_tlc}dt_sng, date_string${fnt_nrm}]" |
| 698 |
echo " ${fnt_bld}--esmf_typ${fnt_nrm} ESMF Extrapolation type (empty means none) (default ${fnt_bld}${esmf_typ}${fnt_nrm}) [${fnt_tlc}esmf_typ, esmf_mth, esmf_extrap_type, esmf_extrap_method${fnt_nrm}] (nearestidavg|neareststod|none)" |
| 699 |
echo " ${fnt_bld}--fl_fmt${fnt_nrm} File format (empty is netCDF3 64bit CDF2) (default ${fnt_bld}${fl_fmt}${fnt_nrm}) [${fnt_tlc}fl_fmt, fmt_out, file_format, format_out${fnt_nrm}]" |
| 700 |
echo "${fnt_rvr}-G${fnt_nrm} ${fnt_bld}grd_sng${fnt_nrm} Grid generation arguments (empty means none) (default ${fnt_bld}${grd_sng}${fnt_nrm}) [${fnt_tlc}grd_sng, grid_generation, grid_gen, grid_string${fnt_nrm}]" |
| 701 |
echo "${fnt_rvr}-g${fnt_nrm} ${fnt_bld}grd_dst${fnt_nrm} Grid-file (destination) (empty means none, i.e., infer from dst_fl or use map_fl) (default ${fnt_bld}${grd_dst}${fnt_nrm}) [${fnt_tlc}grd_dst, grid_dest, dst_grd, dest_grid, destination_grid${fnt_nrm}]" |
| 702 |
echo " ${fnt_bld}--gad_lst${fnt_nrm} Global attributes to delete from output files (default ${fnt_bld}${gad_lst}${fnt_nrm}) [${fnt_tlc}gad, glb_att_del, att_del${fnt_nrm}]" |
| 703 |
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}]" |
| 704 |
echo "${fnt_rvr}-I${fnt_nrm} ${fnt_bld}drc_in${fnt_nrm} Input directory (empty means none) (default ${fnt_bld}${drc_in}${fnt_nrm}) [${fnt_tlc}drc_in, in_drc, dir_in, in_dir, input${fnt_nrm}]" |
| 705 |
echo "${fnt_rvr}-i${fnt_nrm} ${fnt_bld}in_fl${fnt_nrm} Input file (empty means pipe to stdin or drc_in) (default ${fnt_bld}${in_fl}${fnt_nrm}) [${fnt_tlc}in_fl, in_file, input_file${fnt_nrm}]" |
| 706 |
echo "${fnt_rvr}-j${fnt_nrm} ${fnt_bld}job_nbr${fnt_nrm} Job simultaneity for file-level parallelism (default ${fnt_bld}${job_nbr}${fnt_nrm}) [${fnt_tlc}job_nbr, job_number, jobs${fnt_nrm}]" |
| 707 |
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}]" |
| 708 |
echo "${fnt_rvr}-M${fnt_nrm} Multi-map-file toggle (unset means generate one map-file per input file) [${fnt_tlc}mlt_map, no_multimap${fnt_nrm}]" |
| 709 |
echo "${fnt_rvr}-m${fnt_nrm} ${fnt_bld}map_fl${fnt_nrm} Map-file (horizontal regridding) (empty means generate internally) (default ${fnt_bld}${map_fl}${fnt_nrm}) [${fnt_tlc}map_fl, map, map_file, rgr_map, regrid_map${fnt_nrm}]" |
| 710 |
echo " ${fnt_bld}--mbt_grd_nc4${fnt_nrm} Either grid for MOAB mbconvert to read is netCDF4 format (default ${fnt_bld}${mbt_grd_nc4}${fnt_nrm}) [${fnt_tlc}mbt_grd_nc4, mbt_grd_rd_srl, grd_fmt_nc4$, {fnt_nrm}]" |
| 711 |
echo " ${fnt_bld}--mpi_nbr${fnt_nrm} Number of tasks-per-node that MPI-enabled weight generators will request (default ${fnt_bld}${mpi_nbr}${fnt_nrm}) [${fnt_tlc}mpi_nbr, mpi_number, tsk_nbr, task_number${fnt_nrm}]" |
| 712 |
echo " ${fnt_bld}--mpi_pfx${fnt_nrm} Prefix for MPI-enabled weight generators (empty means weight generator is not MPI-enabled) (default ${fnt_bld}${mpi_pfx}${fnt_nrm}) [${fnt_tlc}mpi_pfx, mpi_prefix, srun_cmd, srun_command${fnt_nrm}]" |
| 713 |
echo " ${fnt_bld}--mpt_mss${fnt_nrm} Set empty (sgs_frc==0.0) SGS cells to missing value (default ${fnt_bld}${mpt_mss}${fnt_nrm}) [${fnt_tlc}mpt_mss, sgs_zro_mss$, empty_missing{fnt_nrm}]" |
| 714 |
echo " ${fnt_bld}--msh_fl${fnt_nrm} Mesh-file for grid intersection (empty means generate internally or not at all) (default ${fnt_bld}${msh_fl}${fnt_nrm}) [${fnt_tlc}msh_fl, msh, mesh, mesh_file${fnt_nrm}]" |
| 715 |
echo " ${fnt_bld}--msk_apl${fnt_nrm} Apply msk_out to variables after regridding (default ${fnt_bld}${msk_apl}${fnt_nrm}) [${fnt_tlc}msk_apl, mask_apply, msk_app${fnt_nrm}]" |
| 716 |
echo " ${fnt_bld}--msk_dst${fnt_nrm} Mask-template variable in destination file (empty means none) (default ${fnt_bld}${msk_dst}${fnt_nrm}) [${fnt_tlc}msk_dst, dst_msk, mask_destination, mask_dst${fnt_nrm}]" |
| 717 |
echo " ${fnt_bld}--msk_out${fnt_nrm} Put mask variable in regridded file, argument is name (default ${fnt_bld}${msk_out}${fnt_nrm}) [${fnt_tlc}msk_out, out_msk, mask_output, mask_rgr${fnt_nrm}]" |
| 718 |
echo " ${fnt_bld}--msk_src${fnt_nrm} Mask-template variable in source file (empty means none) (default ${fnt_bld}${msk_src}${fnt_nrm}) [${fnt_tlc}msk_src, src_msk, mask_source, mask_src${fnt_nrm}]" |
| 719 |
echo " ${fnt_bld}--mss_val${fnt_nrm} Missing value for MPAS (empty means none) (default ${fnt_bld}${mss_val}${fnt_nrm}) [${fnt_tlc}mss_val, fll_val, missing_value, fill_value${fnt_nrm}]" |
| 720 |
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_options${fnt_nrm}]" |
| 721 |
echo " ${fnt_bld}--nm_dst${fnt_nrm} Short name of destination grid (required for MWF, no default) [${fnt_tlc}nm_dst, name_dst, nm_sht_dst, short_name_destination${fnt_nrm}]" |
| 722 |
echo " ${fnt_bld}--nm_src${fnt_nrm} Short name of source grid (required for MWF, no default) [${fnt_tlc}nm_src, name_src, nm_sht_src, short_name_source${fnt_nrm}]" |
| 723 |
echo " ${fnt_bld}--no_add_fll${fnt_nrm} Do not add _FillValue to fields with empty destination cells [${fnt_tlc}no_add_fll, no_add_fill_value, no_fll_mpt, no_fill_empty${fnt_nrm}]" |
| 724 |
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}]" |
| 725 |
echo " ${fnt_bld}--no_frm_trm${fnt_nrm} Omit formula_terms variables (e.g., 'hyba', 'PS') [${fnt_tlc}no_frm_trm, no_formula_terms${fnt_nrm}]" |
| 726 |
echo " ${fnt_bld}--no_permute${fnt_nrm} Do not permute dimensions before regridding [${fnt_tlc}no_prm, no_pdq, no_ncpdq${fnt_nrm}]" |
| 727 |
echo " ${fnt_bld}--no_stg_grd${fnt_nrm} Omit staggered grid variables ('slat, slon, w_stag') (default ${fnt_bld}True${fnt_nrm}) [${fnt_tlc}no_stg_grd, no_stg, no_stagger, no_staggered_grid${fnt_nrm}]" |
| 728 |
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}]" |
| 729 |
echo " ${fnt_bld}--nsx_alg${fnt_nrm} Intersection algorithm used by mbtempest (default ${fnt_bld}kdtree${fnt_nrm}) [${fnt_tlc}nsx_alg, intersection_algorithm${fnt_nrm}] (advfront|kdtree)" |
| 730 |
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}]" |
| 731 |
echo "${fnt_rvr}-o${fnt_nrm} ${fnt_bld}out_fl${fnt_nrm} Output-file (regridded file) (empty copies Input filename) (default ${fnt_bld}${out_fl}${fnt_nrm}) [${fnt_tlc}out_fl, out_file, output_file${fnt_nrm}]" |
| 732 |
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, prm_typ, procedure${fnt_nrm}] (cpl|eam|eamxx|elm|mpasa|mpaso|mpassi|cam|clm|pop|...)" |
| 733 |
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}]" |
| 734 |
echo " ${fnt_bld}--pdq_opt${fnt_nrm} ncpdq dimension permutation string (empty means none) (default ${fnt_bld}${pdq_opt}${fnt_nrm}) [${fnt_tlc}pdq, pdq_opt, prm, prm_opt, permute${fnt_nrm}]" |
| 735 |
echo " ${fnt_bld}--preserve${fnt_nrm} Preserved statistic (empty preserves integral, except mean for MPAS) (default ${fnt_bld}${prs_stt}${fnt_nrm}) [${fnt_tlc}preserve, prs_stt, preserved_statistic${fnt_nrm}] (integral|mean)" |
| 736 |
echo " ${fnt_bld}--prt_nbr${fnt_nrm} Partition number for MOAB parallelism (default ${fnt_bld}${prt_nbr}${fnt_nrm}) [${fnt_tlc}prt_nbr, prt, partition_number${fnt_nrm}]" |
| 737 |
echo " ${fnt_bld}--ps_nm${fnt_nrm} Surface pressure variable name (default ${fnt_bld}${ps_nm_dfl}${fnt_nrm}) [${fnt_tlc}ps_nm, ps_name, ps, vrt_ps${fnt_nrm}]" |
| 738 |
echo " ${fnt_bld}--ps_rtn${fnt_nrm} Retain surface pressure after vertical interpolation (default ${fnt_bld}${ps_rtn}${fnt_nrm}) [${fnt_tlc}ps_rtn, rtn_sfc_prs, retain_surface_pressure${fnt_nrm}]" |
| 739 |
# echo " ${fnt_bld}--qea_flg${fnt_nrm} Quasi-equal area mode for TempestRemap (default ${fnt_bld}${qea_flg}${fnt_nrm}) [${fnt_tlc}qea, qea_flg, np2, quasi-equal-area${fnt_nrm}]" |
| 740 |
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}]" |
| 741 |
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}]" |
| 742 |
echo "${fnt_rvr}-r${fnt_nrm} ${fnt_bld}rnr_thr${fnt_nrm} Renormalization threshold (empty means none (except for MPAS, see documentation)) (default ${fnt_bld}${rnr_thr}${fnt_nrm}) [${fnt_tlc}rnr_thr, rnr, renormalize, renormalization_threshold${fnt_nrm}]" |
| 743 |
echo " ${fnt_bld}--rgn_dst${fnt_nrm} Regional destination grid [${fnt_tlc}rgn_dst, dst_rgn, regional_destination${fnt_nrm}]" |
| 744 |
echo " ${fnt_bld}--rgn_src${fnt_nrm} Regional source grid [${fnt_tlc}rgn_src, src_rgn, regional_source${fnt_nrm}]" |
| 745 |
echo " ${fnt_bld}--rrg_bb_wesn${fnt_nrm} Regional regridding bounding-box WESN order (empty means none) (default ${fnt_bld}${bb_wesn}${fnt_nrm}) [${fnt_tlc}rrg_bb_wesn, bb, bb_wesn, wesn_sng${fnt_nrm}]" |
| 746 |
echo " ${fnt_bld}--rrg_dat_glb${fnt_nrm} Regional regridding global data file (empty means none) (default ${fnt_bld}${dat_glb}${fnt_nrm}) [${fnt_tlc}rrg_dat_glb, dat_glb, data_global, global_data${fnt_nrm}]" |
| 747 |
echo " ${fnt_bld}--rrg_grd_glb${fnt_nrm} Regional regridding global grid file (empty means none) (default ${fnt_bld}${grd_glb}${fnt_nrm}) [${fnt_tlc}rrg_grd_glb, grd_glb, grid_global, global_grid${fnt_nrm}]" |
| 748 |
echo " ${fnt_bld}--rrg_grd_rgn${fnt_nrm} Regional regridding regional grid file (empty means none) (default ${fnt_bld}${grd_rgn}${fnt_nrm}) [${fnt_tlc}rrg_grd_rgn, grd_rgn, grid_regional, regional_grid${fnt_nrm}]" |
| 749 |
echo " ${fnt_bld}--rrg_rnm_sng${fnt_nrm} Regional regridding rename string (empty means none) (default ${fnt_bld}${rnm_sng}${fnt_nrm}) [${fnt_tlc}rrg_rnm_sng, rnm_sng, rename_string${fnt_nrm}]" |
| 750 |
echo "${fnt_rvr}-s${fnt_nrm} ${fnt_bld}grd_src${fnt_nrm} Grid-file (source) (empty means infer or use map_fl) (default ${fnt_bld}${grd_src}${fnt_nrm}) [${fnt_tlc}grd_src, grid_source, source_grid, src_grd${fnt_nrm}]" |
| 751 |
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}]" |
| 752 |
echo " ${fnt_bld}--sgs_msk${fnt_nrm} Sub-grid mask variable (empty means none) (default ${fnt_bld}${sgs_msk}${fnt_nrm}) [${fnt_tlc}sgs_msk, ice_msk, lnd_msk, ocn_msk, subgrid_mask${fnt_nrm}]" |
| 753 |
echo " ${fnt_bld}--sgs_nrm${fnt_nrm} Sub-grid fraction normalization (empty means none) (default ${fnt_bld}${sgs_nrm}${fnt_nrm}) [${fnt_tlc}sgs_nrm, subgrid_normalization${fnt_nrm}]" |
| 754 |
echo " ${fnt_bld}--skl_fl${fnt_nrm} Skeleton file (empty means none) (default ${fnt_bld}${skl_fl}${fnt_nrm}) [${fnt_tlc}skl_fl, skl, skeleton, skeleton_file${fnt_nrm}]" |
| 755 |
echo " ${fnt_bld}--std_flg${fnt_nrm} Stdin used for input (default ${fnt_bld}${inp_std}${fnt_nrm}) [${fnt_tlc}stdin, std_flg, inp_std, redirect, standard_input${fnt_nrm}]" |
| 756 |
echo " ${fnt_bld}--stg_grd${fnt_nrm} Add staggered grid variables ('slat, slon, w_stag') (default ${fnt_bld}False${fnt_nrm}) [${fnt_tlc}stg_grd, stg, stagger, staggered_grid${fnt_nrm}]" |
| 757 |
echo "${fnt_rvr}-T${fnt_nrm} ${fnt_bld}drc_tmp${fnt_nrm} Temporary directory (for intermediate files) (default ${fnt_bld}${drc_tmp}${fnt_nrm}) [${fnt_tlc}drc_tmp, tmp_drc, dir_tmp, tmp_dir, tmp${fnt_nrm}]" |
| 758 |
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}]" |
| 759 |
echo "${fnt_rvr}-U${fnt_nrm} Unpack input prior to regridding [${fnt_tlc}unpack, upk, upk_inp${fnt_nrm}]" |
| 760 |
echo "${fnt_rvr}-u${fnt_nrm} ${fnt_bld}unq_sfx${fnt_nrm} Unique suffix (prevents intermediate files from sharing names) (default ${fnt_bld}${unq_sfx}${fnt_nrm}) [${fnt_tlc}unq_sfx, unique_suffix, suffix${fnt_nrm}]" |
| 761 |
echo " ${fnt_bld}--ugrid_fl${fnt_nrm} UGRID file (empty means none) (default ${fnt_bld}${ugrid_fl}${fnt_nrm}) [${fnt_tlc}ugrid_fl, ugrid, ugrid_file${fnt_nrm}]" |
| 762 |
echo " ${fnt_bld}--uio${fnt_nrm} Unbuffered I/O (NC_SHARE) for netCDF3 files [${fnt_tlc}uio, unbuffered, share${fnt_nrm}]" |
| 763 |
echo "${fnt_rvr}-V${fnt_nrm} ${fnt_bld}var_rgr${fnt_nrm} CF template variable (empty means none) (default ${fnt_bld}${var_rgr}${fnt_nrm}) [${fnt_tlc}var_rgr, rgr_var, var_cf, cf_var, cf_variable${fnt_nrm}]" |
| 764 |
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}]" |
| 765 |
echo " ${fnt_bld}--version${fnt_nrm} Version and configuration information [${fnt_tlc}version, vrs, config, configuration, cnf${fnt_nrm}]" |
| 766 |
echo " ${fnt_bld}--vrb_lvl${fnt_nrm} Verbosity level (default ${fnt_bld}${vrb_lvl}${fnt_nrm}) [${fnt_tlc}vrb_lvl, vrb, verbosity, print_verbosity${fnt_nrm}]" |
| 767 |
echo " ${fnt_bld}--vrt_in${fnt_nrm} Vertical grid file for input (empty means none) (default ${fnt_bld}${vrt_in}${fnt_nrm}) [${fnt_tlc}vrt_in, vrt_grd_in${fnt_nrm}]" |
| 768 |
echo " ${fnt_bld}--vrt_nm${fnt_nrm} Vertical coordinate name (empty means \"plev\") (default ${fnt_bld}${vrt_nm}${fnt_nrm}) [${fnt_tlc}vrt_nm, plev_nm, vrt_crd, vertical_coordinate_name${fnt_nrm}]" |
| 769 |
echo " ${fnt_bld}--vrt_ntp${fnt_nrm} Vertical interpolation type (empty means none) (default ${fnt_bld}${vrt_ntp}${fnt_nrm}) [${fnt_tlc}vrt_ntp, ntp_mth, interpolation_type, interpolation_method${fnt_nrm}] (lin|log)" |
| 770 |
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_grd_out${fnt_nrm}]" |
| 771 |
echo " ${fnt_bld}--vrt_xtr${fnt_nrm} Vertical extrapolation type (empty means none) (default ${fnt_bld}nrs_ngh${fnt_nrm}) [${fnt_tlc}vrt_xtr, xtr_mth, extrapolation_type, extrapolation_method${fnt_nrm}] (linear|mss_val|nrs_ngh|zero)" |
| 772 |
echo "${fnt_rvr}-W${fnt_nrm} ${fnt_bld}wgt_opt${fnt_nrm} Weight-generator options (default ${fnt_bld}${wgt_opt_esmf}${fnt_nrm}) [${fnt_tlc}wgt_opt, esmf_opt, esmf_options, tempest_opt, tps_opt${fnt_nrm}]" |
| 773 |
echo "${fnt_rvr}-w${fnt_nrm} ${fnt_bld}wgt_cmd${fnt_nrm} Weight-generator command (default ${fnt_bld}${wgt_exe_esmf}${fnt_nrm}) [${fnt_tlc}wgt_cmd, wgt_gnr, weight_command, weight_generator${fnt_nrm}]" |
| 774 |
echo "${fnt_rvr}-x${fnt_nrm} ${fnt_bld}xtn_var${fnt_nrm} Extensive variables (empty means none) (default ${fnt_bld}${xtn_var}${fnt_nrm}) [${fnt_tlc}xtn_var, xtn_lst, extensive, var_xtn, extensive_variables${fnt_nrm}]" |
| 775 |
echo " ${fnt_bld}--xcl_var${fnt_nrm} Exclude rather than extract var_lst [${fnt_tlc}xcl_var, xcl, exclude, exclude_variables${fnt_nrm}]" |
| 776 |
echo " ${fnt_bld}--xtr_nsp${fnt_nrm} Extrapolation number of source points (for ESMF & NCO only) (default ${fnt_bld}${xtr_nsp}${fnt_nrm}) [${fnt_tlc}xtr_nsp, xtr_pnt_src_nbr, extrap_num_src_pnts${fnt_nrm}]" |
| 777 |
echo " ${fnt_bld}--xtr_xpn${fnt_nrm} Extrapolation inverse-distance exponent (for ESMF & NCO only) (default ${fnt_bld}${xtr_xpn}${fnt_nrm}) [${fnt_tlc}xtr_xpn, xtr_dst_xpn, extrap_dist_exponent${fnt_nrm}]" |
| 778 |
printf "\n" |
| 779 |
printf "Examples: ${fnt_bld}${spt_nm} -m ${map_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 780 |
printf " ${fnt_bld}${spt_nm} -d ${dst_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 781 |
printf " ${fnt_bld}${spt_nm} -s ${grd_src_xmp} -g ${grd_dst_xmp} -m ${map_xmp} ${fnt_nrm}\n" |
| 782 |
printf " ${fnt_bld}${spt_nm} -d ${dst_xmp} -g ${grd_dst_xmp} ${fnt_nrm}\n" |
| 783 |
printf " ${fnt_bld}${spt_nm} -a esmfaave -d ${dst_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 784 |
printf " ${fnt_bld}${spt_nm} -a esmfbilin -d ${dst_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 785 |
printf " ${fnt_bld}${spt_nm} -a ncoaave -d ${dst_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 786 |
printf " ${fnt_bld}${spt_nm} -a traave -d ${dst_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 787 |
printf " ${fnt_bld}${spt_nm} -a trbilin -d ${dst_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 788 |
printf " ${fnt_bld}${spt_nm} -a trfv2 -d ${dst_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 789 |
printf " ${fnt_bld}${spt_nm} -a trintbilin -d ${dst_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 790 |
printf " ${fnt_bld}${spt_nm} -v ${var_xmp} -m ${map_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 791 |
printf " ${fnt_bld}${spt_nm} -m ${map_xmp} -I ${drc_in_xmp} -O ${drc_out_xmp} ${fnt_nrm}\n" |
| 792 |
printf " ${fnt_bld}${spt_nm} -M -d ${dst_xmp} -I ${drc_in_xmp} -O ${drc_out_xmp} ${fnt_nrm}\n" |
| 793 |
printf " ${fnt_bld}${spt_nm} -M -g ${grd_dst_xmp} -I ${drc_in_xmp} -O ${drc_out_xmp} ${fnt_nrm}\n" |
| 794 |
printf " ${fnt_bld}${spt_nm} -s ${grd_src_xmp} -d ${dst_xmp} -I ${drc_in_xmp} -O ${drc_out_xmp} ${fnt_nrm}\n" |
| 795 |
printf " ${fnt_bld}${spt_nm} -d ${dst_xmp} -I ${drc_in_xmp} -O ${drc_out_xmp} ${fnt_nrm}\n" |
| 796 |
printf " ${fnt_bld}${spt_nm} -g ${grd_dst_xmp} -I ${drc_in_xmp} -O ${drc_out_xmp} ${fnt_nrm}\n" |
| 797 |
printf " ${fnt_bld}${spt_nm} --vrt_out=${grd_vrt_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 798 |
printf " ${fnt_bld}${spt_nm} --vrt_out=${grd_vrt_xmp} -m ${map_xmp} ${in_xmp} ${out_xmp} ${fnt_nrm}\n" |
| 799 |
printf " ${fnt_bld}ls mdl*2005*nc | ${spt_nm} -m ${map_xmp} -O ${drc_out_xmp} ${fnt_nrm}\n" |
| 800 |
printf " ${fnt_bld}ls mdl*2005*nc | ${spt_nm} -d ${dst_xmp} -O ${drc_out_xmp} ${fnt_nrm}\n" |
| 801 |
printf "\nComplete documentation at http://nco.sf.net/nco.html#${spt_nm}\n\n" |
| 802 |
exit 1 |
| 803 |
} # !fnc_usg_prn() |
| 804 |
|
| 805 |
# RRG processing needs NCO filters documented in http://nco.sf.net/nco.html#filter |
| 806 |
function ncvarlst { ncks --trd -m ${1} | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' | sort ; } |
| 807 |
function ncdmnlst { ncks --cdl -m ${1} | cut -d ':' -f 1 | cut -d '=' -s -f 1 ; } |
| 808 |
function nchasvar { ncks --trd -C -m -v ${1} ${2} | grep -E ': type' | cut -f 1 -d ' ' | sed 's/://' ; } |
| 809 |
|
| 810 |
function dst_is_grd { |
| 811 |
# Purpose: Is destination grid specified as SCRIP grid-file? |
| 812 |
# fxm: Not working yet |
| 813 |
# Figure-out whether data-file or grid-file and proceed accordingly |
| 814 |
# Allow ncremap to combine -d and -g switches |
| 815 |
# Usage: dst_is_grd ${fl} |
| 816 |
fl=${1} |
| 817 |
flg='Yes' |
| 818 |
#flg='No' |
| 819 |
} # !dst_is_grd() |
| 820 |
|
| 821 |
# Check argument number and complain accordingly |
| 822 |
arg_nbr=$# |
| 823 |
if [ ${arg_nbr} -eq 0 ]; then |
| 824 |
fnc_usg_prn |
| 825 |
fi # !arg_nbr |
| 826 |
|
| 827 |
# Parse command-line options: |
| 828 |
# http://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-line-options |
| 829 |
# http://tuxtweaks.com/2014/05/bash-getopts |
| 830 |
while getopts :34567a:CD:d:f:g:G:h:I:i:j:L:Mm:n:O:o:P:p:R:r:s:T:t:Uu:V:v:W:w:x:-: OPT; do |
| 831 |
case ${OPT} in |
| 832 |
3) fl_fmt='3' ;; # File format |
| 833 |
4) fl_fmt='4' ;; # File format |
| 834 |
5) fl_fmt='5' ;; # File format |
| 835 |
6) fl_fmt='6' ;; # File format |
| 836 |
7) fl_fmt='7' ;; # File format |
| 837 |
a) alg_typ="${OPTARG}" ;; # Algorithm |
| 838 |
C) clm_flg='Yes' ;; # Climo flag (undocumented) |
| 839 |
D) dbg_lvl="${OPTARG}" ;; # Debugging level |
| 840 |
d) dst_fl="${OPTARG}" ;; # Destination file |
| 841 |
g) grd_dst="${OPTARG}" ;; # Destination grid-file |
| 842 |
G) grd_sng="${OPTARG}" ;; # Grid generation string |
| 843 |
I) drc_in="${OPTARG}" ;; # Input directory |
| 844 |
i) in_fl="${OPTARG}" ;; # Input file |
| 845 |
j) job_usr="${OPTARG}" ;; # Job simultaneity |
| 846 |
L) dfl_lvl="${OPTARG}" ;; # Deflate level |
| 847 |
M) mlt_map_flg='No' ;; # Multi-map flag |
| 848 |
m) map_fl="${OPTARG}" ;; # Map-file |
| 849 |
n) nco_opt="${OPTARG} ${nco_opt}" ;; # NCO options |
| 850 |
O) drc_usr="${OPTARG}" ;; # Output directory |
| 851 |
o) out_fl="${OPTARG}" ;; # Output file |
| 852 |
P) prc_typ="${OPTARG}" ;; # Procedure type |
| 853 |
p) par_typ="${OPTARG}" ;; # Parallelism type for files |
| 854 |
r) rnr_thr="${OPTARG}" ;; # Renormalization threshold |
| 855 |
R) rgr_opt="${OPTARG}" ;; # Regridding options |
| 856 |
s) grd_src="${OPTARG}" ;; # Source grid-file |
| 857 |
T) tmp_usr="${OPTARG}" ;; # Temporary directory |
| 858 |
t) thr_usr="${OPTARG}" ;; # Thread number |
| 859 |
U) pdq_opt='-U' ;; # Unpack input |
| 860 |
u) unq_usr="${OPTARG}" ;; # Unique suffix |
| 861 |
V) var_rgr="${OPTARG}" ;; # CF template variable |
| 862 |
v) var_lst="${OPTARG}" ;; # Variables |
| 863 |
W) wgt_opt_usr="${OPTARG}" ;; # Weight-generator options |
| 864 |
w) wgt_usr="${OPTARG}" ;; # Weight-generator command |
| 865 |
x) xtn_var="${OPTARG}" ;; # Extensive variables |
| 866 |
-) LONG_OPTARG="${OPTARG#*=}" |
| 867 |
case ${OPTARG} in |
| 868 |
# Hereafter ${OPTARG} is long argument key, and ${LONG_OPTARG}, if any, is long argument value |
| 869 |
# Long options with no argument, no short option counterpart |
| 870 |
# Long options with argument, no short option counterpart |
| 871 |
# Long options with short counterparts, ordered by short option key |
| 872 |
a2o | atm2ocn | b2l | big2ltl | l2s | lrg2sml ) a2o_flg='Yes' ;; # # Atmosphere-to-ocean |
| 873 |
a2o=?* | atm2ocn=?* | b2l=?* | big2ltl=?* | l2s=?* | lrg2sml=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Atmosphere-to-ocean |
| 874 |
add_fll | add_fill_value | fll_mpt | fill_empty ) add_fll_usr='Yes' ;; # # Add _FillValue to fields with empty destination cells |
| 875 |
add_fll=?* | add_fill_value=?* | fll_mpt=?* | fill_empty=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Add _FillValue to fields with empty destination cells |
| 876 |
no_add_fll | no_add_fill_value | no_fll_mpt | no_fill_empty ) add_fll_usr='No' ;; # # Do not add _FillValue to fields with empty destination cells |
| 877 |
no_add_fll=?* | no_add_fill_value=?* | no_fll_mpt=?* | fill_empty=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Do not add _FillValue to fields with empty destination cells |
| 878 |
alg_lst=?* | algorithm_list=?* ) alg_lst="${LONG_OPTARG}" ;; # # Algorithm list for MWF mode |
| 879 |
alg_typ=?* | algorithm=?* | regrid_algorithm=?* ) alg_typ="${LONG_OPTARG}" ;; # -a # Algorithm |
| 880 |
area_dgn | dgn_area | area_diagnose | diagnose_area ) area_dgn='Yes' ;; # # Diagnose (rather than copy) grid_area to inferred grid-file |
| 881 |
area_dgn=?* | dgn_area=?* | area_diagnose=?* | diagnose_area=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Diagnose (rather than copy) grid_area in inferred grids |
| 882 |
bfr_sz=?* | bfr=?* | buffer_size_hint=?* ) bfr_sz="${LONG_OPTARG}" ;; # # Buffer size for netCDF-classic I/O |
| 883 |
clm_flg | climatology_flag ) clm_flg='Yes' ;; # -C # Climo flag (undocumented) |
| 884 |
clm_flg=?* | climatology_flag=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # clm_flg |
| 885 |
cmp=?* | cmp_sng=?* | compress=? | compression=?* | cpr=?* | cdc=?* | codec=?* ) cmp_sng="${LONG_OPTARG}" ;; # # Compression string |
| 886 |
col_dmn=?* | col_nm=?* | column_dimension=? | unstructured_dimension=? ) col_dmn="${LONG_OPTARG}" ;; # # Column (unstructured) dimension name for coupler files |
| 887 |
d2f | d2s | dbl_flt | dbl_sgl | double_float ) d2f_flg='Yes' ;; # # Convert double-precision fields to single-precision |
| 888 |
d2f=?* | d2s=?* | dbl_flt=?* | dbl_sgl=?* | double_float=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # D2F |
| 889 |
dbg_lvl=?* | dbg=?* | debug=?* | debug_level=?* ) dbg_lvl="${LONG_OPTARG}" ;; # -d # Debugging level |
| 890 |
devnull=?* | dev_nll=?* | dev_null=?* | dvn_flg=?* ) dvn_flg="${LONG_OPTARG}" ;; # # Send NCO weight-generator messages to /dev/null |
| 891 |
dfl_lvl=?* | deflate=?* | dfl=?* ) dfl_lvl="${LONG_OPTARG}" ;; # -L # Deflate level |
| 892 |
dpt | depth | add_dpt | add_depth ) dpt_flg='Yes' ;; # # Add depth coordinate to MPAS files |
| 893 |
dpt=?* | depth=?* | add_dpt=?* | add_depth=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # DPT |
| 894 |
dpt_fl=?* | mpas_fl=?* | mpas_file=?* | depth_file=?* ) dpt_fl="${LONG_OPTARG}" ;; # # Depth file with refBottomDepth for MPAS ocean |
| 895 |
dpt_nm=?* | depth_name=?* | vrt_dpt=?* ) dpt_nm="${LONG_OPTARG}" ;; # # 3D-depth/height variable name |
| 896 |
dst_fl=?* | destination_file=?* | tpl=?* | tpl_fl=?* | template=?* | template_file=?* ) dst_fl="${LONG_OPTARG}" ;; # -d # Destination file |
| 897 |
grd_dst=?* | grid_dest=?* | dst_grd=?* | dest_grid=?* | destination_grid=?* ) grd_dst="${LONG_OPTARG}" ;; # -g # Destination grid-file |
| 898 |
grd_sng=?* | grid_generation=?* | grid_gen=?* | grid_string=?* ) grd_sng="${LONG_OPTARG}" ;; # -G # Grid generation string |
| 899 |
drc_in=?* | in_drc=?* | dir_in=?* | in_dir=?* | input=?* ) drc_in="${LONG_OPTARG}" ;; # -i # Input directory |
| 900 |
dt_sng=?* | date_string=?* ) dt_sng="${LONG_OPTARG}" ;; # # Date string for MWF map names |
| 901 |
esmf_typ=?* | esmf_mth=?* | esmf_extrap_type=?* | esmf_extrap_method=?* ) esmf_typ="${LONG_OPTARG}" ;; # # ESMF extrapolation type (nearestidavg|neareststod|none) |
| 902 |
fl_fmt=?* | fmt_out=?* | file_format=?* | format_out=?* ) fl_fmt="${LONG_OPTARG}" ;; # # Output file format |
| 903 |
gad_lst=?* | gad=?* | att_del=?* | glb_att_del=?* ) gad_sng="--glb_att_del=${LONG_OPTARG}" ;; # # Global attributes to delete |
| 904 |
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()) |
| 905 |
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 |
| 906 |
in_fl=?* | in_file=?* | input_file=?* ) in_fl="${LONG_OPTARG}" ;; # -i # Input file |
| 907 |
job_nbr=?* | job_number=?* | jobs=?* ) job_usr="${LONG_OPTARG}" ;; # -j # Job simultaneity |
| 908 |
map_fl=?* | map=?* | map_file=?* | rgr_map=?* | regrid_map=?* ) map_fl="${LONG_OPTARG}" ;; # -m # Map-file (horizontal regridding) |
| 909 |
mbt_grd_nc4 | mbt_grd_rd_srl | grd_fmt_nc4 ) mbt_grd_nc4='Yes' ;; # # Either grid for MOAB mbconvert to read is netCDF4 format (so read it in serial) |
| 910 |
mbt_grd_nc4=?* | mbt_grd_rd_srl=?* | grd_fmt_nc4=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Either grid for MOAB mbconvert to read is netCDF4 format (so read it in serial) |
| 911 |
mem_mb=?* ) mem_mb="${LONG_OPTARG}" ;; # # Megabytes of RAM per srun job in Cori SLURM in MPI mode |
| 912 |
mlt_map | multimap | no_multimap | nomultimap ) mlt_map_flg='No' ;; # -M # Multi-map flag |
| 913 |
mlt_map=?* | multimap=?* | no_multimap=?* | nomultimap=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # -M # Multi-map flag |
| 914 |
mpi_nbr=?* | mpi_number=?* | tsk_nbr=?* | task_number=?* ) mpi_nbr_usr="${LONG_OPTARG}" ;; # # Number of tasks-per-node that MPI-enabled weight generators will request |
| 915 |
mpi_pfx=?* | mpi_prefix=?* | srun_cmd=?* | srun_command=?* ) mpi_pfx_usr="${LONG_OPTARG}" ;; # # Prefix for MPI-enabled weight generators |
| 916 |
mpt_mss | sgs_zro_mss | empty_missing ) mpt_mss='Yes' ;; # # Set empty (sgs_frc==0.0) SGS cells to missing value |
| 917 |
mpt_mss=?* | sgs_zro_mss=?* | empty_missing=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Set empty (sgs_frc==0.0) SGS cells to missing value |
| 918 |
msh_fl=?* | msh=?* | mesh=?* | mesh_file=?* ) msh_fl="${LONG_OPTARG}" ;; # # Mesh file |
| 919 |
msk_apl | mask_apply | msk_app ) msk_apl='Yes' ;; # # Apply msk_out to variables after regridding |
| 920 |
msk_apl=?* | mask_apply=?* | msk_app=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Apply msk_out to variables after regridding |
| 921 |
msk_dst=?* | dst_msk=?* | mask_destination=?* | mask_dst=?* ) msk_dst="${LONG_OPTARG}" ;; # # Mask-template variable in destination file |
| 922 |
msk_out=?* | out_msk=?* | mask_output=?* | mask_out=?* ) msk_out="${LONG_OPTARG}" ;; # # Put mask variable in regridded file, argument is name |
| 923 |
msk_src=?* | src_msk=?* | mask_source=?* | mask_src=?* ) msk_src="${LONG_OPTARG}" ;; # # Mask-template variable in source file |
| 924 |
mss_val=?* | fll_val=?* | missing_value=?* | fill_value=?* ) mss_val_usr="${LONG_OPTARG}" ;; # # Missing value for MPAS |
| 925 |
nco_opt=?* | nco=?* | nco_options=?* ) nco_opt="${LONG_OPTARG} ${nco_opt}" ;; # -n # NCO options |
| 926 |
nm_dst=?* | name_dst=?* | nm_sht_dst=?* | short_name_destination=?* ) nm_dst="${LONG_OPTARG}" ;; # # Short name of destination grid |
| 927 |
nm_src=?* | name_src=?* | nm_sht_src=?* | short_name_source=?* ) nm_src="${LONG_OPTARG}" ;; # # Short name of source grid |
| 928 |
no_area | no_cll_msr | no_cell_measures ) no_cll_msr='Yes' ;; # # Omit cell_measures variables |
| 929 |
no_area=?* | no_cell_msr=?* | no_cell_measures=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Omit cell_measures variables |
| 930 |
no_frm_trm | no_frm | no_formula_terms ) no_frm_trm='Yes' ;; # # Omit formula_terms variables |
| 931 |
no_frm_trm=?* | no_frm=?* | no_formula_terms=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Omit formula_terms variables |
| 932 |
no_permute | no_prm | no_pdq | no_ncpdq ) pdq_flg='No' ;; # # Do not permute dimensions before regridding |
| 933 |
no_permute=?* | no_prm=?* | no_pdq=?* | no_ncpdq=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Do not permute dimensions before regridding |
| 934 |
nsx_alg=?* | intersection_algorithm=?* ) nsx_alg="${LONG_OPTARG}" ;; # # Intersection algorithm used by mbtempest |
| 935 |
drc_out=?* | out_drc=?* | dir_out=?* | out_dir=?* | output=?* ) drc_usr="${LONG_OPTARG}" ;; # -O # Output directory |
| 936 |
out_fl=?* | output_file=?* | out_file=?* ) out_fl="${LONG_OPTARG}" ;; # -o # Output file |
| 937 |
prc_typ=?* | prm_typ=?* | procedure=?* ) prc_typ="${LONG_OPTARG}" ;; # -P # Procedure type |
| 938 |
par_typ=?* | par_md=?* | parallel_type=?* | parallel_mode=?* | parallel=?* ) par_typ="${LONG_OPTARG}" ;; # -p # Parallelism type for files |
| 939 |
pdq=?* | prm=?* | pdq_opt=?* | prm_opt=?* | permute=?* ) pdq_opt="-a ${LONG_OPTARG}" ;; # # ncpdq dimension permutation option |
| 940 |
qnt=?* | qnt_prc=?* | precision=?* | ppc=?* | ppc_prc=?* | quantize=?* ) qnt_prc="${LONG_OPTARG}" ;; # # Quantization precision |
| 941 |
prs_stt=?* | preserve=?* | preserved_statistic=?* ) prs_stt_usr="${LONG_OPTARG}" ;; # # Preserved statistic |
| 942 |
prt=?* | prt_nbr=?* | partition_number=?* ) prt_nbr="${LONG_OPTARG}" ;; # # Partition number for MOAB parallelism |
| 943 |
ps_nm=?* | ps_name=?* | ps=?* | vrt_ps=?* ) ps_nm="${LONG_OPTARG}" ;; # # Surface pressure variable name |
| 944 |
ps_rtn | rtn_sfc_prs | retain_surface_pressure ) ps_rtn='Yes' ;; # # Retain surface pressure variable in vertical interpolation output |
| 945 |
ps_rtn=?* | rtn_sfc_prs=?* | retain_surface_pressure=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Retain surface pressure variable in vertical interpolation output |
| 946 |
qea | qea_flg | np2 | quasi-equal-area ) qea_flg='Yes' ;; # # Quasi-equal area mode for TempestRemap |
| 947 |
qea=?* | qea_flg=?* | np2=?* | quasi-equal-area=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Quasi-equal area mode for TempestRemap |
| 948 |
rgr_opt=?* | regrid_options=?* ) rgr_opt="${LONG_OPTARG}" ;; # -R # Regridding options |
| 949 |
rnr_thr=?* | thr_rnr=?* | rnr=?* | renormalize=?* | renormalization_threshold=?* ) rnr_thr="${LONG_OPTARG}" ;; # -r # Renormalization threshold |
| 950 |
rgn_dst=?* | dst_rgn=?* | regional_destination=?* ) hnt_dst='--dst_regional' ;; # # Regional destination grid |
| 951 |
rgn_dst=?* | dst_rgn=?* | regional_destination=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Regional destination grid |
| 952 |
rgn_src=?* | src_rgn=?* | regional_source=?* ) hnt_src='--src_regional' ;; # # Regional source grid |
| 953 |
rgn_src=?* | src_rgn=?* | regional_source=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Regional source grid |
| 954 |
rrg_bb_wesn=?* | bb_wesn=?* | bb=?* | bounding_box=?* ) bb_wesn="${LONG_OPTARG}" ; prc_typ='rrg' ; ;; # # Regional regridding bounding-box WESN order |
| 955 |
rrg_dat_glb=?* | dat_glb=?* | data_global=?* | global_data=?* ) dat_glb="${LONG_OPTARG}" ; prc_typ='rrg' ; ;; # # Regional regridding global data file |
| 956 |
rrg_grd_glb=?* | grd_glb=?* | grid_global=?* | global_grid=?* ) grd_glb="${LONG_OPTARG}" ; prc_typ='rrg' ; ;; # # Regional regridding global grid file |
| 957 |
rrg_grd_rgn=?* | grd_rgn=?* | grid_regional=?* | regional_grid=?* ) grd_rgn="${LONG_OPTARG}" ; prc_typ='rrg' ; ;; # # Regional regridding regional grid file |
| 958 |
rrg_rnm_sng=?* | rnm_sng=?* | rename_string=?* ) rnm_sng="${LONG_OPTARG}" ; prc_typ='rrg' ; ;; # # Regional regridding rename string |
| 959 |
grd_src=?* | grid_source=?* | source_grid=?* | src_grd=?* ) grd_src="${LONG_OPTARG}" ;; # -s # Source grid-file |
| 960 |
sgs_frc=?* | ice_frc=?* | lnd_frc=?* | ocn_frc=?* | subgrid_fraction=?* ) sgs_frc_usr="${LONG_OPTARG}" ;; # # Sub-grid fraction variable |
| 961 |
sgs_msk=?* | ice_msk=?* | lnd_msk=?* | ocn_msk=?* | subgrid_mask=?* ) sgs_msk="${LONG_OPTARG}" ;; # # Sub-grid mask variable |
| 962 |
sgs_nrm=?* | subgrid_normalization=?* ) sgs_nrm="${LONG_OPTARG}" ;; # # Sub-grid fraction normalization |
| 963 |
skl_fl=?* | skl=?* | skeleton=?* | skeleton_file=?* ) skl_fl="${LONG_OPTARG}" ;; # # Skeleton file |
| 964 |
stdin | inp_std | std_flg | redirect | standard_input ) inp_std='Yes' ;; # # Input file list from stdin |
| 965 |
stdin=?* | inp_std=?* | std_flg=?* | redirect=?* | standard_input=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Input file list from stdin |
| 966 |
no_stdin | no_inp_std | no_redirect | no_standard_input ) std_chk='No' ;; # # Do not check stdin for input file list |
| 967 |
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 |
| 968 |
stg_grd | stg | stagger | staggered_grid ) stg_grd='Yes' ;; # # Add staggered grid variables |
| 969 |
stg_grd=?* | stg=?* | stagger=?* | staggered_grid ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Add staggered grid variables |
| 970 |
no_stg_grd | no_stg | no_stagger | no_staggered_grid ) stg_grd='No' ;; # # Omit staggered grid variables |
| 971 |
no_stg_grd=?* | no_stg=?* | no_stagger=?* | no_staggered_grid ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Omit staggered grid variables |
| 972 |
drc_tmp=?* | tmp_drc=?* | dir_tmp=?* | tmp_dir=?* | tmp=?* ) tmp_usr="${LONG_OPTARG}" ;; # -T # Temporary directory |
| 973 |
thr_nbr=?* | thr=?* | thread_number=?* | thread=?* | threads=?* ) thr_usr="${LONG_OPTARG}" ;; # -t # Thread number |
| 974 |
unpack=?* | upk=?* | upk_inp=?* ) pdq_opt='-U' ;; # -U # Unpack input |
| 975 |
unpack=?* | upk=?* | upk_inp=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # -U # Unpack input |
| 976 |
ugrid_fl=?* | ugrid=?* | ugrid_file=?* ) ugrid_fl="${LONG_OPTARG}" ;; # # UGRID file |
| 977 |
uio | unbuffered | share ) uio_flg='Yes' ;; # # Unbuffered I/O (NC_SHARE) for netCDF3 files |
| 978 |
uio=?* | unbuffered=?* | share=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Unbuffered I/O (NC_SHARE) for netCDF3 files |
| 979 |
unq_sfx=?* | unique_suffix=?* | suffix=?* ) unq_usr="${LONG_OPTARG}" ;; # -u # Unique suffix |
| 980 |
var_rgr=?* | rgr_var=?* | var_cf=?* | cf_var=?* | cf_variable=?* ) var_rgr="${LONG_OPTARG}" ;; # -V # CF template variable |
| 981 |
var_lst=?* | variable_list=?* | var=?* | vars=?* | variable=?* | variables=?* ) var_lst="${LONG_OPTARG}" ;; # -v # Variables |
| 982 |
version | vrs | config | configuration | cnf ) vrs_prn='Yes' ;; # # Print version information |
| 983 |
version=?* | vrs=?* | config=?* | configuration=?* | cnf=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Print version information |
| 984 |
vrb_lvl=?* | vrb=?* | verbosity=?* | print_verbosity=?* ) vrb_lvl="${LONG_OPTARG}" ;; # # Print verbosity |
| 985 |
vrt_in=?* | vrt_grd_in=?* ) vrt_in="${LONG_OPTARG}" ;; # # Vertical grid file for input |
| 986 |
vrt_nm=?* | plev_nm=?* | vrt_crd=?* | vertical_coordinate_name=?* ) vrt_nm="${LONG_OPTARG}" ;; # # Vertical coordinate name |
| 987 |
vrt_ntp=?* | ntp_mth=?* | interpolation_type=?* | interpolation_method=?* ) vrt_ntp="${LONG_OPTARG}" ;; # # Vertical interpolation type (lin|log) |
| 988 |
vrt_out=?* | vrt_fl=?* | vrt=?* | vrt_grd_out=?* ) vrt_out="${LONG_OPTARG}" ;; # # Vertical grid file for output |
| 989 |
vrt_xtr=?* | xtr_mth=?* | extrapolation_type=?* | extrapolation_method=?* ) vrt_xtr="${LONG_OPTARG}" ;; # # Vertical extrapolation type (linear|mss_val|nrs_ngh|zero) |
| 990 |
wgt_opt=?* | esmf_opt=?* | esmf_options=?* | tps_opt=?* | tempest_opt=?* | tempest_options=?* ) wgt_opt_usr="${LONG_OPTARG}" ;; # -W # Weight-generator options |
| 991 |
wgt_cmd=?* | weight_command=?* | wgt_gnr=?* | weight_generator=?* ) wgt_usr="${LONG_OPTARG}" ;; # -w # Weight-generator command |
| 992 |
xcl_var | xcl | exclude | exclude_variables ) xcl_flg='Yes' ;; # # Exclude rather than extract variable list |
| 993 |
xcl_var=?* | xcl=?* | exclude=?* | exclude_variables=?* ) echo "No argument allowed for --${OPTARG switch}" >&2; exit 1 ;; # # Exclude rather than extract variable list |
| 994 |
xtn_var=?* | extensive=?* | var_xtn=?* | extensive_variables=?* ) xtn_var="${LONG_OPTARG}" ;; # -x # Extensive variables |
| 995 |
xtr_nsp=?* | xtr_pnt_src_nbr=?* | extrap_num_src_pts=?* ) xtr_nsp_usr="${LONG_OPTARG}" ;; # # Extrapolation number of source points (for ESMF & NCO only) |
| 996 |
xtr_xpn=?* | xtr_dst_xpn=?* | extrap_dist_exponent=?* ) xtr_xpn_usr="${LONG_OPTARG}" ;; # # Extrapolation inverse-distance exponent (for ESMF & NCO only) |
| 997 |
'' ) break ;; # "--" terminates argument processing |
| 998 |
* ) printf "\nERROR: Unrecognized option ${fnt_bld}--${OPTARG}${fnt_nrm}\n" >&2; fnc_usg_prn ;; |
| 999 |
esac ;; # !OPTARG |
| 1000 |
\?) # Unrecognized option |
| 1001 |
printf "\nERROR: Option ${fnt_bld}-${OPTARG}${fnt_nrm} not recognized\n" >&2 |
| 1002 |
fnc_usg_prn ;; |
| 1003 |
esac # !OPT |
| 1004 |
done # !getopts |
| 1005 |
shift $((OPTIND-1)) # Advance one argument |
| 1006 |
psn_nbr=$# |
| 1007 |
if [ ${psn_nbr} -ge 1 ]; then |
| 1008 |
# 20200430 Input files as positional command-line arguments mean we need not check standard-input |
| 1009 |
inp_psn='Yes' |
| 1010 |
std_chk='No' |
| 1011 |
fi # !psn_nbr |
| 1012 |
if [ -n "${in_fl}" ]; then |
| 1013 |
# 20200430 Input file as single optional command-line argument means we need not check standard-input |
| 1014 |
inp_aut='Yes' |
| 1015 |
std_chk='No' |
| 1016 |
fi # !in_fl |
| 1017 |
if [ "${d2f_flg}" != 'Yes' ]; then |
| 1018 |
d2f_opt='' |
| 1019 |
fi # !d2f_flg |
| 1020 |
|
| 1021 |
# https://stackoverflow.com/questions/37056192/which-vs-command-v-in-bash |
| 1022 |
cmd_wgt_esmf=`command -v ${wgt_exe_esmf} --no_log 2> /dev/null` |
| 1023 |
cmd_cnv_mbt=`command -v ${cnv_exe_mbt} 2> /dev/null` |
| 1024 |
cmd_cnv_tps=`command -v ${cnv_exe_tps} 2> /dev/null` |
| 1025 |
cmd_dpt_mpas=`command -v ${dpt_exe_mpas} --no_log 2> /dev/null` |
| 1026 |
cmd_prt_mbt=`command -v ${prt_exe_mbt} 2> /dev/null` |
| 1027 |
cmd_wgt_cdo=`command -v ${wgt_exe_cdo} 2> /dev/null` |
| 1028 |
cmd_wgt_mbt=`command -v ${wgt_exe_mbt} 2> /dev/null` |
| 1029 |
cmd_wgt_nco=`command -v ${wgt_exe_nco} 2> /dev/null` |
| 1030 |
cmd_wgt_tps=`command -v ${wgt_exe_tps} 2> /dev/null` |
| 1031 |
cmd_msh_tps=`command -v ${msh_exe_tps} 2> /dev/null` |
| 1032 |
if [ ${vrs_prn} = 'Yes' ]; then |
| 1033 |
printf "${spt_nm}, the NCO regridder and grid, map, and weight-generator, version ${nco_vrs} \"${nco_sng}\"\n" |
| 1034 |
printf "Copyright (C) 2016--present Charlie Zender\n" |
| 1035 |
printf "This program is part of NCO, the netCDF Operators\n" |
| 1036 |
printf "NCO is free software and comes with a BIG FAT KISS and ABSOLUTELY NO WARRANTY\n" |
| 1037 |
printf "You may redistribute and/or modify NCO under the terms of the\n" |
| 1038 |
printf "3-Clause BSD License with exceptions described in the LICENSE file\n" |
| 1039 |
printf "BSD: https://opensource.org/licenses/BSD-3-Clause\n" |
| 1040 |
printf "LICENSE: https://github.com/nco/nco/tree/master/LICENSE\n" |
| 1041 |
printf "Config: ${spt_nm} script located in directory ${drc_spt}\n" |
| 1042 |
printf "Config: NCO binaries located in directory ${drc_nco}, linked to netCDF library version ${lbr_vrs}\n" |
| 1043 |
if [ "${hrd_pth_fnd}" = 'Yes' ]; then |
| 1044 |
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" |
| 1045 |
else |
| 1046 |
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" |
| 1047 |
fi # !hrd_pth_fnd |
| 1048 |
printf "Config: Grid & weight-generation tool availability:\n" |
| 1049 |
if [ -n "${cmd_wgt_cdo}" ]; then |
| 1050 |
printf "Config: CDO weight-generation command ${wgt_exe_cdo} found as ${cmd_wgt_cdo}\n" |
| 1051 |
else |
| 1052 |
printf "Config: CDO weight-generation command ${wgt_exe_cdo} not found\n" |
| 1053 |
fi # !err |
| 1054 |
if [ -n "${cmd_wgt_esmf}" ]; then |
| 1055 |
printf "Config: ESMF weight-generation command ${wgt_exe_esmf} found as ${cmd_wgt_esmf}\n" |
| 1056 |
else |
| 1057 |
printf "Config: ESMF weight-generation command ${wgt_exe_esmf} not found\n" |
| 1058 |
fi # !err |
| 1059 |
if [ -n "${cmd_wgt_mbt}" ]; then |
| 1060 |
printf "Config: MOAB-Tempest mesh- and weight-generation command ${wgt_exe_mbt} found as ${cmd_wgt_mbt}\n" |
| 1061 |
else |
| 1062 |
printf "Config: MOAB-Tempest mesh- and weight-generation command ${wgt_exe_mbt} not found\n" |
| 1063 |
fi # !err |
| 1064 |
if [ -n "${cmd_cnv_mbt}" ]; then |
| 1065 |
printf "Config: MOAB-Tempest SCRIP/Exodus conversion to H5M command ${cnv_exe_mbt} found as ${cmd_cnv_mbt}\n" |
| 1066 |
else |
| 1067 |
printf "Config: MOAB-Tempest SCRIP/Exodus conversion to H5M command ${cnv_exe_mbt} not found\n" |
| 1068 |
fi # !err |
| 1069 |
if [ -n "${cmd_prt_mbt}" ]; then |
| 1070 |
printf "Config: MOAB-Tempest H5M partition command ${prt_exe_mbt} found as ${cmd_prt_mbt}\n" |
| 1071 |
else |
| 1072 |
printf "Config: MOAB-Tempest H5M partition command ${prt_exe_mbt} not found\n" |
| 1073 |
fi # !err |
| 1074 |
if [ -n "${cmd_dpt_mpas}" ]; then |
| 1075 |
printf "Config: MPAS depth coordinate addition command ${dpt_exe_mpas} found as ${cmd_dpt_mpas}\n" |
| 1076 |
else |
| 1077 |
printf "Config: MPAS depth coordinate addition command ${dpt_exe_mpas} not found\n" |
| 1078 |
fi # !err |
| 1079 |
if [ -n "${cmd_wgt_nco}" ]; then |
| 1080 |
printf "Config: NCO mesh- and weight-generation command ${wgt_exe_nco} found as ${cmd_wgt_nco}\n" |
| 1081 |
else |
| 1082 |
printf "Config: NCO mesh- and weight-generation command ${wgt_exe_nco} not found\n" |
| 1083 |
fi # !err |
| 1084 |
if [ -n "${cmd_wgt_tps}" ]; then |
| 1085 |
printf "Config: TempestRemap weight-generation command ${wgt_exe_tps} found as ${cmd_wgt_tps}\n" |
| 1086 |
else |
| 1087 |
printf "Config: TempestRemap weight-generation command ${wgt_exe_tps} not found\n" |
| 1088 |
fi # !err |
| 1089 |
if [ -n "${cmd_msh_tps}" ]; then |
| 1090 |
printf "Config: TempestRemap mesh-generation command ${msh_exe_tps} found as ${cmd_msh_tps}\n" |
| 1091 |
else |
| 1092 |
printf "Config: TempestRemap weight-generation command ${msh_exe_tps} not found\n" |
| 1093 |
fi # !err |
| 1094 |
if [ -n "${cmd_cnv_tps}" ]; then |
| 1095 |
printf "Config: TempestRemap Mesh or SCRIP to Exodus conversion command ${cnv_exe_tps} found as ${cmd_cnv_tps}\n" |
| 1096 |
else |
| 1097 |
printf "Config: TempestRemap Mesh or SCRIP to Exodus conversion command ${cnv_exe_tps} not found\n" |
| 1098 |
fi # !err |
| 1099 |
exit 0 |
| 1100 |
fi # !vrs_prn |
| 1101 |
|
| 1102 |
# Detect input on pipe to stdin: |
| 1103 |
# http://stackoverflow.com/questions/2456750/detect-presence-of-stdin-contents-in-shell-script |
| 1104 |
# http://unix.stackexchange.com/questions/33049/check-if-pipe-is-empty-and-run-a-command-on-the-data-if-it-isnt |
| 1105 |
# 20170119 "if [ ! -t 0 ]" tests whether unit 0 (stdin) is connected to terminal, not whether pipe has data |
| 1106 |
# Non-interactive batch mode (e.g., qsub, sbatch) disconnects stdin from terminal and triggers false-positives with ! -t 0 |
| 1107 |
# 20170123 "if [ -p foo ]" tests whether foo exists and is a pipe or named pipe |
| 1108 |
# Non-interactive batch mode (i.e., sbatch) behaves as desired for -p /dev/stdin on SLURM |
| 1109 |
# Non-interactive batch mode (e.g., qsub) always returns true for -p /dev/stdin on PBS, leads to FALSE POSITIVES! |
| 1110 |
# This is because PBS uses stdin to set the job name |
| 1111 |
# Hence -p /dev/stdin test works everywhere tested except PBS non-interactive batch environment |
| 1112 |
# Check stdin if user has not explicitly disallowed it with --no_stdin |
| 1113 |
if [ "${std_chk}" = 'Yes' ]; then |
| 1114 |
if [ -n "${PBS_ENVIRONMENT}" ]; then |
| 1115 |
if [ "${PBS_ENVIRONMENT}" = 'PBS_BATCH' ]; then |
| 1116 |
# PBS batch detection suggested by OLCF ticket CCS #338970 on 20170127 |
| 1117 |
bch_pbs='Yes' |
| 1118 |
fi # !PBS_ENVIRONMENT |
| 1119 |
fi # !PBS |
| 1120 |
if [ -n "${SLURM_JOBID}" ] && [ -z "${SLURM_PTY_PORT}" ]; then |
| 1121 |
# SLURM batch detection suggested by NERSC ticket INC0096873 on 20170127 |
| 1122 |
bch_slr='Yes' |
| 1123 |
fi # !SLURM |
| 1124 |
if [ ${bch_pbs} = 'Yes' ] || [ ${bch_slr} = 'Yes' ]; then |
| 1125 |
# Batch environment |
| 1126 |
if [ ${bch_pbs} = 'Yes' ]; then |
| 1127 |
if [ ! -p /dev/stdin ]; then |
| 1128 |
# PBS batch jobs cause -p to return true except for stdin redirection |
| 1129 |
# When -p returns true we do not know whether stdin pipe contains any input |
| 1130 |
# User must explicitly indicate use of stdin pipes with --stdin option |
| 1131 |
# Redirection in PBS batch jobs unambiguously causes -p to return false |
| 1132 |
inp_std='Yes' |
| 1133 |
fi # !stdin |
| 1134 |
fi # !bch_slr |
| 1135 |
if [ ${bch_slr} = 'Yes' ]; then |
| 1136 |
if [ -p /dev/stdin ]; then |
| 1137 |
# SLURM batch jobs cause -p to return true for stdin pipes |
| 1138 |
# When -p returns false we do not know whether output was redirectd |
| 1139 |
# User must explicitly indicate use of redirection with --stdin option |
| 1140 |
# Stdin pipes in SLURM batch jobs unambiguously cause -p to return true |
| 1141 |
inp_std='Yes' |
| 1142 |
fi # !stdin |
| 1143 |
fi # !bch_slr |
| 1144 |
else # !bch |
| 1145 |
# Interactive environment |
| 1146 |
if [ -p /dev/stdin ] || [ ! -t 0 ]; then |
| 1147 |
# Interactive environments unambiguously cause -p to return true for stdin pipes |
| 1148 |
# Interactive environments unambiguously cause -t 0 to return false for stdin redirection |
| 1149 |
inp_std='Yes' |
| 1150 |
fi # !stdin |
| 1151 |
fi # !bch |
| 1152 |
if [ ${inp_std} = 'Yes' ] && [ ${inp_psn} = 'Yes' ]; then |
| 1153 |
echo "${spt_nm}: ERROR expecting input from both stdin and positional command-line arguments\n" |
| 1154 |
exit 1 |
| 1155 |
fi # !inp_std |
| 1156 |
fi # !std_chk |
| 1157 |
|
| 1158 |
# Derived variables |
| 1159 |
if [ -n "${drc_usr}" ]; then |
| 1160 |
chr_fst=${drc_usr:0:1} |
| 1161 |
if [ "${chr_fst}" = '-' ]; then |
| 1162 |
printf "${spt_nm}: WARNING first character of user-specified output directory drc_out is \"${chr_fst}\", which looks like an option itself. Be sure the ${spt_nm} '-O' option is followed by an argument that specifies the output directory for regridded files. The '-O' option requires a pathname argument, and should not be confused with the '-O' flag (which takes no argument) used in the rest of NCO to force overwriting files (${spt_nm} automatically overwrites existing output files).\n" |
| 1163 |
fi # !chr_fst |
| 1164 |
drc_out="${drc_usr%/}" |
| 1165 |
else |
| 1166 |
if [ -n "${out_fl}" ]; then |
| 1167 |
drc_out="$(dirname ${out_fl})" |
| 1168 |
fi # !out_fl |
| 1169 |
fi # !drc_usr |
| 1170 |
|
| 1171 |
if [ -n "${tmp_usr}" ]; then |
| 1172 |
# Fancy %/ syntax removes trailing slash (e.g., from $TMPDIR) |
| 1173 |
drc_tmp=${tmp_usr%/} |
| 1174 |
fi # !tmp_usr |
| 1175 |
dmm_fl="${drc_tmp}/ncremap_tmp_dmm.nc" # [sng] Dummy input file |
| 1176 |
grd_dst_dfl="${drc_tmp}/ncremap_tmp_grd_dst.nc" # [sng] Grid-file (destination) default |
| 1177 |
grd_dst_h5m_dfl="${drc_tmp}/ncremap_tmp_grd_dst_h5m.nc" # [sng] H5M Grid-file (destination) default |
| 1178 |
grd_dst_prt_dfl="${drc_tmp}/ncremap_tmp_grd_dst_h5m_prt.nc" # [sng] Partitioned H5M mesh (destination) default |
| 1179 |
grd_src_dfl="${drc_tmp}/ncremap_tmp_grd_src.nc" # [sng] Grid-file (source) default |
| 1180 |
grd_src_h5m_dfl="${drc_tmp}/ncremap_tmp_grd_src_h5m.nc" # [sng] H5M Grid-file (source) default |
| 1181 |
grd_src_prt_dfl="${drc_tmp}/ncremap_tmp_grd_src_h5m_prt.nc" # [sng] Partitioned H5M mesh (source) default |
| 1182 |
hnt_dst_fl="${drc_tmp}/ncremap_tmp_hnt_dst.txt" # [sng] Hint (for ERWG) destination |
| 1183 |
hnt_src_fl="${drc_tmp}/ncremap_tmp_hnt_src.txt" # [sng] Hint (for ERWG) source |
| 1184 |
ncwa_fl="${drc_tmp}/ncremap_tmp_ncwa.nc" # [sng] ncwa workflow (HIRDLS, MLS) default |
| 1185 |
nnt_fl="${drc_tmp}/ncremap_tmp_nnt.nc" # [sng] Annotated global datafile (RRG) default |
| 1186 |
rgn_fl="${drc_tmp}/ncremap_tmp_rgn.nc" # [sng] Regional file with coordinates (RRG) default |
| 1187 |
tmp_out_fl="${drc_tmp}/ncremap_tmp_out.nc" # [sng] Temporary output file |
| 1188 |
znl_fl="${drc_tmp}/ncremap_tmp_znl.nc" # [sng] Zonal workflow (HIRDLS, MLS) default |
| 1189 |
|
| 1190 |
if [ -n "${unq_usr}" ]; then |
| 1191 |
if [ "${unq_usr}" = 'noclean' ]; then |
| 1192 |
cln_flg='No' |
| 1193 |
else |
| 1194 |
if [ "${unq_usr}" = 'none' ] || [ "${unq_usr}" = 'nil' ]; then |
| 1195 |
unq_sfx="" |
| 1196 |
else # !unq_usr |
| 1197 |
unq_sfx="${unq_usr}" |
| 1198 |
fi # !unq_usr |
| 1199 |
fi # !unq_usr |
| 1200 |
fi # !unq_usr |
| 1201 |
dmm_fl=${dmm_fl}${unq_sfx} |
| 1202 |
grd_dst_h5m_tmp=${grd_dst_h5m_dfl}${unq_sfx} |
| 1203 |
grd_src_h5m_tmp=${grd_src_h5m_dfl}${unq_sfx} |
| 1204 |
grd_dst_prt_tmp=${grd_dst_prt_dfl}${unq_sfx} |
| 1205 |
grd_src_prt_tmp=${grd_src_prt_dfl}${unq_sfx} |
| 1206 |
grd_dst_dfl=${grd_dst_dfl}${unq_sfx} |
| 1207 |
grd_src_dfl=${grd_src_dfl}${unq_sfx} |
| 1208 |
hnt_dst_fl=${hnt_dst_fl}${unq_sfx} |
| 1209 |
hnt_src_fl=${hnt_src_fl}${unq_sfx} |
| 1210 |
ncwa_fl=${ncwa_fl}${unq_sfx} |
| 1211 |
nnt_fl=${nnt_fl}${unq_sfx} |
| 1212 |
rgn_fl=${rgn_fl}${unq_sfx} |
| 1213 |
tmp_out_fl=${tmp_out_fl}${unq_sfx} |
| 1214 |
znl_fl=${znl_fl}${unq_sfx} |
| 1215 |
|
| 1216 |
# Algorithm options are bilinear|conserve|conserve2nd|nearestdtos|neareststod|patch|traave|trbilin|trfv2|trintbilin|se2fv_flx|se2fv_stt|se2fv_alt|se2se|fv2se_flx|fv2se_stt|fv2se_alt|fv2fv_flx|fv2fv_stt|ncoaave|nco_con|ncoidw |
| 1217 |
if [ ${alg_typ} = 'cdo_con' ] || [ ${alg_typ} = 'cdo_cns' ] || [ ${alg_typ} = 'cdo_conserve' ] || [ ${alg_typ} = 'cdo' ]; then |
| 1218 |
alg_opt='gencon' |
| 1219 |
wgt_typ='cdo' |
| 1220 |
elif [ ${alg_typ} = 'cdo_bil' ] || [ ${alg_typ} = 'cdo_bilin' ] || [ ${alg_typ} = 'cdo_bilinear' ]; then |
| 1221 |
alg_opt='genbil' |
| 1222 |
wgt_typ='cdo' |
| 1223 |
elif [ ${alg_typ} = 'bilinear' ] || [ ${alg_typ} = 'esmfbilin' ] || [ ${alg_typ} = 'bilin' ] || [ ${alg_typ} = 'blin' ] || [ ${alg_typ} = 'bln' ]; then |
| 1224 |
alg_opt='bilinear' |
| 1225 |
wgt_typ='esmf' |
| 1226 |
# 20211118 Default to nearestidavg extrapolation with bilinear algorithm (as E3SM does), unless user explicitly specifies an extrapolation type |
| 1227 |
if [ -z "${esmf_typ}" ]; then |
| 1228 |
esmf_typ='nearestidavg' |
| 1229 |
fi # !esmf_typ |
| 1230 |
elif [ ${alg_typ} = 'conserve' ] || [ ${alg_typ} = 'esmfaave' ] || [ ${alg_typ} = 'conservative' ] || [ ${alg_typ} = 'cns' ] || [ ${alg_typ} = 'c1' ] || [ ${alg_typ} = 'aave' ]; then |
| 1231 |
alg_opt='conserve' |
| 1232 |
wgt_typ='esmf' |
| 1233 |
elif [ ${alg_typ} = 'conserve2nd' ] || [ ${alg_typ} = 'conservative2nd' ] || [ ${alg_typ} = 'c2' ] || [ ${alg_typ} = 'c2nd' ]; then |
| 1234 |
alg_opt='conserve2nd' |
| 1235 |
wgt_typ='esmf' |
| 1236 |
elif [ ${alg_typ} = 'nearestdtos' ] || [ ${alg_typ} = 'esmfndtos' ] || [ ${alg_typ} = 'ndtos' ] || [ ${alg_typ} = 'dtos' ] || [ ${alg_typ} = 'nds' ]; then |
| 1237 |
alg_opt='nearestdtos' |
| 1238 |
wgt_typ='esmf' |
| 1239 |
elif [ ${alg_typ} = 'neareststod' ] || [ ${alg_typ} = 'esmfnstod' ] || [ ${alg_typ} = 'nstod' ] || [ ${alg_typ} = 'stod' ] || [ ${alg_typ} = 'nsd' ]; then |
| 1240 |
alg_opt='neareststod' |
| 1241 |
wgt_typ='esmf' |
| 1242 |
elif [ ${alg_typ} = 'patch' ] || [ ${alg_typ} = 'patc' ] || [ ${alg_typ} = 'pch' ]; then |
| 1243 |
alg_opt='patch' |
| 1244 |
wgt_typ='esmf' |
| 1245 |
elif [ ${alg_typ} = 'se2fv_flx' ] || [ ${alg_typ} = 'mono_se2fv' ] || [ ${alg_typ} = 'conservative_monotone_se2fv' ]; then # alg_sng='mono' |
| 1246 |
# 20171108 'tempest' invokes TempestRemap with no automatic options, suitable for RLL re-mapping? |
| 1247 |
# 20171108 TempestRemap boutique options based on particular remapping type |
| 1248 |
# 20200221 Add --correct_areas to many TR maps as per Transition to TR page |
| 1249 |
# 20220928 Remove --correct_areas since TR 2.1.12 made this default and eliminated option |
| 1250 |
# 20220928 Replace --mono3 by --method mono3 since TR 2.1.14, 2.1.15 changed option name |
| 1251 |
# 20231130 Correct wgt_opt_mbt for alg_typ=tempest to use order = ${se_np_nbr} == 4 by default (since TR uses order=4) |
| 1252 |
# 20240110 Replace --method mono* by --mono* since MWF mode revealed some failures with --method mono* |
| 1253 |
# 20250604 Remove alg_typ=tempest because it is ambiguous and confused me, Walter H., and likely other users |
| 1254 |
# https://acme-climate.atlassian.net/wiki/spaces/Docs/pages/178848194/Transition+to+TempestRemap+for+Atmosphere+grids |
| 1255 |
# alg_sng in comments is for E3SM naming convention map_src_to_dst_${alg_sng}.${dt_sng}.nc |
| 1256 |
cnv_opt_src="-i GLOBAL_DOFS -r ${se_np_nbr}" |
| 1257 |
cnv_opt_dst="" |
| 1258 |
wgt_opt_mbt="--method cgll --order ${se_np_nbr} --global_id GLOBAL_DOFS --method fv --monotonicity 1 --global_id GLOBAL_ID" |
| 1259 |
wgt_opt_tps="--in_type cgll --in_np ${se_np_nbr} --out_type fv --mono" |
| 1260 |
alg_opt='se2fv_flx' |
| 1261 |
wgt_typ='tempest' |
| 1262 |
elif [ ${alg_typ} = 'se2fv_stt' ] || [ ${alg_typ} = 'highorder_se2fv' ] || [ ${alg_typ} = 'accurate_conservative_nonmonotone_se2fv' ]; then # alg_sng='highorder' |
| 1263 |
cnv_opt_src="-i GLOBAL_DOFS -r ${se_np_nbr}" |
| 1264 |
cnv_opt_dst="" |
| 1265 |
wgt_opt_mbt="--method cgll --order ${se_np_nbr} --method fv" |
| 1266 |
wgt_opt_tps="--in_type cgll --in_np ${se_np_nbr} --out_type fv" |
| 1267 |
alg_opt='se2fv_stt' |
| 1268 |
wgt_typ='tempest' |
| 1269 |
elif [ ${alg_typ} = 'se2fv_alt' ] || [ ${alg_typ} = 'intbilin_se2fv' ] || [ ${alg_typ} = 'accurate_monotone_nonconservative_se2fv' ]; then # alg_sng='intbilin' |
| 1270 |
cnv_opt_src="-i GLOBAL_DOFS -r ${se_np_nbr}" |
| 1271 |
cnv_opt_dst="" |
| 1272 |
wgt_opt_mbt="--method cgll --order ${se_np_nbr} --method fv --monotonicity 3 --noconserve" |
| 1273 |
wgt_opt_tps="--in_type cgll --in_np ${se_np_nbr} --out_type fv --mono3 --noconserve" |
| 1274 |
alg_opt='se2fv_alt' |
| 1275 |
wgt_typ='tempest' |
| 1276 |
elif [ ${alg_typ} = 'se2se' ] || [ ${alg_typ} = 'cs2cs' ] || [ ${alg_typ} = 'conservative_monotone_se2se' ]; then # alg_sng='se2se' |
| 1277 |
cnv_opt_src="-i GLOBAL_DOFS -r ${se_np_nbr}" |
| 1278 |
cnv_opt_dst="-i GLOBAL_DOFS -r ${se_np_nbr}" |
| 1279 |
# 20190227: Add mono for se2se per recommendation of Mark Taylor |
| 1280 |
wgt_opt_mbt="--method cgll --order ${se_np_nbr} --method cgll --order ${se_np_nbr} --monotonicity 1" |
| 1281 |
wgt_opt_tps="--in_type cgll --in_np ${se_np_nbr} --out_type cgll --out_np ${se_np_nbr} --mono" |
| 1282 |
alg_opt='se2se' |
| 1283 |
wgt_typ='tempest' |
| 1284 |
elif [ ${alg_typ} = 'fv2se_flx' ] || [ ${alg_typ} = 'monotr_fv2se' ] || [ ${alg_typ} = 'conservative_monotone_fv2se' ]; then # alg_sng='monotr' |
| 1285 |
# NB: Generate mono map for opposite direction regridding (i.e., reverse switches and grids), then transpose |
| 1286 |
cnv_opt_src="" |
| 1287 |
cnv_opt_dst="-i GLOBAL_DOFS -r ${se_np_nbr}" |
| 1288 |
wgt_opt_mbt="--method cgll --order ${se_np_nbr} --method fv --monotonicity 1" |
| 1289 |
wgt_opt_tps="--in_type cgll --in_np ${se_np_nbr} --out_type fv --mono" |
| 1290 |
alg_opt='fv2se_flx' |
| 1291 |
wgt_typ='tempest' |
| 1292 |
trn_map='Yes' |
| 1293 |
elif [ ${alg_typ} = 'fv2se_stt' ] || [ ${alg_typ} = 'highorder_fv2se' ] || [ ${alg_typ} = 'accurate_conservative_nonmonotone_fv2se' ]; then # alg_sng='highorder' |
| 1294 |
cnv_opt_src="" |
| 1295 |
cnv_opt_dst="-i GLOBAL_DOFS -r ${se_np_nbr}" |
| 1296 |
# 20190716: Remove "--volumetric" from fv2se_stt per Mark Taylor and Paul Ullrich |
| 1297 |
wgt_opt_mbt="--method fv --order 2 --method cgll --order ${se_np_nbr}" |
| 1298 |
wgt_opt_tps="--in_type fv --in_np 2 --out_type cgll --out_np ${se_np_nbr}" |
| 1299 |
alg_opt='fv2se_stt' |
| 1300 |
wgt_typ='tempest' |
| 1301 |
elif [ ${alg_typ} = 'fv2se_alt' ] || [ ${alg_typ} = 'mono_fv2se' ] || [ ${alg_typ} = 'conservative_monotone_fv2se_alt' ]; then # alg_sng='mono' |
| 1302 |
cnv_opt_src="" |
| 1303 |
cnv_opt_dst="-i GLOBAL_DOFS -r ${se_np_nbr}" |
| 1304 |
# 20200525: Remove "--volumetric" from fv2se_mono per Mark Taylor modifying Confluence instructions |
| 1305 |
wgt_opt_mbt="--method fv --order 1 --method cgll --order ${se_np_nbr} --monotonicity 1" |
| 1306 |
wgt_opt_tps="--in_type fv --in_np 1 --out_type cgll --out_np ${se_np_nbr} --mono" |
| 1307 |
alg_opt='fv2se_alt' |
| 1308 |
wgt_typ='tempest' |
| 1309 |
elif [ ${alg_typ} = 'fv2fv' ] || [ ${alg_typ} = 'rll2rll' ]; then # alg_sng='highorder' |
| 1310 |
cnv_opt_src="" |
| 1311 |
cnv_opt_dst="" |
| 1312 |
# 20190227: Add --mono3 --noconserve for fv2fv per (misinterpreted) recommendation of Mark Taylor |
| 1313 |
# 20200115: Replace --mono3 --noconserve with --in_np 2 per recommendation of Mark Taylor and Paul Ullrich |
| 1314 |
wgt_opt_mbt='--method fv --order 2 --method fv' |
| 1315 |
wgt_opt_tps='--in_type fv --in_np 2 --out_type fv' |
| 1316 |
alg_opt='fv2fv' |
| 1317 |
wgt_typ='tempest' |
| 1318 |
elif [ ${alg_typ} = 'fv2fv_flx' ] || [ ${alg_typ} = 'traave' ] || [ ${alg_typ} = 'fv2fv_mono' ] || [ ${alg_typ} = 'conservative_monotone_fv2fv' ]; then # alg_sng='traave' |
| 1319 |
cnv_opt_src="" |
| 1320 |
cnv_opt_dst="" |
| 1321 |
# 20191115: Add per recommendation of Paul Ullrich |
| 1322 |
# 20200221: Add --out_np 1 per (new?) settings in on Transition to TR page |
| 1323 |
# Classic cell-integrated piecewise constant map similar to aave and nco_con |
| 1324 |
wgt_opt_mbt='--method fv --order 1 --method fv --order 1' |
| 1325 |
wgt_opt_tps='--in_type fv --in_np 1 --out_type fv --out_np 1' |
| 1326 |
alg_opt='fv2fv_flx' |
| 1327 |
wgt_typ='tempest' |
| 1328 |
elif [ ${alg_typ} = 'trfv2' ] || [ ${alg_typ} = 'trfvnp2' ]; then # alg_sng='trfv2' |
| 1329 |
cnv_opt_src="" |
| 1330 |
cnv_opt_dst="" |
| 1331 |
# 20231129: E3SMv3 recommended for fluxes when source grid resolution uniformly is _not_ >> target grid resolution (e.g., ne30pg2->r05), i.e., coarse->fine |
| 1332 |
# 20231129: E3SMv3 recommended for states when source grid resolution uniformly << target grid resolution (e.g., ne30pg2->r05), i.e., coarse->fine |
| 1333 |
# 2nd order FV reconstruction, cell integrated on target grid (conservative, though not monotone unless used with FV2+CAAS method) |
| 1334 |
# https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/178848194/Recommended+Mapping+Procedures+for+E3SM+Atmosphere+Grids |
| 1335 |
# https://acme-climate.atlassian.net/wiki/spaces/COM/pages/3771301899/Coupler+High-order+property-preserving+maps |
| 1336 |
wgt_opt_mbt='--method fv --order 2 --method fv --order 1 --fvmethod normalize' |
| 1337 |
wgt_opt_tps='--in_type fv --in_np 2 --out_type fv --out_np 1 --method normalize' |
| 1338 |
alg_opt='trfv2' |
| 1339 |
wgt_typ='tempest' |
| 1340 |
elif [ ${alg_typ} = 'fv2fv_stt' ] || [ ${alg_typ} = 'fv2fv_highorder' ] || [ ${alg_typ} = 'accurate_conservative_nonmonotone_fv2fv' ]; then # alg_sng='highorder' |
| 1341 |
cnv_opt_src="" |
| 1342 |
cnv_opt_dst="" |
| 1343 |
# 20191115: Add per recommendation of Paul Ullrich |
| 1344 |
# --in_np 2 means all nearest neighbor cells will be used for higher order reconstruction of source data, which is then integrated over target cell. Unlike SE case, no mass matrix is used for FV target grids, and thus --out_np is ignored (and will always be 1 internally). |
| 1345 |
wgt_opt_mbt='--method fv --order 2 --method fv' |
| 1346 |
wgt_opt_tps='--in_type fv --in_np 2 --out_type fv' |
| 1347 |
alg_opt='fv2fv_stt' |
| 1348 |
wgt_typ='tempest' |
| 1349 |
elif [ ${alg_typ} = 'trbilin' ]; then # alg_sng='trbilin' |
| 1350 |
# 20231001: Added with options per https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/1217757434/Mapping+file+algorithms+and+naming+convention |
| 1351 |
cnv_opt_src="" |
| 1352 |
cnv_opt_dst="" |
| 1353 |
wgt_opt_mbt='--method fv --method fv --order 1 --order 1 --fvmethod bilin' |
| 1354 |
wgt_opt_tps='--in_type fv --out_type fv --method bilin' |
| 1355 |
alg_opt='trbilin' |
| 1356 |
wgt_typ='tempest' |
| 1357 |
elif [ ${alg_typ} = 'trintbilin' ]; then # alg_sng='trintbilin' |
| 1358 |
# 20231001: Added with options per https://acme-climate.atlassian.net/wiki/spaces/DOC/pages/1217757434/Mapping+file+algorithms+and+naming+convention |
| 1359 |
cnv_opt_src="" |
| 1360 |
cnv_opt_dst="" |
| 1361 |
wgt_opt_mbt='--method fv --method fv --order 1 --order 1 --fvmethod intbilin' |
| 1362 |
wgt_opt_tps='--in_type fv --out_type fv --method intbilin' |
| 1363 |
alg_opt='trintbilin' |
| 1364 |
wgt_typ='tempest' |
| 1365 |
elif [ ${alg_typ} = 'nco_con' ] || [ ${alg_typ} = 'ncoaave' ] || [ ${alg_typ} = 'nco_cns' ] || [ ${alg_typ} = 'nco_conserve' ] || [ ${alg_typ} = 'nco' ]; then # alg_sng='ncoaave' |
| 1366 |
alg_opt='ncoaave' |
| 1367 |
wgt_typ='nco' |
| 1368 |
elif [ ${alg_typ} = 'nco_idw' ] || [ ${alg_typ} = 'ncoidw' ] || [ ${alg_typ} = 'nco_dwe' ] || [ ${alg_typ} = 'dwe' ] || [ ${alg_typ} = 'idw' ] || [ ${alg_typ} = 'nco_distance_weighted' ] || [ ${alg_typ} = 'nco_nearest_neighbor' ]; then |
| 1369 |
alg_opt='ncoidw' |
| 1370 |
wgt_typ='nco' |
| 1371 |
else |
| 1372 |
echo "${spt_nm}: ERROR ${alg_typ} is not a valid weight-generation algorithm" |
| 1373 |
echo "${spt_nm}: HINT Valid CDO weight-generation algorithms and synonyms are cdo_bil,cdo_bilin,cdo_bilinear | cdo_con,cdo_cns,cdo_conserve" |
| 1374 |
echo "${spt_nm}: HINT Valid ESMF weight-generation algorithms and synonyms are esmfbilin,bilinear,bilin,bln | esmfaave,conserve,cns,c1,aave | conserve2nd,c2,c2nd | nearestdtos,nds,dtos | neareststod,nsd,stod | patch,pch" |
| 1375 |
echo "${spt_nm}: HINT Valid NCO weight-generation algorithms and synonyms are ncoaave,nco_con,nco_cns,nco_conserve,nco | nco_idw,nco_dwe" |
| 1376 |
echo "${spt_nm}: HINT Valid TempestRemap (and MOAB-TempestRemap) weight-generation options and synonyms are traave,fv2fv_flx,fv2fv_mono | trbilin | trfv2 | trintbilin | se2fv_flx,mono_se2fv | se2fv_stt,highorder_se2fv | se2fv_alt,intbilin | se2se,cs2cs | fv2se_flx,monotr_fv2se | fv2se_stt,highorder_fv2se | fv2se_alt,mono_fv2se | fv2fv,rll2rll" |
| 1377 |
exit 1 |
| 1378 |
fi # !alg_typ |
| 1379 |
|
| 1380 |
if [ -n "${mpi_nbr_usr}" ]; then |
| 1381 |
mpi_nbr=${mpi_nbr_usr} |
| 1382 |
fi # !mpi_nbr_usr |
| 1383 |
# Specifying a TR algorithm and explicitly setting mpi_nbr implies MOAB |
| 1384 |
if [ ${wgt_typ} = 'tempest' ] && [ -n "${mpi_nbr_usr}" ]; then |
| 1385 |
wgt_typ='mbtempest' |
| 1386 |
fi # !wgt_typ |
| 1387 |
# If user explicitly sets mpi_nbr then we need a prefix |
| 1388 |
if [ -n "${mpi_nbr_usr}" ]; then |
| 1389 |
# ...then set prefix for invoking MPI-enabled weight generators |
| 1390 |
case "${HOSTNAME}" in |
| 1391 |
andes* ) mpi_pfx="srun -n ${mpi_nbr}" ; ;; |
| 1392 |
bebop* | blogin* | b[0123456789][0123456789][0123456789] ) mpi_pfx="mpirun -n ${mpi_nbr}" ; ;; |
| 1393 |
chrysalis* | chrlogin* | chr-[0123456789][0123456789][0123456789][0123456789] ) mpi_pfx="srun -n ${mpi_nbr}" ; ;; |
| 1394 |
compy* | n[0123456789][0123456789][0123456789][0123456789] ) mpi_pfx="srun --mpi=pmi2 -n ${mpi_nbr}" ; ;; |
| 1395 |
constance* | node* ) mpi_pfx="mpirun -n ${mpi_nbr}" ; ;; |
| 1396 |
*derecho* ) mpi_pfx="mpirun -n ${mpi_nbr}" ; ;; |
| 1397 |
frontier* ) mpi_pfx="srun -n ${mpi_nbr}" ; ;; |
| 1398 |
ilogin* | i[0123456789][0123456789][0123456789] ) mpi_pfx="mpirun -n ${mpi_nbr}" ; ;; |
| 1399 |
login[0123456789][0123456789] ) mpi_pfx="srun -n ${mpi_nbr}" ; ;; |
| 1400 |
perlmutter* | nid[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789] ) mpi_pfx="srun -n ${mpi_nbr}" ; ;; |
| 1401 |
# 20250122: Shift default node manager from mpirun to srun |
| 1402 |
# * ) mpi_pfx="mpirun -n ${mpi_nbr}" ; ;; # Default |
| 1403 |
* ) mpi_pfx="srun -n ${mpi_nbr}" ; ;; # Default |
| 1404 |
esac # !HOSTNAME |
| 1405 |
fi # !mpi_nbr |
| 1406 |
if [ -n "${mpi_pfx_usr}" ]; then |
| 1407 |
mpi_pfx="${mpi_pfx_usr}" |
| 1408 |
fi # !mpi_pfx_usr |
| 1409 |
# If MPI will be used, adjust partition number be a multiple of mpi_nbr |
| 1410 |
if [ -n "${mpi_pfx}" ]; then |
| 1411 |
if [ ${prt_nbr} -lt ${mpi_nbr} ]; then |
| 1412 |
[[ ${dbg_lvl} -ge 1 ]] && echo "${spt_nm}: INFO Increasing partition number from ${prt_nbr} to ${mpi_nbr}" |
| 1413 |
prt_nbr=${mpi_nbr} |
| 1414 |
fi # !prt_nbr |
| 1415 |
let prt_nbr_rmd=${prt_nbr}%${mpi_nbr} |
| 1416 |
if [ ${prt_nbr_rmd} -ne 0 ]; then |
| 1417 |
echo "${spt_nm}: ERROR Partition number prt_nbr=${prt_nbr} must be > 1 and <= mpi_nbr=${mpi_nbr}" |
| 1418 |
echo "${spt_nm}: HINT Set partition number with --prt_nbr=${mpi_nbr} unless otherwise warranted" |
| 1419 |
exit 1 |
| 1420 |
fi # !prt_nbr_rmd |
| 1421 |
fi # !mpi_pfx |
| 1422 |
|
| 1423 |
# ERWG requires special handling for version-specific options |
| 1424 |
# 20210705: Avoid invoking ERWG to determine version unless actual algorithm requires ERWG |
| 1425 |
if [ ${wgt_typ} = 'esmf' ]; then |
| 1426 |
# 20180830 Add --ignore_degenerate to default ERWG options for ESMF >= 7.1.0r |
| 1427 |
# 20181114 Add --no_log so ERWG does not try to write logfile into current (possibly write-protected) directory |
| 1428 |
erwg_vrs_sng=`${mpi_pfx} ${wgt_exe_esmf} --no_log --version | grep ESMF_VERSION_STRING | cut -f 2 -d ':'` |
| 1429 |
# Remove whitespace, answer should be something like "7.1.0r" or "6.3.0rp1" |
| 1430 |
erwg_vrs_sng="${erwg_vrs_sng#"${erwg_vrs_sng%%[![:space:]]*}"}" |
| 1431 |
# Extract first character |
| 1432 |
erwg_vrs_mjr="${erwg_vrs_sng:0:1}" |
| 1433 |
if [ -z "${erwg_vrs_mjr}" ]; then |
| 1434 |
# Version can fail when ERWG fails, e.g., due to dynamic link issues |
| 1435 |
printf "${spt_nm}: WARNING ${wgt_exe_esmf} (ERWG) found though does not run as expected. Possible dynamic linking issue due, e.g., to LD_LIBRARY_PATH configuration. Unable to determine ERWG version. ERWG may not be needed so continuing anyway...\n" |
| 1436 |
erwg_vrs_sng='ERWG_VERSION_NOT_FOUND' |
| 1437 |
erwg_vrs_mjr=7 |
| 1438 |
elif [ "${erwg_vrs_mjr}" -ge 7 ]; then |
| 1439 |
wgt_opt_esmf="${wgt_opt_esmf} --ignore_degenerate" |
| 1440 |
fi # !erwg_vrs_mjr |
| 1441 |
fi # !err |
| 1442 |
|
| 1443 |
if [ -n "${fl_fmt}" ]; then |
| 1444 |
if [ "${fl_fmt}" = '3' ] || [ "${fl_fmt}" = 'classic' ] || [ "${fl_fmt}" = 'netcdf3' ]; then |
| 1445 |
nco_fl_fmt='--fl_fmt=classic' |
| 1446 |
wgt_opt_tps="${wgt_opt_tps} --out_format Classic" |
| 1447 |
msh_opt_tps="${msh_opt_tps} --out_format Classic" |
| 1448 |
[[ ${wgt_typ} = 'mbtempest' ]] && map_nfo_sng="INFO: MOAB/mbtempest does not support writing map-file as requested type ${fmt_sng_nc3}, will write ${fmt_sng_nc4} instead" |
| 1449 |
elif [ "${fl_fmt}" = '4' ] || [ "${fl_fmt}" = 'netcdf4' ] || [ "${fl_fmt}" = 'hdf5' ]; then |
| 1450 |
nco_fl_fmt='--fl_fmt=netcdf4' |
| 1451 |
wgt_opt_esmf="${wgt_opt_esmf} --netcdf4" |
| 1452 |
wgt_opt_tps="${wgt_opt_tps} --out_format Netcdf4" |
| 1453 |
msh_opt_tps="${msh_opt_tps} --out_format Netcdf4" |
| 1454 |
elif [ "${fl_fmt}" = '5' ] || [ "${fl_fmt}" = '64bit_data' ] || [ "${fl_fmt}" = 'cdf5' ]; then |
| 1455 |
nco_fl_fmt='--fl_fmt=64bit_data' |
| 1456 |
wgt_opt_esmf="${wgt_opt_esmf} --netcdf4" # Change when ERWG supports CDF5 |
| 1457 |
wgt_opt_tps="${wgt_opt_tps} --out_format Netcdf4" |
| 1458 |
msh_opt_tps="${msh_opt_tps} --out_format Netcdf4" |
| 1459 |
[[ ${wgt_typ} != 'nco' ]] && map_nfo_sng="INFO: ${wgt_typ} does not support writing requested map-file as requested type ${fmt_sng_nc5}, will write ${fmt_sng_nc4} instead" |
| 1460 |
elif [ "${fl_fmt}" = '6' ] || [ "${fl_fmt}" = '64bit_offset' ] || [ "${fl_fmt}" = '64' ]; then |
| 1461 |
nco_fl_fmt='--fl_fmt=64bit_offset' |
| 1462 |
wgt_opt_esmf="${wgt_opt_esmf} --64bit_offset" |
| 1463 |
wgt_opt_tps="${wgt_opt_tps} --out_format Offset64Bits" |
| 1464 |
msh_opt_tps="${msh_opt_tps} --out_format Offset64Bits" |
| 1465 |
[[ ${wgt_typ} = 'mbtempest' ]] && map_nfo_sng="INFO: MOAB/mbtempest does not support writing requested map-file as requested type ${fmt_sng_nc6}, will write ${fmt_sng_nc4} instead" |
| 1466 |
elif [ "${fl_fmt}" = '7' ] || [ "${fl_fmt}" = 'netcdf4_classic' ]; then |
| 1467 |
nco_fl_fmt='--fl_fmt=netcdf4_classic' |
| 1468 |
wgt_opt_esmf="${wgt_opt_esmf} --netcdf4" # Change when ERWG supports netCDF7 |
| 1469 |
wgt_opt_tps="${wgt_opt_tps} --out_format Netcdf4Classic" |
| 1470 |
msh_opt_tps="${msh_opt_tps} --out_format Netcdf4Classic" |
| 1471 |
[[ ${wgt_typ} != 'nco' ]] && map_nfo_sng="INFO: ${wgt_typ} does not support writing requested map-file as requested type ${fmt_sng_nc7}, will write ${fmt_sng_nc4} instead" |
| 1472 |
else # !fl_fmt |
| 1473 |
echo "${spt_nm}: ERROR User-supplied file-format specifier fl_fmt='${fl_fmt}' is invalid" |
| 1474 |
echo "${spt_nm}: HINT Valid format-specifiers include '3', '4', '5', '6', and '7'" |
| 1475 |
exit 1 |
| 1476 |
fi # !fl_fmt |
| 1477 |
nco_opt="${nco_fl_fmt} ${nco_opt}" |
| 1478 |
fi # !fl_fmt |
| 1479 |
|
| 1480 |
if [ -n "${nsx_alg}" ]; then |
| 1481 |
if [ "${nsx_alg}" = 'adv' ] || [ "${nsx_alg}" = 'advfront' ] || [ "${nsx_alg}" = 'advancing_front' ]; then |
| 1482 |
wgt_opt_mbt="--advfront ${wgt_opt_mbt}" |
| 1483 |
elif [ "${nsx_alg}" = 'kd' ] || [ "${nsx_alg}" = 'kdtree' ]; then |
| 1484 |
wgt_opt_mbt="${wgt_opt_mbt}" # Kd-tree is default in mbtempest |
| 1485 |
else |
| 1486 |
echo "${spt_nm}: ERROR User-supplied intersection algorithm specifier nsx_alg='${nsx_alg}' is invalid" |
| 1487 |
echo "${spt_nm}: HINT Valid intersection algorithm specifiers include 'advfront' and 'kdtree'" |
| 1488 |
exit 1 |
| 1489 |
fi # !nsx_alg |
| 1490 |
fi # !nsx_alg |
| 1491 |
if [ -n "${xtr_nsp_usr}" ]; then |
| 1492 |
xtr_nsp=${xtr_nsp_usr} |
| 1493 |
fi # !xtr_nsp_usr |
| 1494 |
if [ -n "${xtr_xpn_usr}" ]; then |
| 1495 |
xtr_xpn=${xtr_xpn_usr} |
| 1496 |
fi # !xtr_xpn_usr |
| 1497 |
|
| 1498 |
if [ -n "${esmf_typ}" ]; then |
| 1499 |
# Configure ERWG options, if necessary |
| 1500 |
if [ ${esmf_typ} = 'neareststod' ] || [ ${esmf_typ} = 'stod' ] || [ ${esmf_typ} = 'nsd' ]; then |
| 1501 |
esmf_opt='neareststod' |
| 1502 |
elif [ ${esmf_typ} = 'nearestidavg' ] || [ ${esmf_typ} = 'idavg' ] || [ ${esmf_typ} = 'id' ]; then |
| 1503 |
esmf_opt='nearestidavg' |
| 1504 |
elif [ ${esmf_typ} = 'none' ] || [ ${esmf_typ} = 'nil' ] || [ ${esmf_typ} = 'nowaydude' ]; then |
| 1505 |
esmf_opt='none' |
| 1506 |
else |
| 1507 |
echo "${spt_nm}: ERROR ${esmf_typ} is not a valid extrapolation method" |
| 1508 |
echo "${spt_nm}: HINT Valid ESMF extrapolation methods and synonyms are neareststod,stod,nsd | nearestidavg,idavg,id | none,nil" |
| 1509 |
exit 1 |
| 1510 |
fi # !esmf_typ |
| 1511 |
wgt_opt_esmf="${wgt_opt_esmf} --extrap_method ${esmf_opt} --extrap_num_src_pnts ${xtr_nsp} --extrap_dist_exponent ${xtr_xpn}" |
| 1512 |
fi # !esmf_typ |
| 1513 |
|
| 1514 |
if [ ${wgt_typ} = 'cdo' ]; then |
| 1515 |
wgt_cmd="${wgt_exe_cdo}" |
| 1516 |
wgt_exe="${wgt_exe_cdo}" |
| 1517 |
wgt_opt="${wgt_opt_cdo}" |
| 1518 |
elif [ ${wgt_typ} = 'esmf' ]; then |
| 1519 |
wgt_cmd="${wgt_exe_esmf}" |
| 1520 |
wgt_exe="${wgt_exe_esmf}" |
| 1521 |
wgt_opt="${wgt_opt_esmf}" |
| 1522 |
elif [ ${wgt_typ} = 'nco' ]; then |
| 1523 |
if [ "${alg_opt}" = 'ncoidw' ]; then |
| 1524 |
wgt_opt_nco="${wgt_opt_nco} --rgr wgt_typ=${alg_opt} --rgr xtr_nsp=${xtr_nsp} --rgr xtr_xpn=${xtr_xpn}" |
| 1525 |
fi # alg_opt |
| 1526 |
wgt_cmd="${wgt_exe_nco}" |
| 1527 |
wgt_exe="${wgt_exe_nco}" |
| 1528 |
wgt_opt="${wgt_opt_nco}" |
| 1529 |
elif [ ${wgt_typ} = 'mbtempest' ]; then |
| 1530 |
wgt_cmd="${wgt_exe_mbt}" |
| 1531 |
wgt_exe="${wgt_exe_mbt}" |
| 1532 |
wgt_opt="${wgt_opt_mbt}" |
| 1533 |
elif [ ${wgt_typ} = 'tempest' ]; then |
| 1534 |
wgt_cmd="${wgt_exe_tps}" |
| 1535 |
wgt_exe="${wgt_exe_tps}" |
| 1536 |
wgt_opt="${wgt_opt_tps}" |
| 1537 |
else |
| 1538 |
echo "${spt_nm}: ERROR ${wgt_typ} is not a valid weight-type" |
| 1539 |
exit 1 |
| 1540 |
fi # !wgt_typ |
| 1541 |
# NB: Define after wgt_typ-block so user can override default options |
| 1542 |
if [ -n "${wgt_opt_usr}" ]; then |
| 1543 |
wgt_opt=${wgt_opt_usr} |
| 1544 |
fi # !wgt_opt_usr |
| 1545 |
if [ -n "${mpi_pfx}" ]; then |
| 1546 |
if [ ${wgt_typ} = 'esmf' ] || [ ${wgt_typ} = 'mbtempest' ]; then |
| 1547 |
wgt_cmd="${mpi_pfx} ${wgt_cmd}" |
| 1548 |
fi # !wgt_typ |
| 1549 |
fi # !mpi_pfx |
| 1550 |
if [ -n "${wgt_usr}" ]; then |
| 1551 |
wgt_cmd=${wgt_usr} |
| 1552 |
fi # !wgt_usr |
| 1553 |
|
| 1554 |
if [ -z "${drc_in}" ]; then |
| 1555 |
drc_in="${drc_pwd}" |
| 1556 |
else # !drc_in |
| 1557 |
if [ ! -d "${drc_in}" ]; then |
| 1558 |
echo "${spt_nm}: ERROR specified input directory \"${drc_in}\" does not exist" |
| 1559 |
exit 1 |
| 1560 |
fi # !drc_in |
| 1561 |
drc_in_usr_flg='Yes' |
| 1562 |
fi # !drc_in |
| 1563 |
if [ -n "${job_usr}" ]; then |
| 1564 |
job_nbr="${job_usr}" |
| 1565 |
fi # !job_usr |
| 1566 |
if [ -n "${mss_val_usr}" ]; then |
| 1567 |
mss_val=${mss_val_usr} |
| 1568 |
att_flg='Yes' |
| 1569 |
fi # !mss_val_usr |
| 1570 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 1571 |
nco_opt="--dbg_lvl=${dbg_lvl} ${nco_opt}" |
| 1572 |
fi # !dbg_lvl |
| 1573 |
if [ -n "${cmp_sng}" ]; then |
| 1574 |
# 20230623: Insert backslashes to protect pipe characters from shell |
| 1575 |
nco_opt="${nco_opt} --cmp=${cmp_sng//\|/\\|}" |
| 1576 |
fi # !cmp_sng |
| 1577 |
if [ -n "${bfr_sz}" ]; then |
| 1578 |
nco_opt="${nco_opt} --bfr_sz=${bfr_sz}" |
| 1579 |
fi # !bfr_sz |
| 1580 |
if [ -n "${col_dmn}" ]; then |
| 1581 |
rgr_opt="${rgr_opt} --rgr col_nm=${col_dmn}" |
| 1582 |
fi # !col_dmn |
| 1583 |
if [ -n "${dfl_lvl}" ]; then |
| 1584 |
nco_opt="${nco_opt} --dfl_lvl=${dfl_lvl}" |
| 1585 |
fi # !dfl_lvl |
| 1586 |
if [ -n "${qnt_prc}" ]; then |
| 1587 |
nco_opt="${nco_opt} --qnt default=${qnt_prc}" |
| 1588 |
fi # !qnt_prc |
| 1589 |
if [ "${dvn_flg}" = 'Yes' ]; then |
| 1590 |
# 20210926 Omit 2>&1 since better for user to see error messages |
| 1591 |
# 20210926 Add 2>&1 to quiet unruly non-error output from mbconvert |
| 1592 |
[[ ${dbg_lvl} -eq 0 ]] && devnull="${devnulll} 2>&1" |
| 1593 |
devnull=' > /dev/null' |
| 1594 |
else |
| 1595 |
devnull='' |
| 1596 |
fi # !dfl_lvl |
| 1597 |
if [ -n "${hdr_pad}" ]; then |
| 1598 |
nco_opt="${nco_opt} --hdr_pad=${hdr_pad}" |
| 1599 |
fi # !hdr_pad |
| 1600 |
if [ -n "${uio_flg}" ]; then |
| 1601 |
nco_opt="${nco_opt} --unbuffered_io" |
| 1602 |
fi # !uio_flg |
| 1603 |
if [ -n "${gaa_sng}" ]; then |
| 1604 |
nco_opt="${nco_opt} ${gaa_sng}" |
| 1605 |
fi # !gaa_sng |
| 1606 |
if [ -n "${gaa_sng}" ]; then |
| 1607 |
nco_opt="${nco_opt} ${gad_sng}" |
| 1608 |
fi # !gad_sng |
| 1609 |
if [ "${no_cll_msr}" = 'Yes' ]; then |
| 1610 |
nco_opt="${nco_opt} --no_cll_msr" |
| 1611 |
fi # !no_cll_msr |
| 1612 |
if [ "${no_frm_trm}" = 'Yes' ]; then |
| 1613 |
nco_opt="${nco_opt} --no_frm_trm" |
| 1614 |
fi # !no_frm_trm |
| 1615 |
if [ "${msk_apl}" = 'Yes' ]; then |
| 1616 |
rgr_opt="${rgr_opt} --rgr mask_apply" |
| 1617 |
fi # !msk_apl |
| 1618 |
if [ -n "${prs_stt_usr}" ]; then |
| 1619 |
if [ "${prs_stt_usr}" = 'mean' ] || [ "${prs_stt_usr}" = 'local' ] || [ "${prs_stt_usr}" = 'local_mean' ] || [ "${prs_stt_usr}" = 'gridcell' ] || [ "${prs_stt_usr}" = 'gridcell_mean' ] || [ "${prs_stt_usr}" = 'natural_values' ]; then |
| 1620 |
prs_stt='mean' |
| 1621 |
elif [ "${prs_stt_usr}" = 'integral' ] || [ "${prs_stt_usr}" = 'global' ] || [ "${prs_stt_usr}" = 'global_integral' ]; then |
| 1622 |
prs_stt='integral' |
| 1623 |
else |
| 1624 |
echo "${spt_nm}: ERROR \"${prs_stt_usr}\" is an invalid value for preserved_statistic" |
| 1625 |
echo "${spt_nm}: HINT The valid values for preserved_statistic are \"mean\" (or synonyms \"local\", \"local_mean\") and \"integral\" (or synonyms \"global\", \"global_integral\")" |
| 1626 |
exit 1 |
| 1627 |
fi # !prs_stt_usr |
| 1628 |
if [ "${prs_stt}" = 'mean' ] && [ -z "${rnr_thr}" ]; then |
| 1629 |
rnr_thr=0.0 |
| 1630 |
fi # !prs_stt |
| 1631 |
if [ "${prs_stt}" = 'integral' ] && [ -n "${rnr_thr}" ]; then |
| 1632 |
if [ "${rnr_thr}" != 'off' ] && [ "${rnr_thr}" != 'none' ]; then |
| 1633 |
echo "${spt_nm}: ERROR preserved_statistic = \"${prs_stt}\" conflicts with rnr_thr=${rnr_thr}" |
| 1634 |
echo "${spt_nm}: HINT Explicitly specifying \"integral\" for the preserved-statistic is the same as turning-off renormalization so do not specify any value for renormalization" |
| 1635 |
exit 1 |
| 1636 |
fi # !rnr_thr |
| 1637 |
fi # !prs_stt |
| 1638 |
fi # !prs_stt_usr |
| 1639 |
if [ -n "${var_lst}" ]; then |
| 1640 |
if [ "${xcl_flg}" = 'Yes' ]; then |
| 1641 |
nco_var_lst="-x -v ${var_lst}" |
| 1642 |
else |
| 1643 |
nco_var_lst="-v ${var_lst}" |
| 1644 |
fi # !xcl_flg |
| 1645 |
nco_var_lst_hrz=${nco_var_lst} |
| 1646 |
fi # !var_lst |
| 1647 |
if [ -n "${area_dgn}" ]; then |
| 1648 |
nco_dgn_area="--rgr diagnose_area" |
| 1649 |
fi # !area_dgn |
| 1650 |
if [ -n "${msk_dst}" ]; then |
| 1651 |
nco_msk_dst="--rgr msk_var=${msk_dst}" |
| 1652 |
fi # !msk_dst |
| 1653 |
if [ "${msk_out}" != 'No' ]; then |
| 1654 |
nco_msk_out="--rgr msk_nm=${msk_out}" |
| 1655 |
fi # !msk_out |
| 1656 |
if [ -n "${msk_src}" ]; then |
| 1657 |
nco_msk_src="--rgr msk_var=${msk_src}" |
| 1658 |
fi # !msk_src |
| 1659 |
if [ -n "${skl_fl}" ]; then |
| 1660 |
nco_skl_fl="--rgr skl=\"${skl_fl}\"" |
| 1661 |
fi # !skl_fl |
| 1662 |
if [ -n "${ugrid_fl}" ]; then |
| 1663 |
nco_ugrid_fl="--rgr ugrid=\"${ugrid_fl}\"" |
| 1664 |
fi # !ugrid_fl |
| 1665 |
if [ -n "${var_rgr}" ]; then |
| 1666 |
nco_var_rgr="--rgr_var=${var_rgr}" |
| 1667 |
fi # !var_rgr |
| 1668 |
if [ -n "${xtn_var}" ]; then |
| 1669 |
rgr_opt="${rgr_opt} --xtn=${xtn_var}" |
| 1670 |
fi # !xtn_var |
| 1671 |
if [ -n "${out_fl}" ]; then |
| 1672 |
out_usr_flg='Yes' |
| 1673 |
fi # !out_fl |
| 1674 |
if [ "${par_typ}" = ${par_bck} ] || [[ "${par_typ}" =~ [bB]ck ]] || [[ "${par_typ}" =~ [bB]ackground ]]; then |
| 1675 |
par_typ=${par_bck} |
| 1676 |
par_opt=' &' |
| 1677 |
elif [ "${par_typ}" = ${par_mpi} ] || [[ "${par_typ}" =~ (mpi|MPI) ]]; then |
| 1678 |
par_typ=${par_mpi} |
| 1679 |
par_opt=' &' |
| 1680 |
mpi_flg='Yes' |
| 1681 |
elif [ "${par_typ}" = ${par_srl} ] || [ "${par_typ}" = 'srl' ] || [[ "${par_typ}" =~ [sS]erial ]] || [[ "${par_typ}" =~ [nN]il ]] || [[ "${par_typ}" =~ [nN]one ]]; then |
| 1682 |
par_typ=${par_srl} |
| 1683 |
else |
| 1684 |
echo "ERROR: Invalid -p par_typ option = ${par_typ}" |
| 1685 |
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." |
| 1686 |
exit 1 |
| 1687 |
fi # !par_typ |
| 1688 |
if [ -n "${prc_typ}" ]; then |
| 1689 |
if [ "${prc_typ}" != 'airs' ] && [ "${prc_typ}" != 'cam' ] && [ "${prc_typ}" != 'clm' ] && [ "${prc_typ}" != 'cice' ] && [ "${prc_typ}" != 'cpl' ] && [ "${prc_typ}" != 'ctsm' ] && [ "${prc_typ}" != 'eam' ] && [ "${prc_typ}" != 'eamxx' ] && [ "${prc_typ}" != 'elm' ] && [ "${prc_typ}" != 'hirdls' ] && [ "${prc_typ}" != 'mali' ] && [ "${prc_typ}" != 'mls' ] && [ "${prc_typ}" != 'mod04' ] && [ "${prc_typ}" != 'mpas' ] && [ "${prc_typ}" != 'mpasa' ] && [ "${prc_typ}" != 'mpasatmosphere' ] && [ "${prc_typ}" != 'mpaso' ] && [ "${prc_typ}" != 'mpasocean' ] && [ "${prc_typ}" != 'mpascice' ] && [ "${prc_typ}" != 'mpasseaice' ] && [ "${prc_typ}" != 'mpassi' ] && [ "${prc_typ}" != 'mwf' ] && [ "${prc_typ}" != 'nil' ] && [ "${prc_typ}" != 'rrg' ] && [ "${prc_typ}" != 'sgs' ]; then |
| 1690 |
echo "ERROR: Invalid -P prc_typ option = ${prc_typ}" |
| 1691 |
echo "HINT: Valid prc_typ arguments are 'airs', 'cam', 'clm', 'cice', 'cpl', 'ctsm', 'eam', 'eamxx', 'elm', 'hirdls', 'mali', 'mls', 'mod04', 'mpas', 'mpasa', 'mpasatmosphere', 'mpaso', 'mpasocean', 'mpascice', 'mpasseaice', 'mpassi', 'mwf', 'nil', 'rrg', and 'sgs'" |
| 1692 |
exit 1 |
| 1693 |
fi # !prc_typ |
| 1694 |
fi # !prc_typ |
| 1695 |
if [ "${prc_typ}" = 'airs' ]; then |
| 1696 |
if [ -z "${pdq_opt}" ] && [ "${pdq_flg}" = 'Yes' ]; then |
| 1697 |
pdq_opt='-a StdPressureLev,GeoTrack,GeoXTrack' |
| 1698 |
fi # !pdq_opt |
| 1699 |
fi # !airs |
| 1700 |
if [ "${prc_typ}" = 'hirdls' ]; then |
| 1701 |
if [ -z "${pdq_opt}" ] && [ "${pdq_flg}" = 'Yes' ]; then |
| 1702 |
pdq_opt='-a Pressure,Latitude,lon' |
| 1703 |
fi # !pdq_opt |
| 1704 |
fi # !hirdls |
| 1705 |
if [ "${prc_typ}" = 'mls' ]; then |
| 1706 |
if [ -z "${pdq_opt}" ] && [ "${pdq_flg}" = 'Yes' ]; then |
| 1707 |
pdq_opt='-a CO_Pressure,CO_Latitude,lon' |
| 1708 |
fi # !pdq_opt |
| 1709 |
fi # !mls |
| 1710 |
if [ "${prc_typ}" = 'mod04' ]; then |
| 1711 |
if [ -z "${pdq_opt}" ] && [ "${pdq_flg}" = 'Yes' ]; then |
| 1712 |
pdq_opt='-U' |
| 1713 |
fi # !pdq_opt |
| 1714 |
hnt_dst='--dst_regional' |
| 1715 |
fi # !mod04 |
| 1716 |
if [ "${prc_typ}" = 'mali' ] || [ "${prc_typ}" = 'mpas' ] || [ "${prc_typ}" = 'mpasa' ] || [ "${prc_typ}" = 'mpasatmosphere' ] || [ "${prc_typ}" = 'mpaso' ] || [ "${prc_typ}" = 'mpasocean' ] || [ "${prc_typ}" = 'mpascice' ] || [ "${prc_typ}" = 'mpasseaice' ] || [ "${prc_typ}" = 'mpassi' ]; then |
| 1717 |
prc_mpas='Yes' |
| 1718 |
fi # !mpas, !mpasa, !mpascice, !mpaso, !mpasocean, !mpasseaice, !mpassi |
| 1719 |
if [ "${prc_mpas}" = 'Yes' ]; then |
| 1720 |
|
| 1721 |
if [ "${prc_typ}" = 'mpasatmosphere' ]; then |
| 1722 |
prc_typ='mpasa' |
| 1723 |
fi # !mpasatmosphere |
| 1724 |
|
| 1725 |
# Add/alter missing metadata to MPAS files unless script was invoked by ncclimo (or with -C == --clm_flg) |
| 1726 |
# NB: MPAS Analysis sets clm_flg=Yes to prevent ncremap from doing unnecessary _FillValue work |
| 1727 |
# MPAS Analysis correctly deals with NaNs, masks, unset MPAS _FillValues, etc |
| 1728 |
if [ "${clm_flg}" = 'No' ] && [ "${prc_typ}" != 'mpasa' ]; then |
| 1729 |
att_flg='Yes' |
| 1730 |
fi # !clm_flg |
| 1731 |
|
| 1732 |
if [ "${prc_typ}" = 'mali' ]; then |
| 1733 |
mss_val='-1.0e36' |
| 1734 |
fi # !prc_typ |
| 1735 |
|
| 1736 |
# MPAS components have historically not written _FillValue into fields |
| 1737 |
# Instead MPAS writes zero to most (all?) fields in "non-computed" regions |
| 1738 |
# This is problematic for all MPAS components except MPAS-Atmosphere which has valid data everywhere |
| 1739 |
# Non-computed regions include, e.g., open ocean in MPAS-Seaice |
| 1740 |
# Simply adding a _FillValue to the variable does not, by itself, change this |
| 1741 |
# The _FillValue needs to be written in appropriate gridcells |
| 1742 |
# The MPAS epic on improving CF-compliance will eventually do that |
| 1743 |
# Until then, automatically invoke add_fll on MPAS datasets (except MPAS-A) to mask "uncomputed" regions |
| 1744 |
# For MPAS-Ocean, this masks continents/islands |
| 1745 |
# For MPAS-Seaice, this additionally masks open (non-sea-ice-covered) ocean |
| 1746 |
# For MPAS-Landice (MALI), this masks (I think) non-glacier land and ocean gridcells |
| 1747 |
if [ "${prc_typ}" != 'mpasa' ]; then |
| 1748 |
add_fll='Yes' |
| 1749 |
fi # !mpasa |
| 1750 |
|
| 1751 |
# Add depth coordinate to MPAS file when requested to by specifying coordinate file, that file exists, and commmand is found |
| 1752 |
if [ -n "${dpt_fl}" ] || [ "${dpt_flg}" = 'Yes' ]; then |
| 1753 |
if [ -n "${dpt_fl}" ]; then |
| 1754 |
if [ ! -f "${dpt_fl}" ] && [ ! -L "${dpt_fl}" ]; then |
| 1755 |
echo "ERROR: Unable to find specified MPAS depth coordinate file ${dpt_fl}" |
| 1756 |
exit 1 |
| 1757 |
fi # ! -f |
| 1758 |
cmd_dpt_opt="-c \"${dpt_fl}\"" |
| 1759 |
fi # !dpt_fl |
| 1760 |
if [ -z "${cmd_dpt_mpas}" ]; then |
| 1761 |
printf "${spt_nm}: ERROR MPAS depth coordinate addition requested but command ${dpt_exe_mpas} not found\n" |
| 1762 |
fi # !err |
| 1763 |
dpt_flg='Yes' |
| 1764 |
fi # !dpt_fl |
| 1765 |
if [ -z "${pdq_opt}" ] && [ "${pdq_flg}" = 'Yes' ]; then |
| 1766 |
# pdq_opt='-a Time,nVertLevels,nIsoLevelsT,nIsoLevelsZ,nCells' # MPAS-Atmosphere |
| 1767 |
# pdq_opt='-a Time,nVertLevels,maxEdges,MaxEdges2,nEdges,nCells' # MPAS-Ocean |
| 1768 |
# pdq_opt='-a Time,nCategories,ONE,nEdges,nCells' # MPAS-SeaIce |
| 1769 |
# pdq_opt='-a Time,nVertInterfaces,nCells' # 20210226: MALI |
| 1770 |
# pdq_opt='-a Time,depth,nVertInterfaces,nVertLevels,nVertLevelsP1,maxEdges,MaxEdges2,nCategories,ONE,TWO,nEdges,nCells' # MPAS LI,O,SI and depth |
| 1771 |
# pdq_opt='-a Time,depth,nVertInterfaces,nVertLevels,nVertLevelsP1,maxEdges,MaxEdges2,nCategories,R3,ONE,TWO,FOUR,nEdges,nCells' # 20190806: MPAS LI,O,SI,depth and BGC in one swell foop |
| 1772 |
# pdq_opt='-a Time,depth,nVertInterfaces,nVertLevels,nVertLevelsP1,nZBGCTracers,nBioLayersP1,nAlgaeIceLayers,nDisIronIceLayers,nIceLayers,nSnowLayers,maxEdges,MaxEdges2,nCategories,R3,ONE,TWO,FOUR,nEdges,nCells' # 20210226: MPAS LI,O,SI,depth and new SI BGC in one swell foop |
| 1773 |
# pdq_opt='-a Time,time,depth,nVertInterfaces,nVertLevelsP1,olevhalf,nVertLevels,nZBGCTracers,nBioLayers,P1,nAlgaeIceLayers,nDisIronIceLayers,nIceLayers,nSnowLayers,maxEdges,MaxEdges2,nCategories,R3,ONE,TWO,FOUR,nEdges,nCells' # 20221115: MPAS LI, O, SI, depth, BGC, and CMOR |
| 1774 |
pdq_opt='-a Time,time,depth,PRESSURE,nVertInterfaces,nVertLevelsP1,olevhalf,nVertLevels,nZBGCTracers,nBioLayers,P1,nAlgaeIceLayers,nDisIronIceLayers,nIceLayers,nIsoLevelsT,nIsoLevelsZ,nSnowLayers,maxEdges,MaxEdges2,nCategories,R3,ONE,TWO,FOUR,nEdges,nCells' # 20221115: MPAS A, LI, O, SI, depth, ARGO, BGC, CMOR |
| 1775 |
fi # !pdq_opt && !pdq_flg |
| 1776 |
# 20181130 No known reason to include staggered grid with regridded MPAS data |
| 1777 |
stg_grd='No' |
| 1778 |
fi # !mpas |
| 1779 |
if [ -n "${rnr_thr}" ]; then |
| 1780 |
if [ "${rnr_thr}" != 'off' ] && [ "${rnr_thr}" != 'none' ]; then |
| 1781 |
rgr_opt="${rgr_opt} --rnr_thr=${rnr_thr}" |
| 1782 |
fi # !rnr_thr |
| 1783 |
elif [ -z "${prs_stt}" ] && [ "${prc_mpas}" = 'Yes' ]; then |
| 1784 |
# Default MPAS behavior (since forever) has been to renormalize |
| 1785 |
rgr_opt="${rgr_opt} --rnr_thr=0.0" |
| 1786 |
fi # !rnr_thr |
| 1787 |
if [ "${stg_grd}" = 'Yes' ]; then |
| 1788 |
rgr_opt="${rgr_opt} --rgr stg_grd" |
| 1789 |
fi # !stg_grd |
| 1790 |
if [ "${prc_typ}" = 'mwf' ]; then |
| 1791 |
[[ ${dbg_lvl} -ge 1 ]] && date_mwf=$(date +"%s") |
| 1792 |
# Replace commas with spaces so alg_lst works in for loop: |
| 1793 |
alg_lst=$(echo ${alg_lst} | sed 's/,/ /g') |
| 1794 |
# Assume destination grid-files that end in .nc are SCRIP (and thus FV), and .g means Exodus (and possibly SE) |
| 1795 |
# 20210519: TR input files are increasingly used including .g FV files, so this assumption untenable |
| 1796 |
# An independent option to distinguish FV from SE files would be useful |
| 1797 |
# https://stackoverflow.com/questions/407184/how-to-check-the-extension-of-a-filename-in-a-bash-script |
| 1798 |
# Compute forward (src->dst) maps |
| 1799 |
if [ -n "${hnt_src}" ]; then |
| 1800 |
hnt_src_sng="--hnt_src=${hnt_src}" |
| 1801 |
fi # !hnt_src |
| 1802 |
if [ -n "${hnt_dst}" ]; then |
| 1803 |
hnt_dst_sng="--hnt_dst=${hnt_dst}" |
| 1804 |
fi # !hnt_dst |
| 1805 |
for alg_typ in ${alg_lst}; do |
| 1806 |
if [[ ${grd_src} == *.g ]] || [[ ${grd_dst} == *.g ]]; then |
| 1807 |
if [ ${alg_typ} == 'ncoaave' ] || [ ${alg_typ} == 'ncoidw' ]; then |
| 1808 |
continue |
| 1809 |
fi # !alg_typ |
| 1810 |
fi # !grd_src |
| 1811 |
alg_sng=${alg_typ} |
| 1812 |
[[ ${alg_typ} = 'fv2se_flx' ]] && alg_sng='monotr' |
| 1813 |
[[ ${alg_typ} = 'fv2se_stt' ]] && alg_sng='highorder' |
| 1814 |
[[ ${alg_typ} = 'fv2se_alt' ]] && alg_sng='mono' |
| 1815 |
map_nm="${drc_out}/map_${nm_src}_to_${nm_dst}_${alg_sng}.${dt_sng}.nc" |
| 1816 |
wgt_sng='' |
| 1817 |
if [ -n "${wgt_usr}" ]; then |
| 1818 |
erwg_alg_typ_rx='aave blin ndtos nstod patc' |
| 1819 |
# https://stackoverflow.com/questions/229551/string-contains-a-substring-in-bash |
| 1820 |
if [[ ${erwg_alg_typ_rx} = *"${alg_typ}"* ]]; then |
| 1821 |
wgt_sng="--wgt_cmd='${wgt_usr}'" |
| 1822 |
fi # !ERWG |
| 1823 |
fi # !wgt_usr |
| 1824 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 1825 |
printf "MWF: Create ${alg_typ} map ${map_nm}\n" |
| 1826 |
fi # !vrb_lvl |
| 1827 |
cmd_mwf="ncremap ${wgt_sng} --alg_typ=${alg_typ} --grd_src=\"${grd_src}\" --grd_dst=\"${grd_dst}\" ${hnt_src_sng} ${hnt_dst_sng} --map_fl=\"${map_nm}\"" |
| 1828 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 1829 |
echo ${cmd_mwf} |
| 1830 |
fi # !dbg |
| 1831 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 1832 |
eval ${cmd_mwf} |
| 1833 |
if [ "$?" -ne 0 ]; then |
| 1834 |
printf "${spt_nm}: ERROR Failed to generate MWF map. Debug this:\n${cmd_mwf}\n" |
| 1835 |
exit 1 |
| 1836 |
fi # !err |
| 1837 |
fi # !dbg |
| 1838 |
if [ ${dbg_lvl} -ge 1 ] && [ ${dbg_lvl} -ne 2 ]; then |
| 1839 |
date_crr=$(date +"%s") |
| 1840 |
date_dff=$((date_crr-date_mwf)) |
| 1841 |
echo "Elapsed time to generate ${alg_typ} map $((date_dff/60))m$((date_dff % 60))s" |
| 1842 |
fi # !dbg |
| 1843 |
done # !alg_typ |
| 1844 |
# Compute reverse (dst->src) maps |
| 1845 |
if [ -n "${hnt_src}" ]; then |
| 1846 |
hnt_dst_sng="--hnt_dst=${hnt_src/src/dst}" |
| 1847 |
fi # !hnt_src |
| 1848 |
if [ -n "${hnt_dst}" ]; then |
| 1849 |
hnt_src_sng="--hnt_src=${hnt_dst/dst/src}" |
| 1850 |
fi # !hnt_dst |
| 1851 |
for alg_typ in ${alg_lst}; do |
| 1852 |
if [[ ${grd_src} == *.g ]] || [[ ${grd_dst} == *.g ]]; then |
| 1853 |
if [ ${alg_typ} == 'ncoaave' ] || [ ${alg_typ} == 'ncoidw' ]; then |
| 1854 |
continue |
| 1855 |
fi # !alg_typ |
| 1856 |
fi # !grd_src |
| 1857 |
# Swap grd_src with grd_dst |
| 1858 |
alg_sng=${alg_typ} |
| 1859 |
[[ ${alg_typ} = 'se2fv_flx' ]] && alg_sng='mono' |
| 1860 |
[[ ${alg_typ} = 'se2fv_stt' ]] && alg_sng='highorder' |
| 1861 |
[[ ${alg_typ} = 'se2fv_alt' ]] && alg_sng='intbilin' |
| 1862 |
map_nm="${drc_out}/map_${nm_dst}_to_${nm_src}_${alg_sng}.${dt_sng}.nc" |
| 1863 |
# MWF-mode must be invoked with ocean as grd_src, atmosphere as grd_dst |
| 1864 |
a2o_sng='' |
| 1865 |
if [ "${alg_typ}" = 'se2fv_flx' ] || [ "${alg_typ}" = 'se2fv_stt' ] || [ "${alg_typ}" = 'se2fv_alt' ] || [ "${alg_typ}" = 'traave' ] || [ "${alg_typ}" = 'trbilin' ] || [ "${alg_typ}" = 'trfv2' ] || [ "${alg_typ}" = 'trintbilin' ]; then |
| 1866 |
a2o_sng='--a2o' |
| 1867 |
fi # !alg_typ |
| 1868 |
wgt_sng='' |
| 1869 |
if [ -n "${wgt_usr}" ]; then |
| 1870 |
erwg_alg_typ_rx='aave blin ndtos nstod patc' |
| 1871 |
# https://stackoverflow.com/questions/229551/string-contains-a-substring-in-bash |
| 1872 |
if [[ ${erwg_alg_typ_rx} = *"${alg_typ}"* ]]; then |
| 1873 |
wgt_sng="--wgt_cmd='${wgt_usr}'" |
| 1874 |
fi # !ERWG |
| 1875 |
fi # !wgt_usr |
| 1876 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 1877 |
printf "MWF: Create ${alg_typ} map ${map_nm}\n" |
| 1878 |
fi # !vrb_lvl |
| 1879 |
cmd_fwm="ncremap ${wgt_sng} ${a2o_sng} --alg_typ=${alg_typ} --grd_src=\"${grd_dst}\" --grd_dst=\"${grd_src}\" ${hnt_src_sng} ${hnt_dst_sng} --map_fl=\"${map_nm}\"" |
| 1880 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 1881 |
echo ${cmd_fwm} |
| 1882 |
fi # !dbg |
| 1883 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 1884 |
eval ${cmd_fwm} |
| 1885 |
if [ "$?" -ne 0 ]; then |
| 1886 |
printf "${spt_nm}: ERROR Failed to generate FWM map. Debug this:\n${cmd_fwm}\n" |
| 1887 |
exit 1 |
| 1888 |
fi # !err |
| 1889 |
fi # !dbg |
| 1890 |
if [ ${dbg_lvl} -ge 1 ] && [ ${dbg_lvl} -ne 2 ]; then |
| 1891 |
date_crr=$(date +"%s") |
| 1892 |
date_dff=$((date_crr-date_mwf)) |
| 1893 |
echo "Elapsed time to generate ${alg_typ} map $((date_dff/60))m$((date_dff % 60))s" |
| 1894 |
fi # !dbg |
| 1895 |
done # !alg_typ |
| 1896 |
echo "Finished MWF mode" |
| 1897 |
exit 0 |
| 1898 |
fi # !mwf |
| 1899 |
if [ "${prc_typ}" = 'rrg' ]; then |
| 1900 |
if [ -n "${dat_rgn}" ]; then # NB: option currently not implemented, drop it? |
| 1901 |
fl_in[0]=${dat_rgn} |
| 1902 |
fi # !dat_glb |
| 1903 |
if [ -n "${dat_glb}" ]; then |
| 1904 |
if [ ! -f "${dat_glb}" ] && [ ! -L "${dat_glb}" ]; then |
| 1905 |
echo "ERROR: Unable to find specified global data file ${dat_glb}" |
| 1906 |
exit 1 |
| 1907 |
fi # ! -f |
| 1908 |
else |
| 1909 |
echo "${spt_nm}: ERROR Regional regridding requires global data coordinates in file specified with --rrg_dat_glb argument\n" |
| 1910 |
exit 1 |
| 1911 |
fi # !dat_glb |
| 1912 |
if [ -n "${grd_glb}" ]; then |
| 1913 |
if [ ! -f "${grd_glb}" ] && [ ! -L "${grd_glb}" ]; then |
| 1914 |
echo "ERROR: Unable to find specified SCRIP-format global grid file ${grd_glb}" |
| 1915 |
exit 1 |
| 1916 |
fi # ! -f |
| 1917 |
else |
| 1918 |
echo "${spt_nm}: ERROR Regional regridding requires SCRIP-format grid for global data in file specified with --rrg_grd_glb argument\n" |
| 1919 |
exit 1 |
| 1920 |
fi # !grd_glb |
| 1921 |
# User may specify final, regional destination grid with either -g or --rrg_grd_rgn |
| 1922 |
if [ -n "${grd_rgn}" ]; then |
| 1923 |
grd_dst=${grd_rgn} |
| 1924 |
else |
| 1925 |
if [ -n "${grd_dst}" ]; then |
| 1926 |
grd_rgn=${grd_dst} |
| 1927 |
else |
| 1928 |
echo "${spt_nm}: ERROR Regional regridding requires SCRIP-format destination grid for regional data in file specified with --rrg_grd_rgn or --grd_dst argument\n" |
| 1929 |
exit 1 |
| 1930 |
fi # !grd_dst |
| 1931 |
fi # !grd_rgn |
| 1932 |
if [ ! -f "${grd_rgn}" ] && [ ! -L "${grd_rgn}" ]; then |
| 1933 |
echo "ERROR: Unable to find specified SCRIP-format regional grid file ${grd_rgn}" |
| 1934 |
exit 1 |
| 1935 |
fi # ! -f |
| 1936 |
grd_dst_usr_flg='Yes' |
| 1937 |
hnt_dst='--dst_regional' |
| 1938 |
fi # !rrg |
| 1939 |
if [ "${prc_typ}" = 'eamxx' ]; then |
| 1940 |
if [ -z "${pdq_opt}" ] && [ "${pdq_flg}" = 'Yes' ]; then |
| 1941 |
# Permute horizontal dimensions to MRV |
| 1942 |
# dim2 (= 2) is used in SCREAM SurfVars to store U,V components in horiz_winds, surf_mom_flux variables |
| 1943 |
# 20240110: EAMXX also uses dim2 dimension for time_bnds |
| 1944 |
#pdq_opt='-a ilev,lev,dim2,ncol' |
| 1945 |
# 20230304: EAMxx may have been vertically interpolated to pure-pressure levels prior to horizontal regridding |
| 1946 |
#pdq_opt='-a ilev,lev,plev,dim2,ncol' |
| 1947 |
# 20241002: EAMxx may have COSP dimensions in order cosp_tau,cosp_cth or cosp_tau,cosp_prs, and spectral dimensions lwband,swband |
| 1948 |
pdq_opt='-a time,lwband,swband,ilev,lev,plev,cosp_tau,cosp_cth,cosp_prs,dim2,ncol' |
| 1949 |
# NB: ncpdq is invoked iff performing horizontal regridding (vertical interpolation works fine either way) |
| 1950 |
fi # !pdq_opt && !pdq_flg |
| 1951 |
if [ -z "${ps_nm}" ]; then |
| 1952 |
ps_nm='ps' |
| 1953 |
fi # !ps_nm |
| 1954 |
fi # !eamxx |
| 1955 |
if [ "${prc_typ}" = 'clm' ] || [ "${prc_typ}" = 'ctsm' ] || [ "${prc_typ}" = 'elm' ]; then |
| 1956 |
# Set CLM/ELM-specific options first, then change prc_typ to sgs |
| 1957 |
# 20220129 sgs_frc is special since ncclimo may supply it (terminating a filename, even) |
| 1958 |
# Hence must keep user-specified sgs_frc value, if any, intact |
| 1959 |
rds_rth='6.37122e6' # [m] Radius of Earth in CLM/CTSM/ELM (SHR_CONST_REARTH) |
| 1960 |
if [ -n "${sgs_frc_usr}" ]; then sgs_frc="${sgs_frc_usr}"; else sgs_frc='landfrac'; fi |
| 1961 |
sgs_msk='landmask' |
| 1962 |
sgs_nrm='1.0' |
| 1963 |
prc_elm='Yes' |
| 1964 |
fi # !clm, !ctsm, !elm |
| 1965 |
if [ "${prc_typ}" = 'cice' ]; then |
| 1966 |
# Set CICE-specific options first, then change prc_typ to sgs |
| 1967 |
rds_rth='6371229.0' # [m] Radius of Earth in MPAS-SeaIce (global attribute sphere_radius) |
| 1968 |
if [ -n "${sgs_frc_usr}" ]; then sgs_frc="${sgs_frc_usr}"; else sgs_frc='aice'; fi |
| 1969 |
sgs_msk='tmask' |
| 1970 |
sgs_nrm='100.0' |
| 1971 |
prc_cice='Yes' |
| 1972 |
add_fll='Yes' |
| 1973 |
fi # !cice |
| 1974 |
if [ "${prc_typ}" = 'mpascice' ] || [ "${prc_typ}" = 'mpasseaice' ] || [ "${prc_typ}" = 'mpassi' ]; then |
| 1975 |
# NB: 'mpasseaice' is an exact synonym for 'mpascice' (which is deprecated) |
| 1976 |
# Set MPAS-SeaIce-specific options first, then change prc_typ to sgs |
| 1977 |
# MPAS-SeaIce requires two modes, MPAS and SGS, so set prc_mpas to 'Yes' |
| 1978 |
rds_rth='6371229.0' # [m] Radius of Earth in MPAS-SeaIce (global attribute sphere_radius) |
| 1979 |
if [ -n "${sgs_frc_usr}" ]; then sgs_frc="${sgs_frc_usr}"; else sgs_frc='timeMonthly_avg_iceAreaCell'; fi |
| 1980 |
# 20190326 timeMonthly_avg_icePresent contains fraction of time in averaging interval when any ice was present |
| 1981 |
# Thus timeMonthly_avg_icePresent is a floating point fraction, not a traditional integer mask |
| 1982 |
# 20190910 timeMonthly_avg_icePresent should be SGS regridded like any 2D field |
| 1983 |
# Treat a field named timeMonthly_avg_icePresentIntMask, if present, as a traditional integer mask |
| 1984 |
sgs_msk='timeMonthly_avg_icePresentIntMask' |
| 1985 |
sgs_nrm='1.0' |
| 1986 |
prc_mpas='Yes' |
| 1987 |
prc_mpasseaice='Yes' |
| 1988 |
fi # !mpascice |
| 1989 |
if [ -n "${add_fll_usr}" ]; then add_fll="${add_fll_usr}"; fi |
| 1990 |
if [ "${add_fll}" = 'Yes' ]; then |
| 1991 |
rgr_opt="${rgr_opt} --rgr add_fill_value" |
| 1992 |
fi # !add_fll |
| 1993 |
if [ "${mpt_mss}" = 'Yes' ]; then |
| 1994 |
rgr_opt="${rgr_opt} --rgr mpt_mss" |
| 1995 |
fi # !mpt_mss |
| 1996 |
if [ -n "${sgs_frc}" ] || [ -n "${sgs_frc_usr}" ] || [ "${prc_typ}" = 'sgs' ]; then |
| 1997 |
prc_sgs='Yes' |
| 1998 |
fi # !sgs |
| 1999 |
if [ "${prc_sgs}" = 'Yes' ]; then |
| 2000 |
if [ -n "${sgs_frc_usr}" ]; then sgs_frc="${sgs_frc_usr}"; fi |
| 2001 |
if [ -z "${sgs_frc}" ]; then |
| 2002 |
echo "ERROR: SGS processing invoked without specifying sgs_frc variable name" |
| 2003 |
echo "HINT: Specify sgs_frc variable name with --sgs_frc=var_name" |
| 2004 |
exit 1 |
| 2005 |
fi # !sgs_frc |
| 2006 |
rgr_opt="${rgr_opt} --rgr sgs_frc_nm=${sgs_frc}" |
| 2007 |
if [ -n "${sgs_msk}" ]; then |
| 2008 |
rgr_opt="${rgr_opt}#sgs_msk_nm=${sgs_msk}" |
| 2009 |
fi # !sgs_msk |
| 2010 |
if [ -n "${sgs_nrm}" ]; then |
| 2011 |
rgr_opt="${rgr_opt}#sgs_nrm=${sgs_nrm}" |
| 2012 |
fi # !sgs_nrm |
| 2013 |
fi # !prc_sgs |
| 2014 |
if [ -n "${thr_usr}" ]; then |
| 2015 |
thr_nbr="${thr_usr}" |
| 2016 |
fi # !thr_usr |
| 2017 |
if [ -n "${vrt_out}" ]; then |
| 2018 |
if [ ! -f "${vrt_out}" ] && [ ! -L "${vrt_out}" ]; then |
| 2019 |
echo "ERROR: Unable to find specified vertical output grid file ${vrt_out}" |
| 2020 |
exit 1 |
| 2021 |
fi # ! -f |
| 2022 |
vrt_usr_flg='Yes' |
| 2023 |
if [ -n "${dpt_nm}" ]; then |
| 2024 |
vrt_opt="${vrt_opt} --rgr dpt_nm_in=${dpt_nm}" |
| 2025 |
fi # !dpt_nm |
| 2026 |
if [ -n "${ps_nm}" ]; then |
| 2027 |
vrt_opt="${vrt_opt} --rgr ps_nm_in=${ps_nm}" |
| 2028 |
fi # !ps_nm |
| 2029 |
if [ "${ps_rtn}" = 'Yes' ]; then |
| 2030 |
vrt_opt="${vrt_opt} --rgr ps_rtn" |
| 2031 |
fi # !ps_rtn |
| 2032 |
if [ -n "${vrt_in}" ]; then |
| 2033 |
if [ ! -f "${vrt_in}" ] && [ ! -L "${vrt_in}" ]; then |
| 2034 |
echo "ERROR: Unable to find specified vertical input grid file ${vrt_in}" |
| 2035 |
exit 1 |
| 2036 |
fi # ! -f |
| 2037 |
vrt_opt="${vrt_opt} --rgr vrt_in=${vrt_in}" |
| 2038 |
fi # !vrt_in |
| 2039 |
if [ -n "${vrt_nm}" ]; then |
| 2040 |
vrt_opt="${vrt_opt} --rgr plev_nm_in=${vrt_nm}" |
| 2041 |
fi # !vrt_nm |
| 2042 |
if [ -n "${vrt_xtr}" ]; then |
| 2043 |
if [ ${vrt_xtr} = 'mss_val' ] || [ ${vrt_xtr} = 'missing_value' ] || [ ${vrt_xtr} = 'msv' ]; then |
| 2044 |
vrt_opt="${vrt_opt} --rgr xtr_mth=mss_val" |
| 2045 |
elif [ ${vrt_xtr} = 'nrs_ngh' ] || [ ${vrt_xtr} = 'nearest_neighbor' ] || [ ${vrt_xtr} = 'nn' ]; then |
| 2046 |
vrt_opt="${vrt_opt} --rgr xtr_mth=nrs_ngh" |
| 2047 |
elif [ ${vrt_xtr} = 'linear' ] || [ ${vrt_xtr} = 'lnr' ] || [ ${vrt_xtr} = 'lin' ]; then |
| 2048 |
vrt_opt="${vrt_opt} --rgr xtr_mth=linear" |
| 2049 |
elif [ ${vrt_xtr} = 'zero' ] || [ ${vrt_xtr} = 'nil' ]; then |
| 2050 |
vrt_opt="${vrt_opt} --rgr xtr_mth=zero" |
| 2051 |
else |
| 2052 |
echo "${spt_nm}: ERROR ${vrt_xtr} is not a valid extrapolation method" |
| 2053 |
echo "${spt_nm}: HINT Valid vertical extrapolation methods and synonyms are: linear,lnr,lin | mss_val,missing_value,msv | nrs_ngh,nearest_neighbor,nn | zero,nil" |
| 2054 |
exit 1 |
| 2055 |
fi # !vrt_xtr |
| 2056 |
fi # !vrt_xtr |
| 2057 |
if [ -n "${vrt_ntp}" ]; then |
| 2058 |
if [ ${vrt_ntp} = 'lin' ] || [ ${vrt_ntp} = 'linear' ] || [ ${vrt_ntp} = 'lnr' ]; then |
| 2059 |
vrt_opt="${vrt_opt} --rgr ntp_mth=lin" |
| 2060 |
elif [ ${vrt_ntp} = 'log' ] || [ ${vrt_ntp} = 'logarithmic' ] || [ ${vrt_ntp} = 'lgr' ]; then |
| 2061 |
vrt_opt="${vrt_opt} --rgr ntp_mth=log" |
| 2062 |
else |
| 2063 |
echo "${spt_nm}: ERROR ${vrt_ntp} is not a valid interpolation method" |
| 2064 |
echo "${spt_nm}: HINT Valid vertical interpolation methods and synonyms are lin,linear,lnr | log,logarithmic,lgr" |
| 2065 |
exit 1 |
| 2066 |
fi # !vrt_ntp |
| 2067 |
fi # !vrt_ntp |
| 2068 |
fi # !vrt_out |
| 2069 |
|
| 2070 |
if [ -n "${dst_fl}" ]; then |
| 2071 |
if [ ! -f "${dst_fl}" ] && [ ! -L "${dst_fl}" ]; then |
| 2072 |
echo "ERROR: Unable to find specified destination-file ${dst_fl}" |
| 2073 |
echo "HINT: Supply the full path-name for the destination-file" |
| 2074 |
exit 1 |
| 2075 |
fi # ! -f |
| 2076 |
dst_usr_flg='Yes' |
| 2077 |
fi # !dst_fl |
| 2078 |
if [ -z "${grd_sng}" ]; then |
| 2079 |
grd_sng_dfl="grd_ttl='Default internally-generated grid'#latlon=10,10#lat_typ=uni#lon_typ=Grn_ctr" # [sng] Grid string default |
| 2080 |
grd_sng="${grd_sng_dfl}" |
| 2081 |
else |
| 2082 |
grd_sng_usr_flg='Yes' |
| 2083 |
fi # !grd_sng |
| 2084 |
if [ -n "${grd_dst}" ]; then |
| 2085 |
if [ -f "${grd_dst}" ] || [ -L "${grd_dst}" ]; then |
| 2086 |
if [ "${dst_usr_flg}" = 'Yes' ]; then |
| 2087 |
printf "${spt_nm}: WARNING ${grd_dst} already exists and will be overwritten by newly inferred grid\n" |
| 2088 |
fi # !dst_usr_flg |
| 2089 |
if [ "${grd_sng_usr_flg}" = 'Yes' ]; then |
| 2090 |
printf "${spt_nm}: WARNING ${grd_dst} already exists and will be overwritten by newly created grid\n" |
| 2091 |
fi # !grd_sng_usr_flg |
| 2092 |
else |
| 2093 |
if [ "${dst_usr_flg}" != 'Yes' ] && [ "${grd_sng_usr_flg}" != 'Yes' ]; then |
| 2094 |
echo "ERROR: Unable to find specified destination grid-file ${grd_dst}" |
| 2095 |
echo "HINT: Supply full path-name for destination grid, or generate it with -G option and arguments" |
| 2096 |
exit 1 |
| 2097 |
fi # !dst_usr_flg |
| 2098 |
fi # ! -f |
| 2099 |
grd_dst_usr_flg='Yes' |
| 2100 |
else |
| 2101 |
grd_dst=${grd_dst_dfl} # [sng] Grid-file default |
| 2102 |
fi # !grd_dst |
| 2103 |
if [ -n "${grd_src}" ]; then |
| 2104 |
if [ "${prc_typ}" != 'rrg' ]; then |
| 2105 |
if [ ! -f "${grd_src}" ] && [ ! -L "${grd_src}" ]; then |
| 2106 |
echo "ERROR: Unable to find specified source grid-file ${grd_src}" |
| 2107 |
exit 1 |
| 2108 |
fi # ! -f |
| 2109 |
grd_src_usr_flg='Yes' |
| 2110 |
fi # !rrg |
| 2111 |
else |
| 2112 |
grd_src=${grd_src_dfl} # [sng] Grid-file default |
| 2113 |
fi # !grd_src |
| 2114 |
if [ "${dst_usr_flg}" = 'Yes' ] || [ "${grd_sng_usr_flg}" = 'Yes' ] || [ "${grd_dst_usr_flg}" = 'Yes' ] || [ "${grd_src_usr_flg}" = 'Yes' ]; then |
| 2115 |
# Create map-file if -d, -G, -g, or -s was specified |
| 2116 |
map_mk='Yes' |
| 2117 |
fi # !map_mk |
| 2118 |
if [ -n "${map_fl}" ]; then |
| 2119 |
map_usr_flg='Yes' |
| 2120 |
if [ "${map_mk}" = 'Yes' ]; then |
| 2121 |
# Confirm before overwriting maps |
| 2122 |
if [ -f "${map_fl}" ] || [ -L "${map_fl}" ]; then |
| 2123 |
# 20160803: fxm invoke iff in interactive shell (block hangs on read() in non-interactive shells) |
| 2124 |
# if [ -t 0 ] || [ ! -p /dev/stdin ]; then |
| 2125 |
# if [ -n "${TERM}" ]; then |
| 2126 |
# if [ -n "${PS1}" ]; then |
| 2127 |
if [ 1 -eq 0 ]; then |
| 2128 |
rsp_kbd_nbr=0 |
| 2129 |
while [ ${rsp_kbd_nbr} -lt 10 ]; do |
| 2130 |
echo "WARNING: Map-file ${map_fl} already exists and will be over-written." |
| 2131 |
read -p "Continue (y/n)? " rsp_kbd |
| 2132 |
let rsp_kbd_nbr+=1 |
| 2133 |
case "${rsp_kbd}" in |
| 2134 |
N*|n*) exit 1 ;; |
| 2135 |
Y*|y*) break ;; |
| 2136 |
*) continue ;; |
| 2137 |
esac |
| 2138 |
done # !rsp_kbd_nbr |
| 2139 |
if [ ${rsp_kbd_nbr} -ge 10 ]; then |
| 2140 |
echo "ERROR: Too many invalid responses, exiting" |
| 2141 |
exit 1 |
| 2142 |
fi # !rsp_kbd_nbr |
| 2143 |
fi # !0 |
| 2144 |
fi # !map_fl |
| 2145 |
else # !map_mk |
| 2146 |
if [ ! -f "${map_fl}" ] && [ ! -L "${map_fl}" ]; then |
| 2147 |
echo "ERROR: Unable to find specified regrid map ${map_fl}" |
| 2148 |
echo "HINT: Supply a valid map-file (weight-file) name or supply the grid files or data files and let ncremap create a mapfile for you" |
| 2149 |
exit 1 |
| 2150 |
fi # ! -f |
| 2151 |
fi # !map_mk |
| 2152 |
else # !map_fl |
| 2153 |
map_fl_dfl="${drc_tmp}/ncremap_tmp_map_${wgt_typ}_${alg_opt}.nc${unq_sfx}" # [sng] Map-file default |
| 2154 |
map_fl=${map_fl_dfl} |
| 2155 |
fi # !map_fl |
| 2156 |
map_rsl_fl=${map_fl} |
| 2157 |
if [ "${map_mk}" = 'Yes' ]; then |
| 2158 |
if [ "${wgt_typ}" = 'nco' ]; then |
| 2159 |
msh_fl_dfl="${drc_tmp}/ncremap_tmp_msh_ovr_${wgt_typ}.nc${unq_sfx}" # [sng] Mesh-file default |
| 2160 |
elif [ "${wgt_typ}" = 'tempest' ]; then |
| 2161 |
msh_fl_dfl="${drc_tmp}/ncremap_tmp_msh_ovr_${wgt_typ}.g${unq_sfx}" # [sng] Mesh-file default |
| 2162 |
if [ "${trn_map}" = 'Yes' ]; then |
| 2163 |
map_trn_fl="${drc_tmp}/ncremap_tmp_map_trn_${wgt_typ}.nc${unq_sfx}" # [sng] Map-file transpose default |
| 2164 |
map_rsl_fl=${map_trn_fl} |
| 2165 |
fi # !trn_map |
| 2166 |
fi # !tempest |
| 2167 |
if [ -n "${msh_fl}" ] && [ "${wgt_typ}" = 'nco' ]; then |
| 2168 |
msh_opt="--rgr msh=\"${msh_fl}\"" |
| 2169 |
else |
| 2170 |
msh_fl=${msh_fl_dfl} |
| 2171 |
fi # !msh_fl_usr |
| 2172 |
fi # !map_mk |
| 2173 |
|
| 2174 |
# Read files from stdin pipe, positional arguments, or directory glob |
| 2175 |
# Code block taken from ncclimo |
| 2176 |
# ncclimo sets inp_aut flag when file list is automatically (i.e., internally) generated |
| 2177 |
# ncremap uses convention that input files specified with -i set inp_aut flag |
| 2178 |
# That way, ncremap code block looks closer to ncclimo without introducing a new "inp_cmd" flag |
| 2179 |
#printf "dbg: inp_aut = ${inp_aut}\n" |
| 2180 |
#printf "dbg: inp_glb = ${inp_glb}\n" |
| 2181 |
#printf "dbg: inp_psn = ${inp_psn}\n" |
| 2182 |
#printf "dbg: inp_std = ${inp_std}\n" |
| 2183 |
if [ ${inp_aut} = 'No' ] && [ ${inp_psn} = 'No' ] && [ ${inp_std} = 'No' ] && [ "${drc_in_usr_flg}" = 'Yes' ]; then |
| 2184 |
inp_glb='Yes' |
| 2185 |
fi # !inp_psn, !inp_std |
| 2186 |
if [ "${map_mk}" != 'Yes' ] && [ ${inp_aut} = 'No' ] && [ ${inp_glb} = 'No' ] && [ ${inp_psn} = 'No' ] && [ ${inp_std} = 'No' ]; then |
| 2187 |
echo "${spt_nm}: ERROR No input data files found to regrid" |
| 2188 |
echo "${spt_nm}: HINT Specify input file(s) with -i \$in_fl or with -I \$drc_in or with positional argument(s) or with stdin" |
| 2189 |
if [ ${bch_pbs} = 'Yes' ]; then |
| 2190 |
echo "${spt_nm}: HINT PBS batch job environment detected, pipe to stdin not allowed, try positional arguments instead" |
| 2191 |
else # !bch_pbs |
| 2192 |
echo "${spt_nm}: HINT Pipe input file list to stdin with, e.g., 'ls *.nc | ${spt_nm} --map=map.nc'" |
| 2193 |
fi # !bch_pbs |
| 2194 |
exit 1 |
| 2195 |
fi # !sbs_flg |
| 2196 |
if [ ${inp_aut} = 'Yes' ]; then |
| 2197 |
# Single file argument |
| 2198 |
fl_in[0]=${in_fl} |
| 2199 |
fl_nbr=1 |
| 2200 |
fi # !inp_aut |
| 2201 |
if [ ${inp_glb} = 'Yes' ]; then |
| 2202 |
for fl in "${drc_in}"/*.nc "${drc_in}"/*.nc3 "${drc_in}"/*.nc4 "${drc_in}"/*.cdf "${drc_in}"/*.hdf "${drc_in}"/*.he5 "${drc_in}"/*.h5 ; do |
| 2203 |
if [ -f "${fl}" ] || [ -L "${fl}" ]; then |
| 2204 |
fl_in[${fl_nbr}]=${fl} # NB: ncremap does not use basename($fl) like ncclimo |
| 2205 |
let fl_nbr=${fl_nbr}+1 |
| 2206 |
fi # !file |
| 2207 |
done |
| 2208 |
fi # !inp_glb |
| 2209 |
if [ ${inp_psn} = 'Yes' ]; then |
| 2210 |
if [ ${psn_nbr} -eq 1 ]; then |
| 2211 |
fl_in[0]=${1} |
| 2212 |
fl_nbr=1 |
| 2213 |
elif [ ${psn_nbr} -eq 2 ]; then |
| 2214 |
if [ -z "${out_fl}" ]; then |
| 2215 |
fl_in[0]=${1} |
| 2216 |
out_fl=${2} |
| 2217 |
out_usr_flg='Yes' |
| 2218 |
fl_nbr=1 |
| 2219 |
else # !out_fl |
| 2220 |
echo "ERROR: Output file specified with -o (${out_fl}) conflicts with second positional argument ${2}" |
| 2221 |
echo "HINT: Use -o out_fl or positional argument, not both" |
| 2222 |
exit 1 |
| 2223 |
fi # !out_fl |
| 2224 |
elif [ ${psn_nbr} -ge 3 ]; then |
| 2225 |
for ((psn_idx=1;psn_idx<=psn_nbr;psn_idx++)); do |
| 2226 |
fl_in[(${psn_idx}-1)]=${!psn_idx} |
| 2227 |
fl_nbr=${psn_nbr} |
| 2228 |
done # !psn_idx |
| 2229 |
fi # !psn_nbr |
| 2230 |
fi # !inp_psn |
| 2231 |
if [ ${inp_std} = 'Yes' ]; then |
| 2232 |
# Input awaits on unit 0, i.e., on stdin |
| 2233 |
while read -r line; do # NeR05 p. 179 |
| 2234 |
fl_in[${fl_nbr}]=${line} |
| 2235 |
let fl_nbr=${fl_nbr}+1 |
| 2236 |
done < /dev/stdin |
| 2237 |
fi # !inp_std |
| 2238 |
|
| 2239 |
# 20231214 Retain multidimensional auxiliary coordinates as needed for vertical (not horizontal) interpolation |
| 2240 |
if [ "${prc_typ}" = 'mpaso' ] || [ "${prc_typ}" = 'mpasocean' ]; then |
| 2241 |
if [ -n "${vrt_out}" ]; then |
| 2242 |
if [ -n "${nco_var_lst}" ] && [ "${xcl_flg}" != 'Yes' ]; then |
| 2243 |
# Search the file iff the extraction list does not already contain the depth coordinate |
| 2244 |
# https://stackoverflow.com/questions/4542732/how-do-i-negate-a-test-with-regular-expressions-in-a-bash-script |
| 2245 |
if [[ ! "${nco_var_lst}" =~ ${mpaso_var_zmid} ]]; then |
| 2246 |
mpaso_var_lst=`nchasvar ${mpaso_var_zmid} ${fl_in[0]}` |
| 2247 |
if [ "${mpaso_var_lst}" = ${mpaso_var_zmid} ]; then |
| 2248 |
nco_var_lst="${nco_var_lst},${mpaso_var_zmid}" |
| 2249 |
# Alternatively, could create nco_var_lst_ncpdq to ensure ncpdq retains mpaso_var_zmid so vertical |
| 2250 |
# interpolation finds it, yet it does not appear in horizontal regridding namelist |
| 2251 |
# echo "DEBUG: Added ${mpaso_var_zmid} to extraction list: nco_var_lst = ${nco_var_lst}" |
| 2252 |
fi # !mpaso_var_lst |
| 2253 |
fi # !nco_var_lst |
| 2254 |
fi # !nco_var_lst, !xcl_flg |
| 2255 |
fi # !vrt_out |
| 2256 |
fi # !mpaso |
| 2257 |
|
| 2258 |
if [ "${mpi_flg}" = 'Yes' ]; then |
| 2259 |
if [ -n "${PBS_NODEFILE}" ]; then |
| 2260 |
nd_fl="${PBS_NODEFILE}" |
| 2261 |
elif [ -n "${SLURM_NODELIST}" ]; then |
| 2262 |
# SLURM returns compressed lists (e.g., "nid00[076-078,559-567]") |
| 2263 |
# Convert this to file with uncompressed list (like PBS) |
| 2264 |
# http://www.ceci-hpc.be/slurm_faq.html#Q12 |
| 2265 |
# Ensure file is in writable directory |
| 2266 |
nd_fl="${drc_out}/${spt_nm}.slurm_nodelist.pid${spt_pid}.tmp" |
| 2267 |
nd_lst=`scontrol show hostname ${SLURM_NODELIST}` |
| 2268 |
echo ${nd_lst} > ${nd_fl} |
| 2269 |
else |
| 2270 |
echo "${spt_nm}: ERROR MPI master process unable to find node-list for distributing jobs" |
| 2271 |
echo "${spt_nm}: ${spt_nm} uses first node-list found in \$PBS_NODEFILE or \$SLURM_NODELIST" |
| 2272 |
echo "${spt_nm}: However, none of these environment variables are set so there is no node-list for distributing MPI jobs" |
| 2273 |
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." |
| 2274 |
exit 1 |
| 2275 |
fi # !PBS |
| 2276 |
# 20210310 MPI run command may need/use thr_nbr so set it first |
| 2277 |
if [ -z "${thr_usr}" ]; then |
| 2278 |
if [ -n "${PBS_NUM_PPN}" ]; then |
| 2279 |
# NB: use export OMP_NUM_THREADS when thr_nbr > 8 |
| 2280 |
# thr_nbr=${PBS_NUM_PPN} |
| 2281 |
thr_nbr=$((PBS_NUM_PPN > 8 ? 8 : PBS_NUM_PPN)) |
| 2282 |
fi # !pbs |
| 2283 |
fi # !thr_usr |
| 2284 |
if [ -n "${nd_fl}" ]; then |
| 2285 |
# NB: nodes are 0-based, e.g., [0..11] |
| 2286 |
nd_idx=0 |
| 2287 |
for nd in `cat ${nd_fl} | uniq` ; do |
| 2288 |
nd_nm[${nd_idx}]=${nd} |
| 2289 |
let nd_idx=${nd_idx}+1 |
| 2290 |
done # !nd |
| 2291 |
nd_nbr=${#nd_nm[@]} |
| 2292 |
if [ "${nd_nbr}" -eq 0 ]; then |
| 2293 |
echo "${spt_nm}: ERROR MPI-mode node number nd_nbr = ${nd_nbr}" |
| 2294 |
echo "${spt_nm}: HINT Parsing the node-list for distributing MPI jobs failed" |
| 2295 |
exit 1 |
| 2296 |
fi # !nd_nbr |
| 2297 |
# NB: ncclimo and ncremap employ different node-allocation algorithms: |
| 2298 |
# 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 |
| 2299 |
# ncclimo (splitter mode) uses simple round robin based on position in variable list |
| 2300 |
# ncremap uses simple round-robin allocation based on position in input file list |
| 2301 |
# Only ncclimo monthly climatology-mode uses 1-based cmd_mpi array |
| 2302 |
# ncclimo splitter-mode, and daily and annual climatology-mode, and ncremap all use 0-based cmd_mpi array |
| 2303 |
# Copy host-specific mpirun syntax but not node-allocation algorithms or loop indices between ncclimo and ncremap |
| 2304 |
# 20160502: Remove tasks-per-node limits (ntasks, npernode) so round-robin algorithm can schedule multiple jobs on same node |
| 2305 |
for ((fl_idx=0;fl_idx<fl_nbr;fl_idx++)); do |
| 2306 |
case "${HOSTNAME}" in |
| 2307 |
andes* | chrysalis* | chrlogin* | chr-[0123456789][0123456789][0123456789][0123456789] | compy* | constance* | frontier* | login[0123456789][0123456789] | n[0123456789][0123456789][0123456789][0123456789] | nid* | node* | perlmutter* ) |
| 2308 |
# 20220518: Non-interactive batch jobs at NERSC/Perlmutter return HOSTNAME as login??, and nodes as nid?????? |
| 2309 |
# 20160803: Non-interactive batch jobs at PNNL constance return HOSTNAME as node*, not constance* |
| 2310 |
# 20190526: Non-interactive batch jobs at PNNL compy return HOSTNAME as n????, not compy* |
| 2311 |
# 20210310: srun option<->long option equivalences are -N = --nodes, -n = --ntasks, -c = --cpus-per-task |
| 2312 |
# NB: NERSC staff says srun automatically assigns to unique nodes even without "-L $node" argument? |
| 2313 |
cmd_mpi[${fl_idx}]="srun --nodelist ${nd_nm[$((${fl_idx} % ${nd_nbr}))]} --nodes=1" ; ;; # SLURM |
| 2314 |
# cmd_mpi[${fl_idx}]="srun --nodelist ${nd_nm[$((${fl_idx} % ${nd_nbr}))]} --nodes=1 --ntasks=1" ; ;; # SLURM |
| 2315 |
# cmd_mpi[${fl_idx}]="srun --nodelist ${nd_nm[$((${fl_idx} % ${nd_nbr}))]} --nodes=1 --ntasks=1 --cpus-per-task=1" ; ;; # SLURM |
| 2316 |
bebop* | blogin* | b[0123456789][0123456789][0123456789] | derecho* | ilogin* | i[0123456789][0123456789][0123456789] ) |
| 2317 |
# 20180120: Non-interactive batch jobs at NCAR return HOSTNAME as cheyenne? |
| 2318 |
# Cheyenne prefers 'mpiexec_mpt dplace -s 1 ncclimo ...' |
| 2319 |
# Unsure how to specify nd_nm to mpiexec_mpt |
| 2320 |
# mpirun from SGI MPT does not accept '-H nd_nm', unlike regular PBS |
| 2321 |
# PBSPro considers ncclimo a 'non-MPT application' so must set MPI_SHEPHERD=true |
| 2322 |
export MPI_SHEPHERD=true |
| 2323 |
# cmd_mpi[${fl_idx}]="mpiexec_mpt dplace ${nd_nm[$((${fl_idx} % ${nd_nbr}))]} -n 1" ; ;; # PBSPro |
| 2324 |
cmd_mpi[${fl_idx}]="mpirun ${nd_nm[$((${fl_idx} % ${nd_nbr}))]} -n 1" ; ;; # PBSPro |
| 2325 |
* ) |
| 2326 |
# 20260311: Shift default node manager from mpirun to srun |
| 2327 |
cmd_mpi[${fl_idx}]="srun --nodelist ${nd_nm[$((${fl_idx} % ${nd_nbr}))]} --nodes=1" ; ;; # SLURM |
| 2328 |
# cmd_mpi[${fl_idx}]="mpirun -H ${nd_nm[$((${fl_idx} % ${nd_nbr}))]} -n 1" ; ;; # Other (PBS) |
| 2329 |
# cmd_mpi[${fl_idx}]="mpirun -H ${nd_nm[$((${fl_idx} % ${nd_nbr}))]} -npernode 1 -n 1" ; ;; # Other |
| 2330 |
esac # !HOSTNAME |
| 2331 |
case "${HOSTNAME}" in |
| 2332 |
perlmutter* | login[0123456789][0123456789] | nid* ) |
| 2333 |
# 20210319: Multiple srun commands cannot run concurrently on single Cori node without special options |
| 2334 |
# --gres=craynetwork:0 --mem=20000 tested by me, Noel Keen documented here: |
| 2335 |
# https://docs.nersc.gov/jobs/examples/#multiple-parallel-jobs-while-sharing-nodes |
| 2336 |
# These options are only expected to work on NERSC Cori |
| 2337 |
# craynetwork:0 (instead of, e.g., :1) allows any number of MPI jobs to run |
| 2338 |
# 20240406 Deprecate --gres=craynetwork:0 since not available on Perlmutter, and keep --mem option |
| 2339 |
# 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 |
| 2340 |
# 20210319: --zonesort=off tested by me does eliminate zonesort messages like these: |
| 2341 |
# slurmstepd: error: Detected zonesort setup failure: zonesort interface write failure (40558186.7) |
| 2342 |
# However, using zonesort option appears to slow-down throughput considerably |
| 2343 |
cmd_mpi[${fl_idx}]="${cmd_mpi[${fl_idx}]} --mem=${mem_mb}" ; ;; # SLURM |
| 2344 |
# cmd_mpi[${fl_idx}]="${cmd_mpi[${fl_idx}]} --nodes=1 --gres=craynetwork:0 --mem=${mem_mb} --zonesort=off" ; ;; # SLURM |
| 2345 |
esac # !HOSTNAME |
| 2346 |
done # !fl_idx |
| 2347 |
if [ -n "${SLURM_NODELIST}" ]; then |
| 2348 |
/bin/rm -f ${nd_fl} |
| 2349 |
fi # !SLURM |
| 2350 |
else # !nd_fl |
| 2351 |
mpi_flg='No' |
| 2352 |
for ((fl_idx=0;fl_idx<fl_nbr;fl_idx++)); do |
| 2353 |
cmd_mpi[${fl_idx}]='' |
| 2354 |
done # !fl_idx |
| 2355 |
fi # !nd_fl |
| 2356 |
if [ -z "${job_usr}" ]; then |
| 2357 |
job_nbr=${nd_nbr} |
| 2358 |
fi # !job_usr |
| 2359 |
fi # !mpi_flg |
| 2360 |
|
| 2361 |
# Print initial state |
| 2362 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2363 |
printf "dbg: a2o_flg = ${a2o_flg}\n" |
| 2364 |
printf "dbg: add_fll = ${add_fll}\n" |
| 2365 |
printf "dbg: alg_lst = ${alg_lst}\n" |
| 2366 |
printf "dbg: alg_opt = ${alg_opt}\n" |
| 2367 |
printf "dbg: alg_typ = ${alg_typ}\n" |
| 2368 |
printf "dbg: att_flg = ${att_flg}\n" |
| 2369 |
printf "dbg: bfr_sz = ${bfr_sz}\n" |
| 2370 |
printf "dbg: cln_flg = ${cln_flg}\n" |
| 2371 |
printf "dbg: cmd_cdo = ${cmd_wgt_cdo}\n" |
| 2372 |
printf "dbg: cmd_esm = ${cmd_wgt_esmf}\n" |
| 2373 |
printf "dbg: cmd_mbt = ${cmd_wgt_mbt}\n" |
| 2374 |
printf "dbg: cmd_nco = ${cmd_wgt_nco}\n" |
| 2375 |
printf "dbg: cmd_tps = ${cmd_wgt_tps}\n" |
| 2376 |
printf "dbg: cmd_tps = ${cmd_msh_tps}\n" |
| 2377 |
printf "dbg: cmp_sng = ${cmp_sng}\n" |
| 2378 |
printf "dbg: col_dmn = ${col_dmn}\n" |
| 2379 |
printf "dbg: d2f_flg = ${d2f_flg}\n" |
| 2380 |
printf "dbg: d2f_opt = ${d2f_opt}\n" |
| 2381 |
printf "dbg: dbg_lvl = ${dbg_lvl}\n" |
| 2382 |
printf "dbg: devnull = ${devnull}\n" |
| 2383 |
printf "dbg: dfl_lvl = ${dfl_lvl}\n" |
| 2384 |
printf "dbg: dpt_flg = ${dpt_flg}\n" |
| 2385 |
printf "dbg: dpt_fl = ${dpt_fl}\n" |
| 2386 |
printf "dbg: dpt_nm = ${dpt_nm}\n" |
| 2387 |
printf "dbg: drc_in = ${drc_in}\n" |
| 2388 |
printf "dbg: drc_out = ${drc_out}\n" |
| 2389 |
printf "dbg: drc_tmp = ${drc_tmp}\n" |
| 2390 |
printf "dbg: dst_fl = ${dst_fl}\n" |
| 2391 |
printf "dbg: erwg_vrs = ${erwg_vrs_sng}\n" |
| 2392 |
printf "dbg: esmf_typ = ${esmf_typ}\n" |
| 2393 |
printf "dbg: fl_fmt = ${fl_fmt}\n" |
| 2394 |
printf "dbg: fl_in[0] = ${fl_in[0]}\n" |
| 2395 |
printf "dbg: fl_nbr = ${fl_nbr}\n" |
| 2396 |
printf "dbg: flg_hrz = ${flg_hrz}\n" |
| 2397 |
printf "dbg: gaa_sng = ${gaa_sng}\n" |
| 2398 |
printf "dbg: gad_sng = ${gad_sng}\n" |
| 2399 |
printf "dbg: grd_dst = ${grd_dst}\n" |
| 2400 |
printf "dbg: grd_sng = ${grd_sng}\n" |
| 2401 |
printf "dbg: grd_src = ${grd_src}\n" |
| 2402 |
printf "dbg: inp_aut = ${inp_aut}\n" |
| 2403 |
printf "dbg: inp_glb = ${inp_glb}\n" |
| 2404 |
printf "dbg: inp_psn = ${inp_psn}\n" |
| 2405 |
printf "dbg: inp_std = ${inp_std}\n" |
| 2406 |
printf "dbg: hdr_pad = ${hdr_pad}\n" |
| 2407 |
printf "dbg: hrd_pth = ${hrd_pth}\n" |
| 2408 |
printf "dbg: hst_att = ${hst_att}\n" |
| 2409 |
printf "dbg: job_nbr = ${job_nbr}\n" |
| 2410 |
printf "dbg: in_fl = ${in_fl}\n" |
| 2411 |
printf "dbg: map_fl = ${map_fl}\n" |
| 2412 |
printf "dbg: map_mk = ${map_mk}\n" |
| 2413 |
printf "dbg: mbt_nc4 = ${mbt_grd_nc4}\n" |
| 2414 |
printf "dbg: mbt_srl = ${mbt_grd_rd_srl}\n" |
| 2415 |
printf "dbg: mlt_map = ${mlt_map_flg}\n" |
| 2416 |
printf "dbg: mpi_flg = ${mpi_flg}\n" |
| 2417 |
printf "dbg: mpi_nbr = ${mpi_nbr}\n" |
| 2418 |
printf "dbg: mpi_pfx = ${mpi_pfx}\n" |
| 2419 |
printf "dbg: mpt_mss = ${mpt_mss}\n" |
| 2420 |
printf "dbg: msh_fl = ${msh_fl}\n" |
| 2421 |
printf "dbg: msk_apl = ${msk_apl}\n" |
| 2422 |
printf "dbg: msk_dst = ${msk_dst}\n" |
| 2423 |
printf "dbg: msk_out = ${msk_out}\n" |
| 2424 |
printf "dbg: msk_src = ${msk_src}\n" |
| 2425 |
printf "dbg: nco_opt = ${nco_opt}\n" |
| 2426 |
printf "dbg: nd_nbr = ${nd_nbr}\n" |
| 2427 |
printf "dbg: out_fl = ${out_fl}\n" |
| 2428 |
printf "dbg: par_typ = ${par_typ}\n" |
| 2429 |
printf "dbg: pdq_flg = ${pdq_flg}\n" |
| 2430 |
printf "dbg: pdq_opt = ${pdq_opt}\n" |
| 2431 |
printf "dbg: prc_sgs = ${prc_sgs}\n" |
| 2432 |
printf "dbg: prc_typ = ${prc_typ}\n" |
| 2433 |
printf "dbg: prs_stt = ${prs_stt}\n" |
| 2434 |
printf "dbg: prt_nbr = ${prt_nbr}\n" |
| 2435 |
printf "dbg: ps_nm = ${ps_nm}\n" |
| 2436 |
printf "dbg: ps_rtn = ${ps_rtn}\n" |
| 2437 |
# printf "dbg: qea_flg = ${qea_flg}\n" |
| 2438 |
printf "dbg: qnt_prc = ${qnt_prc}\n" |
| 2439 |
printf "dbg: rgr_opt = ${rgr_opt}\n" |
| 2440 |
printf "dbg: rnr_thr = ${rnr_thr}\n" |
| 2441 |
printf "dbg: rrg_bb = ${bb_wesn}\n" |
| 2442 |
printf "dbg: rrg_dat = ${dat_glb}\n" |
| 2443 |
printf "dbg: rrg_glb = ${grd_glb}\n" |
| 2444 |
printf "dbg: rrg_rgn = ${grd_rgn}\n" |
| 2445 |
printf "dbg: rrg_rnm = ${rnm_sng}\n" |
| 2446 |
printf "dbg: se_np_nbr= ${se_np_nbr}\n" |
| 2447 |
printf "dbg: sgs_frc = ${sgs_frc}\n" |
| 2448 |
printf "dbg: sgs_msk = ${sgs_msk}\n" |
| 2449 |
printf "dbg: sgs_nrm = ${sgs_nrm}\n" |
| 2450 |
printf "dbg: skl_fl = ${skl_fl}\n" |
| 2451 |
printf "dbg: spt_nm = ${spt_nm}\n" |
| 2452 |
printf "dbg: spt_pid = ${spt_pid}\n" |
| 2453 |
printf "dbg: std_chk = ${std_chk}\n" |
| 2454 |
printf "dbg: stg_grd = ${stg_grd}\n" |
| 2455 |
printf "dbg: thr_nbr = ${thr_nbr}\n" |
| 2456 |
printf "dbg: ugrid_fl = ${ugrid_fl}\n" |
| 2457 |
printf "dbg: uio_flg = ${uio_flg}\n" |
| 2458 |
printf "dbg: unq_sfx = ${unq_sfx}\n" |
| 2459 |
printf "dbg: var_lst = ${var_lst}\n" |
| 2460 |
printf "dbg: var_rgr = ${var_rgr}\n" |
| 2461 |
printf "dbg: vrt_in = ${vrt_in}\n" |
| 2462 |
printf "dbg: vrt_nm = ${vrt_nm}\n" |
| 2463 |
printf "dbg: vrt_opt = ${vrt_opt}\n" |
| 2464 |
printf "dbg: vrt_out = ${vrt_out}\n" |
| 2465 |
printf "dbg: vrt_ntp = ${vrt_ntp}\n" |
| 2466 |
printf "dbg: vrt_xtr = ${vrt_xtr}\n" |
| 2467 |
printf "dbg: wgt_cmd = ${wgt_cmd}\n" |
| 2468 |
printf "dbg: wgt_opt = ${wgt_opt}\n" |
| 2469 |
printf "dbg: wgt_typ = ${wgt_typ}\n" |
| 2470 |
printf "dbg: wgt_usr = ${wgt_usr}\n" |
| 2471 |
printf "dbg: xtr_nsp = ${xtr_nsp}\n" |
| 2472 |
printf "dbg: xtr_xpn = ${xtr_xpn}\n" |
| 2473 |
printf "dbg: Will regrid ${fl_nbr} files:\n" |
| 2474 |
for ((fl_idx=0;fl_idx<${fl_nbr};fl_idx++)); do |
| 2475 |
printf "\${fl_in[${fl_idx}]} = ${fl_in[${fl_idx}]}\n" |
| 2476 |
done # !fl_idx |
| 2477 |
fi # !dbg |
| 2478 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2479 |
if [ ${mpi_flg} = 'Yes' ]; then |
| 2480 |
for ((nd_idx=0;nd_idx<${nd_nbr};nd_idx++)); do |
| 2481 |
printf "dbg: nd_nm[${nd_idx}] = ${nd_nm[${nd_idx}]}\n" |
| 2482 |
done # !nd |
| 2483 |
fi # !mpi |
| 2484 |
fi # !dbg |
| 2485 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2486 |
psn_nbr=$# |
| 2487 |
printf "dbg: Found ${psn_nbr} positional parameters (besides \$0):\n" |
| 2488 |
for ((psn_idx=1;psn_idx<=psn_nbr;psn_idx++)); do |
| 2489 |
printf "dbg: psn_arg[${psn_idx}] = ${!psn_idx}\n" |
| 2490 |
done # !psn_idx |
| 2491 |
fi # !dbg |
| 2492 |
|
| 2493 |
# Create output directories |
| 2494 |
if [ -n "${drc_out}" ] && [ ! -d "${drc_out}" ]; then |
| 2495 |
chr_fst=${drc_out:0:1} |
| 2496 |
if [ "${chr_fst}" = '-' ]; then |
| 2497 |
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" |
| 2498 |
echo "${spt_nm}: HINT Specify output directory name that does not begin with '-'" |
| 2499 |
exit 1 |
| 2500 |
fi # !chr_fst |
| 2501 |
cmd_mkd="mkdir -p ${drc_out}" |
| 2502 |
eval ${cmd_mkd} |
| 2503 |
if [ "$?" -ne 0 ]; then |
| 2504 |
printf "${spt_nm}: ERROR Failed to create output directory. Debug this:\n${cmd_mkd}\n" |
| 2505 |
printf "${spt_nm}: HINT Creating a directory requires proper write permissions\n" |
| 2506 |
exit 1 |
| 2507 |
fi # !err |
| 2508 |
fi # !drc_out |
| 2509 |
if [ -n "${drc_tmp}" ] && [ ! -d "${drc_tmp}" ]; then |
| 2510 |
cmd_mkd="mkdir -p ${drc_tmp}" |
| 2511 |
eval ${cmd_mkd} |
| 2512 |
if [ "$?" -ne 0 ]; then |
| 2513 |
printf "${spt_nm}: ERROR Attempt to create temporary directory. Debug this:\n${cmd_mkd}\n" |
| 2514 |
printf "${spt_nm}: HINT Creating a directory requires proper write permissions\n" |
| 2515 |
exit 1 |
| 2516 |
fi # !err |
| 2517 |
fi # !drc_tmp |
| 2518 |
|
| 2519 |
# Human-readable summary |
| 2520 |
date_srt=$(date +"%s") |
| 2521 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2522 |
printf "NCO regridder invoked with command:\n" |
| 2523 |
echo "${cmd_ln}" |
| 2524 |
fi # !vrb_lvl |
| 2525 |
if [ ${dbg_lvl} -ge 2 ]; then |
| 2526 |
printf "************************************************************************\n" |
| 2527 |
printf "IMPORTANT: This output shows a SIMULATION of a production run\n" |
| 2528 |
printf "The values shown are real, but the printed commands are NOT executed\n" |
| 2529 |
printf "This output is for debugging purpose only since dbg_lvl = ${dbg_lvl} >= 2\n" |
| 2530 |
printf "The elapsed time should be near 0m0s since there is very little disk I/O\n" |
| 2531 |
printf "Set dbg_lvl <= 1 for a PRODUCTION RUN that executes these commands\n" |
| 2532 |
printf "************************************************************************\n" |
| 2533 |
fi # !dbg |
| 2534 |
if [ -f 'PET0.RegridWeightGen.Log' ]; then |
| 2535 |
if [ ${vrb_lvl} -ge ${vrb_4} ]; then |
| 2536 |
printf "${spt_nm}: Removing PET0.RegridWeightGen.Log file and any other PET0.* files from current directory before running\n" |
| 2537 |
fi # !vrb_lvl |
| 2538 |
/bin/rm -f PET0.* |
| 2539 |
fi # !PETO |
| 2540 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2541 |
printf "Started processing at `date`.\n" |
| 2542 |
printf "Running remap script ${spt_nm} from directory ${drc_spt}\n" |
| 2543 |
printf "NCO binaries version ${nco_vrs} from directory ${drc_nco}\n" |
| 2544 |
printf "Parallelism mode for files = ${par_typ}\n" |
| 2545 |
if [ ${fl_nbr} -gt 1 ]; then |
| 2546 |
if [ "${par_typ}" = ${par_bck} ]; then |
| 2547 |
printf "Background parallelism regridding files in fl_nbr/job_nbr = ${fl_nbr}/${job_nbr} = $((fl_nbr / job_nbr)) sequential batches each concurrently processing job_nbr = ${job_nbr} files\n" |
| 2548 |
elif [ "${par_typ}" = ${par_mpi} ]; then |
| 2549 |
printf "MPI parallelism regridding files in fl_nbr/job_nbr = ${fl_nbr}/${job_nbr} = $((fl_nbr / job_nbr)) sequential batches. Each batch is distributed to ${nd_nbr} nodes via round-robin scheduling and handles job_nbr = ${job_nbr} months concurrently.\n" |
| 2550 |
else |
| 2551 |
printf "No parallelism--files will be regridded serially (one at a time) on a single node. HINT: to regrid multiple files in parallel, try \'--par_typ=background\' or \'--par_typ=mpi\'\n" |
| 2552 |
fi # !par_typ |
| 2553 |
fi # !fl_nbr |
| 2554 |
printf "Input files in or relative to directory ${drc_in}\n" |
| 2555 |
printf "Intermediate/temporary files written to directory ${drc_tmp}\n" |
| 2556 |
printf "Output files to directory ${drc_out}\n" |
| 2557 |
fi # !vrb_lvl |
| 2558 |
if [ "${map_mk}" != 'Yes' ] && [ "${map_usr_flg}" = 'Yes' ] && [ -n "${wgt_usr}" ]; then |
| 2559 |
printf "${spt_nm}: ERROR Specifying both '-m map_fl' and '-w wgt_cmd' is only allowed when creating a map (weight-generator is superfluous when user supplies map)\n" |
| 2560 |
exit 1 |
| 2561 |
fi # wgt_usr |
| 2562 |
|
| 2563 |
if [ "${dst_usr_flg}" = 'Yes' ]; then |
| 2564 |
if [ "${grd_dst_usr_flg}" = 'Yes' ]; then |
| 2565 |
printf "${spt_nm}: INFO Both '-d dst_fl' and '-g grd_dst' were specified so ${spt_nm} will infer grid-file ${grd_dst} from data-file ${dst_fl}\n" |
| 2566 |
fi # !grd_dst_usr_flg |
| 2567 |
fi # !dst_usr_flg |
| 2568 |
if [ "${dst_usr_flg}" != 'Yes' ] && [ "${grd_dst_usr_flg}" != 'Yes' ] && [ "${map_usr_flg}" != 'Yes' ] && [ "${grd_sng_usr_flg}" != 'Yes' ] && [ "${vrt_usr_flg}" != 'Yes' ]; then |
| 2569 |
printf "${spt_nm}: ERROR Unable to determine remapping procedure\nHINT: Specify the type of remapping to perform with at least one of the following options: 1) A data/template file, '-d dst_fl'; 2) A destination grid-file, '-g grd_dst'; 3) A grid-construction command, '-G grd_sng'; 4) A map-file with weights to apply, '-m map_fl'; 5) A vertical grid to interpolate to, --vrt_out=vrt_out\n" |
| 2570 |
exit 1 |
| 2571 |
fi # !dst_usr_flg |
| 2572 |
if [ "${dst_usr_flg}" != 'Yes' ] && [ "${grd_dst_usr_flg}" = 'Yes' ] && [ "${map_usr_flg}" != 'Yes' ] && [ "${grd_sng_usr_flg}" = 'Yes' ] && [ "${vrt_usr_flg}" != 'Yes' ]; then |
| 2573 |
flg_grd_only='Yes' |
| 2574 |
fi # !flg_grd_only |
| 2575 |
if [ "${map_mk}" = 'Yes' ] || [ "${map_usr_flg}" = 'Yes' ]; then |
| 2576 |
flg_hrz='Yes' |
| 2577 |
fi # !map_mk, !map_usr_flg |
| 2578 |
if [ "${flg_hrz}" != 'Yes' ]; then |
| 2579 |
# Turn-off dimension permutation if file will not be horizontally regridded |
| 2580 |
pdq_opt='' |
| 2581 |
pdq_flg='No' |
| 2582 |
fi # !flg_hrz |
| 2583 |
|
| 2584 |
# Generate destination grid, if necessary, once (only) before loop over input files |
| 2585 |
# Block 1: Destination grid |
| 2586 |
# Generate destination grid at most one-time (unlike source grid) |
| 2587 |
# Eventually we will allow destination grid to be provided as grid-file, map-file, or data-file without a switch |
| 2588 |
# Currently we require user to know (and specify) means by which destination grid is provided |
| 2589 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2590 |
if [ ${fl_nbr} -eq 0 ]; then |
| 2591 |
printf "Map/grid-only run: no input data detected therefore will exit after generating map and/or grid\n" |
| 2592 |
fi # !fl_nbr |
| 2593 |
if [ -n "${pdq_opt}" ] && [ "${pdq_flg}" = 'Yes' ]; then |
| 2594 |
printf "Input data shaped in native \"${prc_typ}\"-order, will permute with \"ncpdq ${pdq_opt}\" prior to horizontal regridding\n" |
| 2595 |
fi # !pdq_opt |
| 2596 |
if [ "${d2f_flg}" = 'Yes' ]; then |
| 2597 |
printf "Will convert all non-coordinate double precision input fields to single precision with \"ncpdq ${d2f_opt}\"\n" |
| 2598 |
fi # !d2f_flg |
| 2599 |
if [ "${prc_mpas}" = 'Yes' ]; then |
| 2600 |
printf "MPAS input specified: will automatically renormalize (with --rnr=0.0) horizontally regridded fields\n" |
| 2601 |
if [ "${clm_flg}" = 'No' ]; then |
| 2602 |
printf "MPAS input specified: will automatically annotate NC_FLOAT and NC_DOUBLE variables with _FillValue = ${mss_val} prior to horizontal regridding\n" |
| 2603 |
fi # !clm_flg |
| 2604 |
if [ "${dpt_flg}" = 'Yes' ]; then |
| 2605 |
printf "MPAS input specified: will add depth coordinate to all 3D variables prior to horizontal regridding\n" |
| 2606 |
fi # !dpt_flg |
| 2607 |
fi # !mpas |
| 2608 |
if [ "${prc_sgs}" = 'Yes' ]; then |
| 2609 |
printf "Input assumed to contain sub-gridscale (SGS, aka \"fractional area\") data: Intensive values valid in gridcell for spatiotemporal fraction specified by \"${sgs_frc}\" variable, not for entire gridcell area and/or time-interval duration (except where ${sgs_frc} = 1.0). Will regrid ${sgs_frc}, and then normalize subsequent regridding to conserve ${sgs_frc}*gridcell_area*field_value (not gridcell_area*field_value). If re-normalization is also requested (e.g., with --rnr_thr option, or with --preserve=mean), then these values will be renormalized by ${sgs_frc} and will not be conservative.\n" |
| 2610 |
if [ ${fl_nbr} -eq 0 ]; then |
| 2611 |
printf "${spt_nm}: ERROR Sub-gridscale handling currently requires at least one data file (for the surface fractions of each gridcell)\n" |
| 2612 |
echo "${spt_nm}: HINT Supply a data file with \"-i fl_in\"" |
| 2613 |
exit 1 |
| 2614 |
fi # !fl_nbr |
| 2615 |
fi # !prc_sgs |
| 2616 |
fi # !vrb_lvl |
| 2617 |
if [ "${flg_hrz}" = 'Yes' ]; then |
| 2618 |
if [ "${map_mk}" != 'Yes' ] && [ "${map_usr_flg}" = 'Yes' ]; then |
| 2619 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2620 |
printf "Source and destination grids will both be read from supplied map-file\n" |
| 2621 |
fi # !vrb_lvl |
| 2622 |
else # !map_usr_flg |
| 2623 |
fl_idx=0 # [idx] Current file index |
| 2624 |
if [ "${dst_usr_flg}" = 'Yes' ]; then |
| 2625 |
# Block 1 Loop 1: Generate, check, and store (but do not yet execute) commands |
| 2626 |
# Infer destination grid-file from data file |
| 2627 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2628 |
printf "Destination grid will be inferred from destination data-file\n" |
| 2629 |
fi # !vrb_lvl |
| 2630 |
cmd_dst[${fl_idx}]="ncks -O ${nco_opt} --rgr infer --rgr hnt_dst=\"${hnt_dst_fl}\" ${nco_dgn_area} ${nco_msk_dst} ${nco_var_rgr} ${nco_ugrid_fl} --rgr scrip=\"${grd_dst}\" \"${dst_fl}\" \"${tmp_out_fl}\"" |
| 2631 |
else # !dst_usr_flg |
| 2632 |
if [ "${grd_dst_usr_flg}" = 'Yes' ] && [ "${grd_sng_usr_flg}" != 'Yes' ]; then |
| 2633 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2634 |
printf "Destination grid supplied by user\n" |
| 2635 |
fi # !vrb_lvl |
| 2636 |
fi # !grd_dst_usr_flg |
| 2637 |
if [ "${grd_dst_usr_flg}" != 'Yes' ] && [ "${grd_sng_usr_flg}" != 'Yes' ]; then |
| 2638 |
printf "${spt_nm}: WARNING No destination grid specified with -g, template/inferral file specified with -d, or grid string specified with -G\n" |
| 2639 |
fi # !grd_dst_usr_flg |
| 2640 |
if [ "${grd_sng_usr_flg}" = 'Yes' ]; then |
| 2641 |
# 20180903 Must quote grd_sng otherwise whitespace and shell redirection characters (e.g., in ttl argument) will confuse interpreter |
| 2642 |
cmd_dst[${fl_idx}]="ncks -O --dmm_in_mk ${nco_opt} --rgr scrip=\"${grd_dst}\" ${nco_skl_fl} --rgr '${grd_sng}' \"${dmm_fl}\" \"${tmp_out_fl}\"" |
| 2643 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2644 |
if [ "${grd_dst_usr_flg}" = 'Yes' ]; then |
| 2645 |
printf "Destination grid will be generated in SCRIP format from NCO grid-formula ${grd_sng} and stored in ${grd_dst}\n" |
| 2646 |
else |
| 2647 |
printf "Destination grid will be generated in SCRIP format from NCO grid-formula ${grd_sng} and stored in a temporary, internal location\n" |
| 2648 |
fi # !grd_sng_usr_flg |
| 2649 |
fi # !vrb_lvl |
| 2650 |
fi # !grd_sng_usr_flg |
| 2651 |
fi # !dst_usr_flg |
| 2652 |
if [ "${dst_usr_flg}" = 'Yes' ] || [ "${grd_sng_usr_flg}" = 'Yes' ]; then |
| 2653 |
# Block 1 Loop 2: Execute and/or echo commands |
| 2654 |
if [ ${wgt_typ} != 'cdo' ]; then |
| 2655 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2656 |
echo ${cmd_dst[${fl_idx}]} |
| 2657 |
fi # !dbg |
| 2658 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2659 |
eval ${cmd_dst[${fl_idx}]} |
| 2660 |
if [ "$?" -ne 0 ]; then |
| 2661 |
if [ "${grd_sng_usr_flg}" = 'Yes' ]; then |
| 2662 |
printf "${spt_nm}: ERROR Failed to generate grid from user-supplied grid-string. Debug this:\n${cmd_dst[${fl_idx}]}\n" |
| 2663 |
else # !grd_sng_usr_flg |
| 2664 |
printf "${spt_nm}: ERROR Failed to infer destination grid. Debug this:\n${cmd_dst[${fl_idx}]}\n" |
| 2665 |
fi # !grd_sng_usr_flg |
| 2666 |
exit 1 |
| 2667 |
fi # !err |
| 2668 |
if [ "${grd_sng_usr_flg}" = 'Yes' ]; then |
| 2669 |
/bin/rm -f ${tmp_out_fl} |
| 2670 |
fi # !grd_sng_usr_flg |
| 2671 |
fi # !dbg |
| 2672 |
fi # !cdo |
| 2673 |
fi # !dst_usr_flg || grd_dst_usr_flg |
| 2674 |
if [ ${vrb_lvl} -ge ${vrb_3} ] && [ ${flg_grd_only} != 'Yes' ]; then |
| 2675 |
printf "Weight-generation type: ${wgt_typ}\n" |
| 2676 |
printf "Algorithm selected to generate weights in map-file is: ${alg_opt}\n" |
| 2677 |
printf "Will generate mapping weights and map-file with \'${wgt_cmd}\'\n" |
| 2678 |
[[ -n "${map_nfo_sng}" ]] && echo "${map_nfo_sng}" |
| 2679 |
fi # !vrb_lvl |
| 2680 |
if [ ${flg_grd_only} != 'Yes' ]; then |
| 2681 |
command -v ${wgt_exe} 2>&1 > /dev/null || { printf "${spt_nm}: ERROR cannot find weight-generation command executable ${wgt_exe}. Please install the executable, and/or change your PATH to find it.\n${spt_nm}: HINT The Conda 'nco' package automagically installs the 'esmf' package to provide ESMF_RegridWeightGen and the 'tempest-remap' package to install TempestRemap executables such as 'GenerateOfflineMap'. One can obtain the MOAB-Tempest executables like 'mbtempest' via the Conda 'moab' package.\n"; exit 1; } |
| 2682 |
fi # !flg_grd_only |
| 2683 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2684 |
if [ ${fl_nbr} -ge 2 ]; then |
| 2685 |
if [ "${mlt_map_flg}" = 'Yes' ]; then |
| 2686 |
printf "Input files assumed to use unique input grids\nOne source grid-file will be inferred and one map-file generated per input file\n" |
| 2687 |
else # !mlt_map_flg |
| 2688 |
printf "Input files assumed to use same input grid\nOnly one source grid-file and one map-file will be generated\n" |
| 2689 |
fi # !mlt_map_flg |
| 2690 |
fi # !fl_nbr |
| 2691 |
fi # !vrb_lvl |
| 2692 |
fi # !map_usr |
| 2693 |
fi # !flg_hrz |
| 2694 |
|
| 2695 |
if [ "${prc_typ}" = 'rrg' ]; then |
| 2696 |
fl_idx=0 |
| 2697 |
|
| 2698 |
if [ -z "${rnm_sng}" ]; then |
| 2699 |
# Discern rename string from input file, assume dimension is 'ncol', strip whitespace |
| 2700 |
rnm_sng=`ncks -m ${fl_in[${fl_idx}]} | cut -d ':' -f 1 | cut -d '=' -s -f 1 | grep ncol | sed 's/ncol//' | sed -e 's/^ *//' -e 's/ *$//'` |
| 2701 |
rgn_nbr=`echo ${rnm_sng} | wc -l` |
| 2702 |
if [ "${rgn_nbr}" -ne 1 ]; then |
| 2703 |
echo "ERROR: Inferred regional regridding suffix '${rnm_sng}' indicates multiple regions present in input file. ncremap only works on one region at a time." |
| 2704 |
echo "HINT: Provide a single region string as the argument to the --rrg_rnm_sng option" |
| 2705 |
exit 1 |
| 2706 |
fi # !rgn_nbr |
| 2707 |
echo "${spt_nm}: INFO Parsed input file dimension list to obtain regional suffix string '${rnm_sng}'" |
| 2708 |
fi # !rnm_sng |
| 2709 |
if [ -n "${rnm_sng}" ]; then |
| 2710 |
if [ -n "${bb_wesn}" ]; then |
| 2711 |
echo "${spt_nm}: INFO Will use explicitly specified comma-separated rectangular WESN bounding box string ${bb_wesn} instead of parsing string suffix ${rnm_sng}." |
| 2712 |
else # !bb_wesn |
| 2713 |
rnm_rx='^_(.*)_to_(.*)_(.*)_to_(.*)$' |
| 2714 |
if [[ "${rnm_sng}" =~ ${rnm_rx} ]]; then |
| 2715 |
lon1=${BASH_REMATCH[1]%?} |
| 2716 |
lon2=${BASH_REMATCH[2]%?} |
| 2717 |
if [ "${BASH_REMATCH[1]: -1}" = 'w' ]; then |
| 2718 |
let lon1=360-${lon1} |
| 2719 |
fi # !w |
| 2720 |
if [ "${BASH_REMATCH[2]: -1}" = 'w' ]; then |
| 2721 |
let lon2=360-${lon2} |
| 2722 |
fi # !w |
| 2723 |
if [ ${lon1} -lt ${lon2} ]; then |
| 2724 |
lon_min=${lon1} |
| 2725 |
lon_max=${lon2} |
| 2726 |
else |
| 2727 |
# 20210526 Until today we swapped the W,E bounds incorrectly |
| 2728 |
# if wrapped nco_aux_prs() adds 360 degrees to lon_max to ensure lon_min < lon_max |
| 2729 |
lon_min=${lon2} |
| 2730 |
lon_max=${lon1} |
| 2731 |
fi # !lon1 |
| 2732 |
lat1=${BASH_REMATCH[3]%?} |
| 2733 |
lat2=${BASH_REMATCH[4]%?} |
| 2734 |
if [ "${BASH_REMATCH[3]: -1}" = 's' ]; then |
| 2735 |
let lat1=-${lat1} |
| 2736 |
fi # !w |
| 2737 |
if [ "${BASH_REMATCH[4]: -1}" = 's' ]; then |
| 2738 |
let lat2=-${lat2} |
| 2739 |
fi # !w |
| 2740 |
if [ ${lat1} -lt ${lat2} ]; then |
| 2741 |
lat_min=${lat1} |
| 2742 |
lat_max=${lat2} |
| 2743 |
else |
| 2744 |
lat_min=${lat2} |
| 2745 |
lat_max=${lat1} |
| 2746 |
fi # !lat1 |
| 2747 |
else # !rnm_sng |
| 2748 |
echo "ERROR: Regional regridding suffix string '${rnm_sng}' does not match regular expression '${rnm_rx}'" |
| 2749 |
echo "HINT: Regional regridding suffix string must have form like '_128e_to_134e_9s_to_16s' or '_20w_to_20e_10s_to_10n'" |
| 2750 |
exit 1 |
| 2751 |
fi # !rnm_sng |
| 2752 |
bb_wesn="${lon_min},${lon_max},${lat_min},${lat_max}" |
| 2753 |
echo "${spt_nm}: INFO Parsed suffix string ${rnm_sng} to obtain comma-separated rectangular WESN bounding box string ${bb_wesn}" |
| 2754 |
fi # !bb_wesn |
| 2755 |
else |
| 2756 |
echo "${spt_nm}: ERROR Regional regridding requires string suffix appended to variables in regional data file to be specified with --rrg_rnm_sng argument" |
| 2757 |
exit 1 |
| 2758 |
fi # !rnm_sng |
| 2759 |
|
| 2760 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2761 |
printf "Input assumed to be EAM/CAM-SE format regional data to regrid (aka RRG). RRG data are usually produced by explicitly requesting (sometimes multiple) regions from EAM/CAM-SE models with the \"finclNlonlat\" namelist variable. Will infer SCRIP-format regional source grid by cutting vertice information (originally from global dual-grid file ${grd_glb}) from rectangular WESN bounding box \"${bb_wesn}\" of identity-remapped (and thus vertice-annotated) copy of global data file ${dat_glb}. Will then create single map-file to regrid copy of requested fields with \"${rnm_sng}\" removed from dimension and variable names.\n" |
| 2762 |
fi # !vrb_lvl |
| 2763 |
|
| 2764 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2765 |
printf "RRG: Identity-remap global data file from/to dual-grid to annotate it with vertices...\n" |
| 2766 |
fi # !vrb_lvl |
| 2767 |
cmd_nnt[${fl_idx}]="ncremap --vrb=0 -a esmfbilin -s \"${grd_glb}\" -g \"${grd_glb}\" \"${dat_glb}\" \"${nnt_fl}\"" |
| 2768 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2769 |
echo ${cmd_nnt[${fl_idx}]} |
| 2770 |
fi # !dbg |
| 2771 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2772 |
eval ${cmd_nnt[${fl_idx}]} |
| 2773 |
if [ "$?" -ne 0 ]; then |
| 2774 |
printf "${spt_nm}: ERROR Failed to identity-remap to annotate global data file. Debug this:\n${cmd_nnt[${fl_idx}]}\n" |
| 2775 |
exit 1 |
| 2776 |
fi # !err |
| 2777 |
fi # !dbg |
| 2778 |
|
| 2779 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2780 |
printf "RRG: Subset coordinates to rectangular WESN regional bounding box ${bb_wesn}...\n" |
| 2781 |
fi # !vrb_lvl |
| 2782 |
cmd_sbs[${fl_idx}]="ncks -O -v lat,lon -X ${bb_wesn} \"${nnt_fl}\" \"${rgn_fl}\"" |
| 2783 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2784 |
echo ${cmd_sbs[${fl_idx}]} |
| 2785 |
fi # !dbg |
| 2786 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2787 |
eval ${cmd_sbs[${fl_idx}]} |
| 2788 |
if [ "$?" -ne 0 ]; then |
| 2789 |
printf "${spt_nm}: ERROR Failed to subset and hyperslab coordinates into regional file. Debug this:\n${cmd_sbs[${fl_idx}]}\n" |
| 2790 |
exit 1 |
| 2791 |
fi # !err |
| 2792 |
fi # !dbg |
| 2793 |
|
| 2794 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2795 |
printf "RRG: Infer source grid from subsetted, annotated, regional coordinate file...\n" |
| 2796 |
fi # !vrb_lvl |
| 2797 |
cmd_nfr[${fl_idx}]="ncks -O ${nco_opt} --rgr infer --rgr hnt_src=\"${hnt_src_fl}\" ${nco_dgn_area} ${nco_msk_src} ${nco_var_rgr} --rgr scrip=\"${grd_src}\" \"${rgn_fl}\" \"${tmp_out_fl}\"" |
| 2798 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2799 |
echo ${cmd_nfr[${fl_idx}]} |
| 2800 |
fi # !dbg |
| 2801 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2802 |
eval ${cmd_nfr[${fl_idx}]} |
| 2803 |
if [ "$?" -ne 0 ]; then |
| 2804 |
printf "${spt_nm}: ERROR Failed to infer source grid from subsetted, annotated, regional coordinate file. Debug this:\n${cmd_nfr[${fl_idx}]}\n" |
| 2805 |
exit 1 |
| 2806 |
fi # !err |
| 2807 |
fi # !dbg |
| 2808 |
fi # !rrg |
| 2809 |
|
| 2810 |
# 20211102 Pre-process destination grid prior to weight-generation by mbtempest |
| 2811 |
# NB: Unlike source grid, destination grid never changes in file-loop, so pre-process here |
| 2812 |
if [ "${map_mk}" = 'Yes' ]; then |
| 2813 |
if [ "${wgt_typ}" = 'mbtempest' ]; then |
| 2814 |
# 20210827 Pre-process input .nc, .g, and .h5m files to partitioned .h5m files |
| 2815 |
if [[ ${grd_dst} == *.g ]] || [[ ${grd_dst} == *.exo ]] || [[ ${grd_dst} == *".nc"* ]]; then |
| 2816 |
[[ ${grd_dst} == *.g ]] && grd_dst_h5m_tmp="${grd_dst/.g/.h5m}" |
| 2817 |
[[ ${grd_dst} == *.exo ]] && grd_dst_h5m_tmp="${grd_dst/.exo/.h5m}" |
| 2818 |
[[ ${grd_dst} == *".nc"* ]] && grd_dst_h5m_tmp="${grd_dst/.nc/.h5m}" |
| 2819 |
# 20260220: Vijay says on Slack DM that TR Exodus *.g files require (serial) TR Exodus reader accessed via -B |
| 2820 |
# mbconvert can only parallelize conversion of true, official Exodus (*.exo) and SCRIP files |
| 2821 |
# "g2m" stands for "grid-to-MOAB", meaning command converts any grid-type to MOAB |
| 2822 |
[[ ${grd_dst} == *.g ]] || [[ ${mbt_grd_nc4} = 'Yes' ]] && mbt_grd_rd_srl='Yes' || mbt_grd_rd_srl='No' |
| 2823 |
[[ ${mbt_grd_rd_srl} = 'Yes' ]] && cnv_opt_g2m=${cnv_opt_srl_e2m} || cnv_opt_g2m=${cnv_opt_prl_n2m} |
| 2824 |
cmd_g2m[${fl_idx}]="${cmd_cnv_mbt} ${cnv_opt_dst} ${cnv_opt_g2m} \"${grd_dst}\" \"${grd_dst_h5m_tmp}\"${devnull}" |
| 2825 |
[[ ${mbt_grd_rd_srl} = 'No' ]] && cmd_g2m[${fl_idx}]="${mpi_pfx} ${cmd_g2m[${fl_idx}]}" |
| 2826 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2827 |
echo ${cmd_g2m[${fl_idx}]} |
| 2828 |
fi # !dbg |
| 2829 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2830 |
eval ${cmd_g2m[${fl_idx}]} |
| 2831 |
if [ "$?" -ne 0 ] || [ ! -f ${grd_src_h5m} ]; then |
| 2832 |
printf "${spt_nm}: ERROR Failed to convert destination grid to MOAB H5M format. Debug this:\n${cmd_g2m[${fl_idx}]}\n" |
| 2833 |
printf "${cnv_exe_hnt}" |
| 2834 |
exit 1 |
| 2835 |
fi # !err |
| 2836 |
fi # !dbg |
| 2837 |
grd_dst=${grd_dst_h5m_tmp} |
| 2838 |
fi # !grd_dst |
| 2839 |
fi # !mbtempest |
| 2840 |
fi # !map_mk |
| 2841 |
|
| 2842 |
# If user provides source gridfile, or it was inferred in RRG or SGS modes, assume it applies to every input file |
| 2843 |
# In that case, no need to infer source gridfiles within file loop |
| 2844 |
# Generate map-file once outside of file loop, and re-use it for every input file |
| 2845 |
if [ "${grd_src_usr_flg}" = 'Yes' ] || [ "${prc_typ}" = 'rrg' ]; then |
| 2846 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 2847 |
printf "Source grid supplied by user (or derived from RRG procedure) as ${grd_src}\n" |
| 2848 |
fi # !vrb_lvl |
| 2849 |
fl_idx=0 |
| 2850 |
if [ ${vrb_lvl} -ge ${vrb_1} ]; then |
| 2851 |
printf "Grid(src): ${grd_src}\n" |
| 2852 |
printf "Grid(dst): ${grd_dst}\n" |
| 2853 |
fi # !vrb_lvl |
| 2854 |
if [ "${wgt_typ}" = 'cdo' ]; then |
| 2855 |
cmd_map[${fl_idx}]="${wgt_cmd} -gencon,\"${dst_fl}\" \"${in_fl}\" \"${map_fl}\"${devnull}" |
| 2856 |
#cmd_map[${fl_idx}]="${wgt_cmd} -gencon,\"${grd_dst}\" \"${grd_src}\" \"${map_fl}\"${devnull}" |
| 2857 |
elif [ "${wgt_typ}" = 'esmf' ]; then |
| 2858 |
rgn_opt='' |
| 2859 |
if [ -n "${hnt_src}" ]; then |
| 2860 |
rgn_opt="${rgn_opt} ${hnt_src}" |
| 2861 |
elif [ -f "${hnt_src_fl}" ]; then |
| 2862 |
rgn_opt="${rgn_opt} `cat ${hnt_src_fl}`" |
| 2863 |
fi # !hnt_src_fl |
| 2864 |
if [ -n "${hnt_dst}" ]; then |
| 2865 |
rgn_opt="${rgn_opt} ${hnt_dst}" |
| 2866 |
elif [ -f "${hnt_dst_fl}" ]; then |
| 2867 |
rgn_opt="${rgn_opt} `cat ${hnt_dst_fl}`" |
| 2868 |
fi # !hnt_dst_fl |
| 2869 |
cmd_map[${fl_idx}]="${wgt_cmd} -s \"${grd_src}\" -d \"${grd_dst}\" -w \"${map_fl}\" --method ${alg_opt} ${wgt_opt} ${rgn_opt}${devnull}" |
| 2870 |
elif [ "${wgt_typ}" = 'nco' ]; then |
| 2871 |
cmd_map[${fl_idx}]="${wgt_cmd} ${wgt_opt} --thr_nbr=${thr_nbr} ${nco_opt} --grd_src=\"${grd_src}\" --grd_dst=\"${grd_dst}\" --map_fl=\"${map_fl}\" ${msh_opt} ${rgr_opt} \"${dmm_fl}\" \"${tmp_out_fl}\"${devnull}" |
| 2872 |
elif [ "${wgt_typ}" = 'mbtempest' ]; then |
| 2873 |
# 20210827 Pre-process input .nc, .g, and .h5m files to partitioned .h5m files |
| 2874 |
if [[ ${grd_src} == *.g ]] || [[ ${grd_src} == *.exo ]] || [[ ${grd_src} == *".nc"* ]]; then |
| 2875 |
[[ ${grd_src} == *.g ]] && grd_src_h5m_tmp="${grd_src/.g/.h5m}" |
| 2876 |
[[ ${grd_src} == *.exo ]] && grd_src_h5m_tmp="${grd_src/.exo/.h5m}" |
| 2877 |
[[ ${grd_src} == *".nc"* ]] && grd_src_h5m_tmp="${grd_src/.nc/.h5m}" |
| 2878 |
# 20260220: Vijay says on Slack DM that TR Exodus *.g files require (serial) TR Exodus reader accessed via -B |
| 2879 |
# mbconvert can only parallelize conversion of true, official Exodus (*.exo) and SCRIP files |
| 2880 |
[[ ${grd_src} == *.g ]] || [[ ${mbt_grd_nc4} = 'Yes' ]] && mbt_grd_rd_srl='Yes' || mbt_grd_rd_srl='No' |
| 2881 |
[[ ${mbt_grd_rd_srl} = 'Yes' ]] && cnv_opt_g2m=${cnv_opt_srl_e2m} || cnv_opt_g2m=${cnv_opt_prl_n2m} |
| 2882 |
cmd_g2m[${fl_idx}]="${cmd_cnv_mbt} ${cnv_opt_src} ${cnv_opt_g2m} \"${grd_src}\" \"${grd_src_h5m_tmp}\"${devnull}" |
| 2883 |
[[ ${mbt_grd_rd_srl} = 'No' ]] && cmd_g2m[${fl_idx}]="${mpi_pfx} ${cmd_g2m[${fl_idx}]}" |
| 2884 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2885 |
echo ${cmd_g2m[${fl_idx}]} |
| 2886 |
fi # !dbg |
| 2887 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2888 |
eval ${cmd_g2m[${fl_idx}]} |
| 2889 |
if [ "$?" -ne 0 ] || [ ! -f ${grd_src_h5m_tmp} ]; then |
| 2890 |
printf "${spt_nm}: ERROR Failed to convert source grid to MOAB H5M format. Debug this:\n${cmd_g2m[${fl_idx}]}\n" |
| 2891 |
printf "${cnv_exe_hnt}" |
| 2892 |
exit 1 |
| 2893 |
fi # !err |
| 2894 |
fi # !dbg |
| 2895 |
grd_src=${grd_src_h5m_tmp} |
| 2896 |
fi # !grd_src |
| 2897 |
# 20260226: NB: this fails if non-MOAB .h5m grid-name ends with "p" |
| 2898 |
if [[ ${grd_src} == *.h5m ]] && [[ ${grd_src} != *p.h5m ]]; then |
| 2899 |
grd_src_prt_tmp="${grd_src/.h5m/_${prt_nbr}p.h5m}" |
| 2900 |
grd_dst_prt_tmp="${grd_dst/.h5m/_inferred.h5m}" |
| 2901 |
if [ ${prt_alg} = 'zoltan' ]; then |
| 2902 |
# 20260302: Use Recursive Coordinate Bisection (RCB) repartitioning scheme |
| 2903 |
# mbpart runs in serial to create meshes for mbtempest to read in parallel |
| 2904 |
cmd_prt[${fl_idx}]="${cmd_prt_mbt} ${prt_nbr} --zoltan RCB --recompute_rcb_box --project_on_sphere 2 --scale_sphere --imbalance 1.002 --inferred \"${grd_dst}\" \"${grd_src}\" \"${grd_src_prt_tmp}\"${devnull}" |
| 2905 |
fi # !HOSTNAME |
| 2906 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2907 |
echo ${cmd_prt[${fl_idx}]} |
| 2908 |
fi # !dbg |
| 2909 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2910 |
eval ${cmd_prt[${fl_idx}]} |
| 2911 |
if [ "$?" -ne 0 ] || [ ! -f ${grd_src_prt_tmp} ]; then |
| 2912 |
printf "${spt_nm}: ERROR Failed to partition MOAB version of source grid. Debug this:\n${cmd_prt[${fl_idx}]}\n" |
| 2913 |
printf "${spt_nm}: HINT ${prt_exe_mbt} can fail for a number of reasons including 1) fxm ...\n" |
| 2914 |
exit 1 |
| 2915 |
fi # !err |
| 2916 |
fi # !dbg |
| 2917 |
grd_src=${grd_src_prt_tmp} |
| 2918 |
grd_dst=${grd_dst_prt_tmp} |
| 2919 |
fi # !grd_src |
| 2920 |
if [ ${prt_alg} = 'zoltan' ]; then |
| 2921 |
cmd_map[${fl_idx}]="${wgt_cmd} --type ${mbt_typ_map} --weights --load \"${grd_src}\" --load \"${grd_dst}\" ${wgt_opt} --file \"${map_fl}\"${devnull}" |
| 2922 |
fi # !prt_alg |
| 2923 |
elif [ "${wgt_typ}" = 'tempest' ]; then |
| 2924 |
cmd_msh[${fl_idx}]="${cmd_msh_tps} ${msh_opt_tps} --a \"${grd_src}\" --b \"${grd_dst}\" --out \"${msh_fl}\"${devnull}" |
| 2925 |
if [ "${a2o_flg}" = 'Yes' ]; then |
| 2926 |
cmd_msh[${fl_idx}]="${cmd_msh_tps} ${msh_opt_tps} --b \"${grd_src}\" --a \"${grd_dst}\" --out \"${msh_fl}\"${devnull}" |
| 2927 |
fi # !a2o_flg |
| 2928 |
cmd_map[${fl_idx}]="${wgt_cmd} --in_mesh \"${grd_src}\" --out_mesh \"${grd_dst}\" --ov_mesh \"${msh_fl}\" --out_map \"${map_fl}\" ${wgt_opt}${devnull}" |
| 2929 |
if [ "${trn_map}" = 'Yes' ]; then |
| 2930 |
# NB: Generate mono map for opposite direction regridding (i.e., reverse switches and grids), then transpose |
| 2931 |
cmd_map[${fl_idx}]="${wgt_cmd} --in_mesh \"${grd_dst}\" --out_mesh \"${grd_src}\" --ov_mesh \"${msh_fl}\" --out_map \"${map_trn_fl}\" ${wgt_opt}${devnull}" |
| 2932 |
cmd_trn[${fl_idx}]="GenerateTransposeMap --in \"${map_trn_fl}\" --out \"${map_fl}\"${devnull}" |
| 2933 |
fi # !trn_map |
| 2934 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2935 |
echo ${cmd_msh[${fl_idx}]} |
| 2936 |
fi # !dbg |
| 2937 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2938 |
eval ${cmd_msh[${fl_idx}]} |
| 2939 |
if [ "$?" -ne 0 ] || [ ! -f ${msh_fl} ]; then |
| 2940 |
printf "${spt_nm}: ERROR Failed to generate intersection mesh-file. Debug this:\n${cmd_msh[${fl_idx}]}\n" |
| 2941 |
printf "${spt_nm}: HINT ${msh_exe_tps} can fail for a number of reasons including 1) It requires that grids of unequal area be given as arguments in the order smaller first, larger second. ncremap supplies the grid arguments in the order source first, destination second unless explicitly told otherwise. A source grid that is a superset of the destination would violate the ${msh_exe_tps} rule. The solution is to add the \"--a2o\" switch (documented at http://nco.sf.net/nco.html#a2o) that tells ncremap to swap the grid argument order. 2) It requires that SCRIP files strictly adhere to SCRIP conventions, including that \"grid_imask\" be of integer type not floating-point type. Unfortunately some malformed SCRIP files violate this convention. The workaround can be as simple as \"ncap2 -s 'grid_imask=int(grid_imask)' grid_in.nc grid_out.nc\"\n" |
| 2942 |
exit 1 |
| 2943 |
fi # !err |
| 2944 |
fi # !dbg |
| 2945 |
fi # !wgt_typ |
| 2946 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2947 |
echo ${cmd_map[${fl_idx}]} |
| 2948 |
fi # !dbg |
| 2949 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2950 |
eval ${cmd_map[${fl_idx}]} |
| 2951 |
if [ "$?" -ne 0 ] || [ ! -f ${map_rsl_fl} ]; then |
| 2952 |
printf "${spt_nm}: ERROR Failed to generate map-file. Debug this:\n${cmd_map[${fl_idx}]}\n" |
| 2953 |
if [ "${wgt_typ}" = 'esmf' ]; then |
| 2954 |
printf "${spt_nm}: HINT When ESMF fails to generate map-files, it often puts additional debugging information in the file named PET0.RegridWeightGen.Log in the invocation directory (${drc_pwd})\n" |
| 2955 |
fi # !esmf |
| 2956 |
exit 1 |
| 2957 |
fi # !err |
| 2958 |
fi # !dbg |
| 2959 |
# 20181116: GenerateTransposeMap does not propagate global attributes from input map |
| 2960 |
# Moreover, it does not generate any metadata of its own except "Title" |
| 2961 |
# Hence monotr maps are naked of usual Tempest map metadata |
| 2962 |
if [ "${trn_map}" = 'Yes' ]; then |
| 2963 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2964 |
echo ${cmd_trn[${fl_idx}]} |
| 2965 |
fi # !dbg |
| 2966 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2967 |
eval ${cmd_trn[${fl_idx}]} |
| 2968 |
if [ "$?" -ne 0 ] || [ ! -f ${map_fl} ]; then |
| 2969 |
printf "${spt_nm}: ERROR Failed to transpose map-file. Debug this:\n${cmd_trn[${fl_idx}]}\n" |
| 2970 |
exit 1 |
| 2971 |
fi # !err |
| 2972 |
fi # !dbg |
| 2973 |
fi # !trn_map |
| 2974 |
if [ "${map_usr_flg}" = 'Yes' ]; then |
| 2975 |
hst_att="`date`: ${cmd_ln}; ${cmd_map[${fl_idx}]}" |
| 2976 |
if [ "${wgt_typ}" = 'tempest' ]; then |
| 2977 |
hst_att="`date`: ${cmd_ln}; ${cmd_msh[${fl_idx}]}; ${cmd_map[${fl_idx}]}" |
| 2978 |
if [ "${trn_map}" = 'Yes' ]; then |
| 2979 |
hst_att="${hst_att}; ${cmd_trn[${fl_idx}]}" |
| 2980 |
fi # !trn_map |
| 2981 |
fi # !tempest |
| 2982 |
cmd_att[${fl_idx}]="ncatted -O ${gaa_sng} --gaa history='${hst_att}' ${gad_sng} \"${map_fl}\"" |
| 2983 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 2984 |
echo ${cmd_att[${fl_idx}]} |
| 2985 |
fi # !dbg |
| 2986 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 2987 |
eval ${cmd_att[${fl_idx}]} |
| 2988 |
if [ "$?" -ne 0 ] || [ ! -f ${map_fl} ]; then |
| 2989 |
printf "${spt_nm}: ERROR Failed to annotate map-file. Debug this:\n${cmd_att[${fl_idx}]}\n" |
| 2990 |
exit 1 |
| 2991 |
fi # !err |
| 2992 |
fi # !dbg |
| 2993 |
fi # !map_usr_flg |
| 2994 |
# Set map_mk to something besides 'Yes' to avoid re-generating map within file loop |
| 2995 |
map_mk='Already made map once. Never again!' |
| 2996 |
fi # !grd_src_usr_flg |
| 2997 |
|
| 2998 |
# Begin loop over input files |
| 2999 |
let bch_nbr=$((fl_nbr / job_nbr)) |
| 3000 |
let bch_flg=$((fl_nbr % job_nbr)) |
| 3001 |
if [ ${fl_nbr} -gt 0 ] && [ ${bch_nbr} -eq 0 ]; then |
| 3002 |
let bch_nbr=$((bch_nbr+1)) |
| 3003 |
elif [ ${bch_flg} -ne 0 ]; then |
| 3004 |
let bch_nbr=$((bch_nbr+1)) |
| 3005 |
fi # !bch_flg |
| 3006 |
let bch_nbrm1=$((bch_nbr-1)) |
| 3007 |
for ((bch_idx=0;bch_idx<bch_nbr;bch_idx++)); do |
| 3008 |
# fl_idx is 0-based, bch_idx is 0-based |
| 3009 |
let fl_idx_srt=$((bch_idx * job_nbr)) |
| 3010 |
let fl_idx_end=$((fl_idx_srt + job_nbr - 1)) |
| 3011 |
if [ ${bch_idx} -eq ${bch_nbrm1} ] && [ ${bch_flg} -ne 0 ]; then |
| 3012 |
let fl_idx_srt=$((bch_idx * job_nbr)) |
| 3013 |
let fl_idx_end=$((fl_nbr - 1)) |
| 3014 |
fi # !bch_flg |
| 3015 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3016 |
in_fl=${fl_in[${fl_idx}]} |
| 3017 |
if [ "$(basename "${in_fl}")" = "${in_fl}" ]; then |
| 3018 |
in_fl="${drc_pwd}/${in_fl}" |
| 3019 |
fi # !basename |
| 3020 |
idx_prn=`printf "%02d" ${fl_idx}` |
| 3021 |
if [ ${vrb_lvl} -ge ${vrb_1} ]; then |
| 3022 |
printf "Input #${idx_prn}: ${in_fl}\n" |
| 3023 |
fi # !vrb_lvl |
| 3024 |
if [ "${out_usr_flg}" = 'Yes' ]; then |
| 3025 |
if [ ${fl_nbr} -ge 2 ]; then |
| 3026 |
echo "ERROR: Single output filename specified with -o for multiple input files" |
| 3027 |
echo "HINT: For multiple input files use -O option to specify output directory and do not use -o or second positional option. Output files will have same name as input files, but will be in different directory." |
| 3028 |
exit 1 |
| 3029 |
fi # !fl_nbr |
| 3030 |
if [ -n "${drc_usr}" ]; then |
| 3031 |
out_fl="${drc_out}/${out_fl}" |
| 3032 |
fi # !drc_usr |
| 3033 |
else # !out_usr_flg |
| 3034 |
out_fl="${drc_out}/$(basename "${in_fl}")" |
| 3035 |
fi # !out_fl |
| 3036 |
# Test whether input and output filenames point to the same file (i.e., same device and inode numbers) |
| 3037 |
if [ "${in_fl}" -ef "${out_fl}" ]; then |
| 3038 |
# if [ "${in_fl}" = "${out_fl}" ]; then |
| 3039 |
echo "ERROR: Input file = ${in_fl} and Output file = ${out_fl} point to the same file, i.e., point to the same device and inode numbers" |
| 3040 |
echo "HINT: To prevent inadvertent data loss/corruption, ${spt_nm} insists that the Input and Output files be distinct. Retry command after renaming the Output file to a distinct location." |
| 3041 |
exit 1 |
| 3042 |
fi # !basename |
| 3043 |
fl_in[${fl_idx}]=${in_fl} |
| 3044 |
fl_out[${fl_idx}]=${out_fl} |
| 3045 |
|
| 3046 |
# Temporary files that need fl_idx granularity |
| 3047 |
if [ -n "${unq_sfx}" ]; then |
| 3048 |
unq_sfx_grn="${unq_sfx}.flidx${fl_idx}" |
| 3049 |
fi # !unq_sfx |
| 3050 |
att_fl[${fl_idx}]="${drc_tmp}/ncremap_tmp_att.nc${unq_sfx_grn}" # [sng] Missing value workflow (MPAS) default |
| 3051 |
d2f_fl[${fl_idx}]="${drc_tmp}/ncremap_tmp_d2f.nc${unq_sfx_grn}" # [sng] File with doubles converted to float |
| 3052 |
dpt_tmp_fl[${fl_idx}]="${drc_tmp}/ncremap_tmp_dpt.nc${unq_sfx_grn}" # [sng] File with depth coordinate added |
| 3053 |
pdq_fl[${fl_idx}]="${drc_tmp}/ncremap_tmp_pdq.nc${unq_sfx_grn}" # [sng] Permuted/Unpacked data default (AIRS, HIRDLS, MLS, MOD04, MPAS) |
| 3054 |
rnm_fl[${fl_idx}]="${drc_tmp}/ncremap_tmp_rnm.nc${unq_sfx_grn}" # [sng] Renamed regional (RRG) default |
| 3055 |
|
| 3056 |
# Generate new map unless map-file was supplied or already-generated |
| 3057 |
# Multiple maps can be generated only if mlt_map_flg=Yes (temporarily borken 20190920) |
| 3058 |
# NB: RRG infers source grid outside file loop, and forbids multiple source grids |
| 3059 |
# RRG produces map before file loop, and will not make maps inside file loop |
| 3060 |
if [ "${map_mk}" = 'Yes' ] && [ "${fl_idx}" -eq 0 ]; then |
| 3061 |
|
| 3062 |
# Block 1: Special cases |
| 3063 |
if [ "${prc_typ}" = 'hirdls' ] || [ "${prc_typ}" = 'mls' ]; then |
| 3064 |
# Pre-process zonal input files so grid inferral works |
| 3065 |
# 20160214: fix record variable to work around ncpdq problem |
| 3066 |
cmd_znl[${fl_idx}]="ncecat -O -u lon ${nco_opt} ${nco_var_lst} \"${in_fl}\" \"${in_fl}\" \"${in_fl}\" \"${in_fl}\" \"${znl_fl/znl/znl1}\";ncap2 -O ${nco_opt} -s 'lon[\$lon]={0.0,90.0,180.0,270.0}' \"${znl_fl/znl/znl1}\" \"${znl_fl/znl/znl2}\"" |
| 3067 |
in_fl="${znl_fl/znl/znl2}" |
| 3068 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3069 |
echo ${cmd_znl[${fl_idx}]} |
| 3070 |
fi # !dbg |
| 3071 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3072 |
eval ${cmd_znl[${fl_idx}]} |
| 3073 |
if [ "$?" -ne 0 ] || [ ! -f "${znl_fl/znl/znl2}" ]; then |
| 3074 |
printf "${spt_nm}: ERROR Failed to generate lat-lon file from zonal file. Debug this:\n${cmd_znl[${fl_idx}]}\n" |
| 3075 |
exit 1 |
| 3076 |
fi # !err |
| 3077 |
fi # !dbg |
| 3078 |
fi # !znl |
| 3079 |
|
| 3080 |
# Block 2: Source grid |
| 3081 |
# Block 2 Loop 1: Source gridfile command |
| 3082 |
if [ ! -f "${in_fl}" ] && [ ! -L "${in_fl}" ]; then |
| 3083 |
echo "${spt_nm}: ERROR Unable to find input file ${in_fl}" |
| 3084 |
echo "HINT: All files implied to exist must be in the directory specified by their filename or in ${drc_in} before ${spt_nm} will proceed" |
| 3085 |
exit 1 |
| 3086 |
fi # ! -f |
| 3087 |
|
| 3088 |
if [ "${wgt_typ}" != 'cdo' ]; then |
| 3089 |
# Infer source grid-file from input data file |
| 3090 |
cmd_src[${fl_idx}]="ncks -O ${nco_opt} --rgr infer --rgr hnt_src=\"${hnt_src_fl}\" ${nco_dgn_area} ${nco_msk_src} ${nco_ugrid_fl} ${nco_var_rgr} --rgr scrip=\"${grd_src}\" \"${in_fl}\" \"${tmp_out_fl}\"" |
| 3091 |
|
| 3092 |
# Block 2 Loop 2: Execute and/or echo commands |
| 3093 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3094 |
echo ${cmd_src[${fl_idx}]} |
| 3095 |
fi # !dbg |
| 3096 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3097 |
eval ${cmd_src[${fl_idx}]} |
| 3098 |
if [ "$?" -ne 0 ]; then |
| 3099 |
printf "${spt_nm}: ERROR Failed to infer source grid. Debug this:\n${cmd_src[${fl_idx}]}\n" |
| 3100 |
exit 1 |
| 3101 |
fi # !err |
| 3102 |
fi # !dbg |
| 3103 |
|
| 3104 |
# If source grid was just inferred in preceding block, convert and partition it |
| 3105 |
# Duplicate code of mbtempest source grid blocks above |
| 3106 |
if [ "${wgt_typ}" = 'mbtempest' ]; then |
| 3107 |
# 20210827 Pre-process input .nc, .g, and .h5m files to partitioned .h5m files |
| 3108 |
if [[ ${grd_src} == *.g ]] || [[ ${grd_src} == *.exo ]] || [[ ${grd_src} == *".nc"* ]]; then |
| 3109 |
[[ ${grd_src} == *.g ]] && grd_src_h5m_tmp="${grd_src/.g/.h5m}" |
| 3110 |
[[ ${grd_src} == *.exo ]] && grd_src_h5m_tmp="${grd_src/.exo/.h5m}" |
| 3111 |
[[ ${grd_src} == *".nc"* ]] && grd_src_h5m_tmp="${grd_src/.nc/.h5m}" |
| 3112 |
# 20260220: Vijay says on Slack DM that TR Exodus *.g files require (serial) TR Exodus reader accessed via -B |
| 3113 |
# mbconvert can only parallelize conversion of true, official Exodus (*.exo) and SCRIP files |
| 3114 |
[[ ${grd_src} == *.g ]] || [[ ${mbt_grd_nc4} = 'Yes' ]] && mbt_grd_rd_srl='Yes' || mbt_grd_rd_srl='No' |
| 3115 |
[[ ${mbt_grd_rd_srl} = 'Yes' ]] && cnv_opt_g2m=${cnv_opt_srl_e2m} || cnv_opt_g2m=${cnv_opt_prl_n2m} |
| 3116 |
cmd_g2m[${fl_idx}]="${cmd_cnv_mbt} ${cnv_opt_src} ${cnv_opt_g2m} \"${grd_src}\" \"${grd_src_h5m_tmp}\"${devnull}" |
| 3117 |
[[ ${mbt_grd_rd_srl} = 'No' ]] && cmd_g2m[${fl_idx}]="${mpi_pfx} ${cmd_g2m[${fl_idx}]}" |
| 3118 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3119 |
echo ${cmd_g2m[${fl_idx}]} |
| 3120 |
fi # !dbg |
| 3121 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3122 |
eval ${cmd_g2m[${fl_idx}]} |
| 3123 |
if [ "$?" -ne 0 ] || [ ! -f ${grd_src_h5m_tmp} ]; then |
| 3124 |
printf "${spt_nm}: ERROR Failed to convert source grid to MOAB H5M format. Debug this:\n${cmd_g2m[${fl_idx}]}\n" |
| 3125 |
printf "${cnv_exe_hnt}" |
| 3126 |
exit 1 |
| 3127 |
fi # !err |
| 3128 |
fi # !dbg |
| 3129 |
grd_src=${grd_src_h5m_tmp} |
| 3130 |
fi # !grd_src |
| 3131 |
if [[ ${grd_src} == *.h5m ]] && [[ ${grd_src} != *p.h5m ]]; then |
| 3132 |
grd_src_prt_tmp="${grd_src/.h5m/_${prt_nbr}p.h5m}" |
| 3133 |
grd_dst_prt_tmp="${grd_dst/.h5m/_inferred.h5m}" |
| 3134 |
if [ ${prt_alg} = 'zoltan' ]; then |
| 3135 |
# 20260302: Use Recursive Coordinate Bisection (RCB) repartitioning scheme |
| 3136 |
# mbpart runs in serial to create meshes for mbtempest to read in parallel |
| 3137 |
cmd_prt[${fl_idx}]="${cmd_prt_mbt} ${prt_nbr} --zoltan RCB --recompute_rcb_box --project_on_sphere 2 --scale_sphere --imbalance 1.002 --inferred \"${grd_dst}\" \"${grd_src}\" \"${grd_src_prt_tmp}\"${devnull}" |
| 3138 |
fi # !HOSTNAME |
| 3139 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3140 |
echo ${cmd_prt[${fl_idx}]} |
| 3141 |
fi # !dbg |
| 3142 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3143 |
eval ${cmd_prt[${fl_idx}]} |
| 3144 |
if [ "$?" -ne 0 ] || [ ! -f ${grd_src_prt_tmp} ]; then |
| 3145 |
printf "${spt_nm}: ERROR Failed to partition MOAB version of source grid. Debug this:\n${cmd_prt[${fl_idx}]}\n" |
| 3146 |
printf "${spt_nm}: HINT ${prt_exe_mbt} can fail for a number of reasons including 1) fxm ...\n" |
| 3147 |
exit 1 |
| 3148 |
fi # !err |
| 3149 |
fi # !dbg |
| 3150 |
grd_src=${grd_src_prt_tmp} |
| 3151 |
grd_dst=${grd_dst_prt_tmp} |
| 3152 |
fi # !grd_src |
| 3153 |
fi # !mbtempest |
| 3154 |
fi # !cdo |
| 3155 |
|
| 3156 |
# Block 3: Source->destination maps |
| 3157 |
# Block 3 Loop 1: Map-file commands |
| 3158 |
if [ ${vrb_lvl} -ge ${vrb_1} ]; then |
| 3159 |
printf "Grid(src): ${grd_src}\n" |
| 3160 |
printf "Grid(dst): ${grd_dst}\n" |
| 3161 |
fi # !vrb_lvl |
| 3162 |
if [ "${wgt_typ}" = 'cdo' ]; then |
| 3163 |
cmd_map[${fl_idx}]="${wgt_cmd} -gencon,\"${dst_fl}\" \"${in_fl}\" \"${map_fl}\"${devnull}" |
| 3164 |
#cmd_map[${fl_idx}]="${wgt_cmd} -gencon,\"${grd_dst}\" \"${grd_src}\" \"${map_fl}\"${devnull}" |
| 3165 |
elif [ "${wgt_typ}" = 'esmf' ]; then |
| 3166 |
rgn_opt='' |
| 3167 |
if [ -n "${hnt_src}" ]; then |
| 3168 |
rgn_opt="${rgn_opt} ${hnt_src}" |
| 3169 |
elif [ -f "${hnt_src_fl}" ]; then |
| 3170 |
rgn_opt="${rgn_opt} `cat ${hnt_src_fl}`" |
| 3171 |
fi # !hnt_src_fl |
| 3172 |
if [ -n "${hnt_dst}" ]; then |
| 3173 |
rgn_opt="${rgn_opt} ${hnt_dst}" |
| 3174 |
elif [ -f "${hnt_dst_fl}" ]; then |
| 3175 |
rgn_opt="${rgn_opt} `cat ${hnt_dst_fl}`" |
| 3176 |
fi # !hnt_dst_fl |
| 3177 |
cmd_map[${fl_idx}]="${wgt_cmd} -s \"${grd_src}\" -d \"${grd_dst}\" -w \"${map_fl}\" --method ${alg_opt} ${wgt_opt} ${rgn_opt}${devnull}" |
| 3178 |
elif [ "${wgt_typ}" = 'nco' ]; then |
| 3179 |
if [ ${vrb_lvl} -ge ${vrb_1} ]; then |
| 3180 |
if [ -n "${msh_opt}" ]; then |
| 3181 |
printf "Mesh-File: ${msh_fl}\n" |
| 3182 |
fi # !msh_opt |
| 3183 |
fi # !vrb_lvl |
| 3184 |
cmd_map[${fl_idx}]="${wgt_cmd} ${wgt_opt} --thr_nbr=${thr_nbr} ${nco_opt} --grd_src=\"${grd_src}\" --grd_dst=\"${grd_dst}\" --map_fl=\"${map_fl}\" ${msh_opt} ${rgr_opt} \"${dmm_fl}\" \"${tmp_out_fl}\"${devnull}" |
| 3185 |
elif [ "${wgt_typ}" = 'mbtempest' ]; then |
| 3186 |
if [ ${prt_alg} = 'zoltan' ]; then |
| 3187 |
cmd_map[${fl_idx}]="${wgt_cmd} --type ${mbt_typ_map} --weights --load \"${grd_src}\" --load \"${grd_dst}\" ${wgt_opt} --file \"${map_fl}\"${devnull}" |
| 3188 |
fi # !prt_alg |
| 3189 |
elif [ "${wgt_typ}" = 'tempest' ]; then |
| 3190 |
if [ ${vrb_lvl} -ge ${vrb_1} ]; then |
| 3191 |
printf "Mesh-File: ${msh_fl}\n" |
| 3192 |
fi # !vrb_lvl |
| 3193 |
cmd_msh[${fl_idx}]="${cmd_msh_tps} ${msh_opt_tps} --a \"${grd_src}\" --b \"${grd_dst}\" --out \"${msh_fl}\"${devnull}" |
| 3194 |
if [ "${a2o_flg}" = 'Yes' ]; then |
| 3195 |
cmd_msh[${fl_idx}]="${cmd_msh_tps} ${msh_opt_tps} --b \"${grd_src}\" --a \"${grd_dst}\" --out \"${msh_fl}\"${devnull}" |
| 3196 |
fi # !a2o_flg |
| 3197 |
cmd_map[${fl_idx}]="${wgt_cmd} --in_mesh \"${grd_src}\" --out_mesh \"${grd_dst}\" --ov_mesh \"${msh_fl}\" --out_map \"${map_fl}\" ${wgt_opt}${devnull}" |
| 3198 |
if [ "${trn_map}" = 'Yes' ]; then |
| 3199 |
# NB: Generate mono map for opposite direction regridding (i.e., reverse switches and grids), then transpose |
| 3200 |
cmd_map[${fl_idx}]="${wgt_cmd} --in_mesh \"${grd_dst}\" --out_mesh \"${grd_src}\" --ov_mesh \"${msh_fl}\" --out_map \"${map_trn_fl}\" ${wgt_opt}${devnull}" |
| 3201 |
cmd_trn[${fl_idx}]="GenerateTransposeMap --in \"${map_trn_fl}\" --out \"${map_fl}\"${devnull}" |
| 3202 |
fi # !trn_map |
| 3203 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3204 |
echo ${cmd_msh[${fl_idx}]} |
| 3205 |
fi # !dbg |
| 3206 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3207 |
eval ${cmd_msh[${fl_idx}]} |
| 3208 |
if [ "$?" -ne 0 ] || [ ! -f ${msh_fl} ]; then |
| 3209 |
printf "${spt_nm}: ERROR Failed to generate intersection mesh-file. Debug this:\n${cmd_msh[${fl_idx}]}\n" |
| 3210 |
printf "${spt_nm}: HINT ${msh_exe_tps} requires that grids of unequal area be given as arguments in the order smaller first, larger second. ncremap supplies the grid arguments in the order source first, destination second unless explicitly told otherwise. A source grid that is a superset of the destination would violate the ${msh_exe_tps} rule. The solution is to add the \"--a2o\" switch (documented at http://nco.sf.net/nco.html#a2o) that tells ncremap to swap the grid argument order.\n" |
| 3211 |
exit 1 |
| 3212 |
fi # !err |
| 3213 |
fi # !dbg |
| 3214 |
fi # !wgt_typ |
| 3215 |
|
| 3216 |
# Block 3 Loop 2: Execute and/or echo commands |
| 3217 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3218 |
echo ${cmd_map[${fl_idx}]} |
| 3219 |
fi # !dbg |
| 3220 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3221 |
eval ${cmd_map[${fl_idx}]} |
| 3222 |
if [ "$?" -ne 0 ] || [ ! -f ${map_rsl_fl} ]; then |
| 3223 |
printf "${spt_nm}: ERROR Failed to generate map-file. Debug this:\n${cmd_map[${fl_idx}]}\n" |
| 3224 |
if [ "${wgt_typ}" = 'esmf' ]; then |
| 3225 |
printf "${spt_nm}: HINT When ESMF fails to generate map-files, it often puts additional debugging information in the file named PET0.RegridWeightGen.Log in the invocation directory (${drc_pwd})\n" |
| 3226 |
fi # !esmf |
| 3227 |
exit 1 |
| 3228 |
fi # !err |
| 3229 |
if [ "${map_usr_flg}" = 'Yes' ]; then |
| 3230 |
hst_att="`date`: ${cmd_ln}; ${cmd_map[${fl_idx}]}" |
| 3231 |
cmd_att[${fl_idx}]="ncatted -O ${gaa_sng} --gaa history='${hst_att}' ${gad_sng} \"${map_rsl_fl}\"" |
| 3232 |
eval ${cmd_att[${fl_idx}]} |
| 3233 |
if [ "$?" -ne 0 ]; then |
| 3234 |
printf "${spt_nm}: ERROR Failed to annotate map-file. Debug this:\n${cmd_att[${fl_idx}]}\n" |
| 3235 |
exit 1 |
| 3236 |
fi # !err |
| 3237 |
fi # !map_usr_flg |
| 3238 |
fi # !dbg |
| 3239 |
if [ "${trn_map}" = 'Yes' ]; then |
| 3240 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3241 |
echo ${cmd_trn[${fl_idx}]} |
| 3242 |
fi # !dbg |
| 3243 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3244 |
eval ${cmd_trn[${fl_idx}]} |
| 3245 |
if [ "$?" -ne 0 ] || [ ! -f ${map_fl} ]; then |
| 3246 |
printf "${spt_nm}: ERROR Failed to transpose map-file. Debug this:\n${cmd_trn[${fl_idx}]}\n" |
| 3247 |
exit 1 |
| 3248 |
fi # !err |
| 3249 |
fi # !dbg |
| 3250 |
fi # !trn_map |
| 3251 |
|
| 3252 |
# Prevent creating new source gridfile and map-file after first iteration |
| 3253 |
if [ "${mlt_map_flg}" = 'No' ] && [ ${fl_idx} -eq 0 ]; then |
| 3254 |
map_mk='Already made map once. Never again.' |
| 3255 |
fi # !mlt_map_flg |
| 3256 |
|
| 3257 |
fi # !map_mk |
| 3258 |
done # !fl_idx |
| 3259 |
|
| 3260 |
# 20190920: Nothing to wait() for here since we produce only one map |
| 3261 |
|
| 3262 |
# Block 4: Special cases |
| 3263 |
if [ "${dpt_flg}" = 'Yes' ]; then |
| 3264 |
# Block 4a: Add MPAS depth coordinate (prior to permutation) |
| 3265 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3266 |
if [ ${vrb_lvl} -ge ${vrb_2} ]; then |
| 3267 |
printf "DPT(in) : ${fl_in[${fl_idx}]}\n" |
| 3268 |
printf "DPT(out) : ${dpt_tmp_fl[${fl_idx}]}\n" |
| 3269 |
fi # !vrb_lvl |
| 3270 |
cmd_dpt[${fl_idx}]="${cmd_mpi[${fl_idx}]} ${cmd_dpt_mpas} ${cmd_dpt_opt} -i \"${fl_in[${fl_idx}]}\" -o \"${dpt_tmp_fl[${fl_idx}]}\"" |
| 3271 |
${fl_in[${fl_idx}]}=${dpt_tmp_fl[${fl_idx}]} |
| 3272 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3273 |
echo ${cmd_dpt[${fl_idx}]} |
| 3274 |
fi # !dbg |
| 3275 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3276 |
if [ -z "${par_opt}" ]; then |
| 3277 |
eval ${cmd_dpt[${fl_idx}]} |
| 3278 |
if [ "$?" -ne 0 ] || [ ! -f ${dpt_tmp_fl[${fl_idx}]} ]; then |
| 3279 |
printf "${spt_nm}: ERROR Failed to add depth coordinate to MPAS file. Debug this:\n${cmd_dpt[${fl_idx}]}\nHINTS: 1) Verify that ${dpt_exe_mpas} is executable from the command-line, it requires Python and the xarray package to succeed. 2) Verify that ${dpt_fl} or ${fl_in[${fl_idx}]} contains variable \"refBottomDepth\".\n" |
| 3280 |
exit 1 |
| 3281 |
fi # !err |
| 3282 |
else # !par_typ |
| 3283 |
eval ${cmd_dpt[${fl_idx}]} ${par_opt} |
| 3284 |
dpt_pid[${fl_idx}]=$! |
| 3285 |
fi # !par_typ |
| 3286 |
fi # !dbg |
| 3287 |
done # !fl_idx |
| 3288 |
|
| 3289 |
# Parallel regridding (both Background and MPI) spawns simultaneous processes in batches of ${job_nbr} |
| 3290 |
# Once ${job_nbr} jobs are running, wait() for all to finish before issuing another batch |
| 3291 |
# Following wait() blocks are identical except for error message and this comment is omitted |
| 3292 |
if [ -n "${par_opt}" ]; then |
| 3293 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3294 |
wait ${dpt_pid[${fl_idx}]} |
| 3295 |
if [ "$?" -ne 0 ] || [ ! -f ${dpt_tmp_fl[${fl_idx}]} ]; then |
| 3296 |
printf "${spt_nm}: ERROR Failed to add depth coordinate to MPAS file. Debug this:\n${cmd_dpt[${fl_idx}]}\nHINTS: 1) Verify that ${dpt_exe_mpas} is executable from the command-line, it requires Python and the xarray package to succeed. 2) Verify that ${dpt_fl} or ${fl_in[${fl_idx}]} contains variable \"refBottomDepth\".\n" |
| 3297 |
exit 1 |
| 3298 |
fi # !err |
| 3299 |
done # !fl_idx |
| 3300 |
fi # !par_opt |
| 3301 |
fi # !dpt_flg |
| 3302 |
|
| 3303 |
if [ -n "${pdq_opt}" ]; then |
| 3304 |
# Block 4b: Generic Permutation/Unpacking (AIRS, HIRDLS, MLS, MOD04, MPAS) |
| 3305 |
# Do sub-setting operation (like PDQ) first so cmd_att works on smaller, sub-set files |
| 3306 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3307 |
if [ ${vrb_lvl} -ge ${vrb_2} ]; then |
| 3308 |
printf "PDQ(in) : ${fl_in[${fl_idx}]}\n" |
| 3309 |
printf "PDQ(out) : ${pdq_fl[${fl_idx}]}\n" |
| 3310 |
fi # !vrb_lvl |
| 3311 |
cmd_pdq[${fl_idx}]="${cmd_mpi[${fl_idx}]} ncpdq -O ${nco_opt} ${nco_var_lst} ${pdq_opt} \"${fl_in[${fl_idx}]}\" \"${pdq_fl[${fl_idx}]}\"" |
| 3312 |
fl_in[${fl_idx}]=${pdq_fl[${fl_idx}]} |
| 3313 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3314 |
echo ${cmd_pdq[${fl_idx}]} |
| 3315 |
fi # !dbg |
| 3316 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3317 |
if [ -z "${par_opt}" ]; then |
| 3318 |
eval ${cmd_pdq[${fl_idx}]} |
| 3319 |
if [ "$?" -ne 0 ] || [ ! -f ${pdq_fl[${fl_idx}]} ]; then |
| 3320 |
printf "${spt_nm}: ERROR Failed to generate pdq-file. Debug this:\n${cmd_pdq[${fl_idx}]}\n" |
| 3321 |
exit 1 |
| 3322 |
fi # !err |
| 3323 |
else # !par_typ |
| 3324 |
eval ${cmd_pdq[${fl_idx}]} ${par_opt} |
| 3325 |
pdq_pid[${fl_idx}]=$! |
| 3326 |
fi # !par_typ |
| 3327 |
fi # !dbg |
| 3328 |
done # !fl_idx |
| 3329 |
|
| 3330 |
if [ -n "${par_opt}" ]; then |
| 3331 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3332 |
wait ${pdq_pid[${fl_idx}]} |
| 3333 |
if [ "$?" -ne 0 ] || [ ! -f ${pdq_fl[${fl_idx}]} ]; then |
| 3334 |
printf "${spt_nm}: ERROR Failed to generate pdq-file. Debug this:\n${cmd_pdq[${fl_idx}]}\n" |
| 3335 |
exit 1 |
| 3336 |
fi # !err |
| 3337 |
done # !fl_idx |
| 3338 |
fi # !par_opt |
| 3339 |
fi # !pdq_opt |
| 3340 |
|
| 3341 |
if [ "${d2f_flg}" = 'Yes' ]; then |
| 3342 |
# Block 4c: Double->Float conversion (by-request and possibly default for MPAS) |
| 3343 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3344 |
if [ ${vrb_lvl} -ge ${vrb_2} ]; then |
| 3345 |
printf "D2F(in) : ${fl_in[${fl_idx}]}\n" |
| 3346 |
printf "D2F(out) : ${d2f_fl[${fl_idx}]}\n" |
| 3347 |
fi # !vrb_lvl |
| 3348 |
cmd_d2f[${fl_idx}]="${cmd_mpi[${fl_idx}]} ncpdq -O ${nco_opt} ${nco_var_lst} ${d2f_opt} \"${fl_in[${fl_idx}]}\" \"${d2f_fl[${fl_idx}]}\"" |
| 3349 |
fl_in[${fl_idx}]=${d2f_fl[${fl_idx}]} |
| 3350 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3351 |
echo ${cmd_d2f[${fl_idx}]} |
| 3352 |
fi # !dbg |
| 3353 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3354 |
if [ -z "${par_opt}" ]; then |
| 3355 |
eval ${cmd_d2f[${fl_idx}]} |
| 3356 |
if [ "$?" -ne 0 ] || [ ! -f ${d2f_fl[${fl_idx}]} ]; then |
| 3357 |
printf "${spt_nm}: ERROR Failed to convert double-precision to single-precision. Debug this:\n${cmd_d2f[${fl_idx}]}\n" |
| 3358 |
exit 1 |
| 3359 |
fi # !err |
| 3360 |
else # !par_typ |
| 3361 |
eval ${cmd_d2f[${fl_idx}]} ${par_opt} |
| 3362 |
d2f_pid[${fl_idx}]=$! |
| 3363 |
fi # !par_typ |
| 3364 |
fi # !dbg |
| 3365 |
done # !fl_idx |
| 3366 |
|
| 3367 |
if [ -n "${par_opt}" ]; then |
| 3368 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3369 |
wait ${d2f_pid[${fl_idx}]} |
| 3370 |
if [ "$?" -ne 0 ] || [ ! -f ${d2f_fl[${fl_idx}]} ]; then |
| 3371 |
printf "${spt_nm}: ERROR Failed to convert double-precision to single-precision. Debug this:\n${cmd_d2f[${fl_idx}]}\n" |
| 3372 |
exit 1 |
| 3373 |
fi # !err |
| 3374 |
done # !fl_idx |
| 3375 |
fi # !par_opt |
| 3376 |
fi # !d2f_flg |
| 3377 |
|
| 3378 |
if [ "${att_flg}" = 'Yes' ]; then |
| 3379 |
# Block 4d: Add missing metadata to MPAS files unless script was invoked by ncclimo (it makes no sense to give naked files to ncclimo and then to annotate them here, so assume ncclimo is working with annotated files) |
| 3380 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3381 |
if [ ${vrb_lvl} -ge ${vrb_2} ]; then |
| 3382 |
printf "att(in) : ${fl_in[${fl_idx}]}\n" |
| 3383 |
printf "att(out) : ${att_fl[${fl_idx}]}\n" |
| 3384 |
fi # !vrb_lvl |
| 3385 |
cmd_att[${fl_idx}]="${cmd_mpi[${fl_idx}]} ncatted -O --type_match -a _FillValue,,o,d,${mss_val} -a _FillValue,,o,f,${mss_val} \"${fl_in[${fl_idx}]}\" \"${att_fl[${fl_idx}]}\"" |
| 3386 |
fl_in[${fl_idx}]="${att_fl[${fl_idx}]}" |
| 3387 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3388 |
echo ${cmd_att[${fl_idx}]} |
| 3389 |
fi # !dbg |
| 3390 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3391 |
if [ -z "${par_opt}" ]; then |
| 3392 |
eval ${cmd_att[${fl_idx}]} |
| 3393 |
if [ "$?" -ne 0 ] || [ ! -f ${att_fl[${fl_idx}]} ]; then |
| 3394 |
printf "${spt_nm}: ERROR Failed to annotate MPAS file with _FillValue. Debug this:\n${cmd_att[${fl_idx}]}\n" |
| 3395 |
exit 1 |
| 3396 |
fi # !err |
| 3397 |
else # !par_typ |
| 3398 |
eval ${cmd_att[${fl_idx}]} ${par_opt} |
| 3399 |
att_pid[${fl_idx}]=$! |
| 3400 |
fi # !par_typ |
| 3401 |
fi # !dbg |
| 3402 |
done # !fl_idx |
| 3403 |
|
| 3404 |
if [ -n "${par_opt}" ]; then |
| 3405 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3406 |
wait ${att_pid[${fl_idx}]} |
| 3407 |
if [ "$?" -ne 0 ] || [ ! -f ${att_fl[${fl_idx}]} ]; then |
| 3408 |
printf "${spt_nm}: ERROR Failed to annotate MPAS file with _FillValue. Debug this:\n${cmd_att[${fl_idx}]}\n" |
| 3409 |
exit 1 |
| 3410 |
fi # !err |
| 3411 |
done # !fl_idx |
| 3412 |
fi # !par_opt |
| 3413 |
fi # !att_flg |
| 3414 |
|
| 3415 |
if [ "${prc_typ}" = 'rrg' ]; then |
| 3416 |
# Block 4e: RRG |
| 3417 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3418 |
rrg_dmn_lst=`ncdmnlst ${fl_in[${fl_idx}]} | grep ${rnm_sng}` |
| 3419 |
rrg_var_lst=`ncvarlst ${fl_in[${fl_idx}]} | grep ${rnm_sng}` |
| 3420 |
|
| 3421 |
dmn_sng='' |
| 3422 |
if [ -n "${rrg_dmn_lst}" ]; then |
| 3423 |
for dmn in ${rrg_dmn_lst} ; do |
| 3424 |
dmn_sng="${dmn_sng} -d ${dmn},${dmn/${rnm_sng}/}" |
| 3425 |
done # !dmn |
| 3426 |
else # !rrg_dmn_lst |
| 3427 |
echo "ERROR: Regional regridding suffix string '${rnm_sng}' not found in any dimension names in ${fl_in[${fl_idx}]}" |
| 3428 |
echo "HINT: Regional regridding input files must contain dimensions and variables whose names end with the ELM/CAM-SE created (from finclNlonlat namelist input) regional suffix string, e.g., '_128e_to_134e_9s_to_16s'. Valid regional suffix strings for this input file are:" |
| 3429 |
eval "ncks -m ${fl_in[${fl_idx}]} | cut -d ':' -f 1 | cut -d '=' -s -f 1 | grep ncol | sed 's/ncol//' | sed -e 's/^ *//' -e 's/ *$//'" |
| 3430 |
echo "Use exactly one of these strings as the argument to --rrg_rnm_sng" |
| 3431 |
exit 1 |
| 3432 |
fi # !rrg_dmn_lst |
| 3433 |
|
| 3434 |
var_sng='' |
| 3435 |
if [ -n "${rrg_var_lst}" ]; then |
| 3436 |
for var in ${rrg_var_lst} ; do |
| 3437 |
var_sng="${var_sng} -v ${var},${var/${rnm_sng}/}" |
| 3438 |
done # !rrg_var_lst |
| 3439 |
fi # !rrg_var_lst |
| 3440 |
|
| 3441 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 3442 |
printf "RRG: Remove \"${rnm_sng}\" from dimension and variable names...\n" |
| 3443 |
fi # !vrb_lvl |
| 3444 |
cmd_rnm[${fl_idx}]="${cmd_mpi[${fl_idx}]} ncrename -O ${dmn_sng} ${var_sng} \"${fl_in[${fl_idx}]}\" \"${rnm_fl[${fl_idx}]}\"" |
| 3445 |
fl_in[${fl_idx}]=${rnm_fl[${fl_idx}]} |
| 3446 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3447 |
echo ${cmd_rnm[${fl_idx}]} |
| 3448 |
fi # !dbg |
| 3449 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3450 |
if [ -z "${par_opt}" ]; then |
| 3451 |
eval ${cmd_rnm[${fl_idx}]} |
| 3452 |
if [ "$?" -ne 0 ] || [ ! -f ${rnm_fl[${fl_idx}]} ]; then |
| 3453 |
printf "${spt_nm}: ERROR Failed to rename regional input file. Debug this:\n${cmd_rnm[${fl_idx}]}\n" |
| 3454 |
exit 1 |
| 3455 |
fi # !err |
| 3456 |
else # !par_typ |
| 3457 |
eval ${cmd_rnm[${fl_idx}]} ${par_opt} |
| 3458 |
rnm_pid[${fl_idx}]=$! |
| 3459 |
fi # !par_typ |
| 3460 |
fi # !dbg |
| 3461 |
done # !fl_idx |
| 3462 |
|
| 3463 |
if [ -n "${par_opt}" ]; then |
| 3464 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3465 |
wait ${rnm_pid[${fl_idx}]} |
| 3466 |
if [ "$?" -ne 0 ] || [ ! -f ${rnm_fl[${fl_idx}]} ]; then |
| 3467 |
printf "${spt_nm}: ERROR Failed to rename regional input file. Debug this:\n${cmd_rnm[${fl_idx}]}\n" |
| 3468 |
exit 1 |
| 3469 |
fi # !err |
| 3470 |
done # !fl_idx |
| 3471 |
fi # !par_opt |
| 3472 |
|
| 3473 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3474 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 3475 |
printf "RRG: Append regional coordinates and vertices to renamed, annotated regional input data...\n" |
| 3476 |
fi # !vrb_lvl |
| 3477 |
cmd_apn[${fl_idx}]="${cmd_mpi[${fl_idx}]} ncks -A \"${rgn_fl}\" \"${rnm_fl[${fl_idx}]}\"" |
| 3478 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3479 |
echo ${cmd_apn[${fl_idx}]} |
| 3480 |
fi # !dbg |
| 3481 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3482 |
if [ -z "${par_opt}" ]; then |
| 3483 |
eval ${cmd_apn[${fl_idx}]} |
| 3484 |
if [ "$?" -ne 0 ] || [ ! -f ${rnm_fl[${fl_idx}]} ]; then |
| 3485 |
printf "${spt_nm}: ERROR Failed to append regional coordinates and vertices to annotated, regional input data. Debug this:\n${cmd_apn[${fl_idx}]}\n" |
| 3486 |
exit 1 |
| 3487 |
fi # !err |
| 3488 |
else # !par_typ |
| 3489 |
eval ${cmd_apn[${fl_idx}]} ${par_opt} |
| 3490 |
apn_pid[${fl_idx}]=$! |
| 3491 |
fi # !par_typ |
| 3492 |
fi # !dbg |
| 3493 |
done # !fl_idx |
| 3494 |
|
| 3495 |
if [ -n "${par_opt}" ]; then |
| 3496 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3497 |
wait ${apn_pid[${fl_idx}]} |
| 3498 |
if [ "$?" -ne 0 ] || [ ! -f ${rnm_fl[${fl_idx}]} ]; then |
| 3499 |
printf "${spt_nm}: ERROR Failed to append regional coordinates and vertices to annotated, regional input data. Debug this:\n${cmd_apn[${fl_idx}]}\n" |
| 3500 |
exit 1 |
| 3501 |
fi # !err |
| 3502 |
done # !fl_idx |
| 3503 |
fi # !par_opt |
| 3504 |
fi # !rrg |
| 3505 |
|
| 3506 |
if [ -n "${vrt_out}" ]; then |
| 3507 |
# Block 5a: Vertical interpolation |
| 3508 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3509 |
|
| 3510 |
if [ ${vrb_lvl} -ge ${vrb_1} ]; then |
| 3511 |
printf "Vertical : ${vrt_out}\n" |
| 3512 |
fi # !vrb_lvl |
| 3513 |
out_fl=${fl_out[${fl_idx}]} |
| 3514 |
if [ "${flg_hrz}" = 'Yes' ]; then |
| 3515 |
out_fl="${drc_tmp}/ncremap_tmp_out_vrt.${fl_idx}.nc" |
| 3516 |
fi # !flg_hrz |
| 3517 |
cmd_rgr[${fl_idx}]="${cmd_mpi[${fl_idx}]} ncks -O -t ${thr_nbr} ${nco_opt} ${nco_var_lst} ${vrt_opt} --vrt_out=\"${vrt_out}\" \"${fl_in[${fl_idx}]}\" \"${out_fl}\"" |
| 3518 |
fl_in[${fl_idx}]=${out_fl} |
| 3519 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3520 |
echo ${cmd_rgr[${fl_idx}]} |
| 3521 |
fi # !dbg |
| 3522 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3523 |
if [ -z "${par_opt}" ]; then |
| 3524 |
eval ${cmd_rgr[${fl_idx}]} |
| 3525 |
if [ "$?" -ne 0 ]; then |
| 3526 |
printf "${spt_nm}: ERROR Failed to vertically interpolate. cmd_rgr[${fl_idx}] failed. Debug this:\n${cmd_rgr[${fl_idx}]}\n" |
| 3527 |
exit 1 |
| 3528 |
fi # !err |
| 3529 |
else # !par_typ |
| 3530 |
eval ${cmd_rgr[${fl_idx}]} ${par_opt} |
| 3531 |
rgr_pid[${fl_idx}]=$! |
| 3532 |
fi # !par_typ |
| 3533 |
fi # !dbg |
| 3534 |
done # !fl_idx |
| 3535 |
|
| 3536 |
if [ -n "${par_opt}" ]; then |
| 3537 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3538 |
wait ${rgr_pid[${fl_idx}]} |
| 3539 |
if [ "$?" -ne 0 ]; then |
| 3540 |
printf "${spt_nm}: ERROR Failed to vertically interpolate. cmd_rgr[${fl_idx}] failed. Debug this:\n${cmd_rgr[${fl_idx}]}\n" |
| 3541 |
exit 1 |
| 3542 |
fi # !err |
| 3543 |
done # !fl_idx |
| 3544 |
fi # !par_opt |
| 3545 |
fi # !vrt_out |
| 3546 |
|
| 3547 |
if [ "${flg_hrz}" = 'Yes' ]; then |
| 3548 |
# Block 5b: Horizontal regridding |
| 3549 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3550 |
if [ ${vrb_lvl} -ge ${vrb_1} ]; then |
| 3551 |
printf "Map/Wgt : ${map_fl}\n" |
| 3552 |
fi # !vrb_lvl |
| 3553 |
cmd_rgr[${fl_idx}]="${cmd_mpi[${fl_idx}]} ncks -O -t ${thr_nbr} ${nco_opt} ${nco_var_rgr} ${nco_var_lst_hrz} ${nco_msk_out} ${rgr_opt} --map_fl=\"${map_fl}\" \"${fl_in[${fl_idx}]}\" \"${fl_out[${fl_idx}]}\"" |
| 3554 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3555 |
echo ${cmd_rgr[${fl_idx}]} |
| 3556 |
fi # !dbg |
| 3557 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3558 |
if [ -z "${par_opt}" ]; then |
| 3559 |
eval ${cmd_rgr[${fl_idx}]} |
| 3560 |
if [ "$?" -ne 0 ]; then |
| 3561 |
printf "${spt_nm}: ERROR Failed to horizontally regrid. cmd_rgr[${fl_idx}] failed. Debug this:\n${cmd_rgr[${fl_idx}]}\n" |
| 3562 |
exit 1 |
| 3563 |
fi # !err |
| 3564 |
else # !par_typ |
| 3565 |
eval ${cmd_rgr[${fl_idx}]} ${par_opt} |
| 3566 |
rgr_pid[${fl_idx}]=$! |
| 3567 |
fi # !par_typ |
| 3568 |
fi # !dbg |
| 3569 |
done # !fl_idx |
| 3570 |
|
| 3571 |
if [ -n "${par_opt}" ]; then |
| 3572 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3573 |
wait ${rgr_pid[${fl_idx}]} |
| 3574 |
if [ "$?" -ne 0 ]; then |
| 3575 |
printf "${spt_nm}: ERROR Failed to horizontally regrid. cmd_rgr[${fl_idx}] failed. Debug this:\n${cmd_rgr[${fl_idx}]}\n" |
| 3576 |
exit 1 |
| 3577 |
fi # !err |
| 3578 |
done # !fl_idx |
| 3579 |
fi # !par_opt |
| 3580 |
fi # !flg_hrz |
| 3581 |
|
| 3582 |
# Regridding is complete so delete temporary files produced by this batch |
| 3583 |
if [ "${cln_flg}" = 'Yes' ]; then |
| 3584 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3585 |
/bin/rm -f ${att_fl[${fl_idx}]} ${d2f_fl[${fl_idx}]} ${dpt_tmp_fl[${fl_idx}]} ${pdq_fl[${fl_idx}]} ${rnm_fl[${fl_idx}]} |
| 3586 |
if [ -n "${vrt_out}" ] && [ "${flg_hrz}" = 'Yes' ]; then |
| 3587 |
# Remove vertically regridded intermediate output |
| 3588 |
/bin/rm -f "${drc_tmp}/ncremap_tmp_out_vrt.${fl_idx}.nc" |
| 3589 |
fi # !vrt_out |
| 3590 |
done # !fl_idx |
| 3591 |
fi # !cln_flg |
| 3592 |
|
| 3593 |
# Block 7: Parallel post-processing |
| 3594 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3595 |
if [ -n "${prc_elm}" ] && [ "${no_cll_msr}" != 'Yes' ]; then |
| 3596 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 3597 |
printf "${spt_nm}: Implement idiosyncratic CLM/CTSM/ELM characteristics in regridded file...\n" |
| 3598 |
fi # !vrb_lvl |
| 3599 |
# Convert area from [sr] to [km2] |
| 3600 |
cmd_ppp[${fl_idx}]="ncap2 -O -s 'area*=${rds_rth}^2/1.0e6;area@long_name=\"Gridcell area\";area@units=\"km^2\"' \"${fl_out[${fl_idx}]}\" \"${fl_out[${fl_idx}]}\"" |
| 3601 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3602 |
echo ${cmd_ppp[${fl_idx}]} |
| 3603 |
fi # !dbg |
| 3604 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3605 |
if [ -z "${par_opt}" ]; then |
| 3606 |
eval ${cmd_ppp[${fl_idx}]} |
| 3607 |
if [ "$?" -ne 0 ] || [ ! -f ${fl_out[${fl_idx}]} ]; then |
| 3608 |
printf "${spt_nm}: ERROR Failed post-processing to convert output area from [sr] to [km2]. Debug this:\n${cmd_ppp[${fl_idx}]}\n" |
| 3609 |
exit 1 |
| 3610 |
fi # !err |
| 3611 |
else # !par_typ |
| 3612 |
eval ${cmd_ppp[${fl_idx}]} ${par_opt} |
| 3613 |
ppp_pid[${fl_idx}]=$! |
| 3614 |
fi # !par_typ |
| 3615 |
fi # !dbg |
| 3616 |
fi # !prc_elm |
| 3617 |
|
| 3618 |
if [ -n "${prc_cice}" ] && [ "${no_cll_msr}" != 'Yes' ]; then |
| 3619 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 3620 |
printf "${spt_nm}: Implement idiosyncratic CICE characteristics in regridded file...\n" |
| 3621 |
fi # !vrb_lvl |
| 3622 |
# Convert area from [sr] to [m2], and aice from [frc] to [%] |
| 3623 |
cmd_ppp[${fl_idx}]="ncap2 -O -s 'area*=${rds_rth}^2;area@long_name=\"Gridcell area\";area@units=\"m^2\";${sgs_frc}*=100;${sgs_frc}@units=\"%\"' \"${fl_out[${fl_idx}]}\" \"${fl_out[${fl_idx}]}\"" |
| 3624 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3625 |
echo ${cmd_ppp[${fl_idx}]} |
| 3626 |
fi # !dbg |
| 3627 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3628 |
if [ -z "${par_opt}" ]; then |
| 3629 |
eval ${cmd_ppp[${fl_idx}]} |
| 3630 |
if [ "$?" -ne 0 ] || [ ! -f ${fl_out[${fl_idx}]} ]; then |
| 3631 |
printf "${spt_nm}: ERROR Failed post-processing to convert output area from [sr] to [m2] and ${sgs_frc} from [frc] to [%]. Debug this:\n${cmd_ppp[${fl_idx}]}\n" |
| 3632 |
exit 1 |
| 3633 |
fi # !err |
| 3634 |
else # !par_typ |
| 3635 |
eval ${cmd_ppp[${fl_idx}]} ${par_opt} |
| 3636 |
ppp_pid[${fl_idx}]=$! |
| 3637 |
fi # !par_typ |
| 3638 |
fi # !dbg |
| 3639 |
fi # !prc_cice |
| 3640 |
|
| 3641 |
# Block 8: Other special case post-processing |
| 3642 |
if [ "${prc_typ}" = 'hirdls' ] || [ "${prc_typ}" = 'mls' ]; then |
| 3643 |
# NB: Move file to avert problem with --no_tmp_fl causing self-overwrite |
| 3644 |
# fxm: ncwa_fl is not parallel-safe, needs fl_idx suffix |
| 3645 |
cmd_ppp[${fl_idx}]="/bin/mv \"${fl_out[${fl_idx}]}\" \"${ncwa_fl}\";ncwa -O -a lon ${nco_opt} ${nco_var_lst} \"${ncwa_fl}\" \"${fl_out[${fl_idx}]}\"" |
| 3646 |
# Block 7 Loop 2: Execute and/or echo commands |
| 3647 |
if [ ${dbg_lvl} -ge 1 ]; then |
| 3648 |
echo ${cmd_ppp[${fl_idx}]} |
| 3649 |
fi # !dbg |
| 3650 |
if [ ${dbg_lvl} -ne 2 ]; then |
| 3651 |
if [ -z "${par_opt}" ]; then |
| 3652 |
eval ${cmd_ppp[${fl_idx}]} |
| 3653 |
if [ "$?" -ne 0 ] || [ ! -f ${fl_out[${fl_idx}]} ]; then |
| 3654 |
printf "${spt_nm}: ERROR Failed post-processing to generate zonal file from lat-lon file. Debug this:\n${cmd_ppp[${fl_idx}]}\n" |
| 3655 |
exit 1 |
| 3656 |
fi # !err |
| 3657 |
else # !par_typ |
| 3658 |
eval ${cmd_ppp[${fl_idx}]} ${par_opt} |
| 3659 |
ppp_pid[${fl_idx}]=$! |
| 3660 |
fi # !par_typ |
| 3661 |
fi # !dbg |
| 3662 |
fi # !znl |
| 3663 |
done # !fl_idx |
| 3664 |
|
| 3665 |
# Block 9: Wait for post-processing tasks to complete |
| 3666 |
if [ -n "${par_opt}" ]; then |
| 3667 |
for ((fl_idx=fl_idx_srt;fl_idx<=fl_idx_end;fl_idx++)); do |
| 3668 |
wait ${ppp_pid[${fl_idx}]} |
| 3669 |
if [ "$?" -ne 0 ]; then |
| 3670 |
printf "${spt_nm}: ERROR Failed post-processing step cmd_ppp[${fl_idx}]. Debug this:\n${cmd_ppp[${fl_idx}]}\n" |
| 3671 |
exit 1 |
| 3672 |
fi # !err |
| 3673 |
done # !fl_idx |
| 3674 |
fi # !par_opt |
| 3675 |
|
| 3676 |
done # !bch_idx |
| 3677 |
|
| 3678 |
if [ "${cln_flg}" = 'Yes' ]; then |
| 3679 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 3680 |
printf "Clean-up intermediate files...\n" |
| 3681 |
fi # !vrb_lvl |
| 3682 |
|
| 3683 |
/bin/rm -f ${dmm_fl} ${grd_dst_dfl} ${grd_dst_h5m_tmp} ${grd_dst_prt_tmp} ${grd_src_dfl} ${grd_src_h5m_tmp} ${grd_src_prt_tmp} ${hnt_dst_fl} ${hnt_src_fl} ${map_fl_dfl} ${map_trn_fl} ${msh_fl_dfl} ${ncwa_fl} ${nnt_fl} ${rgn_fl} ${tmp_out_fl} ${znl_fl/znl/znl1} ${znl_fl/znl/znl2} |
| 3684 |
else # !cln_flg |
| 3685 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 3686 |
printf "Explicitly instructed not to clean-up intermediate files\n" |
| 3687 |
fi # !vrb_lvl |
| 3688 |
fi # !cln_flg |
| 3689 |
|
| 3690 |
date_end=$(date +"%s") |
| 3691 |
if [ ${vrb_lvl} -ge ${vrb_3} ]; then |
| 3692 |
if [ ${fl_nbr} -eq 0 ]; then |
| 3693 |
if [ "${map_mk}" != 'No' ]; then |
| 3694 |
echo "Check statistics of generated map-file:" |
| 3695 |
echo "ncks --chk_map ${map_fl}" |
| 3696 |
echo "AnalyzeMap --map ${map_fl}" |
| 3697 |
fi # !map_mk |
| 3698 |
printf "Completed generating map/grid-file(s) at `date`.\n" |
| 3699 |
else # !fl_nbr |
| 3700 |
printf "Completed regridding data file(s) at `date`.\n" |
| 3701 |
echo "Quick plots of results from last regridded file:" |
| 3702 |
echo "ncvis ${out_fl} &" |
| 3703 |
fi # !fl_nbr |
| 3704 |
date_dff=$((date_end-date_srt)) |
| 3705 |
echo "Elapsed time $((date_dff/60))m$((date_dff % 60))s" |
| 3706 |
fi # !vrb_lvl |
| 3707 |
|
| 3708 |
exit 0 |