1 | #!/bin/ksh |
---|
2 | #set -xv |
---|
3 | # Function that does a linear interpolation of the variable in |
---|
4 | # filein towards the destionation grid in gridfile. Results in are |
---|
5 | # stored in fileout. |
---|
6 | # |
---|
7 | # Exemple for use : |
---|
8 | # ./era2gcm.ksh grilles_gcm.nc u_filein.nc u_fileout.nc u |
---|
9 | # |
---|
10 | ################################################################### |
---|
11 | # O - Input arguments |
---|
12 | ################################################################### |
---|
13 | # gridfile : File containing the target grid (grilles_gcm.nc) |
---|
14 | gridfile=$1 |
---|
15 | # filein : File containing the variable at source grid |
---|
16 | filein=$2 |
---|
17 | # fileout : Output file with the variable at target grid |
---|
18 | fileout=$3 |
---|
19 | # varin : Variable name in source file |
---|
20 | varin=$4 |
---|
21 | |
---|
22 | ################################################################### |
---|
23 | # 1 - Define variables |
---|
24 | ################################################################### |
---|
25 | # Find number of time step |
---|
26 | tmax=`ncdump -h ${filein} | grep time | head -1 | awk ' { print $6 } '` |
---|
27 | tmax=$( echo ${tmax} | awk '-F(' '{print $2}' ) |
---|
28 | |
---|
29 | # Choose grid and output variable name |
---|
30 | if [ ${varin} = 'u' ] || [ ${varin} = 'vitu' ] ; then |
---|
31 | varout=uwnd |
---|
32 | grille='grille_u' |
---|
33 | elif [ ${varin} = 'v' ] || [ ${varin} = 'vitv' ] ; then |
---|
34 | varout=vwnd |
---|
35 | grille='grille_v' |
---|
36 | elif [ ${varin} = 'ta' ] || [ ${varin} = 'temp' ] ; then |
---|
37 | varout=air |
---|
38 | grille='grille_t' |
---|
39 | elif [ ${varin} = 'r' ] || [ ${varin} = 'hur' ] ; then |
---|
40 | varout=rh |
---|
41 | grille='grille_t' |
---|
42 | elif [ ${varin} = 'msl' ] ; then |
---|
43 | varout=sp |
---|
44 | grille='grille_t' |
---|
45 | else |
---|
46 | echo Error : ${varin} unknown!!!! |
---|
47 | exit |
---|
48 | fi |
---|
49 | |
---|
50 | ################################################################### |
---|
51 | # 2 - Create ferret script for interpolation |
---|
52 | ################################################################### |
---|
53 | cat << eod > ${varin}.jnl |
---|
54 | set memory/size=50 |
---|
55 | |
---|
56 | use "${gridfile}" |
---|
57 | use "${filein}" |
---|
58 | let ${varout}=${varin} |
---|
59 | |
---|
60 | define grid/like=${varout}[d=2]/x=grille_u[d=1]/y=grille_u[d=1] grille_u |
---|
61 | define grid/like=${varout}[d=2]/x=grille_v[d=1]/y=grille_v[d=1] grille_v |
---|
62 | define grid/like=${varout}[d=2]/x=grille_v[d=1]/y=grille_u[d=1] grille_t |
---|
63 | |
---|
64 | save/clobber/file="${fileout}" ${varout}[d=2,g=${grille},l=1] |
---|
65 | repeat/l=1:${tmax} save/file="${fileout}"/append ${varout}[d=2,g=${grille}] |
---|
66 | |
---|
67 | exit |
---|
68 | eod |
---|
69 | |
---|
70 | ################################################################### |
---|
71 | # 3 - Launch interpolation with ferret |
---|
72 | ################################################################### |
---|
73 | ferret -nojnl <<eod > /dev/null |
---|
74 | go ${varin}.jnl |
---|
75 | quit |
---|
76 | eod |
---|
77 | |
---|
78 | #} |
---|