Skip to content

Commit f9372f3

Browse files
Hallberg-NOAAmarshallward
authored andcommitted
+Add get_netcdf_filename for a get_field_nc error
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.
1 parent 5e34f48 commit f9372f3

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/framework/MOM_io_file.F90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module MOM_io_file
3434
use MOM_netcdf, only : write_netcdf_attribute
3535
use MOM_netcdf, only : get_netcdf_size
3636
use MOM_netcdf, only : get_netcdf_fields
37+
use MOM_netcdf, only : get_netcdf_filename
3738
use MOM_netcdf, only : read_netcdf_field
3839

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

17631765
field_nc = handle%fields%get(label)
17641766

src/framework/MOM_netcdf.F90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module MOM_netcdf
3939
public :: write_netcdf_attribute
4040
public :: get_netcdf_size
4141
public :: get_netcdf_fields
42+
public :: get_netcdf_filename
4243
public :: read_netcdf_field
4344

4445

@@ -722,6 +723,14 @@ subroutine get_netcdf_fields(handle, axes, fields)
722723
fields(:) = vars(:nfields)
723724
end subroutine get_netcdf_fields
724725

726+
!> Return the name of a file from a netCDF handle
727+
function get_netcdf_filename(handle)
728+
type(netcdf_file_type), intent(in) :: handle !< A netCDF file handle
729+
character(len=:), allocatable :: get_netcdf_filename !< The name of the file that this handle refers to.
730+
731+
get_netcdf_filename = handle%filename
732+
733+
end function
725734

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

0 commit comments

Comments
 (0)