Skip to content

Commit

Permalink
+Add get_netcdf_filename for a get_field_nc error
Browse files Browse the repository at this point in the history
   Add get_netcdf_filename and use it to add useful details (the field and
filenames in question) to a fatal error message in get_field_nc.  All answers
are bitwise identical, but there is a new public interface and some output is
changed in cases where get_field_nc is failing.
  • Loading branch information
Hallberg-NOAA authored and marshallward committed Apr 2, 2024
1 parent 5e34f48 commit f9372f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/framework/MOM_io_file.F90
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module MOM_io_file
use MOM_netcdf, only : write_netcdf_attribute
use MOM_netcdf, only : get_netcdf_size
use MOM_netcdf, only : get_netcdf_fields
use MOM_netcdf, only : get_netcdf_filename
use MOM_netcdf, only : read_netcdf_field

use MOM_error_handler, only : MOM_error, FATAL
Expand Down Expand Up @@ -1757,8 +1758,9 @@ subroutine get_field_nc(handle, label, values, rescale)
! NOTE: Data on face and vertex points is not yet supported. This is a
! temporary check to detect such cases, but may be removed in the future.
if (.not. (compute_domain .or. data_domain)) &
call MOM_error(FATAL, 'get_field_nc: Only compute and data domains ' // &
'are currently supported.')
call MOM_error(FATAL, 'get_field_nc trying to read '//trim(label)//' from '//&
trim(get_netcdf_filename(handle%handle_nc))//&
': Only compute and data domains are currently supported.')

field_nc = handle%fields%get(label)

Expand Down
9 changes: 9 additions & 0 deletions src/framework/MOM_netcdf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module MOM_netcdf
public :: write_netcdf_attribute
public :: get_netcdf_size
public :: get_netcdf_fields
public :: get_netcdf_filename
public :: read_netcdf_field


Expand Down Expand Up @@ -722,6 +723,14 @@ subroutine get_netcdf_fields(handle, axes, fields)
fields(:) = vars(:nfields)
end subroutine get_netcdf_fields

!> Return the name of a file from a netCDF handle
function get_netcdf_filename(handle)
type(netcdf_file_type), intent(in) :: handle !< A netCDF file handle
character(len=:), allocatable :: get_netcdf_filename !< The name of the file that this handle refers to.

get_netcdf_filename = handle%filename

end function

!> Read the values of a field from a netCDF file
subroutine read_netcdf_field(handle, field, values, bounds)
Expand Down

0 comments on commit f9372f3

Please sign in to comment.