Created
July 10, 2018 18:24
-
-
Save dbaston/f6a99bfb6cb7800b2cd28ff3b6279148 to your computer and use it in GitHub Desktop.
extract a (vertical, time) slice from a netCDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
display_usage() { | |
echo "Extract a slice from a netCDF and remove the variable" | |
echo "extract.sh [in] [dimension] [value] [out]" | |
echo "" | |
echo "Example: extract.sh temperature.nc elevation 2 temperature_2.nc" | |
} | |
if [ $# -ne 4 ] | |
then | |
display_usage | |
exit 1 | |
fi | |
N=1 | |
TEMP1=`mktemp -u --suffix=.nc` | |
TEMP2=`mktemp -u --suffix=.nc` | |
TEMP3=`mktemp -u --suffix=.nc` | |
ncea -d ${2},${N},${N} -F ${1} ${TEMP1} | |
# Drop the time dimension | |
ncwa --no_tmp_fl -h -a ${2} ${TEMP1} ${TEMP2} | |
# Drop the time variable | |
ncks --no_tmp_fl -h -C -O -x -v ${2} ${TEMP2} ${TEMP3} | |
mv ${TEMP3} ${4} | |
rm ${TEMP1} | |
rm ${TEMP2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment