Skip to content

Commit

Permalink
Merge pull request #2207 from GEOS-ESM/hotfix/mathomp4/2192-on-main
Browse files Browse the repository at this point in the history
Fixes #2192. Fix ExtData2G Climatology bug
  • Loading branch information
mathomp4 committed Jun 23, 2023
2 parents 29c9ba3 + f39d432 commit 6b2cbc0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Deprecated

## [2.39.4] - 2023-06-23

### Fixed

- Added bug fix when using climatology option in ExtData2G under certain scenarios

## [2.39.3] - 2023-06-12

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif ()

project (
MAPL
VERSION 2.39.3
VERSION 2.39.4
LANGUAGES Fortran CXX C) # Note - CXX is required for ESMF

# Set the possible values of build type for cmake-gui
Expand Down
53 changes: 27 additions & 26 deletions gridcomps/ExtData2G/ExtDataClimFileHandler.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module MAPL_ExtdataClimFileHandler
use MAPL_StringTemplate
use MAPL_ExtDataBracket
use MAPL_ExtDataConstants
use MAPL_CommsMod
implicit none
private
public ExtDataClimFileHandler
Expand Down Expand Up @@ -44,9 +45,9 @@ subroutine get_file_bracket(this, input_time, source_time, bracket, fail_on_miss

integer :: target_year, original_year,clim_shift,valid_years(2)
integer, allocatable :: source_years(:)
_ASSERT(fail_on_missing_file,"Failure on missing file not allowed when rule is climatology")


_ASSERT(fail_on_missing_file,"Failure on missing file not allowed when rule is climatology")
if (bracket%time_in_bracket(input_time)) then
_RETURN(_SUCCESS)
end if
Expand All @@ -59,10 +60,10 @@ subroutine get_file_bracket(this, input_time, source_time, bracket, fail_on_miss
allocate(source_years(2))
call ESMF_TimeGet(source_time(1),yy=source_years(1),_RC)
call ESMF_TimeGet(source_time(2),yy=source_years(2),_RC)
_ASSERT(source_years(1) >= valid_years(1),'source time outide valid range')
_ASSERT(source_years(1) <= valid_years(2),'source time outide valid range')
_ASSERT(source_years(2) >= valid_years(1),'source time outide valid range')
_ASSERT(source_years(2) <= valid_years(2),'source time outide valid range')
_ASSERT(source_time(1) >= this%valid_range(1),'source time outside valid range')
_ASSERT(source_time(1) <= this%valid_range(2),'source time outside valid range')
_ASSERT(source_time(2) >= this%valid_range(1),'source time outside valid range')
_ASSERT(source_time(2) <= this%valid_range(2),'source time outside valid range')
end if

! shift target year to request source time if specified
Expand All @@ -72,31 +73,31 @@ subroutine get_file_bracket(this, input_time, source_time, bracket, fail_on_miss

!if (size(source_years)>0) then
if (allocated(source_years)) then
if (target_year < source_years(1)) then
if (input_time < source_time(1)) then
target_year = source_years(1)
this%clim_year = target_year
else if (target_year >= source_years(2)) then
this%clim_year = target_year
else if (input_time >= source_time(2)) then
target_year = source_years(2)
this%clim_year = target_year
this%clim_year = target_year
end if
call swap_year(target_time,target_year,_RC)
else
if (target_year < valid_years(1)) then
if (input_time <= this%valid_range(1)) then
target_year = valid_years(1)
this%clim_year = target_year
call swap_year(target_time,target_year,_RC)
else if (target_year >= valid_years(2)) then
else if (input_time >= this%valid_range(2)) then
target_year = valid_years(2)
this%clim_year = target_year
call swap_year(target_time,target_year,_RC)
end if
end if
end if
clim_target_time = target_time

! the target time is contained in the dataset and we are not extrapolating outside of source time selection based on available data
if (this%clim_year == CLIM_NULL) then

call ESMF_TimeIntervalSet(zero,_RC)
call ESMF_TimeIntervalSet(zero,_RC)
if (this%frequency == zero) then
current_file = this%file_template
call this%get_time_on_file(current_file,input_time,'L',time_index,time,_RC)
Expand Down Expand Up @@ -140,12 +141,12 @@ subroutine get_file_bracket(this, input_time, source_time, bracket, fail_on_miss
bracket%new_file_right=.true.
end if

! the target time has been specified to be a climatology for the year; either we
! the target time has been specified to be a climatology for the year; either we
! are outside the dataset or we have requested a source time range and are on
! or outside either end
else

call ESMF_TimeIntervalSet(zero,_RC)
call ESMF_TimeIntervalSet(zero,_RC)
if (this%frequency == zero) then
current_file = this%file_template
clim_shift=0
Expand Down Expand Up @@ -178,9 +179,9 @@ subroutine get_file_bracket(this, input_time, source_time, bracket, fail_on_miss
call ESMF_TimeGet(target_time,yy=target_year,_RC)
if (target_year > this%clim_year) then
call swap_year(time,original_year-1,_RC)
else
else
call swap_year(time,original_year,_RC)
end if
end if
else
call swap_year(time,original_year,_RC)
end if
Expand All @@ -202,9 +203,9 @@ subroutine get_file_bracket(this, input_time, source_time, bracket, fail_on_miss
call ESMF_TimeGet(target_time,yy=target_year,_RC)
if (target_year < this%clim_year) then
call swap_year(time,original_year+1,_RC)
else
else
call swap_year(time,original_year,_RC)
end if
end if
else
call swap_year(time,original_year,_RC)
end if
Expand All @@ -216,7 +217,7 @@ subroutine get_file_bracket(this, input_time, source_time, bracket, fail_on_miss
end if

_RETURN(_SUCCESS)

end subroutine get_file_bracket

subroutine get_file(this,filename,target_time,shift,rc)
Expand All @@ -235,15 +236,15 @@ subroutine get_file(this,filename,target_time,shift,rc)

call ESMF_TimeIntervalGet(this%frequency,s_i8=interval_seconds)
if (interval_seconds==0) then
! time is not representable as absolute time interval (month, year etc...) do this
! time is not representable as absolute time interval (month, year etc...) do this
! brute force way. Not good but ESMF leaves no choice
ftime=this%reff_time
do while (ftime <= target_time)
ftime = ftime + this%frequency
enddo
ftime=ftime -this%frequency + shift*this%frequency
else
n = (target_time-this%reff_time)/this%frequency
n = (target_time-this%reff_time)/this%frequency
ftime = this%reff_time+(n+shift)*this%frequency
end if
if (this%clim_year /= CLIM_NULL) then
Expand All @@ -270,8 +271,8 @@ subroutine swap_year(time,year,rc)
logical :: is_leap_year
type(ESMF_Calendar) :: calendar
integer :: status, month, day, hour, minute, second
is_leap_year=.false.

is_leap_year=.false.
call ESMF_TimeGet(time,mm=month,dd=day,h=hour,m=minute,s=second,calendar=calendar,_RC)
if (day==29 .and. month==2) then
is_leap_year = ESMF_CalendarIsLeapYear(calendar,year,_RC)
Expand Down

0 comments on commit 6b2cbc0

Please sign in to comment.