Skip to content

Commit

Permalink
+Enhanced support for novel axes in MOM_io
Browse files Browse the repository at this point in the history
  Added support for new IO capabilities that are needed by SIS2 to use the MOM6
framework and infrastructure code, but should also be useful within MOM6
itself.  These new capabilities include writing global attributes to files,
using create_file named axes that are not derived from a MOM6 grid type, and new
options and elements in the vardesc type to support a wider array of axes and to
provide the position of the grid staggering via an integer position variable
instead of the short character strings that had been used.

  As a part of this commit, there are the new opaques type axis_info and
attribute_info, and the new routines set_axis_info, delete_axis_info,
set_attribute_info and delete_attribute_info to facilitate these new
capabilities, as well as the publicly visible function position_from_horgrid to
translate the vardesc%hor_grid character strings into the integer position flag
used elsewhere in the MOM6 and FMS codes.  Within the MOM_io_infra, there is a
new variant of the overloaded interface write_meta to handle writing global
attributes. There are also two new optional arguments to create_file and
reopen_file, and two new optional arguments to var_desc, modify_vardesc, and
query_vardesc.  All answers and output are bitwise identical.
  • Loading branch information
Hallberg-NOAA committed Apr 9, 2021
1 parent 7ec08cd commit 03b997b
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 74 deletions.
11 changes: 10 additions & 1 deletion config_src/infra/FMS1/MOM_io_infra.F90
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module MOM_io_infra

!> Write metadata about a variable or axis to a file and store it for later reuse
interface write_metadata
module procedure write_metadata_axis, write_metadata_field
module procedure write_metadata_axis, write_metadata_field, write_metadata_global
end interface write_metadata

!> Close a file (or fileset). If the file handle does not point to an open file,
Expand Down Expand Up @@ -793,4 +793,13 @@ subroutine write_metadata_field(IO_handle, field, axes, name, units, longname, &

end subroutine write_metadata_field

!> Write a global text attribute to a file.
subroutine write_metadata_global(IO_handle, name, attribute)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
character(len=*), intent(in) :: name !< The name in the file of this global attribute
character(len=*), intent(in) :: attribute !< The value of this attribute

call mpp_write_meta(IO_handle%unit, name, cval=attribute)
end subroutine write_metadata_global

end module MOM_io_infra
20 changes: 17 additions & 3 deletions config_src/infra/FMS2/MOM_io_infra.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module MOM_io_infra
use fms2_io_mod, only : FmsNetcdfDomainFile_t, FmsNetcdfFile_t, fms2_read_data => read_data
use fms2_io_mod, only : get_unlimited_dimension_name, get_num_dimensions, get_num_variables
use fms2_io_mod, only : get_variable_names, variable_exists, get_variable_size, get_variable_units
use fms2_io_mod, only : register_field, write_data, register_variable_attribute
use fms2_io_mod, only : register_field, write_data, register_variable_attribute, register_global_attribute
use fms2_io_mod, only : variable_att_exists, get_variable_attribute, get_variable_num_dimensions
use fms2_io_mod, only : get_variable_dimension_names, is_dimension_registered, get_dimension_size
use fms2_io_mod, only : is_dimension_unlimited, register_axis, unlimited
Expand Down Expand Up @@ -90,7 +90,7 @@ module MOM_io_infra

!> Write metadata about a variable or axis to a file and store it for later reuse
interface write_metadata
module procedure write_metadata_axis, write_metadata_field
module procedure write_metadata_axis, write_metadata_field, write_metadata_global
end interface write_metadata

!> Close a file (or fileset). If the file handle does not point to an open file,
Expand Down Expand Up @@ -1779,7 +1779,7 @@ subroutine write_metadata_axis(IO_handle, axis, name, units, longname, cartesian
endif

axis%name = trim(name)
if (present(data) .and. allocated(axis%ax_data)) call MOM_error(FATAL, &
if (present(data) .and. allocated(axis%ax_data)) call MOM_error(FATAL, &
"Data is already allocated in a call to write_metadata_axis for axis "//&
trim(name)//" in file "//trim(IO_handle%filename))

Expand Down Expand Up @@ -1920,4 +1920,18 @@ subroutine write_metadata_field(IO_handle, field, axes, name, units, longname, &

end subroutine write_metadata_field

!> Write a global text attribute to a file.
subroutine write_metadata_global(IO_handle, name, attribute)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
character(len=*), intent(in) :: name !< The name in the file of this global attribute
character(len=*), intent(in) :: attribute !< The value of this attribute

if (IO_handle%FMS2_file) then
call register_global_attribute(IO_handle%fileobj, name, attribute, len_trim(attribute))
else
call mpp_write_meta(IO_handle%unit, name, cval=attribute)
endif

end subroutine write_metadata_global

end module MOM_io_infra
Loading

0 comments on commit 03b997b

Please sign in to comment.