Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix bug in getting number of grid sections #233

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions fortran/test/unit/tuvx.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/tuvx/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") };
Expand Down
12 changes: 6 additions & 6 deletions src/tuvx/interface_grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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_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

Expand Down
Loading