#!/bin/bash

# ICON
#
# ------------------------------------------
# Copyright (C) 2004-2026, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss
# Contact information: icon-model.org
# See AUTHORS.TXT for a list of authors
# See LICENSES/ for license information
# SPDX-License-Identifier: BSD-3-Clause
# ------------------------------------------

# abort on error
set -euo pipefail

cd $(dirname "${BASH_SOURCE[0]}")

addexp="./addexp"
#############################################################################
##
## create list for coupling development
##
#############################################################################

listname=${1:-coupling}
./rmlist $listname
# ./mklist $listname
./create_all_builders $listname

# temporary set nvhpc builder to Inactive, because they
# should not run all tests added to levante below
# their tests will be set up separately
./set_builder_flags Inactive --builders 'levante_aurora levante_gpu_nvhpc levante_cpu_nvhpc levante_gpu_validation levante_nag levante_nag_serial' --list $listname
#-----------------------------------------------------------
# AES
$addexp "checksuite.atm/exp.test_coupled_160kmNestedAtm_40kmOce" --builders "levante_gcc_hybrid" --list $listname  --runflags "cpu_time=00:10:00 no_of_nodes=2"

# DWD coupled tests on levante
$addexp "checksuite.infrastructure/coupling/exp.run_ICON_17_R2B4_AO_coupled_LEVANTE.run" --builders "levante_gcc levante_intel_hybrid" --list $listname
# wave model coupled tests
$addexp "checksuite.nwp/nwpexp.run_ICON_23_R2B4_atmo_waves_coupled"       --builders "levante_gcc levante_intel" --list $listname --runflags "queue=compute"
$addexp "checksuite.nwp/nwpexp.run_ICON_28_R2B6_IAU_atmo_waves_coupled"   --builders "dwd_nec_coupling" --list $listname


$addexp "checksuite.ocean_internal/hamocc/exp.test_concurrent_hamocc_omip_10days" \
	--machines levante --without-configureflags "--without-mpi --enable-mixed" --runflags "cpu_time=00:30:00 no_of_nodes=1 queue=compute" --list $listname
$addexp "checksuite.ocean_internal/technical/exp.test_multioutput_model_40km" \
	--machines levante --without-configureflags "--without-mpi --with-openmp --enable-mixed" --runflags "cpu_time=00:30:00 no_of_nodes=2 queue=compute" --list $listname

# comin on levante_gcc
$addexp "checksuite.infrastructure/comin/exp.build_comin_plugins_LEVANTE.run" --builders "levante_gcc" --list $listname
$addexp "exp.test_nwp_R02B04_R02B05_nest_comin" --builders "levante_gcc" --list $listname
./adddep --from-experiment "exp.test_nwp_R02B04_R02B05_nest_comin" --to-experiment "checksuite.infrastructure/comin/exp.build_comin_plugins_LEVANTE.run" --builders "levante_gcc" --list $listname
$addexp "exp.test_nwp_R02B04_R02B05_nest_comin_python" --without-configureflags "--without-mpi" --runflags "cpu_time=00:30:00 queue=shared,compute memory=32G ntasks=32" --builders "levante_gcc" --list $listname
./adddep --from-experiment "exp.test_nwp_R02B04_R02B05_nest_comin_python" --to-experiment "checksuite.infrastructure/comin/exp.build_comin_plugins_LEVANTE.run" --builders "levante_gcc" --list $listname


$addexp "checksuite.nwp/nwpexp.run_ICON_19_R2B4_cmip_forcing"  --without-configureflags "--without-mpi" --runflags "cpu_time=00:30:00 no_of_nodes=1"  --machines levante --builders "levante_intel_hybrid levante_gcc_hybrid" --list $listname

# DWD
dwd_builder='dwd_nec_coupling'
$addexp checksuite.nwp/nwpexp.run_ICON_17_R2B4_AO_coupled                      --builders ${dwd_builder} --list $listname
# Coupled AO with TERRA
$addexp checksuite.nwp/nwpexp.run_ICON_20_R2B4_R2B6_AO_coupled                 --builders ${dwd_builder} --list $listname
# Coupled AO with TERRA and HD through YAC
$addexp checksuite.nwp/nwpexp.run_ICON_26_R2B4_R2B6_AO-HD_coupled              --builders ${dwd_builder} --list $listname
# atmo-wave coupled test
$addexp checksuite.nwp/nwpexp.run_ICON_23_R2B4_atmo_waves_coupled              --builders ${dwd_builder} --list $listname

