Changeset 3870
- Timestamp:
- 05/31/18 16:42:58 (5 years ago)
- Location:
- TOOLS/CMIP6_FORCING/OZONE
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/CMIP6_FORCING/OZONE/clims_CMIP6.bash
r3847 r3870 3 3 4 4 #=== 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 INDICES5 DOPROCESS=('n' 'y') #--- PROCESSED DATA TYPES (SSTandSeaIce, ozone) 6 IXPROCESS=("0" "5 6 7") #--- PROCESSED DATASETS INDICES 7 7 recomp='n' #--- RECOMPUTE FILES THAT ARE ALREADY PRESENT (y/n) 8 8 … … 31 31 esac 32 32 if [ "$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. 34 34 35 35 #--- DATA TO TREAT (INTERANNUAL AND CLIMATOLOGIES): "SSTsAndSeaIce" "ozone": … … 42 42 input4MIPs/CMIP6/CMIP/PCMDI/PCMDI-AMIP-1-1-4/ocean/mon/\${var}/gn/v20180427/$f" \ 43 43 "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 \ 44 45 input4MIPs/CMIP6/DAMIP/CCCma/CCMI-hist-nat-1-0/atmos/mon/\${var}/gn/v20180503/$f \ 45 46 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") 48 51 CLIMS_IN=("/ / / / /" \ 49 52 "input4MIPs/CMIP6/CMIP/UReading/UReading-CCMI-1-0/atmos/monC/\${var}/gn/v20160830/$f / / / /") 50 53 VARNAM_IN=('tosbcs siconcbcs' 'vmro3') 51 54 DIRSTRUCT='datasets/exercise/project/origin/dataset/domain/frequency/var/grid/version/' 52 DATADATES=() #--- DETERMINED AUTOMATICALLYLATER55 DATADATES=() #--- DETERMINED LATER 53 56 54 57 #--- RESULTS STORAGE … … 60 63 VARNAMFOU=('sst sic' 'tro3') #--- VARIABLES NAMES FOR FILES NAMES 61 64 CLIMDATES=('1870-1899 1979-2008' '1850-1879 1979-2008') 62 coords="X:longitude Y:latitude Z:plev" #--- COORDINATES FOR ce0l 65 coords="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 68 ex="PCMDI-AMIP-1-1-0:grid=gs1x1" # <dset>:<var>=<val> if dataset=dset: export var=val 63 69 64 70 #================================================================================== 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) 69 72 #================================================================================== 70 73 source tools.bash 71 72 74 73 75 #=== DETERMINE TIME INTERVALS AND DISPLAY WHAT DATASET ARE ABOUT TO BE TREATED 74 76 for i in $(eval echo {0..$((${#DATATYPES[@]}-1))}); do 75 77 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; fi78 DATADATES[$i]=$(get_date $var $dt $DATAIN $DIRSTRUCT $fin $ex) 79 date=(${DATADATES[$i]}); fin=($fin); if [ ${DOPROCESS[$i]} != 'y' ]; then continue; fi 78 80 echo ">> Chosen $dt:" 79 81 for ka in ${IXPROCESS[$i]}; do echo " * ${fin[$ka]%/*} (${date[$ka]%-*})"; done … … 93 95 for is in ${IXPROCESS[$i]}; do #=== LOOP ON VERSIONS 94 96 #================================================================================ 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 97 98 dso=$dataset #--- For naming purpose 98 99 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 ;; 102 103 esac 103 104 #============================================================================== … … 106 107 da=${date[$is]}; Yb=${da%%-*}; Ye=${da#*-}; dY=${Ye##*-}; Ye=${Ye%-*} 107 108 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]}) 109 110 axis=$(get_grid $(Yb=$Yb; Ye=????; eval echo $f_in) $v_in) 110 111 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##*/} 114 116 fi 115 f_ou=$(var=${vfo[$iv]}; Y=\${Y}; dataset=$dso; eval echo $DATAOU/${fou})116 117 echo ">> BUILDING 12 MONTHS ${v_in} FILES FOR THE $Yb-$Ye PERIOD USING $dataset DATASET ($version)..." 117 118 #============================================================================ … … 123 124 rename_dims $fO $coords #--- Rename dims/atts 124 125 fi 125 if [ $ doZon= 'y' ]; then #--- Zonal mean126 if [ $Zonal = 'y' ]; then #--- Zonal mean 126 127 fZ=$(Y=$Y; res=${res2D}; eval echo ${f_ou}) #--- Zonal File name 127 128 if [[ ! -f $fZ || $recomp = 'y' ]]; then zonal_mean $fO $fZ; fi … … 136 137 137 138 #=== Is there a single file climatology available ? 138 f C0=$(var=$v_in; Yb=$Yb; Ye=$Yb; datatype=$dt; eval echo $DATAIN/${cli0})139 if [[ ${cli0} != "/" && -f $f C0 ]]; then c='y'; Yc=${Yb}_${Yb}_clim; fi139 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 140 141 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 143 145 if [ "$c" = "y" ]; then 144 146 echo ">> BUILDING $v_ou CLIMATOLOGY USING SPECIAL FILE ${fC0##*/} ($version)..." 145 cp $f C0 $fO ; rename_dims $fO $coords#--- Rename dims/atts147 cp $fc0 $fOc ; rename_dims $fOc $coords #--- Rename dims/atts 146 148 else 147 149 echo ">> BUILDING $v_ou CLIMATOLOGY USING YEARLY FILES FOR $per ($version)..." 148 make_clim ${v_ou} $f _ou $per 0#--- Compute climatology150 make_clim ${v_ou} $fO $per 0 #--- Compute climatology 149 151 fi 150 152 fi 151 if [ $ doZon= 'y' ]; then152 fZ =$(Y=$Y; res=${res2D}; eval echo ${f_ou})#--- Zonal File name153 if [[ ! -f $fZ || $recomp = 'y' ]]; then zonal_mean $fO $fZ; fi153 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 154 156 fi 155 157 done -
TOOLS/CMIP6_FORCING/OZONE/tools.bash
r3847 r3870 1 1 function 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 5 10 while :; do 6 export ${s%%/*}=${d%%/*}11 $(eval echo "export ${s%%/*}=${d%%/*}") 7 12 s=${s#*/}; d=${d#*/} 8 13 if [ "$s" = "${s#*/}" ]; then break; fi 9 14 done 15 while [ $# -ge 1 ]; do if [ $dataset = ${1%:*} ]; then eval export ${1#*:}; fi; shift; done 16 unset d s 17 } 18 #================================================================================== 19 function 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 #================================================================================== 26 function 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 10 31 } 11 32 #================================================================================== 12 33 function 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 15 35 } 16 36 #================================================================================== … … 114 134 done 115 135 f_ou=$(var=$1; Y=${Yb}_${Ye}_clim; eval echo $2) 136 if [ ! -p ${f_ou%/*} ]; then mkdir -p ${f_ou%/*}; fi 116 137 rm -f $f_ou ; ncrcat ${1}_??.nc $f_ou ; rm -f ${1}_??.nc 117 138 f0=`var=$1; Y='YYYY'; eval echo $2`; f0=$(var=$1; Y='YYYY'; eval echo $f0); f0=${f0##*/} 118 139 ncatted -a comment,global,a,c,"\nClimatology from $Yb to $Ye using file(s) $f0" $f_ou 119 echo ">> Done for variable $1."120 140 } 121 141 #================================================================================== … … 218 238 # $1: input file $2: output file 219 239 local tmp=tmp.$$.nc 240 if [ ! -d ${2%/*} ]; then mkdir -p ${2%/*}; fi 220 241 ncwa -a longitude $1 $tmp ; mv $tmp $2 #--- Zonal mean 221 242 ncks -O -x -v longitude $2 $tmp ; mv $tmp $2 #--- Remove longitude … … 225 246 #================================================================================== 226 247 function get_date { 227 # $1: varname $2: datatype $3: dirin $4:...: files_in228 248 # 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}; fi236 a=${a##*-}; if [ ${a::4} -ge $Ye ]; then Ye=${a::4}; fi237 if [ $first = 't' ]; then St=$((Ye-Yb+1)); first='f'; fi238 done239 if [ $f_in = $ 1 ]; then dates="$Yb-$Ye-$St"; else dates="$dates $Yb-$Ye-$St"; fi249 # $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 240 260 done 241 261 echo $dates 262 } 263 #================================================================================== 264 function 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 242 281 } 243 282 #==================================================================================
Note: See TracChangeset
for help on using the changeset viewer.