diff --git a/src/atlas/util/function/MDPI_functions.cc b/src/atlas/util/function/MDPI_functions.cc index 8cec144a7..c32a58415 100644 --- a/src/atlas/util/function/MDPI_functions.cc +++ b/src/atlas/util/function/MDPI_functions.cc @@ -119,17 +119,30 @@ double MDPI_gulfstream(double lon, double lat) { } extern "C" { - double atlas__function__MDPI_sinusoid(double lon, double lat) { - MDPI_sinusoid(lon, lat); + double atlas__functions__MDPI_sinusoid_r8(double& lon, double& lat) { + return MDPI_sinusoid(lon, lat); } - double atlas__function__MDPI_harmonic(double lon, double lat) { - MDPI_harmonic(lon, lat); + double atlas__functions__MDPI_harmonic_r8(double& lon, double& lat) { + return MDPI_harmonic(lon, lat); } - double atlas__function__MDPI_vortex(double lon, double lat) { - MDPI_vortex(lon, lat); + double atlas__functions__MDPI_vortex_r8(double& lon, double& lat) { + return MDPI_vortex(lon, lat); } - double atlas__function__MDPI_gulfstream(double lon, double lat) { - MDPI_gulfstream(lon, lat); + double atlas__functions__MDPI_gulfstream_r8(double& lon, double& lat) { + return MDPI_gulfstream(lon, lat); + } + + float atlas__functions__MDPI_sinusoid_r4(float& lon, float& lat) { + return MDPI_sinusoid(lon, lat); + } + float atlas__functions__MDPI_harmonic_r4(float& lon, float& lat) { + return MDPI_harmonic(lon, lat); + } + float atlas__functions__MDPI_vortex_r4(float& lon, float& lat) { + return MDPI_vortex(lon, lat); + } + float atlas__functions__MDPI_gulfstream_r4(float& lon, float& lat) { + return MDPI_gulfstream(lon, lat); } } diff --git a/src/atlas/util/function/MDPI_functions.h b/src/atlas/util/function/MDPI_functions.h index 32e5e5099..ffd6b9231 100644 --- a/src/atlas/util/function/MDPI_functions.h +++ b/src/atlas/util/function/MDPI_functions.h @@ -31,10 +31,15 @@ double MDPI_vortex(double lon, double lat); double MDPI_gulfstream(double lon, double lat); extern "C" { - double atlas__function__MDPI_sinusoid(double lon, double lat); - double atlas__function__MDPI_harmonic(double lon, double lat); - double atlas__function__MDPI_vortex(double lon, double lat); - double atlas__function__MDPI_gulfstream(double lon, double lat); + double atlas__functions__MDPI_sinusoid_r8(double& lon, double& lat); + double atlas__functions__MDPI_harmonic_r8(double& lon, double& lat); + double atlas__functions__MDPI_vortex_r8(double& lon, double& lat); + double atlas__functions__MDPI_gulfstream_r8(double& lon, double& lat); + + float atlas__functions__MDPI_sinusoid_r4(float& lon, float& lat); + float atlas__functions__MDPI_harmonic_r4(float& lon, float& lat); + float atlas__functions__MDPI_vortex_r4(float& lon, float& lat); + float atlas__functions__MDPI_gulfstream_r4(float& lon, float& lat); } } // namespace function diff --git a/src/atlas_f/CMakeLists.txt b/src/atlas_f/CMakeLists.txt index 9b5d2e3f2..390c46b29 100644 --- a/src/atlas_f/CMakeLists.txt +++ b/src/atlas_f/CMakeLists.txt @@ -137,8 +137,8 @@ generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/redistribution/detail/Redist MODULE atlas_redistribution_c_binding OUTPUT redistribution_c_binding.f90) generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/util/function/MDPI_functions.h - MODULE atlas_function_c_binding - OUTPUT function_c_binding.f90) + MODULE atlas_functions_c_binding + OUTPUT functions_c_binding.f90) if( atlas_HAVE_ATLAS_NUMERICS ) generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/numerics/Nabla.h) @@ -208,7 +208,7 @@ ecbuild_add_library( TARGET atlas_f SOURCES ${FORTRAN_BINDINGS} atlas_module.F90 - util/atlas_function_module.F90 + util/atlas_functions_module.F90 util/atlas_kinds_module.F90 util/atlas_JSON_module.F90 util/atlas_Config_module.F90 diff --git a/src/atlas_f/atlas_module.F90 b/src/atlas_f/atlas_module.F90 index 48ffe33ae..f3f722853 100644 --- a/src/atlas_f/atlas_module.F90 +++ b/src/atlas_f/atlas_module.F90 @@ -150,6 +150,7 @@ module atlas_module & atlas_output_Gmsh use atlas_trace_module, only : & & atlas_Trace +use atlas_functions_module, only: atlas_functions use fckit_log_module, only: atlas_log => fckit_log diff --git a/src/atlas_f/util/atlas_function_module.F90 b/src/atlas_f/util/atlas_function_module.F90 deleted file mode 100644 index 01e226661..000000000 --- a/src/atlas_f/util/atlas_function_module.F90 +++ /dev/null @@ -1,112 +0,0 @@ -! (C) Copyright 2013 ECMWF. -! -! This software is licensed under the terms of the Apache Licence Version 2.0 -! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. -! In applying this licence, ECMWF does not waive the privileges and immunities -! granted to it by virtue of its status as an intergovernmental organisation nor -! does it submit to any jurisdiction. - -#include "atlas/atlas_f.h" - -module atlas_function_module - -use, intrinsic :: iso_c_binding -use fckit_owned_object_module, only : fckit_owned_object - -implicit none - -private :: fckit_owned_object - -public :: atlas_function - -private - -!------------------------------------------------------------------------------ -TYPE, extends(fckit_owned_object) :: atlas_function - -! Purpose : -! ------- -! *function* : Analytic functions for idealised initial data - -! Methods : -! ------- - -! Author : -! ------ -! Nov 2023 Slavko Brdar (ECMWF) - -!------------------------------------------------------------------------------ -contains - procedure, public :: MDPI_sinusoid => atlas_function__MDPI_sinusoid - procedure, public :: MDPI_harmonic => atlas_function__MDPI_harmonic - procedure, public :: MDPI_vortex => atlas_function__MDPI_vortex - procedure, public :: MDPI_gulfstream => atlas_function__MDPI_gulfstream -#if FCKIT_FINAL_NOT_INHERITING - final :: atlas_function__final_auto -#endif - -END TYPE atlas_function - -!------------------------------------------------------------------------------ - -!======================================================== -contains -!======================================================== - - -! ----------------------------------------------------------------------------- - -function atlas_function__MDPI_sinusoid(this, lon, lat) result(val) - use atlas_function_c_binding - class(atlas_function), intent(in) :: this - real(c_double), intent(in) :: lon, lat - real(c_double) :: val - val = atlas__function__MDPI_sinusoid(lon, lat) -end function atlas_function__MDPI_sinusoid - -! ----------------------------------------------------------------------------- - -function atlas_function__MDPI_harmonic(this, lon, lat) result(val) - use atlas_function_c_binding - class(atlas_function), intent(in) :: this - real(c_double), intent(in) :: lon, lat - real(c_double) :: val - val = atlas__function__MDPI_harmonic(lon, lat) -end function atlas_function__MDPI_harmonic - -! ----------------------------------------------------------------------------- - -function atlas_function__MDPI_vortex(this, lon, lat) result(val) - use atlas_function_c_binding - class(atlas_function), intent(in) :: this - real(c_double), intent(in) :: lon, lat - real(c_double) :: val - val = atlas__function__MDPI_vortex(lon, lat) -end function atlas_function__MDPI_vortex - -! ----------------------------------------------------------------------------- - -function atlas_function__MDPI_gulfstream(this, lon, lat) result(val) - use atlas_function_c_binding - class(atlas_function), intent(in) :: this - real(c_double), intent(in) :: lon, lat - real(c_double) :: val - val = atlas__function__MDPI_gulfstream(lon, lat) -end function atlas_function__MDPI_gulfstream - -!------------------------------------------------------------------------------- - -#if FCKIT_FINAL_NOT_INHERITING -ATLAS_FINAL subroutine atlas_function__final_auto(this) - type(atlas_function), intent(inout) :: this -#if FCKIT_FINAL_DEBUGGING - write(0,*) "atlas_function__final_auto" -#endif -#if FCKIT_FINAL_NOT_PROPAGATING - call this%final() -#endif - FCKIT_SUPPRESS_UNUSED( this ) -end subroutine -#endif - -end module atlas_function_module diff --git a/src/atlas_f/util/atlas_functions_module.F90 b/src/atlas_f/util/atlas_functions_module.F90 new file mode 100644 index 000000000..c0f0200ba --- /dev/null +++ b/src/atlas_f/util/atlas_functions_module.F90 @@ -0,0 +1,160 @@ +! (C) Copyright 2013 ECMWF. +! +! This software is licensed under the terms of the Apache Licence Version 2.0 +! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +! In applying this licence, ECMWF does not waive the privileges and immunities +! granted to it by virtue of its status as an intergovernmental organisation nor +! does it submit to any jurisdiction. + +#include "atlas/atlas_f.h" + +module atlas_functions_module + +use, intrinsic :: iso_c_binding +use fckit_owned_object_module, only : fckit_owned_object + +implicit none + +private :: fckit_owned_object + +public :: atlas_functions + +private + +!------------------------------------------------------------------------------ +TYPE, extends(fckit_owned_object) :: atlas_functions + +! Purpose : +! ------- +! *function* : Analytic functions for idealised initial data + +! Methods : +! ------- + +! Author : +! ------ +! Nov 2023 Slavko Brdar (ECMWF) + +!------------------------------------------------------------------------------ +contains + procedure, public :: MDPI_sinusoid_r8 => atlas_functions__MDPI_sinusoid_r8 + procedure, public :: MDPI_sinusoid_r4 => atlas_functions__MDPI_sinusoid_r4 + procedure, public :: MDPI_harmonic_r8 => atlas_functions__MDPI_harmonic_r8 + procedure, public :: MDPI_harmonic_r4 => atlas_functions__MDPI_harmonic_r4 + procedure, public :: MDPI_vortex_r8 => atlas_functions__MDPI_vortex_r8 + procedure, public :: MDPI_vortex_r4 => atlas_functions__MDPI_vortex_r4 + procedure, public :: MDPI_gulfstream_r8 => atlas_functions__MDPI_gulfstream_r8 + procedure, public :: MDPI_gulfstream_r4 => atlas_functions__MDPI_gulfstream_r4 + generic :: MDPI_sinusoid => MDPI_sinusoid_r8, MDPI_sinusoid_r4 + generic :: MDPI_harmonic => MDPI_harmonic_r8, MDPI_harmonic_r4 + generic :: MDPI_vortex => MDPI_vortex_r8, MDPI_vortex_r4 + generic :: MDPI_gulfstream => MDPI_gulfstream_r8, MDPI_gulfstream_r4 +#if FCKIT_FINAL_NOT_INHERITING + final :: atlas_functions__final_auto +#endif + +END TYPE atlas_functions + +!------------------------------------------------------------------------------ + +!======================================================== +contains +!======================================================== + + +! ----------------------------------------------------------------------------- + +function atlas_functions__MDPI_sinusoid_r8(this, lon, lat) result(val) + use atlas_functions_c_binding + class(atlas_functions), intent(in) :: this + real(c_double), intent(in) :: lon, lat + real(c_double) :: val + val = atlas__functions__MDPI_sinusoid_r8(lon, lat) +end function atlas_functions__MDPI_sinusoid_r8 + +! ----------------------------------------------------------------------------- + +function atlas_functions__MDPI_harmonic_r8(this, lon, lat) result(val) + use atlas_functions_c_binding + class(atlas_functions), intent(in) :: this + real(c_double), intent(in) :: lon, lat + real(c_double) :: val + val = atlas__functions__MDPI_harmonic_r8(lon, lat) +end function atlas_functions__MDPI_harmonic_r8 + +! ----------------------------------------------------------------------------- + +function atlas_functions__MDPI_vortex_r8(this, lon, lat) result(val) + use atlas_functions_c_binding + class(atlas_functions), intent(in) :: this + real(c_double), intent(in) :: lon, lat + real(c_double) :: val + val = atlas__functions__MDPI_vortex_r8(lon, lat) +end function atlas_functions__MDPI_vortex_r8 + +! ----------------------------------------------------------------------------- + +function atlas_functions__MDPI_gulfstream_r8(this, lon, lat) result(val) + use atlas_functions_c_binding + class(atlas_functions), intent(in) :: this + real(c_double), intent(in) :: lon, lat + real(c_double) :: val + val = atlas__functions__MDPI_gulfstream_r8(lon, lat) +end function atlas_functions__MDPI_gulfstream_r8 + +! ----------------------------------------------------------------------------- + +function atlas_functions__MDPI_sinusoid_r4(this, lon, lat) result(val) + use atlas_functions_c_binding + class(atlas_functions), intent(in) :: this + real(c_float), intent(in) :: lon, lat + real(c_float) :: val + val = atlas__functions__MDPI_sinusoid_r4(lon, lat) +end function atlas_functions__MDPI_sinusoid_r4 + +! ----------------------------------------------------------------------------- + +function atlas_functions__MDPI_harmonic_r4(this, lon, lat) result(val) + use atlas_functions_c_binding + class(atlas_functions), intent(in) :: this + real(c_float), intent(in) :: lon, lat + real(c_float) :: val + val = atlas__functions__MDPI_harmonic_r4(lon, lat) +end function atlas_functions__MDPI_harmonic_r4 + +! ----------------------------------------------------------------------------- + +function atlas_functions__MDPI_vortex_r4(this, lon, lat) result(val) + use atlas_functions_c_binding + class(atlas_functions), intent(in) :: this + real(c_float), intent(in) :: lon, lat + real(c_float) :: val + val = atlas__functions__MDPI_vortex_r4(lon, lat) +end function atlas_functions__MDPI_vortex_r4 + +! ----------------------------------------------------------------------------- + +function atlas_functions__MDPI_gulfstream_r4(this, lon, lat) result(val) + use atlas_functions_c_binding + class(atlas_functions), intent(in) :: this + real(c_float), intent(in) :: lon, lat + real(c_float) :: val + val = atlas__functions__MDPI_gulfstream_r4(lon, lat) +end function atlas_functions__MDPI_gulfstream_r4 + +!------------------------------------------------------------------------------- + +#if FCKIT_FINAL_NOT_INHERITING +ATLAS_FINAL subroutine atlas_functions__final_auto(this) + type(atlas_functions), intent(inout) :: this +#if FCKIT_FINAL_DEBUGGING + write(0,*) "atlas_function__final_auto" +#endif +#if FCKIT_FINAL_NOT_PROPAGATING + call this%final() +#endif + FCKIT_SUPPRESS_UNUSED( this ) +end subroutine +#endif + +end module atlas_functions_module diff --git a/src/tests/util/CMakeLists.txt b/src/tests/util/CMakeLists.txt index 0566bd3f9..4e6e0daf0 100644 --- a/src/tests/util/CMakeLists.txt +++ b/src/tests/util/CMakeLists.txt @@ -9,6 +9,13 @@ if( HAVE_FCTEST ) + add_fctest( TARGET atlas_fctest_functions + LINKER_LANGUAGE Fortran + SOURCES fctest_functions.F90 + LIBS atlas_f + ENVIRONMENT ${ATLAS_TEST_ENVIRONMENT} + ) + add_fctest( TARGET atlas_fctest_logging LINKER_LANGUAGE Fortran SOURCES fctest_logging.F90