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

cropcalStreamMod compiler error bug fix #2233

Merged
Merged
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
17 changes: 11 additions & 6 deletions src/cpl/share_esmf/cropcalStreamMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module cropcalStreamMod
! Read crop calendars from streams
!
! !USES:
use ESMF
use ESMF , only : ESMF_LogFoundError, ESMF_LOGERR_PASSTHRU, ESMF_Finalize
use ESMF , only : ESMF_END_ABORT
use shr_kind_mod , only : r8 => shr_kind_r8, CL => shr_kind_CL, CS => shr_kind_CS
use dshr_strdata_mod , only : shr_strdata_type
use decompMod , only : bounds_type
Expand Down Expand Up @@ -322,6 +323,7 @@ subroutine cropcal_interp(bounds, num_pcropp, filter_pcropp, crop_inst)
integer :: n, g
integer :: lsize
integer :: rc
integer :: begp, endp
real(r8), pointer :: dataptr1d_swindow_start(:)
real(r8), pointer :: dataptr1d_swindow_end (:)
real(r8), pointer :: dataptr1d_cultivar_gdds(:)
Expand All @@ -342,6 +344,9 @@ subroutine cropcal_interp(bounds, num_pcropp, filter_pcropp, crop_inst)
! Place all data from each type into a temporary 2d array
lsize = bounds%endg - bounds%begg + 1

begp = bounds%begp
endp= bounds%endp

dayspyr = get_curr_days_per_year()

! Read prescribed sowing window start dates from input files
Expand Down Expand Up @@ -397,17 +402,17 @@ subroutine cropcal_interp(bounds, num_pcropp, filter_pcropp, crop_inst)

! Ensure that, if mxsowings > 1, sowing windows are ordered such that ENDS are monotonically increasing. This is necessary because of how get_swindow() works.
if (mxsowings > 1) then
if (any(ends(:,2:mxsowings) <= ends(:,1:mxsowings-1) .and. &
ends(:,2:mxsowings) >= 1)) then
if (any(ends(begp:endp,2:mxsowings) <= ends(begp:endp,1:mxsowings-1) .and. &
ends(begp:endp,2:mxsowings) >= 1)) then
write(iulog, *) 'Sowing window inputs must be ordered such that end dates are monotonically increasing.'
call ESMF_Finalize(endflag=ESMF_END_ABORT)
end if
end if

! Handle invalid sowing window values
if (any(starts < 1 .or. ends < 1)) then
if (any(starts(begp:endp,:) < 1 .or. ends(begp:endp,:) < 1)) then
! Fail if not allowing fallback to paramfile sowing windows
if ((.not. allow_invalid_swindow_inputs) .and. any(all(starts < 1, dim=2) .and. patch%wtgcell > 0._r8 .and. patch%itype >= npcropmin)) then
if ((.not. allow_invalid_swindow_inputs) .and. any(all(starts(begp:endp,:) < 1, dim=2) .and. patch%wtgcell > 0._r8 .and. patch%itype >= npcropmin)) then
write(iulog, *) 'At least one crop in one gridcell has invalid prescribed sowing window start date(s). To ignore and fall back to paramfile sowing windows, set allow_invalid_swindow_inputs to .true.'
write(iulog, *) 'Affected crops:'
do ivt = npcropmin, mxpft
Expand All @@ -422,7 +427,7 @@ subroutine cropcal_interp(bounds, num_pcropp, filter_pcropp, crop_inst)
call ESMF_Finalize(endflag=ESMF_END_ABORT)

! Fail if a sowing window start date is prescribed without an end date (or vice versa)
else if (any((starts >= 1 .and. ends < 1) .or. (starts < 1 .and. ends >= 1))) then
else if (any((starts(begp:endp,:) >= 1 .and. ends(begp:endp,:) < 1) .or. (starts(begp:endp,:) < 1 .and. ends(begp:endp,:) >= 1))) then
write(iulog, *) 'Every prescribed sowing window start date must have a corresponding end date.'
call ESMF_Finalize(endflag=ESMF_END_ABORT)
end if
Expand Down