Skip to content

Commit

Permalink
add a fortran unit test for Fortran API for util/function/MDPI_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrdar committed Nov 21, 2023
1 parent ba80220 commit 61ccf7e
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 127 deletions.
29 changes: 21 additions & 8 deletions src/atlas/util/function/MDPI_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/atlas/util/function/MDPI_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/atlas_f/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/atlas_f/atlas_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
112 changes: 0 additions & 112 deletions src/atlas_f/util/atlas_function_module.F90

This file was deleted.

160 changes: 160 additions & 0 deletions src/atlas_f/util/atlas_functions_module.F90
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/tests/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 61ccf7e

Please sign in to comment.