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

checking of nans in export field bundles #377

Merged
merged 7 commits into from
May 10, 2023
Merged
Changes from 1 commit
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
53 changes: 23 additions & 30 deletions mediator/med_methods_mod.F90
Original file line number Diff line number Diff line change
@@ -2522,12 +2522,17 @@ subroutine med_methods_FB_check_for_nans(FB, rc)
character(len=CL) :: fieldname
real(r8) , pointer :: dataptr1d(:)
real(r8) , pointer :: dataptr2d(:,:)
integer :: nancount
character(len=CS) :: nancount_char
logical :: nanfound
character(len=*), parameter :: subname='(med_methods_FB_check_for_nans)'
! ----------------------------------------------
rc = ESMF_SUCCESS

call ESMF_FieldBundleGet(FB, fieldCount=fieldCount, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

nanfound = .false.
do index=1,fieldCount
call med_methods_FB_getNameN(FB, index, fieldname, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
@@ -2538,57 +2543,51 @@ subroutine med_methods_FB_check_for_nans(FB, rc)
if (fieldrank == 1) then
call ESMF_FieldGet(field, farrayPtr=dataptr1d, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call med_methods_check_for_nans(dataptr1d, nancount)
else
call ESMF_FieldGet(field, farrayPtr=dataptr2d, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call med_methods_check_for_nans(dataptr2d, nancount)
end if
if (nancount > 0) then
write(nancount_char, '(i0)') nancount
call ESMF_LogWrite(trim(subname)//": ERROR "//trim(nancount_char)//" NaNs found in field: "//trim(fieldname), &
ESMF_LOGMSG_WARNING)
nanfound = .true.
end if
end do
if (nanfound) then
call ESMF_LogWrite(trim(subname)//": ERROR nans found in export field bundle ",ESMF_LOGMSG_ERROR)
return
end if

end subroutine med_methods_FB_check_for_nans

!-----------------------------------------------------------------------------
subroutine med_methods_check_for_nans_1d(dataptr, name, rc)
subroutine med_methods_check_for_nans_1d(dataptr, nancount)
! input/output variables
real(r8) , intent(in) :: dataptr(:)
character(len=*) , intent(in) :: name
integer , intent(out) :: rc
real(r8) , intent(in) :: dataptr(:)
integer , intent(out) :: nancount

! local variables
integer :: n
integer :: nancount
character(len=CS) :: nancount_char
character(len=*), parameter :: subname='(med_methods_check_for_nans_1d)'
! ----------------------------------------------
rc = ESMF_SUCCESS

nancount = 0
do n = 1,size(dataptr)
if (isnan(dataptr(n))) then
nancount = nancount + 1
end if
end do
if (nancount > 0) then
write(nancount_char, '(i0)') nancount
call ESMF_LogWrite(trim(subname)//": ERROR "//trim(nancount_char)//" NaNs found in field: "//trim(name), &
ESMF_LOGMSG_ERROR)
return
endif
end subroutine med_methods_check_for_nans_1d

subroutine med_methods_check_for_nans_2d(dataptr, name, rc)
subroutine med_methods_check_for_nans_2d(dataptr, nancount)
! input/output variables
real(r8) , intent(in) :: dataptr(:,:)
character(len=*) , intent(in) :: name
integer , intent(out) :: rc
real(r8) , intent(in) :: dataptr(:,:)
integer , intent(out) :: nancount

! local variables
integer :: n,k
integer :: nancount
character(len=CS) :: nancount_char
character(len=*), parameter :: subname='(med_methods_check_for_nans_2d)'
! ----------------------------------------------
rc = ESMF_SUCCESS

nancount = 0
do k = 1,size(dataptr, dim=1)
do n = 1,size(dataptr, dim=2)
@@ -2597,12 +2596,6 @@ subroutine med_methods_check_for_nans_2d(dataptr, name, rc)
end if
end do
end do
if (nancount > 0) then
write(nancount_char, '(i0)') nancount
call ESMF_LogWrite(trim(subname)//": ERROR "//trim(nancount_char)//" NaNs found in field: "//trim(name), &
ESMF_LOGMSG_ERROR)
return
end if
end subroutine med_methods_check_for_nans_2d

end module med_methods_mod