#!/bin/csh -f
# Minimal compile script for coupled model POEM experiments

set platform      = gfortran   # A unique identifier for your platfo
                                  # This corresponds to the mkmf templates in $root/bin dir.
if ( `hostname` =~ login0? ) then
  set platform      = pik-iplex-ifort11
  if ( -d /p ) then ### argl. what a hack. from hostname nor domain we can distinguish iplex and hpc2015 clusters
    set platform      = pik-hlrs2015-ifort
  endif
  if ( -d /opt/ohpc ) then ### hack on ...
    ifx   --version >& /dev/null && set platform = pik-hpc2024-ifx
    ifort --version >& /dev/null && set platform = pik-hpc2024-ifort
    flang --version >& /dev/null && set platform = pik-hpc2024-aocc
    #set platform      = pik-hpc2024-ifort
    #set platform      = pik-hpc2024-ifx
    #set platform      = pik-hpc2024-aocc
  endif
endif
if ( `hostname` =~ viss0?* ) then
  set platform      = pik-vis-ifort11
endif
if ( `hostname` =~ vis0?* ) then
  set platform      = pik-hlrs2015-ifort
endif
if ( `hostname` =~ pc89 ) then
  set platform      = pik-pc89-gfortran
endif
if ( `hostname` =~ zuse ) then
  set platform      = ifi-zuse-ifort11
endif



set type          = "" # MOM_LAD_AEOLUS      # Type of the experiment
set help = 1  # if invoked without --type then print help
set debug = ""
set profile = ""
set vec = "" # -vec or -omp
set use_netcdf4 = 1
set environ = 1
set simenv = ""
set skillscore = ""
set pik_ml = ""

set argv = (`getopt -u -o hd -l type: -l platform: -l help -l debug -l prof -l pg -l vec -l omp -l simenv -l skillscore -l use_netcdf4 -l no_environ -l pik_ml --  $*`)
if ($? != 0) then
  echo "option parsing failed - try -h"
  exit 1
endif
while ("$argv[1]" != "--")
    switch ($argv[1])
        case --type:
                set type = $argv[2]; shift argv;
		if (  $type == MOM_LAD_AEOLUS \
                    | $type == MOM_LAD_AEOLUS2 \
                    | $type == SLAB_LAD_AEOLUS \
                    | $type == SLAB_LAD_AEOLUS2 \
                    | $type == SLAB_LAD_AEOLUS2_FORPY \
                    | $type == MOM_ATLANTES_AEOLUS \
                    | $type == MOM_ATLANTES_CM2 \
                    | $type == SLAB_ATLANTES_CM2 \
                    | $type == MOM_ATLANTES_LPJ_CM2 \
                    | $type == MOM_ATLANTES2_LPJ_CM2 \
                    | $type == POEM \
                    | $type == POEM2 \
                    | $type == TEST_ASTRO \
                  ) then
                    set help = 0
		else
		  echo "unknown type $type"
                endif
                breaksw
        case --platform:
                set platform = $argv[2]; shift argv;
		if ( ! -f $cwd:h/bin/environs.$platform ) then
		  echo platform unknown. $cwd:h/bin/environs.$platform does not exist
		  exit 1
		endif
                breaksw
        case --use_netcdf4:
                set use_netcdf4 = 1; breaksw
        case --no_environ:
                set environ = 0; breaksw
        case --help:
	case -h:
                set help = 1;  breaksw
        case --debug:
	case -d:
                set debug = "-debug"; breaksw
        case --prof:
	case --pg:
                set profile = "-profile"; breaksw
	case --vec:
                set vec = "-vec"; breaksw
	case --omp:
		set vec = "-omp"; breaksw
	case --simenv:
		set simenv="-simenv"; breaksw;
	case --skillscore:
		set simenv="-simenv"
		set skillscore="-skillscore"
                breaksw
	case --pik_ml:
		set pik_ml="-pik_ml"; breaksw;
	default:
		echo "unknown option $argv[1]"
		set help = 1
                breaksw
    endsw
    shift argv
end

if ("" == "$type") echo "Option --type is required!"

shift argv
if ( $help ) then
    echo "The optional arguments are:"
    echo "--type       followed by the type of the experiment, currently one of the following:"
    echo "             MOM_LAD_AEOLUS        : MOM5, ICE-SIS with land_lad                   and Aeolus"
    echo "             MOM_LAD_AEOLUS2       : MOM5, ICE-SIS with land_lad                   and Aeolus2"
    echo "             SLAB_LAD_AEOLUS       : Slab, ICE-SIS with land_lad                   and Aeolus"
    echo "             SLAB_LAD_AEOLUS2      : Slab, ICE-SIS with land_lad                   and Aeolus2"
    echo "             SLAB_LAD_AEOLUS2_FORPY: Slab, ICE-SIS with land_lad                   and Aeolus2 via forpy"
    echo "             MOM_ATLANTES_AEOLUS   : MOM5, ICE-SIS with land_lad+snowage           and Aeolus"
    echo "             MOM_ATLANTES_CM2      : MOM5, ICE-SIS with land_lad+snowage           and CM2.1p1"
    echo "             SLAB_ATLANTES_CM2     : Slab, ICE-SIS with land_lad+snowage           and CM2.1p1"
    echo "             MOM_ATLANTES_LPJ_CM2  : MOM5, ICE-SIS with land_lad+snowage and LPJmL and CM2.1p1"
    echo "             MOM_ATLANTES2_LPJ_CM2 : MOM5, ICE_SIS with land_lad2        and LPJmL and CM2.1p1 - coming soon"
    echo "             POEM                  : MOM5, ICE-SIS with land_lad         and LPJmL and Aeolus"
    echo "             POEM2                 : MOM5, ICE-SIS with land_lad2        and LPJmL and Aeolus  - Coming soon"
    echo
    echo "             TEST_ASTRO            : test astronomy_mod vs. sinsol"
    echo
    echo "--platform   followed by the platform name that has a corresponding environ file in the ../bin dir, default is $platform"
    echo "--debug | -d to append -debug to the platform name, so that mkmf template with debug options is used,"
    echo "             and the executable is built in a directory with -debug appended to its name."
    echo "--prof | --pg to compile with profiling enabled."
    echo "--vec        Compile with highest optimization and vectorisation (default is without vectorisation)"
    echo "--omp        Compile with highest optimization and OpenMP"
    echo "--simenv     Compile Aeolus with SimEnv"
    echo "--skillscore Compile Aeolus with SimEnv and Skillscore function"
    echo "(Note: Aeolus is now always compiled with -DUSE_MPI_DOMAIN_DECOMPOSE)"
    echo
    echo "--use_netcdf4  use NetCDF4, the default is NetCDF3. Warning: many of the standard experiments don't work with NetCDF4."
    echo
    echo "--no_environ  do not source platform specific environment. Allows customising/overriding default environment"
    echo
    echo "--pik_ml   Enable coupling of machine learning module"
    echo
    exit 0
endif

#
# User does not need to change anything below!
#
set echo
set root          = $cwd:h                            # The directory you created when you checkout
set code_dir      = $root/src                         # source code directory
set executable    = $root/exec/$platform$vec$debug$profile/$type$pik_ml/fms_$type$pik_ml$simenv$skillscore.x      # executable created after compilation
set mppnccombine  = $root/bin/mppnccombine.$platform  # path to executable mppnccombine
set mkmfTemplate  = $root/bin/mkmf.template.$platform$vec$debug # $aeolusmpi # path to template for your platform
set mkmf          = $root/bin/mkmf                    # path to executable mkmf
set cppDefs  = ( "-Duse_netCDF -Duse_netCDF3 -Duse_libMPI -DUSE_OCEAN_BGC -DENABLE_ODA -DSPMD -DLAND_BND_TRACERS" )
#On Altrix systems you may include "-Duse_shared_pointers -Duse_SGI_GSM" in cppDefs for perfomance.
#These are included in the GFDL configuration of the model.
  
set static        = 0              # 1 if you want static memory allocation, 0 for dynamic
if($static) then
  set executable = $root/exec/$platform/${type}_static/fms_$type$simenv$skillscore.x 
  set cppDefs = "$cppDefs -DMOM_STATIC_ARRAYS -DNI_=360 -DNJ_=200 -DNK_=50 -DNI_LOCAL_=60 -DNJ_LOCAL_=50"
endif

if ( $type == EBM ) then
  set cppDefs  = ( "-Duse_netCDF -Duse_netCDF3 -Duse_libMPI -DLAND_BND_TRACERS -DOVERLOAD_C8 -DOVERLOAD_C4 -DOVERLOAD_R4" )
endif

if ( $use_netcdf4 ) then
    set cppDefs = `echo $cppDefs | sed -e 's/-Duse_netCDF3//g'`
    set cppDefs = "$cppDefs -Duse_netCDF4"
endif

if ( "" != "$pik_ml" ) then
    set cppDefs = "$cppDefs -DUSE_PIK_ML"
endif

#
# Users must ensure the correct environment file exists for their platform.
#
if ( $environ ) then
  source $root/bin/environs.$platform  # environment variables and loadable modules
endif
if ( $status ) exit $status

env | grep NETCDF

#
# compile mppnccombine.c, needed only if $npes > 1
  if ( ! -f $mppnccombine ) then
    $CC -O -o $mppnccombine $NETCDFINCLUDE $code_dir/postprocessing/mppnccombine/mppnccombine.c $NETCDFLIBPATH
    if ( $status ) exit $status
  endif

set mkmf_lib = "$mkmf -f -m Makefile -a $code_dir -t $mkmfTemplate"
set lib_include_dirs = "$root/include $code_dir/shared/include $code_dir/shared/mpp/include"

if ( "$profile" == "-profile" ) then
    set cppDefs = ( $cppDefs -pg )
    #set proflibs = "-lc_p"
endif

# Build version
source ./version_compile.csh
if ( $status ) exit $status

# Build FMS
source ./FMS_compile.csh
if ( $status ) exit $status

set includes = "-I$code_dir/shared/include -I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_version/"

if ( $type != TEST_ASTRO & $type !~ 'SLAB_*' ) then
    # Build the core ocean.
    cd $root/exp
    source ./ocean_compile.csh
    if ( $status ) exit $status
endif

if ( $type =~ 'SLAB_*' ) then
    cd $root/exp
    source ./slab_compile.csh
    if ( $status ) exit $status
endif

if ( $type != TEST_ASTRO) then
    cd $root/exp
    source ./ice_compile.csh
    if ( $status ) exit $status
endif

if( $type =~ '*_CM2' ) then
    cd $root/exp
    source ./atmos_phys_compile.csh
    if ( $status ) exit $status
    cd $root/exp
    source ./atmos_fv_compile.csh
    if ( $status ) exit $status
endif

if ( $type =~ '*_AEOLUS' | $type == POEM | $type == POEM2 | $type == TEST_ASTRO ) then
    cd $root/exp
    set lib_atmos_aeolus=lib_atmos_aeolus
    set simenvlibs=""
    setenv SE_HOME /p/projects/progress/simenv/41alpha
    if ( "$simenv" == "-simenv" ) then
        set cppDefs = ( $cppDefs -DWITH_SIMENV )
	set lib_atmos_aeolus = lib_atmos_aeolus_simenv
	set simenvlibs = "-L$SE_HOME/lib -lsimenv -lstdc++"
    endif
    if ( "$skillscore" == "-skillscore" ) then
        set cppDefs = ( $cppDefs -DWITH_COSTFUNCTION )
	set lib_atmos_aeolus = lib_atmos_aeolus_simenv_skillscore
	set simenvlibs = "-L$SE_HOME/lib -lsimenv -lstdc++"
    endif
    set cppDefs = ( $cppDefs -DUSE_MPI_DOMAIN_DECOMPOSE )
    #set cppDefs = ( $cppDefs -DDO_PRINT_SUMS ) # for debugging
    if ( $type =~ '*_ATLANTES_*' ) then
	  set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND -DUSE_CLIMBER2_SNOWAGE )
    endif
    source ./atmos_aeolus_compile.csh
    if ( $status ) exit $status
endif

if ( $type =~ '*AEOLUS2' ) then
    cd $root/exp
    set simenvlibs=""
    set lib_atmos_aeolus2=lib_atmos_aeolus2
    set cppDefs = ( $cppDefs -DMPMD_ATMOS )
    if ( $type =~ '*_ATLANTES_*' ) then
	  set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND -DUSE_CLIMBER2_SNOWAGE )
    endif
    source ./atmos_aeolus2_compile.csh
    if ( $status ) exit $status
endif

if ( $type =~ '*AEOLUS2_FORPY' ) then
    cd $root/exp
    set simenvlibs=""
    set lib_atmos_aeolus2_forpy=lib_atmos_aeolus2_forpy
    set cppDefs = ( $cppDefs )
    if ( $type =~ '*_ATLANTES_*' ) then
	  set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND -DUSE_CLIMBER2_SNOWAGE )
    endif
    source ./atmos_aeolus2_forpy_compile.csh
    if ( $status ) exit $status
endif

if( $type =~ '*_LAD_*' ) then
    cd $root/exp
    source ./land_lad_compile.csh
    if ( $status ) exit $status
endif
if( $type =~ '*ATLANTES*' ) then
    cd $root/exp
    if( $type == MOM_ATLANTES_LPJ_CM2 | $type == POEM ) set cppDefs = ( $cppDefs -DUSE_LPJ )
    source ./land_atlantes_compile.csh
    if ( $status ) exit $status
endif
if( $type == MOM_ATLANTES2_LPJ_CM2 | $type == POEM2 ) then
    cd $root/exp
    set cppDefs = ( $cppDefs -DUSE_LPJ )
    source ./land_lad2_compile.csh
    if ( $status ) exit $status
endif
# check if USE_LPJ is set in cppDefs. if so, build LPJ
if ( "$cppDefs" =~ "*USE_LPJ*" ) then
    if ( $?JSONCROOT ) then
	set lpjreqlibs = "-L$JSONCROOT/lib -ljson-c"
    endif
    if ( $?JSONC_ROOT ) then
	set lpjreqlibs = "-L$JSONC_ROOT/lib -ljson-c"
    endif
    cd $root/exp
    source ./lpj_compile.csh
    if ( $status ) exit $status
endif

if ( "" != "$pik_ml" ) then
    cd $root/exp
    source ./pik_ml_compile.csh
    if ( $status ) exit $status
else
    set pik_ml_libs = ""
endif


# Build the executable
set mkmf_exec = "$mkmf -f -m Makefile -a $code_dir -t $mkmfTemplate -p $executable:t"
mkdir -p $executable:h
cd $executable:h
if( $type == MOM_LAD_AEOLUS ) then
    set srcList = ( coupler )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/$lib_atmos_aeolus -I$executable:h:h/lib_land_lad" 
    set libs = "-L$executable:h:h/lib_ocean -l_ocean -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/$lib_atmos_aeolus -l_atmos_aeolus -L$executable:h:h/lib_land_lad -l_land_lad -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $simenvlibs -lmpicxx"
else if( $type == MOM_LAD_AEOLUS2) then
    set srcList = ( coupler )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/$lib_atmos_aeolus2 -I$executable:h:h/lib_land_lad" 
    set libs = "-L$executable:h:h/lib_ocean -l_ocean -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/$lib_atmos_aeolus2 -l_atmos_aeolus2 -L$executable:h:h/lib_land_lad -l_land_lad -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $simenvlibs -lmpicxx"
else if( $type == MOM_ATLANTES_AEOLUS ) then
    set srcList = ( coupler )
    #set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/$lib_atmos_aeolus -I$executable:h:h/lib_land_atlantes" 
    set libs = "-L$executable:h:h/lib_ocean -l_ocean -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/$lib_atmos_aeolus -l_atmos_aeolus -L$executable:h:h/lib_land_atlantes -l_land_atlantes -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $simenvlibs -lmpicxx"
else if( $type == MOM_ATLANTES_AEOLUS2 ) then
    set srcList = ( coupler )
    #set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/$lib_atmos_aeolus2 -I$executable:h:h/lib_land_atlantes" 
    set libs = "-L$executable:h:h/lib_ocean -l_ocean -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/$lib_atmos_aeolus2 -l_atmos_aeolus2 -L$executable:h:h/lib_land_atlantes -l_land_atlantes -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS `python3-config --ldflags --embed` $simenvlibs -lmpicxx"
else if( $type == SLAB_LAD_AEOLUS ) then
    set srcList = ( coupler )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_slab -I$executable:h:h/lib_ice -I$executable:h:h/$lib_atmos_aeolus -I$executable:h:h/lib_land_lad" 
    set libs = "-L$executable:h:h/lib_slab -l_slab -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/$lib_atmos_aeolus -l_atmos_aeolus -L$executable:h:h/lib_land_lad -l_land_lad -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $simenvlibs -lmpicxx"
else if( $type == SLAB_LAD_AEOLUS2 ) then
    set srcList = ( coupler )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_slab -I$executable:h:h/lib_ice -I$executable:h:h/$lib_atmos_aeolus2 -I$executable:h:h/lib_land_lad" 
    set libs = "-L$executable:h:h/lib_slab -l_slab -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/$lib_atmos_aeolus2 -l_atmos_aeolus2 -L$executable:h:h/lib_land_lad -l_land_lad -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $simenvlibs -lmpicxx"
else if( $type == SLAB_LAD_AEOLUS2_FORPY ) then
    set srcList = ( coupler )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_slab -I$executable:h:h/lib_ice -I$executable:h:h/$lib_atmos_aeolus2_forpy -I$executable:h:h/lib_land_lad" 
    set libs = "-L$executable:h:h/lib_slab -l_slab -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/$lib_atmos_aeolus2_forpy -l_atmos_aeolus2_forpy -L$executable:h:h/lib_land_lad -l_land_lad -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $simenvlibs -lmpicxx"
else if ( $type == MOM_ATLANTES_CM2 ) then
    set srcList = ( coupler )
    #set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/lib_atmos_fv -I$executable:h:h/lib_atmos_phys -I$executable:h:h/lib_land_atlantes"
    set libs = "-L$executable:h:h/lib_ocean -l_ocean -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/lib_atmos_fv -l_atmos_fv -L$executable:h:h/lib_atmos_phys -l_atmos_phys -L$executable:h:h/lib_land_atlantes -l_land_atlantes -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS"
else if ( $type == SLAB_ATLANTES_CM2 ) then
    set srcList = ( coupler )
    #set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_slab -I$executable:h:h/lib_ice -I$executable:h:h/lib_atmos_fv -I$executable:h:h/lib_atmos_phys -I$executable:h:h/lib_land_atlantes"
    set libs = "-L$executable:h:h/lib_slab -l_slab -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/lib_atmos_fv -l_atmos_fv -L$executable:h:h/lib_atmos_phys -l_atmos_phys -L$executable:h:h/lib_land_atlantes -l_land_atlantes -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS"
else if ( $type == MOM_ATLANTES_LPJ_CM2 ) then
    set srcList = ( coupler )
    #set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/lib_atmos_fv -I$executable:h:h/lib_atmos_phys -I$executable:h:h/lib_land_atlantes+lpj"
    set libs = "-L$executable:h:h/lib_ocean -l_ocean -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/lib_atmos_fv -l_atmos_fv -L$executable:h:h/lib_atmos_phys -l_atmos_phys -L$executable:h:h/lib_land_atlantes+lpj -l_land_atlantes+lpj -L$executable:h:h/lib_lpj -l_lpj -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $lpjreqlibs"
else if ( $type == MOM_ATLANTES2_LPJ_CM2 ) then
#    set srcList = ( coupler )
#    set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND )
#    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/lib_atmos_fv -I$executable:h:h/lib_atmos_phys -I$executable:h:h/lib_land_atlantes+lpj"
#    set libs = "$executable:h:h/lib_ocean/lib_ocean.a $executable:h:h/lib_ice/lib_ice.a $executable:h:h/lib_atmos_fv/lib_atmos_fv.a $executable:h:h/lib_atmos_phys/lib_atmos_phys.a $executable:h:h/lib_land_atlantes+lpj/lib_land_atlantes+lpj.a $executable:h:h/lib_FMS/lib_FMS.a $lpjreqlibs"
    echo "sorry - not yet"
else if ( $type == POEM ) then
    set srcList = ( coupler )
    #set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND )
    set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/$lib_atmos_aeolus -I$executable:h:h/lib_land_atlantes+lpj"
    set libs = "-L$executable:h:h/lib_ocean -l_ocean -L$executable:h:h/lib_ice -l_ice -L$executable:h:h/$lib_atmos_aeolus -l_atmos_aeolus -L$executable:h:h/lib_land_atlantes+lpj -l_land_atlantes+lpj -L$executable:h:h/lib_lpj -l_lpj -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $simenvlibs $lpjreqlibs -lmpicxx"
else if ( $type == POEM2 ) then
    #set srcList = ( coupler )
    #set cppDefs = ( $cppDefs -DPIK_COUPLER_COSZEN_TO_LAND )
    #set includes = "-I$executable:h:h/lib_FMS -I$executable:h:h/lib_ocean -I$executable:h:h/lib_ice -I$executable:h:h/lib_atmos_fv -I$executable:h:h/lib_atmos_phys -I$executable:h:h/lib_land_atlantes+lpj"
    #set libs = "$executable:h:h/lib_ocean/lib_ocean.a $executable:h:h/lib_ice/lib_ice.a $executable:h:h/lib_atmos_fv/lib_atmos_fv.a $executable:h:h/lib_atmos_phys/lib_atmos_phys.a $executable:h:h/lib_land_atlantes+lpj/lib_land_atlantes+lpj.a $executable:h:h/lib_FMS/lib_FMS.a $lpjreqlibs"
    echo "sorry - not yet"
else if ( $type == TEST_ASTRO ) then
    set srcList = ( atmos_aeolus/test_astro.F90 )
    set includes = "-I$code_dir/shared/include -I$executable:h:h/lib_FMS -I$executable:h:h/$lib_atmos_aeolus"
    set libs = "-L$executable:h:h/$lib_atmos_aeolus -l_atmos_aeolus -L$executable:h:h/lib_version -l_version -L$executable:h:h/lib_FMS -l_FMS $simenvlibs -lmpicxx"
else
    echo "Error: unsupported model type $type, please see model types in ./MOM_compile.sh --help"
    exit 1
endif

set libs = "$libs $pik_ml_libs"
if ( "" != "$pik_ml" ) then
    # compiling the ML interface together with the coupler eases maintenance of include dirs etc
    set srcList = ( $srcList pik_ml/pik_ml_fortran.F90 )
endif

echo "includes: $includes"
echo "libs: $libs"
echo "srcList: $srcList"

$mkmf_exec -o "-I$executable:h:h/lib_version $includes" -c "$cppDefs" -l "$libs"  $srcList
make
if( $status ) then
    echo "Make failed to create the $type executable"
    exit 1
else
    echo "created $executable"
endif    

exit
