Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+Cleanup of framework module use and wrapping #1280

Merged
merged 7 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/MOM_dynamics_split_RK2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module MOM_dynamics_split_RK2
use MOM_error_handler, only : callTree_enter, callTree_leave, callTree_waypoint
use MOM_file_parser, only : get_param, log_version, param_file_type
use MOM_get_input, only : directories
use MOM_io, only : MOM_io_init, vardesc, var_desc
use MOM_io, only : vardesc, var_desc
use MOM_restart, only : register_restart_field, register_restart_pair
use MOM_restart, only : query_initialized, save_restart
use MOM_restart, only : restart_init, is_new_run, MOM_restart_CS
Expand Down
1 change: 0 additions & 1 deletion src/core/MOM_dynamics_unsplit.F90
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ module MOM_dynamics_unsplit
use MOM_error_handler, only : MOM_error, MOM_mesg, FATAL, WARNING, is_root_pe
use MOM_file_parser, only : get_param, log_version, param_file_type
use MOM_get_input, only : directories
use MOM_io, only : MOM_io_init
use MOM_restart, only : register_restart_field, query_initialized, save_restart
use MOM_restart, only : restart_init, MOM_restart_CS
use MOM_time_manager, only : time_type, real_to_time, operator(+)
Expand Down
1 change: 0 additions & 1 deletion src/core/MOM_dynamics_unsplit_RK2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ module MOM_dynamics_unsplit_RK2
use MOM_error_handler, only : MOM_set_verbosity
use MOM_file_parser, only : get_param, log_version, param_file_type
use MOM_get_input, only : directories
use MOM_io, only : MOM_io_init
use MOM_restart, only : register_restart_field, query_initialized, save_restart
use MOM_restart, only : restart_init, MOM_restart_CS
use MOM_time_manager, only : time_type, time_type_to_real, operator(+)
Expand Down
23 changes: 10 additions & 13 deletions src/core/MOM_open_boundary.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ module MOM_open_boundary

use MOM_array_transform, only : rotate_array, rotate_array_pair
use MOM_array_transform, only : allocate_rotated_array
use MOM_coms, only : sum_across_PEs
use MOM_coms, only : sum_across_PEs, Set_PElist, Get_PElist, PE_here, num_PEs
use MOM_cpu_clock, only : cpu_clock_id, cpu_clock_begin, cpu_clock_end, CLOCK_ROUTINE
use MOM_diag_mediator, only : diag_ctrl, time_type
use MOM_domains, only : pass_var, pass_vector
use MOM_domains, only : To_All, SCALAR_PAIR, CGRID_NE, CORNER
use MOM_error_handler, only : MOM_mesg, MOM_error, FATAL, WARNING, is_root_pe
use MOM_error_handler, only : NOTE
use MOM_error_handler, only : MOM_mesg, MOM_error, FATAL, WARNING, NOTE, is_root_pe
use MOM_file_parser, only : get_param, log_version, param_file_type, log_param
use MOM_grid, only : ocean_grid_type, hor_index_type
use MOM_dyn_horgrid, only : dyn_horgrid_type
Expand Down Expand Up @@ -651,13 +650,11 @@ end subroutine open_boundary_config
!> Allocate space for reading OBC data from files. It sets up the required vertical
!! remapping. In the process, it does funky stuff with the MPI processes.
subroutine initialize_segment_data(G, OBC, PF)
use mpp_mod, only : mpp_pe, mpp_set_current_pelist, mpp_get_current_pelist,mpp_npes

type(ocean_grid_type), intent(in) :: G !< Ocean grid structure
type(ocean_OBC_type), intent(inout) :: OBC !< Open boundary control structure
type(param_file_type), intent(in) :: PF !< Parameter file handle
type(ocean_OBC_type), intent(inout) :: OBC !< Open boundary control structure
type(param_file_type), intent(in) :: PF !< Parameter file handle

integer :: n,m,num_fields
integer :: n, m, num_fields
character(len=1024) :: segstr
character(len=256) :: filename
character(len=20) :: segnam, suffix
Expand Down Expand Up @@ -697,11 +694,11 @@ subroutine initialize_segment_data(G, OBC, PF)

!< temporarily disable communication in order to read segment data independently

