[399] | 1 | #!/bin/ksh |
---|
| 2 | |
---|
| 3 | #************************************************************** |
---|
| 4 | # Author: Josefine Ghattas |
---|
| 5 | # Contact: Josefine.Ghattas__at__ipsl.jussieu.fr |
---|
| 6 | # $Revision:: $ Revision of last commit |
---|
| 7 | # $Author:: $ Author of last commit |
---|
| 8 | # $Date:: $ Date of last commit |
---|
| 9 | # IPSL (2006) |
---|
| 10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
| 11 | # |
---|
| 12 | #************************************************************** |
---|
| 13 | # |
---|
| 14 | # Interpolation of monthly input ERAI files to the actual model grid. |
---|
| 15 | # |
---|
| 16 | # The patch should be applied once for each variable to interpolate. The file start.nc must be present in lmdz.car OutputFiles. |
---|
| 17 | # In lmdz.card all monthly ERAI files for the actual year to be interpolated must be present at format var_month_year.nc, where var=[u,v], |
---|
| 18 | # month=[1,13]. The file var_13_year.nc correspond to january the following year. |
---|
| 19 | # Partial year can be interpolated. |
---|
| 20 | # |
---|
| 21 | # |
---|
[401] | 22 | function IGCM_Patch_20101208_nudge_interp { |
---|
[399] | 23 | IGCM_debug_PushStack "IGCM_Patch_nudge_interp" $@ |
---|
| 24 | |
---|
[401] | 25 | ################################################################################################### |
---|
| 26 | # 1 - Define variables |
---|
[399] | 27 | # Filein is the first month to interpolate for a variable. |
---|
[401] | 28 | # Filein name should be at format X_Y_ZZZZ.nc, where X=varaiable name [u,v,ta], Y=[1,13] and ZZZZ=year. |
---|
[399] | 29 | # To do one year complete for one variable X, 13 month must be present. |
---|
[401] | 30 | ################################################################################################### |
---|
[399] | 31 | filein=${1} |
---|
| 32 | |
---|
| 33 | # Define startfile containg the destination grid. This file must exist in the OutputFiles list in lmdz.card. |
---|
| 34 | startfile=start.nc |
---|
| 35 | |
---|
| 36 | # Determine which variable and year concerned by this patch |
---|
| 37 | var=$( echo ${filein} | awk '-F_' '{print $1}' ) |
---|
| 38 | year=$( echo ${filein} | awk '-F_' '{print $3}' | awk '-F.nc' '{print $1}' ) |
---|
| 39 | echo var=$var year=$year |
---|
| 40 | |
---|
[401] | 41 | ################################################################################################### |
---|
| 42 | # 2 - Interpolate all files for the actual varaiable. |
---|
| 43 | # Original files will be overritten. |
---|
| 44 | ################################################################################################### |
---|
[399] | 45 | filelist=${var}_*.nc |
---|
| 46 | echo 'filelist 1 = ' ${filelist} |
---|
| 47 | for file in ${filelist}; do |
---|
| 48 | month=$( echo ${file} | awk '-F_' '{print $2}' | awk '-F_' '{print $1}' ) |
---|
| 49 | echo 'era2gcm for file = ' ${file} |
---|
| 50 | IGCM_era2gcm ${file} tmp_${file} ${var} ${year} |
---|
| 51 | IGCM_sys_Mv tmp_${file} ${file} |
---|
| 52 | done |
---|
| 53 | |
---|
[401] | 54 | ################################################################################################### |
---|
| 55 | # 3 - Add a final time step in each file, coming from the first time step in following month |
---|
| 56 | ################################################################################################### |
---|
[399] | 57 | filelist=${var}_*.nc |
---|
| 58 | echo 'filelist 2 = ' ${filelist} |
---|
| 59 | for file in ${filelist}; do |
---|
| 60 | month=$( echo ${file} | awk '-F_' '{print $2}' | awk '-F_' '{print $1}' ) |
---|
| 61 | month_next=`expr $month + 1` |
---|
| 62 | file_next=${var}_${month_next}_${year}.nc |
---|
| 63 | if [ -f ${file_next} ] ; then |
---|
| 64 | echo First time step from file ${file_next} will be added last in file ${file} |
---|
| 65 | ncks -O -d THOUR,0,0 ${file_next} tmp.nc |
---|
| 66 | ncrcat -O $file tmp.nc tmptot.nc |
---|
| 67 | IGCM_sys_Mv tmptot.nc $file |
---|
| 68 | else |
---|
| 69 | echo Next file ${file_next} does not exist. Nothing will be done for ${file} |
---|
| 70 | fi |
---|
| 71 | done |
---|
| 72 | |
---|
[401] | 73 | ################################################################################################### |
---|
| 74 | # 4 - Remove 13'th month |
---|
| 75 | ################################################################################################### |
---|
[399] | 76 | if [ -f ${var}_13_${year}.nc ] ; then |
---|
| 77 | echo Remove file ${var}_13_${year}.nc |
---|
| 78 | IGCM_sys_Rm ${var}_13_${year}.nc |
---|
| 79 | fi |
---|
| 80 | |
---|
| 81 | IGCM_debug_PopStack "IGCM_Patch_nudge_interp" |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | function IGCM_era2gcm { |
---|
| 86 | #set -xv |
---|
[401] | 87 | # Function that does a linear interpolation of the variable in |
---|
| 88 | # filein towards the destionation grid in gridfile. Results in are |
---|
| 89 | # stored in fileout. |
---|
| 90 | IGCM_debug_PushStack "IGCM_era2gcm" $@ |
---|
[399] | 91 | |
---|
[401] | 92 | ################################################################### |
---|
| 93 | # 1 - Define variables |
---|
| 94 | ################################################################### |
---|
[399] | 95 | filein=$1 |
---|
| 96 | fileout=$2 |
---|
| 97 | varin=$3 |
---|
| 98 | year=$4 |
---|
| 99 | |
---|
[401] | 100 | # Define file with destination grid |
---|
[399] | 101 | gridfile=start.nc |
---|
| 102 | |
---|
| 103 | # Find time boundaries |
---|
| 104 | tmin=1 |
---|
| 105 | tmax=`ncdump -h ${filein} | grep time | head -1 | awk ' { print $6 } '` |
---|
| 106 | tmax=$( echo ${tmax} | awk '-F(' '{print $2}' ) |
---|
| 107 | |
---|
[401] | 108 | # Choose grid and output variable name |
---|
[399] | 109 | if [ ${varin} = 'u' ] ; then |
---|
| 110 | varout=uwnd |
---|
[401] | 111 | grille='grille_u' |
---|
[399] | 112 | elif [ ${varin} = 'v' ] ; then |
---|
| 113 | varout=vwnd |
---|
[401] | 114 | grille='grille_v' |
---|
[399] | 115 | elif [ ${varin} = 'ta' ] ; then |
---|
| 116 | varout=air |
---|
[401] | 117 | grille='grille_t' |
---|
[399] | 118 | elif [ ${varin} = 'r' ] ; then |
---|
| 119 | varout=rh |
---|
[401] | 120 | grille='grille_t' |
---|
[399] | 121 | elif [ ${varin} = 'msl' ] ; then |
---|
| 122 | varout=sp |
---|
[401] | 123 | grille='grille_t' |
---|
[399] | 124 | else |
---|
| 125 | echo Error : ${varin} unknown!!!! |
---|
| 126 | exit |
---|
| 127 | fi |
---|
| 128 | |
---|
[401] | 129 | ################################################################### |
---|
| 130 | # 2 - Create ferret script for interpolation |
---|
| 131 | ################################################################### |
---|
| 132 | cat << eod > ${varin}.jnl |
---|
| 133 | set memory/size=50 |
---|
[399] | 134 | |
---|
[401] | 135 | use ${gridfile} |
---|
| 136 | use ${filein} |
---|
| 137 | let ${varout}=${varin} |
---|
| 138 | |
---|
| 139 | define axis/t=01-JAN-${year}:31-DEC-${year}:6/units=hours thour |
---|
| 140 | |
---|
| 141 | define grid/like=${varout}[d=2]/x=cu[d=1]/y=cu[d=1] grille_u |
---|
| 142 | define grid/like=${varout}[d=2]/x=cv[d=1]/y=cv[d=1] grille_v |
---|
| 143 | define grid/like=${varout}[d=2]/x=cv[d=1]/y=cu[d=1] grille_t |
---|
| 144 | |
---|
| 145 | save/clobber/file=${fileout} ${varout}[d=2,g=${grille},l=1,gt=thour@asn] |
---|
| 146 | repeat/l=1:${tmax} save/file="${fileout}"/append ${varout}[d=2,g=${grille},gt=thour@asn] |
---|
| 147 | |
---|
[399] | 148 | exit |
---|
| 149 | eod |
---|
| 150 | |
---|
| 151 | ################################################################### |
---|
[401] | 152 | # 3 - Launch interpolation with ferret |
---|
[399] | 153 | ################################################################### |
---|
| 154 | ferret -nojnl <<eod > /dev/null |
---|
[401] | 155 | go ${varin}.jnl |
---|
[399] | 156 | quit |
---|
| 157 | eod |
---|
| 158 | |
---|
| 159 | IGCM_debug_PopStack "IGCM_era2gcm" |
---|
| 160 | } |
---|