Skip to content

Commit

Permalink
Use read_field_chksum in MOM_restart
Browse files Browse the repository at this point in the history
  Use read_field_chksum and MOM_read_data in MOM_restart.  Also internally
renamed mpp_chksum to just chksum in MOM_restart to aid in identifying
unfiltered dependencies on FMS in MOM_restart.F90.  All answers are bitwise
identical.
  • Loading branch information
Hallberg-NOAA committed Jan 3, 2021
1 parent aed5a68 commit aea16f7
Showing 1 changed file with 31 additions and 40 deletions.
71 changes: 31 additions & 40 deletions src/framework/MOM_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ module MOM_restart

! This file is part of MOM6. See LICENSE.md for the license.

use MOM_domains, only : pe_here, num_PEs
use MOM_domains, only : PE_here, num_PEs
use MOM_error_handler, only : MOM_error, FATAL, WARNING, NOTE, is_root_pe
use MOM_file_parser, only : get_param, log_param, log_version, param_file_type
use MOM_string_functions, only : lowercase
use MOM_grid, only : ocean_grid_type
use MOM_io, only : create_file, fieldtype, file_exists, open_file, close_file
use MOM_io, only : MOM_read_data, read_data, get_filename_appendix
use MOM_io, only : MOM_read_data, read_data, get_filename_appendix, read_field_chksum
use MOM_io, only : get_file_info, get_file_atts, get_file_fields, get_file_times
use MOM_io, only : vardesc, var_desc, query_vardesc, modify_vardesc
use MOM_io, only : MULTIPLE, NETCDF_FILE, READONLY_FILE, SINGLE_FILE
use MOM_io, only : CENTER, CORNER, NORTH_FACE, EAST_FACE
use MOM_time_manager, only : time_type, time_type_to_real, real_to_time
use MOM_time_manager, only : days_in_month, get_date, set_date
use MOM_transform_FMS, only : mpp_chksum => rotated_mpp_chksum
use MOM_time_manager, only : time_type, time_type_to_real, real_to_time
use MOM_time_manager, only : days_in_month, get_date, set_date
use MOM_transform_FMS, only : chksum => rotated_mpp_chksum
use MOM_transform_FMS, only : write_field => rotated_write_field
use MOM_verticalGrid, only : verticalGrid_type
use mpp_io_mod, only : mpp_attribute_exist, mpp_get_atts
use mpp_mod, only : mpp_pe
use MOM_verticalGrid, only : verticalGrid_type

implicit none ; private

Expand Down Expand Up @@ -116,7 +114,7 @@ module MOM_restart
module procedure register_restart_field_ptr0d, register_restart_field_0d
end interface

