#!/bin/ksh

# 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
# ------------------------------------------

# usage: get_ocean <icon-dev full path> <ocean only full path>
# links the ocean only needed files from the <icon-dev full path> to the <ocean only full path>

set -x
icon_dev_from=$1
icon_dev_to=$2

if [ ! -d ${icon_dev_to} ] ; then
  mkdir -p ${icon_dev_to}
fi

#-----------------------------------------------------------------------------------
cp_source_list()
{
  source_folder=$1
  source_files_list="$2"

  if [ ${source_folder} != "" ] ; then
    if [ ! -d ${icon_dev_to}/${source_folder} ] ; then
      mkdir -p ${icon_dev_to}/${source_folder}
    fi
  fi

  if [ "${source_files_list}" == "all" ] ; then
    cp -r ${icon_dev_from}/${source_folder}*  ${icon_dev_to}/${source_folder}
  else
    for source_file in ${source_files_list}
    do
      cp -r ${icon_dev_from}/${source_folder}${source_file}  ${icon_dev_to}/${source_folder}
    done
  fi

}



#-----------------------------------------------------------------------------------
#get src
cp_source_list "src/" "ocean sea_ice parallel_infrastructure include shared"
cp_source_list "src/io/" "shared"

cp_source_list "src/advection/" "mo_advection_utils.f90"

cp_source_list "src/configure_model/" "mo_dynamics_config.f90 mo_gribout_config.f90 mo_grid_config.f90 mo_io_config.f90 mo_name_list_output_config.f90
mo_parallel_config.f90 mo_run_config.f90 mo_time_config.f90"

cp_source_list "src/drivers/" "icon.f90 mo_master_control.f90"

cp_source_list "src/namelists/" "mo_dbg_nml.f90  mo_dynamics_nml.f90 mo_gribout_nml.f90 mo_grid_nml.f90 mo_io_nml.f90
mo_master_nml.f90 mo_parallel_nml.f90 mo_run_nml.f90 mo_sea_ice_nml.f90 mo_time_nml.f90"

#cp_source_list "src/shared/" "mo_cdi_constants.f90 mo_datetime.f90 mo_dictionary.f90 mo_exception.f90 mo_fast_math_lib.f90 mo_fortran_tools.f90
#mo_get_utc_date_tr.f90 mo_grid_subset.f90 mo_impl_constants.f90 mo_impl_constants_grf.f90 mo_kind.f90
#mo_linked_list.f90 mo_loopindices.f90 mo_math_constants.f90 mo_math_types.f90  mo_math_utilities.f90
#mo_namelist.f90 mo_orbit.f90 mo_physical_constants.f90 mo_profile.f90 mo_real_timer.f90 mo_statistics.f90
#mo_time_base.f90 mo_timer.f90 mo_util_backtrace.f90 mo_util_dbg_prnt.f90 mo_util_debug.f90 mo_util_hash.f90
#mo_util_signal.f90 mo_util_sort.f90 mo_util_string.f90 mo_util_sysinfo.f90 mo_util_uuid.f90 libmtime.f90
#mo_var_list_element.f90 mo_var_list.f90 mo_vertical_coord_table.f90 mo_var_metadata.f90
#mo_mtime_extensions.f90 mo_util_table.f90 mo_var_metadata_types.f90"

cp_source_list "src/shr_horizontal/" "mo_alloc_patches.f90 mo_ext_data_types.f90 mo_grid_geometry_info.f90 mo_grid_tools.f90
mo_intp_data_strc.f90 mo_lonlat_grid.f90 mo_model_domain.f90 mo_model_domimp_patches.f90
mo_model_domimp_setup.f90 mo_reorder_patches.f90 mo_icon_interpolation_scalar.f90"

cp_source_list "src/testcases/" "mo_ape_params.f90"

#-----------------------------------------------------------------------------------
#get the rest
cd ${icon_dev_from}/run
run_scripts=`ls *oce*`
run_scripts="$run_scripts exec.iconrun add_run_routines post.test_compare_restarts"
cd -

cp_source_list "run/" "$run_scripts"

cp_source_list "config/" all

cp_source_list "" "data doc include scripts support create_builds build_all
aclocal.m4 configure.ac configure make_my_runscript make_runscripts make_nat-ape-dec_runs
Makefile.in externals"

cat > ${icon_dev_to}/config/multiple_builds << EOF
#==============================================
# This file defines multiple builds for ICON
#==============================================

#==============================================
# Define the run scripts in run/ to be common along the following builds
run_scripts=*

#==============================================
# Define parameters for each build (testbed is disabled by default) - examples:
build_folder=gcc_yMyO_hiopt configure_options=--with-fortran=gcc --with-mpi  --with-openmp --with-flags=hiopt --disable-atmo --disable-jsbach
build_folder=gcc_nMnO configure_options=--with-fortran=gcc --without-mpi --disable-atmo --disable-jsbach
build_folder=gcc_nMyO configure_options=--with-fortran=gcc --without-mpi --with-openmp --disable-atmo --disable-jsbach
build_folder=gcc_yMnO configure_options=--with-fortran=gcc --with-mpi --disable-atmo --disable-jsbach
build_folder=gcc_yMnO_hiopt configure_options=--with-fortran=gcc --with-mpi --with-flags=hiopt --disable-atmo --disable-jsbach
build_folder=nag_nMnO configure_options=--with-fortran=nag --without-mpi --disable-atmo --disable-jsbach
build_folder=nag_yMnO configure_options=--with-fortran=nag --with-mpi --disable-atmo --disable-jsbach
build_folder=intel_nMyO configure_options=--with-fortran=intel --without-mpi --with-openmp --disable-atmo --disable-jsbach
build_folder=intel_nMnO configure_options=--with-fortran=intel --without-mpi --disable-atmo --disable-jsbach
build_folder=intel_yMnO configure_options=--with-fortran=intel --with-mpi --disable-atmo --disable-jsbach
build_folder=intel_yMyO configure_options=--with-fortran=intel --with-mpi --with-openmp --disable-atmo --disable-jsbach
build_folder=intel_yMnO_hiopt configure_options=--with-fortran=intel --with-mpi --with-flags=hiopt --disable-atmo --disable-jsbach
build_folder=pgi_yMnO configure_options=--with-fortran=pgi  --with-mpi --disable-atmo --disable-jsbach
EOF

exit
