From 272ebf367f7b7db77fb8898c02f2bc7f0b3b3837 Mon Sep 17 00:00:00 2001 From: drnimbusrain Date: Thu, 15 Dec 2022 12:58:22 -0500 Subject: [PATCH 01/10] Updated gitmodules for noaa-oar-arl fork. --- .gitmodules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 22c723ac1..b233f40fd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,8 +8,8 @@ branch = main [submodule "ccpp/physics"] path = ccpp/physics - url = https://github.com/ufs-community/ccpp-physics - branch = ufs/dev + url = https://github.com/noaa-oar-arl/ccpp-physics + branch = develop [submodule "upp"] path = upp url = https://github.com/NOAA-EMC/UPP From e8d3584eac2026de5d4c80316a223b7f286324ee Mon Sep 17 00:00:00 2001 From: drnimbusrain Date: Thu, 15 Dec 2022 13:09:10 -0500 Subject: [PATCH 02/10] Updated .gitmodule to our noaa-oar-arl fork. --- .gitmodules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index b233f40fd..d998e58a9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,8 +4,8 @@ branch = dev/emc [submodule "ccpp/framework"] path = ccpp/framework - url = https://github.com/NCAR/ccpp-framework - branch = main + url = https://github.com/noaa-oar-arl/ccpp-framework + branch = develop [submodule "ccpp/physics"] path = ccpp/physics url = https://github.com/noaa-oar-arl/ccpp-physics From abf820cdd2a69741b82f0bd51d347e3864631195 Mon Sep 17 00:00:00 2001 From: Dusan Jovic Date: Thu, 15 Feb 2024 16:40:35 +0000 Subject: [PATCH 03/10] Update diagnose_cplFields routine to use FieldBundleWrite. Needs esmf v8.6.0 --- cpl/module_cap_cpl.F90 | 193 ++++++++++++++++++++++++++++++-------- module_fcst_grid_comp.F90 | 9 +- 2 files changed, 159 insertions(+), 43 deletions(-) diff --git a/cpl/module_cap_cpl.F90 b/cpl/module_cap_cpl.F90 index 313ab6cf6..0fb5660ba 100644 --- a/cpl/module_cap_cpl.F90 +++ b/cpl/module_cap_cpl.F90 @@ -25,13 +25,12 @@ subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & logical, intent(in) :: fcstpe logical, intent(in) :: statewrite_flag integer, intent(in) :: stdiagnose_flag - character(len=*), intent(in) :: state_tag !< Import or export. + character(len=*), intent(in) :: state_tag !< "import" or "export". character(len=*),parameter :: subname='(module_cap_cpl:diagnose_cplFields)' type(ESMF_Time) :: currTime type(ESMF_State) :: state character(len=240) :: timestr - integer :: timeslice = 1 character(len=160) :: nuopcMsg character(len=160) :: filename integer :: rc @@ -54,8 +53,8 @@ subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & ! Dump Fields out if (statewrite_flag) then - write(filename,'(A)') 'fv3_cap_import_'//trim(timestr)//'_' - call State_RWFields_tiles(state,trim(filename), timeslice, rc=rc) + write(filename,'(A)') 'fv3_cap_import_'//trim(timestr)//'.tile*.nc' + call State_RWFields_tiles(state,trim(filename), rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return end if end if @@ -70,8 +69,8 @@ subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & ! Dump Fields out if (statewrite_flag) then - write(filename,'(A)') 'fv3_cap_export_'//trim(timestr)//'_' - call State_RWFields_tiles(state,trim(filename), timeslice, rc=rc) + write(filename,'(A)') 'fv3_cap_export_'//trim(timestr)//'.tile*.nc' + call State_RWFields_tiles(state,trim(filename), rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return end if end if @@ -81,28 +80,36 @@ end subroutine diagnose_cplFields !----------------------------------------------------------------------------- ! This subroutine requires ESMFv8 - for coupled FV3 - subroutine State_RWFields_tiles(state,filename,timeslice,rc) + subroutine State_RWFields_tiles(state,filename,rc) type(ESMF_State), intent(in) :: state character(len=*), intent(in) :: fileName - integer, intent(in) :: timeslice integer, intent(out) :: rc - ! local - type(ESMF_Field) :: firstESMFFLD - type(ESMF_Field),allocatable :: flds(:) - type(ESMF_GridComp) :: IOComp - type(ESMF_Grid) :: gridFv3 - - character(len=256) :: msgString - integer :: i, icount, ifld + ! local variables + type(ESMF_Array) :: array + type(ESMF_Grid) :: grid + type(ESMF_FieldBundle) :: fieldbundle + type(ESMF_Field), allocatable :: flds(:) + type(ESMF_DistGrid) :: distgrid + integer :: i, icount, ifld, id integer :: fieldcount, firstfld + integer :: fieldDimCount, gridDimCount, dimCount, tileCount, ungriddedDimCount character(64), allocatable :: itemNameList(:), fldNameList(:) type(ESMF_StateItem_Flag), allocatable :: typeList(:) + integer, allocatable :: minIndexPTile(:,:), maxIndexPTile(:,:) + integer, allocatable :: ungriddedLBound(:), ungriddedUBound(:) + integer, allocatable :: fieldDimLen(:) + character(len=32), allocatable :: gridded_dim_labels(:), ungridded_dim_labels(:) - character(len=*),parameter :: subname='(module_cap_cpl:State_RWFields_tiles)' + character(16), parameter :: convention = 'NetCDF' + character(16), parameter :: purpose = 'FV3' - ! local variables + integer, parameter :: max_n_axes = 4 + integer, parameter :: max_n_dim = 16 + integer, dimension(max_n_axes, max_n_dim) :: axes_dimcount = 0 + + character(len=*),parameter :: subname='(module_cap_cpl:State_RWFields_tiles)' rc = ESMF_SUCCESS !call ESMF_LogWrite(trim(subname)//trim(filename)//": called", ESMF_LOGMSG_INFO, rc=rc) @@ -119,9 +126,6 @@ subroutine State_RWFields_tiles(state,filename,timeslice,rc) if(typeList(i) == ESMF_STATEITEM_FIELD) firstfld = i if(typeList(i) == ESMF_STATEITEM_FIELD) fieldcount = fieldcount + 1 enddo - !write(msgString,*) trim(subname)//' icount = ',icount," fieldcount = - !",fieldcount," firstfld = ",firstfld - !call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO, rc=rc) allocate(flds(fieldCount),fldNameList(fieldCount)) ifld = 1 @@ -132,37 +136,144 @@ subroutine State_RWFields_tiles(state,filename,timeslice,rc) endif enddo - call ESMF_LogWrite(trim(subname)//": write "//trim(filename)//"tile1-tile6", ESMF_LOGMSG_INFO, rc=rc) - ! get first field - call ESMF_StateGet(state, itemName=itemNameList(firstfld), field=firstESMFFLD, rc=rc) - if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & - line=__LINE__, file=__FILE__)) return ! bail out - - call ESMF_FieldGet(firstESMFFLD, grid=gridFv3, rc=rc) - if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & - line=__LINE__, file=__FILE__)) return ! bail out - - IOComp = ESMFIO_Create(gridFv3, rc=rc) - if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & - line=__LINE__, file=__FILE__)) return ! bail out + call ESMF_LogWrite(trim(subname)//": write "//trim(filename), ESMF_LOGMSG_INFO, rc=rc) do ifld=1, fieldCount call ESMF_StateGet(state, itemName=fldNameList(ifld), field=flds(ifld), rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + call ESMF_FieldGet(flds(ifld), grid=grid, dimCount=fieldDimCount, array=array, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + if (fieldDimCount > 4) then + call ESMF_LogWrite(trim(subname)//": fieldDimCount > 4 unsupported", ESMF_LOGMSG_ERROR, rc=rc) + end if + + call ESMF_GridGet(grid, dimCount=gridDimCount, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + if (gridDimCount > 2) then + call ESMF_LogWrite(trim(subname)//": gridDimCount > 2 unsupported", ESMF_LOGMSG_ERROR, rc=rc) + end if + + call ESMF_ArrayGet(array, distgrid=distgrid, dimCount=dimCount, tileCount=tileCount, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + allocate(fieldDimLen(fieldDimCount)) + + allocate(minIndexPTile(dimCount, tileCount)) + allocate(maxIndexPTile(dimCount, tileCount)) + call ESMF_DistGridGet(distgrid, minIndexPTile=minIndexPTile, maxIndexPTile=maxIndexPTile, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + allocate(gridded_dim_labels(gridDimCount)) + do i = 1, gridDimCount + fieldDimLen(i) = maxIndexPTile(i,1) - minIndexPTile(i,1) + 1 + id = find_axis_id_for_axis_count(i,fieldDimLen(i)) + if (id < 1) then + call ESMF_LogWrite(trim(subname)//": id < 1", ESMF_LOGMSG_ERROR, rc=rc) + endif + if (i == 1) write(gridded_dim_labels(i),'(A,I0)') 'xaxis_',id + if (i == 2) write(gridded_dim_labels(i),'(A,I0)') 'yaxis_',id + end do + + deallocate(minIndexPTile) + deallocate(maxIndexPTile) + + ungriddedDimCount = fieldDimCount - gridDimCount + allocate(ungridded_dim_labels(ungriddedDimCount)) + if (fieldDimCount > gridDimCount) then + allocate(ungriddedLBound(ungriddedDimCount)) + allocate(ungriddedUBound(ungriddedDimCount)) + call ESMF_FieldGet(flds(ifld), ungriddedLBound=ungriddedLBound, ungriddedUBound=ungriddedUBound, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + do i=1,ungriddedDimCount + fieldDimLen(i+gridDimCount) = ungriddedUBound(i) - ungriddedLBound(i) + 1 + id = find_axis_id_for_axis_count(i+gridDimCount, fieldDimLen(i+gridDimCount)) + if (id < 1) then + write(0,*)'stop error', id, i, fieldDimLen(i+gridDimCount) + endif + if (i==1) write(ungridded_dim_labels(i),'(A,I0)') 'zaxis_',id + if (i==2) write(ungridded_dim_labels(i),'(A,I0)') 'taxis_',id + end do + deallocate(ungriddedLBound) + deallocate(ungriddedUBound) + end if + + call ESMF_AttributeAdd(grid, convention=convention, purpose=purpose, attrList=(/ ESMF_ATT_GRIDDED_DIM_LABELS /), rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + call ESMF_AttributeSet(grid, convention=convention, purpose=purpose, & + name=ESMF_ATT_GRIDDED_DIM_LABELS, valueList=gridded_dim_labels, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + if (ungriddedDimCount > 0) then + call ESMF_AttributeAdd(flds(ifld), convention=convention, purpose=purpose, & + attrList=(/ ESMF_ATT_UNGRIDDED_DIM_LABELS /), rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + call ESMF_AttributeSet(flds(ifld), convention=convention, purpose=purpose, & + name=ESMF_ATT_UNGRIDDED_DIM_LABELS, valueList=ungridded_dim_labels, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + end if + + deallocate(fieldDimLen) + deallocate(gridded_dim_labels) + deallocate(ungridded_dim_labels) + enddo - call ESMFIO_Write(IOComp, filename, flds, filePath='./', rc=rc) - if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & - line=__LINE__, file=__FILE__)) return ! bail out + fieldbundle = ESMF_FieldBundleCreate(rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return -! -- Finalize ESMFIO + call ESMF_FieldBundleAdd(fieldbundle, flds, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + + call ESMF_FieldBundleWrite(fieldbundle, fileName=trim(filename), convention=convention, purpose=purpose, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + +! -- Finalize deallocate(flds) deallocate(fldNameList) - call ESMFIO_Destroy(IOComp, rc=rc) - if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, & - line=__LINE__, file=__FILE__)) call ESMF_Finalize() + + call ESMF_FieldBundleDestroy(fieldbundle, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return !call ESMF_LogWrite(trim(subname)//trim(filename)//": finished", ESMF_LOGMSG_INFO, rc=rc) + contains + + function find_axis_id_for_axis_count(axis, count) result(id) + integer, intent(in) :: axis, count + + integer :: id + integer :: i + + id = -1 ! not found + + if (axis > max_n_axes) then + call ESMF_LogWrite('axis > max_n_axes. Increase max_n_axes in '//trim(subname), ESMF_LOGMSG_ERROR) + return + end if + + do i =1, max_n_dim + if (axes_dimcount(axis, i) == 0) then + axes_dimcount(axis, i) = count + id = i + return + else + if (axes_dimcount(axis, i) == count) then + id = i + return + end if + end if + end do + + call ESMF_LogWrite('Increase max_n_dim in '//trim(subname), ESMF_LOGMSG_ERROR) + + end function find_axis_id_for_axis_count + end subroutine State_RWFields_tiles !----------------------------------------------------------------------------- diff --git a/module_fcst_grid_comp.F90 b/module_fcst_grid_comp.F90 index ea622369c..ec39f2e69 100644 --- a/module_fcst_grid_comp.F90 +++ b/module_fcst_grid_comp.F90 @@ -293,8 +293,13 @@ subroutine SetServicesNest(nest, rc) ! Write grid to netcdf file if( cplprint_flag ) then write (myGridStr,"(I0)") mygrid - call wrt_fcst_grid(grid, "diagnostic_FV3_fcstGrid"//trim(mygridStr)//".nc", & - regridArea=.TRUE., rc=rc) + if (trim(name)=="global") then + call wrt_fcst_grid(grid, "diagnostic_FV3_fcstGrid"//trim(mygridStr)//".tile*.nc", & + regridArea=.TRUE., rc=rc) + else + call wrt_fcst_grid(grid, "diagnostic_FV3_fcstGrid"//trim(mygridStr)//".nc", & + regridArea=.TRUE., rc=rc) + end if if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return endif From eddf3592e563f0b5e34de6183478d405394ccf3b Mon Sep 17 00:00:00 2001 From: drnimbusrain Date: Mon, 13 May 2024 16:52:14 +0000 Subject: [PATCH 04/10] Fixed bug in aux2d dimensions for GFS meta file. --- ccpp/data/GFS_typedefs.meta | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ccpp/data/GFS_typedefs.meta b/ccpp/data/GFS_typedefs.meta index 92e2cdf37..59b9f19bd 100644 --- a/ccpp/data/GFS_typedefs.meta +++ b/ccpp/data/GFS_typedefs.meta @@ -9938,7 +9938,7 @@ standard_name = auxiliary_2d_arrays long_name = auxiliary 2d arrays to output (for debugging) units = none - dimensions = (horizontal_loop_extent,number_of_xyz_dimensioned_auxiliary_arrays) + dimensions = (horizontal_loop_extent,number_of_xy_dimensioned_auxiliary_arrays) type = real kind = kind_phys active = (number_of_xy_dimensioned_auxiliary_arrays > 0) From 5a5d095b162b8b8cc7c4b62448bf3a3fb6b5c9b1 Mon Sep 17 00:00:00 2001 From: drnimbusrain Date: Mon, 13 May 2024 16:54:43 +0000 Subject: [PATCH 05/10] Reverting gitmodules. --- .gitmodules | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index d998e58a9..22c723ac1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,12 +4,12 @@ branch = dev/emc [submodule "ccpp/framework"] path = ccpp/framework - url = https://github.com/noaa-oar-arl/ccpp-framework - branch = develop + url = https://github.com/NCAR/ccpp-framework + branch = main [submodule "ccpp/physics"] path = ccpp/physics - url = https://github.com/noaa-oar-arl/ccpp-physics - branch = develop + url = https://github.com/ufs-community/ccpp-physics + branch = ufs/dev [submodule "upp"] path = upp url = https://github.com/NOAA-EMC/UPP From c39e6e577c1029b2a8a5ae43687eabfdbb81bdc2 Mon Sep 17 00:00:00 2001 From: Dusan Jovic Date: Wed, 3 Jul 2024 16:54:48 +0000 Subject: [PATCH 06/10] Pass return code from diagnose_cplFields back to caller --- cpl/module_cap_cpl.F90 | 4 ++-- fv3_cap.F90 | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cpl/module_cap_cpl.F90 b/cpl/module_cap_cpl.F90 index 0a2d677e0..80a84130a 100644 --- a/cpl/module_cap_cpl.F90 +++ b/cpl/module_cap_cpl.F90 @@ -17,7 +17,7 @@ module module_cap_cpl !----------------------------------------------------------------------------- subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & - statewrite_flag, stdiagnose_flag, state_tag) + statewrite_flag, stdiagnose_flag, state_tag, rc) type(ESMF_GridComp), intent(in) :: gcomp type(ESMF_Clock),intent(in) :: clock_fv3 @@ -25,6 +25,7 @@ subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & logical, intent(in) :: statewrite_flag integer, intent(in) :: stdiagnose_flag character(len=*), intent(in) :: state_tag !< "import" or "export". + integer, intent(out) :: rc character(len=*),parameter :: subname='(module_cap_cpl:diagnose_cplFields)' type(ESMF_Time) :: currTime @@ -32,7 +33,6 @@ subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & character(len=240) :: timestr character(len=160) :: nuopcMsg character(len=160) :: filename - integer :: rc ! call ESMF_ClockGet(clock_fv3, currTime=currTime, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return diff --git a/fv3_cap.F90 b/fv3_cap.F90 index 20c2bcc7a..b90692270 100644 --- a/fv3_cap.F90 +++ b/fv3_cap.F90 @@ -1081,7 +1081,8 @@ subroutine ModelAdvance_phase1(gcomp, rc) if( dbug > 0 .or. cplprint_flag ) then fcstpe = .false. if( mype < num_pes_fcst ) fcstpe = .true. - call diagnose_cplFields(gcomp, clock, fcstpe, cplprint_flag, dbug, 'import') + call diagnose_cplFields(gcomp, clock, fcstpe, cplprint_flag, dbug, 'import', rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return endif timep1re = MPI_Wtime() @@ -1235,7 +1236,8 @@ subroutine ModelAdvance_phase2(gcomp, rc) if( dbug > 0 .or. cplprint_flag ) then fcstpe = .false. if( mype < num_pes_fcst ) fcstpe = .true. - call diagnose_cplFields(gcomp, clock_out, fcstpe, cplprint_flag, dbug, 'export') + call diagnose_cplFields(gcomp, clock_out, fcstpe, cplprint_flag, dbug, 'export', rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return end if timep2re = MPI_Wtime() From 53b6b225d2d11844e380589249d5d1dc5a2c4453 Mon Sep 17 00:00:00 2001 From: Dusan Jovic Date: Fri, 5 Jul 2024 14:48:37 +0000 Subject: [PATCH 07/10] Skip 'cpl_scalars' field when dumping export state --- cpl/module_cap_cpl.F90 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cpl/module_cap_cpl.F90 b/cpl/module_cap_cpl.F90 index 80a84130a..cc7d31350 100644 --- a/cpl/module_cap_cpl.F90 +++ b/cpl/module_cap_cpl.F90 @@ -135,6 +135,9 @@ subroutine State_RWFields_tiles(state,filename,rc) endif enddo + fieldbundle = ESMF_FieldBundleCreate(rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + call ESMF_LogWrite(trim(subname)//": write "//trim(filename), ESMF_LOGMSG_INFO, rc=rc) do ifld=1, fieldCount @@ -158,6 +161,13 @@ subroutine State_RWFields_tiles(state,filename,rc) call ESMF_ArrayGet(array, distgrid=distgrid, dimCount=dimCount, tileCount=tileCount, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + ! skip 'cpl_scalars' field because it has tileCount == 1, while all other fields have 6. + ! This causes the following error: + ! 20240705 134459.788 ERROR PET000 ESMCI_IO.C:1614 ESMCI::IO::checkNtiles() Wrong data value - New number of tiles (6) does not match previously-set number of tiles (1) for this IO object. All arrays handled by a given IO object must have the same number of tiles. + if (trim(fldNameList(ifld)) == 'cpl_scalars') then + cycle + endif + allocate(fieldDimLen(fieldDimCount)) allocate(minIndexPTile(dimCount, tileCount)) @@ -221,13 +231,10 @@ subroutine State_RWFields_tiles(state,filename,rc) deallocate(gridded_dim_labels) deallocate(ungridded_dim_labels) - enddo - - fieldbundle = ESMF_FieldBundleCreate(rc=rc) - if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + call ESMF_FieldBundleAdd(fieldbundle, (/flds(ifld)/), rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return - call ESMF_FieldBundleAdd(fieldbundle, flds, rc=rc) - if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + enddo call ESMF_FieldBundleWrite(fieldbundle, fileName=trim(filename), convention=convention, purpose=purpose, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return From 54a3b5cdb43dc048c3a8b6614b7a5cce8349ddef Mon Sep 17 00:00:00 2001 From: Jun Wang Date: Mon, 8 Jul 2024 15:15:03 -0500 Subject: [PATCH 08/10] fix fhzero for GEFS --- atmos_model.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atmos_model.F90 b/atmos_model.F90 index 92fa59742..c3bf1ec45 100644 --- a/atmos_model.F90 +++ b/atmos_model.F90 @@ -815,7 +815,7 @@ subroutine atmos_model_init (Atmos, Time_init, Time, Time_step) if (mpp_pe() == mpp_root_pe()) print *,'in atmos_model, fhzero=',GFS_Control%fhzero, 'fhour=',sec/3600.,sec_lastfhzerofh/3600 if (mod((sec-sec_lastfhzerofh),int(GFS_Control%fhzero*3600.)) /= 0) then - diag_time = Time - real_to_time_type(mod(int((GFS_Control%kdt - 1)*dt_phys-sec_lastfhzerofh),int(GFS_Control%fhzero))*3600.0) + diag_time = Time - real_to_time_type(real(mod(int((GFS_Control%kdt - 1)*dt_phys-sec_lastfhzerofh),int(GFS_Control%fhzero*3600.0)))) if (mpp_pe() == mpp_root_pe()) print *,'Warning: in atmos_init,start at non multiple of fhzero' endif if (Atmos%iau_offset > zero) then From c2f71adfe95465a544796c94e9e63f9bd2cc5bf3 Mon Sep 17 00:00:00 2001 From: Denise Worthen Date: Wed, 17 Jul 2024 09:08:05 -0400 Subject: [PATCH 09/10] fix cpl_scalars (#6) * fix issues w/ cplscalars * error out of all 3 spatial indices are not present * add check for scalar_id = 0 --- cpl/module_cplscalars.F90 | 2 +- fv3_cap.F90 | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cpl/module_cplscalars.F90 b/cpl/module_cplscalars.F90 index 2b3e5869e..481de02be 100644 --- a/cpl/module_cplscalars.F90 +++ b/cpl/module_cplscalars.F90 @@ -116,7 +116,7 @@ subroutine State_SetScalar(scalar_value, scalar_id, State, flds_scalar_name, fld if (mytask == 0) then call ESMF_FieldGet(lfield, farrayPtr = farrayptr, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return - if (scalar_id < 0 .or. scalar_id > flds_scalar_num) then + if (scalar_id <= 0 .or. scalar_id > flds_scalar_num) then call ESMF_LogWrite(trim(subname)//": ERROR in scalar_id", ESMF_LOGMSG_INFO) rc = ESMF_FAILURE return diff --git a/fv3_cap.F90 b/fv3_cap.F90 index b90692270..4d3f999d2 100644 --- a/fv3_cap.F90 +++ b/fv3_cap.F90 @@ -288,7 +288,6 @@ subroutine InitializeAdvertise(gcomp, rc) call ESMF_LogWrite(trim(subname)//' flds_scalar_name = '//trim(flds_scalar_name), ESMF_LOGMSG_INFO) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return endif - call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldCount", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return if (isPresent .and. isSet) then @@ -313,14 +312,23 @@ subroutine InitializeAdvertise(gcomp, rc) call ESMF_LogWrite(trim(subname)//' : flds_scalar_index_ny = '//trim(msgString), ESMF_LOGMSG_INFO) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return endif - call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNTile", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc) - if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return - if (isPresent .and. isSet) then - read(cvalue,*) flds_scalar_index_ntile - write(msgString,*) flds_scalar_index_ntile - call ESMF_LogWrite(trim(subname)//' : flds_scalar_index_ntile = '//trim(msgString), ESMF_LOGMSG_INFO) + ! tile index must be present if indices for nx and ny are non-zero + if (flds_scalar_index_nx /= 0 .and. flds_scalar_index_ny /=0 ) then + call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNTile", isPresent=isPresent, isSet=isSet, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return - endif + if (.not. isPresent .and. .not. isSet) then + if (mype == 0)write(*,*)'ERROR : ScalarFieldIdxGridNTile must be set' + call ESMF_LogWrite('ERROR : ScalarFieldIdxGridNTile must be set', ESMF_LOGMSG_ERROR) + rc = ESMF_FAILURE + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + else + call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNTile", value=cvalue, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + read(cvalue,*) flds_scalar_index_ntile + write(msgString,*) flds_scalar_index_ntile + call ESMF_LogWrite(trim(subname)//' : flds_scalar_index_ntile = '//trim(msgString), ESMF_LOGMSG_INFO) + endif + end if !------------------------------------------------------------------------ ! get config variables From 326803df66fe21238f63d05f8a74555876d619c4 Mon Sep 17 00:00:00 2001 From: Denise Worthen Date: Wed, 17 Jul 2024 11:26:24 -0400 Subject: [PATCH 10/10] modify for timeslices and times (#7) * use import and export time strings * add timeslice --- cpl/module_cap_cpl.F90 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cpl/module_cap_cpl.F90 b/cpl/module_cap_cpl.F90 index cc7d31350..f91e95384 100644 --- a/cpl/module_cap_cpl.F90 +++ b/cpl/module_cap_cpl.F90 @@ -30,13 +30,16 @@ subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & character(len=*),parameter :: subname='(module_cap_cpl:diagnose_cplFields)' type(ESMF_Time) :: currTime type(ESMF_State) :: state - character(len=240) :: timestr + type(ESMF_TimeInterval) :: timeStep + character(len=240) :: import_timestr, export_timestr character(len=160) :: nuopcMsg character(len=160) :: filename ! - call ESMF_ClockGet(clock_fv3, currTime=currTime, rc=rc) + call ESMF_ClockGet(clock_fv3, currTime=currTime, timeStep=timestep, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return - call ESMF_TimeGet(currTime, timestring=timestr, rc=rc) + call ESMF_TimeGet(currTime, timestring=import_timestr, rc=rc) + if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return + call ESMF_TimeGet(currTime+timestep, timestring=export_timestr, rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return call ESMF_ClockPrint(clock_fv3, options="currTime", preString="current time: ", unit=nuopcMsg) @@ -52,7 +55,7 @@ subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & ! Dump Fields out if (statewrite_flag) then - write(filename,'(A)') 'fv3_cap_import_'//trim(timestr)//'.tile*.nc' + write(filename,'(A)') 'fv3_cap_import_'//trim(import_timestr)//'.tile*.nc' call State_RWFields_tiles(state,trim(filename), rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return end if @@ -68,7 +71,7 @@ subroutine diagnose_cplFields(gcomp, clock_fv3, fcstpe, & ! Dump Fields out if (statewrite_flag) then - write(filename,'(A)') 'fv3_cap_export_'//trim(timestr)//'.tile*.nc' + write(filename,'(A)') 'fv3_cap_export_'//trim(export_timestr)//'.tile*.nc' call State_RWFields_tiles(state,trim(filename), rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return end if @@ -236,7 +239,8 @@ subroutine State_RWFields_tiles(state,filename,rc) enddo - call ESMF_FieldBundleWrite(fieldbundle, fileName=trim(filename), convention=convention, purpose=purpose, rc=rc) + call ESMF_FieldBundleWrite(fieldbundle, fileName=trim(filename), convention=convention, purpose=purpose, & + timeslice=1, overwrite=.true., rc=rc) if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return ! -- Finalize