source: TOOLS/CMIP6_FORCING/OZONE/clims_CMIP6.bash @ 3389

Last change on this file since 3389 was 3389, checked in by oboucher, 4 years ago

Uploading scripts to prepare ozone files for CMIP6
Only preparatory phase...

  • Property svn:executable set to *
File size: 20.5 KB
Line 
1#!/bin/bash
2
3ia="3"      #=== Indices of chosen Amip  datasets (see below AMIP_VERSION_NAMES/AMIP_VERSION_FOLDERS)
4io="1"      #=== Indices of chosen Ozone datasets (see below OZON_VERSION_NAMES/OZON_VERSION_FOLDERS)
5recomp='n'  #=== Recompute files that are already present (y/n)
6do_amip='n' #=== Compute sic/sst files
7do_ozon='y' #=== Compute ozone files
8
9
10#===============================================================================
11#=== DETERMINE THE MACHINE NAME ================================================
12#===============================================================================
13if   [ ${HOSTNAME:0:3} = 'ada'    ]; then machine='ada';    work=$WORKDIR
14elif [ ${HOSTNAME:0:5} = 'curie'  ]; then machine='curie'work=$CCCWORKDIR
15elif [ ${HOSTNAME:0:6} = 'ciclad' ]; then machine='ciclad'; work=/data/$USER
16else echo "Not set up for this machine yet, sorry."; exit; fi
17export machine=$machine
18
19#===============================================================================
20#=== PARAMETERS NOT SUPPOSED TO BE CHANGED OFTEN ===============================
21#===============================================================================
22local=$PWD
23echo $machine
24case $machine in
25  ada)    work=$WORKDIR
26          DATAIN="/workgpfs/rech/dzt/"$USER"/input4MIPs"
27          DATAOU="/workgpfs/rech/dzt/"$USER"/IGCM"
28          module load netcdf
29          module load nco/4.4.6 ;;
30  curie)  work=$CCCWORKDIR; DATAIN=""
31          DATAIN="/ccc/work/rech/psl/"$USER"/input4MIPs"
32          DATAOU="/ccc/work/rech/psl/"$USER"/IGCM"
33          module load netcdf
34          module load nco ;;
35  ciclad) work=/data/$USER
36          DATAIN='/prodigfs/project/input4MIPs'
37          DATAOU='/prodigfs/ipslfs/igcmg/IGCM'
38          DATAOU='/data/'${USER}'/CMIP6/OZONE'
39          module load nco/4.4.8 ;;
40esac
41
42if [ ! -d ${DATAOU} ] ; then mkdir -p ${DATAOU} ; fi
43
44#--- INPUT DATA: AMIP
45AMIP_VERSION_NAMES=('PCMDI-AMIP-1-1-0' 'PCMDI-AMIP-1-1-1' 'PCMDI-AMIP-1-1-2')
46AMIP_VERSION_FOLDERS=('gs1x1/v20160609' 'gn/v20161020' 'gn/v20170419')
47AMIP_FOLDER_IN=$DATAIN/PCMDI/SSTsAndSeaIce/CMIP/\${amip_version_name}/mon/\${V}/\${amip_version_folder}
48amip_vname_in=('tosbcs' 'siconcbcs')
49amip_fname_in='${V}_input4MIPs_SSTsAndSeaIce_CMIP_${amip_version_name}_${amip_version_folder%/*}*_18????-20????.nc'
50
51#--- INPUT DATA: OZONE
52OZON_VERSION_NAMES=('UReading-CCMI-1-0')
53OZON_VERSION_FOLDERS=('gr/v20160711'); if [ $machine = 'ciclad' ]; then OZON_VERSION_FOLDERS=('gr/v20160907'); fi
54OZON_FOLDER_IN=$DATAIN/UReading/ozone/CMIP/\${ozon_version_name}/mon/\${V}/\${ozon_version_folder}
55ozon_vname_in='vmro3'
56ozon_fname_in='${V}_input4MIPs_ozone_CMIP_${ozon_version_name}_${ozon_version_folder%/*}*_${Yi}01-${Yf}12.nc'
57
58#--- VERSIONS OF INPUT FILES EFFECTIVELY CHOSEN
59((ia--)); ((io--))
60amip_version_name=${AMIP_VERSION_NAMES[$ia]}; amip_version_folder=${AMIP_VERSION_FOLDERS[$ia]}
61ozon_version_name=${OZON_VERSION_NAMES[$io]}; ozon_version_folder=${OZON_VERSION_FOLDERS[$io]}
62
63#--- OUTPUT DATA
64AMIP_FOLDER_OU=$DATAOU/ATM/LIMIT/AMIP.\${amip_version_folder##*/}/original/\${nlon}x\${nlat}/BCS
65OZON_FOLDER_OU=$DATAOU/ATM/OZONE/UReading.\${ozon_version_folder##*/}/original
66amip_vname_ou=('tosbcs' 'sicbcs'); amip_fname_ou='amipbc_${V}_${nlon}x${nlat}_${Y}.nc'
67ozon_vname_ou='tro3'             ; ozon_fname_ou='${V}_${Y}.nc'
68Y_amip=1870-2016                     #--- FOR AMIP  FILES (INTERANNUAL)
69Y_ozon=1850-2014:50                  #--- FOR OZONE FILES (INTERANNUAL)
70Y_clim=1979-2008                     #--- FOR CLIMATOLOGIES (COMMON PERIODS FOR O3 AND SIC/SST)
71Y_pind=1870-1899                     #--- FOR SST/SIC PRE-INDUSTRIAL CLIMATOLOGY
72
73if [ "$do_amip" = "y" ]; then
74  echo ">> Chosen SST files:   $(V=${amip_vname_in[0]}; amip_version_name=$amip_version_name; amip_version_folder=$amip_version_folder; eval echo $AMIP_FOLDER_IN)"
75  echo ">> Chosen SIC files:   $(V=${amip_vname_in[1]}; amip_version_name=$amip_version_name; amip_version_folder=$amip_version_folder; eval echo $AMIP_FOLDER_IN)"
76fi
77if [ "$do_ozon" = "y" ]; then
78  echo ">> Chosen OZONE files: $(V=${ozon_vname_in};    ozon_version_name=$ozon_version_name; ozon_version_folder=$ozon_version_folder; eval echo $OZON_FOLDER_IN)"
79fi
80
81#==================================================================================
82function addc {
83  local s
84  s="$1"; while [ ${#s} -lt $2 ]; do s="_$s"; done ; echo "$s"; unset s
85}
86#==================================================================================
87function progress_bar {
88# $1: iteration  $2: iterations number  $3: length of the bar
89  local n bar
90  bar=`echo "scale=1 ; (100*$1)/$2" | bc`
91  bar="`addc "$bar" 5`% ["
92  n=`echo "scale=0 ; ($3*$1)/$2" | bc`
93  if [ $n -ne 0 ]; then bar="$bar"`eval "printf '='%.0s {1..$n}"`; fi
94  n=$(($3-$n))
95  if [ $n -ne 0 ]; then bar="$bar"`eval "printf '.'%.0s {1..$n}"`']\r'; fi
96  echo -ne $bar; if [ $2 -eq $1 ]; then echo; fi
97  unset n bar
98}
99#==================================================================================
100function extract {
101# Input arguments:
102#    $1: vin,vou       (input/output variable names)
103#    $2: fin,fou       (input/output files names)
104#    $3: Ymin,Ymax,ny  (min/max available years, years/file number)
105#    $4: nmrg          (number of additional months before and after)
106#
107# Purpose:
108#  * Extract year $Y for variable $v_in from files $f_in containing data from
109#    $Ymin to $Ymax, where each input file contains $ny years (=0 for single file)
110#  * Outputs are stored in file $fou, and variable renamed $vou. Special cases:
111#  * Optionally, add before/after the 12 months the $nmrg previous/next months.
112#    - Y=Ymin (missing Ymin-1) => $nmrg last  months of year $Y used instead.
113#    - Y=Ymax (missing Ymax+1) => $nmrg first months of year $Y used instead.
114#
115# Remark:  First record of first file has to be january $Yb.
116#
117  local v_in v_ou d_in f_ou Ymin Ymax Yi Yf Y ny nbm nmrg it fin fou fm ff fp ib ie
118  v_in="${1%%,*}"; v_ou="${1#*,}"; shift
119  f_in="${1%%,*}"; f_ou="${1#*,}"; shift
120  Ymin="${1%%,*}"; Ymax="${1#*,}"; ny="${Ymax#*,}"; Ymax="${Ymax%%,*}"; shift
121  Y=$1; shift; if [ $# -eq 1 ]; then nmrg=$1; else nmrg=0; fi
122  ff=actu_${v_in}_${Y}.nc; fm=""; fp=""
123  #--- INITIAL AND FINAL YEAR OF FILE CONTAINING CURRENT YEAR
124  if [ $ny -eq 0 ]; then
125    Yi=$Ymin; Yf=$Ymax
126  else
127    Yi=$((ny*(Y/ny))); Yf=$((Yi+ny-1)); Yf=$(($Yf>$Ymax?$Ymax:$Yf))
128  fi
129  nbm=$((12*(Yf-Yi+1)-1))                           #--- MONTHS NUMBER OF CURRENT FILE
130  it=$((12*(Y-Yi)))                                 #--- JANUARY INDEX IN CURRENT FILE
131  fin=`V=$v_in; Yi=$Yi; Yf=$Yf; eval echo $f_in`    #--- CURRENT FILE NAME
132  fou=`V=$v_ou; Y=$Y; eval echo $f_ou`              #--- OUTPUT FILE NAME
133  ib=$(($it<=nmrg?0:$((it-nmrg))))                  #--- INDEX OF FIRST USED MONTH
134  ie=$(($((it+11+mrg))>=$nbm?$nbm:$((it+11+nmrg)))) #--- INDEX OF LAST USED MONTH
135  rm -f $ff ; rm -f $ff ; ncks -d time,$ib,$ie $fin $ff
136  #--- MISSING PREVIOUS YEAR LAST  MONTHS => CURRENT YEAR INSTEAD
137  if [ $it           -lt $nmrg ]; then fm="prev_${v_in}_${Y}.nc"; rm -f $fm
138    if [[ $Y -eq $Ymin || $ny -eq 0  ]]; then ncks -d time,$((it-nmrg+12)),11 $fin $fm
139    else Yi=$((ny*((Y-1)/ny))); Yf=$((Yi+ny-1)); Yf=$(($Yf>$Ymax?$Ymax:$Yf))
140      ncks -d time,$((12*(Yf-Yi+1)-nmrg+it)),$((12*(Yf-Yi+1)-1)) `V=$v_in; Yi=$Yi; Yf=$Yf; eval echo $f_in` $fm
141    fi
142  fi
143  #--- MISSING FOLLOWING YEAR FIRST MONTHS => CURRENT YEAR INSTEAD
144  if [ $((it+nmrg+11)) -gt $nbm ]; then fp="next_${v_in}_${Y}.nc"; rm -f $fp
145    if [[ $Y -eq $Ymax || $ny -eq 0  ]]; then ncks -d time,$((nbm-11)),$((it+nmrg-1)) $fin $fp
146    else Yi=$((ny*((Y+1)/ny))); Yf=$((Yi+ny-1)); Yf=$(($Yf>$Ymax?$Ymax:$Yf))
147      ncks -d time,0,$((nmrg-1)) `V=$v_in; Yi=$Yi; Yf=$Yf; eval echo $f_in` $fp
148    fi
149  fi
150  if [ ! -d ${fou%/*} ]; then mkdir -p ${fou%/*}; fi
151  if [[ "$fm" != "" || "$fp" != "" ]]; then
152    rm -f $fou ; ncrcat $fm $ff $fp $fou ; rm -f $fm $ff $fp
153  else
154    mv $ff $fou
155  fi
156  if [ "$v_in" != "$v_ou" ]; then
157    ncrename -v $v_in,$v_ou $fou > /dev/null 2>&1
158  fi
159}
160#==================================================================================
161function make_clim {
162# Input arguments:
163#    $1: variable name   $2: input files name
164#    $3: beg,end years   $4: index for january (optional, starting from 0)
165#
166# Purpose:
167#    Create a 12 months climatology for a variable using 1-year monthly files.
168#
169# Remark:
170#    Files with additional months are usable if the index for january is given (default: 0)
171#
172  local f_ou f0 Yb Ye ib ie M MM
173  Yb="${3%%,*}"; Ye="${3#*,}"
174  if [ $# -eq 4 ]; then ib=$4; else ib=0; fi; ie=$((ib+11))  #=== INDEX $ib FOR JANUARY
175  for M in $(eval echo {$ib..$ie}); do
176    MM=$((M+1-ib)); if [ $MM -le 9 ]; then MM=0$MM; fi
177    for Y in `eval echo {${Yb}..${Ye}}`; do
178      f_ou=$(V=$1; Y=$Y; eval echo $2)
179      rm -f ${1}_$Y$MM.nc ; ncks -d time,$M $(V=$1; Y=$Y; eval echo $f_ou) ${1}_$Y$MM.nc
180    done
181    rm -f ${1}_$MM.nc ; ncra ${1}_????$MM.nc ${1}_$MM.nc ; rm -f ${1}_????$MM.nc
182    progress_bar $((M+1-ib)) $((ie-ib+1)) 50
183  done
184  f_ou=$(V=$1; Y=${Yb}_${Ye}_clim; eval echo $2); f_ou=$(V=$1; Y=${Yb}_${Ye}_clim; eval echo $f_ou)
185  rm -f $f_ou ; ncrcat ${1}_??.nc $f_ou ; rm -f ${1}_??.nc
186  f0=`V=$1; Y='YYYY'; eval echo $2`; f0=$(V=$1; Y='YYYY'; eval echo $f0); f0=${f0##*/}
187  ncatted -a comment,global,a,c,"\nClimatology from $Yb to $Ye using file(s) $f0" $f_ou
188  echo ">> Done for variable $1."
189}
190#==================================================================================
191function str2ascii() {
192  LC_CTYPE=C printf '%d' "'$1"
193}
194
195#==================================================================================
196function deblank {
197#--- REMOVE UNEXPECTED CHARACTERS (IN PARTICULAR THOSE WEIRD ASCII(0) CHARS)
198  local a
199  a=$1; while [ `str2ascii ${a:0:1}` -lt 32 ]; do a=${a:1:${#a}}; done; echo $a
200}
201
202#==================================================================================
203function dim_nam {
204  #--- GET DIMENSION $2 (X/Y/Z/T) NAME FOR FILE $1
205  #--- SPECIAL CASE: RETURN 'Seasons' IF "$2" = "S".
206  local a v Units
207  case $2 in
208    X) Units='degrees_east  degree_east  degree_e degrees_e "degrees east"  "degree east"  degreee degreese' ;;
209    Y) Units='degrees_north degree_north degree_n degrees_n "degrees north" "degree north" degreen degreesn' ;;
210    Z) Units='pa pascal pascals hpa millibar millibars mbar mbars mb bar bars atm atms atmosphere atmospheres' ;;
211    T) Units=' since' ;;
212    S) echo Seasons; return 0 ;;
213    *) echo "error in dim_nam: unrecognized axis $2"; return 1 ;;
214  esac
215  for u in $Units; do
216    case $2 in
217      X|Y|Z) a=`ncdump -h $1 | grep -i ':units = "'"$u"'"'` ;;
218      T)     a=`ncdump -h $1 | grep -i $u | grep ':units = "'` ;;
219    esac
220    if [ "$a" != "" ]; then
221      if [ "$2" = "Z" ]; then v=${a%%:*}; v=`deblank $v`
222        if [ "`ncdump -h $1 | grep -i "$v($v)"`" != "" ]; then break; fi
223      else break
224      fi
225    fi
226  done
227  if [[ "$a" = "" && "$2" = "Z" ]]; then a=`ncdump -h $1 | grep -i ':positive = "'`; fi
228  if [ "$a" = "" ]; then echo "error in dim_nam: unable to recognize axis $2"; return 1; fi
229  echo ${a%%:*}; return 0
230}
231
232#==================================================================================
233function tim_len {
234  local n
235  n=`ncdump -h $1 | grep 'UNLIMITED'`; n=${n#*// (}; n=${n% currently*}; echo $n
236}
237
238#==================================================================================
239function dim_len {
240  local n
241  if [ "$2" = "T" ]; then tim_len $1; else n=`ncdump -h $1 | grep $(dim_nam $1 $2)' = '`; n=${n#* = }; n=${n% ;*}; echo $n; fi
242}
243
244#==================================================================================
245function test_var {
246# Input arguments:
247#    $1: file name  $2: variable name
248  ncdump -h $1 | grep "double $2" > /dev/null; if [ $? -eq 0 ]; then return 0; fi
249  ncdump -h $1 | grep "float  $2" > /dev/null; return $?
250}
251#==================================================================================
252function renam_dims {
253# Input arguments:
254#    $1: file name  $2...: <axis>:<target_name> (axis=X,Y,Z or T)
255#
256# Purpose:
257#    Rename dimensions, dimensional variables and possibly bounds_<variable>.
258#
259  local f=$1 out="" nam_in nam_ou vOK
260  vOK=0; if [ $f = "v" ]; then vOK=1; shift; f=$1; fi
261  shift
262  while [ $# -ge 1 ]; do
263    nam_ou=${1##*:}; nam_in=$(dim_nam $f ${1%:*}); shift
264    if [ "$nam_in" != "$nam_ou" ]; then
265      out="$out -d $nam_in,$nam_ou"
266      if [ $vOK -eq 1 ]; then out="$out -v $nam_in,$nam_ou"; fi
267      nam_in=bounds_$nam_in; nam_ou=bounds_$nam_ou
268      test_var $f $nam_in
269      if [ $? -eq 0 ]; then out="$out -v $nam_in,$nam_ou"; fi
270    fi
271    ((ia++))
272  done
273  echo $out
274}
275#==================================================================================
276
277tmp=tmp.$$.nc
278
279#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
280if [ "$do_amip" = "y" ]; then
281#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
282
283#=== BUILD YEARLY INTERANNUAL SIC/SST FILES WITH 12 RECORDS
284for is in $ia; do                                                       #--- Loop on Amip versions
285  amip_version_name=${AMIP_VERSION_NAMES[$is]}
286  amip_version_folder=${AMIP_VERSION_FOLDERS[$is]}
287  for ivar in $(eval echo {1..${#amip_vname_in[@]}}); do iv=$((ivar-1)) #--- Loop on variables
288
289    #--- VARIABLES NAMES (INPUT, OUTPUT AND FOR FILE NAMING PURPOSE)
290    v_in=${amip_vname_in[$iv]}; v_ou=${amip_vname_ou[$iv]}
291    var='sst'; if [ $ivar -eq  2 ]; then var='sic'; fi
292
293    #--- INPUT FOLDER AND FILE NAMES
294    d_in=$(amip_version_name=$amip_version_name; amip_version_folder=$amip_version_folder; V=$v_in; eval echo $AMIP_FOLDER_IN)
295    f_in=$d_in/$(V=$v_in;       eval echo ${amip_fname_in})
296
297    #--- OUTPUT FILE AND FOLDER NAMES
298    nlon=$(dim_len $f_in X); nlat=$(dim_len $f_in Y)                    #--- Dimensions lengths
299    d_ou=$(amip_version_name=$amip_version_name; amip_version_folder=$amip_version_folder; nlon=$nlon; nlat=$nlat; eval echo $AMIP_FOLDER_OU)
300    if [ ! -d $d_ou ]; then mkdir -p $d_ou; fi
301
302    #--- FILES NAMES (INPUT, OUTPUT)
303    f_ou=$d_ou/$(V=$var; Y=\$Y; nlon=$nlon; nlat=$nlat; eval echo ${amip_fname_ou})
304
305    for per in ${Y_amip}; do
306      Yb=${per%%-*}; Ye=${per##*-}
307      echo ">> BUILDING 12 MONTHS $v_in FILES FOR THE ${per} PERIOD USING $amip_version_name DATASET (${amip_version_folder##*/})..."
308      for Y in $(eval echo {${Yb}..${Ye}); do                             #--- Loop on years
309
310        #--- RECOMPUTE OR NOT
311        if [[ -f $(Y=$Y; eval echo $f_ou) && $recomp = 'n' ]]; then continue; fi
312
313        #--- 2D FIELDS EXTRACTION
314        extract $v_in,$v_ou $AMIP_FOLDER_IN/$amip_fname_in,$f_ou $Yb,$Ye,0 $Y 0
315
316        progress_bar $((Y-Yb+1)) $((Ye-Yb+1)) 50
317     done
318   done
319  done
320done
321
322#=== BUILD SIC/SST 12 RECORDS CLIMATOLOGIES
323for is in $ia; do                                                       #--- Loop on Amip versions
324  amip_version_name=${AMIP_VERSION_NAMES[$is]}
325  amip_version_folder=${AMIP_VERSION_FOLDERS[$is]}
326  for ivar in $(eval echo {1..${#amip_vname_in[@]}}); do iv=$((ivar-1)) #--- Loop on variables
327
328    #--- VARIABLES (OUTPUT, FOR FILE NAMING PURPOSE) AND OUTPUT FILE NAMES
329    v_ou=${amip_vname_ou[$iv]}
330    var='sst'; if [ $ivar -eq 2 ]; then var='sic'; fi
331    d_ou=$(amip_version_name=$amip_version_name; amip_version_folder=$amip_version_folder; eval echo $AMIP_FOLDER_OU)
332    f_ou=$(V=$var; Y=\$Y; eval echo ${amip_fname_ou})
333
334    for per in ${Y_clim} ${Y_pind}; do                                  #--- Loop on periods
335      Yb=${per%%-*}; Ye=${per##*-}
336      echo ">> BUILDING 12 MONTHS $v_ou CLIMATOLOGY ON PERIOD ${per} USING $amip_version_name DATASET (${amip_version_folder##*/})..."
337
338      #--- RECOMPUTE OR NOT
339      if [[ -f $d_ou/$(Y=${Yb}_${Ye}_clim; eval echo $f_ou) && $recomp = 'n' ]]; then continue; fi
340
341      #--- COMPUTE CLIMATOLOGY
342      make_clim $v_ou $d_ou/$f_ou ${Yb},${Ye} 0
343
344    done
345    cd $d_ou; ln -sf $(Y=2002; eval echo $f_ou) $(Y=2002_2002_clim; eval echo $f_ou); cd - 2>&1 > /dev/null
346  done
347done
348#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
349fi
350#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
351
352
353coords="X:longitude Y:latitude Z:plev"
354
355#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
356if [ "$do_ozon" = "y" ]; then
357#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
358
359#=== BUILD YEARLY INTERANNUAL OZONE FILES WITH 12 RECORDS
360Yb=${Y_ozon%%-*}; Ye=${Y_ozon##*-}; dY=${Ye#*:}; Ye=${Ye%:*}
361for is in $io; do                                                 #--- Loop on Ozone versions
362  ozon_version_name=${OZON_VERSION_NAMES[$is]}
363  ozon_version_folder=${OZON_VERSION_FOLDERS[$is]}
364
365  #--- VARIABLES NAMES (INPUT, OUTPUT)
366  v_in=${ozon_vname_in}                                           #--- Input  variable
367  v_ou=${ozon_vname_ou}                                           #--- Output variable
368
369  #--- INPUT/OUTPUT FILE NAME
370  f_in=$(V=$v_in; Yi=\${Yi}; Yf=\${Yf}; ozon_version_name=$ozon_version_name; ozon_version_folder=$ozon_version_folder; eval echo $OZON_FOLDER_IN/${ozon_fname_in[$is]})
371  f_ou=$(V=$v_ou; Y=\$Y; eval echo $ozon_fname_ou)
372
373  #--- INPUT FILE HORIZONTAL RESOLUTION
374  f0=$(Yi=${Yb}; Yf=$((Yb+dY-1)); eval echo $f_in)                #--- First file name
375  nlon=$(dim_len $f0 X); nlat=$(dim_len $f0 Y)                    #--- Dimensions lengths
376
377  #--- OUTPUT FOLDERS NAMES
378  d_ou=$(ozon_version_name=$ozon_version_name; ozon_version_folder=$ozon_version_folder; eval echo $OZON_FOLDER_OU)
379  d_o2=$d_ou/1x${nlat}                                            #--- Output folder (2D)
380  d_o3=$d_ou/${nlon}x${nlat}                                      #--- Output folder (3D)
381  if [ ! -d $d_o2 ]; then mkdir -p $d_o2; fi; f_o2=$d_o2/$f_ou
382  if [ ! -d $d_o3 ]; then mkdir -p $d_o3; fi; f_o3=$d_o3/$f_ou
383  if [ ! -d $d_ou ]; then mkdir -p $d_ou; fi
384
385  for Y in $(eval echo {${Yb}..${Ye}}); do      #--- Loop on years
386 
387    #--- RECOMPUTE OR NOT
388    if [[ -f $(Y=$Y; eval echo $f_o3) && $recomp = 'n' ]]; then continue; fi
389
390    #--- 3D FIELDS EXTRACTION
391    extract $v_in,$v_ou $f_in,$f_o3 $Yb,$Ye,$dY $Y 0
392    #$(((nm-12)/2))
393
394    #--- RENAME DIMENSIONS ACCORDING TO $coords VARIABLE
395    fo3=$(Y=$Y; eval echo $f_o3); fo2=$(Y=$Y; eval echo $f_o2)
396    if [ $Y -eq $Yb ]; then args_ren=$(renam_dims $fo3 $coords); fi
397    if [ "$args_ren" != "" ]; then ncrename $args_ren $fo3 2>&1 > /dev/null ; fi
398
399    #--- ZONAL MEAN
400    ncwa    -a longitude $fo3 $tmp ; mv $tmp $fo2
401    ncks -x -v longitude $fo2 $tmp ; mv $tmp $fo2
402
403    #--- REMOVE USELESS VARIABLE
404    v="bounds_longitude"; test_var $fo2 $v
405    if [ $? -eq 0 ]; then ncks -x -v $v $fo2 $tmp ; mv $tmp $fo2; fi
406
407    progress_bar $((Y-Yb+1)) $((Ye-Yb+1)) $dY
408
409  done
410done
411
412#=== BUILD OZONE 12 RECORDS CLIMATOLOGIES
413for is in $io; do                                                 #--- Loop on Ozone versions
414  ozon_version_name=${OZON_VERSION_NAMES[$is]}
415  ozon_version_folder=${OZON_VERSION_FOLDERS[$is]}
416  v_ou=${ozon_vname_ou}                                           #--- Output variable
417
418  for per in ${Y_clim} ${Y_pind}; do                              #--- Loop on periods
419    Yb=${Y_clim%%-*}; Ye=${Y_clim##*-}
420    for rank in 3 2; do                                           #--- Loop on rank
421      if [ $rank -eq 2 ]; then d_ou=$d_o2; else d_ou=$d_o3; fi
422
423      #--- CLIMATOLOGY ON GIVEN YEARS INTERVAL (Y_clim)
424      f_ou=$(V=$v_ou; Y=${Yb}_${Ye}_clim; eval echo $ozon_fname_ou) #--- Regular climatology name
425      if [[ ! -f $d_ou/$f_ou || $recomp = 'y' ]]; then
426        echo ">> BUILDING 12 MONTHS ${rank}D $v_ou CLIMATOLOGY ON PERIOD ${Y_clim}..."
427        make_clim $v_ou $d_ou/\$ozon_fname_ou ${Yb},${Ye} 0
428      fi
429
430      #--- PRE-INDUSTRIAL CLIMATOLOGY USING SPECIAL FILE
431#set -vx
432      f_in=$(V=$v_in; Yi=1850; Yf=1850; eval echo $OZON_FOLDER_IN/$ozon_fname_in); f_in=${f_in%.nc*}-clim.nc
433      f_ou=$(V=$v_ou; Y=1850_1850_clim; eval echo $ozon_fname_ou)
434      if [[ ! -f $d_ou/$f_ou || $recomp = 'y' ]]; then
435        echo ">> BUILDING 12 MONTHS ${rank}D $v_ou PRE-INDUSTRIAL CLIMATOLOGY..."
436        if [ $rank -eq 3 ]; then f_ou0=$d_ou/$f_ou
437
438          #--- DUPLICATE FILE AND RENAME DIMENSIONS
439          cp $f_in $d_ou/$f_ou ; args_ren=$(renam_dims v $d_ou/$f_ou $coords)
440          ncrename $args_ren -v $ozon_vname_in,$ozon_vname_ou $d_ou/$f_ou 2>&1 > /dev/null
441
442        else
443          #--- ZONAL MEAN
444          ncwa    -a longitude       $f_ou0 $tmp ; mv $tmp $d_ou/$f_ou
445          ncks -x -v longitude $d_ou/$f_ou  $tmp ; mv $tmp $d_ou/$f_ou
446
447          #--- REMOVE USELESS VARIABLE
448          v="bounds_longitude"
449          test_var $d_ou/$f_ou $v
450          if [ $? -eq 0 ]; then ncks -x -v $v $d_ou/$f_ou $tmp ; mv $tmp $d_ou/$f_ou; fi
451        fi
452      fi
453#set +vx
454    done
455  done
456done
457
458#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
459fi
460#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
461
Note: See TracBrowser for help on using the repository browser.