Skip to content

Commit

Permalink
Fixes #1878. The adds ability to expand %d in the long name, when we …
Browse files Browse the repository at this point in the history
…split a field in History
  • Loading branch information
atrayano committed Jan 4, 2023
1 parent 6c9ac44 commit 4538bfe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Added ability to expand "%d" in the long name when we split fields for History

### Changed

Expand Down
38 changes: 38 additions & 0 deletions base/Base/Base_Base_implementation.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3689,6 +3689,7 @@ module subroutine MAPL_FieldSplit(field, fields, aliasName, rc)
character(len=ESMF_MAXSTR) :: name
character(len=ESMF_MAXSTR) :: splitName
character(len=ESMF_MAXSTR), allocatable :: splitNameArray(:)
character(len=ESMF_MAXSTR) :: longName

! get ptr
! loop over 3-d or 4-d dim
Expand Down Expand Up @@ -3828,9 +3829,46 @@ module subroutine MAPL_FieldSplit(field, fields, aliasName, rc)
deallocate(gridToFieldMap)
deallocate(splitNameArray)
! fields SHOULD be deallocated by the caller!!!

!ALT: check if we need to expand "%d" in the long name
! Note that at this point the original, and each of the split fields
! have the same long name. We check the original.

call ESMF_AttributeGet(FIELD, NAME='LONG_NAME', VALUE=longName, _RC)
if (index(longName, "%d") /= 0) then
call expandBinNumber(fields, _RC)
end if


_RETURN(ESMF_SUCCESS)

contains
subroutine expandBinNumber(fields, rc)
type(ESMF_Field) :: fields(:)
integer, optional :: rc

integer :: i, tlen, i1, i2
character(len=ESMF_MAXSTR) :: longName
character(len=3) :: tmp
character(len=ESMF_MAXSTR) :: newLongName

do i = 1, size(fields)
call ESMF_AttributeGet(fields(i), NAME='LONG_NAME', VALUE=longName, _RC)
i1 = index(longName, "%d")
_ASSERT(i1>0, "Nothing to expand")
i2 = i1 + 2 ! size of "%d"
tlen = len(trim(longName))
_ASSERT(tlen + 1 <= len(longName),'LONG_NAME would exceed MAX length after expansion')
write(tmp,'(i3.3)') i
newLongName = longName(1:i1-1)//tmp//trim(longName(i2:tlen))
! remove old attribute
call ESMF_AttributeRemove(fields(i), NAME='LONG_NAME', _RC)
! save the new one
call ESMF_AttributeSet(fields(i), NAME='LONG_NAME', VALUE=newLongName, _RC)
end do
_RETURN(ESMF_SUCCESS)
end subroutine expandBinNumber

subroutine genAlias(name, n, splitNameArray, aliasName, rc)
integer :: n
character(len=*) :: name
Expand Down

0 comments on commit 4538bfe

Please sign in to comment.