From c58c266ea967eca7899dac797319e8d600037ea7 Mon Sep 17 00:00:00 2001 From: Matt Dawson Date: Tue, 8 Oct 2024 19:48:05 -0600 Subject: [PATCH 1/2] fix bug in getting number of grid sections --- fortran/test/unit/tuvx.F90 | 26 ++++++++++++++++++++++++-- src/tuvx/grid.cpp | 2 +- src/tuvx/interface_grid.F90 | 12 ++++++------ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/fortran/test/unit/tuvx.F90 b/fortran/test/unit/tuvx.F90 index ce477652..b7238889 100644 --- a/fortran/test/unit/tuvx.F90 +++ b/fortran/test/unit/tuvx.F90 @@ -144,9 +144,9 @@ subroutine test_tuvx_data_from_host( ) heights => grid_t( "height", "km", 3, error ) ASSERT( error%is_success() ) - call heights%set_edges( [ 0.0_dk, 1.0_dk, 2.0_dk, 3.0_dk ], error ) + call heights%set_edges( [ 0.0_dk, 1.2_dk, 2.0_dk, 3.0_dk ], error ) ASSERT( error%is_success() ) - call heights%set_midpoints( [ 0.5_dk, 1.5_dk, 2.5_dk ], error ) + call heights%set_midpoints( [ 0.5_dk, 1.3_dk, 2.5_dk ], error ) wavelengths => grid_t( "wavelength", "nm", 5, error ) ASSERT( error%is_success() ) call wavelengths%set_edges( [ 300.0_dk, 400.0_dk, 500.0_dk, 600.0_dk, 700.0_dk, 800.0_dk ], error ) @@ -157,6 +157,27 @@ subroutine test_tuvx_data_from_host( ) ASSERT( error%is_success() ) call grids%add( heights, error ) ASSERT( error%is_success() ) + ASSERT_EQ( heights%number_of_sections( error ), 3 ) + ASSERT( error%is_success() ) + allocate( temp_vals(4) ) + call heights%get_edges( temp_vals, error ) + ASSERT( error%is_success() ) + ASSERT_EQ( temp_vals(1), 0.0_dk ) + ASSERT_EQ( temp_vals(2), 1.2_dk ) + ASSERT_EQ( temp_vals(3), 2.0_dk ) + ASSERT_EQ( temp_vals(4), 3.0_dk ) + deallocate( temp_vals ) + allocate( temp_vals(3) ) + call heights%get_midpoints( temp_vals, error ) + ASSERT( error%is_success() ) + ASSERT_EQ( temp_vals(1), 0.5_dk ) + ASSERT_EQ( temp_vals(2), 1.3_dk ) + ASSERT_EQ( temp_vals(3), 2.5_dk ) + deallocate( temp_vals ) + call heights%set_edges( [ 0.0_dk, 1.0_dk, 2.0_dk, 3.0_dk ], error ) + ASSERT( error%is_success() ) + call heights%set_midpoints( [ 0.5_dk, 1.5_dk, 2.5_dk ], error ) + ASSERT( error%is_success() ) call grids%add( wavelengths, error ) ASSERT( error%is_success() ) temperatures => profile_t( "temperature", "K", heights, error ) @@ -204,6 +225,7 @@ subroutine test_tuvx_data_from_host( ) end do end do allocate( temp_vals(4) ) + ASSERT_EQ( heights%number_of_sections( error ), 3 ) call heights%get_edges( temp_vals, error ) ASSERT( error%is_success() ) ASSERT_EQ( temp_vals(1), 0.0_dk ) diff --git a/src/tuvx/grid.cpp b/src/tuvx/grid.cpp index 071b7b0e..1e39baa6 100644 --- a/src/tuvx/grid.cpp +++ b/src/tuvx/grid.cpp @@ -96,7 +96,7 @@ namespace musica std::size_t Grid::GetNumSections(Error *error) { int error_code = 0; - std::size_t n_sections = InternalGetNumSections(grid_, &error_code); + std::size_t n_sections = InternalGetNumSections(updater_, &error_code); if (error_code != 0) { *error = Error{ 1, CreateString(MUSICA_ERROR_CATEGORY), CreateString("Failed to get number of sections") }; diff --git a/src/tuvx/interface_grid.F90 b/src/tuvx/interface_grid.F90 index 41fb7333..e64138df 100644 --- a/src/tuvx/interface_grid.F90 +++ b/src/tuvx/interface_grid.F90 @@ -117,23 +117,23 @@ end subroutine internal_delete_grid_updater !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - function internal_get_num_sections(grid, error_code) & + function internal_get_num_sections(updater, error_code) & bind(C, name="InternalGetNumSections") result(num_sections) use iso_c_binding, only: c_ptr, c_f_pointer, c_int, c_size_t - use tuvx_grid_from_host, only: grid_from_host_t + use tuvx_grid_from_host, only: grid_from_host_t, grid_updater_t ! arguments - type(c_ptr), value, intent(in) :: grid + type(c_ptr), value, intent(in) :: updater integer(kind=c_int), intent(out) :: error_code ! output integer(kind=c_size_t) :: num_sections ! variables - type(grid_from_host_t), pointer :: f_grid + type(grid_updater_t), pointer :: f_updater - call c_f_pointer(grid, f_grid) - num_sections = f_grid%size( ) + call c_f_pointer(updater, f_updater) + num_sections = f_updater%grid_%size( ) end function internal_get_num_sections From 18874ab78787159bb4fa4833edd21a5767266084 Mon Sep 17 00:00:00 2001 From: Matt Dawson Date: Wed, 9 Oct 2024 11:44:48 -0600 Subject: [PATCH 2/2] address reviewer comments --- src/tuvx/interface_grid.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tuvx/interface_grid.F90 b/src/tuvx/interface_grid.F90 index e64138df..70faad54 100644 --- a/src/tuvx/interface_grid.F90 +++ b/src/tuvx/interface_grid.F90 @@ -120,7 +120,7 @@ end subroutine internal_delete_grid_updater function internal_get_num_sections(updater, error_code) & bind(C, name="InternalGetNumSections") result(num_sections) use iso_c_binding, only: c_ptr, c_f_pointer, c_int, c_size_t - use tuvx_grid_from_host, only: grid_from_host_t, grid_updater_t + use tuvx_grid_from_host, only: grid_updater_t ! arguments type(c_ptr), value, intent(in) :: updater