#!/bin/bash # This script is a wrapper around mkprocdata_map that runs that # program and then copies some additional variables from the template # file to the output file. It also does some additional pre and # post-processing in order to create some additional variables. # Created by Bill Sacks, 5-25-11 # ---------------------------------------------------------------------- # SET PARAMETERS HERE # ---------------------------------------------------------------------- # comma-delimited list of extra variables to copy directly from # template file; note that these variables should not be written out # by mkprocdata_map (i.e., everything in this list should be listed in # the 'ignore_var' function in mkprocdata_map.F90); however, there may # be some variables in the 'ignore_var' function that are not listed # here - e.g., variables that we treat specially. copy_vars="lon,lat" # comma-delimited list of extra variables to copy from the template # file if the -l option is specified -- this option says to copy # landfrac and related variables. Note that some of these variables # may be written out by mkprocdata_map, in which case they will be # overwritten afterwards (slighly less efficient, but that keeps # things simpler). landfrac_copy_vars="landfrac,landmask,pftmask" # name of the executable; expected to be in the same directory as this script executable="mkprocdata_map" # minimum value for regridded pftmask variable for the output variable to be 1 pftmask_min="1.e-6" # fill value for landmask landmask_fill=-9999 # ---------------------------------------------------------------------- # LOCAL FUNCTIONS DEFINED HERE # ---------------------------------------------------------------------- function Usage { script_name=`basename $0` echo "Usage: $script_name -i input_file -o output_file -m map_file -t template_file [-h] [-l]" echo "" echo "This script runs mkprocdata_map with the given arguments (-i, -o, -m and -t)," echo "then copies some additional variables from the template file" echo "to the output file. It also does some additional pre and" echo "post-processing in order to create some additional variables." echo "" echo "Additional optional arguments:" echo "" echo "[-h]: Print this help message and exit" echo "" echo "[-l]: Rather than computing landfrac and related variables" echo "by regridding the input file, instead copy these variables" echo "directly from the template file. The variables this pertains" echo "to are:" echo $landfrac_copy_vars } # This function operates on a single variable in a file, changing all # places where that variable is missing to some new (non-missing) # value. The _FillValue attribute remains unchanged. # Usage: change_missing_to_value varname newval infile outfile # - varname: the name of the variable to change # - newval: all instances of the missing value will be replaced with # this new value # - infile: input file name # - outfile: output file name (can be the same as infile) function change_missing_to_value { if [[ $# -ne 4 ]]; then echo "ERROR in change_missing_to_value: wrong number of arguments: expected 2, received $#" exit 1 fi varname=$1 newval=$2 infile=$3 outfile=$4 varname_tmp=${varname}_tmp_$$ cat > cmds.nco.tmp.$$ <= $pftmask_min)' $output_file $output_file" 0 do_cmd "ncks -O -x -v pftmask_float $output_file $output_file" 0 # --- Calculate landmask from landfrac --- echo "" cat > cmds.nco.tmp.$$ < 0); landmask_float.change_miss($landmask_fill); landmask = int(landmask_float); EOF do_cmd "ncap2 -O -S cmds.nco.tmp.$$ $output_file $output_file" 0 rm cmds.nco.tmp.$$ change_missing_to_value landmask 0 $output_file $output_file # in the following, note that we need to manually set missing_value, because it doesn't get changed through the .set_miss call in nco: do_cmd "ncatted -a long_name,landmask,o,c,'land/ocean mask (0.=ocean and 1.=land)' -a missing_value,landmask,o,i,$landmask_fill $output_file" 0 fi echo "Successfully regridded data" return 0