Ignore:
Timestamp:
11/06/18 17:14:39 (6 years ago)
Author:
cugnet
Message:

Available datasets list on ciclad extended.
Scripts slightly modified to accomodate more ways of cutting a time serie into several time slices.

File:
1 edited

Legend:

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

    r3870 r4109  
    7676    Yb=$Ymin; Ye=$Ymax 
    7777  else 
    78     Yb=$((dY*(Y/dY))); Ye=$((Yb+dY-1)); Ye=$(($Ye>$Ymax?$Ymax:$Ye)) 
     78    Yb=$((Ymin+dY*((Y-Ymin)/dY))); Ye=$((Yb+dY-1)) 
     79    Ye=$(($Ye>$Ymax?$Ymax:$Ye)) 
    7980  fi 
    8081  nbm=$((12*(Ye-Yb+1)-1))                           #--- MONTHS NUMBER OF CURRENT FILE 
    8182  it=$((12*(Y-Yb)))                                 #--- JANUARY INDEX IN CURRENT FILE 
    8283  fin=`var=$v_in; Yb=$Yb; Ye=$Ye; eval echo $f_in`  #--- CURRENT FILE NAME 
    83   fou=`var=$v_ou; Y=$Y; eval echo $f_ou`            #--- OUTPUT FILE NAME 
     84  fou=`var=$v_ou; Y=$Y; eval echo $f_ou`            #--- OUTPUT  FILE NAME 
    8485  ib=$(($it<=nmrg?0:$((it-nmrg))))                  #--- INDEX OF FIRST USED MONTH 
    8586  ie=$(($((it+11+mrg))>=$nbm?$nbm:$((it+11+nmrg)))) #--- INDEX OF LAST USED MONTHF 
     
    246247#================================================================================== 
    247248function get_date { 
    248 # Assumes the following filename structure: *_${Yb}*-${Ye}*.* (Yb/e: 4 digits) 
    249 # $1: varname 
    250 # $2: datatype 
    251 # $3: dirin 
    252 # $4: dirin structure patch 
    253 # $5...$N: files_in 
     249# Call get_date1 one time each input file. 
     250# $1: varname    $2: datatype    $3: dirin    $4: <dir_in> patch    $5...$N: <files_in> 
    254251# [$N+1...]: <dset>:<var>=<val> to overwrite value of variables evaluated from parsing. 
    255252  local v_in dtyp d_in dstr f_in Yb Ye St a f first date dates files_in="" 
     
    264261function get_date_1 { 
    265262# 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 
     263# Returns ${FirstYear}-${LastYear}-${IntervalsLengths} 
     264# $1: varname    $2: datatype    $3: dirin    $4: <dir_in> patch    $5: <file_in> 
    271265# [$6...]: <dset>:<var>=<val> to overwrite value of variables evaluated from parsing. 
    272266  local v_in dtyp d_in d_str f_in Yb Ye St a f first 
     
    274268  parse_dir $f_in $dstr $*; Yb=1000000; Ye=0; first='t' 
    275269  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 
     270    a=${f##*_}; ymn=${a::4}; if [ $ymn -le $Yb ]; then Yb=$ymn; fi 
     271    a=${a##*-}; ymx=${a::4}; if [ $ymx -ge $Ye ]; then Ye=$ymx; fi 
     272    if [ $first != 't' ]; then St=${St}-; fi; first='f'; St=${St}$((ymx-ymn+1)) 
    279273  done 
    280274  echo $Yb-$Ye-$St 
     
    311305} 
    312306#================================================================================== 
     307function is_int { 
     308 # $1: string to be checked 
     309  set +vx 
     310  if [[ $1 =~ ^[0-9]+$ ]]; then return 0; else return 1; fi 
     311  set -vx 
     312} 
     313#================================================================================== 
     314function remove_version { 
     315 # $1: variable name 
     316  local out=$1 
     317  while `is_int ${out##*-}`; do out=${out%-*}; done; echo $out; return 1 
     318} 
    313319 
Note: See TracChangeset for help on using the changeset viewer.