Skip to content

Commit

Permalink
+Add explicit interface for field_exists to MOM_io
Browse files Browse the repository at this point in the history
  Added an explicit interface for field_exists to MOM_io.F90, and added a new
optional argument of a MOM_domain_type to field_exists.  All answers are bitwise
identical, and all previous calls still work exactly as before, but there is a
new optional argument.
  • Loading branch information
Hallberg-NOAA committed Jan 10, 2021
1 parent d8806f4 commit 81a6ff8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/framework/MOM_io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ module MOM_io

use ensemble_manager_mod, only : get_ensemble_id
use fms_mod, only : write_version_number, open_namelist_file, check_nml_error
use fms_io_mod, only : file_exist, field_size, read_data
use fms_io_mod, only : field_exists=>field_exist, io_infra_end=>fms_io_exit
use fms_io_mod, only : get_filename_appendix=>get_filename_appendix
use fms_io_mod, only : file_exist, field_exist, field_size, read_data
use fms_io_mod, only : io_infra_end=>fms_io_exit, get_filename_appendix
use mpp_domains_mod, only : domain1d, domain2d, mpp_get_domain_components
use mpp_domains_mod, only : CENTER, CORNER, NORTH_FACE=>NORTH, EAST_FACE=>EAST
use mpp_io_mod, only : open_file => mpp_open, close_file => mpp_close
Expand Down Expand Up @@ -862,7 +861,7 @@ end function MOM_file_exists

!> Returns true if the named file or its domain-decomposed variant exists.
function FMS_file_exists(filename, domain, no_domain)
character(len=*), intent(in) :: filename !< The name of the file being inquired about
character(len=*), intent(in) :: filename !< The name of the file being inquired about
type(domain2d), optional, intent(in) :: domain !< The mpp domain2d that describes the decomposition
logical, optional, intent(in) :: no_domain !< This file does not use domain decomposition
! This function uses the fms_io function file_exist to determine whether
Expand All @@ -874,6 +873,23 @@ function FMS_file_exists(filename, domain, no_domain)

end function FMS_file_exists

!> Field_exists returns true if the field indicated by field_name is present in the
!! file file_name. If file_name does not exist, it returns false.
function field_exists(filename, field_name, domain, no_domain, MOM_domain)
character(len=*), intent(in) :: filename !< The name of the file being inquired about
character(len=*), intent(in) :: field_name !< The name of the field being sought
type(domain2d), target, optional, intent(in) :: domain !< A domain2d type that describes the decomposition
logical, optional, intent(in) :: no_domain !< This file does not use domain decomposition
type(MOM_domain_type), optional, intent(in) :: MOM_Domain !< A MOM_Domain that describes the decomposition
logical :: field_exists !< True if filename exists and field_name is in filename

if (present(MOM_domain)) then
field_exists = field_exist(filename, field_name, domain=MOM_domain%mpp_domain, no_domain=no_domain)
else
field_exists = field_exist(filename, field_name, domain=domain, no_domain=no_domain)
endif

end function field_exists

!> This function uses the fms_io function read_data to read a scalar
!! data field named "fieldname" from file "filename".
Expand Down
2 changes: 1 addition & 1 deletion src/parameterizations/lateral/MOM_tidal_forcing.F90
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ subroutine find_in_files(filenames, varname, array, G)

do nf=1,size(filenames)
if (LEN_TRIM(filenames(nf)) == 0) cycle
if (field_exists(filenames(nf), varname, G%Domain%mpp_domain)) then
if (field_exists(filenames(nf), varname, MOM_domain=G%Domain)) then
call MOM_read_data(filenames(nf), varname, array, G%Domain)
return
endif
Expand Down

0 comments on commit 81a6ff8

Please sign in to comment.