Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions diag_manager/fms_diag_file_object.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1304,10 +1304,12 @@ subroutine write_global_metadata(this)
character (len=MAX_STR_LEN), allocatable :: yaml_file_attributes(:,:) !< Global attributes defined in the yaml

type(diagYamlFiles_type), pointer :: diag_file_yaml !< The diag_file yaml
character(len=MAX_STR_LEN) :: title !< The title as read in from the diag table yaml

diag_file_yaml => this%FMS_diag_file%diag_yaml_file
fms2io_fileobj => this%FMS_diag_file%fms2io_fileobj

!! Write out the global attributes defined in the diag table yaml
if (diag_file_yaml%has_file_global_meta()) then
yaml_file_attributes = diag_file_yaml%get_file_global_meta()
do i = 1, size(yaml_file_attributes,1)
Expand All @@ -1316,6 +1318,12 @@ subroutine write_global_metadata(this)
enddo
deallocate(yaml_file_attributes)
endif

!! Write out the 'title' global attribute
title = diag_yaml%get_title()
call register_global_attribute(fms2io_fileobj, 'title', trim(title), &
str_len=len_trim(title))

end subroutine write_global_metadata

!< @brief Writes a variable's metadata in the netcdf file
Expand Down
21 changes: 20 additions & 1 deletion test_fms/diag_manager/check_time_none.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
!> @brief Checks the output file after running test_reduction_methods using the "none" reduction method
program check_time_none
use fms_mod, only: fms_init, fms_end, string
use fms2_io_mod, only: FmsNetcdfFile_t, read_data, close_file, open_file, get_dimension_size
use fms2_io_mod, only: FmsNetcdfFile_t, read_data, close_file, open_file, get_dimension_size, &
get_global_attribute
use mpp_mod, only: mpp_npes, mpp_error, FATAL, mpp_pe, input_nml_file
use platform_mod, only: r4_kind, r8_kind
use testing_utils, only: allocate_buffer, test_normal, test_openmp, test_halos, no_mask, logical_mask, real_mask
Expand Down Expand Up @@ -61,12 +62,15 @@ program check_time_none

if (.not. open_file(fileobj, "test_none.nc", "read")) &
call mpp_error(FATAL, "unable to open test_none.nc")
call check_global_attribute(fileobj)

if (.not. open_file(fileobj1, "test_none_regional.nc.0004", "read")) &
call mpp_error(FATAL, "unable to open test_none_regional.nc.0004")
call check_global_attribute(fileobj)

if (.not. open_file(fileobj2, "test_none_regional.nc.0005", "read")) &
call mpp_error(FATAL, "unable to open test_none_regional.nc.0005")
call check_global_attribute(fileobj)

print *, "Checking the dimensions of the subaxis"
! This is only done for the "none" reduction because the logic that determines the subaxis
Expand Down Expand Up @@ -231,4 +235,19 @@ subroutine check_data_3d(buffer, time_level, is_regional, nx_offset, ny_offset,
enddo
enddo
end subroutine check_data_3d

!< @brief Check if the global attribute is the expected value
subroutine check_global_attribute(fileobj)
type(FmsNetcdfFile_t), intent(in) :: fileobj

character(len=100) :: attribute_value
character(len=100) :: EXPECTED_ATTRIBUTE_VALUE

EXPECTED_ATTRIBUTE_VALUE = "test_none"
call get_global_attribute(fileobj, "title", attribute_value)
if (trim(attribute_value) .ne. trim(EXPECTED_ATTRIBUTE_VALUE)) then
call mpp_error(FATAL, "The global attribute 'title' is not present in the file.")
endif
end subroutine

end program
Loading