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

Swath grid for MAPL_HistoryGridComp #2458

Merged
merged 48 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0b7d480
Swath grid step 1: allow for destroy grid, regridder and metadata.
metdyn Sep 27, 2023
559dd04
Merge branch 'develop' into feature/ygyu/PR_swath_1_griddio_regridder
metdyn Sep 27, 2023
50a8caa
small update to CHANGELOG.md
metdyn Sep 27, 2023
faf2423
swath grid factory with Epoch update
metdyn Sep 27, 2023
c759032
update
metdyn Sep 28, 2023
3cd3610
Merge branch 'develop' into feature/ygyu/PR_swath_2_epoch
metdyn Oct 3, 2023
db2d719
NC cannot not find 'Cell_Along_Swath\ :mod04'. Try intel.
metdyn Oct 4, 2023
f299349
Code cannot read in HDF4 . I try to bypass by hard coding numbers fo…
metdyn Oct 9, 2023
cd55707
Merge branch 'develop' into feature/ygyu/PR_swath_2_epoch
metdyn Oct 10, 2023
48dd737
small udpate with nf90 get dimension
metdyn Oct 10, 2023
96232bd
h4toh5 conversion
metdyn Oct 11, 2023
b089265
modified: GriddedIO.F90; it should be the version I worked with Ben
metdyn Oct 30, 2023
bb7a46e
.
metdyn Oct 30, 2023
196d6b1
Save this version
metdyn Nov 6, 2023
576022e
add MAPL_ObsUtil.F90
metdyn Nov 8, 2023
6f0fa53
update
metdyn Nov 9, 2023
c115d12
WIP: add and test subroutine Find_M_files in time_ave_util.F90
metdyn Nov 10, 2023
4f8569c
.
metdyn Nov 11, 2023
e5caaa3
wip
metdyn Nov 13, 2023
88f60f8
make it work with
metdyn Nov 14, 2023
0980cca
update
metdyn Nov 14, 2023
b77033b
.
metdyn Nov 15, 2023
890dd02
.
metdyn Nov 15, 2023
d7c53ed
Adding standalone subr. into MAPL_ObsUtil.F90
metdyn Nov 15, 2023
1e957b8
save a copy
metdyn Nov 15, 2023
48ff466
.
metdyn Nov 15, 2023
1ac6d94
WIP, save a copy
metdyn Nov 16, 2023
7694bf3
.
metdyn Nov 16, 2023
bcb194f
update
metdyn Nov 17, 2023
ed43094
.
metdyn Nov 17, 2023
9379876
Merge branch 'develop' into feature/ygyu/PR_swath_1_griddio_regridder
metdyn Nov 17, 2023
04baaa8
Merge branch 'feature/ygyu/PR_swath_1_griddio_regridder' into feature…
metdyn Nov 17, 2023
4d09107
.
metdyn Nov 17, 2023
295d40b
.
metdyn Nov 17, 2023
448b33c
Add MPI_Bcast due to using bash ( ls file_*.)
metdyn Nov 20, 2023
99429c6
Values of lon/lat/time in netCDf is wrong. The reason is not found.
metdyn Nov 27, 2023
9ae3ffe
Merge branch 'develop' into feature/ygyu/PR_swath_2_epoch
metdyn Nov 27, 2023
0a2d1c5
.
metdyn Nov 28, 2023
f54a607
NAG problem:
metdyn Nov 28, 2023
995887f
update
metdyn Nov 28, 2023
4f71590
update
metdyn Nov 29, 2023
ed9cf02
.
metdyn Nov 29, 2023
a1457ce
Fix for missing TARGET attribute.
tclune Nov 29, 2023
d4e218c
small clean up
metdyn Nov 29, 2023
d04b9fe
Fix intel error for use pFlogger
metdyn Nov 30, 2023
1259acb
Add corrections
metdyn Nov 30, 2023
4f21f0f
-m
metdyn Dec 1, 2023
af8e6a6
Merge branch 'develop' into feature/ygyu/PR_swath_2_epoch
mathomp4 Dec 1, 2023
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New directory (`docs/tutorial/grid_comps/automatic_code_generator`) containing an example showing how to automatically generate the source code using the `MAPL_GridCompSpecs_ACG.py` tool.

