From e1e83a73a7a1ef31e58a67c43f83810673f115d9 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Fri, 15 Aug 2025 09:45:15 -0400 Subject: [PATCH 1/7] added pfaf index to MAPL_Locstream --- CHANGELOG.md | 3 + base/MAPL_LocStreamMod.F90 | 126 ++++++++++++++++++++++--------------- 2 files changed, 79 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ebcb632d54..c1706ed40e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Added pfaf_index to MAPL_Losctream +- Enforced present of grid when reading binary tile file + ### Removed ### Deprecated diff --git a/base/MAPL_LocStreamMod.F90 b/base/MAPL_LocStreamMod.F90 index 37a8963cc2d..c3bdd2d5219 100644 --- a/base/MAPL_LocStreamMod.F90 +++ b/base/MAPL_LocStreamMod.F90 @@ -31,6 +31,7 @@ module MAPL_LocStreamMod use MAPL_HashMod use MAPL_ShmemMod use MAPL_ExceptionHandling +use MAPL_EASEConversion use, intrinsic :: iso_fortran_env, only: REAL64, INT64 use mpi @@ -104,6 +105,7 @@ module MAPL_LocStreamMod type(ESMF_GRID) :: TILEGRID !! the next best thing to LocStream grid integer, pointer :: GLOBAL_Id(:) =>null() !! All Location Ids in file order integer, pointer :: LOCAL_Id (:) =>null() !! Location Ids on local PE + integer, pointer :: pfaf_index(:) =>null() !! tile's pfaf index type(MAPL_GeoLocation), pointer :: Global_GeoLocation (:)=>null() !! All GeoLocations !C type(MAPL_IndexLocation), pointer :: Global_IndexLocation(:)=>null() !C All IndexLocations for attach grid type(MAPL_GeoLocation), pointer :: Local_GeoLocation (:)=>null() !! GeoLocations on local PE @@ -189,7 +191,7 @@ subroutine MAPL_LocStreamGet(LocStream, NT_LOCAL, nt_global, TILETYPE, TILEKIND, TILELONS, TILELATS, TILEAREA, & TILEGRID, & GRIDIM, GRIDJM, GRIDNAMES, & - ATTACHEDGRID, LOCAL_ID, local_i, local_j,RC) + ATTACHEDGRID, LOCAL_ID, local_i, local_j, pfaf_index, RC) type(MAPL_LocStream), intent(IN ) :: LocStream integer, optional, intent( OUT) :: NT_LOCAL integer, optional, pointer :: TILETYPE(:) @@ -208,6 +210,7 @@ subroutine MAPL_LocStreamGet(LocStream, NT_LOCAL, nt_global, TILETYPE, TILEKIND, type(ESMF_Grid), optional, intent( OUT) :: ATTACHEDGRID integer, optional, pointer, intent( OUT) :: local_i(:) integer, optional, pointer, intent( OUT) :: local_j(:) + integer, optional, pointer, intent( OUT) :: pfaf_index(:) integer, optional, intent( OUT) :: RC ! MAT These GFORTRAN workarounds are needed because without them @@ -311,6 +314,10 @@ subroutine MAPL_LocStreamGet(LocStream, NT_LOCAL, nt_global, TILETYPE, TILEKIND, local_j => locstream%Ptr%LOCAL_INDEXLOCATION(:)%j end if + if (present(pfaf_index)) then + pfaf_index => locstream%Ptr%pfaf_index + end if + _RETURN(ESMF_SUCCESS) end subroutine MAPL_LocStreamGet @@ -355,14 +362,16 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, integer(kind=1) :: byte(4) integer :: I1, IN, J1, JN, N_Grids, N_PfafCat integer :: iostat, filetype - logical :: isascii, isnc4, isbinary + logical :: isascii, isnc4, isbinary, isEASE logical :: read_always logical, pointer :: ISMINE(:) type(MAPL_Tiling ), pointer :: TILING - type (ESMF_VM) :: vm + type (ESMF_VM) :: vm logical :: NewGridNames_ integer :: hdr(2) - + integer, allocatable :: pfaf_index(:) + real, allocatable :: tile_area(:) + real :: cell_area #ifdef NEW_INTERP_CODE integer :: isc, iec, jsc, jec integer :: isd, ied, jsd, jed @@ -447,8 +456,10 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, allocate(STREAM%TILING(STREAM%N_GRIDS), STAT=STATUS) _VERIFY(STATUS) + isEASE = .false. do N = 1, N_Grids STREAM%TILING(N)%NAME = GridNames(N) + if(index(STREAM%TILING(N)%NAME,'EASE') /=0 ) isEASE = .true. if (NewGridNames_) then call GenOldGridName_(STREAM%TILING(N)%NAME) end if @@ -463,12 +474,10 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, end if ! adjust EASE grid starting index. Internally, the starting index is 1 instead of 0. - do N=1,STREAM%N_GRIDS - if(index(STREAM%TILING(N)%NAME,'EASE') /=0 ) then - AVR(:,NumGlobalVars+1+NumLocalVars*(N-1)) = AVR(:,NumGlobalVars+1+NumLocalVars*(N-1))+1 - AVR(:,NumGlobalVars+2+NumLocalVars*(N-1)) = AVR(:,NumGlobalVars+2+NumLocalVars*(N-1))+1 - endif - enddo + if (isEASE) then + AVR(:,NumGlobalVars+1) = AVR(:,NumGlobalVars+1)+1 + AVR(:,NumGlobalVars+2) = AVR(:,NumGlobalVars+2)+1 + endif !if (use_pfaf_) then !AVR(:,NumGlobalVars+2+NumLocalVars) = 1 @@ -566,6 +575,8 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, _VERIFY(STATUS) allocate(STREAM%GLOBAL_GEOLOCATION(STREAM%NT_GLOBAL), STAT=STATUS) _VERIFY(STATUS) + allocate(STREAM%pfaf_index(STREAM%NT_GLOBAL), STAT=STATUS) + _VERIFY(STATUS) !C do N=1,STREAM%N_GRIDS !C allocate(STREAM%TILING(N)%GLOBAL_IndexLocation(STREAM%NT_GLOBAL), STAT=STATUS) @@ -575,6 +586,18 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, ! Fill global stream parameters subject to mask !---------------------------------------------- + allocate(tile_area(STREAM%NT_GLOBAL)) + allocate(pfaf_index(STREAM%NT_GLOBAL)) + if (isEASE) then + ! i, k is dummy here + call MAPL_ease_extent(STREAM%TILING(1)%NAME, i, k, cell_area=cell_area) + tile_area = AVR(:,7)*cell_area ! the 7th column is frac_cell + pfaf_index = int(AVR(:,2)) + else + tile_area = AVR(:,2) + pfaf_index = int(AVR(:,9)) + endif + K = 0 do I=1, NT if(MSK(I)) then @@ -582,9 +605,11 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, STREAM%GLOBAL_ID (K) = I STREAM%GLOBAL_GeoLocation(K)%T = nint(AVR(I,1)) !if (STREAM%GLOBAL_GeoLocation(K)%T < 0) STREAM%GLOBAL_GeoLocation(K)%T = MAPL_Ocean - STREAM%GLOBAL_GeoLocation(K)%A = AVR(I,2) + STREAM%GLOBAL_GeoLocation(K)%A = tile_area(I) STREAM%GLOBAL_GeoLocation(K)%X = AVR(I,3) * (MAPL_PI/180.) STREAM%GLOBAL_GeoLocation(K)%Y = AVR(I,4) * (MAPL_PI/180.) + STREAM%pfaf_index(K) = pfaf_index(I) + !C X = AVR(I,3) !C Y = AVR(I,4) !C do N=1,STREAM%N_GRIDS @@ -601,6 +626,7 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, deallocate(AVR) else ! BINARY + _ASSERT(present(grid), "Grid must be present for binary file") ! Open file and read header info !------------------------------- @@ -707,45 +733,45 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, ! Fill ISMINE (Pick off local tiles) !------------------------------------ - if (present(GRID)) then - do N=1,STREAM%N_GRIDS - if (read_always .or. gname == STREAM%TILING(N)%NAME) then - call MAPL_SyncSharedMemory(RC=STATUS); _VERIFY(STATUS) - if ( MAPL_am_I_root() ) read(UNIT) AVR - call MAPL_BcastShared(vm, DATA=AVR, N=NT, ROOT=0, RootOnly=.false., RC=status) - K = 0 - do I=1, NT - if(MSK(I)) then - K = K + 1 - if (gname==STREAM%TILING(N)%NAME) then - ISMINE(K) = (I1<=nint(AVR(I,1)) .and. IN>=nint(AVR(I,1))) - endif - end if - end do - call MAPL_SyncSharedMemory(RC=STATUS); _VERIFY(STATUS) - if ( MAPL_am_I_root() ) read(UNIT) AVR - call MAPL_BcastShared(vm, DATA=AVR, N=NT, ROOT=0, RootOnly=.false., RC=status) - !if (use_pfaf_) avr(:,1)=1 - K = 0 - do I=1, NT - if(MSK(I)) then - K = K + 1 - if ((gname==STREAM%TILING(N)%NAME) .and. (ISMINE(K))) then - ISMINE(K) = (J1<=nint(AVR(I,1)) .and. JN>=nint(AVR(I,1))) - endif - end if - end do - if ( MAPL_am_I_root() ) read(UNIT) - else - if ( MAPL_am_I_root() ) read(UNIT) - if ( MAPL_am_I_root() ) read(UNIT) - if ( MAPL_am_I_root() ) read(UNIT) - endif - end do - STREAM%NT_LOCAL = count(ISMINE) - allocate(STREAM%LOCAL_IndexLocation(STREAM%NT_LOCAL), STAT=STATUS) - _VERIFY(STATUS) - end if + if (present(GRID)) then + do N=1,STREAM%N_GRIDS + if (read_always .or. gname == STREAM%TILING(N)%NAME) then + call MAPL_SyncSharedMemory(RC=STATUS); _VERIFY(STATUS) + if ( MAPL_am_I_root() ) read(UNIT) AVR + call MAPL_BcastShared(vm, DATA=AVR, N=NT, ROOT=0, RootOnly=.false., RC=status) + K = 0 + do I=1, NT + if(MSK(I)) then + K = K + 1 + if (gname==STREAM%TILING(N)%NAME) then + ISMINE(K) = (I1<=nint(AVR(I,1)) .and. IN>=nint(AVR(I,1))) + endif + end if + end do + call MAPL_SyncSharedMemory(RC=STATUS); _VERIFY(STATUS) + if ( MAPL_am_I_root() ) read(UNIT) AVR + call MAPL_BcastShared(vm, DATA=AVR, N=NT, ROOT=0, RootOnly=.false., RC=status) + !if (use_pfaf_) avr(:,1)=1 + K = 0 + do I=1, NT + if(MSK(I)) then + K = K + 1 + if ((gname==STREAM%TILING(N)%NAME) .and. (ISMINE(K))) then + ISMINE(K) = (J1<=nint(AVR(I,1)) .and. JN>=nint(AVR(I,1))) + endif + end if + end do + if ( MAPL_am_I_root() ) read(UNIT) + else + if ( MAPL_am_I_root() ) read(UNIT) + if ( MAPL_am_I_root() ) read(UNIT) + if ( MAPL_am_I_root() ) read(UNIT) + endif + end do + STREAM%NT_LOCAL = count(ISMINE) + allocate(STREAM%LOCAL_IndexLocation(STREAM%NT_LOCAL), STAT=STATUS) + _VERIFY(STATUS) + end if if ( MAPL_am_I_root() ) then rewind(UNIT) From 9f2da3f4bee2b03f9ee854a30cded8c41d5699e9 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Tue, 19 Aug 2025 13:17:05 -0400 Subject: [PATCH 2/7] change pfaf_index to local --- base/MAPL_LocStreamMod.F90 | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/base/MAPL_LocStreamMod.F90 b/base/MAPL_LocStreamMod.F90 index c3bdd2d5219..b7f347ca2d8 100644 --- a/base/MAPL_LocStreamMod.F90 +++ b/base/MAPL_LocStreamMod.F90 @@ -106,6 +106,7 @@ module MAPL_LocStreamMod integer, pointer :: GLOBAL_Id(:) =>null() !! All Location Ids in file order integer, pointer :: LOCAL_Id (:) =>null() !! Location Ids on local PE integer, pointer :: pfaf_index(:) =>null() !! tile's pfaf index + integer, pointer :: global_pfaf_index(:) =>null() !! global tile's pfaf index temporary holders type(MAPL_GeoLocation), pointer :: Global_GeoLocation (:)=>null() !! All GeoLocations !C type(MAPL_IndexLocation), pointer :: Global_IndexLocation(:)=>null() !C All IndexLocations for attach grid type(MAPL_GeoLocation), pointer :: Local_GeoLocation (:)=>null() !! GeoLocations on local PE @@ -473,10 +474,19 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, STREAM%TILING(2)%name = "CATCHMENT_GRID" end if + allocate(tile_area(NT)) + allocate(pfaf_index(NT)) ! adjust EASE grid starting index. Internally, the starting index is 1 instead of 0. if (isEASE) then AVR(:,NumGlobalVars+1) = AVR(:,NumGlobalVars+1)+1 AVR(:,NumGlobalVars+2) = AVR(:,NumGlobalVars+2)+1 + ! i, k are dummy here + call MAPL_ease_extent(STREAM%TILING(1)%NAME, i, k, cell_area=cell_area) + tile_area = AVR(:,7)*cell_area ! the 7th column is frac_cell + pfaf_index = int(AVR(:,2)) + else + tile_area = AVR(:,2) + pfaf_index = int(AVR(:,9)) endif !if (use_pfaf_) then @@ -575,7 +585,7 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, _VERIFY(STATUS) allocate(STREAM%GLOBAL_GEOLOCATION(STREAM%NT_GLOBAL), STAT=STATUS) _VERIFY(STATUS) - allocate(STREAM%pfaf_index(STREAM%NT_GLOBAL), STAT=STATUS) + allocate(STREAM%global_pfaf_index(STREAM%NT_GLOBAL), STAT=STATUS) _VERIFY(STATUS) !C do N=1,STREAM%N_GRIDS @@ -586,17 +596,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, ! Fill global stream parameters subject to mask !---------------------------------------------- - allocate(tile_area(STREAM%NT_GLOBAL)) - allocate(pfaf_index(STREAM%NT_GLOBAL)) - if (isEASE) then - ! i, k is dummy here - call MAPL_ease_extent(STREAM%TILING(1)%NAME, i, k, cell_area=cell_area) - tile_area = AVR(:,7)*cell_area ! the 7th column is frac_cell - pfaf_index = int(AVR(:,2)) - else - tile_area = AVR(:,2) - pfaf_index = int(AVR(:,9)) - endif K = 0 do I=1, NT @@ -608,7 +607,7 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, STREAM%GLOBAL_GeoLocation(K)%A = tile_area(I) STREAM%GLOBAL_GeoLocation(K)%X = AVR(I,3) * (MAPL_PI/180.) STREAM%GLOBAL_GeoLocation(K)%Y = AVR(I,4) * (MAPL_PI/180.) - STREAM%pfaf_index(K) = pfaf_index(I) + STREAM%global_pfaf_index(K) = pfaf_index(I) !C X = AVR(I,3) !C Y = AVR(I,4) @@ -619,9 +618,7 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, !C end do end if end do - STREAM%IsTileAreaValid = .true. - deallocate(MSK) deallocate(AVR) else @@ -868,6 +865,8 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, _VERIFY(STATUS) allocate(STREAM%D (-1:1,-1:1,STREAM%NT_LOCAL), STAT=STATUS) _VERIFY(STATUS) + allocate(STREAM%pfaf_index (STREAM%NT_LOCAL), STAT=STATUS) + _VERIFY(STATUS) end if ! For flat files we economize on space by rereading the file to get @@ -982,9 +981,11 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, if(present(GRID)) then STREAM%LOCAL_GeoLocation = pack(STREAM%GLOBAL_GeoLocation, ISMINE) STREAM%LOCAL_ID = pack(STREAM%GLOBAL_ID, ISMINE) + STREAM%pfaf_index = pack(STREAM%GLOBAL_pfaf_index, ISMINE) deallocate(STREAM%GLOBAL_GeoLocation) deallocate(Stream%Global_id) + deallocate(Stream%Global_pfaf_index) end if endif @@ -1355,7 +1356,6 @@ subroutine MAPL_LocStreamCreateFromStream(LocStreamOut, LocStreamIn, NAME, MASK, ! Begin !------ - _ASSERT( associated(LocStreamIn %Ptr),'needs informative message') ! Allocate the Location Stream @@ -1436,6 +1436,8 @@ subroutine MAPL_LocStreamCreateFromStream(LocStreamOut, LocStreamIn, NAME, MASK, _VERIFY(STATUS) allocate(STREAMOUT%D(-1:1,-1:1,STREAMOUT%NT_LOCAL), STAT=STATUS) _VERIFY(STATUS) + allocate(STREAMOUT%pfaf_index(STREAMOUT%NT_LOCAL), STAT=STATUS) + _VERIFY(STATUS) ! Fill local stream parameters subject to mask !---------------------------------------------- @@ -1455,10 +1457,12 @@ subroutine MAPL_LocStreamCreateFromStream(LocStreamOut, LocStreamIn, NAME, MASK, STREAMOUT%LOCAL_IndexLocation(K)%W = STREAMIN%LOCAL_IndexLocation(I)%W STREAMOUT%D(:,:,K) = STREAMIN%D(:,:,I) + STREAMOUT%pfaf_index (K) = STREAMIN%pfaf_index (I) end if end do deallocate(MSK) + ! Create a tile grid !------------------- call MAPL_LocStreamCreateTileGrid(LocStreamOut, STREAMIN%GRID, RC=status) @@ -2824,7 +2828,6 @@ integer function GRIDINDEX(STREAM,GRID,RC) _VERIFY(STATUS) GridIndex = 0 - do N=1,STREAM%N_GRIDS if(STREAM%TILING(N)%NAME==NAME) then GridIndex = N From 9150e99de01e2e9bf3d50e7674464fa667d8eca2 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Mon, 25 Aug 2025 14:09:48 -0400 Subject: [PATCH 3/7] add a simple mapl_locstream --- base/MAPL_LocStreamMod.F90 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/base/MAPL_LocStreamMod.F90 b/base/MAPL_LocStreamMod.F90 index b7f347ca2d8..a06db2f5dd7 100644 --- a/base/MAPL_LocStreamMod.F90 +++ b/base/MAPL_LocStreamMod.F90 @@ -146,6 +146,7 @@ module MAPL_LocStreamMod interface MAPL_LocStreamCreate module procedure MAPL_LocStreamCreateFromFile module procedure MAPL_LocStreamCreateFromStream + module procedure MAPL_LocStreamCreateSimple end interface interface MAPL_LocStreamTransform @@ -2960,4 +2961,33 @@ subroutine MAPL_GridCoordAdjust(GRID, LOCSTREAM, RC) end subroutine MAPL_GridCoordAdjust +!A special subroutine for Nx1 Grid in river-routing grid comp +!Some information in the locstream is not filled +subroutine MAPL_LocstreamCreateSimple(Locstream, grid, rc) + type(MAPL_LocStream), intent(OUT) :: LocStream + type(ESMF_Grid), intent(inout) :: grid + integer, optional, intent(out) :: rc + integer :: status, i, i1, i2, j1, j2 + type(MAPL_LocStreamType), pointer :: STREAM + integer :: globalCount(3) + + LocStream%Ptr => null() + allocate(LocStream%Ptr, STAT=STATUS) + _VERIFY(STATUS) + + stream => LocStream%Ptr + stream%grid = grid + call MAPL_grid_interior(grid, i1, i2, j1, j2) + _ASSERT( j1 == 1 .and. j2 ==1, "This simple Locstream is for Nx1 grid") + allocate(stream%local_id, source = [(i, i = i1, i2)]) + stream%nt_local = i2 - i1 + 1 + call MAPL_GridGet(grid,globalCellCountPerDim=globalCount,rc=status) + _VERIFY(STATUS) + stream%nt_global = globalCount(1) + call MAPL_LocStreamCreateTileGrid(LocStream, grid, RC=status) + _VERIFY(STATUS) + + _RETURN(ESMF_SUCCESS) +end subroutine MAPL_LocStreamCreateSimple + end module MAPL_LocStreamMod From b99acbab2b9c3982cc53b67d3ca128517ae1cc24 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Wed, 10 Sep 2025 14:08:38 -0400 Subject: [PATCH 4/7] remove use_pfaf --- base/MAPL_LocStreamMod.F90 | 67 ++++++++------------------------------ 1 file changed, 13 insertions(+), 54 deletions(-) diff --git a/base/MAPL_LocStreamMod.F90 b/base/MAPL_LocStreamMod.F90 index a06db2f5dd7..3c9fc613c88 100644 --- a/base/MAPL_LocStreamMod.F90 +++ b/base/MAPL_LocStreamMod.F90 @@ -106,7 +106,6 @@ module MAPL_LocStreamMod integer, pointer :: GLOBAL_Id(:) =>null() !! All Location Ids in file order integer, pointer :: LOCAL_Id (:) =>null() !! Location Ids on local PE integer, pointer :: pfaf_index(:) =>null() !! tile's pfaf index - integer, pointer :: global_pfaf_index(:) =>null() !! global tile's pfaf index temporary holders type(MAPL_GeoLocation), pointer :: Global_GeoLocation (:)=>null() !! All GeoLocations !C type(MAPL_IndexLocation), pointer :: Global_IndexLocation(:)=>null() !C All IndexLocations for attach grid type(MAPL_GeoLocation), pointer :: Local_GeoLocation (:)=>null() !! GeoLocations on local PE @@ -114,7 +113,6 @@ module MAPL_LocStreamMod type(MAPL_Tiling), pointer :: Tiling(:) =>null() !! Grid associated tilings real, pointer :: D(:,:,:)=>null() !! Bilinear weights logical :: IsTileAreaValid - integer :: pfafstetter_catchments end type MAPL_LocStreamType type MAPL_LocStreamXformType @@ -331,7 +329,7 @@ end subroutine MAPL_LocStreamGet ! later in various ways. Currently we only decompose it by ! "attaching" it to a decomposed grid. ! - subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, GRID, NewGridNames, use_pfaf, RC) + subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, GRID, NewGridNames, RC) !ARGUMENTS: type(MAPL_LocStream), intent( OUT) :: LocStream @@ -341,7 +339,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, integer, optional, intent(IN ) :: MASK(:) type(ESMF_Grid), optional, intent(INout) :: GRID logical, optional, intent(IN ) :: NewGridNames - logical, optional, intent(In ) :: use_pfaf integer, optional, intent( OUT) :: RC ! Local variables @@ -371,7 +368,7 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, type (ESMF_VM) :: vm logical :: NewGridNames_ integer :: hdr(2) - integer, allocatable :: pfaf_index(:) + integer, allocatable :: pfaf_index(:), global_pfaf_index(:) real, allocatable :: tile_area(:) real :: cell_area #ifdef NEW_INTERP_CODE @@ -381,7 +378,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, real, pointer :: lons(:,:), lats(:,:) real, allocatable :: hlons(:,:), hlats(:,:) #endif - logical :: use_pfaf_ ! Begin !------ @@ -390,11 +386,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, if (present(NewGridNames)) then NewGridNames_ = NewGridNames end if - if (present(use_pfaf)) then - use_pfaf_=use_pfaf - else - use_pfaf_=.false. - end if ! Allocate the Location Stream !----------------------------- @@ -428,7 +419,7 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, if (isnc4) then if (MAPL_AM_I_root()) then - call MAPL_ReadTilingNC4(FILENAME, GridName=GridNames, IM=IMs, JM=JMs, N_Grids=N_Grids, N_PfafCat=N_PfafCat, AVR=AVR, _RC) + call MAPL_ReadTilingNC4(FILENAME, GridName=GridNames, IM=IMs, JM=JMs, N_Grids=N_Grids, AVR=AVR, _RC) NT = size(AVR,1) endif call MAPL_CommsBcast(layout, NT, 1, MAPL_Root, status) @@ -436,10 +427,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, call MAPL_CommsBcast(layout, IMs, 2, MAPL_Root, status) call MAPL_CommsBcast(layout, JMs, 2, MAPL_Root, status) - if (use_pfaf_) then - call MAPL_CommsBcast(layout, N_PfafCat, 1, MAPL_Root, status) - endif - do N = 1, N_Grids call MAPL_CommsBcast(layout, GridNames(N), MAPL_TileNameLength, MAPL_Root, status) enddo @@ -468,12 +455,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, STREAM%TILING(N)%IM = IMs(N) STREAM%TILING(N)%JM = JMs(N) enddo - if (use_pfaf_) then - stream%pfafstetter_catchments = N_PfafCat - STREAM%TILING(2)%IM = stream%pfafstetter_catchments - STREAM%TILING(2)%JM = 1 - STREAM%TILING(2)%name = "CATCHMENT_GRID" - end if allocate(tile_area(NT)) allocate(pfaf_index(NT)) @@ -490,10 +471,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, pfaf_index = int(AVR(:,9)) endif - !if (use_pfaf_) then - !AVR(:,NumGlobalVars+2+NumLocalVars) = 1 - !end if - ! Allocate msk for which tiles to include in the stream being created. !-------------------------------------------------------------------- @@ -541,13 +518,8 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, if(MSK(I)) then K = K + 1 II = nint(AVR(I,NumGlobalVars+1+NumLocalVars*(N-1))) - if (use_pfaf_ .and. (n==2)) then - !JJ = nint(AVR(I,NumGlobalVars+2+NumLocalVars*(N-1))) - JJ = 1 - else - JJ = nint(AVR(I,NumGlobalVars+2+NumLocalVars*(N-1))) - !JJ=1 - end if + JJ = nint(AVR(I,NumGlobalVars+2+NumLocalVars*(N-1))) + ISMINE(K) = I1<=II .and. IN>=II .and. & J1<=JJ .and. JN>=JJ endif @@ -586,7 +558,7 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, _VERIFY(STATUS) allocate(STREAM%GLOBAL_GEOLOCATION(STREAM%NT_GLOBAL), STAT=STATUS) _VERIFY(STATUS) - allocate(STREAM%global_pfaf_index(STREAM%NT_GLOBAL), STAT=STATUS) + allocate(global_pfaf_index(STREAM%NT_GLOBAL), STAT=STATUS) _VERIFY(STATUS) !C do N=1,STREAM%N_GRIDS @@ -608,7 +580,7 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, STREAM%GLOBAL_GeoLocation(K)%A = tile_area(I) STREAM%GLOBAL_GeoLocation(K)%X = AVR(I,3) * (MAPL_PI/180.) STREAM%GLOBAL_GeoLocation(K)%Y = AVR(I,4) * (MAPL_PI/180.) - STREAM%global_pfaf_index(K) = pfaf_index(I) + global_pfaf_index(K) = pfaf_index(I) !C X = AVR(I,3) !C Y = AVR(I,4) @@ -633,14 +605,8 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, ! Total number of tiles in exchange grid !--------------------------------------- - if (use_pfaf_) then - if ( MAPL_am_I_root() ) read(UNIT) NT,stream%pfafstetter_catchments - call MAPL_CommsBcast(vm, DATA=NT, N=1, ROOT=0, RC=status) - call MAPL_CommsBcast(vm, DATA=stream%pfafstetter_catchments, N=1, ROOT=0, RC=status) - else - if ( MAPL_am_I_root() ) read(UNIT) NT - call MAPL_CommsBcast(vm, DATA=NT, N=1, ROOT=0, RC=status) - end if + if ( MAPL_am_I_root() ) read(UNIT) NT + call MAPL_CommsBcast(vm, DATA=NT, N=1, ROOT=0, RC=status) ! Number of grids that can be attached !------------------------------------- @@ -670,11 +636,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, call MAPL_CommsBcast(vm, DATA=STREAM%TILING(N)%IM, N=1, ROOT=0, RC=status) call MAPL_CommsBcast(vm, DATA=STREAM%TILING(N)%JM, N=1, ROOT=0, RC=status) enddo - if (use_pfaf_) then - STREAM%TILING(2)%IM = stream%pfafstetter_catchments - STREAM%TILING(2)%JM = 1 - STREAM%TILING(2)%name = "CATCHMENT_GRID" - end if ! Read location stream file into AVR !--------------------------------------- @@ -749,7 +710,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, call MAPL_SyncSharedMemory(RC=STATUS); _VERIFY(STATUS) if ( MAPL_am_I_root() ) read(UNIT) AVR call MAPL_BcastShared(vm, DATA=AVR, N=NT, ROOT=0, RootOnly=.false., RC=status) - !if (use_pfaf_) avr(:,1)=1 K = 0 do I=1, NT if(MSK(I)) then @@ -814,7 +774,6 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, call MAPL_BcastShared(vm, DATA=AVR, N=NT, ROOT=0, RootOnly=.false., RC=status) K = 0 L = 0 - !if (use_pfaf_) avr(:,1)=1 do I=1, NT if(MSK(I)) then K = K + 1 @@ -978,20 +937,20 @@ subroutine MAPL_LocStreamCreateFromFile(LocStream, LAYOUT, FILENAME, NAME, MASK, DEALOC__(MSK) DEALOC_(AVR) - else ! .not.isascii + else ! .not. binary if(present(GRID)) then STREAM%LOCAL_GeoLocation = pack(STREAM%GLOBAL_GeoLocation, ISMINE) STREAM%LOCAL_ID = pack(STREAM%GLOBAL_ID, ISMINE) - STREAM%pfaf_index = pack(STREAM%GLOBAL_pfaf_index, ISMINE) + STREAM%pfaf_index = pack(GLOBAL_pfaf_index, ISMINE) deallocate(STREAM%GLOBAL_GeoLocation) deallocate(Stream%Global_id) - deallocate(Stream%Global_pfaf_index) + deallocate(Global_pfaf_index) end if endif - if(present(Grid) .and. (.not.use_pfaf_)) then ! A grid was attached + if(present(Grid)) then ! A grid was attached deallocate(ISMINE) DoCoeffs = .true. From a7ea4eb8818d145bc6647982c9917674c614ffd5 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Thu, 30 Oct 2025 10:36:21 -0400 Subject: [PATCH 5/7] Fix Changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8308d74f4c3..e0066d74b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,14 +16,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix a misspelled `MAPL_LIBRARY_TYPE` in `vertical` ### Added -- Added updated version of `MAPL_GridCompSpecs_ACG_writer.py` +- Added updated version of `MAPL_GridCompSpecs_ACG_writer.py` - Added 'Gridname' attribute to history output - Create TilgridIO's outbundle from output grid and deallocate mGriddedIO in History - Added TileGridIO.F90 to output NC4 History file in tile space. The collection's format should be 'CFIO' ### Changed +- Added `pfaf_index` to `MAPL_Losctream` +- Enforced present of grid when reading binary tile file - Update CI to use Baselibs 8.20.0 - Add gcc15 test - Update CI to use organization reusable workflows @@ -84,8 +86,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Added pfaf_index to MAPL_Losctream -- Enforced present of grid when reading binary tile file - Updated the default `VERSION` in History to `1` (which has been the effective default in `HISTORY.rc` for some time) - Update `components.yaml` - `ESMA_env` v5.13.0 From f17f32b7d2b8e6263f0dfca480a468c18de5140b Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Wed, 3 Dec 2025 13:30:04 -0500 Subject: [PATCH 6/7] Fix typo in CHANGELOG.md for grid enforcement --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba162fc9ac5..c7b64599982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `pfaf_index` to `MAPL_Losctream` -- Enforced present of grid when reading binary tile file +- Enforced presence of `grid` when reading binary tile file - Added a simple MAPL_LosctreamCreate ### Changed From 83af781d027301154e1f791c0c256279585476e0 Mon Sep 17 00:00:00 2001 From: Matthew Thompson Date: Fri, 5 Dec 2025 09:31:37 -0500 Subject: [PATCH 7/7] Prepare for 2.64.0 release --- CHANGELOG.md | 15 +++++++++++---- CMakeLists.txt | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7b64599982..34402d12b4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,16 +11,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Added `pfaf_index` to `MAPL_Losctream` -- Enforced presence of `grid` when reading binary tile file -- Added a simple MAPL_LosctreamCreate - ### Changed ### Removed ### Deprecated +## [2.64.0] - 2025-12-05 + +### Added + +- Added `pfaf_index` to `MAPL_Losctream` +- Added a simple MAPL_LosctreamCreate + +### Changed + +- Enforced presence of `grid` when reading binary tile file + ## [2.63.1] - 2025-11-25 ### Changed diff --git a/CMakeLists.txt b/CMakeLists.txt index 9974a03ee36..af1adf84c3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ endif () project ( MAPL - VERSION 2.63.1 + VERSION 2.64.0 LANGUAGES Fortran CXX C) # Note - CXX is required for ESMF # Set the possible values of build type for cmake-gui