From 563379cd23b522f6b8392e98a72f15821e489296 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Wed, 2 Mar 2016 12:30:37 +0100 Subject: [PATCH 1/9] Changed the way of copying mask.regions, if it exists it doesn't copy anything. I noticed when introducing other changes --- common_ocean_post.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common_ocean_post.txt b/common_ocean_post.txt index 3336048..0f468dc 100644 --- a/common_ocean_post.txt +++ b/common_ocean_post.txt @@ -64,7 +64,9 @@ cp -f ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_zgr.nc cp -f ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mask.nc cp -f ${CON_FILES}/new_maskglo.${NEMOVERSION}.nc new_maskglo.nc -cp -f ${CON_FILES}/mask.regions.${NEMOVERSION}.nc mask_regions.nc +if [ -e ${CON_FILES}/mask.regions.${NEMOVERSION}.nc ] ; then +cp ${CON_FILES}/mask.regions.${NEMOVERSION}.nc mask_regions.nc +fi if [[ ! -f mask.nc ]] ; then echo "No configuration files for cdftools" -- GitLab From ac634a57ca959f9d71dbc462f65c84d526b0ce71 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Tue, 15 Mar 2016 09:19:15 +0100 Subject: [PATCH 2/9] I don't know what it's this exactly --- save/README | 101 +++ save/common_ocean_post.txt | 1339 ++++++++++++++++++++++++++++++ save/common_ocean_post.txt.oriol | 1339 ++++++++++++++++++++++++++++++ save/config_file-ocean_pp.bash | 44 + save/ocean_pp.bash | 647 +++++++++++++++ save/ocean_pp.bash.oriol | 647 +++++++++++++++ save/setup_development.bash | 39 + save/testing_ocean_pp_moore.job | 26 + 8 files changed, 4182 insertions(+) create mode 100644 save/README create mode 100644 save/common_ocean_post.txt create mode 100644 save/common_ocean_post.txt.oriol create mode 100644 save/config_file-ocean_pp.bash create mode 100755 save/ocean_pp.bash create mode 100755 save/ocean_pp.bash.oriol create mode 100755 save/setup_development.bash create mode 100755 save/testing_ocean_pp_moore.job diff --git a/save/README b/save/README new file mode 100644 index 0000000..805fa9b --- /dev/null +++ b/save/README @@ -0,0 +1,101 @@ +To use the ocean diagnostic tools available here and to be able to create new diagnostics, +you need first to add the following line to your .bashrc: +PATH=/cfu/software/cdftools2.1/:$PATH + +#Launching instructions: + +./ocean_pp.bash $path_to_your_file/config_file-ocean_pp.bash +- You can copy and modify the config_file to any directory if you indicate the good path when launching ocean_pp.bash +- ocean_pp.bash, README and example of config_file-ocean_pp.bash can be downloaded from git repository: git clone https://dev.cfu.local/cfutools.git + +# + +####################### DIAGNOSTICS LIST ####################################### +'siasiesiv' : sea ice area + sea ice extent + sea ice volume +'moc' : Atlantic + Pacific + Indian + Indo-Pacific + Global + meridional overturning streamfunction +'max_moc' : Yearly maximum of the Atlantic meridional overturning + streamfunction between 38N-50N and 500-3000m and + at 40N. + Beware that the max_moc diagnostics can not be computed + if you don't process complete years, as it is a diagnostic + computed from complete years. +'area_moc' : Averaged Atlantic meridional overturning streamfunction + between 40N-55N and 1km-2km and between 30N-40N and 1km-2km +'convection' : indices of convective activity in the Labrador, extended Irminger, + GIN and Wedell seas computed as the maximum in mixed layer depth + based on the potential density criteria +'stc' : Subtropical cell strength, computed as the averaged Atlantic + and Pacific overturning streamfunction in 0-25N/S, 0-200m +'ext_raw_ice' : raw ice varibales to be extracted from input files + (called "ice" before february 2013 update)) +'ext_raw_oce' : raw ocean varibales to be extracted from input files + (called "sstsssmld" before february 2013 update)) +'heat_sal_mxl' : mixed layer heat and salt content (potential density criteria) +'psi' : barotropic streamfunction +'gyres' : indices of the barotropic gyres computed as the maximum absolute + barotropic streamfunction in the North Atlantic and North Pacific + subpolar and subtropical gyres and in the South Atlantic, South + Pacific and Indian subtropical gyres and indice of the Antarctic + Circumpolar Current strength +'usalc' : upper layer salt content 0-300m +'temp_lev' : temperature, vertical mean between dif levels (2D) +'sal_lev' : salinity, vertical mean between dif levels (2D) +'lmsalc' : middle + lower layer salt content 300m-bottom +'ohc' : global total ocean heat content +'ohc_specified_layer' : Pointwise ocean heat content in a specified ocean thickness (at present 0-300 m) +'uohc' : global upper (0-350m) ocean heat content +'mohc' : global middle (350-800m) ocean heat content +'lohc' : global lower (800m-bottom) ocean heat content +'xohc' : global mixed layer ocean heat content +'TSec_ave190-220E' : meridional temperature section averaged between 190E and 220E +'SSec_ave190-220E' : meridional salinity section averaged between 190E and 220E (added in february 2013 update) +'vert_Tsections' : zonal temperature sections along 45S, 0N, 45N, and + meridional temperature sections along 30W, 80E, 180E +'vert_Ssections' : zonal salinity sections along 45S, 0N, 45N, and + meridional salinity sections along 30W, 80E, 180E (added in february 2013 update) +'3dtemp' : 3-dimensional temperature interpolated horizontally onto the + atmospheric grid +'3dsal' : 3-dimensional salinity interpolated horizontally onto the + atmospheric grid (added in february 2013 update) +'NAtlohc' : North Atlantic (10-65N) total ocean heat content +'xNAtlohc' : North Atlantic (10-65N) mixed layer ocean heat content +'uNAtlohc' : North Atlantic (10-65N) upper (0-350m) ocean heat content +'mNAtlohc' : North Atlantic (10-65N) middle (350-800m) ocean heat content +'lNAtlohc' : North Atlantic (10-65N) lower (800m-bottom) ocean heat content +'NPacohc' : North Pacific (10-70N) ocean heat content +'xNPacohc' : North Pacific (10-70N) mixed layer ocean heat content +'uNPacohc' : North Pacific (10-70N) upper (0-350m) ocean heat content +'mNPacohc' : North Pacific (10-70N) middle (350-800m) ocean heat content +'lNPacohc' : North Pacific (10-70N) lower (800m-bottom) ocean heat content +'TAtlohc' : Tropical Atlantic (30S-30N) ocean heat content +'xTAtlohc' : Tropical Atlantic (30S-30N) mixed layer ocean heat content +'uTAtlohc' : Tropical Atlantic (30S-30N) upper (0-350m) ocean heat content +'mTAtlohc' : Tropical Atlantic (30S-30N) middle (350-800m) ocean heat + content +'lTAtlohc' : Tropical Atlantic (30S-30N) lower (800m-bottom) ocean heat + content +'TPacohc' : Tropical Pacific (30S-30N) ocean heat content +'xTPacohc' : Tropical Pacific (30S-30N) mixed layer ocean heat content +'uTPacohc' : Tropical Pacific (30S-30N) upper (0-350m) ocean heat content +'mTPacohc' : Tropical Pacific (30S-30N) middle (350-800m) ocean heat content +'lTPacohc' : Tropical Pacific (30S-30N) lower (800m-bottom) ocean heat + content +'TIndohc' : Tropical Indian (30S-30N) ocean heat content +'xTIndohc' : Tropical Indian (30S-30N) mixed layer ocean heat content +'uTIndohc' : Tropical Indian (30S-30N) upper (0-350m) ocean heat content +'mTIndohc' : Tropical Indian (30S-30N) middle (350-800m) ocean heat content +'lTIndohc' : Tropical Indian (30S-30N) lower (800m-bottom) ocean heat + content +'Antaohc' : Antarctic (90-60S) ocean heat content +'xAntaohc' : Antarctic (90-60S) mixed layer ocean heat content +'uAntaohc' : Antarctic (90-60S) upper (0-350m) ocean heat content +'mAntaohc' : Antarctic (90-60S) middle (350-800m) ocean heat content +'lAntaohc' : Antarctic (90-60S) lower (800m-bottom) ocean heat content +'Arctohc' : Arctic (65-90N) ocean heat content +'xArctohc' : Arctic (65-90N) mixed layer ocean heat content +'uArctohc' : Arctic (65-90N) upper (0-350m) ocean heat content +'mArctohc' : Arctic (65-90N) middle (350-800m) ocean heat content +'lArctohc' : Arctic (65-90N) lower (800m-bottom) ocean heat content +'temp_lev' : vertical mean of ocean temp (weighted) between level1 and level2 (in numbers, not in meters), specified in the config file +'sal_lev' : vertical mean of ocean sal (weighted) between level1 and level2 (in numbers, not in meters), specified in the config file diff --git a/save/common_ocean_post.txt b/save/common_ocean_post.txt new file mode 100644 index 0000000..4239b91 --- /dev/null +++ b/save/common_ocean_post.txt @@ -0,0 +1,1339 @@ +############################################################################### +# This file gathers a set of bash functions that rely on cdftools to # +# # +# reduce_mmo # +# get_diagsMMO # +# get_nemovar # +# get_glorys # +# clean_diagsMMO # +# vertmeansal # +# heat_sal_mxl # +# ohc_specified_layer # +# moc # +# convection # +# psi # +# gyres # +# area_moc # +# max_moc # +# siasiesiv # +# ohc # +# cutsection # +# interp3d # +# setminmax # +# concat # +# gather_memb # +# vertmeanvar # +# # +# Those functions would never have seen the day without Hui Du, # +# usually referred to as Super-Hui. # +# # +# He made a crucial work to develop what ended up below in the functions # +# that computes the sea ice extent, sea ice area, ocean heat content and # +# meridional overturning streamfunction. # +# Especially, he developped new options from the cdftools sources to be # +# able to compute the heat content in different basins. # +# # +#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# You want to make available a new diagnostic ? @ +# @ +# 1) Get an MMO tar files from any experiment on esnas @ +# 2) Write a bash function that works on a grid_T or grid_U or grid_V or @ +# grid_W file or a combination from this MMO file @ +# --> You can test your function by defining the CON_FILES and NEMOVERSION @ +# variables and by sourcing the current file, the meshmasks will be @ +# available after sourcing, remember to source again after any @ +# modification of your function @ +# --> Your function should work on input files of any resolution @ +# ORCA1/ORCA025/ORCA2 @ +# --> Your function should work on input files of any time length @ +# --> The output file should contain a proper time axis that you can copy @ +# from your input file @ +# --> The output file should be at most a 3d field including the time @ +# dimension @ +# 3) Write a short description of your function, and add its name to the @ +# list above @ +# 4) Go the the ocean_pp.sh script to add a call to your function @ +# @ +# Any doubt ---> vguemas@ic3.cat @ +#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# Link constant file for co # +############################################################################### + +ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_hgr.nc +ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_zgr.nc +ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mask.nc +ln -sf ${CON_FILES}/new_maskglo.${NEMOVERSION}.nc new_maskglo.nc + +if [ -e ${CON_FILES}/mask.regions.${NEMOVERSION}.nc ] ; then +cp ${CON_FILES}/mask.regions.${NEMOVERSION}.nc mask_regions.nc +fi + +if [[ ! -f mask.nc ]] ; then + echo "No configuration files for cdftools" + exit +fi + +############################################################################### +# Reduced number of variables in diag files to save disk space # +# # +# $1 : input grid_T file name # +# $2 : input icemod file name # +# $3 : suffix of output files with nc extension # +# # +# Created in February 2012 Author : vguemas@ic3.cat # +# May 2014 : Compatibility with PA changes to oce output - Virginie # +############################################################################### + +function reduce_mmo { +ncks -O -v sosstsst,sosaline,somixhgt,somxl010,sossheig $1 oce_${3} +typeset var lstvars=`cdo showvar $2` +if [[ ${lstvars/ileadfra} != ${lstvars} ]] ; then + ncks -O -v isnowthi,iicethic,ileadfra,iicetemp $2 ice_${3} +else + ncks -O -v isnowthi,iicethic,iiceconc,iicetemp $2 ice_${3} +fi +ncks -O -v votemper $1 t3d_${3} +} +############################################################################### +# Copy diags or MMO files from esnas # +# # +# $1 : starting date # +# $2 : expid # +# $3 : member # +# $4 : starting leadtime # +# $5 : end leadtime # +# $6 : chunk length in month # +# $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 # +# Option 10: June 2013 isabel.andreu-burillo@ic3.cat +############################################################################### + +function get_diagsMMO { +typeset var yyyy0=`echo $1|cut -c1-4` +typeset var mm0=`echo $1|cut -c5-6` +if [ -z "${10}" ] ; then + typeset var lstypes="grid_T grid_U grid_V grid_W icemod" +else + typeset var lstypes=${10} +fi + +typeset var jt +typeset var year1 +typeset var year2 +typeset var mon1 +typeset var mon2 +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 /esnas/exp/$7/$2/$1/fc$3/outputs/$8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar . + if [[ "$8" == "MMO" ]]; then + for filetype in $lstypes; do + tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar "*${freqkeep}*${filetype}*" + done + else + tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar + fi + rm -f $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar + if [[ `ls *.gz` != '' ]] ; then gunzip -f *.gz ; fi + ipcs -a +done + +typeset var listroots +case $8 in + 'diags' ) + listroots="t3d heat_sal_mxl ice moc psi sal_0-300m sal_300-5400m" + if [[ `ls sstsimld*` != '' ]] ; then + listroots=$listroots" sstsimld" + elif [[ `ls sstsssmld*` != '' ]] ; then + listroots=$listroots" sstsssmld" + else + listroots=$listroots" oce" + fi + ;; + 'MMO' ) listroots=$lstypes ;; +esac +case $9 in + 'daily') freqexcl1='1m' ; freqexcl2='MM' ;; + 'monthly' ) freqexcl1='1d' ; freqexcl2='DD' ;; + *) freqexcl1='1d' ; freqexcl2='DD' ;; +esac + +function concat_startdate { + typeset var root + typeset var lstfiles + for root in ${listroots[@]} ; do + ipcs -a + if [[ "$8" == "MMO" ]] ; then + lstfiles=`ls *${root}* | grep -v "${root}_$2_$1_fc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" | grep -v "km" ` + else + lstfiles=`ls ${root}* | grep -v "${root}_$2_$1_fc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" | grep -v "km" ` + fi + if [[ ! -z ${lstfiles} ]] ; then + + file1=`echo "${lstfiles}" | tail -1` + cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` + rm ff + #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN + if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then + 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 + if [[ $root == 'heat_sal_mxl' ]] ; then + for file in $lstfiles ; do + ncatted -O -a valid_max,somxlheatc,d,, $file $file + ncatted -O -a valid_min,somxlheatc,d,, $file $file + done + fi + fi + + outfile=${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc + 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 ${outfile} + timevar=`ncdump -h ${outfile} | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time ${outfile} ; fi + if [[ $root == 'moc' ]] ; then + lstdims=`ncdump -h ${outfile} | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` + if [[ ${lstdims/gsize} != ${lstdims} ]] ; then + ncrename -d gsize,y ${outfile} + fi + lenx=`ncdump -h ${outfile} | grep 'x =' | head -1 | awk '{print $3}'` + if [[ $lenx > 1 ]] ; then + if [[ ${lstvars/nav_lon} != ${lstvars} ]] ; then + ncks -O -x -v nav_lon,nav_lat ${outfile} ${outfile} + fi + ncrename -d x,y ${outfile} + fi + ncks -A -v nav_lon,nav_lat `echo $lstfiles | awk '{print $1}' ` ${outfile} + fi + rm -f $lstfiles + if [[ $root == 'sstsimld' || $root == 'sstsssmld' ]] ; then mv ${outfile} oce_$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 + done +} + +concat_startdate $1 $2 $3 $4 $5 $6 $7 $8 + +# These lines aim at concatenating the daily means as well and computing the monthly means from these daily means +if [[ $9 == 'monthly' ]] ; then + freqexcl1='1m' ; freqexcl2='MM' + for root in ${listroots[@]} ; do + outfile=${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 [[ -e $outfile ]] ; then + mv $outfile ${root}_1m.nc + fi + done + concat_startdate $1 $2 $3 $4 $5 $6 $7 $8 + for root in ${listroots[@]} ; do + ipcs m + outfile=${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 [[ -e $outfile ]] ; then + cdo monmean $outfile ${root}_daily2monthly.nc + rm -f $outfile + if [[ -e ${root}_1m.nc ]] ; then + mv ${root}_1m.nc $outfile + ncks -A ${root}_daily2monthly.nc $outfile + rm -f ${root}_daily2monthly.nc + else + mv ${root}_daily2monthly.nc $outfile + fi + else + if [[ -e ${root}_1m.nc ]] ; then + mv ${root}_1m.nc $outfile + fi + fi + done +fi + +rm -f *${freqexcl1}* *${freqexcl2}* + +} +############################################################################### +# Copy NEMOVAR files from esnas # +# # +# $1 : expid # +# $2 : member # +# $3 : start year # +# $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 { + +if [ -z "$5" ] ; then + typeset var moni=9 +else + typeset var moni=$5 +fi + +if [ -z "$5" ] ; then + typeset var monf=8 +else + typeset var monf=$6 +fi + +typeset var path +typeset var yearf +case $1 in + 'nemovar_s4') path=/esnas/exp/ECMWF/NEMOVAR_S4/outputs/fc$2/s4 ;; + 'nemovar_combine') path=/esnas/exp/ECMWF/NEMOVAR_COMBINE/outputs/opa0/fa9p_1m ;; +esac +typeset var year +typeset var mon +for year in $(seq $3 $4) ; do + case $year in + $3) mona=${moni} ;; + *) mona=1 ;; + esac + case $year in + $4) monb=${monf} ;; + *) monb=12 ;; + esac + for mon in $(seq $mona $monb); do + cp ${path}_fc$2_${year}$(printf "%02d" $mon)*.gz . + done +done +gunzip -f *.gz + +typeset var listroots=${7} +typeset var root +typeset var lstfiles +typeset var ntimes +typeset var jt +for root in ${listroots[@]} ; do + lstfiles=`ls *fc${2}*${root}* | grep -v "${root}_$1_195709_fc$2_${3}09_${4}$(printf "%02d" $monb).nc"` + ncrcat -O -x -v vorbiasp $lstfiles tmp_${root}.nc + cdo settaxis,${3}-$(printf "%02d" $moni)-15,12:00,1mon tmp_${root}.nc ${root}_$1_19570901_fc$2_${3}$(printf "%02d" $moni)_${4}$(printf "%02d" $monf).nc + rm -f $lstfiles tmp_${root}.nc +done +} +############################################################################### +# Copy GLORYS files from esnas # +# # +# $1 : start year # +# $2 : end year # +# $3 : start month # +# $4 : end month # +# # +# Created in June 2013 Author : vguemas@ic3.cat # +############################################################################### + +function get_glorys { +typeset var path=/esnas/exp/MERCATOR/GLORYS2V1/outputs/ORCA1L46 #ORCA025L75_glorys +typeset var lstfiles="" +for year in $(seq $1 $2) ; do + cp ${path}/vosaline_${year}.nc . + cp ${path}/votemper_${year}.nc . + ncks -A vosaline_${year}.nc votemper_${year}.nc + rm -f vosaline_${year}.nc + lstfiles=${lstfiles}" "votemper_${year}.nc +done +cdo cat ${lstfiles} tmp.nc +cdo settaxis,${1}-01-15,12:00,1mon tmp.nc tmp2.nc +cdo seldate,${1}-$(printf "%02d" $3)-00,${2}-$(printf "%02d" $4)-31 tmp2.nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc +rm -f ${lstfiles} tmp.nc tmp2.nc +ncks -O -x -v nav_lon,nav_lat,x_2,y_2 grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc +ncks -A -v nav_lon,nav_lat mesh_hgr.nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc +} +############################################################################### +# Clean diags or MMO files after postprocessing # +# # +# $1 : starting date # +# $2 : expid # +# $3 : member # +# $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 { +typeset var yyyy0=`echo $1|cut -c1-4` +typeset var mm0=`echo $1|cut -c5-6` +typeset var year1=$(($yyyy0+(10#$mm0+$4-2)/12)) +typeset var year2=$(($yyyy0+(10#$mm0+$5-2)/12)) +typeset var mon1=$(((10#$mm0+$4-2)%12+1)) +typeset var mon2=$(((10#$mm0+$5-2)%12+1)) + +typeset var listroots + case $6 in + 'diags' ) listroots="t3d" ;; + 'MMO' ) + if [ -z "${7}" ] ; then + listroots="grid_T grid_U grid_V grid_W icemod" + else + listroots=${7} + fi + ;; + esac +typeset var root +typeset var lstfiles +for root in ${listroots[@]} ; do + rm -f ${root}_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)_${year2}$(printf "%02d" $mon2).nc +done +} +############################################################################### +# Vertically averaged salt content # +# # +# $1 : input grid_T file name # +# $2 : upper depth of the layer (in meters) # +# $3 : lower depth of the layer (in meters) # +# $4 : output file name (=> 2D) # +# # +# Created in February 2012 Author : vguemas@ic3.cat # +############################################################################### + +function vertmeansal { +cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` +rm ff +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +for jt in $(seq 1 $ntime); do + ncks -d time,$((jt-1)) $1 intvertmeansal.nc + cdfvertmean intvertmeansal.nc vosaline T $2 $3 + ncrename -O -v sovertmean,vertmeansal -d time_counter,time -v time_counter,time vertmean.nc + mv vertmean.nc outputvertmeansal_$jt.nc + list=$list" "outputvertmeansal_$jt.nc + rm -f intvertmeansal.nc + #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN + if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then + ncatted -O -a valid_max,vertmeansal,d,, outputvertmeansal_$jt.nc outputvertmeansal_$jt.nc + ncatted -O -a valid_min,vertmeansal,d,, outputvertmeansal_$jt.nc outputvertmeansal_$jt.nc + fi +done +cdo cat $list $4 +ncks -A -v time $1 $4 +rm -f $list +setminmax $4 vertmeansal +} +############################################################################### +# Compute mixed layer heat and salt content # +# # +# $1 : input grid_T file name # +# $2 : output file name (=> 2D x-y ) # +# # +# Created in February 2012 Author : vguemas@ic3.cat # +################################################################################ + +function heat_sal_mxl { +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +typeset var lstvars=`cdo showvar $1` +for jt in $(seq 1 $ntime); do + ncks -d time,$((jt-1)) $1 intheat_sal_mxl.nc + if [[ ${lstvars/somxl010} == ${lstvars} ]] ; then + cdfmxl intheat_sal_mxl.nc mxl.nc + ncrename -d time_counter,time mxl.nc + ncks -A mxl.nc intheat_sal_mxl.nc + rm -f mxl.nc + fi + cdfmxlheatc intheat_sal_mxl.nc + if [[ $lstvars != ${lstvars/vosaline} ]] ; then + cdfmxlsaltc intheat_sal_mxl.nc + ncks -A mxlsaltc.nc mxlheatc.nc + rm -f mxlsaltc.nc + fi + mv mxlheatc.nc outputintheat_sal_mxl_$jt.nc + timevar=`ncdump -h outputintheat_sal_mxl_$jt.nc | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time outputintheat_sal_mxl_$jt.nc ; fi + list=$list" "outputintheat_sal_mxl_$jt.nc + rm -f intheat_sal_mxl.nc +done +cdo cat $list $2 +ncks -A -v time $1 $2 +rm -f $list +setminmax $2 somxlheatc +if [[ $lstvars != ${lstvars/vosaline} ]] ; then setminmax $2 somxlsaltc ; fi +} +############################################################################### +# Pointwise Ocean Heat Content in a specified ocean thickness # +# (J/m-2) +# # +# $1 : input grid_T file name # +# $2 : upper depth of the layer (in meters) # +# $3 : lower depth of the layer (in meters) # +# $4 : output file name (=> 2D x-y ) # +# # +# Created in June 2012 Author : isabel.andreu-burillo@ic3.cat # +# May 2014 - Virginie Guemas - Way around the bc that does not work on moore # +############################################################################### + +function ohc_specified_layer { +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +ncap2 -v -O -s "heatc_sl=tmask*e3t" mesh_zgr.nc e3t_file.nc +ncrename -d t,time -d z,deptht e3t_file.nc +for jt in $(seq 1 $ntime); do + cdo seltimestep,$jt $1 intohc_slayer.nc + 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 + ncks -d deptht,$2,$3 heatc_sl_out.nc heatc_sl_top.nc + #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 + # lower_bnd=`echo "$3 + 200.0" | bc` -> does not work on new moore + # strip out the .* from $3: + stripped=`echo ${3/.*}` + # addition with float returned: + lower_bnd=`echo $(printf "%f" $(( $stripped + 200)))` + 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 + 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 + ## Here, add the residual contribution, before adding it to the main contribution + ncrename -v deptht,layerthcknss level_below.nc + ncrename -v deptht,layerthcknss level_above.nc + ncbo -A --op_typ=sub -v layerthcknss level_below.nc level_above.nc depth_diff_lay.nc + ncrename -v layerthcknss,heatc_sl depth_diff_lay.nc + ncap2 -s "heatc_sl=($3 - layerthcknss)" level_above.nc depth_diff_sublay.nc + ncbo --op_typ=/ -v heatc_sl depth_diff_sublay.nc depth_diff_lay.nc factor.nc + ncrename -v heatc_sl,factor factor.nc #to be commented + ncks -A -v factor factor.nc level_below.nc + rm -f depth_diff_sublay.nc depth_diff_lay.nc + ncap2 -O -s "heatc_sl=(factor * heatc_sl)" level_below.nc level_below.nc + ncwa -O -a deptht level_below.nc level_below.nc + ncbo --op_typ=+ -v heatc_sl heatc_sl_top.nc level_below.nc total_heatc_sl.nc + ncap2 -s "heatc_sl=1020.0*4000*heatc_sl" total_heatc_sl.nc heatc_sl_$jt.nc + list=$list" "heatc_sl_$jt.nc + rm -f depth_diff_lay.nc depth_diff_sublay.nc + rm -f heatc_sl_out.nc heatc_sl_top.nc heatc_sl_top_invert.nc heatc_sl_bottom.nc + rm -f level_above.nc level_below.nc + rm -f intohc_slayer.nc intmeantem.nc vertmean.nc total_heatc_sl.nc + rm -f factor.nc +done +cdo cat $list $4 +ncks -A -v time $1 $4 +rm -f $list +rm -f e3t_file.nc +setminmax $4 heatc_sl +} +############################################################################### +# Compute the MOC for oceanic basins # +# # +# $1 : input grid_V file name # +# $2 : output file name (=> 2D, depth-y) # +# # +# Created in March 2012 Author : vguemas@ic3.cat # +############################################################################### + +function moc { +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +for jt in $(seq 1 $ntime); do + cdo seltimestep,$jt $1 intmoc.nc + cdfmoc intmoc.nc + ncwa -O -a x moc.nc outmoc_$jt.nc + ncks -O -x -v nav_lon,nav_lat outmoc_$jt.nc outmoc_$jt.nc + timevar=`ncdump -h outmoc_$jt.nc | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time outmoc_$jt.nc ; fi + list=$list" "outmoc_$jt.nc + rm -f intmoc.nc moc.nc +done +cdo cat $list $2 +lstdims=`ncdump -h $2 | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` +if [[ ${lstdims/gsize} != ${lstdims} ]] ; then + ncrename -d gsize,y $2 +fi +ncks -A -v nav_lon,nav_lat $1 $2 +ncks -A -v time $1 $2 +rm -f $list +} +############################################################################### +# # +# Compute the intensity of convection in the four main convection sites # +# # +# $1 : input oce file name containing somxl010 # +# $2 : input grid # +# $3 : output file name (=> index) # +# # +# Created in October 2013 Author : vguemas@ic3.cat # +############################################################################### + +function convection { +case $2 in + 'Ec2.3_O1L42'|'Ec3.0_O1L46'|'N3.2_O1L42'|'N3.3_O1L46'|'nemovar_O1L42') + A1=225;A2=245;A3=215;A4=255; + B1=245;B2=290;B3=215;B4=245; + C1=260;C2=310;C3=245;C4=291; + D1=225;D2=280;D3=1;D4=50;; + + 'Ec3.0_O25L46'|'Ec3.0_O25L75'|'glorys2v1_O25L75') + stop"Option convection not available yet for this configuration" + ;; +esac + +cdo fldmax -selindexbox,${A1},${A2},${A3},${A4} $1 Labrador.nc +ncrename -v somxl010,Labrador Labrador.nc +ncks -v Labrador Labrador.nc convection.nc +rm -f Labrador.nc + +cdo fldmax -selindexbox,${B1},${B2},${B3},${B4} $1 Irminger.nc +ncrename -v somxl010,Irminger Irminger.nc +ncks -A -v Irminger Irminger.nc convection.nc +rm -f Irminger.nc + +cdo fldmax -selindexbox,${C1},${C2},${C3},${C4} $1 GIN.nc +ncrename -v somxl010,GIN GIN.nc +ncks -A -v GIN GIN.nc convection.nc +rm -f GIN.nc + +cdo fldmax -selindexbox,${D1},${D2},${D3},${D4} $1 Wedell.nc +ncrename -v somxl010,Wedell Wedell.nc +ncks -A -v Wedell Wedell.nc convection.nc +rm -f Wedell.nc + +mv convection.nc $3 +} +############################################################################### +# # +# Compute the barotropic stream function # +# # +# $1 : input grid_U file name # +# $2 : input grid_V file name # +# $3 : output file name without nc extension (=> 2D x-y) # +# # +# Created in March 2012 Author : vguemas@ic3.cat # +############################################################################### + +function psi { +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +for jt in $(seq 1 $ntime); do + cdo seltimestep,$jt $1 intU.nc + cdo seltimestep,$jt $2 intV.nc + cdfpsi intU.nc intV.nc + mv psi.nc psi_U.nc + cdfpsi intU.nc intV.nc V + mv psi.nc psi_V.nc + ncea psi_U.nc psi_V.nc psi_${jt}.nc + timevar=`ncdump -h psi_$jt.nc | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time psi_$jt.nc ; fi + list=$list" "psi_$jt.nc + rm -f intU.nc intV.nc psi_U.nc psi_V.nc +done +cdo cat $list ${3} +ncks -A -v time $1 ${3} +rm -f $list +} +############################################################################### +# # +# Compute the intensity of the subtropical and subpolar gyres # +# # +# $1 : input psi file name # +# $2 : input grid # +# $3 : output file name ( => index ) # +# # +# Created in October 2013 Author : vguemas@ic3.cat # +############################################################################### + +function gyres { +case $2 in + 'Ec2.3_O1L42'|'Ec3.0_O1L46'|'N3.2_O1L42'|'N3.3_O1L46'|'nemovar_O1L42') + A1=230;A2=275;A3=215;A4=245; + B1=70;B2=145;B3=195;B4=235; + C1=45;C2=175;C3=165;C4=220; + D1=195;D2=275;D3=175;D4=225; + E1=70;E2=205;E3=120;E4=145; + F1=235;F2=300;F3=120;F4=145; + G1=320;G2=30;G3=110;G4=180; + H1=1;H2=361;H3=1;H4=65;; + + 'Ec3.0_O25L46'|'Ec3.0_O25L75'|'glorys2v1_O25L75') + stop"Option gyres not available yet for this configuration" + ;; +esac + +cdo fldmin -selindexbox,${A1},${A2},${A3},${A4} $1 subpolar_NAtl.nc +ncrename -v sobarstf,subpolNAtl subpolar_NAtl.nc +cdo mulc,-1 subpolar_NAtl.nc gyres.nc +rm -f subpolar_NAtl.nc + +cdo fldmin -selindexbox,${B1},${B2},${B3},${B4} $1 subpolar_NPac.nc +ncrename -v sobarstf,subpolNPac subpolar_NPac.nc +cdo mulc,-1 subpolar_NPac.nc tmp.nc +ncks -A tmp.nc gyres.nc +rm -f subpolar_NPac.nc tmp.nc + +cdo fldmax -selindexbox,${C1},${C2},${C3},${C4} $1 subtrop_NPac.nc +ncrename -v sobarstf,subtropNPac subtrop_NPac.nc +ncks -A subtrop_NPac.nc gyres.nc +rm -f subtrop_NPac.nc + +cdo fldmax -selindexbox,${E1},${E2},${E3},${E4} $1 subtrop_SPac.nc +ncrename -v sobarstf,subtropSPac subtrop_SPac.nc +ncks -A subtrop_SPac.nc gyres.nc +rm -f subtrop_SPac.nc + +cdo fldmax -selindexbox,${D1},${D2},${D3},${D4} $1 subtrop_NAtl.nc +ncrename -v sobarstf,subtropNAtl subtrop_NAtl.nc +ncks -A subtrop_NAtl.nc gyres.nc +rm -f subtrop_NAtl.nc + +cdo fldmax -selindexbox,${F1},${F2},${F3},${F4} $1 subtrop_SAtl.nc +ncrename -v sobarstf,subtropSAtl subtrop_SAtl.nc +ncks -A subtrop_SAtl.nc gyres.nc +rm -f subtrop_SAtl.nc + +cdo fldmax -selindexbox,${G1},${G2},${G3},${G4} $1 subtrop_Ind.nc +ncrename -v sobarstf,subtropInd subtrop_Ind.nc +ncks -A subtrop_Ind.nc gyres.nc +rm -f subtrop_Ind.nc + +cdo fldmax -selindexbox,${H1},${H2},${H3},${H4} $1 ACC.nc +ncrename -v sobarstf,ACC ACC.nc +ncks -A ACC.nc gyres.nc +rm -f ACC.nc + +mv gyres.nc $3 + +} +############################################################################### +# # +# Compute an Atlantic MOC index by averaging the meridional overturning # +# in a latitude band between 1km and 2km # +# or any other index averaging the meridional overturning in # +# a given basin and a given domain # +# # +# $1 : input moc file name # +# $2 : latitude min # +# $3 : latitude max # +# $4 : output file name ( => index ) # +# $5 : depth min (default : 1km) # +# $6 : depth max (default : 2km) # +# $7 : basin (default : zomsfatl) # +# # +# Created in March 2012 Author : vguemas@ic3.cat # +############################################################################### + +function area_moc { +if [ -z "$5" ] ; then + typeset var depmin=-1000.0 +else + typeset var depmin=-$5 +fi +if [ -z "$6" ] ; then + typeset var depmax=-2000.0 +else + typeset var depmax=-$6 +fi +if [ -z "$7" ] ; then + typeset var basin=zomsfatl +else + typeset var basin=$7 +fi +lstdims=`ncdump -h $1 | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` +if [[ ${lstdims/x} != ${lstdims} ]] ; then + ncwa -O -a x $1 tmpmoc.nc +else + cp $1 tmpmoc.nc +fi +ncrename -O -d y,lat -v nav_lat,lat tmpmoc.nc tmpmoc.nc +ncks -O -v $basin,time,depthw,lat tmpmoc.nc tmpmoc.nc +ncks -d lat,$2,$3 -d depthw,${depmax},${depmin} tmpmoc.nc area_moc.nc +cdo vertmean area_moc.nc area_ave_moc.nc +ncap -O -s "coslat[lat]=cos(lat[lat]*3.141592657/180.0)" area_ave_moc.nc area_ave_moc2.nc +ncwa -w coslat -a lat area_ave_moc2.nc area_ave_moc3.nc +ncks -O -v $basin,time area_ave_moc3.nc $4 +rm -f tmpmoc.nc area_moc.nc area_ave_moc2.nc area_ave_moc3.nc +if [[ $4 != area_ave_moc.nc ]] ; then + rm -f area_ave_moc.nc +fi +} +############################################################################### +# # +# Compute an Atlantic MOC index by finding the maximum of the annual # +# mean meridional overturning in a latitude / depth region # +# # +# $1 : input moc file name # +# $2 : latitude min # +# $3 : latitude max # +# $4 : depth mean # +# $5 : depth max # +# $6 : output file name ( => index ) # +# # +# Created in March 2012 Author : vguemas@ic3.cat # +############################################################################### + +function max_moc { +if [ ! -f $6 ] ; then + ncecat -h $1 tmpmoc1.nc + lstdims=`ncdump -h tmpmoc1.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` + if [[ ${lstdims/x} != ${lstdims} ]] ; then + ncwa -O -a x tmpmoc1.nc tmpmoc1.nc + fi + ncrename -d record,x tmpmoc1.nc + ncpdq -O -h -a time,x tmpmoc1.nc tmpmoc1.nc + ncpdq -O -h -a depthw,x tmpmoc1.nc tmpmoc1.nc + ncpdq -O -h -a y,x tmpmoc1.nc tmpmoc1.nc + cdo yearmean tmpmoc1.nc tmpmoc.nc + typeset var ntime=`cdo ntime tmpmoc.nc` + typeset var list="" + for jt in $(seq 1 $ntime) ; do + cdo seltimestep,$jt tmpmoc.nc tmpmoc2.nc + cdfmaxmoc tmpmoc2.nc atl $2 $3 $4 $5 + mv maxmoc.nc maxmoc_$jt.nc + timevar=`ncdump -h maxmoc_$jt.nc | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time maxmoc_$jt.nc ; fi + list=${list}" "maxmoc_$jt.nc + rm -f tmpmoc2.nc + done + cdo cat $list $6 + ncks -A -v time tmpmoc.nc $6 + rm -f $list tmpmoc.nc tmpmoc1.nc +fi +} +############################################################################### +# # +# Compute the sea ice extent (1000km2), area (1000km2), volume (km3) # +# and mean thickness (m) in both hemispheres or a specified region. # +# # +# $1 : input ice file name # +# $2 : output file name ( => index ) # +# $3 : region of interest (if empty default is global) # +# # +# Created in April 2012 Author : vguemas@ic3.cat # +# Modified in June 2014 Author : neven.fuckar@ic3.cat # +# # +# Computation of the properties in various selected regions according to # +# mask.regions.${NEMOVERSION}.nc (mask_regions.nc) is based on modification # +# of mask.regions.ORCA1.noverticalinfo.Matt.nc from Matthieu Chevallier. # +# # +############################################################################### + +function siasiesiv { +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'|'Ec3.0_O25L75') 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 ;; +esac + +typeset var ntime=`cdo ntime $1` +typeset var list1="" +typeset var list2="" +typeset var jt + +if [ ! -z "$3" ] ; then + mv mask.nc mask_tmp.nc + mv mask_regions.nc mask.nc + ncrename -h -v $3,tmask mask.nc +fi + +for jt in $(seq 1 $ntime) ; do + cdo seltimestep,$jt $1 tmpice.nc + cdficediags tmpice.nc>ice.txt + for d in N S;do + ncdump toto_${d}.nc > ice_template.cdl + sia=`grep ${d}Area ice.txt |awk '{print $4}'` + sie=`grep ${d}Exnsidc ice.txt|awk '{print $4}'` + siv=`grep ${d}Volume ice.txt|awk '{print $4}'` + sed -e "s/sia =.*/sia = $sia ;/" ice_template.cdl > ice_template2.cdl + sed -e "s/sie =.*/sie = $sie ;/" ice_template2.cdl > ice_template3.cdl + sed -e "s/siv =.*/siv = $siv ;/" ice_template3.cdl > ice_template.cdl + ncgen -o ice_${d}_${jt}.nc ice_template.cdl + rm -f ice_template.cdl ice_template2.cdl ice_template3.cdl + done + list1=$list1" "ice_N_${jt}.nc + list2=$list2" "ice_S_${jt}.nc + rm -f ice.txt tmpice.nc icediags.nc +done +cdo cat $list1 ice_N_${2} +cdo cat $list2 ice_S_${2} +ncks -A -v time $1 ice_N_${2} +ncks -A -v time $1 ice_S_${2} +rm -f $list1 $list2 toto_N.nc toto_S.nc + +for d in N S;do + ncatted -O -a units,sia,m,c,1000km2 ice_${d}_${2} + ncatted -O -a units,sie,m,c,1000km2 ice_${d}_${2} + + ncks -v siv ice_${d}_${2} siv_${d}_${2}1 + ncks -v sia ice_${d}_${2} sia_${d}_${2}1 + ncrename -h -v sia,siv sia_${d}_${2}1 + ncbo -O --op_typ=dvd siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} + ncatted -O -a standard_name,siv,m,c,Mean_sea_ice_thickness sit_${d}_${2} + ncatted -O -a long_name,siv,m,c,"Mean sea ice thickness" sit_${d}_${2} + ncatted -O -a units,siv,m,c,m sit_${d}_${2} + cdo ltc,100 sit_${d}_${2} sit_${d}_${2}1 + cdo ifthenelse sit_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 + ncrename -h -v siv,sit sit_${d}_${2}2 + ncks -A sit_${d}_${2}2 ice_${d}_${2} + + rm siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 +done + +setminmax ice_N_${2} sia sie siv sit +setminmax ice_S_${2} sia sie siv sit + +if [ ! -z "$3" ] ; then + ncrename -h -v tmask,$3 mask.nc + mv mask.nc mask_regions.nc + mv mask_tmp.nc mask.nc +fi + +} +############################################################################### +# # +# Compute the total ocean heat extent # +# # +# $1 : input temperature file name # +# $2 : output file name ( => 2D x-y ) # +# $3 : basin (NAtl, NPac, TAtl, TPac, TInd, Anta, Arct, Glob) Default : Glob # +# $4 = 0 if $3 = Glob # +# $4 : mixed layer (1=only, 0=included, -1=without) Default : 0 # +# $5 : upper level of the layer (optional) Default : top # +# $6 : lower level of the layer (optional) Default : bottom # +# # +# Created in May 2012 Author : vguemas@ic3.cat # +############################################################################### + +function ohc { +cp ${CON_FILES}/depth.${NEMOVERSION}.txt depth.txt +# +# Input arguments +# +if [ -z "$3" ] ; then + typeset var basin='Glob' +else + typeset var basin=$3 +fi +if [ -z "$4" ] ; then + typeset var mxl=0 +else + typeset var mxl=$4 +fi +if [ -z "$5" ] ; then + typeset var up=1 +else + typeset var up=$5 +fi +if [ -z "$6" ] ; then + typeset var down=`cat depth.txt | wc -l` +else + typeset var down=$6 +fi + +if [[ ${up} -eq 1 ]] ; then + typeset var depmin=0 +else + typeset var depmin=`cat depth.txt |head -${up} |tail -1 | awk '{print $2}' | awk '{printf "%.0f",$1}'` +fi +typeset var depmax=`cat depth.txt |head -${down} |tail -1 | awk '{print $2}' | awk '{printf "%.0f",$1}'` + +cp ${CON_FILES}/heatc_template.nc template_heatc.nc +ncdump template_heatc.nc > template_heatc.cdl +#exec=/home/huidu/download/CDFTOOLS_2.1/cdfheatc-cfu +exec=/home/Earth/vguemas/CDFTOOLS_2.1/cdfheatc-cfu +# +# Define some parameters +# +typeset var para +typeset var output +typeset var nlev=`cat depth.txt | wc -l` +if [[ ! -z "$depmin" && ! -z "$depmax" ]] ; then + if [[ $depmin != 0 || ${down} != ${nlev} && ${down} != 0 ]] ; then + output=${depmin}-${depmax}'_' + fi +fi + +case $basin in + 'NAtl') para="atl $mxl 0 0 10 65"; output='NAtl_10N65N_'${output} ;; + 'TAtl') para="atl $mxl 0 0 -30 30" ; output='TAtl_30S30N_'${output} ;; + 'NPac') para="pac $mxl 0 0 10 70" ; output='NPac_10N70N_'${output} ;; + 'TPac') para="pac $mxl 0 0 -30 30" ; output='TPac_30S30N_'${output} ;; + 'Arct') para="atl $mxl 0 0 65 90" ; output='Arc_65N90N_'${output} ;; + 'Anta') para="all $mxl 0 0 -90 -60" ; output='Ant_90S60S_'${output} ;; + 'TInd') para="ind $mxl 0 0 -30 30" ; output='TInd_30S30N_'${output} ;; + 'Glob') para="all $mxl 0 0 0 0" ;; +esac + +case $mxl in + 1) output='mxl_'${output} ;; + -1) output='nonmxl_'${output} ;; +esac +# +# Compute ohc +# +typeset var lstvars=`cdo showvar $1` +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +for jt in $(seq 1 $ntime) ; do + cdo seltimestep,$jt $1 tmpohc.nc + lstdims=`ncdump -h tmpohc.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` + if [[ ${lstdims/x_2} != ${lstdims} ]] ; then + if [[ ${lstdims/x} != ${lstdims} ]] ; then + ncwa -O -a x tmpohc.nc tmpohc.nc + fi + ncrename -d x_2,x tmpohc.nc + fi + if [[ ${lstvars/somxl010} != ${lstvars} ]] ; then + ncks -v somxl010 tmpohc.nc mxl.nc + else + cdfmxl tmpohc.nc mxl.nc + fi + $exec tmpohc.nc $para $up $down > tmp.log + cat tmp.log + thc=`cat tmp.log | grep "Total Heat content :" | awk '{print $5}'`; + uhc=`cat tmp.log | grep "Total Heat content/volume" | awk '{print $5}'`; + sed -e "s/thc =.*/thc = $thc ;/" template_heatc.cdl > template_heatc2.cdl + sed -e "s/uhc =.*/uhc = $uhc ;/" template_heatc2.cdl > template_heatc.cdl + ncgen -o heatc_${jt}.nc template_heatc.cdl + rm -f template_heatc2.cdl tmpohc.nc mxl.nc tmp.log + list=$list" "heatc_${jt}.nc +done +cdo cat $list ${output}$2 +ncks -h -A -v time $1 ${output}$2 +rm -f $list template_heatc.nc template_heatc.cdl depth.txt +setminmax ${output}$2 thc uhc +} +############################################################################### +# # +# Cut a meridional or zonal section # +# # +# # +# $1 : input file # +# $2 : input var # +# $3 : Z/M (zonal / meridional section) # +# $4 : lat/lon # +# $5 : output file ( => 2D ) # +# # +# Created in September 2012 Author : vguemas@ic3.cat # +# # +############################################################################### + +function cutsection { + typeset var ntime=`cdo ntime $1` + typeset var nx=`ncdump -h $1|grep 'x = '|head -1|cut -f3 -d" "` + typeset var ny=`ncdump -h $1|grep 'y = '|head -1|cut -f3 -d" "` + typeset var nz=`ncdump -h $1|grep 'depth'|head -1|cut -f3 -d" "` +cat>section.R<max(lon)) {exactpos=exactpos-360} + } + # Collect the indexes defining the section + listi=array(dim=switch('$3','Z'=$nx-2,'M'=$ny-1)) + listj=array(dim=switch('$3','Z'=$nx-2,'M'=$ny-1)) + for (jpt in 1:length(listi)) { + vect=switch('$3','Z'=lat[jpt,],'M'=lon[,jpt+1]) + if (min(abs(vect-exactpos))<(2*360./$nx)) { + pos=sort(abs(vect-exactpos),index.return=T)\$ix[1] + listi[jpt]=switch('$3','Z'=jpt+1,'M'=pos) + listj[jpt]=switch('$3','Z'=pos,'M'=jpt) + } + } + listi=listi[is.na(listi)==F] + listj=listj[is.na(listj)==F] + print(listi) + print(listj) + # Select variable at those indexes + fnc1=open.ncdf('$1') + varout=array(dim=c(length(listi),$nz,$ntime)) + for (jt in 1:$ntime) { + varin=get.var.ncdf(fnc1,'$2',start=c(1,1,1,jt),count=c($nx,$ny,$nz,1)) + varin[which(mask<0.5)]=1e20 + for (jpt in 1:length(listi)) { + varout[jpt,,jt]=varin[listi[jpt],listj[jpt],] + } + } + close.ncdf(fnc1) + # Write the output + wtime=dim.def.ncdf("time","",seq(1,$ntime),unlim=TRUE) + dimout=array(dim=length(listi)) + for (jpt in 1:length(listi)) { + dimout[jpt]=switch('$3','Z'=lon[listi[jpt],listj[jpt]],'M'=lat[listi[jpt],listj[jpt]]) + } + wsec=switch('$3','Z'=dim.def.ncdf("lon","",dimout),'M'=dim.def.ncdf("lat","",dimout)) + wdep=dim.def.ncdf("deptht","",depth) + wvar=var.def.ncdf("$2","",list(wsec,wdep,wtime),1e20) + fnc2=create.ncdf('$5',wvar) + put.var.ncdf(fnc2,wvar,varout) + close.ncdf(fnc2) +EOF1 +R CMD BATCH section.R +ncks -h -A -v time $1 $5 +} +############################################################################### +# # +# 3-dimensional conservative interpolation to the regular atmospheric grid # +# # +# $1 : input file # +# $2 : input var # +# $3 : output file ( => 3D ) # +# # +# Created in November 2012 Author : vguemas@ic3.cat # +# # +############################################################################### + +function interp3d { + typeset var nz=`ncdump -h $1|grep 'deptht'|head -1|cut -f3 -d" "` + ln -sf /shared/earth/software/scripts/interpolation/scrip_use scrip_use + for lev in $(seq 1 $nz) ; do + ncks -d deptht,$((lev-1)) -v $2 $1 tmp_${lev}.nc + ncwa -O -h -a deptht tmp_${lev}.nc tmp_${lev}.nc + ln -sf /esnas/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc + cat > scrip_use_in < 2D field ) # +# # +# Created in February 2012 Author : vguemas@ic3.cat # +# Modified (more generic, +# i.e. for any input var) in December 2014 # +# Author : eleftheria.exarchou@ic3.cat # +############################################################################### + +function vertmeanvar { + typeset var ntime=`cdo ntime $1` + typeset var list="" + typeset var jt +for jt in $(seq 1 $ntime); do + ncks -d time,$((jt-1)) $1 a1 + # The oras4 data do not have gdepth data in their mask, but only gdept_0, so: + if grep -q nemovar_s4 $1 ; then + l1=$(( $3 % 6 )) + l2=$(( $4 % 6 )) + ll1=$(( $3 / 6 + 1 )) + ll2=$(( $4 / 6 + 1 )) + lev1=`echo $(cdo output -selvar,gdept_0 mesh_zgr.nc | sed -n ${ll1}p | awk '{ print $'$l1' }')` + lev2=`echo $(cdo output -selvar,gdept_0 mesh_zgr.nc | sed -n ${ll2}p | awk '{ print $'$l2' }')` + else + l1=$(($3+1)) + l2=$(($4+1)) + lev1=`echo $(cdo info -seltimestep,1 -selvar,gdept mesh_zgr.nc | sed -n ${l1}p | awk '{ print $10 }')` + lev2=`echo $(cdo info -seltimestep,1 -selvar,gdept mesh_zgr.nc | sed -n ${l2}p | awk '{ print $10 }')` + fi + cdfvertmean a1 $2 T $lev1 $lev2 + rm -f a1 + ncrename -O -v sovertmean,vertmean -d time_counter,time -v time_counter,time vertmean.nc + mv vertmean.nc outputvertmean_$jt.nc + list=$list" "outputvertmean_$jt.nc + rm -f intvertmean.nc a? +# #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN + ncatted -O -a valid_max,vertmean,d,, outputvertmean_$jt.nc outputvertmean_$jt.nc + ncatted -O -a valid_min,vertmean,d,, outputvertmean_$jt.nc outputvertmean_$jt.nc + ncatted -O -a standard_name,time,a,c,time outputvertmean_$jt.nc outputvertmean_$jt.nc + ncatted -O -a units,time,o,c,'seconds since 1993-05-01 00:00:00' outputvertmean_$jt.nc outputvertmean_$jt.nc + ncatted -O -a long_name,time,a,c,'Time axis' outputvertmean_$jt.nc outputvertmean_$jt.nc +done +cdo cat $list $5 +ncks -A -v time $1 $5 +rm -f $list +setminmax $5 vertmean +ncrename -v vertmean,$2 $5 +#typeset var level=`echo $(cdo info -selvar,$2 -setctomiss,0 $5 | sed -n 2p | awk '{ print $7 }')` +#typeset var lev=`echo $(cdo info -seltimestep,1 -selvar,$2 -setctomiss,0 $1 | grep $level | awk '{ print $1 }')` +lev=$3 +echo $lev +cp $5 tmp_${lev}.nc +## Here we interpolate horizontally onto a regular grid + ln -sf /esnas/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc + ln -sf /shared/earth/software/scripts/interpolation/scrip_use scrip_use + cat > scrip_use_in < You can test your function by defining the CON_FILES and NEMOVERSION @ +# variables and by sourcing the current file, the meshmasks will be @ +# available after sourcing, remember to source again after any @ +# modification of your function @ +# --> Your function should work on input files of any resolution @ +# ORCA1/ORCA025/ORCA2 @ +# --> Your function should work on input files of any time length @ +# --> The output file should contain a proper time axis that you can copy @ +# from your input file @ +# --> The output file should be at most a 3d field including the time @ +# dimension @ +# 3) Write a short description of your function, and add its name to the @ +# list above @ +# 4) Go the the ocean_pp.sh script to add a call to your function @ +# @ +# Any doubt ---> vguemas@ic3.cat @ +#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# Link constant file for co # +############################################################################### + +ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_hgr.nc +ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_zgr.nc +ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mask.nc +ln -sf ${CON_FILES}/new_maskglo.${NEMOVERSION}.nc new_maskglo.nc + +if [ -e ${CON_FILES}/mask.regions.${NEMOVERSION}.nc ] ; then +cp ${CON_FILES}/mask.regions.${NEMOVERSION}.nc mask_regions.nc +fi + +if [[ ! -f mask.nc ]] ; then + echo "No configuration files for cdftools" + exit +fi + +############################################################################### +# Reduced number of variables in diag files to save disk space # +# # +# $1 : input grid_T file name # +# $2 : input icemod file name # +# $3 : suffix of output files with nc extension # +# # +# Created in February 2012 Author : vguemas@ic3.cat # +# May 2014 : Compatibility with PA changes to oce output - Virginie # +############################################################################### + +function reduce_mmo { +ncks -O -v sosstsst,sosaline,somixhgt,somxl010,sossheig $1 oce_${3} +typeset var lstvars=`cdo showvar $2` +if [[ ${lstvars/ileadfra} != ${lstvars} ]] ; then + ncks -O -v isnowthi,iicethic,ileadfra,iicetemp $2 ice_${3} +else + ncks -O -v isnowthi,iicethic,iiceconc,iicetemp $2 ice_${3} +fi +ncks -O -v votemper $1 t3d_${3} +} +############################################################################### +# Copy diags or MMO files from esnas # +# # +# $1 : starting date # +# $2 : expid # +# $3 : member # +# $4 : starting leadtime # +# $5 : end leadtime # +# $6 : chunk length in month # +# $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 # +# Option 10: June 2013 isabel.andreu-burillo@ic3.cat +############################################################################### + +function get_diagsMMO { +typeset var yyyy0=`echo $1|cut -c1-4` +typeset var mm0=`echo $1|cut -c5-6` +if [ -z "${10}" ] ; then + typeset var lstypes="grid_T grid_U grid_V grid_W icemod" +else + typeset var lstypes=${10} +fi + +typeset var jt +typeset var year1 +typeset var year2 +typeset var mon1 +typeset var mon2 +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 /esnas/exp/$7/$2/$1/fc$3/outputs/$8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar . + if [[ "$8" == "MMO" ]]; then + for filetype in $lstypes; do + tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar "*${freqkeep}*${filetype}*" + done + else + tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar + fi + rm -f $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar + if [[ `ls *.gz` != '' ]] ; then gunzip -f *.gz ; fi + ipcs -a +done + +typeset var listroots +case $8 in + 'diags' ) + listroots="t3d heat_sal_mxl ice moc psi sal_0-300m sal_300-5400m" + if [[ `ls sstsimld*` != '' ]] ; then + listroots=$listroots" sstsimld" + elif [[ `ls sstsssmld*` != '' ]] ; then + listroots=$listroots" sstsssmld" + else + listroots=$listroots" oce" + fi + ;; + 'MMO' ) listroots=$lstypes ;; +esac +case $9 in + 'daily') freqexcl1='1m' ; freqexcl2='MM' ;; + 'monthly' ) freqexcl1='1d' ; freqexcl2='DD' ;; + *) freqexcl1='1d' ; freqexcl2='DD' ;; +esac + +function concat_startdate { + typeset var root + typeset var lstfiles + for root in ${listroots[@]} ; do + ipcs -a + if [[ "$8" == "MMO" ]] ; then + lstfiles=`ls *${root}* | grep -v "${root}_$2_$1_fc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" | grep -v "km" ` + else + lstfiles=`ls ${root}* | grep -v "${root}_$2_$1_fc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" | grep -v "km" ` + fi + if [[ ! -z ${lstfiles} ]] ; then + + file1=`echo "${lstfiles}" | tail -1` + cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` + rm ff + #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN + if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then + 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 + if [[ $root == 'heat_sal_mxl' ]] ; then + for file in $lstfiles ; do + ncatted -O -a valid_max,somxlheatc,d,, $file $file + ncatted -O -a valid_min,somxlheatc,d,, $file $file + done + fi + fi + + outfile=${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc + 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 ${outfile} + timevar=`ncdump -h ${outfile} | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time ${outfile} ; fi + if [[ $root == 'moc' ]] ; then + lstdims=`ncdump -h ${outfile} | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` + if [[ ${lstdims/gsize} != ${lstdims} ]] ; then + ncrename -d gsize,y ${outfile} + fi + lenx=`ncdump -h ${outfile} | grep 'x =' | head -1 | awk '{print $3}'` + if [[ $lenx > 1 ]] ; then + if [[ ${lstvars/nav_lon} != ${lstvars} ]] ; then + ncks -O -x -v nav_lon,nav_lat ${outfile} ${outfile} + fi + ncrename -d x,y ${outfile} + fi + ncks -A -v nav_lon,nav_lat `echo $lstfiles | awk '{print $1}' ` ${outfile} + fi + rm -f $lstfiles + if [[ $root == 'sstsimld' || $root == 'sstsssmld' ]] ; then mv ${outfile} oce_$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 + done +} + +concat_startdate $1 $2 $3 $4 $5 $6 $7 $8 + +# These lines aim at concatenating the daily means as well and computing the monthly means from these daily means +if [[ $9 == 'monthly' ]] ; then + freqexcl1='1m' ; freqexcl2='MM' + for root in ${listroots[@]} ; do + outfile=${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 [[ -e $outfile ]] ; then + mv $outfile ${root}_1m.nc + fi + done + concat_startdate $1 $2 $3 $4 $5 $6 $7 $8 + for root in ${listroots[@]} ; do + ipcs m + outfile=${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 [[ -e $outfile ]] ; then + cdo monmean $outfile ${root}_daily2monthly.nc + rm -f $outfile + if [[ -e ${root}_1m.nc ]] ; then + mv ${root}_1m.nc $outfile + ncks -A ${root}_daily2monthly.nc $outfile + rm -f ${root}_daily2monthly.nc + else + mv ${root}_daily2monthly.nc $outfile + fi + else + if [[ -e ${root}_1m.nc ]] ; then + mv ${root}_1m.nc $outfile + fi + fi + done +fi + +rm -f *${freqexcl1}* *${freqexcl2}* + +} +############################################################################### +# Copy NEMOVAR files from esnas # +# # +# $1 : expid # +# $2 : member # +# $3 : start year # +# $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 { + +if [ -z "$5" ] ; then + typeset var moni=9 +else + typeset var moni=$5 +fi + +if [ -z "$5" ] ; then + typeset var monf=8 +else + typeset var monf=$6 +fi + +typeset var path +typeset var yearf +case $1 in + 'nemovar_s4') path=/esnas/exp/ECMWF/NEMOVAR_S4/outputs/fc$2/s4 ;; + 'nemovar_combine') path=/esnas/exp/ECMWF/NEMOVAR_COMBINE/outputs/opa0/fa9p_1m ;; +esac +typeset var year +typeset var mon +for year in $(seq $3 $4) ; do + case $year in + $3) mona=${moni} ;; + *) mona=1 ;; + esac + case $year in + $4) monb=${monf} ;; + *) monb=12 ;; + esac + for mon in $(seq $mona $monb); do + cp ${path}_fc$2_${year}$(printf "%02d" $mon)*.gz . + done +done +gunzip -f *.gz + +typeset var listroots=${7} +typeset var root +typeset var lstfiles +typeset var ntimes +typeset var jt +for root in ${listroots[@]} ; do + lstfiles=`ls *fc${2}*${root}* | grep -v "${root}_$1_195709_fc$2_${3}09_${4}$(printf "%02d" $monb).nc"` + ncrcat -O -x -v vorbiasp $lstfiles tmp_${root}.nc + cdo settaxis,${3}-$(printf "%02d" $moni)-15,12:00,1mon tmp_${root}.nc ${root}_$1_19570901_fc$2_${3}$(printf "%02d" $moni)_${4}$(printf "%02d" $monf).nc + rm -f $lstfiles tmp_${root}.nc +done +} +############################################################################### +# Copy GLORYS files from esnas # +# # +# $1 : start year # +# $2 : end year # +# $3 : start month # +# $4 : end month # +# # +# Created in June 2013 Author : vguemas@ic3.cat # +############################################################################### + +function get_glorys { +typeset var path=/esnas/exp/MERCATOR/GLORYS2V1/outputs/ORCA1L46 #ORCA025L75_glorys +typeset var lstfiles="" +for year in $(seq $1 $2) ; do + cp ${path}/vosaline_${year}.nc . + cp ${path}/votemper_${year}.nc . + ncks -A vosaline_${year}.nc votemper_${year}.nc + rm -f vosaline_${year}.nc + lstfiles=${lstfiles}" "votemper_${year}.nc +done +cdo cat ${lstfiles} tmp.nc +cdo settaxis,${1}-01-15,12:00,1mon tmp.nc tmp2.nc +cdo seldate,${1}-$(printf "%02d" $3)-00,${2}-$(printf "%02d" $4)-31 tmp2.nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc +rm -f ${lstfiles} tmp.nc tmp2.nc +ncks -O -x -v nav_lon,nav_lat,x_2,y_2 grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc +ncks -A -v nav_lon,nav_lat mesh_hgr.nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc +} +############################################################################### +# Clean diags or MMO files after postprocessing # +# # +# $1 : starting date # +# $2 : expid # +# $3 : member # +# $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 { +typeset var yyyy0=`echo $1|cut -c1-4` +typeset var mm0=`echo $1|cut -c5-6` +typeset var year1=$(($yyyy0+(10#$mm0+$4-2)/12)) +typeset var year2=$(($yyyy0+(10#$mm0+$5-2)/12)) +typeset var mon1=$(((10#$mm0+$4-2)%12+1)) +typeset var mon2=$(((10#$mm0+$5-2)%12+1)) + +typeset var listroots + case $6 in + 'diags' ) listroots="t3d" ;; + 'MMO' ) + if [ -z "${7}" ] ; then + listroots="grid_T grid_U grid_V grid_W icemod" + else + listroots=${7} + fi + ;; + esac +typeset var root +typeset var lstfiles +for root in ${listroots[@]} ; do + rm -f ${root}_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)_${year2}$(printf "%02d" $mon2).nc +done +} +############################################################################### +# Vertically averaged salt content # +# # +# $1 : input grid_T file name # +# $2 : upper depth of the layer (in meters) # +# $3 : lower depth of the layer (in meters) # +# $4 : output file name (=> 2D) # +# # +# Created in February 2012 Author : vguemas@ic3.cat # +############################################################################### + +function vertmeansal { +cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` +rm ff +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +for jt in $(seq 1 $ntime); do + ncks -d time,$((jt-1)) $1 intvertmeansal.nc + cdfvertmean intvertmeansal.nc vosaline T $2 $3 + ncrename -O -v sovertmean,vertmeansal -d time_counter,time -v time_counter,time vertmean.nc + mv vertmean.nc outputvertmeansal_$jt.nc + list=$list" "outputvertmeansal_$jt.nc + rm -f intvertmeansal.nc + #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN + if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then + ncatted -O -a valid_max,vertmeansal,d,, outputvertmeansal_$jt.nc outputvertmeansal_$jt.nc + ncatted -O -a valid_min,vertmeansal,d,, outputvertmeansal_$jt.nc outputvertmeansal_$jt.nc + fi +done +cdo cat $list $4 +ncks -A -v time $1 $4 +rm -f $list +setminmax $4 vertmeansal +} +############################################################################### +# Compute mixed layer heat and salt content # +# # +# $1 : input grid_T file name # +# $2 : output file name (=> 2D x-y ) # +# # +# Created in February 2012 Author : vguemas@ic3.cat # +################################################################################ + +function heat_sal_mxl { +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +typeset var lstvars=`cdo showvar $1` +for jt in $(seq 1 $ntime); do + ncks -d time,$((jt-1)) $1 intheat_sal_mxl.nc + if [[ ${lstvars/somxl010} == ${lstvars} ]] ; then + cdfmxl intheat_sal_mxl.nc mxl.nc + ncrename -d time_counter,time mxl.nc + ncks -A mxl.nc intheat_sal_mxl.nc + rm -f mxl.nc + fi + cdfmxlheatc intheat_sal_mxl.nc + if [[ $lstvars != ${lstvars/vosaline} ]] ; then + cdfmxlsaltc intheat_sal_mxl.nc + ncks -A mxlsaltc.nc mxlheatc.nc + rm -f mxlsaltc.nc + fi + mv mxlheatc.nc outputintheat_sal_mxl_$jt.nc + timevar=`ncdump -h outputintheat_sal_mxl_$jt.nc | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time outputintheat_sal_mxl_$jt.nc ; fi + list=$list" "outputintheat_sal_mxl_$jt.nc + rm -f intheat_sal_mxl.nc +done +cdo cat $list $2 +ncks -A -v time $1 $2 +rm -f $list +setminmax $2 somxlheatc +if [[ $lstvars != ${lstvars/vosaline} ]] ; then setminmax $2 somxlsaltc ; fi +} +############################################################################### +# Pointwise Ocean Heat Content in a specified ocean thickness # +# (J/m-2) +# # +# $1 : input grid_T file name # +# $2 : upper depth of the layer (in meters) # +# $3 : lower depth of the layer (in meters) # +# $4 : output file name (=> 2D x-y ) # +# # +# Created in June 2012 Author : isabel.andreu-burillo@ic3.cat # +# May 2014 - Virginie Guemas - Way around the bc that does not work on moore # +############################################################################### + +function ohc_specified_layer { +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +ncap2 -v -O -s "heatc_sl=tmask*e3t" mesh_zgr.nc e3t_file.nc +ncrename -d t,time -d z,deptht e3t_file.nc +for jt in $(seq 1 $ntime); do + cdo seltimestep,$jt $1 intohc_slayer.nc + 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 + ncks -d deptht,$2,$3 heatc_sl_out.nc heatc_sl_top.nc + #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 + # lower_bnd=`echo "$3 + 200.0" | bc` -> does not work on new moore + # strip out the .* from $3: + stripped=`echo ${3/.*}` + # addition with float returned: + lower_bnd=`echo $(printf "%f" $(( $stripped + 200)))` + 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 + 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 + ## Here, add the residual contribution, before adding it to the main contribution + ncrename -v deptht,layerthcknss level_below.nc + ncrename -v deptht,layerthcknss level_above.nc + ncbo -A --op_typ=sub -v layerthcknss level_below.nc level_above.nc depth_diff_lay.nc + ncrename -v layerthcknss,heatc_sl depth_diff_lay.nc + ncap2 -s "heatc_sl=($3 - layerthcknss)" level_above.nc depth_diff_sublay.nc + ncbo --op_typ=/ -v heatc_sl depth_diff_sublay.nc depth_diff_lay.nc factor.nc + ncrename -v heatc_sl,factor factor.nc #to be commented + ncks -A -v factor factor.nc level_below.nc + rm -f depth_diff_sublay.nc depth_diff_lay.nc + ncap2 -O -s "heatc_sl=(factor * heatc_sl)" level_below.nc level_below.nc + ncwa -O -a deptht level_below.nc level_below.nc + ncbo --op_typ=+ -v heatc_sl heatc_sl_top.nc level_below.nc total_heatc_sl.nc + ncap2 -s "heatc_sl=1020.0*4000*heatc_sl" total_heatc_sl.nc heatc_sl_$jt.nc + list=$list" "heatc_sl_$jt.nc + rm -f depth_diff_lay.nc depth_diff_sublay.nc + rm -f heatc_sl_out.nc heatc_sl_top.nc heatc_sl_top_invert.nc heatc_sl_bottom.nc + rm -f level_above.nc level_below.nc + rm -f intohc_slayer.nc intmeantem.nc vertmean.nc total_heatc_sl.nc + rm -f factor.nc +done +cdo cat $list $4 +ncks -A -v time $1 $4 +rm -f $list +rm -f e3t_file.nc +setminmax $4 heatc_sl +} +############################################################################### +# Compute the MOC for oceanic basins # +# # +# $1 : input grid_V file name # +# $2 : output file name (=> 2D, depth-y) # +# # +# Created in March 2012 Author : vguemas@ic3.cat # +############################################################################### + +function moc { +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +for jt in $(seq 1 $ntime); do + cdo seltimestep,$jt $1 intmoc.nc + cdfmoc intmoc.nc + ncwa -O -a x moc.nc outmoc_$jt.nc + ncks -O -x -v nav_lon,nav_lat outmoc_$jt.nc outmoc_$jt.nc + timevar=`ncdump -h outmoc_$jt.nc | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time outmoc_$jt.nc ; fi + list=$list" "outmoc_$jt.nc + rm -f intmoc.nc moc.nc +done +cdo cat $list $2 +lstdims=`ncdump -h $2 | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` +if [[ ${lstdims/gsize} != ${lstdims} ]] ; then + ncrename -d gsize,y $2 +fi +ncks -A -v nav_lon,nav_lat $1 $2 +ncks -A -v time $1 $2 +rm -f $list +} +############################################################################### +# # +# Compute the intensity of convection in the four main convection sites # +# # +# $1 : input oce file name containing somxl010 # +# $2 : input grid # +# $3 : output file name (=> index) # +# # +# Created in October 2013 Author : vguemas@ic3.cat # +############################################################################### + +function convection { +case $2 in + 'Ec2.3_O1L42'|'Ec3.0_O1L46'|'N3.2_O1L42'|'N3.3_O1L46'|'nemovar_O1L42') + A1=225;A2=245;A3=215;A4=255; + B1=245;B2=290;B3=215;B4=245; + C1=260;C2=310;C3=245;C4=291; + D1=225;D2=280;D3=1;D4=50;; + + 'Ec3.0_O25L46'|'Ec3.0_O25L75'|'glorys2v1_O25L75') + stop"Option convection not available yet for this configuration" + ;; +esac + +cdo fldmax -selindexbox,${A1},${A2},${A3},${A4} $1 Labrador.nc +ncrename -v somxl010,Labrador Labrador.nc +ncks -v Labrador Labrador.nc convection.nc +rm -f Labrador.nc + +cdo fldmax -selindexbox,${B1},${B2},${B3},${B4} $1 Irminger.nc +ncrename -v somxl010,Irminger Irminger.nc +ncks -A -v Irminger Irminger.nc convection.nc +rm -f Irminger.nc + +cdo fldmax -selindexbox,${C1},${C2},${C3},${C4} $1 GIN.nc +ncrename -v somxl010,GIN GIN.nc +ncks -A -v GIN GIN.nc convection.nc +rm -f GIN.nc + +cdo fldmax -selindexbox,${D1},${D2},${D3},${D4} $1 Wedell.nc +ncrename -v somxl010,Wedell Wedell.nc +ncks -A -v Wedell Wedell.nc convection.nc +rm -f Wedell.nc + +mv convection.nc $3 +} +############################################################################### +# # +# Compute the barotropic stream function # +# # +# $1 : input grid_U file name # +# $2 : input grid_V file name # +# $3 : output file name without nc extension (=> 2D x-y) # +# # +# Created in March 2012 Author : vguemas@ic3.cat # +############################################################################### + +function psi { +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +for jt in $(seq 1 $ntime); do + cdo seltimestep,$jt $1 intU.nc + cdo seltimestep,$jt $2 intV.nc + cdfpsi intU.nc intV.nc + mv psi.nc psi_U.nc + cdfpsi intU.nc intV.nc V + mv psi.nc psi_V.nc + ncea psi_U.nc psi_V.nc psi_${jt}.nc + timevar=`ncdump -h psi_$jt.nc | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time psi_$jt.nc ; fi + list=$list" "psi_$jt.nc + rm -f intU.nc intV.nc psi_U.nc psi_V.nc +done +cdo cat $list ${3} +ncks -A -v time $1 ${3} +rm -f $list +} +############################################################################### +# # +# Compute the intensity of the subtropical and subpolar gyres # +# # +# $1 : input psi file name # +# $2 : input grid # +# $3 : output file name ( => index ) # +# # +# Created in October 2013 Author : vguemas@ic3.cat # +############################################################################### + +function gyres { +case $2 in + 'Ec2.3_O1L42'|'Ec3.0_O1L46'|'N3.2_O1L42'|'N3.3_O1L46'|'nemovar_O1L42') + A1=230;A2=275;A3=215;A4=245; + B1=70;B2=145;B3=195;B4=235; + C1=45;C2=175;C3=165;C4=220; + D1=195;D2=275;D3=175;D4=225; + E1=70;E2=205;E3=120;E4=145; + F1=235;F2=300;F3=120;F4=145; + G1=320;G2=30;G3=110;G4=180; + H1=1;H2=361;H3=1;H4=65;; + + 'Ec3.0_O25L46'|'Ec3.0_O25L75'|'glorys2v1_O25L75') + stop"Option gyres not available yet for this configuration" + ;; +esac + +cdo fldmin -selindexbox,${A1},${A2},${A3},${A4} $1 subpolar_NAtl.nc +ncrename -v sobarstf,subpolNAtl subpolar_NAtl.nc +cdo mulc,-1 subpolar_NAtl.nc gyres.nc +rm -f subpolar_NAtl.nc + +cdo fldmin -selindexbox,${B1},${B2},${B3},${B4} $1 subpolar_NPac.nc +ncrename -v sobarstf,subpolNPac subpolar_NPac.nc +cdo mulc,-1 subpolar_NPac.nc tmp.nc +ncks -A tmp.nc gyres.nc +rm -f subpolar_NPac.nc tmp.nc + +cdo fldmax -selindexbox,${C1},${C2},${C3},${C4} $1 subtrop_NPac.nc +ncrename -v sobarstf,subtropNPac subtrop_NPac.nc +ncks -A subtrop_NPac.nc gyres.nc +rm -f subtrop_NPac.nc + +cdo fldmax -selindexbox,${E1},${E2},${E3},${E4} $1 subtrop_SPac.nc +ncrename -v sobarstf,subtropSPac subtrop_SPac.nc +ncks -A subtrop_SPac.nc gyres.nc +rm -f subtrop_SPac.nc + +cdo fldmax -selindexbox,${D1},${D2},${D3},${D4} $1 subtrop_NAtl.nc +ncrename -v sobarstf,subtropNAtl subtrop_NAtl.nc +ncks -A subtrop_NAtl.nc gyres.nc +rm -f subtrop_NAtl.nc + +cdo fldmax -selindexbox,${F1},${F2},${F3},${F4} $1 subtrop_SAtl.nc +ncrename -v sobarstf,subtropSAtl subtrop_SAtl.nc +ncks -A subtrop_SAtl.nc gyres.nc +rm -f subtrop_SAtl.nc + +cdo fldmax -selindexbox,${G1},${G2},${G3},${G4} $1 subtrop_Ind.nc +ncrename -v sobarstf,subtropInd subtrop_Ind.nc +ncks -A subtrop_Ind.nc gyres.nc +rm -f subtrop_Ind.nc + +cdo fldmax -selindexbox,${H1},${H2},${H3},${H4} $1 ACC.nc +ncrename -v sobarstf,ACC ACC.nc +ncks -A ACC.nc gyres.nc +rm -f ACC.nc + +mv gyres.nc $3 + +} +############################################################################### +# # +# Compute an Atlantic MOC index by averaging the meridional overturning # +# in a latitude band between 1km and 2km # +# or any other index averaging the meridional overturning in # +# a given basin and a given domain # +# # +# $1 : input moc file name # +# $2 : latitude min # +# $3 : latitude max # +# $4 : output file name ( => index ) # +# $5 : depth min (default : 1km) # +# $6 : depth max (default : 2km) # +# $7 : basin (default : zomsfatl) # +# # +# Created in March 2012 Author : vguemas@ic3.cat # +############################################################################### + +function area_moc { +if [ -z "$5" ] ; then + typeset var depmin=-1000.0 +else + typeset var depmin=-$5 +fi +if [ -z "$6" ] ; then + typeset var depmax=-2000.0 +else + typeset var depmax=-$6 +fi +if [ -z "$7" ] ; then + typeset var basin=zomsfatl +else + typeset var basin=$7 +fi +lstdims=`ncdump -h $1 | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` +if [[ ${lstdims/x} != ${lstdims} ]] ; then + ncwa -O -a x $1 tmpmoc.nc +else + cp $1 tmpmoc.nc +fi +ncrename -O -d y,lat -v nav_lat,lat tmpmoc.nc tmpmoc.nc +ncks -O -v $basin,time,depthw,lat tmpmoc.nc tmpmoc.nc +ncks -d lat,$2,$3 -d depthw,${depmax},${depmin} tmpmoc.nc area_moc.nc +cdo vertmean area_moc.nc area_ave_moc.nc +ncap -O -s "coslat[lat]=cos(lat[lat]*3.141592657/180.0)" area_ave_moc.nc area_ave_moc2.nc +ncwa -w coslat -a lat area_ave_moc2.nc area_ave_moc3.nc +ncks -O -v $basin,time area_ave_moc3.nc $4 +rm -f tmpmoc.nc area_moc.nc area_ave_moc2.nc area_ave_moc3.nc +if [[ $4 != area_ave_moc.nc ]] ; then + rm -f area_ave_moc.nc +fi +} +############################################################################### +# # +# Compute an Atlantic MOC index by finding the maximum of the annual # +# mean meridional overturning in a latitude / depth region # +# # +# $1 : input moc file name # +# $2 : latitude min # +# $3 : latitude max # +# $4 : depth mean # +# $5 : depth max # +# $6 : output file name ( => index ) # +# # +# Created in March 2012 Author : vguemas@ic3.cat # +############################################################################### + +function max_moc { +if [ ! -f $6 ] ; then + ncecat -h $1 tmpmoc1.nc + lstdims=`ncdump -h tmpmoc1.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` + if [[ ${lstdims/x} != ${lstdims} ]] ; then + ncwa -O -a x tmpmoc1.nc tmpmoc1.nc + fi + ncrename -d record,x tmpmoc1.nc + ncpdq -O -h -a time,x tmpmoc1.nc tmpmoc1.nc + ncpdq -O -h -a depthw,x tmpmoc1.nc tmpmoc1.nc + ncpdq -O -h -a y,x tmpmoc1.nc tmpmoc1.nc + cdo yearmean tmpmoc1.nc tmpmoc.nc + typeset var ntime=`cdo ntime tmpmoc.nc` + typeset var list="" + for jt in $(seq 1 $ntime) ; do + cdo seltimestep,$jt tmpmoc.nc tmpmoc2.nc + cdfmaxmoc tmpmoc2.nc atl $2 $3 $4 $5 + mv maxmoc.nc maxmoc_$jt.nc + timevar=`ncdump -h maxmoc_$jt.nc | grep UNLIMITED | awk '{print $1}'` + if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time maxmoc_$jt.nc ; fi + list=${list}" "maxmoc_$jt.nc + rm -f tmpmoc2.nc + done + cdo cat $list $6 + ncks -A -v time tmpmoc.nc $6 + rm -f $list tmpmoc.nc tmpmoc1.nc +fi +} +############################################################################### +# # +# Compute the sea ice extent (1000km2), area (1000km2), volume (km3) # +# and mean thickness (m) in both hemispheres or a specified region. # +# # +# $1 : input ice file name # +# $2 : output file name ( => index ) # +# $3 : region of interest (if empty default is global) # +# # +# Created in April 2012 Author : vguemas@ic3.cat # +# Modified in June 2014 Author : neven.fuckar@ic3.cat # +# # +# Computation of the properties in various selected regions according to # +# mask.regions.${NEMOVERSION}.nc (mask_regions.nc) is based on modification # +# of mask.regions.ORCA1.noverticalinfo.Matt.nc from Matthieu Chevallier. # +# # +############################################################################### + +function siasiesiv { +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'|'Ec3.0_O25L75') 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 ;; +esac + +typeset var ntime=`cdo ntime $1` +typeset var list1="" +typeset var list2="" +typeset var jt + +if [ ! -z "$3" ] ; then + mv mask.nc mask_tmp.nc + mv mask_regions.nc mask.nc + ncrename -h -v $3,tmask mask.nc +fi + +for jt in $(seq 1 $ntime) ; do + cdo seltimestep,$jt $1 tmpice.nc + cdficediags tmpice.nc>ice.txt + for d in N S;do + ncdump toto_${d}.nc > ice_template.cdl + sia=`grep ${d}Area ice.txt |awk '{print $4}'` + sie=`grep ${d}Exnsidc ice.txt|awk '{print $4}'` + siv=`grep ${d}Volume ice.txt|awk '{print $4}'` + sed -e "s/sia =.*/sia = $sia ;/" ice_template.cdl > ice_template2.cdl + sed -e "s/sie =.*/sie = $sie ;/" ice_template2.cdl > ice_template3.cdl + sed -e "s/siv =.*/siv = $siv ;/" ice_template3.cdl > ice_template.cdl + ncgen -o ice_${d}_${jt}.nc ice_template.cdl + rm -f ice_template.cdl ice_template2.cdl ice_template3.cdl + done + list1=$list1" "ice_N_${jt}.nc + list2=$list2" "ice_S_${jt}.nc + rm -f ice.txt tmpice.nc icediags.nc +done +cdo cat $list1 ice_N_${2} +cdo cat $list2 ice_S_${2} +ncks -A -v time $1 ice_N_${2} +ncks -A -v time $1 ice_S_${2} +rm -f $list1 $list2 toto_N.nc toto_S.nc + +for d in N S;do + ncatted -O -a units,sia,m,c,1000km2 ice_${d}_${2} + ncatted -O -a units,sie,m,c,1000km2 ice_${d}_${2} + + ncks -v siv ice_${d}_${2} siv_${d}_${2}1 + ncks -v sia ice_${d}_${2} sia_${d}_${2}1 + ncrename -h -v sia,siv sia_${d}_${2}1 + ncbo -O --op_typ=dvd siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} + ncatted -O -a standard_name,siv,m,c,Mean_sea_ice_thickness sit_${d}_${2} + ncatted -O -a long_name,siv,m,c,"Mean sea ice thickness" sit_${d}_${2} + ncatted -O -a units,siv,m,c,m sit_${d}_${2} + cdo ltc,100 sit_${d}_${2} sit_${d}_${2}1 + cdo ifthenelse sit_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 + ncrename -h -v siv,sit sit_${d}_${2}2 + ncks -A sit_${d}_${2}2 ice_${d}_${2} + + rm siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 +done + +setminmax ice_N_${2} sia sie siv sit +setminmax ice_S_${2} sia sie siv sit + +if [ ! -z "$3" ] ; then + ncrename -h -v tmask,$3 mask.nc + mv mask.nc mask_regions.nc + mv mask_tmp.nc mask.nc +fi + +} +############################################################################### +# # +# Compute the total ocean heat extent # +# # +# $1 : input temperature file name # +# $2 : output file name ( => 2D x-y ) # +# $3 : basin (NAtl, NPac, TAtl, TPac, TInd, Anta, Arct, Glob) Default : Glob # +# $4 = 0 if $3 = Glob # +# $4 : mixed layer (1=only, 0=included, -1=without) Default : 0 # +# $5 : upper level of the layer (optional) Default : top # +# $6 : lower level of the layer (optional) Default : bottom # +# # +# Created in May 2012 Author : vguemas@ic3.cat # +############################################################################### + +function ohc { +cp ${CON_FILES}/depth.${NEMOVERSION}.txt depth.txt +# +# Input arguments +# +if [ -z "$3" ] ; then + typeset var basin='Glob' +else + typeset var basin=$3 +fi +if [ -z "$4" ] ; then + typeset var mxl=0 +else + typeset var mxl=$4 +fi +if [ -z "$5" ] ; then + typeset var up=1 +else + typeset var up=$5 +fi +if [ -z "$6" ] ; then + typeset var down=`cat depth.txt | wc -l` +else + typeset var down=$6 +fi + +if [[ ${up} -eq 1 ]] ; then + typeset var depmin=0 +else + typeset var depmin=`cat depth.txt |head -${up} |tail -1 | awk '{print $2}' | awk '{printf "%.0f",$1}'` +fi +typeset var depmax=`cat depth.txt |head -${down} |tail -1 | awk '{print $2}' | awk '{printf "%.0f",$1}'` + +cp ${CON_FILES}/heatc_template.nc template_heatc.nc +ncdump template_heatc.nc > template_heatc.cdl +#exec=/home/huidu/download/CDFTOOLS_2.1/cdfheatc-cfu +exec=/home/Earth/vguemas/CDFTOOLS_2.1/cdfheatc-cfu +# +# Define some parameters +# +typeset var para +typeset var output +typeset var nlev=`cat depth.txt | wc -l` +if [[ ! -z "$depmin" && ! -z "$depmax" ]] ; then + if [[ $depmin != 0 || ${down} != ${nlev} && ${down} != 0 ]] ; then + output=${depmin}-${depmax}'_' + fi +fi + +case $basin in + 'NAtl') para="atl $mxl 0 0 10 65"; output='NAtl_10N65N_'${output} ;; + 'TAtl') para="atl $mxl 0 0 -30 30" ; output='TAtl_30S30N_'${output} ;; + 'NPac') para="pac $mxl 0 0 10 70" ; output='NPac_10N70N_'${output} ;; + 'TPac') para="pac $mxl 0 0 -30 30" ; output='TPac_30S30N_'${output} ;; + 'Arct') para="atl $mxl 0 0 65 90" ; output='Arc_65N90N_'${output} ;; + 'Anta') para="all $mxl 0 0 -90 -60" ; output='Ant_90S60S_'${output} ;; + 'TInd') para="ind $mxl 0 0 -30 30" ; output='TInd_30S30N_'${output} ;; + 'Glob') para="all $mxl 0 0 0 0" ;; +esac + +case $mxl in + 1) output='mxl_'${output} ;; + -1) output='nonmxl_'${output} ;; +esac +# +# Compute ohc +# +typeset var lstvars=`cdo showvar $1` +typeset var ntime=`cdo ntime $1` +typeset var list="" +typeset var jt +for jt in $(seq 1 $ntime) ; do + cdo seltimestep,$jt $1 tmpohc.nc + lstdims=`ncdump -h tmpohc.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` + if [[ ${lstdims/x_2} != ${lstdims} ]] ; then + if [[ ${lstdims/x} != ${lstdims} ]] ; then + ncwa -O -a x tmpohc.nc tmpohc.nc + fi + ncrename -d x_2,x tmpohc.nc + fi + if [[ ${lstvars/somxl010} != ${lstvars} ]] ; then + ncks -v somxl010 tmpohc.nc mxl.nc + else + cdfmxl tmpohc.nc mxl.nc + fi + $exec tmpohc.nc $para $up $down > tmp.log + cat tmp.log + thc=`cat tmp.log | grep "Total Heat content :" | awk '{print $5}'`; + uhc=`cat tmp.log | grep "Total Heat content/volume" | awk '{print $5}'`; + sed -e "s/thc =.*/thc = $thc ;/" template_heatc.cdl > template_heatc2.cdl + sed -e "s/uhc =.*/uhc = $uhc ;/" template_heatc2.cdl > template_heatc.cdl + ncgen -o heatc_${jt}.nc template_heatc.cdl + rm -f template_heatc2.cdl tmpohc.nc mxl.nc tmp.log + list=$list" "heatc_${jt}.nc +done +cdo cat $list ${output}$2 +ncks -h -A -v time $1 ${output}$2 +rm -f $list template_heatc.nc template_heatc.cdl depth.txt +setminmax ${output}$2 thc uhc +} +############################################################################### +# # +# Cut a meridional or zonal section # +# # +# # +# $1 : input file # +# $2 : input var # +# $3 : Z/M (zonal / meridional section) # +# $4 : lat/lon # +# $5 : output file ( => 2D ) # +# # +# Created in September 2012 Author : vguemas@ic3.cat # +# # +############################################################################### + +function cutsection { + typeset var ntime=`cdo ntime $1` + typeset var nx=`ncdump -h $1|grep 'x = '|head -1|cut -f3 -d" "` + typeset var ny=`ncdump -h $1|grep 'y = '|head -1|cut -f3 -d" "` + typeset var nz=`ncdump -h $1|grep 'depth'|head -1|cut -f3 -d" "` +cat>section.R<max(lon)) {exactpos=exactpos-360} + } + # Collect the indexes defining the section + listi=array(dim=switch('$3','Z'=$nx-2,'M'=$ny-1)) + listj=array(dim=switch('$3','Z'=$nx-2,'M'=$ny-1)) + for (jpt in 1:length(listi)) { + vect=switch('$3','Z'=lat[jpt,],'M'=lon[,jpt+1]) + if (min(abs(vect-exactpos))<(2*360./$nx)) { + pos=sort(abs(vect-exactpos),index.return=T)\$ix[1] + listi[jpt]=switch('$3','Z'=jpt+1,'M'=pos) + listj[jpt]=switch('$3','Z'=pos,'M'=jpt) + } + } + listi=listi[is.na(listi)==F] + listj=listj[is.na(listj)==F] + print(listi) + print(listj) + # Select variable at those indexes + fnc1=open.ncdf('$1') + varout=array(dim=c(length(listi),$nz,$ntime)) + for (jt in 1:$ntime) { + varin=get.var.ncdf(fnc1,'$2',start=c(1,1,1,jt),count=c($nx,$ny,$nz,1)) + varin[which(mask<0.5)]=1e20 + for (jpt in 1:length(listi)) { + varout[jpt,,jt]=varin[listi[jpt],listj[jpt],] + } + } + close.ncdf(fnc1) + # Write the output + wtime=dim.def.ncdf("time","",seq(1,$ntime),unlim=TRUE) + dimout=array(dim=length(listi)) + for (jpt in 1:length(listi)) { + dimout[jpt]=switch('$3','Z'=lon[listi[jpt],listj[jpt]],'M'=lat[listi[jpt],listj[jpt]]) + } + wsec=switch('$3','Z'=dim.def.ncdf("lon","",dimout),'M'=dim.def.ncdf("lat","",dimout)) + wdep=dim.def.ncdf("deptht","",depth) + wvar=var.def.ncdf("$2","",list(wsec,wdep,wtime),1e20) + fnc2=create.ncdf('$5',wvar) + put.var.ncdf(fnc2,wvar,varout) + close.ncdf(fnc2) +EOF1 +R CMD BATCH section.R +ncks -h -A -v time $1 $5 +} +############################################################################### +# # +# 3-dimensional conservative interpolation to the regular atmospheric grid # +# # +# $1 : input file # +# $2 : input var # +# $3 : output file ( => 3D ) # +# # +# Created in November 2012 Author : vguemas@ic3.cat # +# # +############################################################################### + +function interp3d { + typeset var nz=`ncdump -h $1|grep 'deptht'|head -1|cut -f3 -d" "` + ln -sf /shared/earth/software/scripts/interpolation/scrip_use scrip_use + for lev in $(seq 1 $nz) ; do + ncks -d deptht,$((lev-1)) -v $2 $1 tmp_${lev}.nc + ncwa -O -h -a deptht tmp_${lev}.nc tmp_${lev}.nc + ln -sf /esnas/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc + cat > scrip_use_in < 2D field ) # +# # +# Created in February 2012 Author : vguemas@ic3.cat # +# Modified (more generic, +# i.e. for any input var) in December 2014 # +# Author : eleftheria.exarchou@ic3.cat # +############################################################################### + +function vertmeanvar { + typeset var ntime=`cdo ntime $1` + typeset var list="" + typeset var jt +for jt in $(seq 1 $ntime); do + ncks -d time,$((jt-1)) $1 a1 + # The oras4 data do not have gdepth data in their mask, but only gdept_0, so: + if grep -q nemovar_s4 $1 ; then + l1=$(( $3 % 6 )) + l2=$(( $4 % 6 )) + ll1=$(( $3 / 6 + 1 )) + ll2=$(( $4 / 6 + 1 )) + lev1=`echo $(cdo output -selvar,gdept_0 mesh_zgr.nc | sed -n ${ll1}p | awk '{ print $'$l1' }')` + lev2=`echo $(cdo output -selvar,gdept_0 mesh_zgr.nc | sed -n ${ll2}p | awk '{ print $'$l2' }')` + else + l1=$(($3+1)) + l2=$(($4+1)) + lev1=`echo $(cdo info -seltimestep,1 -selvar,gdept mesh_zgr.nc | sed -n ${l1}p | awk '{ print $10 }')` + lev2=`echo $(cdo info -seltimestep,1 -selvar,gdept mesh_zgr.nc | sed -n ${l2}p | awk '{ print $10 }')` + fi + cdfvertmean a1 $2 T $lev1 $lev2 + rm -f a1 + ncrename -O -v sovertmean,vertmean -d time_counter,time -v time_counter,time vertmean.nc + mv vertmean.nc outputvertmean_$jt.nc + list=$list" "outputvertmean_$jt.nc + rm -f intvertmean.nc a? +# #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN + ncatted -O -a valid_max,vertmean,d,, outputvertmean_$jt.nc outputvertmean_$jt.nc + ncatted -O -a valid_min,vertmean,d,, outputvertmean_$jt.nc outputvertmean_$jt.nc + ncatted -O -a standard_name,time,a,c,time outputvertmean_$jt.nc outputvertmean_$jt.nc + ncatted -O -a units,time,o,c,'seconds since 1993-05-01 00:00:00' outputvertmean_$jt.nc outputvertmean_$jt.nc + ncatted -O -a long_name,time,a,c,'Time axis' outputvertmean_$jt.nc outputvertmean_$jt.nc +done +cdo cat $list $5 +ncks -A -v time $1 $5 +rm -f $list +setminmax $5 vertmean +ncrename -v vertmean,$2 $5 +#typeset var level=`echo $(cdo info -selvar,$2 -setctomiss,0 $5 | sed -n 2p | awk '{ print $7 }')` +#typeset var lev=`echo $(cdo info -seltimestep,1 -selvar,$2 -setctomiss,0 $1 | grep $level | awk '{ print $1 }')` +lev=$3 +echo $lev +cp $5 tmp_${lev}.nc +## Here we interpolate horizontally onto a regular grid + ln -sf /esnas/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc + ln -sf /shared/earth/software/scripts/interpolation/scrip_use scrip_use + cat > scrip_use_in < vguemas@ic3.cat +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# +# Preparing WORKDIR and set of available functions +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export WORKDIR=/scratch/Earth/${USER}/tmp/post_ocean/$$ +mkdir -p $WORKDIR +cd $WORKDIR +source $PATHCOMMONOCEANDIAG/common_ocean_post.txt +# +# Interval of lead months be post-processed +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +case $expid in + 'nemovar_s4'|'nemovar_combine') moni=09 ; syeari=1957 ; syearf=1957 ; insdate=1 ; typeoutput='MMO' ; NEMOVERSION='nemovar_O1L42' ;; + 'glorys2v1') moni=01 ; syeari=1993 ; syearf=1993 ; insdate=1 ; typeoutput='MMO' ;; +esac +case $expid in + 'nemovar_s4') rootout='/esnas/exp/ECMWF/NEMOVAR_S4/monthly_mean' ;; + 'nemovar_combine') rootout='/esnas/exp/ECMWF/NEMOVAR_COMBINE/monthly_mean' ;; + 'glorys2v1') rootout='/esnas/exp/MERCATOR/GLORYS2V1/monthly_mean';; +esac +if [[ ${listpost[@]##max_moc} != ${listpost[@]} ]] || [[ -z "$ltimef" ]] || [[ -z "$ltime0" ]] ; then + if [[ ! -z "$year0" ]] && [[ ! -z "$yearf" ]] ; then + ltime0=$(((${year0}-${syeari})*12+1)) + ltimef=$(((${yearf}-${syeari}+1-(10#$moni+10)/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 +# ~~~~~~~~~~~~~~~~~~~~~ +if [[ $intsdate -eq 0 ]] ; then intsdate=1 ; fi # if only one start date, user might set +# intsdates to 0 which leads to an infinite loop below +for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do + # + # Interval of years to be post-processed + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + year0=$(($yeari+(10#$moni+$ltime0-2)/12)) + yearf=$(($yeari+(10#$moni+$ltimef-2)/12)) + + for memb in ${listmemb[@]} ; do + # + # Fetching the files on esnas + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + case $expid in + '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 "${list_files}" + esac + # + # Ready for the post-processing + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + for post in ${listpost[@]} ; do + + case $post in +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# You have created a function ? Enter its call right here under the flag chosen +# Remember to consider both 'MMO' and 'diags' cases +# Any doubt ---> vguemas@ic3.cat +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + 'ext_raw_oce') + if [[ $typeoutput == 'MMO' ]] ; then + lstvars=`cdo showvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc` + if [[ $raw_vars_ocean == '' ]] ; then + lstext=`echo $lstvars | sed s/\ /,/g` + else + if [[ $raw_vars_ocean == 'default' ]] ; then + lstextvar=( 'sosstsst' 'sosaline' 'somixhgt' 'somxl010' ) + lstext='' + for varex in ${lstextvar[@]} ; do + if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then + lstext=`echo ${lstext} ${varex}|sed s/\ /,/g` + fi + done + else + lstext=`echo ${raw_vars_ocean[@]} |sed s/\ /,/g` + fi + fi + if [ -z "$lstext" ] ; then + echo "The list of variables you wish to extract is not in your outputs" + exit 1 + else + ncks -O -v ${lstext} grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc +# ncks -O -v ${lstext[@]} grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'ext_raw_ice') + if [[ $typeoutput == 'MMO' ]] ; then + lstvars=`cdo showvar icemod_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc` + if [[ $raw_vars_ice == '' ]] ; then + lstext=`echo $lstvars | sed s/\ /,/g` + else + if [[ $raw_vars_ice == 'default' ]] ; then + lstextvar=( 'isnowthi' 'iicethic' 'ileadfra' 'iicetemp' 'ice_pres' ) + lstext='' + for varex in ${lstextvar[@]} ; do + if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then + lstext=`echo ${lstext} ${varex}|sed s/\ /,/g` + fi + done + else + lstext=`echo $raw_vars_ice |sed s/\ /,/g` + fi + fi + if [ -z "$lstext" ] ; then + echo "The list of variables you wish to extract is not in your outputs" + exit 1 + else + ncks -O -v ${lstext} icemod_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ice_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'heat_sal_mxl') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f heat_sal_mxl_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + heat_sal_mxl grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc heat_sal_mxl_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'psi') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + psi grid_U_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc grid_V_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'gyres') + gyres psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $NEMOVERSION gyres_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + + 'lmsalc') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f sal_300-5400m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + vertmeansal grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 300 5400 sal_300-5400m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'usalc') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f sal_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + vertmeansal grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0 300 sal_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + + 'temp_lev') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f temp_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + vertmeanvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper $level1 $level2 temp_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + + 'sal_lev') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f sal_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + vertmeanvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline $level1 $level2 sal_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'ohc_specified_layer') + if [ ! -f ohc_2d_avg_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then + case $typeoutput in + 'MMO' ) pref='grid_T' ;; + 'diags') pref='t3d' ;; + esac + ohc_specified_layer ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 300.0 ohc_2d_avg_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ohc_specified_layer ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 300.0 800.0 ohc_2d_avg_300-800m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + + 'vert_Tsections') + case $typeoutput in + 'MMO' ) pref='grid_T' ;; + 'diags') pref='t3d' ;; + esac + for coord in 0 45 -45 -30 180 80 + do + if [[ $coord == '0' ]] || [[ $coord == '45' ]] || [[ $coord == '-45' ]] ; then + [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=S || direction=N + z_m=Z + else + [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=W || direction=E + z_m=M + fi + coord=`echo $coord | sed -e s/-//g` + [ ! -f temp_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cutsection ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper $z_m $coord temp_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + done + + ;; + + 'vert_Ssections') + if [[ $typeoutput == 'MMO' ]] ; then + pref='grid_T' + for coord in 0 45 -45 -30 180 80 + do + if [[ $coord == '0' ]] || [[ $coord == '45' ]] || [[ $coord == '-45' ]] ; then + [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=S || direction=N + z_m=Z + else + [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=W || direction=E + z_m=M + fi + coord=`echo $coord | sed -e s/-//g` + [ ! -f sal_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cutsection ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline $z_m $coord sal_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + done + fi + ;; + '3dtemp') + case $typeoutput in + 'MMO' ) pref='grid_T' ;; + 'diags') pref='t3d' ;; + esac + if [ ! -f regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]; then + echo " Warning: you are about to perform a 3d interpolation " + [ $warning_T ] && echo "(because you asked for cross sections calculations)" + echo "this might take time to complete (~days), be sure you really need/want to do this..." + interp3d ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + '3dsal') + if [[ $typeoutput == 'MMO' ]] ; then + pref='grid_T' + if [ ! -f regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]; then + echo " Warning: you are about to perform a 3d interpolation " + [ $warning_S ] && echo "(because you asked for cross sections calculations)" + echo "this might take time to complete (~days), be sure you really need/want to do this..." + interp3d ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'TSec_ave190-220E') + [ ! -f TSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cdo zonmean -sellonlatbox,190,220,-90,90 regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc TSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + 'SSec_ave190-220E') + if [[ $typeoutput == 'MMO' ]] ; then + [ ! -f SSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cdo zonmean -sellonlatbox,190,220,-90,90 regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc SSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + + 'moc') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + moc grid_V_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'max_moc') + max_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 38 50 500 2000 max_moc_38N50N_500m-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + max_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 40 40 0 10000 max_moc_40N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + + 'stc') + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 25.0 NPac_stc_0N25N_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 zomsfpac + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -25.0 0.0 SPac_stc_25S0S_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 zomsfpac + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 25.0 NAtl_stc_0N25N_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -25.0 0.0 SAtl_stc_25S0S_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 + ;; + + 'area_moc') + if [ ! -f moc_40N55N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 40.0 55.0 moc_40N55N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + if [ ! -f moc_30N40N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 30.0 40.0 moc_30N40N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + + 'convection') + convection oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $NEMOVERSION convection_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + + 'siasiesiv' ) + + if [ ! -f siasiesiv_N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]||[ ! -f siasiesiv_S_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then #check if ? instead of N or S works + case $typeoutput in + 'MMO' ) pref='icemod' ;; + 'diags') pref='ice' ;; + esac + siasiesiv ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc tmp.nc + mv ice_N_tmp.nc siasiesiv_N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + mv ice_S_tmp.nc siasiesiv_S_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + + 'siasiesivsit_Arcticreg1') + + case $typeoutput in + 'MMO' ) pref='icemod' ;; + 'diags') pref='ice' ;; + esac + + if [[ $raw_regions_ice == '' ]] ; then + lstseas=$( cdo showvar mask_regions.nc ) + else + if [[ $raw_regions_ice == 'default' ]] ; then + lstseas="Baffin_Bay Baltic_Sea Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea CntArctic CntArcticRing1 CntArcticRing2 CntArcticRing3 CntArcticRing4 CntArcticRing5 CntArcticRing6 CntArcticRing7_Lincoln_Sea CntArcticRing8 CntArcticPrf1 CntArcticPrf2r CntArcticPrf3 CntArcticPrf4 East_Siberian_Sea1 Greenland_Sea Hudson Icelandic_Sea Irminger Japan1 Kara_Sea Laptev_Sea Labrador_Sea1 Norwegian_Sea Okhotsk StLawr" + else + lstseas=$( echo ${raw_regions_ice[@]} ) + fi + fi + + for sea in $lstseas ; do + + siasiesiv ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc tmp.nc $sea + + ncks -v sia ice_N_tmp.nc sia_N_tmp.nc + ncks -v sie ice_N_tmp.nc sie_N_tmp.nc + ncks -v siv ice_N_tmp.nc siv_N_tmp.nc + ncks -v sit ice_N_tmp.nc sit_N_tmp.nc + + ncrename -h -v sia,sia_$sea sia_N_tmp.nc + ncrename -h -v sie,sie_$sea sie_N_tmp.nc + ncrename -h -v siv,siv_$sea siv_N_tmp.nc + ncrename -h -v sit,sit_$sea sit_N_tmp.nc + + if [ -e sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + ncks -A sia_N_tmp.nc sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ncks -A sie_N_tmp.nc sie_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ncks -A siv_N_tmp.nc siv_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ncks -A sit_N_tmp.nc sit_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + rm -f sia_N_tmp.nc sie_N_tmp.nc siv_N_tmp.nc sit_N_tmp.nc ice_N_tmp.nc ice_S_tmp.nc + else + mv sia_N_tmp.nc sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + mv sie_N_tmp.nc sie_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + mv siv_N_tmp.nc siv_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + mv sit_N_tmp.nc sit_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + rm -f ice_N_tmp.nc ice_S_tmp.nc + fi + + done + ;; + + esac + + case `echo $post|cut -c$((${#post}-2))-${#post}` in + 'ohc') + case `echo $post | cut -c1` in + 'x') kmin=0 ; kmax=0 ; start=2 ; mxl=1 ;; + 'l') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmin=25 ; kmax=42 ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmin=23 ; kmax=46 ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmin=45; kmax=75;; + esac + ;; + 'm') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmin=21 ; kmax=24 ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmin=18 ; kmax=22 ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmin=35; kmax=44;; + esac + ;; + 'u') kmin=1 ; start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmax=20 ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmax=17 ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmax=34;; + esac + ;; + *) kmin="" ; kmax="" ; start=1 ; mxl=0 ;; + esac + case `echo $post | cut -c${start}-$((start+3))` in + 'ohc') basin='Glob' ;; + *) basin=`echo $post | cut -c${start}-$((start+3))` + esac + case $typeoutput in + 'MMO' ) pref='grid_T' ;; + 'diags') + pref='t3d' + ncks -A -v somxl010,somixhgt oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc t3d_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + esac + ohc ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc heatc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $basin $mxl $kmin $kmax + ;; + esac + + ipcs -m + done + + # Removing the raw output from this start dates and this member + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + clean_diagsMMO ${yeari}${moni}01 ${expid} ${memb} $ltime0 $ltimef $typeoutput "${list_files}" + done + + # Prepare storage : choose output directory and file name + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + for post in ${listpost[@]} ; do + case $post in +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# You have created a function ? Enter the output directory and the prefix +# or your(s) output files under the flag chosen +# Any doubt ---> vguemas@ic3.cat +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + 'area_moc') dirout='moc'; files=('moc_40N55N_1-2km' 'moc_30N40N_1-2km') ;; + 'stc') dirout='moc' ; files=( 'NPac_stc_0N25N_0-200m' 'SPac_stc_25S0S_0-200m' 'NAtl_stc_0N25N_0-200m' 'SAtl_stc_25S0S_0-200m' ) ;; + 'max_moc') dirout='moc' ; files=('max_moc_38N50N_500m-2km' 'max_moc_40N' ) ;; + 'siasiesiv' ) dirout='ice' ; files=('siasiesiv_N' 'siasiesiv_S') ;; + 'siasiesivsit_Arcticreg1' ) dirout='ice' ; files=('sia_Arcticreg1' 'sie_Arcticreg1' 'siv_Arcticreg1' 'sit_Arcticreg1') ;; + 'moc') dirout='moc' ; files=('moc') ;; + 'convection') dirout='moc' ; files=('convection') ;; +# 'ext_raw_ice') dirout='ice' ; files=('ice_raw') ;; +# 'ext_raw_oce') dirout='oce_raw' ; files=('oce_raw') ;; + 'ext_raw_ice') dirout='ice' ; files=('ice') ;; + 'ext_raw_oce') dirout='oce' ; files=('oce') ;; + 'heat_sal_mxl') dirout='heatc' ; files=('heat_sal_mxl') ;; + 'psi') dirout='psi' ; files=('psi') ;; + 'gyres') dirout='psi' ; files=('gyres') ;; + 'usalc') dirout='saltc' ; files=('sal_0-300m') ;; + 'temp_lev') dirout='temp_lev'${level1}-${level2} ; files=('temp_lev'${level1}-${level2}) ;; + 'sal_lev') dirout='sal_lev'${level1}-${level2} ; files=('sal_lev'${level1}-${level2}) ;; + 'lmsalc') dirout='saltc' ; files=('sal_300-5400m') ;; + 'ohc_specified_layer') dirout='heatc' ; files=('ohc_2d_avg_0-300m' 'ohc_2d_avg_300-800m') ;; + 'vert_Tsections') dirout='sections' ; files=('temp_0N' 'temp_45N' 'temp_45S' 'temp_30W' 'temp_80E' 'temp_180E') ;; + 'vert_Ssections') dirout='sections' ; files=('sal_0N' 'sal_45N' 'sal_45S' 'sal_30W' 'sal_80E' 'sal_180E') ;; + '3dtemp') dirout='InterpT' ; files=('regular3dT') ;; + '3dsal') dirout='InterpS' ; files=('regular3dS') ;; + 'TSec_ave190-220E') dirout='sections' ; files=('TSec_ave190-220E') ;; + 'SSec_ave190-220E') dirout='sections' ; files=('SSec_ave190-220E') ;; + esac + case `echo $post|cut -c$((${#post}-2))-${#post}` in + 'ohc') + dirout='heatc' + file='heatc' + case `echo $post | cut -c1` in + 'x') mxl=1 ; start=2 ;; + 'l') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='800-5350_'${file} ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='855-5875_'${file} ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='857-5902_'${file};; + esac + ;; + 'm') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='373-657_'${file} ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='382-735_'${file} ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='301-773_'${file};; + esac + ;; + 'u') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='0-315_'${file} ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='0-322_'${file} ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='0-271_'${file};; + esac + ;; + *) mxl=0 ; start=1 ;; + esac + + case `echo $post | cut -c${start}-$((start+3))` in + 'NAtl') file='NAtl_10N65N_'${file} ;; + 'TAtl') file='TAtl_30S30N_'${file};; + 'NPac') file='NPac_10N70N_'${file} ;; + 'TPac') file='TPac_30S30N_'${file} ;; + 'Arct') file='Arc_65N90N_'${file} ;; + 'Anta') file='Ant_90S60S_'${file} ;; + 'TInd') file='TInd_30S30N_'${file} ;; + esac + if [[ $mxl == 1 ]] ; then + file='mxl_'$file + fi + files=( $file ) + esac + pathout=${rootout}/${dirout} + mkdir -m ug+w -m o-w -p $pathout + for file in ${files[@]} ; do + prefix=${file}_${expid}_${yeari}${moni}01_fc + lsmbso=0-${listmemb[${#listmemb[@]}-1]} + # + # Merging the post-processed members together and with the previous members if existing + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + lsyrsh=${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + lsmbsh=${listmemb[0]}-${listmemb[${#listmemb[@]}-1]} + lsmbsb=0-$((${listmemb[0]}-1)) + if [ -e ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ] ; then + cp ${pathout}/${prefix}${lsmbsb}_${lsyrsh} . + lsmbsh=0-${listmemb[${#listmemb[@]}-1]} + fi + gather_memb ${prefix} _${lsyrsh} ${prefix}${lsmbsh}_${lsyrsh} + for jmemb in ${listmemb[@]} ; do + rm -f ${prefix}${jmemb}_${lsyrsh} + done + # + # Concatenating the result with the previous years if existing + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# You have created a function ? If your diagnostic provides yearly output +# you need to use the concat option rather than the ncrcat one below. +# Any doubt ---> vguemas@ic3.cat +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + lsyrsb=${yeari}${moni}_$((year0-(1-(10#$moni+10)/12)))$(printf "%02d" $(((mon0-13)%12+12)) ).nc + lsyrso=${yeari}${moni}_${yearf}$(printf "%02d" ${monf}).nc + if [ -e ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ] ; then + case $post in + 'max_moc' ) concat ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrsh} $(printf "%02d" ${monf}) ${prefix}${lsmbsh}_${lsyrso} ;; + *) ncrcat -O ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrsh} ${prefix}${lsmbsh}_${lsyrso} ;; + esac + else + lsyrso=$lsyrsh + fi + # + # Merging the result with the previous members if existing + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if [[ $lsyrsh != $lsyrso ]] && [[ -e ${pathout}/${prefix}${lsmbsb}_${lsyrso} ]] ; then + cp ${pathout}/${prefix}${lsmbsb}_${lsyrso} . + gather_memb ${prefix} _${lsyrso} ${prefix}${lsmbso}_${lsyrso} + else + lsmbso=$lsmbsh + fi + # + # Storing and cleaning + # ~~~~~~~~~~~~~~~~~~~~~ + cp ${prefix}${lsmbso}_${lsyrso} ${pathout}/. || { if [ -e ${pathout}/${prefix}${lsmbso}_${lsyrso} ]; + then + echo "${prefix}${lsmbso}_${lsyrso} already exists in ${pathout}" + sleep 5 + else + echo " problem writing file in ${pathout} directory" + exit + fi + } + rm -f ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrso} ${prefix}${lsmbsb}_${lsyrso} ${pathout}/${prefix}${lsmbsb}_${lsyrso} ${prefix}${lsmbso}_${lsyrso} ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ${prefix}${lsmbsb}_${lsyrsh} + done + done +done + +trap - EXIT +rm -rf $WORKDIR diff --git a/save/ocean_pp.bash.oriol b/save/ocean_pp.bash.oriol new file mode 100755 index 0000000..c647008 --- /dev/null +++ b/save/ocean_pp.bash.oriol @@ -0,0 +1,647 @@ +#!/bin/bash +set -evx + +module load CDFTOOLS/2.1-foss-2015a + +function delete { +at now +7 days << EOF +rm -rf $WORKDIR +EOF +} + + +msg='Your experiment crashed! Your workdir \($WORKDIR\) will be kept for one week from now and then deleted' +trap "echo $msg ; delete ; exit" SIGINT SIGHUP SIGTERM SIGSEGV SIGKILL EXIT + +################################# +#### User Defined Funtions #### +################################# + + + + +# check if args are ok and read options in config_file + + if [ $# -ne 1 ] ; then + echo + echo "USAGE: config_file " + echo "For example: ./ocean_pp.new.bash /home/Earth/$user/es_git/ocean_diagnostics/config_file " + echo + exit 1 + fi + +config_file=$1 +. ${config_file} + +list_files='grid_T' +if [[ ${listpost[@]} =~ "psi" ]] ; then + echo "The list of diags require grid_U" + list_files=$(echo ${list_files} grid_U) +fi + +if [[ ${listpost[@]} =~ "moc" ]] ; then + echo "The list of diags require grid_V" + list_files=$(echo ${list_files} grid_V) +fi +if [[ ${listpost[@]} =~ "ice" ]] || [[ ${listpost[@]} =~ "siasiesiv" ]]; then + echo "The list of diags contains ice" + list_files=$(echo ${list_files} icemod) +fi + +############################################################################### +# +# moc needs to be computed before max_moc and area_moc +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +if [[ ${listpost[@]##*moc*} != ${listpost[@]} ]] || [[ ${listpost[@]##*stc*} != ${listpost[@]} ]] ; then + if [[ ${listpost[@]#moc} != ${listpost[@]:1} ]] ; then + listpost=( 'moc' "${listpost[@]#moc}" ) + fi +fi +# +# psi needs to be computed before gyres +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +if [[ ${listpost[@]##*gyres*} != ${listpost[@]} ]] ; then + if [[ ${listpost[@]#psi} != ${listpost[@]:1} ]] ; then + listpost=( 'psi' "${listpost[@]#psi}" ) + fi +fi +# +# oce raw outputs need to be extracted before convection option +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +if [[ ${listpost[@]##*convection*} != ${listpost[@]} ]] ; then + if [[ ${listpost[@]#ext_raw_oce} != ${listpost[@]:1} ]] ; then + listpost=( 'ext_raw_oce' "${listpost[@]#ext_raw_oce}" ) + fi +fi +# +# 3d interpolation required before average T sections over longitudes +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +if [[ ${listpost[@]##TSec_ave*} != ${listpost[@]} ]] ; then + if [[ ${listpost[@]#3dtemp} != ${listpost[@]:1} ]] ; then + listpost=( '3dtemp' "${listpost[@]#3dtemp}" ) + warning_T=.true. + fi +fi +if [[ ${listpost[@]##SSec_ave*} != ${listpost[@]} ]] ; then + if [[ ${listpost[@]#3dsal} != ${listpost[@]:1} ]] ; then + listpost=( '3dsal' "${listpost[@]#3dsal}" ) + warning_S=.true. + fi +fi +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# You have created a function ? If your new diagnostic relies on an already +# existing diagnotics, you might need similar lignes to the above ones +# Any doubt ---> vguemas@ic3.cat +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# +# Preparing WORKDIR and set of available functions +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export WORKDIR=/scratch/Earth/${USER}/tmp/post_ocean/$$ +mkdir -p $WORKDIR +cd $WORKDIR +source $PATHCOMMONOCEANDIAG/common_ocean_post.txt +# +# Interval of lead months be post-processed +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +case $expid in + 'nemovar_s4'|'nemovar_combine') moni=09 ; syeari=1957 ; syearf=1957 ; insdate=1 ; typeoutput='MMO' ; NEMOVERSION='nemovar_O1L42' ;; + 'glorys2v1') moni=01 ; syeari=1993 ; syearf=1993 ; insdate=1 ; typeoutput='MMO' ;; +esac +case $expid in + 'nemovar_s4') rootout='/esnas/exp/ECMWF/NEMOVAR_S4/monthly_mean' ;; + 'nemovar_combine') rootout='/esnas/exp/ECMWF/NEMOVAR_COMBINE/monthly_mean' ;; + 'glorys2v1') rootout='/esnas/exp/MERCATOR/GLORYS2V1/monthly_mean';; +esac +if [[ ${listpost[@]##max_moc} != ${listpost[@]} ]] || [[ -z "$ltimef" ]] || [[ -z "$ltime0" ]] ; then + if [[ ! -z "$year0" ]] && [[ ! -z "$yearf" ]] ; then + ltime0=$(((${year0}-${syeari})*12+1)) + ltimef=$(((${yearf}-${syeari}+1-(10#$moni+10)/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 +# ~~~~~~~~~~~~~~~~~~~~~ +if [[ $intsdate -eq 0 ]] ; then intsdate=1 ; fi # if only one start date, user might set +# intsdates to 0 which leads to an infinite loop below +for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do + # + # Interval of years to be post-processed + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + year0=$(($yeari+(10#$moni+$ltime0-2)/12)) + yearf=$(($yeari+(10#$moni+$ltimef-2)/12)) + + for memb in ${listmemb[@]} ; do + # + # Fetching the files on esnas + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + case $expid in + '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 "${list_files}" + esac + # + # Ready for the post-processing + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + for post in ${listpost[@]} ; do + + case $post in +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# You have created a function ? Enter its call right here under the flag chosen +# Remember to consider both 'MMO' and 'diags' cases +# Any doubt ---> vguemas@ic3.cat +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + 'ext_raw_oce') + if [[ $typeoutput == 'MMO' ]] ; then + lstvars=`cdo showvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc` + if [[ $raw_vars_ocean == '' ]] ; then + lstext=`echo $lstvars | sed s/\ /,/g` + else + if [[ $raw_vars_ocean == 'default' ]] ; then + lstextvar=( 'sosstsst' 'sosaline' 'somixhgt' 'somxl010' ) + lstext='' + for varex in ${lstextvar[@]} ; do + if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then + lstext=`echo ${lstext} ${varex}|sed s/\ /,/g` + fi + done + else + lstext=`echo ${raw_vars_ocean[@]} |sed s/\ /,/g` + fi + fi + if [ -z "$lstext" ] ; then + echo "The list of variables you wish to extract is not in your outputs" + exit 1 + else + ncks -O -v ${lstext} grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc +# ncks -O -v ${lstext[@]} grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'ext_raw_ice') + if [[ $typeoutput == 'MMO' ]] ; then + lstvars=`cdo showvar icemod_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc` + if [[ $raw_vars_ice == '' ]] ; then + lstext=`echo $lstvars | sed s/\ /,/g` + else + if [[ $raw_vars_ice == 'default' ]] ; then + lstextvar=( 'isnowthi' 'iicethic' 'ileadfra' 'iicetemp' 'ice_pres' ) + lstext='' + for varex in ${lstextvar[@]} ; do + if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then + lstext=`echo ${lstext} ${varex}|sed s/\ /,/g` + fi + done + else + lstext=`echo $raw_vars_ice |sed s/\ /,/g` + fi + fi + if [ -z "$lstext" ] ; then + echo "The list of variables you wish to extract is not in your outputs" + exit 1 + else + ncks -O -v ${lstext} icemod_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ice_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'heat_sal_mxl') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f heat_sal_mxl_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + heat_sal_mxl grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc heat_sal_mxl_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'psi') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + psi grid_U_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc grid_V_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'gyres') + gyres psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $NEMOVERSION gyres_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + + 'lmsalc') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f sal_300-5400m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + vertmeansal grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 300 5400 sal_300-5400m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'usalc') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f sal_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + vertmeansal grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0 300 sal_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + + 'temp_lev') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f temp_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + vertmeanvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper $level1 $level2 temp_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + + 'sal_lev') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f sal_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + vertmeanvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline $level1 $level2 sal_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'ohc_specified_layer') + if [ ! -f ohc_2d_avg_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then + case $typeoutput in + 'MMO' ) pref='grid_T' ;; + 'diags') pref='t3d' ;; + esac + ohc_specified_layer ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 300.0 ohc_2d_avg_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ohc_specified_layer ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 300.0 800.0 ohc_2d_avg_300-800m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + + 'vert_Tsections') + case $typeoutput in + 'MMO' ) pref='grid_T' ;; + 'diags') pref='t3d' ;; + esac + for coord in 0 45 -45 -30 180 80 + do + if [[ $coord == '0' ]] || [[ $coord == '45' ]] || [[ $coord == '-45' ]] ; then + [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=S || direction=N + z_m=Z + else + [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=W || direction=E + z_m=M + fi + coord=`echo $coord | sed -e s/-//g` + [ ! -f temp_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cutsection ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper $z_m $coord temp_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + done + + ;; + + 'vert_Ssections') + if [[ $typeoutput == 'MMO' ]] ; then + pref='grid_T' + for coord in 0 45 -45 -30 180 80 + do + if [[ $coord == '0' ]] || [[ $coord == '45' ]] || [[ $coord == '-45' ]] ; then + [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=S || direction=N + z_m=Z + else + [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=W || direction=E + z_m=M + fi + coord=`echo $coord | sed -e s/-//g` + [ ! -f sal_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cutsection ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline $z_m $coord sal_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + done + fi + ;; + '3dtemp') + case $typeoutput in + 'MMO' ) pref='grid_T' ;; + 'diags') pref='t3d' ;; + esac + if [ ! -f regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]; then + echo " Warning: you are about to perform a 3d interpolation " + [ $warning_T ] && echo "(because you asked for cross sections calculations)" + echo "this might take time to complete (~days), be sure you really need/want to do this..." + interp3d ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + '3dsal') + if [[ $typeoutput == 'MMO' ]] ; then + pref='grid_T' + if [ ! -f regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]; then + echo " Warning: you are about to perform a 3d interpolation " + [ $warning_S ] && echo "(because you asked for cross sections calculations)" + echo "this might take time to complete (~days), be sure you really need/want to do this..." + interp3d ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'TSec_ave190-220E') + [ ! -f TSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cdo zonmean -sellonlatbox,190,220,-90,90 regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc TSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + 'SSec_ave190-220E') + if [[ $typeoutput == 'MMO' ]] ; then + [ ! -f SSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cdo zonmean -sellonlatbox,190,220,-90,90 regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc SSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + + 'moc') + if [[ $typeoutput == 'MMO' ]] ; then + if [ ! -f moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + moc grid_V_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + fi + ;; + + 'max_moc') + max_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 38 50 500 2000 max_moc_38N50N_500m-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + max_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 40 40 0 10000 max_moc_40N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + + 'stc') + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 25.0 NPac_stc_0N25N_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 zomsfpac + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -25.0 0.0 SPac_stc_25S0S_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 zomsfpac + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 25.0 NAtl_stc_0N25N_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -25.0 0.0 SAtl_stc_25S0S_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 + ;; + + 'area_moc') + if [ ! -f moc_40N55N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 40.0 55.0 moc_40N55N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + if [ ! -f moc_30N40N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then + area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 30.0 40.0 moc_30N40N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + + 'convection') + convection oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $NEMOVERSION convection_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + + 'siasiesiv' ) + + if [ ! -f siasiesiv_N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]||[ ! -f siasiesiv_S_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then #check if ? instead of N or S works + case $typeoutput in + 'MMO' ) pref='icemod' ;; + 'diags') pref='ice' ;; + esac + siasiesiv ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc tmp.nc + mv ice_N_tmp.nc siasiesiv_N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + mv ice_S_tmp.nc siasiesiv_S_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + fi + ;; + + 'siasiesivsit_Arcticreg1') + + case $typeoutput in + 'MMO' ) pref='icemod' ;; + 'diags') pref='ice' ;; + esac + + if [[ $raw_regions_ice == '' ]] ; then + lstseas=$( cdo showvar mask_regions.nc ) + else + if [[ $raw_regions_ice == 'default' ]] ; then + lstseas="Baffin_Bay Baltic_Sea Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea CntArctic CntArcticRing1 CntArcticRing2 CntArcticRing3 CntArcticRing4 CntArcticRing5 CntArcticRing6 CntArcticRing7_Lincoln_Sea CntArcticRing8 CntArcticPrf1 CntArcticPrf2r CntArcticPrf3 CntArcticPrf4 East_Siberian_Sea1 Greenland_Sea Hudson Icelandic_Sea Irminger Japan1 Kara_Sea Laptev_Sea Labrador_Sea1 Norwegian_Sea Okhotsk StLawr" + else + lstseas=$( echo ${raw_regions_ice[@]} ) + fi + fi + + for sea in $lstseas ; do + + siasiesiv ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc tmp.nc $sea + + ncks -v sia ice_N_tmp.nc sia_N_tmp.nc + ncks -v sie ice_N_tmp.nc sie_N_tmp.nc + ncks -v siv ice_N_tmp.nc siv_N_tmp.nc + ncks -v sit ice_N_tmp.nc sit_N_tmp.nc + + ncrename -h -v sia,sia_$sea sia_N_tmp.nc + ncrename -h -v sie,sie_$sea sie_N_tmp.nc + ncrename -h -v siv,siv_$sea siv_N_tmp.nc + ncrename -h -v sit,sit_$sea sit_N_tmp.nc + + if [ -e sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then + ncks -A sia_N_tmp.nc sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ncks -A sie_N_tmp.nc sie_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ncks -A siv_N_tmp.nc siv_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ncks -A sit_N_tmp.nc sit_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + rm -f sia_N_tmp.nc sie_N_tmp.nc siv_N_tmp.nc sit_N_tmp.nc ice_N_tmp.nc ice_S_tmp.nc + else + mv sia_N_tmp.nc sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + mv sie_N_tmp.nc sie_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + mv siv_N_tmp.nc siv_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + mv sit_N_tmp.nc sit_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + rm -f ice_N_tmp.nc ice_S_tmp.nc + fi + + done + ;; + + esac + + case `echo $post|cut -c$((${#post}-2))-${#post}` in + 'ohc') + case `echo $post | cut -c1` in + 'x') kmin=0 ; kmax=0 ; start=2 ; mxl=1 ;; + 'l') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmin=25 ; kmax=42 ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmin=23 ; kmax=46 ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmin=45; kmax=75;; + esac + ;; + 'm') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmin=21 ; kmax=24 ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmin=18 ; kmax=22 ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmin=35; kmax=44;; + esac + ;; + 'u') kmin=1 ; start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmax=20 ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmax=17 ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmax=34;; + esac + ;; + *) kmin="" ; kmax="" ; start=1 ; mxl=0 ;; + esac + case `echo $post | cut -c${start}-$((start+3))` in + 'ohc') basin='Glob' ;; + *) basin=`echo $post | cut -c${start}-$((start+3))` + esac + case $typeoutput in + 'MMO' ) pref='grid_T' ;; + 'diags') + pref='t3d' + ncks -A -v somxl010,somixhgt oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc t3d_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + ;; + esac + ohc ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc heatc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $basin $mxl $kmin $kmax + ;; + esac + + ipcs -m + done + + # Removing the raw output from this start dates and this member + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + clean_diagsMMO ${yeari}${moni}01 ${expid} ${memb} $ltime0 $ltimef $typeoutput "${list_files}" + done + + # Prepare storage : choose output directory and file name + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + for post in ${listpost[@]} ; do + case $post in +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# You have created a function ? Enter the output directory and the prefix +# or your(s) output files under the flag chosen +# Any doubt ---> vguemas@ic3.cat +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + 'area_moc') dirout='moc'; files=('moc_40N55N_1-2km' 'moc_30N40N_1-2km') ;; + 'stc') dirout='moc' ; files=( 'NPac_stc_0N25N_0-200m' 'SPac_stc_25S0S_0-200m' 'NAtl_stc_0N25N_0-200m' 'SAtl_stc_25S0S_0-200m' ) ;; + 'max_moc') dirout='moc' ; files=('max_moc_38N50N_500m-2km' 'max_moc_40N' ) ;; + 'siasiesiv' ) dirout='ice' ; files=('siasiesiv_N' 'siasiesiv_S') ;; + 'siasiesivsit_Arcticreg1' ) dirout='ice' ; files=('sia_Arcticreg1' 'sie_Arcticreg1' 'siv_Arcticreg1' 'sit_Arcticreg1') ;; + 'moc') dirout='moc' ; files=('moc') ;; + 'convection') dirout='moc' ; files=('convection') ;; +# 'ext_raw_ice') dirout='ice' ; files=('ice_raw') ;; +# 'ext_raw_oce') dirout='oce_raw' ; files=('oce_raw') ;; + 'ext_raw_ice') dirout='ice' ; files=('ice') ;; + 'ext_raw_oce') dirout='oce' ; files=('oce') ;; + 'heat_sal_mxl') dirout='heatc' ; files=('heat_sal_mxl') ;; + 'psi') dirout='psi' ; files=('psi') ;; + 'gyres') dirout='psi' ; files=('gyres') ;; + 'usalc') dirout='saltc' ; files=('sal_0-300m') ;; + 'temp_lev') dirout='temp_lev'${level1}-${level2} ; files=('temp_lev'${level1}-${level2}) ;; + 'sal_lev') dirout='sal_lev'${level1}-${level2} ; files=('sal_lev'${level1}-${level2}) ;; + 'lmsalc') dirout='saltc' ; files=('sal_300-5400m') ;; + 'ohc_specified_layer') dirout='heatc' ; files=('ohc_2d_avg_0-300m' 'ohc_2d_avg_300-800m') ;; + 'vert_Tsections') dirout='sections' ; files=('temp_0N' 'temp_45N' 'temp_45S' 'temp_30W' 'temp_80E' 'temp_180E') ;; + 'vert_Ssections') dirout='sections' ; files=('sal_0N' 'sal_45N' 'sal_45S' 'sal_30W' 'sal_80E' 'sal_180E') ;; + '3dtemp') dirout='InterpT' ; files=('regular3dT') ;; + '3dsal') dirout='InterpS' ; files=('regular3dS') ;; + 'TSec_ave190-220E') dirout='sections' ; files=('TSec_ave190-220E') ;; + 'SSec_ave190-220E') dirout='sections' ; files=('SSec_ave190-220E') ;; + esac + case `echo $post|cut -c$((${#post}-2))-${#post}` in + 'ohc') + dirout='heatc' + file='heatc' + case `echo $post | cut -c1` in + 'x') mxl=1 ; start=2 ;; + 'l') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='800-5350_'${file} ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='855-5875_'${file} ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='857-5902_'${file};; + esac + ;; + 'm') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='373-657_'${file} ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='382-735_'${file} ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='301-773_'${file};; + esac + ;; + 'u') start=2 ; mxl=0 + case $NEMOVERSION in + 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='0-315_'${file} ;; + 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='0-322_'${file} ;; + 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='0-271_'${file};; + esac + ;; + *) mxl=0 ; start=1 ;; + esac + + case `echo $post | cut -c${start}-$((start+3))` in + 'NAtl') file='NAtl_10N65N_'${file} ;; + 'TAtl') file='TAtl_30S30N_'${file};; + 'NPac') file='NPac_10N70N_'${file} ;; + 'TPac') file='TPac_30S30N_'${file} ;; + 'Arct') file='Arc_65N90N_'${file} ;; + 'Anta') file='Ant_90S60S_'${file} ;; + 'TInd') file='TInd_30S30N_'${file} ;; + esac + if [[ $mxl == 1 ]] ; then + file='mxl_'$file + fi + files=( $file ) + esac + pathout=${rootout}/${dirout} + mkdir -m ug+w -m o-w -p $pathout + for file in ${files[@]} ; do + prefix=${file}_${expid}_${yeari}${moni}01_fc + lsmbso=0-${listmemb[${#listmemb[@]}-1]} + # + # Merging the post-processed members together and with the previous members if existing + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + lsyrsh=${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc + lsmbsh=${listmemb[0]}-${listmemb[${#listmemb[@]}-1]} + lsmbsb=0-$((${listmemb[0]}-1)) + if [ -e ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ] ; then + cp ${pathout}/${prefix}${lsmbsb}_${lsyrsh} . + lsmbsh=0-${listmemb[${#listmemb[@]}-1]} + fi + gather_memb ${prefix} _${lsyrsh} ${prefix}${lsmbsh}_${lsyrsh} + for jmemb in ${listmemb[@]} ; do + rm -f ${prefix}${jmemb}_${lsyrsh} + done + # + # Concatenating the result with the previous years if existing + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +# You have created a function ? If your diagnostic provides yearly output +# you need to use the concat option rather than the ncrcat one below. +# Any doubt ---> vguemas@ic3.cat +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ + lsyrsb=${yeari}${moni}_$((year0-(1-(10#$moni+10)/12)))$(printf "%02d" $(((mon0-13)%12+12)) ).nc + lsyrso=${yeari}${moni}_${yearf}$(printf "%02d" ${monf}).nc + if [ -e ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ] ; then + case $post in + 'max_moc' ) concat ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrsh} $(printf "%02d" ${monf}) ${prefix}${lsmbsh}_${lsyrso} ;; + *) ncrcat -O ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrsh} ${prefix}${lsmbsh}_${lsyrso} ;; + esac + else + lsyrso=$lsyrsh + fi + # + # Merging the result with the previous members if existing + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if [[ $lsyrsh != $lsyrso ]] && [[ -e ${pathout}/${prefix}${lsmbsb}_${lsyrso} ]] ; then + cp ${pathout}/${prefix}${lsmbsb}_${lsyrso} . + gather_memb ${prefix} _${lsyrso} ${prefix}${lsmbso}_${lsyrso} + else + lsmbso=$lsmbsh + fi + # + # Storing and cleaning + # ~~~~~~~~~~~~~~~~~~~~~ + cp ${prefix}${lsmbso}_${lsyrso} ${pathout}/. || { if [ -e ${pathout}/${prefix}${lsmbso}_${lsyrso} ]; + then + echo "${prefix}${lsmbso}_${lsyrso} already exists in ${pathout}" + sleep 5 + else + echo " problem writing file in ${pathout} directory" + exit + fi + } + rm -f ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrso} ${prefix}${lsmbsb}_${lsyrso} ${pathout}/${prefix}${lsmbsb}_${lsyrso} ${prefix}${lsmbso}_${lsyrso} ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ${prefix}${lsmbsb}_${lsyrsh} + done + done +done + +trap - EXIT +rm -rf $WORKDIR diff --git a/save/setup_development.bash b/save/setup_development.bash new file mode 100755 index 0000000..5409be9 --- /dev/null +++ b/save/setup_development.bash @@ -0,0 +1,39 @@ +#!/bin/bash +# +# This script intends to support the development of new functions in +# common_ocean_post.txt of new options to existing funtions. It allows to +# test quickly these developments +# +# History : Virginie Guemas - Initial version - 2012 +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +set -evx +# This does not need to be changed : +CON_FILES='/esnas/autosubmit/con_files' +# This option is compatible with the testing on i00k but if you want to test +# your developments on another experiment you would need to change this : +NEMOVERSION=Ec2.3_O1L42 +# This lines needs to be replaced by the path were you stored your modifed +# version of common_ocean_post.txt : +source /home/Earth/vguemas/GIT_repositories/ocean_diagnostics/common_ocean_post.txt +# Here we only fetch one random chunk of outputs from i00k : +cp /esnas/exp/ecearth/i00k/19601101/fc0/outputs/MMO_i00k_19601101_fc0_19601101-19610228.tar . +# Here we untar and gunzip these files : +tar -xvf MMO_i00k_19601101_fc0_19601101-19610228.tar +gunzip *.gz +# The lines below might need to be changed depending on which function you need +# to test. In the case below, the grid_T files are needed because they contain +# the 3d temperature = input to ohc function. If you test siasiesiv for exemple, +# you would need to replace grid_T by icemod. +filein=`ls *grid_T*` +cdo cat *grid_T* tmp.nc +# The lines below are essential because the files have a time dimension named +# time in all the functions from common_ocean_post.txt (this is handled in +# ocean_pp.bash and in the templates) +timevar=`ncdump -h tmp.nc | grep UNLIMITED | awk '{print $1}'` +if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time tmp.nc ; fi +# Some cleaning +rm -f *grid* *icemod* +# This is the final testing line. You need to replace that line by the function +# you want to test (here it is ohc) followed by all its arguments (here we have +# only the input file tmp.nc and the output file tmpout.nc) +ohc tmp.nc tmppout.nc diff --git a/save/testing_ocean_pp_moore.job b/save/testing_ocean_pp_moore.job new file mode 100755 index 0000000..9e2cab3 --- /dev/null +++ b/save/testing_ocean_pp_moore.job @@ -0,0 +1,26 @@ +#!/bin/bash +#$ -l h_vmem=4G +#$ -l s_rt=24:00:00 +#$ -l h_rt=24:00:00 + +set -evx +oceanpp_repository=/home/Earth/pbretonn/es_git/ocean_diagnostics +workdir=/scratch/tmp/post_ocean/$$ + +mkdir -p $workdir +cd $workdir +if [ -e ${oceanpp_repository}/ocean_pp.bash ] ; then + cp ${oceanpp_repository}/ocean_pp.bash . +else + echo "Please fill up the location of your ocean_pp repository" + exit 1 +fi + +#lstexp=('b02s_bis') +#lstexp=('b02s_ter' 'l00w_bis') #orig +lstexp=('b02s' 'i00k' 'i01t' 'l00v' 'l00w' 'glorys' 'nemovar' 'b02s_bis' 'b02s_ter' 'l00w_bis') #orig +for exp in ${lstexp[@]} ; do + tmp=${oceanpp_repository//\//\\\/} + sed -e "s/PATHCOMMONOCEANDIAG=.*/PATHCOMMONOCEANDIAG=${tmp}/g" /shared/earth/software/scripts/testing_ocean_pp/config_file-ocean_pp_${exp}.bash &> config_file-ocean_pp_${exp}.bash + ./ocean_pp.bash config_file-ocean_pp_${exp}.bash +done -- GitLab From e356c8bbb56b787262d111ecd60686593c6e1be8 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Tue, 15 Mar 2016 09:22:05 +0100 Subject: [PATCH 3/9] I put in Downloads --- save/README | 101 --- save/common_ocean_post.txt | 1339 ------------------------------ save/common_ocean_post.txt.oriol | 1339 ------------------------------ save/config_file-ocean_pp.bash | 44 - save/ocean_pp.bash | 647 --------------- save/ocean_pp.bash.oriol | 647 --------------- save/setup_development.bash | 39 - save/testing_ocean_pp_moore.job | 26 - 8 files changed, 4182 deletions(-) delete mode 100644 save/README delete mode 100644 save/common_ocean_post.txt delete mode 100644 save/common_ocean_post.txt.oriol delete mode 100644 save/config_file-ocean_pp.bash delete mode 100755 save/ocean_pp.bash delete mode 100755 save/ocean_pp.bash.oriol delete mode 100755 save/setup_development.bash delete mode 100755 save/testing_ocean_pp_moore.job diff --git a/save/README b/save/README deleted file mode 100644 index 805fa9b..0000000 --- a/save/README +++ /dev/null @@ -1,101 +0,0 @@ -To use the ocean diagnostic tools available here and to be able to create new diagnostics, -you need first to add the following line to your .bashrc: -PATH=/cfu/software/cdftools2.1/:$PATH - -#Launching instructions: - -./ocean_pp.bash $path_to_your_file/config_file-ocean_pp.bash -- You can copy and modify the config_file to any directory if you indicate the good path when launching ocean_pp.bash -- ocean_pp.bash, README and example of config_file-ocean_pp.bash can be downloaded from git repository: git clone https://dev.cfu.local/cfutools.git - -# - -####################### DIAGNOSTICS LIST ####################################### -'siasiesiv' : sea ice area + sea ice extent + sea ice volume -'moc' : Atlantic + Pacific + Indian + Indo-Pacific + Global - meridional overturning streamfunction -'max_moc' : Yearly maximum of the Atlantic meridional overturning - streamfunction between 38N-50N and 500-3000m and - at 40N. - Beware that the max_moc diagnostics can not be computed - if you don't process complete years, as it is a diagnostic - computed from complete years. -'area_moc' : Averaged Atlantic meridional overturning streamfunction - between 40N-55N and 1km-2km and between 30N-40N and 1km-2km -'convection' : indices of convective activity in the Labrador, extended Irminger, - GIN and Wedell seas computed as the maximum in mixed layer depth - based on the potential density criteria -'stc' : Subtropical cell strength, computed as the averaged Atlantic - and Pacific overturning streamfunction in 0-25N/S, 0-200m -'ext_raw_ice' : raw ice varibales to be extracted from input files - (called "ice" before february 2013 update)) -'ext_raw_oce' : raw ocean varibales to be extracted from input files - (called "sstsssmld" before february 2013 update)) -'heat_sal_mxl' : mixed layer heat and salt content (potential density criteria) -'psi' : barotropic streamfunction -'gyres' : indices of the barotropic gyres computed as the maximum absolute - barotropic streamfunction in the North Atlantic and North Pacific - subpolar and subtropical gyres and in the South Atlantic, South - Pacific and Indian subtropical gyres and indice of the Antarctic - Circumpolar Current strength -'usalc' : upper layer salt content 0-300m -'temp_lev' : temperature, vertical mean between dif levels (2D) -'sal_lev' : salinity, vertical mean between dif levels (2D) -'lmsalc' : middle + lower layer salt content 300m-bottom -'ohc' : global total ocean heat content -'ohc_specified_layer' : Pointwise ocean heat content in a specified ocean thickness (at present 0-300 m) -'uohc' : global upper (0-350m) ocean heat content -'mohc' : global middle (350-800m) ocean heat content -'lohc' : global lower (800m-bottom) ocean heat content -'xohc' : global mixed layer ocean heat content -'TSec_ave190-220E' : meridional temperature section averaged between 190E and 220E -'SSec_ave190-220E' : meridional salinity section averaged between 190E and 220E (added in february 2013 update) -'vert_Tsections' : zonal temperature sections along 45S, 0N, 45N, and - meridional temperature sections along 30W, 80E, 180E -'vert_Ssections' : zonal salinity sections along 45S, 0N, 45N, and - meridional salinity sections along 30W, 80E, 180E (added in february 2013 update) -'3dtemp' : 3-dimensional temperature interpolated horizontally onto the - atmospheric grid -'3dsal' : 3-dimensional salinity interpolated horizontally onto the - atmospheric grid (added in february 2013 update) -'NAtlohc' : North Atlantic (10-65N) total ocean heat content -'xNAtlohc' : North Atlantic (10-65N) mixed layer ocean heat content -'uNAtlohc' : North Atlantic (10-65N) upper (0-350m) ocean heat content -'mNAtlohc' : North Atlantic (10-65N) middle (350-800m) ocean heat content -'lNAtlohc' : North Atlantic (10-65N) lower (800m-bottom) ocean heat content -'NPacohc' : North Pacific (10-70N) ocean heat content -'xNPacohc' : North Pacific (10-70N) mixed layer ocean heat content -'uNPacohc' : North Pacific (10-70N) upper (0-350m) ocean heat content -'mNPacohc' : North Pacific (10-70N) middle (350-800m) ocean heat content -'lNPacohc' : North Pacific (10-70N) lower (800m-bottom) ocean heat content -'TAtlohc' : Tropical Atlantic (30S-30N) ocean heat content -'xTAtlohc' : Tropical Atlantic (30S-30N) mixed layer ocean heat content -'uTAtlohc' : Tropical Atlantic (30S-30N) upper (0-350m) ocean heat content -'mTAtlohc' : Tropical Atlantic (30S-30N) middle (350-800m) ocean heat - content -'lTAtlohc' : Tropical Atlantic (30S-30N) lower (800m-bottom) ocean heat - content -'TPacohc' : Tropical Pacific (30S-30N) ocean heat content -'xTPacohc' : Tropical Pacific (30S-30N) mixed layer ocean heat content -'uTPacohc' : Tropical Pacific (30S-30N) upper (0-350m) ocean heat content -'mTPacohc' : Tropical Pacific (30S-30N) middle (350-800m) ocean heat content -'lTPacohc' : Tropical Pacific (30S-30N) lower (800m-bottom) ocean heat - content -'TIndohc' : Tropical Indian (30S-30N) ocean heat content -'xTIndohc' : Tropical Indian (30S-30N) mixed layer ocean heat content -'uTIndohc' : Tropical Indian (30S-30N) upper (0-350m) ocean heat content -'mTIndohc' : Tropical Indian (30S-30N) middle (350-800m) ocean heat content -'lTIndohc' : Tropical Indian (30S-30N) lower (800m-bottom) ocean heat - content -'Antaohc' : Antarctic (90-60S) ocean heat content -'xAntaohc' : Antarctic (90-60S) mixed layer ocean heat content -'uAntaohc' : Antarctic (90-60S) upper (0-350m) ocean heat content -'mAntaohc' : Antarctic (90-60S) middle (350-800m) ocean heat content -'lAntaohc' : Antarctic (90-60S) lower (800m-bottom) ocean heat content -'Arctohc' : Arctic (65-90N) ocean heat content -'xArctohc' : Arctic (65-90N) mixed layer ocean heat content -'uArctohc' : Arctic (65-90N) upper (0-350m) ocean heat content -'mArctohc' : Arctic (65-90N) middle (350-800m) ocean heat content -'lArctohc' : Arctic (65-90N) lower (800m-bottom) ocean heat content -'temp_lev' : vertical mean of ocean temp (weighted) between level1 and level2 (in numbers, not in meters), specified in the config file -'sal_lev' : vertical mean of ocean sal (weighted) between level1 and level2 (in numbers, not in meters), specified in the config file diff --git a/save/common_ocean_post.txt b/save/common_ocean_post.txt deleted file mode 100644 index 4239b91..0000000 --- a/save/common_ocean_post.txt +++ /dev/null @@ -1,1339 +0,0 @@ -############################################################################### -# This file gathers a set of bash functions that rely on cdftools to # -# # -# reduce_mmo # -# get_diagsMMO # -# get_nemovar # -# get_glorys # -# clean_diagsMMO # -# vertmeansal # -# heat_sal_mxl # -# ohc_specified_layer # -# moc # -# convection # -# psi # -# gyres # -# area_moc # -# max_moc # -# siasiesiv # -# ohc # -# cutsection # -# interp3d # -# setminmax # -# concat # -# gather_memb # -# vertmeanvar # -# # -# Those functions would never have seen the day without Hui Du, # -# usually referred to as Super-Hui. # -# # -# He made a crucial work to develop what ended up below in the functions # -# that computes the sea ice extent, sea ice area, ocean heat content and # -# meridional overturning streamfunction. # -# Especially, he developped new options from the cdftools sources to be # -# able to compute the heat content in different basins. # -# # -#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# You want to make available a new diagnostic ? @ -# @ -# 1) Get an MMO tar files from any experiment on esnas @ -# 2) Write a bash function that works on a grid_T or grid_U or grid_V or @ -# grid_W file or a combination from this MMO file @ -# --> You can test your function by defining the CON_FILES and NEMOVERSION @ -# variables and by sourcing the current file, the meshmasks will be @ -# available after sourcing, remember to source again after any @ -# modification of your function @ -# --> Your function should work on input files of any resolution @ -# ORCA1/ORCA025/ORCA2 @ -# --> Your function should work on input files of any time length @ -# --> The output file should contain a proper time axis that you can copy @ -# from your input file @ -# --> The output file should be at most a 3d field including the time @ -# dimension @ -# 3) Write a short description of your function, and add its name to the @ -# list above @ -# 4) Go the the ocean_pp.sh script to add a call to your function @ -# @ -# Any doubt ---> vguemas@ic3.cat @ -#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# Link constant file for co # -############################################################################### - -ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_hgr.nc -ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_zgr.nc -ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mask.nc -ln -sf ${CON_FILES}/new_maskglo.${NEMOVERSION}.nc new_maskglo.nc - -if [ -e ${CON_FILES}/mask.regions.${NEMOVERSION}.nc ] ; then -cp ${CON_FILES}/mask.regions.${NEMOVERSION}.nc mask_regions.nc -fi - -if [[ ! -f mask.nc ]] ; then - echo "No configuration files for cdftools" - exit -fi - -############################################################################### -# Reduced number of variables in diag files to save disk space # -# # -# $1 : input grid_T file name # -# $2 : input icemod file name # -# $3 : suffix of output files with nc extension # -# # -# Created in February 2012 Author : vguemas@ic3.cat # -# May 2014 : Compatibility with PA changes to oce output - Virginie # -############################################################################### - -function reduce_mmo { -ncks -O -v sosstsst,sosaline,somixhgt,somxl010,sossheig $1 oce_${3} -typeset var lstvars=`cdo showvar $2` -if [[ ${lstvars/ileadfra} != ${lstvars} ]] ; then - ncks -O -v isnowthi,iicethic,ileadfra,iicetemp $2 ice_${3} -else - ncks -O -v isnowthi,iicethic,iiceconc,iicetemp $2 ice_${3} -fi -ncks -O -v votemper $1 t3d_${3} -} -############################################################################### -# Copy diags or MMO files from esnas # -# # -# $1 : starting date # -# $2 : expid # -# $3 : member # -# $4 : starting leadtime # -# $5 : end leadtime # -# $6 : chunk length in month # -# $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 # -# Option 10: June 2013 isabel.andreu-burillo@ic3.cat -############################################################################### - -function get_diagsMMO { -typeset var yyyy0=`echo $1|cut -c1-4` -typeset var mm0=`echo $1|cut -c5-6` -if [ -z "${10}" ] ; then - typeset var lstypes="grid_T grid_U grid_V grid_W icemod" -else - typeset var lstypes=${10} -fi - -typeset var jt -typeset var year1 -typeset var year2 -typeset var mon1 -typeset var mon2 -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 /esnas/exp/$7/$2/$1/fc$3/outputs/$8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar . - if [[ "$8" == "MMO" ]]; then - for filetype in $lstypes; do - tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar "*${freqkeep}*${filetype}*" - done - else - tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar - fi - rm -f $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar - if [[ `ls *.gz` != '' ]] ; then gunzip -f *.gz ; fi - ipcs -a -done - -typeset var listroots -case $8 in - 'diags' ) - listroots="t3d heat_sal_mxl ice moc psi sal_0-300m sal_300-5400m" - if [[ `ls sstsimld*` != '' ]] ; then - listroots=$listroots" sstsimld" - elif [[ `ls sstsssmld*` != '' ]] ; then - listroots=$listroots" sstsssmld" - else - listroots=$listroots" oce" - fi - ;; - 'MMO' ) listroots=$lstypes ;; -esac -case $9 in - 'daily') freqexcl1='1m' ; freqexcl2='MM' ;; - 'monthly' ) freqexcl1='1d' ; freqexcl2='DD' ;; - *) freqexcl1='1d' ; freqexcl2='DD' ;; -esac - -function concat_startdate { - typeset var root - typeset var lstfiles - for root in ${listroots[@]} ; do - ipcs -a - if [[ "$8" == "MMO" ]] ; then - lstfiles=`ls *${root}* | grep -v "${root}_$2_$1_fc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" | grep -v "km" ` - else - lstfiles=`ls ${root}* | grep -v "${root}_$2_$1_fc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" | grep -v "km" ` - fi - if [[ ! -z ${lstfiles} ]] ; then - - file1=`echo "${lstfiles}" | tail -1` - cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` - rm ff - #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN - if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then - 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 - if [[ $root == 'heat_sal_mxl' ]] ; then - for file in $lstfiles ; do - ncatted -O -a valid_max,somxlheatc,d,, $file $file - ncatted -O -a valid_min,somxlheatc,d,, $file $file - done - fi - fi - - outfile=${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc - 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 ${outfile} - timevar=`ncdump -h ${outfile} | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time ${outfile} ; fi - if [[ $root == 'moc' ]] ; then - lstdims=`ncdump -h ${outfile} | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` - if [[ ${lstdims/gsize} != ${lstdims} ]] ; then - ncrename -d gsize,y ${outfile} - fi - lenx=`ncdump -h ${outfile} | grep 'x =' | head -1 | awk '{print $3}'` - if [[ $lenx > 1 ]] ; then - if [[ ${lstvars/nav_lon} != ${lstvars} ]] ; then - ncks -O -x -v nav_lon,nav_lat ${outfile} ${outfile} - fi - ncrename -d x,y ${outfile} - fi - ncks -A -v nav_lon,nav_lat `echo $lstfiles | awk '{print $1}' ` ${outfile} - fi - rm -f $lstfiles - if [[ $root == 'sstsimld' || $root == 'sstsssmld' ]] ; then mv ${outfile} oce_$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 - done -} - -concat_startdate $1 $2 $3 $4 $5 $6 $7 $8 - -# These lines aim at concatenating the daily means as well and computing the monthly means from these daily means -if [[ $9 == 'monthly' ]] ; then - freqexcl1='1m' ; freqexcl2='MM' - for root in ${listroots[@]} ; do - outfile=${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 [[ -e $outfile ]] ; then - mv $outfile ${root}_1m.nc - fi - done - concat_startdate $1 $2 $3 $4 $5 $6 $7 $8 - for root in ${listroots[@]} ; do - ipcs m - outfile=${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 [[ -e $outfile ]] ; then - cdo monmean $outfile ${root}_daily2monthly.nc - rm -f $outfile - if [[ -e ${root}_1m.nc ]] ; then - mv ${root}_1m.nc $outfile - ncks -A ${root}_daily2monthly.nc $outfile - rm -f ${root}_daily2monthly.nc - else - mv ${root}_daily2monthly.nc $outfile - fi - else - if [[ -e ${root}_1m.nc ]] ; then - mv ${root}_1m.nc $outfile - fi - fi - done -fi - -rm -f *${freqexcl1}* *${freqexcl2}* - -} -############################################################################### -# Copy NEMOVAR files from esnas # -# # -# $1 : expid # -# $2 : member # -# $3 : start year # -# $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 { - -if [ -z "$5" ] ; then - typeset var moni=9 -else - typeset var moni=$5 -fi - -if [ -z "$5" ] ; then - typeset var monf=8 -else - typeset var monf=$6 -fi - -typeset var path -typeset var yearf -case $1 in - 'nemovar_s4') path=/esnas/exp/ECMWF/NEMOVAR_S4/outputs/fc$2/s4 ;; - 'nemovar_combine') path=/esnas/exp/ECMWF/NEMOVAR_COMBINE/outputs/opa0/fa9p_1m ;; -esac -typeset var year -typeset var mon -for year in $(seq $3 $4) ; do - case $year in - $3) mona=${moni} ;; - *) mona=1 ;; - esac - case $year in - $4) monb=${monf} ;; - *) monb=12 ;; - esac - for mon in $(seq $mona $monb); do - cp ${path}_fc$2_${year}$(printf "%02d" $mon)*.gz . - done -done -gunzip -f *.gz - -typeset var listroots=${7} -typeset var root -typeset var lstfiles -typeset var ntimes -typeset var jt -for root in ${listroots[@]} ; do - lstfiles=`ls *fc${2}*${root}* | grep -v "${root}_$1_195709_fc$2_${3}09_${4}$(printf "%02d" $monb).nc"` - ncrcat -O -x -v vorbiasp $lstfiles tmp_${root}.nc - cdo settaxis,${3}-$(printf "%02d" $moni)-15,12:00,1mon tmp_${root}.nc ${root}_$1_19570901_fc$2_${3}$(printf "%02d" $moni)_${4}$(printf "%02d" $monf).nc - rm -f $lstfiles tmp_${root}.nc -done -} -############################################################################### -# Copy GLORYS files from esnas # -# # -# $1 : start year # -# $2 : end year # -# $3 : start month # -# $4 : end month # -# # -# Created in June 2013 Author : vguemas@ic3.cat # -############################################################################### - -function get_glorys { -typeset var path=/esnas/exp/MERCATOR/GLORYS2V1/outputs/ORCA1L46 #ORCA025L75_glorys -typeset var lstfiles="" -for year in $(seq $1 $2) ; do - cp ${path}/vosaline_${year}.nc . - cp ${path}/votemper_${year}.nc . - ncks -A vosaline_${year}.nc votemper_${year}.nc - rm -f vosaline_${year}.nc - lstfiles=${lstfiles}" "votemper_${year}.nc -done -cdo cat ${lstfiles} tmp.nc -cdo settaxis,${1}-01-15,12:00,1mon tmp.nc tmp2.nc -cdo seldate,${1}-$(printf "%02d" $3)-00,${2}-$(printf "%02d" $4)-31 tmp2.nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc -rm -f ${lstfiles} tmp.nc tmp2.nc -ncks -O -x -v nav_lon,nav_lat,x_2,y_2 grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc -ncks -A -v nav_lon,nav_lat mesh_hgr.nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc -} -############################################################################### -# Clean diags or MMO files after postprocessing # -# # -# $1 : starting date # -# $2 : expid # -# $3 : member # -# $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 { -typeset var yyyy0=`echo $1|cut -c1-4` -typeset var mm0=`echo $1|cut -c5-6` -typeset var year1=$(($yyyy0+(10#$mm0+$4-2)/12)) -typeset var year2=$(($yyyy0+(10#$mm0+$5-2)/12)) -typeset var mon1=$(((10#$mm0+$4-2)%12+1)) -typeset var mon2=$(((10#$mm0+$5-2)%12+1)) - -typeset var listroots - case $6 in - 'diags' ) listroots="t3d" ;; - 'MMO' ) - if [ -z "${7}" ] ; then - listroots="grid_T grid_U grid_V grid_W icemod" - else - listroots=${7} - fi - ;; - esac -typeset var root -typeset var lstfiles -for root in ${listroots[@]} ; do - rm -f ${root}_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)_${year2}$(printf "%02d" $mon2).nc -done -} -############################################################################### -# Vertically averaged salt content # -# # -# $1 : input grid_T file name # -# $2 : upper depth of the layer (in meters) # -# $3 : lower depth of the layer (in meters) # -# $4 : output file name (=> 2D) # -# # -# Created in February 2012 Author : vguemas@ic3.cat # -############################################################################### - -function vertmeansal { -cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` -rm ff -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -for jt in $(seq 1 $ntime); do - ncks -d time,$((jt-1)) $1 intvertmeansal.nc - cdfvertmean intvertmeansal.nc vosaline T $2 $3 - ncrename -O -v sovertmean,vertmeansal -d time_counter,time -v time_counter,time vertmean.nc - mv vertmean.nc outputvertmeansal_$jt.nc - list=$list" "outputvertmeansal_$jt.nc - rm -f intvertmeansal.nc - #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN - if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then - ncatted -O -a valid_max,vertmeansal,d,, outputvertmeansal_$jt.nc outputvertmeansal_$jt.nc - ncatted -O -a valid_min,vertmeansal,d,, outputvertmeansal_$jt.nc outputvertmeansal_$jt.nc - fi -done -cdo cat $list $4 -ncks -A -v time $1 $4 -rm -f $list -setminmax $4 vertmeansal -} -############################################################################### -# Compute mixed layer heat and salt content # -# # -# $1 : input grid_T file name # -# $2 : output file name (=> 2D x-y ) # -# # -# Created in February 2012 Author : vguemas@ic3.cat # -################################################################################ - -function heat_sal_mxl { -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -typeset var lstvars=`cdo showvar $1` -for jt in $(seq 1 $ntime); do - ncks -d time,$((jt-1)) $1 intheat_sal_mxl.nc - if [[ ${lstvars/somxl010} == ${lstvars} ]] ; then - cdfmxl intheat_sal_mxl.nc mxl.nc - ncrename -d time_counter,time mxl.nc - ncks -A mxl.nc intheat_sal_mxl.nc - rm -f mxl.nc - fi - cdfmxlheatc intheat_sal_mxl.nc - if [[ $lstvars != ${lstvars/vosaline} ]] ; then - cdfmxlsaltc intheat_sal_mxl.nc - ncks -A mxlsaltc.nc mxlheatc.nc - rm -f mxlsaltc.nc - fi - mv mxlheatc.nc outputintheat_sal_mxl_$jt.nc - timevar=`ncdump -h outputintheat_sal_mxl_$jt.nc | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time outputintheat_sal_mxl_$jt.nc ; fi - list=$list" "outputintheat_sal_mxl_$jt.nc - rm -f intheat_sal_mxl.nc -done -cdo cat $list $2 -ncks -A -v time $1 $2 -rm -f $list -setminmax $2 somxlheatc -if [[ $lstvars != ${lstvars/vosaline} ]] ; then setminmax $2 somxlsaltc ; fi -} -############################################################################### -# Pointwise Ocean Heat Content in a specified ocean thickness # -# (J/m-2) -# # -# $1 : input grid_T file name # -# $2 : upper depth of the layer (in meters) # -# $3 : lower depth of the layer (in meters) # -# $4 : output file name (=> 2D x-y ) # -# # -# Created in June 2012 Author : isabel.andreu-burillo@ic3.cat # -# May 2014 - Virginie Guemas - Way around the bc that does not work on moore # -############################################################################### - -function ohc_specified_layer { -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -ncap2 -v -O -s "heatc_sl=tmask*e3t" mesh_zgr.nc e3t_file.nc -ncrename -d t,time -d z,deptht e3t_file.nc -for jt in $(seq 1 $ntime); do - cdo seltimestep,$jt $1 intohc_slayer.nc - 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 - ncks -d deptht,$2,$3 heatc_sl_out.nc heatc_sl_top.nc - #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 - # lower_bnd=`echo "$3 + 200.0" | bc` -> does not work on new moore - # strip out the .* from $3: - stripped=`echo ${3/.*}` - # addition with float returned: - lower_bnd=`echo $(printf "%f" $(( $stripped + 200)))` - 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 - 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 - ## Here, add the residual contribution, before adding it to the main contribution - ncrename -v deptht,layerthcknss level_below.nc - ncrename -v deptht,layerthcknss level_above.nc - ncbo -A --op_typ=sub -v layerthcknss level_below.nc level_above.nc depth_diff_lay.nc - ncrename -v layerthcknss,heatc_sl depth_diff_lay.nc - ncap2 -s "heatc_sl=($3 - layerthcknss)" level_above.nc depth_diff_sublay.nc - ncbo --op_typ=/ -v heatc_sl depth_diff_sublay.nc depth_diff_lay.nc factor.nc - ncrename -v heatc_sl,factor factor.nc #to be commented - ncks -A -v factor factor.nc level_below.nc - rm -f depth_diff_sublay.nc depth_diff_lay.nc - ncap2 -O -s "heatc_sl=(factor * heatc_sl)" level_below.nc level_below.nc - ncwa -O -a deptht level_below.nc level_below.nc - ncbo --op_typ=+ -v heatc_sl heatc_sl_top.nc level_below.nc total_heatc_sl.nc - ncap2 -s "heatc_sl=1020.0*4000*heatc_sl" total_heatc_sl.nc heatc_sl_$jt.nc - list=$list" "heatc_sl_$jt.nc - rm -f depth_diff_lay.nc depth_diff_sublay.nc - rm -f heatc_sl_out.nc heatc_sl_top.nc heatc_sl_top_invert.nc heatc_sl_bottom.nc - rm -f level_above.nc level_below.nc - rm -f intohc_slayer.nc intmeantem.nc vertmean.nc total_heatc_sl.nc - rm -f factor.nc -done -cdo cat $list $4 -ncks -A -v time $1 $4 -rm -f $list -rm -f e3t_file.nc -setminmax $4 heatc_sl -} -############################################################################### -# Compute the MOC for oceanic basins # -# # -# $1 : input grid_V file name # -# $2 : output file name (=> 2D, depth-y) # -# # -# Created in March 2012 Author : vguemas@ic3.cat # -############################################################################### - -function moc { -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -for jt in $(seq 1 $ntime); do - cdo seltimestep,$jt $1 intmoc.nc - cdfmoc intmoc.nc - ncwa -O -a x moc.nc outmoc_$jt.nc - ncks -O -x -v nav_lon,nav_lat outmoc_$jt.nc outmoc_$jt.nc - timevar=`ncdump -h outmoc_$jt.nc | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time outmoc_$jt.nc ; fi - list=$list" "outmoc_$jt.nc - rm -f intmoc.nc moc.nc -done -cdo cat $list $2 -lstdims=`ncdump -h $2 | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` -if [[ ${lstdims/gsize} != ${lstdims} ]] ; then - ncrename -d gsize,y $2 -fi -ncks -A -v nav_lon,nav_lat $1 $2 -ncks -A -v time $1 $2 -rm -f $list -} -############################################################################### -# # -# Compute the intensity of convection in the four main convection sites # -# # -# $1 : input oce file name containing somxl010 # -# $2 : input grid # -# $3 : output file name (=> index) # -# # -# Created in October 2013 Author : vguemas@ic3.cat # -############################################################################### - -function convection { -case $2 in - 'Ec2.3_O1L42'|'Ec3.0_O1L46'|'N3.2_O1L42'|'N3.3_O1L46'|'nemovar_O1L42') - A1=225;A2=245;A3=215;A4=255; - B1=245;B2=290;B3=215;B4=245; - C1=260;C2=310;C3=245;C4=291; - D1=225;D2=280;D3=1;D4=50;; - - 'Ec3.0_O25L46'|'Ec3.0_O25L75'|'glorys2v1_O25L75') - stop"Option convection not available yet for this configuration" - ;; -esac - -cdo fldmax -selindexbox,${A1},${A2},${A3},${A4} $1 Labrador.nc -ncrename -v somxl010,Labrador Labrador.nc -ncks -v Labrador Labrador.nc convection.nc -rm -f Labrador.nc - -cdo fldmax -selindexbox,${B1},${B2},${B3},${B4} $1 Irminger.nc -ncrename -v somxl010,Irminger Irminger.nc -ncks -A -v Irminger Irminger.nc convection.nc -rm -f Irminger.nc - -cdo fldmax -selindexbox,${C1},${C2},${C3},${C4} $1 GIN.nc -ncrename -v somxl010,GIN GIN.nc -ncks -A -v GIN GIN.nc convection.nc -rm -f GIN.nc - -cdo fldmax -selindexbox,${D1},${D2},${D3},${D4} $1 Wedell.nc -ncrename -v somxl010,Wedell Wedell.nc -ncks -A -v Wedell Wedell.nc convection.nc -rm -f Wedell.nc - -mv convection.nc $3 -} -############################################################################### -# # -# Compute the barotropic stream function # -# # -# $1 : input grid_U file name # -# $2 : input grid_V file name # -# $3 : output file name without nc extension (=> 2D x-y) # -# # -# Created in March 2012 Author : vguemas@ic3.cat # -############################################################################### - -function psi { -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -for jt in $(seq 1 $ntime); do - cdo seltimestep,$jt $1 intU.nc - cdo seltimestep,$jt $2 intV.nc - cdfpsi intU.nc intV.nc - mv psi.nc psi_U.nc - cdfpsi intU.nc intV.nc V - mv psi.nc psi_V.nc - ncea psi_U.nc psi_V.nc psi_${jt}.nc - timevar=`ncdump -h psi_$jt.nc | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time psi_$jt.nc ; fi - list=$list" "psi_$jt.nc - rm -f intU.nc intV.nc psi_U.nc psi_V.nc -done -cdo cat $list ${3} -ncks -A -v time $1 ${3} -rm -f $list -} -############################################################################### -# # -# Compute the intensity of the subtropical and subpolar gyres # -# # -# $1 : input psi file name # -# $2 : input grid # -# $3 : output file name ( => index ) # -# # -# Created in October 2013 Author : vguemas@ic3.cat # -############################################################################### - -function gyres { -case $2 in - 'Ec2.3_O1L42'|'Ec3.0_O1L46'|'N3.2_O1L42'|'N3.3_O1L46'|'nemovar_O1L42') - A1=230;A2=275;A3=215;A4=245; - B1=70;B2=145;B3=195;B4=235; - C1=45;C2=175;C3=165;C4=220; - D1=195;D2=275;D3=175;D4=225; - E1=70;E2=205;E3=120;E4=145; - F1=235;F2=300;F3=120;F4=145; - G1=320;G2=30;G3=110;G4=180; - H1=1;H2=361;H3=1;H4=65;; - - 'Ec3.0_O25L46'|'Ec3.0_O25L75'|'glorys2v1_O25L75') - stop"Option gyres not available yet for this configuration" - ;; -esac - -cdo fldmin -selindexbox,${A1},${A2},${A3},${A4} $1 subpolar_NAtl.nc -ncrename -v sobarstf,subpolNAtl subpolar_NAtl.nc -cdo mulc,-1 subpolar_NAtl.nc gyres.nc -rm -f subpolar_NAtl.nc - -cdo fldmin -selindexbox,${B1},${B2},${B3},${B4} $1 subpolar_NPac.nc -ncrename -v sobarstf,subpolNPac subpolar_NPac.nc -cdo mulc,-1 subpolar_NPac.nc tmp.nc -ncks -A tmp.nc gyres.nc -rm -f subpolar_NPac.nc tmp.nc - -cdo fldmax -selindexbox,${C1},${C2},${C3},${C4} $1 subtrop_NPac.nc -ncrename -v sobarstf,subtropNPac subtrop_NPac.nc -ncks -A subtrop_NPac.nc gyres.nc -rm -f subtrop_NPac.nc - -cdo fldmax -selindexbox,${E1},${E2},${E3},${E4} $1 subtrop_SPac.nc -ncrename -v sobarstf,subtropSPac subtrop_SPac.nc -ncks -A subtrop_SPac.nc gyres.nc -rm -f subtrop_SPac.nc - -cdo fldmax -selindexbox,${D1},${D2},${D3},${D4} $1 subtrop_NAtl.nc -ncrename -v sobarstf,subtropNAtl subtrop_NAtl.nc -ncks -A subtrop_NAtl.nc gyres.nc -rm -f subtrop_NAtl.nc - -cdo fldmax -selindexbox,${F1},${F2},${F3},${F4} $1 subtrop_SAtl.nc -ncrename -v sobarstf,subtropSAtl subtrop_SAtl.nc -ncks -A subtrop_SAtl.nc gyres.nc -rm -f subtrop_SAtl.nc - -cdo fldmax -selindexbox,${G1},${G2},${G3},${G4} $1 subtrop_Ind.nc -ncrename -v sobarstf,subtropInd subtrop_Ind.nc -ncks -A subtrop_Ind.nc gyres.nc -rm -f subtrop_Ind.nc - -cdo fldmax -selindexbox,${H1},${H2},${H3},${H4} $1 ACC.nc -ncrename -v sobarstf,ACC ACC.nc -ncks -A ACC.nc gyres.nc -rm -f ACC.nc - -mv gyres.nc $3 - -} -############################################################################### -# # -# Compute an Atlantic MOC index by averaging the meridional overturning # -# in a latitude band between 1km and 2km # -# or any other index averaging the meridional overturning in # -# a given basin and a given domain # -# # -# $1 : input moc file name # -# $2 : latitude min # -# $3 : latitude max # -# $4 : output file name ( => index ) # -# $5 : depth min (default : 1km) # -# $6 : depth max (default : 2km) # -# $7 : basin (default : zomsfatl) # -# # -# Created in March 2012 Author : vguemas@ic3.cat # -############################################################################### - -function area_moc { -if [ -z "$5" ] ; then - typeset var depmin=-1000.0 -else - typeset var depmin=-$5 -fi -if [ -z "$6" ] ; then - typeset var depmax=-2000.0 -else - typeset var depmax=-$6 -fi -if [ -z "$7" ] ; then - typeset var basin=zomsfatl -else - typeset var basin=$7 -fi -lstdims=`ncdump -h $1 | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` -if [[ ${lstdims/x} != ${lstdims} ]] ; then - ncwa -O -a x $1 tmpmoc.nc -else - cp $1 tmpmoc.nc -fi -ncrename -O -d y,lat -v nav_lat,lat tmpmoc.nc tmpmoc.nc -ncks -O -v $basin,time,depthw,lat tmpmoc.nc tmpmoc.nc -ncks -d lat,$2,$3 -d depthw,${depmax},${depmin} tmpmoc.nc area_moc.nc -cdo vertmean area_moc.nc area_ave_moc.nc -ncap -O -s "coslat[lat]=cos(lat[lat]*3.141592657/180.0)" area_ave_moc.nc area_ave_moc2.nc -ncwa -w coslat -a lat area_ave_moc2.nc area_ave_moc3.nc -ncks -O -v $basin,time area_ave_moc3.nc $4 -rm -f tmpmoc.nc area_moc.nc area_ave_moc2.nc area_ave_moc3.nc -if [[ $4 != area_ave_moc.nc ]] ; then - rm -f area_ave_moc.nc -fi -} -############################################################################### -# # -# Compute an Atlantic MOC index by finding the maximum of the annual # -# mean meridional overturning in a latitude / depth region # -# # -# $1 : input moc file name # -# $2 : latitude min # -# $3 : latitude max # -# $4 : depth mean # -# $5 : depth max # -# $6 : output file name ( => index ) # -# # -# Created in March 2012 Author : vguemas@ic3.cat # -############################################################################### - -function max_moc { -if [ ! -f $6 ] ; then - ncecat -h $1 tmpmoc1.nc - lstdims=`ncdump -h tmpmoc1.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` - if [[ ${lstdims/x} != ${lstdims} ]] ; then - ncwa -O -a x tmpmoc1.nc tmpmoc1.nc - fi - ncrename -d record,x tmpmoc1.nc - ncpdq -O -h -a time,x tmpmoc1.nc tmpmoc1.nc - ncpdq -O -h -a depthw,x tmpmoc1.nc tmpmoc1.nc - ncpdq -O -h -a y,x tmpmoc1.nc tmpmoc1.nc - cdo yearmean tmpmoc1.nc tmpmoc.nc - typeset var ntime=`cdo ntime tmpmoc.nc` - typeset var list="" - for jt in $(seq 1 $ntime) ; do - cdo seltimestep,$jt tmpmoc.nc tmpmoc2.nc - cdfmaxmoc tmpmoc2.nc atl $2 $3 $4 $5 - mv maxmoc.nc maxmoc_$jt.nc - timevar=`ncdump -h maxmoc_$jt.nc | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time maxmoc_$jt.nc ; fi - list=${list}" "maxmoc_$jt.nc - rm -f tmpmoc2.nc - done - cdo cat $list $6 - ncks -A -v time tmpmoc.nc $6 - rm -f $list tmpmoc.nc tmpmoc1.nc -fi -} -############################################################################### -# # -# Compute the sea ice extent (1000km2), area (1000km2), volume (km3) # -# and mean thickness (m) in both hemispheres or a specified region. # -# # -# $1 : input ice file name # -# $2 : output file name ( => index ) # -# $3 : region of interest (if empty default is global) # -# # -# Created in April 2012 Author : vguemas@ic3.cat # -# Modified in June 2014 Author : neven.fuckar@ic3.cat # -# # -# Computation of the properties in various selected regions according to # -# mask.regions.${NEMOVERSION}.nc (mask_regions.nc) is based on modification # -# of mask.regions.ORCA1.noverticalinfo.Matt.nc from Matthieu Chevallier. # -# # -############################################################################### - -function siasiesiv { -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'|'Ec3.0_O25L75') 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 ;; -esac - -typeset var ntime=`cdo ntime $1` -typeset var list1="" -typeset var list2="" -typeset var jt - -if [ ! -z "$3" ] ; then - mv mask.nc mask_tmp.nc - mv mask_regions.nc mask.nc - ncrename -h -v $3,tmask mask.nc -fi - -for jt in $(seq 1 $ntime) ; do - cdo seltimestep,$jt $1 tmpice.nc - cdficediags tmpice.nc>ice.txt - for d in N S;do - ncdump toto_${d}.nc > ice_template.cdl - sia=`grep ${d}Area ice.txt |awk '{print $4}'` - sie=`grep ${d}Exnsidc ice.txt|awk '{print $4}'` - siv=`grep ${d}Volume ice.txt|awk '{print $4}'` - sed -e "s/sia =.*/sia = $sia ;/" ice_template.cdl > ice_template2.cdl - sed -e "s/sie =.*/sie = $sie ;/" ice_template2.cdl > ice_template3.cdl - sed -e "s/siv =.*/siv = $siv ;/" ice_template3.cdl > ice_template.cdl - ncgen -o ice_${d}_${jt}.nc ice_template.cdl - rm -f ice_template.cdl ice_template2.cdl ice_template3.cdl - done - list1=$list1" "ice_N_${jt}.nc - list2=$list2" "ice_S_${jt}.nc - rm -f ice.txt tmpice.nc icediags.nc -done -cdo cat $list1 ice_N_${2} -cdo cat $list2 ice_S_${2} -ncks -A -v time $1 ice_N_${2} -ncks -A -v time $1 ice_S_${2} -rm -f $list1 $list2 toto_N.nc toto_S.nc - -for d in N S;do - ncatted -O -a units,sia,m,c,1000km2 ice_${d}_${2} - ncatted -O -a units,sie,m,c,1000km2 ice_${d}_${2} - - ncks -v siv ice_${d}_${2} siv_${d}_${2}1 - ncks -v sia ice_${d}_${2} sia_${d}_${2}1 - ncrename -h -v sia,siv sia_${d}_${2}1 - ncbo -O --op_typ=dvd siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} - ncatted -O -a standard_name,siv,m,c,Mean_sea_ice_thickness sit_${d}_${2} - ncatted -O -a long_name,siv,m,c,"Mean sea ice thickness" sit_${d}_${2} - ncatted -O -a units,siv,m,c,m sit_${d}_${2} - cdo ltc,100 sit_${d}_${2} sit_${d}_${2}1 - cdo ifthenelse sit_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 - ncrename -h -v siv,sit sit_${d}_${2}2 - ncks -A sit_${d}_${2}2 ice_${d}_${2} - - rm siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 -done - -setminmax ice_N_${2} sia sie siv sit -setminmax ice_S_${2} sia sie siv sit - -if [ ! -z "$3" ] ; then - ncrename -h -v tmask,$3 mask.nc - mv mask.nc mask_regions.nc - mv mask_tmp.nc mask.nc -fi - -} -############################################################################### -# # -# Compute the total ocean heat extent # -# # -# $1 : input temperature file name # -# $2 : output file name ( => 2D x-y ) # -# $3 : basin (NAtl, NPac, TAtl, TPac, TInd, Anta, Arct, Glob) Default : Glob # -# $4 = 0 if $3 = Glob # -# $4 : mixed layer (1=only, 0=included, -1=without) Default : 0 # -# $5 : upper level of the layer (optional) Default : top # -# $6 : lower level of the layer (optional) Default : bottom # -# # -# Created in May 2012 Author : vguemas@ic3.cat # -############################################################################### - -function ohc { -cp ${CON_FILES}/depth.${NEMOVERSION}.txt depth.txt -# -# Input arguments -# -if [ -z "$3" ] ; then - typeset var basin='Glob' -else - typeset var basin=$3 -fi -if [ -z "$4" ] ; then - typeset var mxl=0 -else - typeset var mxl=$4 -fi -if [ -z "$5" ] ; then - typeset var up=1 -else - typeset var up=$5 -fi -if [ -z "$6" ] ; then - typeset var down=`cat depth.txt | wc -l` -else - typeset var down=$6 -fi - -if [[ ${up} -eq 1 ]] ; then - typeset var depmin=0 -else - typeset var depmin=`cat depth.txt |head -${up} |tail -1 | awk '{print $2}' | awk '{printf "%.0f",$1}'` -fi -typeset var depmax=`cat depth.txt |head -${down} |tail -1 | awk '{print $2}' | awk '{printf "%.0f",$1}'` - -cp ${CON_FILES}/heatc_template.nc template_heatc.nc -ncdump template_heatc.nc > template_heatc.cdl -#exec=/home/huidu/download/CDFTOOLS_2.1/cdfheatc-cfu -exec=/home/Earth/vguemas/CDFTOOLS_2.1/cdfheatc-cfu -# -# Define some parameters -# -typeset var para -typeset var output -typeset var nlev=`cat depth.txt | wc -l` -if [[ ! -z "$depmin" && ! -z "$depmax" ]] ; then - if [[ $depmin != 0 || ${down} != ${nlev} && ${down} != 0 ]] ; then - output=${depmin}-${depmax}'_' - fi -fi - -case $basin in - 'NAtl') para="atl $mxl 0 0 10 65"; output='NAtl_10N65N_'${output} ;; - 'TAtl') para="atl $mxl 0 0 -30 30" ; output='TAtl_30S30N_'${output} ;; - 'NPac') para="pac $mxl 0 0 10 70" ; output='NPac_10N70N_'${output} ;; - 'TPac') para="pac $mxl 0 0 -30 30" ; output='TPac_30S30N_'${output} ;; - 'Arct') para="atl $mxl 0 0 65 90" ; output='Arc_65N90N_'${output} ;; - 'Anta') para="all $mxl 0 0 -90 -60" ; output='Ant_90S60S_'${output} ;; - 'TInd') para="ind $mxl 0 0 -30 30" ; output='TInd_30S30N_'${output} ;; - 'Glob') para="all $mxl 0 0 0 0" ;; -esac - -case $mxl in - 1) output='mxl_'${output} ;; - -1) output='nonmxl_'${output} ;; -esac -# -# Compute ohc -# -typeset var lstvars=`cdo showvar $1` -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -for jt in $(seq 1 $ntime) ; do - cdo seltimestep,$jt $1 tmpohc.nc - lstdims=`ncdump -h tmpohc.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` - if [[ ${lstdims/x_2} != ${lstdims} ]] ; then - if [[ ${lstdims/x} != ${lstdims} ]] ; then - ncwa -O -a x tmpohc.nc tmpohc.nc - fi - ncrename -d x_2,x tmpohc.nc - fi - if [[ ${lstvars/somxl010} != ${lstvars} ]] ; then - ncks -v somxl010 tmpohc.nc mxl.nc - else - cdfmxl tmpohc.nc mxl.nc - fi - $exec tmpohc.nc $para $up $down > tmp.log - cat tmp.log - thc=`cat tmp.log | grep "Total Heat content :" | awk '{print $5}'`; - uhc=`cat tmp.log | grep "Total Heat content/volume" | awk '{print $5}'`; - sed -e "s/thc =.*/thc = $thc ;/" template_heatc.cdl > template_heatc2.cdl - sed -e "s/uhc =.*/uhc = $uhc ;/" template_heatc2.cdl > template_heatc.cdl - ncgen -o heatc_${jt}.nc template_heatc.cdl - rm -f template_heatc2.cdl tmpohc.nc mxl.nc tmp.log - list=$list" "heatc_${jt}.nc -done -cdo cat $list ${output}$2 -ncks -h -A -v time $1 ${output}$2 -rm -f $list template_heatc.nc template_heatc.cdl depth.txt -setminmax ${output}$2 thc uhc -} -############################################################################### -# # -# Cut a meridional or zonal section # -# # -# # -# $1 : input file # -# $2 : input var # -# $3 : Z/M (zonal / meridional section) # -# $4 : lat/lon # -# $5 : output file ( => 2D ) # -# # -# Created in September 2012 Author : vguemas@ic3.cat # -# # -############################################################################### - -function cutsection { - typeset var ntime=`cdo ntime $1` - typeset var nx=`ncdump -h $1|grep 'x = '|head -1|cut -f3 -d" "` - typeset var ny=`ncdump -h $1|grep 'y = '|head -1|cut -f3 -d" "` - typeset var nz=`ncdump -h $1|grep 'depth'|head -1|cut -f3 -d" "` -cat>section.R<max(lon)) {exactpos=exactpos-360} - } - # Collect the indexes defining the section - listi=array(dim=switch('$3','Z'=$nx-2,'M'=$ny-1)) - listj=array(dim=switch('$3','Z'=$nx-2,'M'=$ny-1)) - for (jpt in 1:length(listi)) { - vect=switch('$3','Z'=lat[jpt,],'M'=lon[,jpt+1]) - if (min(abs(vect-exactpos))<(2*360./$nx)) { - pos=sort(abs(vect-exactpos),index.return=T)\$ix[1] - listi[jpt]=switch('$3','Z'=jpt+1,'M'=pos) - listj[jpt]=switch('$3','Z'=pos,'M'=jpt) - } - } - listi=listi[is.na(listi)==F] - listj=listj[is.na(listj)==F] - print(listi) - print(listj) - # Select variable at those indexes - fnc1=open.ncdf('$1') - varout=array(dim=c(length(listi),$nz,$ntime)) - for (jt in 1:$ntime) { - varin=get.var.ncdf(fnc1,'$2',start=c(1,1,1,jt),count=c($nx,$ny,$nz,1)) - varin[which(mask<0.5)]=1e20 - for (jpt in 1:length(listi)) { - varout[jpt,,jt]=varin[listi[jpt],listj[jpt],] - } - } - close.ncdf(fnc1) - # Write the output - wtime=dim.def.ncdf("time","",seq(1,$ntime),unlim=TRUE) - dimout=array(dim=length(listi)) - for (jpt in 1:length(listi)) { - dimout[jpt]=switch('$3','Z'=lon[listi[jpt],listj[jpt]],'M'=lat[listi[jpt],listj[jpt]]) - } - wsec=switch('$3','Z'=dim.def.ncdf("lon","",dimout),'M'=dim.def.ncdf("lat","",dimout)) - wdep=dim.def.ncdf("deptht","",depth) - wvar=var.def.ncdf("$2","",list(wsec,wdep,wtime),1e20) - fnc2=create.ncdf('$5',wvar) - put.var.ncdf(fnc2,wvar,varout) - close.ncdf(fnc2) -EOF1 -R CMD BATCH section.R -ncks -h -A -v time $1 $5 -} -############################################################################### -# # -# 3-dimensional conservative interpolation to the regular atmospheric grid # -# # -# $1 : input file # -# $2 : input var # -# $3 : output file ( => 3D ) # -# # -# Created in November 2012 Author : vguemas@ic3.cat # -# # -############################################################################### - -function interp3d { - typeset var nz=`ncdump -h $1|grep 'deptht'|head -1|cut -f3 -d" "` - ln -sf /shared/earth/software/scripts/interpolation/scrip_use scrip_use - for lev in $(seq 1 $nz) ; do - ncks -d deptht,$((lev-1)) -v $2 $1 tmp_${lev}.nc - ncwa -O -h -a deptht tmp_${lev}.nc tmp_${lev}.nc - ln -sf /esnas/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc - cat > scrip_use_in < 2D field ) # -# # -# Created in February 2012 Author : vguemas@ic3.cat # -# Modified (more generic, -# i.e. for any input var) in December 2014 # -# Author : eleftheria.exarchou@ic3.cat # -############################################################################### - -function vertmeanvar { - typeset var ntime=`cdo ntime $1` - typeset var list="" - typeset var jt -for jt in $(seq 1 $ntime); do - ncks -d time,$((jt-1)) $1 a1 - # The oras4 data do not have gdepth data in their mask, but only gdept_0, so: - if grep -q nemovar_s4 $1 ; then - l1=$(( $3 % 6 )) - l2=$(( $4 % 6 )) - ll1=$(( $3 / 6 + 1 )) - ll2=$(( $4 / 6 + 1 )) - lev1=`echo $(cdo output -selvar,gdept_0 mesh_zgr.nc | sed -n ${ll1}p | awk '{ print $'$l1' }')` - lev2=`echo $(cdo output -selvar,gdept_0 mesh_zgr.nc | sed -n ${ll2}p | awk '{ print $'$l2' }')` - else - l1=$(($3+1)) - l2=$(($4+1)) - lev1=`echo $(cdo info -seltimestep,1 -selvar,gdept mesh_zgr.nc | sed -n ${l1}p | awk '{ print $10 }')` - lev2=`echo $(cdo info -seltimestep,1 -selvar,gdept mesh_zgr.nc | sed -n ${l2}p | awk '{ print $10 }')` - fi - cdfvertmean a1 $2 T $lev1 $lev2 - rm -f a1 - ncrename -O -v sovertmean,vertmean -d time_counter,time -v time_counter,time vertmean.nc - mv vertmean.nc outputvertmean_$jt.nc - list=$list" "outputvertmean_$jt.nc - rm -f intvertmean.nc a? -# #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN - ncatted -O -a valid_max,vertmean,d,, outputvertmean_$jt.nc outputvertmean_$jt.nc - ncatted -O -a valid_min,vertmean,d,, outputvertmean_$jt.nc outputvertmean_$jt.nc - ncatted -O -a standard_name,time,a,c,time outputvertmean_$jt.nc outputvertmean_$jt.nc - ncatted -O -a units,time,o,c,'seconds since 1993-05-01 00:00:00' outputvertmean_$jt.nc outputvertmean_$jt.nc - ncatted -O -a long_name,time,a,c,'Time axis' outputvertmean_$jt.nc outputvertmean_$jt.nc -done -cdo cat $list $5 -ncks -A -v time $1 $5 -rm -f $list -setminmax $5 vertmean -ncrename -v vertmean,$2 $5 -#typeset var level=`echo $(cdo info -selvar,$2 -setctomiss,0 $5 | sed -n 2p | awk '{ print $7 }')` -#typeset var lev=`echo $(cdo info -seltimestep,1 -selvar,$2 -setctomiss,0 $1 | grep $level | awk '{ print $1 }')` -lev=$3 -echo $lev -cp $5 tmp_${lev}.nc -## Here we interpolate horizontally onto a regular grid - ln -sf /esnas/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc - ln -sf /shared/earth/software/scripts/interpolation/scrip_use scrip_use - cat > scrip_use_in < You can test your function by defining the CON_FILES and NEMOVERSION @ -# variables and by sourcing the current file, the meshmasks will be @ -# available after sourcing, remember to source again after any @ -# modification of your function @ -# --> Your function should work on input files of any resolution @ -# ORCA1/ORCA025/ORCA2 @ -# --> Your function should work on input files of any time length @ -# --> The output file should contain a proper time axis that you can copy @ -# from your input file @ -# --> The output file should be at most a 3d field including the time @ -# dimension @ -# 3) Write a short description of your function, and add its name to the @ -# list above @ -# 4) Go the the ocean_pp.sh script to add a call to your function @ -# @ -# Any doubt ---> vguemas@ic3.cat @ -#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# Link constant file for co # -############################################################################### - -ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_hgr.nc -ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_zgr.nc -ln -sf ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mask.nc -ln -sf ${CON_FILES}/new_maskglo.${NEMOVERSION}.nc new_maskglo.nc - -if [ -e ${CON_FILES}/mask.regions.${NEMOVERSION}.nc ] ; then -cp ${CON_FILES}/mask.regions.${NEMOVERSION}.nc mask_regions.nc -fi - -if [[ ! -f mask.nc ]] ; then - echo "No configuration files for cdftools" - exit -fi - -############################################################################### -# Reduced number of variables in diag files to save disk space # -# # -# $1 : input grid_T file name # -# $2 : input icemod file name # -# $3 : suffix of output files with nc extension # -# # -# Created in February 2012 Author : vguemas@ic3.cat # -# May 2014 : Compatibility with PA changes to oce output - Virginie # -############################################################################### - -function reduce_mmo { -ncks -O -v sosstsst,sosaline,somixhgt,somxl010,sossheig $1 oce_${3} -typeset var lstvars=`cdo showvar $2` -if [[ ${lstvars/ileadfra} != ${lstvars} ]] ; then - ncks -O -v isnowthi,iicethic,ileadfra,iicetemp $2 ice_${3} -else - ncks -O -v isnowthi,iicethic,iiceconc,iicetemp $2 ice_${3} -fi -ncks -O -v votemper $1 t3d_${3} -} -############################################################################### -# Copy diags or MMO files from esnas # -# # -# $1 : starting date # -# $2 : expid # -# $3 : member # -# $4 : starting leadtime # -# $5 : end leadtime # -# $6 : chunk length in month # -# $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 # -# Option 10: June 2013 isabel.andreu-burillo@ic3.cat -############################################################################### - -function get_diagsMMO { -typeset var yyyy0=`echo $1|cut -c1-4` -typeset var mm0=`echo $1|cut -c5-6` -if [ -z "${10}" ] ; then - typeset var lstypes="grid_T grid_U grid_V grid_W icemod" -else - typeset var lstypes=${10} -fi - -typeset var jt -typeset var year1 -typeset var year2 -typeset var mon1 -typeset var mon2 -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 /esnas/exp/$7/$2/$1/fc$3/outputs/$8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar . - if [[ "$8" == "MMO" ]]; then - for filetype in $lstypes; do - tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar "*${freqkeep}*${filetype}*" - done - else - tar --wildcards -xvf $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar - fi - rm -f $8_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)01-${year2}$(printf "%02d" $mon2)*.tar - if [[ `ls *.gz` != '' ]] ; then gunzip -f *.gz ; fi - ipcs -a -done - -typeset var listroots -case $8 in - 'diags' ) - listroots="t3d heat_sal_mxl ice moc psi sal_0-300m sal_300-5400m" - if [[ `ls sstsimld*` != '' ]] ; then - listroots=$listroots" sstsimld" - elif [[ `ls sstsssmld*` != '' ]] ; then - listroots=$listroots" sstsssmld" - else - listroots=$listroots" oce" - fi - ;; - 'MMO' ) listroots=$lstypes ;; -esac -case $9 in - 'daily') freqexcl1='1m' ; freqexcl2='MM' ;; - 'monthly' ) freqexcl1='1d' ; freqexcl2='DD' ;; - *) freqexcl1='1d' ; freqexcl2='DD' ;; -esac - -function concat_startdate { - typeset var root - typeset var lstfiles - for root in ${listroots[@]} ; do - ipcs -a - if [[ "$8" == "MMO" ]] ; then - lstfiles=`ls *${root}* | grep -v "${root}_$2_$1_fc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" | grep -v "km" ` - else - lstfiles=`ls ${root}* | grep -v "${root}_$2_$1_fc" | grep -v "${freqexcl1}" | grep -v "${freqexcl2}" | grep -v "km" ` - fi - if [[ ! -z ${lstfiles} ]] ; then - - file1=`echo "${lstfiles}" | tail -1` - cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` - rm ff - #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN - if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then - 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 - if [[ $root == 'heat_sal_mxl' ]] ; then - for file in $lstfiles ; do - ncatted -O -a valid_max,somxlheatc,d,, $file $file - ncatted -O -a valid_min,somxlheatc,d,, $file $file - done - fi - fi - - outfile=${root}_$2_$1_fc$3_$(($yyyy0+(10#$mm0+$4-2)/12))$(printf "%02d" $(((10#$mm0+$4-2)%12+1)))_${year2}$(printf "%02d" $mon2).nc - 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 ${outfile} - timevar=`ncdump -h ${outfile} | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time ${outfile} ; fi - if [[ $root == 'moc' ]] ; then - lstdims=`ncdump -h ${outfile} | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` - if [[ ${lstdims/gsize} != ${lstdims} ]] ; then - ncrename -d gsize,y ${outfile} - fi - lenx=`ncdump -h ${outfile} | grep 'x =' | head -1 | awk '{print $3}'` - if [[ $lenx > 1 ]] ; then - if [[ ${lstvars/nav_lon} != ${lstvars} ]] ; then - ncks -O -x -v nav_lon,nav_lat ${outfile} ${outfile} - fi - ncrename -d x,y ${outfile} - fi - ncks -A -v nav_lon,nav_lat `echo $lstfiles | awk '{print $1}' ` ${outfile} - fi - rm -f $lstfiles - if [[ $root == 'sstsimld' || $root == 'sstsssmld' ]] ; then mv ${outfile} oce_$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 - done -} - -concat_startdate $1 $2 $3 $4 $5 $6 $7 $8 - -# These lines aim at concatenating the daily means as well and computing the monthly means from these daily means -if [[ $9 == 'monthly' ]] ; then - freqexcl1='1m' ; freqexcl2='MM' - for root in ${listroots[@]} ; do - outfile=${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 [[ -e $outfile ]] ; then - mv $outfile ${root}_1m.nc - fi - done - concat_startdate $1 $2 $3 $4 $5 $6 $7 $8 - for root in ${listroots[@]} ; do - ipcs m - outfile=${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 [[ -e $outfile ]] ; then - cdo monmean $outfile ${root}_daily2monthly.nc - rm -f $outfile - if [[ -e ${root}_1m.nc ]] ; then - mv ${root}_1m.nc $outfile - ncks -A ${root}_daily2monthly.nc $outfile - rm -f ${root}_daily2monthly.nc - else - mv ${root}_daily2monthly.nc $outfile - fi - else - if [[ -e ${root}_1m.nc ]] ; then - mv ${root}_1m.nc $outfile - fi - fi - done -fi - -rm -f *${freqexcl1}* *${freqexcl2}* - -} -############################################################################### -# Copy NEMOVAR files from esnas # -# # -# $1 : expid # -# $2 : member # -# $3 : start year # -# $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 { - -if [ -z "$5" ] ; then - typeset var moni=9 -else - typeset var moni=$5 -fi - -if [ -z "$5" ] ; then - typeset var monf=8 -else - typeset var monf=$6 -fi - -typeset var path -typeset var yearf -case $1 in - 'nemovar_s4') path=/esnas/exp/ECMWF/NEMOVAR_S4/outputs/fc$2/s4 ;; - 'nemovar_combine') path=/esnas/exp/ECMWF/NEMOVAR_COMBINE/outputs/opa0/fa9p_1m ;; -esac -typeset var year -typeset var mon -for year in $(seq $3 $4) ; do - case $year in - $3) mona=${moni} ;; - *) mona=1 ;; - esac - case $year in - $4) monb=${monf} ;; - *) monb=12 ;; - esac - for mon in $(seq $mona $monb); do - cp ${path}_fc$2_${year}$(printf "%02d" $mon)*.gz . - done -done -gunzip -f *.gz - -typeset var listroots=${7} -typeset var root -typeset var lstfiles -typeset var ntimes -typeset var jt -for root in ${listroots[@]} ; do - lstfiles=`ls *fc${2}*${root}* | grep -v "${root}_$1_195709_fc$2_${3}09_${4}$(printf "%02d" $monb).nc"` - ncrcat -O -x -v vorbiasp $lstfiles tmp_${root}.nc - cdo settaxis,${3}-$(printf "%02d" $moni)-15,12:00,1mon tmp_${root}.nc ${root}_$1_19570901_fc$2_${3}$(printf "%02d" $moni)_${4}$(printf "%02d" $monf).nc - rm -f $lstfiles tmp_${root}.nc -done -} -############################################################################### -# Copy GLORYS files from esnas # -# # -# $1 : start year # -# $2 : end year # -# $3 : start month # -# $4 : end month # -# # -# Created in June 2013 Author : vguemas@ic3.cat # -############################################################################### - -function get_glorys { -typeset var path=/esnas/exp/MERCATOR/GLORYS2V1/outputs/ORCA1L46 #ORCA025L75_glorys -typeset var lstfiles="" -for year in $(seq $1 $2) ; do - cp ${path}/vosaline_${year}.nc . - cp ${path}/votemper_${year}.nc . - ncks -A vosaline_${year}.nc votemper_${year}.nc - rm -f vosaline_${year}.nc - lstfiles=${lstfiles}" "votemper_${year}.nc -done -cdo cat ${lstfiles} tmp.nc -cdo settaxis,${1}-01-15,12:00,1mon tmp.nc tmp2.nc -cdo seldate,${1}-$(printf "%02d" $3)-00,${2}-$(printf "%02d" $4)-31 tmp2.nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc -rm -f ${lstfiles} tmp.nc tmp2.nc -ncks -O -x -v nav_lon,nav_lat,x_2,y_2 grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc -ncks -A -v nav_lon,nav_lat mesh_hgr.nc grid_T_glorys2v1_19930101_fc0_${1}$(printf "%02d" $3)_${2}$(printf "%02d" $4).nc -} -############################################################################### -# Clean diags or MMO files after postprocessing # -# # -# $1 : starting date # -# $2 : expid # -# $3 : member # -# $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 { -typeset var yyyy0=`echo $1|cut -c1-4` -typeset var mm0=`echo $1|cut -c5-6` -typeset var year1=$(($yyyy0+(10#$mm0+$4-2)/12)) -typeset var year2=$(($yyyy0+(10#$mm0+$5-2)/12)) -typeset var mon1=$(((10#$mm0+$4-2)%12+1)) -typeset var mon2=$(((10#$mm0+$5-2)%12+1)) - -typeset var listroots - case $6 in - 'diags' ) listroots="t3d" ;; - 'MMO' ) - if [ -z "${7}" ] ; then - listroots="grid_T grid_U grid_V grid_W icemod" - else - listroots=${7} - fi - ;; - esac -typeset var root -typeset var lstfiles -for root in ${listroots[@]} ; do - rm -f ${root}_$2_$1_fc$3_${year1}$(printf "%02d" $mon1)_${year2}$(printf "%02d" $mon2).nc -done -} -############################################################################### -# Vertically averaged salt content # -# # -# $1 : input grid_T file name # -# $2 : upper depth of the layer (in meters) # -# $3 : lower depth of the layer (in meters) # -# $4 : output file name (=> 2D) # -# # -# Created in February 2012 Author : vguemas@ic3.cat # -############################################################################### - -function vertmeansal { -cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` -rm ff -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -for jt in $(seq 1 $ntime); do - ncks -d time,$((jt-1)) $1 intvertmeansal.nc - cdfvertmean intvertmeansal.nc vosaline T $2 $3 - ncrename -O -v sovertmean,vertmeansal -d time_counter,time -v time_counter,time vertmean.nc - mv vertmean.nc outputvertmeansal_$jt.nc - list=$list" "outputvertmeansal_$jt.nc - rm -f intvertmeansal.nc - #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN - if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then - ncatted -O -a valid_max,vertmeansal,d,, outputvertmeansal_$jt.nc outputvertmeansal_$jt.nc - ncatted -O -a valid_min,vertmeansal,d,, outputvertmeansal_$jt.nc outputvertmeansal_$jt.nc - fi -done -cdo cat $list $4 -ncks -A -v time $1 $4 -rm -f $list -setminmax $4 vertmeansal -} -############################################################################### -# Compute mixed layer heat and salt content # -# # -# $1 : input grid_T file name # -# $2 : output file name (=> 2D x-y ) # -# # -# Created in February 2012 Author : vguemas@ic3.cat # -################################################################################ - -function heat_sal_mxl { -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -typeset var lstvars=`cdo showvar $1` -for jt in $(seq 1 $ntime); do - ncks -d time,$((jt-1)) $1 intheat_sal_mxl.nc - if [[ ${lstvars/somxl010} == ${lstvars} ]] ; then - cdfmxl intheat_sal_mxl.nc mxl.nc - ncrename -d time_counter,time mxl.nc - ncks -A mxl.nc intheat_sal_mxl.nc - rm -f mxl.nc - fi - cdfmxlheatc intheat_sal_mxl.nc - if [[ $lstvars != ${lstvars/vosaline} ]] ; then - cdfmxlsaltc intheat_sal_mxl.nc - ncks -A mxlsaltc.nc mxlheatc.nc - rm -f mxlsaltc.nc - fi - mv mxlheatc.nc outputintheat_sal_mxl_$jt.nc - timevar=`ncdump -h outputintheat_sal_mxl_$jt.nc | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time outputintheat_sal_mxl_$jt.nc ; fi - list=$list" "outputintheat_sal_mxl_$jt.nc - rm -f intheat_sal_mxl.nc -done -cdo cat $list $2 -ncks -A -v time $1 $2 -rm -f $list -setminmax $2 somxlheatc -if [[ $lstvars != ${lstvars/vosaline} ]] ; then setminmax $2 somxlsaltc ; fi -} -############################################################################### -# Pointwise Ocean Heat Content in a specified ocean thickness # -# (J/m-2) -# # -# $1 : input grid_T file name # -# $2 : upper depth of the layer (in meters) # -# $3 : lower depth of the layer (in meters) # -# $4 : output file name (=> 2D x-y ) # -# # -# Created in June 2012 Author : isabel.andreu-burillo@ic3.cat # -# May 2014 - Virginie Guemas - Way around the bc that does not work on moore # -############################################################################### - -function ohc_specified_layer { -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -ncap2 -v -O -s "heatc_sl=tmask*e3t" mesh_zgr.nc e3t_file.nc -ncrename -d t,time -d z,deptht e3t_file.nc -for jt in $(seq 1 $ntime); do - cdo seltimestep,$jt $1 intohc_slayer.nc - 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 - ncks -d deptht,$2,$3 heatc_sl_out.nc heatc_sl_top.nc - #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 - # lower_bnd=`echo "$3 + 200.0" | bc` -> does not work on new moore - # strip out the .* from $3: - stripped=`echo ${3/.*}` - # addition with float returned: - lower_bnd=`echo $(printf "%f" $(( $stripped + 200)))` - 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 - 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 - ## Here, add the residual contribution, before adding it to the main contribution - ncrename -v deptht,layerthcknss level_below.nc - ncrename -v deptht,layerthcknss level_above.nc - ncbo -A --op_typ=sub -v layerthcknss level_below.nc level_above.nc depth_diff_lay.nc - ncrename -v layerthcknss,heatc_sl depth_diff_lay.nc - ncap2 -s "heatc_sl=($3 - layerthcknss)" level_above.nc depth_diff_sublay.nc - ncbo --op_typ=/ -v heatc_sl depth_diff_sublay.nc depth_diff_lay.nc factor.nc - ncrename -v heatc_sl,factor factor.nc #to be commented - ncks -A -v factor factor.nc level_below.nc - rm -f depth_diff_sublay.nc depth_diff_lay.nc - ncap2 -O -s "heatc_sl=(factor * heatc_sl)" level_below.nc level_below.nc - ncwa -O -a deptht level_below.nc level_below.nc - ncbo --op_typ=+ -v heatc_sl heatc_sl_top.nc level_below.nc total_heatc_sl.nc - ncap2 -s "heatc_sl=1020.0*4000*heatc_sl" total_heatc_sl.nc heatc_sl_$jt.nc - list=$list" "heatc_sl_$jt.nc - rm -f depth_diff_lay.nc depth_diff_sublay.nc - rm -f heatc_sl_out.nc heatc_sl_top.nc heatc_sl_top_invert.nc heatc_sl_bottom.nc - rm -f level_above.nc level_below.nc - rm -f intohc_slayer.nc intmeantem.nc vertmean.nc total_heatc_sl.nc - rm -f factor.nc -done -cdo cat $list $4 -ncks -A -v time $1 $4 -rm -f $list -rm -f e3t_file.nc -setminmax $4 heatc_sl -} -############################################################################### -# Compute the MOC for oceanic basins # -# # -# $1 : input grid_V file name # -# $2 : output file name (=> 2D, depth-y) # -# # -# Created in March 2012 Author : vguemas@ic3.cat # -############################################################################### - -function moc { -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -for jt in $(seq 1 $ntime); do - cdo seltimestep,$jt $1 intmoc.nc - cdfmoc intmoc.nc - ncwa -O -a x moc.nc outmoc_$jt.nc - ncks -O -x -v nav_lon,nav_lat outmoc_$jt.nc outmoc_$jt.nc - timevar=`ncdump -h outmoc_$jt.nc | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time outmoc_$jt.nc ; fi - list=$list" "outmoc_$jt.nc - rm -f intmoc.nc moc.nc -done -cdo cat $list $2 -lstdims=`ncdump -h $2 | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` -if [[ ${lstdims/gsize} != ${lstdims} ]] ; then - ncrename -d gsize,y $2 -fi -ncks -A -v nav_lon,nav_lat $1 $2 -ncks -A -v time $1 $2 -rm -f $list -} -############################################################################### -# # -# Compute the intensity of convection in the four main convection sites # -# # -# $1 : input oce file name containing somxl010 # -# $2 : input grid # -# $3 : output file name (=> index) # -# # -# Created in October 2013 Author : vguemas@ic3.cat # -############################################################################### - -function convection { -case $2 in - 'Ec2.3_O1L42'|'Ec3.0_O1L46'|'N3.2_O1L42'|'N3.3_O1L46'|'nemovar_O1L42') - A1=225;A2=245;A3=215;A4=255; - B1=245;B2=290;B3=215;B4=245; - C1=260;C2=310;C3=245;C4=291; - D1=225;D2=280;D3=1;D4=50;; - - 'Ec3.0_O25L46'|'Ec3.0_O25L75'|'glorys2v1_O25L75') - stop"Option convection not available yet for this configuration" - ;; -esac - -cdo fldmax -selindexbox,${A1},${A2},${A3},${A4} $1 Labrador.nc -ncrename -v somxl010,Labrador Labrador.nc -ncks -v Labrador Labrador.nc convection.nc -rm -f Labrador.nc - -cdo fldmax -selindexbox,${B1},${B2},${B3},${B4} $1 Irminger.nc -ncrename -v somxl010,Irminger Irminger.nc -ncks -A -v Irminger Irminger.nc convection.nc -rm -f Irminger.nc - -cdo fldmax -selindexbox,${C1},${C2},${C3},${C4} $1 GIN.nc -ncrename -v somxl010,GIN GIN.nc -ncks -A -v GIN GIN.nc convection.nc -rm -f GIN.nc - -cdo fldmax -selindexbox,${D1},${D2},${D3},${D4} $1 Wedell.nc -ncrename -v somxl010,Wedell Wedell.nc -ncks -A -v Wedell Wedell.nc convection.nc -rm -f Wedell.nc - -mv convection.nc $3 -} -############################################################################### -# # -# Compute the barotropic stream function # -# # -# $1 : input grid_U file name # -# $2 : input grid_V file name # -# $3 : output file name without nc extension (=> 2D x-y) # -# # -# Created in March 2012 Author : vguemas@ic3.cat # -############################################################################### - -function psi { -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -for jt in $(seq 1 $ntime); do - cdo seltimestep,$jt $1 intU.nc - cdo seltimestep,$jt $2 intV.nc - cdfpsi intU.nc intV.nc - mv psi.nc psi_U.nc - cdfpsi intU.nc intV.nc V - mv psi.nc psi_V.nc - ncea psi_U.nc psi_V.nc psi_${jt}.nc - timevar=`ncdump -h psi_$jt.nc | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time psi_$jt.nc ; fi - list=$list" "psi_$jt.nc - rm -f intU.nc intV.nc psi_U.nc psi_V.nc -done -cdo cat $list ${3} -ncks -A -v time $1 ${3} -rm -f $list -} -############################################################################### -# # -# Compute the intensity of the subtropical and subpolar gyres # -# # -# $1 : input psi file name # -# $2 : input grid # -# $3 : output file name ( => index ) # -# # -# Created in October 2013 Author : vguemas@ic3.cat # -############################################################################### - -function gyres { -case $2 in - 'Ec2.3_O1L42'|'Ec3.0_O1L46'|'N3.2_O1L42'|'N3.3_O1L46'|'nemovar_O1L42') - A1=230;A2=275;A3=215;A4=245; - B1=70;B2=145;B3=195;B4=235; - C1=45;C2=175;C3=165;C4=220; - D1=195;D2=275;D3=175;D4=225; - E1=70;E2=205;E3=120;E4=145; - F1=235;F2=300;F3=120;F4=145; - G1=320;G2=30;G3=110;G4=180; - H1=1;H2=361;H3=1;H4=65;; - - 'Ec3.0_O25L46'|'Ec3.0_O25L75'|'glorys2v1_O25L75') - stop"Option gyres not available yet for this configuration" - ;; -esac - -cdo fldmin -selindexbox,${A1},${A2},${A3},${A4} $1 subpolar_NAtl.nc -ncrename -v sobarstf,subpolNAtl subpolar_NAtl.nc -cdo mulc,-1 subpolar_NAtl.nc gyres.nc -rm -f subpolar_NAtl.nc - -cdo fldmin -selindexbox,${B1},${B2},${B3},${B4} $1 subpolar_NPac.nc -ncrename -v sobarstf,subpolNPac subpolar_NPac.nc -cdo mulc,-1 subpolar_NPac.nc tmp.nc -ncks -A tmp.nc gyres.nc -rm -f subpolar_NPac.nc tmp.nc - -cdo fldmax -selindexbox,${C1},${C2},${C3},${C4} $1 subtrop_NPac.nc -ncrename -v sobarstf,subtropNPac subtrop_NPac.nc -ncks -A subtrop_NPac.nc gyres.nc -rm -f subtrop_NPac.nc - -cdo fldmax -selindexbox,${E1},${E2},${E3},${E4} $1 subtrop_SPac.nc -ncrename -v sobarstf,subtropSPac subtrop_SPac.nc -ncks -A subtrop_SPac.nc gyres.nc -rm -f subtrop_SPac.nc - -cdo fldmax -selindexbox,${D1},${D2},${D3},${D4} $1 subtrop_NAtl.nc -ncrename -v sobarstf,subtropNAtl subtrop_NAtl.nc -ncks -A subtrop_NAtl.nc gyres.nc -rm -f subtrop_NAtl.nc - -cdo fldmax -selindexbox,${F1},${F2},${F3},${F4} $1 subtrop_SAtl.nc -ncrename -v sobarstf,subtropSAtl subtrop_SAtl.nc -ncks -A subtrop_SAtl.nc gyres.nc -rm -f subtrop_SAtl.nc - -cdo fldmax -selindexbox,${G1},${G2},${G3},${G4} $1 subtrop_Ind.nc -ncrename -v sobarstf,subtropInd subtrop_Ind.nc -ncks -A subtrop_Ind.nc gyres.nc -rm -f subtrop_Ind.nc - -cdo fldmax -selindexbox,${H1},${H2},${H3},${H4} $1 ACC.nc -ncrename -v sobarstf,ACC ACC.nc -ncks -A ACC.nc gyres.nc -rm -f ACC.nc - -mv gyres.nc $3 - -} -############################################################################### -# # -# Compute an Atlantic MOC index by averaging the meridional overturning # -# in a latitude band between 1km and 2km # -# or any other index averaging the meridional overturning in # -# a given basin and a given domain # -# # -# $1 : input moc file name # -# $2 : latitude min # -# $3 : latitude max # -# $4 : output file name ( => index ) # -# $5 : depth min (default : 1km) # -# $6 : depth max (default : 2km) # -# $7 : basin (default : zomsfatl) # -# # -# Created in March 2012 Author : vguemas@ic3.cat # -############################################################################### - -function area_moc { -if [ -z "$5" ] ; then - typeset var depmin=-1000.0 -else - typeset var depmin=-$5 -fi -if [ -z "$6" ] ; then - typeset var depmax=-2000.0 -else - typeset var depmax=-$6 -fi -if [ -z "$7" ] ; then - typeset var basin=zomsfatl -else - typeset var basin=$7 -fi -lstdims=`ncdump -h $1 | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` -if [[ ${lstdims/x} != ${lstdims} ]] ; then - ncwa -O -a x $1 tmpmoc.nc -else - cp $1 tmpmoc.nc -fi -ncrename -O -d y,lat -v nav_lat,lat tmpmoc.nc tmpmoc.nc -ncks -O -v $basin,time,depthw,lat tmpmoc.nc tmpmoc.nc -ncks -d lat,$2,$3 -d depthw,${depmax},${depmin} tmpmoc.nc area_moc.nc -cdo vertmean area_moc.nc area_ave_moc.nc -ncap -O -s "coslat[lat]=cos(lat[lat]*3.141592657/180.0)" area_ave_moc.nc area_ave_moc2.nc -ncwa -w coslat -a lat area_ave_moc2.nc area_ave_moc3.nc -ncks -O -v $basin,time area_ave_moc3.nc $4 -rm -f tmpmoc.nc area_moc.nc area_ave_moc2.nc area_ave_moc3.nc -if [[ $4 != area_ave_moc.nc ]] ; then - rm -f area_ave_moc.nc -fi -} -############################################################################### -# # -# Compute an Atlantic MOC index by finding the maximum of the annual # -# mean meridional overturning in a latitude / depth region # -# # -# $1 : input moc file name # -# $2 : latitude min # -# $3 : latitude max # -# $4 : depth mean # -# $5 : depth max # -# $6 : output file name ( => index ) # -# # -# Created in March 2012 Author : vguemas@ic3.cat # -############################################################################### - -function max_moc { -if [ ! -f $6 ] ; then - ncecat -h $1 tmpmoc1.nc - lstdims=`ncdump -h tmpmoc1.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` - if [[ ${lstdims/x} != ${lstdims} ]] ; then - ncwa -O -a x tmpmoc1.nc tmpmoc1.nc - fi - ncrename -d record,x tmpmoc1.nc - ncpdq -O -h -a time,x tmpmoc1.nc tmpmoc1.nc - ncpdq -O -h -a depthw,x tmpmoc1.nc tmpmoc1.nc - ncpdq -O -h -a y,x tmpmoc1.nc tmpmoc1.nc - cdo yearmean tmpmoc1.nc tmpmoc.nc - typeset var ntime=`cdo ntime tmpmoc.nc` - typeset var list="" - for jt in $(seq 1 $ntime) ; do - cdo seltimestep,$jt tmpmoc.nc tmpmoc2.nc - cdfmaxmoc tmpmoc2.nc atl $2 $3 $4 $5 - mv maxmoc.nc maxmoc_$jt.nc - timevar=`ncdump -h maxmoc_$jt.nc | grep UNLIMITED | awk '{print $1}'` - if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time maxmoc_$jt.nc ; fi - list=${list}" "maxmoc_$jt.nc - rm -f tmpmoc2.nc - done - cdo cat $list $6 - ncks -A -v time tmpmoc.nc $6 - rm -f $list tmpmoc.nc tmpmoc1.nc -fi -} -############################################################################### -# # -# Compute the sea ice extent (1000km2), area (1000km2), volume (km3) # -# and mean thickness (m) in both hemispheres or a specified region. # -# # -# $1 : input ice file name # -# $2 : output file name ( => index ) # -# $3 : region of interest (if empty default is global) # -# # -# Created in April 2012 Author : vguemas@ic3.cat # -# Modified in June 2014 Author : neven.fuckar@ic3.cat # -# # -# Computation of the properties in various selected regions according to # -# mask.regions.${NEMOVERSION}.nc (mask_regions.nc) is based on modification # -# of mask.regions.ORCA1.noverticalinfo.Matt.nc from Matthieu Chevallier. # -# # -############################################################################### - -function siasiesiv { -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'|'Ec3.0_O25L75') 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 ;; -esac - -typeset var ntime=`cdo ntime $1` -typeset var list1="" -typeset var list2="" -typeset var jt - -if [ ! -z "$3" ] ; then - mv mask.nc mask_tmp.nc - mv mask_regions.nc mask.nc - ncrename -h -v $3,tmask mask.nc -fi - -for jt in $(seq 1 $ntime) ; do - cdo seltimestep,$jt $1 tmpice.nc - cdficediags tmpice.nc>ice.txt - for d in N S;do - ncdump toto_${d}.nc > ice_template.cdl - sia=`grep ${d}Area ice.txt |awk '{print $4}'` - sie=`grep ${d}Exnsidc ice.txt|awk '{print $4}'` - siv=`grep ${d}Volume ice.txt|awk '{print $4}'` - sed -e "s/sia =.*/sia = $sia ;/" ice_template.cdl > ice_template2.cdl - sed -e "s/sie =.*/sie = $sie ;/" ice_template2.cdl > ice_template3.cdl - sed -e "s/siv =.*/siv = $siv ;/" ice_template3.cdl > ice_template.cdl - ncgen -o ice_${d}_${jt}.nc ice_template.cdl - rm -f ice_template.cdl ice_template2.cdl ice_template3.cdl - done - list1=$list1" "ice_N_${jt}.nc - list2=$list2" "ice_S_${jt}.nc - rm -f ice.txt tmpice.nc icediags.nc -done -cdo cat $list1 ice_N_${2} -cdo cat $list2 ice_S_${2} -ncks -A -v time $1 ice_N_${2} -ncks -A -v time $1 ice_S_${2} -rm -f $list1 $list2 toto_N.nc toto_S.nc - -for d in N S;do - ncatted -O -a units,sia,m,c,1000km2 ice_${d}_${2} - ncatted -O -a units,sie,m,c,1000km2 ice_${d}_${2} - - ncks -v siv ice_${d}_${2} siv_${d}_${2}1 - ncks -v sia ice_${d}_${2} sia_${d}_${2}1 - ncrename -h -v sia,siv sia_${d}_${2}1 - ncbo -O --op_typ=dvd siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} - ncatted -O -a standard_name,siv,m,c,Mean_sea_ice_thickness sit_${d}_${2} - ncatted -O -a long_name,siv,m,c,"Mean sea ice thickness" sit_${d}_${2} - ncatted -O -a units,siv,m,c,m sit_${d}_${2} - cdo ltc,100 sit_${d}_${2} sit_${d}_${2}1 - cdo ifthenelse sit_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 - ncrename -h -v siv,sit sit_${d}_${2}2 - ncks -A sit_${d}_${2}2 ice_${d}_${2} - - rm siv_${d}_${2}1 sia_${d}_${2}1 sit_${d}_${2} sit_${d}_${2}1 sit_${d}_${2}2 -done - -setminmax ice_N_${2} sia sie siv sit -setminmax ice_S_${2} sia sie siv sit - -if [ ! -z "$3" ] ; then - ncrename -h -v tmask,$3 mask.nc - mv mask.nc mask_regions.nc - mv mask_tmp.nc mask.nc -fi - -} -############################################################################### -# # -# Compute the total ocean heat extent # -# # -# $1 : input temperature file name # -# $2 : output file name ( => 2D x-y ) # -# $3 : basin (NAtl, NPac, TAtl, TPac, TInd, Anta, Arct, Glob) Default : Glob # -# $4 = 0 if $3 = Glob # -# $4 : mixed layer (1=only, 0=included, -1=without) Default : 0 # -# $5 : upper level of the layer (optional) Default : top # -# $6 : lower level of the layer (optional) Default : bottom # -# # -# Created in May 2012 Author : vguemas@ic3.cat # -############################################################################### - -function ohc { -cp ${CON_FILES}/depth.${NEMOVERSION}.txt depth.txt -# -# Input arguments -# -if [ -z "$3" ] ; then - typeset var basin='Glob' -else - typeset var basin=$3 -fi -if [ -z "$4" ] ; then - typeset var mxl=0 -else - typeset var mxl=$4 -fi -if [ -z "$5" ] ; then - typeset var up=1 -else - typeset var up=$5 -fi -if [ -z "$6" ] ; then - typeset var down=`cat depth.txt | wc -l` -else - typeset var down=$6 -fi - -if [[ ${up} -eq 1 ]] ; then - typeset var depmin=0 -else - typeset var depmin=`cat depth.txt |head -${up} |tail -1 | awk '{print $2}' | awk '{printf "%.0f",$1}'` -fi -typeset var depmax=`cat depth.txt |head -${down} |tail -1 | awk '{print $2}' | awk '{printf "%.0f",$1}'` - -cp ${CON_FILES}/heatc_template.nc template_heatc.nc -ncdump template_heatc.nc > template_heatc.cdl -#exec=/home/huidu/download/CDFTOOLS_2.1/cdfheatc-cfu -exec=/home/Earth/vguemas/CDFTOOLS_2.1/cdfheatc-cfu -# -# Define some parameters -# -typeset var para -typeset var output -typeset var nlev=`cat depth.txt | wc -l` -if [[ ! -z "$depmin" && ! -z "$depmax" ]] ; then - if [[ $depmin != 0 || ${down} != ${nlev} && ${down} != 0 ]] ; then - output=${depmin}-${depmax}'_' - fi -fi - -case $basin in - 'NAtl') para="atl $mxl 0 0 10 65"; output='NAtl_10N65N_'${output} ;; - 'TAtl') para="atl $mxl 0 0 -30 30" ; output='TAtl_30S30N_'${output} ;; - 'NPac') para="pac $mxl 0 0 10 70" ; output='NPac_10N70N_'${output} ;; - 'TPac') para="pac $mxl 0 0 -30 30" ; output='TPac_30S30N_'${output} ;; - 'Arct') para="atl $mxl 0 0 65 90" ; output='Arc_65N90N_'${output} ;; - 'Anta') para="all $mxl 0 0 -90 -60" ; output='Ant_90S60S_'${output} ;; - 'TInd') para="ind $mxl 0 0 -30 30" ; output='TInd_30S30N_'${output} ;; - 'Glob') para="all $mxl 0 0 0 0" ;; -esac - -case $mxl in - 1) output='mxl_'${output} ;; - -1) output='nonmxl_'${output} ;; -esac -# -# Compute ohc -# -typeset var lstvars=`cdo showvar $1` -typeset var ntime=`cdo ntime $1` -typeset var list="" -typeset var jt -for jt in $(seq 1 $ntime) ; do - cdo seltimestep,$jt $1 tmpohc.nc - lstdims=`ncdump -h tmpohc.nc | awk /dimensions:/,/variables:/ | grep -v dimensions: | grep -v variables: | awk '{print $1}'` - if [[ ${lstdims/x_2} != ${lstdims} ]] ; then - if [[ ${lstdims/x} != ${lstdims} ]] ; then - ncwa -O -a x tmpohc.nc tmpohc.nc - fi - ncrename -d x_2,x tmpohc.nc - fi - if [[ ${lstvars/somxl010} != ${lstvars} ]] ; then - ncks -v somxl010 tmpohc.nc mxl.nc - else - cdfmxl tmpohc.nc mxl.nc - fi - $exec tmpohc.nc $para $up $down > tmp.log - cat tmp.log - thc=`cat tmp.log | grep "Total Heat content :" | awk '{print $5}'`; - uhc=`cat tmp.log | grep "Total Heat content/volume" | awk '{print $5}'`; - sed -e "s/thc =.*/thc = $thc ;/" template_heatc.cdl > template_heatc2.cdl - sed -e "s/uhc =.*/uhc = $uhc ;/" template_heatc2.cdl > template_heatc.cdl - ncgen -o heatc_${jt}.nc template_heatc.cdl - rm -f template_heatc2.cdl tmpohc.nc mxl.nc tmp.log - list=$list" "heatc_${jt}.nc -done -cdo cat $list ${output}$2 -ncks -h -A -v time $1 ${output}$2 -rm -f $list template_heatc.nc template_heatc.cdl depth.txt -setminmax ${output}$2 thc uhc -} -############################################################################### -# # -# Cut a meridional or zonal section # -# # -# # -# $1 : input file # -# $2 : input var # -# $3 : Z/M (zonal / meridional section) # -# $4 : lat/lon # -# $5 : output file ( => 2D ) # -# # -# Created in September 2012 Author : vguemas@ic3.cat # -# # -############################################################################### - -function cutsection { - typeset var ntime=`cdo ntime $1` - typeset var nx=`ncdump -h $1|grep 'x = '|head -1|cut -f3 -d" "` - typeset var ny=`ncdump -h $1|grep 'y = '|head -1|cut -f3 -d" "` - typeset var nz=`ncdump -h $1|grep 'depth'|head -1|cut -f3 -d" "` -cat>section.R<max(lon)) {exactpos=exactpos-360} - } - # Collect the indexes defining the section - listi=array(dim=switch('$3','Z'=$nx-2,'M'=$ny-1)) - listj=array(dim=switch('$3','Z'=$nx-2,'M'=$ny-1)) - for (jpt in 1:length(listi)) { - vect=switch('$3','Z'=lat[jpt,],'M'=lon[,jpt+1]) - if (min(abs(vect-exactpos))<(2*360./$nx)) { - pos=sort(abs(vect-exactpos),index.return=T)\$ix[1] - listi[jpt]=switch('$3','Z'=jpt+1,'M'=pos) - listj[jpt]=switch('$3','Z'=pos,'M'=jpt) - } - } - listi=listi[is.na(listi)==F] - listj=listj[is.na(listj)==F] - print(listi) - print(listj) - # Select variable at those indexes - fnc1=open.ncdf('$1') - varout=array(dim=c(length(listi),$nz,$ntime)) - for (jt in 1:$ntime) { - varin=get.var.ncdf(fnc1,'$2',start=c(1,1,1,jt),count=c($nx,$ny,$nz,1)) - varin[which(mask<0.5)]=1e20 - for (jpt in 1:length(listi)) { - varout[jpt,,jt]=varin[listi[jpt],listj[jpt],] - } - } - close.ncdf(fnc1) - # Write the output - wtime=dim.def.ncdf("time","",seq(1,$ntime),unlim=TRUE) - dimout=array(dim=length(listi)) - for (jpt in 1:length(listi)) { - dimout[jpt]=switch('$3','Z'=lon[listi[jpt],listj[jpt]],'M'=lat[listi[jpt],listj[jpt]]) - } - wsec=switch('$3','Z'=dim.def.ncdf("lon","",dimout),'M'=dim.def.ncdf("lat","",dimout)) - wdep=dim.def.ncdf("deptht","",depth) - wvar=var.def.ncdf("$2","",list(wsec,wdep,wtime),1e20) - fnc2=create.ncdf('$5',wvar) - put.var.ncdf(fnc2,wvar,varout) - close.ncdf(fnc2) -EOF1 -R CMD BATCH section.R -ncks -h -A -v time $1 $5 -} -############################################################################### -# # -# 3-dimensional conservative interpolation to the regular atmospheric grid # -# # -# $1 : input file # -# $2 : input var # -# $3 : output file ( => 3D ) # -# # -# Created in November 2012 Author : vguemas@ic3.cat # -# # -############################################################################### - -function interp3d { - typeset var nz=`ncdump -h $1|grep 'deptht'|head -1|cut -f3 -d" "` - ln -sf /shared/earth/software/scripts/interpolation/scrip_use scrip_use - for lev in $(seq 1 $nz) ; do - ncks -d deptht,$((lev-1)) -v $2 $1 tmp_${lev}.nc - ncwa -O -h -a deptht tmp_${lev}.nc tmp_${lev}.nc - ln -sf /esnas/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc - cat > scrip_use_in < 2D field ) # -# # -# Created in February 2012 Author : vguemas@ic3.cat # -# Modified (more generic, -# i.e. for any input var) in December 2014 # -# Author : eleftheria.exarchou@ic3.cat # -############################################################################### - -function vertmeanvar { - typeset var ntime=`cdo ntime $1` - typeset var list="" - typeset var jt -for jt in $(seq 1 $ntime); do - ncks -d time,$((jt-1)) $1 a1 - # The oras4 data do not have gdepth data in their mask, but only gdept_0, so: - if grep -q nemovar_s4 $1 ; then - l1=$(( $3 % 6 )) - l2=$(( $4 % 6 )) - ll1=$(( $3 / 6 + 1 )) - ll2=$(( $4 / 6 + 1 )) - lev1=`echo $(cdo output -selvar,gdept_0 mesh_zgr.nc | sed -n ${ll1}p | awk '{ print $'$l1' }')` - lev2=`echo $(cdo output -selvar,gdept_0 mesh_zgr.nc | sed -n ${ll2}p | awk '{ print $'$l2' }')` - else - l1=$(($3+1)) - l2=$(($4+1)) - lev1=`echo $(cdo info -seltimestep,1 -selvar,gdept mesh_zgr.nc | sed -n ${l1}p | awk '{ print $10 }')` - lev2=`echo $(cdo info -seltimestep,1 -selvar,gdept mesh_zgr.nc | sed -n ${l2}p | awk '{ print $10 }')` - fi - cdfvertmean a1 $2 T $lev1 $lev2 - rm -f a1 - ncrename -O -v sovertmean,vertmean -d time_counter,time -v time_counter,time vertmean.nc - mv vertmean.nc outputvertmean_$jt.nc - list=$list" "outputvertmean_$jt.nc - rm -f intvertmean.nc a? -# #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN - ncatted -O -a valid_max,vertmean,d,, outputvertmean_$jt.nc outputvertmean_$jt.nc - ncatted -O -a valid_min,vertmean,d,, outputvertmean_$jt.nc outputvertmean_$jt.nc - ncatted -O -a standard_name,time,a,c,time outputvertmean_$jt.nc outputvertmean_$jt.nc - ncatted -O -a units,time,o,c,'seconds since 1993-05-01 00:00:00' outputvertmean_$jt.nc outputvertmean_$jt.nc - ncatted -O -a long_name,time,a,c,'Time axis' outputvertmean_$jt.nc outputvertmean_$jt.nc -done -cdo cat $list $5 -ncks -A -v time $1 $5 -rm -f $list -setminmax $5 vertmean -ncrename -v vertmean,$2 $5 -#typeset var level=`echo $(cdo info -selvar,$2 -setctomiss,0 $5 | sed -n 2p | awk '{ print $7 }')` -#typeset var lev=`echo $(cdo info -seltimestep,1 -selvar,$2 -setctomiss,0 $1 | grep $level | awk '{ print $1 }')` -lev=$3 -echo $lev -cp $5 tmp_${lev}.nc -## Here we interpolate horizontally onto a regular grid - ln -sf /esnas/autosubmit/con_files/weigths/${NEMOVERSION}/rmp_${NEMOVERSION}_to_*_lev${lev}.nc rmp_${NEMOVERSION}_to_regular_lev${lev}.nc - ln -sf /shared/earth/software/scripts/interpolation/scrip_use scrip_use - cat > scrip_use_in < vguemas@ic3.cat -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# -# Preparing WORKDIR and set of available functions -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -export WORKDIR=/scratch/Earth/${USER}/tmp/post_ocean/$$ -mkdir -p $WORKDIR -cd $WORKDIR -source $PATHCOMMONOCEANDIAG/common_ocean_post.txt -# -# Interval of lead months be post-processed -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -case $expid in - 'nemovar_s4'|'nemovar_combine') moni=09 ; syeari=1957 ; syearf=1957 ; insdate=1 ; typeoutput='MMO' ; NEMOVERSION='nemovar_O1L42' ;; - 'glorys2v1') moni=01 ; syeari=1993 ; syearf=1993 ; insdate=1 ; typeoutput='MMO' ;; -esac -case $expid in - 'nemovar_s4') rootout='/esnas/exp/ECMWF/NEMOVAR_S4/monthly_mean' ;; - 'nemovar_combine') rootout='/esnas/exp/ECMWF/NEMOVAR_COMBINE/monthly_mean' ;; - 'glorys2v1') rootout='/esnas/exp/MERCATOR/GLORYS2V1/monthly_mean';; -esac -if [[ ${listpost[@]##max_moc} != ${listpost[@]} ]] || [[ -z "$ltimef" ]] || [[ -z "$ltime0" ]] ; then - if [[ ! -z "$year0" ]] && [[ ! -z "$yearf" ]] ; then - ltime0=$(((${year0}-${syeari})*12+1)) - ltimef=$(((${yearf}-${syeari}+1-(10#$moni+10)/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 -# ~~~~~~~~~~~~~~~~~~~~~ -if [[ $intsdate -eq 0 ]] ; then intsdate=1 ; fi # if only one start date, user might set -# intsdates to 0 which leads to an infinite loop below -for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do - # - # Interval of years to be post-processed - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - year0=$(($yeari+(10#$moni+$ltime0-2)/12)) - yearf=$(($yeari+(10#$moni+$ltimef-2)/12)) - - for memb in ${listmemb[@]} ; do - # - # Fetching the files on esnas - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - case $expid in - '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 "${list_files}" - esac - # - # Ready for the post-processing - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - for post in ${listpost[@]} ; do - - case $post in -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# You have created a function ? Enter its call right here under the flag chosen -# Remember to consider both 'MMO' and 'diags' cases -# Any doubt ---> vguemas@ic3.cat -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - 'ext_raw_oce') - if [[ $typeoutput == 'MMO' ]] ; then - lstvars=`cdo showvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc` - if [[ $raw_vars_ocean == '' ]] ; then - lstext=`echo $lstvars | sed s/\ /,/g` - else - if [[ $raw_vars_ocean == 'default' ]] ; then - lstextvar=( 'sosstsst' 'sosaline' 'somixhgt' 'somxl010' ) - lstext='' - for varex in ${lstextvar[@]} ; do - if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then - lstext=`echo ${lstext} ${varex}|sed s/\ /,/g` - fi - done - else - lstext=`echo ${raw_vars_ocean[@]} |sed s/\ /,/g` - fi - fi - if [ -z "$lstext" ] ; then - echo "The list of variables you wish to extract is not in your outputs" - exit 1 - else - ncks -O -v ${lstext} grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -# ncks -O -v ${lstext[@]} grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'ext_raw_ice') - if [[ $typeoutput == 'MMO' ]] ; then - lstvars=`cdo showvar icemod_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc` - if [[ $raw_vars_ice == '' ]] ; then - lstext=`echo $lstvars | sed s/\ /,/g` - else - if [[ $raw_vars_ice == 'default' ]] ; then - lstextvar=( 'isnowthi' 'iicethic' 'ileadfra' 'iicetemp' 'ice_pres' ) - lstext='' - for varex in ${lstextvar[@]} ; do - if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then - lstext=`echo ${lstext} ${varex}|sed s/\ /,/g` - fi - done - else - lstext=`echo $raw_vars_ice |sed s/\ /,/g` - fi - fi - if [ -z "$lstext" ] ; then - echo "The list of variables you wish to extract is not in your outputs" - exit 1 - else - ncks -O -v ${lstext} icemod_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ice_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'heat_sal_mxl') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f heat_sal_mxl_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - heat_sal_mxl grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc heat_sal_mxl_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'psi') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - psi grid_U_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc grid_V_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'gyres') - gyres psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $NEMOVERSION gyres_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - - 'lmsalc') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f sal_300-5400m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - vertmeansal grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 300 5400 sal_300-5400m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'usalc') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f sal_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - vertmeansal grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0 300 sal_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - - 'temp_lev') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f temp_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - vertmeanvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper $level1 $level2 temp_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - - 'sal_lev') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f sal_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - vertmeanvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline $level1 $level2 sal_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'ohc_specified_layer') - if [ ! -f ohc_2d_avg_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then - case $typeoutput in - 'MMO' ) pref='grid_T' ;; - 'diags') pref='t3d' ;; - esac - ohc_specified_layer ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 300.0 ohc_2d_avg_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ohc_specified_layer ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 300.0 800.0 ohc_2d_avg_300-800m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - - 'vert_Tsections') - case $typeoutput in - 'MMO' ) pref='grid_T' ;; - 'diags') pref='t3d' ;; - esac - for coord in 0 45 -45 -30 180 80 - do - if [[ $coord == '0' ]] || [[ $coord == '45' ]] || [[ $coord == '-45' ]] ; then - [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=S || direction=N - z_m=Z - else - [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=W || direction=E - z_m=M - fi - coord=`echo $coord | sed -e s/-//g` - [ ! -f temp_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cutsection ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper $z_m $coord temp_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - done - - ;; - - 'vert_Ssections') - if [[ $typeoutput == 'MMO' ]] ; then - pref='grid_T' - for coord in 0 45 -45 -30 180 80 - do - if [[ $coord == '0' ]] || [[ $coord == '45' ]] || [[ $coord == '-45' ]] ; then - [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=S || direction=N - z_m=Z - else - [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=W || direction=E - z_m=M - fi - coord=`echo $coord | sed -e s/-//g` - [ ! -f sal_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cutsection ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline $z_m $coord sal_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - done - fi - ;; - '3dtemp') - case $typeoutput in - 'MMO' ) pref='grid_T' ;; - 'diags') pref='t3d' ;; - esac - if [ ! -f regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]; then - echo " Warning: you are about to perform a 3d interpolation " - [ $warning_T ] && echo "(because you asked for cross sections calculations)" - echo "this might take time to complete (~days), be sure you really need/want to do this..." - interp3d ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - '3dsal') - if [[ $typeoutput == 'MMO' ]] ; then - pref='grid_T' - if [ ! -f regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]; then - echo " Warning: you are about to perform a 3d interpolation " - [ $warning_S ] && echo "(because you asked for cross sections calculations)" - echo "this might take time to complete (~days), be sure you really need/want to do this..." - interp3d ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'TSec_ave190-220E') - [ ! -f TSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cdo zonmean -sellonlatbox,190,220,-90,90 regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc TSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - 'SSec_ave190-220E') - if [[ $typeoutput == 'MMO' ]] ; then - [ ! -f SSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cdo zonmean -sellonlatbox,190,220,-90,90 regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc SSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - - 'moc') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - moc grid_V_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'max_moc') - max_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 38 50 500 2000 max_moc_38N50N_500m-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - max_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 40 40 0 10000 max_moc_40N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - - 'stc') - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 25.0 NPac_stc_0N25N_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 zomsfpac - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -25.0 0.0 SPac_stc_25S0S_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 zomsfpac - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 25.0 NAtl_stc_0N25N_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -25.0 0.0 SAtl_stc_25S0S_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 - ;; - - 'area_moc') - if [ ! -f moc_40N55N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 40.0 55.0 moc_40N55N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - if [ ! -f moc_30N40N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 30.0 40.0 moc_30N40N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - - 'convection') - convection oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $NEMOVERSION convection_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - - 'siasiesiv' ) - - if [ ! -f siasiesiv_N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]||[ ! -f siasiesiv_S_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then #check if ? instead of N or S works - case $typeoutput in - 'MMO' ) pref='icemod' ;; - 'diags') pref='ice' ;; - esac - siasiesiv ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc tmp.nc - mv ice_N_tmp.nc siasiesiv_N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - mv ice_S_tmp.nc siasiesiv_S_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - - 'siasiesivsit_Arcticreg1') - - case $typeoutput in - 'MMO' ) pref='icemod' ;; - 'diags') pref='ice' ;; - esac - - if [[ $raw_regions_ice == '' ]] ; then - lstseas=$( cdo showvar mask_regions.nc ) - else - if [[ $raw_regions_ice == 'default' ]] ; then - lstseas="Baffin_Bay Baltic_Sea Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea CntArctic CntArcticRing1 CntArcticRing2 CntArcticRing3 CntArcticRing4 CntArcticRing5 CntArcticRing6 CntArcticRing7_Lincoln_Sea CntArcticRing8 CntArcticPrf1 CntArcticPrf2r CntArcticPrf3 CntArcticPrf4 East_Siberian_Sea1 Greenland_Sea Hudson Icelandic_Sea Irminger Japan1 Kara_Sea Laptev_Sea Labrador_Sea1 Norwegian_Sea Okhotsk StLawr" - else - lstseas=$( echo ${raw_regions_ice[@]} ) - fi - fi - - for sea in $lstseas ; do - - siasiesiv ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc tmp.nc $sea - - ncks -v sia ice_N_tmp.nc sia_N_tmp.nc - ncks -v sie ice_N_tmp.nc sie_N_tmp.nc - ncks -v siv ice_N_tmp.nc siv_N_tmp.nc - ncks -v sit ice_N_tmp.nc sit_N_tmp.nc - - ncrename -h -v sia,sia_$sea sia_N_tmp.nc - ncrename -h -v sie,sie_$sea sie_N_tmp.nc - ncrename -h -v siv,siv_$sea siv_N_tmp.nc - ncrename -h -v sit,sit_$sea sit_N_tmp.nc - - if [ -e sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - ncks -A sia_N_tmp.nc sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ncks -A sie_N_tmp.nc sie_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ncks -A siv_N_tmp.nc siv_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ncks -A sit_N_tmp.nc sit_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - rm -f sia_N_tmp.nc sie_N_tmp.nc siv_N_tmp.nc sit_N_tmp.nc ice_N_tmp.nc ice_S_tmp.nc - else - mv sia_N_tmp.nc sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - mv sie_N_tmp.nc sie_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - mv siv_N_tmp.nc siv_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - mv sit_N_tmp.nc sit_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - rm -f ice_N_tmp.nc ice_S_tmp.nc - fi - - done - ;; - - esac - - case `echo $post|cut -c$((${#post}-2))-${#post}` in - 'ohc') - case `echo $post | cut -c1` in - 'x') kmin=0 ; kmax=0 ; start=2 ; mxl=1 ;; - 'l') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmin=25 ; kmax=42 ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmin=23 ; kmax=46 ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmin=45; kmax=75;; - esac - ;; - 'm') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmin=21 ; kmax=24 ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmin=18 ; kmax=22 ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmin=35; kmax=44;; - esac - ;; - 'u') kmin=1 ; start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmax=20 ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmax=17 ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmax=34;; - esac - ;; - *) kmin="" ; kmax="" ; start=1 ; mxl=0 ;; - esac - case `echo $post | cut -c${start}-$((start+3))` in - 'ohc') basin='Glob' ;; - *) basin=`echo $post | cut -c${start}-$((start+3))` - esac - case $typeoutput in - 'MMO' ) pref='grid_T' ;; - 'diags') - pref='t3d' - ncks -A -v somxl010,somixhgt oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc t3d_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - esac - ohc ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc heatc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $basin $mxl $kmin $kmax - ;; - esac - - ipcs -m - done - - # Removing the raw output from this start dates and this member - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - clean_diagsMMO ${yeari}${moni}01 ${expid} ${memb} $ltime0 $ltimef $typeoutput "${list_files}" - done - - # Prepare storage : choose output directory and file name - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - for post in ${listpost[@]} ; do - case $post in -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# You have created a function ? Enter the output directory and the prefix -# or your(s) output files under the flag chosen -# Any doubt ---> vguemas@ic3.cat -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - 'area_moc') dirout='moc'; files=('moc_40N55N_1-2km' 'moc_30N40N_1-2km') ;; - 'stc') dirout='moc' ; files=( 'NPac_stc_0N25N_0-200m' 'SPac_stc_25S0S_0-200m' 'NAtl_stc_0N25N_0-200m' 'SAtl_stc_25S0S_0-200m' ) ;; - 'max_moc') dirout='moc' ; files=('max_moc_38N50N_500m-2km' 'max_moc_40N' ) ;; - 'siasiesiv' ) dirout='ice' ; files=('siasiesiv_N' 'siasiesiv_S') ;; - 'siasiesivsit_Arcticreg1' ) dirout='ice' ; files=('sia_Arcticreg1' 'sie_Arcticreg1' 'siv_Arcticreg1' 'sit_Arcticreg1') ;; - 'moc') dirout='moc' ; files=('moc') ;; - 'convection') dirout='moc' ; files=('convection') ;; -# 'ext_raw_ice') dirout='ice' ; files=('ice_raw') ;; -# 'ext_raw_oce') dirout='oce_raw' ; files=('oce_raw') ;; - 'ext_raw_ice') dirout='ice' ; files=('ice') ;; - 'ext_raw_oce') dirout='oce' ; files=('oce') ;; - 'heat_sal_mxl') dirout='heatc' ; files=('heat_sal_mxl') ;; - 'psi') dirout='psi' ; files=('psi') ;; - 'gyres') dirout='psi' ; files=('gyres') ;; - 'usalc') dirout='saltc' ; files=('sal_0-300m') ;; - 'temp_lev') dirout='temp_lev'${level1}-${level2} ; files=('temp_lev'${level1}-${level2}) ;; - 'sal_lev') dirout='sal_lev'${level1}-${level2} ; files=('sal_lev'${level1}-${level2}) ;; - 'lmsalc') dirout='saltc' ; files=('sal_300-5400m') ;; - 'ohc_specified_layer') dirout='heatc' ; files=('ohc_2d_avg_0-300m' 'ohc_2d_avg_300-800m') ;; - 'vert_Tsections') dirout='sections' ; files=('temp_0N' 'temp_45N' 'temp_45S' 'temp_30W' 'temp_80E' 'temp_180E') ;; - 'vert_Ssections') dirout='sections' ; files=('sal_0N' 'sal_45N' 'sal_45S' 'sal_30W' 'sal_80E' 'sal_180E') ;; - '3dtemp') dirout='InterpT' ; files=('regular3dT') ;; - '3dsal') dirout='InterpS' ; files=('regular3dS') ;; - 'TSec_ave190-220E') dirout='sections' ; files=('TSec_ave190-220E') ;; - 'SSec_ave190-220E') dirout='sections' ; files=('SSec_ave190-220E') ;; - esac - case `echo $post|cut -c$((${#post}-2))-${#post}` in - 'ohc') - dirout='heatc' - file='heatc' - case `echo $post | cut -c1` in - 'x') mxl=1 ; start=2 ;; - 'l') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='800-5350_'${file} ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='855-5875_'${file} ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='857-5902_'${file};; - esac - ;; - 'm') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='373-657_'${file} ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='382-735_'${file} ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='301-773_'${file};; - esac - ;; - 'u') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='0-315_'${file} ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='0-322_'${file} ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='0-271_'${file};; - esac - ;; - *) mxl=0 ; start=1 ;; - esac - - case `echo $post | cut -c${start}-$((start+3))` in - 'NAtl') file='NAtl_10N65N_'${file} ;; - 'TAtl') file='TAtl_30S30N_'${file};; - 'NPac') file='NPac_10N70N_'${file} ;; - 'TPac') file='TPac_30S30N_'${file} ;; - 'Arct') file='Arc_65N90N_'${file} ;; - 'Anta') file='Ant_90S60S_'${file} ;; - 'TInd') file='TInd_30S30N_'${file} ;; - esac - if [[ $mxl == 1 ]] ; then - file='mxl_'$file - fi - files=( $file ) - esac - pathout=${rootout}/${dirout} - mkdir -m ug+w -m o-w -p $pathout - for file in ${files[@]} ; do - prefix=${file}_${expid}_${yeari}${moni}01_fc - lsmbso=0-${listmemb[${#listmemb[@]}-1]} - # - # Merging the post-processed members together and with the previous members if existing - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - lsyrsh=${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - lsmbsh=${listmemb[0]}-${listmemb[${#listmemb[@]}-1]} - lsmbsb=0-$((${listmemb[0]}-1)) - if [ -e ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ] ; then - cp ${pathout}/${prefix}${lsmbsb}_${lsyrsh} . - lsmbsh=0-${listmemb[${#listmemb[@]}-1]} - fi - gather_memb ${prefix} _${lsyrsh} ${prefix}${lsmbsh}_${lsyrsh} - for jmemb in ${listmemb[@]} ; do - rm -f ${prefix}${jmemb}_${lsyrsh} - done - # - # Concatenating the result with the previous years if existing - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# You have created a function ? If your diagnostic provides yearly output -# you need to use the concat option rather than the ncrcat one below. -# Any doubt ---> vguemas@ic3.cat -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - lsyrsb=${yeari}${moni}_$((year0-(1-(10#$moni+10)/12)))$(printf "%02d" $(((mon0-13)%12+12)) ).nc - lsyrso=${yeari}${moni}_${yearf}$(printf "%02d" ${monf}).nc - if [ -e ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ] ; then - case $post in - 'max_moc' ) concat ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrsh} $(printf "%02d" ${monf}) ${prefix}${lsmbsh}_${lsyrso} ;; - *) ncrcat -O ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrsh} ${prefix}${lsmbsh}_${lsyrso} ;; - esac - else - lsyrso=$lsyrsh - fi - # - # Merging the result with the previous members if existing - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - if [[ $lsyrsh != $lsyrso ]] && [[ -e ${pathout}/${prefix}${lsmbsb}_${lsyrso} ]] ; then - cp ${pathout}/${prefix}${lsmbsb}_${lsyrso} . - gather_memb ${prefix} _${lsyrso} ${prefix}${lsmbso}_${lsyrso} - else - lsmbso=$lsmbsh - fi - # - # Storing and cleaning - # ~~~~~~~~~~~~~~~~~~~~~ - cp ${prefix}${lsmbso}_${lsyrso} ${pathout}/. || { if [ -e ${pathout}/${prefix}${lsmbso}_${lsyrso} ]; - then - echo "${prefix}${lsmbso}_${lsyrso} already exists in ${pathout}" - sleep 5 - else - echo " problem writing file in ${pathout} directory" - exit - fi - } - rm -f ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrso} ${prefix}${lsmbsb}_${lsyrso} ${pathout}/${prefix}${lsmbsb}_${lsyrso} ${prefix}${lsmbso}_${lsyrso} ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ${prefix}${lsmbsb}_${lsyrsh} - done - done -done - -trap - EXIT -rm -rf $WORKDIR diff --git a/save/ocean_pp.bash.oriol b/save/ocean_pp.bash.oriol deleted file mode 100755 index c647008..0000000 --- a/save/ocean_pp.bash.oriol +++ /dev/null @@ -1,647 +0,0 @@ -#!/bin/bash -set -evx - -module load CDFTOOLS/2.1-foss-2015a - -function delete { -at now +7 days << EOF -rm -rf $WORKDIR -EOF -} - - -msg='Your experiment crashed! Your workdir \($WORKDIR\) will be kept for one week from now and then deleted' -trap "echo $msg ; delete ; exit" SIGINT SIGHUP SIGTERM SIGSEGV SIGKILL EXIT - -################################# -#### User Defined Funtions #### -################################# - - - - -# check if args are ok and read options in config_file - - if [ $# -ne 1 ] ; then - echo - echo "USAGE: config_file " - echo "For example: ./ocean_pp.new.bash /home/Earth/$user/es_git/ocean_diagnostics/config_file " - echo - exit 1 - fi - -config_file=$1 -. ${config_file} - -list_files='grid_T' -if [[ ${listpost[@]} =~ "psi" ]] ; then - echo "The list of diags require grid_U" - list_files=$(echo ${list_files} grid_U) -fi - -if [[ ${listpost[@]} =~ "moc" ]] ; then - echo "The list of diags require grid_V" - list_files=$(echo ${list_files} grid_V) -fi -if [[ ${listpost[@]} =~ "ice" ]] || [[ ${listpost[@]} =~ "siasiesiv" ]]; then - echo "The list of diags contains ice" - list_files=$(echo ${list_files} icemod) -fi - -############################################################################### -# -# moc needs to be computed before max_moc and area_moc -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if [[ ${listpost[@]##*moc*} != ${listpost[@]} ]] || [[ ${listpost[@]##*stc*} != ${listpost[@]} ]] ; then - if [[ ${listpost[@]#moc} != ${listpost[@]:1} ]] ; then - listpost=( 'moc' "${listpost[@]#moc}" ) - fi -fi -# -# psi needs to be computed before gyres -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if [[ ${listpost[@]##*gyres*} != ${listpost[@]} ]] ; then - if [[ ${listpost[@]#psi} != ${listpost[@]:1} ]] ; then - listpost=( 'psi' "${listpost[@]#psi}" ) - fi -fi -# -# oce raw outputs need to be extracted before convection option -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if [[ ${listpost[@]##*convection*} != ${listpost[@]} ]] ; then - if [[ ${listpost[@]#ext_raw_oce} != ${listpost[@]:1} ]] ; then - listpost=( 'ext_raw_oce' "${listpost[@]#ext_raw_oce}" ) - fi -fi -# -# 3d interpolation required before average T sections over longitudes -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if [[ ${listpost[@]##TSec_ave*} != ${listpost[@]} ]] ; then - if [[ ${listpost[@]#3dtemp} != ${listpost[@]:1} ]] ; then - listpost=( '3dtemp' "${listpost[@]#3dtemp}" ) - warning_T=.true. - fi -fi -if [[ ${listpost[@]##SSec_ave*} != ${listpost[@]} ]] ; then - if [[ ${listpost[@]#3dsal} != ${listpost[@]:1} ]] ; then - listpost=( '3dsal' "${listpost[@]#3dsal}" ) - warning_S=.true. - fi -fi -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# You have created a function ? If your new diagnostic relies on an already -# existing diagnotics, you might need similar lignes to the above ones -# Any doubt ---> vguemas@ic3.cat -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# -# Preparing WORKDIR and set of available functions -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -export WORKDIR=/scratch/Earth/${USER}/tmp/post_ocean/$$ -mkdir -p $WORKDIR -cd $WORKDIR -source $PATHCOMMONOCEANDIAG/common_ocean_post.txt -# -# Interval of lead months be post-processed -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -case $expid in - 'nemovar_s4'|'nemovar_combine') moni=09 ; syeari=1957 ; syearf=1957 ; insdate=1 ; typeoutput='MMO' ; NEMOVERSION='nemovar_O1L42' ;; - 'glorys2v1') moni=01 ; syeari=1993 ; syearf=1993 ; insdate=1 ; typeoutput='MMO' ;; -esac -case $expid in - 'nemovar_s4') rootout='/esnas/exp/ECMWF/NEMOVAR_S4/monthly_mean' ;; - 'nemovar_combine') rootout='/esnas/exp/ECMWF/NEMOVAR_COMBINE/monthly_mean' ;; - 'glorys2v1') rootout='/esnas/exp/MERCATOR/GLORYS2V1/monthly_mean';; -esac -if [[ ${listpost[@]##max_moc} != ${listpost[@]} ]] || [[ -z "$ltimef" ]] || [[ -z "$ltime0" ]] ; then - if [[ ! -z "$year0" ]] && [[ ! -z "$yearf" ]] ; then - ltime0=$(((${year0}-${syeari})*12+1)) - ltimef=$(((${yearf}-${syeari}+1-(10#$moni+10)/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 -# ~~~~~~~~~~~~~~~~~~~~~ -if [[ $intsdate -eq 0 ]] ; then intsdate=1 ; fi # if only one start date, user might set -# intsdates to 0 which leads to an infinite loop below -for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do - # - # Interval of years to be post-processed - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - year0=$(($yeari+(10#$moni+$ltime0-2)/12)) - yearf=$(($yeari+(10#$moni+$ltimef-2)/12)) - - for memb in ${listmemb[@]} ; do - # - # Fetching the files on esnas - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - case $expid in - '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 "${list_files}" - esac - # - # Ready for the post-processing - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - for post in ${listpost[@]} ; do - - case $post in -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# You have created a function ? Enter its call right here under the flag chosen -# Remember to consider both 'MMO' and 'diags' cases -# Any doubt ---> vguemas@ic3.cat -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - 'ext_raw_oce') - if [[ $typeoutput == 'MMO' ]] ; then - lstvars=`cdo showvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc` - if [[ $raw_vars_ocean == '' ]] ; then - lstext=`echo $lstvars | sed s/\ /,/g` - else - if [[ $raw_vars_ocean == 'default' ]] ; then - lstextvar=( 'sosstsst' 'sosaline' 'somixhgt' 'somxl010' ) - lstext='' - for varex in ${lstextvar[@]} ; do - if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then - lstext=`echo ${lstext} ${varex}|sed s/\ /,/g` - fi - done - else - lstext=`echo ${raw_vars_ocean[@]} |sed s/\ /,/g` - fi - fi - if [ -z "$lstext" ] ; then - echo "The list of variables you wish to extract is not in your outputs" - exit 1 - else - ncks -O -v ${lstext} grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -# ncks -O -v ${lstext[@]} grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'ext_raw_ice') - if [[ $typeoutput == 'MMO' ]] ; then - lstvars=`cdo showvar icemod_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc` - if [[ $raw_vars_ice == '' ]] ; then - lstext=`echo $lstvars | sed s/\ /,/g` - else - if [[ $raw_vars_ice == 'default' ]] ; then - lstextvar=( 'isnowthi' 'iicethic' 'ileadfra' 'iicetemp' 'ice_pres' ) - lstext='' - for varex in ${lstextvar[@]} ; do - if [[ ${lstvars/${varex}/} != ${lstvars} ]] ; then - lstext=`echo ${lstext} ${varex}|sed s/\ /,/g` - fi - done - else - lstext=`echo $raw_vars_ice |sed s/\ /,/g` - fi - fi - if [ -z "$lstext" ] ; then - echo "The list of variables you wish to extract is not in your outputs" - exit 1 - else - ncks -O -v ${lstext} icemod_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ice_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'heat_sal_mxl') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f heat_sal_mxl_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - heat_sal_mxl grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc heat_sal_mxl_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'psi') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - psi grid_U_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc grid_V_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'gyres') - gyres psi_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $NEMOVERSION gyres_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - - 'lmsalc') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f sal_300-5400m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - vertmeansal grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 300 5400 sal_300-5400m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'usalc') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f sal_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - vertmeansal grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0 300 sal_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - - 'temp_lev') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f temp_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - vertmeanvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper $level1 $level2 temp_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - - 'sal_lev') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f sal_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - vertmeanvar grid_T_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline $level1 $level2 sal_lev${level1}-${level2}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'ohc_specified_layer') - if [ ! -f ohc_2d_avg_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then - case $typeoutput in - 'MMO' ) pref='grid_T' ;; - 'diags') pref='t3d' ;; - esac - ohc_specified_layer ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 300.0 ohc_2d_avg_0-300m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ohc_specified_layer ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 300.0 800.0 ohc_2d_avg_300-800m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - - 'vert_Tsections') - case $typeoutput in - 'MMO' ) pref='grid_T' ;; - 'diags') pref='t3d' ;; - esac - for coord in 0 45 -45 -30 180 80 - do - if [[ $coord == '0' ]] || [[ $coord == '45' ]] || [[ $coord == '-45' ]] ; then - [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=S || direction=N - z_m=Z - else - [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=W || direction=E - z_m=M - fi - coord=`echo $coord | sed -e s/-//g` - [ ! -f temp_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cutsection ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper $z_m $coord temp_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - done - - ;; - - 'vert_Ssections') - if [[ $typeoutput == 'MMO' ]] ; then - pref='grid_T' - for coord in 0 45 -45 -30 180 80 - do - if [[ $coord == '0' ]] || [[ $coord == '45' ]] || [[ $coord == '-45' ]] ; then - [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=S || direction=N - z_m=Z - else - [[ ` echo $coord | cut -b 1 ` == '-' ]] && direction=W || direction=E - z_m=M - fi - coord=`echo $coord | sed -e s/-//g` - [ ! -f sal_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cutsection ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline $z_m $coord sal_${coord}${direction}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - done - fi - ;; - '3dtemp') - case $typeoutput in - 'MMO' ) pref='grid_T' ;; - 'diags') pref='t3d' ;; - esac - if [ ! -f regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]; then - echo " Warning: you are about to perform a 3d interpolation " - [ $warning_T ] && echo "(because you asked for cross sections calculations)" - echo "this might take time to complete (~days), be sure you really need/want to do this..." - interp3d ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc votemper regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - '3dsal') - if [[ $typeoutput == 'MMO' ]] ; then - pref='grid_T' - if [ ! -f regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]; then - echo " Warning: you are about to perform a 3d interpolation " - [ $warning_S ] && echo "(because you asked for cross sections calculations)" - echo "this might take time to complete (~days), be sure you really need/want to do this..." - interp3d ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc vosaline regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'TSec_ave190-220E') - [ ! -f TSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cdo zonmean -sellonlatbox,190,220,-90,90 regular3dT_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc TSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - 'SSec_ave190-220E') - if [[ $typeoutput == 'MMO' ]] ; then - [ ! -f SSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] && cdo zonmean -sellonlatbox,190,220,-90,90 regular3dS_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc SSec_ave190-220E_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - - 'moc') - if [[ $typeoutput == 'MMO' ]] ; then - if [ ! -f moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - moc grid_V_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - fi - ;; - - 'max_moc') - max_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 38 50 500 2000 max_moc_38N50N_500m-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - max_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 40 40 0 10000 max_moc_40N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - - 'stc') - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 25.0 NPac_stc_0N25N_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 zomsfpac - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -25.0 0.0 SPac_stc_25S0S_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 zomsfpac - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 25.0 NAtl_stc_0N25N_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc -25.0 0.0 SAtl_stc_25S0S_0-200m_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 0.0 200.0 - ;; - - 'area_moc') - if [ ! -f moc_40N55N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 40.0 55.0 moc_40N55N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - if [ ! -f moc_30N40N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then - area_moc moc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc 30.0 40.0 moc_30N40N_1-2km_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - - 'convection') - convection oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $NEMOVERSION convection_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - - 'siasiesiv' ) - - if [ ! -f siasiesiv_N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ]||[ ! -f siasiesiv_S_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ];then #check if ? instead of N or S works - case $typeoutput in - 'MMO' ) pref='icemod' ;; - 'diags') pref='ice' ;; - esac - siasiesiv ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc tmp.nc - mv ice_N_tmp.nc siasiesiv_N_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - mv ice_S_tmp.nc siasiesiv_S_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - fi - ;; - - 'siasiesivsit_Arcticreg1') - - case $typeoutput in - 'MMO' ) pref='icemod' ;; - 'diags') pref='ice' ;; - esac - - if [[ $raw_regions_ice == '' ]] ; then - lstseas=$( cdo showvar mask_regions.nc ) - else - if [[ $raw_regions_ice == 'default' ]] ; then - lstseas="Baffin_Bay Baltic_Sea Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea CntArctic CntArcticRing1 CntArcticRing2 CntArcticRing3 CntArcticRing4 CntArcticRing5 CntArcticRing6 CntArcticRing7_Lincoln_Sea CntArcticRing8 CntArcticPrf1 CntArcticPrf2r CntArcticPrf3 CntArcticPrf4 East_Siberian_Sea1 Greenland_Sea Hudson Icelandic_Sea Irminger Japan1 Kara_Sea Laptev_Sea Labrador_Sea1 Norwegian_Sea Okhotsk StLawr" - else - lstseas=$( echo ${raw_regions_ice[@]} ) - fi - fi - - for sea in $lstseas ; do - - siasiesiv ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc tmp.nc $sea - - ncks -v sia ice_N_tmp.nc sia_N_tmp.nc - ncks -v sie ice_N_tmp.nc sie_N_tmp.nc - ncks -v siv ice_N_tmp.nc siv_N_tmp.nc - ncks -v sit ice_N_tmp.nc sit_N_tmp.nc - - ncrename -h -v sia,sia_$sea sia_N_tmp.nc - ncrename -h -v sie,sie_$sea sie_N_tmp.nc - ncrename -h -v siv,siv_$sea siv_N_tmp.nc - ncrename -h -v sit,sit_$sea sit_N_tmp.nc - - if [ -e sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc ] ; then - ncks -A sia_N_tmp.nc sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ncks -A sie_N_tmp.nc sie_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ncks -A siv_N_tmp.nc siv_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ncks -A sit_N_tmp.nc sit_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - rm -f sia_N_tmp.nc sie_N_tmp.nc siv_N_tmp.nc sit_N_tmp.nc ice_N_tmp.nc ice_S_tmp.nc - else - mv sia_N_tmp.nc sia_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - mv sie_N_tmp.nc sie_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - mv siv_N_tmp.nc siv_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - mv sit_N_tmp.nc sit_Arcticreg1_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - rm -f ice_N_tmp.nc ice_S_tmp.nc - fi - - done - ;; - - esac - - case `echo $post|cut -c$((${#post}-2))-${#post}` in - 'ohc') - case `echo $post | cut -c1` in - 'x') kmin=0 ; kmax=0 ; start=2 ; mxl=1 ;; - 'l') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmin=25 ; kmax=42 ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmin=23 ; kmax=46 ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmin=45; kmax=75;; - esac - ;; - 'm') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmin=21 ; kmax=24 ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmin=18 ; kmax=22 ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmin=35; kmax=44;; - esac - ;; - 'u') kmin=1 ; start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') kmax=20 ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') kmax=17 ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') kmax=34;; - esac - ;; - *) kmin="" ; kmax="" ; start=1 ; mxl=0 ;; - esac - case `echo $post | cut -c${start}-$((start+3))` in - 'ohc') basin='Glob' ;; - *) basin=`echo $post | cut -c${start}-$((start+3))` - esac - case $typeoutput in - 'MMO' ) pref='grid_T' ;; - 'diags') - pref='t3d' - ncks -A -v somxl010,somixhgt oce_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc t3d_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - ;; - esac - ohc ${pref}_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc heatc_${expid}_${yeari}${moni}01_fc${memb}_${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc $basin $mxl $kmin $kmax - ;; - esac - - ipcs -m - done - - # Removing the raw output from this start dates and this member - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - clean_diagsMMO ${yeari}${moni}01 ${expid} ${memb} $ltime0 $ltimef $typeoutput "${list_files}" - done - - # Prepare storage : choose output directory and file name - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - for post in ${listpost[@]} ; do - case $post in -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# You have created a function ? Enter the output directory and the prefix -# or your(s) output files under the flag chosen -# Any doubt ---> vguemas@ic3.cat -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - 'area_moc') dirout='moc'; files=('moc_40N55N_1-2km' 'moc_30N40N_1-2km') ;; - 'stc') dirout='moc' ; files=( 'NPac_stc_0N25N_0-200m' 'SPac_stc_25S0S_0-200m' 'NAtl_stc_0N25N_0-200m' 'SAtl_stc_25S0S_0-200m' ) ;; - 'max_moc') dirout='moc' ; files=('max_moc_38N50N_500m-2km' 'max_moc_40N' ) ;; - 'siasiesiv' ) dirout='ice' ; files=('siasiesiv_N' 'siasiesiv_S') ;; - 'siasiesivsit_Arcticreg1' ) dirout='ice' ; files=('sia_Arcticreg1' 'sie_Arcticreg1' 'siv_Arcticreg1' 'sit_Arcticreg1') ;; - 'moc') dirout='moc' ; files=('moc') ;; - 'convection') dirout='moc' ; files=('convection') ;; -# 'ext_raw_ice') dirout='ice' ; files=('ice_raw') ;; -# 'ext_raw_oce') dirout='oce_raw' ; files=('oce_raw') ;; - 'ext_raw_ice') dirout='ice' ; files=('ice') ;; - 'ext_raw_oce') dirout='oce' ; files=('oce') ;; - 'heat_sal_mxl') dirout='heatc' ; files=('heat_sal_mxl') ;; - 'psi') dirout='psi' ; files=('psi') ;; - 'gyres') dirout='psi' ; files=('gyres') ;; - 'usalc') dirout='saltc' ; files=('sal_0-300m') ;; - 'temp_lev') dirout='temp_lev'${level1}-${level2} ; files=('temp_lev'${level1}-${level2}) ;; - 'sal_lev') dirout='sal_lev'${level1}-${level2} ; files=('sal_lev'${level1}-${level2}) ;; - 'lmsalc') dirout='saltc' ; files=('sal_300-5400m') ;; - 'ohc_specified_layer') dirout='heatc' ; files=('ohc_2d_avg_0-300m' 'ohc_2d_avg_300-800m') ;; - 'vert_Tsections') dirout='sections' ; files=('temp_0N' 'temp_45N' 'temp_45S' 'temp_30W' 'temp_80E' 'temp_180E') ;; - 'vert_Ssections') dirout='sections' ; files=('sal_0N' 'sal_45N' 'sal_45S' 'sal_30W' 'sal_80E' 'sal_180E') ;; - '3dtemp') dirout='InterpT' ; files=('regular3dT') ;; - '3dsal') dirout='InterpS' ; files=('regular3dS') ;; - 'TSec_ave190-220E') dirout='sections' ; files=('TSec_ave190-220E') ;; - 'SSec_ave190-220E') dirout='sections' ; files=('SSec_ave190-220E') ;; - esac - case `echo $post|cut -c$((${#post}-2))-${#post}` in - 'ohc') - dirout='heatc' - file='heatc' - case `echo $post | cut -c1` in - 'x') mxl=1 ; start=2 ;; - 'l') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='800-5350_'${file} ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='855-5875_'${file} ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='857-5902_'${file};; - esac - ;; - 'm') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='373-657_'${file} ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='382-735_'${file} ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='301-773_'${file};; - esac - ;; - 'u') start=2 ; mxl=0 - case $NEMOVERSION in - 'Ec2.3_O1L42'|'N3.2_O1L42'|'nemovar_O1L42') file='0-315_'${file} ;; - 'Ec3.0_O1L46'|'Ec3.0_O25L46'|'N3.3_O1L46') file='0-322_'${file} ;; - 'Ec3.0_O1L75'|'Ec3.0_O25L75'|'glorys2v1_O25L75') file='0-271_'${file};; - esac - ;; - *) mxl=0 ; start=1 ;; - esac - - case `echo $post | cut -c${start}-$((start+3))` in - 'NAtl') file='NAtl_10N65N_'${file} ;; - 'TAtl') file='TAtl_30S30N_'${file};; - 'NPac') file='NPac_10N70N_'${file} ;; - 'TPac') file='TPac_30S30N_'${file} ;; - 'Arct') file='Arc_65N90N_'${file} ;; - 'Anta') file='Ant_90S60S_'${file} ;; - 'TInd') file='TInd_30S30N_'${file} ;; - esac - if [[ $mxl == 1 ]] ; then - file='mxl_'$file - fi - files=( $file ) - esac - pathout=${rootout}/${dirout} - mkdir -m ug+w -m o-w -p $pathout - for file in ${files[@]} ; do - prefix=${file}_${expid}_${yeari}${moni}01_fc - lsmbso=0-${listmemb[${#listmemb[@]}-1]} - # - # Merging the post-processed members together and with the previous members if existing - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - lsyrsh=${year0}$(printf "%02d" ${mon0})_${yearf}$(printf "%02d" ${monf}).nc - lsmbsh=${listmemb[0]}-${listmemb[${#listmemb[@]}-1]} - lsmbsb=0-$((${listmemb[0]}-1)) - if [ -e ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ] ; then - cp ${pathout}/${prefix}${lsmbsb}_${lsyrsh} . - lsmbsh=0-${listmemb[${#listmemb[@]}-1]} - fi - gather_memb ${prefix} _${lsyrsh} ${prefix}${lsmbsh}_${lsyrsh} - for jmemb in ${listmemb[@]} ; do - rm -f ${prefix}${jmemb}_${lsyrsh} - done - # - # Concatenating the result with the previous years if existing - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -# You have created a function ? If your diagnostic provides yearly output -# you need to use the concat option rather than the ncrcat one below. -# Any doubt ---> vguemas@ic3.cat -# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - lsyrsb=${yeari}${moni}_$((year0-(1-(10#$moni+10)/12)))$(printf "%02d" $(((mon0-13)%12+12)) ).nc - lsyrso=${yeari}${moni}_${yearf}$(printf "%02d" ${monf}).nc - if [ -e ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ] ; then - case $post in - 'max_moc' ) concat ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrsh} $(printf "%02d" ${monf}) ${prefix}${lsmbsh}_${lsyrso} ;; - *) ncrcat -O ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrsh} ${prefix}${lsmbsh}_${lsyrso} ;; - esac - else - lsyrso=$lsyrsh - fi - # - # Merging the result with the previous members if existing - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - if [[ $lsyrsh != $lsyrso ]] && [[ -e ${pathout}/${prefix}${lsmbsb}_${lsyrso} ]] ; then - cp ${pathout}/${prefix}${lsmbsb}_${lsyrso} . - gather_memb ${prefix} _${lsyrso} ${prefix}${lsmbso}_${lsyrso} - else - lsmbso=$lsmbsh - fi - # - # Storing and cleaning - # ~~~~~~~~~~~~~~~~~~~~~ - cp ${prefix}${lsmbso}_${lsyrso} ${pathout}/. || { if [ -e ${pathout}/${prefix}${lsmbso}_${lsyrso} ]; - then - echo "${prefix}${lsmbso}_${lsyrso} already exists in ${pathout}" - sleep 5 - else - echo " problem writing file in ${pathout} directory" - exit - fi - } - rm -f ${pathout}/${prefix}${lsmbsh}_${lsyrsb} ${prefix}${lsmbsh}_${lsyrso} ${prefix}${lsmbsb}_${lsyrso} ${pathout}/${prefix}${lsmbsb}_${lsyrso} ${prefix}${lsmbso}_${lsyrso} ${pathout}/${prefix}${lsmbsb}_${lsyrsh} ${prefix}${lsmbsb}_${lsyrsh} - done - done -done - -trap - EXIT -rm -rf $WORKDIR diff --git a/save/setup_development.bash b/save/setup_development.bash deleted file mode 100755 index 5409be9..0000000 --- a/save/setup_development.bash +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# -# This script intends to support the development of new functions in -# common_ocean_post.txt of new options to existing funtions. It allows to -# test quickly these developments -# -# History : Virginie Guemas - Initial version - 2012 -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -set -evx -# This does not need to be changed : -CON_FILES='/esnas/autosubmit/con_files' -# This option is compatible with the testing on i00k but if you want to test -# your developments on another experiment you would need to change this : -NEMOVERSION=Ec2.3_O1L42 -# This lines needs to be replaced by the path were you stored your modifed -# version of common_ocean_post.txt : -source /home/Earth/vguemas/GIT_repositories/ocean_diagnostics/common_ocean_post.txt -# Here we only fetch one random chunk of outputs from i00k : -cp /esnas/exp/ecearth/i00k/19601101/fc0/outputs/MMO_i00k_19601101_fc0_19601101-19610228.tar . -# Here we untar and gunzip these files : -tar -xvf MMO_i00k_19601101_fc0_19601101-19610228.tar -gunzip *.gz -# The lines below might need to be changed depending on which function you need -# to test. In the case below, the grid_T files are needed because they contain -# the 3d temperature = input to ohc function. If you test siasiesiv for exemple, -# you would need to replace grid_T by icemod. -filein=`ls *grid_T*` -cdo cat *grid_T* tmp.nc -# The lines below are essential because the files have a time dimension named -# time in all the functions from common_ocean_post.txt (this is handled in -# ocean_pp.bash and in the templates) -timevar=`ncdump -h tmp.nc | grep UNLIMITED | awk '{print $1}'` -if [[ $timevar == 'time_counter' ]] ; then ncrename -v time_counter,time -d time_counter,time tmp.nc ; fi -# Some cleaning -rm -f *grid* *icemod* -# This is the final testing line. You need to replace that line by the function -# you want to test (here it is ohc) followed by all its arguments (here we have -# only the input file tmp.nc and the output file tmpout.nc) -ohc tmp.nc tmppout.nc diff --git a/save/testing_ocean_pp_moore.job b/save/testing_ocean_pp_moore.job deleted file mode 100755 index 9e2cab3..0000000 --- a/save/testing_ocean_pp_moore.job +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -#$ -l h_vmem=4G -#$ -l s_rt=24:00:00 -#$ -l h_rt=24:00:00 - -set -evx -oceanpp_repository=/home/Earth/pbretonn/es_git/ocean_diagnostics -workdir=/scratch/tmp/post_ocean/$$ - -mkdir -p $workdir -cd $workdir -if [ -e ${oceanpp_repository}/ocean_pp.bash ] ; then - cp ${oceanpp_repository}/ocean_pp.bash . -else - echo "Please fill up the location of your ocean_pp repository" - exit 1 -fi - -#lstexp=('b02s_bis') -#lstexp=('b02s_ter' 'l00w_bis') #orig -lstexp=('b02s' 'i00k' 'i01t' 'l00v' 'l00w' 'glorys' 'nemovar' 'b02s_bis' 'b02s_ter' 'l00w_bis') #orig -for exp in ${lstexp[@]} ; do - tmp=${oceanpp_repository//\//\\\/} - sed -e "s/PATHCOMMONOCEANDIAG=.*/PATHCOMMONOCEANDIAG=${tmp}/g" /shared/earth/software/scripts/testing_ocean_pp/config_file-ocean_pp_${exp}.bash &> config_file-ocean_pp_${exp}.bash - ./ocean_pp.bash config_file-ocean_pp_${exp}.bash -done -- GitLab From f67421a56c61a1b68a95ed7f7f28ff2a0712e067 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Tue, 15 Mar 2016 09:32:58 +0100 Subject: [PATCH 4/9] Added the cdo version 1.6.3 option, in case we have to remove the valid_min/max attributes to avoid values out of that range to be replaced by NaN or very high numbers --- common_ocean_post.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common_ocean_post.txt b/common_ocean_post.txt index 0f468dc..e4dec9e 100644 --- a/common_ocean_post.txt +++ b/common_ocean_post.txt @@ -178,7 +178,7 @@ function concat_startdate { cdo_version=`cdo -V &> ff ; grep Climate ff | cut -d \ -f 5` rm ff #test on cdo version: if >1.5.6, remove valid_min/max attributes to avoid values out of that range to be replaced by NaN - if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] ; then + if [[ "$cdo_version" = "`echo -e "$cdo_version\n1.5.6" | sort -V | head -n1`" ]] || [[ "$cdo_version" = "`echo -e "$cdo_version\n1.6.3" | sort -V | head -n1`" ]] ; then if [[ $root == 'grid_T' || $root == 't3d' ]] ; then for file in $lstfiles ; do ncatted -O -a valid_max,votemper,d,, $file $file @@ -924,7 +924,6 @@ fi # # # Created in May 2012 Author : vguemas@ic3.cat # ############################################################################### -module load CDO/1.5.3-foss-2015a function ohc { cp ${CON_FILES}/depth.${NEMOVERSION}.txt depth.txt # -- GitLab From 117b31169cfc43da9c3768a01b5ae632422a14d3 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Tue, 15 Mar 2016 15:56:45 +0100 Subject: [PATCH 5/9] Deleted the HEAD and separator introduced by Git --- common_ocean_post.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/common_ocean_post.txt b/common_ocean_post.txt index 6960bd7..ac5e08e 100644 --- a/common_ocean_post.txt +++ b/common_ocean_post.txt @@ -64,7 +64,6 @@ cp -f ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mesh_zgr.nc cp -f ${CON_FILES}/mesh_mask_nemo.${NEMOVERSION}.nc mask.nc cp -f ${CON_FILES}/new_maskglo.${NEMOVERSION}.nc new_maskglo.nc -<<<<<<< HEAD if [ -e ${CON_FILES}/mask.regions.${NEMOVERSION}.nc ] ; then cp ${CON_FILES}/mask.regions.${NEMOVERSION}.nc mask_regions.nc fi @@ -72,11 +71,9 @@ fi if [ -e ${CON_FILES}/mask.regions.3d.${NEMOVERSION}.nc ] ; then cp ${CON_FILES}/mask.regions.3d.${NEMOVERSION}.nc mask_regions.3d.nc fi -======= if [ -e ${CON_FILES}/mask.regions.${NEMOVERSION}.nc ] ; then cp ${CON_FILES}/mask.regions.${NEMOVERSION}.nc mask_regions.nc fi ->>>>>>> develop-debug-cdo_version if [[ ! -f mask.nc ]] ; then echo "No configuration files for cdftools" -- GitLab From 77f6bce61804d1134326e01924dc7afc144ea619 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Wed, 18 May 2016 18:25:51 +0200 Subject: [PATCH 6/9] Now it extracts nav_lon and nav_lat from the seas list when you provide in lstseas of the ohc_Arcticreg1 --- ocean_pp.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocean_pp.bash b/ocean_pp.bash index edefc68..ed2080d 100755 --- a/ocean_pp.bash +++ b/ocean_pp.bash @@ -457,7 +457,7 @@ for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do esac if [[ $raw_regions_ice == '' ]] ; then - lstseas=$( cdo showvar mask_regions.nc ) + lstseas=$( cdo showvar mask_regions.nc | sed -e "s/nav_lon//g" | sed -e "s/nav_lat//g" ) else if [[ $raw_regions_ice == 'default' ]] ; then lstseas="Baffin_Bay Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea East_Siberian_Sea Greenland_Sea Hudson Icelandic_Sea Kara_Sea Laptev_Sea Labrador_Sea Norwegian_Sea Okhotsk Central_Arctic" -- GitLab From 3ff2ec1d42e47570ee2dff97acde8710825b67c3 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Thu, 19 May 2016 12:59:39 +0200 Subject: [PATCH 7/9] Now ohc excludes nav_lon and nav_lat in the lstvar of the --- common_ocean_post.txt | 2 +- setup_development.bash | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/common_ocean_post.txt b/common_ocean_post.txt index ac5e08e..255274b 100644 --- a/common_ocean_post.txt +++ b/common_ocean_post.txt @@ -943,7 +943,7 @@ cp ${CON_FILES}/depth.${NEMOVERSION}.txt depth.txt case $3 in '') typeset var basin="Glob" ;; 'NAtl' | 'NPac' | 'TAtl' | 'TPac' | 'TInd' | 'Anta' | 'Arct' | 'Glob') typeset var basin=$3 ;; -*) mv mask.nc mask_tmp.nc ; mv mask_regions.3d.nc mask.nc ; typeset var lstvars=`cdo showvar mask.nc` ; if [[ ${lstvars/$3} != ${lstvars} ]] ; then ncrename -h -v $3,tmask mask.nc ; else echo 'This region does not exist, please choose another region' ; exit; fi ;; +*) mv mask.nc mask_tmp.nc ; mv mask_regions.3d.nc mask.nc ; typeset var lstvars=`cdo showvar mask.nc | sed -e "s/nav_lon//g" | sed -e "s/nav_lat//g"` ; if [[ ${lstvars/$3} != ${lstvars} ]] ; then ncrename -h -v $3,tmask mask.nc ; else echo 'This region does not exist, please choose another region' ; exit; fi ;; esac if [ -z "$4" ] ; then typeset var mxl=0 diff --git a/setup_development.bash b/setup_development.bash index 5cfcb3b..8cac31b 100755 --- a/setup_development.bash +++ b/setup_development.bash @@ -8,7 +8,8 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ set -evx # This does not need to be changed : -CON_FILES='/esnas/autosubmit/con_files' +CON_FILES='/esnas/scratch/ruben/CON_FILES' +#CON_FILES='/esnas/autosubmit/con_files' # This option is compatible with the testing on i00k but if you want to test # your developments on another experiment you would need to change this : NEMOVERSION=Ec2.3_O1L42 -- GitLab From a8f5605f4581b8adc88833daed7c89052984f2c3 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Thu, 19 May 2016 13:00:38 +0200 Subject: [PATCH 8/9] Now sie_ArcticReg1 excludes nav_lon and nav_lat in the lstseas of the Arctic regions --- ocean_pp.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocean_pp.bash b/ocean_pp.bash index ed2080d..70cf595 100755 --- a/ocean_pp.bash +++ b/ocean_pp.bash @@ -409,7 +409,7 @@ for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do esac if [[ $raw_regions_ice == '' ]] ; then - lstseas=$( cdo showvar mask_regions.nc ) + lstseas=$( cdo showvar mask_regions.nc | sed -e "s/nav_lon//g" | sed -e "s/nav_lat//g" ) else if [[ $raw_regions_ice == 'default' ]] ; then lstseas="Baffin_Bay Baltic_Sea Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea CntArctic CntArcticRing1 CntArcticRing2 CntArcticRing3 CntArcticRing4 CntArcticRing5 CntArcticRing6 CntArcticRing7_Lincoln_Sea CntArcticRing8 CntArcticPrf1 CntArcticPrf2r CntArcticPrf3 CntArcticPrf4 East_Siberian_Sea1 Greenland_Sea Hudson Icelandic_Sea Irminger Japan1 Kara_Sea Laptev_Sea Labrador_Sea1 Norwegian_Sea Okhotsk StLawr" -- GitLab From 275e3d46bc504fe824adb318c5d608a6312eabf9 Mon Sep 17 00:00:00 2001 From: Ruben Cruz Garcia Date: Mon, 30 May 2016 19:12:42 +0200 Subject: [PATCH 9/9] Added Irminger_Sea --- ocean_pp.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocean_pp.bash b/ocean_pp.bash index 70cf595..bb7d840 100755 --- a/ocean_pp.bash +++ b/ocean_pp.bash @@ -412,7 +412,7 @@ for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do lstseas=$( cdo showvar mask_regions.nc | sed -e "s/nav_lon//g" | sed -e "s/nav_lat//g" ) else if [[ $raw_regions_ice == 'default' ]] ; then - lstseas="Baffin_Bay Baltic_Sea Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea CntArctic CntArcticRing1 CntArcticRing2 CntArcticRing3 CntArcticRing4 CntArcticRing5 CntArcticRing6 CntArcticRing7_Lincoln_Sea CntArcticRing8 CntArcticPrf1 CntArcticPrf2r CntArcticPrf3 CntArcticPrf4 East_Siberian_Sea1 Greenland_Sea Hudson Icelandic_Sea Irminger Japan1 Kara_Sea Laptev_Sea Labrador_Sea1 Norwegian_Sea Okhotsk StLawr" + lstseas="Baffin_Bay Baltic_Sea Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea CntArctic CntArcticRing1 CntArcticRing2 CntArcticRing3 CntArcticRing4 CntArcticRing5 CntArcticRing6 CntArcticRing7_Lincoln_Sea CntArcticRing8 CntArcticPrf1 CntArcticPrf2r CntArcticPrf3 CntArcticPrf4 East_Siberian_Sea1 Greenland_Sea Hudson Icelandic_Sea Irminger_Sea Japan1 Kara_Sea Laptev_Sea Labrador_Sea1 Norwegian_Sea Okhotsk StLawr" else lstseas=$( echo ${raw_regions_ice[@]} ) fi @@ -460,7 +460,7 @@ for ((yeari=$syeari;yeari<=$syearf;yeari=$(($yeari+intsdate)))) ; do lstseas=$( cdo showvar mask_regions.nc | sed -e "s/nav_lon//g" | sed -e "s/nav_lat//g" ) else if [[ $raw_regions_ice == 'default' ]] ; then - lstseas="Baffin_Bay Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea East_Siberian_Sea Greenland_Sea Hudson Icelandic_Sea Kara_Sea Laptev_Sea Labrador_Sea Norwegian_Sea Okhotsk Central_Arctic" + lstseas="Baffin_Bay Barents_Sea Beaufort_Sea Bering CanArch Chukchi_Sea East_Siberian_Sea Greenland_Sea Hudson Icelandic_Sea Irminger_Sea Kara_Sea Laptev_Sea Labrador_Sea Norwegian_Sea Okhotsk Central_Arctic" else lstseas=$( echo ${raw_regions_ice[@]} ) fi -- GitLab