### Changed

- Change the verification of the grid in MAPL_GetGlobalHorzIJIndex to avoid collective call
- Swath grid step 1: allow for destroying and regenerating swath grid and regenerating regridder route handle, and creating
allocatable metadata in griddedIO. Modifications are made to GriddedIO.F90, MAPL_AbstractRegridder.F90, and MAPL_EsmfRegridder.F90.
- Swath grid step 2: add control keywords for swath grid. Allow for filename template with '*' and DOY. Allow for missing obs files. Specify index_name_lon/lat, var_name_lon/lat/time, tunit, obs_file_begin/end/interval, Epoch and Epoch_init.

### Fixed

- [#2433] Implemented workarounds for gfortran-13
- Missing TARGET in GriddedIO - exposed runtime error when using NAG + debug.

### Removed

Expand Down
4 changes: 2 additions & 2 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set (srcs
MAPL_IO.F90
MAPL_LatLonGridFactory.F90 MAPL_TransposeRegridder.F90
MAPL_Comms.F90 MAPL_LatLonToLatLonRegridder.F90 MAPL_TripolarGridFactory.F90
MAPL_LlcGridFactory.F90
MAPL_LlcGridFactory.F90 MAPL_SwathGridFactory.F90
MAPL_Config.F90 MAPL_LocStreamMod.F90
MAPL_ConservativeRegridder.F90 MAPL_MaxMinMod.F90 MAPL_VerticalInterpMod.F90
MAPL_CubedSphereGridFactory.F90 MAPL_MemUtils.F90 MAPL_VerticalMethods.F90
Expand All @@ -55,7 +55,7 @@ set (srcs
MAPL_Resource.F90
MAPL_XYGridFactory.F90
MAPL_NetCDF.F90 Plain_netCDF_Time.F90
MAPL_DateTime_Parsing_ESMF.F90
MAPL_DateTime_Parsing_ESMF.F90 MAPL_ObsUtil.F90
# Orphaned program: should not be in this library.
# tstqsat.F90
)
Expand Down
52 changes: 51 additions & 1 deletion base/MAPL_AbstractGridFactory.F90
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ module MAPL_AbstractGridFactoryMod
procedure(get_file_format_vars), deferred :: get_file_format_vars
procedure(decomps_are_equal), deferred :: decomps_are_equal
procedure(physical_params_are_equal), deferred :: physical_params_are_equal

procedure :: get_xy_subset
procedure :: get_xy_mask
procedure :: destroy
procedure :: get_obs_time
metdyn marked this conversation as resolved.
Show resolved Hide resolved
end type AbstractGridFactory

abstract interface
Expand Down Expand Up @@ -238,6 +243,7 @@ function generate_file_reference3D(this,fpointer,metadata) result(ref)
type(FileMetadata), intent(in), optional :: metaData
end function generate_file_reference3D


end interface

character(len=*), parameter :: MOD_NAME = 'MAPL_AbstractGridFactory::'
Expand Down Expand Up @@ -1030,5 +1036,49 @@ function get_grid(this, unusable, rc) result(grid)
end if

end function get_grid



! This procedure should only be called for time dependent grids.
! A default implementation is to fail for other grid types, so we do not
! have to explicitly add methods to all of the existing subclasses.
subroutine get_xy_subset(this, interval, xy_subset, rc)
class(AbstractGridFactory), intent(in) :: this
type(ESMF_Time), intent(in) :: interval(2)
integer, intent(out) :: xy_subset(2,2)
integer, optional, intent(out) :: rc
integer :: status

_RETURN(_FAILURE)
end subroutine get_xy_subset

subroutine get_xy_mask(this, interval, xy_mask, rc)
class(AbstractGridFactory), intent(inout) :: this
type(ESMF_Time), intent(in) :: interval(2)
integer, allocatable, intent(out) :: xy_mask(:,:)
integer, optional, intent(out) :: rc
integer :: status

_RETURN(_FAILURE)
end subroutine get_xy_mask

! Probably don't need to do anything more for subclasses unless they have
! other objects that don't finalize well. (NetCDF, ESMF, MPI, ...)
subroutine destroy(this, rc)
class(AbstractGridFactory), intent(inout) :: this
integer, optional, intent(out) :: rc
integer :: status

call ESMF_GridDestroy(this%grid, noGarbage=.true., _RC)
_RETURN(_SUCCESS)
end subroutine destroy

subroutine get_obs_time(this, grid, obs_time, rc)
class(AbstractGridFactory), intent(inout) :: this
type (ESMF_Grid), intent(in) :: grid
real(ESMF_KIND_R4), intent(out) :: obs_time(:,:)
integer, optional, intent(out) :: rc

_RETURN(_SUCCESS)
end subroutine get_obs_time

end module MAPL_AbstractGridFactoryMod
21 changes: 21 additions & 0 deletions base/MAPL_AbstractRegridder.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module MAPL_AbstractRegridderMod
use ESMF
use MAPL_MemUtilsMod
use MAPL_ExceptionHandling
use MAPL_RegridderSpecRouteHandleMap
use, intrinsic :: iso_fortran_env, only: REAL32, REAL64
implicit none
private
Expand Down Expand Up @@ -92,6 +93,9 @@ module MAPL_AbstractRegridderMod
procedure :: has_undef_value
procedure :: get_regrid_method

procedure :: destroy
procedure :: destroy_route_handle

end type AbstractRegridder


Expand Down Expand Up @@ -1006,4 +1010,21 @@ integer function get_regrid_method(this) result(method)
method = this%spec%regrid_method
end function get_regrid_method


subroutine destroy(this, rc)
class(AbstractRegridder), intent(inout) :: this
integer, optional, intent(out) :: rc
integer :: status

_RETURN(_SUCCESS)
end subroutine destroy

subroutine destroy_route_handle(this, kind, rc)
class(AbstractRegridder), intent(inout) :: this
type(ESMF_TypeKind_Flag), intent(in) :: kind
integer, optional, intent(out) :: rc

_RETURN(_SUCCESS)
end subroutine destroy_route_handle

end module MAPL_AbstractRegridderMod
52 changes: 52 additions & 0 deletions base/MAPL_EsmfRegridder.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ module MAPL_EsmfRegridderMod
procedure :: do_regrid
procedure :: create_route_handle
procedure :: select_route_handle
procedure :: destroy
procedure :: destroy_route_handle

end type EsmfRegridder

Expand Down Expand Up @@ -1600,4 +1602,54 @@ function select_route_handle(this, kind, do_transpose, rc) result(route_handle)

end function select_route_handle

subroutine destroy(this, rc)
class(EsmfRegridder), intent(inout) :: this
integer, optional, intent(out) :: rc
integer :: status

call this%destroy_route_handle(ESMF_TYPEKIND_R4, _RC)

_RETURN(_SUCCESS)
end subroutine destroy


subroutine destroy_route_handle(this, kind, rc)
class(EsmfRegridder), intent(inout) :: this
type(ESMF_TypeKind_Flag), intent(in) :: kind
integer, optional, intent(out) :: rc

type (RegridderSpec) :: spec
type(ESMF_RouteHandle) :: dummy_rh
type(RegridderSpecRouteHandleMap), pointer :: route_handles, transpose_route_handles
type(ESMF_RouteHandle) :: route_handle
type(RegridderSpecRouteHandleMapIterator) :: iter
integer :: status

if (kind == ESMF_TYPEKIND_R4) then
route_handles => route_handles_r4
transpose_route_handles => transpose_route_handles_r4
else if(kind == ESMF_TYPEKIND_R8) then
route_handles => route_handles_r8
transpose_route_handles => transpose_route_handles_r8
else
_FAIL('unsupported type kind (must be R4 or R8)')
end if

spec = this%get_spec()

_ASSERT(route_handles%count(spec) == 1, 'Did not find this spec in route handle table.')
route_handle = route_handles%at(spec)
call ESMF_RouteHandleDestroy(route_handle, noGarbage=.true.,_RC)
iter = route_handles%find(spec)
call route_handles%erase(iter)

_ASSERT(transpose_route_handles%count(spec) == 1, 'Did not find this spec in route handle table.')
route_handle = transpose_route_handles%at(spec)
call ESMF_RouteHandleDestroy(route_handle, noGarbage=.true., _RC)
iter = transpose_route_handles%find(spec)
call transpose_route_handles%erase(iter)

_RETURN(_SUCCESS)
end subroutine destroy_route_handle

end module MAPL_EsmfRegridderMod
35 changes: 30 additions & 5 deletions base/MAPL_GridManager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module MAPL_GridManager_private
type (Integer64GridFactoryMap) :: factories
contains
procedure :: add_prototype
procedure :: destroy_grid
generic :: destroy => destroy_grid

procedure :: delete
!!$ procedure :: make_field
!!$ procedure :: delete_field
Expand Down Expand Up @@ -120,6 +123,7 @@ subroutine initialize_prototypes(this, unusable, rc)
use MAPL_LlcGridFactoryMod, only: LlcGridFactory
use MAPL_ExternalGridFactoryMod, only: ExternalGridFactory
use MAPL_XYGridFactoryMod, only: XYGridFactory
use MAPL_SwathGridFactoryMod, only : SwathGridFactory

class (GridManager), intent(inout) :: this
class (KeywordEnforcer), optional, intent(in) :: unusable
Expand All @@ -131,7 +135,8 @@ subroutine initialize_prototypes(this, unusable, rc)
type (LlcGridFactory) :: llc_factory
type (ExternalGridFactory) :: external_factory
type (XYGridFactory) :: xy_factory

type (SwathGridFactory) :: swath_factory

! This is a local variable to prevent the subroutine from running
! initialiazation twice. Calling functions have their own local variables
! to prevent calling this subroutine twice, but the initialization status
Expand All @@ -147,6 +152,7 @@ subroutine initialize_prototypes(this, unusable, rc)
call this%prototypes%insert('llc', llc_factory)
call this%prototypes%insert('External', external_factory)
call this%prototypes%insert('XY', xy_factory)
call this%prototypes%insert('Swath', swath_factory)
initialized = .true.
end if

Expand Down Expand Up @@ -397,6 +403,27 @@ function make_factory_from_distGrid(this, grid_type, dist_grid, lon_array, lat_a
end function make_factory_from_distGrid


subroutine destroy_grid(this, grid, unusable, rc)
use ESMF
class (GridManager), target, intent(inout) :: this
type (ESMF_Grid), intent(inout) :: grid
class (KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

integer :: status
integer (kind=ESMF_KIND_I8) :: id
class(AbstractGridFactory), pointer :: factory
type(Integer64GridFactoryMapIterator) :: iter

call ESMF_AttributeGet(grid, factory_id_attribute, id, _RC)
factory => this%factories%at(id)
call factory%destroy(_RC)
iter = this%factories%find(id)
call this%factories%erase(iter)

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end subroutine destroy_grid

! Clients should use this procedure to release ESMF resources when a grid
! is no longer being used.
Expand All @@ -413,15 +440,13 @@ subroutine delete(this, grid, unusable, rc)
integer :: status
character(len=*), parameter :: Iam= MOD_NAME // 'destroy_grid'

_UNUSED_DUMMY(unusable)

if (.not. this%keep_grids) then
call ESMF_GridDestroy(grid, rc=status)
call ESMF_GridDestroy(grid, noGarbage=.true., rc=status)
_ASSERT(status==0,'failed to destroy grid')
end if

_RETURN(_SUCCESS)

_UNUSED_DUMMY(unusable)
end subroutine delete


Expand Down
Loading