diff --git a/src/driver/mpas_subdriver.F b/src/driver/mpas_subdriver.F index 90217ad80d1c..d404c0934ca0 100644 --- a/src/driver/mpas_subdriver.F +++ b/src/driver/mpas_subdriver.F @@ -44,7 +44,7 @@ module mpas_subdriver subroutine mpas_init() - use mpas_stream_manager, only : MPAS_stream_mgr_init, MPAS_build_stream_filename + use mpas_stream_manager, only : MPAS_stream_mgr_init, MPAS_build_stream_filename, MPAS_stream_mgr_validate_streams use iso_c_binding, only : c_char, c_loc, c_ptr, c_int use mpas_c_interfacing, only : mpas_f_to_c_string, mpas_c_to_f_string use mpas_timekeeping, only : mpas_get_clock_time, mpas_get_time @@ -311,6 +311,15 @@ end subroutine xml_stream_get_attributes call mpas_dmpar_abort(domain_ptr % dminfo) end if + ! + ! Validate streams after set-up + ! + call mpas_log_write(' ** Validating streams') + call MPAS_stream_mgr_validate_streams(domain_ptr % streamManager, ierr = ierr) + if ( ierr /= MPAS_STREAM_MGR_NOERR ) then + call mpas_dmpar_global_abort('ERROR: Validation of streams failed for core ' // trim(domain_ptr % core % coreName)) + end if + ! ! Finalize the setup of blocks and fields ! diff --git a/src/framework/mpas_stream_manager.F b/src/framework/mpas_stream_manager.F index b77050a9c5d0..2f5716dbfe80 100644 --- a/src/framework/mpas_stream_manager.F +++ b/src/framework/mpas_stream_manager.F @@ -20,6 +20,7 @@ module mpas_stream_manager public :: MPAS_stream_mgr_init, & MPAS_stream_mgr_finalize, & MPAS_stream_mgr_create_stream, & + MPAS_stream_mgr_validate_streams, & MPAS_stream_mgr_destroy_stream, & MPAS_stream_mgr_get_clock, & MPAS_stream_mgr_set_property, & @@ -412,6 +413,112 @@ subroutine MPAS_stream_mgr_create_stream(manager, streamID, direction, filename, end subroutine MPAS_stream_mgr_create_stream!}}} + !----------------------------------------------------------------------- + ! routine MPAS_stream_mgr_validate_streams + ! + !> \brief Validate all streams or one stream, if optional argument streamID is present. + !> \author Dom Heinzeller + !> \date 12 September 2017 + !> \details + !> Validates all streams of a stream manager, or one stream if optional argument + !> streamID is specified. A low-level validation of streams happens within + !> xml_stream_parser in xml_stream_parser.c (e.g. immutable streams must not be + !> specified as mutable streams etc.). MPAS_stream_mgr_validate_streams performs + !> higher-level checks that should stay separate from the low-level checks and + !> that may require additional logic or settings not necessarily present when + !> calling xml_stream_parser. + ! + !----------------------------------------------------------------------- + subroutine MPAS_stream_mgr_validate_streams(manager, streamID, ierr)!{{{ + + implicit none + + type (MPAS_streamManager_type), intent(inout) :: manager + character (len=*), intent(in), optional :: streamID + integer, intent(out), optional :: ierr + + character(len=StrKIND) :: stream_name + character(len=StrKIND) :: filename_interval + integer :: direction, io_type + character (len=StrKIND) :: message + integer :: err_local + + ! For future validation of SIONlib data - need to check that there is only one timestamp per file + type (MPAS_TimeInterval_type) :: time_interval_zero, time_interval_file, time_interval_input, time_interval_output + + if (present(streamID)) then + STREAM_DEBUG_WRITE('-- Called MPAS_stream_mgr_validate_streams() for '//trim(streamID)) + else + STREAM_DEBUG_WRITE('-- Called MPAS_stream_mgr_validate_streams() for all streams') + end if + + if (present(ierr)) ierr = MPAS_STREAM_MGR_NOERR + call mpas_set_timeInterval(time_interval_zero, dt = 0.0) + + if (present(streamID)) then + call MPAS_stream_mgr_begin_iteration(manager, streamID, ierr=err_local) + if (err_local .eq. MPAS_STREAM_MGR_ERROR) then + if (present(ierr)) ierr = MPAS_STREAM_MGR_ERROR + return + end if + end if + + call MPAS_stream_mgr_begin_iteration(manager) + do while (MPAS_stream_mgr_get_next_stream(manager, streamID = stream_name, directionProperty = direction, & + filenameIntervalProperty = filename_interval)) + if (present(streamID)) then + if (trim(streamID) .ne. trim(stream_name)) cycle + end if + STREAM_DEBUG_WRITE('-- Validating stream '//trim(stream_name)) + call MPAS_stream_mgr_get_property(manager, stream_name, MPAS_STREAM_PROPERTY_IOTYPE, io_type) + +#if 0 + ! Placeholder for testing additional consistency checks for future SIONlib implementation, + ! and demo of how to use MPAS_stream_mgr_get_stream_interval for directions input/output. + if (io_type == MPAS_IO_SIONLIB) then + + if (trim(filename_interval) /= 'none') then + call mpas_set_timeInterval(time_interval_file, timeString=filename_interval) + else + call mpas_set_timeInterval(time_interval_file, dt = 0.0) + end if + + if (direction == MPAS_STREAM_INPUT .or. direction == MPAS_STREAM_INPUT_OUTPUT) then + time_interval_input = MPAS_stream_mgr_get_stream_interval(manager, stream_name, MPAS_STREAM_INPUT, err_local) + if (err_local /= MPAS_STREAM_MGR_NOERR) then + if (present(ierr)) ierr = MPAS_STREAM_MGR_ERROR + return + end if + if (time_interval_input .gt. time_interval_zero) then + if ( (time_interval_file .eq. time_interval_zero) .or. (time_interval_file .gt. time_interval_input) ) then + message = 'Filename interval is larger than input interval for SIONlib stream ''' // trim(stream_name) //''' (only one time stamp per file allowed).' + call mpas_log_write(message, MPAS_LOG_CRIT) + end if + end if + end if + + if (direction == MPAS_STREAM_OUTPUT .or. direction == MPAS_STREAM_INPUT_OUTPUT) then + time_interval_output = MPAS_stream_mgr_get_stream_interval(manager, stream_name, MPAS_STREAM_OUTPUT, err_local) + if (err_local /= MPAS_STREAM_MGR_NOERR) then + if (present(ierr)) ierr = MPAS_STREAM_MGR_ERROR + return + end if + if (time_interval_output .gt. time_interval_zero) then + if ( (time_interval_file .eq. time_interval_zero) .or. (time_interval_file .gt. time_interval_output) ) then + message = 'Filename interval is larger than output interval for SIONlib stream ''' // trim(stream_name) //''' (only one time stamp per file allowed).' + call mpas_log_write(message, MPAS_LOG_CRIT) + end if + end if + end if + + end if +#endif + + end do + + end subroutine MPAS_stream_mgr_validate_streams!}}} + + !----------------------------------------------------------------------- ! routine MPAS_stream_mgr_destroy_stream !