Skip to content

Commit cc9d83b

Browse files
committed
Add 1D character read test.
1 parent 1597566 commit cc9d83b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

test/unit/fortran/src/mock_routines/test_pio_reader.pf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,78 @@ subroutine test_pio_reader_2d_int_read()
267267
end subroutine test_pio_reader_2d_int_read
268268
!----------------------------------------
269269

270+
@test
271+
subroutine test_pio_reader_1d_char_read()
272+
!Check that the PIO reader can read a 1D character variable
273+
!from a file successfully.
274+
275+
use funit
276+
277+
use ccpp_io_reader, only: abstract_netcdf_reader_t
278+
use ccpp_io_reader, only: create_netcdf_reader_t
279+
280+
class(abstract_netcdf_reader_t), allocatable :: reader
281+
282+
integer :: errcode
283+
character(len=256) :: errmsg
284+
285+
!Variable to be read:
286+
character(len=:), pointer :: gas_names(:)
287+
288+
! File name for testing:
289+
! NOTE: This specific file is added during the Github Actions workflow.
290+
character(len=*), parameter :: fname = &
291+
"../../../rrtmgp-data/rrtmgp-gas-sw-g112.nc"
292+
293+
! Begin test:
294+
295+
reader = create_netcdf_reader_t()
296+
297+
! Open file:
298+
call reader%open_file(fname, errmsg, errcode)
299+
300+
! Read 1D character variable:
301+
call reader%get_var("gas_names", gas_names, errmsg, errcode)
302+
303+
! Check that the variable was read successfully:
304+
@assertTrue(errcode == 0)
305+
@assertTrue(errmsg == '')
306+
307+
! Check that the variable's properties are correct:
308+
@assertTrue(associated(gas_names))
309+
@assertTrue(len(gas_names) == 32)
310+
@assertTrue(size(gas_names) == 19)
311+
312+
! Check that the variable's values are correct:
313+
@assertTrue(trim(gas_names(1)) == "h2o")
314+
@assertTrue(trim(gas_names(2)) == "co2")
315+
@assertTrue(trim(gas_names(3)) == "o3")
316+
@assertTrue(trim(gas_names(4)) == "n2o")
317+
@assertTrue(trim(gas_names(5)) == "co")
318+
@assertTrue(trim(gas_names(6)) == "ch4")
319+
@assertTrue(trim(gas_names(7)) == "o2")
320+
@assertTrue(trim(gas_names(8)) == "n2")
321+
@assertTrue(trim(gas_names(9)) == "ccl4")
322+
@assertTrue(trim(gas_names(10)) == "cfc11")
323+
@assertTrue(trim(gas_names(11)) == "cfc12")
324+
@assertTrue(trim(gas_names(12)) == "cfc22")
325+
@assertTrue(trim(gas_names(13)) == "hfc143a")
326+
@assertTrue(trim(gas_names(14)) == "hfc125")
327+
@assertTrue(trim(gas_names(15)) == "hfc23")
328+
@assertTrue(trim(gas_names(16)) == "hfc32")
329+
@assertTrue(trim(gas_names(17)) == "hfc134a")
330+
@assertTrue(trim(gas_names(18)) == "cf4")
331+
@assertTrue(trim(gas_names(19)) == "no2")
332+
333+
! Perform test cleanup:
334+
deallocate(gas_names)
335+
call reader%close_file(errmsg, errcode)
336+
deallocate(reader)
337+
338+
end subroutine test_pio_reader_1d_char_read
339+
340+
!----------------------------------------
341+
270342
@test
271343
subroutine final_test()
272344
use funit

0 commit comments

Comments
 (0)