-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/fortran api init functions (#165)
* add Fortran API for MDPI initial functions * add a fortran unit test for Fortran API for util/function/MDPI_functions
- Loading branch information
Showing
7 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
! (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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
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 | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
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 | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
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) | ||
end function MDPI_gulfstream | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
end module atlas_functions_module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
! (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. | ||
|
||
! This File contains Unit Tests for testing the | ||
! C++ / Fortran Interfaces to the logging facilities | ||
! @author Willem Deconinck | ||
|
||
#include "fckit/fctest.h" | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
module fcta_functions_fxt | ||
use atlas_module | ||
use, intrinsic :: iso_c_binding | ||
implicit none | ||
character(len=1024) :: msg | ||
|
||
end module fcta_functions_fxt | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
TESTSUITE_WITH_FIXTURE(fctest_atlas_functions,fcta_functions_fxt) | ||
|
||
! ----------------------------------------------------------------------------- | ||
TESTSUITE_INIT | ||
call atlas_library%initialise() | ||
END_TESTSUITE_INIT | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
TESTSUITE_FINALIZE | ||
call atlas_library%finalise() | ||
END_TESTSUITE_FINALIZE | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
TEST( test_atlas_Functions ) | ||
real(c_double) :: val | ||
val = MDPI_sinusoid(1._c_double, 1._c_double) | ||
FCTEST_CHECK_CLOSE(val, 1.0002115216773033_c_double, 1e-12_c_double) | ||
val = MDPI_harmonic(1._c_double, 1._c_double) | ||
FCTEST_CHECK_CLOSE(val, 2.0000000000000000_c_double, 1e-12_c_double) | ||
val = MDPI_vortex(1._c_double, 1._c_double) | ||
FCTEST_CHECK_CLOSE(val, 2.7267489215500755_c_double, 1e-12_c_double) | ||
val = MDPI_gulfstream(1._c_double, 1._c_double) | ||
FCTEST_CHECK_CLOSE(val, 1.0002115216773033_c_double, 1e-12_c_double) | ||
END_TEST | ||
|
||
TEST( test_atlas_Functions_vector ) | ||
real(c_double), dimension(3) :: val, lon, lat, val_ref | ||
lon = [ 1._c_double, 2._c_double, 3._c_double ] | ||
lat = [ 1._c_double, 2._c_double, 3._c_double ] | ||
val = MDPI_sinusoid(lon, lat) | ||
val_ref = [1.0002115216773033_c_double, 1.0008458683590891_c_double, 1.0019023851484181_c_double] | ||
FCTEST_CHECK_CLOSE(val, val_ref, 1e-12_c_double) | ||
val = MDPI_harmonic(lon, lat) | ||
val_ref = [2.0000000000000000_c_double, 2.0000000000000000_c_double, 2.0000000000000000_c_double] | ||
FCTEST_CHECK_CLOSE(val, val_ref, 1e-12_c_double) | ||
val = MDPI_vortex(lon, lat) | ||
val_ref = [2.7267489215500755_c_double, 2.7520839004022091_c_double, 2.7755506683886928_c_double] | ||
FCTEST_CHECK_CLOSE(val, val_ref, 1e-12_c_double) | ||
val = MDPI_gulfstream(lon, lat) | ||
val_ref = [1.0002115216773033_c_double, 1.0008458683590891_c_double, 1.0019023851484181_c_double] | ||
FCTEST_CHECK_CLOSE(val, val_ref, 1e-12_c_double) | ||
END_TEST | ||
|
||
TEST( test_initialise_field ) | ||
type(atlas_Field) :: field_xy, field_val | ||
real(c_double), dimension(:,:), pointer :: field_xy_v | ||
real(c_double), dimension(:), pointer :: field_val_v | ||
real(c_double), dimension(3) :: field_val_ref | ||
field_xy = atlas_Field(kind=atlas_real(c_double), shape=[2,3]) | ||
field_val = atlas_Field(kind=atlas_real(c_double), shape=[3]) | ||
call field_xy%data(field_xy_v) | ||
field_xy_v = 1._c_double | ||
call field_val%data(field_val_v) | ||
field_val_v = MDPI_sinusoid(field_xy_v(1,:), field_xy_v(2,:)) | ||
field_val_ref = [1.0002115216773033_c_double, 1.0002115216773033_c_double, 1.0002115216773033_c_double] | ||
FCTEST_CHECK_CLOSE(field_val_v, field_val_ref, 1e-12_c_double) | ||
END_TEST | ||
|
||
! ----------------------------------------------------------------------------- | ||
|
||
END_TESTSUITE |