source: BOL/era2gcm_tuto.sh @ 4609

Last change on this file since 4609 was 4609, checked in by asima, 11 months ago

Initial import of LMDZ_configure environment.
Folder's content is identical to TEST_PROD from
https://lmdz.lmd.jussieu.fr/pub/Training/Archive/tutorial_prod.tar_v20230705.

File size: 8.8 KB
Line 
1#!/bin/bash
2
3#-----------------------------------------------------------------------------
4#
5#  Script for interpolating monthly ERA* files to the LMDZ grid;
6#  it creates the folder structure required by the tutorial_prod scripts
7#
8#  NB: for "cleanest" guiding, the 1st step of the next month should be added at the end of each month.
9#    If you need such precision, you should use the scripts here  - AND adjust "ERADIR" in script_SIMU !
10#    wget http://forge.ipsl.jussieu.fr/igcmg/browser/TOOLS/INTERP_NUDGE
11#      documented on LMDZpedia (search for "Guidage" )
12#
13#-----------------------------------------------------------------------------
14# Requires : netcdf, ferret, nco
15#-----------------------------------------------------------------------------
16module load netcdf/4.7.2-mpi-cuda ferret nco cdo
17#
18# Check&modify section "User choices", then run the script with ./era2gcm.sh
19#-----------------------------------------------------------------------------
20# ATTENTION : VERIFIEZ
21#  --> l'acces (repositoire ou telechargement) a la reanalyse ERA souhaitee (variable ANA_DIR)
22#    Contact pour demander acces aux fichiers sur Jean-Zay :
23#        Sophie Bouffiès-Cloché, IPSL : Sophie.Bouffies-Cloche@ipsl.fr
24
25#  --> la disponibilite des fichiers pour la periode souhaitee (variables file*)
26#-----------------------------------------------------------------------------
27
28#------------------------------------------------
29# User choices
30#------------------------------------------------
31# Periode :
32mth_i=200001
33mth_f=200001
34#
35# Guidage en vent(u&v) et/ou temperature, humidite
36guide_uv=y
37guide_t=n
38guide_q=n
39#
40# Choix des fichiers de guidage ("rea"nalyses) : ERA5, ERAI, OPERA
41rea=ERA5
42#------------------------------------------------
43
44GRID_DIR=./INIT
45#-----------------------------------------------------------------------------
46#Utilite du block suivant a re-examiner :
47#-----------------------------------------------------------------------------
48#L'utilisateur a maintenant des choix a faire en plus de mth* : type de guidage, et "rea"
49# Alors c'est plus facile d'editer&modifier le script, puis lancer avec ./era2gcm.sh, que de donner tous les params
50while (($# > 0))
51   do
52   case $1 in
53     "-h") cat <<........fin
54           ./era2gcm.sh [-mthini initial_month] [-mthend final_month] [-grid_dir directory_containing_grille_gcm.nc]
55........fin
56     exit ;;
57     "-grille_dir") GRID_DIR=$2 ; shift ; shift ;;
58     "-mthini") mth_i=$2 ; shift ; shift ;;
59     "-mthend") mth_f=$2 ; shift ; shift ;;
60     *) $0 -h ; exit
61   esac
62done
63#--Fin du block a examiner --------------------------------------------
64
65tmin=1
66resol=grilles_gcm.nc
67
68GRID_FI=${GRID_DIR}/${resol}
69if [ ! -f "$GRID_FI" ] ; then
70   echo Le fichier $GRID_DIR/$resol est necessaire
71   echo creer le fichier $GRID_FI avec grilles_gcm_netcdf.e
72   exit
73fi
74mth=$mth_i
75
76
77#####################################################################
78while (( $mth <= $mth_f )) ; do
79#####################################################################
80   echo mth $mth
81   mois=`echo $mth | cut -c 5-`
82   an=`echo $mth | cut -c -4`
83   ndays=( 31 28 31 30 31 30 31 31 30 31 30 31 )
84   months=( jan feb mar apr may jun jul aug sep oct nov dec )
85   if [ $(( $an % 4 )) = 0 ] ; then ndays[1]=29 ; fi
86   imois=$(( ${mois#0} - 1 ))
87   month=${months[$imois]}
88   nday=${ndays[$imois]}
89   tmax=$(( $nday * 4 ))
90   echo PARAMETRES CALENDAIRES $imois $month $nday $tmax
91
92
93   iip1=`ncdump -h $GRID_FI | grep lonu | head -1 | awk ' { print $3 } '`
94   jjm=`ncdump -h $GRID_FI | grep latv | head -1 | awk ' { print $3 } '`
95   (( jjp1 =  $jjm + 1 ))
96   (( iim  = $iip1 - 1 ))
97#   \rm t2.nc ua.nc va.nc sst.nc u.nc v.nc T.nc ts.nc
98
99#####################################################################
100# Choix de la periode temporelle
101#####################################################################
102
103   t0="l=$tmin"
104   t1tn="l=${tmin}:${tmax}"
105
106#####################################################################
107# Lien avec les fichiers netcdf contenant les d0 ECMWF
108#####################################################################
109   echo -------- liens de telechargement a actualiser ----
110   if [ "$rea" = "ERA5" ] ; then
111      ANA_DIR='/gpfsstore/rech/psl/rpsl376/ergon/ERA5/NETCDF/GLOBAL_025/4xdaily'
112      suf="e5.GLOBAL_025"
113   elif [ "$rea" = "ERAI" ] ; then
114      #ANA_DIR='http://prodn.idris.fr/thredds/dodsC/ipsl_private/rpsl376/ERAI/NETCDF/GLOBAL_1125/4xdaily'
115      ANA_DIR='/gpfsstore/rech/psl/rpsl376/ergon/ERAI/NETCDF/GLOBAL_1125/4xdaily'
116      #/gpfsstore/rech/psl/rpsl376/ergon/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_PL/2006/u.200601.aphei.GLOBAL_075.nc
117      suf="ei.GLOBAL_1125"
118   else  #OPERA
119      #ANA_DIR='http://prodn.idris.fr/thredds/dodsC/ipsl_private/rpsl376/OPERA/NETCDF/4xdaily'
120      ANA_DIR='/gpfsstore/rech/psl/rpsl376/ergon/OPERA/NETCDF/4xdaily'
121      suf=".GLOBAL_1125"
122   fi
123
124varu=u
125varv=v
126vart=ta # peut etre parfois juste "t"
127varq=q
128if [ "$rea" = "ERA5" ] ; then varq=r ; fi
129#varp=msl
130
131if [ "$rea" = "ERAI" ] ; then
132  # variables en format "short" doivent etre transformees en "float" via NCO
133  # This is done here with ncap2 ; also possible: "ncpdq --overwrite --unpack fin.nc fout.nc"
134  fushort="$ANA_DIR/AN_PL/$an/u.$an$mois.aph$suf.nc"
135  fvshort="$ANA_DIR/AN_PL/$an/v.$an$mois.aph$suf.nc"
136  ftshort="$ANA_DIR/AN_PL/$an/ta.$an$mois.aph$suf.nc"
137  fileu="$SCRATCH/u.$an$mois.aph$suf.nc"
138  filev="$SCRATCH/v.$an$mois.aph$suf.nc"
139  filet="$SCRATCH/ta.$an$mois.aph$suf.nc"
140  ncap2 -s 'u=float(u)' $fushort $fileu
141  ncap2 -s 'v=float(v)' $fvshort $filev
142  ncap2 -s 'ta=float(ta)' $ftshort $filet
143else
144 fileu="$ANA_DIR/AN_PL/$an/u.$an$mois.aph$suf.nc"
145 filev="$ANA_DIR/AN_PL/$an/v.$an$mois.aph$suf.nc"
146 filet="$ANA_DIR/AN_PL/$an/ta.$an$mois.aph$suf.nc"
147fi
148fileq="$ANA_DIR/AN_PL/$an/r.$an$mois.aph$suf.nc"
149
150# verifier disponibilite des fichiers
151if [ "$guide_uv" = "y" ] ; then  ls $fileu ; ls $filev ; fi
152if [ "$guide_t" = "y" ] ; then  ls $filet ; fi
153if [ "$guide_q" = "y" ] ; then  ls $fileq ; fi
154
155outd=GUIDE_${rea}/$an/$mois
156mkdir -p $outd
157
158# effacer lien vers repertoire des vents ERA interpoles (utilise dans script_SIMU) s'il existe deja
159# recreer lien vers le repertoire "rea" choisi
160# NB : si GUIDE existe en tant que repertoire, non pas comme lien, il n'est pas affecte
161rm -f GUIDE
162ln -s GUIDE_${rea} GUIDE
163
164ij="i=1:$iip1,j=1:$jjp1"
165ijm="i=1:$iip1,j=1:$jjm"
166
167###################################################################3
168# scripts ferret pour interpolation
169###################################################################3
170
171# --- guide uv ---
172
173if [ "$guide_uv" = "y" ] ; then
174
175cat <<eod>| tmp_uv.jnl
176! NB : Augmenter la memoire (plus de 512) peut faire planter
177set memory/size=512
178
179use "$GRID_FI"
180use "$fileu"
181use "$filev"
182
183define axis/t="1-${month}-${an}:00:00":"${nday}-${month}-${an}:18:00":6/units=hours thour
184! Pour regrid horizontal on utilise la variable grille_s(lonv,latu) du fichier grilles_gcm.nc
185
186
187!! ATTENTION : pour ecrire le fichier en simple, non pas double precision :
188!! on utilise directement $varu = "float" dans le fichier d'origine (non pas une variable definie avec "let" dans ferret)
189!! Alors il faut renommer la variable à la fin (ncrename), car le code cherche "UWND", "VWND".
190save/clobber/file="$outd/u.nc" $varu[d=2,gxy=grille_u[d=1],$ij,$t0,gt=thour@asn]
191repeat/$t1tn save/file="$outd/u.nc"/append $varu[d=2,gxy=grille_u[d=1],$ij,gt=thour@asn]
192save/clobber/file="$outd/v.nc" $varv[d=3,gxy=grille_v[d=1],$ijm,$t0,gt=thour@asn]
193repeat/$t1tn save/file="$outd/v.nc"/append $varv[d=3,gxy=grille_v[d=1],$ijm,gt=thour@asn]
194
195eod
196
197ferret -nojnl <<eod
198go tmp_uv.jnl
199quit
200eod
201#Ferret a ecrit $varu en majuscules, l'equivalent en bash est ${varu^^}
202#   (Note : inversement, ${varu,,} passe $varu de majuscules en minuscules)
203ncrename -v ${varu^^},UWND $outd/u.nc
204ncrename -v ${varv^^},VWND $outd/v.nc
205
206fi  # ------- fin guide_uv --------
207
208# --- guide_t  ---
209
210if [ "$guide_t" = "y" ] ; then
211
212cat <<eod>| tmp_t.jnl
213set memory/size=512
214
215use "$GRID_FI"
216use "$filet"
217
218define axis/t="1-${month}-${an}:00:00":"${nday}-${month}-${an}:18:00":6/units=hours thour
219
220save/clobber/file="$outd/T.nc" $vart[d=2,gxy=grille_s[d=1],$ij,$t0,gt=thour@asn]
221repeat/$t1tn save/file="$outd/T.nc"/append $vart[d=2,gxy=grille_s[d=1],$ij,gt=thour@asn]
222eod
223
224ferret -nojnl <<eod
225go tmp_t.jnl
226quit
227eod
228ncrename -v ${vart^^},AIR $outd/T.nc
229
230fi  # ------- fin guide_t --------
231
232# --- guide_q  ---
233
234if [ "$guide_q" = "y" ] ; then
235
236cat <<eod>| tmp_q.jnl
237set memory/size=512
238
239use "$GRID_FI"
240use "$fileq"
241
242define axis/t="1-${month}-${an}:00:00":"${nday}-${month}-${an}:18:00":6/units=hours thour
243
244save/clobber/file="$outd/hur.nc" $varq[d=2,gxy=grille_s[d=1],$ij,$t0,gt=thour@asn]
245repeat/$t1tn save/file="$outd/hur.nc"/append $varq[d=2,gxy=grille_s[d=1],$ij,gt=thour@asn]
246eod
247
248ferret -nojnl <<eod
249go tmp_q.jnl
250quit
251eod
252ncrename -v ${varq^^},RH $outd/hur.nc
253
254fi  # ------- fin guide_q --------
255
256
257echo AN MTH $an $mois
258(( mth = $mth + 1 ))
259if [ $mois = 12 ] ; then
260   (( an = $an + 1 ))
261   mth=${an}01
262fi
263
264done
Note: See TracBrowser for help on using the repository browser.