Skip to content

Instantly share code, notes, and snippets.

@MiCurry
Created November 12, 2021 12:18
Show Gist options
  • Save MiCurry/dadf5a6760f806f3490de4509a2a301c to your computer and use it in GitHub Desktop.
Save MiCurry/dadf5a6760f806f3490de4509a2a301c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#PBS -N deposition_run
#PBS -A NMMM0013
#PBS -l walltime=00:40:00
#PBS -q regular
#PBS -j oe
#PBS -l select=1:ncpus=36:mpiprocs=36
if [ $# -ne 3 ]; then
echo "Usage: create_deposition.sh grid_alias ESMF/SCRIP-gridFile date" 1>&2
exit 1;
fi
short_grid_name=$1
mpas_grid_file=$2 # This can be either ESMF or SCRIP format
datestr=$3
ulimit -s unlimited
mapdir=`pwd`
export MPI_TYPE_DEPTH=16 # Seems to be needed with netcdf-mpi module on Cheyenne
module load gnu
module load esmf_libs
module load esmf-8.0.0-ncdfio-mpi-O
module load nco/4.7.9
export srcgrid=0.23x0.31
export srcgridfile=/glade/p/cesmdata/inputdata/share/scripgrids/fv0.23x0.31_141008.nc
export srcinitfile=/glade/p/cesmdata/inputdata/atm/cam/chem/trop_mam/atmsrf_0.23x0.31_181018.nc
export dstinitfile=atmsrf_${short_grid_name}_${datestr}.nc
echo "create_deposition: Creating mapping file between ${srcgridfile} and ${mpas_grid_file}"
ESMF_RegridWeightGen --64bit_offset --ignore_unmapped -m bilinear --dst_loc center -w map_${srcgrid}_to_${short_grid_name}_blin.nc -s ${srcgridfile} -d ${mpas_grid_file}
if [ $? -ne 0 ]; then
echo "ERROR: Error when generating map between ${srcgridfile} and ${mpas_grid_file}"
exit 1;
fi
echo "create_deposition: Creating remapping of ${srcinitfile} to ${mpas_grid_file} using map_${srcgrid}_to_${short_grid_name}_blin.nc"
#use the mapfile to remap srcinitfile to dstinitfile
ncremap -6 -m ./map_${srcgrid}_to_${short_grid_name}_blin.nc -i ${srcinitfile} -o ${dstinitfile}
if [ $? -ne 0 ]; then
echo "ERROR: Error when generating map between ${srcgridfile} and ${mpas_grid_file}"
exit 1;
fi
echo "create_deposition: Remapped deposition file succsfully ${dstinitfile}"
echo "create_deposition: Removing temporary mapping file map_${srcgrid}_to_${short_grid_name}_blin.nc..."
rm map_${srcgrid}_to_${short_grid_name}_blin.nc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment