Skip to content

Commit

Permalink
Merge pull request #1364 from GEOS-ESM/feature/atrayano/#1363_split_f…
Browse files Browse the repository at this point in the history
…ield

Fixes #1363. The main change to create a copy of the exports, so we c…
  • Loading branch information
mathomp4 authored Feb 23, 2022
2 parents b05beb8 + 4c7d4c7 commit 87af383
Show file tree
Hide file tree
Showing 4 changed files with 462 additions and 395 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Changed the naming convention for the split name(s): we now take the entries from the field alias(es) without appending any digits. Also allowing the user to specify more entries in the alias, so that HISTORY.rc does not need to change when running GOCART with more wavelengths
- A small performance improvement. cycle => exit in MAPL_Generic.F90
- Made history global metadata configurable. This can be done in two ways
1. Globally for all collections by setting `COMMENT:`, `CONTACT:`, `CONVENTION:`, `INSTITUTION:`, `REFERENCES:`, and `SOURCE:` at the top of `HISTORY.rc` like `EXPDSC:`
Expand Down
78 changes: 45 additions & 33 deletions base/Base/Base_Base_implementation.F90
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "MAPL_Exceptions.h"
#include "MAPL_ErrLog.h"
#include "unused_dummy.H"

Expand Down Expand Up @@ -3662,45 +3663,56 @@ subroutine genAlias(name, n, splitNameArray, aliasName, rc)

integer :: i, k
integer :: k1, k2, kk, count
integer :: nn
character(len=ESMF_MAXSTR), allocatable :: tmp(:)
character(len=ESMF_MAXSTR) :: aliasName_

if (present(aliasName)) then
aliasName_ = aliasName
else
aliasName_ = name
end if

allocate(splitNameArray(n), stat=status)
_VERIFY(status)
if (present(aliasName)) then
! count the separators (";") in aliasName
! if they match n (i.e. the count = n-1) use each
! else if count is 0, append 00i to aliasName
! else return an error

! parse the aliasName
count = 0
k1 = 1
kk = len_trim(aliasName)
do k=1,kk
if (aliasName(k:k) == ";") then
count = count+1
k2=k-1
_ASSERT(count < n, 'Too many split separators')
splitNameArray(count) = aliasName(k1:k2)
k1 = k+1
end if
end do
if (count == 0) then
do i=1,n
write(splitNameArray(i),'(A,I3.3)') trim(aliasName), i
end do
else if(count == n-1) then
k2 = kk

! parse the aliasName
! count the separators (";") in aliasName
count = 0
k1 = 1
kk = len_trim(aliasName_)
do k=1,kk
if (aliasName_(k:k) == ";") then
count = count+1
splitNameArray(count) = aliasName(k1:k2)
else
_ASSERT(.false.,'Inconsistent number of split separators')
end if
end do
nn = count+1
allocate(tmp(nn), __STAT__)

else
do i=1,n
write(splitNameArray(i),'(A,I3.3)') trim(name), i
end do
end if
count = 0
do k=1,kk
if (aliasName_(k:k) == ";") then
count = count+1
k2=k-1
if (count > n) exit ! use atmost n of the aliases
tmp(count) = aliasName_(k1:k2)
k1 = k+1
end if
end do
count = count+1
k2 = kk
tmp(count) = aliasName_(k1:k2)

do i=1,min(nn,n)
splitNameArray(i) = tmp(i)
end do
deallocate(tmp)
! if the user did no supply enough separated alias field names,
! append 00i to the original field name
do i=nn+1,n
write(splitNameArray(i),'(A,I3.3)') trim(name), i
end do

_RETURN(ESMF_SUCCESS)
end subroutine GenAlias
end subroutine MAPL_FieldSplit
Expand Down
7 changes: 3 additions & 4 deletions gridcomps/History/MAPL_HistoryCollection.F90
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ module MAPL_HistoryCollectionMod
character(len=ESMF_MAXSTR),pointer :: PExtraFields(:) => null()
character(len=ESMF_MAXSTR),pointer :: PExtraGridComp(:) => null()
type (FieldSet), pointer :: field_set
logical, pointer :: r8_to_r4(:) => null()
type(ESMF_FIELD), pointer :: r8(:) => null()
type(ESMF_FIELD), pointer :: r4(:) => null()
logical, allocatable :: r8_to_r4(:)
type(ESMF_FIELD), allocatable :: r8(:)
type(ESMF_FIELD), allocatable :: r4(:)
character(len=ESMF_MAXSTR) :: output_grid_label
type(GriddedIOItemVector) :: items
character(len=ESMF_MAXSTR) :: currentFile
Expand All @@ -114,7 +114,6 @@ function define_collection_attributes(this,rc) result(global_attributes)
integer, optional, intent(out) :: rc

type(StringStringMap) :: global_attributes
integer :: status

call global_attributes%insert("Title",trim(this%descr))
call global_attributes%insert("History","File written by MAPL_PFIO")
Expand Down
Loading

0 comments on commit 87af383

Please sign in to comment.