Commit 84584a52 authored by Isabel Andreu-Burillo's avatar Isabel Andreu-Burillo
Browse files

iandreu's working ocean-diagnostics code

parent 9ca4c5f8
......@@ -94,8 +94,10 @@ ncks -O -v votemper $1 t3d_${3}
# $7 : nemo/ecearth #
# $8 : diags/MMO #
# $9 : storage frequency (daily/monthly) #
# $10 : list of files extracted from the original tarballs
# #
# Created in May 2012 Author : vguemas@ic3.cat #
# Modified: June 2013 isabel.andreu-burillo@ic3.cat
###############################################################################
function get_diagsMMO {
......@@ -106,49 +108,49 @@ typeset var year1
typeset var year2
typeset var mon1
typeset var mon2
typeset var listroots
case $8 in
'diags' ) if [[ $6 -lt 12 || $5 -gt 12 ]] ; then listroots="t3d heat_sal_mxl ice moc psi sal_0-300m sal_300-5400m sstsssmld" ; fi ;;
'MMO' ) listroots=${10} ;;
esac
case $9 in
'daily') freqkeep='1d'; freqexcl1='1m' ; freqexcl2='MM' ;;
'monthly' ) freqkeep='1m'; freqexcl1='1d' ; freqexcl2='DD' ;;
*) freqkeep='1m'; freqexcl1='1d' ; freqexcl2='DD' ;;
esac
for jt in $(seq $4 $6 $5) ; do
year1=$(($yyyy0+(10#$mm0+$jt-2)/12))
mon1=$(((10#$mm0+$jt-2)%12+1))
year2=$(($yyyy0+(10#$mm0+$jt+$6-3)/12))
mon2=$(((10#$mm0+$jt+$6-3)%12+1))
cp /cfunas/exp/$7/$2/$1/fc$3/outputs/$8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar .
tar -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar
for filetype in ${10}; do
tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar "*${freqkeep}*${filetype}*"
done
rm -f $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar
if [[ `ls *.gz` != '' ]] ; then gunzip *.gz ; fi
done
typeset var listroots
case $8 in
'diags' ) if [[ $6 -lt 12 || $5 -gt 12 ]] ; then listroots="t3d heat_sal_mxl ice moc psi sal_0-300m sal_300-5400m sstsssmld sstsimld" ; fi ;;
'MMO' ) listroots="grid_T grid_U grid_V grid_W icemod" ;;
esac
case $9 in
'daily') freqexcl1='1m' ; freqexcl2='MM' ;;
'monthly' ) freqexcl1='1d' ; freqexcl2='DD' ;;
*) freqexcl1='1d' ; freqexcl2='DD' ;;
esac
typeset var root
typeset var lstfiles
for root in ${listroots[@]} ; do
if [[ `ls *${root}*` != '' ]] ; then
lstfiles=`ls *${root}* | grep -v "${root}_$2_$1_fc*_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" `
file1=`echo "${lstfiles}" | tail -1`
typeset var lstvars=`cdo showvar $file1`
if [[ ${lstvars/iicenflx} != ${lstvars} ]] ; then for file in $lstfiles ; do ncks -O -x -v iicenflx $file $file ; done ; fi
cdo mergetime $lstfiles ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc
if [[ $root == 'moc' ]] ; then
lstdims=`ncdump -h ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'`
if [[ ${lstdims/gsize} != ${lstdims} ]] ; then
ncrename -d gsize,y ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc
fi
ncks -A -v nav_lon,nav_lat `echo $lstfiles | awk '{print $1}' ` ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc
if [[ ${lstdims/x} != ${lstdims} ]] ; then
ncwa -O -a x ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc
fi
fi
rm -f $lstfiles *${freqexcl1}* *${freqexcl2}*
lstfiles=`ls *${root}* | grep -v "${root}_$2_$1_fc*_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" `
if [[ $root == 'grid_T' || $root == 't3d' ]] ; then
for file in $lstfiles ; do
ncatted -O -a valid_max,votemper,d,, $file $file
ncatted -O -a valid_min,votemper,d,, $file $file
done
fi
file1=`echo "${lstfiles}" | tail -1`
typeset var lstvars=`cdo showvar $file1`
if [[ ${lstvars/iicenflx} != ${lstvars} ]] ; then for file in $lstfiles ; do ncks -O -x -v iicenflx $file $file ; done ; fi
cdo mergetime $lstfiles ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc
if [[ $root == 'moc' ]] ; then
ncrename -d gsize,y ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc
ncks -A -v nav_lon,nav_lat `echo $lstfiles | awk '{print $1}' ` ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc
fi
if [[ $root == 'sstsimld' ]] ; then mv ${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc sstsssmld_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc ; fi
rm -f $lstfiles *${freqexcl1}* *${freqexcl2}*
done
}
###############################################################################
......@@ -160,8 +162,10 @@ done
# $4 : end year #
# $5 : start month #
# $6 : end month #
# $7 : list of files extracted from the original tarballs #
# #
# Created in May 2012 Author : vguemas@ic3.cat #
# Modified: June 2013 isabel.andreu-burillo@ic3.cat #
###############################################################################
function get_nemovar {
......@@ -201,7 +205,7 @@ for year in $(seq $3 $4) ; do
done
gunzip *.gz
typeset var listroots="grid_T grid_U grid_V grid_W"
typeset var listroots=${7}
typeset var root
typeset var lstfiles
typeset var ntimes
......@@ -250,8 +254,10 @@ ncks -A -v nav_lon,nav_lat mesh_hgr.nc grid_T_glorys2v1_19930101_fc0_${1}$(print
# $4 : starting leadtime #
# $5 : end leadtime #
# $6 : diags/MMO #
# $7 : list of files extracted from the original tarballs
# #
# Created in May 2012 Author : vguemas@ic3.cat #
# Modified: June 2013 isabel.andreu-burillo@ic3.cat #
###############################################################################
function clean_diagsMMO {
......@@ -265,7 +271,7 @@ typeset var mon2=$(((10#$mm0+$5-2)%12+1))
typeset var listroots
case $6 in
'diags' ) listroots="t3d" ;;
'MMO' ) listroots="grid_T grid_U grid_V grid_W icemod" ;;
'MMO' ) listroots=${7} ;;
esac
typeset var root
typeset var lstfiles
......@@ -362,18 +368,17 @@ for jt in $(seq 1 $ntime); do
ncks -O -v votemper intohc_slayer.nc intmeantem.nc
ncrename -v votemper,heatc_sl intmeantem.nc #to be commented
cdo mul intmeantem.nc e3t_file.nc heatc_sl_out.nc
#? ncks -A -m -v nav_lon,nav_lat $1 heatc_sl_out.nc
# extract the data between the two given depths --> heatc_sl_top.nc
## extract the data between the two given depths --> heatc_sl_top.nc
ncks -d deptht,$2,$3 heatc_sl_out.nc heatc_sl_top.nc
#perform the integration of ohc down to that level (main contribution)
## perform the integration of ohc down to that level (main contribution)
ncap2 -O -s 'heatc_sl=heatc_sl.total($deptht)' heatc_sl_top.nc heatc_sl_top.nc
# now extract a few levels below, to compute the residual ohc
## now extract a few levels below, to compute the residual ohc
lower_bnd=`echo "$3 + 200.0" | bc`
ncks -d deptht,$3,$lower_bnd heatc_sl_out.nc heatc_sl_bottom.nc
# obtain the weight for the extra level containing the 300 m
# deptht in the gridT files is positive
# weight = (300.0 - depth_top)/(depth_bottom - depth_top)
# and add the thickness down to 300 m in the next layer
## obtain the weight for the extra level containing the 300 m
## deptht in the gridT files is positive
## weight = (300.0 - depth_top)/(depth_bottom - depth_top)
## and add the thickness down to 300 m in the next layer
ncpdq -a '-deptht' heatc_sl_top.nc heatc_sl_top_invert.nc
ncks -d deptht,0,0,1 heatc_sl_top_invert.nc level_above.nc
ncks -d deptht,0,0,1 heatc_sl_bottom.nc level_below.nc
......@@ -561,12 +566,8 @@ cp ${CON_FILES}/ice_template.nc toto_N.nc
cp ${CON_FILES}/ice_template.nc toto_S.nc
case ${NEMOVERSION} in
'Ec3.0_O1L46'|'Ec3.0_O25L46') for var in `cdo showvar $1 | head -1`
do
[[ $var = "ice_pres" || $var = "iiceconc" ]] && ncrename -v $var,ileadfra $1
done;;
#'Ec3.0_O1L46'|'Ec3.0_O25L46') ncrename -v ice_pres,ileadfra $1 ;;
#'Ec3.0_O1L46'|'Ec3.0_O25L46') ncrename -v iiceconc,ileadfra $1 ;;
#'Ec3.0_O1L46'|'Ec3.0_O25L46') ncrename -v ice_pres,ileadfra $1 ;;
'Ec3.0_O1L46'|'Ec3.0_O25L46') ncrename -v iiceconc,ileadfra $1 ;;
esac
typeset var ntime=`cdo ntime $1`
......@@ -825,7 +826,12 @@ EOF
ncpdq -O -h -a time,deptht tmpout.nc tmp2out.nc
ncks -A -v deptht $1 tmp2out.nc
cdo setgrid,t106grid tmp2out.nc tmp3out.nc
cdo invertlatdata tmp3out.nc $3
orca_res=`echo $NEMOVERSION | cut -c 7-9`
if ((${orca_res} \= "O25")); then
cdo invertlatdata tmp3out.nc $3
else
cp tmp3out.nc $3
fi
rm -f tmp_* tmpout.nc tmp2out.nc tmp3out.nc rmp_${NEMOVERSION}_to_regular_lev* scrip_use scrip_use_in
}
......
#!/bin/bash
set -evx
if [[ -z `grep "/cfu/software/cdftools2.1" ~/.bashrc` && -z `grep "/cfu/software/cdftools2.1" ~/.profile` ]]; then
echo "Your path does not contain the right version of the cdf tools, please add PATH="/cfu/software/cdftools2.1:$PATH" to your .bashrc"
exit
fi
#################################
#### User Defined Funtions ####
#################################
......@@ -26,6 +21,16 @@ fi
config_file=$1
. ${config_file}
list_files='grid_T'
if [[ ${listpost[@]} =~ "psi" ]] || [[ ${listpost[@]} =~ "moc" ]] ; then
echo "The list of diags require grid_V[U]"
list_files=$(echo ${list_files} grid_U grid_V)
fi
if [[ ${listpost[@]} =~ "ice" ]]; then
echo "The list of diags contains ice"
list_files=$(echo ${list_files} icemod)
fi
###############################################################################
#
......@@ -79,24 +84,16 @@ if [[ ${listpost[@]##max_moc} != ${listpost[@]} ]] || [[ -z "$ltimef" ]] || [[ -
if [[ ! -z "$year0" ]] && [[ ! -z "$yearf" ]] ; then
ltime0=$(((${year0}-${syeari})*12+1))
ltimef=$(((${yearf}-${syeari}+1-(10#$moni+10)/12)*12))
else
ltime0=$((((ltime0-1)/12)*12+1))
ltimef=$((((ltimef+11)/12)*12))
fi
fi
mon0=$(( (10#$moni+$ltime0-2)%12+1 ))
monf=$(( (10#$moni+$ltimef-2)%12+1 ))
#
# Check on the consistency between the chunk length and the leadtimes
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [[ $((($ltimef-$ltime0+1)%$chunklen)) != 0 || $((($ltime0-1)%$chunklen)) != 0 ]] ; then
echo "This a safety stop because we think you might have made a mistake in your configuration file"
echo "Unless you have run your experiment with a variable chunk length, you should have"
echo "a number of leadtimes to post-process that is a multiple of the chunken and the first"
echo "leadtime should be right after the end of a chunk"
echo "If you have run your experiment with a variable chunk length, please remove l.85-93 of ocean_pp.bash"
exit 1
fi
#
# Loop on start dates
# ~~~~~~~~~~~~~~~~~~~~~
# Loop on start dates
# ~~~~~~~~~~~~~~~~~~~~
for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do
#
# Interval of years to be post-processed
......@@ -109,11 +106,11 @@ for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do
# Fetching the files on cfunas
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
case $expid in
'nemovar_s4'|'nemovar_combine') get_nemovar ${expid} ${memb} ${year0} ${yearf} ${mon0} ${monf}
'nemovar_s4'|'nemovar_combine') get_nemovar ${expid} ${memb} ${year0} ${yearf} ${mon0} ${monf} "${list_files}"
;;
'glorys2v1') get_glorys ${year0} ${yearf} ${mon0} ${monf} ;;
*) freqout=${rootout:${#rootout}-12} ; freqout=${freqout/_mean} ; freqout=${freqout/*\/}
get_diagsMMO ${yeari}${moni}01 ${expid} ${memb} $ltime0 $ltimef $chunklen $mod $typeoutput $freqout
get_diagsMMO ${yeari}${moni}01 ${expid} ${memb} $ltime0 $ltimef $chunklen $mod $typeoutput $freqout "${list_files}"
esac
#
# Ready for the post-processing
......@@ -377,7 +374,7 @@ for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do
# Removing the raw output from this start dates and this member
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clean_diagsMMO ${yeari}${moni}01 ${expid} ${memb} $ltime0 $ltimef $typeoutput
clean_diagsMMO ${yeari}${moni}01 ${expid} ${memb} $ltime0 $ltimef $typeoutput "${list_files}"
done
# Prepare storage : choose output directory and file name
......@@ -468,8 +465,8 @@ for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do
if [ -e ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ] ; then
cp ${pathout}/${prefix}${lsmbsb}_${lsyrsh} .
lsmbsh=0-${listmemb[${#listmemb[@]}-1]}
gather_memb ${prefix} _${lsyrsh} ${prefix}${lsmbsh}_${lsyrsh}
fi
gather_memb ${prefix} _${lsyrsh} ${prefix}${lsmbsh}_${lsyrsh}
for jmemb in ${listmemb[@]} ; do
rm -f ${prefix}${jmemb}_${lsyrsh}
done
......@@ -508,6 +505,7 @@ for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do
echo "${prefix}${lsmbso}_${lsyrso} already exists in ${pathout}"
sleep 5
else
ls -l ${pathout}/${prefix}${lsmbso}_${lsyrso}
echo " problem writing file in ${pathout} directory"
exit
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment