# Build the Aeolus (alias potsdam3) library

if (! -d $code_dir/atmos_aeolus/Aeolus ) then
  echo Directory $code_dir/atmos_aeolus/Aeolus does not exist
  echo You need to obtain the Aeolus source code
  echo "    cd $code_dir/atmos_aeolus/"
  echo "    git clone git@gitlab.pik-potsdam.de:poem/aeolus.git Aeolus"
  exit 42
endif

set pathnames = aeolus_paths-$$

sed -e '/^#.*$/d' > $pathnames <<EOF
atmos_coupled/atmos_model.F90
atmos_aeolus/atmosphere.F90
atmos_aeolus/constants_poem.F90
atmos_aeolus/Aeolus.cpp
atmos_aeolus/fmsclocks.F90

atmos_aeolus/Aeolus/Atmosphere.cpp
atmos_aeolus/Aeolus/AuxiliaryFunctionality.cpp
atmos_aeolus/Aeolus/Cell.cpp
atmos_aeolus/Aeolus/CellVariable.cpp
atmos_aeolus/Aeolus/Cloudiness_2.cpp
atmos_aeolus/Aeolus/Cloudiness_3Layers.cpp
atmos_aeolus/Aeolus/Clouds-3lc.cpp
atmos_aeolus/Aeolus/Compute.cpp
atmos_aeolus/Aeolus/DataStorage.cpp
atmos_aeolus/Aeolus/Earth.cpp
atmos_aeolus/Aeolus/FMSAstronomy.cpp
#atmos_aeolus/Aeolus/FiniteVolumeAlgorithms.cpp
atmos_aeolus/Aeolus/HeatTransfer.cpp
atmos_aeolus/Aeolus/HorizontalVariable.cpp
atmos_aeolus/Aeolus/Interface.cpp
#atmos_aeolus/Aeolus/InterfaceVariable.cpp
atmos_aeolus/Aeolus/LargeScaleDynamics.cpp
atmos_aeolus/Aeolus/LongWaveRadiation.cpp
atmos_aeolus/Aeolus/LongWaveRadiation-ts.cpp
atmos_aeolus/Aeolus/MathOperators.cpp
atmos_aeolus/Aeolus/MeridionalVariable.cpp
atmos_aeolus/Aeolus/MeridionalVariable1D.cpp
#atmos_aeolus/Aeolus/Model.cpp
atmos_aeolus/Aeolus/Namelist.cpp
atmos_aeolus/Aeolus/NetCDFInput.cpp
atmos_aeolus/Aeolus/NetCDFOutput.cpp
atmos_aeolus/Aeolus/Parameter.cpp
atmos_aeolus/Aeolus/PlanetaryBoundaryLayerPhysics.cpp
atmos_aeolus/Aeolus/PlanWave.cpp
atmos_aeolus/Aeolus/PolynomialInterpolation.cpp
atmos_aeolus/Aeolus/RadiativeTransfer.cpp
atmos_aeolus/Aeolus/Restart.cpp
atmos_aeolus/Aeolus/ShortWaveRadiation.cpp
atmos_aeolus/Aeolus/ShortWaveRadiation-3lc.cpp
atmos_aeolus/Aeolus/SphericalGrid.cpp
# SurfaceFluxes.cpp is only needed for compilation, never invoked in the coupled system
atmos_aeolus/Aeolus/SurfaceFluxes.cpp
atmos_aeolus/Aeolus/SynopticScaleDynamics.cpp
atmos_aeolus/Aeolus/TransportScheme.cpp
atmos_aeolus/Aeolus/Variable.cpp
atmos_aeolus/Aeolus/VerticalVariable.cpp
atmos_aeolus/Aeolus/WaterVaporTransfer.cpp
atmos_aeolus/Aeolus/WrapSinsol.cpp
atmos_aeolus/Aeolus/sinsol.F90
atmos_aeolus/Aeolus/swr-3lc.F

atmos_shared/tracer_driver/atmos_tracer_driver.F90
atmos_shared/tracer_driver/atmos_tracer_utilities.F90
atmos_shared/tracer_driver/atmos_age_tracer.F90
atmos_shared/tracer_driver/atmos_carbon_aerosol.F90
atmos_shared/tracer_driver/atmos_ch3i.F90
atmos_shared/tracer_driver/atmos_co2.F90
atmos_shared/tracer_driver/atmos_convection_tracer.F90
atmos_shared/tracer_driver/atmos_dust.F90
atmos_shared/tracer_driver/atmos_radon.F90
atmos_shared/tracer_driver/atmos_sea_salt.F90
atmos_shared/tracer_driver/atmos_soa.F90
atmos_shared/tracer_driver/atmos_sulfate.F90
atmos_shared/tracer_driver/atmos_sulfur_hex.F90
atmos_shared/tracer_driver/atmos_sea_salt.F90
atmos_shared/tracer_driver/atmos_soa.F90
atmos_shared/tracer_driver/atmos_sulfate.F90
atmos_shared/tracer_driver/atmos_sulfur_hex.F90
atmos_shared/interpolator/interpolator.F90
atmos_shared/tracer_driver/stratchem/strat_chem_driver.F90
atmos_shared/tracer_driver/stratchem/strat_chem_model.F90
atmos_shared/tracer_driver/tropchem/tropchem_driver.F90
atmos_shared/tracer_driver/tropchem/mo_chemdr.F90
atmos_shared/tracer_driver/tropchem/mo_chemini.F90
atmos_shared/tracer_driver/tropchem/mo_chem_utls.F90
atmos_shared/tracer_driver/tropchem/mo_exp_slv.F90
atmos_shared/tracer_driver/tropchem/mo_fastjx.F90
atmos_shared/tracer_driver/tropchem/mo_fphoto.F90
atmos_shared/tracer_driver/tropchem/mo_hook.F90
atmos_shared/tracer_driver/tropchem/mo_imp_slv.F90
atmos_shared/tracer_driver/tropchem/mo_jpl.F90
atmos_shared/tracer_driver/tropchem/mo_photo.F90
atmos_shared/tracer_driver/tropchem/mo_read_sim_chm.F90
atmos_shared/tracer_driver/tropchem/mo_rodas_slv.F90
atmos_shared/tracer_driver/tropchem/mo_setinv.F90
atmos_shared/tracer_driver/tropchem/mo_setsox.F90
atmos_shared/tracer_driver/tropchem/mo_usrrxt.F90
atmos_shared/tracer_driver/tropchem/moz.mat.F90
atmos_shared/tracer_driver/tropchem/moz.mods.F90
atmos_shared/tracer_driver/tropchem/moz.subs.F90
atmos_shared/tracer_driver/tropchem/m_tracname.F90
atmos_shared/tracer_driver/tropchem/strat_chem_utilities.F90
atmos_shared/tracer_driver/tropchem/tropchem_driver.F90

atmos_param/diag_integral/diag_integral.F90
atmos_param/monin_obukhov/monin_obukhov.F90
atmos_param/monin_obukhov/monin_obukhov_interfaces.h
atmos_param/monin_obukhov/monin_obukhov_kernel.F90
atmos_param/sea_esf_rad/esfsw_parameters.F90
atmos_param/sea_esf_rad/rad_utilities.F90

#atmos_shared/tracer_driver/stratchem 
#atmos_shared/tracer_driver/tropchem 
#atmos_shared/tracer_driver/aer_ccn_act 
#atmos_shared/tracer_driver 
#atmos_shared/atmos_nudge 
#atmos_shared/vert_advection 
#atmos_shared/interpolator 
#atmos_param/diag_cloud_rad/null 
#atmos_param/dry_adj/null 
#atmos_param/radiation_driver 
#atmos_param/moist_conv/null 
#atmos_param/shallow_conv/null 
#atmos_param/diag_integral 
#atmos_param/cloud_obs/null 
#atmos_param/strat_cloud atmos_param/sea_esf_rad/null
#atmos_param/sea_esf_rad atmos_param/mg_drag
#atmos_param/lscale_cond/null
#atmos_param/grey_radiation
#atmos_param/damping_driver
#atmos_param/ras
#atmos_param/my25_turb/null
#atmos_param/donner_deep/null
#atmos_param/betts_miller
#atmos_param/entrain
#atmos_param/clouds/null
#atmos_param/cg_drag/null
#atmos_param/moist_processes
#atmos_param/fsrad/null
#atmos_param/cosp/null
#atmos_param/shallow_cu/null
#atmos_param/cloud_zonal/null
#atmos_param/rh_clouds/null
#atmos_param/stable_bl_turb
#atmos_param/physics_driver
#atmos_param/lin_cloud_microphys
#atmos_param/cloud_generator/null
#atmos_param/cu_mo_trans
#atmos_param/vert_diff_driver
#atmos_param/vert_diff
#atmos_param/cloud_rad
#atmos_param/diag_cloud/null
#atmos_param/monin_obukhov
#atmos_param/topo_drag
#atmos_param/vert_turb_driver
#atmos_param/diffusivity/null
#atmos_param/edt/null
EOF

if ( "$simenv" == "-simenv" ) then
sed -e '/^#.*$/d' >> $pathnames <<EOF
#atmos_aeolus/Aeolus-SkillScore.cpp # included in Aeolus.cpp
atmos_aeolus/Aeolus/SimenvOutput.cpp
atmos_aeolus/Aeolus/simenv_notranspose.c
atmos_aeolus/Aeolus/simenv_j_notranspose.f
atmos_aeolus/Aeolus/simenv_ini_safe.c
EOF
endif


set srcList = ( `cat $pathnames` )
rm $pathnames

set lib_name = "lib_atmos_aeolus"

mkdir -p $executable:h:h/$lib_atmos_aeolus
cd $executable:h:h/$lib_atmos_aeolus
$mkmf_lib -p $lib_name.a -c "$cppDefs" -o "-I$executable:h:h/lib_FMS -I$code_dir/atmos_aeolus/Aeolus -DUSE_FMSCLOCK" $srcList $lib_include_dirs
make

if( $status ) then
    echo "Make failed to create $lib_name.a"
    exit 1
endif
