Skip to content

Commit

Permalink
+Add edge_axis argument to write_metadata_axis
Browse files Browse the repository at this point in the history
  Added a new optional logical argument to write_metadata_axis to indicate when
an axis is staggered at the edges of the tracer grid, and changed calls to
get_file_info to stop requesting the number of global attributes.  Also
eliminated some unused optional arguments to the FMS1 version of write_metadata
field.  All answers are bitwise identical, but there are minor changes to
some I/O related interfaces.
  • Loading branch information
Hallberg-NOAA committed Mar 18, 2021
1 parent ee0152f commit f89ddea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
33 changes: 14 additions & 19 deletions config_src/infra/FMS1/MOM_io_infra.F90
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,12 @@ subroutine get_filename_suffix(suffix)
end subroutine get_filename_suffix


!> Get information about the number of dimensions, variables, global attributes and time levels
!> Get information about the number of dimensions, variables and time levels
!! in the file associated with an open file unit
subroutine get_file_info(IO_handle, ndim, nvar, natt, ntime)
subroutine get_file_info(IO_handle, ndim, nvar, ntime)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for I/O
integer, optional, intent(out) :: ndim !< The number of dimensions in the file
integer, optional, intent(out) :: nvar !< The number of variables in the file
integer, optional, intent(out) :: natt !< The number of global attributes in the file
integer, optional, intent(out) :: ntime !< The number of time levels in the file

! Local variables
Expand All @@ -328,7 +327,6 @@ subroutine get_file_info(IO_handle, ndim, nvar, natt, ntime)

if (present(ndim)) ndim = ndims
if (present(nvar)) nvar = nvars
if (present(natt)) natt = natts
if (present(ntime)) ntime = ntimes

end subroutine get_file_info
Expand Down Expand Up @@ -683,7 +681,7 @@ subroutine write_field_4d(IO_handle, field_md, MOM_domain, field, tstamp, tile_c
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:,:,:), intent(inout) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field
integer, optional, intent(in) :: tile_count !< PEs per tile (default: 1)
real, optional, intent(in) :: fill_value !< Missing data fill value

Expand All @@ -697,7 +695,7 @@ subroutine write_field_3d(IO_handle, field_md, MOM_domain, field, tstamp, tile_c
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:,:), intent(inout) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field
integer, optional, intent(in) :: tile_count !< PEs per tile (default: 1)
real, optional, intent(in) :: fill_value !< Missing data fill value

Expand All @@ -711,7 +709,7 @@ subroutine write_field_2d(IO_handle, field_md, MOM_domain, field, tstamp, tile_c
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:), intent(inout) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field
integer, optional, intent(in) :: tile_count !< PEs per tile (default: 1)
real, optional, intent(in) :: fill_value !< Missing data fill value

Expand All @@ -724,7 +722,7 @@ subroutine write_field_1d(IO_handle, field_md, field, tstamp)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
real, dimension(:), intent(in) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field

call mpp_write(IO_handle%unit, field_md, field, tstamp=tstamp)
end subroutine write_field_1d
Expand All @@ -734,7 +732,7 @@ subroutine write_field_0d(IO_handle, field_md, field, tstamp)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
real, intent(in) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field

call mpp_write(IO_handle%unit, field_md, field, tstamp=tstamp)
end subroutine write_field_0d
Expand All @@ -750,7 +748,8 @@ end subroutine MOM_write_axis