allocate(saved_pelist(0:mpp_npes()-1))
call mpp_get_current_pelist(saved_pelist)
current_pe = mpp_pe()
allocate(saved_pelist(0:num_PEs()-1))
call Get_PElist(saved_pelist)
current_pe = PE_here()
single_pelist(1) = current_pe
call mpp_set_current_pelist(single_pelist)
call Set_PElist(single_pelist)

do n=1, OBC%number_of_segments
segment => OBC%segment(n)
Expand Down Expand Up @@ -955,7 +952,7 @@ subroutine initialize_segment_data(G, OBC, PF)
endif
enddo

call mpp_set_current_pelist(saved_pelist)
call Set_PElist(saved_pelist)

end subroutine initialize_segment_data

Expand Down
1 change: 0 additions & 1 deletion src/framework/MOM_diag_remap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ module MOM_diag_remap
use coord_sigma, only : build_sigma_column
use coord_rho, only : build_rho_column

use diag_axis_mod, only : get_diag_axis_name
use diag_manager_mod, only : diag_axis_init

use MOM_debugging, only : check_column_integrals
Expand Down
11 changes: 4 additions & 7 deletions src/framework/MOM_horizontal_regridding.F90
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ module MOM_horizontal_regridding
use MOM_time_manager, only : get_external_field_axes, get_external_field_missing
use MOM_transform_FMS, only : time_interp_external => rotated_time_interp_external
use MOM_variables, only : thermo_var_ptrs
use mpp_io_mod, only : axistype
use mpp_domains_mod, only : mpp_global_field, mpp_get_compute_domain
use mpp_mod, only : mpp_broadcast,mpp_root_pe,mpp_sync,mpp_sync_self
use mpp_mod, only : mpp_max
use horiz_interp_mod, only : horiz_interp_new, horiz_interp,horiz_interp_type

use mpp_io_mod, only : axistype, mpp_get_axis_data
use mpp_mod, only : mpp_broadcast, mpp_sync, mpp_sync_self, mpp_max
use horiz_interp_mod, only : horiz_interp_new, horiz_interp, horiz_interp_type
use horiz_interp_mod, only : horiz_interp_init, horiz_interp_del

use mpp_io_mod, only : mpp_get_axis_data
use mpp_io_mod, only : MPP_SINGLE
use netcdf

implicit none ; private
Expand Down
78 changes: 57 additions & 21 deletions src/framework/MOM_io.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ 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 : field_exists=>field_exist, io_infra_end=>fms_io_exit
use fms_io_mod, only : get_filename_appendix=>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
use mpp_io_mod, only : mpp_write_meta, write_field => mpp_write, mpp_get_info
use mpp_io_mod, only : mpp_get_atts, mpp_get_axes, get_axis_data=>mpp_get_axis_data, axistype
use mpp_io_mod, only : mpp_get_fields, fieldtype, axistype, flush_file => mpp_flush
use mpp_io_mod, only : mpp_write_meta, write_field => mpp_write
use mpp_io_mod, only : mpp_get_atts, mpp_attribute_exist
use mpp_io_mod, only : mpp_get_axes, axistype, get_axis_data=>mpp_get_axis_data
use mpp_io_mod, only : mpp_get_fields, fieldtype, flush_file=>mpp_flush
use mpp_io_mod, only : APPEND_FILE=>MPP_APPEND, ASCII_FILE=>MPP_ASCII
use mpp_io_mod, only : MULTIPLE=>MPP_MULTI, NETCDF_FILE=>MPP_NETCDF
use mpp_io_mod, only : OVERWRITE_FILE=>MPP_OVERWR, READONLY_FILE=>MPP_RDONLY
use mpp_io_mod, only : SINGLE_FILE=>MPP_SINGLE, WRITEONLY_FILE=>MPP_WRONLY
use mpp_io_mod, only : MPP_APPEND, MPP_MULTI, MPP_OVERWR, MPP_NETCDF, MPP_RDONLY
use mpp_io_mod, only : get_file_info=>mpp_get_info, get_file_atts=>mpp_get_atts
use mpp_io_mod, only : get_file_fields=>mpp_get_fields, get_file_times=>mpp_get_times
use mpp_io_mod, only : io_infra_init=>mpp_io_init
Expand All @@ -40,7 +40,7 @@ module MOM_io

