#!/usr/bin/env bash # ncremap, the NCO regridder and grid-file, map-file, and weight-generator # 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 # Copyright (C) 2015--present Charlie Zender # This file is part of NCO, the netCDF Operators. NCO is free software. # You may redistribute and/or modify NCO under the terms of the # 3-Clause BSD License. # You are permitted to link NCO with the HDF, netCDF, OPeNDAP, and UDUnits # libraries and to distribute the resulting executables under the terms # of the BSD, but in addition obeying the extra stipulations of the # HDF, netCDF, OPeNDAP, and UDUnits licenses. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the 3-Clause BSD License for more details. # The original author of this software, Charlie Zender, seeks to improve # it with your suggestions, contributions, bug-reports, and patches. # Please contact the NCO project at http://nco.sf.net or write to # Charlie Zender # Department of Earth System Science # University of California, Irvine # Irvine, CA 92697-3100 # Prerequisites: Bash, NCO (also ESMF_RegridWeightGen and/or TempestRemap for full functionality) # Script could use other shells, e.g., dash (Debian default) after rewriting function definitions and loops # Debug with 'bash -x ncremap --dbg=dbg_lvl' where 0 <= dbg_lvl <= 5 # Source: https://github.com/nco/nco/tree/master/data/ncremap # Documentation: http://nco.sf.net/nco.html#ncremap # Additional Documentation: # ncremap HowTo: https://e3sm.atlassian.net/wiki/spaces/DOC/pages/754286611/Regridding+E3SM+Data+with+ncremap # ncclimo HowTo: https://e3sm.atlassian.net/wiki/spaces/DOC/pages/31129737/Generate+Regrid+and+Split+Climatologies+climo+files+with+ncclimo # 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) # Benchmarks: https://acme-climate.atlassian.net/wiki/spaces/ATM/pages/25231711/Validation+and+Benchmarking+of+Regridders # Regridder works in one of four modes: # 1. Free-will: Infer source and destination grids to generate map-file, then regrid # 2. Old Grid: Use known-good destination grid to generate map-file then regrid # 3. New Grid: Generate source-grid from ncks parameter string # 4. Pre-Destination: Apply supplied map-file to all input files # By default, ncremap deletes any intermediate grids and map-file that it generates # 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 # 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 # Insta-install: # scp ~/nco/data/ncremap andes.olcf.ornl.gov:bin_andes # scp ~/nco/data/ncremap ac.zender@bebop.lcrc.anl.gov:bin # scp ~/nco/data/ncremap ac.zender@chrysalis.lcrc.anl.gov:bin_chrysalis # scp ~/nco/data/ncremap compy.pnl.gov:bin # scp ~/nco/data/ncremap derecho.hpc.ucar.edu:bin # scp ~/nco/data/ncremap dust.ess.uci.edu:bin # scp ~/nco/data/ncremap e3sm.ess.uci.edu:bin # scp ~/nco/data/ncremap frontier.olcf.ornl.gov:bin_frontier # scp ~/nco/data/ncclimo imua.ess.uci.edu:bin # scp ~/nco/data/ncclimo perlmutter-p1.nersc.gov:bin_perlmutter # scp ~/nco/data/ncremap spectral.ess.uci.edu:bin # scp dust.ess.uci.edu:bin/ncremap ~/bin # scp dust.ess.uci.edu:bin/ncremap ${MY_BIN_DIR} # scp zender@dust.ess.uci.edu:bin/ncremap ${MY_BIN_DIR} # Set script name, directory, PID, run directory drc_pwd=${PWD} # Security: Explicitly unset IFS before wordsplitting, so Bash uses default IFS= unset IFS # Set these before 'module' command which can overwrite ${BASH_SOURCE[0]} # NB: dash supports $0 syntax, not ${BASH_SOURCE[0]} syntax # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in spt_src="${BASH_SOURCE[0]}" [[ -z "${spt_src}" ]] && spt_src="${0}" # Use ${0} when BASH_SOURCE is unavailable (e.g., dash) while [ -h "${spt_src}" ]; do # Recursively resolve ${spt_src} until file is no longer a symlink drc_spt="$( cd -P "$( dirname "${spt_src}" )" && pwd )" spt_src="$(readlink "${spt_src}")" [[ ${spt_src} != /* ]] && spt_src="${drc_spt}/${spt_src}" # If ${spt_src} was relative symlink, resolve it relative to path where symlink file was located done cmd_ln="${spt_src} ${@}" drc_spt="$( cd -P "$( dirname "${spt_src}" )" && pwd )" spt_nm=$(basename ${spt_src}) # [sng] Script name (unlike $0, ${BASH_SOURCE[0]} works well with 'source