Skip to content

Commit cda48c8

Browse files
authored
DIAG MANAGER: Fixes to zbounds (#1880)
1 parent 361511c commit cda48c8

3 files changed

Lines changed: 57 additions & 8 deletions

File tree

diag_manager/fms_diag_axis_object.F90

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,13 @@ subroutine write_axis_data(this, fms2io_fileobj, parent_axis)
458458
if (present(parent_axis)) then
459459
select type(parent_axis)
460460
type is (fmsDiagFullAxis_type)
461-
call write_data(fms2io_fileobj, this%subaxis_name, parent_axis%axis_data(i:j))
461+
! Added this select type so the the data is indexed correctly
462+
select type (vardata => parent_axis%axis_data)
463+
type is (real(kind=r8_kind))
464+
call write_data(fms2io_fileobj, this%subaxis_name, vardata(i:j))
465+
type is (real(kind=r4_kind))
466+
call write_data(fms2io_fileobj, this%subaxis_name, vardata(i:j))
467+
end select
462468
end select
463469
endif
464470
type is (fmsDiagDiurnalAxis_type)
@@ -881,8 +887,10 @@ subroutine fill_subaxis(this, starting_index, ending_index, axis_id, parent_id,
881887
if (present(nz_subaxis)) nsubaxis = nz_subaxis
882888

883889
this%axis_id = axis_id
884-
this%starting_index = starting_index
885-
this%ending_index = ending_index
890+
891+
! The min and max were added here to support axis that are both increasing and decreasing
892+
this%starting_index = min(starting_index, ending_index)
893+
this%ending_index = max(starting_index, ending_index)
886894
this%parent_axis_id = parent_id
887895
write(nsubaxis_char, '(i2.2)') nsubaxis
888896
this%subaxis_name = trim(parent_axis_name)//"_sub"//nsubaxis_char

test_fms/diag_manager/test_multiple_zbounds.F90

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ program test_multiple_zbounds
2929
type(time_type) :: Time_step !< Time_step of the simulation
3030
integer :: id_z1 !< Axis id for the z dimension
3131
integer :: id_z2 !< Axis id for the z dimension
32+
integer :: id_z_reverse !< Axis id for the z dimension (decreasing)
3233
integer :: id_var1 !< var id for the first variable
3334
integer :: id_var2 !< var_id for the second variable
35+
integer :: id_var3 !< var_id for the third variable
3436
real, allocatable :: z(:) !< z axis data
37+
real, allocatable :: z_reverse(:) !< z axis data (decreasing)
3538
integer :: nz !< Size of the z dimension
3639
integer :: i
3740
logical :: used !< Dummy argument to send_data
@@ -42,25 +45,28 @@ program test_multiple_zbounds
4245

4346
nz = 10
4447
allocate(z(nz))
48+
allocate(z_reverse(nz))
4549
do i=1, nz
4650
z(i) = i
51+
z_reverse(i) = nz - i + 1
4752
enddo
4853

4954
Time = set_date(2,1,1,0,0,0)
5055
Time_step = set_time (3600,0)
5156

5257
id_z1 = diag_axis_init('zaxis1', z, 'z', 'z', long_name='Z1')
5358
id_z2 = diag_axis_init('zaxis2', z, 'z', 'z', long_name='Z2')
59+
id_z_reverse = diag_axis_init('zaxis3', z_reverse, 'z_reverse', 'z', long_name='Z3')
5460
id_var1 = register_diag_field ('atmos', 'ua_1', (/id_z1/), Time)
5561
id_var2 = register_diag_field ('atmos', 'ua_2', (/id_z2/), Time)
62+
id_var3 = register_diag_field ('atmos', 'ua_3', (/id_z_reverse/), Time)
5663

5764
call diag_manager_set_time_end(set_date(2,1,2,0,0,0))
5865
do i = 1, 24
5966
Time = Time + Time_step
60-
z = real(i)
6167
used = send_data(id_var1, z, Time)
6268
used = send_data(id_var2, z, Time)
63-
69+
used = send_data(id_var3, z, Time)
6470
call diag_send_complete(Time_step)
6571
end do
6672

@@ -77,15 +83,25 @@ subroutine check_output()
7783
integer :: SUB1_SIZE = 3
7884
integer :: SUB2_SIZE = 1
7985
character(len=20) :: EXPECTED_DIM_NAMES(2)
86+
real :: EXPECTED_ZSUBAXIS_1(3)
87+
real :: EXPECTED_ZSUBAXIS_2(1)
88+
real :: EXPECTED_ZSUBAXIS_3(3)
8089

8190
EXPECTED_DIM_NAMES(2) = "time"
8291
if (.not. open_file(fileobj, "test_multiple_zbounds.nc", "read")) then
8392
call mpp_error(FATAL, "Unable to open the expected output file: test_var_masks.nc")
8493
endif
8594

8695
call check_dimension(fileobj, "time", EXPECTED_NTIMES)
87-
call check_dimension(fileobj, "zaxis1_sub01", SUB1_SIZE)
88-
call check_dimension(fileobj, "zaxis2_sub02", SUB2_SIZE)
96+
97+
EXPECTED_ZSUBAXIS_1 = (/3., 4., 5./)
98+
call check_dimension(fileobj, "zaxis1_sub01", SUB1_SIZE, EXPECTED_ZSUBAXIS_1)
99+
100+
EXPECTED_ZSUBAXIS_2 = (/1./)
101+
call check_dimension(fileobj, "zaxis2_sub02", SUB2_SIZE, EXPECTED_ZSUBAXIS_2)
102+
103+
EXPECTED_ZSUBAXIS_3 = (/5., 4., 3./)
104+
call check_dimension(fileobj, "zaxis3_sub03", SUB1_SIZE, EXPECTED_ZSUBAXIS_3)
89105

90106
EXPECTED_DIM_NAMES(1) = "zaxis1_sub01"
91107
call check_variable(fileobj, "ua_1", EXPECTED_DIM_NAMES)
@@ -114,17 +130,40 @@ subroutine check_variable(fileobj, variable_name, expected_dimnames)
114130

115131
end subroutine check_variable
116132

117-
subroutine check_dimension(fileobj, dimension_name, expected_size)
133+
!> @brief Check dimension data
134+
subroutine check_data(err_msg, actual_data, expected_data)
135+
character(len=*), intent(in) :: err_msg !< Error message to append
136+
real, intent(in) :: actual_data(:) !< Dimension data from file
137+
real, intent(in) :: expected_data(:) !< Expected data
138+
139+
integer :: i
140+
141+
do i = 1, size(actual_data)
142+
if (actual_data(i) .ne. expected_data(i)) &
143+
call mpp_error(FATAL, "The data is not expected for "//trim(err_msg))
144+
enddo
145+
end subroutine check_data
146+
147+
subroutine check_dimension(fileobj, dimension_name, expected_size, expected_data)
118148
type(FmsNetcdfFile_t), intent(in) :: fileobj
119149
character(len=*), intent(in) :: dimension_name
120150
integer, intent(in) :: expected_size
151+
real, optional, intent(in) :: expected_data(:)
121152

122153
integer :: dim_size
154+
real, allocatable :: z_data(:)
123155

124156
call get_dimension_size(fileobj, dimension_name, dim_size)
125157
if (dim_size .ne. expected_size) then
126158
call mpp_error(FATAL, trim(dimension_name)//" is not the expected size!")
127159
endif
128160

161+
if (present(expected_data)) then
162+
allocate(z_data(dim_size))
163+
call read_data(fileobj, dimension_name, z_data)
164+
call check_data(dimension_name, z_data, expected_data)
165+
endif
166+
167+
129168
end subroutine
130169
end program test_multiple_zbounds

test_fms/diag_manager/test_multiple_zbounds.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ diag_files:
4747
zbounds: 3 5
4848
- var_name: ua_2
4949
zbounds: 1 1
50+
- var_name: ua_3
51+
zbounds: 3 5
5052
_EOF
5153

5254
test_expect_success "Test with multiple zbounds limits (modern diag manager)" '

0 commit comments

Comments
 (0)