123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #!/usr/bin/env bash
- #
- # interp, scrip_use and scrip_use_extrap have been written by Virginie Guemas
- # in 2011 based on SCRIP software that computes interpolation weights:
- # Spherical Coordinate Remapping and Interpolation Package
- #
- #~~~~~~~~~~~~~~~
- # get arguments
- #~~~~~~~~~~~~~~~
- if [ $# == 0 ]; then
- echo
- echo "USAGE: $(basename $0) <input_file> <input_var> <method> <gridin> <gridout> <output_file> <debug>"
- echo "<method> can be bilinear/bicubic/conserv/distwgt"
- echo "<gridin> and <gridout> can be ORCA1t_v2.2/ORCA1t_v3.2/ORCA025t_v3.2/ERA40/ERAint/EcEarth2/EcEarth3/HadISST/NCEP/NOAAv3b/NSIDC"
- echo "<debug> optional argument in case default choices not convenient : TRUE/FALSE"
- exit 1
- fi
-
- filein=$1
- varin=$2
- method=$3
- gridin=$4
- gridout=$5
- fileout=$6
- if [ $# == 7 ]; then
- debug=$7
- else
- debug='FALSE'
- fi
- exec='scrip_use'
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # /cfu/data conventions or not ?
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- case $gridin in
- 'ORCA1t_v2.2'|'ORCA1t_v3.2'|'ORCA025t_v3.2'|'NSIDC')
- flag1='FALSE'
- ;;
- 'NCEP'|'ERAint'|'ERA40'|'EcEarth2'|'EcEarth3'|'HadISST'|'NOAAv3b')
- flag1='TRUE'
- ;;
- *)
- flag1='FALSE'
- ;;
- esac
- case $gridin in
- 'ERA40'|'ERAint'|'EcEarth2'|'EcEarth3'|'HadISST'|'NCEP'|'NOAAv3b'|'NSIDC')
- flag2='TRUE'
- ;;
- 'ORCA1t_v2.2'|'ORCA1t_v3.2'|'ORCA025t_v3.2')
- flag2='FALSE'
- ;;
- *)
- flag2='FALSE'
- ;;
- esac
- #~~~~~~~~~~~~~~~~~~~~
- # land data or not ?
- #~~~~~~~~~~~~~~~~~~~~
- case $varin in
- 'tas'|'prlr'|'g500'|'g200'|'psl'|'hflsd'|'hfssd'|'hus'|'rls'|'rss'|'rsds'|'vas'|'uas'|'tasmax'|'tasmin') ;;
- 'tos'|'ice'|'mld'|'sic'|'sit'|'sea_ice_area_fraction') gridin=${gridin}'_ocean' ;;
- 'ice_pres'|'somixhgt'|'sosstsst'|'sosaline'|'iicethic'|'ileadfra'|'isnowthi'|'iicetemp'|'somxl010'|'somxlheatc'|'somxlsaltc'|'sobarstfu'|'sobarstfv'|'sobarstf'|'heatc_sl'|'vertmeansal'|'votemper'|'vosaline'|'rhopn') gridout=${gridout}'_ocean' ;;
- *) echo "unexpected input variable : contact Virginie" ; exit 1 ;;
- esac
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- # Weigths available or not ?
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- if [[ ! -e /cfu/pub/scripts/interpolation/weigths/rmp_${gridin}_to_${gridout}_${method}.nc ]] ; then
- echo "unexpected input or output grid : contact Virginie"
- exit 1
- fi
- #~~~~~~~~~~~~~~~
- # Interpolation
- #~~~~~~~~~~~~~~~
- if [[ ! -e ${filein} ]] ; then
- echo ${filein}" does not exist"
- exit 1
- fi
- vars=`cdo showvar ${filein}`
- exist='FALSE'
- for var in $vars ; do
- if [[ $var == ${varin} ]] ; then exist='TRUE' ; fi
- done
- if [[ $exist == 'FALSE' ]] ; then
- echo $var" is not in input file"
- exit 1
- fi
- cat > scrip_use_in <<EOF
- &remap_inputs
- remap_wgt = '/cfu/pub/scripts/interpolation/weigths/rmp_${gridin}_to_${gridout}_${method}.nc'
- infile = '${filein}'
- invertlat = ${flag1}
- var = '${varin}'
- fromregular = ${flag2}
- outfile = '${fileout}'
- /
- EOF
- ln -sf /cfu/pub/scripts/interpolation/${exec} ${exec}
- ./${exec}
- if [[ $debug == 'FALSE' ]] ; then
- rm -f ${exec} scrip_use_in
- else
- ln -sf /cfu/pub/scripts/interpolation/${exec}_extrap ${exec}_extrap
- fi
|