Skip to content

Commit

Permalink
improve unit test for Fortran API functions: add initialisation of At…
Browse files Browse the repository at this point in the history
…las field
  • Loading branch information
sbrdar committed Nov 21, 2023
1 parent d702052 commit d89f092
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/atlas_f/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/functionspace/detail/PointCl
generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/redistribution/detail/RedistributionInterface.h
MODULE atlas_redistribution_c_binding
OUTPUT redistribution_c_binding.f90)
generate_fortran_bindings(FORTRAN_BINDINGS ../atlas/util/function/MDPI_functions.h
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
41 changes: 36 additions & 5 deletions src/atlas_f/util/atlas_functions_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,68 @@
module atlas_functions_module

use, intrinsic :: iso_c_binding
use atlas_functions_c_binding

implicit none

interface

pure function atlas__functions__MDPI_sinusoid( lon, lat ) bind(C,name="atlas__functi&
&ons__MDPI_sinusoid")
use iso_c_binding, only: c_double
real(c_double) :: atlas__functions__MDPI_sinusoid
real(c_double), intent(in) :: lon, lat
end function

pure function atlas__functions__MDPI_harmonic( lon, lat ) bind(C,name="atlas__functi&
&ons__MDPI_harmonic")
use iso_c_binding, only: c_double
real(c_double) :: atlas__functions__MDPI_harmonic
real(c_double), intent(in) :: lon, lat
end function

pure function atlas__functions__MDPI_vortex( lon, lat ) bind(C,name="atlas__function&
&s__MDPI_vortex")
use iso_c_binding, only: c_double
real(c_double) :: atlas__functions__MDPI_vortex
real(c_double), intent(in) :: lon, lat
end function

pure function atlas__functions__MDPI_gulfstream( lon, lat ) bind(C,name="atlas__func&
&tions__MDPI_gulfstream")
use iso_c_binding, only: c_double
real(c_double) :: atlas__functions__MDPI_gulfstream
real(c_double), intent(in) :: lon, lat
end function

end interface

contains

function MDPI_sinusoid(lon, lat) result(val)
elemental function MDPI_sinusoid(lon, lat) result(val)
real(c_double), intent(in) :: lon, lat
real(c_double) :: val
val = atlas__functions__MDPI_sinusoid(lon, lat)
end function MDPI_sinusoid

! -----------------------------------------------------------------------------

function MDPI_harmonic(lon, lat) result(val)
elemental function MDPI_harmonic(lon, lat) result(val)
real(c_double), intent(in) :: lon, lat
real(c_double) :: val
val = atlas__functions__MDPI_harmonic(lon, lat)
end function MDPI_harmonic

! -----------------------------------------------------------------------------

function MDPI_vortex(lon, lat) result(val)
elemental function MDPI_vortex(lon, lat) result(val)
real(c_double), intent(in) :: lon, lat
real(c_double) :: val
val = atlas__functions__MDPI_vortex(lon, lat)
end function MDPI_vortex

! -----------------------------------------------------------------------------

function MDPI_gulfstream(lon, lat) result(val)
elemental function MDPI_gulfstream(lon, lat) result(val)
real(c_double), intent(in) :: lon, lat
real(c_double) :: val
val = atlas__functions__MDPI_gulfstream(lon, lat)
Expand Down
19 changes: 19 additions & 0 deletions src/tests/util/fctest_functions.F90
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ end module fcta_functions_fxt
val = MDPI_gulfstream(1._c_double, 1._c_double)
END_TEST

TEST( test_atlas_Functions_vector )
real(c_double), dimension(3) :: val, lon, lat
lon = [ 1._c_double, 1._c_double, 1._c_double ]
lat = [ 1._c_double, 1._c_double, 1._c_double ]
val = MDPI_sinusoid(lon, lat)
val = MDPI_harmonic(lon, lat)
val = MDPI_vortex(lon, lat)
val = MDPI_gulfstream(lon, lat)
END_TEST

TEST( test_initialise_field )
type(atlas_Field) :: field
real(c_double), dimension(:,:), pointer :: fieldv
real(c_double), dimension(3) :: val
field = atlas_Field(kind=atlas_real(c_double), shape=[3,3])
call field%data(fieldv)
val = MDPI_sinusoid(fieldv(1,:), fieldv(2,:))
END_TEST

! -----------------------------------------------------------------------------

END_TESTSUITE

0 comments on commit d89f092

Please sign in to comment.