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

Last change on this file since 3595 was 3595, checked in by tlurton, 4 years ago

20/02/2018 Th. Lurton
Updated paths to final location of input files on Ciclad: /prodigfs/project/input4MIPs/.

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