From 9fd6b6be7c9a034c9799972d48dc60df57685f2b Mon Sep 17 00:00:00 2001 From: "Lauren C. Andrews" Date: Mon, 26 Oct 2026 15:47:14 -0400 Subject: [PATCH 01/90] partially finished reader --- .../clsm_ensupd_glob_param.F90 | 2 +- .../clsm_ensupd_read_obs.F90 | 920 +++++++++++++++++- GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml | 129 +++ 3 files changed, 1019 insertions(+), 32 deletions(-) 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 37e03ba9..00246fd4 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6787,6 +6787,482 @@ end subroutine read_obs_MODIS_SCF ! ******************************************************************************************************* + subroutine read_obs_JPSS_SCF( & + date_time, dtstep_assim, N_catd, tile_coord, & + tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + this_obs_param, & + found_obs, JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat ) + + ! read JPSS snow cover observations on the 0.05-degree climate + ! modeling grid (CMG) + ! + ! JPSS1/NOAA-20: VJ110C1 (launched 2022) + ! JPSS2/NOAA-21: VJ210C1 (launched 2017) + ! S-NPP : VNP10C1 (launched 2011, decomissioned 2026) + ! + ! + ! For now, assume that VIIRS/JPSS 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 + ! + ! lcandre2, 26 Oct 2026 + ! + ! ------------------------------------------------------------------------------ + + implicit none + + ! inputs + + type(date_time_type), intent(in) :: date_time + + integer, intent(in) :: dtstep_assim ! [seconds] + integer, intent(in) :: N_catd + + type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + + type(grid_def_type), intent(in) :: tile_grid_d + + integer, dimension(tile_grid_d%N_lon,tile_grid_d%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 + + ! output + + logical, intent(out) :: found_obs + + real, dimension(N_catd), intent(out) :: JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat + + ! ------------------------------------------------------------------------ + + ! locals + + integer, parameter :: dtstep_assim_max = 21600 ! [seconds] avoid assim window spanning >=180 deg lon + + real, parameter :: CMG_dlon = 0.05 ! [degrees] longitude spacing of JPSS CMG grid + real, parameter :: CMG_dlat = 0.05 ! [degrees] latitude spacing of JPSS CMG grid + + real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of JPSS CMG grid + real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of JPSS CMG grid + + character(7) :: JPSS_product_ID + + character(4) :: YYYY + character(3) :: DDD ! day of year + + character(400) :: fname + + real :: overpass_hour, tmp_delta, tmp_real, max_delta_lon + + integer :: N_files, N_lon, N_lat, N_tmp, nn, kk, ind + 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_JPSS, date_time_end_JPSS + type(date_time_type) :: date_time_obs_beg + + real :: lon_beg, lon_end + real :: lon_beg_JPSS, lon_end_JPSS + + integer :: delta_day_beg, delta_day_end + integer :: delta_day_beg_JPSS, delta_day_end_JPSS + + real :: lat_min, lat_max + + real, dimension(2) :: lon_min_vec, lon_max_vec + + integer, dimension(2) :: N_lon_vec, year_vec, dofyr_vec, start_ind, last_ind + + real, dimension(:), allocatable :: CMG_obs, CMG_lon, CMG_lat + + integer, dimension(:), allocatable :: tmp_tile_num + + integer, dimension(N_catd) :: N_obs_in_tile + + character(len=*), parameter :: Iam = 'read_obs_JPSS_SCF' + character(len=400) :: err_msg + + ! ------------------------------------------------------------------------------------ + ! + ! initialize + + found_obs = .false. + + ! determine operating time range of sensor + + if (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) + else + err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + end if + + ! return if date_time falls outside operating time range + + if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return + + ! ---------------------------------------------------------------------------------- + ! + ! restrict assimilation time step to max allowed + + if (dtstep_assim > dtstep_assim_max) then + + err_msg = 'dtstep_assim exceeds max allowed' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! identify JPSS product and overpass hour https://vlab.noaa.gov/web/towr-s/satellite-operations-updates + + MODIS_product_ID = this_obs_param%name(1:7) + + select case (MODIS_product_ID) + + case('VJ110C1'); overpass_hour = 13.5 ! [hours] JPSS1: 13:30 local time + + case('VJ210C1'); overpass_hour = 13.5 ! [hours] JPSS2: 13:30 local time + + case('VNP10C1'); overpass_hour = 13.5 ! [hours] S-NPP: 13:30 local time + + end select + + + ! determine beginning and end of assimilation window + + date_time_beg = date_time + date_time_end = date_time + + call augment_date_time( -dtstep_assim/2, date_time_beg ) + call augment_date_time( dtstep_assim/2, date_time_end ) + + + ! 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 + + call localtime2longitude( date_time_beg, overpass_hour, lon_beg, delta_day_beg ) + call localtime2longitude( date_time_end, overpass_hour, lon_end, delta_day_end ) + + + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! lca: do we want to narrow this band just slightly to remove the striping that occurs in the assimilation currently??? !!!!!!!!!! + ! determine (rough) longitude band for which MODIS obs need to be read + ! + ! --> because tiles have a non-zero extent, need to read JPSS 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 ) + + tmp_delta = 3.*maxval( tile_coord(1:N_catd)%max_lon - tile_coord(1:N_catd)%min_lon ) ! [degrees] + + tmp_delta = tmp_delta/360.*86400. ! [seconds] + + date_time_beg_JPSS = date_time_beg + date_time_end_JPSS = date_time_end + + call augment_date_time( -nint(tmp_delta), date_time_beg_JPSS ) + call augment_date_time( nint(tmp_delta), date_time_end_JPSS ) + + call localtime2longitude( date_time_beg_JPSS, overpass_hour, lon_beg_JPSS, delta_day_beg_JPSS ) + call localtime2longitude( date_time_end_JPSS, overpass_hour, lon_end_JPSS, delta_day_end_JPSS ) + + ! adjust date_time_*_JPSS to reflect calendar date at lon_*_JPSS + + call augment_date_time( delta_day_beg_JPSS*86400, date_time_beg_JPSS ) + call augment_date_time( delta_day_end_JPSS*86400, date_time_end_JPSS ) + + ! put together arguments for call(s) to read_JPSS_SCF_hdf() + + lon_min_vec = MAPL_UNDEF + lon_max_vec = MAPL_UNDEF + + year_vec = -9999 + dofyr_vec = -9999 + + N_lon_vec = 0 + + if (lon_end_JPSS < lon_beg_JPSS) then + + if ( date_time_end_JPSS%dofyr == date_time_beg_JPSS%dofyr ) then + + ! need only one daily MODIS file and longitude band + + N_files = 1 + + lon_min_vec(1) = lon_end_JPSS + lon_max_vec(1) = lon_beg_JPSS + + year_vec( 1) = date_time_beg_JPSS%year + dofyr_vec( 1) = date_time_beg_JPSS%dofyr + + else + + ! this should never happen for dtstep_assim_max=21600 and overpass_hour of 13:30 + + write (logunit,*) 'overpass_hour = ', overpass_hour + 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_JPSS + write (logunit,*) 'date_time_end_MODIS = ', date_time_end_JPSS + write (logunit,*) 'lon_beg = ', lon_beg + write (logunit,*) 'lon_end = ', lon_end + write (logunit,*) 'lon_beg_MODIS = ', lon_beg_JPSS + write (logunit,*) 'lon_end_MODIS = ', lon_end_JPSS + + err_msg = 'encountered unexpected condition for longitude band!!!' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + 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 + ! empty first longitude band, but because of tmp_delta>0, this should + ! never happen) + + N_files = 2 + + lon_min_vec(1) = lon_end_JPSS + 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_JPSS%year + dofyr_vec( 1) = date_time_end_JPSS%dofyr + + lon_min_vec(2) = -180. + lon_max_vec(2) = lon_beg_JPSS + + year_vec( 2) = date_time_beg_JPSS%year + dofyr_vec( 2) = date_time_beg_JPSS%dofyr + + end if + + ! verify that longitude bands do not exceed max expected expected width + ! (add 0.1 degree of wiggle room) + !!!!!!!!!! is this wiggle room the problem with the additional striping????!!!!!! + max_delta_lon = real(dtstep_assim_max + 2*nint(tmp_delta))/86400.*360. + 0.1 ! [degree] + + do nn=1,N_files + + if ( lon_max_vec(nn) - lon_min_vec(nn) > max_delta_lon ) then + + err_msg = 'longitude band too wide' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + end do + + + ! 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 ) + + + ! determine N_lat and N_lon[_vec] (# CMG grid cells in lat/lon bands ) + + start_ind(1) = (CMG_ur_lat - lat_max )/CMG_dlat + last_ind(1) = (CMG_ur_lat - lat_min )/CMG_dlat + + N_lat = last_ind(1) - start_ind(1) + 1 + + start_ind(1:N_files) = (lon_min_vec(1:N_files) - CMG_ll_lon)/CMG_dlon + last_ind( 1:N_files) = (lon_max_vec(1:N_files) - CMG_ll_lon)/CMG_dlon + + N_lon_vec(1:N_files) = last_ind(1:N_files) - start_ind(1:N_files) + 1 + + 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) + + N_tmp = N_lon*N_lat + + allocate( CMG_obs(N_tmp) ) + allocate( CMG_lon(N_tmp) ) + 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 = 'VJ210C1.Ayyyyddd.002.' + ! full name = 'VJ210C1.AYYYYDDD.002.YYYYDDDhhmmss.h5 + ! + ! + ! MOD10C1 = JPSS product name + ! .A = "acquisition time" indicator + ! YYYYDDD = placeholder for year/day-of-year + ! .002 = version indicator + ! YYYYDDDhhmmss = production year, day and time + ! .h5 = file name extension + ! + + N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_MODIS_SCF_hdf() + + do nn=1,N_files ! loop through longitude bands + + ! determine MODIS 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:21)//'*'//'.h5' + + ! 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_JPSS_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) ) + + N_CMG_obs = N_CMG_obs + N_good_data + + end do + + + ! return if no JPSS obs were found (found_obs=.false. per initialization above) + + if (N_CMG_obs==0) return + + + ! map to tile space + + 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, & + N_CMG_obs, CMG_lat(1:N_CMG_obs), CMG_lon(1:N_CMG_obs), & + this_obs_param, & + tmp_tile_num ) + + + std_JPSS_obs = this_obs_param%errstd + + JPSS_obs = 0. + JPSS_lon = 0. + JPSS_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) + + if (ind>0) then ! this condition eliminates obs outside domain + + JPSS_obs( ind) = JPSS_obs( ind) + CMG_obs(kk) + JPSS_lon( ind) = JPSS_lon( ind) + CMG_lon(kk) + JPSS_lat( ind) = JPSS_lat( ind) + CMG_lat(kk) + + N_obs_in_tile(ind) = N_obs_in_tile(ind) + 1 + + end if + + end do + + ! normalize + + do kk=1,N_catd + if (N_obs_in_tile(kk)>0) then + + tmp_real = real(N_obs_in_tile(kk)) + + JPSS_obs(kk) = JPSS_obs(kk)/tmp_real + JPSS_lon(kk) = JPSS_lon(kk)/tmp_real + JPSS_lat(kk) = JPSS_lat(kk)/tmp_real + + else if (N_obs_in_tile(kk)==0) then + + JPSS_obs(kk) = this_obs_param%nodata + JPSS_lon(kk) = this_obs_param%nodata + JPSS_lat(kk) = this_obs_param%nodata + + end if + end do + + if (any(N_obs_in_tile>0)) then + + found_obs = .true. + + else + + found_obs = .false. + + end if + + deallocate(tmp_tile_num) + + deallocate(CMG_obs) + deallocate(CMG_lon) + deallocate(CMG_lat) + + ! to avoid double-counting of JPSS CMG obs, remove obs for tiles with center-of-mass longitude + ! falling outside the longitude band associated with assimilation window + + if (lon_end < lon_beg) then + + ! need only one longitude band (keep obs when lon_end<=com_lon<=lon_beg) + + do kk=1,N_catd + + if ( (tile_coord(kk)%com_lonlon_beg) ) & + JPSS_obs(kk) = this_obs_param%nodata + + end do + + else + + ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_end<=com_lon<=180) + + do kk=1,N_catd + + if ( (tile_coord(kk)%com_lon>lon_beg) .and. (tile_coord(kk)%com_lon= 24.) ) then + + err_msg = 'input local_hour falls outside allowed range of 0:24' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! initialize + + delta_day = 0 + + ! determine fractional UTC hour and time difference with local_hour + + UTC_hour = ( date_time%hour*3600 + date_time%min*60 + date_time%sec )/3600. ! 0 <= UTC_hour < 24 + + time_diff = local_hour - UTC_hour + + ! enforce -12. < time_diff <= 12. and determine associated date difference, if any + + if (time_diff <= -12.) then + + delta_day = 1 + + time_diff = time_diff + 24. + + elseif (time_diff > 12.) then + + delta_day = -1 + + time_diff = time_diff - 24. + + end if + + ! determine longitude + + longitude = time_diff/24.*360. + + end subroutine localtime2longitude + + ! ***************************************************************** + + subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & + N_good_data, CMG_lon, CMG_lat, CMG_SCF ) + + ! read snow cover area fraction (SCF) obs from daily MODIS Terra or Aqua M?D10C1, version 6.1 + ! - Terra: https://nsidc.org/data/mod10c1/versions/61 + ! - Aqua: https://nsidc.org/data/myd10c1/versions/61 + ! - daily data with spatial resolution of 0.05 deg on MODIS climate modeling grid (CMG) + ! - Terra: missing days 2016 d. 50-58 + ! - data are read for the requested lat/lon range + ! - apply QC + ! + ! reichle, 20 Oct 2023 + ! + ! ------------------------------------------------------------------------------------------------- + + implicit none + + character(*), intent(in) :: fname ! MODIS 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 + + ! ------------------------------------------------- + + ! local parameters + + ! ll/ur_lon/lat simply indicate the extent of the MODIS 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(22), dimension(N_fields), parameter :: field_names = (/ & + 'Day_CMG_Snow_Cover ', & ! 1 + 'Day_CMG_Clear_Index ', & ! 2 + 'Snow_Spatial_QA '/) ! 3 + + ! 1234567890123456789012 + ! 1 2 + + integer, parameter :: SCF_nodata = -9999. + + integer(int16), parameter :: qc_snow_cover_max = 100 ! exclude lake ice, night, inland water, ocean, etc + integer(int16), parameter :: qc_clear_index_min = 20 ! ensure sufficiently clear conditions + integer(int16), parameter :: qc_snow_spatial_max = 2 ! data quality (0=best, 1=good, 2=OK, 3=poor, 4=other) + + integer, parameter :: DFACC_READ = 1 ! from hdf.inc + + 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, edge, stride, last, dimsizes + + logical :: file_exists, keep_data + + integer :: status, sd_id, sds_id, sds_index + + character(64) :: sds_name + + integer :: rank, data_type, num_attrs + + integer(int16), dimension(:,:), allocatable :: Snow_Cover + integer(int16), dimension(:,:), allocatable :: Clear_Index + integer(int16), dimension(:,:), allocatable :: Snow_Spatial_QA + + character(kind=c_char, len=1), dimension(:,:), allocatable :: tmp_char1 + + character(len=*), parameter :: Iam = 'read_MODIS_SCF_hdf' + character(len=400) :: err_msg + + ! ------------------------------------------------------------------------- + ! + ! make sure file exists + + 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 MODIS 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 MODIS CMG array indices for requested lat/lon_min/max range + + ! MODIS CMG hdf files: + ! - lon-by-lat (NOTE: The metadata "s.Vgroup(1).Vgroup(1).SDS(1).Dims.Size" returned + ! by Matlab's hdfinfo() confusingly suggests that CMG files are + ! lat-by-lon, which is not the case!) + ! - 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] - real :: UTC_hour, time_diff + N_lon = last(1) - start(1) + 1 + N_lat = last(2) - start(2) + 1 - character(len=*), parameter :: Iam = 'localtime2longitude' - character(len=400) :: err_msg + edge(1) = N_lon + edge(2) = N_lat - ! --------------------------------------------------------------------------- + stride(1) = 1 + stride(2) = 1 - ! make sure local_hour is within range: 0 <= local_hour < 24 + + + ! ! dbg ! ! write (*,*) '###############################################################################' + ! ! dbg ! ! write (*,*) Iam // '():' + ! ! dbg ! ! write (*,*) 'size(CMG_SCF), N_lon, N_lat = ', size(CMG_SCF), N_lon, N_lat + ! ! dbg ! ! write (*,*) 'lon_min, lon_max = ', lon_min, lon_max + ! ! dbg ! ! write (*,*) 'lat_min, lat_max = ', lat_min, lat_max + ! ! dbg ! ! write (*,*) 'start [lon, lat] = ', start + ! ! dbg ! ! write (*,*) 'last [lon, lat] = ', last + ! ! dbg ! ! write (*,*) 'edge [lon, lat] = ', edge + ! ! dbg ! ! write (*,*) '###############################################################################' - if ( (local_hour < 0.) .or. (local_hour >= 24.) ) then + + + ! 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 = 'input local_hour falls outside allowed range of 0:24' + err_msg = 'inconsistent array dimensions' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - ! initialize + ! check array bounds - delta_day = 0 + 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 MODIS 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 - ! determine fractional UTC hour and time difference with local_hour + + ! allocate arrays + + allocate(lon_c( N_lon)) + allocate(lat_c( N_lat)) - UTC_hour = ( date_time%hour*3600 + date_time%min*60 + date_time%sec )/3600. ! 0 <= UTC_hour < 24 + 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(Snow_Spatial_QA(N_lon,N_lat)) + + allocate(tmp_char1( N_lon,N_lat)) + + ! -------------------------- - time_diff = local_hour - UTC_hour + ! 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 - ! enforce -12. < time_diff <= 12. and determine associated date difference, if any + 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 + + ! -------------------------- - if (time_diff <= -12.) then + ! open hdf file (read-only) and initialize SD interface + + sd_id = sfstart(trim(fname), DFACC_READ) + + if (sd_id<0) then + + err_msg = 'cannot sfstart (open) file: ' // trim(fname) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - delta_day = 1 + end if + + ! read data - time_diff = time_diff + 24. + do nn=1,N_fields - elseif (time_diff > 12.) then + sds_index = sfn2index( sd_id, trim(field_names(nn)) ) + sds_id = sfselect( sd_id, sds_index ) + + + status = sfginfo( sds_id, sds_name, rank, dimsizes, data_type, num_attrs ) - delta_day = -1 + if ( (dimsizes(1)/=CMG_N_lon) .or. (dimsizes(2)/=CMG_N_lat) ) then - time_diff = time_diff - 24. + err_msg = 'dimensions in hdf file doe not match CMG_N_lon and/or CMG_N_lat' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + + ! ######################################################### + ! ! dbg ! ! write (*,*) 'sds_name = ', trim(sds_name) + ! ! dbg ! ! write (*,*) 'rank, data_type, num_attrs = ', rank, data_type, num_attrs + ! ! dbg ! ! write (*,*) 'dimsizes = ', dimsizes + ! ######################################################### + + + select case (nn) + + case (1); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Cover = ichar(tmp_char1,2) + case (2); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Clear_Index = ichar(tmp_char1,2) + case (3); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Spatial_QA = ichar(tmp_char1,2) + + case default; call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown field') + + end select + + if (status/=0) then + + err_msg = 'error reading data from hdf file: ' // trim(fname) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + status = sfendacc(sds_id) ! terminate access to SDS (field) + + end do + + status = sfend(sd_id) ! close hdf file and SD interface + + + ! ################################################################################# + ! ! dbg ! ! write (*,*) 'Snow_Cover(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Snow_Cover(1:10,1:5) + ! ! dbg ! ! write (*,*) 'Clear_Index(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Clear_Index(1:10,1:5) + ! ! dbg ! ! write (*,*) 'Snow_Spatial_QA(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Snow_Spatial_QA(1:10,1:5) + + ! ! dbg ! ! !if ( (lon_min>-138) .and. (lon_min<-134) ) then + ! ! dbg ! ! if (.false.) then + ! ! dbg ! ! do jj=1,N_lat + ! ! dbg ! ! write(997) Snow_Cover( jj,:) + ! ! dbg ! ! write(998) Clear_Index( jj,:) + ! ! dbg ! ! write(999) Snow_Spatial_QA(jj,:) + ! ! dbg ! ! end do + ! ! dbg ! ! write (*,*) 'stopping after file dump ' + ! ! dbg ! ! stop + ! ! dbg ! ! end if + ! ################################################################################# + + + + ! check range (make sure uint8 from hdf 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(Snow_Spatial_QA < uint8_min) .or. & + any(Snow_Spatial_QA > uint8_max) ) then + + err_msg = 'unexpected range in data from hdf file' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - ! determine longitude + ! ------------------------------------- + ! + ! apply QC and put SCF obs into output array - longitude = time_diff/24.*360. + 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) + (Snow_Spatial_QA(ii,jj) <= qc_snow_spatial_max) ! keep "best", "good", or "OK" quality (3) + + ! (1) excludes "lake ice", "night", "inland water", "ocean", "cloud obscured water", "data not mapped", "fill" + ! (2) clear_index>100 already removed via qc_snow_cover_max + ! (3) excludes Antarctica + + if (keep_data) then + + kk = kk + 1 + + ! raw SCF value is for clear portion of grid cell only, need to normalize with Clear_Index + + CMG_SCF(kk) = 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 - end subroutine localtime2longitude + deallocate(lat_c) + deallocate(lon_c) - ! ***************************************************************** + deallocate(lat_ind) + deallocate(lon_ind) + + deallocate(Snow_Cover ) + deallocate(Clear_Index ) + deallocate(Snow_Spatial_QA) + + end subroutine read_MODIS_SCF_hdf + +! ***************************************************************** - subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & + subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & N_good_data, CMG_lon, CMG_lat, CMG_SCF ) - ! read snow cover area fraction (SCF) obs from daily MODIS Terra or Aqua M?D10C1, version 6.1 - ! - Terra: https://nsidc.org/data/mod10c1/versions/61 - ! - Aqua: https://nsidc.org/data/myd10c1/versions/61 + ! read snow cover area fraction (SCF) obs from daily VIIRS JPSS 1/2 and S-NPP, version 2 + ! - + ! - ! - daily data with spatial resolution of 0.05 deg on MODIS climate modeling grid (CMG) ! - Terra: missing days 2016 d. 50-58 ! - data are read for the requested lat/lon range @@ -7235,10 +8092,11 @@ subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & deallocate(Clear_Index ) deallocate(Snow_Spatial_QA) - end subroutine read_MODIS_SCF_hdf + end subroutine read_JPSS_SCF_hdf + ! ***************************************************************** - + ! lca currently working on!! subroutine read_obs_SMAP_FT( 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, & diff --git a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml index 7581c3a0..b2cae128 100644 --- a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml +++ b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml @@ -2699,8 +2699,137 @@ 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/VJ110C1/' +obs_param_nml(59)%name = 'VJ110C1.AYYYYDDD.002.' +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/VJ210C1/' +obs_param_nml(60)%name = 'VJ210C1.AYYYYDDD.002.' +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 SCF, 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/polam/JPSS/VNP10C1/' +obs_param_nml(61)%name = 'VNP10C1.AYYYYDDD.002.' +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 + +! -------------------------------------------------------------------- + / ! =========================== EOF ======================================= From cee4997a6755d86a134644b3c74fde3dd6b7c2f6 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Mon, 2 Nov 2026 12:11:33 -0700 Subject: [PATCH 02/90] HDF5 reader for VIIRS SCF obs (VNP10C1, VJ110C1, VJ210C1) - read_JPSS_SCF_hdf(): read VIIRS CMG v2 hdf5 files (Snow_Cover, Clear_Index, Basic_QA) via io_hdf5; same QC as MODIS reader, keep Basic_QA=0 ("good") only - io_hdf5.F90: added readDataset2DInt() to read 2d block (hyperslab) - read_obs_JPSS_SCF(): fixed undeclared MODIS_product_ID; file names without production time stamp (renamed files, as for MODIS SCF); corrected launch years and MODIS wording in comments - read_obs(): added case for VNP10C1, VJ110C1, VJ210C1 - LDASsa_DEFAULT_inputs_ensupd.nml: VIIRS obs paths and file names Co-Authored-By: Claude Opus 5.5 --- .../clsm_ensupd_read_obs.F90 | 267 +++++++----------- GEOSlandassim_GridComp/io_hdf5.F90 | 43 ++- GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml | 12 +- 3 files changed, 149 insertions(+), 173 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 00246fd4..d9ab5e29 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6796,9 +6796,9 @@ subroutine read_obs_JPSS_SCF( & ! read JPSS snow cover observations on the 0.05-degree climate ! modeling grid (CMG) ! - ! JPSS1/NOAA-20: VJ110C1 (launched 2022) - ! JPSS2/NOAA-21: VJ210C1 (launched 2017) - ! S-NPP : VNP10C1 (launched 2011, decomissioned 2026) + ! JPSS1/NOAA-20: VJ110C1 (launched 2017) + ! JPSS2/NOAA-21: VJ210C1 (launched 2022) + ! S-NPP : VNP10C1 (launched 2011, decommissioned 2026) ! ! ! For now, assume that VIIRS/JPSS resolution is finer than Catchment tile space @@ -6919,9 +6919,9 @@ subroutine read_obs_JPSS_SCF( & ! identify JPSS product and overpass hour https://vlab.noaa.gov/web/towr-s/satellite-operations-updates - MODIS_product_ID = this_obs_param%name(1:7) + JPSS_product_ID = this_obs_param%name(1:7) - select case (MODIS_product_ID) + select case (JPSS_product_ID) case('VJ110C1'); overpass_hour = 13.5 ! [hours] JPSS1: 13:30 local time @@ -6951,7 +6951,7 @@ subroutine read_obs_JPSS_SCF( & !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! lca: do we want to narrow this band just slightly to remove the striping that occurs in the assimilation currently??? !!!!!!!!!! - ! determine (rough) longitude band for which MODIS obs need to be read + ! determine (rough) longitude band for which JPSS obs need to be read ! ! --> because tiles have a non-zero extent, need to read JPSS obs in CMG grid cells located ! in a wider band (lon_min-delta:lon_max+delta), @@ -6989,7 +6989,7 @@ subroutine read_obs_JPSS_SCF( & if ( date_time_end_JPSS%dofyr == date_time_beg_JPSS%dofyr ) then - ! need only one daily MODIS file and longitude band + ! need only one daily JPSS file and longitude band N_files = 1 @@ -7007,12 +7007,12 @@ subroutine read_obs_JPSS_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_JPSS - write (logunit,*) 'date_time_end_MODIS = ', date_time_end_JPSS + write (logunit,*) 'date_time_beg_JPSS = ', date_time_beg_JPSS + write (logunit,*) 'date_time_end_JPSS = ', date_time_end_JPSS write (logunit,*) 'lon_beg = ', lon_beg write (logunit,*) 'lon_end = ', lon_end - write (logunit,*) 'lon_beg_MODIS = ', lon_beg_JPSS - write (logunit,*) 'lon_end_MODIS = ', lon_end_JPSS + write (logunit,*) 'lon_beg_JPSS = ', lon_beg_JPSS + write (logunit,*) 'lon_end_JPSS = ', lon_end_JPSS err_msg = 'encountered unexpected condition for longitude band!!!' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) @@ -7021,8 +7021,8 @@ subroutine read_obs_JPSS_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 JPSS files are needed + ! (this could also occur if lon_*_JPSS=180., which would result in an ! empty first longitude band, but because of tmp_delta>0, this should ! never happen) @@ -7097,7 +7097,7 @@ subroutine read_obs_JPSS_SCF( & - ! allocate arrays for MODIS CMG data (max size that could possibly be needed for obs from both files) + ! allocate arrays for JPSS CMG data (max size that could possibly be needed for obs from both files) N_tmp = N_lon*N_lat @@ -7106,36 +7106,38 @@ subroutine read_obs_JPSS_SCF( & allocate( CMG_lat(N_tmp) ) - ! read MODIS SCF obs + ! read VIIRS SCF obs ! - ! - (renamed) files currently located at /discover/nobackup/projects/S2SHMA/MODIS/MOD10C1_V61/ (2010-2022) + ! - files must be renamed (production time stamp removed), as for MODIS SCF obs: + ! 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 = 'VJ210C1.Ayyyyddd.002.' - ! full name = 'VJ210C1.AYYYYDDD.002.YYYYDDDhhmmss.h5 + ! %name = 'VJ110C1.Ayyyyddd.002.h5' ! - ! - ! MOD10C1 = JPSS product name - ! .A = "acquisition time" indicator - ! YYYYDDD = placeholder for year/day-of-year - ! .002 = version indicator - ! YYYYDDDhhmmss = production year, day and time - ! .h5 = file name extension + ! 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 ! - 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_JPSS_SCF_hdf() do nn=1,N_files ! loop through longitude bands - ! determine MODIS file name(s) + ! determine JPSS 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:21)//'*'//'.h5' + this_obs_param%name(1:9) // YYYY // DDD // this_obs_param%name(17:23) ! determine sub-array of CMG_* @@ -7718,21 +7720,23 @@ end subroutine read_MODIS_SCF_hdf subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & N_good_data, CMG_lon, CMG_lat, CMG_SCF ) - ! read snow cover area fraction (SCF) obs from daily VIIRS JPSS 1/2 and S-NPP, version 2 - ! - - ! - + ! 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 climate modeling grid (CMG) - ! - Terra: missing days 2016 d. 50-58 ! - data are read for the requested lat/lon range ! - apply QC ! - ! reichle, 20 Oct 2023 + ! adapted from read_MODIS_SCF_hdf() (reichle, 20 Oct 2023) + ! + ! amfox, 2 Nov 2026 - hdf5 version for VIIRS ! ! ------------------------------------------------------------------------------------------------- implicit none - character(*), intent(in) :: fname ! MODIS file name with full path + 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 @@ -7745,7 +7749,7 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! local parameters - ! ll/ur_lon/lat simply indicate the extent of the MODIS CMG grid + ! ll/ur_lon/lat simply indicate the extent of the CMG grid ! ! index increases from (-180,90) to (180,-90) (southward and eastward) @@ -7763,21 +7767,21 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & integer, parameter :: N_fields = 3 - character(22), dimension(N_fields), parameter :: field_names = (/ & - 'Day_CMG_Snow_Cover ', & ! 1 - 'Day_CMG_Clear_Index ', & ! 2 - 'Snow_Spatial_QA '/) ! 3 + character(*), parameter :: field_path = '/HDFEOS/GRIDS/VIIRS_Daily_SnowCover_CMG/Data Fields/' - ! 1234567890123456789012 - ! 1 2 + 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(int16), parameter :: qc_snow_cover_max = 100 ! exclude lake ice, night, inland water, ocean, etc - integer(int16), parameter :: qc_clear_index_min = 20 ! ensure sufficiently clear conditions - integer(int16), parameter :: qc_snow_spatial_max = 2 ! data quality (0=best, 1=good, 2=OK, 3=poor, 4=other) - - integer, parameter :: DFACC_READ = 1 ! from hdf.inc + integer, parameter :: qc_snow_cover_max = 100 ! exclude no decision, night, lake, ocean, Antarctica, cloud, fill, etc + integer, parameter :: qc_clear_index_min = 20 ! ensure sufficiently clear conditions + integer, parameter :: qc_basic_qa_max = 0 ! data quality (0=good, 1=poor, 2=bad, 3=other) integer, parameter :: uint8_min = 0 integer, parameter :: uint8_max = 255 @@ -7793,23 +7797,21 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & real, dimension(:), allocatable :: lon_ind real, dimension(:), allocatable :: lat_ind - integer, dimension(2) :: start, edge, stride, last, dimsizes + integer, dimension(2) :: start, last + + integer, dimension(7) :: dimsizes logical :: file_exists, keep_data - integer :: status, sd_id, sds_id, sds_index + integer :: rank - character(64) :: sds_name - - integer :: rank, data_type, num_attrs + type(hdf5read) :: h5r - integer(int16), dimension(:,:), allocatable :: Snow_Cover - integer(int16), dimension(:,:), allocatable :: Clear_Index - integer(int16), dimension(:,:), allocatable :: Snow_Spatial_QA - - character(kind=c_char, len=1), dimension(:,:), allocatable :: tmp_char1 + integer, dimension(:,:), allocatable :: Snow_Cover + integer, dimension(:,:), allocatable :: Clear_Index + integer, dimension(:,:), allocatable :: Basic_QA - character(len=*), parameter :: Iam = 'read_MODIS_SCF_hdf' + character(len=*), parameter :: Iam = 'read_JPSS_SCF_hdf' character(len=400) :: err_msg ! ------------------------------------------------------------------------- @@ -7822,7 +7824,7 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & if (logit) then write (logunit,'(400A)') trim(Iam), ': cannot find file ', trim(fname) - write (logunit,* ) 'not reading MODIS SCF obs' + write (logunit,* ) 'not reading VIIRS SCF obs' end if N_good_data = 0 @@ -7843,12 +7845,10 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & end if - ! determine MODIS CMG array indices for requested lat/lon_min/max range + ! determine CMG array indices for requested lat/lon_min/max range - ! MODIS CMG hdf files: - ! - lon-by-lat (NOTE: The metadata "s.Vgroup(1).Vgroup(1).SDS(1).Dims.Size" returned - ! by Matlab's hdfinfo() confusingly suggests that CMG files are - ! lat-by-lon, which is not the case!) + ! 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] @@ -7859,26 +7859,6 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & N_lon = last(1) - start(1) + 1 N_lat = last(2) - start(2) + 1 - - edge(1) = N_lon - edge(2) = N_lat - - stride(1) = 1 - stride(2) = 1 - - - - ! ! dbg ! ! write (*,*) '###############################################################################' - ! ! dbg ! ! write (*,*) Iam // '():' - ! ! dbg ! ! write (*,*) 'size(CMG_SCF), N_lon, N_lat = ', size(CMG_SCF), N_lon, N_lat - ! ! dbg ! ! write (*,*) 'lon_min, lon_max = ', lon_min, lon_max - ! ! dbg ! ! write (*,*) 'lat_min, lat_max = ', lat_min, lat_max - ! ! dbg ! ! write (*,*) 'start [lon, lat] = ', start - ! ! dbg ! ! write (*,*) 'last [lon, lat] = ', last - ! ! dbg ! ! write (*,*) 'edge [lon, lat] = ', edge - ! ! dbg ! ! write (*,*) '###############################################################################' - - ! checks array dimensions @@ -7908,7 +7888,7 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & end if if (logit) then - write (logunit,'(400A)') trim(Iam), '(): reading MODIS SCF obs from ', trim(fname) + 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 @@ -7922,11 +7902,9 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & 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(Snow_Spatial_QA(N_lon,N_lat)) - - allocate(tmp_char1( N_lon,N_lat)) + allocate(Snow_Cover (N_lon,N_lat)) + allocate(Clear_Index(N_lon,N_lat)) + allocate(Basic_QA (N_lon,N_lat)) ! -------------------------- @@ -7942,98 +7920,47 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! -------------------------- - ! open hdf file (read-only) and initialize SD interface + ! open hdf5 file (read-only) - sd_id = sfstart(trim(fname), DFACC_READ) - - if (sd_id<0) then - - err_msg = 'cannot sfstart (open) file: ' // trim(fname) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if + call h5r%openFile(trim(fname)) ! read data do nn=1,N_fields - sds_index = sfn2index( sd_id, trim(field_names(nn)) ) - sds_id = sfselect( sd_id, sds_index ) - + call h5r%queryDataset(field_path // trim(field_names(nn)), rank, dimsizes) - status = sfginfo( sds_id, sds_name, rank, dimsizes, data_type, num_attrs ) - - if ( (dimsizes(1)/=CMG_N_lon) .or. (dimsizes(2)/=CMG_N_lat) ) then + if ( (rank/=2) .or. (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 hdf5 file do not match CMG_N_lon and/or CMG_N_lat' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - - ! ######################################################### - ! ! dbg ! ! write (*,*) 'sds_name = ', trim(sds_name) - ! ! dbg ! ! write (*,*) 'rank, data_type, num_attrs = ', rank, data_type, num_attrs - ! ! dbg ! ! write (*,*) 'dimsizes = ', dimsizes - ! ######################################################### - - select case (nn) - case (1); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Cover = ichar(tmp_char1,2) - case (2); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Clear_Index = ichar(tmp_char1,2) - case (3); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Spatial_QA = ichar(tmp_char1,2) + 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 - if (status/=0) then - - err_msg = 'error reading data from hdf file: ' // trim(fname) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - status = sfendacc(sds_id) ! terminate access to SDS (field) - end do - status = sfend(sd_id) ! close hdf file and SD interface + call h5r%closeFile ! close hdf5 file + ! check range (make sure uint8 from hdf5 file is correctly translated into Fortran integer) - ! ################################################################################# - ! ! dbg ! ! write (*,*) 'Snow_Cover(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Snow_Cover(1:10,1:5) - ! ! dbg ! ! write (*,*) 'Clear_Index(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Clear_Index(1:10,1:5) - ! ! dbg ! ! write (*,*) 'Snow_Spatial_QA(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Snow_Spatial_QA(1:10,1:5) + 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 - ! ! dbg ! ! !if ( (lon_min>-138) .and. (lon_min<-134) ) then - ! ! dbg ! ! if (.false.) then - ! ! dbg ! ! do jj=1,N_lat - ! ! dbg ! ! write(997) Snow_Cover( jj,:) - ! ! dbg ! ! write(998) Clear_Index( jj,:) - ! ! dbg ! ! write(999) Snow_Spatial_QA(jj,:) - ! ! dbg ! ! end do - ! ! dbg ! ! write (*,*) 'stopping after file dump ' - ! ! dbg ! ! stop - ! ! dbg ! ! end if - ! ################################################################################# - - - - ! check range (make sure uint8 from hdf 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(Snow_Spatial_QA < uint8_min) .or. & - any(Snow_Spatial_QA > uint8_max) ) then - - err_msg = 'unexpected range in data from hdf file' + err_msg = 'unexpected range in data from hdf5 file' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if @@ -8054,19 +7981,19 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! 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) - (Snow_Spatial_QA(ii,jj) <= qc_snow_spatial_max) ! keep "best", "good", or "OK" quality (3) + (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) + (Basic_QA( ii,jj) <= qc_basic_qa_max ) ! keep "good" quality (3) - ! (1) excludes "lake ice", "night", "inland water", "ocean", "cloud obscured water", "data not mapped", "fill" + ! (1) excludes "no decision", "night", "lake", "ocean", "Antarctica", "cloud", "fill", etc ! (2) clear_index>100 already removed via qc_snow_cover_max - ! (3) excludes Antarctica + ! (3) excludes "poor", "bad", and "other" quality if (keep_data) then kk = kk + 1 - ! raw SCF value is for clear portion of grid cell only, need to normalize with Clear_Index + ! raw SCF value is percent of all obs in grid cell, need to normalize with Clear_Index CMG_SCF(kk) = real(Snow_Cover(ii,jj))/real(Clear_Index(ii,jj)) @@ -8088,9 +8015,9 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & deallocate(lat_ind) deallocate(lon_ind) - deallocate(Snow_Cover ) - deallocate(Clear_Index ) - deallocate(Snow_Spatial_QA) + deallocate(Snow_Cover ) + deallocate(Clear_Index) + deallocate(Basic_QA ) end subroutine read_JPSS_SCF_hdf @@ -10890,6 +10817,14 @@ subroutine read_obs( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) + + case ('VNP10C1','VJ110C1','VJ210C1') + + call read_obs_JPSS_SCF( & + date_time, dtstep_assim, N_catd, tile_coord, & + tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + this_obs_param, & + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) case('SMAP_L1C_Tbh_A', 'SMAP_L1C_Tbv_A', & 'SMAP_L1C_Tbh_D', 'SMAP_L1C_Tbv_D', & diff --git a/GEOSlandassim_GridComp/io_hdf5.F90 b/GEOSlandassim_GridComp/io_hdf5.F90 index eba2c8c5..95c4b70a 100644 --- a/GEOSlandassim_GridComp/io_hdf5.F90 +++ b/GEOSlandassim_GridComp/io_hdf5.F90 @@ -50,13 +50,14 @@ 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 ! private procedure, private :: readDataset1DReal procedure, private :: readDataset1DReal8 procedure, private :: readDataset1DInt procedure, private :: readDataset1DChar24 procedure, private :: readDataset2DReal + procedure, private :: readDataset2DInt procedure, private :: uninitDataset end type hdf5read @@ -324,6 +325,46 @@ 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 + ! check return code ! (not part of class hdf5read) subroutine checkErrCode_(routineName, hdf5errCode) diff --git a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml index b2cae128..5ad8f72e 100644 --- a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml +++ b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml @@ -2726,8 +2726,8 @@ 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/VJ110C1/' -obs_param_nml(59)%name = 'VJ110C1.AYYYYDDD.002.' +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 = '' @@ -2769,8 +2769,8 @@ 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/VJ210C1/' -obs_param_nml(60)%name = 'VJ210C1.AYYYYDDD.002.' +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 = '' @@ -2812,8 +2812,8 @@ 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/polam/JPSS/VNP10C1/' -obs_param_nml(61)%name = 'VNP10C1.AYYYYDDD.002.' +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 = '' From ca6b37772ac0474e6449e1b05c2fbe0f0a37b79f Mon Sep 17 00:00:00 2001 From: amfox37 Date: Mon, 2 Nov 2026 12:59:08 -0700 Subject: [PATCH 03/90] Keep low-illumination VIIRS SCF obs; exclude Clear_Index flag values (read_JPSS_SCF_hdf) - keep Basic_QA = 0, 1, 3 (best, good, other); exclude 2 (poor). "other" = low illumination (70<=SZA<85 deg), which applies to most high-latitude winter obs (QA=0 only kept ~1% of obs north of 60N) - explicit Clear_Index <= 100 check (Antarctica has Snow_Cover=100 and Clear_Index=243) - corrected QC comments Co-Authored-By: Claude Opus 5.5 --- .../clsm_ensupd_read_obs.F90 | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index d9ab5e29..cabc9e59 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -7779,9 +7779,11 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & integer, parameter :: SCF_nodata = -9999. - integer, parameter :: qc_snow_cover_max = 100 ! exclude no decision, night, lake, ocean, Antarctica, cloud, fill, etc + 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_basic_qa_max = 0 ! data quality (0=good, 1=poor, 2=bad, 3=other) + integer, parameter :: qc_clear_index_max = 100 ! exclude flag values (e.g., Antarctica) + integer, parameter :: qc_basic_qa_max = 3 ! data quality (0=best, 1=good, 2=poor, 3=other) + integer, parameter :: qc_basic_qa_poor = 2 ! exclude "poor" quality integer, parameter :: uint8_min = 0 integer, parameter :: uint8_max = 255 @@ -7983,11 +7985,16 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & 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) - (Basic_QA( ii,jj) <= qc_basic_qa_max ) ! keep "good" quality (3) - - ! (1) excludes "no decision", "night", "lake", "ocean", "Antarctica", "cloud", "fill", etc - ! (2) clear_index>100 already removed via qc_snow_cover_max - ! (3) excludes "poor", "bad", and "other" quality + (Clear_Index(ii,jj) <= qc_clear_index_max ) .and. & ! 0<=CI<=100 (3) + (Basic_QA( ii,jj) <= qc_basic_qa_max ) .and. & ! keep "best", "good", or "other" (4) + (Basic_QA( ii,jj) /= qc_basic_qa_poor ) ! quality (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) "other" = low illumination (70<=SZA<85 deg); must be kept to retain most + ! high-latitude winter obs (as with MODIS reader); excludes "poor" and flag values if (keep_data) then From 5d4d636dbfacb95fa040d5baf8d7e8155a712ae4 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Mon, 2 Nov 2026 13:27:29 -0700 Subject: [PATCH 04/90] Cap VIIRS SCF obs at 1 (read_JPSS_SCF_hdf) VIIRS Snow_Cover can exceed Clear_Index by 1 (rounding), giving SCF up to ~1.05 in ~17% of snow-covered cells; MODIS Snow_Cover never exceeds Clear_Index. Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index cabc9e59..34ecf50c 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -8000,9 +8000,10 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & kk = kk + 1 - ! raw SCF value is percent of all obs in grid cell, need to normalize with Clear_Index + ! 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) = real(Snow_Cover(ii,jj))/real(Clear_Index(ii,jj)) + 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) From 5862a4587ca5534d41e4f42d394d643e6cb16739 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Tue, 3 Nov 2026 15:09:24 -0700 Subject: [PATCH 05/90] Log original file name (LocalGranuleID) in VIIRS SCF reader (read_JPSS_SCF_hdf) VIIRS SCF obs files are renamed without the production time stamp, so the log did not show which production of each file was used. read_JPSS_SCF_hdf now logs the LocalGranuleID global attribute (original file name). - io_hdf5.F90: new readAttribute (fixed-length string attribute of root group; blank if attribute does not exist) Co-Authored-By: Claude Opus 5.5 --- .../clsm_ensupd_read_obs.F90 | 9 ++++ GEOSlandassim_GridComp/io_hdf5.F90 | 52 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 34ecf50c..e8fac3a9 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -7813,6 +7813,8 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & integer, dimension(:,:), allocatable :: Clear_Index integer, dimension(:,:), allocatable :: Basic_QA + character(256) :: granule_id + character(len=*), parameter :: Iam = 'read_JPSS_SCF_hdf' character(len=400) :: err_msg @@ -7926,6 +7928,13 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & call h5r%openFile(trim(fname)) + ! log original file name (incl. production time stamp) because files are renamed + ! (see read_obs_JPSS_SCF()); identifies the obs used in an experiment + + call h5r%readAttribute('LocalGranuleID', granule_id) + + if (logit) write (logunit,'(400A)') ' LocalGranuleID = ', trim(granule_id) + ! read data do nn=1,N_fields diff --git a/GEOSlandassim_GridComp/io_hdf5.F90 b/GEOSlandassim_GridComp/io_hdf5.F90 index 95c4b70a..46cd03de 100644 --- a/GEOSlandassim_GridComp/io_hdf5.F90 +++ b/GEOSlandassim_GridComp/io_hdf5.F90 @@ -51,6 +51,7 @@ module io_hdf5 procedure, public :: closeFile procedure, public :: queryDataset generic, public :: readDataset => readDataset1DReal, readDataset1DReal8, readDataset1DInt, readDataset1DChar24, readDataset2DReal, readDataset2DInt + generic, public :: readAttribute => readAttributeChar ! private procedure, private :: readDataset1DReal procedure, private :: readDataset1DReal8 @@ -58,6 +59,7 @@ module io_hdf5 procedure, private :: readDataset1DChar24 procedure, private :: readDataset2DReal procedure, private :: readDataset2DInt + procedure, private :: readAttributeChar procedure, private :: uninitDataset end type hdf5read @@ -365,6 +367,56 @@ subroutine readDataset2DInt(this, data2D, offset) 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 + 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 + 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) + call checkErrCode_('h5aexists_f', hdf5err) + + if (.not. attr_exists) return + + call h5aopen_f(this%file_id, attrName, attr_id, hdf5err) + call checkErrCode_('h5aopen_f', hdf5err) + + ! create the memory datatype for a fixed-length string of length len(attrValue) + call h5tcopy_f(H5T_FORTRAN_S1, memtype_id, hdf5err) + call checkErrCode_('h5tcopy_f', hdf5err) + + call h5tset_size_f(memtype_id, int(len(attrValue),size_t), hdf5err) + call checkErrCode_('h5tset_size_f', hdf5err) + + dims = 1_hsize_t + call h5aread_f(attr_id, memtype_id, attrValue, dims, hdf5err) + call checkErrCode_('h5aread_f', hdf5err) + + call h5tclose_f(memtype_id, hdf5err) + call checkErrCode_('h5tclose_f', hdf5err) + + call h5aclose_f(attr_id, hdf5err) + call checkErrCode_('h5aclose_f', hdf5err) + + end subroutine readAttributeChar + ! check return code ! (not part of class hdf5read) subroutine checkErrCode_(routineName, hdf5errCode) From d1475c10c260206c129287adf0a940b54284f3e4 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 4 Nov 2026 11:55:41 -0700 Subject: [PATCH 06/90] Return blank from readAttributeChar unless the attribute is a single fixed-length string readAttributeChar (io_hdf5.F90) reads into one string of length len(attrValue). An attribute of another type, or a variable-length string, failed the type conversion and stopped the run; an array of strings was written past the end of attrValue. Now these return blank, like a missing attribute, so the LocalGranuleID log line in read_JPSS_SCF_hdf can never stop or corrupt a run. No change for normal VIIRS files. Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/io_hdf5.F90 | 42 +++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/GEOSlandassim_GridComp/io_hdf5.F90 b/GEOSlandassim_GridComp/io_hdf5.F90 index 46cd03de..0a9daef1 100644 --- a/GEOSlandassim_GridComp/io_hdf5.F90 +++ b/GEOSlandassim_GridComp/io_hdf5.F90 @@ -369,6 +369,7 @@ 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 is not a single fixed-length string subroutine readAttributeChar(this, attrName, attrValue) ! input/output variables @@ -377,10 +378,10 @@ subroutine readAttributeChar(this, attrName, attrValue) character(len=*), intent(out) :: attrValue ! local variables - integer :: hdf5err - logical :: attr_exists - integer(hid_t) :: attr_id, memtype_id - integer(hsize_t) :: dims(1) + integer :: hdf5err, type_class + logical :: attr_exists, is_vlen + integer(hid_t) :: attr_id, memtype_id, filetype_id, space_id + integer(hsize_t) :: dims(1), npoints ! check file state if (this%file_id == INVALID_HID) then @@ -398,6 +399,39 @@ subroutine readAttributeChar(this, attrName, attrValue) call h5aopen_f(this%file_id, attrName, attr_id, hdf5err) call checkErrCode_('h5aopen_f', hdf5err) + ! return blank unless the attribute is a single fixed-length string + ! (h5aread_f() below reads into one string of length len(attrValue); other types + ! fail the type conversion, and more than one element would overflow attrValue) + call h5aget_type_f(attr_id, filetype_id, hdf5err) + call checkErrCode_('h5aget_type_f', hdf5err) + + call h5tget_class_f(filetype_id, type_class, hdf5err) + call checkErrCode_('h5tget_class_f', hdf5err) + + is_vlen = .false. + if (type_class == H5T_STRING_F) then + call h5tis_variable_str_f(filetype_id, is_vlen, hdf5err) + call checkErrCode_('h5tis_variable_str_f', hdf5err) + end if + + call h5tclose_f(filetype_id, hdf5err) + call checkErrCode_('h5tclose_f', hdf5err) + + call h5aget_space_f(attr_id, space_id, hdf5err) + call checkErrCode_('h5aget_space_f', hdf5err) + + call h5sget_simple_extent_npoints_f(space_id, npoints, hdf5err) + call checkErrCode_('h5sget_simple_extent_npoints_f', hdf5err) + + call h5sclose_f(space_id, hdf5err) + call checkErrCode_('h5sclose_f', hdf5err) + + if (type_class /= H5T_STRING_F .or. is_vlen .or. npoints /= 1_hsize_t) then + call h5aclose_f(attr_id, hdf5err) + call checkErrCode_('h5aclose_f', hdf5err) + return + end if + ! create the memory datatype for a fixed-length string of length len(attrValue) call h5tcopy_f(H5T_FORTRAN_S1, memtype_id, hdf5err) call checkErrCode_('h5tcopy_f', hdf5err) From 8c778e4e6d0d29358df4b198acdc98dba684abaf Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 4 Nov 2026 12:31:09 -0700 Subject: [PATCH 07/90] Assimilate VIIRS SCF obs of tiles on a window boundary only once (read_obs_JPSS_SCF) The final tile mask kept tiles with lon_end <= com_lon <= lon_beg, so a tile whose com_lon is exactly on the boundary between two assimilation windows got the same daily obs in both windows. With 3-hourly windows centered at 0z, 3z, ... the boundaries are at multiples of 45 deg; in EASEv2 M36 this affects 470 tiles (full columns at +-45 and +-135 deg), in CF0360 6 tiles, in M09 none. Keep lon_end < com_lon <= lon_beg, as documented above (one longitude band) and correspondingly for the band that wraps around the dateline. Each tile now falls into exactly one window per day (checked for M36, M09 and CF0360 tile coords, 13:30 and 10:30 overpass, windows centered at 0z,3z,... and 1:30z,4:30z,...). Same defect in read_obs_MODIS_SCF (develop); fixed separately. Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index e8fac3a9..b78b4616 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -7235,25 +7235,29 @@ subroutine read_obs_JPSS_SCF( & ! to avoid double-counting of JPSS 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 + ! assimilation windows gets its obs only once (e.g., EASEv2 M36 tiles at +-45 and +-135 deg + ! for windows centered at 0z, 3z, ...) if (lon_end < lon_beg) then - ! need only one longitude band (keep obs when lon_end<=com_lon<=lon_beg) + ! need only one longitude band (keep obs when lon_endlon_beg) ) & + if ( (tile_coord(kk)%com_lon<=lon_end) .or. (tile_coord(kk)%com_lon>lon_beg) ) & JPSS_obs(kk) = this_obs_param%nodata end do else - ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_end<=com_lon<=180) + ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_endlon_beg) .and. (tile_coord(kk)%com_lonlon_beg) .and. (tile_coord(kk)%com_lon<=lon_end) ) & JPSS_obs(kk) = this_obs_param%nodata end do From 0bb0c1b68d557ed523857c091a533c4ac7366d05 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 4 Nov 2026 12:31:09 -0700 Subject: [PATCH 08/90] Correct VIIRS Basic_QA labels in read_JPSS_SCF_hdf comments The CMG files and the VNP10C1 v2 user guide define Basic_QA as 0=good, 1=poor, 2=bad, 3=other; the comments used the L2 swath key (0=best, 1=good, 2=poor). Rename qc_basic_qa_poor to qc_basic_qa_bad. No change in the obs that are kept (QA 0, 1 and 3). Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index b78b4616..a133653d 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -7786,8 +7786,8 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & 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_max = 3 ! data quality (0=best, 1=good, 2=poor, 3=other) - integer, parameter :: qc_basic_qa_poor = 2 ! exclude "poor" quality + integer, parameter :: qc_basic_qa_max = 3 ! data quality (0=good, 1=poor, 2=bad, 3=other) + integer, parameter :: qc_basic_qa_bad = 2 ! exclude "bad" quality integer, parameter :: uint8_min = 0 integer, parameter :: uint8_max = 255 @@ -7999,15 +7999,16 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & (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_max ) .and. & ! keep "best", "good", or "other" (4) - (Basic_QA( ii,jj) /= qc_basic_qa_poor ) ! quality (4) + (Basic_QA( ii,jj) <= qc_basic_qa_max ) .and. & ! keep "good", "poor", or "other" (4) + (Basic_QA( ii,jj) /= qc_basic_qa_bad ) ! quality (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) "other" = low illumination (70<=SZA<85 deg); must be kept to retain most - ! high-latitude winter obs (as with MODIS reader); excludes "poor" and 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); excludes "bad" and flag values if (keep_data) then From baca36e48a622ac106fb08c2c62f4548ca5ea746 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 4 Nov 2026 12:31:09 -0700 Subject: [PATCH 09/90] Never stop in readAttributeChar; read UTF-8 string attributes readAttributeChar (io_hdf5.F90) is used only for log output, but any HDF5 error called checkErrCode_ and stopped the run (with exit status 0). A fixed-length UTF-8 attribute stopped in h5aread_f (HDF5 does not convert between ASCII and UTF-8), and an attribute with a null dataspace stopped in h5sget_simple_extent_npoints_f. Now: - the memory datatype uses the character set of the attribute; - the dataspace type is checked (scalar or simple) before the number of points; - any HDF5 error closes the open handles and returns blank. No change for normal VIIRS files. Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/io_hdf5.F90 | 101 +++++++++++++++-------------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/GEOSlandassim_GridComp/io_hdf5.F90 b/GEOSlandassim_GridComp/io_hdf5.F90 index 0a9daef1..0bb5296d 100644 --- a/GEOSlandassim_GridComp/io_hdf5.F90 +++ b/GEOSlandassim_GridComp/io_hdf5.F90 @@ -368,8 +368,10 @@ subroutine readDataset2DInt(this, data2D, offset) 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 is not a single fixed-length string + ! attribute "LocalGranuleID"); returns blank if attribute does not exist, + ! is not a single fixed-length string, or cannot be read + ! + ! meant for log output: never stops on an HDF5 error (unlike checkErrCode_()) subroutine readAttributeChar(this, attrName, attrValue) ! input/output variables @@ -378,8 +380,8 @@ subroutine readAttributeChar(this, attrName, attrValue) character(len=*), intent(out) :: attrValue ! local variables - integer :: hdf5err, type_class - logical :: attr_exists, is_vlen + integer :: hdf5err, tmperr, type_class, space_class, cset + logical :: attr_exists, is_vlen, is_ok integer(hid_t) :: attr_id, memtype_id, filetype_id, space_id integer(hsize_t) :: dims(1), npoints @@ -392,62 +394,65 @@ subroutine readAttributeChar(this, attrName, attrValue) attrValue = '' call h5aexists_f(this%file_id, attrName, attr_exists, hdf5err) - call checkErrCode_('h5aexists_f', hdf5err) - if (.not. attr_exists) return + if (hdf5err < 0 .or. (.not. attr_exists)) return call h5aopen_f(this%file_id, attrName, attr_id, hdf5err) - call checkErrCode_('h5aopen_f', hdf5err) - ! return blank unless the attribute is a single fixed-length string - ! (h5aread_f() below reads into one string of length len(attrValue); other types - ! fail the type conversion, and more than one element would overflow attrValue) - call h5aget_type_f(attr_id, filetype_id, hdf5err) - call checkErrCode_('h5aget_type_f', hdf5err) + if (hdf5err < 0) return - call h5tget_class_f(filetype_id, type_class, hdf5err) - call checkErrCode_('h5tget_class_f', hdf5err) - - is_vlen = .false. - if (type_class == H5T_STRING_F) then - call h5tis_variable_str_f(filetype_id, is_vlen, hdf5err) - call checkErrCode_('h5tis_variable_str_f', hdf5err) - end if - - call h5tclose_f(filetype_id, hdf5err) - call checkErrCode_('h5tclose_f', hdf5err) + ! dataspace must hold exactly one element (scalar, or simple with one point); + ! more than one element would overflow attrValue + is_ok = .false. + npoints = 0_hsize_t call h5aget_space_f(attr_id, space_id, hdf5err) - call checkErrCode_('h5aget_space_f', hdf5err) - - call h5sget_simple_extent_npoints_f(space_id, npoints, hdf5err) - call checkErrCode_('h5sget_simple_extent_npoints_f', hdf5err) - call h5sclose_f(space_id, hdf5err) - call checkErrCode_('h5sclose_f', hdf5err) - - if (type_class /= H5T_STRING_F .or. is_vlen .or. npoints /= 1_hsize_t) then - call h5aclose_f(attr_id, hdf5err) - call checkErrCode_('h5aclose_f', hdf5err) - return + if (hdf5err >= 0) then + call h5sget_simple_extent_type_f(space_id, space_class, hdf5err) + if (hdf5err >= 0 .and. (space_class == H5S_SCALAR_F .or. space_class == H5S_SIMPLE_F)) then + call h5sget_simple_extent_npoints_f(space_id, npoints, hdf5err) + is_ok = (hdf5err >= 0 .and. npoints == 1_hsize_t) + end if + call h5sclose_f(space_id, tmperr) end if - ! create the memory datatype for a fixed-length string of length len(attrValue) - call h5tcopy_f(H5T_FORTRAN_S1, memtype_id, hdf5err) - call checkErrCode_('h5tcopy_f', hdf5err) - - call h5tset_size_f(memtype_id, int(len(attrValue),size_t), hdf5err) - call checkErrCode_('h5tset_size_f', hdf5err) - - dims = 1_hsize_t - call h5aread_f(attr_id, memtype_id, attrValue, dims, hdf5err) - call checkErrCode_('h5aread_f', hdf5err) + ! datatype must be a fixed-length string; get its character set (ASCII or UTF-8), + ! because HDF5 does not convert between character sets + if (is_ok) then + is_ok = .false. + is_vlen = .true. + cset = -1 + call h5aget_type_f(attr_id, filetype_id, hdf5err) + if (hdf5err >= 0) then + call h5tget_class_f(filetype_id, type_class, hdf5err) + if (hdf5err >= 0 .and. type_class == H5T_STRING_F) then + call h5tis_variable_str_f(filetype_id, is_vlen, hdf5err) + if (hdf5err >= 0 .and. (.not. is_vlen)) then + call h5tget_cset_f(filetype_id, cset, hdf5err) + is_ok = (hdf5err >= 0) + end if + end if + call h5tclose_f(filetype_id, tmperr) + end if + end if - call h5tclose_f(memtype_id, hdf5err) - call checkErrCode_('h5tclose_f', hdf5err) + ! read into a fixed-length string of length len(attrValue) with the character set of the attribute + if (is_ok) then + 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) call h5tset_cset_f(memtype_id, cset, 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 + end if - call h5aclose_f(attr_id, hdf5err) - call checkErrCode_('h5aclose_f', hdf5err) + call h5aclose_f(attr_id, tmperr) end subroutine readAttributeChar From a3dbc4867bcea30deeda55f53d14bd7d194ac251 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 4 Nov 2026 13:02:26 -0700 Subject: [PATCH 10/90] Remove resolved striping notes in read_obs_JPSS_SCF The striping at +-45 and +-135 deg in M36 runs came from tiles on a window boundary getting the obs twice (fixed in 8c778e4), not from the width of the read band or the 0.1 deg margin of the band-width check. Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 2 -- 1 file changed, 2 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index a133653d..ef4073c0 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6950,7 +6950,6 @@ subroutine read_obs_JPSS_SCF( & -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! lca: do we want to narrow this band just slightly to remove the striping that occurs in the assimilation currently??? !!!!!!!!!! ! determine (rough) longitude band for which JPSS obs need to be read ! ! --> because tiles have a non-zero extent, need to read JPSS obs in CMG grid cells located @@ -7044,7 +7043,6 @@ subroutine read_obs_JPSS_SCF( & ! verify that longitude bands do not exceed max expected expected width ! (add 0.1 degree of wiggle room) - !!!!!!!!!! is this wiggle room the problem with the additional striping????!!!!!! max_delta_lon = real(dtstep_assim_max + 2*nint(tmp_delta))/86400.*360. + 0.1 ! [degree] do nn=1,N_files From 072cbcebea5504b34058c20ad37525fd56336608 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 4 Nov 2026 13:02:39 -0700 Subject: [PATCH 11/90] Add CHANGELOG entry for VIIRS SCF obs Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1332ec59..5a3bb0c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Added assimilation of VIIRS snow cover fraction obs (VJ110C1, VJ210C1, VNP10C1; hdf5 reader); the reader logs the original obs file name. - 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)). From fc04238cfeba554fffe19594a6d108a596a90e76 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 4 Nov 2026 13:05:14 -0700 Subject: [PATCH 12/90] Remove leftover WIP note; align VIIRS species comments in ensupd nml Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 1 - GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index ef4073c0..7ea184cf 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -8043,7 +8043,6 @@ end subroutine read_JPSS_SCF_hdf ! ***************************************************************** - ! lca currently working on!! subroutine read_obs_SMAP_FT( 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, & diff --git a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml index 5ad8f72e..4aa655c3 100644 --- a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml +++ b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml @@ -2747,9 +2747,9 @@ 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 @@ -2789,7 +2789,7 @@ obs_param_nml(60)%adapt = 0 ! ! 61 = VIIRS/S-NPP snow cover area fraction (SCF) ! -! VNP10C1.*.002.*h5: VIIRS/S-NPP SCF, 0.05deg CMG, daytime (13:30 local) ascending overpass, version 2 +! 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) From 6d0ed325e8d8be2ba1a9b8922ec0ede13f65fecc Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 4 Nov 2026 13:06:47 -0700 Subject: [PATCH 13/90] Remove commented-out debug output in read_obs_JPSS_SCF Co-Authored-By: Claude Opus 5.5 --- .../clsm_ensupd_read_obs.F90 | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 7ea184cf..d55d0417 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -7076,24 +7076,6 @@ subroutine read_obs_JPSS_SCF( & N_lon_vec(1:N_files) = last_ind(1:N_files) - start_ind(1:N_files) + 1 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 JPSS CMG data (max size that could possibly be needed for obs from both files) From 0f9409a1241af99ffd57c8a42f4c75dc9d0c29dc Mon Sep 17 00:00:00 2001 From: amfox37 Date: Thu, 5 Nov 2026 14:29:55 -0700 Subject: [PATCH 14/90] Write VIIRS SCF file names to obslog, as for MODIS (read_obs_JPSS_SCF) - read_JPSS_SCF_hdf() returns the original file name (LocalGranuleID, blank if missing) instead of writing it to the general log. - read_obs_JPSS_SCF() writes one obslog row per daily file read: the number of good obs and the file name with the original name in place of the renamed one (requested name if LocalGranuleID is blank). Same pattern as read_obs_MODIS_SCF() in PR #239. Obs are unchanged (standalone reader check vs. Python mirror, VJ110C1, VJ210C1, VNP10C1). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- .../clsm_ensupd_read_obs.F90 | 82 ++++++++++++++++--- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 302ac110..2ccfa658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - 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); the reader logs the original obs file name. +- Added assimilation of VIIRS snow cover fraction obs (VJ110C1, VJ210C1, VNP10C1; hdf5 reader); original obs file names are written to the obslog. - 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)). diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 6eadb6e5..bbd9b938 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6794,7 +6794,7 @@ end subroutine read_obs_MODIS_SCF subroutine read_obs_JPSS_SCF( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & - this_obs_param, & + this_obs_param, write_obslog, & found_obs, JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat ) ! read JPSS snow cover observations on the 0.05-degree climate @@ -6832,6 +6832,8 @@ subroutine read_obs_JPSS_SCF( & type(obs_param_type), intent(in) :: this_obs_param + logical, intent(in) :: write_obslog + ! output logical, intent(out) :: found_obs @@ -6855,11 +6857,18 @@ subroutine read_obs_JPSS_SCF( & character(4) :: YYYY character(3) :: DDD ! day of year + character( 12) :: tmpstr12 + character( 16) :: YYYYMMDD_HHMMSSz + character( 80) :: tmpstr80 + character(400) :: fname + character(256) :: granule_id + + character(400), dimension(2) :: fname_list real :: overpass_hour, tmp_delta, tmp_real, max_delta_lon - integer :: N_files, N_lon, N_lat, N_tmp, nn, kk, ind + integer :: N_files, N_lon, N_lat, N_tmp, nn, kk, ind, tmp_ind integer :: N_CMG_obs, N_good_data, tmp_ind_start, tmp_ind_last type(date_time_type) :: date_time_beg, date_time_end @@ -6876,7 +6885,7 @@ subroutine read_obs_JPSS_SCF( & real, dimension(2) :: lon_min_vec, lon_max_vec - integer, dimension(2) :: N_lon_vec, year_vec, dofyr_vec, start_ind, last_ind + integer, dimension(2) :: N_lon_vec, year_vec, dofyr_vec, start_ind, last_ind, N_good_data_list real, dimension(:), allocatable :: CMG_obs, CMG_lon, CMG_lat @@ -7112,7 +7121,7 @@ subroutine read_obs_JPSS_SCF( & N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_JPSS_SCF_hdf() - do nn=1,N_files ! loop through longitude bands + do nn=1,N_files ! loop through longitude bands (i.e., files) ! determine JPSS file name(s) @@ -7133,12 +7142,51 @@ subroutine read_obs_JPSS_SCF( & 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) ) + CMG_obs(tmp_ind_start:tmp_ind_last), & + granule_id ) N_CMG_obs = N_CMG_obs + N_good_data + ! record number of good obs and file name for obslog + + N_good_data_list(nn) = N_good_data + + if (len_trim(granule_id)>0) then + + tmp_ind = index(trim(fname), '/', back=.true.) ! position of last "/" + + if (tmp_ind>0) then + fname_list(nn) = fname(1:tmp_ind) // trim(granule_id) ! replace file name with granule id + else + fname_list(nn) = trim(granule_id) ! fname was only file name (no path) + end if + + else + + fname_list( nn) = fname ! use fname b/c granule_id is empty + + end if + end do + ! write "obslog" file + + if (write_obslog) then + + YYYYMMDD_HHMMSSz = date_time2string(date_time) + + tmpstr80 = trim(Iam) // '()' ! name of this subroutine + + do nn=1,N_files + + write (tmpstr12,'(i12)') N_good_data_list(nn) ! convert integer to string + + call add_to_obslog( YYYYMMDD_HHMMSSz, this_obs_param%descr, tmpstr80, & + tmpstr12, fname_list(nn) ) + + end do + + end if ! return if no JPSS obs were found (found_obs=.false. per initialization above) @@ -7706,7 +7754,7 @@ end subroutine read_MODIS_SCF_hdf ! ***************************************************************** subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & - N_good_data, CMG_lon, CMG_lat, CMG_SCF ) + 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 @@ -7720,6 +7768,13 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! ! amfox, 2 Nov 2026 - hdf5 version for VIIRS ! + ! 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_JPSS_SCF(), as for MODIS + ! - amfox, 5 Nov 2026 + ! ! ------------------------------------------------------------------------------------------------- implicit none @@ -7732,6 +7787,8 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & 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) ! ------------------------------------------------- @@ -7801,14 +7858,14 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & integer, dimension(:,:), allocatable :: Clear_Index integer, dimension(:,:), allocatable :: Basic_QA - character(256) :: granule_id - character(len=*), parameter :: Iam = 'read_JPSS_SCF_hdf' character(len=400) :: err_msg ! ------------------------------------------------------------------------- ! ! make sure file exists + + granule_id = '' inquire( file=trim(fname), exist=file_exists ) @@ -7916,13 +7973,12 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & call h5r%openFile(trim(fname)) - ! log original file name (incl. production time stamp) because files are renamed - ! (see read_obs_JPSS_SCF()); identifies the obs used in an experiment + ! get original file name (incl. production time stamp) because files are renamed; returned to + ! read_obs_JPSS_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) - if (logit) write (logunit,'(400A)') ' LocalGranuleID = ', trim(granule_id) - ! read data do nn=1,N_fields @@ -10828,7 +10884,7 @@ subroutine read_obs( & call read_obs_JPSS_SCF( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & - this_obs_param, & + this_obs_param, write_obslog, & found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) case('SMAP_L1C_Tbh_A', 'SMAP_L1C_Tbv_A', & From 0aa34f44d7a6649a09a38f43d2536b2d3dbf553c Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang Date: Thu, 5 Nov 2026 21:14:25 -0500 Subject: [PATCH 15/90] Fix NAG build on macOS (GEOSlandassim) - Compile hdf4_c_api.c as a separate object library so that hdf.h's does not resolve to GMAO_mpeu/assert.H on case-insensitive file systems - clsm_ensupd_read_obs: real(8) -> real(REAL64) --- GEOSlandassim_GridComp/CMakeLists.txt | 10 +++++++++- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) 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/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 37e03ba9..e99a1392 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 @@ -2291,7 +2291,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) From 9c854952abd9521b615f64a951597cdb44d9def2 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Fri, 6 Nov 2026 14:04:39 -0700 Subject: [PATCH 16/90] add cube-sphere ("c3") grid to get_ij_ind_from_latlon() and get_tile_num_from_latlon(); add check_c3_tile_grid() (LDAS_TileCoordRoutines.F90) - get_ij_ind_from_latlon(): 'c3' branch with the geometry of MAPL_GetGlobalHorzIJIndex() (gnomonic equal-edge cube, pi/18 shift, real*8); global N from dlon = 360/(4*N) - get_tile_num_from_latlon(): 'c3' branch; among tiles in the cube-sphere cell of the obs (then in the cells of 8 points +/- half a cell) whose bounding box holds the obs, pick the min box-normalized distance; else nearest center + existing max_dist check - check_c3_tile_grid(): count tiles whose center maps to a cell other than [i_indg,j_indg]; abort if > 0.1% EASEv and LatLon branches unchanged; new code is not yet called (0-diff). Co-Authored-By: Claude Opus 5.5 --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 324 ++++++++++++++++++++++++- 1 file changed, 323 insertions(+), 1 deletion(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 43e5f86b..41a05aaf 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -5,6 +5,8 @@ ! 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, 6 Nov 2026 - added cube-sphere grid ("c3") to get_ij_ind_from_latlon() and +! get_tile_num_from_latlon(); added check_c3_tile_grid() ! ! ======================================================================== @@ -24,7 +26,9 @@ 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, & @@ -47,6 +51,7 @@ module LDAS_TileCoordRoutines public :: get_tile_num_in_ellipse public :: get_tile_num_from_latlon public :: get_ij_ind_from_latlon + public :: check_c3_tile_grid public :: tile2grid_simple public :: grid2tile public :: tile_mask_grid @@ -775,6 +780,12 @@ 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 cube-sphere ("c3") tile_grid; tiles do not nest in the cells of a lat/lon + ! grid, so for cube-sphere tile space, tile_grid 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) + ! - amfox, 6 Nov 2026 implicit none @@ -809,6 +820,13 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & real :: tmp_dist_x, min_dist_x real, dimension(N_latlon) :: max_dist_tmp_x + ! for cube-sphere tile_grid + + integer :: ii, jj, kk, N_cell_c3 + integer, dimension(9) :: i_cell_c3, j_cell_c3 + + real :: tmp_hx, tmp_hy, tmp_dlon, tmp_dlat + character(len=*), parameter :: Iam = 'get_tile_num_from_latlon' character(len=400) :: err_msg @@ -910,6 +928,138 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & end do + elseif (index(tile_grid%gridtype, 'c3')/=0) then + + ! 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 there is no such tile, repeat 1.) for all tiles within the grid cells + ! that contain the 8 points at +/- half a grid cell (approx.) around + ! lat/lon, because the bounding box of a tile can extend into a + ! neighboring grid cell. + ! + ! 3.) If there is still no such tile, loop through all tiles of 1.) and 2.) + ! and find minimum distance (Minkowski norm) as for LatLon. This tile + ! is subject to the bounding box and max_dist check below. + ! + ! If there are no land tiles in these grid cells, tile_num will not change + ! from its initialized value. + ! + ! amfox, 6 Nov 2026 + + N_cell_c3 = 1 + + i_cell_c3(1) = i_ind + j_cell_c3(1) = j_ind + + do kk=1,9 + + if (kk>N_cell_c3) exit + + do k=1,N_tile_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk)) + + this_tile_num = tile_num_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk),k) + + if ( tile_coord(this_tile_num)%min_lon <= lon(n) .and. & + tile_coord(this_tile_num)%max_lon >= lon(n) .and. & + tile_coord(this_tile_num)%min_lat <= lat(n) .and. & + tile_coord(this_tile_num)%max_lat >= lat(n) ) 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(n) - tile_coord(this_tile_num)%com_lon) + tmp_dist_y = abs(lat(n) - tile_coord(this_tile_num)%com_lat) + + tmp_dist = (tmp_dist_x/tmp_hx)**2 + (tmp_dist_y/tmp_hy)**2 + + if (tmp_dist abort. + ! + ! A few tiles do not match because their center-of-mass is outside of (or on the + ! edge of) their grid cell, e.g., 23 of 1188020 land tiles for CF0360. + ! + ! amfox, 6 Nov 2026 + + implicit none + + integer, intent(in) :: N_tile + + type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + + type(grid_def_type), intent(in) :: tile_grid + + ! local variables + + real, parameter :: max_frac_mismatch = 0.001 ! abort if more tiles do not match + + integer :: n, i_ind, j_ind, off_i, off_j, N_mismatch + + character(len=*), parameter :: Iam = 'check_c3_tile_grid' + character(len=400) :: err_msg + + ! ----------------------------------------------------------- + + ! adjust for 0-based indexing (as in get_number_of_tiles_in_cell_ij()) + + off_i = tile_grid%i_offg + (tile_grid%ind_base - 1) + off_j = tile_grid%j_offg + (tile_grid%ind_base - 1) + + N_mismatch = 0 + + do n=1,N_tile + + call get_ij_ind_from_latlon( tile_grid, tile_coord(n)%com_lat, tile_coord(n)%com_lon, & + i_ind, j_ind ) + + if ( (i_ind /= tile_coord(n)%i_indg - off_i) .or. & + (j_ind /= tile_coord(n)%j_indg - off_j) ) N_mismatch = N_mismatch + 1 + + end do + + if (logit) write (logunit,*) trim(Iam), ': number of tiles = ', N_tile, & + ', number of tiles w/ center-of-mass not in grid cell [i_indg,j_indg] = ', N_mismatch + if (logit) write (logunit,*) + + if (real(N_mismatch) > max_frac_mismatch*real(N_tile)) then + + write (err_msg,'(A,i8,A,i8,A)') 'center-of-mass of ', N_mismatch, ' of ', N_tile, & + ' tiles not in cube-sphere grid cell [i_indg,j_indg]; only gnomonic cube-sphere ' // & + 'grids w/ pi/18 shift of longitude (not stretched) are supported' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + end subroutine check_c3_tile_grid + + ! ******************************************************************* + subroutine get_tile_num_in_ellipse( lon, lat, r_x, r_y, & N_tile, tile_coord, tile_grid, & N_tile_in_cell_ij, tile_num_in_cell_ij, & From b20fe14ab3eff9a59ed5fe682e82ba121fda8e05 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Fri, 6 Nov 2026 14:04:39 -0700 Subject: [PATCH 17/90] map obs to tiles on cube-sphere tile grid for cube-sphere tile space (clsm_ensupd_enkf_update.F90) For cube-sphere tile space, pass tile_grid_f (= tile_grid_g) and tables built from tile_coord_f%i_indg/j_indg to collect_obs() instead of the lat/lon pert_grid_f and its tables, in whose cells the tiles do not nest (for CF0360, 38% of land obs were dropped and 16% assigned to the wrong tile). Keep the lat/lon extent of pert_grid_f so that obs outside pert_grid_f are still dropped (needed by get_obs_pert()). Call check_c3_tile_grid() once on root. Unchanged for EASE and lat/lon tile space. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + .../clsm_ensupd_enkf_update.F90 | 91 ++++++++++++++++--- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70504db7..04b8ba63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 mapping of obs to tiles in cube-sphere tile space: map obs on the cube-sphere tile grid with tile bounding boxes instead of on the lat/lon perturbation grid, in whose cells the tiles do not nest (not 0-diff for cube-sphere tile space). - 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 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)). diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index c82c7533..87a84446 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -73,6 +73,7 @@ module clsm_ensupd_enkf_update use LDAS_TilecoordRoutines, ONLY: & get_number_of_tiles_in_cell_ij, & get_tile_num_in_cell_ij, & + check_c3_tile_grid, & grid2tile use nr_ran2_gasdev, ONLY: & @@ -277,6 +278,13 @@ subroutine get_enkf_increments( & integer, dimension(:,:), pointer :: N_tile_in_cell_ij_f integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij_f + ! grid that goes with N_tile_in_cell_ij_f and tile_num_in_cell_ij_f: + ! pert_grid_f, or tile_grid_f for cube-sphere tile space (amfox, 6 Nov 2026) + + type(grid_def_type) :: obs2tile_grid_f + + logical, save :: c3_tile_grid_checked = .false. + integer :: i, n, n_e ! obs bias variables @@ -390,20 +398,73 @@ subroutine get_enkf_increments( & ! 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()) + + obs2tile_grid_f = pert_grid_f ! for cube-sphere tile space see below + 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)) + if (index(tile_grid_g%gridtype,'c3')/=0) then + + ! cube-sphere tile space: map obs to tiles on the cube-sphere tile_grid_f, + ! not on the lat/lon pert_grid_f, because tiles do not nest in the cells of + ! pert_grid_f; each tile is inside the tile_grid_f cell given by + ! tile_coord%i_indg and tile_coord%j_indg (see get_tile_num_from_latlon()) + ! + ! 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()) + ! + ! amfox, 6 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 + + ! check (once) the cube-sphere geometry of get_ij_ind_from_latlon() + + if (root_proc .and. (.not. c3_tile_grid_checked)) then - ! 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 check_c3_tile_grid( N_catf, tile_coord_f, tile_grid_g ) - 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 ) + c3_tile_grid_checked = .true. + + 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, & + tile_coord_f%i_indg, tile_coord_f%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, & + tile_coord_f%i_indg, tile_coord_f%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(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 ) + + end if else allocate(N_tile_in_cell_ij_f(0,0)) ! for debugging end if @@ -421,7 +482,7 @@ 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, 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 ) @@ -430,7 +491,7 @@ subroutine get_enkf_increments( & 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, & 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, & @@ -2146,7 +2207,7 @@ 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, & + tile_coord_f, tile_grid_g, 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 ) @@ -2158,6 +2219,8 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & ! reichle, 2 May 2013 ! reichle, 11 Dec 2013 - added 'SMOS_fit_Tb*' obs species ! (needed for L4_SM_SMOS prototype product) + ! amfox, 6 Nov 2026 - renamed pert_grid_f to obs2tile_grid_f, which is tile_grid_f + ! for cube-sphere tile space (see get_enkf_increments()) ! ! ------------------------------------------------------------------- @@ -2175,7 +2238,7 @@ 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) :: obs2tile_grid_f integer, dimension(numprocs), intent(in) :: N_catl_vec integer, dimension(numprocs), intent(in) :: low_ind @@ -2250,7 +2313,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, & 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., & From 9e99e35c0c69e5047d753c0de4c09a600aacaf0c Mon Sep 17 00:00:00 2001 From: amfox37 Date: Fri, 6 Nov 2026 15:52:29 -0700 Subject: [PATCH 18/90] apply QC of Tb obs for non-land surfaces also in cube-sphere tile space (clsm_ensupd_upd_routines.F90, clsm_ensupd_enkf_update.F90) The QC of Tb obs for too much non-land (water, land ice) in the FOV was done for EASE grids only. In cube-sphere tile space a grid cell contains several tiles, whose frac_cell add up to the land fraction of the grid cell; average the land fraction of the grid cells in the FOV and count each grid cell once by weighting each tile with its share of the land in its grid cell (identical to EASE if there is one tile per grid cell). New optional input c3_tile_space in get_obs_pred(), because tile_grid_g there is the (lat/lon) pert grid. Needs correct frac_cell from nc4 tile files. 0-diff for EASE and lat/lon tile spaces. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + .../clsm_ensupd_enkf_update.F90 | 7 +- .../clsm_ensupd_upd_routines.F90 | 79 ++++++++++++++++++- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae57da84..6eb54d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 QC of Tb obs for non-land surfaces (water, land ice) in cube-sphere tile space, where it was not applied (not 0-diff for cube-sphere tile space with Tb obs; 0-diff for EASE and lat/lon tile spaces). - 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 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 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)). diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index c82c7533..4b960e2a 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -517,7 +517,8 @@ subroutine get_enkf_increments( & obs_param, & met_force, lai, cat_param, cat_progn, mwRTM_param, & N_obsl, Observations_l, Obs_pred_l, obsbias_ok, & - fcsterr_inflation_fac ) + fcsterr_inflation_fac, & + c3_tile_space = (index(tile_grid_g%gridtype,'c3')/=0) ) if (allocated(obsbias_ok)) deallocate(obsbias_ok) @@ -2128,6 +2129,10 @@ subroutine output_ObsFcstAna_wrapper( out_ObsFcstAna, & met_force, lai, cat_param, cat_progn, mwRTM_param, & N_obsl_tmp, Observations_l, Obs_pred_l ) + ! NOTE: c3_tile_space is not needed here; obs that fail the QC of Tb for non-land + ! surfaces were removed in the call to get_obs_pred() before the EnKF update + ! (amfox, 6 Nov 2026) + ! clean up if (associated(Obs_pred_l)) deallocate(Obs_pred_l) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index edeb2387..b3c33813 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1002,7 +1002,7 @@ subroutine get_obs_pred( & obs_param, & met_force, lai, cat_param, cat_progn, mwRTM_param, & N_obsl, Observations_l, Obs_pred_l, obsbias_ok, & - fcsterr_inflation_fac ) + fcsterr_inflation_fac, c3_tile_space ) ! Compute ensemble of measurement predictions from ensemble ! of tile-space Catchment prognostics. @@ -1025,6 +1025,8 @@ 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 optional input "c3_tile_space" and QC of Tb for non-land + ! surfaces in cube-sphere tile space implicit none @@ -1059,6 +1061,11 @@ subroutine get_obs_pred( & real, intent(in), optional :: fcsterr_inflation_fac + ! "tile_grid_g" is the pert grid (lat/lon for cube-sphere tile space), so tell + ! get_obs_pred() whether the tile space is cube-sphere (default: .false.) + + logical, intent(in), optional :: c3_tile_space + ! -------------------------------------------------------------------------------- ! ! locals @@ -1088,6 +1095,9 @@ subroutine get_obs_pred( & logical :: tmpRFI, tmpWater, tmpPeat, use_distance_weights + logical :: c3_tile_space_tmp + 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 @@ -1139,6 +1149,7 @@ subroutine get_obs_pred( & integer, dimension(:), allocatable :: ind_tmp real, dimension(:), allocatable :: tmp_ndst2, tmp_wFOV, tmp_weights, tmp_data + real, dimension(:), allocatable :: tmp_wcell ! cube-sphere tile space only ! dimension "N_catlH-[by-N_XXXX-]by-N_ens" ! (need to be communicated between processors) @@ -1150,6 +1161,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() @@ -1576,6 +1590,44 @@ subroutine get_obs_pred( & 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 (tile_coord_f must contain all tiles of the grid cell) + ! - amfox, 6 Nov 2026 + + c3_tile_space_tmp = .false. + + if (present(c3_tile_space)) c3_tile_space_tmp = c3_tile_space + + if (c3_tile_space_tmp .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) + + 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 + + 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)) @@ -1677,6 +1729,7 @@ subroutine get_obs_pred( & allocate(tmp_wFOV( N_catlH)) allocate(tmp_weights(N_catlH)) allocate(tmp_data( N_catlH)) + if (c3_tile_space_tmp) allocate(tmp_wcell(N_catlH)) do i=1,N_obsl @@ -1879,6 +1932,9 @@ subroutine get_obs_pred( & ! for EASE grids *ONLY*: screen for non-land surfaces (e.g., lakes) ! - reichle, 28 Mar 2015 + ! + ! and for cube-sphere tile space (see below) + ! - amfox, 6 Nov 2026 if (index(tile_grid_g%gridtype, 'EASEv') /=0) then @@ -1901,6 +1957,25 @@ subroutine get_obs_pred( & tmpWater = ( 1. - tmp_fraccell > EASE_max_water_frac ) + elseif (c3_tile_space_tmp) then + + ! cube-sphere tile space: screen for non-land surfaces as for EASE grids, + ! but a grid cell contains several tiles; average the land fraction of + ! the grid cells in the FOV (FOV-weighted) and count each grid cell once + ! by weighting each tile with its share of the land in its grid cell + ! (identical to EASE grids if there is one tile per grid cell) + ! - amfox, 6 Nov 2026 + + tmp_data(1:N_tmp) = land_frac_cell_lH(ind_tmp(1:N_tmp)) + + tmp_wcell(1:N_tmp) = tmp_wFOV(1:N_tmp) & + * tile_coord_lH(ind_tmp(1:N_tmp))%frac_cell / max( tmp_data(1:N_tmp), 1.e-10 ) + + call tile2obs_helper( & + N_tmp, tmp_wcell(1:N_tmp), tmp_data(1:N_tmp), tmp_fraccell) + + tmpWater = ( 1. - tmp_fraccell > EASE_max_water_frac ) + else tmpWater = .false. @@ -2024,6 +2099,8 @@ 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(tmp_wcell)) deallocate(tmp_wcell) + if (allocated(land_frac_cell_lH)) deallocate(land_frac_cell_lH) if (allocated(peat_lH)) deallocate(peat_lH) From 1f375874e18a3b5335b2095d2c280a16a127a65f Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Sat, 7 Nov 2026 15:23:49 -0500 Subject: [PATCH 19/90] tweaked init of obs2tile_grid_f; edited comments and error messages (LDAS_TileCoordRoutines.F90, clsm_ensupd_enkf_update.F90) --- .../clsm_ensupd_enkf_update.F90 | 37 ++++++----- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 65 +++++++++++-------- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 87a84446..25851230 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 @@ -278,12 +279,12 @@ subroutine get_enkf_increments( & integer, dimension(:,:), pointer :: N_tile_in_cell_ij_f integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij_f - ! grid that goes with N_tile_in_cell_ij_f and tile_num_in_cell_ij_f: - ! pert_grid_f, or tile_grid_f for cube-sphere tile space (amfox, 6 Nov 2026) + ! 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, 6 Nov 2026) type(grid_def_type) :: obs2tile_grid_f - logical, save :: c3_tile_grid_checked = .false. + logical, save :: c3_tile_grid_checked = .false. ! initialize integer :: i, n, n_e @@ -399,17 +400,17 @@ subroutine get_enkf_increments( & ! - 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()) - obs2tile_grid_f = pert_grid_f ! for cube-sphere tile space see below - + call init_grid_def_type( obs2tile_grid_f ) ! initialize to undefined grid + if ( (root_proc) .or. & (any(obs_param(1:N_obs_param)%FOV>FOV_threshold)) ) then if (index(tile_grid_g%gridtype,'c3')/=0) then - - ! cube-sphere tile space: map obs to tiles on the cube-sphere tile_grid_f, - ! not on the lat/lon pert_grid_f, because tiles do not nest in the cells of - ! pert_grid_f; each tile is inside the tile_grid_f cell given by - ! tile_coord%i_indg and tile_coord%j_indg (see get_tile_num_from_latlon()) + + ! 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) @@ -444,22 +445,29 @@ subroutine get_enkf_increments( & call get_number_of_tiles_in_cell_ij( N_catf, & tile_coord_f%i_indg, tile_coord_f%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, & tile_coord_f%i_indg, tile_coord_f%j_indg, & obs2tile_grid_f, maxval(N_tile_in_cell_ij_f), tile_num_in_cell_ij_f ) 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 + 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 ) @@ -2219,8 +2227,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & ! reichle, 2 May 2013 ! reichle, 11 Dec 2013 - added 'SMOS_fit_Tb*' obs species ! (needed for L4_SM_SMOS prototype product) - ! amfox, 6 Nov 2026 - renamed pert_grid_f to obs2tile_grid_f, which is tile_grid_f - ! for cube-sphere tile space (see get_enkf_increments()) + ! amfox, 6 Nov 2026 - renamed pert_grid_f to obs2tile_grid_f (only passed through to collect_obs()) ! ! ------------------------------------------------------------------- diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 41a05aaf..5917a0b0 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -5,7 +5,7 @@ ! 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, 6 Nov 2026 - added cube-sphere grid ("c3") to get_ij_ind_from_latlon() and +! amfox, 6 Nov 2026 - added cube-sphere grid ("c3") case to get_ij_ind_from_latlon() and ! get_tile_num_from_latlon(); added check_c3_tile_grid() ! ! ======================================================================== @@ -781,10 +781,11 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & ! meridional max distance (max_dist_x) ! - reichle, 2014/12/23 ! - ! added cube-sphere ("c3") tile_grid; tiles do not nest in the cells of a lat/lon + ! added case for cube-sphere ("c3") tile_grid; tiles do not nest in the cells of a lat/lon ! grid, so for cube-sphere tile space, tile_grid 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) + ! obtained from tile_coord%i_indg and tile_coord%j_indg). The LatLon pert_grid_f + ! that was used previously does not work for obs-to-tile mapping. ! - amfox, 6 Nov 2026 implicit none @@ -941,13 +942,15 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & ! are half the width and height of the bounding box. ! ! 2.) If there is no such tile, repeat 1.) for all tiles within the grid cells - ! that contain the 8 points at +/- half a grid cell (approx.) around + ! that contain 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. ! - ! 3.) If there is still no such tile, loop through all tiles of 1.) and 2.) - ! and find minimum distance (Minkowski norm) as for LatLon. This tile - ! is subject to the bounding box and max_dist check below. + ! 3.) If there is still no such tile, loop through all tiles within the grid + ! cells identified in 1.) and 2.) and find minimum distance (Minkowski norm). + ! + ! The tiles identified in this way are still subject to the bounding box and + ! max_dist checks below. ! ! If there are no land tiles in these grid cells, tile_num will not change ! from its initialized value. @@ -956,15 +959,17 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & N_cell_c3 = 1 - i_cell_c3(1) = i_ind + i_cell_c3(1) = i_ind j_cell_c3(1) = j_ind - do kk=1,9 + do kk=1,9 ! check tiles located within up to 9 grid cells - if (kk>N_cell_c3) exit + if (kk>N_cell_c3) exit ! exit loop through kk if a tile was found in Step 1.) do k=1,N_tile_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk)) + ! This block is Step 1.) for kk=1 and Step 2.) for kk=2,9 + this_tile_num = tile_num_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk),k) if ( tile_coord(this_tile_num)%min_lon <= lon(n) .and. & @@ -997,14 +1002,16 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & end if - end do + end do ! for k=1,.. - ! no tile found in grid cell that contains lat/lon: - ! add grid cells of 8 points around lat/lon - ! (tile_grid%dlon = 360/(4*N) is the approximate grid spacing, see LDAS_create_grid_g()) if (kk==1 .and. tile_num(n)==nodata_tilenum) then - + + ! no tile found for kk=1 (in grid cell that contains lat/lon): + ! add i,j indices of grid cells that contain 8 lat/lon points around lat(n)/lon(n) + ! (tile_grid%dlon = 360/(4*N) is the approximate grid spacing, see LDAS_create_grid_g()) + ! may result in repeated grid cells + tmp_dlat = 0.5*tile_grid%dlon tmp_dlon = tmp_dlat / max( cos( MAPL_PI/180. * lat(n) ), 0.1 ) @@ -1027,9 +1034,9 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & end if - end do + end do ! for kk=1,9 - ! no bounding box contains lat/lon: find minimum distance (Minkowski norm) + ! no bounding box contains lat/lon: find closest tile among those in 9 grid cells identified above if (tile_num(n)==nodata_tilenum) then @@ -1042,7 +1049,7 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & 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) - tmp_dist = tmp_dist_x + tmp_dist_y ! Minkowski norm + tmp_dist = tmp_dist_x + tmp_dist_y ! "closest": Minkowski norm if (tmp_dist Date: Sun, 8 Nov 2026 13:47:05 -0700 Subject: [PATCH 20/90] map obs to cube-sphere grid cells with MAPL_GetGlobalHorzIJIndex() and the ESMF grid instead of copied cube-sphere geometry; removed check_c3_tile_grid() (LDAS_TileCoordRoutines.F90, clsm_ensupd_enkf_update.F90, clsm_ensupd_read_obs.F90, GEOS_LandAssimGridComp.F90) - pass the grid attached to the land locstream (cube-sphere grid for c3 tile space) as optional c3_grid from LandAssim RUN through get_enkf_increments(), collect_obs(), read_obs(), the obs readers and get_tile_num_for_obs() to get_tile_num_from_latlon() - new get_ij_ind_from_latlon_c3() (vector of lat/lon, one MAPL call) and get_tile_num_from_latlon_c3() (c3 search moved out of get_tile_num_from_latlon(), processed in chunks; neighbouring grid cells that were already searched are skipped); EASE and LatLon code of get_tile_num_from_latlon() is again identical to develop - new init_c3_grid(), called once by all processes in get_enkf_increments(): the first MAPL_GridGetCorners() call for a grid is collective (halo exchange), and obs are mapped to tiles on root_proc only - removed copied MAPL constants and check_c3_tile_grid(); MAPL checks the grid and supports stretched grids Standalone test (Mac, C360 ESMF grid, 6 PETs, 2,688,020 points): grid cells and tile numbers identical to #245 for FOV 0 and 20 km; EASEv2 M36 identical to develop. Co-Authored-By: Claude Opus 5.5 --- .../GEOS_LandAssimGridComp.F90 | 8 +- .../clsm_ensupd_enkf_update.F90 | 58 +- .../clsm_ensupd_read_obs.F90 | 125 ++- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 780 ++++++++++++------ 4 files changed, 641 insertions(+), 330 deletions(-) diff --git a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 index 61c5f897..cb7fee12 100644 --- a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 +++ b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 @@ -1488,6 +1488,7 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) integer :: N_adapt_R type(MAPL_LocStream) :: locstream + type(ESMF_Grid) :: tile_space_grid ! grid attached to locstream (cube-sphere grid for c3) integer, dimension(:), allocatable :: obs_pert_adapt_param real, dimension(:,:), allocatable :: Pert_adapt_R @@ -1612,6 +1613,10 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_LocStreamGet(locstream, NT_LOCAL=N_catl,rc=status) _VERIFY(status) + ! Get grid of tile space (needed to map obs to tiles in cube-sphere tile space) + call MAPL_LocStreamGet(locstream, ATTACHEDGRID=tile_space_grid, rc=status) + _VERIFY(status) + ! Pointers to internals !---------------------- @@ -1931,7 +1936,8 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) 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) + N_adapt_R, obs_pert_adapt_param, Pert_adapt_R, & + c3_grid=tile_space_grid ) if (fresh_incr) then ! apply EnKF increments (incl. call to catch_calc_soil_moist but not to recompute_diagS()) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 25851230..e48f97dd 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -74,9 +74,12 @@ module clsm_ensupd_enkf_update use LDAS_TilecoordRoutines, ONLY: & get_number_of_tiles_in_cell_ij, & get_tile_num_in_cell_ij, & - check_c3_tile_grid, & + init_c3_grid, & grid2tile + use ESMF, ONLY: & + ESMF_Grid + use nr_ran2_gasdev, ONLY: & NRANDSEED @@ -163,12 +166,16 @@ subroutine get_enkf_increments( & cat_progn_incr, fresh_incr, & N_obsf, N_obsl, Observations_l, & N_adapt_R, obs_pert_adapt_param, Pert_adapt_R, & - Obs_pert ) + Obs_pert, c3_grid ) ! ------------------------------------------------------------- ! return increments instead of updated cat_progn ! reichle, 18 Oct 2005 + ! + ! added optional input c3_grid (ESMF grid of tile space), needed (only) to map obs + ! to tiles in cube-sphere tile space + ! amfox, 8 Nov 2026 implicit none @@ -251,6 +258,8 @@ subroutine get_enkf_increments( & real, dimension(N_obsl_max,N_ens), intent(out), optional :: Obs_pert + type(ESMF_Grid), intent(in), optional :: c3_grid ! needed for cube-sphere tile space + ! ---------------------------------------------- ! local variables @@ -284,7 +293,7 @@ subroutine get_enkf_increments( & type(grid_def_type) :: obs2tile_grid_f - logical, save :: c3_tile_grid_checked = .false. ! initialize + logical, save :: c3_grid_initialized = .false. ! initialize integer :: i, n, n_e @@ -402,6 +411,25 @@ subroutine get_enkf_increments( & 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_c3_grid()). - amfox, 8 Nov 2026 + + if ( (index(tile_grid_g%gridtype,'c3')/=0) .and. (.not. c3_grid_initialized) ) then + + if (.not. present(c3_grid)) then + + err_msg = 'cube-sphere tile space requires optional input c3_grid (ESMF grid)' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + call init_c3_grid( c3_grid, tile_grid_g ) + + c3_grid_initialized = .true. + + end if + if ( (root_proc) .or. & (any(obs_param(1:N_obs_param)%FOV>FOV_threshold)) ) then @@ -418,7 +446,7 @@ subroutine get_enkf_increments( & ! 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()) + ! grid cell of an obs (see get_ij_ind_from_latlon_c3()) ! ! amfox, 6 Nov 2026 @@ -429,16 +457,6 @@ subroutine get_enkf_increments( & obs2tile_grid_f%ur_lon = pert_grid_f%ur_lon obs2tile_grid_f%ur_lat = pert_grid_f%ur_lat - ! check (once) the cube-sphere geometry of get_ij_ind_from_latlon() - - if (root_proc .and. (.not. c3_tile_grid_checked)) then - - call check_c3_tile_grid( N_catf, tile_coord_f, tile_grid_g ) - - c3_tile_grid_checked = .true. - - 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 @@ -492,7 +510,8 @@ subroutine get_enkf_increments( & N_ens, N_catl, N_catf, N_obsl_max, & tile_coord_f, tile_grid_g, 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, & + c3_grid=c3_grid ) ! check for observations, found_obs_f=.true. if obs availalbe @@ -503,7 +522,7 @@ subroutine get_enkf_increments( & 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, & - N_obsl, Observations_l, found_obs_f ) + N_obsl, Observations_l, found_obs_f, c3_grid=c3_grid ) ! -------------------------------------------------------------------- @@ -2217,7 +2236,7 @@ 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, 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, c3_grid ) ! wrapper for output of original (unscaled) SMAP Tb observations into ! SMAP L4_SM "aup" (analysis update) @@ -2228,6 +2247,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & ! reichle, 11 Dec 2013 - added 'SMOS_fit_Tb*' obs species ! (needed for L4_SM_SMOS prototype product) ! amfox, 6 Nov 2026 - renamed pert_grid_f to obs2tile_grid_f (only passed through to collect_obs()) + ! amfox, 8 Nov 2026 - added optional c3_grid (only passed through to collect_obs()) ! ! ------------------------------------------------------------------- @@ -2266,6 +2286,8 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & type(cat_param_type), dimension(N_catl), intent(in) :: cat_param type(cat_progn_type), dimension(N_catl,N_ens), intent(in) :: cat_progn + type(ESMF_Grid), optional, intent(in) :: c3_grid + ! ------------------------------------------ ! local variables @@ -2324,7 +2346,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & 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., & - N_obsl_tmp, Observations_l, found_obs_f ) + N_obsl_tmp, Observations_l, found_obs_f, c3_grid=c3_grid ) ! write appropriate fields (according to 'option') into file diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index d2ce35a1..da2fb6e9 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -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, & @@ -432,7 +435,7 @@ subroutine read_obs_ae_l2_sm( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, ae_l2_sm, std_ae_l2_sm ) + found_obs, ae_l2_sm, std_ae_l2_sm, c3_grid ) ! Read observations of surface soil moisture from AMSR-E L2 files ! Set flag "found_obs" to true if observations are available @@ -468,6 +471,8 @@ subroutine read_obs_ae_l2_sm( & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -657,7 +662,7 @@ subroutine read_obs_ae_l2_sm( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num ) + tmp_tile_num, c3_grid=c3_grid ) ! ---------------------------------------------------------------- @@ -943,7 +948,7 @@ subroutine read_obs_ae_sm_LPRM( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, ae_sm_LPRM, std_ae_sm_LPRM ) + found_obs, ae_sm_LPRM, std_ae_sm_LPRM, c3_grid ) ! Read observations of surface soil moisture from AMSR-E sm LPRM files ! (Richard de Jeu, Vrije Universiteit Amsterdam) @@ -980,6 +985,8 @@ subroutine read_obs_ae_sm_LPRM( & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -1172,7 +1179,7 @@ subroutine read_obs_ae_sm_LPRM( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num ) + tmp_tile_num, c3_grid=c3_grid ) ! ---------------------------------------------------------------- @@ -1254,7 +1261,7 @@ subroutine read_obs_sm_ASCAT( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, sm_ASCAT, std_sm_ASCAT ) + found_obs, sm_ASCAT, std_sm_ASCAT, c3_grid ) !--------------------------------------------------------------------- ! @@ -1290,6 +1297,8 @@ subroutine read_obs_sm_ASCAT( & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -1485,7 +1494,7 @@ subroutine read_obs_sm_ASCAT( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num ) + tmp_tile_num, c3_grid=c3_grid ) ! ---------------------------------------------------------------- @@ -1565,7 +1574,7 @@ 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, & - found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time ) + found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time, c3_grid ) !--------------------------------------------------------------------- ! @@ -1608,6 +1617,8 @@ subroutine read_obs_sm_ASCAT_EUMET( & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -2065,7 +2076,7 @@ subroutine read_obs_sm_ASCAT_EUMET( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num ) + tmp_tile_num, c3_grid=c3_grid ) ! ---------------------------------------------------------------- @@ -2161,7 +2172,7 @@ 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, & this_obs_param, write_obslog, & - found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time ) + found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time, c3_grid ) ! Read H SAF ASCAT SSM CDR (H121) and ICDR (H139) from netCDF swath files. ! @@ -2218,6 +2229,8 @@ subroutine read_obs_sm_ASCAT_HSAF( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(obs_param_type), intent(in) :: this_obs_param logical, intent(in) :: write_obslog @@ -2635,7 +2648,7 @@ subroutine read_obs_sm_ASCAT_HSAF( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_valid, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num ) + tmp_tile_num, c3_grid=c3_grid ) do ii = 1, N_valid @@ -2795,7 +2808,7 @@ 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, & - found_obs, CYGNSS_sm, CYGNSS_sm_std, CYGNSS_lon, CYGNSS_lat, CYGNSS_time ) + found_obs, CYGNSS_sm, CYGNSS_sm_std, CYGNSS_lon, CYGNSS_lat, CYGNSS_time, c3_grid ) !--------------------------------------------------------------------- ! @@ -2835,6 +2848,8 @@ subroutine read_obs_sm_CYGNSS( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(obs_param_type), intent(in) :: this_obs_param logical, intent(in) :: write_obslog @@ -3224,7 +3239,7 @@ subroutine read_obs_sm_CYGNSS( & 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_tile_num, c3_grid=c3_grid ) ! ---------------------------------------------------------------- ! @@ -3516,7 +3531,7 @@ 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, & this_obs_param, & - found_obs, ts_LARC, std_ts_LARC ) + found_obs, ts_LARC, std_ts_LARC, c3_grid ) !--------------------------------------------------------------------- ! @@ -3541,6 +3556,8 @@ subroutine read_obs_LaRC_Tskin( & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -3714,7 +3731,7 @@ subroutine read_obs_LaRC_Tskin( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num ) + tmp_tile_num, c3_grid=c3_grid ) ! ---------------------------------------------------------------- @@ -4860,7 +4877,7 @@ 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, & - found_obs, isccp_tskin_gswp2_v1, std_isccp_tskin_gswp2_v1 ) + found_obs, isccp_tskin_gswp2_v1, std_isccp_tskin_gswp2_v1, c3_grid ) ! Read observations of land skin temperature from ISCCP data ! produced by Sarith on GSWP-2 grid @@ -4894,6 +4911,8 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -5027,7 +5046,7 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & tile_grid_d, 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) ) + tmp_tile_num(1:N_tmp), c3_grid=c3_grid ) ! ---------------------------------------------------------------- ! @@ -5550,7 +5569,7 @@ 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 ) + found_obs, SMOS_data, std_SMOS_data, SMOS_lon, SMOS_lat, c3_grid ) ! reader for preprocessed SMOS Tb and soil moisture (SM) files ! @@ -5603,6 +5622,8 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + logical, intent(in) :: write_obslog ! outputs: @@ -6182,7 +6203,7 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & N_obs, tmp_lat, tmp_lon, & this_obs_param, & tmp_tile_num, & - tmp_shift_lat, tmp_shift_lon ) + tmp_shift_lat, tmp_shift_lon, c3_grid=c3_grid ) ! -------------------------------------------------------------------------- ! @@ -6376,7 +6397,7 @@ 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, & this_obs_param, write_obslog, & - found_obs, MODIS_obs, std_MODIS_obs, MODIS_lon, MODIS_lat ) + found_obs, MODIS_obs, std_MODIS_obs, MODIS_lon, MODIS_lat, c3_grid ) ! read MODIS snow cover fraction observations on MODIS 0.05-degree climate ! modeling grid (CMG) @@ -6408,6 +6429,8 @@ subroutine read_obs_MODIS_SCF( & integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -6795,7 +6818,7 @@ subroutine read_obs_MODIS_SCF( & 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, c3_grid=c3_grid ) std_MODIS_obs = this_obs_param%errstd @@ -7440,7 +7463,7 @@ end subroutine read_MODIS_SCF_hdf subroutine read_obs_SMAP_FT( 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, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time ) + found_obs, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time, c3_grid ) ! 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) @@ -7469,6 +7492,8 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + logical, intent(in) :: write_obslog ! outputs: @@ -7939,7 +7964,7 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & tmp_lat(1:N_obs_kept(kk)), & tmp_lon(1:N_obs_kept(kk)), & this_obs_param, & - tmp_tile_num ) + tmp_tile_num, c3_grid=c3_grid ) ! -------------------------------------------------------------------------- ! @@ -8125,7 +8150,7 @@ 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, & 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, c3_grid ) ! read brightness temperature data within the assimilation window from one or more ! SMAP half-orbit h5 files (L1C, L1CE (Enhanced), or L2AP) @@ -8167,6 +8192,8 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + logical, intent(in) :: write_obslog ! outputs: @@ -9045,7 +9072,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & tmp_lon(1:N_obs_kept(kk)), & this_obs_param, & tmp_tile_num, & - tmp_shift_lat, tmp_shift_lon ) + tmp_shift_lat, tmp_shift_lon, c3_grid=c3_grid ) else @@ -9055,7 +9082,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & tmp_lat(1:N_obs_kept(kk)), & tmp_lon(1:N_obs_kept(kk)), & this_obs_param, & - tmp_tile_num) + tmp_tile_num, c3_grid=c3_grid) end if @@ -9851,7 +9878,7 @@ subroutine read_obs( & tile_grid_d, 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 ) + tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time, tmp_assim, c3_grid ) ! read observations and optionally scale observations to model clim ! @@ -9867,6 +9894,8 @@ subroutine read_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) + ! 8 Nov 2026 - added optional input c3_grid (ESMF grid of cube-sphere tile space) + ! (amfox) implicit none @@ -9892,6 +9921,8 @@ subroutine read_obs( & logical, intent(in) :: write_obslog + type(ESMF_Grid), intent(in), optional :: c3_grid ! needed for cube-sphere tile space + ! outputs: real, intent(out), dimension(N_catd) :: tmp_obs @@ -9941,7 +9972,7 @@ subroutine read_obs( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs ) + found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) ! scale observations to model climatology @@ -9962,7 +9993,7 @@ subroutine read_obs( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs ) + found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) ! scale observations to model climatology @@ -9983,7 +10014,7 @@ subroutine read_obs( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs ) + found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) ! scale observations to model climatology @@ -10003,7 +10034,7 @@ subroutine read_obs( & tile_grid_d, 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, c3_grid=c3_grid) ! scale observations to model climatology @@ -10024,7 +10055,7 @@ subroutine read_obs( & tile_grid_d, 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, c3_grid=c3_grid) ! scale observations to model climatology @@ -10045,7 +10076,7 @@ subroutine read_obs( & tile_grid_d, 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, c3_grid=c3_grid) ! scale observations to model climatology @@ -10065,7 +10096,7 @@ subroutine read_obs( & date_time, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs ) + found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) if (this_obs_param%scale .and. found_obs) then @@ -10190,7 +10221,7 @@ subroutine read_obs( & 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, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, c3_grid=c3_grid ) ! scale observations to model climatology @@ -10210,7 +10241,7 @@ subroutine read_obs( & 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, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, c3_grid=c3_grid ) ! scale observations to model climatology @@ -10229,7 +10260,7 @@ subroutine read_obs( & 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, & - found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, c3_grid=c3_grid ) case('SMAP_L1C_Tbh_A', 'SMAP_L1C_Tbv_A', & 'SMAP_L1C_Tbh_D', 'SMAP_L1C_Tbv_D', & @@ -10244,7 +10275,7 @@ subroutine read_obs( & 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, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time, c3_grid=c3_grid ) ! scale observations to model climatology @@ -10264,7 +10295,7 @@ subroutine read_obs( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs ) + found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) ! NOT IMPLEMENTED: scale observations to model climatology @@ -11357,7 +11388,7 @@ subroutine collect_obs( N_catf, tile_coord_f, tile_grid_f, 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 ) + N_obsl, Observations_l, found_obs_f, c3_grid ) ! check for observations that must be assimilated, ! collect into measurement vector @@ -11371,6 +11402,8 @@ 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 + ! 8 Nov 2026 - added optional input c3_grid (ESMF grid of cube-sphere tile space) + ! (amfox) implicit none @@ -11413,6 +11446,8 @@ subroutine collect_obs( logical, intent(out) :: found_obs_f + type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + ! ---------------------------- ! locals @@ -11478,7 +11513,7 @@ subroutine collect_obs( tile_grid_f, 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, c3_grid=c3_grid) if (scaled_obs) any_scaled_obs = .true. @@ -11864,7 +11899,7 @@ 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, & this_obs_param, & tile_num, & - shift_lat, shift_lon ) + shift_lat, shift_lon, c3_grid ) ! find one tile for each obs that "administers" the obs ! @@ -11872,6 +11907,10 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & ! (to be called from within obs readers) ! ! - reichle, 2015/02/20 + ! + ! added optional input c3_grid (ESMF grid of cube-sphere tile space), see + ! get_tile_num_from_latlon() + ! - amfox, 8 Nov 2026 implicit none @@ -11893,6 +11932,8 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & real, optional, intent(in) :: shift_lat real, optional, intent(in) :: shift_lon + + type(ESMF_Grid), optional, intent(in) :: c3_grid ! for cube-sphere tile space ! ------------------------ @@ -11954,7 +11995,7 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & call get_tile_num_from_latlon(N_catd, tile_coord, & tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_latlon, tmp_lat, tmp_lon, & - tile_num, max_dist_x, max_dist_y ) + tile_num, max_dist_x, max_dist_y, c3_grid=c3_grid ) end subroutine get_tile_num_for_obs diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 5917a0b0..f69e07cb 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -5,8 +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, 6 Nov 2026 - added cube-sphere grid ("c3") case to get_ij_ind_from_latlon() and -! get_tile_num_from_latlon(); added check_c3_tile_grid() +! amfox, 6 Nov 2026 - added cube-sphere grid ("c3") case to get_tile_num_from_latlon() +! amfox, 8 Nov 2026 - map lat/lon to cube-sphere grid cells with MAPL_GetGlobalHorzIJIndex() +! and the ESMF grid (get_ij_ind_from_latlon_c3(), init_c3_grid()) ! ! ======================================================================== @@ -32,7 +33,12 @@ module LDAS_TileCoordRoutines use MAPL, ONLY: & MAPL_ease_convert, & - MAPL_ease_extent + MAPL_ease_extent, & + MAPL_GridGet, & + MAPL_GetGlobalHorzIJIndex + + use ESMF, ONLY: & + ESMF_Grid use LDAS_ExceptionsMod, ONLY: & ldas_abort, & @@ -51,7 +57,8 @@ module LDAS_TileCoordRoutines public :: get_tile_num_in_ellipse public :: get_tile_num_from_latlon public :: get_ij_ind_from_latlon - public :: check_c3_tile_grid + public :: get_ij_ind_from_latlon_c3 + public :: init_c3_grid public :: tile2grid_simple public :: grid2tile public :: tile_mask_grid @@ -768,7 +775,7 @@ 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, & - tile_num, max_dist_x, max_dist_y ) + tile_num, max_dist_x, max_dist_y, c3_grid ) ! bug fix re. "check that lat/lon is inside tile_grid" ! - reichle, 2005/11/17 @@ -781,12 +788,9 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & ! meridional max distance (max_dist_x) ! - reichle, 2014/12/23 ! - ! added case for cube-sphere ("c3") tile_grid; tiles do not nest in the cells of a lat/lon - ! grid, so for cube-sphere tile space, tile_grid 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). The LatLon pert_grid_f - ! that was used previously does not work for obs-to-tile mapping. - ! - amfox, 6 Nov 2026 + ! added cube-sphere ("c3") tile_grid, see get_tile_num_from_latlon_c3(); + ! requires optional input "c3_grid" (ESMF grid of cube-sphere tile space) + ! - amfox, 8 Nov 2026 implicit none @@ -807,6 +811,7 @@ 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] + type(ESMF_Grid), optional, intent(in) :: c3_grid ! for "c3" tile_grid ! local variables @@ -821,13 +826,6 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & real :: tmp_dist_x, min_dist_x real, dimension(N_latlon) :: max_dist_tmp_x - ! for cube-sphere tile_grid - - integer :: ii, jj, kk, N_cell_c3 - integer, dimension(9) :: i_cell_c3, j_cell_c3 - - real :: tmp_hx, tmp_hy, tmp_dlon, tmp_dlat - character(len=*), parameter :: Iam = 'get_tile_num_from_latlon' character(len=400) :: err_msg @@ -843,6 +841,26 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & tile_num = nodata_tilenum ! initialize to negative value + ! cube-sphere tile_grid: tiles do not nest in grid cells of a lat/lon grid, + ! use bounding boxes of tiles (amfox, 8 Nov 2026) + + if (index(tile_grid%gridtype, 'c3')/=0) then + + if (.not. present(c3_grid)) then + + err_msg = 'cube-sphere ("c3") tile_grid requires optional input c3_grid (ESMF grid)' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + call get_tile_num_from_latlon_c3( c3_grid, tile_coord, & + tile_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 + + end if + ! loop through observations do n=1,N_latlon @@ -929,167 +947,304 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & end do - elseif (index(tile_grid%gridtype, 'c3')/=0) then - - ! 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 there is no such tile, repeat 1.) for all tiles within the grid cells - ! that contain 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. - ! - ! 3.) If there is still no such tile, loop through all tiles within the grid - ! cells identified in 1.) and 2.) and find minimum distance (Minkowski norm). - ! - ! The tiles identified in this way are still subject to the bounding box and - ! max_dist checks below. - ! - ! If there are no land tiles in these grid cells, tile_num will not change - ! from its initialized value. - ! - ! amfox, 6 Nov 2026 - - N_cell_c3 = 1 - - i_cell_c3(1) = i_ind - j_cell_c3(1) = j_ind - - do kk=1,9 ! check tiles located within up to 9 grid cells - - if (kk>N_cell_c3) exit ! exit loop through kk if a tile was found in Step 1.) + else + + call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown grid type') + + end if + - do k=1,N_tile_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk)) + ! check whether lat/lon is inside bounding box of given tile + ! (if domain consists of a single tile and tile_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 + + ! return a valid tile_num even if lat/lon is not within the + ! bounding box of the chosen tile, as long as lat/lon is no further + ! from the com_lat/com_lon of the tile than max_dist + ! - reichle, 2008/03/28 + + ! this might be important for assimilation of 36km EASE grid obs + ! into the 9 km EASE grid tile space (because the lat/lon of + ! the 36 km EASE grid obs is exactly on the corners of four + ! 9 km EASE grid cells) + ! - reichle, 2013/06/21 - ! This block is Step 1.) for kk=1 and Step 2.) for kk=2,9 - - this_tile_num = tile_num_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk),k) + if (tile_num(n)>0) then - if ( tile_coord(this_tile_num)%min_lon <= lon(n) .and. & - tile_coord(this_tile_num)%max_lon >= lon(n) .and. & - tile_coord(this_tile_num)%min_lat <= lat(n) .and. & - tile_coord(this_tile_num)%max_lat >= lat(n) ) 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 > max_dist_tmp_x(n) .or. & + min_dist_y > max_dist_tmp_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 if + + end do + + end subroutine get_tile_num_from_latlon + + ! ******************************************************************* + + subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & + tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & + max_dist_x, max_dist_y, tile_num ) - ! lat/lon is inside bounding box of tile + ! find tile_num for lat/lon in cube-sphere ("c3") tile space, see get_tile_num_from_latlon() + ! + ! tiles do not nest in the cells of a lat/lon grid, so for cube-sphere tile space, + ! tile_grid 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). c3_grid 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 there is no such tile, repeat 1.) for all tiles within the grid cells + ! that contain 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. Grid cells that were already searched are skipped. + ! + ! 3.) If there is still no such tile, loop through all tiles within the grid + ! cells identified in 1.) and 2.) and find minimum distance (Minkowski norm). + ! + ! The tiles identified in this way are still subject to the bounding box and + ! max_dist checks of get_tile_num_from_latlon(). + ! + ! 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 for 2.) per chunk. + ! + ! amfox, 6 Nov 2026 + ! amfox, 8 Nov 2026 - moved here from get_tile_num_from_latlon(); grid cells from + ! MAPL_GetGlobalHorzIJIndex() (no copied cube-sphere geometry) - 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) + implicit none - tmp_hx = max( tmp_hx, 1.e-6 ) ! avoid division by zero - tmp_hy = max( tmp_hy, 1.e-6 ) + type(ESMF_Grid), intent(in) :: c3_grid - 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) + type(tile_coord_type), dimension(:), pointer :: tile_coord ! input - tmp_dist = (tmp_dist_x/tmp_hx)**2 + (tmp_dist_y/tmp_hy)**2 + type(grid_def_type), intent(in) :: tile_grid - if (tmp_dist1) & + 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, 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 + + if (tile_num(n)==nodata_tilenum) then + + do kk=1,N_cell + + do k=1,N_tile_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk)) + + this_tile_num = tile_num_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk),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) + + tmp_dist = tmp_dist_x + tmp_dist_y ! "closest": Minkowski norm + + if (tmp_dist0) then @@ -1097,26 +1252,114 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & 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 ) - + lat(n) > tile_coord(tile_num(n))%max_lat ) + too_far_away = ( & - min_dist_x > max_dist_tmp_x(n) .or. & - min_dist_y > max_dist_tmp_y ) - + 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 if - + + end do + end do - - end subroutine get_tile_num_from_latlon - + + deallocate( i_ind, j_ind, ind_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, 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 grid cells of the cube-sphere tile_grid, 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, 8 Nov 2026 (moved here from get_tile_num_from_latlon()) + + 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 + + integer, dimension(tile_grid%N_lon,tile_grid%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 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_c3_grid() must have been called by all processors. + ! + ! amfox, 8 Nov 2026 - x = x/max_xyz - y = y/max_xyz - z = z/max_xyz + implicit none - ! find face and coordinates on face (points on edges of faces are assigned - ! in the order of faces 1,...,6) + type(ESMF_Grid), intent(in) :: c3_grid - if (abs(x-1.d0) <= epsilon(1.d0)) then + type(grid_def_type), intent(in) :: tile_grid - face = 1 - xval = y - yval = z + integer, intent(in) :: N_latlon - elseif (abs(y-1.d0) <= epsilon(1.d0)) then + real, dimension(N_latlon), intent(in) :: lat, lon ! [deg] - face = 2 - xval = -x - yval = z + integer, dimension(N_latlon), intent(out) :: i_ind, j_ind - elseif (abs(z-1.d0) <= epsilon(1.d0)) then + ! local variables - face = 3 - xval = -x - yval = -y + type(ESMF_Grid) :: tmp_grid - elseif (abs(x+1.d0) <= epsilon(1.d0)) then + real*8, dimension(:), allocatable :: tmp_lat, tmp_lon - face = 4 - xval = -z - yval = -y + integer :: status - elseif (abs(y+1.d0) <= epsilon(1.d0)) then + character(len=*), parameter :: Iam = 'get_ij_ind_from_latlon_c3' + character(len=400) :: err_msg - face = 5 - xval = -z - yval = x + ! ------------------------------------------------------------- - else ! z = -1 + if (N_latlon<1) return - face = 6 - xval = y - yval = x + ! convert lat/lon from [deg] to [rad] - end if + allocate( tmp_lat(N_latlon), tmp_lon(N_latlon) ) - i_indg_c3 = ceiling( (atan(xval/sqr2) + alpha)/dalpha ) - j_indg_c3 = ceiling( (atan(yval/sqr2) + alpha)/dalpha ) + tmp_lat = real(lat,8)*(MAPL_PI_R8/180.d0) + tmp_lon = real(lon,8)*(MAPL_PI_R8/180.d0) - i_indg_c3 = min( max(i_indg_c3, 1), N_c3 ) - j_indg_c3 = min( max(j_indg_c3, 1), N_c3 ) + (face-1)*N_c3 + ! MAPL_GetGlobalHorzIJIndex() needs intent(inout) for the grid (to store the grid corners + ! as attributes, see init_c3_grid()) --> pass a copy of the ESMF grid handle (same grid) - ! convert to index into array defined by tile_grid_d + tmp_grid = c3_grid - i_ind = i_indg_c3 - tile_grid%i_offg - (tile_grid%ind_base - 1) - j_ind = j_indg_c3 - tile_grid%j_offg - (tile_grid%ind_base - 1) + call MAPL_GetGlobalHorzIJIndex( N_latlon, i_ind, j_ind, lonR8=tmp_lon, latR8=tmp_lat, & + Grid=tmp_grid, rc=status ) - else + if (status/=0) then - call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown grid type') + err_msg = 'MAPL_GetGlobalHorzIJIndex() failed' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - - end subroutine get_ij_ind_from_latlon - + + ! convert to index into array defined by tile_grid + + i_ind = i_ind - tile_grid%i_offg - (tile_grid%ind_base - 1) + j_ind = j_ind - tile_grid%j_offg - (tile_grid%ind_base - 1) + + ! make sure that i/j_ind is within bounds + + i_ind = min( max(i_ind, 1), tile_grid%N_lon ) + j_ind = min( max(j_ind, 1), tile_grid%N_lat ) + + deallocate( tmp_lat, tmp_lon ) + + end subroutine get_ij_ind_from_latlon_c3 + ! ******************************************************************* - subroutine check_c3_tile_grid( N_tile, tile_coord, tile_grid ) + subroutine init_c3_grid( c3_grid, tile_grid ) - ! check the cube-sphere geometry supported in get_ij_ind_from_latlon(): - ! map center-of-mass lat/lon of all tiles to the cube-sphere tile_grid and count - ! the tiles for which the resulting i,j indices differs from those in tile_coord - ! (tile_coord%i_indg and tile_coord%j_indg). + ! 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) ! - ! The geometry in get_ij_ind_from_latlon() is for gnomonic, equal-edge cube-sphere - ! grids with pi/18 shift of longitude. For other cube-sphere grids (e.g., stretched - ! grids), most tiles do not match, and obs cannot be mapped to tiles --> abort. + ! 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): ! - ! A few tiles do not match because their center-of-mass is outside of (or on the - ! edge of) their grid cell, e.g., 23 of 1188020 land tiles for CF0360. + ! 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. ! - ! amfox, 6 Nov 2026 + ! amfox, 8 Nov 2026 implicit none - integer, intent(in) :: N_tile + type(ESMF_Grid), intent(in) :: c3_grid - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input - - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: tile_grid ! local variables - real, parameter :: max_frac_mismatch = 0.001 ! abort if more tiles do not match + type(ESMF_Grid) :: tmp_grid + + real*8, dimension(0) :: tmp_lat, tmp_lon - integer :: n, i_ind, j_ind, off_i, off_j, N_mismatch + integer, dimension(0) :: tmp_i_ind, tmp_j_ind - character(len=*), parameter :: Iam = 'check_c3_tile_grid' + integer, dimension(3) :: dims + + integer :: status + + character(len=*), parameter :: Iam = 'init_c3_grid' character(len=400) :: err_msg - ! ----------------------------------------------------------- + ! ------------------------------------------------------------- - ! adjust for 0-based indexing (as in get_number_of_tiles_in_cell_ij()) + tmp_grid = c3_grid ! copy of ESMF grid handle (same grid), see get_ij_ind_from_latlon_c3() - off_i = tile_grid%i_offg + (tile_grid%ind_base - 1) - off_j = tile_grid%j_offg + (tile_grid%ind_base - 1) + ! check grid size (N-by-6*N for cube-sphere grid) - N_mismatch = 0 + dims = 0 - do n=1,N_tile + call MAPL_GridGet( tmp_grid, globalCellCountPerDim=dims, rc=status ) - call get_ij_ind_from_latlon( tile_grid, tile_coord(n)%com_lat, tile_coord(n)%com_lon, & - i_ind, j_ind ) + if (status/=0) then - if ( (i_ind /= tile_coord(n)%i_indg - off_i) .or. & - (j_ind /= tile_coord(n)%j_indg - off_j) ) N_mismatch = N_mismatch + 1 + err_msg = 'MAPL_GridGet() failed' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - end do + end if - if (logit) write (logunit,*) trim(Iam), ': number of tiles = ', N_tile, & - ', number of tiles w/ center-of-mass not in grid cell tile_coord%[i,j]_indg = ', N_mismatch - if (logit) write (logunit,*) + if ( (dims(1)/=tile_grid%N_lon) .or. (dims(2)/=tile_grid%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%N_lon, tile_grid%N_lat + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if - if (real(N_mismatch) > max_frac_mismatch*real(N_tile)) then + ! check grid and store grid corners as grid attributes (on all processors) - write (err_msg,'(A,i8,A,i8,A)') 'center-of-mass of ', N_mismatch, ' out of ', N_tile, & - ' tiles not in cube-sphere grid cell tile_coord%[i,j]_indg]; only gnomonic cube-sphere ' // & - 'grids w/ pi/18 shift of longitude (not stretched) are supported.' + 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 - end subroutine check_c3_tile_grid + if (logit) write (logunit,*) trim(Iam), ': cube-sphere grid ready for obs-to-tile mapping, size = ', dims(1:2) + if (logit) write (logunit,*) + + end subroutine init_c3_grid ! ******************************************************************* From 2c1caa2fc7a6f35f2c74e94eb826287d96e70d8c Mon Sep 17 00:00:00 2001 From: amfox37 Date: Sun, 8 Nov 2026 13:47:55 -0700 Subject: [PATCH 21/90] c3 obs-to-tile fallback: choose closest tile only among tiles within max_dist (LDAS_TileCoordRoutines.F90) In Step 3 of get_tile_num_from_latlon_c3() (no tile bounding box contains the obs), the closest tile (Minkowski norm) was chosen among all candidate tiles and then dropped if it failed the per-axis max_dist check, even if another candidate passed it. Now only candidates within max_dist_x and max_dist_y are considered (cube-sphere tile space only; review finding 1). Co-Authored-By: Claude Opus 5.5 --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index f69e07cb..ee148719 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -1024,10 +1024,12 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! neighboring grid cell. Grid cells that were already searched are skipped. ! ! 3.) If there is still no such tile, loop through all tiles within the grid - ! cells identified in 1.) and 2.) and find minimum distance (Minkowski norm). + ! 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(). + ! 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. @@ -1039,6 +1041,9 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! amfox, 6 Nov 2026 ! amfox, 8 Nov 2026 - moved here from get_tile_num_from_latlon(); grid cells from ! MAPL_GetGlobalHorzIJIndex() (no copied cube-sphere geometry) + ! amfox, 8 Nov 2026 - Step 3.) considers only tiles within max_dist (otherwise the + ! closest tile could fail the max_dist check while another tile + ! within max_dist would pass it) implicit none @@ -1206,7 +1211,7 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & 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 + ! in all grid cells identified above that are within max_dist if (tile_num(n)==nodata_tilenum) then @@ -1219,6 +1224,10 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & 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_dist Date: Sun, 8 Nov 2026 13:49:05 -0700 Subject: [PATCH 22/90] c3 obs-to-tile mapping: also search grid cells within max_dist of the obs (LDAS_TileCoordRoutines.F90) In Step 2 of get_tile_num_from_latlon_c3() (no tile bounding box in the obs's grid cell contains the obs), the 8 points at +/- half a grid cell could miss grid cells that hold tiles within max_dist, so the obs was dropped although develop kept it. Step 2 now also searches the grid cells of a lattice of points over lat/lon +/- max_dist (spacing at most a quarter grid cell; at most N_lattice_max intervals on either side), mapped to grid cells with one MAPL call per batch of at most N_pts_max points. For FOV=0 (max_dist=0), the lattice is just the obs and the result is unchanged (cube-sphere tile space only; review finding 2). Co-Authored-By: Claude Opus 5.5 --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 197 ++++++++++++++++--------- 1 file changed, 131 insertions(+), 66 deletions(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index ee148719..4653c1b2 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -1019,9 +1019,12 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! are half the width and height of the bounding box. ! ! 2.) If there is no such tile, repeat 1.) for all tiles within the grid cells - ! that contain the 8 lat/lon points at +/- half a grid cell (approx.) around + ! 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. Grid cells that were already searched are skipped. + ! 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.), + ! so that Step 3.) can find all tiles within max_dist. Grid cells that were + ! already searched are skipped. ! ! 3.) If there is still no such tile, loop through all tiles within the grid ! cells identified in 1.) and 2.) and find minimum distance (Minkowski norm) @@ -1036,7 +1039,8 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! ! 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 for 2.) per chunk. + ! therefore processed in chunks, with one call for 1.) and one call per batch of at + ! most N_pts_max points for 2.). ! ! amfox, 6 Nov 2026 ! amfox, 8 Nov 2026 - moved here from get_tile_num_from_latlon(); grid cells from @@ -1044,6 +1048,8 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! amfox, 8 Nov 2026 - Step 3.) considers only tiles within max_dist (otherwise the ! closest tile could fail the max_dist check while another tile ! within max_dist would pass it) + ! amfox, 8 Nov 2026 - Step 2.) also searches the grid cells within max_dist (the 8 points + ! alone can miss grid cells with tiles within max_dist) implicit none @@ -1072,17 +1078,25 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & integer, parameter :: N_chunk = 10000 ! max number of lat/lon per chunk - integer :: n, nn, k, kk, ii, jj, this_tile_num + 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 = 100000 ! 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 + real :: tmp_dist_x, tmp_dist_y, tmp_dlon, tmp_dlat, tmp_slon, tmp_slat - integer, dimension(9) :: i_cell_c3, j_cell_c3 + integer, dimension(N_cell_max) :: i_cell_c3, j_cell_c3 - integer, dimension(:), allocatable :: i_ind, j_ind, ind_nbr, i_ind_nbr, j_ind_nbr + 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 @@ -1090,9 +1104,9 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & tile_num = nodata_tilenum ! initialize to negative value - allocate( i_ind(N_chunk), j_ind(N_chunk), ind_nbr(N_chunk) ) + 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(8*N_chunk), j_ind_nbr(8*N_chunk), tmp_lat(8*N_chunk), tmp_lon(8*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 @@ -1145,106 +1159,157 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & end do - ! Step 2.): add grid cells that contain 8 lat/lon points around lat/lon - ! (tile_grid%dlon = 360/(4*N) is the approximate grid spacing, see LDAS_create_grid_g()) + ! Step 2.): add grid cells that contain points around lat/lon: + ! + ! (i) 8 points at +/- half a grid cell (approx.) around lat/lon + ! (tile_grid%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 - kk = 0 + do while (nn_start<=N_nbr) - do nn=1,N_nbr + ! points for lat/lon ind_nbr(nn_start:nn_end) - n = ind_start - 1 + ind_nbr(nn) + kk = 0 + nn_end = nn_start - 1 - tmp_dlat = 0.5*tile_grid%dlon - tmp_dlon = tmp_dlat / max( cos( MAPL_PI/180. * lat(n) ), 0.1 ) + do nn=nn_start,N_nbr - do ii=-1,1 - do jj=-1,1 + n = ind_start - 1 + ind_nbr(nn) - if (ii==0 .and. jj==0) cycle + tmp_dlat = 0.5*tile_grid%dlon + tmp_dlon = tmp_dlat / max( cos( MAPL_PI/180. * lat(n) ), 0.1 ) - kk = kk + 1 + tmp_slat = 0.25*tile_grid%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 - tmp_lat(kk) = lat(n) + real(jj)*tmp_dlat - tmp_lon(kk) = lon(n) + real(ii)*tmp_dlon + ! (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 - end do + call get_ij_ind_from_latlon_c3( c3_grid, tile_grid, kk, & + tmp_lat(1:kk), tmp_lon(1:kk), i_ind_nbr(1:kk), j_ind_nbr(1:kk) ) - call get_ij_ind_from_latlon_c3( c3_grid, tile_grid, kk, & - tmp_lat(1:kk), tmp_lon(1:kk), i_ind_nbr(1:kk), j_ind_nbr(1:kk) ) + kk = 0 - do nn=1,N_nbr + do nn=nn_start,nn_end - n = ind_start - 1 + ind_nbr(nn) + n = ind_start - 1 + ind_nbr(nn) - ! list of unique grid cells, starting with the grid cell that contains lat/lon + ! list of unique grid cells, starting with the grid cell that contains lat/lon - N_cell = 1 + N_cell = 1 - i_cell_c3(1) = i_ind(ind_nbr(nn)) - j_cell_c3(1) = j_ind(ind_nbr(nn)) + i_cell_c3(1) = i_ind(ind_nbr(nn)) + j_cell_c3(1) = j_ind(ind_nbr(nn)) - do k=1,8 + do k=1,N_pts_nbr(nn) - kk = 8*(nn-1) + k + 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 + 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 + N_cell = N_cell + 1 - i_cell_c3(N_cell) = i_ind_nbr(kk) - j_cell_c3(N_cell) = j_ind_nbr(kk) + i_cell_c3(N_cell) = i_ind_nbr(kk) + j_cell_c3(N_cell) = j_ind_nbr(kk) - end do + end do - ! Step 2.): tiles within neighboring grid cells (grid cell 1 was searched in Step 1.) + ! Step 2.): tiles within additional grid cells (grid cell 1 was searched in Step 1.) - min_dist = 1.e10 ! initialize + 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, 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)) ) + 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, 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 + ! 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 + if (tile_num(n)==nodata_tilenum) then - do kk=1,N_cell + do mm=1,N_cell - do k=1,N_tile_in_cell_ij(i_cell_c3(kk),j_cell_c3(kk)) + 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(kk),j_cell_c3(kk),k) + 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) + 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) + ! 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 + 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 + tmp_dist = tmp_dist_x + tmp_dist_y ! "closest": Minkowski norm - if (tmp_dist Date: Sun, 8 Nov 2026 13:50:19 -0700 Subject: [PATCH 23/90] build obs-to-tile tables in get_enkf_increments() only on root_proc; removed unused N_tile_in_cell_ij, tile_num_in_cell_ij in cat_enkf_increments() (clsm_ensupd_enkf_update.F90, clsm_ensupd_upd_routines.F90, clsm_ensupd_read_obs.F90) The tables N_tile_in_cell_ij_f, tile_num_in_cell_ij_f are used only in read_obs(), which collect_obs() calls on root_proc only. For FOV>~0, get_obs_pred() computes its own tables for get_tile_num_in_ellipse() (the "tile_num_in_circle" mentioned in the comment no longer exists). The "FOV>FOV_threshold" condition for building the tables on all processes is therefore obsolete. 0-diff. Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 | 14 ++++++-------- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 3 +-- .../clsm_ensupd_upd_routines.F90 | 6 ------ 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index e48f97dd..ae45eb71 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -104,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 @@ -405,9 +404,10 @@ 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()) + ! from lat/lon to tiles. This needs to be done only by root process + ! (because of call to read_obs() in collect_obs()). + ! (For 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, 8 Nov 2026) call init_grid_def_type( obs2tile_grid_f ) ! initialize to undefined grid @@ -430,8 +430,7 @@ subroutine get_enkf_increments( & end if - if ( (root_proc) .or. & - (any(obs_param(1:N_obs_param)%FOV>FOV_threshold)) ) then + if (root_proc) then if (index(tile_grid_g%gridtype,'c3')/=0) then @@ -2273,8 +2272,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & 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 diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index da2fb6e9..943a1866 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -11426,8 +11426,7 @@ subroutine collect_obs( type(grid_def_type), intent(in) :: tile_grid_f ! 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 diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index edeb2387..20a370d5 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -3729,9 +3729,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 +5555,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. From b4045d7dff37213be12de828f1fc72603fe8f28c Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Sun, 8 Nov 2026 17:35:05 -0500 Subject: [PATCH 24/90] renamed a couple of variables and edited comments for clarity (clsm_ensupd_enkf_update.F90, clsm_ensupd_upd_routines.F90) --- .../clsm_ensupd_enkf_update.F90 | 6 +- .../clsm_ensupd_upd_routines.F90 | 56 ++++++++++++------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 4b960e2a..97a76cbe 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -2129,9 +2129,9 @@ subroutine output_ObsFcstAna_wrapper( out_ObsFcstAna, & met_force, lai, cat_param, cat_progn, mwRTM_param, & N_obsl_tmp, Observations_l, Obs_pred_l ) - ! NOTE: c3_tile_space is not needed here; obs that fail the QC of Tb for non-land - ! surfaces were removed in the call to get_obs_pred() before the EnKF update - ! (amfox, 6 Nov 2026) + ! NOTE: no need to pass c3_tile_space into get_obs_pred() here; obs that fail the QC + ! of Tb for non-land surfaces were already removed in the call to get_obs_pred() + ! before the EnKF update (amfox, 6 Nov 2026) ! clean up diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index b3c33813..45be43eb 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1061,7 +1061,7 @@ subroutine get_obs_pred( & real, intent(in), optional :: fcsterr_inflation_fac - ! "tile_grid_g" is the pert grid (lat/lon for cube-sphere tile space), so tell + ! "tile_grid_g" is the pert grid (which is lat/lon for cube-sphere tile space), so tell ! get_obs_pred() whether the tile space is cube-sphere (default: .false.) logical, intent(in), optional :: c3_tile_space @@ -1074,7 +1074,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 @@ -1149,7 +1149,7 @@ subroutine get_obs_pred( & integer, dimension(:), allocatable :: ind_tmp real, dimension(:), allocatable :: tmp_ndst2, tmp_wFOV, tmp_weights, tmp_data - real, dimension(:), allocatable :: tmp_wcell ! cube-sphere tile space only + real, dimension(:), allocatable :: tmp_wtmp ! cube-sphere tile space only ! dimension "N_catlH-[by-N_XXXX-]by-N_ens" ! (need to be communicated between processors) @@ -1608,6 +1608,10 @@ subroutine get_obs_pred( & 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. @@ -1619,6 +1623,8 @@ subroutine get_obs_pred( & 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 @@ -1729,7 +1735,8 @@ subroutine get_obs_pred( & allocate(tmp_wFOV( N_catlH)) allocate(tmp_weights(N_catlH)) allocate(tmp_data( N_catlH)) - if (c3_tile_space_tmp) allocate(tmp_wcell(N_catlH)) + + if (c3_tile_space_tmp) allocate(tmp_wtmp(N_catlH)) do i=1,N_obsl @@ -1930,11 +1937,9 @@ subroutine get_obs_pred( & end if - ! for EASE grids *ONLY*: screen for non-land surfaces (e.g., lakes) - ! - reichle, 28 Mar 2015 - ! - ! and for cube-sphere tile space (see below) - ! - amfox, 6 Nov 2026 + ! for EASE and cube-sphere grids *ONLY*: screen for non-land surfaces (e.g., lakes) + ! - reichle, 28 Mar 2015 (EASE) + ! - amfox, 6 Nov 2026 (cube-sphere) if (index(tile_grid_g%gridtype, 'EASEv') /=0) then @@ -1955,7 +1960,7 @@ subroutine get_obs_pred( & ! 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 ) + tmpWater = ( 1. - tmp_fraccell > Tb_max_nonland_frac ) elseif (c3_tile_space_tmp) then @@ -1964,21 +1969,32 @@ subroutine get_obs_pred( & ! the grid cells in the FOV (FOV-weighted) and count each grid cell once ! by weighting each tile with its share of the land in its grid cell ! (identical to EASE grids if there is one tile per grid cell) + ! + ! ASSUMPTION: + ! - grid cells have the same area (or at least have nearly identical + ! areas) in the neighborhood surrounding the obs; + ! regular cube-sphere grid cellcell areas differ by ~1-2% within ~0.5 deg; + ! NEEDS REVISITING for stretched cube-sphere grids + ! ! - amfox, 6 Nov 2026 tmp_data(1:N_tmp) = land_frac_cell_lH(ind_tmp(1:N_tmp)) + + ! weight each tile's contribution by (1) FOV and (2) area fraction of land tile w.r.t. all land in grid cell + + tmp_wtmp(1:N_tmp) = & + ( tmp_wFOV(1:N_tmp) & ! (1) + * tile_coord_lH(ind_tmp(1:N_tmp))%frac_cell / max( tmp_data(1:N_tmp), 1.e-10 ) ) ! (2) + + call tile2obs_helper( & + N_tmp, tmp_wtmp(1:N_tmp), tmp_data(1:N_tmp), tmp_fraccell) - tmp_wcell(1:N_tmp) = tmp_wFOV(1:N_tmp) & - * tile_coord_lH(ind_tmp(1:N_tmp))%frac_cell / max( tmp_data(1:N_tmp), 1.e-10 ) - - call tile2obs_helper( & - N_tmp, tmp_wcell(1:N_tmp), tmp_data(1:N_tmp), tmp_fraccell) - - tmpWater = ( 1. - tmp_fraccell > EASE_max_water_frac ) + tmpWater = ( 1. - tmp_fraccell > Tb_max_nonland_frac ) else - - tmpWater = .false. + + 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 @@ -2099,7 +2115,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(tmp_wcell)) deallocate(tmp_wcell) + if (allocated(tmp_wtmp)) deallocate(tmp_wtmp) if (allocated(land_frac_cell_lH)) deallocate(land_frac_cell_lH) if (allocated(peat_lH)) deallocate(peat_lH) From 52d84d302425cd7ef13a02cda28b7197c3ccd9fd Mon Sep 17 00:00:00 2001 From: amfox37 Date: Sun, 8 Nov 2026 16:18:12 -0700 Subject: [PATCH 25/90] reject stretched cube-sphere grids in init_c3_grid(); corrected comments about the grid-cell search and stretched grids (LDAS_TileCoordRoutines.F90) The search for nearby grid cells in get_tile_num_from_latlon_c3() uses the grid spacing of an unstretched grid and misses many tiles where a stretched grid is finer (synthetic C360 test, stretch factor 8: 6,471 of 10,000 obs within max_dist rejected). Stretched grids are now rejected with a clear error message instead. The quarter-cell lattice can miss a grid cell that overlaps only a small corner of the lat/lon +/- max_dist rectangle; the comment now says so (3 of 83,645 Step 3 cases in the CF0360 offline test, where another tile within max_dist was chosen). No change in results for unstretched grids. Co-Authored-By: Claude Opus 5.5 --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 46 ++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 4653c1b2..5a7b219b 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -38,7 +38,8 @@ module LDAS_TileCoordRoutines MAPL_GetGlobalHorzIJIndex use ESMF, ONLY: & - ESMF_Grid + ESMF_Grid, & + ESMF_AttributeGet use LDAS_ExceptionsMod, ONLY: & ldas_abort, & @@ -1022,9 +1023,12 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! 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.), - ! so that Step 3.) can find all tiles within max_dist. Grid cells that were - ! already searched are skipped. + ! 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 there is still no such tile, loop through all tiles within the grid ! cells identified in 1.) and 2.) and find minimum distance (Minkowski norm) @@ -1540,8 +1544,8 @@ subroutine get_ij_ind_from_latlon_c3( c3_grid, tile_grid, N_latlon, lat, lon, i_ ! ! 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 supports stretched grids and fails for grids that it - ! cannot handle. + ! and tile_coord%j_indg. It fails for grids that it cannot handle. (It also handles + ! stretched grids, but init_c3_grid() 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. @@ -1630,6 +1634,12 @@ subroutine init_c3_grid( c3_grid, tile_grid ) ! 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, 8 Nov 2026 implicit none @@ -1650,6 +1660,8 @@ subroutine init_c3_grid( c3_grid, tile_grid ) integer :: status + logical :: has_factor, has_lon, has_lat + character(len=*), parameter :: Iam = 'init_c3_grid' character(len=400) :: err_msg @@ -1678,6 +1690,28 @@ subroutine init_c3_grid( c3_grid, tile_grid ) 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, & From 5da1e909c9730f149bca09a293512f967fe37b20 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Sun, 8 Nov 2026 17:06:12 -0700 Subject: [PATCH 26/90] skip QC of Tb for non-land surfaces after EnKF update instead of aborting (clsm_ensupd_upd_routines.F90) After the EnKF update, get_obs_pred() is called from output_ObsFcstAna_wrapper() without c3_tile_space, so its tile_grid_g (the pert grid) is LatLon for cube-sphere tile space and the QC fell into the new abort for every Tb obs. Obs that fail this QC were already removed before the update, and grid types without this QC still abort there, so skip the QC after the update (as before b4045d7). Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index 45be43eb..ce4949df 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1991,6 +1991,17 @@ subroutine get_obs_pred( & tmpWater = ( 1. - tmp_fraccell > Tb_max_nonland_frac ) + elseif (.not. beforeEnKFupdate) then + + ! after the EnKF update, get_obs_pred() is called without c3_tile_space + ! (see output_ObsFcstAna_wrapper()), so that tile_grid_g (pert grid) is + ! LatLon for cube-sphere tile space; obs that failed the QC of Tb for + ! non-land surfaces were already removed before the EnKF update, and grid + ! types without this QC were rejected there (see below) + ! - amfox, 8 Nov 2026 + + tmpWater = .false. + else err_msg = 'Tb QC for non-land frac not implemented for this grid type' From e97bdaee20a25b077a501e5a49ee4c234055c089 Mon Sep 17 00:00:00 2001 From: Weiyuan Jiang <52509753+weiyuan-jiang@users.noreply.github.com> Date: Mon, 9 Nov 2026 09:53:13 -0500 Subject: [PATCH 27/90] Update CHANGELOG with recent fixes and updates Added a new entry for fixing compiler warnings and improved handling of observation data in various scripts. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30c4d528..9fb5cd43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 for compiler Nag - 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 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)). From 13b2abe9ddc561b25c1bcef9e9ba93dd01c09700 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Mon, 9 Nov 2026 12:56:30 -0700 Subject: [PATCH 28/90] c3 obs-to-tile mapping: larger chunks and batches (N_chunk=100000, N_pts_max=1000000) for fewer MAPL_GetGlobalHorzIJIndex() calls on high-res grids (LDAS_TileCoordRoutines.F90) Co-Authored-By: Claude Opus 5.5 --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 5a7b219b..4a994340 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -1044,7 +1044,9 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! 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.). + ! 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, 6 Nov 2026 ! amfox, 8 Nov 2026 - moved here from get_tile_num_from_latlon(); grid cells from @@ -1054,6 +1056,7 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! within max_dist would pass it) ! amfox, 8 Nov 2026 - Step 2.) also searches the grid cells within max_dist (the 8 points ! alone can miss grid cells with tiles within max_dist) + ! amfox, 9 Nov 2026 - larger N_chunk and N_pts_max (fewer MAPL calls for high-res grids) implicit none @@ -1080,14 +1083,14 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & integer, parameter :: nodata_tilenum = -9999 - integer, parameter :: N_chunk = 10000 ! max number of lat/lon per chunk + 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 = 100000 ! max number of points per batch (Step 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 From c8014240faa4ab7973456d1e2a3e0ff721667acd Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Mon, 9 Nov 2026 16:16:13 -0500 Subject: [PATCH 29/90] changed QC of Tb for nonland fraction on c3 tile space to use "tile area" instead of "fraction of land area of tile in grid cell" as weight; simplified/cleaned-up if-logic; edited comments (clsm_ensupd_upd_routines.F90) --- .../clsm_ensupd_upd_routines.F90 | 147 ++++++++---------- 1 file changed, 68 insertions(+), 79 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index ce4949df..dc03aa4e 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1149,7 +1149,6 @@ subroutine get_obs_pred( & integer, dimension(:), allocatable :: ind_tmp real, dimension(:), allocatable :: tmp_ndst2, tmp_wFOV, tmp_weights, tmp_data - real, dimension(:), allocatable :: tmp_wtmp ! cube-sphere tile space only ! dimension "N_catlH-[by-N_XXXX-]by-N_ens" ! (need to be communicated between processors) @@ -1594,7 +1593,10 @@ subroutine get_obs_pred( & ! 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 (tile_coord_f must contain all tiles of the grid cell) + ! fraction of the grid cell; + ! 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 ! - amfox, 6 Nov 2026 c3_tile_space_tmp = .false. @@ -1736,8 +1738,6 @@ subroutine get_obs_pred( & allocate(tmp_weights(N_catlH)) allocate(tmp_data( N_catlH)) - if (c3_tile_space_tmp) allocate(tmp_wtmp(N_catlH)) - do i=1,N_obsl this_species = Observations_l(i)%species @@ -1916,11 +1916,17 @@ subroutine get_obs_pred( & case('Tb') - ! start with QC based on model *soil* temperature, motivated by RFI + ! start with model-based QC ! (requires model estimates *and* observation together; ! only performed before the EnKF update b/c not needed afterwards) + tmpRFI = .false. + + tmpWater = .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 ) @@ -1931,84 +1937,68 @@ subroutine get_obs_pred( & tmpRFI = ((Observations_l(i)%obs-tmp_stemp) > Tbobs_minus_stemp_max) - else - - tmpRFI = .false. - - end if - - ! for EASE and cube-sphere grids *ONLY*: screen for non-land surfaces (e.g., lakes) - ! - reichle, 28 Mar 2015 (EASE) - ! - amfox, 6 Nov 2026 (cube-sphere) - - 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 > Tb_max_nonland_frac ) - - elseif (c3_tile_space_tmp) then - - ! cube-sphere tile space: screen for non-land surfaces as for EASE grids, - ! but a grid cell contains several tiles; average the land fraction of - ! the grid cells in the FOV (FOV-weighted) and count each grid cell once - ! by weighting each tile with its share of the land in its grid cell - ! (identical to EASE grids if there is one tile per grid cell) - ! - ! ASSUMPTION: - ! - grid cells have the same area (or at least have nearly identical - ! areas) in the neighborhood surrounding the obs; - ! regular cube-sphere grid cellcell areas differ by ~1-2% within ~0.5 deg; - ! NEEDS REVISITING for stretched cube-sphere grids - ! - ! - amfox, 6 Nov 2026 - - tmp_data(1:N_tmp) = land_frac_cell_lH(ind_tmp(1:N_tmp)) - - ! weight each tile's contribution by (1) FOV and (2) area fraction of land tile w.r.t. all land in grid cell - - tmp_wtmp(1:N_tmp) = & - ( tmp_wFOV(1:N_tmp) & ! (1) - * tile_coord_lH(ind_tmp(1:N_tmp))%frac_cell / max( tmp_data(1:N_tmp), 1.e-10 ) ) ! (2) - - call tile2obs_helper( & - N_tmp, tmp_wtmp(1:N_tmp), tmp_data(1:N_tmp), tmp_fraccell) - - tmpWater = ( 1. - tmp_fraccell > Tb_max_nonland_frac ) + ! --------------------- - elseif (.not. beforeEnKFupdate) then - - ! after the EnKF update, get_obs_pred() is called without c3_tile_space - ! (see output_ObsFcstAna_wrapper()), so that tile_grid_g (pert grid) is - ! LatLon for cube-sphere tile space; obs that failed the QC of Tb for - ! non-land surfaces were already removed before the EnKF update, and grid - ! types without this QC were rejected there (see below) - ! - amfox, 8 Nov 2026 + ! screen for non-land surfaces (e.g., lakes, landice) + ! *ONLY* implemented for EASE and cube-sphere grids + ! - reichle, 28 Mar 2015 (EASE) + ! - amfox, 6 Nov 2026 (cube-sphere) + + 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 > Tb_max_nonland_frac ) + + elseif (c3_tile_space_tmp) then + + ! cube-sphere tile space: screen for non-land surfaces as for EASE grids, + ! but a grid cell contains several tiles; average the land fraction of + ! the grid cells in the FOV (FOV-weighted) and count each grid cell once + ! by weighting each tile with its share of the land in its grid cell + ! (identical to EASE grids if there is one tile per grid cell) + ! + ! ASSUMPTION: + ! - grid cells have the same area (or at least have nearly identical + ! areas) in the neighborhood surrounding the obs; + ! regular cube-sphere grid cellcell areas differ by ~1-2% within ~0.5 deg; + ! NEEDS REVISITING for stretched cube-sphere grids + ! + ! - amfox, 6 Nov 2026 + + tmp_data(1:N_tmp) = land_frac_cell_lH(ind_tmp(1:N_tmp)) + + ! compute average land_frac_cell weighted by each tile's area and contribution to FOV + + call tile2obs_helper( & + N_tmp, tmp_wFOV(1:N_tmp)*tile_coord_lH(ind_tmp(1:N_tmp))%area, & + tmp_data(1:N_tmp), tmp_fraccell) + + tmpWater = ( 1. - tmp_fraccell > Tb_max_nonland_frac ) - tmpWater = .false. + else - else + err_msg = 'Tb QC for non-land frac not implemented for this grid type' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - 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 - end if - + end if ! beforeEnKFupdate ! compute Obs_pred @@ -2126,7 +2116,6 @@ 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(tmp_wtmp)) deallocate(tmp_wtmp) if (allocated(land_frac_cell_lH)) deallocate(land_frac_cell_lH) if (allocated(peat_lH)) deallocate(peat_lH) From c9531a3004aead3167cd92b0a1c91b918b8600c0 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Tue, 10 Nov 2026 09:34:34 -0500 Subject: [PATCH 30/90] corrected weights used in QC of TB for non-land in c3 tile space; edited comments (clsm_ensupd_upd_routines.F90) --- .../clsm_ensupd_upd_routines.F90 | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index dc03aa4e..6e1a1793 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1943,15 +1943,23 @@ subroutine get_obs_pred( & ! *ONLY* implemented for EASE and cube-sphere grids ! - reichle, 28 Mar 2015 (EASE) ! - amfox, 6 Nov 2026 (cube-sphere) - + + ! 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(tile_grid_g%gridtype, 'EASEv') /=0) then - ! ASSUMPTIONS: + ! ADDITIONAL 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) + ! - 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 ! compute FOV-weighted average "frac_cell" @@ -1973,20 +1981,14 @@ subroutine get_obs_pred( & ! by weighting each tile with its share of the land in its grid cell ! (identical to EASE grids if there is one tile per grid cell) ! - ! ASSUMPTION: - ! - grid cells have the same area (or at least have nearly identical - ! areas) in the neighborhood surrounding the obs; - ! regular cube-sphere grid cellcell areas differ by ~1-2% within ~0.5 deg; - ! NEEDS REVISITING for stretched cube-sphere grids - ! ! - amfox, 6 Nov 2026 tmp_data(1:N_tmp) = land_frac_cell_lH(ind_tmp(1:N_tmp)) ! compute average land_frac_cell weighted by each tile's area and contribution to FOV - call tile2obs_helper( & - N_tmp, tmp_wFOV(1:N_tmp)*tile_coord_lH(ind_tmp(1:N_tmp))%area, & + call tile2obs_helper( & + N_tmp, tmp_wFOV(1:N_tmp)*tile_coord_lH(ind_tmp(1:N_tmp))%area/max(land_frac_cell,1.e-10), & tmp_data(1:N_tmp), tmp_fraccell) tmpWater = ( 1. - tmp_fraccell > Tb_max_nonland_frac ) From c03de7aaceeb84c013020af5f98658a467a9932b Mon Sep 17 00:00:00 2001 From: amfox37 Date: Tue, 10 Nov 2026 11:17:09 -0700 Subject: [PATCH 31/90] fix undeclared land_frac_cell in c3 Tb non-land QC weight (use tmp_data) (clsm_ensupd_upd_routines.F90) land_frac_cell was shorthand in the PR comment, not a variable; the per-tile grid-cell land fraction is already in tmp_data(1:N_tmp). Co-Authored-By: Claude Opus 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index 6e1a1793..85b57964 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1988,7 +1988,7 @@ subroutine get_obs_pred( & ! compute average land_frac_cell weighted by each tile's area and contribution to FOV call tile2obs_helper( & - N_tmp, tmp_wFOV(1:N_tmp)*tile_coord_lH(ind_tmp(1:N_tmp))%area/max(land_frac_cell,1.e-10), & + 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_fraccell) tmpWater = ( 1. - tmp_fraccell > Tb_max_nonland_frac ) From 22880d763848adedc56ef200b48bfbe88d3240d3 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Tue, 10 Nov 2026 15:43:25 -0500 Subject: [PATCH 32/90] cleanup of model-based QC logic and comments - moved QC of Tb obs for non-land fraction out of loop through ensemble members - run QC of soil moisture obs for peat area frac only before EnKF update - renamed tmp_fraccell to tmp_nonland_frac for clarity - renamed tmp_peatfrac to tmp_peat_frac for consistency - edited comments --- .../clsm_ensupd_upd_routines.F90 | 190 +++++++++--------- 1 file changed, 100 insertions(+), 90 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index 85b57964..bc8e80dd 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1090,7 +1090,7 @@ subroutine get_obs_pred( & real, dimension(numprocs) :: xhalo, yhalo, tmplatvec, tmprx - real :: tmpreal, tmp_stemp, tmp_fraccell, tmp_peatfrac + real :: tmpreal, tmp_stemp, tmp_nonland_frac, tmp_peat_frac real :: tmpsum_w logical :: tmpRFI, tmpWater, tmpPeat, use_distance_weights @@ -1851,38 +1851,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 + + 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 + + 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 + + end if + + end if - 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)) + ! 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) then - ! FOV- and area-weighted peat fraction over tiles with valid porosity + ! 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(tile_grid_g%gridtype, 'EASEv') /=0) then + + ! 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" - 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) = tile_coord_lH(ind_tmp(1:N_tmp))%frac_cell - if (tmpsum_w > 0.) then + call tile2obs_helper( & + N_tmp, tmp_wFOV(1:N_tmp), tmp_data(1:N_tmp), tmp_nonland_frac) - 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 + elseif (c3_tile_space_tmp) then - tmpPeat = (tmp_peatfrac>=SM_max_peat_frac) + ! 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 properites: + ! 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 - else + tmp_data(1:N_tmp) = land_frac_cell_lH(ind_tmp(1:N_tmp)) - tmpPeat = .true. ! no valid porosity anywhere in FOV + 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_nonland_frac) - end if + else - end if - + 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_nonland_frac > Tb_max_nonland_frac ) + + end if ! if get_Tb_lH + + end if ! if beforeEnKFupdate + do n_e=1,N_ens ! ----------------------------------------- @@ -1916,14 +1991,12 @@ subroutine get_obs_pred( & case('Tb') - ! start with model-based QC - ! (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. - - tmpWater = .false. - + if (beforeEnKFupdate) then ! QC based on model *soil* temperature, motivated by RFI @@ -1937,69 +2010,6 @@ subroutine get_obs_pred( & tmpRFI = ((Observations_l(i)%obs-tmp_stemp) > Tbobs_minus_stemp_max) - ! --------------------- - - ! screen for non-land surfaces (e.g., lakes, landice) - ! *ONLY* implemented for EASE and cube-sphere grids - ! - reichle, 28 Mar 2015 (EASE) - ! - amfox, 6 Nov 2026 (cube-sphere) - - ! 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(tile_grid_g%gridtype, 'EASEv') /=0) then - - ! ADDITIONAL 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) - ! - 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 - - ! 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 > Tb_max_nonland_frac ) - - elseif (c3_tile_space_tmp) then - - ! cube-sphere tile space: screen for non-land surfaces as for EASE grids, - ! but a grid cell contains several tiles; average the land fraction of - ! the grid cells in the FOV (FOV-weighted) and count each grid cell once - ! by weighting each tile with its share of the land in its grid cell - ! (identical to EASE grids if there is one tile per grid cell) - ! - ! - amfox, 6 Nov 2026 - - tmp_data(1:N_tmp) = land_frac_cell_lH(ind_tmp(1:N_tmp)) - - ! compute average land_frac_cell weighted by each tile's area and contribution to FOV - - 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_fraccell) - - tmpWater = ( 1. - tmp_fraccell > Tb_max_nonland_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 - end if ! beforeEnKFupdate ! compute Obs_pred From c0dfa46ee23ec0b5db1aa25497b8dce29d62c40c Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Tue, 10 Nov 2026 15:55:57 -0500 Subject: [PATCH 33/90] fixed syntax error in previous commit (clsm_ensupd_upd_routines.F90) --- GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index bc8e80dd..c999082f 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1883,7 +1883,7 @@ subroutine get_obs_pred( & abs(tmp_data(1:N_tmp)-nodata_generic)>=nodata_tol_generic ) ) & / tmpsum_w - tmpPeat = (tmp_peat_frac > =SM_max_peat_frac) + tmpPeat = (tmp_peat_frac >= SM_max_peat_frac) else From 843e156a427db9baea4a434dce189946f4aaf389 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Tue, 10 Nov 2026 16:52:57 -0500 Subject: [PATCH 34/90] run QC of Tb for non-land fraction only for 'Tb' obs species; renamed tmp_nonland_frac to tmp_land_frac; fixed typo in comment (clsm_ensupd_upd_routines.F90) --- GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index c999082f..db2c7d94 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1090,7 +1090,7 @@ subroutine get_obs_pred( & real, dimension(numprocs) :: xhalo, yhalo, tmplatvec, tmprx - real :: tmpreal, tmp_stemp, tmp_nonland_frac, tmp_peat_frac + real :: tmpreal, tmp_stemp, tmp_land_frac, tmp_peat_frac real :: tmpsum_w logical :: tmpRFI, tmpWater, tmpPeat, use_distance_weights @@ -1900,7 +1900,7 @@ subroutine get_obs_pred( & ! - reichle, 28 Mar 2015 (EASE) ! - amfox, 6 Nov 2026 (cube-sphere) - if (get_Tb_lH) then + if (get_Tb_lH .and. trim(obs_param(this_species)%varname)=='Tb') then ! ASSUMPTION: ! - all grid cells in FOV contain at least some land; grid cells @@ -1921,14 +1921,14 @@ subroutine get_obs_pred( & 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_nonland_frac) + N_tmp, tmp_wFOV(1:N_tmp), tmp_data(1:N_tmp), tmp_land_frac) elseif (c3_tile_space_tmp) then ! 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 properites: + ! 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 @@ -1940,7 +1940,7 @@ subroutine get_obs_pred( & 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_nonland_frac) + tmp_data(1:N_tmp), tmp_land_frac) else @@ -1952,7 +1952,7 @@ subroutine get_obs_pred( & ! check whether there is too much non-land in FOV ! (typically water, but could be land-ice) - tmpWater = ( 1. - tmp_nonland_frac > Tb_max_nonland_frac ) + tmpWater = ( 1. - tmp_land_frac > Tb_max_nonland_frac ) end if ! if get_Tb_lH From 43d7a11eb30e19f2b1fad71c53fca8d3683150a1 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Tue, 10 Nov 2026 17:07:08 -0700 Subject: [PATCH 35/90] set FFT lengths (fft_lens) for nr_fft used when MKL is not available (rectangle_random_fields.F90) fft_lens was declared but never assigned. Builds without MKL (e.g., macOS with gfortran) use the Numerical Recipes FFT, fourn(), which reads fft_lens, and crashed with a segmentation fault when generating perturbations. Builds with MKL do not use fft_lens, so results are unchanged (0-diff). Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + GEOSlandpert_GridComp/rectangle_random_fields.F90 | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37eaad3d..cd7074c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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), caused by FFT lengths (`fft_lens`) that were never set (0-diff for builds with MKL). ### Removed 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)) From 2762342e3db9320bf1f434eccf55905c4a3e6e0c Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Wed, 11 Nov 2026 12:04:50 -0500 Subject: [PATCH 36/90] renamed variables and subroutines for clarity: - type(ESMF_Grid) :: c3_grid --> tile_grid_g_ESMF (c3_grid is also used for a logical in GEOSldas) - type(ESMF_Grid) :: tile_space_grid --> tile_grid_g_ESMF - subroutine init_c3_grid() --> init_tile_grid_g_ESMF_c3() --- .../GEOS_LandAssimGridComp.F90 | 9 +- .../clsm_ensupd_enkf_update.F90 | 28 ++-- .../clsm_ensupd_read_obs.F90 | 120 +++++++++--------- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 54 ++++---- 4 files changed, 105 insertions(+), 106 deletions(-) diff --git a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 index cb7fee12..cba0ccbc 100644 --- a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 +++ b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 @@ -1488,7 +1488,7 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) integer :: N_adapt_R type(MAPL_LocStream) :: locstream - type(ESMF_Grid) :: tile_space_grid ! grid attached to locstream (cube-sphere grid for c3) + 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 @@ -1614,7 +1614,7 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) _VERIFY(status) ! Get grid of tile space (needed to map obs to tiles in cube-sphere tile space) - call MAPL_LocStreamGet(locstream, ATTACHEDGRID=tile_space_grid, rc=status) + call MAPL_LocStreamGet(locstream, ATTACHEDGRID=tile_grid_g_ESMF, rc=status) _VERIFY(status) ! Pointers to internals @@ -1935,9 +1935,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, & - c3_grid=tile_space_grid ) + N_adapt_R, obs_pert_adapt_param, Pert_adapt_R, & ! "adapt" is dummy for now + tile_grid_g_ESMF=tile_grid_g_ESMF ) if (fresh_incr) then ! apply EnKF increments (incl. call to catch_calc_soil_moist but not to recompute_diagS()) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 27433031..1627652d 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -74,7 +74,7 @@ module clsm_ensupd_enkf_update use LDAS_TilecoordRoutines, ONLY: & get_number_of_tiles_in_cell_ij, & get_tile_num_in_cell_ij, & - init_c3_grid, & + init_tile_grid_g_ESMF_c3, & grid2tile use ESMF, ONLY: & @@ -165,14 +165,14 @@ subroutine get_enkf_increments( & cat_progn_incr, fresh_incr, & N_obsf, N_obsl, Observations_l, & N_adapt_R, obs_pert_adapt_param, Pert_adapt_R, & - Obs_pert, c3_grid ) + Obs_pert, tile_grid_g_ESMF ) ! ------------------------------------------------------------- ! return increments instead of updated cat_progn ! reichle, 18 Oct 2005 ! - ! added optional input c3_grid (ESMF grid of tile space), needed (only) to map obs + ! added optional input tile_grid_g_ESMF (ESMF grid of tile space), needed (only) to map obs ! to tiles in cube-sphere tile space ! amfox, 8 Nov 2026 @@ -257,7 +257,7 @@ subroutine get_enkf_increments( & real, dimension(N_obsl_max,N_ens), intent(out), optional :: Obs_pert - type(ESMF_Grid), intent(in), optional :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), intent(in), optional :: tile_grid_g_ESMF ! needed for cube-sphere tile space ! ---------------------------------------------- @@ -413,18 +413,18 @@ subroutine get_enkf_increments( & ! 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_c3_grid()). - amfox, 8 Nov 2026 + ! processes (see init_tile_grid_g_ESMF_c3()). - amfox, 8 Nov 2026 if ( (index(tile_grid_g%gridtype,'c3')/=0) .and. (.not. c3_grid_initialized) ) then - if (.not. present(c3_grid)) then + if (.not. present(tile_grid_g_ESMF)) then - err_msg = 'cube-sphere tile space requires optional input c3_grid (ESMF grid)' + err_msg = 'cube-sphere tile space requires optional input tile_grid_g_ESMF (ESMF grid)' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - call init_c3_grid( c3_grid, tile_grid_g ) + call init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid_g ) c3_grid_initialized = .true. @@ -510,7 +510,7 @@ subroutine get_enkf_increments( & tile_coord_f, tile_grid_g, 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, & - c3_grid=c3_grid ) + tile_grid_g_ESMF=tile_grid_g_ESMF ) ! check for observations, found_obs_f=.true. if obs availalbe @@ -521,7 +521,7 @@ subroutine get_enkf_increments( & 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, & - N_obsl, Observations_l, found_obs_f, c3_grid=c3_grid ) + N_obsl, Observations_l, found_obs_f, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! -------------------------------------------------------------------- @@ -2240,7 +2240,7 @@ 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, 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, c3_grid ) + N_obs_param, obs_param, Observations_l, cat_param, cat_progn, tile_grid_g_ESMF ) ! wrapper for output of original (unscaled) SMAP Tb observations into ! SMAP L4_SM "aup" (analysis update) @@ -2251,7 +2251,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & ! reichle, 11 Dec 2013 - added 'SMOS_fit_Tb*' obs species ! (needed for L4_SM_SMOS prototype product) ! amfox, 6 Nov 2026 - renamed pert_grid_f to obs2tile_grid_f (only passed through to collect_obs()) - ! amfox, 8 Nov 2026 - added optional c3_grid (only passed through to collect_obs()) + ! amfox, 8 Nov 2026 - added optional tile_grid_g_ESMF (only passed through to collect_obs()) ! ! ------------------------------------------------------------------- @@ -2289,7 +2289,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & type(cat_param_type), dimension(N_catl), intent(in) :: cat_param type(cat_progn_type), dimension(N_catl,N_ens), intent(in) :: cat_progn - type(ESMF_Grid), optional, intent(in) :: c3_grid + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! ------------------------------------------ @@ -2349,7 +2349,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & 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., & - N_obsl_tmp, Observations_l, found_obs_f, c3_grid=c3_grid ) + N_obsl_tmp, Observations_l, found_obs_f, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! write appropriate fields (according to 'option') into file diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 943a1866..72adc6cb 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -435,7 +435,7 @@ subroutine read_obs_ae_l2_sm( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, ae_l2_sm, std_ae_l2_sm, c3_grid ) + found_obs, ae_l2_sm, std_ae_l2_sm, tile_grid_g_ESMF ) ! Read observations of surface soil moisture from AMSR-E L2 files ! Set flag "found_obs" to true if observations are available @@ -472,7 +472,7 @@ subroutine read_obs_ae_l2_sm( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -662,7 +662,7 @@ subroutine read_obs_ae_l2_sm( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! ---------------------------------------------------------------- @@ -948,7 +948,7 @@ subroutine read_obs_ae_sm_LPRM( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, ae_sm_LPRM, std_ae_sm_LPRM, c3_grid ) + found_obs, ae_sm_LPRM, std_ae_sm_LPRM, tile_grid_g_ESMF ) ! Read observations of surface soil moisture from AMSR-E sm LPRM files ! (Richard de Jeu, Vrije Universiteit Amsterdam) @@ -986,7 +986,7 @@ subroutine read_obs_ae_sm_LPRM( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -1179,7 +1179,7 @@ subroutine read_obs_ae_sm_LPRM( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! ---------------------------------------------------------------- @@ -1261,7 +1261,7 @@ subroutine read_obs_sm_ASCAT( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, sm_ASCAT, std_sm_ASCAT, c3_grid ) + found_obs, sm_ASCAT, std_sm_ASCAT, tile_grid_g_ESMF ) !--------------------------------------------------------------------- ! @@ -1298,7 +1298,7 @@ subroutine read_obs_sm_ASCAT( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -1494,7 +1494,7 @@ subroutine read_obs_sm_ASCAT( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! ---------------------------------------------------------------- @@ -1574,7 +1574,7 @@ 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, & - found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time, c3_grid ) + found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time, tile_grid_g_ESMF ) !--------------------------------------------------------------------- ! @@ -1618,7 +1618,7 @@ subroutine read_obs_sm_ASCAT_EUMET( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -2076,7 +2076,7 @@ subroutine read_obs_sm_ASCAT_EUMET( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! ---------------------------------------------------------------- @@ -2172,7 +2172,7 @@ 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, & this_obs_param, write_obslog, & - found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time, c3_grid ) + found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time, tile_grid_g_ESMF ) ! Read H SAF ASCAT SSM CDR (H121) and ICDR (H139) from netCDF swath files. ! @@ -2229,7 +2229,7 @@ subroutine read_obs_sm_ASCAT_HSAF( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -2648,7 +2648,7 @@ subroutine read_obs_sm_ASCAT_HSAF( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_valid, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) do ii = 1, N_valid @@ -2808,7 +2808,7 @@ 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, & - found_obs, CYGNSS_sm, CYGNSS_sm_std, CYGNSS_lon, CYGNSS_lat, CYGNSS_time, c3_grid ) + found_obs, CYGNSS_sm, CYGNSS_sm_std, CYGNSS_lon, CYGNSS_lat, CYGNSS_time, tile_grid_g_ESMF ) !--------------------------------------------------------------------- ! @@ -2848,7 +2848,7 @@ subroutine read_obs_sm_CYGNSS( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -3239,7 +3239,7 @@ subroutine read_obs_sm_CYGNSS( & 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, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! ---------------------------------------------------------------- ! @@ -3531,7 +3531,7 @@ 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, & this_obs_param, & - found_obs, ts_LARC, std_ts_LARC, c3_grid ) + found_obs, ts_LARC, std_ts_LARC, tile_grid_g_ESMF ) !--------------------------------------------------------------------- ! @@ -3557,7 +3557,7 @@ subroutine read_obs_LaRC_Tskin( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -3731,7 +3731,7 @@ subroutine read_obs_LaRC_Tskin( & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_tmp, tmp_lat, tmp_lon, & this_obs_param, & - tmp_tile_num, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! ---------------------------------------------------------------- @@ -4877,7 +4877,7 @@ 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, & - found_obs, isccp_tskin_gswp2_v1, std_isccp_tskin_gswp2_v1, c3_grid ) + found_obs, isccp_tskin_gswp2_v1, std_isccp_tskin_gswp2_v1, tile_grid_g_ESMF ) ! Read observations of land skin temperature from ISCCP data ! produced by Sarith on GSWP-2 grid @@ -4912,7 +4912,7 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -5046,7 +5046,7 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & tile_grid_d, 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), c3_grid=c3_grid ) + tmp_tile_num(1:N_tmp), tile_grid_g_ESMF=tile_grid_g_ESMF ) ! ---------------------------------------------------------------- ! @@ -5569,7 +5569,7 @@ 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, c3_grid ) + found_obs, SMOS_data, std_SMOS_data, SMOS_lon, SMOS_lat, tile_grid_g_ESMF ) ! reader for preprocessed SMOS Tb and soil moisture (SM) files ! @@ -5622,7 +5622,7 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space logical, intent(in) :: write_obslog @@ -6203,7 +6203,7 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & N_obs, tmp_lat, tmp_lon, & this_obs_param, & tmp_tile_num, & - tmp_shift_lat, tmp_shift_lon, c3_grid=c3_grid ) + tmp_shift_lat, tmp_shift_lon, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! -------------------------------------------------------------------------- ! @@ -6397,7 +6397,7 @@ 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, & this_obs_param, write_obslog, & - found_obs, MODIS_obs, std_MODIS_obs, MODIS_lon, MODIS_lat, c3_grid ) + found_obs, MODIS_obs, std_MODIS_obs, MODIS_lon, MODIS_lat, tile_grid_g_ESMF ) ! read MODIS snow cover fraction observations on MODIS 0.05-degree climate ! modeling grid (CMG) @@ -6430,7 +6430,7 @@ subroutine read_obs_MODIS_SCF( & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space type(obs_param_type), intent(in) :: this_obs_param @@ -6818,7 +6818,7 @@ subroutine read_obs_MODIS_SCF( & 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, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) std_MODIS_obs = this_obs_param%errstd @@ -7463,7 +7463,7 @@ end subroutine read_MODIS_SCF_hdf subroutine read_obs_SMAP_FT( 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, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time, c3_grid ) + found_obs, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time, tile_grid_g_ESMF ) ! 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) @@ -7492,7 +7492,7 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space logical, intent(in) :: write_obslog @@ -7964,7 +7964,7 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & tmp_lat(1:N_obs_kept(kk)), & tmp_lon(1:N_obs_kept(kk)), & this_obs_param, & - tmp_tile_num, c3_grid=c3_grid ) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! -------------------------------------------------------------------------- ! @@ -8150,7 +8150,7 @@ 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, & 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, c3_grid ) + found_obs, SMAP_data, std_SMAP_data, SMAP_lon, SMAP_lat, SMAP_time, tile_grid_g_ESMF ) ! read brightness temperature data within the assimilation window from one or more ! SMAP half-orbit h5 files (L1C, L1CE (Enhanced), or L2AP) @@ -8192,7 +8192,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space logical, intent(in) :: write_obslog @@ -9072,7 +9072,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & tmp_lon(1:N_obs_kept(kk)), & this_obs_param, & tmp_tile_num, & - tmp_shift_lat, tmp_shift_lon, c3_grid=c3_grid ) + tmp_shift_lat, tmp_shift_lon, tile_grid_g_ESMF=tile_grid_g_ESMF ) else @@ -9082,7 +9082,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & tmp_lat(1:N_obs_kept(kk)), & tmp_lon(1:N_obs_kept(kk)), & this_obs_param, & - tmp_tile_num, c3_grid=c3_grid) + tmp_tile_num, tile_grid_g_ESMF=tile_grid_g_ESMF) end if @@ -9878,7 +9878,7 @@ subroutine read_obs( & tile_grid_d, 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, c3_grid ) + tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time, tmp_assim, tile_grid_g_ESMF ) ! read observations and optionally scale observations to model clim ! @@ -9894,7 +9894,7 @@ subroutine read_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) - ! 8 Nov 2026 - added optional input c3_grid (ESMF grid of cube-sphere tile space) + ! 8 Nov 2026 - added optional input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space) ! (amfox) implicit none @@ -9921,7 +9921,7 @@ subroutine read_obs( & logical, intent(in) :: write_obslog - type(ESMF_Grid), intent(in), optional :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), intent(in), optional :: tile_grid_g_ESMF ! needed for cube-sphere tile space ! outputs: @@ -9972,7 +9972,7 @@ subroutine read_obs( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! scale observations to model climatology @@ -9993,7 +9993,7 @@ subroutine read_obs( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! scale observations to model climatology @@ -10014,7 +10014,7 @@ subroutine read_obs( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! scale observations to model climatology @@ -10034,7 +10034,7 @@ subroutine read_obs( & tile_grid_d, 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, c3_grid=c3_grid) + tmp_time, tile_grid_g_ESMF=tile_grid_g_ESMF) ! scale observations to model climatology @@ -10055,7 +10055,7 @@ subroutine read_obs( & tile_grid_d, 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, c3_grid=c3_grid) + tmp_time, tile_grid_g_ESMF=tile_grid_g_ESMF) ! scale observations to model climatology @@ -10076,7 +10076,7 @@ subroutine read_obs( & tile_grid_d, 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, c3_grid=c3_grid) + tmp_time, tile_grid_g_ESMF=tile_grid_g_ESMF) ! scale observations to model climatology @@ -10096,7 +10096,7 @@ subroutine read_obs( & date_time, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) if (this_obs_param%scale .and. found_obs) then @@ -10221,7 +10221,7 @@ subroutine read_obs( & 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, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! scale observations to model climatology @@ -10241,7 +10241,7 @@ subroutine read_obs( & 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, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! scale observations to model climatology @@ -10260,7 +10260,7 @@ subroutine read_obs( & 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, & - found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tile_grid_g_ESMF=tile_grid_g_ESMF ) case('SMAP_L1C_Tbh_A', 'SMAP_L1C_Tbv_A', & 'SMAP_L1C_Tbh_D', 'SMAP_L1C_Tbv_D', & @@ -10275,7 +10275,7 @@ subroutine read_obs( & 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, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! scale observations to model climatology @@ -10295,7 +10295,7 @@ subroutine read_obs( & date_time, dtstep_assim, N_catd, tile_coord, & tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, c3_grid=c3_grid ) + found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) ! NOT IMPLEMENTED: scale observations to model climatology @@ -11388,7 +11388,7 @@ subroutine collect_obs( N_catf, tile_coord_f, tile_grid_f, 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, c3_grid ) + N_obsl, Observations_l, found_obs_f, tile_grid_g_ESMF ) ! check for observations that must be assimilated, ! collect into measurement vector @@ -11402,7 +11402,7 @@ 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 - ! 8 Nov 2026 - added optional input c3_grid (ESMF grid of cube-sphere tile space) + ! 8 Nov 2026 - added optional input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space) ! (amfox) implicit none @@ -11445,7 +11445,7 @@ subroutine collect_obs( logical, intent(out) :: found_obs_f - type(ESMF_Grid), optional, intent(in) :: c3_grid ! needed for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space ! ---------------------------- @@ -11512,7 +11512,7 @@ subroutine collect_obs( tile_grid_f, 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, c3_grid=c3_grid) + tmp_obs_f, tmp_std_obs_f, tmp_lon_f, tmp_lat_f, tmp_time_f, tmp_assim_f, tile_grid_g_ESMF=tile_grid_g_ESMF) if (scaled_obs) any_scaled_obs = .true. @@ -11898,7 +11898,7 @@ 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, & this_obs_param, & tile_num, & - shift_lat, shift_lon, c3_grid ) + shift_lat, shift_lon, tile_grid_g_ESMF ) ! find one tile for each obs that "administers" the obs ! @@ -11907,7 +11907,7 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & ! ! - reichle, 2015/02/20 ! - ! added optional input c3_grid (ESMF grid of cube-sphere tile space), see + ! added optional input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space), see ! get_tile_num_from_latlon() ! - amfox, 8 Nov 2026 @@ -11932,7 +11932,7 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & real, optional, intent(in) :: shift_lat real, optional, intent(in) :: shift_lon - type(ESMF_Grid), optional, intent(in) :: c3_grid ! for cube-sphere tile space + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! for cube-sphere tile space ! ------------------------ @@ -11994,7 +11994,7 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & call get_tile_num_from_latlon(N_catd, tile_coord, & tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, & N_latlon, tmp_lat, tmp_lon, & - tile_num, max_dist_x, max_dist_y, c3_grid=c3_grid ) + tile_num, max_dist_x, max_dist_y, tile_grid_g_ESMF=tile_grid_g_ESMF ) end subroutine get_tile_num_for_obs diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 4a994340..32034a1c 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -7,7 +7,7 @@ ! reichle, 5 Apr 2013 - added EASEv2 grid, minimal change to max lat/lon for EASE (v1) ! amfox, 6 Nov 2026 - added cube-sphere grid ("c3") case to get_tile_num_from_latlon() ! amfox, 8 Nov 2026 - map lat/lon to cube-sphere grid cells with MAPL_GetGlobalHorzIJIndex() -! and the ESMF grid (get_ij_ind_from_latlon_c3(), init_c3_grid()) +! and the ESMF grid (get_ij_ind_from_latlon_c3(), init_tile_grid_g_ESMF_c3()) ! ! ======================================================================== @@ -59,7 +59,7 @@ module LDAS_TileCoordRoutines public :: get_tile_num_from_latlon public :: get_ij_ind_from_latlon public :: get_ij_ind_from_latlon_c3 - public :: init_c3_grid + public :: init_tile_grid_g_ESMF_c3 public :: tile2grid_simple public :: grid2tile public :: tile_mask_grid @@ -514,7 +514,7 @@ function get_minExtent_grid( N_tile, tc_i_indg, tc_j_indg, tc_minlon, tc_minlat, 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 @@ -776,7 +776,7 @@ 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, & - tile_num, max_dist_x, max_dist_y, c3_grid ) + tile_num, max_dist_x, max_dist_y, tile_grid_g_ESMF ) ! bug fix re. "check that lat/lon is inside tile_grid" ! - reichle, 2005/11/17 @@ -790,7 +790,7 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & ! - reichle, 2014/12/23 ! ! added cube-sphere ("c3") tile_grid, see get_tile_num_from_latlon_c3(); - ! requires optional input "c3_grid" (ESMF grid of cube-sphere tile space) + ! requires optional input "tile_grid_g_ESMF" (ESMF grid of cube-sphere tile space) ! - amfox, 8 Nov 2026 implicit none @@ -812,7 +812,7 @@ 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] - type(ESMF_Grid), optional, intent(in) :: c3_grid ! for "c3" tile_grid + type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! for "c3" tile_grid ! local variables @@ -847,15 +847,15 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & if (index(tile_grid%gridtype, 'c3')/=0) then - if (.not. present(c3_grid)) then + if (.not. present(tile_grid_g_ESMF)) then - err_msg = 'cube-sphere ("c3") tile_grid requires optional input c3_grid (ESMF grid)' + err_msg = 'cube-sphere ("c3") tile_grid requires optional input tile_grid_g_ESMF (ESMF grid)' call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - call get_tile_num_from_latlon_c3( c3_grid, tile_coord, & - tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & + call get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & + tile_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 @@ -998,7 +998,7 @@ end subroutine get_tile_num_from_latlon ! ******************************************************************* - subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & + subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & max_dist_x, max_dist_y, tile_num ) @@ -1007,7 +1007,7 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! tiles do not nest in the cells of a lat/lon grid, so for cube-sphere tile space, ! tile_grid 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). c3_grid is the ESMF grid of the cube-sphere tile space. + ! 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 @@ -1060,7 +1060,7 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & implicit none - type(ESMF_Grid), intent(in) :: c3_grid + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF type(tile_coord_type), dimension(:), pointer :: tile_coord ! input @@ -1128,7 +1128,7 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & ! determine grid cells that contain lat/lon - call get_ij_ind_from_latlon_c3( c3_grid, tile_grid, N_tmp, & + call get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid, 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 @@ -1238,7 +1238,7 @@ subroutine get_tile_num_from_latlon_c3( c3_grid, tile_coord, & end do - call get_ij_ind_from_latlon_c3( c3_grid, tile_grid, kk, & + call get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid, kk, & tmp_lat(1:kk), tmp_lon(1:kk), i_ind_nbr(1:kk), j_ind_nbr(1:kk) ) kk = 0 @@ -1537,7 +1537,7 @@ end subroutine get_ij_ind_from_latlon ! ******************************************************************* - subroutine get_ij_ind_from_latlon_c3( c3_grid, tile_grid, N_latlon, lat, lon, i_ind, j_ind ) + subroutine get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid, N_latlon, lat, lon, i_ind, j_ind ) ! find i/j_ind of cube-sphere ("c3") grid cells that contain lat/lon ! @@ -1548,19 +1548,19 @@ subroutine get_ij_ind_from_latlon_c3( c3_grid, tile_grid, N_latlon, lat, lon, i_ ! 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_c3_grid() rejects them, see there.) + ! 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_c3_grid() must have been called by all processors. + ! init_tile_grid_g_ESMF_c3() must have been called by all processors. ! ! amfox, 8 Nov 2026 implicit none - type(ESMF_Grid), intent(in) :: c3_grid + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF type(grid_def_type), intent(in) :: tile_grid @@ -1593,9 +1593,9 @@ subroutine get_ij_ind_from_latlon_c3( c3_grid, tile_grid, N_latlon, lat, lon, i_ 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_c3_grid()) --> pass a copy of the ESMF grid handle (same grid) + ! as attributes, see init_tile_grid_g_ESMF_c3()) --> pass a copy of the ESMF grid handle (same grid) - tmp_grid = c3_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 ) @@ -1623,7 +1623,7 @@ end subroutine get_ij_ind_from_latlon_c3 ! ******************************************************************* - subroutine init_c3_grid( c3_grid, tile_grid ) + subroutine init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid ) ! 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) @@ -1647,7 +1647,7 @@ subroutine init_c3_grid( c3_grid, tile_grid ) implicit none - type(ESMF_Grid), intent(in) :: c3_grid + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF type(grid_def_type), intent(in) :: tile_grid @@ -1665,12 +1665,12 @@ subroutine init_c3_grid( c3_grid, tile_grid ) logical :: has_factor, has_lon, has_lat - character(len=*), parameter :: Iam = 'init_c3_grid' + character(len=*), parameter :: Iam = 'init_tile_grid_g_ESMF_c3' character(len=400) :: err_msg ! ------------------------------------------------------------- - tmp_grid = c3_grid ! copy of ESMF grid handle (same grid), see get_ij_ind_from_latlon_c3() + 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) @@ -1727,10 +1727,10 @@ subroutine init_c3_grid( c3_grid, tile_grid ) end if - if (logit) write (logunit,*) trim(Iam), ': cube-sphere grid ready for obs-to-tile mapping, size = ', dims(1:2) + 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_c3_grid + end subroutine init_tile_grid_g_ESMF_c3 ! ******************************************************************* From 5b3500d2ae3e7d5e8af1406fcb0702c8744b556f Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Wed, 11 Nov 2026 12:42:36 -0500 Subject: [PATCH 37/90] cleaned up if blocks that calculate N_tile_in_cell_ij and tile_num_in_cell_ij for obs-to-tile mapping (clsm_ensupd_enkf_update.F90) --- .../clsm_ensupd_enkf_update.F90 | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 1627652d..3cd2fe39 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -294,6 +294,8 @@ subroutine get_enkf_increments( & 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 @@ -458,16 +460,9 @@ subroutine get_enkf_increments( & 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, & - tile_coord_f%i_indg, tile_coord_f%j_indg, & - obs2tile_grid_f, N_tile_in_cell_ij_f ) + tmp_i_indg = tile_coord_f%i_indg + tmp_j_indg = tile_coord_f%j_indg - ! second call: find out which tiles are in each tile_grid_f cell - call get_tile_num_in_cell_ij( N_catf, & - tile_coord_f%i_indg, tile_coord_f%j_indg, & - obs2tile_grid_f, maxval(N_tile_in_cell_ij_f), tile_num_in_cell_ij_f ) - else ! EASE or LatLon tile space: use pert_grid_f as hash grid for mapping obs to tile space @@ -479,17 +474,21 @@ subroutine get_enkf_increments( & 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 ) + tmp_i_indg = tile_coord_f%pert_i_indg + tmp_j_indg = tile_coord_f%pert_j_indg end if + + ! 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 From a38d33120a83d916dfc23fe758f2eeeb37a96f69 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Wed, 11 Nov 2026 12:54:31 -0500 Subject: [PATCH 38/90] removed pass-thru of tile_grid_g_ESMF from output_smapL4SMaup(), which is only used when tile space is EASEv2_M09, which is already checked in Initialize() of LandAssim GridComp (clsm_ensupd_enkf_update.F90) --- GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 3cd2fe39..94284db5 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -508,8 +508,7 @@ subroutine get_enkf_increments( & N_ens, N_catl, N_catf, N_obsl_max, & tile_coord_f, tile_grid_g, 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, & - tile_grid_g_ESMF=tile_grid_g_ESMF ) + N_obs_param, obs_param, Observations_l, cat_param, cat_progn ) ! check for observations, found_obs_f=.true. if obs availalbe @@ -2236,10 +2235,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, & + N_ens, N_catl, N_catf, N_obsl_max, & tile_coord_f, tile_grid_g, 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, tile_grid_g_ESMF ) + 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) @@ -2250,7 +2249,6 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & ! reichle, 11 Dec 2013 - added 'SMOS_fit_Tb*' obs species ! (needed for L4_SM_SMOS prototype product) ! amfox, 6 Nov 2026 - renamed pert_grid_f to obs2tile_grid_f (only passed through to collect_obs()) - ! amfox, 8 Nov 2026 - added optional tile_grid_g_ESMF (only passed through to collect_obs()) ! ! ------------------------------------------------------------------- @@ -2288,8 +2286,6 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & type(cat_param_type), dimension(N_catl), intent(in) :: cat_param type(cat_progn_type), dimension(N_catl,N_ens), intent(in) :: cat_progn - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF - ! ------------------------------------------ ! local variables @@ -2348,7 +2344,7 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & 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., & - N_obsl_tmp, Observations_l, found_obs_f, tile_grid_g_ESMF=tile_grid_g_ESMF ) + N_obsl_tmp, Observations_l, found_obs_f ) ! write appropriate fields (according to 'option') into file From 0c6403e44e8bdf366d3c9f88070982b438632841 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 12 Nov 2026 12:14:13 -0500 Subject: [PATCH 39/90] make "tile_grid_g_ESMF" regular input arg (not optional) for get_enkf_increments() (GEOS_LandAssimGridComp.F90, clsm_ensupd_enkf_update.F90) --- GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 | 9 +++++---- GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 index cba0ccbc..b84ac228 100644 --- a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 +++ b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 @@ -1613,7 +1613,7 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) call MAPL_LocStreamGet(locstream, NT_LOCAL=N_catl,rc=status) _VERIFY(status) - ! Get grid of tile space (needed to map obs to tiles in cube-sphere tile space) + ! 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) @@ -1924,7 +1924,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, & @@ -1935,8 +1936,8 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) Pert_rseed, obs_bias, & cat_progn_incr, fresh_incr, & N_obsf, N_obsl, Observations_l, & - N_adapt_R, obs_pert_adapt_param, Pert_adapt_R, & ! "adapt" is dummy for now - tile_grid_g_ESMF=tile_grid_g_ESMF ) + ! 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()) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 94284db5..daa82abd 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -153,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, & @@ -165,14 +166,14 @@ subroutine get_enkf_increments( & cat_progn_incr, fresh_incr, & N_obsf, N_obsl, Observations_l, & N_adapt_R, obs_pert_adapt_param, Pert_adapt_R, & - Obs_pert, tile_grid_g_ESMF ) + Obs_pert ) ! ------------------------------------------------------------- ! return increments instead of updated cat_progn ! reichle, 18 Oct 2005 ! - ! added optional input tile_grid_g_ESMF (ESMF grid of tile space), needed (only) to map obs + ! added input tile_grid_g_ESMF (ESMF grid of tile space), needed (only) to map obs ! to tiles in cube-sphere tile space ! amfox, 8 Nov 2026 @@ -205,8 +206,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 cube-sphere tile space + integer, intent(in), dimension(numprocs) :: N_catl_vec, low_ind integer, intent(in), dimension(N_catl) :: l2f @@ -257,8 +260,6 @@ subroutine get_enkf_increments( & real, dimension(N_obsl_max,N_ens), intent(out), optional :: Obs_pert - type(ESMF_Grid), intent(in), optional :: tile_grid_g_ESMF ! needed for cube-sphere tile space - ! ---------------------------------------------- ! local variables From fe1b8e15f052d22e7be48bb3e8b26d79b007185c Mon Sep 17 00:00:00 2001 From: amfox37 Date: Thu, 12 Nov 2026 11:58:56 -0700 Subject: [PATCH 40/90] Use land tiles only when copying per-tile data from tile_coord tile_coord holds all tiles of the forcing locstream (land, plus lake and landice if requested), but LandPert (i_indgs, j_indgs) and LandAssim (f_num) copied it into arrays sized for land tiles only (land_nt_local). This is an out-of-bounds write for grids with lake/landice tiles (e.g., cube-sphere; EASE M36 has none). Found as heap corruption on macOS (gfortran) and as a shape-mismatch abort in an Intel Debug build. - LandPert: pack() land tiles by tile type; _ASSERT on the land count. - LandAssim: assert land tiles come first in tile_coord (assumed by l2f, f_num and tile_coord_l passed with N_catl); set f_num for land tiles only. 0-diff for CF0090 on Discover (Release); not a fix for Debug runs, which additionally trip on NaN in the CF0090 vegopacity input. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 | 9 ++++++++- GEOSlandpert_GridComp/GEOS_LandPertGridComp.F90 | 7 +++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37eaad3d..f347e9e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 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 (e.g., cube-sphere tile space); `tile_coord` now used for land tiles only, with `_ASSERT`s (0-diff on Discover for CF0090; undefined behavior before). - Fixed QC of Tb obs for non-land surfaces (water, land ice) in cube-sphere tile space, where it was not applied (not 0-diff for cube-sphere tile space with Tb obs; 0-diff for EASE and lat/lon tile spaces). - 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)). diff --git a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 index 61c5f897..eab31322 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) 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 From dc140fbeab4288dc3b4596d6bc6cbbb0d99d05b6 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 12 Nov 2026 14:59:39 -0500 Subject: [PATCH 41/90] changed tile_grid_g_ESMF from optional to regular argument for subroutines that deal with reading of obs (clsm_ensupd_enkf_update.F90, clsm_ensupd_read_obs.F90, LDAS_TileCoordRoutines.F90) --- .../clsm_ensupd_enkf_update.F90 | 28 +- .../clsm_ensupd_read_obs.F90 | 304 ++++++++++-------- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 24 +- 3 files changed, 187 insertions(+), 169 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index daa82abd..4f2014e5 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -173,9 +173,8 @@ subroutine get_enkf_increments( & ! return increments instead of updated cat_progn ! reichle, 18 Oct 2005 ! - ! added input tile_grid_g_ESMF (ESMF grid of tile space), needed (only) to map obs - ! to tiles in cube-sphere tile space - ! amfox, 8 Nov 2026 + ! 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, 8 Nov 2026 implicit none @@ -208,7 +207,7 @@ subroutine get_enkf_increments( & 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 cube-sphere tile space + 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 @@ -420,13 +419,6 @@ subroutine get_enkf_increments( & if ( (index(tile_grid_g%gridtype,'c3')/=0) .and. (.not. c3_grid_initialized) ) then - if (.not. present(tile_grid_g_ESMF)) then - - err_msg = 'cube-sphere tile space requires optional input tile_grid_g_ESMF (ESMF grid)' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - call init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid_g ) c3_grid_initialized = .true. @@ -507,7 +499,7 @@ 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, obs2tile_grid_f, & + tile_coord_f, tile_grid_g, obs2tile_grid_f, tile_grid_g_ESMF, & 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 ) @@ -516,11 +508,11 @@ subroutine get_enkf_increments( & call collect_obs( & work_path, exp_id, date_time, dtstep_assim, & N_catl, & - N_catf, tile_coord_f, obs2tile_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, & - N_obsl, Observations_l, found_obs_f, tile_grid_g_ESMF=tile_grid_g_ESMF ) + N_obsl, Observations_l, found_obs_f ) ! -------------------------------------------------------------------- @@ -2237,7 +2229,7 @@ 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, obs2tile_grid_f, & + tile_coord_f, tile_grid_g, obs2tile_grid_f, tile_grid_g_ESMF, & 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 ) @@ -2269,6 +2261,8 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & type(grid_def_type), intent(in) :: tile_grid_g type(grid_def_type), intent(in) :: obs2tile_grid_f + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! pass-through only to collect_obs(), not needed for L4SMaup output + integer, dimension(numprocs), intent(in) :: N_catl_vec integer, dimension(numprocs), intent(in) :: low_ind @@ -2341,7 +2335,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, obs2tile_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., & @@ -2349,7 +2343,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_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 72adc6cb..0a48d809 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -433,9 +433,10 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF ) + found_obs, ae_l2_sm, std_ae_l2_sm ) ! Read observations of surface soil moisture from AMSR-E L2 files ! Set flag "found_obs" to true if observations are available @@ -466,14 +467,14 @@ subroutine read_obs_ae_l2_sm( & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param ! outputs: @@ -659,10 +660,11 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) ! ---------------------------------------------------------------- @@ -943,12 +945,13 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF ) + found_obs, ae_sm_LPRM, std_ae_sm_LPRM ) ! Read observations of surface soil moisture from AMSR-E sm LPRM files ! (Richard de Jeu, Vrije Universiteit Amsterdam) @@ -980,14 +983,14 @@ subroutine read_obs_ae_sm_LPRM( & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param ! outputs: @@ -1176,10 +1179,11 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) ! ---------------------------------------------------------------- @@ -1259,9 +1263,10 @@ 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, & + tile_grid_d, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, sm_ASCAT, std_sm_ASCAT, tile_grid_g_ESMF ) + found_obs, sm_ASCAT, std_sm_ASCAT ) !--------------------------------------------------------------------- ! @@ -1292,14 +1297,14 @@ subroutine read_obs_sm_ASCAT( & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param ! outputs: @@ -1491,10 +1496,11 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) ! ---------------------------------------------------------------- @@ -1572,9 +1578,9 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF ) + found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time ) !--------------------------------------------------------------------- ! @@ -1612,14 +1618,14 @@ subroutine read_obs_sm_ASCAT_EUMET( & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param ! outputs: @@ -2073,10 +2079,11 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) ! ---------------------------------------------------------------- @@ -2170,9 +2177,10 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF ) + found_obs, ASCAT_sm, ASCAT_sm_std, ASCAT_lon, ASCAT_lat, ASCAT_time ) ! Read H SAF ASCAT SSM CDR (H121) and ICDR (H139) from netCDF swath files. ! @@ -2224,13 +2232,13 @@ subroutine read_obs_sm_ASCAT_HSAF( & type(grid_def_type), intent(in) :: tile_grid_d + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param logical, intent(in) :: write_obslog @@ -2645,10 +2653,11 @@ subroutine read_obs_sm_ASCAT_HSAF( & 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) do ii = 1, N_valid @@ -2804,11 +2813,11 @@ 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, & - found_obs, CYGNSS_sm, CYGNSS_sm_std, CYGNSS_lon, CYGNSS_lat, CYGNSS_time, tile_grid_g_ESMF ) + subroutine read_obs_sm_CYGNSS( & + date_time, dtstep_assim, N_catd, tile_coord, & + tile_grid_d, 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 ) !--------------------------------------------------------------------- ! @@ -2843,13 +2852,13 @@ subroutine read_obs_sm_CYGNSS( & type(grid_def_type), intent(in) :: tile_grid_d + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param logical, intent(in) :: write_obslog @@ -3236,10 +3245,11 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) ! ---------------------------------------------------------------- ! @@ -3529,9 +3539,10 @@ 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, & + tile_grid_d, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, ts_LARC, std_ts_LARC, tile_grid_g_ESMF ) + found_obs, ts_LARC, std_ts_LARC ) !--------------------------------------------------------------------- ! @@ -3551,14 +3562,14 @@ subroutine read_obs_LaRC_Tskin( & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param ! outputs: @@ -3728,10 +3739,11 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) ! ---------------------------------------------------------------- @@ -4873,11 +4885,12 @@ 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, & - found_obs, isccp_tskin_gswp2_v1, std_isccp_tskin_gswp2_v1, tile_grid_g_ESMF ) + subroutine read_obs_isccp_tskin_gswp2_v1( & + date_time, N_catd, tile_coord, & + tile_grid_d, 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 ! produced by Sarith on GSWP-2 grid @@ -4906,14 +4919,14 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param ! outputs: @@ -5043,10 +5056,11 @@ 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, & + tile_grid_d, 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), tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num(1:N_tmp) ) ! ---------------------------------------------------------------- ! @@ -5567,9 +5581,9 @@ 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, & + dtstep_assim, tile_coord, tile_grid_d, 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, tile_grid_g_ESMF ) + found_obs, SMOS_data, std_SMOS_data, SMOS_lon, SMOS_lat ) ! reader for preprocessed SMOS Tb and soil moisture (SM) files ! @@ -5615,6 +5629,8 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & type(grid_def_type), intent(in) :: tile_grid_d + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space + type(tile_coord_type), dimension(:), pointer :: tile_coord ! input integer, dimension(tile_grid_d%N_lon,tile_grid_d%N_lat), intent(in) :: & @@ -5622,8 +5638,6 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - logical, intent(in) :: write_obslog ! outputs: @@ -6199,11 +6213,12 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & ! 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_shift_lat, tmp_shift_lon ) ! -------------------------------------------------------------------------- ! @@ -6395,9 +6410,10 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF ) + found_obs, MODIS_obs, std_MODIS_obs, MODIS_lon, MODIS_lat ) ! read MODIS snow cover fraction observations on MODIS 0.05-degree climate ! modeling grid (CMG) @@ -6425,13 +6441,13 @@ subroutine read_obs_MODIS_SCF( & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - type(obs_param_type), intent(in) :: this_obs_param logical, intent(in) :: write_obslog @@ -6814,11 +6830,11 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) std_MODIS_obs = this_obs_param%errstd @@ -7461,9 +7477,9 @@ end subroutine read_MODIS_SCF_hdf ! ***************************************************************** subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & + dtstep_assim, tile_coord, tile_grid_d, 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, tile_grid_g_ESMF ) + 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) @@ -7486,14 +7502,14 @@ subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - logical, intent(in) :: write_obslog ! outputs: @@ -7959,12 +7975,13 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_tile_num ) ! -------------------------------------------------------------------------- ! @@ -8148,9 +8165,9 @@ 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, & + dtstep_assim, tile_coord, tile_grid_d, 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, tile_grid_g_ESMF ) + 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) @@ -8186,14 +8203,14 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), pointer :: tile_num_in_cell_ij ! input - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - logical, intent(in) :: write_obslog ! outputs: @@ -9066,23 +9083,25 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & ! 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, & + tile_grid_d, 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_shift_lat, tmp_shift_lon, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tmp_shift_lat, tmp_shift_lon ) else call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, N_tile_in_cell_ij, tile_num_in_cell_ij, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF) + tmp_tile_num ) end if @@ -9875,10 +9894,11 @@ 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, & + tile_grid_d, 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, tile_grid_g_ESMF ) + tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time, tmp_assim ) ! read observations and optionally scale observations to model clim ! @@ -9894,34 +9914,33 @@ subroutine read_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) - ! 8 Nov 2026 - added optional input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space) - ! (amfox) + ! 8 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_catd type(tile_coord_type), dimension(:), pointer :: tile_coord ! input - type(grid_def_type), intent(in) :: tile_grid_d + type(grid_def_type), intent(in) :: tile_grid_d + + 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(:,:,:), 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 - - type(ESMF_Grid), intent(in), optional :: tile_grid_g_ESMF ! needed for cube-sphere tile space + logical, intent(in) :: write_obslog ! outputs: @@ -9970,9 +9989,10 @@ 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, & + tile_grid_d, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs ) ! scale observations to model climatology @@ -9991,9 +10011,10 @@ 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, & + tile_grid_d, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs ) ! scale observations to model climatology @@ -10012,9 +10033,10 @@ 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, & + tile_grid_d, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs ) ! scale observations to model climatology @@ -10031,10 +10053,11 @@ subroutine read_obs( & 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF) + tmp_time ) ! scale observations to model climatology @@ -10052,10 +10075,11 @@ subroutine read_obs( & 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF) + tmp_time ) ! scale observations to model climatology @@ -10073,10 +10097,11 @@ subroutine read_obs( & 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF) + tmp_time ) ! scale observations to model climatology @@ -10094,9 +10119,10 @@ subroutine read_obs( & 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, & + tile_grid_d, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs ) if (this_obs_param%scale .and. found_obs) then @@ -10219,9 +10245,9 @@ subroutine read_obs( & call read_obs_SMOS( & date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & + dtstep_assim, tile_coord, tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) ! scale observations to model climatology @@ -10239,9 +10265,9 @@ subroutine read_obs( & call read_obs_SMOS( & date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & + dtstep_assim, tile_coord, tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) ! scale observations to model climatology @@ -10258,9 +10284,10 @@ subroutine read_obs( & 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, & + tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat ) case('SMAP_L1C_Tbh_A', 'SMAP_L1C_Tbv_A', & 'SMAP_L1C_Tbh_D', 'SMAP_L1C_Tbv_D', & @@ -10273,9 +10300,9 @@ subroutine read_obs( & call read_obs_SMAP_halforbit_Tb( & date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, & + dtstep_assim, tile_coord, tile_grid_d, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs, tmp_lon, tmp_lat, tmp_time ) ! scale observations to model climatology @@ -10293,9 +10320,10 @@ subroutine read_obs( & 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, & + tile_grid_d, tile_grid_g_ESMF, & + N_tile_in_cell_ij, tile_num_in_cell_ij, & this_obs_param, & - found_obs, tmp_obs, tmp_std_obs, tile_grid_g_ESMF=tile_grid_g_ESMF ) + found_obs, tmp_obs, tmp_std_obs ) ! NOT IMPLEMENTED: scale observations to model climatology @@ -11385,10 +11413,11 @@ 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, tile_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, tile_grid_g_ESMF ) + N_obsl, Observations_l, found_obs_f ) ! check for observations that must be assimilated, ! collect into measurement vector @@ -11402,13 +11431,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 - ! 8 Nov 2026 - added optional input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space) - ! (amfox) + ! 8 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 @@ -11424,6 +11452,8 @@ subroutine collect_obs( type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(grid_def_type), intent(in) :: tile_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 (see get_enkf_increments()) @@ -11445,8 +11475,6 @@ subroutine collect_obs( logical, intent(out) :: found_obs_f - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! needed for cube-sphere tile space - ! ---------------------------- ! locals @@ -11509,10 +11537,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, & + tile_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, tile_grid_g_ESMF=tile_grid_g_ESMF) + 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. @@ -11895,10 +11924,11 @@ 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, & + tile_grid, 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, tile_grid_g_ESMF ) + shift_lat, shift_lon, ) ! find one tile for each obs that "administers" the obs ! @@ -11907,8 +11937,7 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & ! ! - reichle, 2015/02/20 ! - ! added optional input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space), see - ! get_tile_num_from_latlon() + ! added input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space), see get_tile_num_from_latlon() ! - amfox, 8 Nov 2026 implicit none @@ -11918,6 +11947,8 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input type(grid_def_type), intent(in) :: tile_grid + + 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 @@ -11932,8 +11963,6 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & real, optional, intent(in) :: shift_lat real, optional, intent(in) :: shift_lon - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! for cube-sphere tile space - ! ------------------------ ! local variables @@ -11992,9 +12021,10 @@ 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, & + tile_grid, 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, tile_grid_g_ESMF=tile_grid_g_ESMF ) + tile_num, max_dist_x, max_dist_y ) end subroutine get_tile_num_for_obs diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 32034a1c..51ec78c7 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -774,9 +774,10 @@ 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, & - tile_num, max_dist_x, max_dist_y, tile_grid_g_ESMF ) + subroutine get_tile_num_from_latlon( N_catd, tile_coord, & + tile_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 ) ! bug fix re. "check that lat/lon is inside tile_grid" ! - reichle, 2005/11/17 @@ -789,8 +790,8 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & ! meridional max distance (max_dist_x) ! - reichle, 2014/12/23 ! - ! added cube-sphere ("c3") tile_grid, see get_tile_num_from_latlon_c3(); - ! requires optional input "tile_grid_g_ESMF" (ESMF grid of cube-sphere tile space) + ! 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) ! - amfox, 8 Nov 2026 implicit none @@ -800,10 +801,12 @@ 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(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(:,:,:), pointer :: tile_num_in_cell_ij ! input + integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input real, dimension(N_latlon), intent(in) :: lat, lon @@ -812,8 +815,6 @@ 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] - type(ESMF_Grid), optional, intent(in) :: tile_grid_g_ESMF ! for "c3" tile_grid - ! local variables integer, parameter :: nodata_tilenum = -9999 @@ -847,13 +848,6 @@ subroutine get_tile_num_from_latlon(N_catd, tile_coord, & if (index(tile_grid%gridtype, 'c3')/=0) then - if (.not. present(tile_grid_g_ESMF)) then - - err_msg = 'cube-sphere ("c3") tile_grid requires optional input tile_grid_g_ESMF (ESMF grid)' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - call get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & tile_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 ) From 93b0c7c67824a111a95316354ec51e034a4e34eb Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 12 Nov 2026 15:14:18 -0500 Subject: [PATCH 42/90] fix typo/syntax error in previous commit (clsm_ensupd_read_obs.F90) --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 0a48d809..844149bc 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -11928,7 +11928,7 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & this_obs_param, & tile_num, & - shift_lat, shift_lon, ) + shift_lat, shift_lon ) ! find one tile for each obs that "administers" the obs ! From 2bfe972f80d07cad85ae2594f79d82c13e7ee77c Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 12 Nov 2026 16:23:50 -0500 Subject: [PATCH 43/90] changed order of inputs args of output_smapL4SMaup() (clsm_ensupd_enkf_update.F90) --- GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 4f2014e5..fb342136 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -499,7 +499,7 @@ 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, obs2tile_grid_f, tile_grid_g_ESMF, & + 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 ) @@ -2229,7 +2229,7 @@ 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, obs2tile_grid_f, tile_grid_g_ESMF, & + 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 ) From 949f5b082c2e553a9cd9bd5d97258139903d5c88 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 12 Nov 2026 17:23:15 -0500 Subject: [PATCH 44/90] small cleanup of if block, comment, declaration (clsm_ensupd_enkf_update.F90) --- GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index fb342136..1d9faf8e 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -451,8 +451,6 @@ subroutine get_enkf_increments( & obs2tile_grid_f%ur_lon = pert_grid_f%ur_lon obs2tile_grid_f%ur_lat = pert_grid_f%ur_lat - allocate(N_tile_in_cell_ij_f(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat)) - tmp_i_indg = tile_coord_f%i_indg tmp_j_indg = tile_coord_f%j_indg @@ -465,13 +463,13 @@ subroutine get_enkf_increments( & obs2tile_grid_f = pert_grid_f - allocate(N_tile_in_cell_ij_f(pert_grid_f%N_lon,pert_grid_f%N_lat)) - 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, & @@ -2241,7 +2239,6 @@ subroutine output_smapL4SMaup( date_time, work_path, exp_id, dtstep_assim, & ! reichle, 2 May 2013 ! reichle, 11 Dec 2013 - added 'SMOS_fit_Tb*' obs species ! (needed for L4_SM_SMOS prototype product) - ! amfox, 6 Nov 2026 - renamed pert_grid_f to obs2tile_grid_f (only passed through to collect_obs()) ! ! ------------------------------------------------------------------- @@ -2258,10 +2255,9 @@ 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) :: obs2tile_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 to collect_obs(), not needed for L4SMaup output + 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 From a35b6930666eedbc417298b3e3ad105e2b67a1eb Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 12 Nov 2026 18:13:59 -0500 Subject: [PATCH 45/90] renamed tile_grid to tiles2obsFOV_grid where applicable (clsm_ensupd_upd_routines.F90, clsm_ensupd_enkf_update.F90) --- .../clsm_ensupd_enkf_update.F90 | 10 ++-- .../clsm_ensupd_upd_routines.F90 | 48 +++++++++++-------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index 1d9faf8e..c1eca79d 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -405,11 +405,11 @@ 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 only by root process - ! (because of call to read_obs() in collect_obs()). - ! (For 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, 8 Nov 2026) + ! 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, 8 Nov 2026 call init_grid_def_type( obs2tile_grid_f ) ! initialize to undefined grid diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index 09b60fcf..e489b3b9 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -998,7 +998,7 @@ 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, tiles2obsFOV_grid_g, & obs_param, & met_force, lai, cat_param, cat_progn, mwRTM_param, & N_obsl, Observations_l, Obs_pred_l, obsbias_ok, & @@ -1040,7 +1040,7 @@ 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) :: tiles2obsFOV_grid_g ! hash grid for mapping from tile space to obs FOV type(obs_param_type), intent(in), dimension(N_obs_param) :: obs_param @@ -1061,8 +1061,11 @@ subroutine get_obs_pred( & real, intent(in), optional :: fcsterr_inflation_fac - ! "tile_grid_g" is the pert grid (which is lat/lon for cube-sphere tile space), so tell - ! get_obs_pred() whether the tile space is cube-sphere (default: .false.) + ! get_obs_pred() is called 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, + ! => need "c3_tile_space" to tell get_obs_pred() whether the tile space is cube-sphere (default: .false.) logical, intent(in), optional :: c3_tile_space @@ -1108,7 +1111,8 @@ 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 + + type(grid_def_type) :: tiles2obsFOV_grid_lH integer, dimension(N_obs_param) :: ind_obsparam2Tbspecies integer, dimension(N_obs_param) :: ind_Tbspecies2TbuniqFreqAngRTMid @@ -1583,9 +1587,12 @@ 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 ) @@ -1706,27 +1713,28 @@ subroutine get_obs_pred( & 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 - 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, & + 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 @@ -1808,7 +1816,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 ) @@ -1907,7 +1915,7 @@ subroutine get_obs_pred( & ! that are entirely non-land are not considered because the ! calculations use only land tile properties - if (index(tile_grid_g%gridtype, 'EASEv') /=0) then + if (index(tiles2obsFOV_grid_g%gridtype, 'EASEv') /=0) then ! ADDITIONAL ASSUMPTIONS: ! - at most one land tile per grid cell From 1b27363fbb081bf59fa854edc1785347ecfe904b Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 12 Nov 2026 18:50:14 -0500 Subject: [PATCH 46/90] for cross-file consistency and clarity, renamed tile_grid_d -> obs2tile_grid_d, N_catd -> N_catf, tile_coord[_d] -> tile_coord_f throughout obs reader subroutines (clsm_ensupd_read_obs.F90) --- .../clsm_ensupd_read_obs.F90 | 770 +++++++++--------- 1 file changed, 385 insertions(+), 385 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 844149bc..da4c7770 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -432,8 +432,8 @@ 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, tile_grid_g_ESMF, & + 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 ) @@ -447,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 ! @@ -462,15 +462,15 @@ 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 @@ -479,8 +479,8 @@ subroutine read_obs_ae_l2_sm( & ! 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 ! --------------- @@ -512,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' @@ -659,8 +659,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -677,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 @@ -691,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 @@ -713,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 @@ -947,8 +947,8 @@ end subroutine read_ae_sm_LPRM_bin subroutine read_obs_ae_sm_LPRM( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -963,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 ! @@ -978,15 +978,15 @@ 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 @@ -995,8 +995,8 @@ subroutine read_obs_ae_sm_LPRM( & ! 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 ! --------------- @@ -1028,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' @@ -1178,8 +1178,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -1196,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 @@ -1210,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 @@ -1232,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 @@ -1262,8 +1262,8 @@ 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, tile_grid_g_ESMF, & + 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 ) @@ -1292,15 +1292,15 @@ 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 @@ -1309,8 +1309,8 @@ subroutine read_obs_sm_ASCAT( & ! 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 ! --------------- @@ -1340,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 @@ -1495,8 +1495,8 @@ subroutine read_obs_sm_ASCAT( & allocate(tmp_tile_num(N_tmp)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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, & @@ -1513,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 @@ -1527,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 @@ -1549,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 ! -------------------------------- @@ -1576,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, tile_grid_g_ESMF, 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 ) !--------------------------------------------------------------------- @@ -1613,15 +1613,15 @@ 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 @@ -1632,10 +1632,10 @@ subroutine read_obs_sm_ASCAT_EUMET( & 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 ! --------------- @@ -1705,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 @@ -2078,8 +2078,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -2100,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 @@ -2117,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 @@ -2176,8 +2176,8 @@ end subroutine read_obs_sm_ASCAT_EUMET ! **************************************************************************** subroutine read_obs_sm_ASCAT_HSAF( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -2226,15 +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 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 @@ -2247,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 ! --------------- @@ -2343,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(:) @@ -2652,8 +2652,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -2706,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 @@ -2749,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 @@ -2814,8 +2814,8 @@ end subroutine read_obs_sm_ASCAT_HSAF ! **************************************************************************** subroutine read_obs_sm_CYGNSS( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, 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, CYGNSS_sm, CYGNSS_sm_std, CYGNSS_lon, CYGNSS_lat, CYGNSS_time ) @@ -2846,15 +2846,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 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 @@ -2867,10 +2867,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: @@ -2909,7 +2909,7 @@ 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(:,:) @@ -3244,8 +3244,8 @@ subroutine read_obs_sm_CYGNSS( allocate(tmp_tile_num(N_obs)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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, & @@ -3265,7 +3265,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 @@ -3282,7 +3282,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 @@ -3538,8 +3538,8 @@ end subroutine read_sm_ASCAT_bin ! ***************************************************************** subroutine read_obs_LaRC_Tskin( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -3557,15 +3557,15 @@ 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 @@ -3574,8 +3574,8 @@ subroutine read_obs_LaRC_Tskin( & ! 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 ! --------------- @@ -3603,7 +3603,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 @@ -3738,8 +3738,8 @@ subroutine read_obs_LaRC_Tskin( & allocate(tmp_tile_num(N_tmp)) - call get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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, & @@ -3757,7 +3757,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 @@ -3777,7 +3777,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 @@ -3793,7 +3793,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 @@ -4254,8 +4254,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 @@ -4268,7 +4268,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 @@ -4281,16 +4281,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 ! --------------- @@ -4329,7 +4329,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 @@ -4404,10 +4404,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)' @@ -4430,7 +4430,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 @@ -4479,7 +4479,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 @@ -4497,7 +4497,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 @@ -4515,7 +4515,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 @@ -4544,7 +4544,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 ) @@ -4558,7 +4558,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 @@ -4572,14 +4572,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 ! --------------- @@ -4637,8 +4637,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 @@ -4665,7 +4665,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 ) @@ -4677,7 +4677,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 @@ -4691,14 +4691,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 ! --------------- @@ -4752,10 +4752,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 @@ -4781,7 +4781,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 @@ -4791,7 +4791,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 ! @@ -4803,14 +4803,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 ! --------------- @@ -4860,7 +4860,7 @@ subroutine read_obs_RedArkOSSE_truth( & if (istat==0) then - do i=1,N_catd + do i=1,N_catf read(10,*) tmp_real @@ -4872,7 +4872,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 @@ -4886,8 +4886,8 @@ end subroutine read_obs_RedArkOSSE_truth ! ***************************************************************** subroutine read_obs_isccp_tskin_gswp2_v1( & - date_time, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -4902,7 +4902,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 ! @@ -4914,15 +4914,15 @@ 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 @@ -4931,8 +4931,8 @@ subroutine read_obs_isccp_tskin_gswp2_v1( & ! 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 ! --------------- @@ -4973,7 +4973,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 ! ------------------------------------------------------------------- @@ -5055,8 +5055,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -5072,7 +5072,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 @@ -5086,7 +5086,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 @@ -5106,7 +5106,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 @@ -5129,7 +5129,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 ) @@ -5142,7 +5142,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 ! @@ -5154,16 +5154,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 ! --------------- @@ -5256,7 +5256,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 @@ -5305,7 +5305,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 @@ -5339,7 +5339,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 @@ -5356,9 +5356,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 *** @@ -5373,7 +5373,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 ! @@ -5385,16 +5385,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 ! --------------- @@ -5475,7 +5475,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 @@ -5523,7 +5523,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 @@ -5565,7 +5565,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 @@ -5580,9 +5580,9 @@ 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, tile_grid_g_ESMF, & - N_tile_in_cell_ij, tile_num_in_cell_ij, write_obslog, & + 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 @@ -5625,15 +5625,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(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - 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 @@ -5644,8 +5644,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 ! -------------------------------------- @@ -5710,7 +5710,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 @@ -6212,8 +6212,8 @@ subroutine read_obs_SMOS( date_time, N_catd, this_obs_param, & ! (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, tile_grid_g_ESMF, & + 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, & @@ -6248,16 +6248,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', & @@ -6288,7 +6288,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 @@ -6304,7 +6304,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 @@ -6332,7 +6332,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 @@ -6409,8 +6409,8 @@ end subroutine read_obs_SMOS ! ***************************************************************** subroutine read_obs_MODIS_SCF( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -6436,15 +6436,15 @@ 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 @@ -6456,7 +6456,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) :: MODIS_obs, std_MODIS_obs, MODIS_lon, MODIS_lat ! ------------------------------------------------------------------------ @@ -6509,7 +6509,7 @@ 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=400) :: err_msg @@ -6570,7 +6570,7 @@ 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 ) @@ -6580,11 +6580,11 @@ subroutine read_obs_MODIS_SCF( & ! ! --> because tiles have a non-zero extent, need to read MODIS 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 @@ -6686,8 +6686,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 ) @@ -6829,8 +6829,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -6847,7 +6847,7 @@ subroutine read_obs_MODIS_SCF( & 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 @@ -6863,7 +6863,7 @@ 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)) @@ -6908,9 +6908,9 @@ subroutine read_obs_MODIS_SCF( & ! need only one longitude band (keep obs when lon_endlon_beg) ) & + if ( (tile_coord_f(kk)%com_lon<=lon_end) .or. (tile_coord_f(kk)%com_lon>lon_beg) ) & MODIS_obs(kk) = this_obs_param%nodata end do @@ -6919,9 +6919,9 @@ 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) ) & + if ( (tile_coord_f(kk)%com_lon>lon_beg) .and. (tile_coord_f(kk)%com_lon<=lon_end) ) & MODIS_obs(kk) = this_obs_param%nodata end do @@ -7476,8 +7476,8 @@ end subroutine read_MODIS_SCF_hdf ! ***************************************************************** - subroutine read_obs_SMAP_FT( date_time, N_catd, this_obs_param, & - dtstep_assim, tile_coord, tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -7495,17 +7495,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 @@ -7516,9 +7516,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 ! -------------------------------------- @@ -7585,7 +7585,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 @@ -7974,8 +7974,8 @@ 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, tile_grid_g_ESMF, & + 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)), & @@ -8021,16 +8021,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', & @@ -8056,7 +8056,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 @@ -8087,7 +8087,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 @@ -8113,7 +8113,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 @@ -8164,8 +8164,8 @@ 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, tile_grid_g_ESMF, & + 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 ) @@ -8196,17 +8196,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_f_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 @@ -8217,9 +8217,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 ! -------------------------------------- @@ -8309,7 +8309,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 @@ -9075,15 +9075,15 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catd, this_obs_param, & ! shift M36 obs lat/lon for proper assignment of M09 tile? - if ( L1C_files .and. (index(tile_grid_d%gridtype, 'EASEv2_M09') /=0 .or. index(tile_grid_d%gridtype, 'EASEv2-M09') /=0 )) then + if ( L1C_files .and. (index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0 .or. index(obs2tile_grid_f%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, tile_grid_g_ESMF, & + 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)), & @@ -9094,8 +9094,8 @@ 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, tile_grid_g_ESMF, & + 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)), & @@ -9142,16 +9142,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', & @@ -9177,7 +9177,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 @@ -9215,7 +9215,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 @@ -9241,7 +9241,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 @@ -9893,8 +9893,8 @@ end function SMAPdatetime_to_DateTimeType subroutine read_obs( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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, & @@ -9908,7 +9908,7 @@ 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) @@ -9925,15 +9925,15 @@ subroutine read_obs( & 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 @@ -9944,12 +9944,12 @@ subroutine read_obs( & ! 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 @@ -9969,8 +9969,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) @@ -9988,8 +9988,8 @@ subroutine read_obs( & call read_obs_ae_l2_sm( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -10000,7 +10000,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 @@ -10010,8 +10010,8 @@ subroutine read_obs( & call read_obs_ae_sm_LPRM( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -10022,7 +10022,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 @@ -10032,8 +10032,8 @@ subroutine read_obs( & call read_obs_sm_ASCAT( & work_path, exp_id, & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -10044,7 +10044,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 @@ -10052,8 +10052,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -10065,7 +10065,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 ) @@ -10074,8 +10074,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -10087,7 +10087,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 ) @@ -10096,8 +10096,8 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -10109,7 +10109,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 ) @@ -10118,8 +10118,8 @@ subroutine read_obs( & case ('isccp_tskin_gswp2_v1') call read_obs_isccp_tskin_gswp2_v1( & - date_time, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -10128,7 +10128,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 @@ -10136,7 +10136,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 ) @@ -10144,7 +10144,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 @@ -10152,7 +10152,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 ) @@ -10160,7 +10160,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 @@ -10168,7 +10168,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) @@ -10177,7 +10177,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 @@ -10185,7 +10185,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) @@ -10194,7 +10194,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 @@ -10202,7 +10202,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) @@ -10211,7 +10211,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 @@ -10227,7 +10227,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) @@ -10236,17 +10236,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, tile_grid_g_ESMF, & - 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 @@ -10255,7 +10255,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 @@ -10263,10 +10263,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, tile_grid_g_ESMF, & - 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 @@ -10275,7 +10275,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 @@ -10283,8 +10283,8 @@ subroutine read_obs( & case ('MOD10C1','MYD10C1') call read_obs_MODIS_SCF( & - date_time, dtstep_assim, N_catd, tile_coord, & - tile_grid_d, tile_grid_g_ESMF, & + 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 ) @@ -10299,8 +10299,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, tile_grid_g_ESMF, & + 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 ) @@ -10310,7 +10310,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 @@ -10319,8 +10319,8 @@ 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, tile_grid_g_ESMF, & + 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 ) @@ -10340,7 +10340,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 @@ -10367,20 +10367,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 @@ -10421,7 +10421,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 @@ -10446,7 +10446,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) @@ -10455,7 +10455,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 @@ -10463,7 +10463,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 @@ -10566,8 +10566,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) @@ -10585,9 +10585,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 @@ -10595,8 +10595,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 ! ---------------------------------------------------------- @@ -10667,7 +10667,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 @@ -10677,7 +10677,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) @@ -10687,14 +10687,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 @@ -10745,7 +10745,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 ) @@ -10790,21 +10790,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 ! ------------------- @@ -10920,7 +10920,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) @@ -10993,7 +10993,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) @@ -11012,12 +11012,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. @@ -11034,9 +11034,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 @@ -11044,9 +11044,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 ! ---------------------------------------------------------- @@ -11303,7 +11303,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) @@ -11313,11 +11313,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 @@ -11325,7 +11325,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 @@ -11351,8 +11351,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 @@ -11413,7 +11413,7 @@ 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, tile_grid_g_ESMF, & + 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, & @@ -11451,7 +11451,7 @@ 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 @@ -11537,7 +11537,7 @@ subroutine collect_obs( call read_obs( & work_path, exp_id, & date_time, dtstep_assim, N_catf, tile_coord_f, & - tile_grid_f, tile_grid_g_ESMF, & + 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, & @@ -11771,7 +11771,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 ) @@ -11793,15 +11793,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 @@ -11819,7 +11819,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 @@ -11923,8 +11923,8 @@ end subroutine add_to_obslog ! ***************************************************************** - subroutine get_tile_num_for_obs(N_catd, tile_coord, & - tile_grid, tile_grid_g_ESMF, & + subroutine get_tile_num_for_obs(N_catf, tile_coord_f, & + obs2tile_grid, tile_grid_g_ESMF, & N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & this_obs_param, & tile_num, & @@ -11942,15 +11942,15 @@ subroutine get_tile_num_for_obs(N_catd, tile_coord, & 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 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%N_lon,obs2tile_grid%N_lat), intent(in) :: N_tile_in_cell_ij integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input @@ -12020,8 +12020,8 @@ 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, tile_grid_g_ESMF, & + call get_tile_num_from_latlon(N_catf, tile_coord_f, & + obs2tile_grid, 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 ) From bda33b01c5dbe7245f12ebe3be2d789438550b2b Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 10:03:31 -0500 Subject: [PATCH 47/90] fixed typo/syntax error in previous commit (clsm_ensupd_read_obs.F90) --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index da4c7770..0377c4e3 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -8200,7 +8200,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catf, this_obs_param, & type(obs_param_type), intent(in) :: this_obs_param - type(tile_coord_f_type), dimension(:), pointer :: tile_coord_f ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input type(grid_def_type), intent(in) :: obs2tile_grid_f From 7d34a53507eba4fbeb4b73fea581e2a490851cfe Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 11:08:27 -0500 Subject: [PATCH 48/90] replaced optional logical arg "c3_tile_grid" with new regular arg "tile_grid_g"; renamed pert_grid_g to tiles2obsFOV_grid_g where appropriate (GEOS_LandAssimGridComp.F90, clsm_ensupd_enkf_update.F90, clsm_ensupd_upd_routines.F90) --- .../GEOS_LandAssimGridComp.F90 | 3 +- .../clsm_ensupd_enkf_update.F90 | 53 ++++++++++--------- .../clsm_ensupd_upd_routines.F90 | 37 +++++-------- 3 files changed, 44 insertions(+), 49 deletions(-) diff --git a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 index b84ac228..11745c0a 100644 --- a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 +++ b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 @@ -1961,7 +1961,8 @@ subroutine RUN ( GC, IMPORT, EXPORT, CLOCK, RC ) 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_catf, tile_coord_rf, & + tcinternal%tgrid_g, tiles2obsFOV_grid_g=tcinternal%pgrid_g, & ! passed through to get_obs_pred() N_catl_vec, low_ind, rf2l, & update_type, LandAssimDTstep, & obs_param, & diff --git a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index c1eca79d..fb4d8e62 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -584,17 +584,22 @@ 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, & - fcsterr_inflation_fac, & - c3_tile_space = (index(tile_grid_g%gridtype,'c3')/=0) ) + ! 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( & + beforeEnKFupdate = .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, tiles2obsFOV_grid_g = pert_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) @@ -2122,7 +2127,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, & @@ -2151,7 +2156,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 @@ -2195,20 +2201,17 @@ 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( & + beforeEnKFupdate=.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 ) - ! NOTE: no need to pass c3_tile_space into get_obs_pred() here; obs that fail the QC - ! of Tb for non-land surfaces were already removed in the call to get_obs_pred() - ! before the EnKF update (amfox, 6 Nov 2026) - ! clean up if (associated(Obs_pred_l)) deallocate(Obs_pred_l) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index e489b3b9..5e99e69a 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -998,11 +998,12 @@ 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, tiles2obsFOV_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, & - fcsterr_inflation_fac, c3_tile_space ) + fcsterr_inflation_fac ) ! Compute ensemble of measurement predictions from ensemble ! of tile-space Catchment prognostics. @@ -1025,8 +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 optional input "c3_tile_space" and QC of Tb for non-land - ! surfaces in cube-sphere tile space + ! 6 Nov 2026 - amfox: added QC of Tb for non-land surfaces in cube-sphere tile space implicit none @@ -1040,8 +1040,9 @@ subroutine get_obs_pred( & integer, intent(in), dimension(numprocs) :: N_catl_vec, low_ind - type(grid_def_type), intent(in) :: tiles2obsFOV_grid_g ! hash grid for mapping from tile space to obs FOV - + 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 @@ -1060,14 +1061,6 @@ subroutine get_obs_pred( & logical, intent(in), dimension(N_obsl), optional :: obsbias_ok real, intent(in), optional :: fcsterr_inflation_fac - - ! get_obs_pred() is called 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, - ! => need "c3_tile_space" to tell get_obs_pred() whether the tile space is cube-sphere (default: .false.) - - logical, intent(in), optional :: c3_tile_space ! -------------------------------------------------------------------------------- ! @@ -1098,7 +1091,6 @@ subroutine get_obs_pred( & logical :: tmpRFI, tmpWater, tmpPeat, use_distance_weights - logical :: c3_tile_space_tmp integer :: ind_i_min, ind_i_max, ind_j_min, ind_j_max real, dimension(1) :: tmpmean, tmpvar @@ -1111,6 +1103,8 @@ subroutine get_obs_pred( & logical :: get_FT_l, get_FT_lH logical :: get_asnow_l, get_asnow_lH logical :: get_peat_lH + + logical :: c3_tile_space type(grid_def_type) :: tiles2obsFOV_grid_lH @@ -1604,13 +1598,10 @@ subroutine get_obs_pred( & ! 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 - ! - amfox, 6 Nov 2026 - - c3_tile_space_tmp = .false. - - if (present(c3_tile_space)) c3_tile_space_tmp = c3_tile_space - - if (c3_tile_space_tmp .and. get_Tb_lH) then + + c3_tile_space = (index(tile_grid_g%gridtype,'c3')/=0) + + if (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) @@ -1931,7 +1922,7 @@ subroutine get_obs_pred( & call tile2obs_helper( & N_tmp, tmp_wFOV(1:N_tmp), tmp_data(1:N_tmp), tmp_land_frac) - elseif (c3_tile_space_tmp) then + elseif (c3_tile_space) then ! 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, From f58ef7d419782f558e0946b0caa4321ccdb58a5b Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 12:51:09 -0500 Subject: [PATCH 49/90] fix keyword arg syntax error in previous commit (GEOS_LandAssimGridComp.F90, clsm_ensupd_enkf_update.F90) --- .../GEOS_LandAssimGridComp.F90 | 22 +++++------ .../clsm_ensupd_enkf_update.F90 | 38 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 index 11745c0a..890a9c7e 100644 --- a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 +++ b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 @@ -1957,17 +1957,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%tgrid_g, tiles2obsFOV_grid_g=tcinternal%pgrid_g, & ! passed through to get_obs_pred() - 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 fb4d8e62..de995fd9 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -589,16 +589,16 @@ subroutine get_enkf_increments( & ! - EASE for EASE tile space, ! - LatLon for cube-sphere tile space, - call get_obs_pred( & - beforeEnKFupdate = .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, tiles2obsFOV_grid_g = 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( & + .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) @@ -2201,15 +2201,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( & - beforeEnKFupdate=.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, & + 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 From 6887e843bdb27f3b3b582f7ed0f8ed2103695bcd Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 13:58:47 -0500 Subject: [PATCH 50/90] changed name of logical variable "c3_grid" to "c3_tile_space" for clarity; added comment (preprocess_ldas_routines.F90, clsm_ensupd_upd_routines.F90) --- GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 | 2 +- GEOSldas_App/preprocess_ldas_routines.F90 | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index 5e99e69a..ce714998 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1707,7 +1707,7 @@ subroutine get_obs_pred( & ! determine tiles2obsFOV_grid_lH from tile_coord_lH and tiles2obsFOV_grid_g tiles2obsFOV_grid_lH = get_minExtent_grid( & - N_catlH, tile_coord_lH%pert_i_indg, tile_coord_lH%pert_j_indg, & + 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) diff --git a/GEOSldas_App/preprocess_ldas_routines.F90 b/GEOSldas_App/preprocess_ldas_routines.F90 index ae46007e..f2553d5a 100644 --- a/GEOSldas_App/preprocess_ldas_routines.F90 +++ b/GEOSldas_App/preprocess_ldas_routines.F90 @@ -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 From 8fb0524b5f5a3ff69fe7de3a63510320abe11bcc Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 14:03:35 -0500 Subject: [PATCH 51/90] for clarification, edited comments and renamed variables: - subroutine io_domain_files() - N_cat_domain --> N_catf - tile_grid_d --> tile_grid_f - subroutines LDAS_create_grid_g(), get_minExtent_grid() - tile_grid[_g] --> my_grid[_g] --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 294 +++++++++++++------------ 1 file changed, 151 insertions(+), 143 deletions(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 51ec78c7..e55faa01 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -78,7 +78,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 @@ -86,19 +86,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 @@ -114,7 +114,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 ! ----------------------------------------------------------- ! @@ -172,20 +172,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 @@ -225,7 +225,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') @@ -264,8 +264,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') @@ -283,13 +283,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 @@ -299,7 +301,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 @@ -310,27 +312,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. @@ -345,13 +348,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 @@ -362,12 +365,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 ! ---------------- @@ -383,69 +386,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 @@ -453,18 +456,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 my_grid 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 @@ -473,18 +478,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() ! @@ -499,8 +506,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 @@ -513,10 +520,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_(:) character(len=*), parameter :: Iam = 'get_minExtent_grid' - character(len=400) :: err_msg + character(len=400) :: err_msg ! ------------------------------------------------- @@ -525,99 +533,99 @@ 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 From a0da96798a5df9b256e7d9ab46ff4d3a714bed96 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 15:00:25 -0500 Subject: [PATCH 52/90] for clarification, edited comments and changed "tile_grid" to "my_grid" in subroutines: - get_number_of_tiles_in_cell_ij() - get_tile_num_in_cell_ij() - get_tile_num_from_latlon() --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 107 ++++++++++++------------- 1 file changed, 51 insertions(+), 56 deletions(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index e55faa01..c3b3d55f 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -631,18 +631,18 @@ 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() @@ -658,10 +658,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 @@ -670,8 +669,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 @@ -687,33 +686,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() @@ -729,16 +721,15 @@ 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 @@ -750,16 +741,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(tile_grid%N_lon,tile_grid%N_lat, & - max_N_tile_in_cells)) + allocate(tile_num_in_cell_ij( my_grid%N_lon, my_grid%N_lat, max_N_tile_in_cells )) tile_num_in_cell_ij = nodata ! 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 @@ -783,10 +772,16 @@ end subroutine get_tile_num_in_cell_ij ! ******************************************************************* subroutine get_tile_num_from_latlon( N_catd, tile_coord, & - tile_grid, tile_grid_g_ESMF, & + 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 ! @@ -808,11 +803,11 @@ 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 @@ -851,16 +846,16 @@ subroutine get_tile_num_from_latlon( N_catd, tile_coord, & tile_num = nodata_tilenum ! initialize to negative value - ! cube-sphere tile_grid: tiles do not nest in grid cells of a lat/lon grid, - ! use bounding boxes of tiles (amfox, 8 Nov 2026) - - if (index(tile_grid%gridtype, 'c3')/=0) then - - call get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & - tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & + 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, 8 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 + return ! all done if tile space is cube-sphere end if @@ -868,16 +863,16 @@ subroutine get_tile_num_from_latlon( N_catd, tile_coord, & 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 @@ -888,17 +883,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) @@ -922,7 +917,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). @@ -958,7 +953,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 From b019d40bf7123867af509305d5b26c9d9329924e Mon Sep 17 00:00:00 2001 From: amfox37 Date: Tue, 10 Nov 2026 17:07:09 -0700 Subject: [PATCH 53/90] use "sed -i.tmp" so process_hist.csh works with BSD sed on macOS (process_hist.csh) BSD sed takes the argument after "-i" as the backup suffix, so "sed -i 'expr' file" failed on macOS and the HISTORY collections were never activated. "sed -i.tmp" works with both GNU and BSD sed; the backup file is removed at the end of the script. Results with GNU sed are unchanged (0-diff). Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + GEOSldas_App/process_hist.csh | 49 ++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd7074c6..5a6c3a39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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), caused by FFT lengths (`fft_lens`) that were never set (0-diff for builds with MKL). +- Fixed `process_hist.csh` for BSD `sed` (macOS), which takes the argument after `-i` as backup suffix; now uses `sed -i.tmp` and removes the backup file (0-diff with GNU `sed`). ### Removed 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 From 3ae03d290a839d156073d0f80d2f9b2f3f6d9ace Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 16:44:35 -0500 Subject: [PATCH 54/90] for clarification, edited comments and changed variable names: - from "tile_grid" to "my_grid" in subroutines: - get_tile_num_in_ellipse() - get_ij_ind_from_latlon() - from "tile_grid" to "tile_grid_g" in subroutines: - get_ij_ind_from_latlon_c3() - init_tile_grid_g_ESMF_c3() - get_tile_num_from_latlon_c3() - get_tile_num_in_bbox_c3() --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 152 +++++++++++++------------ 1 file changed, 78 insertions(+), 74 deletions(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index c3b3d55f..0c07f80e 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -456,7 +456,7 @@ subroutine LDAS_create_grid_g( gridname, n_lon, n_lat, & if( c3_grid) then - ! LDAS grid type cannot really represent c3 grid parameters; fill in my_grid as much as possible + ! 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 @@ -995,14 +995,14 @@ end subroutine get_tile_num_from_latlon ! ******************************************************************* - subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & - tile_grid, N_tile_in_cell_ij, tile_num_in_cell_ij, N_latlon, lat, lon, & + 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() ! ! tiles do not nest in the cells of a lat/lon grid, so for cube-sphere tile space, - ! tile_grid must be the cube-sphere grid that defines the tile space (and + ! 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. ! @@ -1061,9 +1061,9 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, 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) :: tile_grid_g - integer, dimension(tile_grid%N_lon,tile_grid%N_lat), intent(in) :: N_tile_in_cell_ij + 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 @@ -1125,7 +1125,7 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & ! determine grid cells that contain lat/lon - call get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid, N_tmp, & + 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 @@ -1139,15 +1139,15 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & ! Make sure lat/lon is *inside* tile_grid, otherwise do nothing ! (see get_tile_num_from_latlon()) - 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 ( 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, N_tile_in_cell_ij, tile_num_in_cell_ij, & + 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 @@ -1166,7 +1166,7 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & ! Step 2.): add grid cells that contain points around lat/lon: ! ! (i) 8 points at +/- half a grid cell (approx.) around lat/lon - ! (tile_grid%dlon = 360/(4*N) is the approximate grid spacing, see LDAS_create_grid_g()) + ! (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 @@ -1187,10 +1187,10 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & n = ind_start - 1 + ind_nbr(nn) - tmp_dlat = 0.5*tile_grid%dlon + 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%dlon + 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) ) ) @@ -1235,7 +1235,7 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & end do - call get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid, kk, & + 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 @@ -1269,10 +1269,10 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & 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, N_tile_in_cell_ij, tile_num_in_cell_ij, & + 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 @@ -1353,11 +1353,11 @@ 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, N_tile_in_cell_ij, tile_num_in_cell_ij, & + 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 grid cells of the cube-sphere tile_grid, find the + ! among the tiles within the given 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() @@ -1376,9 +1376,9 @@ subroutine get_tile_num_in_bbox_c3( lat, lon, N_cell, i_cell, j_cell, & type(tile_coord_type), dimension(:), pointer :: tile_coord ! input - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: tile_grid_g - integer, dimension(tile_grid%N_lon,tile_grid%N_lat), intent(in) :: N_tile_in_cell_ij + 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 @@ -1438,14 +1438,14 @@ end subroutine get_tile_num_in_bbox_c3 ! ******************************************************************* - subroutine get_ij_ind_from_latlon( tile_grid, lat, lon, i_ind, j_ind ) + subroutine get_ij_ind_from_latlon( my_grid, lat, lon, i_ind, j_ind ) ! NOTE order of input arguments ("lat", "lon", "lon_ind", "lat_ind") - ! find i/j_ind of grid cell that contains lat/lon + ! find i/j_ind of grid cell in my_grid that contains lat/lon ! ! that is, for given lat/lon, find out corresponding i/j_ind into an array - ! of size N_lon-by-N_lat whose lat/lon coordinates are defined by tile_grid + ! of size N_lon-by-N_lat whose lat/lon coordinates are defined by my_grid ! NOTE: ALL arrays in LDASsa are declared with base 1 @@ -1456,7 +1456,7 @@ subroutine get_ij_ind_from_latlon( tile_grid, lat, lon, i_ind, j_ind ) implicit none - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: my_grid real, intent(in) :: lat, lon integer, intent(out) :: i_ind, j_ind @@ -1475,21 +1475,21 @@ subroutine get_ij_ind_from_latlon( tile_grid, lat, lon, i_ind, j_ind ) ! ! select grid type - if (index(tile_grid%gridtype, 'EASEv')/=0) then + if (index(my_grid%gridtype, 'EASEv')/=0) then ! EASE grid lat/lon to index provides *global*, *0-based* index! - call MAPL_ease_convert(tile_grid%gridtype, lat, lon, r, s) + call MAPL_ease_convert(my_grid%gridtype, lat, lon, r, s) i_indg = nint(r) ! i_ind or lon_ind j_indg = nint(s) ! j_ind or lat_ind - ! convert to index into array defined by tile_grid_d + ! convert to index into array defined by my_grid - i_ind = i_indg - tile_grid%i_offg - (tile_grid%ind_base - 1) - j_ind = j_indg - tile_grid%j_offg - (tile_grid%ind_base - 1) + i_ind = i_indg - my_grid%i_offg - (my_grid%ind_base - 1) + j_ind = j_indg - my_grid%j_offg - (my_grid%ind_base - 1) - elseif (index(tile_grid%gridtype, 'LatLon')/=0) then + elseif (index(my_grid%gridtype, 'LatLon')/=0) then ! ll_lon and ll_lat refer to lower left corner of grid cell ! ur_lon and ur_lat refer to upper right corner of grid cell @@ -1497,28 +1497,28 @@ subroutine get_ij_ind_from_latlon( tile_grid, lat, lon, i_ind, j_ind ) ! ! ALL arrays in LDASsa are declared with base 1 (--> 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(tile_grid%gridtype, 'c3')/=0) then + elseif (index(my_grid%gridtype, 'c3')/=0) then ! cube-sphere grid requires the ESMF grid (amfox, 8 Nov 2026) @@ -1534,7 +1534,7 @@ end subroutine get_ij_ind_from_latlon ! ******************************************************************* - subroutine get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid, N_latlon, lat, lon, i_ind, j_ind ) + 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 ! @@ -1559,7 +1559,7 @@ subroutine get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid, N_latlon, lat type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: tile_grid_g integer, intent(in) :: N_latlon @@ -1604,15 +1604,15 @@ subroutine get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid, N_latlon, lat end if - ! convert to index into array defined by tile_grid + ! convert to index into array defined by tile_grid_g - i_ind = i_ind - tile_grid%i_offg - (tile_grid%ind_base - 1) - j_ind = j_ind - tile_grid%j_offg - (tile_grid%ind_base - 1) + 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%N_lon ) - j_ind = min( max(j_ind, 1), tile_grid%N_lat ) + 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 ) @@ -1620,10 +1620,10 @@ end subroutine get_ij_ind_from_latlon_c3 ! ******************************************************************* - subroutine init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid ) + 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) + ! 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): @@ -1646,7 +1646,7 @@ subroutine init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid ) type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF - type(grid_def_type), intent(in) :: tile_grid + type(grid_def_type), intent(in) :: tile_grid_g ! local variables @@ -1682,21 +1682,21 @@ subroutine init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid ) end if - if ( (dims(1)/=tile_grid%N_lon) .or. (dims(2)/=tile_grid%N_lat) ) then + 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%N_lon, tile_grid%N_lat + 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 ) + 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 @@ -1732,7 +1732,7 @@ 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 ) @@ -1742,7 +1742,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) @@ -1758,9 +1762,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 @@ -1794,8 +1798,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 @@ -1804,15 +1808,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) From 7d4bdcf171e88bca74fcb5a709773c813111b931 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 16:47:14 -0500 Subject: [PATCH 55/90] for clarification, changed var name "obs2tile_grid" to "obs2tile_grid_f" in subroutine get_tile_num_for_obs(); white-space changes (clsm_ensupd_read_obs.F90, clsm_ensupd_upd_routines.F90) --- GEOS_LdasGridComp.F90 | 10 +++++----- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/GEOS_LdasGridComp.F90 b/GEOS_LdasGridComp.F90 index d16b83e1..1da79a81 100644 --- a/GEOS_LdasGridComp.F90 +++ b/GEOS_LdasGridComp.F90 @@ -734,14 +734,14 @@ subroutine Initialize(gc, import, export, clock, rc) !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 diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 0377c4e3..dfb508ef 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -11924,7 +11924,7 @@ end subroutine add_to_obslog ! ***************************************************************** subroutine get_tile_num_for_obs(N_catf, tile_coord_f, & - obs2tile_grid, tile_grid_g_ESMF, & + 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, & @@ -11946,11 +11946,11 @@ subroutine get_tile_num_for_obs(N_catf, tile_coord_f, & type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - type(grid_def_type), intent(in) :: obs2tile_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(obs2tile_grid%N_lon,obs2tile_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 @@ -12021,7 +12021,7 @@ subroutine get_tile_num_for_obs(N_catf, tile_coord_f, & ! find tile numbers call get_tile_num_from_latlon(N_catf, tile_coord_f, & - obs2tile_grid, tile_grid_g_ESMF, & + 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 ) From 0560f4d0f7ccd91b4f09930814d9f49473cfb04c Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 16:50:00 -0500 Subject: [PATCH 56/90] for consistency, changed ">" to ">=" for FOV_threshold if condition (clsm_ensupd_upd_routines.F90) --- GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index ce714998..72902dfe 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1702,7 +1702,7 @@ subroutine get_obs_pred( & ! Get additional grid/tile information that is needed to map from tile ! to obs space - 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 tiles2obsFOV_grid_lH from tile_coord_lH and tiles2obsFOV_grid_g From ef1852b24f00c3bf8c33192cdef88b6b4c3a34f3 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Fri, 13 Nov 2026 17:19:52 -0500 Subject: [PATCH 57/90] cleaned up nodata values (LDAS_TileCoordRoutines.F90) --- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 34 ++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 0c07f80e..0b6c30b0 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -66,9 +66,11 @@ module LDAS_TileCoordRoutines 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 @@ -733,7 +735,7 @@ subroutine get_tile_num_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, my_grid, & ! 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 @@ -743,7 +745,7 @@ subroutine get_tile_num_in_cell_ij( N_tile, tc_i_indg, tc_j_indg, my_grid, & allocate(tile_num_in_cell_ij( my_grid%N_lon, my_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) @@ -820,8 +822,6 @@ subroutine get_tile_num_from_latlon( N_catd, tile_coord, & ! local variables - integer, parameter :: nodata_tilenum = -9999 - integer :: n, k, i_ind, j_ind, this_tile_num logical :: outside_bbox, too_far_away @@ -1078,8 +1078,6 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & ! local variables - integer, parameter :: nodata_tilenum = -9999 - integer, parameter :: N_chunk = 100000 ! max number of lat/lon per chunk integer, parameter :: N_lattice_max = 20 ! max lattice intervals on either side @@ -1887,10 +1885,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 ! ------------------------------------ @@ -1906,7 +1906,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 @@ -2076,7 +2077,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' @@ -2089,7 +2092,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 From c260aa5e8e5ed1b39cd68d1a2239c015980b7b07 Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:13:58 -0500 Subject: [PATCH 58/90] white-space changes only --- GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 index eab31322..f06b3b2f 100644 --- a/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 +++ b/GEOSlandassim_GridComp/GEOS_LandAssimGridComp.F90 @@ -1343,8 +1343,8 @@ subroutine Initialize(gc, import, export, clock, rc) ! 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") + _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, & From 53fd4ddfbcf79818663d16b5a5ca8a43bda86cac Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:20:59 -0500 Subject: [PATCH 59/90] Update CHANGELOG --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f347e9e2..2dee312a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,9 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 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 (e.g., cube-sphere tile space); `tile_coord` now used for land tiles only, with `_ASSERT`s (0-diff on Discover for CF0090; undefined behavior before). -- Fixed QC of Tb obs for non-land surfaces (water, land ice) in cube-sphere tile space, where it was not applied (not 0-diff for cube-sphere tile space with Tb obs; 0-diff for EASE and lat/lon tile spaces). -- 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 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, land ice) in cube-sphere tile space, where it was not applied (not 0-diff for cube-sphere tile space with Tb obs; 0-diff for EASE and lat/lon tile spaces) ([PR #249](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/249)). +- 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) ([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 EASEv2 M36 and CF0360) ([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)). From 5c3e03b7bf1b0f833ab2ac8cc7aa1315e84abec6 Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Sat, 14 Nov 2026 10:43:35 -0500 Subject: [PATCH 60/90] Update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a41e3b43..47d26126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 for compiler Nag +- 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, land ice) in cube-sphere tile space, where it was not applied (not 0-diff for cube-sphere tile space with Tb obs; 0-diff for EASE and lat/lon tile spaces) ([PR #249](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/249)). - 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) ([PR #247](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/247)). From 51c932294667c0ecc9e014b29c5852a60f5a238e Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:20:01 -0500 Subject: [PATCH 61/90] Updated CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f076cc74..0ad368d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,8 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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), caused by FFT lengths (`fft_lens`) that were never set (0-diff for builds with MKL). -- Fixed `process_hist.csh` for BSD `sed` (macOS), which takes the argument after `-i` as backup suffix; now uses `sed -i.tmp` and removes the backup file (0-diff with GNU `sed`). +- 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 From f87aa3f559ae90fc86959a8e9b3b86b3f530e55a Mon Sep 17 00:00:00 2001 From: amfox37 Date: Tue, 17 Nov 2026 13:03:21 -0700 Subject: [PATCH 62/90] Keep only Basic_QA 0 and 3 in VIIRS SCF reader (read_JPSS_SCF_hdf) Basic_QA=1 ("poor") obs agree badly with MODIS (15 Jan 2020, VJ110C1 and VNP10C1: corr 0.41, bias +0.26, rmsd 0.43), whereas Basic_QA=3 ("other", low illumination) agree well (corr 0.90, rmsd 0.10). Basic_QA=1 is about 1% of kept cells and 2% of snow cells. Previously kept: 0, 1, 3. Not 0-diff for VIIRS SCF obs (fewer obs); no change for other obs types. Co-Authored-By: Claude Sonnet 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 84cce96b..06b2fec8 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -8021,8 +8021,8 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & 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_max = 3 ! data quality (0=good, 1=poor, 2=bad, 3=other) - integer, parameter :: qc_basic_qa_bad = 2 ! exclude "bad" quality + 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 @@ -8233,8 +8233,8 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & (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_max ) .and. & ! keep "good", "poor", or "other" (4) - (Basic_QA( ii,jj) /= qc_basic_qa_bad ) ! quality (4) + (Basic_QA( ii,jj) == qc_basic_qa_good .or. & ! keep "good" or "other" (4) + Basic_QA( ii,jj) == qc_basic_qa_other ) ! quality only (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 @@ -8242,7 +8242,10 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! (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); excludes "bad" and flag values + ! high-latitude winter obs (as with MODIS reader); Basic_QA=1 ("poor") and 2 ("bad") + ! are excluded, as are flag values: comparison with MODIS (15 Jan 2020, + ! VJ110C1 and VNP10C1) shows that Basic_QA=1 obs agree poorly (corr 0.41, + ! bias +0.26, rmsd 0.43), whereas Basic_QA=3 obs agree well (corr 0.90, rmsd 0.10) if (keep_data) then From 5b948abc0c685c737becf85a782a6d6bad4234dc Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Wed, 18 Nov 2026 11:31:07 -0500 Subject: [PATCH 63/90] mininmal edits of comments; white-space changes (LDAS_TileCoordType.F90, LDAS_PertTypes.F90, LDAS_ensdrv_mpi.F90, clsm_ensupd_upd_routines.F90, preprocess_ldas_routines.F90) --- .../clsm_ensupd_upd_routines.F90 | 2 +- GEOSldas_App/preprocess_ldas_routines.F90 | 2 +- LDAS_Shared/LDAS_PertTypes.F90 | 75 ++++++++++--------- LDAS_Shared/LDAS_TileCoordType.F90 | 11 +-- LDAS_Shared/LDAS_ensdrv_mpi.F90 | 4 +- 5 files changed, 48 insertions(+), 46 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index 72902dfe..fc3421e6 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1704,7 +1704,7 @@ subroutine get_obs_pred( & if ( any(obs_param(1:N_obs_param)%FOV>=FOV_threshold) ) then - ! determine tiles2obsFOV_grid_lH from tile_coord_lH and tiles2obsFOV_grid_g + ! determine tiles2obsFOV_grid_lH from tile_coord_lH and tiles2obsFOV_grid_g (i.e., pert_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 diff --git a/GEOSldas_App/preprocess_ldas_routines.F90 b/GEOSldas_App/preprocess_ldas_routines.F90 index f2553d5a..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, & 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_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] From ae68155af074f66d63da6acad7b122a79ddfa08e Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Wed, 18 Nov 2026 15:49:43 -0500 Subject: [PATCH 64/90] edited/added comments; white-space changes (GEOS_LdasGridComp.F90, clsm_ensupd_enkf_update.F90, clsm_ensupd_read_obs.F90, clsm_ensupd_upd_routines.F90, LDAS_TileCoordRoutines.F90) --- GEOS_LdasGridComp.F90 | 141 +++++++++--------- .../clsm_ensupd_enkf_update.F90 | 12 +- .../clsm_ensupd_read_obs.F90 | 6 +- .../clsm_ensupd_upd_routines.F90 | 6 +- LDAS_Shared/LDAS_TileCoordRoutines.F90 | 109 +++++++------- 5 files changed, 137 insertions(+), 137 deletions(-) diff --git a/GEOS_LdasGridComp.F90 b/GEOS_LdasGridComp.F90 index 1da79a81..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,31 +707,34 @@ 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, & @@ -741,14 +744,14 @@ subroutine Initialize(gc, import, export, clock, rc) 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/clsm_ensupd_enkf_update.F90 b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 index de995fd9..29cf2763 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_enkf_update.F90 @@ -174,7 +174,7 @@ subroutine get_enkf_increments( & ! 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, 8 Nov 2026 + ! - amfox, 9 Nov 2026 implicit none @@ -288,7 +288,7 @@ subroutine get_enkf_increments( & 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, 6 Nov 2026) + ! 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 @@ -409,13 +409,15 @@ subroutine get_enkf_increments( & ! 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, 8 Nov 2026 + ! 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, 8 Nov 2026 + ! 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 @@ -442,7 +444,7 @@ subroutine get_enkf_increments( & ! (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, 6 Nov 2026 + ! amfox, 9 Nov 2026 obs2tile_grid_f = tile_grid_g diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 28a1f3e5..3858c346 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -9914,7 +9914,7 @@ subroutine read_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) - ! 8 Nov 2026 - added input tile_grid_g_ESMF (ESMF grid associated with cube-sphere tile space) (amfox) + ! 9 Nov 2026 - added input tile_grid_g_ESMF (ESMF grid associated with cube-sphere tile space) (amfox) implicit none @@ -11431,7 +11431,7 @@ 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 - ! 8 Nov 2026 - added input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space) (amfox) + ! 9 Nov 2026 - added input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space) (amfox) implicit none @@ -11938,7 +11938,7 @@ subroutine get_tile_num_for_obs(N_catf, tile_coord_f, & ! - reichle, 2015/02/20 ! ! added input tile_grid_g_ESMF (ESMF grid of cube-sphere tile space), see get_tile_num_from_latlon() - ! - amfox, 8 Nov 2026 + ! - amfox, 9 Nov 2026 implicit none diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index fc3421e6..5b59305b 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1697,10 +1697,12 @@ 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 diff --git a/LDAS_Shared/LDAS_TileCoordRoutines.F90 b/LDAS_Shared/LDAS_TileCoordRoutines.F90 index 0b6c30b0..fe8ba5d7 100644 --- a/LDAS_Shared/LDAS_TileCoordRoutines.F90 +++ b/LDAS_Shared/LDAS_TileCoordRoutines.F90 @@ -5,8 +5,8 @@ ! 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, 6 Nov 2026 - added cube-sphere grid ("c3") case to get_tile_num_from_latlon() -! amfox, 8 Nov 2026 - map lat/lon to cube-sphere grid cells with MAPL_GetGlobalHorzIJIndex() +! 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()) ! ! ======================================================================== @@ -796,8 +796,9 @@ subroutine get_tile_num_from_latlon( N_catd, tile_coord, & ! - 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) - ! - amfox, 8 Nov 2026 + ! 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 @@ -849,7 +850,7 @@ subroutine get_tile_num_from_latlon( N_catd, tile_coord, & 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, 8 Nov 2026) + ! 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, & @@ -1001,10 +1002,10 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & ! find tile_num for lat/lon in cube-sphere ("c3") tile space, see get_tile_num_from_latlon() ! - ! 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. + ! 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 @@ -1016,7 +1017,7 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & ! 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 there is no such tile, repeat 1.) for all tiles within the grid cells + ! 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 @@ -1027,54 +1028,46 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & ! another tile within max_dist was then chosen). Grid cells that were already ! searched are skipped. ! - ! 3.) If there is still no such tile, loop through all tiles within the grid + ! 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. + ! 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, 6 Nov 2026 - ! amfox, 8 Nov 2026 - moved here from get_tile_num_from_latlon(); grid cells from - ! MAPL_GetGlobalHorzIJIndex() (no copied cube-sphere geometry) - ! amfox, 8 Nov 2026 - Step 3.) considers only tiles within max_dist (otherwise the - ! closest tile could fail the max_dist check while another tile - ! within max_dist would pass it) - ! amfox, 8 Nov 2026 - Step 2.) also searches the grid cells within max_dist (the 8 points - ! alone can miss grid cells with tiles within max_dist) - ! amfox, 9 Nov 2026 - larger N_chunk and N_pts_max (fewer MAPL calls for high-res grids) - + ! 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(ESMF_Grid), intent(in) :: tile_grid_g_ESMF - - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord ! input - type(grid_def_type), intent(in) :: tile_grid_g + 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, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - integer, intent(in) :: N_latlon + integer, intent(in) :: N_latlon - real, dimension(N_latlon), intent(in) :: lat, lon + 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] + 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 + integer, dimension(N_latlon), intent(out) :: tile_num ! local variables @@ -1126,7 +1119,7 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & 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 + ! Step 1.): tiles within grid cell that contains lat/lon points N_nbr = 0 @@ -1161,7 +1154,7 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & end do - ! Step 2.): add grid cells that contain points around lat/lon: + ! 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()) @@ -1253,8 +1246,8 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & 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 + 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 @@ -1313,7 +1306,7 @@ subroutine get_tile_num_from_latlon_c3( tile_grid_g_ESMF, tile_coord, & nn_start = nn_end + 1 - end do + end do ! while (nn_start<=N_nbr) ! check whether lat/lon is inside bounding box of given tile ! (see get_tile_num_from_latlon()) @@ -1355,34 +1348,34 @@ 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 grid cells of the cube-sphere tile_grid_g, find the + ! 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, 8 Nov 2026 (moved here from get_tile_num_from_latlon()) + ! amfox, 9 Nov 2026 implicit none - real, intent(in) :: lat, lon + real, intent(in) :: lat, lon - integer, intent(in) :: N_cell + integer, intent(in) :: N_cell - integer, dimension(N_cell), intent(in) :: i_cell, j_cell + integer, dimension(N_cell), intent(in) :: i_cell, j_cell - type(tile_coord_type), dimension(:), pointer :: tile_coord ! input + type(tile_coord_type), dimension(:), pointer :: tile_coord ! input - type(grid_def_type), intent(in) :: tile_grid_g + 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, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - integer, intent(inout) :: tile_num + integer, intent(inout) :: tile_num - real, intent(inout) :: min_dist, min_dist_x, min_dist_y + real, intent(inout) :: min_dist, min_dist_x, min_dist_y ! local variables @@ -1467,7 +1460,7 @@ subroutine get_ij_ind_from_latlon( my_grid, lat, lon, i_ind, j_ind ) real :: r, s, i_indg, j_indg character(len=*), parameter :: Iam = 'get_ij_ind_from_latlon' - character(len=400) :: err_msg + character(len=400) :: err_msg ! ------------------------------------------------------------- ! @@ -1518,7 +1511,7 @@ subroutine get_ij_ind_from_latlon( my_grid, lat, lon, i_ind, j_ind ) elseif (index(my_grid%gridtype, 'c3')/=0) then - ! cube-sphere grid requires the ESMF grid (amfox, 8 Nov 2026) + ! 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()') @@ -1534,7 +1527,7 @@ 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 + ! 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, @@ -1551,7 +1544,7 @@ subroutine get_ij_ind_from_latlon_c3( tile_grid_g_ESMF, tile_grid_g, N_latlon, l ! 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, 8 Nov 2026 + ! amfox, 9 Nov 2026 implicit none @@ -1638,7 +1631,7 @@ subroutine init_tile_grid_g_ESMF_c3( tile_grid_g_ESMF, tile_grid_g ) ! stretched grid is finer. MAPL marks a stretched grid with the attributes ! STRETCH_FACTOR, TARGET_LON and TARGET_LAT (see MAPL_Reverse_Schmidt()). ! - ! amfox, 8 Nov 2026 + ! amfox, 9 Nov 2026 implicit none From 35c78c13b39412cb78e996115a9e8fe8b50426d5 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 18 Nov 2026 17:16:41 -0700 Subject: [PATCH 65/90] shift CYGNSS L3 obs lat/lon for obs-to-tile mapping on EASEv2 M09 tile space CYGNSS L3 soil moisture obs are on the 36-km EASEv2 grid. Without the small lat/lon shift used for SMAP L1C Tb, the obs lie exactly on the equidistant point between M09 tiles and the tile assignment is ambiguous. Shift is applied only when the tile space is EASEv2 M09 (0-diff for other tile spaces). Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + .../clsm_ensupd_read_obs.F90 | 35 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ad368d4..8a91ad9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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)). +- Fixed obs-to-tile mapping of CYGNSS L3 soil moisture obs on EASEv2 M09 tile space by shifting the obs lat/lon, as is done for SMAP L1C Tb obs, to avoid ambiguous tile assignment within an M36 obs grid cell (not 0-diff for EASEv2 M09 tile space with CYGNSS L3 obs; 0-diff for all other tile spaces). ### Removed diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index f5b30019..571db1b6 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -2814,6 +2814,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()) ! ! -------------------------------------------------------------------- @@ -2891,6 +2892,14 @@ subroutine read_obs_sm_CYGNSS( & 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 +3229,27 @@ 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 of M09 tile? + + if ( index(tile_grid_d%gridtype, 'EASEv2_M09') /=0 .or. & + index(tile_grid_d%gridtype, 'EASEv2-M09') /=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, & + 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_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 ) + + end if ! ---------------------------------------------------------------- ! From 0b180e6fda1c9e3ecbf6e6045627ae86e7bb377c Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 18 Nov 2026 20:29:00 -0500 Subject: [PATCH 66/90] SMOS: shift obs lat/lon before tile search only for EASEv2 M09 tile space read_obs_SMOS always shifted the obs lat/lon by (0.005, 0.01) deg before get_tile_num_for_obs(), a workaround for ties between M09 tiles within an M36 obs grid cell. The SMAP L1C readers apply the shift only for EASEv2 M09 model tile space. In cube-sphere tile space the shift assigns about 13 percent of SMOS obs (CF0360) to a tile other than the one at the obs location. Tested against ae68155: - CF0360 (SMOS monitored): only SMOS obs change tile (13.5 percent); all other species, restarts and outputs are value-identical. Mapping check for SMOS: 86 percent -> 99 percent of obs on the tile given by the documented algorithm. - EASEv2 M36 (2 days) and EASEv2 M09 (SI_Team LDAS_GLOBAL/assim, 12 h): all outputs value-identical. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + .../clsm_ensupd_read_obs.F90 | 45 +++++++++++++------ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 144bf094..b61b0939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed mapping of obs to tiles in cube-sphere tile space: map obs on the cube-sphere tile grid with tile bounding boxes instead of on the lat/lon perturbation grid, in whose cells the tiles do not nest (not 0-diff for cube-sphere tile space). +- Fixed tile assignment of SMOS obs: shift obs lat/lon before the tile search only in EASEv2 M09 tile space, as for SMAP L1C obs (not 0-diff for cube-sphere tile space with SMOS obs; 0-diff for EASEv2 M36 and M09). - 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, land ice) in cube-sphere tile space, where it was not applied (not 0-diff for cube-sphere tile space with Tb obs; 0-diff for EASE and lat/lon tile spaces) ([PR #249](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/249)). diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 3858c346..ab6c0a49 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6206,19 +6206,38 @@ subroutine read_obs_SMOS( date_time, N_catf, 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_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 ) + + ! shift M36 obs lat/lon for proper assignment of M09 tile? + ! (only for EASEv2 M09 model tile space, 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 ) 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 ! -------------------------------------------------------------------------- ! From 158a1bd3b7beb905020dba70377af74548bc57e5 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Wed, 18 Nov 2026 19:55:39 -0700 Subject: [PATCH 67/90] CHANGELOG: reword CYGNSS L3 M09 shift entry and add PR number Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a91ad9d..f11ac775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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)). -- Fixed obs-to-tile mapping of CYGNSS L3 soil moisture obs on EASEv2 M09 tile space by shifting the obs lat/lon, as is done for SMAP L1C Tb obs, to avoid ambiguous tile assignment within an M36 obs grid cell (not 0-diff for EASEv2 M09 tile space with CYGNSS L3 obs; 0-diff for all other tile spaces). +- Fixed obs-to-tile mapping of CYGNSS L3 soil moisture obs on EASEv2 M09 tile space by shifting the obs lat/lon, as is done for SMAP L1C Tb obs (not 0-diff for EASEv2 M09 tile space with CYGNSS L3 obs; 0-diff for all other tile spaces) ([PR #257](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/257)). ### Removed From da16c21b7fe9e4f793115c851c2ae732488f1ebd Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Thu, 19 Nov 2026 09:40:32 -0500 Subject: [PATCH 68/90] corrected variable name change from previous commit --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index e66360bb..d78260c1 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -3255,8 +3255,8 @@ subroutine read_obs_sm_CYGNSS( ! in M09 tile space, shift M36 obs lat/lon for proper assignment of M09 tile - if ( index(obs2tile_grid_d%gridtype, 'EASEv2_M09') /=0 .or. & - index(obs2tile_grid_d%gridtype, 'EASEv2-M09') /=0 ) then + if ( index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2-M09') /=0 ) then call get_tile_num_for_obs(N_catf, tile_coord_f, & obs2tile_grid_f, tile_grid_g_ESMF, & From 6884a9eeb9036c38de31c9987a25ef7d16e3d715 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Thu, 19 Nov 2026 10:23:13 -0700 Subject: [PATCH 69/90] CHANGELOG: add PR number to SMOS tile assignment entry Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1d02dfc..74b107c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed mapping of obs to tiles in cube-sphere tile space: map obs on the cube-sphere tile grid with tile bounding boxes instead of on the lat/lon perturbation grid, in whose cells the tiles do not nest (not 0-diff for cube-sphere tile space). -- Fixed tile assignment of SMOS obs: shift obs lat/lon before the tile search only in EASEv2 M09 tile space, as for SMAP L1C obs (not 0-diff for cube-sphere tile space with SMOS obs; 0-diff for EASEv2 M36 and M09). +- Fixed tile assignment of SMOS obs: shift obs lat/lon before the tile search only in EASEv2 M09 tile space, as for SMAP L1C obs (not 0-diff for cube-sphere tile space with SMOS obs; 0-diff for EASEv2 M36 and M09) ([PR #252](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/252)). - 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, land ice) in cube-sphere tile space, where it was not applied (not 0-diff for cube-sphere tile space with Tb obs; 0-diff for EASE and lat/lon tile spaces) ([PR #249](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/249)). From 9e0450df3ee3db6bd92cddb013fcf80a158b233c Mon Sep 17 00:00:00 2001 From: amfox37 Date: Thu, 19 Nov 2026 10:24:09 -0700 Subject: [PATCH 70/90] CHANGELOG: add PR number to cube-sphere obs-to-tile mapping entry Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74b107c9..047901f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 mapping of obs to tiles in cube-sphere tile space: map obs on the cube-sphere tile grid with tile bounding boxes instead of on the lat/lon perturbation grid, in whose cells the tiles do not nest (not 0-diff for cube-sphere tile space). +- Fixed mapping of obs to tiles in cube-sphere tile space: map obs on the cube-sphere tile grid with tile bounding boxes instead of on the lat/lon perturbation grid, in whose cells the tiles do not nest (not 0-diff for cube-sphere tile space) ([PR #252](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/252)). - Fixed tile assignment of SMOS obs: shift obs lat/lon before the tile search only in EASEv2 M09 tile space, as for SMAP L1C obs (not 0-diff for cube-sphere tile space with SMOS obs; 0-diff for EASEv2 M36 and M09) ([PR #252](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/252)). - 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)). From 4037cd199a86e4b409e3ac5137207d9c75ecae50 Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:25:45 -0500 Subject: [PATCH 71/90] simplified recent CHANGELOG entries --- CHANGELOG.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 047901f9..9f3c7a9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,20 +23,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 mapping of obs to tiles in cube-sphere tile space: map obs on the cube-sphere tile grid with tile bounding boxes instead of on the lat/lon perturbation grid, in whose cells the tiles do not nest (not 0-diff for cube-sphere tile space) ([PR #252](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/252)). -- Fixed tile assignment of SMOS obs: shift obs lat/lon before the tile search only in EASEv2 M09 tile space, as for SMAP L1C obs (not 0-diff for cube-sphere tile space with SMOS obs; 0-diff for EASEv2 M36 and M09) ([PR #252](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/252)). +- 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 CYGNSS L3 soil moisture obs on EASEv2 M09 tile space (not 0-diff for EASEv2 M09 tile space with CYGNSS L3 obs) ([PR #257](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/257)). - 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, land ice) in cube-sphere tile space, where it was not applied (not 0-diff for cube-sphere tile space with Tb obs; 0-diff for EASE and lat/lon tile spaces) ([PR #249](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/249)). -- 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) ([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 EASEv2 M36 and CF0360) ([PR #240](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/240)). +- 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)). +- 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)). -- Fixed obs-to-tile mapping of CYGNSS L3 soil moisture obs on EASEv2 M09 tile space by shifting the obs lat/lon, as is done for SMAP L1C Tb obs (not 0-diff for EASEv2 M09 tile space with CYGNSS L3 obs; 0-diff for all other tile spaces) ([PR #257](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/257)). ### Removed From 9be8a898871500657819451379aafab1614e345d Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:51:40 -0500 Subject: [PATCH 72/90] Run land_frac calc for Tb QC only before EnKF update (clsm_ensupd_upd_routines.F90) --- GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 index 5b59305b..3a52b910 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_upd_routines.F90 @@ -1595,13 +1595,14 @@ subroutine get_obs_pred( & ! 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 (c3_tile_space .and. get_Tb_lH) then + 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) From fc2ba042fd1367de33be7f0883ac31e8447fc53b Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:19:56 -0500 Subject: [PATCH 73/90] add M01 and M03 tile spaces to M36 obs lat/lon shift for SMAP, SMOS, CYGNSS (clsm_ensupd_read_obs.F90) --- .../clsm_ensupd_read_obs.F90 | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index d78260c1..d6496b1a 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -3253,10 +3253,13 @@ subroutine read_obs_sm_CYGNSS( allocate(tmp_tile_num(N_obs)) - ! in M09 tile space, shift M36 obs lat/lon for proper assignment of M09 tile + ! 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 ) then + index(obs2tile_grid_f%gridtype, 'EASEv2-M09') /=0 .or. & + 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, & @@ -6233,10 +6236,13 @@ subroutine read_obs_SMOS( date_time, N_catf, this_obs_param, & allocate(tmp_tile_num(N_obs)) - ! shift M36 obs lat/lon for proper assignment of M09 tile? - ! (only for EASEv2 M09 model tile space, as for the SMAP L1C obs readers) + ! 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 ) then + if ( index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2-M09') /=0 .or. & + 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 @@ -9117,10 +9123,16 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catf, 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. (index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0 .or. index(obs2tile_grid_f%gridtype, 'EASEv2-M09') /=0 )) then + if ( L1C_files .and. & + ( & + index(obs2tile_grid_f%gridtype, 'EASEv2_M09') /=0 .or. & + index(obs2tile_grid_f%gridtype, 'EASEv2-M09') /=0 .or. & + 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 From 6c541a8d0fb6d0b093c3ea1129c4b4e7e78c5085 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Thu, 19 Nov 2026 16:09:19 -0500 Subject: [PATCH 74/90] added shift of SMAP L1C_TB_E (M09) obs lat/lon when tile space is M03 or M01 (clsm_ensupd_read_obs.F90) --- .../clsm_ensupd_read_obs.F90 | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index d6496b1a..88f196c5 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -3257,7 +3257,7 @@ subroutine read_obs_sm_CYGNSS( ! (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. & + 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 @@ -6240,7 +6240,7 @@ subroutine read_obs_SMOS( date_time, N_catf, this_obs_param, & ! (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. & + 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 @@ -8326,7 +8326,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catf, this_obs_param, & type(hdf5read) :: h5r - logical :: L1C_files, L1CE_files, hpol + logical :: L1C_files, L1CE_files, hpol, use_shift logical :: L1CE_thinning, keep_data_1, keep_data_2, tmp_keep, file_exists type(date_time_type) :: date_time_low, date_time_upp @@ -9125,14 +9125,27 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catf, this_obs_param, & 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) - - if ( L1C_files .and. & - ( & + ! shift M09 obs lat/lon for proper assignment if tile space M03/M01 (tiles nest in M09) + + use_shift = & + (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. & + 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 & + ) & + ) & + .or. & ! or + (L1CE_files .and. & ! M09 obs and M03, or M01 tile space + ( & index(obs2tile_grid_f%gridtype, 'EASEv2_M03') /=0 .or. & index(obs2tile_grid_f%gridtype, 'EASEv2_M01') /=0 & - ) ) then + ) & + ) + + + if (use_shift) 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 From f478b413e4c9ff1918c222aefbbe2584720daa1f Mon Sep 17 00:00:00 2001 From: Rolf Reichle <54944691+gmao-rreichle@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:11:03 -0500 Subject: [PATCH 75/90] updated CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f3c7a9d..706cc001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,10 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - 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 CYGNSS L3 soil moisture obs on EASEv2 M09 tile space (not 0-diff for EASEv2 M09 tile space with CYGNSS L3 obs) ([PR #257](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/257)). +- Fixed obs-to-tile mapping of SMAP Tb, SMOS Tb, and CYGNSS soil moisture obs 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)). +- 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)). From 79c9fc0d8a66dcaa9e384a31b291e3eae589a7d5 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Sat, 21 Nov 2026 16:40:41 -0500 Subject: [PATCH 76/90] reverted "shift" of L1C Enhanced (M09) obs when used with M03/M01 tile space (clsm_ensupd_read_obs.F90) --- CHANGELOG.md | 2 +- .../clsm_ensupd_read_obs.F90 | 22 +++++-------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 706cc001..d7f01950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - 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 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 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)). diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 88f196c5..e2be0bb4 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -8326,7 +8326,7 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catf, this_obs_param, & type(hdf5read) :: h5r - logical :: L1C_files, L1CE_files, hpol, use_shift + logical :: L1C_files, L1CE_files, hpol logical :: L1CE_thinning, keep_data_1, keep_data_2, tmp_keep, file_exists type(date_time_type) :: date_time_low, date_time_upp @@ -9125,28 +9125,16 @@ subroutine read_obs_SMAP_halforbit_Tb( date_time, N_catf, this_obs_param, & 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 M09 obs lat/lon for proper assignment if tile space M03/M01 (tiles nest in M09) - - use_shift = & - (L1C_files .and. & ! M36 obs and M09, M03, or M01 tile space + + 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-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 & ) & - ) & - .or. & ! or - (L1CE_files .and. & ! M09 obs and M03, or M01 tile space - ( & - index(obs2tile_grid_f%gridtype, 'EASEv2_M03') /=0 .or. & - index(obs2tile_grid_f%gridtype, 'EASEv2_M01') /=0 & - ) & - ) - + ) then - if (use_shift) 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 From 64b713d4005a5124a98cdaa24d6417e0c8a809c1 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Sun, 22 Nov 2026 12:28:48 -0700 Subject: [PATCH 77/90] CHANGELOG: add PR number to VIIRS SCF entry Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed5fbc83..bd8d4a6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added 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. +- 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)). From 6af6e15219d88b9e2a3a05582a262a9a8f94b0b8 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Sun, 22 Nov 2026 12:35:29 -0700 Subject: [PATCH 78/90] Tidy VIIRS SCF code: alignment, comments, duplicate nml separator (no logic change) Co-Authored-By: Claude Sonnet 5.5 --- .../clsm_ensupd_read_obs.F90 | 28 ++++++++++--------- GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml | 1 - 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 387028bb..b8e059d3 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6999,6 +6999,9 @@ subroutine read_obs_JPSS_SCF( & ! ! lcandre2, 26 Oct 2026 ! + ! amfox, 5 Nov 2026 - obs on tiles at a window boundary are assimilated only once (as for MODIS); + ! original file names ("granule_id") are written to the obslog (as for MODIS) + ! ! ------------------------------------------------------------------------------ implicit none @@ -7042,7 +7045,7 @@ subroutine read_obs_JPSS_SCF( & real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of JPSS CMG grid real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of JPSS CMG grid - character(7) :: JPSS_product_ID + character( 7) :: JPSS_product_ID character(4) :: YYYY character(3) :: DDD ! day of year @@ -7095,11 +7098,11 @@ subroutine read_obs_JPSS_SCF( & ! determine operating time range of sensor if (trim(this_obs_param%descr) == 'VJ110C1') then - date_time_obs_beg = date_time_type(2018, 1, 5, 0, 0, 0, -9999, -9999) ! JPSS1 + 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 + 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) + date_time_obs_beg = date_time_type(2012, 1,19, 0, 0, 0,-9999,-9999) ! S-NPP else err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) @@ -7120,7 +7123,8 @@ subroutine read_obs_JPSS_SCF( & end if - ! identify JPSS product and overpass hour https://vlab.noaa.gov/web/towr-s/satellite-operations-updates + ! identify JPSS product and overpass hour + ! (see https://vlab.noaa.gov/web/towr-s/satellite-operations-updates) JPSS_product_ID = this_obs_param%name(1:7) @@ -7327,7 +7331,7 @@ subroutine read_obs_JPSS_SCF( & tmp_ind_start = N_CMG_obs + 1 tmp_ind_last = N_CMG_obs + N_lon_vec(nn)*N_lat - call read_JPSS_SCF_hdf( fname, & + call read_JPSS_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), & @@ -7395,11 +7399,11 @@ subroutine read_obs_JPSS_SCF( & tmp_tile_num ) - std_JPSS_obs = this_obs_param%errstd + std_JPSS_obs = this_obs_param%errstd - JPSS_obs = 0. - JPSS_lon = 0. - JPSS_lat = 0. + JPSS_obs = 0. + JPSS_lon = 0. + JPSS_lat = 0. N_obs_in_tile = 0 @@ -8330,9 +8334,7 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! (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, as are flag values: comparison with MODIS (15 Jan 2020, - ! VJ110C1 and VNP10C1) shows that Basic_QA=1 obs agree poorly (corr 0.41, - ! bias +0.26, rmsd 0.43), whereas Basic_QA=3 obs agree well (corr 0.90, rmsd 0.10) + ! are excluded because Basic_QA=1 obs agree poorly with MODIS (15 Jan 2020 comparison) if (keep_data) then diff --git a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml index 4aa655c3..b9fab525 100644 --- a/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml +++ b/GEOSldas_App/LDASsa_DEFAULT_inputs_ensupd.nml @@ -2698,7 +2698,6 @@ obs_param_nml(58)%xcorr = 0.2 obs_param_nml(58)%ycorr = 0.2 obs_param_nml(58)%adapt = 0 -! -------------------------------------------------------------------- ! -------------------------------------------------------------------- ! ! 59 = VIIRS/JPSS1 snow cover area fraction (SCF) From 64d2c3d4fb7ef0ecd3547aa729bb1113d89d1830 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Sun, 22 Nov 2026 14:27:23 -0700 Subject: [PATCH 79/90] Simplify readAttributeChar: read as fixed-length string, return blank on any HDF5 error Co-Authored-By: Claude Sonnet 5.5 --- GEOSlandassim_GridComp/io_hdf5.F90 | 64 ++++++------------------------ 1 file changed, 13 insertions(+), 51 deletions(-) diff --git a/GEOSlandassim_GridComp/io_hdf5.F90 b/GEOSlandassim_GridComp/io_hdf5.F90 index 0bb5296d..247dde24 100644 --- a/GEOSlandassim_GridComp/io_hdf5.F90 +++ b/GEOSlandassim_GridComp/io_hdf5.F90 @@ -368,8 +368,8 @@ subroutine readDataset2DInt(this, data2D, offset) 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, - ! is not a single fixed-length string, or cannot be read + ! 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) @@ -380,10 +380,10 @@ subroutine readAttributeChar(this, attrName, attrValue) character(len=*), intent(out) :: attrValue ! local variables - integer :: hdf5err, tmperr, type_class, space_class, cset - logical :: attr_exists, is_vlen, is_ok - integer(hid_t) :: attr_id, memtype_id, filetype_id, space_id - integer(hsize_t) :: dims(1), npoints + 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 @@ -401,55 +401,17 @@ subroutine readAttributeChar(this, attrName, attrValue) if (hdf5err < 0) return - ! dataspace must hold exactly one element (scalar, or simple with one point); - ! more than one element would overflow attrValue - is_ok = .false. - npoints = 0_hsize_t - - call h5aget_space_f(attr_id, space_id, hdf5err) + ! read into a fixed-length string of length len(attrValue) + call h5tcopy_f(H5T_FORTRAN_S1, memtype_id, hdf5err) if (hdf5err >= 0) then - call h5sget_simple_extent_type_f(space_id, space_class, hdf5err) - if (hdf5err >= 0 .and. (space_class == H5S_SCALAR_F .or. space_class == H5S_SIMPLE_F)) then - call h5sget_simple_extent_npoints_f(space_id, npoints, hdf5err) - is_ok = (hdf5err >= 0 .and. npoints == 1_hsize_t) - end if - call h5sclose_f(space_id, tmperr) - end if - - ! datatype must be a fixed-length string; get its character set (ASCII or UTF-8), - ! because HDF5 does not convert between character sets - if (is_ok) then - is_ok = .false. - is_vlen = .true. - cset = -1 - call h5aget_type_f(attr_id, filetype_id, hdf5err) - if (hdf5err >= 0) then - call h5tget_class_f(filetype_id, type_class, hdf5err) - if (hdf5err >= 0 .and. type_class == H5T_STRING_F) then - call h5tis_variable_str_f(filetype_id, is_vlen, hdf5err) - if (hdf5err >= 0 .and. (.not. is_vlen)) then - call h5tget_cset_f(filetype_id, cset, hdf5err) - is_ok = (hdf5err >= 0) - end if - end if - call h5tclose_f(filetype_id, tmperr) - end if - end if - - ! read into a fixed-length string of length len(attrValue) with the character set of the attribute - if (is_ok) then - call h5tcopy_f(H5T_FORTRAN_S1, memtype_id, hdf5err) + call h5tset_size_f(memtype_id, int(len(attrValue),size_t), hdf5err) if (hdf5err >= 0) then - call h5tset_size_f(memtype_id, int(len(attrValue),size_t), hdf5err) - if (hdf5err >= 0) call h5tset_cset_f(memtype_id, cset, 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) + 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) From 982e1c80a87a27eb9ea44719caf498096f17bcac Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Mon, 23 Nov 2026 10:11:17 -0500 Subject: [PATCH 80/90] moved entire subroutine read_JPSS_SCF() within file to get cleaner diff view on GitHub; minimal white-space changes (clsm_ensupd_read_obs.F90, io_hdf5.F90) --- .../clsm_ensupd_read_obs.F90 | 1641 +++++++++-------- GEOSlandassim_GridComp/io_hdf5.F90 | 2 +- 2 files changed, 822 insertions(+), 821 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index b8e059d3..1bbfadd8 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6976,1067 +6976,1067 @@ subroutine read_obs_MODIS_SCF( & end subroutine read_obs_MODIS_SCF - ! ******************************************************************************************************* + ! **************** - subroutine read_obs_JPSS_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, JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat ) - - ! read JPSS snow cover observations on the 0.05-degree climate - ! modeling grid (CMG) - ! - ! JPSS1/NOAA-20: VJ110C1 (launched 2017) - ! JPSS2/NOAA-21: VJ210C1 (launched 2022) - ! S-NPP : VNP10C1 (launched 2011, decommissioned 2026) - ! - ! - ! For now, assume that VIIRS/JPSS 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 - ! - ! lcandre2, 26 Oct 2026 - ! - ! amfox, 5 Nov 2026 - obs on tiles at a window boundary are assimilated only once (as for MODIS); - ! original file names ("granule_id") are written to the obslog (as for MODIS) - ! - ! ------------------------------------------------------------------------------ + subroutine localtime2longitude( date_time, local_hour, longitude, delta_day ) + ! for date_time in UTC, find the longitude where the local time is local_hour; + ! delta_day is the offset between the UTC calendar day and the calendar + ! day at the returned longitude + ! when UTC and local time are exactly 12 hours offset, always return longitude=+180. + ! + ! - reichle, 19 Oct 2023 + implicit none + + type(date_time_type), intent(in) :: date_time ! current date and time in UTC - ! inputs + real, intent(in) :: local_hour ! fractional local hour (e.g., 1:30pm is 13.5); range=[0,24) - type(date_time_type), intent(in) :: date_time + real, intent(out) :: longitude ! [degree] -180 < longitude <= 180 + + integer, intent(out) :: delta_day ! [days] -1 <= delta_day <= 1 - integer, intent(in) :: dtstep_assim ! [seconds] - integer, intent(in) :: N_catf + ! ---------------------------------------------- - type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input + real :: UTC_hour, time_diff - type(grid_def_type), intent(in) :: obs2tile_grid_f + character(len=*), parameter :: Iam = 'localtime2longitude' + character(len=400) :: err_msg + + ! --------------------------------------------------------------------------- + + ! make sure local_hour is within range: 0 <= local_hour < 24 + + if ( (local_hour < 0.) .or. (local_hour >= 24.) ) then + + err_msg = 'input local_hour falls outside allowed range of 0:24' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! initialize + + delta_day = 0 + + ! determine fractional UTC hour and time difference with local_hour + + UTC_hour = ( date_time%hour*3600 + date_time%min*60 + date_time%sec )/3600. ! 0 <= UTC_hour < 24 + + time_diff = local_hour - UTC_hour + + ! enforce -12. < time_diff <= 12. and determine associated date difference, if any + + if (time_diff <= -12.) then + + delta_day = 1 - type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space + time_diff = time_diff + 24. + + elseif (time_diff > 12.) then + + delta_day = -1 - integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: N_tile_in_cell_ij + time_diff = time_diff - 24. + + end if - integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + ! determine longitude - type(obs_param_type), intent(in) :: this_obs_param + longitude = time_diff/24.*360. + + end subroutine localtime2longitude - logical, intent(in) :: write_obslog + ! ***************************************************************** + + subroutine get_MODIS_granule_id( sd_id, granule_id ) - ! output + ! get original file name (incl. production time stamp) of MODIS hdf4 file from + ! LOCALGRANULEID in global attribute "CoreMetadata.0" (ODL text), e.g., + ! + ! OBJECT = LOCALGRANULEID + ! NUM_VAL = 1 + ! VALUE = "MYD10C1.A2020015.061.2020326041737.hdf" + ! END_OBJECT = LOCALGRANULEID + ! + ! returns blank if not found + ! + ! amfox, 3 Nov 2026 + ! + ! ------------------------------------------------------------------------------------------------- - logical, intent(out) :: found_obs + implicit none - real, dimension(N_catf), intent(out) :: JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat + integer, intent(in) :: sd_id ! from sfstart() - ! ------------------------------------------------------------------------ - - ! locals + character(*), intent(out) :: granule_id - integer, parameter :: dtstep_assim_max = 21600 ! [seconds] avoid assim window spanning >=180 deg lon + ! local variables - real, parameter :: CMG_dlon = 0.05 ! [degrees] longitude spacing of JPSS CMG grid - real, parameter :: CMG_dlat = 0.05 ! [degrees] latitude spacing of JPSS CMG grid - - real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of JPSS CMG grid - real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of JPSS CMG grid - - character( 7) :: JPSS_product_ID - - character(4) :: YYYY - character(3) :: DDD ! day of year - - character( 12) :: tmpstr12 - character( 16) :: YYYYMMDD_HHMMSSz - character( 80) :: tmpstr80 + integer :: attr_index, data_type, attr_count, status, i1, i2, i3, i4 - character(400) :: fname - character(256) :: granule_id + character(256) :: attr_name - character(400), dimension(2) :: fname_list + character(:), allocatable :: core_metadata - real :: overpass_hour, tmp_delta, tmp_real, max_delta_lon - - integer :: N_files, N_lon, N_lat, N_tmp, nn, kk, ind, tmp_ind - 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_JPSS, date_time_end_JPSS - type(date_time_type) :: date_time_obs_beg + granule_id = '' - real :: lon_beg, lon_end - real :: lon_beg_JPSS, lon_end_JPSS - - integer :: delta_day_beg, delta_day_end - integer :: delta_day_beg_JPSS, delta_day_end_JPSS + attr_index = sffattr( sd_id, 'CoreMetadata.0' ) - real :: lat_min, lat_max + if (attr_index < 0) return - real, dimension(2) :: lon_min_vec, lon_max_vec + status = sfgainfo( sd_id, attr_index, attr_name, data_type, attr_count ) - integer, dimension(2) :: N_lon_vec, year_vec, dofyr_vec, start_ind, last_ind, N_good_data_list + if (status < 0) return - real, dimension(:), allocatable :: CMG_obs, CMG_lon, CMG_lat + ! CoreMetadata.0 is a character attribute; return blank for any other type + ! (sfrcatt() writes attr_count values of data_type, so the buffer below would be too small) - integer, dimension(:), allocatable :: tmp_tile_num + if ((data_type /= DFNT_CHAR8 .and. data_type /= DFNT_UCHAR8) .or. attr_count <= 0) return - integer, dimension(N_catf) :: N_obs_in_tile + allocate(character(attr_count) :: core_metadata) - character(len=*), parameter :: Iam = 'read_obs_JPSS_SCF' - character(len=400) :: err_msg + status = sfrcatt( sd_id, attr_index, core_metadata ) - ! ------------------------------------------------------------------------------------ - ! - ! initialize - - found_obs = .false. - - ! determine operating time range of sensor + if (status >= 0) then - if (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 - else - err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - end if + ! search only within the LOCALGRANULEID object, i.e., from "LOCALGRANULEID" to the next + ! "END_OBJECT"; VALUE is the text between the first two double quotes there - ! return if date_time falls outside operating time range + i2 = 0 + i3 = 0 + i4 = 0 - if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return + i1 = index( core_metadata, 'LOCALGRANULEID' ) - ! ---------------------------------------------------------------------------------- - ! - ! restrict assimilation time step to max allowed + if (i1 > 0) i4 = index( core_metadata(i1:), 'END_OBJECT' ) ! end of object (relative to i1) + if (i4 > 0) i2 = index( core_metadata(i1:i1+i4-2), '"' ) ! opening quote (relative to i1) + if (i2 > 0) i3 = index( core_metadata(i1+i2:i1+i4-2), '"' ) ! closing quote (relative to i1+i2) - if (dtstep_assim > dtstep_assim_max) then - - err_msg = 'dtstep_assim exceeds max allowed' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if + if (i3 > 1) granule_id = core_metadata(i1+i2:i1+i2+i3-2) - ! identify JPSS product and overpass hour - ! (see https://vlab.noaa.gov/web/towr-s/satellite-operations-updates) + end if - JPSS_product_ID = this_obs_param%name(1:7) - - select case (JPSS_product_ID) - - case('VJ110C1'); overpass_hour = 13.5 ! [hours] JPSS1: 13:30 local time - - case('VJ210C1'); overpass_hour = 13.5 ! [hours] JPSS2: 13:30 local time + deallocate(core_metadata) - case('VNP10C1'); overpass_hour = 13.5 ! [hours] S-NPP: 13:30 local time - - end select + end subroutine get_MODIS_granule_id + + ! ***************************************************************** + + subroutine read_MODIS_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 MODIS Terra or Aqua M?D10C1, version 6.1 + ! - Terra: https://nsidc.org/data/mod10c1/versions/61 + ! - Aqua: https://nsidc.org/data/myd10c1/versions/61 + ! - daily data with spatial resolution of 0.05 deg on MODIS climate modeling grid (CMG) + ! - Terra: missing days 2016 d. 50-58 + ! - data are read for the requested lat/lon range + ! - apply QC + ! + ! reichle, 20 Oct 2023 + ! + ! 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() + ! - amfox, reichle, 4 Nov 2026 + ! + ! ------------------------------------------------------------------------------------------------- - ! determine beginning and end of assimilation window + implicit none - date_time_beg = date_time - date_time_end = date_time + character(*), intent(in) :: fname ! MODIS file name with full path - call augment_date_time( -dtstep_assim/2, date_time_beg ) - call augment_date_time( dtstep_assim/2, date_time_end ) + 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 - ! determine longitude band associated with assimilation window and local overpass hour + real, dimension(:), intent(out) :: CMG_lon, CMG_lat, CMG_SCF ! NOTE: 1-dim array on CMG grid + + character(256), intent(out) :: granule_id ! original MODIS file name (incl. production time stamp) + + ! ------------------------------------------------- + + ! local parameters + + ! ll/ur_lon/lat simply indicate the extent of the MODIS CMG grid ! - ! observations will be returned only for tiles with lon_end < tile_coord_f%com_lon <= lon_beg + ! index increases from (-180,90) to (180,-90) (southward and eastward) - call localtime2longitude( date_time_beg, overpass_hour, lon_beg, delta_day_beg ) - call localtime2longitude( date_time_end, overpass_hour, lon_end, delta_day_end ) + 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 - ! determine (rough) longitude band for which JPSS obs need to be read - ! - ! --> because tiles have a non-zero extent, need to read JPSS 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_f%max_lon - tile_coord_f%min_lon ) + integer, parameter :: N_fields = 3 + + character(22), dimension(N_fields), parameter :: field_names = (/ & + 'Day_CMG_Snow_Cover ', & ! 1 + 'Day_CMG_Clear_Index ', & ! 2 + 'Snow_Spatial_QA '/) ! 3 + + ! 1234567890123456789012 + ! 1 2 + + integer, parameter :: SCF_nodata = -9999. - tmp_delta = 3.*maxval( tile_coord_f(1:N_catf)%max_lon - tile_coord_f(1:N_catf)%min_lon ) ! [degrees] + integer(int16), parameter :: qc_snow_cover_max = 100 ! exclude lake ice, night, inland water, ocean, etc + integer(int16), parameter :: qc_clear_index_min = 20 ! ensure sufficiently clear conditions + integer(int16), parameter :: qc_snow_spatial_max = 2 ! data quality (0=best, 1=good, 2=OK, 3=poor, 4=other) - tmp_delta = tmp_delta/360.*86400. ! [seconds] + integer, parameter :: DFACC_READ = 1 ! from hdf.inc - date_time_beg_JPSS = date_time_beg - date_time_end_JPSS = date_time_end + integer, parameter :: uint8_min = 0 + integer, parameter :: uint8_max = 255 - call augment_date_time( -nint(tmp_delta), date_time_beg_JPSS ) - call augment_date_time( nint(tmp_delta), date_time_end_JPSS ) - - call localtime2longitude( date_time_beg_JPSS, overpass_hour, lon_beg_JPSS, delta_day_beg_JPSS ) - call localtime2longitude( date_time_end_JPSS, overpass_hour, lon_end_JPSS, delta_day_end_JPSS ) + + ! local variables - ! adjust date_time_*_JPSS to reflect calendar date at lon_*_JPSS + 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, edge, stride, last, dimsizes - call augment_date_time( delta_day_beg_JPSS*86400, date_time_beg_JPSS ) - call augment_date_time( delta_day_end_JPSS*86400, date_time_end_JPSS ) - - ! put together arguments for call(s) to read_JPSS_SCF_hdf() + logical :: file_exists, keep_data - lon_min_vec = MAPL_UNDEF - lon_max_vec = MAPL_UNDEF + integer :: status, sd_id, sds_id, sds_index + + character(64) :: sds_name - year_vec = -9999 - dofyr_vec = -9999 + integer :: rank, data_type, num_attrs - N_lon_vec = 0 + integer(int16), dimension(:,:), allocatable :: Snow_Cover + integer(int16), dimension(:,:), allocatable :: Clear_Index + integer(int16), dimension(:,:), allocatable :: Snow_Spatial_QA + + character(kind=c_char, len=1), dimension(:,:), allocatable :: tmp_char1 - if (lon_end_JPSS < lon_beg_JPSS) then + character(len=*), parameter :: Iam = 'read_MODIS_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 ( date_time_end_JPSS%dofyr == date_time_beg_JPSS%dofyr ) then - - ! need only one daily JPSS file and longitude band - - N_files = 1 - - lon_min_vec(1) = lon_end_JPSS - lon_max_vec(1) = lon_beg_JPSS - - year_vec( 1) = date_time_beg_JPSS%year - dofyr_vec( 1) = date_time_beg_JPSS%dofyr - - else - - ! this should never happen for dtstep_assim_max=21600 and overpass_hour of 13:30 - - write (logunit,*) 'overpass_hour = ', overpass_hour - 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_JPSS = ', date_time_beg_JPSS - write (logunit,*) 'date_time_end_JPSS = ', date_time_end_JPSS - write (logunit,*) 'lon_beg = ', lon_beg - write (logunit,*) 'lon_end = ', lon_end - write (logunit,*) 'lon_beg_JPSS = ', lon_beg_JPSS - write (logunit,*) 'lon_end_JPSS = ', lon_end_JPSS - - err_msg = 'encountered unexpected condition for longitude band!!!' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - + if (logit) then + write (logunit,'(400A)') trim(Iam), ': cannot find file ', trim(fname) + write (logunit,* ) 'not reading MODIS SCF obs' end if - - else - - ! longitude band wraps around dateline, two daily JPSS files are needed - ! (this could also occur if lon_*_JPSS=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_JPSS - 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_JPSS%year - dofyr_vec( 1) = date_time_end_JPSS%dofyr - - lon_min_vec(2) = -180. - lon_max_vec(2) = lon_beg_JPSS - - year_vec( 2) = date_time_beg_JPSS%year - dofyr_vec( 2) = date_time_beg_JPSS%dofyr + + N_good_data = 0 + + return end if - ! verify that longitude bands do not exceed max expected expected width - ! (add 0.1 degree of wiggle room) - max_delta_lon = real(dtstep_assim_max + 2*nint(tmp_delta))/86400.*360. + 0.1 ! [degree] + ! ensure lon_* and lat_* inputs are within range - do nn=1,N_files - - if ( lon_max_vec(nn) - lon_min_vec(nn) > max_delta_lon ) then - - err_msg = 'longitude band too wide' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - end do + 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 MODIS CMG array indices for requested lat/lon_min/max range + + ! MODIS CMG hdf files: + ! - lon-by-lat (NOTE: The metadata "s.Vgroup(1).Vgroup(1).SDS(1).Dims.Size" returned + ! by Matlab's hdfinfo() confusingly suggests that CMG files are + ! lat-by-lon, which is not the case!) + ! - index values increase eastward and southward - ! determine latitude band covered by domain (no need to read obs outside domain) + 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 + + edge(1) = N_lon + edge(2) = N_lat + + stride(1) = 1 + stride(2) = 1 + - lat_min = minval( tile_coord_f(1:N_catf)%min_lat ) - lat_max = maxval( tile_coord_f(1:N_catf)%max_lat ) + ! ! dbg ! ! write (*,*) '###############################################################################' + ! ! dbg ! ! write (*,*) Iam // '():' + ! ! dbg ! ! write (*,*) 'size(CMG_SCF), N_lon, N_lat = ', size(CMG_SCF), N_lon, N_lat + ! ! dbg ! ! write (*,*) 'lon_min, lon_max = ', lon_min, lon_max + ! ! dbg ! ! write (*,*) 'lat_min, lat_max = ', lat_min, lat_max + ! ! dbg ! ! write (*,*) 'start [lon, lat] = ', start + ! ! dbg ! ! write (*,*) 'last [lon, lat] = ', last + ! ! dbg ! ! write (*,*) 'edge [lon, lat] = ', edge + ! ! dbg ! ! write (*,*) '###############################################################################' - ! determine N_lat and N_lon[_vec] (# CMG grid cells in lat/lon bands ) - start_ind(1) = (CMG_ur_lat - lat_max )/CMG_dlat - last_ind(1) = (CMG_ur_lat - lat_min )/CMG_dlat - - N_lat = last_ind(1) - start_ind(1) + 1 + + ! checks array dimensions - start_ind(1:N_files) = (lon_min_vec(1:N_files) - CMG_ll_lon)/CMG_dlon - last_ind( 1:N_files) = (lon_max_vec(1:N_files) - CMG_ll_lon)/CMG_dlon + 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 - N_lon_vec(1:N_files) = last_ind(1:N_files) - start_ind(1:N_files) + 1 + ! check array bounds - N_lon = sum( N_lon_vec(1:N_files) ) + 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 - ! allocate arrays for JPSS CMG data (max size that could possibly be needed for obs from both files) + if (logit) then + write (logunit,'(400A)') trim(Iam), '(): reading MODIS 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 - N_tmp = N_lon*N_lat - allocate( CMG_obs(N_tmp) ) - allocate( CMG_lon(N_tmp) ) - allocate( CMG_lat(N_tmp) ) + ! 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(Snow_Spatial_QA(N_lon,N_lat)) + + allocate(tmp_char1( N_lon,N_lat)) + + ! -------------------------- - ! read VIIRS SCF obs - ! - ! - files must be renamed (production time stamp removed), as for MODIS SCF obs: - ! 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 - ! + ! 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 - N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_JPSS_SCF_hdf() + 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 + + ! -------------------------- - do nn=1,N_files ! loop through longitude bands (i.e., files) - - ! determine JPSS 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:23) - - ! 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_JPSS_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 ) + ! open hdf file (read-only) and initialize SD interface + + sd_id = sfstart(trim(fname), DFACC_READ) - N_CMG_obs = N_CMG_obs + N_good_data + if (sd_id<0) then + + err_msg = 'cannot sfstart (open) file: ' // trim(fname) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - ! record number of good obs and file name for obslog + 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 - N_good_data_list(nn) = N_good_data + call get_MODIS_granule_id( sd_id, granule_id ) - if (len_trim(granule_id)>0) then + ! read data - tmp_ind = index(trim(fname), '/', back=.true.) ! position of last "/" + do nn=1,N_fields + + sds_index = sfn2index( sd_id, trim(field_names(nn)) ) + sds_id = sfselect( sd_id, sds_index ) - if (tmp_ind>0) then - fname_list(nn) = fname(1:tmp_ind) // trim(granule_id) ! replace file name with granule id - else - fname_list(nn) = trim(granule_id) ! fname was only file name (no path) - end if - else + status = sfginfo( sds_id, sds_name, rank, dimsizes, data_type, num_attrs ) + + if ( (dimsizes(1)/=CMG_N_lon) .or. (dimsizes(2)/=CMG_N_lat) ) then - fname_list( nn) = fname ! use fname b/c granule_id is empty + err_msg = 'dimensions in hdf file doe not match CMG_N_lon and/or CMG_N_lat' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! ######################################################### + ! ! dbg ! ! write (*,*) 'sds_name = ', trim(sds_name) + ! ! dbg ! ! write (*,*) 'rank, data_type, num_attrs = ', rank, data_type, num_attrs + ! ! dbg ! ! write (*,*) 'dimsizes = ', dimsizes + ! ######################################################### + + + select case (nn) + + case (1); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Cover = ichar(tmp_char1,2) + case (2); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Clear_Index = ichar(tmp_char1,2) + case (3); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Spatial_QA = ichar(tmp_char1,2) + + case default; call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown field') + + end select + + if (status/=0) then + + err_msg = 'error reading data from hdf file: ' // trim(fname) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + end if + status = sfendacc(sds_id) ! terminate access to SDS (field) + end do - ! write "obslog" file - - if (write_obslog) then - - YYYYMMDD_HHMMSSz = date_time2string(date_time) + status = sfend(sd_id) ! close hdf file and SD interface - tmpstr80 = trim(Iam) // '()' ! name of this subroutine - do nn=1,N_files + ! ################################################################################# + ! ! dbg ! ! write (*,*) 'Snow_Cover(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Snow_Cover(1:10,1:5) + ! ! dbg ! ! write (*,*) 'Clear_Index(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Clear_Index(1:10,1:5) + ! ! dbg ! ! write (*,*) 'Snow_Spatial_QA(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Snow_Spatial_QA(1:10,1:5) + + ! ! dbg ! ! !if ( (lon_min>-138) .and. (lon_min<-134) ) then + ! ! dbg ! ! if (.false.) then + ! ! dbg ! ! do jj=1,N_lat + ! ! dbg ! ! write(997) Snow_Cover( jj,:) + ! ! dbg ! ! write(998) Clear_Index( jj,:) + ! ! dbg ! ! write(999) Snow_Spatial_QA(jj,:) + ! ! dbg ! ! end do + ! ! dbg ! ! write (*,*) 'stopping after file dump ' + ! ! dbg ! ! stop + ! ! dbg ! ! end if + ! ################################################################################# - write (tmpstr12,'(i12)') N_good_data_list(nn) ! convert integer to string - call add_to_obslog( YYYYMMDD_HHMMSSz, this_obs_param%descr, tmpstr80, & - tmpstr12, fname_list(nn) ) - end do + ! check range (make sure uint8 from hdf 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(Snow_Spatial_QA < uint8_min) .or. & + any(Snow_Spatial_QA > uint8_max) ) then + + err_msg = 'unexpected range in data from hdf file' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + end if - - ! return if no JPSS obs were found (found_obs=.false. per initialization above) - - if (N_CMG_obs==0) return - - - ! map to tile space - - allocate(tmp_tile_num(N_CMG_obs)) - - 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 ) + ! ------------------------------------- + ! + ! apply QC and put SCF obs into output array - std_JPSS_obs = this_obs_param%errstd - - JPSS_obs = 0. - JPSS_lon = 0. - JPSS_lat = 0. + CMG_lon = SCF_nodata ! initialize + CMG_lat = SCF_nodata ! initialize + CMG_SCF = SCF_nodata ! initialize - N_obs_in_tile = 0 - - do kk=1,N_CMG_obs - - ind = tmp_tile_num(kk) ! 1<=tmp_tile_num<=N_catf (unless nodata) - - if (ind>0) then ! this condition eliminates obs outside domain - - JPSS_obs( ind) = JPSS_obs( ind) + CMG_obs(kk) - JPSS_lon( ind) = JPSS_lon( ind) + CMG_lon(kk) - JPSS_lat( ind) = JPSS_lat( ind) + CMG_lat(kk) + kk = 0 ! initialize counter for "good" data - N_obs_in_tile(ind) = N_obs_in_tile(ind) + 1 + do ii=1,N_lon + do jj=1,N_lat - end if - - end do - - ! normalize - - do kk=1,N_catf - if (N_obs_in_tile(kk)>0) then + ! note: Snow_Cover >= 0 per range check above, no need to check for minimum - tmp_real = real(N_obs_in_tile(kk)) - - JPSS_obs(kk) = JPSS_obs(kk)/tmp_real - JPSS_lon(kk) = JPSS_lon(kk)/tmp_real - JPSS_lat(kk) = JPSS_lat(kk)/tmp_real + 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) + (Snow_Spatial_QA(ii,jj) <= qc_snow_spatial_max) ! keep "best", "good", or "OK" quality (3) - else if (N_obs_in_tile(kk)==0) then + ! (1) excludes "lake ice", "night", "inland water", "ocean", "cloud obscured water", "data not mapped", "fill" + ! (2) clear_index>100 already removed via qc_snow_cover_max + ! (3) excludes Antarctica - JPSS_obs(kk) = this_obs_param%nodata - JPSS_lon(kk) = this_obs_param%nodata - JPSS_lat(kk) = this_obs_param%nodata + if (keep_data) then + + kk = kk + 1 + + ! raw SCF value is for clear portion of grid cell only, need to normalize with Clear_Index + + CMG_SCF(kk) = 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 if + end do end do - if (any(N_obs_in_tile>0)) then - - found_obs = .true. - - else - - found_obs = .false. - - end if - - deallocate(tmp_tile_num) - - deallocate(CMG_obs) - deallocate(CMG_lon) - deallocate(CMG_lat) - - ! to avoid double-counting of JPSS 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 - ! assimilation windows gets its obs only once (e.g., EASEv2 M36 tiles at +-45 and +-135 deg - ! for windows centered at 0z, 3z, ...) + N_good_data = kk - if (lon_end < lon_beg) then - - ! need only one longitude band (keep obs when lon_endlon_beg) ) & - JPSS_obs(kk) = this_obs_param%nodata - - end do - - else - - ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_endlon_beg) .and. (tile_coord_f(kk)%com_lon<=lon_end) ) & - JPSS_obs(kk) = this_obs_param%nodata - - end do - - end if + if (logit) write (logunit,*) 'N_good_data = ', N_good_data + + deallocate(lat_c) + deallocate(lon_c) + deallocate(lat_ind) + deallocate(lon_ind) - end subroutine read_obs_JPSS_SCF - - ! ******************************************************************************************************* + deallocate(Snow_Cover ) + deallocate(Clear_Index ) + deallocate(Snow_Spatial_QA) - subroutine localtime2longitude( date_time, local_hour, longitude, delta_day ) + end subroutine read_MODIS_SCF_hdf + + ! ******************************************************************************************************* - ! for date_time in UTC, find the longitude where the local time is local_hour; - ! delta_day is the offset between the UTC calendar day and the calendar - ! day at the returned longitude - ! when UTC and local time are exactly 12 hours offset, always return longitude=+180. - ! - ! - reichle, 19 Oct 2023 + subroutine read_obs_JPSS_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, JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat ) - implicit none - - type(date_time_type), intent(in) :: date_time ! current date and time in UTC + ! read JPSS snow cover observations on the 0.05-degree climate + ! modeling grid (CMG) + ! + ! JPSS1/NOAA-20: VJ110C1 (launched 2017) + ! JPSS2/NOAA-21: VJ210C1 (launched 2022) + ! S-NPP : VNP10C1 (launched 2011, decommissioned 2026) + ! + ! + ! For now, assume that VIIRS/JPSS 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 + ! + ! lcandre2, 26 Oct 2026 + ! + ! amfox, 5 Nov 2026 - obs on tiles at a window boundary are assimilated only once (as for MODIS); + ! original file names ("granule_id") are written to the obslog (as for MODIS) + ! + ! ------------------------------------------------------------------------------ - real, intent(in) :: local_hour ! fractional local hour (e.g., 1:30pm is 13.5); range=[0,24) + implicit none - real, intent(out) :: longitude ! [degree] -180 < longitude <= 180 + ! inputs - integer, intent(out) :: delta_day ! [days] -1 <= delta_day <= 1 - - ! ---------------------------------------------- - - real :: UTC_hour, time_diff - - character(len=*), parameter :: Iam = 'localtime2longitude' - character(len=400) :: err_msg - - ! --------------------------------------------------------------------------- - - ! make sure local_hour is within range: 0 <= local_hour < 24 - - if ( (local_hour < 0.) .or. (local_hour >= 24.) ) then - - err_msg = 'input local_hour falls outside allowed range of 0:24' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - ! initialize - - delta_day = 0 - - ! determine fractional UTC hour and time difference with local_hour - - UTC_hour = ( date_time%hour*3600 + date_time%min*60 + date_time%sec )/3600. ! 0 <= UTC_hour < 24 + type(date_time_type), intent(in) :: date_time - time_diff = local_hour - UTC_hour + integer, intent(in) :: dtstep_assim ! [seconds] + integer, intent(in) :: N_catf - ! enforce -12. < time_diff <= 12. and determine associated date difference, if any + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - if (time_diff <= -12.) then - - delta_day = 1 + type(grid_def_type), intent(in) :: obs2tile_grid_f - time_diff = time_diff + 24. - - elseif (time_diff > 12.) then - - delta_day = -1 + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - time_diff = time_diff - 24. - - end if + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: N_tile_in_cell_ij - ! determine longitude + integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - longitude = time_diff/24.*360. - - end subroutine localtime2longitude + type(obs_param_type), intent(in) :: this_obs_param - ! ***************************************************************** - - subroutine get_MODIS_granule_id( sd_id, granule_id ) + logical, intent(in) :: write_obslog - ! get original file name (incl. production time stamp) of MODIS hdf4 file from - ! LOCALGRANULEID in global attribute "CoreMetadata.0" (ODL text), e.g., - ! - ! OBJECT = LOCALGRANULEID - ! NUM_VAL = 1 - ! VALUE = "MYD10C1.A2020015.061.2020326041737.hdf" - ! END_OBJECT = LOCALGRANULEID - ! - ! returns blank if not found - ! - ! amfox, 3 Nov 2026 - ! - ! ------------------------------------------------------------------------------------------------- + ! output - implicit none + logical, intent(out) :: found_obs - integer, intent(in) :: sd_id ! from sfstart() + real, dimension(N_catf), intent(out) :: JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat - character(*), intent(out) :: granule_id + ! ------------------------------------------------------------------------ + + ! locals - ! local variables + integer, parameter :: dtstep_assim_max = 21600 ! [seconds] avoid assim window spanning >=180 deg lon - integer :: attr_index, data_type, attr_count, status, i1, i2, i3, i4 + real, parameter :: CMG_dlon = 0.05 ! [degrees] longitude spacing of JPSS CMG grid + real, parameter :: CMG_dlat = 0.05 ! [degrees] latitude spacing of JPSS CMG grid + + real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of JPSS CMG grid + real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of JPSS CMG grid + + character( 7) :: JPSS_product_ID + + character(4) :: YYYY + character(3) :: DDD ! day of year + + character( 12) :: tmpstr12 + character( 16) :: YYYYMMDD_HHMMSSz + character( 80) :: tmpstr80 - character(256) :: attr_name + character(400) :: fname + character(256) :: granule_id - character(:), allocatable :: core_metadata + character(400), dimension(2) :: fname_list - ! ------------------------------------------------- + real :: overpass_hour, tmp_delta, tmp_real, max_delta_lon + + integer :: N_files, N_lon, N_lat, N_tmp, nn, kk, ind, tmp_ind + integer :: N_CMG_obs, N_good_data, tmp_ind_start, tmp_ind_last - granule_id = '' + type(date_time_type) :: date_time_beg, date_time_end + type(date_time_type) :: date_time_beg_JPSS, date_time_end_JPSS + type(date_time_type) :: date_time_obs_beg - attr_index = sffattr( sd_id, 'CoreMetadata.0' ) + real :: lon_beg, lon_end + real :: lon_beg_JPSS, lon_end_JPSS + + integer :: delta_day_beg, delta_day_end + integer :: delta_day_beg_JPSS, delta_day_end_JPSS - if (attr_index < 0) return + real :: lat_min, lat_max - status = sfgainfo( sd_id, attr_index, attr_name, data_type, attr_count ) + real, dimension(2) :: lon_min_vec, lon_max_vec - if (status < 0) return + integer, dimension(2) :: N_lon_vec, year_vec, dofyr_vec, start_ind, last_ind, N_good_data_list - ! CoreMetadata.0 is a character attribute; return blank for any other type - ! (sfrcatt() writes attr_count values of data_type, so the buffer below would be too small) + real, dimension(:), allocatable :: CMG_obs, CMG_lon, CMG_lat - if ((data_type /= DFNT_CHAR8 .and. data_type /= DFNT_UCHAR8) .or. attr_count <= 0) return + integer, dimension(:), allocatable :: tmp_tile_num - allocate(character(attr_count) :: core_metadata) + integer, dimension(N_catf) :: N_obs_in_tile - status = sfrcatt( sd_id, attr_index, core_metadata ) + character(len=*), parameter :: Iam = 'read_obs_JPSS_SCF' + character(len=400) :: err_msg - if (status >= 0) then + ! ------------------------------------------------------------------------------------ + ! + ! initialize + + found_obs = .false. + + ! determine operating time range of sensor - ! search only within the LOCALGRANULEID object, i.e., from "LOCALGRANULEID" to the next - ! "END_OBJECT"; VALUE is the text between the first two double quotes there + if (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 + else + err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + end if - i2 = 0 - i3 = 0 - i4 = 0 + ! return if date_time falls outside operating time range - i1 = index( core_metadata, 'LOCALGRANULEID' ) + if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return - if (i1 > 0) i4 = index( core_metadata(i1:), 'END_OBJECT' ) ! end of object (relative to i1) - if (i4 > 0) i2 = index( core_metadata(i1:i1+i4-2), '"' ) ! opening quote (relative to i1) - if (i2 > 0) i3 = index( core_metadata(i1+i2:i1+i4-2), '"' ) ! closing quote (relative to i1+i2) + ! ---------------------------------------------------------------------------------- + ! + ! restrict assimilation time step to max allowed - if (i3 > 1) granule_id = core_metadata(i1+i2:i1+i2+i3-2) - - end if - - deallocate(core_metadata) - - end subroutine get_MODIS_granule_id + if (dtstep_assim > dtstep_assim_max) then + + err_msg = 'dtstep_assim exceeds max allowed' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if - ! ***************************************************************** + ! identify JPSS product and overpass hour + ! (see https://vlab.noaa.gov/web/towr-s/satellite-operations-updates) - subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & - N_good_data, CMG_lon, CMG_lat, CMG_SCF, granule_id ) + JPSS_product_ID = this_obs_param%name(1:7) - ! read snow cover area fraction (SCF) obs from daily MODIS Terra or Aqua M?D10C1, version 6.1 - ! - Terra: https://nsidc.org/data/mod10c1/versions/61 - ! - Aqua: https://nsidc.org/data/myd10c1/versions/61 - ! - daily data with spatial resolution of 0.05 deg on MODIS climate modeling grid (CMG) - ! - Terra: missing days 2016 d. 50-58 - ! - data are read for the requested lat/lon range - ! - apply QC - ! - ! reichle, 20 Oct 2023 - ! - ! 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() - ! - amfox, reichle, 4 Nov 2026 - ! - ! ------------------------------------------------------------------------------------------------- + select case (JPSS_product_ID) + + case('VJ110C1'); overpass_hour = 13.5 ! [hours] JPSS1: 13:30 local time + + case('VJ210C1'); overpass_hour = 13.5 ! [hours] JPSS2: 13:30 local time + + case('VNP10C1'); overpass_hour = 13.5 ! [hours] S-NPP: 13:30 local time + + end select - implicit none - character(*), intent(in) :: fname ! MODIS file name with full path + ! determine beginning and end of assimilation window - real, intent(in) :: lon_min, lon_max ! -180 <= lon_* <= 180 - real, intent(in) :: lat_min, lat_max ! -90 <= lat_* <= 90 + date_time_beg = date_time + date_time_end = date_time - integer, intent(out) :: N_good_data + call augment_date_time( -dtstep_assim/2, date_time_beg ) + call augment_date_time( dtstep_assim/2, date_time_end ) - real, dimension(:), intent(out) :: CMG_lon, CMG_lat, CMG_SCF ! NOTE: 1-dim array on CMG grid - - character(256), intent(out) :: granule_id ! original MODIS file name (incl. production time stamp) - - ! ------------------------------------------------- - - ! local parameters - ! ll/ur_lon/lat simply indicate the extent of the MODIS CMG grid + ! determine longitude band associated with assimilation window and local overpass hour ! - ! index increases from (-180,90) to (180,-90) (southward and eastward) - - integer, parameter :: CMG_N_lon = 7200 - integer, parameter :: CMG_N_lat = 3600 + ! observations will be returned only for tiles with lon_end < tile_coord_f%com_lon <= lon_beg - real, parameter :: CMG_ll_lon = -180. - real, parameter :: CMG_ll_lat = -90. + call localtime2longitude( date_time_beg, overpass_hour, lon_beg, delta_day_beg ) + call localtime2longitude( date_time_end, overpass_hour, lon_end, delta_day_end ) - 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(22), dimension(N_fields), parameter :: field_names = (/ & - 'Day_CMG_Snow_Cover ', & ! 1 - 'Day_CMG_Clear_Index ', & ! 2 - 'Snow_Spatial_QA '/) ! 3 - - ! 1234567890123456789012 - ! 1 2 - - integer, parameter :: SCF_nodata = -9999. - - integer(int16), parameter :: qc_snow_cover_max = 100 ! exclude lake ice, night, inland water, ocean, etc - integer(int16), parameter :: qc_clear_index_min = 20 ! ensure sufficiently clear conditions - integer(int16), parameter :: qc_snow_spatial_max = 2 ! data quality (0=best, 1=good, 2=OK, 3=poor, 4=other) + ! determine (rough) longitude band for which JPSS obs need to be read + ! + ! --> because tiles have a non-zero extent, need to read JPSS 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_f%max_lon - tile_coord_f%min_lon ) - integer, parameter :: DFACC_READ = 1 ! from hdf.inc + tmp_delta = 3.*maxval( tile_coord_f(1:N_catf)%max_lon - tile_coord_f(1:N_catf)%min_lon ) ! [degrees] - integer, parameter :: uint8_min = 0 - integer, parameter :: uint8_max = 255 - - - ! local variables + tmp_delta = tmp_delta/360.*86400. ! [seconds] - 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 + date_time_beg_JPSS = date_time_beg + date_time_end_JPSS = date_time_end - integer, dimension(2) :: start, edge, stride, last, dimsizes + call augment_date_time( -nint(tmp_delta), date_time_beg_JPSS ) + call augment_date_time( nint(tmp_delta), date_time_end_JPSS ) + + call localtime2longitude( date_time_beg_JPSS, overpass_hour, lon_beg_JPSS, delta_day_beg_JPSS ) + call localtime2longitude( date_time_end_JPSS, overpass_hour, lon_end_JPSS, delta_day_end_JPSS ) - logical :: file_exists, keep_data + ! adjust date_time_*_JPSS to reflect calendar date at lon_*_JPSS - integer :: status, sd_id, sds_id, sds_index + call augment_date_time( delta_day_beg_JPSS*86400, date_time_beg_JPSS ) + call augment_date_time( delta_day_end_JPSS*86400, date_time_end_JPSS ) + + ! put together arguments for call(s) to read_JPSS_SCF_hdf() - character(64) :: sds_name + lon_min_vec = MAPL_UNDEF + lon_max_vec = MAPL_UNDEF - integer :: rank, data_type, num_attrs + year_vec = -9999 + dofyr_vec = -9999 - integer(int16), dimension(:,:), allocatable :: Snow_Cover - integer(int16), dimension(:,:), allocatable :: Clear_Index - integer(int16), dimension(:,:), allocatable :: Snow_Spatial_QA - - character(kind=c_char, len=1), dimension(:,:), allocatable :: tmp_char1 + N_lon_vec = 0 - character(len=*), parameter :: Iam = 'read_MODIS_SCF_hdf' - character(len=400) :: err_msg - - ! ------------------------------------------------------------------------- - ! - ! make sure file exists + if (lon_end_JPSS < lon_beg_JPSS) then + + if ( date_time_end_JPSS%dofyr == date_time_beg_JPSS%dofyr ) then + + ! need only one daily JPSS file and longitude band + + N_files = 1 + + lon_min_vec(1) = lon_end_JPSS + lon_max_vec(1) = lon_beg_JPSS + + year_vec( 1) = date_time_beg_JPSS%year + dofyr_vec( 1) = date_time_beg_JPSS%dofyr + + else + + ! this should never happen for dtstep_assim_max=21600 and overpass_hour of 13:30 + + write (logunit,*) 'overpass_hour = ', overpass_hour + 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_JPSS = ', date_time_beg_JPSS + write (logunit,*) 'date_time_end_JPSS = ', date_time_end_JPSS + write (logunit,*) 'lon_beg = ', lon_beg + write (logunit,*) 'lon_end = ', lon_end + write (logunit,*) 'lon_beg_JPSS = ', lon_beg_JPSS + write (logunit,*) 'lon_end_JPSS = ', lon_end_JPSS + + err_msg = 'encountered unexpected condition for longitude band!!!' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + else + + ! longitude band wraps around dateline, two daily JPSS files are needed + ! (this could also occur if lon_*_JPSS=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_JPSS + 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_JPSS%year + dofyr_vec( 1) = date_time_end_JPSS%dofyr + + lon_min_vec(2) = -180. + lon_max_vec(2) = lon_beg_JPSS + + year_vec( 2) = date_time_beg_JPSS%year + dofyr_vec( 2) = date_time_beg_JPSS%dofyr + + end if - granule_id = '' - - inquire( file=trim(fname), exist=file_exists ) + ! verify that longitude bands do not exceed max expected expected width + ! (add 0.1 degree of wiggle room) + max_delta_lon = real(dtstep_assim_max + 2*nint(tmp_delta))/86400.*360. + 0.1 ! [degree] - if (.not. file_exists ) then + do nn=1,N_files - if (logit) then - write (logunit,'(400A)') trim(Iam), ': cannot find file ', trim(fname) - write (logunit,* ) 'not reading MODIS SCF obs' + if ( lon_max_vec(nn) - lon_min_vec(nn) > max_delta_lon ) then + + err_msg = 'longitude band too wide' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + end if - N_good_data = 0 + end do + + + ! determine latitude band covered by domain (no need to read obs outside domain) + + lat_min = minval( tile_coord_f(1:N_catf)%min_lat ) + lat_max = maxval( tile_coord_f(1:N_catf)%max_lat ) - 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 + ! determine N_lat and N_lon[_vec] (# CMG grid cells in lat/lon bands ) - err_msg = 'lat/lon min/max inputs out of range' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if + start_ind(1) = (CMG_ur_lat - lat_max )/CMG_dlat + last_ind(1) = (CMG_ur_lat - lat_min )/CMG_dlat + + N_lat = last_ind(1) - start_ind(1) + 1 - ! determine MODIS CMG array indices for requested lat/lon_min/max range + start_ind(1:N_files) = (lon_min_vec(1:N_files) - CMG_ll_lon)/CMG_dlon + last_ind( 1:N_files) = (lon_max_vec(1:N_files) - CMG_ll_lon)/CMG_dlon - ! MODIS CMG hdf files: - ! - lon-by-lat (NOTE: The metadata "s.Vgroup(1).Vgroup(1).SDS(1).Dims.Size" returned - ! by Matlab's hdfinfo() confusingly suggests that CMG files are - ! lat-by-lon, which is not the case!) - ! - index values increase eastward and southward + N_lon_vec(1:N_files) = last_ind(1:N_files) - start_ind(1:N_files) + 1 + + N_lon = sum( N_lon_vec(1:N_files) ) - 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] + ! allocate arrays for JPSS CMG data (max size that could possibly be needed for obs from both files) - 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_tmp = N_lon*N_lat + + allocate( CMG_obs(N_tmp) ) + allocate( CMG_lon(N_tmp) ) + allocate( CMG_lat(N_tmp) ) - N_lon = last(1) - start(1) + 1 - N_lat = last(2) - start(2) + 1 - edge(1) = N_lon - edge(2) = N_lat + ! read VIIRS SCF obs + ! + ! - files must be renamed (production time stamp removed), as for MODIS SCF obs: + ! 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 + ! - stride(1) = 1 - stride(2) = 1 + N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_JPSS_SCF_hdf() + do nn=1,N_files ! loop through longitude bands (i.e., files) + + ! determine JPSS 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:23) + + ! 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_JPSS_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 ) + N_CMG_obs = N_CMG_obs + N_good_data + + ! record number of good obs and file name for obslog - ! ! dbg ! ! write (*,*) '###############################################################################' - ! ! dbg ! ! write (*,*) Iam // '():' - ! ! dbg ! ! write (*,*) 'size(CMG_SCF), N_lon, N_lat = ', size(CMG_SCF), N_lon, N_lat - ! ! dbg ! ! write (*,*) 'lon_min, lon_max = ', lon_min, lon_max - ! ! dbg ! ! write (*,*) 'lat_min, lat_max = ', lat_min, lat_max - ! ! dbg ! ! write (*,*) 'start [lon, lat] = ', start - ! ! dbg ! ! write (*,*) 'last [lon, lat] = ', last - ! ! dbg ! ! write (*,*) 'edge [lon, lat] = ', edge - ! ! dbg ! ! write (*,*) '###############################################################################' - + N_good_data_list(nn) = N_good_data + if (len_trim(granule_id)>0) then - ! 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 + tmp_ind = index(trim(fname), '/', back=.true.) ! position of last "/" - if (logit) then - write (logunit,'(400A)') trim(Iam), '(): reading MODIS 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 - + if (tmp_ind>0) then + fname_list(nn) = fname(1:tmp_ind) // trim(granule_id) ! replace file name with granule id + else + fname_list(nn) = trim(granule_id) ! fname was only file name (no path) + end if - ! allocate arrays + else - allocate(lon_c( N_lon)) - allocate(lat_c( N_lat)) + fname_list( nn) = fname ! use fname b/c granule_id is empty + + end if + + end do - allocate(lon_ind(N_lon)) - allocate(lat_ind(N_lat)) + ! write "obslog" file - allocate(Snow_Cover (N_lon,N_lat)) - allocate(Clear_Index (N_lon,N_lat)) - allocate(Snow_Spatial_QA(N_lon,N_lat)) + if (write_obslog) then - allocate(tmp_char1( N_lon,N_lat)) + YYYYMMDD_HHMMSSz = date_time2string(date_time) - ! -------------------------- - - ! determine center lat/lon of CMG cells + tmpstr80 = trim(Iam) // '()' ! name of this subroutine - 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) + do nn=1,N_files - ! 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 hdf file (read-only) and initialize SD interface - - sd_id = sfstart(trim(fname), DFACC_READ) + write (tmpstr12,'(i12)') N_good_data_list(nn) ! convert integer to string + + call add_to_obslog( YYYYMMDD_HHMMSSz, this_obs_param%descr, tmpstr80, & + tmpstr12, fname_list(nn) ) + + end do - if (sd_id<0) then - - err_msg = 'cannot sfstart (open) file: ' // trim(fname) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - 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 - call get_MODIS_granule_id( sd_id, granule_id ) + ! return if no JPSS obs were found (found_obs=.false. per initialization above) - ! read data + if (N_CMG_obs==0) return - do nn=1,N_fields - - sds_index = sfn2index( sd_id, trim(field_names(nn)) ) - sds_id = sfselect( sd_id, sds_index ) + ! map to tile space + + allocate(tmp_tile_num(N_CMG_obs)) + + 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 ) + + + std_JPSS_obs = this_obs_param%errstd + + JPSS_obs = 0. + JPSS_lon = 0. + JPSS_lat = 0. - status = sfginfo( sds_id, sds_name, rank, dimsizes, data_type, num_attrs ) + N_obs_in_tile = 0 + + do kk=1,N_CMG_obs - if ( (dimsizes(1)/=CMG_N_lon) .or. (dimsizes(2)/=CMG_N_lat) ) then + ind = tmp_tile_num(kk) ! 1<=tmp_tile_num<=N_catf (unless nodata) + + if (ind>0) then ! this condition eliminates obs outside domain + + JPSS_obs( ind) = JPSS_obs( ind) + CMG_obs(kk) + JPSS_lon( ind) = JPSS_lon( ind) + CMG_lon(kk) + JPSS_lat( ind) = JPSS_lat( ind) + CMG_lat(kk) - err_msg = 'dimensions in hdf file doe not match CMG_N_lon and/or CMG_N_lat' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + N_obs_in_tile(ind) = N_obs_in_tile(ind) + 1 end if - - ! ######################################################### - ! ! dbg ! ! write (*,*) 'sds_name = ', trim(sds_name) - ! ! dbg ! ! write (*,*) 'rank, data_type, num_attrs = ', rank, data_type, num_attrs - ! ! dbg ! ! write (*,*) 'dimsizes = ', dimsizes - ! ######################################################### - + end do + + ! normalize + + do kk=1,N_catf + if (N_obs_in_tile(kk)>0) then - select case (nn) + tmp_real = real(N_obs_in_tile(kk)) + + JPSS_obs(kk) = JPSS_obs(kk)/tmp_real + JPSS_lon(kk) = JPSS_lon(kk)/tmp_real + JPSS_lat(kk) = JPSS_lat(kk)/tmp_real - case (1); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Cover = ichar(tmp_char1,2) - case (2); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Clear_Index = ichar(tmp_char1,2) - case (3); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Spatial_QA = ichar(tmp_char1,2) + else if (N_obs_in_tile(kk)==0) then - case default; call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown field') - - end select - - if (status/=0) then + JPSS_obs(kk) = this_obs_param%nodata + JPSS_lon(kk) = this_obs_param%nodata + JPSS_lat(kk) = this_obs_param%nodata - err_msg = 'error reading data from hdf file: ' // trim(fname) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - end if - - status = sfendacc(sds_id) ! terminate access to SDS (field) - end do - status = sfend(sd_id) ! close hdf file and SD interface - - - ! ################################################################################# - ! ! dbg ! ! write (*,*) 'Snow_Cover(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Snow_Cover(1:10,1:5) - ! ! dbg ! ! write (*,*) 'Clear_Index(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Clear_Index(1:10,1:5) - ! ! dbg ! ! write (*,*) 'Snow_Spatial_QA(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Snow_Spatial_QA(1:10,1:5) - - ! ! dbg ! ! !if ( (lon_min>-138) .and. (lon_min<-134) ) then - ! ! dbg ! ! if (.false.) then - ! ! dbg ! ! do jj=1,N_lat - ! ! dbg ! ! write(997) Snow_Cover( jj,:) - ! ! dbg ! ! write(998) Clear_Index( jj,:) - ! ! dbg ! ! write(999) Snow_Spatial_QA(jj,:) - ! ! dbg ! ! end do - ! ! dbg ! ! write (*,*) 'stopping after file dump ' - ! ! dbg ! ! stop - ! ! dbg ! ! end if - ! ################################################################################# - - - - ! check range (make sure uint8 from hdf 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(Snow_Spatial_QA < uint8_min) .or. & - any(Snow_Spatial_QA > uint8_max) ) then + if (any(N_obs_in_tile>0)) then - err_msg = 'unexpected range in data from hdf file' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + found_obs = .true. + + else + + found_obs = .false. end if - ! ------------------------------------- + deallocate(tmp_tile_num) + + deallocate(CMG_obs) + deallocate(CMG_lon) + deallocate(CMG_lat) + + ! to avoid double-counting of JPSS CMG obs, remove obs for tiles with center-of-mass longitude + ! falling outside the longitude band associated with assimilation window ! - ! apply QC and put SCF obs into output array + ! the band excludes lon_end, so that a tile with com_lon exactly on the boundary between two + ! assimilation windows gets its obs only once (e.g., EASEv2 M36 tiles at +-45 and +-135 deg + ! for windows centered at 0z, 3z, ...) - 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 + if (lon_end < lon_beg) then + + ! need only one longitude band (keep obs when lon_end qc_clear_index_min ) .and. & ! sufficiently clear sky (2) - (Snow_Spatial_QA(ii,jj) <= qc_snow_spatial_max) ! keep "best", "good", or "OK" quality (3) + if ( (tile_coord_f(kk)%com_lon<=lon_end) .or. (tile_coord_f(kk)%com_lon>lon_beg) ) & + JPSS_obs(kk) = this_obs_param%nodata - ! (1) excludes "lake ice", "night", "inland water", "ocean", "cloud obscured water", "data not mapped", "fill" - ! (2) clear_index>100 already removed via qc_snow_cover_max - ! (3) excludes Antarctica + end do + + else + + ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_endlon_beg) .and. (tile_coord_f(kk)%com_lon<=lon_end) ) & + JPSS_obs(kk) = this_obs_param%nodata end do - end do - - N_good_data = kk - - if (logit) write (logunit,*) 'N_good_data = ', N_good_data - - deallocate(lat_c) - deallocate(lon_c) + + end if - deallocate(lat_ind) - deallocate(lon_ind) - deallocate(Snow_Cover ) - deallocate(Clear_Index ) - deallocate(Snow_Spatial_QA) + end subroutine read_obs_JPSS_SCF - end subroutine read_MODIS_SCF_hdf - -! ***************************************************************** + ! ***************************************************************** subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & N_good_data, CMG_lon, CMG_lat, CMG_SCF, granule_id ) @@ -8371,6 +8371,7 @@ end subroutine read_JPSS_SCF_hdf ! ***************************************************************** + 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, & diff --git a/GEOSlandassim_GridComp/io_hdf5.F90 b/GEOSlandassim_GridComp/io_hdf5.F90 index 247dde24..39b1ea13 100644 --- a/GEOSlandassim_GridComp/io_hdf5.F90 +++ b/GEOSlandassim_GridComp/io_hdf5.F90 @@ -50,7 +50,7 @@ module io_hdf5 procedure, public :: openFile procedure, public :: closeFile procedure, public :: queryDataset - generic, public :: readDataset => readDataset1DReal, readDataset1DReal8, readDataset1DInt, readDataset1DChar24, readDataset2DReal, readDataset2DInt + generic, public :: readDataset => readDataset1DReal, readDataset1DReal8, readDataset1DInt, readDataset1DChar24, readDataset2DReal, readDataset2DInt generic, public :: readAttribute => readAttributeChar ! private procedure, private :: readDataset1DReal From 5ddd814270d3f1085403e19c49de59f083c867cf Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Mon, 23 Nov 2026 10:40:56 -0500 Subject: [PATCH 81/90] Revert "moved entire subroutine read_JPSS_SCF() within file to get cleaner diff view on GitHub; minimal white-space changes (clsm_ensupd_read_obs.F90, io_hdf5.F90)" This reverts commit 982e1c80a87a27eb9ea44719caf498096f17bcac. --- .../clsm_ensupd_read_obs.F90 | 1647 ++++++++--------- GEOSlandassim_GridComp/io_hdf5.F90 | 2 +- 2 files changed, 824 insertions(+), 825 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 1bbfadd8..b8e059d3 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6976,1067 +6976,1067 @@ subroutine read_obs_MODIS_SCF( & end subroutine read_obs_MODIS_SCF - ! **************** + ! ******************************************************************************************************* - subroutine localtime2longitude( date_time, local_hour, longitude, delta_day ) - - ! for date_time in UTC, find the longitude where the local time is local_hour; - ! delta_day is the offset between the UTC calendar day and the calendar - ! day at the returned longitude - ! when UTC and local time are exactly 12 hours offset, always return longitude=+180. - ! - ! - reichle, 19 Oct 2023 + subroutine read_obs_JPSS_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, JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat ) - implicit none - - type(date_time_type), intent(in) :: date_time ! current date and time in UTC + ! read JPSS snow cover observations on the 0.05-degree climate + ! modeling grid (CMG) + ! + ! JPSS1/NOAA-20: VJ110C1 (launched 2017) + ! JPSS2/NOAA-21: VJ210C1 (launched 2022) + ! S-NPP : VNP10C1 (launched 2011, decommissioned 2026) + ! + ! + ! For now, assume that VIIRS/JPSS 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 + ! + ! lcandre2, 26 Oct 2026 + ! + ! amfox, 5 Nov 2026 - obs on tiles at a window boundary are assimilated only once (as for MODIS); + ! original file names ("granule_id") are written to the obslog (as for MODIS) + ! + ! ------------------------------------------------------------------------------ - real, intent(in) :: local_hour ! fractional local hour (e.g., 1:30pm is 13.5); range=[0,24) + implicit none - real, intent(out) :: longitude ! [degree] -180 < longitude <= 180 + ! inputs - integer, intent(out) :: delta_day ! [days] -1 <= delta_day <= 1 - - ! ---------------------------------------------- - - real :: UTC_hour, time_diff - - character(len=*), parameter :: Iam = 'localtime2longitude' - character(len=400) :: err_msg - - ! --------------------------------------------------------------------------- - - ! make sure local_hour is within range: 0 <= local_hour < 24 - - if ( (local_hour < 0.) .or. (local_hour >= 24.) ) then - - err_msg = 'input local_hour falls outside allowed range of 0:24' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - ! initialize - - delta_day = 0 - - ! determine fractional UTC hour and time difference with local_hour - - UTC_hour = ( date_time%hour*3600 + date_time%min*60 + date_time%sec )/3600. ! 0 <= UTC_hour < 24 + type(date_time_type), intent(in) :: date_time - time_diff = local_hour - UTC_hour + integer, intent(in) :: dtstep_assim ! [seconds] + integer, intent(in) :: N_catf - ! enforce -12. < time_diff <= 12. and determine associated date difference, if any + type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - if (time_diff <= -12.) then - - delta_day = 1 + type(grid_def_type), intent(in) :: obs2tile_grid_f - time_diff = time_diff + 24. - - elseif (time_diff > 12.) then - - delta_day = -1 + type(ESMF_Grid), intent(in) :: tile_grid_g_ESMF ! needed for obs-to-tile mapping in cube-sphere tile space - time_diff = time_diff - 24. - - end if + integer, dimension(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: N_tile_in_cell_ij - ! determine longitude + integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input - longitude = time_diff/24.*360. - - end subroutine localtime2longitude + type(obs_param_type), intent(in) :: this_obs_param - ! ***************************************************************** - - subroutine get_MODIS_granule_id( sd_id, granule_id ) - - ! get original file name (incl. production time stamp) of MODIS hdf4 file from - ! LOCALGRANULEID in global attribute "CoreMetadata.0" (ODL text), e.g., - ! - ! OBJECT = LOCALGRANULEID - ! NUM_VAL = 1 - ! VALUE = "MYD10C1.A2020015.061.2020326041737.hdf" - ! END_OBJECT = LOCALGRANULEID - ! - ! returns blank if not found - ! - ! amfox, 3 Nov 2026 - ! - ! ------------------------------------------------------------------------------------------------- - - implicit none + logical, intent(in) :: write_obslog - integer, intent(in) :: sd_id ! from sfstart() + ! output - character(*), intent(out) :: granule_id + logical, intent(out) :: found_obs - ! local variables + real, dimension(N_catf), intent(out) :: JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat - integer :: attr_index, data_type, attr_count, status, i1, i2, i3, i4 + ! ------------------------------------------------------------------------ + + ! locals - character(256) :: attr_name + integer, parameter :: dtstep_assim_max = 21600 ! [seconds] avoid assim window spanning >=180 deg lon - character(:), allocatable :: core_metadata + real, parameter :: CMG_dlon = 0.05 ! [degrees] longitude spacing of JPSS CMG grid + real, parameter :: CMG_dlat = 0.05 ! [degrees] latitude spacing of JPSS CMG grid + + real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of JPSS CMG grid + real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of JPSS CMG grid + + character( 7) :: JPSS_product_ID + + character(4) :: YYYY + character(3) :: DDD ! day of year + + character( 12) :: tmpstr12 + character( 16) :: YYYYMMDD_HHMMSSz + character( 80) :: tmpstr80 - ! ------------------------------------------------- + character(400) :: fname + character(256) :: granule_id - granule_id = '' + character(400), dimension(2) :: fname_list - attr_index = sffattr( sd_id, 'CoreMetadata.0' ) + real :: overpass_hour, tmp_delta, tmp_real, max_delta_lon + + integer :: N_files, N_lon, N_lat, N_tmp, nn, kk, ind, tmp_ind + integer :: N_CMG_obs, N_good_data, tmp_ind_start, tmp_ind_last - if (attr_index < 0) return + type(date_time_type) :: date_time_beg, date_time_end + type(date_time_type) :: date_time_beg_JPSS, date_time_end_JPSS + type(date_time_type) :: date_time_obs_beg - status = sfgainfo( sd_id, attr_index, attr_name, data_type, attr_count ) + real :: lon_beg, lon_end + real :: lon_beg_JPSS, lon_end_JPSS + + integer :: delta_day_beg, delta_day_end + integer :: delta_day_beg_JPSS, delta_day_end_JPSS - if (status < 0) return + real :: lat_min, lat_max - ! CoreMetadata.0 is a character attribute; return blank for any other type - ! (sfrcatt() writes attr_count values of data_type, so the buffer below would be too small) + real, dimension(2) :: lon_min_vec, lon_max_vec - if ((data_type /= DFNT_CHAR8 .and. data_type /= DFNT_UCHAR8) .or. attr_count <= 0) return + integer, dimension(2) :: N_lon_vec, year_vec, dofyr_vec, start_ind, last_ind, N_good_data_list - allocate(character(attr_count) :: core_metadata) + real, dimension(:), allocatable :: CMG_obs, CMG_lon, CMG_lat - status = sfrcatt( sd_id, attr_index, core_metadata ) + integer, dimension(:), allocatable :: tmp_tile_num - if (status >= 0) then + integer, dimension(N_catf) :: N_obs_in_tile - ! search only within the LOCALGRANULEID object, i.e., from "LOCALGRANULEID" to the next - ! "END_OBJECT"; VALUE is the text between the first two double quotes there + character(len=*), parameter :: Iam = 'read_obs_JPSS_SCF' + character(len=400) :: err_msg - i2 = 0 - i3 = 0 - i4 = 0 + ! ------------------------------------------------------------------------------------ + ! + ! initialize + + found_obs = .false. + + ! determine operating time range of sensor - i1 = index( core_metadata, 'LOCALGRANULEID' ) + if (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 + else + err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + end if - if (i1 > 0) i4 = index( core_metadata(i1:), 'END_OBJECT' ) ! end of object (relative to i1) - if (i4 > 0) i2 = index( core_metadata(i1:i1+i4-2), '"' ) ! opening quote (relative to i1) - if (i2 > 0) i3 = index( core_metadata(i1+i2:i1+i4-2), '"' ) ! closing quote (relative to i1+i2) + ! return if date_time falls outside operating time range - if (i3 > 1) granule_id = core_metadata(i1+i2:i1+i2+i3-2) + if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return - end if + ! ---------------------------------------------------------------------------------- + ! + ! restrict assimilation time step to max allowed - deallocate(core_metadata) + if (dtstep_assim > dtstep_assim_max) then + + err_msg = 'dtstep_assim exceeds max allowed' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if - end subroutine get_MODIS_granule_id + ! identify JPSS product and overpass hour + ! (see https://vlab.noaa.gov/web/towr-s/satellite-operations-updates) - ! ***************************************************************** + JPSS_product_ID = this_obs_param%name(1:7) + + select case (JPSS_product_ID) + + case('VJ110C1'); overpass_hour = 13.5 ! [hours] JPSS1: 13:30 local time + + case('VJ210C1'); overpass_hour = 13.5 ! [hours] JPSS2: 13:30 local time - subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & - N_good_data, CMG_lon, CMG_lat, CMG_SCF, granule_id ) + case('VNP10C1'); overpass_hour = 13.5 ! [hours] S-NPP: 13:30 local time + + end select - ! read snow cover area fraction (SCF) obs from daily MODIS Terra or Aqua M?D10C1, version 6.1 - ! - Terra: https://nsidc.org/data/mod10c1/versions/61 - ! - Aqua: https://nsidc.org/data/myd10c1/versions/61 - ! - daily data with spatial resolution of 0.05 deg on MODIS climate modeling grid (CMG) - ! - Terra: missing days 2016 d. 50-58 - ! - data are read for the requested lat/lon range - ! - apply QC - ! - ! reichle, 20 Oct 2023 - ! - ! 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() - ! - amfox, reichle, 4 Nov 2026 - ! - ! ------------------------------------------------------------------------------------------------- - implicit none + ! determine beginning and end of assimilation window - character(*), intent(in) :: fname ! MODIS file name with full path + date_time_beg = date_time + date_time_end = date_time - real, intent(in) :: lon_min, lon_max ! -180 <= lon_* <= 180 - real, intent(in) :: lat_min, lat_max ! -90 <= lat_* <= 90 + call augment_date_time( -dtstep_assim/2, date_time_beg ) + call augment_date_time( dtstep_assim/2, date_time_end ) - 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 MODIS file name (incl. production time stamp) - - ! ------------------------------------------------- - - ! local parameters - - ! ll/ur_lon/lat simply indicate the extent of the MODIS CMG grid + ! determine longitude band associated with assimilation window and local overpass hour ! - ! index increases from (-180,90) to (180,-90) (southward and eastward) - - integer, parameter :: CMG_N_lon = 7200 - integer, parameter :: CMG_N_lat = 3600 + ! observations will be returned only for tiles with lon_end < tile_coord_f%com_lon <= lon_beg - real, parameter :: CMG_ll_lon = -180. - real, parameter :: CMG_ll_lat = -90. + call localtime2longitude( date_time_beg, overpass_hour, lon_beg, delta_day_beg ) + call localtime2longitude( date_time_end, overpass_hour, lon_end, delta_day_end ) - 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(22), dimension(N_fields), parameter :: field_names = (/ & - 'Day_CMG_Snow_Cover ', & ! 1 - 'Day_CMG_Clear_Index ', & ! 2 - 'Snow_Spatial_QA '/) ! 3 - - ! 1234567890123456789012 - ! 1 2 - integer, parameter :: SCF_nodata = -9999. - - integer(int16), parameter :: qc_snow_cover_max = 100 ! exclude lake ice, night, inland water, ocean, etc - integer(int16), parameter :: qc_clear_index_min = 20 ! ensure sufficiently clear conditions - integer(int16), parameter :: qc_snow_spatial_max = 2 ! data quality (0=best, 1=good, 2=OK, 3=poor, 4=other) + ! determine (rough) longitude band for which JPSS obs need to be read + ! + ! --> because tiles have a non-zero extent, need to read JPSS 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_f%max_lon - tile_coord_f%min_lon ) - integer, parameter :: DFACC_READ = 1 ! from hdf.inc + tmp_delta = 3.*maxval( tile_coord_f(1:N_catf)%max_lon - tile_coord_f(1:N_catf)%min_lon ) ! [degrees] - integer, parameter :: uint8_min = 0 - integer, parameter :: uint8_max = 255 - - - ! local variables + tmp_delta = tmp_delta/360.*86400. ! [seconds] - 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 + date_time_beg_JPSS = date_time_beg + date_time_end_JPSS = date_time_end - integer, dimension(2) :: start, edge, stride, last, dimsizes + call augment_date_time( -nint(tmp_delta), date_time_beg_JPSS ) + call augment_date_time( nint(tmp_delta), date_time_end_JPSS ) + + call localtime2longitude( date_time_beg_JPSS, overpass_hour, lon_beg_JPSS, delta_day_beg_JPSS ) + call localtime2longitude( date_time_end_JPSS, overpass_hour, lon_end_JPSS, delta_day_end_JPSS ) - logical :: file_exists, keep_data + ! adjust date_time_*_JPSS to reflect calendar date at lon_*_JPSS - integer :: status, sd_id, sds_id, sds_index + call augment_date_time( delta_day_beg_JPSS*86400, date_time_beg_JPSS ) + call augment_date_time( delta_day_end_JPSS*86400, date_time_end_JPSS ) + + ! put together arguments for call(s) to read_JPSS_SCF_hdf() - character(64) :: sds_name - - integer :: rank, data_type, num_attrs + lon_min_vec = MAPL_UNDEF + lon_max_vec = MAPL_UNDEF - integer(int16), dimension(:,:), allocatable :: Snow_Cover - integer(int16), dimension(:,:), allocatable :: Clear_Index - integer(int16), dimension(:,:), allocatable :: Snow_Spatial_QA - - character(kind=c_char, len=1), dimension(:,:), allocatable :: tmp_char1 + year_vec = -9999 + dofyr_vec = -9999 - character(len=*), parameter :: Iam = 'read_MODIS_SCF_hdf' - character(len=400) :: err_msg - - ! ------------------------------------------------------------------------- - ! - ! make sure file exists - - granule_id = '' + N_lon_vec = 0 - inquire( file=trim(fname), exist=file_exists ) - - if (.not. file_exists ) then + if (lon_end_JPSS < lon_beg_JPSS) then - if (logit) then - write (logunit,'(400A)') trim(Iam), ': cannot find file ', trim(fname) - write (logunit,* ) 'not reading MODIS SCF obs' + if ( date_time_end_JPSS%dofyr == date_time_beg_JPSS%dofyr ) then + + ! need only one daily JPSS file and longitude band + + N_files = 1 + + lon_min_vec(1) = lon_end_JPSS + lon_max_vec(1) = lon_beg_JPSS + + year_vec( 1) = date_time_beg_JPSS%year + dofyr_vec( 1) = date_time_beg_JPSS%dofyr + + else + + ! this should never happen for dtstep_assim_max=21600 and overpass_hour of 13:30 + + write (logunit,*) 'overpass_hour = ', overpass_hour + 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_JPSS = ', date_time_beg_JPSS + write (logunit,*) 'date_time_end_JPSS = ', date_time_end_JPSS + write (logunit,*) 'lon_beg = ', lon_beg + write (logunit,*) 'lon_end = ', lon_end + write (logunit,*) 'lon_beg_JPSS = ', lon_beg_JPSS + write (logunit,*) 'lon_end_JPSS = ', lon_end_JPSS + + err_msg = 'encountered unexpected condition for longitude band!!!' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + end if - - N_good_data = 0 - - return + + else + + ! longitude band wraps around dateline, two daily JPSS files are needed + ! (this could also occur if lon_*_JPSS=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_JPSS + 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_JPSS%year + dofyr_vec( 1) = date_time_end_JPSS%dofyr + + lon_min_vec(2) = -180. + lon_max_vec(2) = lon_beg_JPSS + + year_vec( 2) = date_time_beg_JPSS%year + dofyr_vec( 2) = date_time_beg_JPSS%dofyr end if - ! ensure lon_* and lat_* inputs are within range + ! verify that longitude bands do not exceed max expected expected width + ! (add 0.1 degree of wiggle room) + max_delta_lon = real(dtstep_assim_max + 2*nint(tmp_delta))/86400.*360. + 0.1 ! [degree] - 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 + do nn=1,N_files + + if ( lon_max_vec(nn) - lon_min_vec(nn) > max_delta_lon ) then + + err_msg = 'longitude band too wide' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if - err_msg = 'lat/lon min/max inputs out of range' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - ! determine MODIS CMG array indices for requested lat/lon_min/max range - - ! MODIS CMG hdf files: - ! - lon-by-lat (NOTE: The metadata "s.Vgroup(1).Vgroup(1).SDS(1).Dims.Size" returned - ! by Matlab's hdfinfo() confusingly suggests that CMG files are - ! lat-by-lon, which is not the case!) - ! - index values increase eastward and southward + end do - 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 - - edge(1) = N_lon - edge(2) = N_lat - - stride(1) = 1 - stride(2) = 1 - + ! determine latitude band covered by domain (no need to read obs outside domain) - ! ! dbg ! ! write (*,*) '###############################################################################' - ! ! dbg ! ! write (*,*) Iam // '():' - ! ! dbg ! ! write (*,*) 'size(CMG_SCF), N_lon, N_lat = ', size(CMG_SCF), N_lon, N_lat - ! ! dbg ! ! write (*,*) 'lon_min, lon_max = ', lon_min, lon_max - ! ! dbg ! ! write (*,*) 'lat_min, lat_max = ', lat_min, lat_max - ! ! dbg ! ! write (*,*) 'start [lon, lat] = ', start - ! ! dbg ! ! write (*,*) 'last [lon, lat] = ', last - ! ! dbg ! ! write (*,*) 'edge [lon, lat] = ', edge - ! ! dbg ! ! write (*,*) '###############################################################################' - + 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 ) - ! checks array dimensions + start_ind(1) = (CMG_ur_lat - lat_max )/CMG_dlat + last_ind(1) = (CMG_ur_lat - lat_min )/CMG_dlat + + N_lat = last_ind(1) - start_ind(1) + 1 - 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 + start_ind(1:N_files) = (lon_min_vec(1:N_files) - CMG_ll_lon)/CMG_dlon + last_ind( 1:N_files) = (lon_max_vec(1:N_files) - CMG_ll_lon)/CMG_dlon - ! check array bounds + N_lon_vec(1:N_files) = last_ind(1:N_files) - start_ind(1:N_files) + 1 - 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 + N_lon = sum( N_lon_vec(1:N_files) ) - if (logit) then - write (logunit,'(400A)') trim(Iam), '(): reading MODIS 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 for JPSS CMG data (max size that could possibly be needed for obs from both files) + N_tmp = N_lon*N_lat - ! 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(Snow_Spatial_QA(N_lon,N_lat)) - - allocate(tmp_char1( N_lon,N_lat)) - - ! -------------------------- + allocate( CMG_obs(N_tmp) ) + allocate( CMG_lon(N_tmp) ) + allocate( CMG_lat(N_tmp) ) - ! 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 - - ! -------------------------- + ! read VIIRS SCF obs + ! + ! - files must be renamed (production time stamp removed), as for MODIS SCF obs: + ! 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 + ! - ! open hdf file (read-only) and initialize SD interface + N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_JPSS_SCF_hdf() - sd_id = sfstart(trim(fname), DFACC_READ) - - if (sd_id<0) then - - err_msg = 'cannot sfstart (open) file: ' // trim(fname) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + do nn=1,N_files ! loop through longitude bands (i.e., files) - 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 + ! determine JPSS 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:23) + + ! 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_JPSS_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 ) - call get_MODIS_granule_id( sd_id, granule_id ) + N_CMG_obs = N_CMG_obs + N_good_data + + ! record number of good obs and file name for obslog - ! read data + N_good_data_list(nn) = N_good_data - do nn=1,N_fields - - sds_index = sfn2index( sd_id, trim(field_names(nn)) ) - sds_id = sfselect( sd_id, sds_index ) + if (len_trim(granule_id)>0) then + tmp_ind = index(trim(fname), '/', back=.true.) ! position of last "/" - status = sfginfo( sds_id, sds_name, rank, dimsizes, data_type, num_attrs ) - - if ( (dimsizes(1)/=CMG_N_lon) .or. (dimsizes(2)/=CMG_N_lat) ) then + if (tmp_ind>0) then + fname_list(nn) = fname(1:tmp_ind) // trim(granule_id) ! replace file name with granule id + else + fname_list(nn) = trim(granule_id) ! fname was only file name (no path) + end if - err_msg = 'dimensions in hdf file doe not match CMG_N_lon and/or CMG_N_lat' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - + else - ! ######################################################### - ! ! dbg ! ! write (*,*) 'sds_name = ', trim(sds_name) - ! ! dbg ! ! write (*,*) 'rank, data_type, num_attrs = ', rank, data_type, num_attrs - ! ! dbg ! ! write (*,*) 'dimsizes = ', dimsizes - ! ######################################################### + fname_list( nn) = fname ! use fname b/c granule_id is empty - - select case (nn) - - case (1); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Cover = ichar(tmp_char1,2) - case (2); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Clear_Index = ichar(tmp_char1,2) - case (3); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Spatial_QA = ichar(tmp_char1,2) - - case default; call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown field') - - end select - - if (status/=0) then - - err_msg = 'error reading data from hdf file: ' // trim(fname) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - end if - status = sfendacc(sds_id) ! terminate access to SDS (field) - end do - status = sfend(sd_id) ! close hdf file and SD interface + ! write "obslog" file + if (write_obslog) then - ! ################################################################################# - ! ! dbg ! ! write (*,*) 'Snow_Cover(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Snow_Cover(1:10,1:5) - ! ! dbg ! ! write (*,*) 'Clear_Index(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Clear_Index(1:10,1:5) - ! ! dbg ! ! write (*,*) 'Snow_Spatial_QA(1:10,1:5)=' - ! ! dbg ! ! write (*,*) Snow_Spatial_QA(1:10,1:5) - - ! ! dbg ! ! !if ( (lon_min>-138) .and. (lon_min<-134) ) then - ! ! dbg ! ! if (.false.) then - ! ! dbg ! ! do jj=1,N_lat - ! ! dbg ! ! write(997) Snow_Cover( jj,:) - ! ! dbg ! ! write(998) Clear_Index( jj,:) - ! ! dbg ! ! write(999) Snow_Spatial_QA(jj,:) - ! ! dbg ! ! end do - ! ! dbg ! ! write (*,*) 'stopping after file dump ' - ! ! dbg ! ! stop - ! ! dbg ! ! end if - ! ################################################################################# + YYYYMMDD_HHMMSSz = date_time2string(date_time) + tmpstr80 = trim(Iam) // '()' ! name of this subroutine + do nn=1,N_files - ! check range (make sure uint8 from hdf file is correctly translated into Fortran integer) + write (tmpstr12,'(i12)') N_good_data_list(nn) ! convert integer to string + + call add_to_obslog( YYYYMMDD_HHMMSSz, this_obs_param%descr, tmpstr80, & + tmpstr12, fname_list(nn) ) + + end do - 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(Snow_Spatial_QA < uint8_min) .or. & - any(Snow_Spatial_QA > uint8_max) ) then - - err_msg = 'unexpected range in data from hdf file' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - end if + + ! return if no JPSS obs were found (found_obs=.false. per initialization above) + + if (N_CMG_obs==0) return + + + ! map to tile space - ! ------------------------------------- - ! - ! apply QC and put SCF obs into output array + allocate(tmp_tile_num(N_CMG_obs)) - CMG_lon = SCF_nodata ! initialize - CMG_lat = SCF_nodata ! initialize - CMG_SCF = SCF_nodata ! initialize + 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 ) + + + std_JPSS_obs = this_obs_param%errstd + + JPSS_obs = 0. + JPSS_lon = 0. + JPSS_lat = 0. - kk = 0 ! initialize counter for "good" data + N_obs_in_tile = 0 + + do kk=1,N_CMG_obs + + ind = tmp_tile_num(kk) ! 1<=tmp_tile_num<=N_catf (unless nodata) + + if (ind>0) then ! this condition eliminates obs outside domain + + JPSS_obs( ind) = JPSS_obs( ind) + CMG_obs(kk) + JPSS_lon( ind) = JPSS_lon( ind) + CMG_lon(kk) + JPSS_lat( ind) = JPSS_lat( ind) + CMG_lat(kk) - do ii=1,N_lon - do jj=1,N_lat + N_obs_in_tile(ind) = N_obs_in_tile(ind) + 1 - ! note: Snow_Cover >= 0 per range check above, no need to check for minimum + end if + + end do + + ! normalize + + do kk=1,N_catf + if (N_obs_in_tile(kk)>0) then - 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) - (Snow_Spatial_QA(ii,jj) <= qc_snow_spatial_max) ! keep "best", "good", or "OK" quality (3) + tmp_real = real(N_obs_in_tile(kk)) + + JPSS_obs(kk) = JPSS_obs(kk)/tmp_real + JPSS_lon(kk) = JPSS_lon(kk)/tmp_real + JPSS_lat(kk) = JPSS_lat(kk)/tmp_real - ! (1) excludes "lake ice", "night", "inland water", "ocean", "cloud obscured water", "data not mapped", "fill" - ! (2) clear_index>100 already removed via qc_snow_cover_max - ! (3) excludes Antarctica + else if (N_obs_in_tile(kk)==0) then - if (keep_data) then - - kk = kk + 1 - - ! raw SCF value is for clear portion of grid cell only, need to normalize with Clear_Index - - CMG_SCF(kk) = real(Snow_Cover(ii,jj))/real(Clear_Index(ii,jj)) - - CMG_lon(kk) = lon_c(ii) - CMG_lat(kk) = lat_c(jj) - - end if + JPSS_obs(kk) = this_obs_param%nodata + JPSS_lon(kk) = this_obs_param%nodata + JPSS_lat(kk) = this_obs_param%nodata - end do + end if end do - N_good_data = kk - - if (logit) write (logunit,*) 'N_good_data = ', N_good_data - - deallocate(lat_c) - deallocate(lon_c) + if (any(N_obs_in_tile>0)) then + + found_obs = .true. + + else + + found_obs = .false. + + end if - deallocate(lat_ind) - deallocate(lon_ind) + deallocate(tmp_tile_num) + + deallocate(CMG_obs) + deallocate(CMG_lon) + deallocate(CMG_lat) - deallocate(Snow_Cover ) - deallocate(Clear_Index ) - deallocate(Snow_Spatial_QA) + ! to avoid double-counting of JPSS 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 + ! assimilation windows gets its obs only once (e.g., EASEv2 M36 tiles at +-45 and +-135 deg + ! for windows centered at 0z, 3z, ...) + + if (lon_end < lon_beg) then + + ! need only one longitude band (keep obs when lon_endlon_beg) ) & + JPSS_obs(kk) = this_obs_param%nodata + + end do + + else + + ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_endlon_beg) .and. (tile_coord_f(kk)%com_lon<=lon_end) ) & + JPSS_obs(kk) = this_obs_param%nodata + + end do + + end if + - end subroutine read_MODIS_SCF_hdf - - ! ******************************************************************************************************* + end subroutine read_obs_JPSS_SCF - subroutine read_obs_JPSS_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, JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat ) - - ! read JPSS snow cover observations on the 0.05-degree climate - ! modeling grid (CMG) - ! - ! JPSS1/NOAA-20: VJ110C1 (launched 2017) - ! JPSS2/NOAA-21: VJ210C1 (launched 2022) - ! S-NPP : VNP10C1 (launched 2011, decommissioned 2026) - ! - ! - ! For now, assume that VIIRS/JPSS 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 - ! - ! lcandre2, 26 Oct 2026 - ! - ! amfox, 5 Nov 2026 - obs on tiles at a window boundary are assimilated only once (as for MODIS); - ! original file names ("granule_id") are written to the obslog (as for MODIS) - ! - ! ------------------------------------------------------------------------------ + ! ******************************************************************************************************* + + subroutine localtime2longitude( date_time, local_hour, longitude, delta_day ) + ! for date_time in UTC, find the longitude where the local time is local_hour; + ! delta_day is the offset between the UTC calendar day and the calendar + ! day at the returned longitude + ! when UTC and local time are exactly 12 hours offset, always return longitude=+180. + ! + ! - reichle, 19 Oct 2023 + implicit none + + type(date_time_type), intent(in) :: date_time ! current date and time in UTC - ! inputs + real, intent(in) :: local_hour ! fractional local hour (e.g., 1:30pm is 13.5); range=[0,24) - type(date_time_type), intent(in) :: date_time + real, intent(out) :: longitude ! [degree] -180 < longitude <= 180 + + integer, intent(out) :: delta_day ! [days] -1 <= delta_day <= 1 - integer, intent(in) :: dtstep_assim ! [seconds] - integer, intent(in) :: N_catf + ! ---------------------------------------------- - type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input + real :: UTC_hour, time_diff - 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(obs2tile_grid_f%N_lon,obs2tile_grid_f%N_lat), intent(in) :: N_tile_in_cell_ij + character(len=*), parameter :: Iam = 'localtime2longitude' + character(len=400) :: err_msg - integer, dimension(:,:,:), pointer :: tile_num_in_cell_ij ! input + ! --------------------------------------------------------------------------- - type(obs_param_type), intent(in) :: this_obs_param + ! make sure local_hour is within range: 0 <= local_hour < 24 - logical, intent(in) :: write_obslog - - ! output - - logical, intent(out) :: found_obs - - real, dimension(N_catf), intent(out) :: JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat - - ! ------------------------------------------------------------------------ + if ( (local_hour < 0.) .or. (local_hour >= 24.) ) then + + err_msg = 'input local_hour falls outside allowed range of 0:24' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if - ! locals + ! initialize + + delta_day = 0 + + ! determine fractional UTC hour and time difference with local_hour + + UTC_hour = ( date_time%hour*3600 + date_time%min*60 + date_time%sec )/3600. ! 0 <= UTC_hour < 24 + + time_diff = local_hour - UTC_hour + + ! enforce -12. < time_diff <= 12. and determine associated date difference, if any + + if (time_diff <= -12.) then + + delta_day = 1 - integer, parameter :: dtstep_assim_max = 21600 ! [seconds] avoid assim window spanning >=180 deg lon + time_diff = time_diff + 24. + + elseif (time_diff > 12.) then + + delta_day = -1 - real, parameter :: CMG_dlon = 0.05 ! [degrees] longitude spacing of JPSS CMG grid - real, parameter :: CMG_dlat = 0.05 ! [degrees] latitude spacing of JPSS CMG grid - - real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of JPSS CMG grid - real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of JPSS CMG grid + time_diff = time_diff - 24. + + end if - character( 7) :: JPSS_product_ID + ! determine longitude - character(4) :: YYYY - character(3) :: DDD ! day of year + longitude = time_diff/24.*360. + + end subroutine localtime2longitude - character( 12) :: tmpstr12 - character( 16) :: YYYYMMDD_HHMMSSz - character( 80) :: tmpstr80 + ! ***************************************************************** + + subroutine get_MODIS_granule_id( sd_id, granule_id ) - character(400) :: fname - character(256) :: granule_id + ! get original file name (incl. production time stamp) of MODIS hdf4 file from + ! LOCALGRANULEID in global attribute "CoreMetadata.0" (ODL text), e.g., + ! + ! OBJECT = LOCALGRANULEID + ! NUM_VAL = 1 + ! VALUE = "MYD10C1.A2020015.061.2020326041737.hdf" + ! END_OBJECT = LOCALGRANULEID + ! + ! returns blank if not found + ! + ! amfox, 3 Nov 2026 + ! + ! ------------------------------------------------------------------------------------------------- - character(400), dimension(2) :: fname_list + implicit none - real :: overpass_hour, tmp_delta, tmp_real, max_delta_lon - - integer :: N_files, N_lon, N_lat, N_tmp, nn, kk, ind, tmp_ind - integer :: N_CMG_obs, N_good_data, tmp_ind_start, tmp_ind_last + integer, intent(in) :: sd_id ! from sfstart() - type(date_time_type) :: date_time_beg, date_time_end - type(date_time_type) :: date_time_beg_JPSS, date_time_end_JPSS - type(date_time_type) :: date_time_obs_beg + character(*), intent(out) :: granule_id - real :: lon_beg, lon_end - real :: lon_beg_JPSS, lon_end_JPSS - - integer :: delta_day_beg, delta_day_end - integer :: delta_day_beg_JPSS, delta_day_end_JPSS + ! local variables - real :: lat_min, lat_max + integer :: attr_index, data_type, attr_count, status, i1, i2, i3, i4 - real, dimension(2) :: lon_min_vec, lon_max_vec + character(256) :: attr_name - integer, dimension(2) :: N_lon_vec, year_vec, dofyr_vec, start_ind, last_ind, N_good_data_list + character(:), allocatable :: core_metadata - real, dimension(:), allocatable :: CMG_obs, CMG_lon, CMG_lat + ! ------------------------------------------------- - integer, dimension(:), allocatable :: tmp_tile_num + granule_id = '' - integer, dimension(N_catf) :: N_obs_in_tile + attr_index = sffattr( sd_id, 'CoreMetadata.0' ) - character(len=*), parameter :: Iam = 'read_obs_JPSS_SCF' - character(len=400) :: err_msg + if (attr_index < 0) return - ! ------------------------------------------------------------------------------------ - ! - ! initialize - - found_obs = .false. - - ! determine operating time range of sensor + status = sfgainfo( sd_id, attr_index, attr_name, data_type, attr_count ) - if (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 - else - err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - end if + if (status < 0) return - ! return if date_time falls outside operating time range + ! CoreMetadata.0 is a character attribute; return blank for any other type + ! (sfrcatt() writes attr_count values of data_type, so the buffer below would be too small) - if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return + if ((data_type /= DFNT_CHAR8 .and. data_type /= DFNT_UCHAR8) .or. attr_count <= 0) return - ! ---------------------------------------------------------------------------------- - ! - ! restrict assimilation time step to max allowed + allocate(character(attr_count) :: core_metadata) - if (dtstep_assim > dtstep_assim_max) then - - err_msg = 'dtstep_assim exceeds max allowed' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if + status = sfrcatt( sd_id, attr_index, core_metadata ) - ! identify JPSS product and overpass hour - ! (see https://vlab.noaa.gov/web/towr-s/satellite-operations-updates) + if (status >= 0) then - JPSS_product_ID = this_obs_param%name(1:7) - - select case (JPSS_product_ID) - - case('VJ110C1'); overpass_hour = 13.5 ! [hours] JPSS1: 13:30 local time - - case('VJ210C1'); overpass_hour = 13.5 ! [hours] JPSS2: 13:30 local time + ! search only within the LOCALGRANULEID object, i.e., from "LOCALGRANULEID" to the next + ! "END_OBJECT"; VALUE is the text between the first two double quotes there - case('VNP10C1'); overpass_hour = 13.5 ! [hours] S-NPP: 13:30 local time - - end select - - - ! determine beginning and end of assimilation window - - date_time_beg = date_time - date_time_end = date_time + i2 = 0 + i3 = 0 + i4 = 0 + + i1 = index( core_metadata, 'LOCALGRANULEID' ) + + if (i1 > 0) i4 = index( core_metadata(i1:), 'END_OBJECT' ) ! end of object (relative to i1) + if (i4 > 0) i2 = index( core_metadata(i1:i1+i4-2), '"' ) ! opening quote (relative to i1) + if (i2 > 0) i3 = index( core_metadata(i1+i2:i1+i4-2), '"' ) ! closing quote (relative to i1+i2) + + if (i3 > 1) granule_id = core_metadata(i1+i2:i1+i2+i3-2) + + end if + + deallocate(core_metadata) + + end subroutine get_MODIS_granule_id + + ! ***************************************************************** + + subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & + N_good_data, CMG_lon, CMG_lat, CMG_SCF, granule_id ) - call augment_date_time( -dtstep_assim/2, date_time_beg ) - call augment_date_time( dtstep_assim/2, date_time_end ) + ! read snow cover area fraction (SCF) obs from daily MODIS Terra or Aqua M?D10C1, version 6.1 + ! - Terra: https://nsidc.org/data/mod10c1/versions/61 + ! - Aqua: https://nsidc.org/data/myd10c1/versions/61 + ! - daily data with spatial resolution of 0.05 deg on MODIS climate modeling grid (CMG) + ! - Terra: missing days 2016 d. 50-58 + ! - data are read for the requested lat/lon range + ! - apply QC + ! + ! reichle, 20 Oct 2023 + ! + ! 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() + ! - amfox, reichle, 4 Nov 2026 + ! + ! ------------------------------------------------------------------------------------------------- + implicit none - ! determine longitude band associated with assimilation window and local overpass hour - ! - ! observations will be returned only for tiles with lon_end < tile_coord_f%com_lon <= lon_beg + character(*), intent(in) :: fname ! MODIS file name with full path - call localtime2longitude( date_time_beg, overpass_hour, lon_beg, delta_day_beg ) - call localtime2longitude( date_time_end, overpass_hour, lon_end, delta_day_end ) + 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 - ! determine (rough) longitude band for which JPSS obs need to be read - ! - ! --> because tiles have a non-zero extent, need to read JPSS 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_f%max_lon - tile_coord_f%min_lon ) - - tmp_delta = 3.*maxval( tile_coord_f(1:N_catf)%max_lon - tile_coord_f(1:N_catf)%min_lon ) ! [degrees] + character(256), intent(out) :: granule_id ! original MODIS file name (incl. production time stamp) + + ! ------------------------------------------------- + + ! local parameters - tmp_delta = tmp_delta/360.*86400. ! [seconds] + ! ll/ur_lon/lat simply indicate the extent of the MODIS CMG grid + ! + ! index increases from (-180,90) to (180,-90) (southward and eastward) - date_time_beg_JPSS = date_time_beg - date_time_end_JPSS = date_time_end - - call augment_date_time( -nint(tmp_delta), date_time_beg_JPSS ) - call augment_date_time( nint(tmp_delta), date_time_end_JPSS ) - - call localtime2longitude( date_time_beg_JPSS, overpass_hour, lon_beg_JPSS, delta_day_beg_JPSS ) - call localtime2longitude( date_time_end_JPSS, overpass_hour, lon_end_JPSS, delta_day_end_JPSS ) + integer, parameter :: CMG_N_lon = 7200 + integer, parameter :: CMG_N_lat = 3600 - ! adjust date_time_*_JPSS to reflect calendar date at lon_*_JPSS + real, parameter :: CMG_ll_lon = -180. + real, parameter :: CMG_ll_lat = -90. - call augment_date_time( delta_day_beg_JPSS*86400, date_time_beg_JPSS ) - call augment_date_time( delta_day_end_JPSS*86400, date_time_end_JPSS ) - - ! put together arguments for call(s) to read_JPSS_SCF_hdf() + real, parameter :: CMG_ur_lon = 180. + real, parameter :: CMG_ur_lat = 90. - lon_min_vec = MAPL_UNDEF - lon_max_vec = MAPL_UNDEF + real, parameter :: CMG_dlon = 0.05 + real, parameter :: CMG_dlat = 0.05 - year_vec = -9999 - dofyr_vec = -9999 + integer, parameter :: N_fields = 3 - N_lon_vec = 0 + character(22), dimension(N_fields), parameter :: field_names = (/ & + 'Day_CMG_Snow_Cover ', & ! 1 + 'Day_CMG_Clear_Index ', & ! 2 + 'Snow_Spatial_QA '/) ! 3 - if (lon_end_JPSS < lon_beg_JPSS) then - - if ( date_time_end_JPSS%dofyr == date_time_beg_JPSS%dofyr ) then - - ! need only one daily JPSS file and longitude band - - N_files = 1 - - lon_min_vec(1) = lon_end_JPSS - lon_max_vec(1) = lon_beg_JPSS - - year_vec( 1) = date_time_beg_JPSS%year - dofyr_vec( 1) = date_time_beg_JPSS%dofyr - - else - - ! this should never happen for dtstep_assim_max=21600 and overpass_hour of 13:30 - - write (logunit,*) 'overpass_hour = ', overpass_hour - 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_JPSS = ', date_time_beg_JPSS - write (logunit,*) 'date_time_end_JPSS = ', date_time_end_JPSS - write (logunit,*) 'lon_beg = ', lon_beg - write (logunit,*) 'lon_end = ', lon_end - write (logunit,*) 'lon_beg_JPSS = ', lon_beg_JPSS - write (logunit,*) 'lon_end_JPSS = ', lon_end_JPSS - - err_msg = 'encountered unexpected condition for longitude band!!!' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - else - - ! longitude band wraps around dateline, two daily JPSS files are needed - ! (this could also occur if lon_*_JPSS=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_JPSS - 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_JPSS%year - dofyr_vec( 1) = date_time_end_JPSS%dofyr - - lon_min_vec(2) = -180. - lon_max_vec(2) = lon_beg_JPSS - - year_vec( 2) = date_time_beg_JPSS%year - dofyr_vec( 2) = date_time_beg_JPSS%dofyr - - end if + ! 1234567890123456789012 + ! 1 2 + + integer, parameter :: SCF_nodata = -9999. - ! verify that longitude bands do not exceed max expected expected width - ! (add 0.1 degree of wiggle room) - max_delta_lon = real(dtstep_assim_max + 2*nint(tmp_delta))/86400.*360. + 0.1 ! [degree] + integer(int16), parameter :: qc_snow_cover_max = 100 ! exclude lake ice, night, inland water, ocean, etc + integer(int16), parameter :: qc_clear_index_min = 20 ! ensure sufficiently clear conditions + integer(int16), parameter :: qc_snow_spatial_max = 2 ! data quality (0=best, 1=good, 2=OK, 3=poor, 4=other) - do nn=1,N_files - - if ( lon_max_vec(nn) - lon_min_vec(nn) > max_delta_lon ) then - - err_msg = 'longitude band too wide' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - end do + integer, parameter :: DFACC_READ = 1 ! from hdf.inc + + integer, parameter :: uint8_min = 0 + integer, parameter :: uint8_max = 255 - ! determine latitude band covered by domain (no need to read obs outside domain) + ! local variables + + integer :: N_lon, N_lat, N_tmp, ii, jj, kk, nn - lat_min = minval( tile_coord_f(1:N_catf)%min_lat ) - lat_max = maxval( tile_coord_f(1:N_catf)%max_lat ) + real, dimension(:), allocatable :: lon_c + real, dimension(:), allocatable :: lat_c - - ! determine N_lat and N_lon[_vec] (# CMG grid cells in lat/lon bands ) + real, dimension(:), allocatable :: lon_ind + real, dimension(:), allocatable :: lat_ind - start_ind(1) = (CMG_ur_lat - lat_max )/CMG_dlat - last_ind(1) = (CMG_ur_lat - lat_min )/CMG_dlat - - N_lat = last_ind(1) - start_ind(1) + 1 + integer, dimension(2) :: start, edge, stride, last, dimsizes - start_ind(1:N_files) = (lon_min_vec(1:N_files) - CMG_ll_lon)/CMG_dlon - last_ind( 1:N_files) = (lon_max_vec(1:N_files) - CMG_ll_lon)/CMG_dlon + logical :: file_exists, keep_data - N_lon_vec(1:N_files) = last_ind(1:N_files) - start_ind(1:N_files) + 1 + integer :: status, sd_id, sds_id, sds_index - N_lon = sum( N_lon_vec(1:N_files) ) + character(64) :: sds_name - ! allocate arrays for JPSS CMG data (max size that could possibly be needed for obs from both files) - - N_tmp = N_lon*N_lat + integer :: rank, data_type, num_attrs - allocate( CMG_obs(N_tmp) ) - allocate( CMG_lon(N_tmp) ) - allocate( CMG_lat(N_tmp) ) + integer(int16), dimension(:,:), allocatable :: Snow_Cover + integer(int16), dimension(:,:), allocatable :: Clear_Index + integer(int16), dimension(:,:), allocatable :: Snow_Spatial_QA + character(kind=c_char, len=1), dimension(:,:), allocatable :: tmp_char1 + + character(len=*), parameter :: Iam = 'read_MODIS_SCF_hdf' + character(len=400) :: err_msg - ! read VIIRS SCF obs - ! - ! - files must be renamed (production time stamp removed), as for MODIS SCF obs: - ! 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 + ! ------------------------------------------------------------------------- ! + ! make sure file exists - N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_JPSS_SCF_hdf() + granule_id = '' + + inquire( file=trim(fname), exist=file_exists ) - do nn=1,N_files ! loop through longitude bands (i.e., files) - - ! determine JPSS 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:23) - - ! determine sub-array of CMG_* - - tmp_ind_start = N_CMG_obs + 1 - tmp_ind_last = N_CMG_obs + N_lon_vec(nn)*N_lat + if (.not. file_exists ) then - call read_JPSS_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 ) + if (logit) then + write (logunit,'(400A)') trim(Iam), ': cannot find file ', trim(fname) + write (logunit,* ) 'not reading MODIS SCF obs' + end if - N_CMG_obs = N_CMG_obs + N_good_data - - ! record number of good obs and file name for obslog + N_good_data = 0 - N_good_data_list(nn) = N_good_data + 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 - if (len_trim(granule_id)>0) then + err_msg = 'lat/lon min/max inputs out of range' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + + end if + + ! determine MODIS CMG array indices for requested lat/lon_min/max range + + ! MODIS CMG hdf files: + ! - lon-by-lat (NOTE: The metadata "s.Vgroup(1).Vgroup(1).SDS(1).Dims.Size" returned + ! by Matlab's hdfinfo() confusingly suggests that CMG files are + ! lat-by-lon, which is not the case!) + ! - index values increase eastward and southward - tmp_ind = index(trim(fname), '/', back=.true.) ! position of last "/" + 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 + + edge(1) = N_lon + edge(2) = N_lat + + stride(1) = 1 + stride(2) = 1 + - if (tmp_ind>0) then - fname_list(nn) = fname(1:tmp_ind) // trim(granule_id) ! replace file name with granule id - else - fname_list(nn) = trim(granule_id) ! fname was only file name (no path) - end if - else + ! ! dbg ! ! write (*,*) '###############################################################################' + ! ! dbg ! ! write (*,*) Iam // '():' + ! ! dbg ! ! write (*,*) 'size(CMG_SCF), N_lon, N_lat = ', size(CMG_SCF), N_lon, N_lat + ! ! dbg ! ! write (*,*) 'lon_min, lon_max = ', lon_min, lon_max + ! ! dbg ! ! write (*,*) 'lat_min, lat_max = ', lat_min, lat_max + ! ! dbg ! ! write (*,*) 'start [lon, lat] = ', start + ! ! dbg ! ! write (*,*) 'last [lon, lat] = ', last + ! ! dbg ! ! write (*,*) 'edge [lon, lat] = ', edge + ! ! dbg ! ! write (*,*) '###############################################################################' + - fname_list( nn) = fname ! use fname b/c granule_id is empty - end if + ! 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 - end do + if (logit) then + write (logunit,'(400A)') trim(Iam), '(): reading MODIS 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 - ! write "obslog" file - if (write_obslog) then + ! allocate arrays - YYYYMMDD_HHMMSSz = date_time2string(date_time) + allocate(lon_c( N_lon)) + allocate(lat_c( N_lat)) + + allocate(lon_ind(N_lon)) + allocate(lat_ind(N_lat)) - tmpstr80 = trim(Iam) // '()' ! name of this subroutine + allocate(Snow_Cover (N_lon,N_lat)) + allocate(Clear_Index (N_lon,N_lat)) + allocate(Snow_Spatial_QA(N_lon,N_lat)) - do nn=1,N_files + allocate(tmp_char1( N_lon,N_lat)) - write (tmpstr12,'(i12)') N_good_data_list(nn) ! convert integer to string + ! -------------------------- + + ! determine center lat/lon of CMG cells - call add_to_obslog( YYYYMMDD_HHMMSSz, this_obs_param%descr, tmpstr80, & - tmpstr12, fname_list(nn) ) + 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) - end do + ! 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 hdf file (read-only) and initialize SD interface + + sd_id = sfstart(trim(fname), DFACC_READ) + if (sd_id<0) then + + err_msg = 'cannot sfstart (open) file: ' // trim(fname) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + 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 - ! return if no JPSS obs were found (found_obs=.false. per initialization above) + call get_MODIS_granule_id( sd_id, granule_id ) - if (N_CMG_obs==0) return + ! read data + do nn=1,N_fields + + sds_index = sfn2index( sd_id, trim(field_names(nn)) ) + sds_id = sfselect( sd_id, sds_index ) - ! map to tile space - - allocate(tmp_tile_num(N_CMG_obs)) - - 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 ) - - - std_JPSS_obs = this_obs_param%errstd - - JPSS_obs = 0. - JPSS_lon = 0. - JPSS_lat = 0. - N_obs_in_tile = 0 - - do kk=1,N_CMG_obs - - ind = tmp_tile_num(kk) ! 1<=tmp_tile_num<=N_catf (unless nodata) + status = sfginfo( sds_id, sds_name, rank, dimsizes, data_type, num_attrs ) - if (ind>0) then ! this condition eliminates obs outside domain - - JPSS_obs( ind) = JPSS_obs( ind) + CMG_obs(kk) - JPSS_lon( ind) = JPSS_lon( ind) + CMG_lon(kk) - JPSS_lat( ind) = JPSS_lat( ind) + CMG_lat(kk) + if ( (dimsizes(1)/=CMG_N_lon) .or. (dimsizes(2)/=CMG_N_lat) ) then - N_obs_in_tile(ind) = N_obs_in_tile(ind) + 1 + err_msg = 'dimensions in hdf file doe not match CMG_N_lon and/or CMG_N_lat' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - end do - - ! normalize - - do kk=1,N_catf - if (N_obs_in_tile(kk)>0) then - - tmp_real = real(N_obs_in_tile(kk)) - JPSS_obs(kk) = JPSS_obs(kk)/tmp_real - JPSS_lon(kk) = JPSS_lon(kk)/tmp_real - JPSS_lat(kk) = JPSS_lat(kk)/tmp_real + ! ######################################################### + ! ! dbg ! ! write (*,*) 'sds_name = ', trim(sds_name) + ! ! dbg ! ! write (*,*) 'rank, data_type, num_attrs = ', rank, data_type, num_attrs + ! ! dbg ! ! write (*,*) 'dimsizes = ', dimsizes + ! ######################################################### + - else if (N_obs_in_tile(kk)==0) then + select case (nn) - JPSS_obs(kk) = this_obs_param%nodata - JPSS_lon(kk) = this_obs_param%nodata - JPSS_lat(kk) = this_obs_param%nodata + case (1); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Cover = ichar(tmp_char1,2) + case (2); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Clear_Index = ichar(tmp_char1,2) + case (3); status = sfrdata( sds_id, start, stride, edge, tmp_char1 ); Snow_Spatial_QA = ichar(tmp_char1,2) + + case default; call ldas_abort(LDAS_GENERIC_ERROR, Iam, 'unknown field') + + end select + + if (status/=0) then + err_msg = 'error reading data from hdf file: ' // trim(fname) + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) + end if + + status = sfendacc(sds_id) ! terminate access to SDS (field) + end do - if (any(N_obs_in_tile>0)) then - - found_obs = .true. - - else + status = sfend(sd_id) ! close hdf file and SD interface + + + ! ################################################################################# + ! ! dbg ! ! write (*,*) 'Snow_Cover(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Snow_Cover(1:10,1:5) + ! ! dbg ! ! write (*,*) 'Clear_Index(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Clear_Index(1:10,1:5) + ! ! dbg ! ! write (*,*) 'Snow_Spatial_QA(1:10,1:5)=' + ! ! dbg ! ! write (*,*) Snow_Spatial_QA(1:10,1:5) + + ! ! dbg ! ! !if ( (lon_min>-138) .and. (lon_min<-134) ) then + ! ! dbg ! ! if (.false.) then + ! ! dbg ! ! do jj=1,N_lat + ! ! dbg ! ! write(997) Snow_Cover( jj,:) + ! ! dbg ! ! write(998) Clear_Index( jj,:) + ! ! dbg ! ! write(999) Snow_Spatial_QA(jj,:) + ! ! dbg ! ! end do + ! ! dbg ! ! write (*,*) 'stopping after file dump ' + ! ! dbg ! ! stop + ! ! dbg ! ! end if + ! ################################################################################# + + + + ! check range (make sure uint8 from hdf 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(Snow_Spatial_QA < uint8_min) .or. & + any(Snow_Spatial_QA > uint8_max) ) then - found_obs = .false. + err_msg = 'unexpected range in data from hdf file' + call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) end if - deallocate(tmp_tile_num) - - deallocate(CMG_obs) - deallocate(CMG_lon) - deallocate(CMG_lat) - - ! to avoid double-counting of JPSS 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 - ! assimilation windows gets its obs only once (e.g., EASEv2 M36 tiles at +-45 and +-135 deg - ! for windows centered at 0z, 3z, ...) + ! apply QC and put SCF obs into output array - if (lon_end < lon_beg) then - - ! need only one longitude band (keep obs when lon_endlon_beg) ) & - JPSS_obs(kk) = this_obs_param%nodata + ! note: Snow_Cover >= 0 per range check above, no need to check for minimum - end do - - else - - ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_end qc_clear_index_min ) .and. & ! sufficiently clear sky (2) + (Snow_Spatial_QA(ii,jj) <= qc_snow_spatial_max) ! keep "best", "good", or "OK" quality (3) - if ( (tile_coord_f(kk)%com_lon>lon_beg) .and. (tile_coord_f(kk)%com_lon<=lon_end) ) & - JPSS_obs(kk) = this_obs_param%nodata + ! (1) excludes "lake ice", "night", "inland water", "ocean", "cloud obscured water", "data not mapped", "fill" + ! (2) clear_index>100 already removed via qc_snow_cover_max + ! (3) excludes Antarctica + + if (keep_data) then + + kk = kk + 1 + + ! raw SCF value is for clear portion of grid cell only, need to normalize with Clear_Index + + CMG_SCF(kk) = 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 if + 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) - end subroutine read_obs_JPSS_SCF + deallocate(Snow_Cover ) + deallocate(Clear_Index ) + deallocate(Snow_Spatial_QA) - ! ***************************************************************** + end subroutine read_MODIS_SCF_hdf + +! ***************************************************************** subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & N_good_data, CMG_lon, CMG_lat, CMG_SCF, granule_id ) @@ -8371,7 +8371,6 @@ end subroutine read_JPSS_SCF_hdf ! ***************************************************************** - 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, & diff --git a/GEOSlandassim_GridComp/io_hdf5.F90 b/GEOSlandassim_GridComp/io_hdf5.F90 index 39b1ea13..247dde24 100644 --- a/GEOSlandassim_GridComp/io_hdf5.F90 +++ b/GEOSlandassim_GridComp/io_hdf5.F90 @@ -50,7 +50,7 @@ module io_hdf5 procedure, public :: openFile procedure, public :: closeFile procedure, public :: queryDataset - generic, public :: readDataset => readDataset1DReal, readDataset1DReal8, readDataset1DInt, readDataset1DChar24, readDataset2DReal, readDataset2DInt + generic, public :: readDataset => readDataset1DReal, readDataset1DReal8, readDataset1DInt, readDataset1DChar24, readDataset2DReal, readDataset2DInt generic, public :: readAttribute => readAttributeChar ! private procedure, private :: readDataset1DReal From 472a9dbabfafa2c3e3d65ddb6c92b13b25487dda Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Mon, 23 Nov 2026 12:35:12 -0500 Subject: [PATCH 82/90] merged read_obs_MODIS_SCF() and read_obs_JPSS_SCF() into single subroutine read_obs_MODIS_VIIRS_SCF(); renamed read_JPSS_SCF_hdf() to read_VIIRS_SCF_hdf() (clsm_ensupd_read_obs.F90) --- .../clsm_ensupd_read_obs.F90 | 790 ++++-------------- 1 file changed, 155 insertions(+), 635 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index b8e059d3..4feebde3 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6453,25 +6453,32 @@ end subroutine read_obs_SMOS ! ***************************************************************** - subroutine read_obs_MODIS_SCF( & + 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 @@ -6501,7 +6508,7 @@ subroutine read_obs_MODIS_SCF( & logical, intent(out) :: found_obs - real, dimension(N_catf), 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 ! ------------------------------------------------------------------------ @@ -6509,13 +6516,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 @@ -6535,14 +6542,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_beg_MVSCF, date_time_end_MVSCF type(date_time_type) :: date_time_obs_beg 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 @@ -6556,7 +6563,7 @@ subroutine read_obs_MODIS_SCF( & 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 ! ------------------------------------------------------------------------------------ @@ -6565,12 +6572,18 @@ subroutine read_obs_MODIS_SCF( & found_obs = .false. - ! determine operating time range of sensor + ! determine operating time range of platform with MODIS/VIIRS sensor 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 else err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) @@ -6591,16 +6604,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) + + MVSCF_product_ID = this_obs_param%name(1:7) - select case (MODIS_product_ID) + 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 @@ -6621,9 +6641,9 @@ subroutine read_obs_MODIS_SCF( & 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_f%max_lon - tile_coord_f%min_lon ) @@ -6631,21 +6651,21 @@ subroutine read_obs_MODIS_SCF( & 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 @@ -6655,19 +6675,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 @@ -6677,12 +6697,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) @@ -6691,24 +6711,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 @@ -6749,25 +6769,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 @@ -6795,33 +6797,75 @@ subroutine read_obs_MODIS_SCF( & ! ! Assuming the MODIS file naming convention remains unchanged, the version can then ! be specified in the nml file. + + ! read VIIRS SCF obs + ! + ! - 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. - 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' ) + + 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') + + 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 @@ -6865,7 +6909,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 @@ -6882,11 +6926,11 @@ subroutine read_obs_MODIS_SCF( & 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 @@ -6896,9 +6940,9 @@ subroutine read_obs_MODIS_SCF( & 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 @@ -6913,15 +6957,15 @@ subroutine read_obs_MODIS_SCF( & 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 @@ -6942,7 +6986,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 @@ -6956,7 +7000,7 @@ subroutine read_obs_MODIS_SCF( & do kk=1,N_catf if ( (tile_coord_f(kk)%com_lon<=lon_end) .or. (tile_coord_f(kk)%com_lon>lon_beg) ) & - MODIS_obs(kk) = this_obs_param%nodata + MVSCF_obs(kk) = this_obs_param%nodata end do @@ -6967,532 +7011,17 @@ subroutine read_obs_MODIS_SCF( & do kk=1,N_catf if ( (tile_coord_f(kk)%com_lon>lon_beg) .and. (tile_coord_f(kk)%com_lon<=lon_end) ) & - MODIS_obs(kk) = this_obs_param%nodata + 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 read_obs_JPSS_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, JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat ) - - ! read JPSS snow cover observations on the 0.05-degree climate - ! modeling grid (CMG) - ! - ! JPSS1/NOAA-20: VJ110C1 (launched 2017) - ! JPSS2/NOAA-21: VJ210C1 (launched 2022) - ! S-NPP : VNP10C1 (launched 2011, decommissioned 2026) - ! - ! - ! For now, assume that VIIRS/JPSS 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 - ! - ! lcandre2, 26 Oct 2026 - ! - ! amfox, 5 Nov 2026 - obs on tiles at a window boundary are assimilated only once (as for MODIS); - ! original file names ("granule_id") are written to the obslog (as for MODIS) - ! - ! ------------------------------------------------------------------------------ - - implicit none - - ! inputs - - type(date_time_type), intent(in) :: date_time - - integer, intent(in) :: dtstep_assim ! [seconds] - integer, intent(in) :: N_catf - - type(tile_coord_type), dimension(:), pointer :: tile_coord_f ! input - - 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(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 - - ! output - - logical, intent(out) :: found_obs - - real, dimension(N_catf), intent(out) :: JPSS_obs, std_JPSS_obs, JPSS_lon, JPSS_lat - - ! ------------------------------------------------------------------------ - - ! locals - - integer, parameter :: dtstep_assim_max = 21600 ! [seconds] avoid assim window spanning >=180 deg lon - - real, parameter :: CMG_dlon = 0.05 ! [degrees] longitude spacing of JPSS CMG grid - real, parameter :: CMG_dlat = 0.05 ! [degrees] latitude spacing of JPSS CMG grid - - real, parameter :: CMG_ll_lon = -180. ! [degrees] lower-left longitude of JPSS CMG grid - real, parameter :: CMG_ur_lat = 90. ! [degrees] upper-right latitude of JPSS CMG grid - - character( 7) :: JPSS_product_ID - - character(4) :: YYYY - character(3) :: DDD ! day of year - - character( 12) :: tmpstr12 - character( 16) :: YYYYMMDD_HHMMSSz - character( 80) :: tmpstr80 - - character(400) :: fname - character(256) :: granule_id - - character(400), dimension(2) :: fname_list - - real :: overpass_hour, tmp_delta, tmp_real, max_delta_lon - - integer :: N_files, N_lon, N_lat, N_tmp, nn, kk, ind, tmp_ind - 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_JPSS, date_time_end_JPSS - type(date_time_type) :: date_time_obs_beg - - real :: lon_beg, lon_end - real :: lon_beg_JPSS, lon_end_JPSS - - integer :: delta_day_beg, delta_day_end - integer :: delta_day_beg_JPSS, delta_day_end_JPSS - - real :: lat_min, lat_max - - real, dimension(2) :: lon_min_vec, lon_max_vec - - integer, dimension(2) :: N_lon_vec, year_vec, dofyr_vec, start_ind, last_ind, N_good_data_list - - real, dimension(:), allocatable :: CMG_obs, CMG_lon, CMG_lat - - integer, dimension(:), allocatable :: tmp_tile_num - - integer, dimension(N_catf) :: N_obs_in_tile - - character(len=*), parameter :: Iam = 'read_obs_JPSS_SCF' - character(len=400) :: err_msg - - ! ------------------------------------------------------------------------------------ - ! - ! initialize - - found_obs = .false. - - ! determine operating time range of sensor - - if (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 - else - err_msg = 'Unknown obs_param%descr: ' // trim(this_obs_param%descr) - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - end if - - ! return if date_time falls outside operating time range - - if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return - - ! ---------------------------------------------------------------------------------- - ! - ! restrict assimilation time step to max allowed - - if (dtstep_assim > dtstep_assim_max) then - - err_msg = 'dtstep_assim exceeds max allowed' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - ! identify JPSS product and overpass hour - ! (see https://vlab.noaa.gov/web/towr-s/satellite-operations-updates) - - JPSS_product_ID = this_obs_param%name(1:7) - - select case (JPSS_product_ID) - - case('VJ110C1'); overpass_hour = 13.5 ! [hours] JPSS1: 13:30 local time - - case('VJ210C1'); overpass_hour = 13.5 ! [hours] JPSS2: 13:30 local time - - case('VNP10C1'); overpass_hour = 13.5 ! [hours] S-NPP: 13:30 local time - - end select - - - ! determine beginning and end of assimilation window - - date_time_beg = date_time - date_time_end = date_time - - call augment_date_time( -dtstep_assim/2, date_time_beg ) - call augment_date_time( dtstep_assim/2, date_time_end ) - - - ! determine longitude band associated with assimilation window and local overpass hour - ! - ! 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 JPSS obs need to be read - ! - ! --> because tiles have a non-zero extent, need to read JPSS 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_f%max_lon - tile_coord_f%min_lon ) - - 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] - - date_time_beg_JPSS = date_time_beg - date_time_end_JPSS = date_time_end - - call augment_date_time( -nint(tmp_delta), date_time_beg_JPSS ) - call augment_date_time( nint(tmp_delta), date_time_end_JPSS ) - - call localtime2longitude( date_time_beg_JPSS, overpass_hour, lon_beg_JPSS, delta_day_beg_JPSS ) - call localtime2longitude( date_time_end_JPSS, overpass_hour, lon_end_JPSS, delta_day_end_JPSS ) - - ! adjust date_time_*_JPSS to reflect calendar date at lon_*_JPSS - - call augment_date_time( delta_day_beg_JPSS*86400, date_time_beg_JPSS ) - call augment_date_time( delta_day_end_JPSS*86400, date_time_end_JPSS ) - - ! put together arguments for call(s) to read_JPSS_SCF_hdf() - - lon_min_vec = MAPL_UNDEF - lon_max_vec = MAPL_UNDEF - - year_vec = -9999 - dofyr_vec = -9999 - - N_lon_vec = 0 - - if (lon_end_JPSS < lon_beg_JPSS) then - - if ( date_time_end_JPSS%dofyr == date_time_beg_JPSS%dofyr ) then - - ! need only one daily JPSS file and longitude band - - N_files = 1 - - lon_min_vec(1) = lon_end_JPSS - lon_max_vec(1) = lon_beg_JPSS - - year_vec( 1) = date_time_beg_JPSS%year - dofyr_vec( 1) = date_time_beg_JPSS%dofyr - - else - - ! this should never happen for dtstep_assim_max=21600 and overpass_hour of 13:30 - - write (logunit,*) 'overpass_hour = ', overpass_hour - 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_JPSS = ', date_time_beg_JPSS - write (logunit,*) 'date_time_end_JPSS = ', date_time_end_JPSS - write (logunit,*) 'lon_beg = ', lon_beg - write (logunit,*) 'lon_end = ', lon_end - write (logunit,*) 'lon_beg_JPSS = ', lon_beg_JPSS - write (logunit,*) 'lon_end_JPSS = ', lon_end_JPSS - - err_msg = 'encountered unexpected condition for longitude band!!!' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - else - - ! longitude band wraps around dateline, two daily JPSS files are needed - ! (this could also occur if lon_*_JPSS=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_JPSS - 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_JPSS%year - dofyr_vec( 1) = date_time_end_JPSS%dofyr - - lon_min_vec(2) = -180. - lon_max_vec(2) = lon_beg_JPSS - - year_vec( 2) = date_time_beg_JPSS%year - dofyr_vec( 2) = date_time_beg_JPSS%dofyr - - end if - - ! verify that longitude bands do not exceed max expected expected width - ! (add 0.1 degree of wiggle room) - max_delta_lon = real(dtstep_assim_max + 2*nint(tmp_delta))/86400.*360. + 0.1 ! [degree] - - do nn=1,N_files - - if ( lon_max_vec(nn) - lon_min_vec(nn) > max_delta_lon ) then - - err_msg = 'longitude band too wide' - call ldas_abort(LDAS_GENERIC_ERROR, Iam, err_msg) - - end if - - end do - - - ! determine latitude band covered by domain (no need to read obs outside domain) - - 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 ) - - start_ind(1) = (CMG_ur_lat - lat_max )/CMG_dlat - last_ind(1) = (CMG_ur_lat - lat_min )/CMG_dlat - - N_lat = last_ind(1) - start_ind(1) + 1 - - start_ind(1:N_files) = (lon_min_vec(1:N_files) - CMG_ll_lon)/CMG_dlon - last_ind( 1:N_files) = (lon_max_vec(1:N_files) - CMG_ll_lon)/CMG_dlon - - N_lon_vec(1:N_files) = last_ind(1:N_files) - start_ind(1:N_files) + 1 - - N_lon = sum( N_lon_vec(1:N_files) ) - - ! allocate arrays for JPSS CMG data (max size that could possibly be needed for obs from both files) - - N_tmp = N_lon*N_lat - - allocate( CMG_obs(N_tmp) ) - allocate( CMG_lon(N_tmp) ) - allocate( CMG_lat(N_tmp) ) - - - ! read VIIRS SCF obs - ! - ! - files must be renamed (production time stamp removed), as for MODIS SCF obs: - ! 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 - ! - - N_CMG_obs = 0 ! initialize counter for "good" obs returned by calls to read_JPSS_SCF_hdf() - - do nn=1,N_files ! loop through longitude bands (i.e., files) - - ! determine JPSS 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:23) - - ! 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_JPSS_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 ) - - N_CMG_obs = N_CMG_obs + N_good_data - - ! record number of good obs and file name for obslog - - N_good_data_list(nn) = N_good_data - - if (len_trim(granule_id)>0) then - - tmp_ind = index(trim(fname), '/', back=.true.) ! position of last "/" - - if (tmp_ind>0) then - fname_list(nn) = fname(1:tmp_ind) // trim(granule_id) ! replace file name with granule id - else - fname_list(nn) = trim(granule_id) ! fname was only file name (no path) - end if - - else - - fname_list( nn) = fname ! use fname b/c granule_id is empty - - end if - - end do - - ! write "obslog" file - - if (write_obslog) then - - YYYYMMDD_HHMMSSz = date_time2string(date_time) - - tmpstr80 = trim(Iam) // '()' ! name of this subroutine - - do nn=1,N_files - - write (tmpstr12,'(i12)') N_good_data_list(nn) ! convert integer to string - - call add_to_obslog( YYYYMMDD_HHMMSSz, this_obs_param%descr, tmpstr80, & - tmpstr12, fname_list(nn) ) - - end do - - end if - - ! return if no JPSS obs were found (found_obs=.false. per initialization above) - - if (N_CMG_obs==0) return - - - ! map to tile space - - allocate(tmp_tile_num(N_CMG_obs)) - - 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 ) - - - std_JPSS_obs = this_obs_param%errstd - - JPSS_obs = 0. - JPSS_lon = 0. - JPSS_lat = 0. - - N_obs_in_tile = 0 - - do kk=1,N_CMG_obs - - ind = tmp_tile_num(kk) ! 1<=tmp_tile_num<=N_catf (unless nodata) - - if (ind>0) then ! this condition eliminates obs outside domain - - JPSS_obs( ind) = JPSS_obs( ind) + CMG_obs(kk) - JPSS_lon( ind) = JPSS_lon( ind) + CMG_lon(kk) - JPSS_lat( ind) = JPSS_lat( ind) + CMG_lat(kk) - - N_obs_in_tile(ind) = N_obs_in_tile(ind) + 1 - - end if - - end do - - ! normalize - - do kk=1,N_catf - if (N_obs_in_tile(kk)>0) then - - tmp_real = real(N_obs_in_tile(kk)) - - JPSS_obs(kk) = JPSS_obs(kk)/tmp_real - JPSS_lon(kk) = JPSS_lon(kk)/tmp_real - JPSS_lat(kk) = JPSS_lat(kk)/tmp_real - - else if (N_obs_in_tile(kk)==0) then - - JPSS_obs(kk) = this_obs_param%nodata - JPSS_lon(kk) = this_obs_param%nodata - JPSS_lat(kk) = this_obs_param%nodata - - end if - end do - - if (any(N_obs_in_tile>0)) then - - found_obs = .true. - - else - - found_obs = .false. - - end if - - deallocate(tmp_tile_num) - - deallocate(CMG_obs) - deallocate(CMG_lon) - deallocate(CMG_lat) - - ! to avoid double-counting of JPSS 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 - ! assimilation windows gets its obs only once (e.g., EASEv2 M36 tiles at +-45 and +-135 deg - ! for windows centered at 0z, 3z, ...) - - if (lon_end < lon_beg) then - - ! need only one longitude band (keep obs when lon_endlon_beg) ) & - JPSS_obs(kk) = this_obs_param%nodata - - end do - - else - - ! longitude band wraps around dateline (keep obs when -180<=com_lon<=lon_beg or lon_endlon_beg) .and. (tile_coord_f(kk)%com_lon<=lon_end) ) & - JPSS_obs(kk) = this_obs_param%nodata - - end do - - end if - - - end subroutine read_obs_JPSS_SCF - ! ******************************************************************************************************* subroutine localtime2longitude( date_time, local_hour, longitude, delta_day ) @@ -7658,7 +7187,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 ! ! ------------------------------------------------------------------------------------------------- @@ -7891,7 +7420,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 ) @@ -8038,7 +7567,7 @@ end subroutine read_MODIS_SCF_hdf ! ***************************************************************** - subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & + 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) @@ -8057,7 +7586,7 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! 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_JPSS_SCF(), as for MODIS + ! calling subroutine read_obs_MODIS_VIIRS_SCF() ! - amfox, 5 Nov 2026 ! ! ------------------------------------------------------------------------------------------------- @@ -8143,7 +7672,7 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & integer, dimension(:,:), allocatable :: Clear_Index integer, dimension(:,:), allocatable :: Basic_QA - character(len=*), parameter :: Iam = 'read_JPSS_SCF_hdf' + character(len=*), parameter :: Iam = 'read_VIIRS_SCF_hdf' character(len=400) :: err_msg ! ------------------------------------------------------------------------- @@ -8367,7 +7896,7 @@ subroutine read_JPSS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & deallocate(Clear_Index) deallocate(Basic_QA ) - end subroutine read_JPSS_SCF_hdf + end subroutine read_VIIRS_SCF_hdf ! ***************************************************************** @@ -11175,18 +10704,9 @@ subroutine read_obs( & end if - case ('MOD10C1','MYD10C1') - - call read_obs_MODIS_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 ) - - case ('VNP10C1','VJ110C1','VJ210C1') + case ('MOD10C1','MYD10C1','VNP10C1','VJ110C1','VJ210C1') - call read_obs_JPSS_SCF( & + 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, & From 5d7d34bd39da4cd391cb6c565ae5f1e2d75cd025 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Mon, 23 Nov 2026 12:46:06 -0500 Subject: [PATCH 83/90] added end date for VIIRS/SNPP (clsm_ensupd_read_obs.F90) --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 4feebde3..5cd1d7e4 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6543,7 +6543,7 @@ subroutine read_obs_MODIS_VIIRS_SCF( & type(date_time_type) :: date_time_beg, date_time_end type(date_time_type) :: date_time_beg_MVSCF, date_time_end_MVSCF - type(date_time_type) :: date_time_obs_beg + type(date_time_type) :: date_time_obs_beg, date_time_obs_end real :: lon_beg, lon_end real :: lon_beg_MVSCF, lon_end_MVSCF @@ -6574,6 +6574,8 @@ subroutine read_obs_MODIS_VIIRS_SCF( & ! 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 @@ -6584,6 +6586,7 @@ subroutine read_obs_MODIS_VIIRS_SCF( & 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) @@ -6591,8 +6594,9 @@ subroutine read_obs_MODIS_VIIRS_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_gt_refdatetime(date_time, date_time_obs_end)) return ! date_time too late for obs + ! ---------------------------------------------------------------------------------- ! ! restrict assimilation time step to max allowed From 4c7427f4ec34a778a00906e3aa2e572db7b7bfaf Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Mon, 23 Nov 2026 14:52:29 -0500 Subject: [PATCH 84/90] fixed build error in previous commit (clsm_ensupd_read_obs.F90) --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 5cd1d7e4..22f47aea 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6594,8 +6594,8 @@ subroutine read_obs_MODIS_VIIRS_SCF( & ! return if date_time falls outside operating time range - if (datetime_lt_refdatetime(date_time, date_time_obs_beg)) return ! date_time too early for obs - if (datetime_gt_refdatetime(date_time, date_time_obs_end)) return ! date_time too late for obs + 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 ! ---------------------------------------------------------------------------------- ! From a8c9bdc737739fff63075c41e5262d1707b480c5 Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Mon, 23 Nov 2026 15:55:53 -0500 Subject: [PATCH 85/90] minimal cleanup of comments, vertical alignment in VIIRS SCF reader (clsm_ensupd_read_obs.F90) --- .../clsm_ensupd_read_obs.F90 | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 22f47aea..4235f226 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -7024,9 +7024,7 @@ subroutine read_obs_MODIS_VIIRS_SCF( & end subroutine read_obs_MODIS_VIIRS_SCF - ! ******************************************************************************************************* - - ! ******************************************************************************************************* + ! ***************************************************************** subroutine localtime2longitude( date_time, local_hour, longitude, delta_day ) @@ -7440,7 +7438,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 @@ -7569,7 +7567,7 @@ subroutine read_MODIS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & 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 ) @@ -7578,13 +7576,11 @@ subroutine read_VIIRS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! - 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 climate modeling grid (CMG) + ! - 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 ! - ! adapted from read_MODIS_SCF_hdf() (reichle, 20 Oct 2023) - ! - ! amfox, 2 Nov 2026 - hdf5 version for VIIRS + ! 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 @@ -7853,13 +7849,12 @@ subroutine read_VIIRS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & ! 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. & ! keep "good" or "other" (4) - Basic_QA( ii,jj) == qc_basic_qa_other ) ! quality only (4) - + 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 @@ -7904,6 +7899,7 @@ end subroutine read_VIIRS_SCF_hdf ! ***************************************************************** + 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, & From 5ec90a72e48d9213a26933bf12deb3fc4756b89f Mon Sep 17 00:00:00 2001 From: Rolf Reichle Date: Mon, 23 Nov 2026 16:06:11 -0500 Subject: [PATCH 86/90] moved comments in MODIS/VIIRS SCF reader (clsm_ensupd_read_obs.F90) --- .../clsm_ensupd_read_obs.F90 | 82 +++++++++---------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 4235f226..07fa2c50 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -6782,47 +6782,7 @@ subroutine read_obs_MODIS_VIIRS_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 VIIRS SCF obs - ! - ! - 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. + ! 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(), read_VIIRS_SCF_hdf() @@ -6841,7 +6801,25 @@ subroutine read_obs_MODIS_VIIRS_SCF( & 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) @@ -6856,6 +6834,26 @@ subroutine read_obs_MODIS_VIIRS_SCF( & 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) From 566f3b49dcc96d3ec910b5d8fb3a690c8c58b0ac Mon Sep 17 00:00:00 2001 From: amfox37 Date: Mon, 23 Nov 2026 14:49:56 -0700 Subject: [PATCH 87/90] Update comment: read_obs_JPSS_SCF -> read_obs_MODIS_VIIRS_SCF (read_VIIRS_SCF_hdf) Co-Authored-By: Claude Sonnet 5.5 --- GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 index 07fa2c50..36be8f27 100644 --- a/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 +++ b/GEOSlandassim_GridComp/clsm_ensupd_read_obs.F90 @@ -7786,7 +7786,7 @@ subroutine read_VIIRS_SCF_hdf( fname, lon_min, lon_max, lat_min, lat_max, & call h5r%openFile(trim(fname)) ! get original file name (incl. production time stamp) because files are renamed; returned to - ! read_obs_JPSS_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 ! (blank if the attribute is missing or cannot be read) call h5r%readAttribute('LocalGranuleID', granule_id) From 3fa0911a6d6260856e64a60dadae83017ad946ff Mon Sep 17 00:00:00 2001 From: amfox37 Date: Fri, 27 Nov 2026 11:02:35 -0700 Subject: [PATCH 88/90] Weight tiles by area in Python ObsFcstAna stats maps tile_to_latlongrid() and the spatial averages in the titles of Plot_stats_maps.py used unweighted means over tiles. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + .../ObsFcstAna_stats/Plot_stats_maps.py | 11 +++++++---- .../util/shared/python/tile_to_latlongrid.py | 17 ++++++++++------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3c4b60e..72b8ee63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added logging of original (pre-renaming) file names of MODIS SCF obs ([PR #239](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/239)). ### Changed +- Changed Python ObsFcstAna stats maps (`tile_to_latlongrid.py`, `Plot_stats_maps.py`) to weight tiles by area (changes plots and spatial averages only). - 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)). 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..82ac6bda 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,7 +47,7 @@ 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']): @@ -53,12 +55,13 @@ def tile_to_latlongrid( tile_data, tile_coord, resolution, nodata=1.e15, nodata_ if ~np.isnan(tile_data[k,v]): 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 From 3b14a9b5bd73fba0f18ef03af4f8ea168eca0098 Mon Sep 17 00:00:00 2001 From: amfox37 Date: Fri, 27 Nov 2026 11:12:14 -0700 Subject: [PATCH 89/90] tile_to_latlongrid: skip zero-area tiles A zero-area first tile in a grid cell gave 0/0 and left the cell NaN. Co-Authored-By: Claude Sonnet 5.5 --- GEOSldas_App/util/shared/python/tile_to_latlongrid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEOSldas_App/util/shared/python/tile_to_latlongrid.py b/GEOSldas_App/util/shared/python/tile_to_latlongrid.py index 82ac6bda..98195a7f 100644 --- a/GEOSldas_App/util/shared/python/tile_to_latlongrid.py +++ b/GEOSldas_App/util/shared/python/tile_to_latlongrid.py @@ -52,7 +52,7 @@ def tile_to_latlongrid( tile_data, tile_coord, resolution, nodata=1.e15, nodata_ 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 area-weighted mean of all tiles within From eb8f5f400b4ee95bfaac8886d7cd03918145e10f Mon Sep 17 00:00:00 2001 From: amfox37 Date: Fri, 27 Nov 2026 12:27:25 -0700 Subject: [PATCH 90/90] CHANGELOG: add PR number Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72b8ee63..17f9b324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added logging of original (pre-renaming) file names of MODIS SCF obs ([PR #239](https://github.com/GEOS-ESM/GEOSldas_GridComp/pull/239)). ### Changed -- Changed Python ObsFcstAna stats maps (`tile_to_latlongrid.py`, `Plot_stats_maps.py`) to weight tiles by area (changes plots and spatial averages only). +- 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)).