!> Store information about an axis in a previously defined axistype and write this
!! information to the file indicated by unit.
subroutine write_metadata_axis(IO_handle, axis, name, units, longname, cartesian, sense, domain, data, calendar)
subroutine write_metadata_axis(IO_handle, axis, name, units, longname, cartesian, sense, domain, &
data, edge_axis, calendar)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(axistype), intent(inout) :: axis !< The axistype where this information is stored.
character(len=*), intent(in) :: name !< The name in the file of this axis
Expand All @@ -763,6 +762,7 @@ subroutine write_metadata_axis(IO_handle, axis, name, units, longname, cartesian
!! -1 if they increase downward.
type(domain1D), optional, intent(in) :: domain !< The domain decomposion for this axis
real, dimension(:), optional, intent(in) :: data !< The coordinate values of the points on this axis
logical, optional, intent(in) :: edge_axis !< If true, this axis marks an edge of the tracer cells
character(len=*), optional, intent(in) :: calendar !< The name of the calendar used with a time axis

call mpp_write_meta(IO_handle%unit, axis, name, units, longname, cartesian=cartesian, sense=sense, &
Expand All @@ -772,19 +772,13 @@ end subroutine write_metadata_axis
!> Store information about an output variable in a previously defined fieldtype and write this
!! information to the file indicated by unit.
subroutine write_metadata_field(IO_handle, field, axes, name, units, longname, &
min, max, fill, scale, add, pack, standard_name, checksum)
pack, standard_name, checksum)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(inout) :: field !< The fieldtype where this information is stored
type(axistype), dimension(:), intent(in) :: axes !< Handles for the axis used for this variable
character(len=*), intent(in) :: name !< The name in the file of this variable
character(len=*), intent(in) :: units !< The units of this variable
character(len=*), intent(in) :: longname !< The long description of this variable
real, optional, intent(in) :: min !< The minimum valid value for this variable
real, optional, intent(in) :: max !< The maximum valid value for this variable
real, optional, intent(in) :: fill !< Missing data fill value
real, optional, intent(in) :: scale !< An multiplicative factor by which to scale
!! the variable before output
real, optional, intent(in) :: add !< An offset to add to the variable before output
integer, optional, intent(in) :: pack !< A precision reduction factor with which the
!! variable. The default, 1, has no reduction,
!! but 2 is not uncommon.
Expand All @@ -793,8 +787,9 @@ subroutine write_metadata_field(IO_handle, field, axes, name, units, longname, &
optional, intent(in) :: checksum !< Checksum values that can be used to verify reads.


call mpp_write_meta(IO_handle%unit, field, axes, name, units, longname, min=min, max=max, &
fill=fill, scale=scale, add=add, pack=pack, standard_name=standard_name, checksum=checksum)
call mpp_write_meta(IO_handle%unit, field, axes, name, units, longname, &
pack=pack, standard_name=standard_name, checksum=checksum)
! unused opt. args: min=min, max=max, fill=fill, scale=scale, add=add, &

end subroutine write_metadata_field

Expand Down
14 changes: 8 additions & 6 deletions config_src/infra/FMS2/MOM_io_infra.F90
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ subroutine write_field_4d(IO_handle, field_md, MOM_domain, field, tstamp, tile_c
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:,:,:), intent(inout) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field
integer, optional, intent(in) :: tile_count !< PEs per tile (default: 1)
real, optional, intent(in) :: fill_value !< Missing data fill value

Expand All @@ -893,7 +893,7 @@ subroutine write_field_3d(IO_handle, field_md, MOM_domain, field, tstamp, tile_c
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:,:), intent(inout) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field
integer, optional, intent(in) :: tile_count !< PEs per tile (default: 1)
real, optional, intent(in) :: fill_value !< Missing data fill value

Expand All @@ -907,7 +907,7 @@ subroutine write_field_2d(IO_handle, field_md, MOM_domain, field, tstamp, tile_c
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:), intent(inout) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field
integer, optional, intent(in) :: tile_count !< PEs per tile (default: 1)
real, optional, intent(in) :: fill_value !< Missing data fill value

Expand All @@ -920,7 +920,7 @@ subroutine write_field_1d(IO_handle, field_md, field, tstamp)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
real, dimension(:), intent(in) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field

call mpp_write(IO_handle%unit, field_md, field, tstamp=tstamp)
end subroutine write_field_1d
Expand All @@ -930,7 +930,7 @@ subroutine write_field_0d(IO_handle, field_md, field, tstamp)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
real, intent(in) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
real, optional, intent(in) :: tstamp !< Model time of this field

call mpp_write(IO_handle%unit, field_md, field, tstamp=tstamp)
end subroutine write_field_0d
Expand All @@ -946,7 +946,8 @@ end subroutine MOM_write_axis

!> Store information about an axis in a previously defined axistype and write this
!! information to the file indicated by unit.
subroutine write_metadata_axis(IO_handle, axis, name, units, longname, cartesian, sense, domain, data, calendar)
subroutine write_metadata_axis(IO_handle, axis, name, units, longname, cartesian, sense, domain, data, &
edge_axis, calendar)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(axistype), intent(inout) :: axis !< The axistype where this information is stored.
character(len=*), intent(in) :: name !< The name in the file of this axis
Expand All @@ -959,6 +960,7 @@ subroutine write_metadata_axis(IO_handle, axis, name, units, longname, cartesian
!! -1 if they increase downward.
type(domain1D), optional, intent(in) :: domain !< The domain decomposion for this axis
real, dimension(:), optional, intent(in) :: data !< The coordinate values of the points on this axis
logical, optional, intent(in) :: edge_axis !< If true, this axis marks an edge of the tracer cells
character(len=*), optional, intent(in) :: calendar !< The name of the calendar used with a time axis

call mpp_write_meta(IO_handle%unit, axis, name, units, longname, cartesian=cartesian, sense=sense, &
Expand Down
18 changes: 9 additions & 9 deletions src/framework/MOM_io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ subroutine create_file(IO_handle, filename, vars, novars, fields, threading, tim

if (use_latq) &
call write_metadata(IO_handle, axis_latq, name="latq", units=y_axis_units, longname="Latitude", &
cartesian='Y', domain=y_domain, data=gridLatB(JsgB:JegB))
cartesian='Y', domain=y_domain, data=gridLatB(JsgB:JegB), edge_axis=.true.)

if (use_lonq) &
call write_metadata(IO_handle, axis_lonq, name="lonq", units=x_axis_units, longname="Longitude", &
cartesian='X', domain=x_domain, data=gridLonB(IsgB:IegB))
cartesian='X', domain=x_domain, data=gridLonB(IsgB:IegB), edge_axis=.true.)

if (use_layer) &
call write_metadata(IO_handle, axis_layer, name="Layer", units=trim(GV%zAxisUnits), &
Expand Down Expand Up @@ -383,7 +383,7 @@ subroutine reopen_file(IO_handle, filename, vars, novars, fields, threading, tim

type(MOM_domain_type), pointer :: Domain => NULL()
character(len=200) :: check_name, mesg
integer :: length, ndim, nvar, natt, ntime, thread
integer :: length, nvar, thread
logical :: exists, one_file, domain_set

thread = SINGLE_FILE
Expand Down Expand Up @@ -418,7 +418,7 @@ subroutine reopen_file(IO_handle, filename, vars, novars, fields, threading, tim
endif
if (.not.file_is_open(IO_handle)) return

call get_file_info(IO_handle, ndim, nvar, natt, ntime)
call get_file_info(IO_handle, nvar=nvar)

if (nvar == -1) then
write (mesg,*) "Reopening file ",trim(filename)," apparently had ",nvar,&
Expand Down Expand Up @@ -1343,7 +1343,7 @@ end subroutine query_vardesc
!> Write a 4d field to an output file, potentially with rotation
subroutine MOM_write_field_4d(IO_handle, field_md, MOM_domain, field, tstamp, tile_count, &
fill_value, turns, scale)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(file_type), intent(inout) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:,:,:), intent(inout) :: field !< Unrotated field to write
Expand Down Expand Up @@ -1378,7 +1378,7 @@ end subroutine MOM_write_field_4d
!> Write a 3d field to an output file, potentially with rotation
subroutine MOM_write_field_3d(IO_handle, field_md, MOM_domain, field, tstamp, tile_count, &
fill_value, turns, scale)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(file_type), intent(inout) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:,:), intent(inout) :: field !< Unrotated field to write
Expand Down Expand Up @@ -1413,7 +1413,7 @@ end subroutine MOM_write_field_3d
!> Write a 2d field to an output file, potentially with rotation
subroutine MOM_write_field_2d(IO_handle, field_md, MOM_domain, field, tstamp, tile_count, &
fill_value, turns, scale)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(file_type), intent(inout) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
type(MOM_domain_type), intent(in) :: MOM_domain !< The MOM_Domain that describes the decomposition
real, dimension(:,:), intent(inout) :: field !< Unrotated field to write
Expand Down Expand Up @@ -1447,7 +1447,7 @@ end subroutine MOM_write_field_2d

!> Write a 1d field to an output file
subroutine MOM_write_field_1d(IO_handle, field_md, field, tstamp, fill_value, scale)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(file_type), intent(inout) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
real, dimension(:), intent(in) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
Expand Down Expand Up @@ -1476,7 +1476,7 @@ end subroutine MOM_write_field_1d

!> Write a 0d field to an output file
subroutine MOM_write_field_0d(IO_handle, field_md, field, tstamp, fill_value, scale)
type(file_type), intent(in) :: IO_handle !< Handle for a file that is open for writing
type(file_type), intent(inout) :: IO_handle !< Handle for a file that is open for writing
type(fieldtype), intent(in) :: field_md !< Field type with metadata
real, intent(in) :: field !< Field to write
real, optional, intent(in) :: tstamp !< Model timestamp
Expand Down

0 comments on commit f89ddea

Please sign in to comment.