#! /bin/ksh
#
# esm-ssp585-ocn-alk_EXP3.mon
#
# Generated by Make Experiments! (mkexp) 1.1.5rc2
#
# $Id: DEFAULT.mon.tmpl 1 2021-02-08 13:12:54Z m221078 $
#
# $Id: DEFAULT.config 1 2021-02-03 20:53:47Z m221078 $
# $Id$
# $Id$
# $Id: CDRSYNTRA_OUTPUT.config 9899 2019-07-01 09:57:06Z m221078 $
# $Id: levante.config $
#
###############################################################################
#
# The Parameters in section TIME PARAMETERS are edited by the calling script
# just before submission.
#
###############################################################################
#
#
# Setup for levante (SLURM)
#
# $Id: levante.tmpl $
#
#SBATCH --job-name=esm-ssp585-ocn-alk_EXP3_mon
#SBATCH --partition=shared
#SBATCH --tasks-per-node=4
#SBATCH --time=00:10:00
#SBATCH --output=%x_%j.log
#SBATCH --mail-type=FAIL,ARRAY_TASKS
#SBATCH --account=bm1241
#SBATCH --propagate=STACK,CORE
ulimit -s 390625 # * 1024 B = 400 MB
# OpenMPI
export HDF5_USE_FILE_LOCKING=FALSE
export MALLOC_TRIM_THRESHOLD_="-1"
export KMP_AFFINITY="granularity=fine,scatter"
export KMP_LIBRARY="turnaround"
export MKL_DEBUG_CPU_TYPE=5
export MKL_ENABLE_INSTRUCTIONS=AVX2
export OMPI_MCA_btl=self
export OMPI_MCA_coll="^ml"
export OMPI_MCA_coll_hcoll_enable="1"
export OMPI_MCA_io="romio321"
export OMPI_MCA_osc="pt2pt"
export OMPI_MCA_pml="ucx"
export HCOLL_ENABLE_MCAST_ALL="1"
export HCOLL_MAIN_IB=mlx5_0:1
export UCX_IB_ADDR_TYPE=ib_global
export UCX_NET_DEVICES=mlx5_0:1
export UCX_TLS=mm,knem,cma,dc_mlx5,dc_x,self
export UCX_UNIFIED_MODE=y
export SLURM_CPU_FREQ_REQ=HighM1
# Intel OpenMP
export KMP_STACKSIZE=128M
# OpenMP
export OMP_NUM_THREADS=1
# Workaround for SLURM bug in chained jobs
SLURM_JOB_NAME=esm-ssp585-ocn-alk_EXP3_mon
sbatch () {
unset SLURM_MEM_PER_CPU SLURM_NTASKS_PER_NODE
command sbatch "$@"
}
#
DEBUG_LEVEL=${DEBUG_LEVEL:-0}
# Support log style output
export LANG=C
print () { command print "$(date +'%F %T'):" "$@"; }
print_re='^[0-9]+-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}'
warn () { print 'Hey:' "$@" >&2; }
die () { print 'Oops:' "$@" >&2; return 1; }
# Bail out on error
trap 'print Error at line $LINENO >&2' ERR
set -eu
# Print command info
[[ $DEBUG_LEVEL -ge 2 ]] && set -x
###############################################################################
#
# TIME PARAMETERS
#
###############################################################################
jobnum=Jobnum
startdate=Startdate
nextdate=Nextdate
inidate=Inidate
findate=Findate
###############################################################################
#
# USER INTERFACE
#
###############################################################################
#
# Setup of experiment
#
EXP_ID=esm-ssp585-ocn-alk_EXP3
#------------------------------------------------------------------------------
# Configuration of component(s)
#------------------------------------------------------------------------------
#
#-- ECHAM
#
ATMO_USES_FRACTIONAL_MASK=false
ATM_LEVELS=47 # number of vertical levels
#
#-- JSBACH
#
dynveg=yes # calculate dynamic vegetation (yes/no)
yasso=yes # use yasso soil carbon scheme (yes/no)
nitrogen=yes # with nitrogen cycle (yes/no)
#------------------------------------------------------------------------------
# 1.3 TIME CONTROL
#------------------------------------------------------------------------------
#
#-- calendar type: Available calendar options:
# 0 : No leap year (365 days per year)
# 1 : Gregorian (365/366 days per year)
# n : Equal months of "n" days (30 for 30 day months)
caltype=1
#------------------------------------------------------------------------------
# 1.6 FILE SYSTEMS
#------------------------------------------------------------------------------
#
#-- MODEL_DIR: Root directory of the model code
#
MODEL_DIR=/home/m/m300966/CDRSynTra-mpiesm-1.2.01p7
#
#-- SCRIPT_DIR: Permanent file system for the SCRIPTS on the COMPUTING HOST
# (only needs to be specified if the tasks are NOT generated on the
# computing host)
SCRIPT_DIR=/home/m/m300966/CDRSynTra-mpiesm-1.2.01p7/experiments/esm-ssp585-ocn-alk_EXP3/scripts
#
#-- DATA_DIR, RESTART_DIR, LOG_DIR, MON_DIR:
# Directories of the SHORT TERM data server.
# Model INPUT and OUTPUT will be read from/written to
# this file system of the computing host
#
# - The parent-directory needs to exist before submission of the job
DATA_DIR=/work/bm1241/m300966/CDRSynTra-mpiesm-1.2.01p7/experiments/esm-ssp585-ocn-alk_EXP3/outdata
RESTART_DIR=/work/bm1241/m300966/CDRSynTra-mpiesm-1.2.01p7/experiments/esm-ssp585-ocn-alk_EXP3/restart
LOG_DIR=/work/bm1241/m300966/CDRSynTra-mpiesm-1.2.01p7/experiments/esm-ssp585-ocn-alk_EXP3/log
MON_DIR=/work/bm1241/m300966/CDRSynTra-mpiesm-1.2.01p7/experiments/monitoring
#
#-- WORK_DIR: Root directory for the temporary working directory
# (for production runs use $TMPDIR on NEC)
#
WORK_DIR=/scratch/m/m300966/CDRSynTra-mpiesm-1.2.01p7/experiments/esm-ssp585-ocn-alk_EXP3/work
#------------------------------------------------------------------------------
# 1.9 UNIX COMMANDS
#------------------------------------------------------------------------------
PATH=$(dirname $(type -p cdo | head -1)):$PATH
cdo () { command cdo -f nc2 -r "$@"; }
#------------------------------------------------------------------------------
# 1.13 MONITORING
#------------------------------------------------------------------------------
# Online web monitoring
webplots=$MON_DIR/${EXP_ID} # this is where the plots are generated
web_process=${MON_PROCESS:-true} # update the time series of relevant variables
web_visualize=${MON_VISUALIZE:-true}
# further process the data and generate the
# plots (time consuming)
lock_timeout=${MON_LOCK_TIMEOUT:-180}
# override lock timeout setting for parallel
# reruns
MON_ZOOM_EXP=${MON_ZOOM_EXP:-false}
# zoom time axis to experiment period
# IDs of reference experiments, that will be plotted in the same graphs
refid=''
###############################################################################
#
# END OF THE USER INTERFACE
#
###############################################################################
#------------------------------------------------------------------------------
# Complete setup (parameters that are not to be changed casually)
#------------------------------------------------------------------------------
#
# Path to helper scripts, load functions
#
PATH=$MODEL_DIR/contrib/plots:/home/m/m300966/CDRSynTra-mpiesm-1.2.01p7/util/running/functions:/home/m/m300966/CDRSynTra-mpiesm-1.2.01p7/util:$PATH
. /home/m/m300966/CDRSynTra-mpiesm-1.2.01p7/util/running/functions/lock_functions
#
# Component directories/names
#
atmmod=echam6
srfmod=jsbach
ocemod=mpiom
bgcmod=hamocc
#
# Definition of some time variables
#
# enddate: last day of this run
# prevstartdate: first day of previous run
typeset -i nyears
enddate=$(calc_date minus -c${caltype} -D1 -- ${nextdate})
prevstartdate=$(calc_date minus -c${caltype} -M12 -- ${startdate}_)
prevstartdate=$(calc_date minus -c${caltype} -D0 -- ${prevstartdate}_)
# Computation of expected years for concatenated output
iniyear=${inidate%????}
finyear=${findate%????}
startyear=${startdate%????}
endyear=${enddate%????}
[[ $startyear == $iniyear && $inidate != *0101 ]] && ((++startyear))
[[ $enddate != *1231 ]] && ((--endyear))
print "monitoring started for $startdate-$enddate"
# Temporary directory
post_dir=$DATA_DIR/mon_$startdate-$enddate
[[ -d $post_dir ]] &&
warn "previous job failed or still running; removing temp dir"
rm -rf $post_dir
mkdir -pv $post_dir
# Move previous log file to log directory
mkdir -pv $LOG_DIR
for log_path in $(grep -El "$print_re: monitoring finished for $prevstartdate" $SCRIPT_DIR/${EXP_ID}_mon*_[0-9]*.log || :)
do
log_file=${log_path##*/}
# The * after mon might contain underscores or numbers,
# so make sure we only take the latter part as previous job's id
log_prefix=${log_file%_[0-9]*.log}
log_suffix=${log_file#$log_prefix}
mv $log_path $LOG_DIR/${EXP_ID}_mon_${prevstartdate}$log_suffix
done
#
# Create common NCL setup
#
NCARG_USRRESFILE=$post_dir/hluresfile
cat >> $NCARG_USRRESFILE << EOF
*wkForegroundColor : (/0.,0.,0./)
*wkBackgroundColor : (/1.,1.,1./)
*Font : helvetica
*TextFuncCode : ~
*wkWidth : 800
*wkHeight : 800
*wsMaximumSize : 32556688
EOF
export NCARG_USRRESFILE
#
# Creating folder for web-online monitoring
#
description='Config file for CDRSynTra WPII Simulations'
if [[ ! -d $MON_DIR ]]
then
print 'creating index directory'
# Create index dir if needed
mkdir -pv $MON_DIR
# Make index dir and index file group-writable and world-readable
chmod 2775 $MON_DIR
fi
MON_INDEX=$MON_DIR/index.html
acquire_lock -t $lock_timeout $MON_INDEX
if [[ ! -f $MON_INDEX ]]
then
print 'creating index file'
# Create index file if needed, add experiment entry if needed
cat > $MON_INDEX << EOF
Monitoring
Monitoring
| Start of the experiment |
Initial date |
Final date |
Current date |
Experiment |
Last update |
Description |
| $(date +'%F %T') |
$inidate |
$findate |
$enddate |
${EXP_ID} |
$(date +"%F %T") |
$description |
EOF
# Make index dir and index file group-writable and world-readable
chmod 664 $MON_INDEX
elif grep -n " name=${EXP_ID} " $MON_INDEX
then
print 'updating experiment in index'
# Update experiment entry in index file
expline=$(grep -n " name=${EXP_ID} " $MON_INDEX | cut -f1 -d\:)
sed "
$((expline - 2)) s,.*, | $findate | ,
$((expline - 1)) s,.*, | $enddate | ,
$((expline + 1)) s,.*, | $(date +'%F\ \;%T') | ,
$((expline + 2)) s|.*| | $description | |
" $MON_INDEX > $MON_INDEX.$$
cp $MON_INDEX.$$ $MON_INDEX
rm $MON_INDEX.$$
else
print 'adding experiment to index'
cat >> $MON_INDEX << EOF
| $(date +'%F %T') |
$inidate |
$findate |
$enddate |
${EXP_ID} |
$(date +"%F %T") |
$description |
EOF
fi
release_lock $MON_INDEX
# Create experiment's plot dir if needed
mkdir -pv $webplots
# Create index for experiment's plot files if missing or script has changed
version_id='$Id: DEFAULT.mon.tmpl 1 2021-02-08 13:12:54Z m221078 $'
if [[ ! -f $webplots/index.html ]] ||
! fgrep "" $webplots/index.html > /dev/null
then
print "creating experiment's index"
cat > ${webplots}/index.html << EOF
Experiment ${EXP_ID}
Index of Experiments
Experiment ${EXP_ID}
Data directory: $DATA_DIR
Log directory: $LOG_DIR
Script directory: $SCRIPT_DIR
Model directory: $MODEL_DIR
EOF
fi
# Update ancillary files
cp -u $SCRIPT_DIR/README $webplots/README
###############################################################################
# Determine variable name mapping
partab () {
case "$2" in
BOT) result=echam6;;
*) result=$LOG_DIR/${1}_$2.codes;;
esac
echo $result
}
###############################################################################
#
# Monitoring of ECHAM output fields
#
###############################################################################
# Settings
mod=$atmmod
filetags='BOT co2 tracer'
print "${mod} monitoring started"
outmod=${DATA_DIR}/$mod
plothome=$webplots/$mod/plots
mkdir -pv ${plothome}
cd ${plothome}
#
# generate time series of relevant echam6 output
#
prefix=${EXP_ID}_$mod
if [[ ${web_process} = true ]]
then
for ((year=startyear; year<=endyear; ++year))
do
suffix=$year.grb
# Create global yearly means from monthly georeferenced data
echo 0 > $post_dir/status
if [[ -r $outmod/${prefix}_BOT_mm_$suffix ]]
then
partab=$(partab $prefix BOT)
(
trap 'echo $? > $post_dir/status' ERR
# Define labels for net fluxes
echo '
¶meter code=9
long_name="net fresh water flux (prec. + evap.)"
units="kg m-2 s-1" /
¶meter code=10
long_name="net top radiation (solar + thermal)"
units="W m-2" /
' > $post_dir/echam_BOT.partab
# Compute net fluxes
cdo setmon,1 -setday,1 -settime,00:00:00 -fldmean \
-yearmonmean \
-setpartab,$post_dir/echam_BOT.partab \
-aexpr,'var9=precip+evap;var10=srad0+trad0' \
-setpartab,$partab \
-selcode,4,164,167,176,177,178,179,182,219 \
$outmod/${prefix}_BOT_mm_$suffix \
$post_dir/${prefix}_BOT_gym_$year.nc
) &
fi
if [[ -r $outmod/${prefix}_co2_mm_$suffix ]]
then
partab=$(partab $prefix co2)
(
trap 'echo $? > $post_dir/status' ERR
cdo -t $partab setmon,1 -setday,1 -settime,00:00:00 -fldmean \
-yearmonmean -expr,"co2_flx_land=co2_flx_land+co2_flx_lcc+co2_flx_harvest;co2_flx_ocean;co2_burden" \
$outmod/${prefix}_co2_mm_$suffix \
$post_dir/${prefix}_co2_gym_$year.nc
) &
fi
if [[ -r $outmod/${prefix}_tracer_mm_$suffix ]]
then
partab=$(partab $prefix tracer)
(
trap 'echo $? > $post_dir/status' ERR
# convert CO2 from [kg/kg] to [ppmV];
# factor: 28.970 / 44.011 * 1000000 = 658244.5
echo '
¶meter code=1
long_name="CO2 concentration of the lowest atm. level"
units="ppmV"
factor=658244.5 /
' > $post_dir/echam_co2.partab
cdo -t $partab setpartab,$post_dir/echam_co2.partab \
-setmon,1 -setday,1 -settime,00:00:00 -fldmean \
-yearmonmean -sellevel,$ATM_LEVELS -selcode,1 \
$outmod/${prefix}_tracer_mm_$suffix \
$post_dir/${prefix}_tracer_gym_$year.nc
) &
fi
wait
[[ $(<$post_dir/status) -eq 0 ]]
# Add to time series
echo 0 > $post_dir/status
for filetag in $filetags
do
input=$post_dir/${prefix}_${filetag}_gym_$year.nc
output_grb=${prefix}_${filetag}_gym.grb
output=${prefix}_${filetag}_gym.nc
partab=$(partab $prefix $filetag)
if [[ -r $input ]]
then
(
trap 'echo $? > $post_dir/status' ERR
acquire_lock -t $lock_timeout $output
# Convert existing GRIB time series
if [[ -r $output_grb && ! -r $output ]]
then
cdo -t $partab copy $output_grb $output
rm -f $output_grb
fi
if [[ -r $output ]]
then
cdo_merge_monitoring $input $output $post_dir/$output
mv $post_dir/$output $output
else
mv $input $output
fi
release_lock $output
) &
fi
done # filetag
wait
[[ $(<$post_dir/status) -eq 0 ]]
done # year
fi # web_process
if [[ ${web_visualize} = true ]]
then
#
# Visualization NCL
#
browser_files=
for filetag in $filetags
do
input_file=${prefix}_${filetag}_gym.nc
[[ -r $input_file ]] || continue
partab=$(partab $prefix $filetag)
# Process monitoring files for each experiment.
# Save command line (input) for plot script.
input=
i=0
for spec in $EXP_ID $refid
do
IFS=: read exp offset << EOF
$spec
EOF
(( i = i + 1 ))
input_file=$MON_DIR/${exp}/$mod/plots/${exp}_${mod}_${filetag}_gym.nc
input_file_grb=$MON_DIR/${exp}/$mod/plots/${exp}_${mod}_${filetag}_gym.grb
series_file=$post_dir/${exp}_${mod}_${filetag}_gym.nc
runmean_file=$post_dir/${exp}_${mod}_${filetag}_rgym.nc
# Skip missing files
[[ -r $input_file || -r $input_file_grb ]] || continue
# Define zoom of time axis to experiment period
zoom=
if $MON_ZOOM_EXP
then
if [[ -n "$offset" ]]
then
zoom="-settaxis,${iniyear}-01-01,00:00:00,1year -selyear,$offset/$((offset + finyear - iniyear))"
else
zoom="-selyear,$iniyear/$finyear"
fi
fi
# Convert existing GRIB time series and/or zoom time axis
if [[ -r $input_file_grb && ! -r $input_file ]]
then
cdo -t $partab ${zoom:-copy} $input_file_grb $series_file
elif [[ -n "$zoom" && $exp != $EXP_ID ]]
then
cdo $zoom $input_file $series_file
else
series_file=$input_file
fi
input="$input --with${i}=$series_file,${exp}"
# Determine interval for running means
nyears=$(cdo -s nyear $series_file)
print "$nyears years available for $exp"
nra=1
[[ $nyears -gt 20 ]] && nra=5
[[ $nyears -gt 100 ]] && nra=20
# Create running means if appropriate
if [[ $nra -gt 1 ]]
then
cdo runmean,$nra $series_file $runmean_file
input="$input --with${i}a=$runmean_file,${nra}a_running_avg"
fi
done # experiments
plot_timeser --mode=monitoring --output=${prefix}_${filetag} \
--manifest=${prefix}_${filetag}.lst $input
browser_files="$browser_files ${prefix}_${filetag}.lst"
done # end of stream list
#
# Create HTML browser page
#
MOD=$(echo $mod | tr '[:lower:]' '[:upper:]')
create_plot_browser -t "Monitoring for $MOD" $browser_files > $prefix.html
mv $prefix.html *.png *.pdf $webplots/
fi # web_visualize
print "${mod} monitoring finished"
###############################################################################
#
# Monitoring of JSBACH output fields
#
###############################################################################
# Settings
mod=$srfmod
filetags='land jsbach veg yasso'
[[ $nitrogen == yes ]] && filetags="$filetags nitro"
print "${mod} monitoring started"
outmod=${DATA_DIR}/$mod
plothome=$webplots/$mod/plots
mkdir -pv ${plothome}
cd ${plothome}
#
# generate time series of relevant jsbach output
#
prefix=${EXP_ID}_$mod
# Currently, viz may only be run with the full file set (cmor_land.sh)
input_file_missing=false
if [[ ${web_process} = true ]]
then
for ((year=startyear; year<=endyear; ++year))
do
suffix=$year.grb
# Create global yearly means from monthly georeferenced data
echo 0 > $post_dir/status
for filetag in $filetags
do
partab=$(partab $prefix $filetag)
file=$outmod/${prefix}_${filetag}_mm_$suffix
if [[ -r $file ]]
then
(
trap 'echo $? > $post_dir/status' ERR
case $filetag in
land) options='-selcode,60,76,107';;
jsbach) options='-selcode,10,12,20,84';;
veg) options='-selcode,50,143,160,161,162,'
options=$options'170,171,173,175,176,178,211';;
yasso) options='-selcode,31,32,33,34,35,36,37,38,39,'
options=$options'41,42,43,44,45,46,47,48,49';;
nitro) options=$'-selcode,73,77,240,241,242,243,244,245,246,247,248';;
*) options=
esac
cdo -t $partab setmon,1 -setday,1 -settime,00:00:00 \
-yearmonmean $options $file \
$post_dir/${prefix}_${filetag}_gym_$year.nc
) &
else
input_file_missing=true
print "skipping $mod monitoring: '$file' not found"
break
fi
done
wait
[[ $(<$post_dir/status) -eq 0 ]]
# Currently, viz may only be run with the full file set (cmor_land.sh)
$input_file_missing && break
# Convert files to NetCDF using name mapping.
# Fractional sea/land mask requires additional input file for cmor_land.sh.
# Must not be given for integer mask.
slf_file=
if $ATMO_USES_FRACTIONAL_MASK
then
slf_file=$post_dir/${prefix}_slf.nc
cdo -selname,SLF \
/pool/data/ECHAM6/input/r0008/T63/T63GR15_jan_surf.nc \
${slf_file}
fi
(
cd $post_dir
ls3mip=no
crescendo=no
output_tag=${EXP_ID}
monitoring_vars_only=yes
$MODEL_DIR/contrib/plots/cosmos-asob/c6_cmor_land.sh ${EXP_ID} \
/pool/data/JSBACH/input/r0010/T63/jsbach_T63GR15_11tiles_5layers_1850_dynveg.nc \
${prefix}_veg_gym_$year.nc ${prefix}_jsbach_gym_$year.nc \
${prefix}_land_gym_$year.nc ${prefix}_yasso_gym_$year.nc \
${prefix}_nitro_gym_$year.nc NULL NULL NULL NULL NULL NULL \
${dynveg} ${nitrogen} ${ls3mip} ${crescendo} \
${monitoring_vars_only} ${output_tag} ${slf_file}
# Concatenate averaged output of cmor_land
cdo -O setyear,$year -setmon,1 -setday,1 -settime,00:00:00 -merge "outdata_land/${EXP_ID}_*.*.nc" ${prefix}_gym_$year.nc
)
# Add to time series
echo 0 > $post_dir/status
input=$post_dir/${prefix}_gym_$year.nc
output=${prefix}_gym.nc
acquire_lock -t $lock_timeout $output
# Convert existing time series
if [[ ! -r $output && -d outdata_land ]]
then
# Concatenate averaged output of cmor_land
cdo -O merge outdata_land/*_${EXP_ID}.*.nc $output
rm -r outdata_land
rm ${prefix}_*_gym.grb
fi
if [[ -r $output ]]
then
cdo_merge_monitoring $input $output $post_dir/$output
mv $post_dir/$output $output
else
mv $input $output
fi
release_lock $output
done # year
fi # web_process
if [[ ${web_visualize} = true && ${input_file_missing} = false ]]
then
#
# Visualization NCL
#
# Process monitoring files for each experiment.
# Save command line (input) for plot script
input=
i=0
for spec in $EXP_ID $refid
do
IFS=: read exp offset << EOF
$spec
EOF
(( i = i + 1 ))
input_dir=$MON_DIR/${exp}/$mod/plots
series_file=${exp}_${mod}_gym.nc
runmean_file=$post_dir/${exp}_${mod}_rgym.nc
# Skip missing files
[[ -d $input_dir ]] || continue
# Define zoom of time axis to experiment period
zoom=
if $MON_ZOOM_EXP
then
if [[ -n "$offset" ]]
then
zoom="-settaxis,${iniyear}-01-01,00:00:00,1year -selyear,$offset/$((offset + finyear - iniyear))"
else
zoom="-selyear,$iniyear/$finyear"
fi
fi
# Merge existing one-variable time series and/or zoom time axis
if [[ -d $input_dir/outdata_land && ! -r $input_dir/$series_file ]]
then
# Concatenate averaged output of cmor_land
series_file=$post_dir/$series_file
cdo -O $zoom -merge $input_dir/outdata_land/*_${exp}.*.nc $series_file
elif [[ -n "$zoom" && $exp != $EXP_ID ]]
then
cdo $zoom $input_dir/$series_file $post_dir/$series_file
series_file=$post_dir/$series_file
else
series_file=$input_dir/$series_file
fi
input="$input --with${i}=$series_file,${exp}"
# Determine interval for running means
nyears=$(cdo -s nyear $series_file)
print "$nyears years available for $exp"
nra=1
[[ $nyears -gt 20 ]] && nra=5
[[ $nyears -gt 100 ]] && nra=20
# Create running means if appropriate
if [[ $nra -gt 1 ]]
then
cdo runmean,$nra $series_file $runmean_file
input="$input --with${i}a=$runmean_file,${nra}a_running_avg"
fi
done # experiment index
plot_timeser --mode=monitoring --output=${prefix} \
--manifest=${prefix}.lst $input
#
# Create HTML browser page
#
MOD=$(echo $mod | tr '[:lower:]' '[:upper:]')
create_plot_browser -t "Monitoring for $MOD" ${prefix}.lst > $prefix.html
mv $prefix.html *.png *.pdf $webplots/
fi # web_visualize
print "${mod} monitoring finished"
###############################################################################
#
# Monitoring of MPIOM timeseries
#
###############################################################################
# Settings
mod=$ocemod
print "${mod} monitoring started"
outmod=${DATA_DIR}/${mod}
plothome=${webplots}/${mod}/plots
mkdir -pv ${plothome}
cd ${plothome}
#
# generate time series of relevant mpiom output
#
prefix=${EXP_ID}_$mod
suffix=${startdate}_${enddate}.nc
if [[ ${web_process} = true ]]
then
files=
if [[ -r $outmod/${prefix}_data_moc_mm_$suffix ]]
then
cdo yearmean -setunit,Sv -mulc,1.025e-9 -selindexbox,1,1,116,116 -sellevidx,24 -selcode,101 $outmod/${prefix}_data_moc_mm_$suffix $post_dir/${prefix}_data_moc_ym_$suffix
files="$files $post_dir/${prefix}_data_moc_ym_$suffix"
fi
if [[ -r $outmod/${prefix}_monitoring_ym_$suffix ]]
then
files="$files $outmod/${prefix}_monitoring_ym_$suffix"
fi
# Add to time series
echo 0 > $post_dir/status
for file in $files
do
(
trap 'echo $? > $post_dir/status' ERR
input=${file/_ym_/_gym_}
input=${input#$outmod/}
input=${input#$post_dir/}
output=${input%_$suffix}.nc
input=$post_dir/$input
# Set time to begin of year
cdo setmon,1 -setday,1 -settime,00:00:00 $file $input
acquire_lock -t $lock_timeout $output
if [[ -r $output ]]
then
cdo_merge_monitoring $input $output $post_dir/$output
mv $post_dir/$output $output
else
mv $input $output
fi
release_lock $output
) &
done # file
wait
[[ $(<$post_dir/status) -eq 0 ]]
fi # web_process
if [[ ${web_visualize} = true ]]
then
#
# Visualization NCL
#
browser_files=
for filetag in $(ls ${prefix}_*_gym.nc | sed "s/^${prefix}_//;s/_gym.nc$//")
do
# Process monitoring files for each experiment.
# Save command line (input) for plot script.
input=
i=0
for spec in $EXP_ID $refid
do
IFS=: read exp offset << EOF
$spec
EOF
(( i = i + 1 ))
input_file=$MON_DIR/${exp}/$mod/plots/${exp}_${mod}_${filetag}_gym.nc
series_file=$post_dir/${exp}_${mod}_${filetag}_gym.nc
runmean_file=$post_dir/${exp}_${mod}_${filetag}_rgym.nc
# Skip missing files
[[ -r $input_file ]] || continue
# Define zoom of time axis to experiment period
zoom=
if $MON_ZOOM_EXP
then
if [[ -n "$offset" ]]
then
zoom="-settaxis,${iniyear}-01-01,00:00:00,1year -selyear,$offset/$((offset + finyear - iniyear))"
else
zoom="-selyear,$iniyear/$finyear"
fi
fi
# Zoom time axis
if [[ -n "$zoom" && $exp != $EXP_ID ]]
then
cdo $zoom $input_file $series_file
else
series_file=$input_file
fi
# Add file for plotting
input="$input --with${i}=$series_file,${exp}"
# Determine interval for running means
nyears=$(cdo -s nyear $series_file)
print "$nyears years available for $exp"
nra=1
[[ ${nyears} -gt 20 ]] && nra=5
[[ ${nyears} -gt 100 ]] && nra=20
# Create running means if appropriate
if [[ $nra -gt 1 ]]
then
cdo runmean,$nra $series_file $runmean_file
input="$input --with${i}a=$runmean_file,${nra}a_running_avg"
fi
done # experiments
plot_timeser --mode=monitoring --output=${prefix}_${filetag} \
--manifest=${prefix}_${filetag}.lst $input
browser_files="$browser_files ${prefix}_${filetag}.lst"
done # end of file list
#
# Create HTML browser page
#
MOD=$(echo $mod | tr '[:lower:]' '[:upper:]')
create_plot_browser -t "Monitoring for $MOD" $browser_files > $prefix.html
mv $prefix.html *.png *.pdf $webplots/
fi # web_visualize
print "${mod} monitoring finished"
###############################################################################
#
# Monitoring of HAMOCC timeseries
#
###############################################################################
# Settings
mod=$bgcmod
print "${mod} monitoring started"
outmod=${DATA_DIR}/${mod}
plothome=${webplots}/${mod}/plots
mkdir -pv ${plothome}
cd ${plothome}
#
# generate time series of relevant hamocc output
#
prefix=${EXP_ID}_$mod
suffix=${startdate}_${enddate}.nc
if [[ ${web_process} = true ]]
then
monitoring_file=$outmod/${prefix}_monitoring_ym_$suffix
if [[ -r $monitoring_file ]]
then
:
else
monitoring_file=
fi
# Add to time series
echo 0 > $post_dir/status
for file in $monitoring_file
do
(
trap 'echo $? > $post_dir/status' ERR
input=${file#$outmod/}
input=${input/_ym_/_gym_}
output=${input%_$suffix}.nc
input=$post_dir/$input
# Set time to begin of year
cdo setmon,1 -setday,1 -settime,00:00:00 $file $input
acquire_lock -t $lock_timeout $output
if [[ -r $output ]]
then
cdo_merge_monitoring $input $output $post_dir/$output
mv $post_dir/$output $output
else
mv $input $output
fi
release_lock $output
) &
done # file
wait
[[ $(<$post_dir/status) -eq 0 ]]
fi # web_process
if [[ ${web_visualize} = true ]]
then
#
# Visualization NCL
#
browser_files=
for filetag in $(ls ${prefix}_*_gym.nc | sed "s/^${prefix}_//;s/_gym.nc$//")
do
# Process monitoring files for each experiment.
# Save command line (input) for plot script.
input=
i=0
for spec in $EXP_ID $refid
do
IFS=: read exp offset << EOF
$spec
EOF
(( i = i + 1 ))
input_file=$MON_DIR/${exp}/$mod/plots/${exp}_${mod}_${filetag}_gym.nc
series_file=$post_dir/${exp}_${mod}_${filetag}_gym.nc
runmean_file=$post_dir/${exp}_${mod}_${filetag}_rgym.nc
# Skip missing files
[[ -r $input_file ]] || continue
# Make sure that all series files use the same variable names
chname=
if [[ $exp == $EXP_ID ]]
then
first_series_file=$input_file
else
chname=`cdo_get_name_map $first_series_file $input_file`
fi
# Define zoom of time axis to experiment period
zoom=
if $MON_ZOOM_EXP
then
if [[ -n "$offset" ]]
then
zoom="-settaxis,${iniyear}-01-01,00:00:00,1year -selyear,$offset/$((offset + finyear - iniyear))"
else
zoom="-selyear,$iniyear/$finyear"
fi
fi
# Unify variable names and/or zoom time axis
if [[ -n "$chname" ]]
then
cdo chname,$chname $zoom $input_file $series_file
elif [[ -n "$zoom" && $exp != $EXP_ID ]]
then
cdo $zoom $input_file $series_file
else
series_file=$input_file
fi
# Add file for plotting
input="$input --with${i}=$series_file,${exp}"
# Determine interval for running means
nyears=$(cdo -s nyear $series_file)
print "$nyears years available for $exp"
nra=1
[[ ${nyears} -gt 20 ]] && nra=5
[[ ${nyears} -gt 100 ]] && nra=20
# Create running means if appropriate
if [[ $nra -gt 1 ]]
then
cdo runmean,$nra $series_file $runmean_file
input="$input --with${i}a=$runmean_file,${nra}a_running_avg"
fi
done # experiments
plot_timeser --mode=monitoring --output=${prefix}_${filetag} \
--manifest=${prefix}_${filetag}.lst $input
browser_files="$browser_files ${prefix}_${filetag}.lst"
done # end of file list
#
# Create HTML browser page
#
MOD=$(echo $mod | tr '[:lower:]' '[:upper:]')
create_plot_browser -t "Monitoring for $MOD" $browser_files > $prefix.html
mv $prefix.html *.png *.pdf $webplots/
fi # web_visualize
print "${mod} monitoring finished"
#------------------------------------------------------------------------------
#
# 9. EPILOGUE
#
#------------------------------------------------------------------------------
# Clean up
rm -r $post_dir
# Update run dates and submit job scripts
cd ${SCRIPT_DIR}
# $Id$
print "monitoring finished for $startdate-$enddate"