Skip to content

Commit

Permalink
Merge pull request #3162 from GEOS-ESM/feature/tclune/mapl3-introduce…
Browse files Browse the repository at this point in the history
…-field_bundle-dir

Further progress towards integrating support for info at Field and
  • Loading branch information
tclune authored Nov 7, 2024
2 parents 83c5248 + 04de6fe commit 67074f4
Show file tree
Hide file tree
Showing 36 changed files with 917 additions and 1,650 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ add_subdirectory (profiler)
add_subdirectory (generic)
add_subdirectory (generic3g)
add_subdirectory (field)
add_subdirectory (field_bundle)
add_subdirectory (oomph) # temporary - will rename to generic when done
add_subdirectory (shared)
add_subdirectory (include)
Expand Down
2 changes: 1 addition & 1 deletion GeomIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(srcs

esma_add_library(${this}
SRCS ${srcs}
DEPENDENCIES MAPL.geom_mgr MAPL.pfio MAPL.base MAPL.shared MAPL.esmf_utils MAPL.hconfig_utils GFTL::gftl-v2
DEPENDENCIES MAPL.field MAPL.field_bundle MAPL.geom_mgr MAPL.pfio MAPL.base MAPL.shared MAPL.esmf_utils MAPL.hconfig_utils GFTL::gftl-v2
TYPE SHARED
)

Expand Down
137 changes: 78 additions & 59 deletions GeomIO/SharedIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
module mapl3g_SharedIO
use mapl_ErrorHandlingMod
use mapl3g_InfoUtilities
use mapl3g_FieldBundleGet
use mapl3g_FieldGet
use mapl3g_VerticalStaggerLoc
use pfio
use gFTL2_StringVector
use gFTL2_StringSet
use mapl3g_geom_mgr
use MAPL_BaseMod
use mapl3g_UngriddedDims
use mapl3g_UngriddedDim
use mapl3g_FieldDimensionInfo
!# use mapl3g_FieldDimensionInfo
use esmf

implicit none
implicit none(type,external)

public add_variables
public add_variable
Expand All @@ -21,7 +25,6 @@ module mapl3g_SharedIO
public esmf_to_pfio_type

public :: add_vertical_dimensions
public :: get_vertical_dimension_name
public :: get_vertical_dimension_num_levels
public :: get_vertical_dimension_name_from_field
public :: add_ungridded_dimensions
Expand Down Expand Up @@ -65,16 +68,13 @@ subroutine add_variables(metadata, bundle, rc)
type(FileMetaData), intent(inout) :: metadata
integer, intent(out), optional :: rc

integer :: status, num_fields, i
character(len=ESMF_MAXSTR), allocatable :: field_names(:)
integer :: status, i
type(ESMF_Field) :: field
type(ESMF_Field), allocatable :: fieldList(:)

call ESMF_FieldBundleGet(bundle, fieldCount=num_fields, _RC)
allocate(field_names(num_fields))
call ESMF_FieldBundleGet(bundle, fieldNameList=field_names, _RC)
do i=1,num_fields
call ESMF_FieldBundleGet(bundle, field_names(i), field=field, _RC)
call add_variable(metadata, field, _RC)
call MAPL_FieldBundleGet(bundle, fieldList=fieldList, _RC)
do i=1,size(fieldList)
call add_variable(metadata, fieldList(i), _RC)
enddo
_RETURN(_SUCCESS)

Expand All @@ -101,7 +101,7 @@ subroutine add_variable(metadata, field, rc)
mapl_geom => get_mapl_geom(esmfgeom, _RC)
grid_variables = mapl_geom%get_gridded_dims()
dims = string_vec_to_comma_sep(grid_variables)
call ESMF_FieldGet(field, name=fname, typekind = typekind, _RC)
call ESMF_FieldGet(field, name=fname, typekind=typekind, _RC)
! add vertical dimension
vert_dim_name = get_vertical_dimension_name_from_field(field, _RC)
if(vert_dim_name /= EMPTY) dims = dims//","//vert_dim_name
Expand All @@ -112,9 +112,9 @@ subroutine add_variable(metadata, field, rc)
dims = dims//",time"
pfio_type = esmf_to_pfio_type(typekind ,_RC)
v = Variable(type=pfio_type, dimensions=dims)
call MAPL_InfoGetInternal(field, 'units', char, _RC)
call MAPL_FieldGet(field, units=char, _RC)
call v%add_attribute('units',char)
call MAPL_InfoGetInternal(field, 'standard_name', char, _RC)
call MAPL_FieldGet(field, standard_name=char, _RC)
call v%add_attribute('long_name',char)
call metadata%add_variable(trim(fname), v, _RC)
_RETURN(_SUCCESS)
Expand Down Expand Up @@ -188,47 +188,52 @@ subroutine add_vertical_dimensions(bundle, metadata, rc)
type(ESMF_FieldBundle), intent(in) :: bundle
type(FileMetaData), intent(inout) :: metadata
integer, optional, intent(out) :: rc

integer :: status
integer :: num_levels
type(StringVector) :: vertical_names
type(StringVectorIterator) :: iter
character(len=:), allocatable :: spec_name, dim_name

num_levels = get_num_levels(bundle, _RC)
if(num_levels == 0) return
vertical_names = get_vertical_dim_spec_names(bundle, _RC)
iter = vertical_names%begin()
do while(iter /= vertical_names%end())
spec_name = iter%of()
num_levels = get_vertical_dimension_num_levels(spec_name, num_levels)
dim_name = get_vertical_dimension_name(spec_name)
call metadata%add_dimension(dim_name, num_levels)
call iter%next()
end do
_RETURN(_SUCCESS)
character(len=:), allocatable :: dim_name
type(VerticalStaggerLoc) :: vert_staggerloc
integer :: i, num_vgrid_levels, field_vgrid_levels
type(ESMF_Field), allocatable :: fieldList(:)

end subroutine add_vertical_dimensions

function get_vertical_dimension_name(dim_spec_name) result(dim_name)
character(len=:), allocatable :: dim_name
character(len=*), intent(in) :: dim_spec_name
character(len=*), parameter :: VERTICAL_CENTER_NAME = 'lev'
character(len=*), parameter :: VERTICAL_EDGE_NAME = 'edge'
character(len=*), parameter :: VERTICAL_UNKNOWN_NAME = EMPTY
call MAPL_FieldBundleGet(bundle, fieldList=fieldList, _RC)
num_vgrid_levels = 0

vertical_names = StringVector()
do i = 1, size(fieldList)
call MAPL_FieldGet(fieldList(i), vert_staggerloc=vert_staggerloc, _RC)
if (vert_staggerloc == VERTICAL_STAGGER_NONE) cycle

! Ensure consistent vertical grid
call MAPL_FieldGet(fieldList(i), num_vgrid_levels=field_vgrid_levels, _RC)
if (num_vgrid_levels > 0) then
_ASSERT(field_vgrid_levels == num_vgrid_levels, "Inconsistent vertical grid in bundle.")
else
num_vgrid_levels = field_vgrid_levels
end if

dim_name = vert_staggerloc%get_dimension_name()
call vertical_names%push_back(dim_name)

dim_name = VERTICAL_UNKNOWN_NAME
end do

if(dim_spec_name == 'VERTICAL_DIM_EDGE') then
dim_name = VERTICAL_EDGE_NAME
return
end if
associate (e => vertical_names%ftn_end())
iter = vertical_names%ftn_begin()
do while(iter /= e)
call iter%next()
dim_name = iter%of()
num_levels = vert_staggerloc%get_num_levels(num_vgrid_levels)
call metadata%add_dimension(dim_name, num_levels)
end do
end associate

if(dim_spec_name == 'VERTICAL_DIM_CENTER') then
dim_name = VERTICAL_CENTER_NAME
return
end if
_RETURN(_SUCCESS)

end subroutine add_vertical_dimensions

end function get_vertical_dimension_name

integer function get_vertical_dimension_num_levels(dim_spec_name, num_levels) result(num)
character(len=*), intent(in) :: dim_spec_name
Expand All @@ -243,11 +248,12 @@ function get_vertical_dimension_name_from_field(field, rc) result(dim_name)
character(len=:), allocatable :: dim_name
type(ESMF_Field), intent(in) :: field
integer, intent(out), optional :: rc

integer :: status
character(len=:), allocatable :: dim_spec_name
type(VerticalStaggerLoc) :: vert_staggerloc

dim_spec_name = get_vertical_dim_spec_name(field, _RC)
dim_name = get_vertical_dimension_name(dim_spec_name)
call MAPL_FieldGet(field, vert_staggerLoc=vert_staggerLoc, _RC)
dim_name = vert_staggerLoc%get_dimension_name()
_RETURN(_SUCCESS)

end function get_vertical_dimension_name_from_field
Expand All @@ -257,28 +263,41 @@ subroutine add_ungridded_dimensions(bundle, metadata, rc)
type(FileMetaData), intent(inout) :: metadata
integer, optional, intent(out) :: rc
integer :: status
type(UngriddedDims) :: ungridded_dims
type(UngriddedDims) :: field_ungridded_dims, ungridded_dims
type(UngriddedDim) :: u
integer :: i

ungridded_dims = get_ungridded_dims(bundle, _RC)
do i = 1, ungridded_dims%get_num_ungridded()
u = ungridded_dims%get_ith_dim_spec(i)
call metadata%add_dimension(u%get_name(), u%get_extent())
integer :: i, j
type(ESMF_Field) :: field
type(ESMF_Field), allocatable :: fieldList(:)
type(StringSet) :: dim_names
character(:), allocatable :: dim_name
logical :: is_new

call MAPL_FieldBundleGet(bundle, fieldList=fieldList, _RC)
do i = 1, size(fieldList)
call MAPL_FieldGet(fieldList(i), ungridded_dims=field_ungridded_dims, _RC)

do j = 1, field_ungridded_dims%get_num_ungridded()
u = ungridded_dims%get_ith_dim_spec(i)
dim_name = u%get_name()
call dim_names%insert(dim_name, is_new=is_new)
if (is_new) then
call metadata%add_dimension(u%get_name(), u%get_extent())
end if
end do
end do
_RETURN(_SUCCESS)

_RETURN(_SUCCESS)
end subroutine add_ungridded_dimensions

function ungridded_dim_names(field, rc) result(dim_names)
character(len=:), allocatable :: dim_names
type(ESMF_Field), intent(in) :: field
integer, optional, intent(out) :: rc
integer :: status
type(UngriddedDims) :: dims
type(UngriddedDims) :: ungridded_dims

dims = get_ungridded_dims(field, _RC)
dim_names = cat_ungridded_dim_names(dims)
call MAPL_FieldGet(field, ungridded_dims=ungridded_dims, _RC)
dim_names = cat_ungridded_dim_names(ungridded_dims)
_RETURN(_SUCCESS)

end function ungridded_dim_names
Expand Down
21 changes: 0 additions & 21 deletions GeomIO/tests/Test_SharedIO.pf
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,6 @@ contains

end subroutine assign_character_from_string

@Test
subroutine test_get_vertical_dimension_name()
character(len=:), allocatable :: name
character(len=:), allocatable :: vertical_dim
character(len=:), allocatable :: message

vertical_dim = DIM_CENTER
name = CENTER_NAME
message = make_message('Dimension name does not match for', vertical_dim)
@assertEqual(name, get_vertical_dimension_name(vertical_dim), message)

vertical_dim = DIM_EDGE
name = EDGE_NAME
message = make_message('Dimension name does not match for', vertical_dim)
@assertEqual(name, get_vertical_dimension_name(vertical_dim), message)

vertical_dim = DIM_UNK
message = make_message('Return value should be empty String', vertical_dim)
@assertEqual(0, len(get_vertical_dimension_name(DIM_UNK)), message)

end subroutine test_get_vertical_dimension_name

@Test
subroutine test_get_vertical_dimension_num_levels()
Expand Down
1 change: 0 additions & 1 deletion esmf_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ esma_set_this (OVERRIDE MAPL.esmf_utils)

set(srcs
InfoUtilities.F90
FieldDimensionInfo.F90
UngriddedDim.F90
UngriddedDims.F90
UngriddedDimVector.F90
Expand Down
Loading

0 comments on commit 67074f4

Please sign in to comment.