# ICON Coupled Setups on levante
# Ruby0 coupled tests, only with mpi
$addexp exp.esm_bb_ruby0 --without-configureflags "--without-mpi" --machines levante --runflags "cpu_time=00:10:00 no_of_nodes=4" --list $listname
$addexp "checksuite.infrastructure/output/exp.esm_bb_ruby0_check_output_LEVANTE.run" --builders "levante_gcc" --list $listname
./adddep --from-experiment "checksuite.infrastructure/output/exp.esm_bb_ruby0_check_output_LEVANTE.run" --to-experiment "exp.esm_bb_ruby0" --builders "levante_gcc" --list $listname

## new seamless entries for levante - hybrid with 4 openmp-threads with gcc (1 thread with intel_hybrid due to ecrad radiation)
#-----------------------------------------------------------
## Prototype-3:
# $addexp exp.seamless_bb-proto3 --builders "levante_intel levante_gcc" --runflags "cpu_time=00:10:00 no_of_nodes=4" --list $listname
# $addexp exp.seamless_bb-proto3 --builders "levante_intel_hybrid" \
#          --runflags "cpu_time=00:10:00 no_of_nodes=4 openmp_threads=1" --list $listname
# $addexp exp.seamless_bb-proto3 --builders "levante_gcc_hybrid" \
#          --runflags "cpu_time=00:10:00 no_of_nodes=4 openmp_threads=4" --list $listname
## Prototype-2:
$addexp exp.seamless_bb-proto2 --builders "levante_intel levante_gcc" --runflags "cpu_time=00:10:00 no_of_nodes=4" --list $listname
$addexp exp.seamless_bb-proto2 --builders "levante_intel_hybrid" \
         --runflags "cpu_time=00:10:00 no_of_nodes=4 openmp_threads=1" --list $listname
$addexp exp.seamless_bb-proto2 --builders "levante_gcc_hybrid" \
         --runflags "cpu_time=00:10:00 no_of_nodes=4 openmp_threads=4" --list $listname
## Prototype-1:
$addexp exp.seamless_bb-proto1 --builders "levante_intel levante_gcc levante_nag" --runflags "cpu_time=00:10:00 no_of_nodes=4" --list $listname
$addexp exp.seamless_bb-proto1 --builders "levante_intel_hybrid levante_gcc_hybrid" \
         --runflags "cpu_time=00:10:00 no_of_nodes=4 openmp_threads=4" --list $listname
## ICON-NWP/ECRAD test:
$addexp exp.seamless_bb-ecradmin --builders "levante_intel levante_gcc" --runflags "cpu_time=00:10:00 no_of_nodes=2" --list $listname
$addexp exp.seamless_bb-ecradmin --builders "levante_intel_hybrid levante_gcc_hybrid" \
         --runflags "cpu_time=00:10:00 no_of_nodes=2 openmp_threads=4" --list $listname
#-----------------------------------------------------------


# nextGEMS test setup (!) ALPHA
$addexp test_nextGEMS.config --builders levante_intel_hybrid --list $listname
$addexp test_yaxt_xchange.config --builders levante_intel_hybrid --list $listname

# activate runs for the CDI-PIO builder on mistral
./set_builder_flags Active --builders 'levante_intel_pio' --list $listname
for builder in levante_intel_pio; do
  $addexp exp.esm_bb_ruby0_pio  --builders ${builder} --list $listname --runflags "cpu_time=00:20:00 no_of_nodes=4"
  $addexp exp.esm_bb_ruby0      --builders ${builder} --list $listname --runflags "cpu_time=00:20:00 no_of_nodes=4"
done


# add tests for checking yaxt and yac stand-alone; this needs yaxt/yac to be enabled
$addexp  checksuite.infrastructure/checkExternals/exp.check_externals_DWD.run --builders dwd_nec_coupling --list ${listname}
$addexp  checksuite.infrastructure/checkExternals/exp.check_externals_LEVANTE.run --machines levante --list ${listname}
./adddep --from-experiment "checksuite.infrastructure/comin/exp.build_comin_plugins_LEVANTE.run" --to-experiment "checksuite.infrastructure/checkExternals/exp.check_externals_LEVANTE.run" --builders "levante_gcc" --list $listname


# icon-clm tests
$addexp "checksuite.clm/clmexp.ICON_CLM_output_coupling" --builders "levante_intel levante_gcc_hybrid" --list ${listname} --runflags="ntasks=32 queue=shared"

#lets see the list
./lslist $listname
#-----------------------------------------------------------
