Skip to content
93 changes: 93 additions & 0 deletions src/framework/mpas_stream_manager.F
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,103 @@ subroutine MPAS_stream_mgr_validate_streams(manager, streamID, ierr)!{{{
#endif

end do

! Only check filename_template uniqueness when validating all streams
if (.not. present(streamID)) then
call MPAS_stream_mgr_check_filename_template(manager, ierr=err_local)
Comment thread
mgduda marked this conversation as resolved.
end if

end subroutine MPAS_stream_mgr_validate_streams!}}}



!-----------------------------------------------------------------------
! routine MPAS_stream_mgr_check_filename_template
!
!> \brief Check for identical filename templates in active output streams.
!> \author Abishek Gopal
!> \date June 3 2026
!> \details
!> Checks that there are no identical filename templates among active output
!> streams in the stream manager, which may lead to file conflicts. This
!> routine can be called from within MPAS_stream_mgr_validate_streams or
!> separately as needed.
!
!-----------------------------------------------------------------------
subroutine MPAS_stream_mgr_check_filename_template(manager, ierr)!{{{

implicit none

type (MPAS_streamManager_type), intent(inout) :: manager
integer, intent(out), optional :: ierr
Comment thread
mgduda marked this conversation as resolved.

character(len=StrKIND) :: stream1_name, stream2_name, stream1_filename, stream2_filename
character(len=StrKIND) :: filename_interval
Comment thread
mgduda marked this conversation as resolved.
Outdated
integer :: threadNum, err_local
character (len=StrKIND) :: message, streamID
type (MPAS_stream_list_type), pointer :: stream1_cursor, stream2_cursor

logical :: stream1_active, stream2_active, stream1_pkg_active, stream2_pkg_active
logical :: stream1_output, stream2_output

STREAM_DEBUG_WRITE('-- Called MPAS_stream_mgr_check_filename_template() for all streams')

threadNum = mpas_threading_get_thread_num()

if ( threadNum == 0 ) then

streamID = '.*' ! query all streams

nullify(stream1_cursor)
do while (MPAS_stream_list_query(manager % streams, streamID, stream1_cursor, ierr=err_local))

stream1_name = stream1_cursor % name
stream1_active = stream1_cursor % active_stream
stream1_filename = stream1_cursor % filename_template
stream1_pkg_active = stream_active_pkg_check(stream1_cursor)
stream1_output = (stream1_cursor % direction == MPAS_STREAM_OUTPUT) .or. &
(stream1_cursor % direction == MPAS_STREAM_INPUT_OUTPUT)

call mpas_log_write('Stream 1 '//trim(stream1_name)//' filename '//trim(stream1_filename)//' &
active = $l output = $l packages_active $l',logicArgs=(/stream1_active, stream1_output, stream1_pkg_active/))
Comment thread
mgduda marked this conversation as resolved.
Outdated

if ( stream1_active .and. stream1_output .and. stream1_pkg_active) then
Comment thread
mgduda marked this conversation as resolved.
Outdated

nullify(stream2_cursor)
do while (MPAS_stream_list_query(manager % streams, streamID, stream2_cursor, ierr=err_local))

stream2_name = stream2_cursor % name
stream2_active = stream2_cursor % active_stream
stream2_pkg_active = stream_active_pkg_check(stream2_cursor)
stream2_output = (stream2_cursor % direction == MPAS_STREAM_OUTPUT) .or. &
(stream2_cursor % direction == MPAS_STREAM_INPUT_OUTPUT)

! uniqueness_check has already checked that two different streams do not have the same name
if ( trim(stream1_name) /= trim(stream2_name) .and. stream2_active .and. stream2_output .and. stream2_pkg_active) then

stream2_filename = stream2_cursor % filename_template
call mpas_log_write('Stream 2 '//trim(stream2_name)//' filename '//trim(stream2_filename)//' &
active = $l output = $l pkg_active: $l',logicArgs=(/stream2_active, stream2_output, stream2_pkg_active/))
Comment thread
mgduda marked this conversation as resolved.
Outdated

if ( trim(stream1_filename) == trim(stream2_filename) ) then
message = 'Found identical values of the filename_template attribute for multiple active output streams &
(' // trim(stream1_name) // ' and ' // trim(stream2_name) // ') in streams.<CORE>. This may &
result in file conflicts.'
Comment thread
mgduda marked this conversation as resolved.
Outdated
call mpas_log_write(message, MPAS_LOG_CRIT)
end if

end if
end do

end if

end do

end if


end subroutine MPAS_stream_mgr_check_filename_template!}}}

!-----------------------------------------------------------------------
! routine MPAS_stream_mgr_destroy_stream
!
Expand Down
7 changes: 0 additions & 7 deletions src/framework/xml_stream_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,6 @@ int uniqueness_check(ezxml_t stream1, ezxml_t stream2)
fmt_err(msgbuf);
return 1;
}
if (strstr(type, "output") != NULL || strstr(type2, "output") != NULL){
if (strcmp(filename, filename2) == 0) {
snprintf(msgbuf, MSGSIZE, "Output streams \"%s\" and \"%s\" cannot share the filename_template \"%s\".", name, name2, filename);
fmt_err(msgbuf);
return 1;
}
}
}

return 0;
Expand Down