!> Register a pair of restart fieilds whose rotations map onto each other
!> Register a pair of restart fields whose rotations map onto each other
interface register_restart_pair
module procedure register_restart_pair_ptr2d
module procedure register_restart_pair_ptr3d
Expand Down Expand Up @@ -1010,18 +1008,15 @@ subroutine save_restart(directory, time, G, CS, time_stamped, filename, GV, num_
endif
do m=start_var,next_var-1
if (associated(CS%var_ptr3d(m)%p)) then
check_val(m-start_var+1,1) = &
mpp_chksum(CS%var_ptr3d(m)%p(isL:ieL,jsL:jeL,:), turns=-turns)
check_val(m-start_var+1,1) = chksum(CS%var_ptr3d(m)%p(isL:ieL,jsL:jeL,:), turns=-turns)
elseif (associated(CS%var_ptr2d(m)%p)) then
check_val(m-start_var+1,1) = &
mpp_chksum(CS%var_ptr2d(m)%p(isL:ieL,jsL:jeL), turns=-turns)
check_val(m-start_var+1,1) = chksum(CS%var_ptr2d(m)%p(isL:ieL,jsL:jeL), turns=-turns)
elseif (associated(CS%var_ptr4d(m)%p)) then
check_val(m-start_var+1,1) = &
mpp_chksum(CS%var_ptr4d(m)%p(isL:ieL,jsL:jeL,:,:), turns=-turns)
check_val(m-start_var+1,1) = chksum(CS%var_ptr4d(m)%p(isL:ieL,jsL:jeL,:,:), turns=-turns)
elseif (associated(CS%var_ptr1d(m)%p)) then
check_val(m-start_var+1,1) = mpp_chksum(CS%var_ptr1d(m)%p)
check_val(m-start_var+1,1) = chksum(CS%var_ptr1d(m)%p)
elseif (associated(CS%var_ptr0d(m)%p)) then
check_val(m-start_var+1,1) = mpp_chksum(CS%var_ptr0d(m)%p,pelist=(/mpp_pe()/))
check_val(m-start_var+1,1) = chksum(CS%var_ptr0d(m)%p, pelist=(/PE_here()/))
endif
enddo

Expand Down Expand Up @@ -1100,9 +1095,9 @@ subroutine restore_state(filename, directory, day, G, CS)
real :: t1, t2 ! Two times.
real, allocatable :: time_vals(:)
type(fieldtype), allocatable :: fields(:)
logical :: check_exist, is_there_a_checksum
integer(kind=8),dimension(3) :: checksum_file
integer(kind=8) :: checksum_data
logical :: is_there_a_checksum ! Is there a valid checksum that should be checked.
integer(kind=8) :: checksum_file ! The checksum value recorded in the input file.
integer(kind=8) :: checksum_data ! The checksum value for the data that was read in.

if (.not.associated(CS)) call MOM_error(FATAL, "MOM_restart " // &
"restore_state: Module must be initialized before it is used.")
Expand Down Expand Up @@ -1202,25 +1197,21 @@ subroutine restore_state(filename, directory, day, G, CS)
do i=1, nvar
call get_file_atts(fields(i),name=varname)
if (lowercase(trim(varname)) == lowercase(trim(CS%restart_field(m)%var_name))) then
check_exist = mpp_attribute_exist(fields(i),"checksum")
checksum_file(:) = -1
checksum_data = -1
is_there_a_checksum = .false.
if ( check_exist ) then
call mpp_get_atts(fields(i),checksum=checksum_file)
is_there_a_checksum = .true.
if (CS%checksum_required) then
call read_field_chksum(fields(i), checksum_file, is_there_a_checksum)
else
checksum_file = -1
is_there_a_checksum = .false. ! Do not need to do data checksumming.
endif
if (.NOT. CS%checksum_required) is_there_a_checksum = .false. ! Do not need to do data checksumming.

if (associated(CS%var_ptr1d(m)%p)) then
! Read a 1d array, which should be invariant to domain decomposition.
call read_data(unit_path(n), varname, CS%var_ptr1d(m)%p, &
G%Domain%mpp_domain, timelevel=1)
if (is_there_a_checksum) checksum_data = mpp_chksum(CS%var_ptr1d(m)%p)
call MOM_read_data(unit_path(n), varname, CS%var_ptr1d(m)%p, timelevel=1)
if (is_there_a_checksum) checksum_data = chksum(CS%var_ptr1d(m)%p)
elseif (associated(CS%var_ptr0d(m)%p)) then ! Read a scalar...
call read_data(unit_path(n), varname, CS%var_ptr0d(m)%p, &
G%Domain%mpp_domain, timelevel=1)
if (is_there_a_checksum) checksum_data = mpp_chksum(CS%var_ptr0d(m)%p,pelist=(/mpp_pe()/))
call MOM_read_data(unit_path(n), varname, CS%var_ptr0d(m)%p, timelevel=1)
if (is_there_a_checksum) checksum_data = chksum(CS%var_ptr0d(m)%p, pelist=(/PE_here()/))
elseif (associated(CS%var_ptr2d(m)%p)) then ! Read a 2d array.
if (pos /= 0) then
call MOM_read_data(unit_path(n), varname, CS%var_ptr2d(m)%p, &
Expand All @@ -1229,7 +1220,7 @@ subroutine restore_state(filename, directory, day, G, CS)
call read_data(unit_path(n), varname, CS%var_ptr2d(m)%p, &
no_domain=.true., timelevel=1)
endif
if (is_there_a_checksum) checksum_data = mpp_chksum(CS%var_ptr2d(m)%p(isL:ieL,jsL:jeL))
if (is_there_a_checksum) checksum_data = chksum(CS%var_ptr2d(m)%p(isL:ieL,jsL:jeL))
elseif (associated(CS%var_ptr3d(m)%p)) then ! Read a 3d array.
if (pos /= 0) then
call MOM_read_data(unit_path(n), varname, CS%var_ptr3d(m)%p, &
Expand All @@ -1238,7 +1229,7 @@ subroutine restore_state(filename, directory, day, G, CS)
call read_data(unit_path(n), varname, CS%var_ptr3d(m)%p, &
no_domain=.true., timelevel=1)
endif
if (is_there_a_checksum) checksum_data = mpp_chksum(CS%var_ptr3d(m)%p(isL:ieL,jsL:jeL,:))
if (is_there_a_checksum) checksum_data = chksum(CS%var_ptr3d(m)%p(isL:ieL,jsL:jeL,:))
elseif (associated(CS%var_ptr4d(m)%p)) then ! Read a 4d array.
if (pos /= 0) then
call MOM_read_data(unit_path(n), varname, CS%var_ptr4d(m)%p, &
Expand All @@ -1247,14 +1238,14 @@ subroutine restore_state(filename, directory, day, G, CS)
call read_data(unit_path(n), varname, CS%var_ptr4d(m)%p, &
no_domain=.true., timelevel=1)
endif
if (is_there_a_checksum) checksum_data = mpp_chksum(CS%var_ptr4d(m)%p(isL:ieL,jsL:jeL,:,:))
if (is_there_a_checksum) checksum_data = chksum(CS%var_ptr4d(m)%p(isL:ieL,jsL:jeL,:,:))
else
call MOM_error(FATAL, "MOM_restart restore_state: No pointers set for "//trim(varname))
endif

if (is_root_pe() .and. is_there_a_checksum .and. (checksum_file(1) /= checksum_data)) then
if (is_root_pe() .and. is_there_a_checksum .and. (checksum_file /= checksum_data)) then
write (mesg,'(a,Z16,a,Z16,a)') "Checksum of input field "// trim(varname)//" ",checksum_data,&
" does not match value ", checksum_file(1), &
" does not match value ", checksum_file, &
" stored in "//trim(unit_path(n)//"." )
call MOM_error(FATAL, "MOM_restart(restore_state): "//trim(mesg) )
endif
Expand Down Expand Up @@ -1455,7 +1446,7 @@ function open_restart_units(filename, directory, G, CS, units, file_paths, &
if (fexists) then
if (present(units)) &
call open_file(units(n), trim(filepath), READONLY_FILE, NETCDF_FILE, &
threading = MULTIPLE, fileset = SINGLE_FILE)
threading=MULTIPLE, fileset=SINGLE_FILE)
if (present(global_files)) global_files(n) = .true.
elseif (CS%parallel_restartfiles) then
! Look for decomposed files using the I/O Layout.
Expand Down Expand Up @@ -1484,7 +1475,7 @@ function open_restart_units(filename, directory, G, CS, units, file_paths, &
if (fexists) then
if (present(units)) &
call open_file(units(n), trim(filepath), READONLY_FILE, NETCDF_FILE, &
threading = MULTIPLE, fileset = SINGLE_FILE)
threading=MULTIPLE, fileset=SINGLE_FILE)
if (present(global_files)) global_files(n) = .true.
if (present(file_paths)) file_paths(n) = filepath
n = n + 1
Expand Down

0 comments on commit aea16f7

Please sign in to comment.