Skip to content

Commit

Permalink
maybe the last memory error
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Jun 14, 2024
1 parent f29504e commit cec4cb6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
12 changes: 6 additions & 6 deletions fortran/tuvx.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions src/test/unit/tuvx/tuvx_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> edges = {0.0, 1.0, 2.0};
ASSERT_NO_THROW(
SetEdges(grid, edges.data(), edges.size(), &error);
);
std::vector<double> midpoints = {0.5, 1.5};
ASSERT_NO_THROW(
SetMidpoints(grid, midpoints.data(), midpoints.size(), &error);
);
}

TEST_F(TuvxCApiTest, Grid) {

}
8 changes: 5 additions & 3 deletions src/tuvx/interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -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
Expand Down

0 comments on commit cec4cb6

Please sign in to comment.