Skip to content

Commit

Permalink
revert changes to FMS1 infra
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Dussin authored and Raphael Dussin committed Sep 6, 2023
1 parent bb28144 commit 95cbc78
Showing 1 changed file with 24 additions and 74 deletions.
98 changes: 24 additions & 74 deletions config_src/infra/FMS1/MOM_io_infra.F90
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module MOM_io_infra
!> Read a data field from a file
interface read_field
module procedure read_field_4d
module procedure read_field_3d, read_field_3d_region
module procedure read_field_3d
module procedure read_field_2d, read_field_2d_region
module procedure read_field_1d, read_field_1d_int
module procedure read_field_0d, read_field_0d_int
Expand Down Expand Up @@ -696,50 +696,11 @@ subroutine read_field_3d(filename, fieldname, data, MOM_Domain, &
endif ; endif
end subroutine read_field_3d

!> This routine uses the fms_io subroutine read_data to read a region from a distributed or
!! global 3-D data field named "fieldname" from file "filename".
subroutine read_field_3d_region(filename, fieldname, data, start, nread, MOM_domain, &
no_domain, scale)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The variable name of the data in the file
real, dimension(:,:,:), intent(inout) :: data !< The 3-dimensional array into which the data
!! should be read
integer, dimension(:), intent(in) :: start !< The starting index to read in each of 4
!! dimensions. For this 3-d read, the
!! 4th values are always 1.
integer, dimension(:), intent(in) :: nread !< The number of points to read in each of 4
!! dimensions. For this 3-d read, the
!! 4th values are always 1.
type(MOM_domain_type), &
optional, intent(in) :: MOM_Domain !< The MOM_Domain that describes the decomposition
logical, optional, intent(in) :: no_domain !< If present and true, this variable does not
!! use domain decomposion.
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before it is returned.

if (present(MOM_Domain)) then
call read_data(filename, fieldname, data, start, nread, domain=MOM_Domain%mpp_domain, &
no_domain=no_domain)
else
call read_data(filename, fieldname, data, start, nread, no_domain=no_domain)
endif

if (present(scale)) then ; if (scale /= 1.0) then
if (present(MOM_Domain)) then
call rescale_comp_data(MOM_Domain, data, scale)
else
! Dangerously rescale the whole array
data(:,:,:) = scale*data(:,:,:)
endif
endif ; endif
end subroutine read_field_3d_region


!> This routine uses the fms_io subroutine read_data to read a distributed
!! 4-D data field named "fieldname" from file "filename". Valid values for
!! "position" include CORNER, CENTER, EAST_FACE and NORTH_FACE.
subroutine read_field_4d(filename, fieldname, data, MOM_Domain, &
timelevel, position, scale, global_file, file_may_be_4d)
timelevel, position, scale, global_file)
character(len=*), intent(in) :: filename !< The name of the file to read
character(len=*), intent(in) :: fieldname !< The variable name of the data in the file
real, dimension(:,:,:,:), intent(inout) :: data !< The 4-dimensional array into which the data
Expand All @@ -750,55 +711,44 @@ subroutine read_field_4d(filename, fieldname, data, MOM_Domain, &
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before it is returned.
logical, optional, intent(in) :: global_file !< If true, read from a single global file
logical, optional, intent(in) :: file_may_be_4d !< If true, this file may have 4-d arrays,
!! in which case a more elaborate set of calls
!! is needed to read it due to FMS limitations.

! Local variables
character(len=80) :: varname ! The name of a variable in the file
type(fieldtype), allocatable :: fields(:) ! An array of types describing all the variables in the file
logical :: use_fms_read_data, file_is_global
logical :: file_is_global
integer :: n, unit, ndim, nvar, natt, ntime

! This single call does not work for a 4-d array due to FMS limitations, so multiple calls are
! needed.
! call read_data(filename, fieldname, data, MOM_Domain%mpp_domain, &
! timelevel=timelevel, position=position)

use_fms_read_data = .true. ; if (present(file_may_be_4d)) use_fms_read_data = .not.file_may_be_4d
file_is_global = .true. ; if (present(global_file)) file_is_global = global_file

use_fms_read_data = .false. ! 4d arrays not working with FMS1

if (use_fms_read_data) then
call read_data(filename, fieldname, data, MOM_Domain%mpp_domain, &
timelevel=timelevel, position=position)
if (file_is_global) then
call mpp_open(unit, trim(filename), form=NETCDF_FILE, action=READONLY_FILE, &
threading=MULTIPLE, fileset=SINGLE_FILE) !, domain=MOM_Domain%mpp_domain )
else
if (file_is_global) then
call mpp_open(unit, trim(filename), form=NETCDF_FILE, action=READONLY_FILE, &
threading=MULTIPLE, fileset=SINGLE_FILE) !, domain=MOM_Domain%mpp_domain )
else
call mpp_open(unit, trim(filename), form=NETCDF_FILE, action=READONLY_FILE, &
threading=MULTIPLE, fileset=MULTIPLE, domain=MOM_Domain%mpp_domain )
call mpp_open(unit, trim(filename), form=NETCDF_FILE, action=READONLY_FILE, &
threading=MULTIPLE, fileset=MULTIPLE, domain=MOM_Domain%mpp_domain )
endif
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(fields(nvar))
call mpp_get_fields(unit, fields(1:nvar))
do n=1, nvar
call mpp_get_atts(fields(n), name=varname)
if (lowercase(trim(varname)) == lowercase(trim(fieldname))) then
call MOM_error(NOTE, "Reading 4-d variable "//trim(fieldname)//" from file "//trim(filename))
! Maybe something should be done depending on the value of ntime.
call mpp_read(unit, fields(n), MOM_Domain%mpp_domain, data, timelevel)
exit
endif
call mpp_get_info(unit, ndim, nvar, natt, ntime)
allocate(fields(nvar))
call mpp_get_fields(unit, fields(1:nvar))
do n=1, nvar
call mpp_get_atts(fields(n), name=varname)
if (lowercase(trim(varname)) == lowercase(trim(fieldname))) then
call MOM_error(NOTE, "Reading 4-d variable "//trim(fieldname)//" from file "//trim(filename))
! Maybe something should be done depending on the value of ntime.
call mpp_read(unit, fields(n), MOM_Domain%mpp_domain, data, timelevel)
exit
endif
enddo
if ((n == nvar+1) .or. (nvar < 1)) call MOM_error(WARNING, &
"read_field apparently did not find 4-d variable "//trim(fieldname)//" in file "//trim(filename))
enddo
if ((n == nvar+1) .or. (nvar < 1)) call MOM_error(WARNING, &
"read_field apparently did not find 4-d variable "//trim(fieldname)//" in file "//trim(filename))

deallocate(fields)
call mpp_close(unit)
endif
deallocate(fields)
call mpp_close(unit)

if (present(scale)) then ; if (scale /= 1.0) then
call rescale_comp_data(MOM_Domain, data, scale)
Expand Down

0 comments on commit 95cbc78

Please sign in to comment.