public :: close_file, create_file, field_exists, field_size, fieldtype, get_filename_appendix
public :: file_exists, flush_file, get_file_info, get_file_atts, get_file_fields
public :: get_file_times, open_file, read_axis_data, read_data
public :: get_file_times, open_file, read_axis_data, read_data, read_field_chksum
public :: num_timelevels, MOM_read_data, MOM_read_vector, ensembler
public :: reopen_file, slasher, write_field, write_version_number, MOM_io_init
public :: open_namelist_file, check_nml_error, io_infra_init, io_infra_end
Expand Down Expand Up @@ -77,6 +77,7 @@ module MOM_io
module procedure MOM_read_data_3d
module procedure MOM_read_data_2d
module procedure MOM_read_data_1d
module procedure MOM_read_data_0d
end interface

!> Read a pair of data fields representing the two components of a vector from a file
Expand Down Expand Up @@ -162,9 +163,9 @@ subroutine create_file(unit, filename, vars, novars, fields, threading, timeunit
if (domain_set) one_file = (thread == SINGLE_FILE)

if (one_file) then
call open_file(unit, filename, MPP_OVERWR, MPP_NETCDF, threading=thread)
call open_file(unit, filename, OVERWRITE_FILE, NETCDF_FILE, threading=thread)
else
call open_file(unit, filename, MPP_OVERWR, MPP_NETCDF, domain=Domain%mpp_domain)
call open_file(unit, filename, OVERWRITE_FILE, NETCDF_FILE, domain=Domain%mpp_domain)
endif

! Define the coordinates.
Expand Down Expand Up @@ -404,13 +405,13 @@ subroutine reopen_file(unit, filename, vars, novars, fields, threading, timeunit
if (domain_set) one_file = (thread == SINGLE_FILE)

if (one_file) then
call open_file(unit, filename, MPP_APPEND, MPP_NETCDF, threading=thread)
call open_file(unit, filename, APPEND_FILE, NETCDF_FILE, threading=thread)
else
call open_file(unit, filename, MPP_APPEND, MPP_NETCDF, domain=Domain%mpp_domain)
call open_file(unit, filename, APPEND_FILE, NETCDF_FILE, domain=Domain%mpp_domain)
endif
if (unit < 0) return

call mpp_get_info(unit, ndim, nvar, natt, ntime)
call get_file_info(unit, ndim, nvar, natt, ntime)

if (nvar == -1) then
write (mesg,*) "Reopening file ",trim(filename)," apparently had ",nvar,&
Expand Down Expand Up @@ -449,11 +450,11 @@ subroutine read_axis_data(filename, axis_name, var)
type(axistype) :: time_axis
character(len=32) :: name, units

call open_file(unit, trim(filename), action=MPP_RDONLY, form=MPP_NETCDF, &
threading=MPP_MULTI, fileset=SINGLE_FILE)
call open_file(unit, trim(filename), action=READONLY_FILE, form=NETCDF_FILE, &
threading=MULTIPLE, fileset=SINGLE_FILE)

!Find the number of variables (nvar) in this file
call mpp_get_info(unit, ndim, nvar, natt, ntime)
call get_file_info(unit, ndim, nvar, natt, ntime)
! -------------------------------------------------------------------
! Allocate space for the number of axes in the data file.
! -------------------------------------------------------------------
Expand All @@ -462,7 +463,7 @@ subroutine read_axis_data(filename, axis_name, var)

axis_found = .false.
do i = 1, ndim
call mpp_get_atts(axes(i), name=name,len=len,units=units)
call get_file_atts(axes(i), name=name, len=len, units=units)
if (name == axis_name) then
axis_found = .true.
call get_axis_data(axes(i),var)
Expand All @@ -477,6 +478,23 @@ subroutine read_axis_data(filename, axis_name, var)

end subroutine read_axis_data

subroutine read_field_chksum(field, chksum, valid_chksum)
type(fieldtype), intent(in) :: field !< The field whose checksum attribute is to be read.
integer(kind=8), intent(out) :: chksum !< The checksum for the field.
logical, intent(out) :: valid_chksum !< If true, chksum has been successfully read.
! Local variables
integer(kind=8), dimension(3) :: checksum_file

checksum_file(:) = -1
valid_chksum = mpp_attribute_exist(field, "checksum")
if (valid_chksum) then
call mpp_get_atts(field, checksum=checksum_file)
chksum = checksum_file(1)
else
chksum = -1
endif
end subroutine read_field_chksum

!> This function determines how many time levels a variable has.
function num_timelevels(filename, varname, min_dims) result(n_time)
character(len=*), intent(in) :: filename !< name of the file to read
Expand Down Expand Up @@ -519,7 +537,6 @@ function num_timelevels(filename, varname, min_dims) result(n_time)
return
endif


allocate(varids(nvars))

status = nf90_inq_varids(ncid, nvars, varids)
Expand Down Expand Up @@ -848,7 +865,26 @@ function FMS_file_exists(filename, domain, no_domain)

end function FMS_file_exists

!> This function uses the fms_io function read_data to read 1-D

!> This function uses the fms_io function read_data to read a scalar
!! data field named "fieldname" from file "filename".
subroutine MOM_read_data_0d(filename, fieldname, data, timelevel, 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, intent(inout) :: data !< The 1-dimensional array into which the data
integer, optional, intent(in) :: timelevel !< The time level in the file to read
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before it is returned.

call read_data(filename, fieldname, data, timelevel=timelevel, no_domain=.true.)

if (present(scale)) then ; if (scale /= 1.0) then
data = scale*data
endif ; endif

end subroutine MOM_read_data_0d

!> This function uses the fms_io function read_data to read a 1-D
!! data field named "fieldname" from file "filename".
subroutine MOM_read_data_1d(filename, fieldname, data, timelevel, scale)
character(len=*), intent(in) :: filename !< The name of the file to read
Expand Down Expand Up @@ -879,7 +915,7 @@ subroutine MOM_read_data_2d(filename, fieldname, data, MOM_Domain, &
integer, optional, intent(in) :: timelevel !< The time level in the file to read
integer, optional, intent(in) :: position !< A flag indicating where this data is located
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before they are returned.
!! by before it is returned.

integer :: is, ie, js, je

Expand Down Expand Up @@ -907,7 +943,7 @@ subroutine MOM_read_data_3d(filename, fieldname, data, MOM_Domain, &
integer, optional, intent(in) :: timelevel !< The time level in the file to read
integer, optional, intent(in) :: position !< A flag indicating where this data is located
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before they are returned.
!! by before it is returned.

integer :: is, ie, js, je

Expand Down Expand Up @@ -935,7 +971,7 @@ subroutine MOM_read_data_4d(filename, fieldname, data, MOM_Domain, &
integer, optional, intent(in) :: timelevel !< The time level in the file to read
integer, optional, intent(in) :: position !< A flag indicating where this data is located
real, optional, intent(in) :: scale !< A scaling factor that the field is multiplied
!! by before they are returned.
!! by before it is returned.

integer :: is, ie, js, je

Expand Down
8 changes: 3 additions & 5 deletions src/framework/MOM_random.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module MOM_random
use MersenneTwister_mod, only : getRandomReal ! Generates a random number
use MersenneTwister_mod, only : getRandomPositiveInt ! Generates a random positive integer

use MOM_io, only : stdout, stderr
use iso_fortran_env, only : stdout=>output_unit, stderr=>error_unit

implicit none ; private

Expand All @@ -23,8 +23,6 @@ module MOM_random
public :: random_2d_norm
public :: random_unit_tests

#include <MOM_memory.h>

!> Container for pseudo-random number generators
type, public :: PRNG ; private

Expand Down Expand Up @@ -63,7 +61,7 @@ end function random_norm
subroutine random_2d_01(CS, HI, rand)
type(PRNG), intent(inout) :: CS !< Container for pseudo-random number generators
type(hor_index_type), intent(in) :: HI !< Horizontal index structure
real, dimension(SZI_(HI),SZJ_(HI)), intent(out) :: rand !< Random numbers between 0 and 1
real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), intent(out) :: rand !< Random numbers between 0 and 1
! Local variables
integer :: i,j

Expand All @@ -80,7 +78,7 @@ end subroutine random_2d_01
subroutine random_2d_norm(CS, HI, rand)
type(PRNG), intent(inout) :: CS !< Container for pseudo-random number generators
type(hor_index_type), intent(in) :: HI !< Horizontal index structure
real, dimension(SZI_(HI),SZJ_(HI)), intent(out) :: rand !< Random numbers between 0 and 1
real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), intent(out) :: rand !< Random numbers between 0 and 1
! Local variables
integer :: i,j,n

Expand Down
Loading