diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8fbcb1c91..2ae21971a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -22,4 +22,5 @@ | MetBenjaminWent | Benjamin Went | Met Office | 2026-01-30 | | jcsmeto | James Cunningham-Smith | Met Office | 2026-02-06 | | thomasmelvin | Thomas Melvin | Met Office | 2026-01-15 | -| ericaneininger | Erica Neininger | Met Office | 2026-03-02 | \ No newline at end of file +| ericaneininger | Erica Neininger | Met Office | 2026-03-02 | +| allynt | Allyn Treshansky | Met Office | 2026-02-12 | \ No newline at end of file diff --git a/components/lfric-xios/source/lfric_xios_read_mod.F90 b/components/lfric-xios/source/lfric_xios_read_mod.F90 index 456ce5f3d..b42f52d6b 100644 --- a/components/lfric-xios/source/lfric_xios_read_mod.F90 +++ b/components/lfric-xios/source/lfric_xios_read_mod.F90 @@ -119,7 +119,7 @@ subroutine checkpoint_read_value(io_value, value_name) class(io_value_type), intent(inout) :: io_value character(*), optional, intent(in) :: value_name character(str_def) :: restart_id - integer(i_def) :: array_dims + real(kind=r_def), allocatable :: data_value(:) integer(tik) :: timing_id if ( LPROF ) call start_timing(timing_id, 'lfric_xios.chkpt_readv') @@ -129,11 +129,11 @@ subroutine checkpoint_read_value(io_value, value_name) else restart_id = "restart_" // trim(io_value%io_id) end if - array_dims = size(io_value%data) + + allocate(data_value, source=io_value%get_data()) if ( xios_is_valid_field(trim(restart_id)) ) then - call xios_recv_field( trim(restart_id), & - io_value%data(1:array_dims) ) + call xios_recv_field( trim(restart_id), data_value ) else call log_event( 'No XIOS field with id="'//trim(restart_id)//'" is defined', & LOG_LEVEL_ERROR ) diff --git a/components/lfric-xios/source/lfric_xios_write_mod.F90 b/components/lfric-xios/source/lfric_xios_write_mod.F90 index 634aefd1b..b55ddbe43 100644 --- a/components/lfric-xios/source/lfric_xios_write_mod.F90 +++ b/components/lfric-xios/source/lfric_xios_write_mod.F90 @@ -83,7 +83,7 @@ subroutine write_value_generic(io_value, value_name) class(io_value_type), intent(inout) :: io_value character(*), optional, intent(in) :: value_name - integer(i_def) :: array_dims + real(kind=r_def), allocatable :: data_value(:) character(:), allocatable :: value_id if (present(value_name)) then @@ -92,10 +92,11 @@ subroutine write_value_generic(io_value, value_name) value_id = io_value%io_id end if - array_dims = size(io_value%data) + allocate(data_value, source=io_value%get_data()) + if ( xios_is_valid_field(trim(value_id)) ) then call xios_send_field( trim(value_id), & - reshape(io_value%data, (/ 1, array_dims /)) ) + reshape(data_value, (/ 1, size(data_value) /)) ) else call log_event( 'No XIOS field with id="'//trim(io_value%io_id)//'" is defined', & LOG_LEVEL_ERROR ) @@ -191,17 +192,19 @@ subroutine checkpoint_write_value(io_value, value_name) character(*), optional, intent(in) :: value_name character(str_def) :: checkpoint_id - integer(i_def) :: array_dims + real(kind=r_def), allocatable :: data_value(:) if(present(value_name)) then checkpoint_id = trim(value_name) else checkpoint_id = trim(io_value%io_id) end if - array_dims = size(io_value%data) + + allocate(data_value, source=io_value%get_data()) + if ( xios_is_valid_field(trim(checkpoint_id)) ) then call xios_send_field( trim(checkpoint_id), & - reshape(io_value%data, (/ 1, array_dims /)) ) + reshape(data_value, (/ 1, size(data_value) /)) ) else call log_event( 'No XIOS field with id="'//trim(checkpoint_id)//'" is defined', & LOG_LEVEL_ERROR ) diff --git a/infrastructure/source/io/io_value_mod.f90 b/infrastructure/source/io/io_value_mod.f90 index d9c0562b9..453f9e24f 100644 --- a/infrastructure/source/io/io_value_mod.f90 +++ b/infrastructure/source/io/io_value_mod.f90 @@ -22,12 +22,16 @@ module io_value_mod !> that can be stored in a key-value pair type, extends(abstract_value_type) :: io_value_type character(str_def) :: io_id + ! TODO: + ! real(kind=r_def), private, allocatable :: data(:) real(kind=r_def), allocatable :: data(:) procedure(io_operation_interface), pointer :: write_method => null() procedure(io_operation_interface), pointer :: checkpoint_read_method => null() procedure(io_operation_interface), pointer :: checkpoint_write_method => null() contains procedure, public :: init + procedure, public :: set_data + procedure, public :: get_data procedure, public :: set_write_behaviour procedure, public :: set_checkpoint_write_behaviour procedure, public :: set_checkpoint_read_behaviour @@ -49,18 +53,41 @@ end subroutine io_operation_interface !> @brief Initialiser for the io_value_type !> @param[in] io_id The ID used for managing I/O operations -!> @param[in] data An array holding the data -subroutine init(self, io_id, data) +!> @param[in] data_value An array holding the data +subroutine init(self, io_id, data_value) class(io_value_type), intent(inout) :: self character(len=*), intent(in) :: io_id - real(kind=r_def), intent(in) :: data(:) + real(kind=r_def), intent(in) :: data_value(:) self%io_id = io_id - allocate(self%data, source=data) + allocate(self%data, source=data_value) end subroutine init +!> @brief Setter for the data array +!> @param[in] data_value An array holding the data +subroutine set_data(self, data_value) + class(io_value_type), intent(inout) :: self + real(kind=r_def), intent(in) :: data_value(:) + + if (allocated(self%data)) then + deallocate(self%data) + end if + allocate(self%data, source=data_value) + +end subroutine set_data + +!> @brief Getter for the data array +!> @return An array holding the data +function get_data(self) result(data_value) + class(io_value_type), intent(in) :: self + + real(kind=r_def), dimension(1:size(self%data)) :: data_value + data_value = self%data + +end function get_data + !> @brief Sets the diagnostic write behaviour for io_value !> @param[in] write_behaviour Pointer to procedure implementing the write method subroutine set_write_behaviour(self, write_behaviour)