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