Changeset 3870


Ignore:
Timestamp:
05/31/18 16:42:58 (6 years ago)
Author:
cugnet
Message:

Available datasets list on ciclad extended.
Genral tools contained in tools.bash are now fully independent of the main script clims_CMIP6.

Location:
TOOLS/CMIP6_FORCING/OZONE
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/CMIP6_FORCING/OZONE/clims_CMIP6.bash

    r3847 r3870  
    33 
    44#=== Indices of chosen datasets among available collection (see DATANAMES after) 
    5 DOPROCESS=('y' 'y')          #--- PROCESSED DATA TYPES (SSTandSeaIce, ozone) 
    6 IXPROCESS=("0" "3")        #--- PROCESSED DATASETS INDICES 
     5DOPROCESS=('n' 'y')          #--- PROCESSED DATA TYPES (SSTandSeaIce, ozone) 
     6IXPROCESS=("0" "5 6 7")      #--- PROCESSED DATASETS INDICES 
    77recomp='n'                   #--- RECOMPUTE FILES THAT ARE ALREADY PRESENT (y/n) 
    88 
     
    3131esac 
    3232if [ "$DATAIN" = "" ]; then echo "Raw data folder for $machine has to be specified."; exit; fi 
    33 DATAOU=/data/dcugnet$DATAOU 
     33# DATAOU=/data/dcugnet$DATAOU  # No write acces to $DATAOU => temporary storage space. 
    3434 
    3535#--- DATA TO TREAT (INTERANNUAL AND CLIMATOLOGIES): "SSTsAndSeaIce" "ozone": 
     
    4242           input4MIPs/CMIP6/CMIP/PCMDI/PCMDI-AMIP-1-1-4/ocean/mon/\${var}/gn/v20180427/$f" \ 
    4343          "input4MIPs/CMIP6/CMIP/UReading/UReading-CCMI-1-0/atmos/mon/\${var}/gn/v20160711/$f   \ 
     44           input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-stratO3-1-0/atmos/mon/\${var}/gn/v20170814/$f \ 
    4445           input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-nat-1-0/atmos/mon/\${var}/gn/v20180503/$f     \ 
    4546           input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-sol-1-0/atmos/mon/\${var}/gn/v20180503/$f     \ 
    46            input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-stratO3-1-0/atmos/mon/\${var}/gn/v20170814/$f \ 
    47            input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-volc-1-0/atmos/mon/\${var}/gn/v20180503/$f") 
     47           input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-volc-1-0/atmos/mon/\${var}/gn/v20180503/$f    \ 
     48           input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-sol-1-1/atmos/mon/\${var}/gn/v20180525/$f     \ 
     49           input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-nat-1-1/atmos/mon/\${var}/gn/v20180525/$f     \ 
     50           input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-volc-1-1/atmos/mon/\${var}/gn/v20180525/$f") 
    4851CLIMS_IN=("/ / / / /" \ 
    4952          "input4MIPs/CMIP6/CMIP/UReading/UReading-CCMI-1-0/atmos/monC/\${var}/gn/v20160830/$f  /  /  /  /") 
    5053VARNAM_IN=('tosbcs siconcbcs' 'vmro3') 
    5154DIRSTRUCT='datasets/exercise/project/origin/dataset/domain/frequency/var/grid/version/' 
    52 DATADATES=()                                #--- DETERMINED AUTOMATICALLY LATER 
     55DATADATES=()                                #--- DETERMINED LATER 
    5356 
    5457#--- RESULTS STORAGE 
     
    6063VARNAMFOU=('sst sic'             'tro3')    #--- VARIABLES NAMES FOR FILES NAMES 
    6164CLIMDATES=('1870-1899 1979-2008' '1850-1879 1979-2008') 
    62 coords="X:longitude Y:latitude Z:plev"      #--- COORDINATES FOR ce0l 
     65coords="X:longitude Y:latitude Z:plev"      #--- COORDINATES NAMES KNOWN BY ce0l 
     66 
     67#=== EXCEPTIONS FOR STORAGE TREE ERRORS: variables not deduced from folder name parsing 
     68ex="PCMDI-AMIP-1-1-0:grid=gs1x1"  # <dset>:<var>=<val> if dataset=dset: export var=val 
    6369 
    6470#================================================================================== 
    65 #=== FEW FUNCTIONS 
    66 #   NOTE: These functions are not specific to this script. 
    67 #   EXCEPTION: in get_date (error in ciclad storage tree for PCMDI-AMIP-1-1-0): 
    68 #          if [ $dataset = "PCMDI-AMIP-1-1-0" ]; then grid='gs1x1'; fi 
     71#=== FEW FUNCTIONS (not specific to this script) 
    6972#================================================================================== 
    7073source tools.bash 
    71  
    7274 
    7375#=== DETERMINE TIME INTERVALS AND DISPLAY WHAT DATASET ARE ABOUT TO BE TREATED 
    7476for i in $(eval echo {0..$((${#DATATYPES[@]}-1))}); do 
    7577  fin=${FILES_IN[$i]}; dt=${DATATYPES[$i]}; var=${VARNAM_IN[$i]%% *} 
    76   DATADATES[$i]=$(get_date $var $dt $DATAIN $fin); date=($DATADATES[$i]); fin=($fin) 
    77   if [ ${DOPROCESS[$i]} != 'y' ]; then continue; fi 
     78  DATADATES[$i]=$(get_date $var $dt $DATAIN $DIRSTRUCT $fin $ex) 
     79  date=(${DATADATES[$i]}); fin=($fin); if [ ${DOPROCESS[$i]} != 'y' ]; then continue; fi 
    7880  echo ">> Chosen $dt:" 
    7981  for ka in ${IXPROCESS[$i]}; do echo "  * ${fin[$ka]%/*} (${date[$ka]%-*})"; done 
     
    9395  for is in ${IXPROCESS[$i]}; do                           #=== LOOP ON VERSIONS 
    9496  #================================================================================ 
    95     parse_dir ${fin[$is]} $DIRSTRUCT                       #--- Parse input directory 
    96     gridin=$grid; if [ $dataset = "PCMDI-AMIP-1-1-0" ]; then gridin='gs1x1'; fi 
     97    parse_dir ${fin[$is]} $DIRSTRUCT $ex                   #--- Parse input directory 
    9798    dso=$dataset                                           #--- For naming purpose 
    9899    case $dt in                                            #--- NAMING EXCEPTIONS 
    99       ozone) if [ "$dataset" =    "PCMDI-AMIP-1-0" ]; then dso='AMIP'; fi ;; 
    100       SSTAndSeaIce) dso=${dso#*hist-}; dso=hist-${dso%%-*} 
    101              if [ "$dataset" = "UReading-CCMI-1-0" ]; then dso="historical"; fi ;; 
     100      ozone) dso=${dso#*hist-}; dso=hist-${dso%%-*} 
     101                    if [ "$dataset" = "UReading-CCMI-1-0" ]; then dso="historical"; fi ;; 
     102      SSTAndSeaIce) if [ "$dataset" =  "PCMDI-AMIP-1-1-0" ]; then dso='AMIP'; fi ;; 
    102103    esac 
    103104    #============================================================================== 
     
    106107      da=${date[$is]}; Yb=${da%%-*}; Ye=${da#*-}; dY=${Ye##*-}; Ye=${Ye%-*} 
    107108      v_in=${vin[$iv]}; v_ou=${vou[$iv]}                   #--- Variables names 
    108       f_in=$(var=$v_in; Yb=\${Yb}; Ye=\${Ye}; datatype=$dt; grid=$gridin; eval echo $DATAIN/${fin[$is]}) 
     109      f_in=$(var=$v_in; Yb=\${Yb}; Ye=\${Ye}; datatype=$dt; eval echo $DATAIN/${fin[$is]}) 
    109110      axis=$(get_grid $(Yb=$Yb; Ye=????; eval echo $f_in) $v_in) 
    110111      res=${axis#*=}; axis=${axis%=*} 
    111       doZon='n'; if [ $axis = 'XYZT' ]; then doZon='y'; fi #--- Zonal mean ?  For 3D files 
    112       if [ $doZon = 'y' ]; then                            #--- 2 directories for 3D files 
    113         res3D=${res%x*}; res2D=${res3D#*x}_zonal; f_ou=${f_ou%/*}/\\\${res}/${f_ou##*/} 
     112      Zonal='n'; if [ $axis = 'XYZT' ]; then Zonal='y'; fi #--- Zonal mean ?  For 3D files 
     113      f_ou=$(var=${vfo[$iv]}; Y=\${Y}; dataset=$dso; eval echo $DATAOU/${fou}) 
     114      if [ $Zonal = 'y' ]; then                            #--- 2 directories for 3D files 
     115        res3D=${res%x*}; res2D=${res3D#*x}_zonal; f_ou=${f_ou%/*}/\${res}/${f_ou##*/} 
    114116      fi 
    115       f_ou=$(var=${vfo[$iv]}; Y=\${Y}; dataset=$dso; eval echo $DATAOU/${fou}) 
    116117      echo ">> BUILDING 12 MONTHS ${v_in} FILES FOR THE $Yb-$Ye PERIOD USING $dataset DATASET ($version)..." 
    117118      #============================================================================ 
     
    123124          rename_dims $fO $coords                          #--- Rename dims/atts 
    124125        fi 
    125         if [ $doZon = 'y' ]; then                          #--- Zonal mean 
     126        if [ $Zonal = 'y' ]; then                          #--- Zonal mean 
    126127          fZ=$(Y=$Y; res=${res2D}; eval echo ${f_ou})      #--- Zonal File name 
    127128          if [[ ! -f $fZ || $recomp = 'y' ]]; then zonal_mean $fO $fZ; fi 
     
    136137 
    137138        #=== Is there a single file climatology available ? 
    138         fC0=$(var=$v_in; Yb=$Yb; Ye=$Yb; datatype=$dt; eval echo $DATAIN/${cli0}) 
    139         if [[ ${cli0} != "/" && -f $fC0 ]]; then c='y'; Yc=${Yb}_${Yb}_clim; fi 
     139        fc0=$(var=$v_in; Yb=$Yb; Ye=$Yb; datatype=$dt; eval echo $DATAIN/${cli0}) 
     140        if [[ ${cli0} != "/" && -f $fc0 ]]; then c='y'; Yc=${Yb}_${Yb}_clim; fi 
    140141 
    141         fO=$(Y=$Yc; res=${res3D}; eval echo ${f_ou})       #--- Original resolution 
    142         if [[ ! -f $fO || $recomp = 'y' ]]; then 
     142        fO=$(Y=\$Y; res=${res3D}; eval echo ${f_ou})       #--- Original resolution 
     143        fOc=$(Y=$Yc; res=${res3D}; eval echo ${f_ou})      #--- ", target climatology 
     144        if [[ ! -f $fOc || $recomp = 'y' ]]; then 
    143145          if [ "$c" = "y" ]; then 
    144146            echo ">> BUILDING $v_ou CLIMATOLOGY USING SPECIAL FILE ${fC0##*/} ($version)..." 
    145             cp $fC0 $fO ; rename_dims $fO $coords          #--- Rename dims/atts 
     147            cp $fc0 $fOc ; rename_dims $fOc $coords        #--- Rename dims/atts 
    146148          else 
    147149            echo ">> BUILDING $v_ou CLIMATOLOGY USING YEARLY FILES FOR $per ($version)..." 
    148             make_clim ${v_ou} $f_ou $per 0                 #--- Compute climatology 
     150            make_clim ${v_ou} $fO $per 0                   #--- Compute climatology 
    149151          fi 
    150152        fi 
    151         if [ $doZon = 'y' ]; then 
    152           fZ=$(Y=$Y; res=${res2D}; eval echo ${f_ou})      #--- Zonal File name 
    153           if [[ ! -f $fZ || $recomp = 'y' ]]; then zonal_mean $fO $fZ; fi 
     153        if [ $Zonal = 'y' ]; then 
     154          fZc=$(Y=$Yc; res=${res2D}; eval echo ${f_ou})    #--- Zonal File name 
     155          if [[ ! -f $fZc || $recomp = 'y' ]]; then zonal_mean $fOc $fZc; fi 
    154156        fi 
    155157      done 
  • TOOLS/CMIP6_FORCING/OZONE/tools.bash

    r3847 r3870  
    11function parse_dir { 
    2 # Syntax: export variables from directory $1 with structure var1/var2/.../varN ($2) 
    3 # Each variable ${vari} is exported. 
    4   local d=$1 s=$2 
     2# Syntax:   parse_dir <dir> <dir_struct> [<patch1 ... patchN>] 
     3#       $1:     directory to parse 
     4#       $2:     directory structure 
     5#      [$3...]: <dset>:<var>=<val> patches 
     6# Purpose: parse directory <dir> with structure <dir_struct> and export all variables. 
     7# If $dataset = $dset, the value of <var> obtain with parsing is replaced with <val>. 
     8  local d s 
     9  d=$1; shift; s=$1; shift 
    510  while :; do 
    6     export ${s%%/*}=${d%%/*} 
     11    $(eval echo "export ${s%%/*}=${d%%/*}") 
    712    s=${s#*/}; d=${d#*/} 
    813    if [ "$s" = "${s#*/}" ]; then break; fi 
    914  done 
     15  while [ $# -ge 1 ]; do if [ $dataset = ${1%:*} ]; then eval export ${1#*:}; fi; shift; done 
     16  unset d s 
     17} 
     18#================================================================================== 
     19function replace_1 { 
     20  # $1: string  $2: <patch>=<replacement string> 
     21  local out=$1 
     22  while [ "${out%${2%=*}*}" != "$out" ]; do out=${out%${2%=*}*}"${2#*=}"${out##*${2#=*}*}; done 
     23  echo $out; unset out; return 0 
     24} 
     25#================================================================================== 
     26function replace { 
     27  # same as "replace_1", but with several <patch>=<replacement string> arguments. 
     28  local out=$1; shift 
     29  while [ $# -ne 0 ]; do out=$(replace_1 $out "$1"); shift; done 
     30  echo $out; unset out; return 0 
    1031} 
    1132#================================================================================== 
    1233function addc { 
    13   local s 
    14   s="$1"; while [ ${#s} -lt $2 ]; do s="_$s"; done ; echo "$s"; unset s 
     34  local s="$1"; while [ ${#s} -lt $2 ]; do s="_$s"; done ; echo "$s"; unset s 
    1535} 
    1636#================================================================================== 
     
    114134  done 
    115135  f_ou=$(var=$1; Y=${Yb}_${Ye}_clim; eval echo $2) 
     136  if [ ! -p ${f_ou%/*} ]; then mkdir -p ${f_ou%/*}; fi 
    116137  rm -f $f_ou ; ncrcat ${1}_??.nc $f_ou ; rm -f ${1}_??.nc 
    117138  f0=`var=$1; Y='YYYY'; eval echo $2`; f0=$(var=$1; Y='YYYY'; eval echo $f0); f0=${f0##*/} 
    118139  ncatted -a comment,global,a,c,"\nClimatology from $Yb to $Ye using file(s) $f0" $f_ou 
    119   echo ">> Done for variable $1." 
    120140} 
    121141#================================================================================== 
     
    218238#    $1: input file  $2: output file 
    219239  local tmp=tmp.$$.nc 
     240  if [ ! -d ${2%/*} ]; then mkdir -p ${2%/*}; fi 
    220241  ncwa       -a longitude $1 $tmp ; mv $tmp $2    #--- Zonal mean 
    221242  ncks -O -x -v longitude $2 $tmp ; mv $tmp $2    #--- Remove longitude 
     
    225246#================================================================================== 
    226247function get_date { 
    227 # $1: varname  $2: datatype  $3: dirin  $4:...: files_in 
    228248# Assumes the following filename structure: *_${Yb}*-${Ye}*.* (Yb/e: 4 digits) 
    229   local v_in dtyp d_in f_in ixf Yb Ye St a f first dates 
    230   v_in=$1; shift; dtyp=$1; shift; d_in=$1; shift 
    231   for f_in in $@; do parse_dir ${f_in} $DIRSTRUCT; Yb=1000000; Ye=0; first='t' 
    232     #=== /!\ ERROR IN THE STORAGE TREE ON CICLAD FOR PCMDI-AMIP-1-1-0 
    233     if [ $dataset = "PCMDI-AMIP-1-1-0" ]; then grid='gs1x1'; fi 
    234     for f in $(var=$v_in; Yb=????; Ye=????; datatype=$dtyp; eval echo $d_in/$f_in); do 
    235       a=${f##*_}; if [ ${a::4} -le $Yb ]; then Yb=${a::4}; fi 
    236       a=${a##*-}; if [ ${a::4} -ge $Ye ]; then Ye=${a::4}; fi 
    237       if [ $first = 't' ]; then St=$((Ye-Yb+1)); first='f'; fi 
    238     done 
    239     if [ $f_in = $1 ]; then dates="$Yb-$Ye-$St"; else dates="$dates $Yb-$Ye-$St"; fi 
     249# $1: varname 
     250# $2: datatype 
     251# $3: dirin 
     252# $4: dirin structure patch 
     253# $5...$N: files_in 
     254# [$N+1...]: <dset>:<var>=<val> to overwrite value of variables evaluated from parsing. 
     255  local v_in dtyp d_in dstr f_in Yb Ye St a f first date dates files_in="" 
     256  v_in=$1; shift; dtyp=$1; shift; d_in=$1; shift; dstr=$1; shift; f0=$1 
     257  while [ "$1" = "${1##*=}" ]; do files_in="$files_in $1"; shift; done 
     258  for f_in in $files_in; do date=$(get_date_1 $v_in $dtyp $d_in $dstr $f_in $*) 
     259    if [ $f_in = $f0 ]; then dates=$date; else dates="$dates $date"; fi 
    240260  done 
    241261  echo $dates 
     262} 
     263#================================================================================== 
     264function get_date_1 { 
     265# Assumes the following filename structure: *_${Yb}*-${Ye}*.* (Yb/e: 4 digits) 
     266# $1: varname 
     267# $2: datatype 
     268# $3: base directory for files 
     269# $4: dirin structure patch 
     270# $5: file_in 
     271# [$6...]: <dset>:<var>=<val> to overwrite value of variables evaluated from parsing. 
     272  local v_in dtyp d_in d_str f_in Yb Ye St a f first 
     273  v_in=$1; shift; dtyp=$1; shift; d_in=$1; shift; dstr=$1; shift; f_in=$1; shift 
     274  parse_dir $f_in $dstr $*; Yb=1000000; Ye=0; first='t' 
     275  for f in $(var=$v_in; Yb=????; Ye=????; datatype=$dtyp; eval ls $d_in/$f_in); do 
     276    a=${f##*_}; if [ ${a::4} -le $Yb ]; then Yb=${a::4}; fi 
     277    a=${a##*-}; if [ ${a::4} -ge $Ye ]; then Ye=${a::4}; fi 
     278    if [ $first = 't' ]; then St=$((Ye-Yb+1)); first='f'; fi 
     279  done 
     280  echo $Yb-$Ye-$St 
    242281} 
    243282#================================================================================== 
Note: See TracChangeset for help on using the changeset viewer.