diff --git a/fortran/tuvx.F90 b/fortran/tuvx.F90 index 210e9c2c..55d8e1cb 100644 --- a/fortran/tuvx.F90 +++ b/fortran/tuvx.F90 @@ -50,19 +50,19 @@ end function get_grid_c subroutine set_edges_c(grid, edges, n_edges, error) bind(C, name="SetEdges") use musica_util, only: error_t_c import c_ptr, c_double, c_size_t - type(c_ptr), value, intent(in) :: grid + type(c_ptr), value, intent(in) :: grid real(c_double), dimension(*), intent(in) :: edges - integer(c_size_t), intent(in) :: n_edges - type(error_t_c), intent(inout) :: error + integer(c_size_t), value :: n_edges + type(error_t_c), intent(inout) :: error end subroutine set_edges_c subroutine set_midpoints_c(grid, midpoints, n_midpoints, error) bind(C, name="SetMidpoints") use musica_util, only: error_t_c import c_ptr, c_double, c_size_t - type(c_ptr), value, intent(in) :: grid + type(c_ptr), value, intent(in) :: grid real(c_double), dimension(*), intent(in) :: midpoints - integer(c_size_t), intent(in) :: n_midpoints - type(error_t_c), intent(inout) :: error + integer(c_size_t), value :: n_midpoints + type(error_t_c), intent(inout) :: error end subroutine set_midpoints_c end interface diff --git a/src/test/unit/tuvx/tuvx_c_api.cpp b/src/test/unit/tuvx/tuvx_c_api.cpp index b6191725..8eb1f969 100644 --- a/src/test/unit/tuvx/tuvx_c_api.cpp +++ b/src/test/unit/tuvx/tuvx_c_api.cpp @@ -56,9 +56,22 @@ TEST_F(TuvxCApiTest, DetectsNonexistentConfigFile) { DeleteError(&error); } -TEST_F(TuvxCApiTest, GridMap) { +TEST_F(TuvxCApiTest, CanGetGrid) { + const char* yaml_config_path = "examples/ts1_tsmlt.yml"; + SetUp(yaml_config_path); + Error error; + GridMap* grid_map = GetGridMap(tuvx, &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(grid_map, nullptr); + Grid* grid = GetGrid(grid_map, "height", "km", &error); + ASSERT_TRUE(IsSuccess(error)); + ASSERT_NE(grid, nullptr); + std::vector edges = {0.0, 1.0, 2.0}; + ASSERT_NO_THROW( + SetEdges(grid, edges.data(), edges.size(), &error); + ); + std::vector midpoints = {0.5, 1.5}; + ASSERT_NO_THROW( + SetMidpoints(grid, midpoints.data(), midpoints.size(), &error); + ); } - -TEST_F(TuvxCApiTest, Grid) { - -} \ No newline at end of file diff --git a/src/tuvx/interface.F90 b/src/tuvx/interface.F90 index f1ba9c97..2ba11bc4 100644 --- a/src/tuvx/interface.F90 +++ b/src/tuvx/interface.F90 @@ -157,12 +157,12 @@ end subroutine internal_delete_grid !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine internal_set_edges(grid, edges, num_edges, error_code) bind(C, name="InternalSetEdges") - use iso_c_binding, only: c_ptr, c_f_pointer, c_int, c_double + use iso_c_binding, only: c_ptr, c_f_pointer, c_int, c_double, c_size_t ! arguments type(c_ptr), value, intent(in) :: grid real(kind=c_double), intent(in), dimension(*) :: edges - integer(kind=c_int), intent(in) :: num_edges + integer(kind=c_size_t), intent(in), value :: num_edges integer(kind=c_int), intent(out) :: error_code ! variables @@ -174,6 +174,8 @@ subroutine internal_set_edges(grid, edges, num_edges, error_code) bind(C, name=" f_grid%delta_ = edges(2:num_edges) - edges(1:num_edges-1) + f_grid%ncells_ = num_edges - 1 + end subroutine internal_set_edges !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -184,7 +186,7 @@ subroutine internal_set_midpoints(grid, midpoints, num_midpoints, error_code) bi ! arguments type(c_ptr), value, intent(in) :: grid real(kind=c_double), intent(in), dimension(*) :: midpoints - integer(kind=c_int), intent(in) :: num_midpoints + integer(kind=c_int), intent(in), value :: num_midpoints integer(kind=c_int), intent(out) :: error_code ! variables