diff --git a/CHANGELOG.md b/CHANGELOG.md index d7120e6f..a53a08c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added obslog output for H SAF ASCAT and CYGNSS L3 soil moisture, with quoted filenames where needed ([PR #242](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/242)). - Added functionality to generate perturbations on sphere ([PR #187](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/187)). +- Added assimilation of VIIRS snow cover fraction obs (VJ110C1, VJ210C1, VNP10C1; hdf5 reader); original obs file names are written to the obslog ([PR #260](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/260)). - Added Python version of obs scaling scripts ([PR #228](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/228)). - Added support for M21C date/time formatting in post-processing of HISTORY output ([PR #229](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/229)). - Improved error handling in preprocessor for SMOS obs ([PR #212](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/212)). @@ -20,16 +21,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Refactored ldas_setup +- Changed Python ObsFcstAna stats maps (`tile_to_latlongrid.py`, `Plot_stats_maps.py`) to weight tiles by area (changes plots and spatial averages only) ([PR #262](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/262)). - Changed MATLAB obs scaling scripts to read nc4 ObsFcstAna files ([PR #227](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/227)). - Updated [x,y]corr values for HSAF ASCAT soil moisture obs in LDASsa_DEFAULT_inputs_ensupd.nml ([PR #235](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/235)). ### Fixed -- Fixed `frac_cell` and units of `area` in tile_coord when reading nc4 tile file in preprocessing (not 0-diff for nc4 tile files; 0-diff for *.til ASCII tile files). -- Fixed double assimilation of MODIS SCF obs for tiles whose center longitude is exactly on the boundary between two assimilation windows (not 0-diff for EASEv2 M36 and CF0360) ([PR #240](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/240)). +- Fixed obs-to-tile mapping in cube-sphere tile space (not 0-diff for assimilation in cube-sphere tile space) ([PR #252](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/252)). +- Fixed obs-to-tile mapping of SMAP Tb, SMOS Tb, and CYGNSS soil moisture obs on EASEv2 M36 when used with EASEv2 M09/M03/M01 tile space (not 0-diff for M09 tile space with CYGNSS obs or M03/M01 tile space with SMAP/SMOS/CYGNSS obs) ([PR #257](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/257), [PR #259](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/259)). +- Fixed NAG build on macOS (GEOSlandassim) ([PR #244](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/244)). +- Fixed out-of-bounds copies of per-tile data in LandPert (`i_indgs`, `j_indgs`) and LandAssim (`f_num`) when `tile_coord` contains lake and land ice tiles in addition to land tiles ([PR #254](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/254)). +- Fixed QC of Tb obs for non-land surfaces (water, landice) in cube-sphere tile space (not 0-diff for cube-sphere tile space with Tb obs) ([PR #249](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/249), [PR #259](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/259)). +- Fixed `frac_cell` and units of `area` in tile_coord when reading nc4 tile file in preprocessing (not 0-diff when using nc4 tile file) ([PR #247](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/247)). +- Fixed double assimilation of MODIS SCF obs for tiles whose center longitude is exactly on the boundary between two assimilation windows (not 0-diff for MODIS SCF assimilation) ([PR #240](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/240)). - Fixed bugs in MATLAB obs scaling parameter scripts (not 0-diff for lat/lon grid) ([PR #227](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/227)). - Fixed string and no-data obs handling in read_GEOSldas.py ([PR #228](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/228)). - Fixed assignment of angles in obs_param structure ([PR #233](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/233)). - Standardized units strings in LDASsa_DEFAULT_inputs_ensupd.nml ([PR #233](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/233)). +- Fixed segmentation fault in the generation of perturbations when MKL is not available (e.g., macOS builds) ([PR #255](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/255)). +- Fixed `process_hist.csh` for BSD `sed` (macOS) ([PR #255](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/255)). ### Removed diff --git a/GEOS_LdasGridComp.F90 b/GEOS_LdasGridComp.F90 index d16b83e1..dbbd8380 100644 --- a/GEOS_LdasGridComp.F90 +++ b/GEOS_LdasGridComp.F90 @@ -8,7 +8,7 @@ module GEOS_LdasGridCompMod use ESMF use MAPL - + use GEOS_MetforceGridCompMod, only: MetforceSetServices => SetServices use GEOS_LandGridCompMod, only: LandSetServices => SetServices use GEOS_LandPertGridCompMod, only: LandPertSetServices => SetServices @@ -39,13 +39,13 @@ module GEOS_LdasGridCompMod use StieglitzSnow, only: StieglitzSnow_echo_constants use SurfParams, only: SurfParams_init use mapl_StateMerge_mod, only: StateMerge - + implicit none private ! !PUBLIC MEMBER FUNCTIONS: - + public SetServices ! !DESCRIPTION: This gridded component (GC) combines the GridComps: @@ -75,7 +75,7 @@ module GEOS_LdasGridCompMod logical :: with_lake ! true if lake tiles requested by config logical :: with_land ! true if land tiles requested by config integer :: RUN_ROUTE ! 0:, no river routing, 1: routing w/o reservoirs, 2: routing w/ reservoirs - + contains !BOP @@ -531,16 +531,16 @@ subroutine Initialize(gc, import, export, clock, rc) call MAPL_GetResource(MAPL, grid_type,Label="GEOSldas.GRID_TYPE:",RC=STATUS) VERIFY_(STATUS) - ! if (trim(grid_type) == "Cubed-Sphere") then - ! call grid_manager%add_prototype("Cubed-Sphere", cubed_sphere_factory) - ! associate (method => REGRID_METHOD_BILINEAR, mgr => regridder_manager) - ! call mgr%add_prototype('Cubed-Sphere', 'LatLon', method, cube_to_latlon_prototype) - ! call mgr%add_prototype('LatLon', 'Cubed-Sphere', method, latlon_to_cube_prototype) - ! call mgr%add_prototype('Cubed-Sphere', 'Cubed-Sphere', method, cube_to_cube_prototype) - ! end associate - ! endif - - ! Create atmospheric (single level atm grid covers all of surface) grid + ! if (trim(grid_type) == "Cubed-Sphere") then + ! call grid_manager%add_prototype("Cubed-Sphere", cubed_sphere_factory) + ! associate (method => REGRID_METHOD_BILINEAR, mgr => regridder_manager) + ! call mgr%add_prototype('Cubed-Sphere', 'LatLon', method, cube_to_latlon_prototype) + ! call mgr%add_prototype('LatLon', 'Cubed-Sphere', method, latlon_to_cube_prototype) + ! call mgr%add_prototype('Cubed-Sphere', 'Cubed-Sphere', method, cube_to_cube_prototype) + ! end associate + ! endif + + ! Create atmospheric (single level atm grid covers all of surface) grid call MAPL_GridCreate(gc, rc=status) VERIFY_(status) @@ -568,10 +568,10 @@ subroutine Initialize(gc, import, export, clock, rc) isEASEv1 = .true. endif if( isEASEv1) then - ! To be implemented + ! To be implemented endif if( isEASEv2) then -! Retrieve the coordinates so we can set them + ! Retrieve the coordinates so we can set them call ESMF_GridGetCoord(agrid, coordDim=1, localDE=0, & staggerloc=ESMF_STAGGERLOC_CENTER, & farrayPtr=centerX, rc=status) @@ -698,7 +698,7 @@ subroutine Initialize(gc, import, export, clock, rc) call MPI_AllReduce(local_nt,total_nt,1,MPI_INT,MPI_SUM,mpicomm,mpierr); decomf = get_io_filename(trim(out_path), trim(exp_id), 'ldas_domdecomp', date_time=start_time, & - dir_name='rc_out', file_ext='.txt') + dir_name='rc_out', file_ext='.txt') if (IamRoot) then @@ -707,48 +707,51 @@ subroutine Initialize(gc, import, export, clock, rc) deallocate(f2g) print*, "Number of tiles: ", N_f if(N_f /= total_nt) then - print*, "total_nt = ", total_nt - stop "tiles number not equal" + print*, "total_nt = ", total_nt + stop "tiles number not equal" endif open(10,file= trim(decomf), action='write') write(10,*) N_f close(10) call io_grid_def_type('w', logunit, tile_grid_f, 'tile_grid_f') - ! get a grid for perturbations and EnKF: - ! - ! tile grid ! pert grid - ! (defines tile space) ! (used for perturbations and as "hash" grid in EnKF analysis) - ! =========================================================================================================== - ! lat/lon ! same as tile_grid (i.e., lat/lon) - ! ----------------------------------------------------------------------------------------------------------- - ! EASEv[X] ! same as tile_grid (i.e., EASE) - ! ----------------------------------------------------------------------------------------------------------- - ! cube-sphere ! lat/lon grid of resolution similar to that of (cube-sphere) tile_grid - + ! get a grid for perturbations, also used (w/ one exception, see Table) for obs2tile + tiles2obsFOV mapping in EnKF: + + ! =============================================================================================================== + ! tile_grid | pert_grid | obs2tile_grid | tiles2obsFOV_grid + ! (defines tile space) | (perturbations) | (obs reader) | (get_obs_pred) + ! =============================================================================================================== + ! lat/lon | =tile_grid (i.e., lat/lon) | =pert_grid | =pert_grid + ! --------------------------------------------------------------------------------------------------------------- + ! EASEv[X] | =tile_grid (i.e., EASE) | =pert_grid | =pert_grid + ! --------------------------------------------------------------------------------------------------------------- + ! cube-sphere (c3) | lat/lon grid of resolution | =tile_grid (c3!) | =pert_grid (i.e., lat/lon) + ! | similar to that of (c3) tile_grid | | + ! =============================================================================================================== + pert_grid_g = get_pert_grid(tile_grid_g) - + if ( .not. (pert_grid_g==tile_grid_g) ) then ! arrive here when tile_grid_g is cube-sphere and pert_grid_g is lat/lon after call to get_pert_grid() above - + !1) get pert_i_indg, pert_j_indg for tiles in (full) domain relative to pert_grid_g do i = 1, N_f - call get_ij_ind_from_latlon(pert_grid_g,tile_coord_f(i)%com_lat,tile_coord_f(i)%com_lon, & - tile_coord_f(i)%pert_i_indg,tile_coord_f(i)%pert_j_indg) + call get_ij_ind_from_latlon( pert_grid_g, tile_coord_f(i)%com_lat, tile_coord_f(i)%com_lon, & + tile_coord_f(i)%pert_i_indg, tile_coord_f(i)%pert_j_indg) enddo !2) determine pert_grid_f - pert_grid_f = get_minExtent_grid(N_f, tile_coord_f%pert_i_indg, tile_coord_f%pert_j_indg, & - tile_coord_f%min_lon, tile_coord_f%min_lat, tile_coord_f%max_lon, tile_coord_f%max_lat, & + pert_grid_f = get_minExtent_grid( N_f, tile_coord_f%pert_i_indg, tile_coord_f%pert_j_indg, & + tile_coord_f%min_lon, tile_coord_f%min_lat, tile_coord_f%max_lon, tile_coord_f%max_lat, & pert_grid_g) else - + pert_grid_f = tile_grid_f ! note that %pert_i_indg and %pert_j_indg were initialized to %i_indg and %j_indg ! in io_tile_coord_type() when tile_coord was read via io_domain_files() - + endif endif @@ -774,24 +777,24 @@ subroutine Initialize(gc, import, export, clock, rc) enddo enddo if (j /= local_nt) then - stop "tile distributtion is wrong. cannot find the right tile" + stop "tile distributtion is wrong. cannot find the right tile" endif tcinternal%tile_coord = tile_coord_f(tcinternal%l2f) end block - + do i = 0, numprocs-1 - if( i == myid) then - open(10,file= trim(decomf), action='write',position='append') - do j = 1, local_nt - write(10,*) local_id(j), myid - enddo - close(10) - endif - call MPI_Barrier(mpicomm,mpierr) - enddo + if( i == myid) then + open(10,file= trim(decomf), action='write',position='append') + do j = 1, local_nt + write(10,*) local_id(j), myid + enddo + close(10) + endif + call MPI_Barrier(mpicomm,mpierr) + enddo allocate(tcinternal%tile_coord_f,source = tile_coord_f) - + pert_grid_l = get_minExtent_grid(local_nt, & tcinternal%tile_coord%pert_i_indg, tcinternal%tile_coord%pert_j_indg, & tcinternal%tile_coord%min_lon, tcinternal%tile_coord%min_lat, & @@ -802,7 +805,7 @@ subroutine Initialize(gc, import, export, clock, rc) tcinternal%pgrid_f = pert_grid_f tcinternal%pgrid_l = pert_grid_l tcinternal%tgrid_g = tile_grid_g - + do i = 1, NUM_ENSEMBLE call MAPL_GetObjectFromGC(gcs(METFORCE(i)), CHILD_MAPL, rc=status) VERIFY_(status) ! CHILD = METFORCE @@ -816,7 +819,7 @@ subroutine Initialize(gc, import, export, clock, rc) enddo do i = 1,NUM_ENSEMBLE - + if (with_land) then call MAPL_GetObjectFromGC(gcs(LAND(i)), CHILD_MAPL, rc=status) VERIFY_(status) @@ -827,7 +830,7 @@ subroutine Initialize(gc, import, export, clock, rc) VERIFY_(status) ! CHILD = LANDPERT call MAPL_Set(CHILD_MAPL, LocStream=land_locstream, rc=status) VERIFY_(status) - + ! Add LAND's tile_coord to children's GridComps call ESMF_UserCompSetInternalState(gcs(LAND(i)), 'TILE_COORD', tcwrap, status) VERIFY_(status) @@ -848,16 +851,16 @@ subroutine Initialize(gc, import, export, clock, rc) call MAPL_Set(CHILD_MAPL, LocStream=landice_locstream, rc=status) VERIFY_(status) endif - + if (RUN_ROUTE >= 1) then call MAPL_GetObjectFromGC(gcs(ROUTE(i)), CHILD_MAPL, rc=status) VERIFY_(status) call MAPL_Set(CHILD_MAPL, LocStream=land_locstream, rc=status) VERIFY_(status) endif - - enddo + enddo + if (land_assim .or. mwRTM ) then call MAPL_GetObjectFromGC( gcs(LANDASSIM), CHILD_MAPL, rc=status) VERIFY_(status) @@ -867,13 +870,13 @@ subroutine Initialize(gc, import, export, clock, rc) call ESMF_UserCompSetInternalState(gcs(LANDASSIM), 'TILE_COORD', tcwrap, status) VERIFY_(status) endif - + call MAPL_GetObjectFromGC( gcs(METFORCEAVG), CHILD_MAPL, rc=status) VERIFY_(status) ! only land_locstream is averaged. call MAPL_Set( CHILD_MAPL, LocStream=land_locstream, rc=status) VERIFY_(status) - + if ( with_land) then call MAPL_GetObjectFromGC( gcs(LANDAVG), CHILD_MAPL, rc=status) VERIFY_(status) ! CHILD = ens_avg @@ -892,7 +895,7 @@ subroutine Initialize(gc, import, export, clock, rc) call MAPL_Set( CHILD_MAPL, LocStream=landice_locstream, rc=status) VERIFY_(status) endif - + !if ( RUN_ROUTE >= 1) then ! ! not necessary. Route Avg has its own pfaf_locstream ! call MAPL_GetObjectFromGC(gcs(ROUTEAVG), CHILD_MAPL, rc=status) @@ -901,15 +904,15 @@ subroutine Initialize(gc, import, export, clock, rc) call MAPL_GenericInitialize(gc, import, export, clock, rc=status) VERIFY_(status) - ! solar alarm is created in solar gridcomp. Since GEOSldas doesnot have that gridcomp, it is created here - ! -create-nonsticky-alarm- + ! solar alarm is created in solar gridcomp. Since GEOSldas doesnot have that gridcomp, it is created here + ! -create-nonsticky-alarm- call MAPL_Get(MAPL, HEARTBEAT = DT, RC=STATUS) VERIFY_(STATUS) call MAPL_GetResource ( MAPL, DT_Solar, Label="SOLAR_DT:", DEFAULT=DT, RC=STATUS) VERIFY_(STATUS) call ESMF_TimeIntervalSet(SOLAR_DT, s=NINT(DT_Solar), rc=status) VERIFY_(status) - + SolarAlarm = ESMF_AlarmCreate( & clock, & name='SOLAR_Alarm', & @@ -932,7 +935,7 @@ subroutine Initialize(gc, import, export, clock, rc) end subroutine Initialize - + subroutine Run(gc, import, export, clock, rc) ! !ARGUMENTS: @@ -975,8 +978,8 @@ subroutine Run(gc, import, export, clock, rc) type (ESMF_Field) :: field type (ESMF_State) :: merged_import - ! Begin... - + ! Begin... + ! Get component's name and setup traceback handle call ESMF_GridCompget(gc, name=comp_name, rc=status) VERIFY_(status) @@ -1026,7 +1029,7 @@ subroutine Run(gc, import, export, clock, rc) VERIFY_(status) call MAPL_TimerOff(MAPL, gcnames(igc)) enddo - + ! Run children GridComps (in order) ! Generate raw perturbed force and progn do i = 1,NUM_ENSEMBLE @@ -1037,7 +1040,7 @@ subroutine Run(gc, import, export, clock, rc) call MAPL_TimerOff(MAPL, gcnames(igc)) enddo endif ! with_land - + do i = 1, NUM_ENSEMBLE igc = METFORCE(i) call MAPL_TimerOn( MAPL, gcnames(igc)) @@ -1072,7 +1075,7 @@ subroutine Run(gc, import, export, clock, rc) endif call MAPL_TimerOff(MAPL, gcnames(igc)) enddo - + do i = 1,NUM_ENSEMBLE if (with_land) then @@ -1170,9 +1173,9 @@ subroutine Run(gc, import, export, clock, rc) VERIFY_(status) endif endif - endif ! with_land + endif ! with_land enddo - + if ( mwRTM .and. LSM_CHOICE == 1 ) then ! output_smapl4smlmc call ESMF_GridCompRun(gcs(LANDASSIM), importState=gim(LANDASSIM), exportState=gex(LANDASSIM), clock=clock,phase=4, userRC=status) @@ -1194,7 +1197,7 @@ subroutine Run(gc, import, export, clock, rc) ! Extract updated exports from "cat_progn" call ESMF_GridCompRun(gcs(igc), importState=gim(igc), exportState=gex(LAND(i)), clock=clock, phase=2, userRC=status) VERIFY_(status) - + enddo call MAPL_TimerOff(MAPL, gcnames(igc)) endif @@ -1214,7 +1217,7 @@ end subroutine Run ! !IROTUINE: Finalize -- finalize method for LDAS GC ! !INTERFACE: - + subroutine Finalize(gc, import, export, clock, rc) ! !ARGUMENTS: diff --git a/GEOSlandassim_GridComp/CMakeLists.txt b/GEOSlandassim_GridComp/CMakeLists.txt index 87a9bf58..5befb400 100644 --- a/GEOSlandassim_GridComp/CMakeLists.txt +++ b/GEOSlandassim_GridComp/CMakeLists.txt @@ -5,7 +5,7 @@ set (alldirs ) set (SRCS - hdf4_c_api.c hdf4_fortran_api.F90 io_hdf5.F90 enkf_general.F90 adapt_types.F90 mwRTM_types.F90 clsm_ensupd_glob_param.F90 + hdf4_fortran_api.F90 io_hdf5.F90 enkf_general.F90 adapt_types.F90 mwRTM_types.F90 clsm_ensupd_glob_param.F90 mwRTM_routines.F90 clsm_ensupd_upd_routines.F90 clsm_ensdrv_drv_routines.F90 clsm_ensupd_read_obs.F90 catch_bias_types.F90 clsm_bias_routines.F90 clsm_adapt_routines.F90 clsm_ensupd_enkf_update.F90 clsm_ensdrv_out_routines.F90 GEOS_LandAssimGridComp.F90 @@ -16,6 +16,14 @@ find_path(HDF4_INCLUDE_DIR hdf.h PATH_SUFFIXES hdf REQUIRED) find_library(HDF4_MFHDF_LIBRARY NAMES mfhdf REQUIRED) find_library(HDF4_DF_LIBRARY NAMES df REQUIRED) +# The HDF4 C bridge is compiled separately so that it only sees the HDF4 headers. +# Otherwise, on case-insensitive file systems (macOS), the included by +# hdf.h resolves to GMAO_mpeu/assert.H through the include paths of the dependencies. +add_library (${this}_hdf4_c OBJECT hdf4_c_api.c) +target_include_directories (${this}_hdf4_c PRIVATE ${HDF4_INCLUDE_DIR}) +set_target_properties (${this}_hdf4_c PROPERTIES POSITION_INDEPENDENT_CODE ON) +list (APPEND SRCS $) + esma_add_library (${this} SRCS ${SRCS} SUBCOMPONENTS ${alldirs} diff --git a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 index 61c5f897..5f1db313 100644 --- a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 +++ b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 @@ -1339,6 +1339,13 @@ subroutine Initialize(gc, import, export, clock, rc) allocate(rf2f(N_catf)) allocate(f2rf(N_catf)) + ! tile_coord holds all tiles of the forcing locstream (land, plus lake and landice if requested), + ! whereas land_nt_local is the number of land tiles. + ! Here and below (l2f, f_num, and tile_coord_l passed with N_catl), only the first land_nt_local entries + ! are used, which requires that land tiles come first in tile_coord. + _ASSERT( count(tcinternal%tile_coord( : )%typ==MAPL_LAND)==land_nt_local, "LandAssim: number of land tiles in tile_coord does not match land locstream") + _ASSERT( all( tcinternal%tile_coord(1:land_nt_local)%typ==MAPL_LAND) , "LandAssim: land tiles must come first in tile_coord") + call MPI_AllGATHERV(tcinternal%l2f, land_nt_local, MPI_INTEGER, & rf2f, N_catl_vec, low_ind-1, MPI_INTEGER, & mpicomm,mpierr) @@ -1357,7 +1364,7 @@ subroutine Initialize(gc, import, export, clock, rc) l2rf(i) = low_ind(myid+1) + i - 1 end do - tcwrap%ptr%tile_coord%f_num = l2rf + tcwrap%ptr%tile_coord(1:land_nt_local)%f_num = l2rf ! land tiles only (see above) ! invert mapping from local to full grid (get f2l from l2f) @@ -1488,6 +1495,7 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) integer :: N_adapt_R type(MAPL_LocStream) :: locstream + type(ESMF_Grid) :: tile_grid_g_ESMF ! grid attached to locstream (cube-sphere grid for c3) integer, dimension(:), allocatable :: obs_pert_adapt_param real, dimension(:,:), allocatable :: Pert_adapt_R @@ -1612,6 +1620,10 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_LocStreamGet(locstream, NT_LOCAL=N_catl,rc=status) _VERIFY(status) + ! Get grid associated with tile space (needed to map obs to tiles in cube-sphere tile space) + call MAPL_LocStreamGet(locstream, ATTACHEDGRID=tile_grid_g_ESMF, rc=status) + _VERIFY(status) + ! Pointers to internals !---------------------- @@ -1919,7 +1931,8 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) trim(out_path), trim(exp_id), & met_force, lai, cat_param, mwRTM_param, & tile_coord_l, tile_coord_rf, & - tcinternal%tgrid_g, tcinternal%pgrid_f, tcinternal%pgrid_g, & + tcinternal%tgrid_g, tile_grid_g_ESMF, & + tcinternal%pgrid_f, tcinternal%pgrid_g, & N_catl_vec, low_ind, l2rf, rf2l, & update_type, & LandAssimDTstep, pert_choice, & @@ -1930,8 +1943,8 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) Pert_rseed, obs_bias, & cat_progn_incr, fresh_incr, & N_obsf, N_obsl, Observations_l, & - ! below are dummy for now - N_adapt_R, obs_pert_adapt_param, Pert_adapt_R) + ! below are dummy for now + N_adapt_R, obs_pert_adapt_param, Pert_adapt_R ) if (fresh_incr) then ! apply EnKF increments (incl. call to catch_calc_soil_moist but not to recompute_diagS()) @@ -1951,16 +1964,17 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) if (.true.) then ! replace obsolete check for analysis time with "if true" to keep indents - call output_ObsFcstAna_wrapper( out_ObsFcstAna, & - date_time_new, trim(exp_id), & - N_obsl, N_obs_param, NUM_ENSEMBLE, & - N_catl, tile_coord_l, & - N_catf, tile_coord_rf, tcinternal%pgrid_g, & - N_catl_vec, low_ind, rf2l, & - update_type, LandAssimDTstep, & - obs_param, & - met_force, lai, & - cat_param, cat_progn, mwRTM_param, & + call output_ObsFcstAna_wrapper( out_ObsFcstAna, & + date_time_new, trim(exp_id), & + N_obsl, N_obs_param, NUM_ENSEMBLE, & + N_catl, tile_coord_l, & + N_catf, tile_coord_rf, & + tcinternal%tgrid_g, tcinternal%pgrid_g, & ! tcinternal%pgrid_g => tiles2obsFOV_grid_g + N_catl_vec, low_ind, rf2l, & + update_type, LandAssimDTstep, & + obs_param, & + met_force, lai, & + cat_param, cat_progn, mwRTM_param, & Observations_l, rf2f=rf2f ) do ii = 1, N_catl diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index c82c7533..29cf2763 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -65,7 +65,8 @@ module clsm_ensupd_enkf_update use LDAS_TilecoordType, ONLY: & tile_coord_type, & - grid_def_type + grid_def_type, & + init_grid_def_type use catch_bias_types, ONLY: & obs_bias_type @@ -73,8 +74,12 @@ module clsm_ensupd_enkf_update use LDAS_TilecoordRoutines, ONLY: & get_number_of_tiles_in_cell_ij, & get_tile_num_in_cell_ij, & + init_tile_grid_g_ESMF_c3, & grid2tile + use ESMF, ONLY: & + ESMF_Grid + use nr_ran2_gasdev, ONLY: & NRANDSEED @@ -99,7 +104,6 @@ module clsm_ensupd_enkf_update get_ind_obs_assim, & get_ind_obs_lat_lon_box, & halo_type, & - FOV_threshold, & get_halo_around_tile, & TileNnzObs @@ -149,7 +153,8 @@ subroutine get_enkf_increments( & work_path, exp_id, & met_force, lai, cat_param, mwRTM_param, & tile_coord_l, tile_coord_f, & - tile_grid_g, pert_grid_f, pert_grid_g, & + tile_grid_g, tile_grid_g_ESMF, & + pert_grid_f, pert_grid_g, & N_catl_vec, low_ind, l2f, f2l, & update_type, & dtstep_assim, pert_choice, & @@ -167,6 +172,9 @@ subroutine get_enkf_increments( & ! return increments instead of updated cat_progn ! reichle, 18 Oct 2005 + ! + ! added input tile_grid_g_ESMF (ESMF grid associated with tile space), needed (only) for obs-to-tile mapping in cube-sphere tile space + ! - amfox, 9 Nov 2026 implicit none @@ -197,8 +205,10 @@ subroutine get_enkf_increments( & type(tile_coord_type), dimension(:), pointer :: tile_coord_l, tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_g, pert_grid_f, pert_grid_g + type(grid_def_type), intent(in) :: tile_grid_g, pert_grid_f, pert_grid_g ! LDAS grid type + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! ESMF grid type, needed for obs-to-tile mapping in cube-sphere tile space + integer, intent(in), dimension(numprocs) :: N_catl_vec, low_ind integer, intent(in), dimension(N_catl) :: l2f @@ -277,6 +287,15 @@ subroutine get_enkf_increments( & integer, dimension(:,:), pointer :: N_tile_in_cell_ij_f integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij_f + ! obs2tile_grid_f is the grid that goes with N_tile_in_cell_ij_f and tile_num_in_cell_ij_f: + ! pert_grid_f for EASE and LatLon tile space, or tile_grid_f for cube-sphere tile space (amfox, 9 Nov 2026) + + type(grid_def_type) :: obs2tile_grid_f + + logical, save :: c3_grid_initialized = .false. ! initialize + + integer, dimension(N_catf) :: tmp_i_indg, tmp_j_indg + integer :: i, n, n_e ! obs bias variables @@ -386,24 +405,83 @@ subroutine get_enkf_increments( & ! ----------------------------------------------------------------- ! - ! Get additional grid/tile information that is needed to map obs - ! from lat/lon to tiles. This needs to be done: - ! - by root process (because of call to read_obs() in collect_obs()) - ! - by all processes if FOV>~0 ("tile_num_in_circle" needed in get_obs_pred()) - if ( (root_proc) .or. & - (any(obs_param(1:N_obs_param)%FOV>FOV_threshold)) ) then - - allocate(N_tile_in_cell_ij_f(pert_grid_f%N_lon,pert_grid_f%N_lat)) - - ! first call: count how many tiles are in each pert_grid_f cell - call get_number_of_tiles_in_cell_ij( N_catf, & - tile_coord_f%pert_i_indg, tile_coord_f%pert_j_indg, & - pert_grid_f, N_tile_in_cell_ij_f ) - ! second call: find out which tiles are in each pert_grid_f cell - - call get_tile_num_in_cell_ij( N_catf, & - tile_coord_f%pert_i_indg, tile_coord_f%pert_j_indg, & - pert_grid_f, maxval(N_tile_in_cell_ij_f), tile_num_in_cell_ij_f ) + ! Get additional grid/tile information that is needed to map from obs lat/lon to tiles. + ! This needs to be done only by root process because of call to read_obs() in collect_obs(). + ! + ! For tile2obsFOV mapping when FOV>~0, get_obs_pred() computes its own N_tile_in_cell_ij_lH and + ! tile_num_in_cell_ij_lH for get_tile_num_in_ellipse(); amfox, 9 Nov 2026 + ! + ! See also subroutine Initialize() of GEOS_LdasGridComp.F90. + + call init_grid_def_type( obs2tile_grid_f ) ! initialize to undefined grid + + ! Cube-sphere tile space: prepare (once) the cube-sphere ESMF grid for mapping obs to + ! tiles, which is done by root_proc only (in read_obs()). This must be done by ALL + ! processes (see init_tile_grid_g_ESMF_c3()). - amfox, 9 Nov 2026 + + if ( (index(tile_grid_g%gridtype,'c3')/=0) .and. (.not. c3_grid_initialized) ) then + + call init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid_g ) + + c3_grid_initialized = .true. + + end if + + if (root_proc) then + + if (index(tile_grid_g%gridtype,'c3')/=0) then + + ! Cube-sphere tile space: Use the cube-sphere tile_grid_f as hash grid for mapping obs to + ! tile space. Obs-to-tile mapping requires that tiles nest perfectly in the hash grid. + ! (Cube-sphere tiles do not nest in the LatLon pert_grid_f used for perturbations + ! when tile space is cube-sphere.) + ! + ! tile_grid_f is identical to tile_grid_g for cube-sphere tile space + ! (get_minExtent_grid() does not zoom in for cube-sphere grids) + ! + ! keep lat/lon extent of pert_grid_f because get_tile_num_from_latlon() + ! ignores obs outside of this extent, as needed for obs perturbations + ! (see get_obs_pert()); the extent is not used to find the cube-sphere + ! grid cell of an obs (see get_ij_ind_from_latlon_c3()) + ! + ! amfox, 9 Nov 2026 + + obs2tile_grid_f = tile_grid_g + + obs2tile_grid_f%ll_lon = pert_grid_f%ll_lon + obs2tile_grid_f%ll_lat = pert_grid_f%ll_lat + obs2tile_grid_f%ur_lon = pert_grid_f%ur_lon + obs2tile_grid_f%ur_lat = pert_grid_f%ur_lat + + tmp_i_indg = tile_coord_f%i_indg + tmp_j_indg = tile_coord_f%j_indg + + else + + ! EASE or LatLon tile space: use pert_grid_f as hash grid for mapping obs to tile space + ! + ! pert_grid_f is an EASE grid for EASE tile space and a LatLon grid for LatLon tile space, + ! so tiles always nest perfectly in pert_grid_f + + obs2tile_grid_f = pert_grid_f + + tmp_i_indg = tile_coord_f%pert_i_indg + tmp_j_indg = tile_coord_f%pert_j_indg + + end if + + allocate(N_tile_in_cell_ij_f(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat)) + + ! first call: count how many tiles are in each tile_grid_f cell + call get_number_of_tiles_in_cell_ij( N_catf, & + tmp_i_indg, tmp_j_indg, & + obs2tile_grid_f, N_tile_in_cell_ij_f ) + + ! second call: find out which tiles are in each tile_grid_f cell + call get_tile_num_in_cell_ij( N_catf, & + tmp_i_indg, tmp_j_indg, & + obs2tile_grid_f, maxval(N_tile_in_cell_ij_f), tile_num_in_cell_ij_f ) + else allocate(N_tile_in_cell_ij_f(0,0)) ! for debugging end if @@ -421,16 +499,16 @@ subroutine get_enkf_increments( & if (out_smapL4SMaup) & call output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & N_ens, N_catl, N_catf, N_obsl_max, & - tile_coord_f, tile_grid_g, pert_grid_f, & + tile_coord_f, tile_grid_g, tile_grid_g_ESMF, obs2tile_grid_f, & N_catl_vec, low_ind, l2f, N_tile_in_cell_ij_f, tile_num_in_cell_ij_f, & - N_obs_param, obs_param, Observations_l, cat_param, cat_progn ) + N_obs_param, obs_param, Observations_l, cat_param, cat_progn ) ! check for observations, found_obs_f=.true. if obs availalbe call collect_obs( & work_path, exp_id, date_time, dtstep_assim, & N_catl, & - N_catf, tile_coord_f, pert_grid_f, & + N_catf, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & N_tile_in_cell_ij_f, tile_num_in_cell_ij_f, & N_catl_vec, low_ind, l2f, & N_obs_param, obs_param, N_obsl_max, out_obslog, & @@ -508,15 +586,21 @@ subroutine get_enkf_increments( & ! incl. obs bias estimation - call get_obs_pred( & - .true., & ! -> before EnKF update - N_obs_param, N_ens, & - N_catl, tile_coord_l, & - N_catf, tile_coord_f, f2l, & - N_catl_vec, low_ind, pert_grid_g, & - obs_param, & - met_force, lai, cat_param, cat_progn, mwRTM_param, & - N_obsl, Observations_l, Obs_pred_l, obsbias_ok, & + ! call get_obs_pred() with "pert_grid_g" as "tiles2obsFOV_grid_g", which is: + ! - LatLon for LatLon tile space, + ! - EASE for EASE tile space, + ! - LatLon for cube-sphere tile space, + + call get_obs_pred( & + .true., & ! => before EnKF update + N_obs_param, N_ens, & + N_catl, tile_coord_l, & + N_catf, tile_coord_f, f2l, & + N_catl_vec, low_ind, & + tile_grid_g, pert_grid_g, & ! pert_grid_g => tiles2obsFOV_grid_g + obs_param, & + met_force, lai, cat_param, cat_progn, mwRTM_param, & + N_obsl, Observations_l, Obs_pred_l, obsbias_ok, & fcsterr_inflation_fac ) if (allocated(obsbias_ok)) deallocate(obsbias_ok) @@ -2045,7 +2129,7 @@ subroutine output_ObsFcstAna_wrapper( out_ObsFcstAna, & date_time, exp_id, & N_obsl, N_obs_param, N_ens, & N_catl, tile_coord_l, & - N_catf, tile_coord_f, pert_grid_g, & + N_catf, tile_coord_f, tile_grid_g, tiles2obsFOV_grid_g, & N_catl_vec, low_ind, f2l, & update_type, dtstep_assim, & obs_param, & @@ -2074,7 +2158,8 @@ subroutine output_ObsFcstAna_wrapper( out_ObsFcstAna, & type(tile_coord_type), dimension(:), pointer :: tile_coord_l ! input type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: pert_grid_g + type(grid_def_type), intent(in) :: tile_grid_g + type(grid_def_type), intent(in) :: tiles2obsFOV_grid_g integer, dimension(numprocs), intent(in) :: N_catl_vec, low_ind @@ -2118,14 +2203,15 @@ subroutine output_ObsFcstAna_wrapper( out_ObsFcstAna, & N_obsl_tmp = N_obsl ! cannot pass N_obsl into get_obs_pred() b/c of intent(in) - call get_obs_pred( & - .false., & ! -> after EnKF update - N_obs_param, N_ens, & - N_catl, tile_coord_l, & - N_catf, tile_coord_f, f2l, & - N_catl_vec, low_ind, pert_grid_g, & - obs_param, & - met_force, lai, cat_param, cat_progn, mwRTM_param, & + call get_obs_pred( & + .false., & ! => after EnKF update + N_obs_param, N_ens, & + N_catl, tile_coord_l, & + N_catf, tile_coord_f, f2l, & + N_catl_vec, low_ind, & + tile_grid_g, tiles2obsFOV_grid_g, & + obs_param, & + met_force, lai, cat_param, cat_progn, mwRTM_param, & N_obsl_tmp, Observations_l, Obs_pred_l ) ! clean up @@ -2145,10 +2231,10 @@ end subroutine output_ObsFcstAna_wrapper ! ********************************************************************** subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & - N_ens, N_catl, N_catf, N_obsl_max, & - tile_coord_f, tile_grid_g, pert_grid_f, & + N_ens, N_catl, N_catf, N_obsl_max, & + tile_coord_f, tile_grid_g, tile_grid_g_ESMF, obs2tile_grid_f, & N_catl_vec, low_ind, l2f, N_tile_in_cell_ij_f, tile_num_in_cell_ij_f, & - N_obs_param, obs_param, Observations_l, cat_param, cat_progn ) + N_obs_param, obs_param, Observations_l, cat_param, cat_progn ) ! wrapper for output of original (unscaled) SMAP Tb observations into ! SMAP L4_SM "aup" (analysis update) @@ -2174,17 +2260,17 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_g - type(grid_def_type), intent(in) :: pert_grid_f + type(grid_def_type), intent(in) :: tile_grid_g, obs2tile_grid_f + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! pass-through only, not used for L4SMaup output + integer, dimension(numprocs), intent(in) :: N_catl_vec integer, dimension(numprocs), intent(in) :: low_ind integer, dimension(N_catl), intent(in) :: l2f ! N_tile_in_cell_ij and tile_num_in_cell_ij are on the "full" domain - ! and guaranteed to be allocated ONLY for the root_proc - ! (but may be allocated on all processors depending on obs_param%FOV) + ! and guaranteed to be allocated ONLY for the root_proc (see get_enkf_increments()) integer, dimension(:,:), pointer :: N_tile_in_cell_ij_f ! input integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij_f ! input @@ -2250,7 +2336,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & call collect_obs( & work_path, exp_id, date_time, dtstep_assim, & N_catl, & - N_catf, tile_coord_f, pert_grid_f, & + N_catf, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & N_tile_in_cell_ij_f, tile_num_in_cell_ij_f, & N_catl_vec, low_ind, l2f, & N_obs_param_tmp, obs_param_tmp(1:N_obs_param_tmp), N_obsl_max, .false., & @@ -2258,7 +2344,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & ! write appropriate fields (according to 'option') into file - call write_smapL4SMaup( 'orig_obs', date_time, exp_id, N_ens, & + call write_smapL4SMaup( 'orig_obs', date_time, exp_id, N_ens, & N_catl, N_catf, N_obsl_tmp, tile_coord_f, tile_grid_g, & N_catl_vec, low_ind, & N_obs_param_tmp, obs_param_tmp(1:N_obs_param_tmp), Observations_l, & diff --git a/GEOSlandassim_GridComp/clsm_ensupd_glob_param.F90 b/GEOSlandassim_GridComp/clsm_ensupd_glob_param.F90 index 74965731..285ff489 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_glob_param.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_glob_param.F90 @@ -48,7 +48,7 @@ module clsm_ensupd_glob_param ! total number of all obs species defined in "ensupd" namelist file ! (regardless of whether "assim" flag is true or false) - integer, parameter :: N_obs_species_nml = 58 + integer, parameter :: N_obs_species_nml = 61 ! ---------------------------------------------------------------------- ! diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index d2ce35a1..16707be8 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -20,7 +20,7 @@ module clsm_ensupd_read_obs c_char use, intrinsic :: iso_fortran_env, ONLY: & - int16 + int16, REAL64 use MAPL_BaseMod, ONLY: & MAPL_UNDEF @@ -76,6 +76,9 @@ module clsm_ensupd_read_obs use LDAS_TilecoordRoutines, ONLY: & get_tile_num_from_latlon + + use ESMF, ONLY: & + ESMF_Grid use LDAS_ensdrv_mpi, ONLY: & root_proc, & @@ -429,8 +432,9 @@ end subroutine read_ae_l2_sm_hdf subroutine read_obs_ae_l2_sm( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, ae_l2_sm, std_ae_l2_sm ) @@ -443,7 +447,7 @@ subroutine read_obs_ae_l2_sm( & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! reichle, 25 Jul 2005 ! @@ -458,23 +462,25 @@ subroutine read_obs_ae_l2_sm( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - + type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: ae_l2_sm - real, intent(out), dimension(N_catd) :: std_ae_l2_sm + real, intent(out), dimension(N_catf) :: ae_l2_sm + real, intent(out), dimension(N_catf) :: std_ae_l2_sm logical, intent(out) :: found_obs ! --------------- @@ -506,7 +512,7 @@ subroutine read_obs_ae_l2_sm( & real, dimension(:), pointer :: tmp_obs, tmp_lat, tmp_lon integer, dimension(:), pointer :: tmp_tile_num - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile character(len=*), parameter :: Iam = 'read_obs_ae_l2_sm' @@ -653,8 +659,9 @@ subroutine read_obs_ae_l2_sm( & allocate(tmp_tile_num(N_tmp)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & tmp_tile_num ) @@ -670,7 +677,7 @@ subroutine read_obs_ae_l2_sm( & do i=1,N_tmp - ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this step eliminates obs outside domain @@ -684,7 +691,7 @@ subroutine read_obs_ae_l2_sm( & ! normalize - do i=1,N_catd + do i=1,N_catf if (N_obs_in_tile(i)>1) then @@ -706,7 +713,7 @@ subroutine read_obs_ae_l2_sm( & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_ae_l2_sm(i) = this_obs_param%errstd end do @@ -938,10 +945,11 @@ end subroutine read_ae_sm_LPRM_bin ! ***************************************************************** - subroutine read_obs_ae_sm_LPRM( & + subroutine read_obs_ae_sm_LPRM( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, ae_sm_LPRM, std_ae_sm_LPRM ) @@ -955,7 +963,7 @@ subroutine read_obs_ae_sm_LPRM( & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! reichle, 20 Feb 2009 ! @@ -970,23 +978,25 @@ subroutine read_obs_ae_sm_LPRM( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - + type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: ae_sm_LPRM - real, intent(out), dimension(N_catd) :: std_ae_sm_LPRM + real, intent(out), dimension(N_catf) :: ae_sm_LPRM + real, intent(out), dimension(N_catf) :: std_ae_sm_LPRM logical, intent(out) :: found_obs ! --------------- @@ -1018,7 +1028,7 @@ subroutine read_obs_ae_sm_LPRM( & real, dimension(:), pointer :: tmp_obs, tmp_lat, tmp_lon integer, dimension(:), pointer :: tmp_tile_num - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile character(len=*), parameter :: Iam = 'read_obs_ae_sm_LPRM' @@ -1168,8 +1178,9 @@ subroutine read_obs_ae_sm_LPRM( & allocate(tmp_tile_num(N_tmp)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & tmp_tile_num ) @@ -1185,7 +1196,7 @@ subroutine read_obs_ae_sm_LPRM( & do i=1,N_tmp - ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this step eliminates obs outside domain @@ -1199,7 +1210,7 @@ subroutine read_obs_ae_sm_LPRM( & ! normalize - do i=1,N_catd + do i=1,N_catf if (N_obs_in_tile(i)>1) then @@ -1221,7 +1232,7 @@ subroutine read_obs_ae_sm_LPRM( & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_ae_sm_LPRM(i) = this_obs_param%errstd end do @@ -1251,8 +1262,9 @@ end subroutine read_obs_ae_sm_LPRM subroutine read_obs_sm_ASCAT( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, sm_ASCAT, std_sm_ASCAT ) @@ -1280,23 +1292,25 @@ subroutine read_obs_sm_ASCAT( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - + type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: sm_ASCAT - real, intent(out), dimension(N_catd) :: std_sm_ASCAT + real, intent(out), dimension(N_catf) :: sm_ASCAT + real, intent(out), dimension(N_catf) :: std_sm_ASCAT logical, intent(out) :: found_obs ! --------------- @@ -1326,7 +1340,7 @@ subroutine read_obs_sm_ASCAT( & real, dimension(:), pointer :: tmp_obs, tmp_lat, tmp_lon integer, dimension(:), pointer :: tmp_tile_num - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile real, parameter :: tol = 1e-2 @@ -1481,8 +1495,9 @@ subroutine read_obs_sm_ASCAT( & allocate(tmp_tile_num(N_tmp)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & tmp_tile_num ) @@ -1498,7 +1513,7 @@ subroutine read_obs_sm_ASCAT( & do i=1,N_tmp - ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this step eliminates obs outside domain @@ -1512,7 +1527,7 @@ subroutine read_obs_sm_ASCAT( & ! normalize - do i=1,N_catd + do i=1,N_catf if (N_obs_in_tile(i)>1) then @@ -1534,7 +1549,7 @@ subroutine read_obs_sm_ASCAT( & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_sm_ASCAT(i) = this_obs_param%errstd enddo ! -------------------------------- @@ -1561,10 +1576,10 @@ end subroutine read_obs_sm_ASCAT ! **************************************************************************** - subroutine read_obs_sm_ASCAT_EUMET( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & - this_obs_param, & + subroutine read_obs_sm_ASCAT_EUMET( & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, N_tile_in_cell_ij, tile_num_in_cell_ij, & + this_obs_param, & found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time ) !--------------------------------------------------------------------- @@ -1598,27 +1613,29 @@ subroutine read_obs_sm_ASCAT_EUMET( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - + type(obs_param_type), intent(in) :: this_obs_param ! outputs: logical, intent(out) :: found_obs - real, intent(out), dimension(N_catd) :: ASCAT_sm ! sfds obs [fraction] (i.e., 0-1) - real, intent(out), dimension(N_catd) :: ASCAT_sm_std ! sfds obs err std [fraction] (i.e., 0-1) - real, intent(out), dimension(N_catd) :: ASCAT_lon, ASCAT_lat - real*8, intent(out), dimension(N_catd) :: ASCAT_time ! J2000 seconds + real, intent(out), dimension(N_catf) :: ASCAT_sm ! sfds obs [fraction] (i.e., 0-1) + real, intent(out), dimension(N_catf) :: ASCAT_sm_std ! sfds obs err std [fraction] (i.e., 0-1) + real, intent(out), dimension(N_catf) :: ASCAT_lon, ASCAT_lat + real*8, intent(out), dimension(N_catf) :: ASCAT_time ! J2000 seconds ! --------------- @@ -1688,7 +1705,7 @@ subroutine read_obs_sm_ASCAT_EUMET( & integer, dimension(:), pointer :: tmp_tile_num - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile character(len=*), parameter :: Iam = 'read_obs_sm_ASCAT_EUMET' character(len=400) :: err_msg @@ -2061,8 +2078,9 @@ subroutine read_obs_sm_ASCAT_EUMET( & allocate(tmp_tile_num(N_tmp)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & tmp_tile_num ) @@ -2082,7 +2100,7 @@ subroutine read_obs_sm_ASCAT_EUMET( & do ii=1,N_tmp - ind = tmp_tile_num(ii) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(ii) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this step eliminates obs outside domain @@ -2099,7 +2117,7 @@ subroutine read_obs_sm_ASCAT_EUMET( & ! normalize and set obs error std-dev - do ii=1,N_catd + do ii=1,N_catf ! set observation error standard deviation @@ -2158,8 +2176,9 @@ end subroutine read_obs_sm_ASCAT_EUMET ! **************************************************************************** subroutine read_obs_sm_ASCAT_HSAF( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, write_obslog, & found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time ) @@ -2207,13 +2226,15 @@ subroutine read_obs_sm_ASCAT_HSAF( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space + + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input @@ -2226,10 +2247,10 @@ subroutine read_obs_sm_ASCAT_HSAF( & logical, intent(out) :: found_obs - real, intent(out), dimension(N_catd) :: ASCAT_sm ! degree of saturation (sfds) [fraction 0-1] - real, intent(out), dimension(N_catd) :: ASCAT_sm_std ! sfds obs error std [fraction 0-1] - real, intent(out), dimension(N_catd) :: ASCAT_lon, ASCAT_lat - real*8, intent(out), dimension(N_catd) :: ASCAT_time ! J2000 seconds + real, intent(out), dimension(N_catf) :: ASCAT_sm ! degree of saturation (sfds) [fraction 0-1] + real, intent(out), dimension(N_catf) :: ASCAT_sm_std ! sfds obs error std [fraction 0-1] + real, intent(out), dimension(N_catf) :: ASCAT_lon, ASCAT_lat + real*8, intent(out), dimension(N_catf) :: ASCAT_time ! J2000 seconds ! --------------- @@ -2302,7 +2323,7 @@ subroutine read_obs_sm_ASCAT_HSAF( & ! per-file arrays allocated to actual obs dimension size integer, allocatable :: lat_raw(:), lon_raw(:) - real(8), allocatable :: time_raw(:) + real(REAL64), allocatable :: time_raw(:) integer(2), allocatable :: ssm_raw(:) integer(1), allocatable :: sflag_raw(:) ! surface_flag (NC_UBYTE -> int8) integer(1), allocatable :: pflag_raw(:) ! processing_flag (NC_UBYTE -> int8) @@ -2322,7 +2343,7 @@ subroutine read_obs_sm_ASCAT_HSAF( & integer, dimension(:), pointer :: tmp_tile_num ! tile accumulation across all files - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile ! optional thinning of tile obs integer, allocatable :: ind_tile(:), indx(:) @@ -2631,8 +2652,9 @@ subroutine read_obs_sm_ASCAT_HSAF( & tmp_lon = tmp1_lon( 1:N_valid) tmp_jtime = tmp1_jtime(1:N_valid) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_valid, tmp_lat, tmp_lon, & this_obs_param, & tmp_tile_num ) @@ -2684,7 +2706,7 @@ subroutine read_obs_sm_ASCAT_HSAF( & ! ! normalise tile super-obs and set obs error std-dev - do ii = 1, N_catd + do ii = 1, N_catf ASCAT_sm_std(ii) = this_obs_param%errstd / 100. ! % -> fraction @@ -2727,7 +2749,7 @@ subroutine read_obs_sm_ASCAT_HSAF( & kk = 0 - do ii = 1, N_catd + do ii = 1, N_catf if (N_obs_in_tile(ii) > 0) then @@ -2791,10 +2813,10 @@ end subroutine read_obs_sm_ASCAT_HSAF ! **************************************************************************** - subroutine read_obs_sm_CYGNSS( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & - this_obs_param, write_obslog, & + subroutine read_obs_sm_CYGNSS( & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, N_tile_in_cell_ij, tile_num_in_cell_ij, & + this_obs_param, write_obslog, & found_obs, CYGNSS_sm, CYGNSS_sm_std, CYGNSS_lon, CYGNSS_lat, CYGNSS_time ) !--------------------------------------------------------------------- @@ -2814,6 +2836,7 @@ subroutine read_obs_sm_CYGNSS( & ! ! A. Fox, reichle, Jan 2025 ! amfox, 5 Nov 2026 - added obslog output + ! amfox, 18 Nov 2026 - shift obs lat/lon for obs-to-tile mapping on EASEv2 M09 tile space (as in read_obs_SMAP_halforbit_Tb()) ! ! -------------------------------------------------------------------- @@ -2824,13 +2847,15 @@ subroutine read_obs_sm_CYGNSS( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space + + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input @@ -2843,10 +2868,10 @@ subroutine read_obs_sm_CYGNSS( & logical, intent(out) :: found_obs - real, intent(out), dimension(N_catd) :: CYGNSS_sm ! sm obs [cm3 cm-3] - real, intent(out), dimension(N_catd) :: CYGNSS_sm_std ! sm obs err std [cm3 cm-3] - real, intent(out), dimension(N_catd) :: CYGNSS_lon, CYGNSS_lat - real*8, intent(out), dimension(N_catd) :: CYGNSS_time ! J2000 seconds + real, intent(out), dimension(N_catf) :: CYGNSS_sm ! sm obs [cm3 cm-3] + real, intent(out), dimension(N_catf) :: CYGNSS_sm_std ! sm obs err std [cm3 cm-3] + real, intent(out), dimension(N_catf) :: CYGNSS_lon, CYGNSS_lat + real*8, intent(out), dimension(N_catf) :: CYGNSS_time ! J2000 seconds ! ------------------------------------------------------------------- ! local variables: @@ -2885,12 +2910,20 @@ subroutine read_obs_sm_CYGNSS( & real, dimension(:), pointer :: tmp_lon(:), tmp_lat(:), tmp_obs(:), tmp_err(:), tmp_jtime(:) integer, dimension(:), pointer :: tmp_tile_num - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile real, allocatable :: timeintervals(:,:), latitudes(:,:), longitudes(:,:), tmp_sm(:,:), tmp_sigma(:,:) real, allocatable :: time(:), timeslices(:,:) real, allocatable :: latitudes_m(:,:), longitudes_m(:,:) + ! temporarily shift lat/lon of obs for computation of nearest tile to + ! avoid ambiguous assignment of M09 model tile within M36 obs grid cell + ! (center of M36 grid cell is equidistant from at least two M09 model + ! tiles) -- reichle, 23 Aug 2013 + + real, parameter :: tmp_shift_lon = 0.01 + real, parameter :: tmp_shift_lat = 0.005 + real :: date_time_low_hour, date_time_up_hour real :: tmp1_lon(max_obs), tmp1_lat(max_obs), tmp1_obs(max_obs), tmp1_err(max_obs), tmp1_jtime(max_obs) @@ -3220,11 +3253,32 @@ subroutine read_obs_sm_CYGNSS( & allocate(tmp_tile_num(N_obs)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & - N_obs, tmp_lat, tmp_lon, & - this_obs_param, & - tmp_tile_num ) + ! shift M36 obs lat/lon for proper assignment if tile space M09/M03/M01 (tiles nest in M36) + ! (as for the SMAP L1C obs readers) + + if ( index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2-M09') /=0 .or. & ! allow outdated grid name only for M09 + index(obs2tile_grid_f%gridtype, 'EASEv2_M03') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2_M01') /=0 ) then + + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & + N_obs, tmp_lat, tmp_lon, & + this_obs_param, & + tmp_tile_num, & + tmp_shift_lat, tmp_shift_lon ) + + else + + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & + N_obs, tmp_lat, tmp_lon, & + this_obs_param, & + tmp_tile_num ) + + end if ! ---------------------------------------------------------------- ! @@ -3240,7 +3294,7 @@ subroutine read_obs_sm_CYGNSS( & do ii=1,N_obs - ind = tmp_tile_num(ii) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(ii) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this step eliminates obs outside domain @@ -3257,7 +3311,7 @@ subroutine read_obs_sm_CYGNSS( & ! normalize and set obs error std-dev - do ii=1,N_catd + do ii=1,N_catf ! set observation error standard deviation @@ -3513,8 +3567,9 @@ end subroutine read_sm_ASCAT_bin ! ***************************************************************** subroutine read_obs_LaRC_Tskin( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, ts_LARC, std_ts_LARC ) @@ -3531,23 +3586,25 @@ subroutine read_obs_LaRC_Tskin( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - + type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: ts_LARC - real, intent(out), dimension(N_catd) :: std_ts_LARC + real, intent(out), dimension(N_catf) :: ts_LARC + real, intent(out), dimension(N_catf) :: std_ts_LARC logical, intent(out) :: found_obs ! --------------- @@ -3575,7 +3632,7 @@ subroutine read_obs_LaRC_Tskin( & real, dimension(:), pointer :: tmp_obs, tmp_lat, tmp_lon - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile integer, dimension(:), pointer :: tmp_tile_num @@ -3710,8 +3767,9 @@ subroutine read_obs_LaRC_Tskin( & allocate(tmp_tile_num(N_tmp)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & tmp_tile_num ) @@ -3728,7 +3786,7 @@ subroutine read_obs_LaRC_Tskin( & do i=1,N_tmp - ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this step eliminates obs outside domain @@ -3748,7 +3806,7 @@ subroutine read_obs_LaRC_Tskin( & ! normalize - do i=1,N_catd + do i=1,N_catf if (N_obs_in_tile(i)>1) then @@ -3764,7 +3822,7 @@ subroutine read_obs_LaRC_Tskin( & if (associated(tmp_tile_num)) deallocate(tmp_tile_num) - do i=1,N_catd + do i=1,N_catf std_ts_LARC(i) = this_obs_param%errstd @@ -4225,8 +4283,8 @@ end subroutine read_LaRC_Tskin_nc4 ! ***************************************************************** - subroutine read_obs_RedArkOSSE_sm( & - date_time, N_catd, tile_coord, this_obs_param, & + subroutine read_obs_RedArkOSSE_sm( & + date_time, N_catf, tile_coord_f, this_obs_param, & found_obs, RedArkOSSE_sm, std_RedArkOSSE_sm ) ! Read observations of surface soil moisture from Wade Crow's @@ -4239,7 +4297,7 @@ subroutine read_obs_RedArkOSSE_sm( & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! reichle, 25 May 2006 ! reichle, 26 Sep 2006 - added iostat to open statement @@ -4252,16 +4310,16 @@ subroutine read_obs_RedArkOSSE_sm( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: RedArkOSSE_sm - real, intent(out), dimension(N_catd) :: std_RedArkOSSE_sm + real, intent(out), dimension(N_catf) :: RedArkOSSE_sm + real, intent(out), dimension(N_catf) :: std_RedArkOSSE_sm logical, intent(out) :: found_obs ! --------------- @@ -4300,7 +4358,7 @@ subroutine read_obs_RedArkOSSE_sm( & real, dimension(:), allocatable :: tmp_obs integer, dimension(:), allocatable :: tmp_tile_num - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile character(len=*), parameter :: Iam = 'read_obs_RedArkOSSE_sm' character(len=400) :: err_msg @@ -4375,10 +4433,10 @@ subroutine read_obs_RedArkOSSE_sm( & ! check tile_id for consistency if (p2t(i)>0) then ! if statement added 1 May 2007, reichle - if (tmp_tile_id/=tile_coord(p2t(i))%tile_id) then + if (tmp_tile_id/=tile_coord_f(p2t(i))%tile_id) then !write (logunit,*) 'read_obs_RedArkOSSE(): something is wrong (p2t)' - !!!write (logunit,*) i, p2t(i), tmp_tile_id, tile_coord(p2t(i))%tile_id + !!!write (logunit,*) i, p2t(i), tmp_tile_id, tile_coord_f(p2t(i))%tile_id !stop err_msg = 'something is wrong (p2t)' @@ -4401,7 +4459,7 @@ subroutine read_obs_RedArkOSSE_sm( & read(10,*) t2p(i,1:2), tmp_tile_id ! pixel_num, tile_num, tile_id - if (tmp_tile_id/=tile_coord(t2p(i,2))%tile_id) then + if (tmp_tile_id/=tile_coord_f(t2p(i,2))%tile_id) then err_msg = 'something is wrong (t2p)' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if @@ -4450,7 +4508,7 @@ subroutine read_obs_RedArkOSSE_sm( & do i=1,N_tmp - ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this step eliminates obs outside domain @@ -4468,7 +4526,7 @@ subroutine read_obs_RedArkOSSE_sm( & ! normalize - do i=1,N_catd + do i=1,N_catf if (N_obs_in_tile(i)>1) then @@ -4486,7 +4544,7 @@ subroutine read_obs_RedArkOSSE_sm( & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_RedArkOSSE_sm(i) = this_obs_param%errstd end do @@ -4515,7 +4573,7 @@ end subroutine read_obs_RedArkOSSE_sm ! ******************************************************************* - subroutine read_obs_RedArkOSSE_CLSMsynthSM( date_time, N_catd, & + subroutine read_obs_RedArkOSSE_CLSMsynthSM( date_time, N_catf, & this_obs_param, & found_obs, RedArkOSSE_CLSMsynthSM, std_RedArkOSSE_CLSMsynthSM ) @@ -4529,7 +4587,7 @@ subroutine read_obs_RedArkOSSE_CLSMsynthSM( date_time, N_catd, & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! reichle, 16 Feb 2006 ! reichle, 5 Apr 2007 - use obs std from default nml input @@ -4543,14 +4601,14 @@ subroutine read_obs_RedArkOSSE_CLSMsynthSM( date_time, N_catd, & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: RedArkOSSE_CLSMsynthSM - real, intent(out), dimension(N_catd) :: std_RedArkOSSE_CLSMsynthSM + real, intent(out), dimension(N_catf) :: RedArkOSSE_CLSMsynthSM + real, intent(out), dimension(N_catf) :: std_RedArkOSSE_CLSMsynthSM logical, intent(out) :: found_obs ! --------------- @@ -4608,8 +4666,8 @@ subroutine read_obs_RedArkOSSE_CLSMsynthSM( date_time, N_catd, & tmp_obs_std = this_obs_param%errstd - RedArkOSSE_CLSMsynthSM( 1:N_catd) = nodata - std_RedArkOSSE_CLSMsynthSM(1:N_catd) = tmp_obs_std + RedArkOSSE_CLSMsynthSM( 1:N_catf) = nodata + std_RedArkOSSE_CLSMsynthSM(1:N_catf) = tmp_obs_std do i=1,N_tmp @@ -4636,7 +4694,7 @@ end subroutine read_obs_RedArkOSSE_CLSMsynthSM ! ***************************************************************** - subroutine read_obs_VivianaOK_CLSMsynthSM( date_time, N_catd, & + subroutine read_obs_VivianaOK_CLSMsynthSM( date_time, N_catf, & this_obs_param, & found_obs, VivianaOK_CLSMsynthSM, std_VivianaOK_CLSMsynthSM ) @@ -4648,7 +4706,7 @@ subroutine read_obs_VivianaOK_CLSMsynthSM( date_time, N_catd, & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! vmaggion + reichle, 4 Aug 2008: ! adapted from read_obs_RedArkOSSE_CLSMsynthSM @@ -4662,14 +4720,14 @@ subroutine read_obs_VivianaOK_CLSMsynthSM( date_time, N_catd, & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: VivianaOK_CLSMsynthSM - real, intent(out), dimension(N_catd) :: std_VivianaOK_CLSMsynthSM + real, intent(out), dimension(N_catf) :: VivianaOK_CLSMsynthSM + real, intent(out), dimension(N_catf) :: std_VivianaOK_CLSMsynthSM logical, intent(out) :: found_obs ! --------------- @@ -4723,10 +4781,10 @@ subroutine read_obs_VivianaOK_CLSMsynthSM( date_time, N_catd, & tmp_obs_std = this_obs_param%errstd - VivianaOK_CLSMsynthSM( 1:N_catd) = nodata - std_VivianaOK_CLSMsynthSM(1:N_catd) = tmp_obs_std + VivianaOK_CLSMsynthSM( 1:N_catf) = nodata + std_VivianaOK_CLSMsynthSM(1:N_catf) = tmp_obs_std - do i=1,N_catd + do i=1,N_catf read(10,*) tmp_obs @@ -4752,7 +4810,7 @@ end subroutine read_obs_VivianaOK_CLSMsynthSM ! ***************************************************************** subroutine read_obs_RedArkOSSE_truth( & - date_time, N_catd, this_obs_param, & + date_time, N_catf, this_obs_param, & found_obs, RedArkOSSE_truth, std_RedArkOSSE_truth ) ! Read "observations" of true surface soil moisture from Wade Crow's @@ -4762,7 +4820,7 @@ subroutine read_obs_RedArkOSSE_truth( & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! reichle, 18 Sep 2006 ! @@ -4774,14 +4832,14 @@ subroutine read_obs_RedArkOSSE_truth( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: RedArkOSSE_truth - real, intent(out), dimension(N_catd) :: std_RedArkOSSE_truth + real, intent(out), dimension(N_catf) :: RedArkOSSE_truth + real, intent(out), dimension(N_catf) :: std_RedArkOSSE_truth logical, intent(out) :: found_obs ! --------------- @@ -4831,7 +4889,7 @@ subroutine read_obs_RedArkOSSE_truth( & if (istat==0) then - do i=1,N_catd + do i=1,N_catf read(10,*) tmp_real @@ -4843,7 +4901,7 @@ subroutine read_obs_RedArkOSSE_truth( & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_RedArkOSSE_truth(i) = this_obs_param%errstd end do @@ -4856,10 +4914,11 @@ end subroutine read_obs_RedArkOSSE_truth ! ***************************************************************** - subroutine read_obs_isccp_tskin_gswp2_v1( & - date_time, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & - this_obs_param, & + subroutine read_obs_isccp_tskin_gswp2_v1( & + date_time, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & + this_obs_param, & found_obs, isccp_tskin_gswp2_v1, std_isccp_tskin_gswp2_v1 ) ! Read observations of land skin temperature from ISCCP data @@ -4872,7 +4931,7 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! reichle, 26 Sep 2005 ! @@ -4884,23 +4943,25 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - + type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: isccp_tskin_gswp2_v1 - real, intent(out), dimension(N_catd) :: std_isccp_tskin_gswp2_v1 + real, intent(out), dimension(N_catf) :: isccp_tskin_gswp2_v1 + real, intent(out), dimension(N_catf) :: std_isccp_tskin_gswp2_v1 logical, intent(out) :: found_obs ! --------------- @@ -4941,7 +5002,7 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & real, dimension(N_gswp2_compressed) :: tmp_obs, tmp_lat, tmp_lon - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile ! ------------------------------------------------------------------- @@ -5023,8 +5084,9 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & if (N_tmp>0) then - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat(1:N_tmp), tmp_lon(1:N_tmp), & this_obs_param, & tmp_tile_num(1:N_tmp) ) @@ -5039,7 +5101,7 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & do i=1,N_tmp - ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this step eliminates obs outside domain @@ -5053,7 +5115,7 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & ! normalize - do i=1,N_catd + do i=1,N_catf if (N_obs_in_tile(i)>1) then @@ -5073,7 +5135,7 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_isccp_tskin_gswp2_v1(i) = this_obs_param%errstd end do @@ -5096,7 +5158,7 @@ end subroutine read_obs_isccp_tskin_gswp2_v1 ! ***************************************************************** subroutine read_obs_isccp_tskin_ceop3n4( & - date_time, N_catd, tile_coord, & + date_time, N_catf, tile_coord_f, & this_obs_param, & found_obs, isccp_tskin_gswp2_v1, std_isccp_tskin_gswp2_v1 ) @@ -5109,7 +5171,7 @@ subroutine read_obs_isccp_tskin_ceop3n4( & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! reichle, 27 Jan 2009 ! @@ -5121,16 +5183,16 @@ subroutine read_obs_isccp_tskin_ceop3n4( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: isccp_tskin_gswp2_v1 - real, intent(out), dimension(N_catd) :: std_isccp_tskin_gswp2_v1 + real, intent(out), dimension(N_catf) :: isccp_tskin_gswp2_v1 + real, intent(out), dimension(N_catf) :: std_isccp_tskin_gswp2_v1 logical, intent(out) :: found_obs ! --------------- @@ -5223,7 +5285,7 @@ subroutine read_obs_isccp_tskin_ceop3n4( & ! ------------------------------------------------------------------- - if (N_catd/=N_tiles) then + if (N_catf/=N_tiles) then err_msg = 'error 1 -- use only for CEOP3n4_by_tile_144x91 domain' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if @@ -5272,7 +5334,7 @@ subroutine read_obs_isccp_tskin_ceop3n4( & ! double-check tile ids - if (GEOS5_to_ISCCP(1,i)/=tile_coord(i)%tile_id) then + if (GEOS5_to_ISCCP(1,i)/=tile_coord_f(i)%tile_id) then !write (logunit,*) 'error 2 -- only for CEOP3n4_by_tile_144x91 domain' !stop @@ -5306,7 +5368,7 @@ subroutine read_obs_isccp_tskin_ceop3n4( & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_isccp_tskin_gswp2_v1(i) = this_obs_param%errstd end do @@ -5323,9 +5385,9 @@ end subroutine read_obs_isccp_tskin_ceop3n4 ! ***************************************************************** ! ***************************************************************** - subroutine read_obs_isccp_ts_ceop3n4_hdASC( & - date_time, N_catd, tile_coord, & - this_obs_param, & + subroutine read_obs_isccp_ts_ceop3n4_hdASC( & + date_time, N_catf, tile_coord_f, & + this_obs_param, & found_obs, isccp_tskin_halfdeg, std_isccp_tskin_halfdeg ) ! *** ONLY for "CEOP3n4_by_tile_FV_144x91" domain *** @@ -5340,7 +5402,7 @@ subroutine read_obs_isccp_ts_ceop3n4_hdASC( & ! ! inputs to this subroutine: ! date_time = current model date and time - ! N_catd = number of catchments in domain + ! N_catf = number of catchments in domain ! ! reichle, 1 Apr 2010 ! @@ -5352,16 +5414,16 @@ subroutine read_obs_isccp_ts_ceop3n4_hdASC( & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(obs_param_type), intent(in) :: this_obs_param ! outputs: - real, intent(out), dimension(N_catd) :: isccp_tskin_halfdeg - real, intent(out), dimension(N_catd) :: std_isccp_tskin_halfdeg + real, intent(out), dimension(N_catf) :: isccp_tskin_halfdeg + real, intent(out), dimension(N_catf) :: std_isccp_tskin_halfdeg logical, intent(out) :: found_obs ! --------------- @@ -5442,7 +5504,7 @@ subroutine read_obs_isccp_ts_ceop3n4_hdASC( & ! ------------------------------------------------------------------- - if (N_catd/=N_tiles) then + if (N_catf/=N_tiles) then err_msg = 'error 1 -- use only for CEOP3n4_by_tile_144x91 domain' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if @@ -5490,7 +5552,7 @@ subroutine read_obs_isccp_ts_ceop3n4_hdASC( & ! double-check tile ids - if (GEOS5_to_ISCCP(1,i)/=tile_coord(i)%tile_id) then + if (GEOS5_to_ISCCP(1,i)/=tile_coord_f(i)%tile_id) then !write (logunit,*) 'error 2 -- only for CEOP3n4_by_tile_144x91 domain' !stop @@ -5532,7 +5594,7 @@ subroutine read_obs_isccp_ts_ceop3n4_hdASC( & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_isccp_tskin_halfdeg(i) = this_obs_param%errstd end do @@ -5547,10 +5609,10 @@ end subroutine read_obs_isccp_ts_ceop3n4_hdASC ! ***************************************************************** - subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & - N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & - found_obs, SMOS_data, std_SMOS_data, SMOS_lon, SMOS_lat ) + subroutine read_obs_SMOS( date_time, N_catf, this_obs_param, & + dtstep_assim, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & + found_obs, SMOS_data, std_SMOS_data, SMOS_lon, SMOS_lat ) ! reader for preprocessed SMOS Tb and soil moisture (SM) files ! @@ -5592,13 +5654,15 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & type(date_time_type), intent(in) :: date_time type(obs_param_type), intent(in) :: this_obs_param - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input + + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input @@ -5609,8 +5673,8 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & logical, intent(out) :: found_obs - real, intent(out), dimension(N_catd) :: SMOS_data, std_SMOS_data - real, intent(out), dimension(N_catd) :: SMOS_lon, SMOS_lat + real, intent(out), dimension(N_catf) :: SMOS_data, std_SMOS_data + real, intent(out), dimension(N_catf) :: SMOS_lon, SMOS_lat ! -------------------------------------- @@ -5675,7 +5739,7 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & character( 80) :: tmpstr80 character(300) :: tmpfname - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile character(300), dimension(:), allocatable :: fnames @@ -6171,18 +6235,41 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & if (N_obs>0) then allocate(tmp_tile_num(N_obs)) - - ! temporarily shift lat/lon of obs for computation of nearest tile to - ! avoid ambiguous assignment of M09 model tile within M36 obs grid cell - ! (center of M36 grid cell is equidistant from at least two M09 model - ! tiles) -- reichle, 23 Aug 2013 - - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & - N_obs, tmp_lat, tmp_lon, & - this_obs_param, & - tmp_tile_num, & - tmp_shift_lat, tmp_shift_lon ) + + ! shift M36 obs lat/lon for proper assignment if tile space M09/M03/M01 (tiles nest in M36) + ! (as for the SMAP L1C obs readers) + + if ( index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2-M09') /=0 .or. & ! allow outdated grid name only for M09 + index(obs2tile_grid_f%gridtype, 'EASEv2_M03') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2_M01') /=0 ) then + + ! temporarily shift lat/lon of obs for computation of nearest tile to + ! avoid ambiguous assignment of M09 model tile within M36 obs grid cell + ! (center of M36 grid cell is equidistant from at least two M09 model + ! tiles) -- reichle, 23 Aug 2013 + + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & + N_obs, tmp_lat, tmp_lon, & + this_obs_param, & + tmp_tile_num, & + tmp_shift_lat, tmp_shift_lon ) + + else + + ! no shift in other tile spaces (e.g., cube-sphere), where shifting the obs lat/lon + ! can assign the obs to a tile other than the one at the obs location + + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & + N_obs, tmp_lat, tmp_lon, & + this_obs_param, & + tmp_tile_num ) + + end if ! -------------------------------------------------------------------------- ! @@ -6212,16 +6299,16 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & ! ! - reichle, 3 Feb 2016 ! ! if ( & - ! (index(tile_grid_d%gridtype, 'EASEv2_M09') /=0) .or. & - ! (index(tile_grid_d%gridtype, 'EASEv2_M36') /=0) ) then + ! (index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0) .or. & + ! (index(obs2tile_grid_f%gridtype, 'EASEv2_M36') /=0) ) then ! ! do ii=1,N_obs ! ! if (tmp_tile_num(ii)>0) then ! ! call MAPL_ease_convert('EASEv2_M36', & - ! tile_coord(tmp_tile_num(ii))%com_lat, & - ! tile_coord(tmp_tile_num(ii))%com_lon, & + ! tile_coord_f(tmp_tile_num(ii))%com_lat, & + ! tile_coord_f(tmp_tile_num(ii))%com_lon, & ! M36_col_ind_tile, M36_row_ind_tile ) ! ! call MAPL_ease_convert('EASEv2_M36', & @@ -6252,7 +6339,7 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & do i=1,N_obs - ind_tile = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind_tile = tmp_tile_num(i) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind_tile>0) then ! this step eliminates obs outside domain @@ -6268,7 +6355,7 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & ! normalize - do i=1,N_catd + do i=1,N_catf if (N_obs_in_tile(i)>1) then @@ -6296,7 +6383,7 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & ! set observation error standard deviation - do i=1,N_catd + do i=1,N_catf std_SMOS_data(i) = this_obs_param%errstd end do @@ -6372,24 +6459,32 @@ end subroutine read_obs_SMOS ! ***************************************************************** - subroutine read_obs_MODIS_SCF( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + subroutine read_obs_MODIS_VIIRS_SCF( & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, write_obslog, & - found_obs, MODIS_obs, std_MODIS_obs, MODIS_lon, MODIS_lat ) + found_obs, MVSCF_obs, std_MVSCF_obs, MVSCF_lon, MVSCF_lat ) - ! read MODIS snow cover fraction observations on MODIS 0.05-degree climate - ! modeling grid (CMG) + ! read MODIS or VIIRS snow cover fraction observations on MODIS/VIIRS 0.05-degree climate modeling grid (CMG) ! - ! Terra: MOD10C1 - ! Aqua: MYD10C1 + ! MODIS Terra : MOD10C1 + ! MODIS Aqua : MYD10C1 + ! VIIRS JPSS1/NOAA-20 : VJ110C1 (launched 2017) + ! VIIRS JPSS2/NOAA-21 : VJ210C1 (launched 2022) + ! VIIRS S-NPP : VNP10C1 (launched 2011, decommissioned 2026) ! - ! For now, assume that MODIS resolution is finer than Catchment tile space + ! For now, assume that MODIS/VIIRS SCF resolution is finer than Catchment tile space ! and super-ob data to tile space, with lat/lon coords of obs matching ! lat/lon coords of tiles ! ! reichle, 18 Oct 2023 ! + ! amfox, 5 Nov 2026 - obs on tiles at a window boundary are assimilated only once; + ! original file names ("granule_id") are written to the obslog + ! + ! reichle, amfox, 23 Nov 2026: unified MODIS and VIIRS SCF reader + ! ! ------------------------------------------------------------------------------ implicit none @@ -6399,16 +6494,18 @@ subroutine read_obs_MODIS_SCF( & type(date_time_type), intent(in) :: date_time integer, intent(in) :: dtstep_assim ! [seconds] - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: N_tile_in_cell_ij + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - + type(obs_param_type), intent(in) :: this_obs_param logical, intent(in) :: write_obslog @@ -6417,7 +6514,7 @@ subroutine read_obs_MODIS_SCF( & logical, intent(out) :: found_obs - real, dimension(N_catd), intent(out) :: MODIS_obs, std_MODIS_obs, MODIS_lon, MODIS_lat + real, dimension(N_catf), intent(out) :: MVSCF_obs, std_MVSCF_obs, MVSCF_lon, MVSCF_lat ! ------------------------------------------------------------------------ @@ -6425,13 +6522,13 @@ subroutine read_obs_MODIS_SCF( & integer, parameter :: dtstep_assim_max = 21600 ! [seconds] avoid assim window spanning >=180 deg lon - real, parameter :: CMG_dlon = 0.05 ! [degrees] longitude spacing of MODIS CMG grid - real, parameter :: CMG_dlat = 0.05 ! [degrees] latitude spacing of MODIS CMG grid + real, parameter :: CMG_dlon = 0.05 ! [degrees] longitude spacing of CMG grid + real, parameter :: CMG_dlat = 0.05 ! [degrees] latitude spacing of CMG grid - real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of MODIS CMG grid - real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of MODIS CMG grid + real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of CMG grid + real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of CMG grid - character( 7) :: MODIS_product_ID + character( 7) :: MVSCF_product_ID character( 4) :: YYYY character( 3) :: DDD ! day of year @@ -6451,14 +6548,14 @@ subroutine read_obs_MODIS_SCF( & integer :: N_CMG_obs, N_good_data, tmp_ind_start, tmp_ind_last type(date_time_type) :: date_time_beg, date_time_end - type(date_time_type) :: date_time_beg_MODIS, date_time_end_MODIS - type(date_time_type) :: date_time_obs_beg + type(date_time_type) :: date_time_beg_MVSCF, date_time_end_MVSCF + type(date_time_type) :: date_time_obs_beg, date_time_obs_end real :: lon_beg, lon_end - real :: lon_beg_MODIS, lon_end_MODIS + real :: lon_beg_MVSCF, lon_end_MVSCF integer :: delta_day_beg, delta_day_end - integer :: delta_day_beg_MODIS, delta_day_end_MODIS + integer :: delta_day_beg_MVSCF, delta_day_end_MVSCF real :: lat_min, lat_max @@ -6470,9 +6567,9 @@ subroutine read_obs_MODIS_SCF( & integer, dimension(:), allocatable :: tmp_tile_num - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile - character(len=*), parameter :: Iam = 'read_obs_MODIS_SCF' + character(len=*), parameter :: Iam = 'read_obs_MODIS_VIIRS_SCF' character(len=400) :: err_msg ! ------------------------------------------------------------------------------------ @@ -6481,12 +6578,21 @@ subroutine read_obs_MODIS_SCF( & found_obs = .false. - ! determine operating time range of sensor + ! determine operating time range of platform with MODIS/VIIRS sensor + date_time_obs_end = date_time_type(9999, 1, 1, 1, 1, 1,-9999,-9999) ! default: no end date + if (trim(this_obs_param%descr) == 'MOD10C1') then date_time_obs_beg = date_time_type(2000, 2,24, 1,31, 0,-9999,-9999) ! Terra elseif (trim(this_obs_param%descr) == 'MYD10C1') then date_time_obs_beg = date_time_type(2002, 7, 4, 8, 0, 0,-9999,-9999) ! Aqua + elseif (trim(this_obs_param%descr) == 'VJ110C1') then + date_time_obs_beg = date_time_type(2018, 1, 5, 0, 0, 0,-9999,-9999) ! JPSS1 + elseif (trim(this_obs_param%descr) == 'VJ210C1') then + date_time_obs_beg = date_time_type(2023, 2,10, 0, 0, 0,-9999,-9999) ! JPSS2 + elseif (trim(this_obs_param%descr) == 'VNP10C1') then + date_time_obs_beg = date_time_type(2012, 1,19, 0, 0, 0,-9999,-9999) ! S-NPP + date_time_obs_end = date_time_type(2026,11, 3, 0, 0, 0,-9999,-9999) else err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) @@ -6494,8 +6600,9 @@ subroutine read_obs_MODIS_SCF( & ! return if date_time falls outside operating time range - if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return - + if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return ! date_time too early for obs + if (datetime_lt_refdatetime(date_time_obs_end, date_time )) return ! date_time too late for obs + ! ---------------------------------------------------------------------------------- ! ! restrict assimilation time step to max allowed @@ -6507,16 +6614,23 @@ subroutine read_obs_MODIS_SCF( & end if - ! identify MODIS product and overpass hour - - MODIS_product_ID = this_obs_param%name(1:7) + ! identify MODIS/VIIRS product and overpass hour + ! (for VIIRS, see https://vlab.noaa.gov/web/towr-s/satellite-operations-updates) - select case (MODIS_product_ID) + MVSCF_product_ID = this_obs_param%name(1:7) + + select case (MVSCF_product_ID) case('MOD10C1'); overpass_hour = 10.5 ! [hours] Terra: 10:30am local time case('MYD10C1'); overpass_hour = 13.5 ! [hours] Aqua: 1:30pm local time + case('VJ110C1'); overpass_hour = 13.5 ! [hours] JPSS1: 1:30pm local time + + case('VJ210C1'); overpass_hour = 13.5 ! [hours] JPSS2: 1:30pm local time + + case('VNP10C1'); overpass_hour = 13.5 ! [hours] S-NPP: 1:30pm local time + end select @@ -6531,37 +6645,37 @@ subroutine read_obs_MODIS_SCF( & ! determine longitude band associated with assimilation window and local overpass hour ! - ! observations will be returned only for tiles with lon_end < tile_coord%com_lon <= lon_beg + ! observations will be returned only for tiles with lon_end < tile_coord_f%com_lon <= lon_beg call localtime2longitude( date_time_beg, overpass_hour, lon_beg, delta_day_beg ) call localtime2longitude( date_time_end, overpass_hour, lon_end, delta_day_end ) - ! determine (rough) longitude band for which MODIS obs need to be read + ! determine (rough) longitude band for which MODIS/VIIRS obs need to be read ! - ! --> because tiles have a non-zero extent, need to read MODIS obs in CMG grid cells located + ! --> because tiles have a non-zero extent, need to read MODIS/VIIRS obs in CMG grid cells located ! in a wider band (lon_min-delta:lon_max+delta), - ! where delta should be somewhat larger than max( tile_coord%max_lon - tile_coord%min_lon ) + ! where delta should be somewhat larger than max( tile_coord_f%max_lon - tile_coord_f%min_lon ) - tmp_delta = 3.*maxval( tile_coord(1:N_catd)%max_lon - tile_coord(1:N_catd)%min_lon ) ! [degrees] + tmp_delta = 3.*maxval( tile_coord_f(1:N_catf)%max_lon - tile_coord_f(1:N_catf)%min_lon ) ! [degrees] - tmp_delta = tmp_delta/360.*86400. ! [seconds] + tmp_delta = tmp_delta/360.*86400. ! [seconds] - date_time_beg_MODIS = date_time_beg - date_time_end_MODIS = date_time_end + date_time_beg_MVSCF = date_time_beg + date_time_end_MVSCF = date_time_end - call augment_date_time( -nint(tmp_delta), date_time_beg_MODIS ) - call augment_date_time( nint(tmp_delta), date_time_end_MODIS ) + call augment_date_time( -nint(tmp_delta), date_time_beg_MVSCF ) + call augment_date_time( nint(tmp_delta), date_time_end_MVSCF ) - call localtime2longitude( date_time_beg_MODIS, overpass_hour, lon_beg_MODIS, delta_day_beg_MODIS ) - call localtime2longitude( date_time_end_MODIS, overpass_hour, lon_end_MODIS, delta_day_end_MODIS ) + call localtime2longitude( date_time_beg_MVSCF, overpass_hour, lon_beg_MVSCF, delta_day_beg_MVSCF ) + call localtime2longitude( date_time_end_MVSCF, overpass_hour, lon_end_MVSCF, delta_day_end_MVSCF ) - ! adjust date_time_*_MODIS to reflect calendar date at lon_*_MODIS + ! adjust date_time_*_MVSCF to reflect calendar date at lon_*_MVSCF - call augment_date_time( delta_day_beg_MODIS*86400, date_time_beg_MODIS ) - call augment_date_time( delta_day_end_MODIS*86400, date_time_end_MODIS ) + call augment_date_time( delta_day_beg_MVSCF*86400, date_time_beg_MVSCF ) + call augment_date_time( delta_day_end_MVSCF*86400, date_time_end_MVSCF ) - ! put together arguments for call(s) to read_MODIS_SCF_hdf() + ! put together arguments for call(s) to read_MODIS_SCF_hdf() or read_VIIRS_SCF_hdf() lon_min_vec = MAPL_UNDEF lon_max_vec = MAPL_UNDEF @@ -6571,19 +6685,19 @@ subroutine read_obs_MODIS_SCF( & N_lon_vec = 0 - if (lon_end_MODIS < lon_beg_MODIS) then + if (lon_end_MVSCF < lon_beg_MVSCF) then - if ( date_time_end_MODIS%dofyr == date_time_beg_MODIS%dofyr ) then + if ( date_time_end_MVSCF%dofyr == date_time_beg_MVSCF%dofyr ) then - ! need only one daily MODIS file and longitude band + ! need only one daily MODIS/VIIRS file and longitude band N_files = 1 - lon_min_vec(1) = lon_end_MODIS - lon_max_vec(1) = lon_beg_MODIS + lon_min_vec(1) = lon_end_MVSCF + lon_max_vec(1) = lon_beg_MVSCF - year_vec( 1) = date_time_beg_MODIS%year - dofyr_vec( 1) = date_time_beg_MODIS%dofyr + year_vec( 1) = date_time_beg_MVSCF%year + dofyr_vec( 1) = date_time_beg_MVSCF%dofyr else @@ -6593,12 +6707,12 @@ subroutine read_obs_MODIS_SCF( & write (logunit,*) 'date_time = ', date_time write (logunit,*) 'date_time_beg = ', date_time_beg write (logunit,*) 'date_time_end = ', date_time_end - write (logunit,*) 'date_time_beg_MODIS = ', date_time_beg_MODIS - write (logunit,*) 'date_time_end_MODIS = ', date_time_end_MODIS + write (logunit,*) 'date_time_beg_MVSCF = ', date_time_beg_MVSCF + write (logunit,*) 'date_time_end_MVSCF = ', date_time_end_MVSCF write (logunit,*) 'lon_beg = ', lon_beg write (logunit,*) 'lon_end = ', lon_end - write (logunit,*) 'lon_beg_MODIS = ', lon_beg_MODIS - write (logunit,*) 'lon_end_MODIS = ', lon_end_MODIS + write (logunit,*) 'lon_beg_MVSCF = ', lon_beg_MVSCF + write (logunit,*) 'lon_end_MVSCF = ', lon_end_MVSCF err_msg = 'encountered unexpected condition for longitude band!!!' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) @@ -6607,24 +6721,24 @@ subroutine read_obs_MODIS_SCF( & else - ! longitude band wraps around dateline, two daily MODIS files are needed - ! (this could also occur if lon_*_MODIS=180., which would result in an + ! longitude band wraps around dateline, two daily MODIS/VIIRS files are needed + ! (this could also occur if lon_*_MVSCF=180., which would result in an ! empty first longitude band, but because of tmp_delta>0, this should ! never happen) N_files = 2 - lon_min_vec(1) = lon_end_MODIS + lon_min_vec(1) = lon_end_MVSCF lon_max_vec(1) = 179.999 ! use 179.999 such that zero-based last_ind<=N_lon-1 (see below) - year_vec( 1) = date_time_end_MODIS%year - dofyr_vec( 1) = date_time_end_MODIS%dofyr + year_vec( 1) = date_time_end_MVSCF%year + dofyr_vec( 1) = date_time_end_MVSCF%dofyr lon_min_vec(2) = -180. - lon_max_vec(2) = lon_beg_MODIS + lon_max_vec(2) = lon_beg_MVSCF - year_vec( 2) = date_time_beg_MODIS%year - dofyr_vec( 2) = date_time_beg_MODIS%dofyr + year_vec( 2) = date_time_beg_MVSCF%year + dofyr_vec( 2) = date_time_beg_MVSCF%dofyr end if @@ -6647,8 +6761,8 @@ subroutine read_obs_MODIS_SCF( & ! determine latitude band covered by domain (no need to read obs outside domain) - lat_min = minval( tile_coord(1:N_catd)%min_lat ) - lat_max = maxval( tile_coord(1:N_catd)%max_lat ) + lat_min = minval( tile_coord_f(1:N_catf)%min_lat ) + lat_max = maxval( tile_coord_f(1:N_catf)%max_lat ) ! determine N_lat and N_lon[_vec] (# CMG grid cells in lat/lon bands ) @@ -6665,25 +6779,7 @@ subroutine read_obs_MODIS_SCF( & N_lon = sum( N_lon_vec(1:N_files) ) - - - ! ! dbg ! ! write (*,*) '###############################################################################' - ! ! dbg ! ! write (*,*) Iam // '():' - ! ! dbg ! ! write (*,*) 'lon_min_vec = ', lon_min_vec - ! ! dbg ! ! write (*,*) 'lon_max_vec = ', lon_max_vec - ! ! dbg ! ! write (*,*) 'start_ind = ', start_ind - ! ! dbg ! ! write (*,*) 'last_ind = ', last_ind - ! ! dbg ! ! write (*,*) 'lat_min = ', lat_min - ! ! dbg ! ! write (*,*) 'lat_max = ', lat_max - ! ! dbg ! ! write (*,*) 'year_vec = ', year_vec - ! ! dbg ! ! write (*,*) 'dofyr_vec = ', dofyr_vec - ! ! dbg ! ! write (*,*) 'N_lon_vec = ', N_lon_vec - ! ! dbg ! ! write (*,*) 'N_lat = ', N_lat - ! ! dbg ! ! write (*,*) '###############################################################################' - - - - ! allocate arrays for MODIS CMG data (max size that could possibly be needed for obs from both files) + ! allocate arrays for MODIS/VIIRS CMG data (max size that could possibly be needed for obs from both files) N_tmp = N_lon*N_lat @@ -6692,52 +6788,92 @@ subroutine read_obs_MODIS_SCF( & allocate( CMG_lat(N_tmp) ) - ! read MODIS SCF obs - ! - ! - (renamed) files currently located at /discover/nobackup/projects/S2SHMA/MODIS/MOD10C1_V61/ (2010-2022) - ! - ! - in ensupd nml file, specify the file "name" according to the following template: - ! - ! %name = 'MOD10C1.Ayyyyddd.061.hdf' - ! - ! 1 2 - ! 123456789012345678901234 - ! - ! MOD10C1 = MODIS product name - ! .A = "acquisition time" indicator - ! yyyyddd = placeholder for year/day-of-year - ! .061 = version (Collection) indicator - ! .hdf = file name extension - ! - ! Assuming the MODIS file naming convention remains unchanged, the version can then - ! be specified in the nml file. + ! read MODIS/VIIRS SCF obs from hdf/h5 files - N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_MODIS_SCF_hdf() + N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_MODIS_SCF_hdf(), read_VIIRS_SCF_hdf() do nn=1,N_files ! loop through longitude bands (i.e., files) - ! determine MODIS file name(s) + ! determine MODIS/VIIRS file name(s) write (YYYY,'(i4.4)') year_vec( nn) write (DDD, '(i3.3)') dofyr_vec(nn) - fname = & - trim(this_obs_param%path) // '/' // YYYY // '/' // & - this_obs_param%name(1:9) // YYYY // DDD // this_obs_param%name(17:24) - ! determine sub-array of CMG_* tmp_ind_start = N_CMG_obs + 1 tmp_ind_last = N_CMG_obs + N_lon_vec(nn)*N_lat - call read_MODIS_SCF_hdf( fname, & - lon_min_vec(nn), lon_max_vec(nn), lat_min, lat_max, & - N_good_data, & - CMG_lon(tmp_ind_start:tmp_ind_last), & - CMG_lat(tmp_ind_start:tmp_ind_last), & - CMG_obs(tmp_ind_start:tmp_ind_last), & - granule_id ) + select case (MVSCF_product_ID) + + case( 'MOD10C1', 'MYD10C1' ) + ! (renamed) files currently located at /discover/nobackup/projects/S2SHMA/MODIS/MOD10C1_V61/ (2010-2022) + ! + ! in ensupd nml file, specify the file "name" according to the following template: + ! + ! %name = 'MOD10C1.Ayyyyddd.061.hdf' + ! + ! 1 2 + ! 123456789012345678901234 + ! + ! MOD10C1 = MODIS product name + ! .A = "acquisition time" indicator + ! yyyyddd = placeholder for year/day-of-year + ! .061 = version (Collection) indicator + ! .hdf = file name extension + ! + ! assuming the MODIS file naming convention remains unchanged, the version can then + ! be specified in the nml file. + + fname = & + trim(this_obs_param%path) // '/' // YYYY // '/' // & + this_obs_param%name(1:9) // YYYY // DDD // this_obs_param%name(17:24) + + call read_MODIS_SCF_hdf( fname, & + lon_min_vec(nn), lon_max_vec(nn), lat_min, lat_max, & + N_good_data, & + CMG_lon(tmp_ind_start:tmp_ind_last), & + CMG_lat(tmp_ind_start:tmp_ind_last), & + CMG_obs(tmp_ind_start:tmp_ind_last), & + granule_id ) + + case( 'VJ110C1', 'VJ210C1', 'VNP10C1') + + ! files must be renamed (production time stamp removed): + ! original name: VJ110C1.AYYYYDDD.002.yyyydddhhmmss.h5 + ! renamed: VJ110C1.AYYYYDDD.002.h5 + ! + ! in ensupd nml file, specify the file "name" according to the following template: + ! + ! %name = 'VJ110C1.Ayyyyddd.002.h5' + ! + ! 1 2 + ! 12345678901234567890123 + ! + ! VJ110C1 = VIIRS product name (VNP10C1, VJ110C1, or VJ210C1) + ! .A = "acquisition time" indicator + ! yyyyddd = placeholder for year/day-of-year + ! .002 = version (Collection) indicator + ! .h5 = file name extension + ! + ! Assuming the VIIRS file naming convention remains unchanged, the version can then + ! be specified in the nml file. + + fname = & + trim(this_obs_param%path) // '/' // YYYY // '/' // & + this_obs_param%name(1:9) // YYYY // DDD // this_obs_param%name(17:23) + + call read_VIIRS_SCF_hdf( fname, & + lon_min_vec(nn), lon_max_vec(nn), lat_min, lat_max, & + N_good_data, & + CMG_lon(tmp_ind_start:tmp_ind_last), & + CMG_lat(tmp_ind_start:tmp_ind_last), & + CMG_obs(tmp_ind_start:tmp_ind_last), & + granule_id ) + + end select + N_CMG_obs = N_CMG_obs + N_good_data ! record number of good obs and file name for obslog @@ -6781,7 +6917,7 @@ subroutine read_obs_MODIS_SCF( & end if - ! return if no MODIS obs were found (found_obs=.false. per initialization above) + ! return if no MODIS/VIIRS obs were found (found_obs=.false. per initialization above) if (N_CMG_obs==0) return @@ -6790,31 +6926,31 @@ subroutine read_obs_MODIS_SCF( & allocate(tmp_tile_num(N_CMG_obs)) - call get_tile_num_for_obs( N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, & - tile_num_in_cell_ij, & + call get_tile_num_for_obs( N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_CMG_obs, CMG_lat(1:N_CMG_obs), CMG_lon(1:N_CMG_obs), & this_obs_param, & - tmp_tile_num ) + tmp_tile_num ) - std_MODIS_obs = this_obs_param%errstd + std_MVSCF_obs = this_obs_param%errstd - MODIS_obs = 0. - MODIS_lon = 0. - MODIS_lat = 0. + MVSCF_obs = 0. + MVSCF_lon = 0. + MVSCF_lat = 0. N_obs_in_tile = 0 do kk=1,N_CMG_obs - ind = tmp_tile_num(kk) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind = tmp_tile_num(kk) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind>0) then ! this condition eliminates obs outside domain - MODIS_obs( ind) = MODIS_obs( ind) + CMG_obs(kk) - MODIS_lon( ind) = MODIS_lon( ind) + CMG_lon(kk) - MODIS_lat( ind) = MODIS_lat( ind) + CMG_lat(kk) + MVSCF_obs( ind) = MVSCF_obs( ind) + CMG_obs(kk) + MVSCF_lon( ind) = MVSCF_lon( ind) + CMG_lon(kk) + MVSCF_lat( ind) = MVSCF_lat( ind) + CMG_lat(kk) N_obs_in_tile(ind) = N_obs_in_tile(ind) + 1 @@ -6824,20 +6960,20 @@ subroutine read_obs_MODIS_SCF( & ! normalize - do kk=1,N_catd + do kk=1,N_catf if (N_obs_in_tile(kk)>0) then tmp_real = real(N_obs_in_tile(kk)) - MODIS_obs(kk) = MODIS_obs(kk)/tmp_real - MODIS_lon(kk) = MODIS_lon(kk)/tmp_real - MODIS_lat(kk) = MODIS_lat(kk)/tmp_real + MVSCF_obs(kk) = MVSCF_obs(kk)/tmp_real + MVSCF_lon(kk) = MVSCF_lon(kk)/tmp_real + MVSCF_lat(kk) = MVSCF_lat(kk)/tmp_real else if (N_obs_in_tile(kk)==0) then - MODIS_obs(kk) = this_obs_param%nodata - MODIS_lon(kk) = this_obs_param%nodata - MODIS_lat(kk) = this_obs_param%nodata + MVSCF_obs(kk) = this_obs_param%nodata + MVSCF_lon(kk) = this_obs_param%nodata + MVSCF_lat(kk) = this_obs_param%nodata end if end do @@ -6858,7 +6994,7 @@ subroutine read_obs_MODIS_SCF( & deallocate(CMG_lon) deallocate(CMG_lat) - ! to avoid double-counting of MODIS CMG obs, remove obs for tiles with center-of-mass longitude + ! to avoid double-counting of MODIS/VIIRS CMG obs, remove obs for tiles with center-of-mass longitude ! falling outside the longitude band associated with assimilation window ! ! the band excludes lon_end, so that a tile with com_lon exactly on the boundary between two @@ -6869,10 +7005,10 @@ subroutine read_obs_MODIS_SCF( & ! need only one longitude band (keep obs when lon_endlon_beg) ) & - MODIS_obs(kk) = this_obs_param%nodata + if ( (tile_coord_f(kk)%com_lon<=lon_end) .or. (tile_coord_f(kk)%com_lon>lon_beg) ) & + MVSCF_obs(kk) = this_obs_param%nodata end do @@ -6880,19 +7016,19 @@ subroutine read_obs_MODIS_SCF( & ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_endlon_beg) .and. (tile_coord(kk)%com_lon<=lon_end) ) & - MODIS_obs(kk) = this_obs_param%nodata + if ( (tile_coord_f(kk)%com_lon>lon_beg) .and. (tile_coord_f(kk)%com_lon<=lon_end) ) & + MVSCF_obs(kk) = this_obs_param%nodata end do end if - end subroutine read_obs_MODIS_SCF + end subroutine read_obs_MODIS_VIIRS_SCF - ! ******************************************************************************************************* + ! ***************************************************************** subroutine localtime2longitude( date_time, local_hour, longitude, delta_day ) @@ -7057,7 +7193,7 @@ subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! Added output of "granule_id", which is the original MODIS file name including the production ! date/time stamp. The MODIS file names on Discover were stripped of the production date/time ! stamp to make the file names predictable. The "granule_id" is returned so the information - ! can be added into the "obslog" file by the calling subroutine read_obs_MODIS_SCF() + ! can be added into the "obslog" file by the calling subroutine read_obs_MODIS_VIIRS_SCF() ! - amfox, reichle, 4 Nov 2026 ! ! ------------------------------------------------------------------------------------------------- @@ -7290,7 +7426,7 @@ subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & end if ! get original file name (incl. production time stamp) because files are renamed; returned to - ! read_obs_MODIS_SCF() for the obslog, identifies the exact obs file version used in an experiment + ! read_obs_MODIS_VIIRS_SCF() for the obslog, identifies the exact obs file version used in an experiment call get_MODIS_granule_id( sd_id, granule_id ) @@ -7306,7 +7442,7 @@ subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & if ( (dimsizes(1)/=CMG_N_lon) .or. (dimsizes(2)/=CMG_N_lat) ) then - err_msg = 'dimensions in hdf file doe not match CMG_N_lon and/or CMG_N_lat' + err_msg = 'dimensions in hdf file do not match CMG_N_lon and/or CMG_N_lat' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if @@ -7434,13 +7570,344 @@ subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & deallocate(Snow_Spatial_QA) end subroutine read_MODIS_SCF_hdf + + ! ***************************************************************** + + subroutine read_VIIRS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & + N_good_data, CMG_lon, CMG_lat, CMG_SCF, granule_id ) + + ! read snow cover area fraction (SCF) obs from daily VIIRS V[NP|J1|J2]10C1, version 2 (hdf5) + ! - S-NPP: https://nsidc.org/data/vnp10c1/versions/2 + ! - JPSS1: https://nsidc.org/data/vj110c1/versions/2 + ! - JPSS2: https://nsidc.org/data/vj210c1/versions/2 + ! - daily data with spatial resolution of 0.05 deg on MODIS/VIIRS climate modeling grid (CMG) + ! - data are read for the requested lat/lon range + ! - apply QC + ! + ! amfox, 2 Nov 2026 - hdf5 version for VIIRS, adapted from read_MODIS_SCF_hdf() + ! + ! Added output of "granule_id", which is the original VIIRS file name including the production + ! date/time stamp (global attribute "LocalGranuleID"). The VIIRS file names on Discover are + ! stripped of the production date/time stamp to make the file names predictable. The + ! "granule_id" is returned so the information can be added into the "obslog" file by the + ! calling subroutine read_obs_MODIS_VIIRS_SCF() + ! - amfox, 5 Nov 2026 + ! + ! ------------------------------------------------------------------------------------------------- + + implicit none + + character(*), intent(in) :: fname ! VIIRS file name with full path + + real, intent(in) :: lon_min, lon_max ! -180 <= lon_* <= 180 + real, intent(in) :: lat_min, lat_max ! -90 <= lat_* <= 90 + + integer, intent(out) :: N_good_data + + real, dimension(:), intent(out) :: CMG_lon, CMG_lat, CMG_SCF ! NOTE: 1-dim array on CMG grid + + character(256), intent(out) :: granule_id ! original VIIRS file name (incl. production time stamp) + + ! ------------------------------------------------- + + ! local parameters + + ! ll/ur_lon/lat simply indicate the extent of the CMG grid + ! + ! index increases from (-180,90) to (180,-90) (southward and eastward) + + integer, parameter :: CMG_N_lon = 7200 + integer, parameter :: CMG_N_lat = 3600 + + real, parameter :: CMG_ll_lon = -180. + real, parameter :: CMG_ll_lat = -90. + + real, parameter :: CMG_ur_lon = 180. + real, parameter :: CMG_ur_lat = 90. + + real, parameter :: CMG_dlon = 0.05 + real, parameter :: CMG_dlat = 0.05 + + integer, parameter :: N_fields = 3 + + character(*), parameter :: field_path = '/HDFEOS/GRIDS/VIIRS_Daily_SnowCover_CMG/Data Fields/' + + character(11), dimension(N_fields), parameter :: field_names = (/ & + 'Snow_Cover ', & ! 1 + 'Clear_Index', & ! 2 + 'Basic_QA '/) ! 3 + + ! 12345678901 + ! 1 + + integer, parameter :: SCF_nodata = -9999. + + integer, parameter :: qc_snow_cover_max = 100 ! exclude no decision, night, lake, ocean, fill, etc + integer, parameter :: qc_clear_index_min = 20 ! ensure sufficiently clear conditions + integer, parameter :: qc_clear_index_max = 100 ! exclude flag values (e.g., Antarctica) + integer, parameter :: qc_basic_qa_good = 0 ! keep Basic_QA=0 ("good" quality) + integer, parameter :: qc_basic_qa_other = 3 ! keep Basic_QA=3 ("other", low illumination) + + integer, parameter :: uint8_min = 0 + integer, parameter :: uint8_max = 255 + + + ! local variables + + integer :: N_lon, N_lat, N_tmp, ii, jj, kk, nn + + real, dimension(:), allocatable :: lon_c + real, dimension(:), allocatable :: lat_c + + real, dimension(:), allocatable :: lon_ind + real, dimension(:), allocatable :: lat_ind + + integer, dimension(2) :: start, last + + integer, dimension(7) :: dimsizes + + logical :: file_exists, keep_data + + integer :: rank + + type(hdf5read) :: h5r + + integer, dimension(:,:), allocatable :: Snow_Cover + integer, dimension(:,:), allocatable :: Clear_Index + integer, dimension(:,:), allocatable :: Basic_QA + + character(len=*), parameter :: Iam = 'read_VIIRS_SCF_hdf' + character(len=400) :: err_msg + + ! ------------------------------------------------------------------------- + ! + ! make sure file exists + + granule_id = '' + + inquire( file=trim(fname), exist=file_exists ) + + if (.not. file_exists ) then + + if (logit) then + write (logunit,'(400A)') trim(Iam), ': cannot find file ', trim(fname) + write (logunit,* ) 'not reading VIIRS SCF obs' + end if + + N_good_data = 0 + + return + + end if + + ! ensure lon_* and lat_* inputs are within range + + if ( (lon_min < CMG_ll_lon) .or. & + (lon_max > CMG_ur_lon) .or. & + (lat_min < CMG_ll_lat) .or. & + (lat_max > CMG_ur_lat) ) then + + err_msg = 'lat/lon min/max inputs out of range' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! determine CMG array indices for requested lat/lon_min/max range + + ! VIIRS CMG hdf5 files: + ! - lat-by-lon in the file (3600x7200), which is lon-by-lat in Fortran + ! - index values increase eastward and southward + + start(1) = (lon_min - CMG_ll_lon)/CMG_dlon ! 0-based [as required for hdf read] + start(2) = (CMG_ur_lat - lat_max )/CMG_dlat ! 0-based [as required for hdf read] + + last(1) = (lon_max - CMG_ll_lon)/CMG_dlon ! 0-based [as required for hdf read] + last(2) = (CMG_ur_lat - lat_min )/CMG_dlat ! 0-based [as required for hdf read] + + N_lon = last(1) - start(1) + 1 + N_lat = last(2) - start(2) + 1 + + ! checks array dimensions + + N_tmp = N_lon*N_lat + + if ( (N_tmp /= size(CMG_lon)) .or. & + (N_tmp /= size(CMG_lat)) .or. & + (N_tmp /= size(CMG_SCF)) ) then + + err_msg = 'inconsistent array dimensions' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! check array bounds + + if ( ( start(1) < 0 ) .or. ( start(1) > CMG_N_lon - 1 ) .or. & + ( start(2) < 0 ) .or. ( start(2) > CMG_N_lat - 1 ) .or. & + ( last( 1) < 0 ) .or. ( last( 1) > CMG_N_lon - 1 ) .or. & + ( last( 2) < 0 ) .or. ( last( 2) > CMG_N_lat - 1 ) .or. & + ( start(1) > last(1) ) .or. ( start(2) > last(2) ) & + ) then + + err_msg = 'start/edge indices out of bounds' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + if (logit) then + write (logunit,'(400A)') trim(Iam), '(): reading VIIRS SCF obs from ', trim(fname) + write (logunit,* ) ' N_lon, N_lat, lon_min, lon_max, lat_min, lat_max = ' + write (logunit,* ) N_lon, N_lat, lon_min, lon_max, lat_min, lat_max + end if + + + ! allocate arrays + + allocate(lon_c( N_lon)) + allocate(lat_c( N_lat)) + + allocate(lon_ind(N_lon)) + allocate(lat_ind(N_lat)) + + allocate(Snow_Cover (N_lon,N_lat)) + allocate(Clear_Index(N_lon,N_lat)) + allocate(Basic_QA (N_lon,N_lat)) + ! -------------------------- + + ! determine center lat/lon of CMG cells + + lon_ind = (/(ii, ii=0, N_lon-1, 1)/) ! =0:(N_lon-1) + lat_ind = (/(jj, jj=0, N_lat-1, 1)/) ! =0:(N_lat-1) + + ! lat_c, lon_c are lat/lon at center of CMG grid cell + + lon_c = CMG_ll_lon + 0.5*CMG_dlon + (start(1)+lon_ind)*CMG_dlon + lat_c = CMG_ur_lat - 0.5*CMG_dlat - (start(2)+lat_ind)*CMG_dlat + + ! -------------------------- + + ! open hdf5 file (read-only) + + call h5r%openFile(trim(fname)) + + ! get original file name (incl. production time stamp) because files are renamed; returned to + ! read_obs_MODIS_VIIRS_SCF() for the obslog, identifies the exact obs file version used in an experiment + ! (blank if the attribute is missing or cannot be read) + + call h5r%readAttribute('LocalGranuleID', granule_id) + + ! read data + + do nn=1,N_fields + + call h5r%queryDataset(field_path // trim(field_names(nn)), rank, dimsizes) + + if ( (rank/=2) .or. (dimsizes(1)/=CMG_N_lon) .or. (dimsizes(2)/=CMG_N_lat) ) then + + err_msg = 'dimensions in hdf5 file do not match CMG_N_lon and/or CMG_N_lat' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + select case (nn) + + case (1); call h5r%readDataset(Snow_Cover, start) + case (2); call h5r%readDataset(Clear_Index, start) + case (3); call h5r%readDataset(Basic_QA, start) + + case default; call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown field') + + end select + + end do + + call h5r%closeFile ! close hdf5 file + + ! check range (make sure uint8 from hdf5 file is correctly translated into Fortran integer) + + if ( any(Snow_Cover < uint8_min) .or. & + any(Snow_Cover > uint8_max) .or. & + any(Clear_Index < uint8_min) .or. & + any(Clear_Index > uint8_max) .or. & + any(Basic_QA < uint8_min) .or. & + any(Basic_QA > uint8_max) ) then + + err_msg = 'unexpected range in data from hdf5 file' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! ------------------------------------- + ! + ! apply QC and put SCF obs into output array + + CMG_lon = SCF_nodata ! initialize + CMG_lat = SCF_nodata ! initialize + CMG_SCF = SCF_nodata ! initialize + + kk = 0 ! initialize counter for "good" data + + do ii=1,N_lon + do jj=1,N_lat + + ! note: Snow_Cover >= 0 per range check above, no need to check for minimum + + keep_data = & + ( Snow_Cover( ii,jj) <= qc_snow_cover_max ) .and. & ! 0<=SCF<=100 (1) + ( Clear_Index(ii,jj) > qc_clear_index_min ) .and. & ! sufficiently clear sky (2) + ( Clear_Index(ii,jj) <= qc_clear_index_max ) .and. & ! 0<=CI<=100 (3) + ( Basic_QA( ii,jj) == qc_basic_qa_good .or. Basic_QA(ii,jj) == qc_basic_qa_other ) ! keep "good" or "other" (4) + + ! (1) excludes "no decision", "night", "lake", "ocean", "fill", etc; cloud is not + ! flagged (cloudy cells have low Clear_Index); Antarctica has Snow_Cover=100 + ! (2) Snow_Cover and Clear_Index are percent of all obs in grid cell + ! (3) excludes Antarctica (Clear_Index=243) and other flag values + ! (4) Basic_QA key as in the CMG file attributes and the VNP10C1 v2 user guide; + ! "other" = low illumination (70<=SZA<85 deg); must be kept to retain most + ! high-latitude winter obs (as with MODIS reader); Basic_QA=1 ("poor") and 2 ("bad") + ! are excluded because Basic_QA=1 obs agree poorly with MODIS (15 Jan 2020 comparison) + + if (keep_data) then + + kk = kk + 1 + + ! raw SCF value is percent of all obs in grid cell, need to normalize with Clear_Index; + ! cap at 1 because VIIRS Snow_Cover can exceed Clear_Index by 1 (rounding) + + CMG_SCF(kk) = min( 1., real(Snow_Cover(ii,jj))/real(Clear_Index(ii,jj)) ) + + CMG_lon(kk) = lon_c(ii) + CMG_lat(kk) = lat_c(jj) + + end if + + end do + end do + + N_good_data = kk + + if (logit) write (logunit,*) 'N_good_data = ', N_good_data + + deallocate(lat_c) + deallocate(lon_c) + + deallocate(lat_ind) + deallocate(lon_ind) + + deallocate(Snow_Cover ) + deallocate(Clear_Index) + deallocate(Basic_QA ) + + end subroutine read_VIIRS_SCF_hdf + + ! ***************************************************************** - - subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & + + subroutine read_obs_SMAP_FT( date_time, N_catf, this_obs_param, & + dtstep_assim, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & - found_obs, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time ) + found_obs, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time ) ! read freeze/thaw (FT) data within the assimilation window from one or more ! SMAP L2_SM_AP half-orbit h5 files (or L3_FT_A files -- TO BE IMPLEMENTED) @@ -7456,15 +7923,17 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd, dtstep_assim + integer, intent(in) :: N_catf, dtstep_assim type(obs_param_type), intent(in) :: this_obs_param - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input @@ -7475,9 +7944,9 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & logical, intent(out) :: found_obs - real, intent(out), dimension(N_catd) :: SMAP_data, std_SMAP_data - real, intent(out), dimension(N_catd) :: SMAP_lon, SMAP_lat - real*8, intent(out), dimension(N_catd) :: SMAP_time ! J2000 seconds + real, intent(out), dimension(N_catf) :: SMAP_data, std_SMAP_data + real, intent(out), dimension(N_catf) :: SMAP_lon, SMAP_lat + real*8, intent(out), dimension(N_catf) :: SMAP_time ! J2000 seconds ! -------------------------------------- @@ -7544,7 +8013,7 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & integer, dimension(7) :: dset_size integer, dimension(N_fnames_max) :: N_obs_kept - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile real, dimension(:), allocatable :: tmp_lon, tmp_lat @@ -7933,8 +8402,9 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & allocate(tmp_tile_num(N_obs_kept(kk))) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_obs_kept(kk), & tmp_lat(1:N_obs_kept(kk)), & tmp_lon(1:N_obs_kept(kk)), & @@ -7979,16 +8449,16 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & ! ! - reichle, 3 Feb 2016 ! ! if ( & - ! (index(tile_grid_d%gridtype, 'EASEv2_M09') /=0) .or. & - ! (index(tile_grid_d%gridtype, 'EASEv2_M36') /=0) ) then + ! (index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0) .or. & + ! (index(obs2tile_grid_f%gridtype, 'EASEv2_M36') /=0) ) then ! ! do ii=1,N_obs_kept(kk) ! ! if (tmp_tile_num(ii)>0) then ! ! call MAPL_ease_convert('EASEv2_M09', & - ! tile_coord(tmp_tile_num(ii))%com_lat, & - ! tile_coord(tmp_tile_num(ii))%com_lon, & + ! tile_coord_f(tmp_tile_num(ii))%com_lat, & + ! tile_coord_f(tmp_tile_num(ii))%com_lon, & ! M09_col_ind_tile, M09_row_ind_tile ) ! ! call MAPL_ease_convert('EASEv2_M09', & @@ -8014,7 +8484,7 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & do ii=1,N_obs_kept(kk) - ind_tile = tmp_tile_num(ii) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind_tile = tmp_tile_num(ii) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind_tile>0) then ! this step eliminates obs outside domain @@ -8045,7 +8515,7 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & ! normalize - do ii=1,N_catd + do ii=1,N_catf if (N_obs_in_tile(ii)>1) then @@ -8071,7 +8541,7 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & ! set observation error standard deviation - do ii=1,N_catd + do ii=1,N_catf std_SMAP_data(ii) = this_obs_param%errstd end do @@ -8122,10 +8592,10 @@ end subroutine read_obs_SMAP_FT ! ***************************************************************** - subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & + subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catf, this_obs_param, & + dtstep_assim, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & - found_obs, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time ) + found_obs, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time ) ! read brightness temperature data within the assimilation window from one or more ! SMAP half-orbit h5 files (L1C, L1CE (Enhanced), or L2AP) @@ -8154,15 +8624,17 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & type(date_time_type), intent(in) :: date_time - integer, intent(in) :: N_catd, dtstep_assim + integer, intent(in) :: N_catf, dtstep_assim type(obs_param_type), intent(in) :: this_obs_param - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input @@ -8173,9 +8645,9 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & logical, intent(out) :: found_obs - real, intent(out), dimension(N_catd) :: SMAP_data, std_SMAP_data - real, intent(out), dimension(N_catd) :: SMAP_lon, SMAP_lat - real*8, intent(out), dimension(N_catd) :: SMAP_time ! J2000 seconds + real, intent(out), dimension(N_catf) :: SMAP_data, std_SMAP_data + real, intent(out), dimension(N_catf) :: SMAP_lon, SMAP_lat + real*8, intent(out), dimension(N_catf) :: SMAP_time ! J2000 seconds ! -------------------------------------- @@ -8265,7 +8737,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & integer, dimension(7) :: dset_size integer, dimension(N_fnames_max) :: N_obs_kept - integer, dimension(N_catd) :: N_obs_in_tile + integer, dimension(N_catf) :: N_obs_in_tile real, dimension(:), allocatable :: tmp_lon, tmp_lat @@ -9028,18 +9500,26 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & if (N_obs_kept(kk)>0) then allocate(tmp_tile_num(N_obs_kept(kk))) + + ! shift M36 obs lat/lon for proper assignment if tile space M09/M03/M01 (tiles nest in M36) - ! shift M36 obs lat/lon for proper assignment of M09 tile? + if (L1C_files .and. & ! M36 obs and M09, M03, or M01 tile space + ( & + index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2-M09') /=0 .or. & ! allow outdated grid name only for M09 + index(obs2tile_grid_f%gridtype, 'EASEv2_M03') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2_M01') /=0 & + ) & + ) then - if ( L1C_files .and. (index(tile_grid_d%gridtype, 'EASEv2_M09') /=0 .or. index(tile_grid_d%gridtype, 'EASEv2-M09') /=0 )) then - ! temporarily shift lat/lon of obs for computation of nearest tile to ! avoid ambiguous assignment of M09 model tile within M36 obs grid cell ! (center of M36 grid cell is equidistant from at least two M09 model ! tiles) -- reichle, 23 Aug 2013 - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_obs_kept(kk), & tmp_lat(1:N_obs_kept(kk)), & tmp_lon(1:N_obs_kept(kk)), & @@ -9049,13 +9529,14 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & else - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_obs_kept(kk), & tmp_lat(1:N_obs_kept(kk)), & tmp_lon(1:N_obs_kept(kk)), & this_obs_param, & - tmp_tile_num) + tmp_tile_num ) end if @@ -9096,16 +9577,16 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & ! ! - reichle, 3 Feb 2016 ! ! if ( & - ! (index(tile_grid_d%gridtype, 'EASEv2_M09') /=0) .or. & - ! (index(tile_grid_d%gridtype, 'EASEv2_M36') /=0) ) then + ! (index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0) .or. & + ! (index(obs2tile_grid_f%gridtype, 'EASEv2_M36') /=0) ) then ! ! do ii=1,N_obs_kept(kk) ! ! if (tmp_tile_num(ii)>0) then ! ! call MAPL_ease_convert('EASEv2_M36', & - ! tile_coord(tmp_tile_num(ii))%com_lat, & - ! tile_coord(tmp_tile_num(ii))%com_lon, & + ! tile_coord_f(tmp_tile_num(ii))%com_lat, & + ! tile_coord_f(tmp_tile_num(ii))%com_lon, & ! M36_col_ind_tile, M36_row_ind_tile ) ! ! call MAPL_ease_convert('EASEv2_M36', & @@ -9131,7 +9612,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & do ii=1,N_obs_kept(kk) - ind_tile = tmp_tile_num(ii) ! 1<=tmp_tile_num<=N_catd (unless nodata) + ind_tile = tmp_tile_num(ii) ! 1<=tmp_tile_num<=N_catf (unless nodata) if (ind_tile>0) then ! this step eliminates obs outside domain @@ -9169,7 +9650,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & ! normalize - do ii=1,N_catd + do ii=1,N_catf if (N_obs_in_tile(ii)>1) then @@ -9195,7 +9676,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & ! set observation error standard deviation - do ii=1,N_catd + do ii=1,N_catf std_SMAP_data(ii) = this_obs_param%errstd end do @@ -9847,8 +10328,9 @@ end function SMAPdatetime_to_DateTimeType subroutine read_obs( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, write_obslog, & found_obs, scaled_obs, & tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time, tmp_assim ) @@ -9861,45 +10343,48 @@ subroutine read_obs( & ! in connection with get_obs_pred()) ! 22 Nov 2011 - minor clean-up, renamed scale_obs_*() subroutines ! 23 Aug 2013 - added possibility of using lat/lon of obs from reader - ! (rather than using lat/lon from model tile_coord) + ! (rather than using lat/lon from model tile_coord_f) ! 31 Jan 2014 - added output of time stamp ("tmp_time") ! 14 Jul 2014 - added summary diagnostic "scaled_obs" ! (indicates whether any of the founds obs were scaled) ! 6 Jun 2016 - added functionality to keep obs that cannot be scaled ! (but will not be assimilated; SMAP/SMOS Tb only for now) + ! 9 Nov 2026 - added input tile_grid_g_ESMF (ESMF grid associated with cube-sphere tile space) (amfox) implicit none ! inputs: - character(*), intent(in) :: work_path - character(*), intent(in) :: exp_id + character(*), intent(in) :: work_path + character(*), intent(in) :: exp_id - type(date_time_type), intent(in) :: date_time + type(date_time_type), intent(in) :: date_time - integer, intent(in) :: dtstep_assim, N_catd + integer, intent(in) :: dtstep_assim, N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(obs_param_type), intent(in) :: this_obs_param + type(obs_param_type), intent(in) :: this_obs_param - logical, intent(in) :: write_obslog + logical, intent(in) :: write_obslog ! outputs: - real, intent(out), dimension(N_catd) :: tmp_obs - real, intent(out), dimension(N_catd) :: tmp_std_obs - real, intent(out), dimension(N_catd) :: tmp_lon - real, intent(out), dimension(N_catd) :: tmp_lat - real*8, intent(out), dimension(N_catd) :: tmp_time - logical, intent(out), dimension(N_catd) :: tmp_assim + real, intent(out), dimension(N_catf) :: tmp_obs + real, intent(out), dimension(N_catf) :: tmp_std_obs + real, intent(out), dimension(N_catf) :: tmp_lon + real, intent(out), dimension(N_catf) :: tmp_lat + real*8, intent(out), dimension(N_catf) :: tmp_time + logical, intent(out), dimension(N_catf) :: tmp_assim logical, intent(out) :: found_obs, scaled_obs @@ -9919,8 +10404,8 @@ subroutine read_obs( & ! initialize lat/lon/time info (may later be overwritten by individual reader) - tmp_lon = tile_coord%com_lon - tmp_lat = tile_coord%com_lat + tmp_lon = tile_coord_f%com_lon + tmp_lat = tile_coord_f%com_lat ! obs time stamp in LDASsa *must* be in J2000 seconds with 'TT12' epoch ! (see enkf_types.F90) @@ -9938,8 +10423,9 @@ subroutine read_obs( & call read_obs_ae_l2_sm( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) @@ -9949,7 +10435,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + call scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) end if @@ -9959,8 +10445,9 @@ subroutine read_obs( & call read_obs_ae_sm_LPRM( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) @@ -9970,7 +10457,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + call scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) end if @@ -9980,8 +10467,9 @@ subroutine read_obs( & call read_obs_sm_ASCAT( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) @@ -9991,7 +10479,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + call scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) end if @@ -9999,11 +10487,12 @@ subroutine read_obs( & case ('ASCAT_META_SM','ASCAT_METB_SM','ASCAT_METC_SM' ) call read_obs_sm_ASCAT_EUMET( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, & - tmp_time) + tmp_time ) ! scale observations to model climatology @@ -10011,7 +10500,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_zscore( N_catd, tile_coord, & + call scale_obs_sfmc_zscore( N_catf, tile_coord_f, & date_time, this_obs_param, tmp_lon, tmp_lat, tmp_time, & tmp_obs, tmp_std_obs ) @@ -10020,11 +10509,12 @@ subroutine read_obs( & case ('ASCAT_HSAF_META_SM','ASCAT_HSAF_METB_SM','ASCAT_HSAF_METC_SM' ) call read_obs_sm_ASCAT_HSAF( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, write_obslog, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, & - tmp_time) + tmp_time ) ! scale observations to model climatology @@ -10032,7 +10522,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_zscore( N_catd, tile_coord, & + call scale_obs_sfmc_zscore( N_catf, tile_coord_f, & date_time, this_obs_param, tmp_lon, tmp_lat, tmp_time, & tmp_obs, tmp_std_obs ) @@ -10041,11 +10531,12 @@ subroutine read_obs( & case ('CYGNSS_SM_6hr','CYGNSS_SM_daily') call read_obs_sm_CYGNSS( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, write_obslog, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, & - tmp_time) + tmp_time ) ! scale observations to model climatology @@ -10053,7 +10544,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_zscore( N_catd, tile_coord, & + call scale_obs_sfmc_zscore( N_catf, tile_coord_f, & date_time, this_obs_param, tmp_lon, tmp_lat, tmp_time, & tmp_obs, tmp_std_obs ) @@ -10062,8 +10553,9 @@ subroutine read_obs( & case ('isccp_tskin_gswp2_v1') call read_obs_isccp_tskin_gswp2_v1( & - date_time, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) @@ -10071,7 +10563,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_tskin_zscore( N_catd, tile_coord, & + call scale_obs_tskin_zscore( N_catf, tile_coord_f, & date_time, this_obs_param, tmp_obs, tmp_std_obs ) end if @@ -10079,7 +10571,7 @@ subroutine read_obs( & case ('isccp_tskin_ceop3n4') call read_obs_isccp_tskin_ceop3n4( & - date_time, N_catd, tile_coord, & + date_time, N_catf, tile_coord_f, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) @@ -10087,7 +10579,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_tskin_zscore( N_catd, tile_coord, & + call scale_obs_tskin_zscore( N_catf, tile_coord_f, & date_time, this_obs_param, tmp_obs, tmp_std_obs ) end if @@ -10095,7 +10587,7 @@ subroutine read_obs( & case ('isccp_tskin_ceop3n4_hdASC') call read_obs_isccp_ts_ceop3n4_hdASC( & - date_time, N_catd, tile_coord, & + date_time, N_catf, tile_coord_f, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) @@ -10103,7 +10595,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_tskin_zscore( N_catd, tile_coord, & + call scale_obs_tskin_zscore( N_catf, tile_coord_f, & date_time, this_obs_param, tmp_obs, tmp_std_obs ) end if @@ -10111,7 +10603,7 @@ subroutine read_obs( & case ('RedArkOSSE_sm') call read_obs_RedArkOSSE_sm( & - date_time, N_catd, tile_coord, this_obs_param, & + date_time, N_catf, tile_coord_f, this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) ! scale observations to model climatology (use AMSR-E subroutine) @@ -10120,7 +10612,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + call scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) end if @@ -10128,7 +10620,7 @@ subroutine read_obs( & case ('RedArkOSSE_CLSMsynthSM') call read_obs_RedArkOSSE_CLSMsynthSM( & - date_time, N_catd, this_obs_param, & + date_time, N_catf, this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) ! scale observations to model climatology (use AMSR-E subroutine) @@ -10137,7 +10629,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + call scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) end if @@ -10145,7 +10637,7 @@ subroutine read_obs( & case ('RedArkOSSE_truth_50mm','RedArkOSSE_truth_400mm') call read_obs_RedArkOSSE_truth( & - date_time, N_catd, this_obs_param, & + date_time, N_catf, this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) ! scale observations to model climatology (use AMSR-E subroutine) @@ -10154,7 +10646,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + call scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) end if @@ -10170,7 +10662,7 @@ subroutine read_obs( & case ('VivianaOK_CLSMsynthSM') call read_obs_VivianaOK_CLSMsynthSM( & - date_time, N_catd, this_obs_param, & + date_time, N_catf, this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) ! scale observations to model climatology (use AMSR-E subroutine) @@ -10179,17 +10671,17 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + call scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) end if case('SMOS_SM_A','SMOS_SM_D') - call read_obs_SMOS( & - date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & - N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & + call read_obs_SMOS( & + date_time, N_catf, this_obs_param, & + dtstep_assim, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) ! scale observations to model climatology @@ -10198,7 +10690,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + call scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) end if @@ -10206,10 +10698,10 @@ subroutine read_obs( & case('SMOS_reg_Tbh_A','SMOS_reg_Tbh_D','SMOS_reg_Tbv_A','SMOS_reg_Tbv_D', & 'SMOS_fit_Tbh_A','SMOS_fit_Tbh_D','SMOS_fit_Tbv_A','SMOS_fit_Tbv_D') - call read_obs_SMOS( & - date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & - N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & + call read_obs_SMOS( & + date_time, N_catf, this_obs_param, & + dtstep_assim, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) ! scale observations to model climatology @@ -10218,16 +10710,17 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_Tb_zscore( N_catd, tile_coord, date_time, & + call scale_obs_Tb_zscore( N_catf, tile_coord_f, date_time, & this_obs_param, tmp_obs, tmp_std_obs, tmp_assim ) end if - case ('MOD10C1','MYD10C1') + case ('MOD10C1','MYD10C1','VNP10C1','VJ110C1','VJ210C1') - call read_obs_MODIS_SCF( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call read_obs_MODIS_VIIRS_SCF( & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, write_obslog, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) @@ -10241,8 +10734,8 @@ subroutine read_obs( & 'SMAP_L2AP_Tbh_D', 'SMAP_L2AP_Tbv_D' ) call read_obs_SMAP_halforbit_Tb( & - date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & + date_time, N_catf, this_obs_param, & + dtstep_assim, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time ) @@ -10252,7 +10745,7 @@ subroutine read_obs( & scaled_obs = .true. - call scale_obs_Tb_zscore( N_catd, tile_coord, date_time, & + call scale_obs_Tb_zscore( N_catf, tile_coord_f, date_time, & this_obs_param, tmp_obs, tmp_std_obs, tmp_assim ) end if @@ -10261,8 +10754,9 @@ subroutine read_obs( & 'LaRC_tskin-FY2E-', 'LaRC_tskin-MTST2') call read_obs_LaRC_Tskin( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + date_time, dtstep_assim, N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs ) @@ -10281,7 +10775,7 @@ end subroutine read_obs ! ***************************************************************** - subroutine scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & + subroutine scale_obs_sfmc_cdf( N_catf, tile_coord_f, this_obs_param, & tmp_obs, tmp_std_obs ) ! scale sfmc obs to model climatology via cdf matching @@ -10308,20 +10802,20 @@ subroutine scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & ! ! reichle, 22 Nov 2011 - renamed subroutine, minor clean-up, added comments ! reichle, 9 Nov 2012 - edited to enable use of stats file that do not - ! perfectly match current domain (as in tile_coord) + ! perfectly match current domain (as in tile_coord_f) implicit none - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(obs_param_type), intent(in) :: this_obs_param ! inout - real, intent(inout), dimension(N_catd) :: tmp_obs - real, intent(inout), dimension(N_catd) :: tmp_std_obs + real, intent(inout), dimension(N_catf) :: tmp_obs + real, intent(inout), dimension(N_catf) :: tmp_std_obs ! local variables @@ -10362,7 +10856,7 @@ subroutine scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & ! minimal consistency check - if (N_catd>N_sclprm) then + if (N_catf>N_sclprm) then err_msg = 'N_sclprm too small' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if @@ -10387,7 +10881,7 @@ subroutine scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & ! scale observations - do i=1,N_catd + do i=1,N_catf ! check for no-data-values in observation ! (any negative number could be no-data-value for observations) @@ -10396,7 +10890,7 @@ subroutine scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & ! find ind for current tile id in scaling parameters - if (tmp_tile_id(i)==tile_coord(i)%tile_id) then + if (tmp_tile_id(i)==tile_coord_f(i)%tile_id) then ind = i ! educated guess for global domain @@ -10404,7 +10898,7 @@ subroutine scale_obs_sfmc_cdf( N_catd, tile_coord, this_obs_param, & do ind=1,N_sclprm - if (tmp_tile_id(ind)==tile_coord(i)%tile_id) exit + if (tmp_tile_id(ind)==tile_coord_f(i)%tile_id) exit end do @@ -10507,8 +11001,8 @@ end subroutine scale_obs_sfmc_cdf ! ***************************************************************** - subroutine scale_obs_tskin_zscore( N_catd, tile_coord, & - date_time, this_obs_param, & + subroutine scale_obs_tskin_zscore( N_catf, tile_coord_f, & + date_time, this_obs_param, & tmp_obs, tmp_std_obs ) ! scale tskin obs to model climatology via standard-normal-deviate (zscore) @@ -10526,9 +11020,9 @@ subroutine scale_obs_tskin_zscore( N_catd, tile_coord, & implicit none - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(date_time_type), intent(in) :: date_time @@ -10536,8 +11030,8 @@ subroutine scale_obs_tskin_zscore( N_catd, tile_coord, & ! inout - real, intent(inout), dimension(N_catd) :: tmp_obs - real, intent(inout), dimension(N_catd) :: tmp_std_obs + real, intent(inout), dimension(N_catf) :: tmp_obs + real, intent(inout), dimension(N_catf) :: tmp_std_obs ! ---------------------------------------------------------- @@ -10608,7 +11102,7 @@ subroutine scale_obs_tskin_zscore( N_catd, tile_coord, & ! minimal consistency check - if (N_catd>N_sclprm) then + if (N_catf>N_sclprm) then call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'something is wrong') end if @@ -10618,7 +11112,7 @@ subroutine scale_obs_tskin_zscore( N_catd, tile_coord, & ! isccp_tskin_gswp2_v1 because of the way the subroutine is called ! from subroutine read_obs()) - do i=1,N_catd + do i=1,N_catf ! check for no-data-values in observation (any neg Tskin is no_data) @@ -10628,14 +11122,14 @@ subroutine scale_obs_tskin_zscore( N_catd, tile_coord, & do ind=1,N_sclprm - if (sclprm_tile_id(ind)==tile_coord(i)%tile_id) exit + if (sclprm_tile_id(ind)==tile_coord_f(i)%tile_id) exit end do ! sanity check (against accidental use of wrong tile space) - if ( abs(tile_coord(i)%com_lat-sclprm_lat(ind))>tol .or. & - abs(tile_coord(i)%com_lon-sclprm_lon(ind))>tol ) then + if ( abs(tile_coord_f(i)%com_lat-sclprm_lat(ind))>tol .or. & + abs(tile_coord_f(i)%com_lon-sclprm_lon(ind))>tol ) then err_msg = 'something wrong' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if @@ -10686,7 +11180,7 @@ end subroutine scale_obs_tskin_zscore ! ***************************************************************** - subroutine scale_obs_sfmc_zscore( N_catd, tile_coord, & + subroutine scale_obs_sfmc_zscore( N_catf, tile_coord_f, & date_time, this_obs_param, tmp_lon, tmp_lat, tmp_time, & tmp_obs, tmp_std_obs ) @@ -10731,21 +11225,21 @@ subroutine scale_obs_sfmc_zscore( N_catd, tile_coord, & use netcdf implicit none - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(date_time_type), intent(in) :: date_time type(obs_param_type), intent(in) :: this_obs_param - real, intent(in), dimension(N_catd) :: tmp_lon, tmp_lat - real*8, intent(in), dimension(N_catd) :: tmp_time ! J2000 seconds + real, intent(in), dimension(N_catf) :: tmp_lon, tmp_lat + real*8, intent(in), dimension(N_catf) :: tmp_time ! J2000 seconds ! inout - real, intent(inout), dimension(N_catd) :: tmp_obs - real, intent(inout), dimension(N_catd) :: tmp_std_obs + real, intent(inout), dimension(N_catf) :: tmp_obs + real, intent(inout), dimension(N_catf) :: tmp_std_obs ! ------------------- @@ -10861,7 +11355,7 @@ subroutine scale_obs_sfmc_zscore( N_catd, tile_coord, & ! Scale observations (at this point all obs are of same type because ! of the way the subroutine is called from subroutine read_obs() - do i=1,N_catd + do i=1,N_catf ! Check for no-data-values in observation (any neg value is no_data) @@ -10934,7 +11428,7 @@ end subroutine scale_obs_sfmc_zscore ! ******************************************************************************** - subroutine scale_obs_Tb_zscore( N_catd, tile_coord, date_time, this_obs_param, & + subroutine scale_obs_Tb_zscore( N_catf, tile_coord_f, date_time, this_obs_param, & tmp_obs, tmp_std_obs, tmp_assim ) ! Scale Tb obs to model climatology via standard-normal-deviate (zscore) @@ -10953,12 +11447,12 @@ subroutine scale_obs_Tb_zscore( N_catd, tile_coord, date_time, this_obs_param, ! global input scaling files for each pentad. ! ! Note that the tiles in the input scaling parameter files do NOT need - ! to be in the same order as in the domain tile_coord vector (although + ! to be in the same order as in the domain tile_coord_f vector (although ! the fastest execution is obtained when the scaling parameter files - ! and the domain tile_coord vector are for exactly the same tiles in + ! and the domain tile_coord_f vector are for exactly the same tiles in ! the same order. ! - ! The vector "tmp_obs" is of length N_catd. The observations in "tmp_obs" + ! The vector "tmp_obs" is of length N_catf. The observations in "tmp_obs" ! are mapped into tile space ONLY for book-keeping (each observation has ! been assigned to a model tile). The observations are not necessarily ! representative of the assigned tile and could be for a larger area. @@ -10975,9 +11469,9 @@ subroutine scale_obs_Tb_zscore( N_catd, tile_coord, date_time, this_obs_param, implicit none - integer, intent(in) :: N_catd + integer, intent(in) :: N_catf - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(date_time_type), intent(in) :: date_time @@ -10985,9 +11479,9 @@ subroutine scale_obs_Tb_zscore( N_catd, tile_coord, date_time, this_obs_param, ! inout - real, intent(inout), dimension(N_catd) :: tmp_obs - real, intent(inout), dimension(N_catd) :: tmp_std_obs - logical, intent(inout), dimension(N_catd) :: tmp_assim + real, intent(inout), dimension(N_catf) :: tmp_obs + real, intent(inout), dimension(N_catf) :: tmp_std_obs + logical, intent(inout), dimension(N_catf) :: tmp_assim ! ---------------------------------------------------------- @@ -11244,7 +11738,7 @@ subroutine scale_obs_Tb_zscore( N_catd, tile_coord, date_time, this_obs_param, ! scale observations (at this point all obs are of type Tb because ! of the way the subroutine is called from subroutine read_obs()) - do i=1,N_catd + do i=1,N_catf ! check for no-data-values in observation (any neg Tb is no_data) @@ -11254,11 +11748,11 @@ subroutine scale_obs_Tb_zscore( N_catd, tile_coord, date_time, this_obs_param, ind = -9999 ! initialize to negative integer - if (N_sclprm==N_catd) then + if (N_sclprm==N_catf) then ! try an educated guess (to avoid an additional loop) - if (sclprm_tile_id(i)==tile_coord(i)%tile_id) ind = i + if (sclprm_tile_id(i)==tile_coord_f(i)%tile_id) ind = i end if @@ -11266,7 +11760,7 @@ subroutine scale_obs_Tb_zscore( N_catd, tile_coord, date_time, this_obs_param, do ind=1,N_sclprm - if (sclprm_tile_id(ind)==tile_coord(i)%tile_id) exit + if (sclprm_tile_id(ind)==tile_coord_f(i)%tile_id) exit end do @@ -11292,8 +11786,8 @@ subroutine scale_obs_Tb_zscore( N_catd, tile_coord, date_time, this_obs_param, ! sanity check (against accidental use of wrong tile space) - if ( abs(tile_coord(i)%com_lat-sclprm_lat(ind))>tol .or. & - abs(tile_coord(i)%com_lon-sclprm_lon(ind))>tol ) then + if ( abs(tile_coord_f(i)%com_lat-sclprm_lat(ind))>tol .or. & + abs(tile_coord_f(i)%com_lon-sclprm_lon(ind))>tol ) then call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'something wrong') end if @@ -11354,7 +11848,8 @@ end subroutine scale_obs_Tb_zscore subroutine collect_obs( & work_path, exp_id, date_time, dtstep_assim, & N_catl, & - N_catf, tile_coord_f, tile_grid_f, N_tile_in_cell_ij_f, tile_num_in_cell_ij_f, & + N_catf, tile_coord_f, obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij_f, tile_num_in_cell_ij_f, & N_catl_vec, low_ind, l2f, & N_obs_param, obs_param, N_obsl_max, write_obslog, & N_obsl, Observations_l, found_obs_f ) @@ -11371,11 +11866,12 @@ subroutine collect_obs( ! 31 Dec 2014 - added time stamp to Observations ! 21 Mar 2014 - sort Observations_l by tilenum and then species to avoid lay-out ! dependency for MPI parallel execution + ! 9 Nov 2026 - added input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space) (amfox) implicit none - character(*), intent(in) :: work_path - character(*), intent(in) :: exp_id + character(*), intent(in) :: work_path + character(*), intent(in) :: exp_id type(date_time_type), intent(in) :: date_time @@ -11390,11 +11886,12 @@ subroutine collect_obs( type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid_f + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space ! N_tile_in_cell_ij and tile_num_in_cell_ij are on the "full" domain - ! and guaranteed to be allocated ONLY for the root_proc - ! (but may be allocated on all processors depending on obs_param%FOV) + ! and guaranteed to be allocated ONLY for the root_proc (see get_enkf_increments()) integer, dimension(:,:), pointer :: N_tile_in_cell_ij_f ! input integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij_f ! input @@ -11475,10 +11972,11 @@ subroutine collect_obs( call read_obs( & work_path, exp_id, & date_time, dtstep_assim, N_catf, tile_coord_f, & - tile_grid_f, N_tile_in_cell_ij_f, tile_num_in_cell_ij_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij_f, tile_num_in_cell_ij_f, & obs_param(species), write_obslog, & found_obs, scaled_obs, & - tmp_obs_f, tmp_std_obs_f, tmp_lon_f, tmp_lat_f, tmp_time_f, tmp_assim_f) + tmp_obs_f, tmp_std_obs_f, tmp_lon_f, tmp_lat_f, tmp_time_f, tmp_assim_f ) if (scaled_obs) any_scaled_obs = .true. @@ -11708,7 +12206,7 @@ end subroutine collect_obs ! ************************************************************** - subroutine put_into_Observations( this_obs_param, N_obs_max, N_catd, l2f, & + subroutine put_into_Observations( this_obs_param, N_obs_max, N_catf, l2f, & tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time, tmp_assim, & obs_count, Observations ) @@ -11730,15 +12228,15 @@ subroutine put_into_Observations( this_obs_param, N_obs_max, N_catd, l2f, & type(obs_param_type), intent(in) :: this_obs_param - integer, intent(in) :: N_obs_max, N_catd + integer, intent(in) :: N_obs_max, N_catf - integer, dimension(N_catd), intent(in) :: l2f + integer, dimension(N_catf), intent(in) :: l2f - real, dimension(N_catd), intent(in) :: tmp_obs, tmp_std_obs, tmp_lon, tmp_lat + real, dimension(N_catf), intent(in) :: tmp_obs, tmp_std_obs, tmp_lon, tmp_lat - real*8, dimension(N_catd), intent(in) :: tmp_time + real*8, dimension(N_catf), intent(in) :: tmp_time - logical, dimension(N_catd), intent(in) :: tmp_assim + logical, dimension(N_catf), intent(in) :: tmp_assim integer, intent(inout) :: obs_count @@ -11756,7 +12254,7 @@ subroutine put_into_Observations( this_obs_param, N_obs_max, N_catd, l2f, & tol = abs(nodatavalue*nodata_tolfrac_generic) - do i=1,N_catd + do i=1,N_catf if (abs(tmp_obs(i)-nodatavalue) > tol) then ! check for no-data-value @@ -11860,8 +12358,9 @@ end subroutine add_to_obslog ! ***************************************************************** - subroutine get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & + subroutine get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & this_obs_param, & tile_num, & shift_lat, shift_lon ) @@ -11872,16 +12371,21 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & ! (to be called from within obs readers) ! ! - reichle, 2015/02/20 + ! + ! added input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space), see get_tile_num_from_latlon() + ! - amfox, 9 Nov 2026 implicit none - integer, intent(in) :: N_catd, N_latlon + integer, intent(in) :: N_catf, N_latlon - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: obs2tile_grid_f + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - integer, dimension(tile_grid%N_lon,tile_grid%N_lat), intent(in) :: N_tile_in_cell_ij + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input @@ -11893,7 +12397,7 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & real, optional, intent(in) :: shift_lat real, optional, intent(in) :: shift_lon - + ! ------------------------ ! local variables @@ -11951,8 +12455,9 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & ! find tile numbers - call get_tile_num_from_latlon(N_catd, tile_coord, & - tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, & + call get_tile_num_from_latlon(N_catf, tile_coord_f, & + obs2tile_grid_f, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & N_latlon, tmp_lat, tmp_lon, & tile_num, max_dist_x, max_dist_y ) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index edeb2387..3a52b910 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -998,7 +998,8 @@ subroutine get_obs_pred( & N_obs_param, N_ens, & N_catl, tile_coord_l, & N_catf, tile_coord_f, f2l, & - N_catl_vec, low_ind, tile_grid_g, & + N_catl_vec, low_ind, & + tile_grid_g, tiles2obsFOV_grid_g, & obs_param, & met_force, lai, cat_param, cat_progn, mwRTM_param, & N_obsl, Observations_l, Obs_pred_l, obsbias_ok, & @@ -1025,6 +1026,7 @@ subroutine get_obs_pred( & ! 18 Jun 2012 - reichle: rewritten for better memory management w/ MPI ! 26 Mar 2014 - reichle: apply all model-based QC only before EnKF update ! 25 Sep 2020 - wjiang+reichle: accommodate processors that have no tiles + ! 6 Nov 2026 - amfox: added QC of Tb for non-land surfaces in cube-sphere tile space implicit none @@ -1038,8 +1040,9 @@ subroutine get_obs_pred( & integer, intent(in), dimension(numprocs) :: N_catl_vec, low_ind - type(grid_def_type), intent(in) :: tile_grid_g - + type(grid_def_type), intent(in) :: tile_grid_g + type(grid_def_type), intent(in) :: tiles2obsFOV_grid_g ! hash grid to map from tile space to obs FOV + type(obs_param_type), intent(in), dimension(N_obs_param) :: obs_param integer, intent(in), dimension(N_catf) :: f2l @@ -1058,7 +1061,7 @@ subroutine get_obs_pred( & logical, intent(in), dimension(N_obsl), optional :: obsbias_ok real, intent(in), optional :: fcsterr_inflation_fac - + ! -------------------------------------------------------------------------------- ! ! locals @@ -1067,7 +1070,7 @@ subroutine get_obs_pred( & real, parameter :: fac_search_FOV_km = 2. ! [-] - real, parameter :: EASE_max_water_frac = 0.05 ! [-] + real, parameter :: Tb_max_nonland_frac = 0.05 ! [-] real, parameter :: SM_max_peat_frac = 0.10 ! [-] integer :: N_catlH, n_e, i, j, k, N_tmp, ii, jj @@ -1083,11 +1086,13 @@ subroutine get_obs_pred( & real, dimension(numprocs) :: xhalo, yhalo, tmplatvec, tmprx - real :: tmpreal, tmp_stemp, tmp_fraccell, tmp_peatfrac + real :: tmpreal, tmp_stemp, tmp_land_frac, tmp_peat_frac real :: tmpsum_w logical :: tmpRFI, tmpWater, tmpPeat, use_distance_weights + integer :: ind_i_min, ind_i_max, ind_j_min, ind_j_max + real, dimension(1) :: tmpmean, tmpvar logical :: get_sfmc_l, get_sfmc_lH @@ -1098,7 +1103,10 @@ subroutine get_obs_pred( & logical :: get_FT_l, get_FT_lH logical :: get_asnow_l, get_asnow_lH logical :: get_peat_lH - type(grid_def_type) :: tile_grid_lH + + logical :: c3_tile_space + + type(grid_def_type) :: tiles2obsFOV_grid_lH integer, dimension(N_obs_param) :: ind_obsparam2Tbspecies integer, dimension(N_obs_param) :: ind_Tbspecies2TbuniqFreqAngRTMid @@ -1150,6 +1158,9 @@ subroutine get_obs_pred( & real, dimension(:,:,:), allocatable :: Tb_h_lH, Tb_v_lH real, dimension(:), allocatable :: peat_lH + + real, dimension(:), allocatable :: land_frac_cell_lH ! cube-sphere tile space only + real, dimension(:,:), allocatable :: land_frac_cell_ij ! cube-sphere tile space only real, dimension(:,:,:), pointer :: tile_data_lH => null() @@ -1570,12 +1581,60 @@ subroutine get_obs_pred( & end if N_fields = 0 ! set to zero temporarily, not yet needed + ! move up the allocation. The input should be allocated in debug mode although it is not used ! allocate and assemble tile_data_l + allocate(tile_data_l(0,0,0)) ! for debugging to pass + call get_tiles_in_halo( N_catl, N_fields, N_ens, tile_data_l, tile_coord_l, & tile_coord_f, N_catl_vec, low_ind, xhalo, yhalo, & N_catlH, tile_coord_lH=tile_coord_lH ) + + ! for cube-sphere tile space, get the land fraction of the (cube-sphere) grid cell + ! of each tile in the local halo domain ("lH") for the QC of Tb for non-land surfaces + ! (below); a grid cell contains several tiles, whose frac_cell add up to the land + ! fraction of the grid cell; + ! this is only needed before the EnKF update; + ! near the edge of the domain, land_frac might be underestimated if non-land tiles + ! in a given grid cell are within the (full) domain, leading to more aggressive + ! screening of Tb obs; this is acceptable because typically the domain is global + + c3_tile_space = (index(tile_grid_g%gridtype,'c3')/=0) + + if (beforeEnKFupdate .and. c3_tile_space .and. get_Tb_lH) then + + ind_i_min = minval(tile_coord_f%i_indg) + ind_i_max = maxval(tile_coord_f%i_indg) + ind_j_min = minval(tile_coord_f%j_indg) + ind_j_max = maxval(tile_coord_f%j_indg) + + ! get land_frac for each cube-sphere grid cell, with cube-sphere grid + ! here being stored on the 2d array consistent with the [i,j]_indg + ! indices of tilecoord + + allocate(land_frac_cell_ij(ind_i_min:ind_i_max,ind_j_min:ind_j_max)) + + land_frac_cell_ij = 0. + + do k=1,N_catf + if (tile_coord_f(k)%typ==MAPL_LAND) & + land_frac_cell_ij(tile_coord_f(k)%i_indg,tile_coord_f(k)%j_indg) = & + land_frac_cell_ij(tile_coord_f(k)%i_indg,tile_coord_f(k)%j_indg) + & + tile_coord_f(k)%frac_cell + end do + + ! for each tile in halo domain, record land_frac of parent cube-sphere grid cell + + allocate(land_frac_cell_lH(N_catlH)) + + do k=1,N_catlH + land_frac_cell_lH(k) = land_frac_cell_ij(tile_coord_lH(k)%i_indg,tile_coord_lH(k)%j_indg) + end do + + deallocate(land_frac_cell_ij) + + end if if (get_sfmc_lH) allocate(sfmc_lH( N_catlH, N_ens)) if (get_rzmc_lH) allocate(rzmc_lH( N_catlH, N_ens)) @@ -1639,34 +1698,37 @@ subroutine get_obs_pred( & #endif if (allocated(tile_data_l)) deallocate(tile_data_l) + ! ---------------------------------------------------------------- ! - ! Get additional grid/tile information that is needed to map from tile - ! to obs space + ! Get additional grid/tile information that is needed to map from tile to obs space. + ! + ! See also subroutine Initialize() of GEOS_LdasGridComp.F90. - if ( any(obs_param(1:N_obs_param)%FOV>FOV_threshold) ) then + if ( any(obs_param(1:N_obs_param)%FOV>=FOV_threshold) ) then - ! determine tile_grid_lH from tile_coord_lH + ! determine tiles2obsFOV_grid_lH from tile_coord_lH and tiles2obsFOV_grid_g (i.e., pert_grid_g) - tile_grid_lH = get_minExtent_grid( N_catlH, tile_coord_lH%pert_i_indg, tile_coord_lH%pert_j_indg,& - tile_coord_lH%min_lon, tile_coord_lH%min_lat, tile_coord_lH%max_lon, tile_coord_lH%max_lat, & - tile_grid_g) + tiles2obsFOV_grid_lH = get_minExtent_grid( & + N_catlH, tile_coord_lH%pert_i_indg, tile_coord_lH%pert_j_indg, & ! NOTE: %pert_i_indg, %pert_j_indg + tile_coord_lH%min_lon, tile_coord_lH%min_lat, tile_coord_lH%max_lon, tile_coord_lH%max_lat, & + tiles2obsFOV_grid_g) - allocate(N_tile_in_cell_ij_lH(tile_grid_lH%N_lon,tile_grid_lH%N_lat)) + allocate(N_tile_in_cell_ij_lH(tiles2obsFOV_grid_lH%N_lon,tiles2obsFOV_grid_lH%N_lat)) - ! first call: count how many tiles are in each tile_grid_lH cell + ! first call: count how many tiles are in each tiles2obsFOV_grid_lH cell - call get_number_of_tiles_in_cell_ij( N_catlH, & - tile_coord_lH%pert_i_indg, tile_coord_lH%pert_j_indg, & - tile_grid_lH, N_tile_in_cell_ij_lH ) + call get_number_of_tiles_in_cell_ij( N_catlH, & + tile_coord_lH%pert_i_indg, tile_coord_lH%pert_j_indg, & + tiles2obsFOV_grid_lH, N_tile_in_cell_ij_lH ) - ! second call: find out which tiles are in each tile_grid_lH cell + ! second call: find out which tiles are in each tiles2obsFOV_grid_lH cell ! [tile numbers in "tile_num_in_cell_ij_lH" are relative ! to local halo ("lH") domain] - call get_tile_num_in_cell_ij( N_catlH, & - tile_coord_lH%pert_i_indg, tile_coord_lH%pert_j_indg, & - tile_grid_lH, maxval(N_tile_in_cell_ij_lH), tile_num_in_cell_ij_lH ) + call get_tile_num_in_cell_ij( N_catlH, & + tile_coord_lH%pert_i_indg, tile_coord_lH%pert_j_indg, & + tiles2obsFOV_grid_lH, maxval(N_tile_in_cell_ij_lH), tile_num_in_cell_ij_lH ) end if @@ -1748,7 +1810,7 @@ subroutine get_obs_pred( & end if call get_tile_num_in_ellipse( this_lon, this_lat(1), r_x(1), r_y, & - N_catlH, tile_coord_lH, tile_grid_lH, & + N_catlH, tile_coord_lH, tiles2obsFOV_grid_lH, & N_tile_in_cell_ij_lH, tile_num_in_cell_ij_lH, & N_tmp, ind_tmp, tmp_ndst2 ) @@ -1791,38 +1853,113 @@ subroutine get_obs_pred( & end if - ! screen surface soil moisture observations if too much of the FOV is peatland + ! --------------------------------------------------- + ! + ! model-based QC that depends on static information (e.g., peat or non-land area fraction); + ! requires model info *and* observation info together; + ! only performed before the EnKF update b/c not needed afterwards. - tmpPeat = .false. + tmpPeat = .false. + + tmpWater = .false. + + if (beforeEnKFupdate) then + + ! screen surface soil moisture observations if too much of the FOV is peatland + + if (get_peat_lH .and. & + (trim(obs_param(this_species)%varname)=='sfmc' .or. & + trim(obs_param(this_species)%varname)=='sfds')) then + + tmp_data(1:N_tmp) = peat_lH(ind_tmp(1:N_tmp)) + + ! FOV- and area-weighted peat fraction over tiles with valid porosity - if (get_peat_lH .and. & - (trim(obs_param(this_species)%varname)=='sfmc' .or. & - trim(obs_param(this_species)%varname)=='sfds')) then + tmpsum_w = sum( merge( tmp_weights(1:N_tmp), 0., & + abs(tmp_data(1:N_tmp)-nodata_generic)>=nodata_tol_generic ) ) - tmp_data(1:N_tmp) = peat_lH(ind_tmp(1:N_tmp)) + if (tmpsum_w > 0.) then + + tmp_peat_frac = sum( merge( & + tmp_weights(1:N_tmp)*tmp_data(1:N_tmp), 0., & + abs(tmp_data(1:N_tmp)-nodata_generic)>=nodata_tol_generic ) ) & + / tmpsum_w + + tmpPeat = (tmp_peat_frac >= SM_max_peat_frac) + + else + + tmpPeat = .true. ! no valid porosity anywhere in FOV - ! FOV- and area-weighted peat fraction over tiles with valid porosity + end if + + end if - tmpsum_w = sum( merge( tmp_weights(1:N_tmp), 0., & - abs(tmp_data(1:N_tmp)-nodata_generic)>=nodata_tol_generic ) ) + ! --------------------- - if (tmpsum_w > 0.) then + ! screen Tb obs for non-land surfaces (lake, landice) in FOV; + ! *ONLY* implemented for EASE and cube-sphere grids + ! - reichle, 28 Mar 2015 (EASE) + ! - amfox, 6 Nov 2026 (cube-sphere) + + if (get_Tb_lH .and. trim(obs_param(this_species)%varname)=='Tb') then - tmp_peatfrac = sum( merge( & - tmp_weights(1:N_tmp)*tmp_data(1:N_tmp), 0., & - abs(tmp_data(1:N_tmp)-nodata_generic)>=nodata_tol_generic ) )& - / tmpsum_w + ! ASSUMPTION: + ! - all grid cells in FOV contain at least some land; grid cells + ! that are entirely non-land are not considered because the + ! calculations use only land tile properties + + if (index(tiles2obsFOV_grid_g%gridtype, 'EASEv') /=0) then - tmpPeat = (tmp_peatfrac>=SM_max_peat_frac) + ! ADDITIONAL ASSUMPTIONS: + ! - at most one land tile per grid cell + ! - grid cells have the same area (true for EASE) or at least have nearly + ! identical areas in the surrounding region; that is, + ! a regular lat/lon grid with just one tile per grid + ! cell would be ok if that property could be asserted here + + ! compute FOV-weighted average "frac_cell" - else + tmp_data(1:N_tmp) = tile_coord_lH(ind_tmp(1:N_tmp))%frac_cell - tmpPeat = .true. ! no valid porosity anywhere in FOV + call tile2obs_helper( & + N_tmp, tmp_wFOV(1:N_tmp), tmp_data(1:N_tmp), tmp_land_frac) - end if + elseif (c3_tile_space) then - end if - + ! a cube-sphere grid cell can contain several tiles; + ! average the land fraction of the grid cells with at least one land tile in the FOV, + ! which misses grid cells that have no land at all (as for EASE); + ! average is weighted by the following land tile properties: + ! 1) relative contribution to FOV (tmp_wFOV) + ! 2) relative share of the land area in grid cell (frac_cell/land_frac) + ! 3) grid cell area + ! total weight = tmp_wFOV * frac_cell/land_frac_cell * grid-cell-area + ! = tmp_wFOV * frac_cell/land_frac_cell * tile-area/frac_cell + ! = tmp_wFOV * 1/land_frac_cell * tile-area + + tmp_data(1:N_tmp) = land_frac_cell_lH(ind_tmp(1:N_tmp)) + + call tile2obs_helper( & + N_tmp, tmp_wFOV(1:N_tmp)*tile_coord_lH(ind_tmp(1:N_tmp))%area/max(tmp_data(1:N_tmp),1.e-10), & + tmp_data(1:N_tmp), tmp_land_frac) + + else + + err_msg = 'Tb QC for non-land frac not implemented for this grid type' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! check whether there is too much non-land in FOV + ! (typically water, but could be land-ice) + + tmpWater = ( 1. - tmp_land_frac > Tb_max_nonland_frac ) + + end if ! if get_Tb_lH + + end if ! if beforeEnKFupdate + do n_e=1,N_ens ! ----------------------------------------- @@ -1856,11 +1993,15 @@ subroutine get_obs_pred( & case('Tb') - ! start with QC based on model *soil* temperature, motivated by RFI - ! (requires model estimates *and* observation together; - ! only performed before the EnKF update b/c not needed afterwards) + ! model-based QC that depends on ensemble member-specific dynamic states (e.g., soil temperature); + ! requires model estimates *and* observation together; + ! only performed before the EnKF update b/c not needed afterwards + tmpRFI = .false. + if (beforeEnKFupdate) then + + ! QC based on model *soil* temperature, motivated by RFI tmp_data(1:N_tmp) = stemp_lH( ind_tmp(1:N_tmp), n_e ) @@ -1871,42 +2012,7 @@ subroutine get_obs_pred( & tmpRFI = ((Observations_l(i)%obs-tmp_stemp) > Tbobs_minus_stemp_max) - else - - tmpRFI = .false. - - end if - - ! for EASE grids *ONLY*: screen for non-land surfaces (e.g., lakes) - ! - reichle, 28 Mar 2015 - - if (index(tile_grid_g%gridtype, 'EASEv') /=0) then - - ! ASSUMPTIONS: - ! - at most one land tile per grid cell - ! - grid cells have the same area (or at least have nearly - ! identical areas in the surrounding region; that is, - ! a regular lat/lon grid with just one tile per grid - ! cell would be ok if that property could be asserted here) - - ! compute FOV-weighted average "frac_cell" - - tmp_data(1:N_tmp) = tile_coord_lH(ind_tmp(1:N_tmp))%frac_cell - - call tile2obs_helper( & - N_tmp, tmp_wFOV(1:N_tmp), tmp_data(1:N_tmp), tmp_fraccell) - - ! check whether there is too much non-land in FOV - ! (typically water, but could be land-ice) - - tmpWater = ( 1. - tmp_fraccell > EASE_max_water_frac ) - - else - - tmpWater = .false. - - end if - + end if ! beforeEnKFupdate ! compute Obs_pred @@ -2024,6 +2130,7 @@ subroutine get_obs_pred( & if (allocated(tmp_wFOV)) deallocate(tmp_wFOV) ! fix memory leak if (allocated(tmp_weights)) deallocate(tmp_weights) if (allocated(tmp_data)) deallocate(tmp_data) + if (allocated(land_frac_cell_lH)) deallocate(land_frac_cell_lH) if (allocated(peat_lH)) deallocate(peat_lH) @@ -3729,9 +3836,6 @@ subroutine cat_enkf_increments( & integer, dimension(N_obs_param) :: select_species_smTb, select_species_Tb, select_species_asnow ! alloc max possible length integer, dimension(:), allocatable :: select_tilenum - - integer, dimension(:,:), pointer :: N_tile_in_cell_ij => null() - integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij => null() character(len=*), parameter :: Iam = 'cat_enkf_increments' character(len=400) :: err_msg @@ -5558,9 +5662,6 @@ subroutine cat_enkf_increments( & if (allocated( select_tilenum )) deallocate( select_tilenum ) if (allocated( Obs_cov )) deallocate( Obs_cov ) - - if (associated(N_tile_in_cell_ij )) deallocate( N_tile_in_cell_ij ) - if (associated(tile_num_in_cell_ij)) deallocate( tile_num_in_cell_ij ) ! NO checks of prognostics after update, this is now done after ! increments have been applied. diff --git a/GEOSlandassim_GridComp/io_hdf5.F90 b/GEOSlandassim_GridComp/io_hdf5.F90 index eba2c8c5..247dde24 100644 --- a/GEOSlandassim_GridComp/io_hdf5.F90 +++ b/GEOSlandassim_GridComp/io_hdf5.F90 @@ -50,13 +50,16 @@ module io_hdf5 procedure, public :: openFile procedure, public :: closeFile procedure, public :: queryDataset - generic, public :: readDataset => readDataset1DReal, readDataset1DReal8, readDataset1DInt, readDataset1DChar24, readDataset2DReal + generic, public :: readDataset => readDataset1DReal, readDataset1DReal8, readDataset1DInt, readDataset1DChar24, readDataset2DReal, readDataset2DInt + generic, public :: readAttribute => readAttributeChar ! private procedure, private :: readDataset1DReal procedure, private :: readDataset1DReal8 procedure, private :: readDataset1DInt procedure, private :: readDataset1DChar24 procedure, private :: readDataset2DReal + procedure, private :: readDataset2DInt + procedure, private :: readAttributeChar procedure, private :: uninitDataset end type hdf5read @@ -324,6 +327,97 @@ subroutine readDataset2DReal(this, data2D) end subroutine readDataset2DReal + ! read block of 2D integer dataset that starts at (0-based) offset; + ! block size is given by shape of data2D + subroutine readDataset2DInt(this, data2D, offset) + + ! input/output variables + class (hdf5read), intent(inout) :: this + integer, intent(out) :: data2D(:,:) + integer, intent(in) :: offset(2) + + ! local variables + integer :: hdf5err + integer(hsize_t) :: block_size(2) + integer(hid_t) :: memspace_id + + ! check dataset state + if (this%dset_name == UNINIT_STR) then + write(*,*) 'ERROR readDataset2DInt: No open dataset available' + stop + end if + + block_size = shape(data2D) + + ! select block in file and create matching data space in memory + call h5sselect_hyperslab_f(this%dspace_id, H5S_SELECT_SET_F, int(offset,hsize_t), block_size, hdf5err) + call checkErrCode_('h5sselect_hyperslab_f', hdf5err) + + call h5screate_simple_f(2, block_size, memspace_id, hdf5err) + call checkErrCode_('h5screate_simple_f', hdf5err) + + call h5dread_f(this%dset_id, H5T_NATIVE_INTEGER, data2D, block_size, hdf5err, memspace_id, this%dspace_id) + call checkErrCode_('h5dread_f', hdf5err) + + call h5sclose_f(memspace_id, hdf5err) + call checkErrCode_('h5sclose_f', hdf5err) + + ! un-initialize dataset just queried/read + call this%uninitDataset + + end subroutine readDataset2DInt + + ! read (fixed-length) string attribute of root group of file (e.g., global + ! attribute "LocalGranuleID"); returns blank if attribute does not exist or + ! cannot be read + ! + ! meant for log output: never stops on an HDF5 error (unlike checkErrCode_()) + subroutine readAttributeChar(this, attrName, attrValue) + + ! input/output variables + class (hdf5read), intent(inout) :: this + character(len=*), intent(in) :: attrName + character(len=*), intent(out) :: attrValue + + ! local variables + integer :: hdf5err, tmperr + logical :: attr_exists + integer(hid_t) :: attr_id, memtype_id + integer(hsize_t) :: dims(1) + + ! check file state + if (this%file_id == INVALID_HID) then + write(*,*) 'ERROR readAttributeChar: No open file available' + stop + end if + + attrValue = '' + + call h5aexists_f(this%file_id, attrName, attr_exists, hdf5err) + + if (hdf5err < 0 .or. (.not. attr_exists)) return + + call h5aopen_f(this%file_id, attrName, attr_id, hdf5err) + + if (hdf5err < 0) return + + ! read into a fixed-length string of length len(attrValue) + call h5tcopy_f(H5T_FORTRAN_S1, memtype_id, hdf5err) + + if (hdf5err >= 0) then + call h5tset_size_f(memtype_id, int(len(attrValue),size_t), hdf5err) + if (hdf5err >= 0) then + dims = 1_hsize_t + call h5aread_f(attr_id, memtype_id, attrValue, dims, hdf5err) + end if + if (hdf5err < 0) attrValue = '' + call h5tclose_f(memtype_id, tmperr) + end if + + call h5aclose_f(attr_id, tmperr) + + end subroutine readAttributeChar + ! check return code ! (not part of class hdf5read) subroutine checkErrCode_(routineName, hdf5errCode) diff --git a/GEOSlandpert_GridComp/GEOS_LandPertGridComp.F90 b/GEOSlandpert_GridComp/GEOS_LandPertGridComp.F90 index fd88c6f4..8339d785 100644 --- a/GEOSlandpert_GridComp/GEOS_LandPertGridComp.F90 +++ b/GEOSlandpert_GridComp/GEOS_LandPertGridComp.F90 @@ -1042,8 +1042,11 @@ subroutine Initialize(gc, import, export, clock, rc) VERIFY_(status) allocate(internal%j_indgs(land_nt_local),stat=status) VERIFY_(status) - internal%i_indgs(:)=tile_coord(:)%pert_i_indg - internal%j_indgs(:)=tile_coord(:)%pert_j_indg + ! tile_coord holds all tiles of the forcing locstream (land, plus lake and landice if requested), + ! whereas land_nt_local is the number of land tiles in LAND's locstream + _ASSERT(count(tile_coord(:)%typ==MAPL_LAND)==land_nt_local, "LandPert: number of land tiles in tile_coord does not match land locstream") + internal%i_indgs(:)=pack(tile_coord(:)%pert_i_indg, tile_coord(:)%typ==MAPL_LAND) + internal%j_indgs(:)=pack(tile_coord(:)%pert_j_indg, tile_coord(:)%typ==MAPL_LAND) ! Get pert options from *default* namelist files ! WARNING: get_force/progn_pert_param() calls allocate memory diff --git a/GEOSlandpert_GridComp/rectangle_random_fields.F90 b/GEOSlandpert_GridComp/rectangle_random_fields.F90 index 590cec66..6bc71909 100644 --- a/GEOSlandpert_GridComp/rectangle_random_fields.F90 +++ b/GEOSlandpert_GridComp/rectangle_random_fields.F90 @@ -177,6 +177,9 @@ function new_rectangle_random_fields(pert_param, pert_grid_f, comm, rc) result ( rf%xStride, rf%yStride, rf%rdlon, rf%rdlat) rf%ID_string = rectangle_random_fields_id(pert_param, pert_grid_f) + ! FFT lengths for nr_fft (fourn); x varies fastest in tmpdata + rf%fft_lens = [rf%N_x_fft, rf%N_y_fft] + ! allocate memory allocate(rf%field1_fft(rf%N_x_fft, rf%N_y_fft)) allocate(rf%field2_fft(rf%N_x_fft, rf%N_y_fft)) diff --git a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml index 7581c3a0..b9fab525 100644 --- a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml +++ b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml @@ -2699,7 +2699,135 @@ obs_param_nml(58)%ycorr = 0.2 obs_param_nml(58)%adapt = 0 ! -------------------------------------------------------------------- +! +! 59 = VIIRS/JPSS1 snow cover area fraction (SCF) +! +! VJ110C1.*.002.*h5: VIIRS/JPSS1 Snow Cover Daily L3 Global 0.05deg CMG, daytime (13:30 local) ascending overpass, version 2 +! +! for rule-based snow cover analysis (no obs error/pert specs) + +obs_param_nml(59)%descr = 'VJ110C1' +obs_param_nml(59)%orbit = 1 +obs_param_nml(59)%pol = 0 +obs_param_nml(59)%N_ang = 0 +obs_param_nml(59)%freq = 0. +obs_param_nml(59)%FOV = 0. +obs_param_nml(59)%FOV_units = 'deg' +obs_param_nml(59)%assim = .false. +obs_param_nml(59)%scale = .false. +obs_param_nml(59)%getinnov = .false. +obs_param_nml(59)%RTM_ID = 0 +obs_param_nml(59)%bias_Npar = 0 +obs_param_nml(59)%bias_trel = 864000 +obs_param_nml(59)%bias_tcut = 432000 +obs_param_nml(59)%nodata = -9999. +obs_param_nml(59)%varname = 'asnow' +obs_param_nml(59)%units = 'm2 m-2' +obs_param_nml(59)%fcstvarname = 'NULL' ! do not edit! +obs_param_nml(59)%fcstunits = 'NULL' ! do not edit! +obs_param_nml(59)%path = '/discover/nobackup/projects/gmao/polarm/JPSS/VJ110C1/' +obs_param_nml(59)%name = 'VJ110C1.Ayyyyddd.002.h5' +obs_param_nml(59)%maskpath = '' +obs_param_nml(59)%maskname = '' +obs_param_nml(59)%scalepath = '' +obs_param_nml(59)%scalename = '' +obs_param_nml(59)%flistpath = '' +obs_param_nml(59)%flistname = '' +obs_param_nml(59)%errstd = -9999. +obs_param_nml(59)%std_normal_max = -9999. +obs_param_nml(59)%zeromean = .false. +obs_param_nml(59)%coarsen_pert = .false. +obs_param_nml(59)%xcorr = 0. +obs_param_nml(59)%ycorr = 0. +obs_param_nml(59)%adapt = 0 + +! -------------------------------------------------------------------- +! +! 60 = VIIRS/JPSS2 snow cover area fraction (SCF) +! +! VJ210C1.*.002.*h5: VIIRS/JPSS2 Snow Cover Daily L3 Global 0.05deg CMG, daytime (13:30 local) ascending overpass, version 2 +! +! for rule-based snow cover analysis (no obs error/pert specs) + +obs_param_nml(60)%descr = 'VJ210C1' +obs_param_nml(60)%orbit = 1 +obs_param_nml(60)%pol = 0 +obs_param_nml(60)%N_ang = 0 +obs_param_nml(60)%freq = 0. +obs_param_nml(60)%FOV = 0. +obs_param_nml(60)%FOV_units = 'deg' +obs_param_nml(60)%assim = .false. +obs_param_nml(60)%scale = .false. +obs_param_nml(60)%getinnov = .false. +obs_param_nml(60)%RTM_ID = 0 +obs_param_nml(60)%bias_Npar = 0 +obs_param_nml(60)%bias_trel = 864000 +obs_param_nml(60)%bias_tcut = 432000 +obs_param_nml(60)%nodata = -9999. +obs_param_nml(60)%varname = 'asnow' +obs_param_nml(60)%units = 'm2 m-2' +obs_param_nml(60)%fcstvarname = 'NULL' ! do not edit! +obs_param_nml(60)%fcstunits = 'NULL' ! do not edit! +obs_param_nml(60)%path = '/discover/nobackup/projects/gmao/polarm/JPSS/VJ210C1/' +obs_param_nml(60)%name = 'VJ210C1.Ayyyyddd.002.h5' +obs_param_nml(60)%maskpath = '' +obs_param_nml(60)%maskname = '' +obs_param_nml(60)%scalepath = '' +obs_param_nml(60)%scalename = '' +obs_param_nml(60)%flistpath = '' +obs_param_nml(60)%flistname = '' +obs_param_nml(60)%errstd = -9999. +obs_param_nml(60)%std_normal_max = -9999. +obs_param_nml(60)%zeromean = .false. +obs_param_nml(60)%coarsen_pert = .false. +obs_param_nml(60)%xcorr = 0. +obs_param_nml(60)%ycorr = 0. +obs_param_nml(60)%adapt = 0 + +! -------------------------------------------------------------------- +! +! 61 = VIIRS/S-NPP snow cover area fraction (SCF) +! +! VNP10C1.*.002.*h5: VIIRS/S-NPP Snow Cover Daily L3 Global 0.05deg CMG, daytime (13:30 local) ascending overpass, version 2 +! +! for rule-based snow cover analysis (no obs error/pert specs) +obs_param_nml(61)%descr = 'VNP10C1' +obs_param_nml(61)%orbit = 1 +obs_param_nml(61)%pol = 0 +obs_param_nml(61)%N_ang = 0 +obs_param_nml(61)%freq = 0. +obs_param_nml(61)%FOV = 0. +obs_param_nml(61)%FOV_units = 'deg' +obs_param_nml(61)%assim = .false. +obs_param_nml(61)%scale = .false. +obs_param_nml(61)%getinnov = .false. +obs_param_nml(61)%RTM_ID = 0 +obs_param_nml(61)%bias_Npar = 0 +obs_param_nml(61)%bias_trel = 864000 +obs_param_nml(61)%bias_tcut = 432000 +obs_param_nml(61)%nodata = -9999. +obs_param_nml(61)%varname = 'asnow' +obs_param_nml(61)%units = 'm2 m-2' +obs_param_nml(61)%fcstvarname = 'NULL' ! do not edit! +obs_param_nml(61)%fcstunits = 'NULL' ! do not edit! +obs_param_nml(61)%path = '/discover/nobackup/projects/gmao/polarm/JPSS/VNP10C1/' +obs_param_nml(61)%name = 'VNP10C1.Ayyyyddd.002.h5' +obs_param_nml(61)%maskpath = '' +obs_param_nml(61)%maskname = '' +obs_param_nml(61)%scalepath = '' +obs_param_nml(61)%scalename = '' +obs_param_nml(61)%flistpath = '' +obs_param_nml(61)%flistname = '' +obs_param_nml(61)%errstd = -9999. +obs_param_nml(61)%std_normal_max = -9999. +obs_param_nml(61)%zeromean = .false. +obs_param_nml(61)%coarsen_pert = .false. +obs_param_nml(61)%xcorr = 0. +obs_param_nml(61)%ycorr = 0. +obs_param_nml(61)%adapt = 0 + +! -------------------------------------------------------------------- / diff --git a/GEOSldas_App/preprocess_ldas_routines.F90 b/GEOSldas_App/preprocess_ldas_routines.F90 index ae46007e..5f3508dc 100644 --- a/GEOSldas_App/preprocess_ldas_routines.F90 +++ b/GEOSldas_App/preprocess_ldas_routines.F90 @@ -352,7 +352,7 @@ end function is_cat_in_box ! ******************************************************************** subroutine domain_setup( & - tile_coord_r, & + tile_coord_r, & tile_grid_g, & exclude_path, exclude_file, include_path, include_file, & work_path, exp_domain, exp_id, & @@ -434,8 +434,8 @@ subroutine domain_setup( & integer :: this_i_indg, this_j_indg type(grid_def_type) :: tmp_grid_def - logical :: c3_grid - character(512) :: fname + logical :: c3_tile_space + character(512) :: fname character(len=*), parameter :: Iam = 'domain_setup' character(len=400) :: err_msg @@ -487,8 +487,7 @@ subroutine domain_setup( & ! ! find and count tiles that are in the domain - c3_grid = .false. - if(index(tile_grid_g%gridtype,"c3")/=0) c3_grid = .true. + c3_tile_space = (index(tile_grid_g%gridtype,"c3")/=0) indomain = 0 ! initialize @@ -498,7 +497,7 @@ subroutine domain_setup( & this_tileid = tile_coord_r(n)%tile_id - if( .not. c3_grid .and. tile_coord_r(n)%typ == MAPL_LAND) then + if( .not. c3_tile_space .and. tile_coord_r(n)%typ == MAPL_LAND) then this_minlon = tile_coord_r(n)%min_lon this_minlat = tile_coord_r(n)%min_lat this_maxlon = tile_coord_r(n)%max_lon diff --git a/GEOSldas_App/process_hist.csh b/GEOSldas_App/process_hist.csh index 24879767..5ca4b4b0 100644 --- a/GEOSldas_App/process_hist.csh +++ b/GEOSldas_App/process_hist.csh @@ -24,55 +24,58 @@ setenv DO_ISSM $8 echo $GRIDNAME +# NOTE: use "sed -i.tmp" (backup suffix attached), not "sed -i", so that the script also works +# with BSD sed on macOS, which takes the next argument after "-i" as the backup suffix + # uncomment 2d or 1d collections, depending on "OUT1d" (EASE tile space) or "OUT2d" (non-EASE tile space) if($OUTxd == OUT1d) then - sed -i 's|\#OUT1d|''|g' $HISTRC + sed -i.tmp 's|\#OUT1d|''|g' $HISTRC else - sed -i 's|\#OUT2d|''|g' $HISTRC + sed -i.tmp 's|\#OUT2d|''|g' $HISTRC endif # fill in name of grid associated with tile space -sed -i -e s/\'GRIDNAME\'/$GRIDNAME/g $HISTRC +sed -i.tmp -e s/\'GRIDNAME\'/$GRIDNAME/g $HISTRC # set 'GridComp' based on LSM_CHOICE; # turn on/off variables associated with CATCHCN, AEROSOL_DEPOSITION, RUN_IRRIG if($LSM_CHOICE == 1) then set GridComp = CATCH - sed -i '/^>>>HIST_CATCHCN<<>>HIST_CATCHCNCLM45<<>>HIST_CATCHCN<<>>HIST_CATCHCNCLM45<<>>HIST_CATCHCNCLM45<<>>HIST_CATCHCN<<>>HIST_CATCHCNCLM45<<>>HIST_CATCHCN<<>>HIST_CATCHCN<<>>HIST_CATCHCNCLM45<<>>HIST_CATCHCN<<>>HIST_CATCHCNCLM45<<>>HIST_AEROSOL<<>>HIST_AEROSOL<<>>HIST_AEROSOL<<>>HIST_AEROSOL<<>>HIST_IRRIG<<>>HIST_IRRIG<<>>HIST_IRRIG<<>>HIST_IRRIG<<>>HIST_ISSM<<>>HIST_ISSM<<>>HIST_ISSM<<>>HIST_ISSM<< 1) then set GridComp = LANDAVG - sed -i "s|'VEGDYN'|'VEGDYN_e0000'|g" $HISTRC - sed -i "s|'ROUTE'|'ROUTEAVG'|g" $HISTRC - sed -i "s|'LAKE'|'LAKE_e0000'|g" $HISTRC - sed -i "s|'LANDICE'|'LANDICE_e0000'|g" $HISTRC - sed -i "s|'ISSM'|'ISSM_e0000'|g" $HISTRC + sed -i.tmp "s|'VEGDYN'|'VEGDYN_e0000'|g" $HISTRC + sed -i.tmp "s|'ROUTE'|'ROUTEAVG'|g" $HISTRC + sed -i.tmp "s|'LAKE'|'LAKE_e0000'|g" $HISTRC + sed -i.tmp "s|'LANDICE'|'LANDICE_e0000'|g" $HISTRC + sed -i.tmp "s|'ISSM'|'ISSM_e0000'|g" $HISTRC endif # fill in source 'GridComp' information for output variables -sed -i 's|GridComp|'$GridComp'|g' $HISTRC +sed -i.tmp 's|GridComp|'$GridComp'|g' $HISTRC + +# "sed -i.tmp" (with suffix) works with both GNU and BSD (macOS) sed; remove the backup file + +rm -f $HISTRC.tmp diff --git a/GEOSldas_App/util/postproc/ObsFcstAna_stats/Plot_stats_maps.py b/GEOSldas_App/util/postproc/ObsFcstAna_stats/Plot_stats_maps.py index 18a4c09e..84b870eb 100644 --- a/GEOSldas_App/util/postproc/ObsFcstAna_stats/Plot_stats_maps.py +++ b/GEOSldas_App/util/postproc/ObsFcstAna_stats/Plot_stats_maps.py @@ -187,12 +187,15 @@ def Main_OmF_maps(): grid_data, lat_2d, lon_2d = tile_to_latlongrid(tile_data, tc, my_res) - # compute spatial avg of metric (directly from tile_data; no weighting) - mean = np.nanmean( tile_data ) - absmean = np.nanmean(np.abs(tile_data)) + # compute spatial avg of metric (directly from tile_data; weighted by tile area) + valid = ~np.isnan(tile_data) + data = tile_data[ valid] + area = tc['area'][valid].astype(np.float64) + mean = np.sum(area* data )/np.sum(area) + absmean = np.sum(area*np.abs(data))/np.sum(area) if 'normalized' in title_txt: - absmean = np.nanmean(np.abs(tile_data-1.) ) + absmean = np.sum(area*np.abs(data-1.))/np.sum(area) if 'normalized' in title_txt and 'stdv' in title_txt: title_txt = title_txt + '\n' + "avg=%.3f, avg(abs(nstdv-1))=%.3f" % (mean, absmean)+' '+units diff --git a/GEOSldas_App/util/shared/python/tile_to_latlongrid.py b/GEOSldas_App/util/shared/python/tile_to_latlongrid.py index da870be0..98195a7f 100644 --- a/GEOSldas_App/util/shared/python/tile_to_latlongrid.py +++ b/GEOSldas_App/util/shared/python/tile_to_latlongrid.py @@ -7,13 +7,15 @@ def tile_to_latlongrid( tile_data, tile_coord, resolution, nodata=1.e15, nodata_ """ Map (1d) tile-space data onto (2d) regular lat/lon grid of arbitrary "resolution". + The value of a grid cell is the area-weighted mean of the tiles whose center-of-mass + falls into the grid cell. Use "tile2grid.py" to map tile data onto the grid that is associated with the tile space. Parameters: ---------- tile_data : Array in tile space, shape (N_tile, N_fields) - tile_coord : Dictionary containing tile coordinate information + tile_coord : Dictionary containing tile coordinate information (incl. 'area') resolution : Target grid resolution nodata : Value for missing data nodata_tol_frac : Tolerance fraction for comparing values to nodata @@ -45,20 +47,21 @@ def tile_to_latlongrid( tile_data, tile_coord, resolution, nodata=1.e15, nodata_ lon_2d, lat_2d = np.meshgrid(lon_grid, lat_grid) grid_data = np.zeros((len(lat_grid), len(lon_grid), nf)) - N_tilecnt = np.zeros((len(lat_grid), len(lon_grid), nf)) + wgrid = np.zeros((len(lat_grid), len(lon_grid), nf)) for k in range(tile_coord['N_tile']): for v in range(nf): - if ~np.isnan(tile_data[k,v]): + if ~np.isnan(tile_data[k,v]) and tile_coord['area'][k] > 0: # zero weight would give 0/0 j = np.searchsorted(lat_grid + resolution/2., tile_coord['com_lat'][k]) i = np.searchsorted(lon_grid + resolution/2., tile_coord['com_lon'][k]) - # grid value takes the mean of all tiles within - # new_mean = old_mean + (new_value - old_mean)/count - N_tilecnt[j,i,v] += 1 - grid_data[j,i,v] = grid_data[j,i,v] + (tile_data[k,v]-grid_data[j,i,v])/N_tilecnt[j,i,v] + # grid value takes the area-weighted mean of all tiles within + # new_mean = old_mean + (new_value - old_mean)*weight/sum_of_weights + w = tile_coord['area'][k] + wgrid[j,i,v] += w + grid_data[j,i,v] = grid_data[j,i,v] + (tile_data[k,v]-grid_data[j,i,v])*w/wgrid[j,i,v] - grid_data[N_tilecnt == 0] = np.nan + grid_data[wgrid == 0] = np.nan return grid_data.squeeze(), lat_2d, lon_2d diff --git a/LDAS_Shared/LDAS_PertTypes.F90 b/LDAS_Shared/LDAS_PertTypes.F90 index e0ed963d..ef8d1d42 100644 --- a/LDAS_Shared/LDAS_PertTypes.F90 +++ b/LDAS_Shared/LDAS_PertTypes.F90 @@ -89,65 +89,66 @@ module LDAS_PertTypes ! ********************************************************************** type T_PERT - ! private - integer :: npert ! number of perturbation + ! private + integer :: npert ! number of perturbation !In situation that a processor has no tiles, this processor can still participate parallel fft - integer :: fft_npert - integer :: dtstep - type(ESMF_Time) :: TimePrv, TimeNxt - type(pert_param_type), pointer :: param(:)=>null() - real, allocatable :: DataPrv(:,:), DataNxt(:,:) - end type T_PERT - + integer :: fft_npert + integer :: dtstep + type(ESMF_Time) :: TimePrv, TimeNxt + type(pert_param_type), pointer :: param(:)=>null() + real, allocatable :: DataPrv(:,:), DataNxt(:,:) + end type T_PERT + ! Internal state and its wrapper - type T_LANDPERT_STATE + type T_LANDPERT_STATE !private - integer :: PERT_CHOICE ! => rc variable PERTURBATIONS: 0=none, 1=rectangular, 2=sphere (see also GEOSldas_LDAS.rc) - integer :: ens_id - integer :: NUM_ENSEMBLE - logical :: isCubedSphere - - integer,allocatable :: i_indgs(:) - integer,allocatable :: j_indgs(:) + integer :: PERT_CHOICE ! => rc variable PERTURBATIONS: 0=none, 1=rectangular, 2=sphere (see also GEOSldas_LDAS.rc) + integer :: ens_id + integer :: NUM_ENSEMBLE + logical :: isCubedSphere + + integer, allocatable :: i_indgs(:) ! => tilecoord%pert_i_indg + integer, allocatable :: j_indgs(:) ! => tilecoord%pert_j_indg ! if it is cubed-sphere grid, swith to internal start - real,allocatable :: fpert_ntrmdt(:,:,:) - real,allocatable :: ppert_ntrmdt(:,:,:) - real(kind=ESMF_KIND_R8), allocatable :: pert_rseed_r8(:) + real, allocatable :: fpert_ntrmdt(:,:,:) + real, allocatable :: ppert_ntrmdt(:,:,:) + real(kind=ESMF_KIND_R8), allocatable :: pert_rseed_r8(:) ! force/progn perturbations - type(T_PERT) :: ForcePert, PrognPert - end type T_LANDPERT_STATE - type LANDPERT_WRAP - type(T_LANDPERT_STATE), pointer :: ptr=>null() - end type LANDPERT_WRAP + type(T_PERT) :: ForcePert, PrognPert + end type T_LANDPERT_STATE + type LANDPERT_WRAP + type(T_LANDPERT_STATE), pointer :: ptr=>null() + end type LANDPERT_WRAP + contains subroutine allocate_pert_param(N_pert, N_x, N_y, pert_param) - + implicit none - + integer, intent(in) :: N_pert, N_x, N_y - + type(pert_param_type), dimension(:), pointer :: pert_param - + ! local variables - + integer :: k - + ! -------------------------------------------------------- - + nullify(pert_param) - + allocate(pert_param(N_pert)) - + do k=1,N_pert - + allocate(pert_param(k)%mean(N_x,N_y)) allocate(pert_param(k)%std(N_x,N_y)) allocate(pert_param(k)%ccorr(N_pert,N_x,N_y)) - + end do - + end subroutine allocate_pert_param ! ********************************************************************** diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 43e5f86b..fe8ba5d7 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -5,6 +5,9 @@ ! reichle, 14 Apr 2006 - split tile_coord.F90 into 2 files to avoid ! having more than one module per file ! reichle, 5 Apr 2013 - added EASEv2 grid, minimal change to max lat/lon for EASE (v1) +! amfox, 9 Nov 2026 - added cube-sphere grid ("c3") case to get_tile_num_from_latlon(); +! map lat/lon to cube-sphere grid cells with MAPL_GetGlobalHorzIJIndex() +! and the ESMF grid (get_ij_ind_from_latlon_c3(), init_tile_grid_g_ESMF_c3()) ! ! ======================================================================== @@ -24,11 +27,19 @@ module LDAS_TileCoordRoutines nodata_tol_generic use MAPL_ConstantsMod, ONLY: & - MAPL_RADIUS ! Earth radius + MAPL_RADIUS, & ! Earth radius + MAPL_PI, & + MAPL_PI_R8 use MAPL, ONLY: & MAPL_ease_convert, & - MAPL_ease_extent + MAPL_ease_extent, & + MAPL_GridGet, & + MAPL_GetGlobalHorzIJIndex + + use ESMF, ONLY: & + ESMF_Grid, & + ESMF_AttributeGet use LDAS_ExceptionsMod, ONLY: & ldas_abort, & @@ -47,15 +58,19 @@ module LDAS_TileCoordRoutines public :: get_tile_num_in_ellipse public :: get_tile_num_from_latlon public :: get_ij_ind_from_latlon + public :: get_ij_ind_from_latlon_c3 + public :: init_tile_grid_g_ESMF_c3 public :: tile2grid_simple public :: grid2tile public :: tile_mask_grid public :: LDAS_create_grid_g public :: io_domain_files - character(10) :: tmpstring10 - character(40) :: tmpstring40 - + character(10) :: tmpstring10 + character(40) :: tmpstring40 + + integer, parameter :: nodata_tilenum = -9999 + interface grid2tile module procedure grid2tile_real, grid2tile_real8 end interface grid2tile @@ -65,7 +80,7 @@ module LDAS_TileCoordRoutines ! ********************************************************************** subroutine io_domain_files( action, work_path, exp_id, & - N_cat_domain, d2g, tile_coord, tile_grid_g, tile_grid_d, rc ) + N_catf, d2g, tile_coord, tile_grid_g, tile_grid_f, rc ) ! reichle, 23 July 2010 ! reichle, 7 Jan 2014 - changed tile_coord and tile_grids I/O to binary @@ -73,19 +88,19 @@ subroutine io_domain_files( action, work_path, exp_id, & implicit none - character, intent(in) :: action + character, intent(in) :: action - character(*), intent(in) :: work_path - character(*), intent(in) :: exp_id + character(*), intent(in) :: work_path + character(*), intent(in) :: exp_id - integer, intent(inout) :: N_cat_domain + integer, intent(inout) :: N_catf integer, dimension(:), pointer :: d2g - type(tile_coord_type), dimension(:), pointer :: tile_coord ! inout + type(tile_coord_type), dimension(:), pointer :: tile_coord ! inout type(grid_def_type), intent(inout) :: tile_grid_g - type(grid_def_type), intent(inout) :: tile_grid_d + type(grid_def_type), intent(inout) :: tile_grid_f integer, intent( out) :: rc @@ -101,7 +116,7 @@ subroutine io_domain_files( action, work_path, exp_id, & character( 40) :: file_tag, dir_name, file_ext, tmp_action, tmp_status character(len=*), parameter :: Iam = 'io_domain_files' - character(len=400) :: err_msg + character(len=400) :: err_msg ! ----------------------------------------------------------- ! @@ -159,20 +174,20 @@ subroutine io_domain_files( action, work_path, exp_id, & if (writing) then - write (unitnumber,*) N_cat_domain + write (unitnumber,*) N_catf - do n=1,N_cat_domain + do n=1,N_catf write (unitnumber,*) tile_coord(n)%tile_id, d2g(n) end do else - read (unitnumber,*) N_cat_domain + read (unitnumber,*) N_catf - allocate(tile_coord(N_cat_domain)) - allocate(d2g( N_cat_domain)) + allocate(tile_coord(N_catf)) + allocate(d2g( N_catf)) - do n=1,N_cat_domain + do n=1,N_catf read (unitnumber,*) tile_coord(n)%tile_id, d2g(n) end do @@ -212,7 +227,7 @@ subroutine io_domain_files( action, work_path, exp_id, & else - call io_tile_coord_type( action, unitnumber, N_cat_domain, tile_coord ) + call io_tile_coord_type( action, unitnumber, N_catf, tile_coord ) close (unitnumber,status='keep') @@ -251,8 +266,8 @@ subroutine io_domain_files( action, work_path, exp_id, & ! read/write 'tile_grid_g' call io_grid_def_type( action, unitnumber, tile_grid_g ) - ! read/write 'tile_grid_d' - call io_grid_def_type( action, unitnumber, tile_grid_d ) + ! read/write 'tile_grid_f' + call io_grid_def_type( action, unitnumber, tile_grid_f ) close (unitnumber,status='keep') @@ -270,13 +285,15 @@ end subroutine io_domain_files ! ********************************************************************** subroutine LDAS_create_grid_g( gridname, n_lon, n_lat, & - tile_grid, i_indg_offset, j_indg_offset, cell_area) - + my_grid, i_indg_offset, j_indg_offset, cell_area) + + ! assemble LDAS grid type for global grid + ! ! inputs: ! gridname, n_lon, n_lat ! ! inouts: - ! tile_grid : parameters of tile definition grid + ! my_grid : LDAS grid type with parameters according to input args ! ! outputs: ! offsets @@ -286,7 +303,7 @@ subroutine LDAS_create_grid_g( gridname, n_lon, n_lat, & character(*), intent(in) :: gridname integer, intent(in) :: n_lon, n_lat - type(grid_def_type), intent(inout) :: tile_grid + type(grid_def_type), intent(inout) :: my_grid integer, intent(out) :: i_indg_offset, j_indg_offset real, optional, intent(out) :: cell_area @@ -297,27 +314,28 @@ subroutine LDAS_create_grid_g( gridname, n_lon, n_lat, & logical :: ease_grid, c3_grid, latlon_grid logical :: file_exist integer :: k, rows, cols + character(len=*), parameter :: Iam = 'create global ldas_grid ' character(len=400) :: err_msg - ! initialize all fields to no-data values + ! ---------------------------------- - i_indg_offset = 0 - j_indg_offset = 0 + i_indg_offset = 0 + j_indg_offset = 0 - call init_grid_def_type(tile_grid) + call init_grid_def_type(my_grid) - tile_grid%N_lon = N_lon - tile_grid%N_lat = N_lat + my_grid%N_lon = N_lon + my_grid%N_lat = N_lat - tile_grid%i_offg = 0 ! tile_grid refers to *global* grid - tile_grid%j_offg = 0 ! tile_grid refers to *global* grid + my_grid%i_offg = 0 ! my_grid refers to *global* grid + my_grid%j_offg = 0 ! my_grid refers to *global* grid - date_line_on_center = .false. - pole_on_center = .false. - ease_grid = .false. - c3_grid = .false. - latlon_grid = .true. + date_line_on_center = .false. + pole_on_center = .false. + ease_grid = .false. + c3_grid = .false. + latlon_grid = .true. if (index(gridname,"DC") /=0) then date_line_on_center = .true. @@ -332,13 +350,13 @@ subroutine LDAS_create_grid_g( gridname, n_lon, n_lat, & endif if (index(gridname,"EASEv") /=0) then - ease_grid = .true. - latlon_grid = .false. + ease_grid = .true. + latlon_grid = .false. endif if (index(gridname,"CF") /=0) then - c3_grid = .true. - latlon_grid = .false. + c3_grid = .true. + latlon_grid = .false. endif ! special cases , inconsistent of naming @@ -349,12 +367,12 @@ subroutine LDAS_create_grid_g( gridname, n_lon, n_lat, & ! Weiyuan Note, we should fix the tile file and the naming if( index(gridname,"PE_720x360_DE") /=0) then - i_indg_offset = 110 - j_indg_offset = 230 + i_indg_offset = 110 + j_indg_offset = 230 endif if( index(gridname,"PE_2880x1440_DE") /=0) then - i_indg_offset = 440 - j_indg_offset = 920 + i_indg_offset = 440 + j_indg_offset = 920 endif ! ---------------- @@ -370,69 +388,69 @@ subroutine LDAS_create_grid_g( gridname, n_lon, n_lat, & call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - tile_grid%gridtype = trim(gridname(k:)) + my_grid%gridtype = trim(gridname(k:)) - tile_grid%ind_base = 0 + my_grid%ind_base = 0 ! global cylindrical EASE grid - tile_grid%i_dir = +1 - tile_grid%j_dir = -1 + my_grid%i_dir = +1 + my_grid%j_dir = -1 - call MAPL_ease_extent ( & - gridname, cols, rows, & - cell_area = ease_cell_area, & ! [m^2] - ll_lon = tile_grid%ll_lon, & - ll_lat = tile_grid%ll_lat, & - ur_lon = tile_grid%ur_lon, & - ur_lat = tile_grid%ur_lat & + call MAPL_ease_extent ( & + gridname, cols, rows, & + cell_area = ease_cell_area, & ! [m^2] + ll_lon = my_grid%ll_lon, & + ll_lat = my_grid%ll_lat, & + ur_lon = my_grid%ur_lon, & + ur_lat = my_grid%ur_lat & ) - tile_grid%dlon = 360./real(tile_grid%N_lon) - tile_grid%dlat = (tile_grid%ur_lat-tile_grid%ll_lat)/real(tile_grid%N_lat) ! *avg* dlat! + my_grid%dlon = 360./real(my_grid%N_lon) + my_grid%dlat = (my_grid%ur_lat-my_grid%ll_lat)/real(my_grid%N_lat) ! *avg* dlat! if(present(cell_area)) then - cell_area=ease_cell_area + cell_area = ease_cell_area endif endif ! EASE grid if (latlon_grid) then ! regular LatLon grid - tile_grid%gridtype = 'LatLon' + my_grid%gridtype = 'LatLon' - tile_grid%ind_base = 1 + my_grid%ind_base = 1 - tile_grid%dlon = 360./real(tile_grid%N_lon) + my_grid%dlon = 360./real(my_grid%N_lon) - tile_grid%i_dir = +1 - tile_grid%j_dir = +1 + my_grid%i_dir = +1 + my_grid%j_dir = +1 if (pole_on_center) then - tile_grid%dlat = 180./real(tile_grid%N_lat-1) + my_grid%dlat = 180./real(my_grid%N_lat-1) - tile_grid%ll_lat = -90. - tile_grid%dlat/2. - tile_grid%ur_lat = 90. + tile_grid%dlat/2. + my_grid%ll_lat = -90. - my_grid%dlat/2. + my_grid%ur_lat = 90. + my_grid%dlat/2. else - tile_grid%dlat = 180./real(tile_grid%N_lat) + my_grid%dlat = 180./real(my_grid%N_lat) - tile_grid%ll_lat = -90. - tile_grid%ur_lat = 90. + my_grid%ll_lat = -90. + my_grid%ur_lat = 90. end if if (date_line_on_center) then - tile_grid%ll_lon = -180. - tile_grid%dlon/2. - tile_grid%ur_lon = 180. - tile_grid%dlon/2. ! fixed 20 sep 2010, reichle + my_grid%ll_lon = -180. - my_grid%dlon/2. + my_grid%ur_lon = 180. - my_grid%dlon/2. ! fixed 20 sep 2010, reichle else - tile_grid%ll_lon = -180. - tile_grid%ur_lon = 180. + my_grid%ll_lon = -180. + my_grid%ur_lon = 180. end if @@ -440,18 +458,20 @@ subroutine LDAS_create_grid_g( gridname, n_lon, n_lat, & if( c3_grid) then - tile_grid%gridtype = 'c3' - tile_grid%ind_base = 1 - tile_grid%i_dir = +1 - tile_grid%j_dir = +1 - tile_grid%ll_lon = -180. - tile_grid%ur_lon = 180. - tile_grid%ll_lat = -90. - tile_grid%ur_lat = 90. + ! LDAS grid type cannot really represent c3 grid parameters; fill in parameters as much as possible + + my_grid%gridtype = 'c3' + my_grid%ind_base = 1 + my_grid%i_dir = +1 + my_grid%j_dir = +1 + my_grid%ll_lon = -180. + my_grid%ur_lon = 180. + my_grid%ll_lat = -90. + my_grid%ur_lat = 90. ! dlon and dlat are approximate! - tile_grid%dlon = 360./real(4*tile_grid%N_lon) - tile_grid%dlat = tile_grid%dlon + my_grid%dlon = 360./real(4*my_grid%N_lon) + my_grid%dlat = my_grid%dlon endif @@ -460,18 +480,20 @@ end subroutine LDAS_create_grid_g ! ******************************************************************* function get_minExtent_grid( N_tile, tc_i_indg, tc_j_indg, tc_minlon, tc_minlat, tc_maxlon, tc_maxlat, & - tile_grid_g) result( tile_grid ) + my_grid_g) result( my_grid ) - ! get tile_grid with smallest extent for given set of tiles in tile_coord on (global) tile_grid_g + ! get LDAS grid type "my_grid" with smallest extent for given set of tiles, as a subgrid of the global "my_grid_g" ! - ! make sure to pass in consistent tile_coord (tc) and tile_grid_g inputs: + ! IMPORTANT: make sure to pass in consistent tile_coord (tc) and my_grid_g inputs: ! - ! iff tile_grid_g is the grid that is associated with the tile space definition, + ! iff my_grid_g is the grid that is associated with the tile space definition, ! then input tc_[x]_indg must be tile_coord%[x]_indg ! - ! iff tile_grid_g is the grid that supports efficient mapping for perts and the EnKF analysis, + ! iff my_grid_g is the grid that supports efficient mapping for perts and or tiles2obsFOV mapping in the EnKF analysis, ! then input tc_[x]_indg must be tile_coord%pert_[x]_indg ! + ! Note: get_minExtent_grid() is not used for obs2tile mapping in the obs readers. + ! ! reichle, 20 June 2012 -- moved from within domain_setup() ! for re-use in get_obs_pred() ! @@ -486,8 +508,8 @@ function get_minExtent_grid( N_tile, tc_i_indg, tc_j_indg, tc_minlon, tc_minlat, real, intent(in), dimension(N_tile) :: tc_minlon, tc_minlat real, intent(in), dimension(N_tile) :: tc_maxlon, tc_maxlat - type(grid_def_type), intent(in) :: tile_grid_g - type(grid_def_type) :: tile_grid + type(grid_def_type), intent(in) :: my_grid_g + type(grid_def_type) :: my_grid ! output (result) ! local variables @@ -500,10 +522,11 @@ function get_minExtent_grid( N_tile, tc_i_indg, tc_j_indg, tc_minlon, tc_minlat, integer :: ind_i_min, ind_i_max, ind_j_min, ind_j_max integer :: this_i_indg, this_j_indg + integer , allocatable :: i_indg_(:), j_indg_(:) - logical :: c3_grid + character(len=*), parameter :: Iam = 'get_minExtent_grid' - character(len=400) :: err_msg + character(len=400) :: err_msg ! ------------------------------------------------- @@ -512,116 +535,116 @@ function get_minExtent_grid( N_tile, tc_i_indg, tc_j_indg, tc_minlon, tc_minlat, max_max_lon = -180. max_max_lat = -90. - ind_i_min = tile_grid_g%N_lon+1 ! initialize - ind_j_min = tile_grid_g%N_lat+1 - ind_i_max = -1 - ind_j_max = -1 + ind_i_min = my_grid_g%N_lon+1 ! initialize + ind_j_min = my_grid_g%N_lat+1 + ind_i_max = -1 + ind_j_max = -1 - ! THIS COMMENT SEEMS OUTDATED (reichle, 2 Aug 2020) - ! for c3 grid, only get the ll_,ur_ lat and lon, the index is meaningless; - ! it will be used in creating the lat_lon pert_grid - - if(index(tile_grid_g%gridtype,"c3") /=0) then + if (index(my_grid_g%gridtype,"c3") /=0) then ! for cube-sphere grids, do NOT zoom in - tile_grid=tile_grid_g + my_grid=my_grid_g - return + return ! all done if cube-sphere grid - endif - + endif + if (N_tile == 0) then - tile_grid=tile_grid_g - tile_grid%n_lon = 0 - tile_grid%n_lat = 0 - return + + my_grid = my_grid_g + + my_grid%n_lon = 0 + my_grid%n_lat = 0 + + return ! all done if there are no tiles + endif do n=1,N_tile - this_minlon = tc_minlon(n) - this_minlat = tc_minlat(n) - this_maxlon = tc_maxlon(n) - this_maxlat = tc_maxlat(n) + this_minlon = tc_minlon(n) + this_minlat = tc_minlat(n) + this_maxlon = tc_maxlon(n) + this_maxlat = tc_maxlat(n) - this_i_indg = tc_i_indg(n) - this_j_indg = tc_j_indg(n) + this_i_indg = tc_i_indg(n) + this_j_indg = tc_j_indg(n) - min_min_lon = min( min_min_lon, this_minlon) - min_min_lat = min( min_min_lat, this_minlat) - max_max_lon = max( max_max_lon, this_maxlon) - max_max_lat = max( max_max_lat, this_maxlat) + min_min_lon = min( min_min_lon, this_minlon) + min_min_lat = min( min_min_lat, this_minlat) + max_max_lon = max( max_max_lon, this_maxlon) + max_max_lat = max( max_max_lat, this_maxlat) - ind_i_min = min( ind_i_min, this_i_indg) - ind_j_min = min( ind_j_min, this_j_indg) - ind_i_max = max( ind_i_max, this_i_indg) - ind_j_max = max( ind_j_max, this_j_indg) + ind_i_min = min( ind_i_min, this_i_indg) + ind_j_min = min( ind_j_min, this_j_indg) + ind_i_max = max( ind_i_max, this_i_indg) + ind_j_max = max( ind_j_max, this_j_indg) end do - ! assemble tile_grid (revised 20 Sep 2010, reichle) + ! assemble my_grid (revised 20 Sep 2010, reichle) - tile_grid%N_lon = ind_i_max - ind_i_min + 1 - tile_grid%N_lat = ind_j_max - ind_j_min + 1 + my_grid%N_lon = ind_i_max - ind_i_min + 1 + my_grid%N_lat = ind_j_max - ind_j_min + 1 - tile_grid%i_offg = ind_i_min - tile_grid_g%ind_base - tile_grid%j_offg = ind_j_min - tile_grid_g%ind_base + my_grid%i_offg = ind_i_min - my_grid_g%ind_base + my_grid%j_offg = ind_j_min - my_grid_g%ind_base - tile_grid%dlon = tile_grid_g%dlon + my_grid%dlon = my_grid_g%dlon - if (index(tile_grid_g%gridtype,'LatLon')/=0) then + if (index(my_grid_g%gridtype,'LatLon')/=0) then - tile_grid%dlat = tile_grid_g%dlat + my_grid%dlat = my_grid_g%dlat - tile_grid%ll_lon = tile_grid_g%ll_lon + real(tile_grid%i_offg)*tile_grid%dlon - tile_grid%ll_lat = tile_grid_g%ll_lat + real(tile_grid%j_offg)*tile_grid%dlat + my_grid%ll_lon = my_grid_g%ll_lon + real(my_grid%i_offg)*my_grid%dlon + my_grid%ll_lat = my_grid_g%ll_lat + real(my_grid%j_offg)*my_grid%dlat - tile_grid%ur_lon = tile_grid%ll_lon + real(tile_grid%N_lon)*tile_grid%dlon - tile_grid%ur_lat = tile_grid%ll_lat + real(tile_grid%N_lat)*tile_grid%dlat + my_grid%ur_lon = my_grid%ll_lon + real(my_grid%N_lon)*my_grid%dlon + my_grid%ur_lat = my_grid%ll_lat + real(my_grid%N_lat)*my_grid%dlat - elseif ( index(tile_grid_g%gridtype,'EASEv') /=0 ) then + elseif ( index(my_grid_g%gridtype,'EASEv') /=0 ) then ! *average* dlat over the domain - tile_grid%dlat = (max_max_lat - min_min_lat)/real(tile_grid%N_lat) + my_grid%dlat = (max_max_lat - min_min_lat)/real(my_grid%N_lat) - tile_grid%ll_lon = min_min_lon - tile_grid%ll_lat = min_min_lat + my_grid%ll_lon = min_min_lon + my_grid%ll_lat = min_min_lat - tile_grid%ur_lon = max_max_lon - tile_grid%ur_lat = max_max_lat + my_grid%ur_lon = max_max_lon + my_grid%ur_lat = max_max_lat else - err_msg = 'not yet implemented for ' // tile_grid_g%gridtype + err_msg = 'not yet implemented for ' // my_grid_g%gridtype call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - tile_grid%gridtype = tile_grid_g%gridtype + my_grid%gridtype = my_grid_g%gridtype - tile_grid%ind_base = tile_grid_g%ind_base ! should this be inherited??? + my_grid%ind_base = my_grid_g%ind_base ! should this be inherited??? - tile_grid%i_dir = tile_grid_g%i_dir - tile_grid%j_dir = tile_grid_g%j_dir + my_grid%i_dir = my_grid_g%i_dir + my_grid%j_dir = my_grid_g%j_dir end function get_minExtent_grid ! ********************************************************************** - subroutine get_number_of_tiles_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, tile_grid, & + subroutine get_number_of_tiles_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, my_grid, & N_tile_in_cell_ij) - ! find out how many tiles are in a given tile definition grid cell + ! find out how many tiles are in a given grid cell ! reichle, 22 Jul 2005 ! - ! make sure to pass in consistent tile_coord (tc) and tile_grid_g inputs: + ! make sure to pass in consistent tile_coord (tc) and my_grid inputs: ! - ! iff tile_grid_g is the grid that is associated with the tile space definition, + ! iff my_grid is the grid that is associated with the tile space definition, ! then tc_[x]_indg must be tile_coord%[x]_indg ! - ! iff tile_grid_g is the grid that supports efficient mapping for perts and the EnKF analysis, + ! iff my_grid is the grid that supports efficient mapping for perts and obs2tile or tiles2obsFOV mapping in the EnKF analysis, ! then tc_[x]_indg must be tile_coord%pert_[x]_indg ! ! wjiang(?) -- split off from LDASsa legacy subroutine get_tile_num_in_cell_ij() @@ -637,10 +660,9 @@ subroutine get_number_of_tiles_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, tile_gr integer, intent(in), dimension(N_tile) :: tc_i_indg, tc_j_indg - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: my_grid - integer, dimension(tile_grid%N_lon,tile_grid%N_lat), intent(inout) :: & - N_tile_in_cell_ij + integer, dimension(my_grid%N_lon,my_grid%N_lat), intent(inout) :: N_tile_in_cell_ij ! locals @@ -649,8 +671,8 @@ subroutine get_number_of_tiles_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, tile_gr ! adjust for 0-based indexing (eg., EASE grids) - off_i = tile_grid%i_offg + (tile_grid%ind_base - 1) - off_j = tile_grid%j_offg + (tile_grid%ind_base - 1) + off_i = my_grid%i_offg + (my_grid%ind_base - 1) + off_j = my_grid%j_offg + (my_grid%ind_base - 1) ! (re-)initialize @@ -666,33 +688,26 @@ subroutine get_number_of_tiles_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, tile_gr enddo if (logit) write (logunit,*) & - 'Maximum number of tiles in tile def grid cell = ', maxval(N_tile_in_cell_ij) + 'Maximum number of tiles in grid cell = ', maxval(N_tile_in_cell_ij) if (logit) write (logunit,*) end subroutine get_number_of_tiles_in_cell_ij ! ********************************************************************** - subroutine get_tile_num_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, tile_grid, & + subroutine get_tile_num_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, my_grid, & max_N_tile_in_cells, tile_num_in_cell_ij ) - ! find out tile_num in given cells - ! - ! The indices tile_coord%i_indg and tile_coord%j_indg refer to the *global* - ! tile definition grid (as obtained from the tile_coord_file). - ! Integers "off_i" and "off_j" describe the offset between the global - ! "tile_grid_g" and a smaller "tile_grid_d" for the domain of interest. - ! With these offsets tile2grid() can be used to map from a - ! subgrid of "tile_grid_g" to tile space + ! find out tile_num indices of tiles in given grid cells ! ! reichle, 22 Jul 2005 ! - ! make sure to pass in consistent tile_coord (tc) and tile_grid_g inputs: + ! make sure to pass in consistent tile_coord (tc) and my_grid inputs: ! - ! iff tile_grid_g is the grid that is associated with the tile space definition, + ! iff my_grid is the grid that is associated with the tile space definition, ! then tc_[x]_indg must be tile_coord%[x]_indg ! - ! iff tile_grid_g is the grid that supports efficient mapping for perts and the EnKF analysis, + ! iff my_grid is the grid that supports efficient mapping for perts and the EnKF analysis, ! then tc_[x]_indg must be tile_coord%pert_[x]_indg ! ! wjiang(?) -- split off from LDASsa legacy subroutine get_tile_num_in_cell_ij() @@ -708,20 +723,19 @@ subroutine get_tile_num_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, tile_grid, & integer, intent(in), dimension(N_tile) :: tc_i_indg, tc_j_indg - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: my_grid - integer, intent(in) :: max_N_tile_in_cells + integer, intent(in) :: max_N_tile_in_cells ! the pointer is an output arguments that is allocated here - integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij + integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij - integer, dimension(tile_grid%N_lon,tile_grid%N_lat) :: & - N_tile_in_cell_ij + integer, dimension(my_grid%N_lon,my_grid%N_lat) :: N_tile_in_cell_ij ! locals - integer, parameter :: nodata = -9999. + !integer, parameter :: nodata = -9999. ! note bad int init; replaced with nodata_tilenum, 13 Nov 2026 integer :: i, j, k, n, off_i, off_j @@ -729,16 +743,14 @@ subroutine get_tile_num_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, tile_grid, & ! ! allocate and initialize pointers if present + allocate(tile_num_in_cell_ij( my_grid%N_lon, my_grid%N_lat, max_N_tile_in_cells )) - allocate(tile_num_in_cell_ij(tile_grid%N_lon,tile_grid%N_lat, & - max_N_tile_in_cells)) - - tile_num_in_cell_ij = nodata + tile_num_in_cell_ij = nodata_tilenum ! adjust for 0-based indexing (eg., EASE grids) - off_i = tile_grid%i_offg + (tile_grid%ind_base - 1) - off_j = tile_grid%j_offg + (tile_grid%ind_base - 1) + off_i = my_grid%i_offg + (my_grid%ind_base - 1) + off_j = my_grid%j_offg + (my_grid%ind_base - 1) ! (re-)initialize @@ -761,10 +773,17 @@ end subroutine get_tile_num_in_cell_ij ! ******************************************************************* - subroutine get_tile_num_from_latlon(N_catd, tile_coord, & - tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & + subroutine get_tile_num_from_latlon( N_catd, tile_coord, & + my_grid, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & tile_num, max_dist_x, max_dist_y ) + ! determine tile_num indices of tiles that "contain" given lat/lon coords + ! + ! "my_grid" could be the grid associated with tile space definition or the hash grid used for + ! efficient obs2tile or tiles2obsFOV mapping in the EnKF analysis (i.e., pert_grid). + ! "N_tile_in_cell_ij" and "tile_num_in_cell_ij" must be consistent with "my_grid". + ! ! bug fix re. "check that lat/lon is inside tile_grid" ! - reichle, 2005/11/17 ! @@ -775,6 +794,11 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & ! distance units are in [deg]; added functionality for latitude-dependent ! meridional max distance (max_dist_x) ! - reichle, 2014/12/23 + ! + ! added case for cube-sphere ("c3") tile space, see get_tile_num_from_latlon_c3(); + ! requires input "tile_grid_g_ESMF" (ESMF grid associated with cube-sphere tile space); + ! see also subroutine Initialize() of GEOS_LdasGridComp.F90 + ! - amfox, 9 Nov 2026 implicit none @@ -782,11 +806,13 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: my_grid + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for "c3" tile_grid - integer, dimension(tile_grid%N_lon,tile_grid%N_lat), intent(in) :: N_tile_in_cell_ij + integer, dimension(my_grid%N_lon,my_grid%N_lat), intent(in) :: N_tile_in_cell_ij - integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input real, dimension(N_latlon), intent(in) :: lat, lon @@ -795,11 +821,8 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & real, dimension(N_latlon), optional, intent(in) :: max_dist_x ! vector [deg] real, optional, intent(in) :: max_dist_y ! scalar [deg] - ! local variables - integer, parameter :: nodata_tilenum = -9999 - integer :: n, k, i_ind, j_ind, this_tile_num logical :: outside_bbox, too_far_away @@ -824,20 +847,33 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & tile_num = nodata_tilenum ! initialize to negative value + if (index(my_grid%gridtype, 'c3')/=0) then + + ! cube-sphere tile space: tiles do not nest in grid cells of a lat/lon grid, + ! use bounding boxes of tiles (amfox, 9 Nov 2026) + + call get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & + my_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & + max_dist_tmp_x, max_dist_tmp_y, tile_num ) + + return ! all done if tile space is cube-sphere + + end if + ! loop through observations do n=1,N_latlon - ! Make sure lat/lon is *inside* tile_grid, otherwise do nothing. - ! Do *not* allow obs outside tile_grid because obs perturbations + ! Make sure lat/lon is *inside* my_grid, otherwise do nothing. + ! Do *not* allow obs outside my_grid because obs perturbations ! routines are not set up to generate perturbations for such obs, ! and obs_pred would be questionable anyway. ! - reichle+csdraper, 29 Jan 2016 - if ( tile_grid%ll_lat < (lat(n) ) .and. & - tile_grid%ll_lon < (lon(n) ) .and. & - (lat(n) ) < tile_grid%ur_lat .and. & - (lon(n) ) < tile_grid%ur_lon ) then + if ( my_grid%ll_lat < (lat(n) ) .and. & + my_grid%ll_lon < (lon(n) ) .and. & + (lat(n) ) < my_grid%ur_lat .and. & + (lon(n) ) < my_grid%ur_lon ) then ! min_dist = distance betw lat/lon in question and center-of-mass of ! matching tile @@ -848,17 +884,17 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & ! determine grid cell that contains lat/lon - call get_ij_ind_from_latlon( tile_grid, lat(n), lon(n), i_ind, j_ind ) + call get_ij_ind_from_latlon( my_grid, lat(n), lon(n), i_ind, j_ind ) ! make sure that i/j_ind is still within bounds ! (works in conjunction with if statement above re. ll/ur_lat/lon) - i_ind = min( max(i_ind, 1), tile_grid%N_lon ) - j_ind = min( max(j_ind, 1), tile_grid%N_lat ) + i_ind = min( max(i_ind, 1), my_grid%N_lon ) + j_ind = min( max(j_ind, 1), my_grid%N_lat ) ! map from i_ind, j_ind to tile_num - if ( index(tile_grid%gridtype, 'EASEv') /=0 ) then + if ( index(my_grid%gridtype, 'EASEv') /=0 ) then ! ASSUMPTION: tiles match EASE grid cells exactly ! (unless "outside" the domain, eg. water surface) @@ -882,7 +918,7 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & end if - elseif (index(tile_grid%gridtype, 'LatLon')/=0) then + elseif (index(my_grid%gridtype, 'LatLon')/=0) then ! Loop through all tiles within grid cell that contain lat/lon and ! find minimum distance (Minkowski norm). @@ -918,7 +954,7 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & ! check whether lat/lon is inside bounding box of given tile - ! (if domain consists of a single tile and tile_grid is coarse, + ! (if domain consists of a single tile and my_grid is coarse, ! it is likely that lat/lon is outside bounding box of tile ! even if the lat/lon is inside the tile definition grid cell that ! contains the given tile) - reichle, 18 Aug 2005 @@ -960,14 +996,447 @@ end subroutine get_tile_num_from_latlon ! ******************************************************************* - subroutine get_ij_ind_from_latlon( tile_grid, lat, lon, i_ind, j_ind ) + subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & + tile_grid_g, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & + max_dist_x, max_dist_y, tile_num ) + + ! find tile_num for lat/lon in cube-sphere ("c3") tile space, see get_tile_num_from_latlon() + ! + ! c3 tiles do not nest in the cells of a lat/lon grid, so for cube-sphere tile space, + ! tile_grid_g must be the cube-sphere grid that defines the tile space (and + ! N_tile_in_cell_ij, tile_num_in_cell_ij must be obtained from tile_coord%i_indg and + ! tile_coord%j_indg). tile_grid_g_ESMF is the ESMF grid of the cube-sphere tile space. + ! + ! Each tile is inside the cube-sphere grid cell given by tile_coord%i_indg and + ! tile_coord%j_indg, but a tile can be much smaller than the grid cell, and lat/lon is + ! often not inside the tile with the nearest center-of-mass. Therefore, use the + ! bounding box of the tiles: + ! + ! 1.) Loop through all tiles within grid cell that contains lat/lon. + ! Among the tiles whose bounding box contains lat/lon, find the minimum + ! normalized square distance (dx/hx)**2 + (dy/hy)**2, where hx and hy + ! are half the width and height of the bounding box. + ! + ! 2.) If no tile was found in 1.), repeat 1.) for all tiles within the neighbor grid cells + ! that contain (i) the 8 lat/lon points at +/- half a grid cell (approx.) around + ! lat/lon, because the bounding box of a tile can extend into a + ! neighboring grid cell, and (ii) the points of a lattice that covers + ! lat/lon +/- max_dist, with a spacing of at most a quarter grid cell (approx.). + ! The lattice finds nearly all grid cells within max_dist, but it can miss a grid + ! cell that overlaps only a small corner of the lat/lon +/- max_dist rectangle + ! (3 of 83,645 Step 3.) cases in an offline test for CF0360 with FOV 20 and 50 km; + ! another tile within max_dist was then chosen). Grid cells that were already + ! searched are skipped. + ! + ! 3.) If no tile was found in 1.) or 2.), loop through all tiles within the grid + ! cells identified in 1.) and 2.) and find minimum distance (Minkowski norm) + ! among the tiles whose center-of-mass is within max_dist_x and max_dist_y + ! of lat/lon. + ! + ! The tiles identified in this way are still subject to the bounding box and + ! max_dist checks of get_tile_num_from_latlon(), which they pass by construction. + ! + ! If there are no land tiles in these grid cells, tile_num will not change + ! from its initialized value. + ! + ! The grid cells are obtained from MAPL_GetGlobalHorzIJIndex() (see + ! get_ij_ind_from_latlon_c3()), which has a fixed cost per call. lat/lon are + ! therefore processed in chunks, with one call for 1.) and one call per batch of at + ! most N_pts_max points for 2.). The fixed cost grows with the grid resolution (~4x + ! per doubling; ~0.1 s per call for C2880), whereas the cost per point is small + ! (~0.05 us), hence the large chunks and batches. + ! + ! amfox, 9 Nov 2026 + + implicit none + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF + + type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + + type(grid_def_type), intent(in) :: tile_grid_g + + integer, dimension(tile_grid_g%N_lon,tile_grid_g%N_lat), intent(in) :: N_tile_in_cell_ij + + integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + integer, intent(in) :: N_latlon + + real, dimension(N_latlon), intent(in) :: lat, lon + + real, dimension(N_latlon), intent(in) :: max_dist_x ! vector [deg] + real, intent(in) :: max_dist_y ! scalar [deg] + + integer, dimension(N_latlon), intent(out) :: tile_num + + ! local variables + + integer, parameter :: N_chunk = 100000 ! max number of lat/lon per chunk + + integer, parameter :: N_lattice_max = 20 ! max lattice intervals on either side + ! of lat/lon (Step 2.) + + integer, parameter :: N_cell_max = 9 + (2*N_lattice_max+1)**2 + + integer, parameter :: N_pts_max = 1000000 ! max number of points per batch (Step 2.) + + integer :: n, nn, k, kk, ii, jj, mm, this_tile_num + integer :: ind_start, ind_end, N_tmp, N_nbr, N_cell + integer :: nn_start, nn_end, N_x, N_y + + logical :: outside_bbox, too_far_away + + real :: tmp_dist, min_dist + real :: tmp_dist_x, tmp_dist_y, tmp_dlon, tmp_dlat, tmp_slon, tmp_slat + + integer, dimension(N_cell_max) :: i_cell_c3, j_cell_c3 + + integer, dimension(:), allocatable :: i_ind, j_ind, ind_nbr, N_pts_nbr, i_ind_nbr, j_ind_nbr + + real, dimension(:), allocatable :: min_dist_x, min_dist_y, tmp_lat, tmp_lon + + ! ----------------------------------------------------------- + + tile_num = nodata_tilenum ! initialize to negative value + + allocate( i_ind(N_chunk), j_ind(N_chunk), ind_nbr(N_chunk), N_pts_nbr(N_chunk) ) + allocate( min_dist_x(N_chunk), min_dist_y(N_chunk) ) + allocate( i_ind_nbr(N_pts_max), j_ind_nbr(N_pts_max), tmp_lat(N_pts_max), tmp_lon(N_pts_max) ) + + ! loop through chunks of observations + + do ind_start=1,N_latlon,N_chunk + + ind_end = min( ind_start+N_chunk-1, N_latlon ) + + N_tmp = ind_end - ind_start + 1 + + min_dist_x = 1.e10 ! initialize + min_dist_y = 1.e10 ! initialize + + ! determine grid cells that contain lat/lon + + call get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid_g, N_tmp, & + lat(ind_start:ind_end), lon(ind_start:ind_end), i_ind(1:N_tmp), j_ind(1:N_tmp) ) + + ! Step 1.): tiles within grid cell that contains lat/lon points + + N_nbr = 0 + + do nn=1,N_tmp + + n = ind_start - 1 + nn + + ! Make sure lat/lon is *inside* tile_grid, otherwise do nothing + ! (see get_tile_num_from_latlon()) + + if ( tile_grid_g%ll_lat < (lat(n) ) .and. & + tile_grid_g%ll_lon < (lon(n) ) .and. & + (lat(n) ) < tile_grid_g%ur_lat .and. & + (lon(n) ) < tile_grid_g%ur_lon ) then + + min_dist = 1.e10 ! initialize + + call get_tile_num_in_bbox_c3( lat(n), lon(n), 1, i_ind(nn:nn), j_ind(nn:nn), & + tile_coord, tile_grid_g, N_tile_in_cell_ij, tile_num_in_cell_ij, & + tile_num(n), min_dist, min_dist_x(nn), min_dist_y(nn) ) + + if (tile_num(n)==nodata_tilenum) then + + ! no tile found: lat/lon needs Step 2.) + + N_nbr = N_nbr + 1 + ind_nbr(N_nbr) = nn + + end if + + end if + + end do + + ! Step 2.): add neighboring ("nbr") grid cells that contain points around lat/lon: + ! + ! (i) 8 points at +/- half a grid cell (approx.) around lat/lon + ! (tile_grid_g%dlon = 360/(4*N) is the approximate grid spacing, see LDAS_create_grid_g()) + ! + ! (ii) points of a lattice that covers lat/lon +/- max_dist, with a spacing of at most + ! a quarter grid cell (approx.); the number of lattice intervals on either side of + ! lat/lon is limited to N_lattice_max (only for very large max_dist or near the poles) + ! + ! points are processed in batches of at most N_pts_max points (one MAPL call per batch) + + nn_start = 1 + + do while (nn_start<=N_nbr) + + ! points for lat/lon ind_nbr(nn_start:nn_end) + + kk = 0 + nn_end = nn_start - 1 + + do nn=nn_start,N_nbr + + n = ind_start - 1 + ind_nbr(nn) + + tmp_dlat = 0.5 *tile_grid_g%dlon + tmp_dlon = tmp_dlat / max( cos( MAPL_PI/180. * lat(n) ), 0.1 ) + + tmp_slat = 0.25*tile_grid_g%dlon + tmp_slon = tmp_slat / max( cos( MAPL_PI/180. * lat(n) ), 0.1 ) + + N_y = ceiling( min( max_dist_y /tmp_slat, real(N_lattice_max) ) ) + N_x = ceiling( min( max_dist_x(n)/tmp_slon, real(N_lattice_max) ) ) + + N_pts_nbr(nn) = 8 + (2*N_x+1)*(2*N_y+1) + + if (kk+N_pts_nbr(nn) > N_pts_max) exit ! batch is full + + ! (i) 8 points at +/- half a grid cell + + do ii=-1,1 + do jj=-1,1 + + if (ii==0 .and. jj==0) cycle + + kk = kk + 1 + + tmp_lat(kk) = lat(n) + real(jj)*tmp_dlat + tmp_lon(kk) = lon(n) + real(ii)*tmp_dlon + + end do + end do + + ! (ii) lattice over lat/lon +/- max_dist (just lat/lon if max_dist=0) + + do ii=-N_x,N_x + do jj=-N_y,N_y + + kk = kk + 1 + + tmp_lat(kk) = lat(n) + tmp_lon(kk) = lon(n) + + if (N_y>0) tmp_lat(kk) = lat(n) + real(jj)*(max_dist_y /real(N_y)) + if (N_x>0) tmp_lon(kk) = lon(n) + real(ii)*(max_dist_x(n)/real(N_x)) + + end do + end do + + nn_end = nn + + end do + + call get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid_g, kk, & + tmp_lat(1:kk), tmp_lon(1:kk), i_ind_nbr(1:kk), j_ind_nbr(1:kk) ) + + kk = 0 + + do nn=nn_start,nn_end + + n = ind_start - 1 + ind_nbr(nn) + + ! list of unique grid cells, starting with the grid cell that contains lat/lon + + N_cell = 1 + + i_cell_c3(1) = i_ind(ind_nbr(nn)) + j_cell_c3(1) = j_ind(ind_nbr(nn)) + + do k=1,N_pts_nbr(nn) + + kk = kk + 1 + + if (any( i_cell_c3(1:N_cell)==i_ind_nbr(kk) .and. & + j_cell_c3(1:N_cell)==j_ind_nbr(kk) )) cycle ! already in list + + N_cell = N_cell + 1 + + i_cell_c3(N_cell) = i_ind_nbr(kk) + j_cell_c3(N_cell) = j_ind_nbr(kk) + + end do + + ! Step 2.): tiles within additional grid cells (grid cell 1 was searched in Step 1.) + + min_dist = 1.e10 ! initialize + + if (N_cell>1) & + call get_tile_num_in_bbox_c3( lat(n), lon(n), N_cell-1, & + i_cell_c3(2:N_cell), j_cell_c3(2:N_cell), & + tile_coord, tile_grid_g, N_tile_in_cell_ij, tile_num_in_cell_ij, & + tile_num(n), min_dist, min_dist_x(ind_nbr(nn)), min_dist_y(ind_nbr(nn)) ) + + ! Step 3.): no bounding box contains lat/lon: find closest tile among those + ! in all grid cells identified above that are within max_dist + + if (tile_num(n)==nodata_tilenum) then + + do mm=1,N_cell + + do k=1,N_tile_in_cell_ij(i_cell_c3(mm),j_cell_c3(mm)) + + this_tile_num = tile_num_in_cell_ij(i_cell_c3(mm),j_cell_c3(mm),k) + + tmp_dist_x = abs(lon(n) - tile_coord(this_tile_num)%com_lon) + tmp_dist_y = abs(lat(n) - tile_coord(this_tile_num)%com_lat) + + ! skip tile that is too far away (see bounding box and max_dist check below) + + if (tmp_dist_x > max_dist_x(n) .or. tmp_dist_y > max_dist_y) cycle + + tmp_dist = tmp_dist_x + tmp_dist_y ! "closest": Minkowski norm + + if (tmp_dist0) then + + outside_bbox = ( & + lon(n) < tile_coord(tile_num(n))%min_lon .or. & + lon(n) > tile_coord(tile_num(n))%max_lon .or. & + lat(n) < tile_coord(tile_num(n))%min_lat .or. & + lat(n) > tile_coord(tile_num(n))%max_lat ) + + too_far_away = ( & + min_dist_x(nn) > max_dist_x(n) .or. & + min_dist_y(nn) > max_dist_y ) + + ! keep tile_num unless obs is outside the bounding box *and* too far away + + if (outside_bbox .and. too_far_away) tile_num(n) = nodata_tilenum + + end if + + end do + + end do + + deallocate( i_ind, j_ind, ind_nbr, N_pts_nbr, min_dist_x, min_dist_y ) + deallocate( i_ind_nbr, j_ind_nbr, tmp_lat, tmp_lon ) + + end subroutine get_tile_num_from_latlon_c3 + + ! ******************************************************************* + + subroutine get_tile_num_in_bbox_c3( lat, lon, N_cell, i_cell, j_cell, & + tile_coord, tile_grid_g, N_tile_in_cell_ij, tile_num_in_cell_ij, & + tile_num, min_dist, min_dist_x, min_dist_y ) + + ! among the tiles within the given N_cell grid cells of the cube-sphere tile_grid_g, find the + ! tile whose bounding box contains lat/lon and that has the minimum normalized square + ! distance (dx/hx)**2 + (dy/hy)**2 (< min_dist), where hx and hy are half the width + ! and height of the bounding box; see get_tile_num_from_latlon_c3() + ! + ! tile_num, min_dist, min_dist_x, and min_dist_y change only if such a tile is found + ! + ! amfox, 9 Nov 2026 + + implicit none + + real, intent(in) :: lat, lon + + integer, intent(in) :: N_cell + + integer, dimension(N_cell), intent(in) :: i_cell, j_cell + + type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + + type(grid_def_type), intent(in) :: tile_grid_g + + integer, dimension(tile_grid_g%N_lon,tile_grid_g%N_lat), intent(in) :: N_tile_in_cell_ij + + integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + integer, intent(inout) :: tile_num + + real, intent(inout) :: min_dist, min_dist_x, min_dist_y + + ! local variables + + integer :: k, kk, this_tile_num + + real :: tmp_dist, tmp_dist_x, tmp_dist_y, tmp_hx, tmp_hy + + ! ----------------------------------------------------------- + + do kk=1,N_cell + + do k=1,N_tile_in_cell_ij(i_cell(kk),j_cell(kk)) + + this_tile_num = tile_num_in_cell_ij(i_cell(kk),j_cell(kk),k) + + if ( tile_coord(this_tile_num)%min_lon <= lon .and. & + tile_coord(this_tile_num)%max_lon >= lon .and. & + tile_coord(this_tile_num)%min_lat <= lat .and. & + tile_coord(this_tile_num)%max_lat >= lat ) then + + ! lat/lon is inside bounding box of tile + + tmp_hx = 0.5*(tile_coord(this_tile_num)%max_lon - tile_coord(this_tile_num)%min_lon) + tmp_hy = 0.5*(tile_coord(this_tile_num)%max_lat - tile_coord(this_tile_num)%min_lat) + + tmp_hx = max( tmp_hx, 1.e-6 ) ! avoid division by zero + tmp_hy = max( tmp_hy, 1.e-6 ) + + tmp_dist_x = abs(lon - tile_coord(this_tile_num)%com_lon) + tmp_dist_y = abs(lat - tile_coord(this_tile_num)%com_lat) + + tmp_dist = (tmp_dist_x/tmp_hx)**2 + (tmp_dist_y/tmp_hy)**2 + + if (tmp_dist use "ceiling") - if (tile_grid%i_dir==1) then + if (my_grid%i_dir==1) then - i_ind = ceiling( (lon - tile_grid%ll_lon)/tile_grid%dlon ) + i_ind = ceiling( (lon - my_grid%ll_lon)/my_grid%dlon ) else - i_ind = ceiling( (tile_grid%ur_lon - lon)/tile_grid%dlon ) + i_ind = ceiling( (my_grid%ur_lon - lon)/my_grid%dlon ) end if - if (tile_grid%j_dir==1) then + if (my_grid%j_dir==1) then - j_ind = ceiling( (lat - tile_grid%ll_lat)/tile_grid%dlat ) + j_ind = ceiling( (lat - my_grid%ll_lat)/my_grid%dlat ) else - j_ind = ceiling( (tile_grid%ur_lat - lat)/tile_grid%dlat ) + j_ind = ceiling( (my_grid%ur_lat - lat)/my_grid%dlat ) end if + elseif (index(my_grid%gridtype, 'c3')/=0) then + + ! cube-sphere grid requires the ESMF grid (amfox, 9 Nov 2026) + + call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'cube-sphere grid: use get_ij_ind_from_latlon_c3()') + else call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown grid type') @@ -1050,8 +1525,205 @@ end subroutine get_ij_ind_from_latlon ! ******************************************************************* + subroutine get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid_g, N_latlon, lat, lon, i_ind, j_ind ) + + ! find i/j_ind of cube-sphere ("c3") grid cells that contain lat/lon points + ! + ! as get_ij_ind_from_latlon(), but for a vector of lat/lon and cube-sphere tile_grid; + ! returns i/j_ind into an array of size N_lon-by-N_lat defined by tile_grid, + ! limited to 1,...,N_lon and 1,...,N_lat + ! + ! MAPL_GetGlobalHorzIJIndex() needs the ESMF grid and returns *global*, *1-based* + ! indices i=1,...,N and j=1,...,6*N (6 faces stacked in j), as in tile_coord%i_indg + ! and tile_coord%j_indg. It fails for grids that it cannot handle. (It also handles + ! stretched grids, but init_tile_grid_g_ESMF_c3() rejects them, see there.) + ! + ! NOTE: Each call of MAPL_GetGlobalHorzIJIndex() checks the grid, and the MAPL subroutine + ! allocates ~100 bytes per lat/lon --> call with many, but not too many, lat/lon. + ! + ! NOTE: Before this subroutine is called by root_proc only (e.g., in obs readers), + ! init_tile_grid_g_ESMF_c3() must have been called by all processors. + ! + ! amfox, 9 Nov 2026 + + implicit none + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF + + type(grid_def_type), intent(in) :: tile_grid_g + + integer, intent(in) :: N_latlon + + real, dimension(N_latlon), intent(in) :: lat, lon ! [deg] + + integer, dimension(N_latlon), intent(out) :: i_ind, j_ind + + ! local variables + + type(ESMF_Grid) :: tmp_grid + + real*8, dimension(:), allocatable :: tmp_lat, tmp_lon + + integer :: status + + character(len=*), parameter :: Iam = 'get_ij_ind_from_latlon_c3' + character(len=400) :: err_msg + + ! ------------------------------------------------------------- + + if (N_latlon<1) return + + ! convert lat/lon from [deg] to [rad] + + allocate( tmp_lat(N_latlon), tmp_lon(N_latlon) ) + + tmp_lat = real(lat,8)*(MAPL_PI_R8/180.d0) + tmp_lon = real(lon,8)*(MAPL_PI_R8/180.d0) + + ! MAPL_GetGlobalHorzIJIndex() needs intent(inout) for the grid (to store the grid corners + ! as attributes, see init_tile_grid_g_ESMF_c3()) --> pass a copy of the ESMF grid handle (same grid) + + tmp_grid = tile_grid_g_ESMF + + call MAPL_GetGlobalHorzIJIndex( N_latlon, i_ind, j_ind, lonR8=tmp_lon, latR8=tmp_lat, & + Grid=tmp_grid, rc=status ) + + if (status/=0) then + + err_msg = 'MAPL_GetGlobalHorzIJIndex() failed' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! convert to index into array defined by tile_grid_g + + i_ind = i_ind - tile_grid_g%i_offg - (tile_grid_g%ind_base - 1) + j_ind = j_ind - tile_grid_g%j_offg - (tile_grid_g%ind_base - 1) + + ! make sure that i/j_ind is within bounds + + i_ind = min( max(i_ind, 1), tile_grid_g%N_lon ) + j_ind = min( max(j_ind, 1), tile_grid_g%N_lat ) + + deallocate( tmp_lat, tmp_lon ) + + end subroutine get_ij_ind_from_latlon_c3 + + ! ******************************************************************* + + subroutine init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid_g ) + + ! prepare cube-sphere ("c3") ESMF grid for get_ij_ind_from_latlon_c3() and check that + ! the grid matches the (global, cube-sphere) tile grid (tile_grid_g) + ! + ! MUST be called by ALL processors (once), before get_ij_ind_from_latlon_c3() is + ! called by root_proc only (e.g., in obs readers): + ! + ! MAPL_GetGlobalHorzIJIndex() checks the grid with MAPL_GridGetCorners(). The first + ! call of MAPL_GridGetCorners() for a given grid needs all processors (halo exchange) + ! and stores the grid corners as attributes of the grid. Later calls use these + ! attributes and are local. Here, MAPL_GetGlobalHorzIJIndex() is called for zero + ! lat/lon, which only checks the grid. + ! + ! Stretched cube-sphere grids are not supported: MAPL_GetGlobalHorzIJIndex() handles + ! them, but the search for nearby grid cells in get_tile_num_from_latlon_c3() uses the + ! grid spacing of an unstretched grid (tile_grid%dlon) and misses many tiles where the + ! stretched grid is finer. MAPL marks a stretched grid with the attributes + ! STRETCH_FACTOR, TARGET_LON and TARGET_LAT (see MAPL_Reverse_Schmidt()). + ! + ! amfox, 9 Nov 2026 + + implicit none + + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF + + type(grid_def_type), intent(in) :: tile_grid_g + + ! local variables + + type(ESMF_Grid) :: tmp_grid + + real*8, dimension(0) :: tmp_lat, tmp_lon + + integer, dimension(0) :: tmp_i_ind, tmp_j_ind + + integer, dimension(3) :: dims + + integer :: status + + logical :: has_factor, has_lon, has_lat + + character(len=*), parameter :: Iam = 'init_tile_grid_g_ESMF_c3' + character(len=400) :: err_msg + + ! ------------------------------------------------------------- + + tmp_grid = tile_grid_g_ESMF ! copy of ESMF grid handle (same grid), see get_ij_ind_from_latlon_c3() + + ! check grid size (N-by-6*N for cube-sphere grid) + + dims = 0 + + call MAPL_GridGet( tmp_grid, globalCellCountPerDim=dims, rc=status ) + + if (status/=0) then + + err_msg = 'MAPL_GridGet() failed' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + if ( (dims(1)/=tile_grid_g%N_lon) .or. (dims(2)/=tile_grid_g%N_lat) ) then + + write (err_msg,'(A,2i8,A,2i8)') 'size of ESMF grid ', dims(1:2), & + ' does not match size of cube-sphere tile_grid ', tile_grid_g%N_lon, tile_grid_g%N_lat + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! reject stretched grid (see above) + + call ESMF_AttributeGet( tmp_grid, name='STRETCH_FACTOR', isPresent=has_factor, rc=status ) + if (status==0) & + call ESMF_AttributeGet( tmp_grid, name='TARGET_LON', isPresent=has_lon, rc=status ) + if (status==0) & + call ESMF_AttributeGet( tmp_grid, name='TARGET_LAT', isPresent=has_lat, rc=status ) + + if (status/=0) then + + err_msg = 'ESMF_AttributeGet() failed' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + if (has_factor .and. has_lon .and. has_lat) then + + err_msg = 'stretched cube-sphere grid not supported for mapping obs to tiles (obs assimilation)' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! check grid and store grid corners as grid attributes (on all processors) + + call MAPL_GetGlobalHorzIJIndex( 0, tmp_i_ind, tmp_j_ind, lonR8=tmp_lon, latR8=tmp_lat, & + Grid=tmp_grid, rc=status ) + + if (status/=0) then + + err_msg = 'MAPL_GetGlobalHorzIJIndex() failed; cube-sphere grid not supported' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + if (logit) write (logunit,*) trim(Iam), ': cube-sphere tile_grid_g_ESMF is ready for obs-to-tile mapping, size = ', dims(1:2) + if (logit) write (logunit,*) + + end subroutine init_tile_grid_g_ESMF_c3 + + ! ******************************************************************* + subroutine get_tile_num_in_ellipse( lon, lat, r_x, r_y, & - N_tile, tile_coord, tile_grid, & + N_tile, tile_coord, my_grid, & N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tile_in_ellipse, tile_num_in_ellipse, norm_square_distance ) @@ -1061,7 +1733,11 @@ subroutine get_tile_num_in_ellipse( lon, lat, r_x, r_y, & ! and axes r_x, r_y ! ! also return normalized square distance of tile center-of-mass lat/lon from lat/lon - + ! + ! "my_grid" could be the grid associated with tile space definition or the hash grid used for + ! efficient obs2tile or tiles2obsFOV mapping in the EnKF analysis (i.e., pert_grid). + ! "N_tile_in_cell_ij" and "tile_num_in_cell_ij" must be consistent with "my_grid". + ! TO DO: what about dateline? poles? [ignore for now] ! NOTE: get_tile_num_in_ellipse() returns zero tiles (N_tile_in_ellipse=0) @@ -1077,9 +1753,9 @@ subroutine get_tile_num_in_ellipse( lon, lat, r_x, r_y, & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: my_grid - integer, dimension(tile_grid%N_lon,tile_grid%N_lat), intent(in) :: & + integer, dimension(my_grid%N_lon,my_grid%N_lat), intent(in) :: & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input @@ -1113,8 +1789,8 @@ subroutine get_tile_num_in_ellipse( lon, lat, r_x, r_y, & ! identify rectangle +/- r_x and +/- r_y around lat/lon - tmp_dx = tile_grid%dlon ! broaden rectangle to avoid missing tiles - tmp_dy = tile_grid%dlon ! use *dlon* because for EASE grid *dlat* is ill-defined + tmp_dx = my_grid%dlon ! broaden rectangle to avoid missing tiles + tmp_dy = my_grid%dlon ! use *dlon* because for EASE grid *dlat* is ill-defined minlon = lon - r_x - tmp_dx maxlon = lon + r_x + tmp_dx @@ -1123,15 +1799,15 @@ subroutine get_tile_num_in_ellipse( lon, lat, r_x, r_y, & ! find i,j indices of two opposite corners (lower left and upper right) - call get_ij_ind_from_latlon( tile_grid, minlat, minlon, i_ind_ll, j_ind_ll ) - call get_ij_ind_from_latlon( tile_grid, maxlat, maxlon, i_ind_ur, j_ind_ur ) + call get_ij_ind_from_latlon( my_grid, minlat, minlon, i_ind_ll, j_ind_ll ) + call get_ij_ind_from_latlon( my_grid, maxlat, maxlon, i_ind_ur, j_ind_ur ) - ! restrict i_ind_* and j_ind_* to fall within tile_grid + ! restrict i_ind_* and j_ind_* to fall within my_grid - i_ind_ll = min( tile_grid%N_lon, max( 1, i_ind_ll )) - j_ind_ll = min( tile_grid%N_lat, max( 1, j_ind_ll )) - i_ind_ur = min( tile_grid%N_lon, max( 1, i_ind_ur )) - j_ind_ur = min( tile_grid%N_lat, max( 1, j_ind_ur )) + i_ind_ll = min( my_grid%N_lon, max( 1, i_ind_ll )) + j_ind_ll = min( my_grid%N_lat, max( 1, j_ind_ll )) + i_ind_ur = min( my_grid%N_lon, max( 1, i_ind_ur )) + j_ind_ur = min( my_grid%N_lat, max( 1, j_ind_ur )) ! find smaller and larger of the two indices ! (index may run north-to-south/west-to-east depending on i_dir/j_dir) @@ -1202,10 +1878,12 @@ subroutine tile2grid_simple( N_tile, i_indgs, j_indgs, tile_grid, tile_data, gri ! local variables - integer :: n, i, j, off_i, off_j - real, parameter :: no_data= -9999. + integer :: n, i, j, off_i, off_j + + !real, parameter :: no_data= -9999. ! replaced with nodata_generic, reichle, 13 Nov 2026 + character(len=*), parameter :: Iam = 'tile2grid_simple' - character(len=400) :: err_msg + character(len=400) :: err_msg ! ------------------------------------ @@ -1221,7 +1899,8 @@ subroutine tile2grid_simple( N_tile, i_indgs, j_indgs, tile_grid, tile_data, gri ! loop through tile space - grid_data = no_data + grid_data = nodata_generic + do n=1,N_tile i = i_indgs(n) - off_i j = j_indgs(n) - off_j @@ -1391,7 +2070,9 @@ subroutine tile_mask_grid( tile_grid, N_tile, i_indgs,j_indgs, grid_data) real, dimension(tile_grid%N_lon,tile_grid%N_lat) :: grid ! local variables - real, parameter :: no_data= -9999. + + !real, parameter :: no_data= -9999. ! replaced with nodata_generic, reichle, 13 Nov 2026 + integer :: n, i, j, off_i, off_j character(len=*), parameter :: Iam = 'tile_mask_grid' @@ -1404,7 +2085,8 @@ subroutine tile_mask_grid( tile_grid, N_tile, i_indgs,j_indgs, grid_data) off_i = tile_grid%i_offg + (tile_grid%ind_base - 1) off_j = tile_grid%j_offg + (tile_grid%ind_base - 1) - grid = no_data + grid = nodata_generic + do n=1,N_tile i = i_indgs(n) - off_i j = j_indgs(n) - off_j diff --git a/LDAS_Shared/LDAS_TileCoordType.F90 b/LDAS_Shared/LDAS_TileCoordType.F90 index f89aa5e7..774eeae9 100644 --- a/LDAS_Shared/LDAS_TileCoordType.F90 +++ b/LDAS_Shared/LDAS_TileCoordType.F90 @@ -62,8 +62,8 @@ module LDAS_TileCoordType ! For cubed-sphere tile spaces, pert_[x]_indg refers to a lat-lon perturbation grid that will ! be created at runtime to support efficient mapping for perturbations and the EnKF analysis. ! For EASE and LatLon tile spaces, pert_[x]_indg is identical to [x]_indg - integer :: pert_i_indg ! i index (w.r.t. *global* pert_grid for perts and EnKF) - integer :: pert_j_indg ! j index (w.r.t. *global* pert_grid for perts and EnKF) + integer :: pert_i_indg ! i index (w.r.t. *global* pert_grid for perts and obs2tile + tiles2obsFOV mapping in EnKF) + integer :: pert_j_indg ! j index (w.r.t. *global* pert_grid for perts and obs2tile + tiles2obsFOV mapping in EnKF) real :: frac_cell ! area fraction of grid cell covered by tile real :: frac_pfaf ! fraction of Pfafstetter catchment for land tiles real :: area ! area [km^2] @@ -386,9 +386,10 @@ subroutine io_tile_coord_type( action, unitnum, N_tile, tile_coord ) integer :: n, istat, N_tile_tmp character(len=*), parameter :: Iam = 'io_tile_coord_type' - character(len=400) :: err_msg - integer, allocatable :: tmp_int(:) - real , allocatable :: tmp_real(:) + character(len=400) :: err_msg + + integer, allocatable :: tmp_int(:) + real , allocatable :: tmp_real(:) ! ------------------------------------------------------------- diff --git a/LDAS_Shared/LDAS_ensdrv_mpi.F90 b/LDAS_Shared/LDAS_ensdrv_mpi.F90 index 6b36a77a..74508bf3 100644 --- a/LDAS_Shared/LDAS_ensdrv_mpi.F90 +++ b/LDAS_Shared/LDAS_ensdrv_mpi.F90 @@ -141,8 +141,8 @@ subroutine init_MPI_types() ! ! For cubed-sphere tile spaces, pert_[x]_indg refers to a lat-lon perturbation grid that will ! ! be created at runtime to support efficient mapping for perturbations and the EnKF analysis. ! ! For EASE and LatLon tile spaces, pert_[x]_indg is identical to [x]_indg - ! integer :: pert_i_indg ! i index (w.r.t. *global* pert_grid for perts and EnKF) - ! integer :: pert_j_indg ! j index (w.r.t. *global* pert_grid for perts and EnKF) + ! integer :: pert_i_indg ! i index (w.r.t. *global* pert_grid for perts and obs2tile + tiles2obsFOV mapping in EnKF) + ! integer :: pert_j_indg ! j index (w.r.t. *global* pert_grid for perts and obs2tile + tiles2obsFOV mapping in EnKF) ! real :: frac_cell ! area fraction of grid cell covered by tile ! real :: frac_pfaf ! fraction of Pfafstetter catchment for land tiles ! real :: area ! area [km^2]