From 96dec6453ebb3fcb2eba2e2dc5783e4513f04d02 Mon Sep 17 00:00:00 2001 From: lewisn-met Date: Tue, 24 Nov 2026 16:20:44 +0000 Subject: [PATCH 1/6] Handle 1D variables which should be projected across levels. --- src/opsinputs/opsinputs_fill_mod.F90 | 169 +++++++++++++------ src/opsinputs/opsinputs_varobswriter_mod.F90 | 39 +++-- 2 files changed, 141 insertions(+), 67 deletions(-) diff --git a/src/opsinputs/opsinputs_fill_mod.F90 b/src/opsinputs/opsinputs_fill_mod.F90 index bd4b0d6b..5cf51b3f 100644 --- a/src/opsinputs/opsinputs_fill_mod.F90 +++ b/src/opsinputs/opsinputs_fill_mod.F90 @@ -225,11 +225,13 @@ end subroutine opsinputs_fill_fillelementtypefromsimulatedvariable !> Pointer to a ioda::ObsDataVector object containing observation errors. !> \param[in] JediVarName !> Name of the JEDI variables (in the ObsValue, ObsError and GrossErrorProbability groups) -!> used to populate El2 and Hdr. The variables can either have no channel suffix (in which case -!> \p El2 will have only a single row) or have suffixes representing the indices specified in -!> \p Channels. +!> used to populate El2 and Hdr. The variables can have suffixes representing the indices +!> specified in \p Channels. If \p JediVarHasChannels is false, the exact variable name is used +!> for each output channel. !> \param[in] JediGroupName !> Name of the JEDI Variable group, for example, ObsValue or BiasCorrObsValue. +!> \param[in] JediVarHasChannels +!> If false, use \p JediVarName for every output channel. !> \param[in] PackPGEs !> Optional; true by default. If set to false, PGEs won't be stored in packed form. !> The Ops_VarobPGEs subroutine expects PGEs to be stored in packed form for most varobs fields, @@ -239,7 +241,8 @@ end subroutine opsinputs_fill_fillelementtypefromsimulatedvariable !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_norecords( & - Hdr, OpsVarName, NumObs, El2, ObsSpace, Channels, Flags, ObsErrors, JediVarName, JediGroupName, PackPGEs) + Hdr, OpsVarName, NumObs, El2, ObsSpace, Channels, Flags, ObsErrors, JediVarName, JediGroupName, & + JediVarHasChannels, PackPGEs) implicit none ! Subroutine arguments: @@ -253,6 +256,7 @@ subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_norecords( & type(c_ptr), value, intent(in) :: ObsErrors character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediGroupName +logical, intent(in) :: JediVarHasChannels logical, optional, intent(in) :: PackPGEs ! Local declarations: @@ -287,7 +291,8 @@ subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_norecords( & MissingDouble = missing_value(0.0_c_double) MissingFloat = missing_value(0.0_c_float) -JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels(JediVarName, Channels) +JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & + JediVarName, Channels, JediVarHasChannels) if (obsspace_has(ObsSpace, JediGroupName, JediVarNamesWithChannels(1))) then ! Allocate OPS data structures @@ -517,10 +522,13 @@ end subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_records !> \param[in] JediVarName !> Name of the JEDI variables (in the ObsValue, ObsError and GrossErrorProbability groups) used !> to populate El2 and Hdr. If each JEDI location needs to be mapped to a separate OPS -!> observation, the variables can either have no channel suffix (in which case \p El2 will have -!> only a single row) or have suffixes representing the indices specified in \p Channels. +!> observation, the variables can have suffixes representing the indices specified in +!> \p Channels. If \p JediVarHasChannels is false, the exact variable name is used for each +!> output channel. !> \param[in] JediGroupName !> Name of the JEDI Variable group, for example, ObsValue or BiasCorrObsValue. +!> \param[in] JediVarHasChannels +!> If false, use \p JediVarName for every output channel. Defaults to true. !> \param[in] PackPGEs !> Optional; true by default. If set to false, PGEs won't be stored in packed form. !> The Ops_VarobPGEs subroutine expects PGEs to be stored in packed form for most varobs fields, @@ -531,7 +539,7 @@ end subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_records !> are not found. subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Hdr, OpsVarName, JediToOpsLayoutMapping, El2, ObsSpace, Channels, Flags, ObsErrors, VarobsLength, JediVarName, & - JediGroupName, PackPGEs) + JediGroupName, PackPGEs, JediVarHasChannels) implicit none ! Subroutine arguments: @@ -547,8 +555,14 @@ subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable( & character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediGroupName logical, optional, intent(in) :: PackPGEs +logical, optional, intent(in) :: JediVarHasChannels + +! Local declarations: +logical :: JediVarHasChannelsLocal ! Body: +JediVarHasChannelsLocal = .true. +if (present(JediVarHasChannels)) JediVarHasChannelsLocal = JediVarHasChannels if (JediToOpsLayoutMapping % ConvertRecordsToMultilevelObs) then call opsinputs_fill_fillelementtype2dfromsimulatedvariable_records( & @@ -557,7 +571,7 @@ subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable( & else call opsinputs_fill_fillelementtype2dfromsimulatedvariable_norecords( & Hdr, OpsVarName, JediToOpsLayoutMapping % NumOpsObs, El2, ObsSpace, Channels, Flags, & - ObsErrors, JediVarName, JediGroupName, PackPGEs) + ObsErrors, JediVarName, JediGroupName, JediVarHasChannelsLocal, PackPGEs) end if end subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable @@ -1022,16 +1036,18 @@ end subroutine opsinputs_fill_fillreal !> Pointer to the array to be populated. !> \param[in] ObsSpace !> Pointer to ioda::ObsSpace object containing the specified JEDI variable. The variable can -!> have either no channel suffix (in which case \p Real2 will have only a single row) or suffixes -!> representing the indices specified in \p Channels. +!> have suffixes representing the indices specified in \p Channels, or can be unchannelized +!> when \p JediVarHasChannels is false. !> \param[in] Channels !> Indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediVarName -!> Name of the JEDI variable used to populate \p Real2. This can represent either a single -!> variable with no channel suffix (in which case \p Real2 will have only a single row) or a set -!> of variables with suffixes corresponding to the indices specified in \p Channels. +!> Name of the JEDI variable used to populate \p Real2. This can represent a set of variables +!> with suffixes corresponding to the indices specified in \p Channels. If +!> \p JediVarHasChannels is false, the exact variable name is used for each output channel. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Real2. +!> \param[in] JediVarHasChannels +!> If false, use \p JediVarName for every output channel. !> \param[in] compressVarChannels !> Whether to apply var channel compression (No NaN spaces between channels) !> \param[in] sizeOfVarobsArray @@ -1044,7 +1060,7 @@ end subroutine opsinputs_fill_fillreal !> are not found. subroutine opsinputs_fill_fillreal2d_norecords( & Hdr, OpsVarName, NumObs, Real2, ObsSpace, Channels, JediVarName, & - JediVarGroup, compressVarChannels, sizeOfVarobsArray, varChannels) + JediVarGroup, JediVarHasChannels, compressVarChannels, sizeOfVarobsArray, varChannels) implicit none ! Subroutine arguments: @@ -1056,6 +1072,7 @@ subroutine opsinputs_fill_fillreal2d_norecords( & integer(c_int), intent(in) :: Channels(:) character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediVarGroup +logical, intent(in) :: JediVarHasChannels logical, optional, intent(in) :: compressVarChannels integer(integer64), optional, intent(in) :: sizeOfVarobsArray integer(c_int), optional, intent(in) :: varChannels(:) @@ -1081,7 +1098,8 @@ subroutine opsinputs_fill_fillreal2d_norecords( & compressChannels = compressVarChannels end if -JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels(JediVarName, Channels) +JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & + JediVarName, Channels, JediVarHasChannels) !take into account offsetting of 2nd dimension if required !designed to be used to pack where multiple satellite instruments expected @@ -1243,26 +1261,29 @@ end subroutine opsinputs_fill_fillreal2d_records !> Pointer to the array to be populated. !> \param[in] ObsSpace !> Pointer to ioda::ObsSpace object containing the specified JEDI variable. The variable can -!> have either no channel suffix (in which case \p Real2 will have only a single row) or suffixes -!> representing the indices specified in \p Channels. +!> have suffixes representing the indices specified in \p Channels, or can be unchannelized +!> when \p JediVarHasChannels is false. !> \param[in] Channels !> Indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] VarobsLength !> Length of varobs profile. !> \param[in] JediVarName !> Name of the JEDI variable used to populate \p Real2. If each JEDI location needs to be mapped -!> to a separate OPS observation, this can represent either a single variable with no channel -!> suffix (in which case \p Real2 will have only a single row) or a set of variables with -!> suffixes corresponding to the indices specified in \p Channels. +!> to a separate OPS observation, this can represent a set of variables with suffixes +!> corresponding to the indices specified in \p Channels. If \p JediVarHasChannels is false, +!> the exact variable name is used for each output channel. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Real2. +!> \param[in] JediVarHasChannels +!> If false, use \p JediVarName for every output channel. Defaults to true. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. subroutine opsinputs_fill_fillreal2d( & Hdr, OpsVarName, JediToOpsLayoutMapping, Real2, ObsSpace, Channels, & - VarobsLength, JediVarName, JediVarGroup, compressVarChannels, sizeOfVarobsArray, varChannels) + VarobsLength, JediVarName, JediVarGroup, compressVarChannels, sizeOfVarobsArray, varChannels, & + JediVarHasChannels) implicit none ! Subroutine arguments: @@ -1278,9 +1299,11 @@ subroutine opsinputs_fill_fillreal2d( & logical, optional, intent(in) :: compressVarChannels integer(integer64), optional, intent(in) :: sizeOfVarobsArray integer(c_int), optional, intent(in) :: varChannels(:) +logical, optional, intent(in) :: JediVarHasChannels ! local variables logical :: compressChannels +logical :: JediVarHasChannelsLocal integer(integer64) :: sizeOfVarobsArray_local integer(c_int), allocatable :: localvarChannels(:) @@ -1291,6 +1314,9 @@ subroutine opsinputs_fill_fillreal2d( & compressChannels = compressVarChannels end if +JediVarHasChannelsLocal = .true. +if (present(JediVarHasChannels)) JediVarHasChannelsLocal = JediVarHasChannels + if (present(varChannels)) then allocate(localvarChannels(size(varChannels))) localvarChannels = varChannels @@ -1308,11 +1334,13 @@ subroutine opsinputs_fill_fillreal2d( & if (allocated(localvarChannels)) then call opsinputs_fill_fillreal2d_norecords( & Hdr, OpsVarName, JediToOpsLayoutMapping % NumOpsObs, Real2, ObsSpace, Channels, & - JediVarName, JediVarGroup, compressChannels, sizeOfVarobsArray_local, varChannels) + JediVarName, JediVarGroup, JediVarHasChannelsLocal, compressChannels, & + sizeOfVarobsArray_local, varChannels) else call opsinputs_fill_fillreal2d_norecords( & Hdr, OpsVarName, JediToOpsLayoutMapping % NumOpsObs, Real2, ObsSpace, Channels, & - JediVarName, JediVarGroup, compressChannels, sizeOfVarobsArray_local) + JediVarName, JediVarGroup, JediVarHasChannelsLocal, compressChannels, & + sizeOfVarobsArray_local) end if end if @@ -2100,24 +2128,27 @@ end subroutine opsinputs_fill_filltimeoffsets !> Pointer to the array to be populated. !> \param[in] ObsSpace !> Pointer to ioda::ObsSpace object containing the specified JEDI variable. The variable can -!> have either no channel suffix (in which case \p Real2 will have only a single row) or suffixes -!> representing the indices specified in \p Channels. +!> have suffixes representing the indices specified in \p Channels, or can be unchannelized +!> when \p JediVarHasChannels is false. !> \param[in] Channels !> Indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediVarName -!> Name of the JEDI variable used to populate \p Real2. This can represent either a single -!> variable with no channel suffix (in which case \p Real2 will have only a single row) or a set -!> of variables with suffixes corresponding to the indices specified in \p Channels. +!> Name of the JEDI variable used to populate \p Real2. This can represent a set of variables +!> with suffixes corresponding to the indices specified in \p Channels. If +!> \p JediVarHasChannels is false, the exact variable name is used for each output channel. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Real2. !> \param[in] ReferenceTime !> Reference time. JEDI datetimes will be converted into offsets from this time. +!> \param[in] JediVarHasChannels +!> If false, use \p JediVarName for every output channel. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. subroutine opsinputs_fill_filltimeoffsets2d_norecords( & - Hdr, OpsVarName, NumObs, Real2, ObsSpace, Channels, JediVarName, JediVarGroup, ReferenceTime) + Hdr, OpsVarName, NumObs, Real2, ObsSpace, Channels, JediVarName, JediVarGroup, JediVarHasChannels, & + ReferenceTime) use datetime_mod, only: datetime implicit none @@ -2130,6 +2161,7 @@ subroutine opsinputs_fill_filltimeoffsets2d_norecords( & integer(c_int), intent(in) :: Channels(:) character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediVarGroup +logical, intent(in) :: JediVarHasChannels type(datetime), intent(in) :: ReferenceTime ! Local declarations: @@ -2142,7 +2174,8 @@ subroutine opsinputs_fill_filltimeoffsets2d_norecords( & MissingDouble = missing_value(0.0_c_double) -JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels(JediVarName, Channels) +JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & + JediVarName, Channels, JediVarHasChannels) if (obsspace_has(ObsSpace, JediVarGroup, JediVarNamesWithChannels(1))) then ! Allocate OPS data structures @@ -2268,28 +2301,30 @@ end subroutine opsinputs_fill_filltimeoffsets2d_records !> Pointer to the array to be populated. !> \param[in] ObsSpace !> Pointer to ioda::ObsSpace object containing the specified JEDI variable. The variable can -!> have either no channel suffix (in which case \p Real2 will have only a single row) or suffixes -!> representing the indices specified in \p Channels. +!> have suffixes representing the indices specified in \p Channels, or can be unchannelized +!> when \p JediVarHasChannels is false. !> \param[in] Channels !> Indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] VarobsLength !> Length of varobs profile. !> \param[in] JediVarName !> Name of the JEDI variable used to populate \p Real2. If each JEDI location needs to be mapped -!> to a separate OPS observation, this can represent either a single variable with no channel -!> suffix (in which case \p Real2 will have only a single row) or a set of variables with -!> suffixes corresponding to the indices specified in \p Channels. +!> to a separate OPS observation, this can represent a set of variables with suffixes +!> corresponding to the indices specified in \p Channels. If \p JediVarHasChannels is false, +!> the exact variable name is used for each output channel. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Real2. !> \param[in] ReferenceTime !> Reference time. JEDI datetimes will be converted into offsets from this time. +!> \param[in] JediVarHasChannels +!> If false, use \p JediVarName for every output channel. Defaults to true. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. subroutine opsinputs_fill_filltimeoffsets2d( & Hdr, OpsVarName, JediToOpsLayoutMapping, Real2, ObsSpace, Channels, VarobsLength, JediVarName, JediVarGroup, & - ReferenceTime) + ReferenceTime, JediVarHasChannels) use datetime_mod, only: datetime implicit none @@ -2304,8 +2339,14 @@ subroutine opsinputs_fill_filltimeoffsets2d( & character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediVarGroup type(datetime), intent(in) :: ReferenceTime +logical, optional, intent(in) :: JediVarHasChannels + +! Local declarations: +logical :: JediVarHasChannelsLocal ! Body: +JediVarHasChannelsLocal = .true. +if (present(JediVarHasChannels)) JediVarHasChannelsLocal = JediVarHasChannels if (JediToOpsLayoutMapping % ConvertRecordsToMultilevelObs) then call opsinputs_fill_filltimeoffsets2d_records(Hdr, OpsVarName, & @@ -2316,7 +2357,7 @@ subroutine opsinputs_fill_filltimeoffsets2d( & call opsinputs_fill_filltimeoffsets2d_norecords(Hdr, OpsVarName, & JediToOpsLayoutMapping % NumOpsObs, Real2, & ObsSpace, Channels, JediVarName, JediVarGroup, & - ReferenceTime) + JediVarHasChannelsLocal, ReferenceTime) end if end subroutine opsinputs_fill_filltimeoffsets2d @@ -2339,22 +2380,25 @@ end subroutine opsinputs_fill_filltimeoffsets2d !> Pointer to the array to be populated. !> \param[in] ObsSpace !> Pointer to ioda::ObsSpace object containing the specified JEDI variable. The variable can -!> have either no channel suffix (in which case \p Coord2 will have only a single row) or suffixes -!> representing the indices specified in \p Channels. +!> have suffixes representing the indices specified in \p Channels, or can be unchannelized +!> when \p JediVarHasChannels is false. !> \param[in] Channels !> Indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediVarName -!> Name of the JEDI variable used to populate \p Coord2. This can represent either a single -!> variable with no channel suffix (in which case \p Coord2 will have only a single row) or a set -!> of variables with suffixes corresponding to the indices specified in \p Channels. +!> Name of the JEDI variable used to populate \p Coord2. This can represent a set of variables +!> with suffixes corresponding to the indices specified in \p Channels. If +!> \p JediVarHasChannels is false, the exact variable name is used for each output channel. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Coord2. +!> \param[in] JediVarHasChannels +!> If false, use \p JediVarName for every output channel. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. subroutine opsinputs_fill_fillcoord2d_norecords( & - Hdr, OpsVarName, NumObs, Coord2, ObsSpace, Channels, JediVarName, JediVarGroup) + Hdr, OpsVarName, NumObs, Coord2, ObsSpace, Channels, JediVarName, JediVarGroup, & + JediVarHasChannels) implicit none ! Subroutine arguments: @@ -2366,6 +2410,7 @@ subroutine opsinputs_fill_fillcoord2d_norecords( & integer(c_int), intent(in) :: Channels(:) character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediVarGroup +logical, intent(in) :: JediVarHasChannels ! Local declarations: real(kind=c_double) :: VarValue(NumObs) @@ -2377,7 +2422,8 @@ subroutine opsinputs_fill_fillcoord2d_norecords( & MissingDouble = missing_value(0.0_c_double) -JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels(JediVarName, Channels) +JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & + JediVarName, Channels, JediVarHasChannels) if (obsspace_has(ObsSpace, JediVarGroup, JediVarNamesWithChannels(1))) then ! Allocate OPS data structures @@ -2418,7 +2464,6 @@ end subroutine opsinputs_fill_fillcoord2d_norecords !> Name of the JEDI variable used to populate \p Coord2. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Coord2. -!> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. @@ -2485,17 +2530,20 @@ end subroutine opsinputs_fill_fillcoord2d_records !> Indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediVarName !> Name of the JEDI variable used to populate \p Coord2. If each JEDI location needs to be mapped -!> to a separate OPS observation, this can represent either a single variable with no channel -!> suffix (in which case \p Coord2 will have only a single row) or a set of variables with -!> suffixes corresponding to the indices specified in \p Channels. +!> to a separate OPS observation, this can represent a set of variables with suffixes +!> corresponding to the indices specified in \p Channels. If \p JediVarHasChannels is false, +!> the exact variable name is used for each output channel. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Coord2. +!> \param[in] JediVarHasChannels +!> If false, use \p JediVarName for every output channel. Defaults to true. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. subroutine opsinputs_fill_fillcoord2d( & - Hdr, OpsVarName, JediToOpsLayoutMapping, Coord2, ObsSpace, Channels, JediVarName, JediVarGroup) + Hdr, OpsVarName, JediToOpsLayoutMapping, Coord2, ObsSpace, Channels, JediVarName, JediVarGroup, & + JediVarHasChannels) implicit none ! Subroutine arguments: @@ -2507,8 +2555,14 @@ subroutine opsinputs_fill_fillcoord2d( & integer(c_int), intent(in) :: Channels(:) character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediVarGroup +logical, optional, intent(in) :: JediVarHasChannels + +! Local declarations: +logical :: JediVarHasChannelsLocal ! Body: +JediVarHasChannelsLocal = .true. +if (present(JediVarHasChannels)) JediVarHasChannelsLocal = JediVarHasChannels if (JediToOpsLayoutMapping % ConvertRecordsToMultilevelObs) then call opsinputs_fill_fillcoord2d_records( & @@ -2516,7 +2570,7 @@ subroutine opsinputs_fill_fillcoord2d( & else call opsinputs_fill_fillcoord2d_norecords( & Hdr, OpsVarName, JediToOpsLayoutMapping % NumOpsObs, Coord2, ObsSpace, Channels, & - JediVarName, JediVarGroup) + JediVarName, JediVarGroup, JediVarHasChannelsLocal) end if end subroutine opsinputs_fill_fillcoord2d @@ -2549,20 +2603,27 @@ end function opsinputs_fill_varnames_with_levels ! ------------------------------------------------------------------------------ !> Return an array containing the names of JEDI variables storing individual channels of the -!> variable \p VarName. If the list of channels is empty, this means the variable in question is -!> 1D and hence the returned array contains just the single string \p VarName. -function opsinputs_fill_varnames_with_channels(VarName, Channels) result(VarNames) +!> variable \p VarName. If \p JediVarHasChannels is false, the exact variable name is repeated +!> for each channel in the result. +function opsinputs_fill_varnames_with_channels(VarName, Channels, JediVarHasChannels) result(VarNames) implicit none ! Subroutine arguments: character(len=*), intent(in) :: VarName integer(c_int), intent(in) :: Channels(:) +logical, optional, intent(in) :: JediVarHasChannels ! Local declarations: character(len=max_varname_with_channel_length) :: VarNames(max(size(Channels), 1)) integer :: ichan +logical :: useChannelSuffixes + +useChannelSuffixes = .true. +if (present(JediVarHasChannels)) useChannelSuffixes = JediVarHasChannels if (size(Channels) == 0) then VarNames(1) = VarName +else if (.not. useChannelSuffixes) then + VarNames = VarName else do ichan = 1, size(Channels) write (VarNames(ichan),'(A,"_",I0)') VarName, Channels(ichan) diff --git a/src/opsinputs/opsinputs_varobswriter_mod.F90 b/src/opsinputs/opsinputs_varobswriter_mod.F90 index 4d0dae9c..3ff410fb 100644 --- a/src/opsinputs/opsinputs_varobswriter_mod.F90 +++ b/src/opsinputs/opsinputs_varobswriter_mod.F90 @@ -765,9 +765,10 @@ subroutine opsinputs_varobswriter_populateobservations( & call Ops_DeAlloc(Ob % Header % SatId, "SatId", Ob % SatId) end if +! Match the ObsGroup output: read the 1D pressure once per output channel. call opsinputs_fill_fillcoord2d( & Ob % Header % PlevelsA, "PlevelsA", JediToOpsLayoutMapping, Ob % PlevelsA, & - ObsSpace, self % channels, "pressure", "MetaData") + ObsSpace, self % channels, "pressure", "MetaData", JediVarHasChannels = .false.) GPSRO_TPD = self % AccountForGPSROTangentPointDrift if (Ob % header % ObsGroup == ObsGroupGPSRO .and. GPSRO_TPD) then @@ -1036,19 +1037,23 @@ subroutine opsinputs_varobswriter_populateobservations( & ! fixes the problem. call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % RadialVelocSO, "RadialVelocSO", JediToOpsLayoutMapping, Ob % RadialVelocSO, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "radialVelocity", "ObsValue") + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "radialVelocity", "ObsValue", & + JediVarHasChannels = .false.) call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % RadialVelocity, "RadialVelocity", JediToOpsLayoutMapping, Ob % RadialVelocity, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "radialVelocity", "ObsValue") + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "radialVelocity", "ObsValue", & + JediVarHasChannels = .false.) case (VarField_Reflectivity) ! Write DerivedObsValue/reflectivity to both Ob % ReflectivitySO and Ob % Reflectivity. ! See the explanation given for RadialVelocity above. call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % ReflectivitySO, "ReflectivitySO", JediToOpsLayoutMapping, Ob % ReflectivitySO, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "reflectivity", "ObsValue") + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "reflectivity", "ObsValue", & + JediVarHasChannels = .false.) call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % Reflectivity, "Reflectivity", JediToOpsLayoutMapping, Ob % Reflectivity, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "reflectivity", "ObsValue") + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "reflectivity", "ObsValue", & + JediVarHasChannels = .false.) case (VarField_ReflectivityR) ! TODO(someone): handle this varfield ! call Ops_Alloc(Ob % Header % ReflectivityR, "ReflectivityR", Ob % Header % NumObsLocal, Ob % ReflectivityR) @@ -1058,15 +1063,18 @@ subroutine opsinputs_varobswriter_populateobservations( & case (VarField_RadarBeamElev) call opsinputs_fill_fillreal2d( & Ob % Header % RadarBeamElev, "RadarBeamElev", JediToOpsLayoutMapping, Ob % RadarBeamElev, & - ObsSpace, self % channels, self % VarobsLength, "beamTiltAngle", "MetaData") + ObsSpace, self % channels, self % VarobsLength, "beamTiltAngle", "MetaData", & + JediVarHasChannels = .false.) case (VarField_RadarObRange) call opsinputs_fill_fillreal2d( & Ob % Header % RadarObRange, "RadarObRange", JediToOpsLayoutMapping, Ob % RadarObRange, & - ObsSpace, self % channels, self % VarobsLength, "gateRange", "MetaData") + ObsSpace, self % channels, self % VarobsLength, "gateRange", "MetaData", & + JediVarHasChannels = .false.) case (VarField_RadarObAzim) call opsinputs_fill_fillreal2d( & Ob % Header % RadarObAzim, "RadarObAzim", JediToOpsLayoutMapping, Ob % RadarObAzim, & - ObsSpace, self % channels, self % VarobsLength, "beamAzimuthAngle", "MetaData") + ObsSpace, self % channels, self % VarobsLength, "beamAzimuthAngle", "MetaData", & + JediVarHasChannels = .false.) case (VarField_RadIdent) call opsinputs_fill_fillinteger2d( & Ob % Header % RadIdent, "RadIdent", JediToOpsLayoutMapping, Ob % RadIdent, & @@ -1074,7 +1082,8 @@ subroutine opsinputs_varobswriter_populateobservations( & case (VarField_RadAltAboveMSL) call opsinputs_fill_fillreal2d( & Ob % Header % RadAltAboveMSL, "RadAltAboveMSL", JediToOpsLayoutMapping, Ob % RadAltAboveMSL, & - ObsSpace, self % channels, self % VarobsLength, "stationElevation", "MetaData") + ObsSpace, self % channels, self % VarobsLength, "stationElevation", "MetaData", & + JediVarHasChannels = .false.) case (VarField_RadNoiseLvl) ! TODO(someone): handle this varfield ! call Ops_Alloc(Ob % Header % RadNoiseLvl, "RadNoiseLvl", Ob % Header % NumObsLocal, Ob % RadNoiseLvl) @@ -1136,7 +1145,8 @@ subroutine opsinputs_varobswriter_populateobservations( & ! However multiple wavelength options could be added in future. call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % AOD, "AOD", JediToOpsLayoutMapping, Ob % AOD, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "aerosolOpticalDepth", "ObsValue") + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "aerosolOpticalDepth", "ObsValue", & + JediVarHasChannels = .false.) ! NAODWaves is used by the Ops_VarobPGEs subroutine. if (Ob % Header % AOD % Present) NAODWaves = Ob % Header % AOD % NumLev case (VarField_BriTempVarError) @@ -1157,15 +1167,18 @@ subroutine opsinputs_varobswriter_populateobservations( & case (VarField_LevelTime) call opsinputs_fill_filltimeoffsets2d( & Ob % Header % level_time, "level_time", JediToOpsLayoutMapping, Ob % level_time, & - ObsSpace, self % channels, self % VarobsLength, "dateTime", "MetaData", self % validitytime) + ObsSpace, self % channels, self % VarobsLength, "dateTime", "MetaData", self % validitytime, & + JediVarHasChannels = .false.) case (VarField_LevelLat) call opsinputs_fill_fillreal2d( & Ob % Header % level_lat, "level_lat", JediToOpsLayoutMapping, Ob % level_lat, & - ObsSpace, self % channels, self % VarobsLength, "latitude", "MetaData") + ObsSpace, self % channels, self % VarobsLength, "latitude", "MetaData", & + JediVarHasChannels = .false.) case (VarField_LevelLon) call opsinputs_fill_fillreal2d( & Ob % Header % level_lon, "level_lon", JediToOpsLayoutMapping, Ob % level_lon, & - ObsSpace, self % channels, self % VarobsLength, "longitude", "MetaData") + ObsSpace, self % channels, self % VarobsLength, "longitude", "MetaData", & + JediVarHasChannels = .false.) case (VarField_RainAccum) ! TODO(someone): handle this varfield ! call Ops_Alloc(Ob % Header % RainAccum, "RainAccum", Ob % Header % NumObsLocal, Ob % RainAccum) From 35056863871b48e7b9388c36fe40f1875006d435 Mon Sep 17 00:00:00 2001 From: lewisn-met Date: Tue, 24 Nov 2026 16:52:51 +0000 Subject: [PATCH 2/6] Code cleanup, extended testing. --- src/opsinputs/opsinputs_fill_mod.F90 | 39 +++++++------------- src/opsinputs/opsinputs_varobswriter_mod.F90 | 15 +++----- test/testinput/055_VarField_channum.yaml | 8 ++++ 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/opsinputs/opsinputs_fill_mod.F90 b/src/opsinputs/opsinputs_fill_mod.F90 index 5cf51b3f..02e67f92 100644 --- a/src/opsinputs/opsinputs_fill_mod.F90 +++ b/src/opsinputs/opsinputs_fill_mod.F90 @@ -226,12 +226,9 @@ end subroutine opsinputs_fill_fillelementtypefromsimulatedvariable !> \param[in] JediVarName !> Name of the JEDI variables (in the ObsValue, ObsError and GrossErrorProbability groups) !> used to populate El2 and Hdr. The variables can have suffixes representing the indices -!> specified in \p Channels. If \p JediVarHasChannels is false, the exact variable name is used -!> for each output channel. +!> specified in \p Channels. !> \param[in] JediGroupName !> Name of the JEDI Variable group, for example, ObsValue or BiasCorrObsValue. -!> \param[in] JediVarHasChannels -!> If false, use \p JediVarName for every output channel. !> \param[in] PackPGEs !> Optional; true by default. If set to false, PGEs won't be stored in packed form. !> The Ops_VarobPGEs subroutine expects PGEs to be stored in packed form for most varobs fields, @@ -242,7 +239,7 @@ end subroutine opsinputs_fill_fillelementtypefromsimulatedvariable !> are not found. subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_norecords( & Hdr, OpsVarName, NumObs, El2, ObsSpace, Channels, Flags, ObsErrors, JediVarName, JediGroupName, & - JediVarHasChannels, PackPGEs) + PackPGEs) implicit none ! Subroutine arguments: @@ -256,7 +253,6 @@ subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_norecords( & type(c_ptr), value, intent(in) :: ObsErrors character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediGroupName -logical, intent(in) :: JediVarHasChannels logical, optional, intent(in) :: PackPGEs ! Local declarations: @@ -292,7 +288,7 @@ subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_norecords( & MissingFloat = missing_value(0.0_c_float) JediVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & - JediVarName, Channels, JediVarHasChannels) + JediVarName, Channels) if (obsspace_has(ObsSpace, JediGroupName, JediVarNamesWithChannels(1))) then ! Allocate OPS data structures @@ -523,12 +519,9 @@ end subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_records !> Name of the JEDI variables (in the ObsValue, ObsError and GrossErrorProbability groups) used !> to populate El2 and Hdr. If each JEDI location needs to be mapped to a separate OPS !> observation, the variables can have suffixes representing the indices specified in -!> \p Channels. If \p JediVarHasChannels is false, the exact variable name is used for each -!> output channel. +!> \p Channels. !> \param[in] JediGroupName !> Name of the JEDI Variable group, for example, ObsValue or BiasCorrObsValue. -!> \param[in] JediVarHasChannels -!> If false, use \p JediVarName for every output channel. Defaults to true. !> \param[in] PackPGEs !> Optional; true by default. If set to false, PGEs won't be stored in packed form. !> The Ops_VarobPGEs subroutine expects PGEs to be stored in packed form for most varobs fields, @@ -539,7 +532,7 @@ end subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_records !> are not found. subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Hdr, OpsVarName, JediToOpsLayoutMapping, El2, ObsSpace, Channels, Flags, ObsErrors, VarobsLength, JediVarName, & - JediGroupName, PackPGEs, JediVarHasChannels) + JediGroupName, PackPGEs) implicit none ! Subroutine arguments: @@ -555,15 +548,8 @@ subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable( & character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediGroupName logical, optional, intent(in) :: PackPGEs -logical, optional, intent(in) :: JediVarHasChannels - -! Local declarations: -logical :: JediVarHasChannelsLocal ! Body: -JediVarHasChannelsLocal = .true. -if (present(JediVarHasChannels)) JediVarHasChannelsLocal = JediVarHasChannels - if (JediToOpsLayoutMapping % ConvertRecordsToMultilevelObs) then call opsinputs_fill_fillelementtype2dfromsimulatedvariable_records( & Hdr, OpsVarName, JediToOpsLayoutMapping, El2, ObsSpace, Flags, & @@ -571,7 +557,7 @@ subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable( & else call opsinputs_fill_fillelementtype2dfromsimulatedvariable_norecords( & Hdr, OpsVarName, JediToOpsLayoutMapping % NumOpsObs, El2, ObsSpace, Channels, Flags, & - ObsErrors, JediVarName, JediGroupName, JediVarHasChannelsLocal, PackPGEs) + ObsErrors, JediVarName, JediGroupName, PackPGEs) end if end subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable @@ -1072,7 +1058,7 @@ subroutine opsinputs_fill_fillreal2d_norecords( & integer(c_int), intent(in) :: Channels(:) character(len=*), intent(in) :: JediVarName character(len=*), intent(in) :: JediVarGroup -logical, intent(in) :: JediVarHasChannels +logical, intent(in) :: JediVarHasChannels logical, optional, intent(in) :: compressVarChannels integer(integer64), optional, intent(in) :: sizeOfVarobsArray integer(c_int), optional, intent(in) :: varChannels(:) @@ -1275,7 +1261,7 @@ end subroutine opsinputs_fill_fillreal2d_records !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Real2. !> \param[in] JediVarHasChannels -!> If false, use \p JediVarName for every output channel. Defaults to true. +!> Optional; defaults to true. If false, use \p JediVarName for every output channel. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield @@ -2317,7 +2303,7 @@ end subroutine opsinputs_fill_filltimeoffsets2d_records !> \param[in] ReferenceTime !> Reference time. JEDI datetimes will be converted into offsets from this time. !> \param[in] JediVarHasChannels -!> If false, use \p JediVarName for every output channel. Defaults to true. +!> Optional; defaults to true. If false, use \p JediVarName for every output channel. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield @@ -2536,7 +2522,7 @@ end subroutine opsinputs_fill_fillcoord2d_records !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Coord2. !> \param[in] JediVarHasChannels -!> If false, use \p JediVarName for every output channel. Defaults to true. +!> Optional; defaults to true. If false, use \p JediVarName for every output channel. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield @@ -2603,8 +2589,9 @@ end function opsinputs_fill_varnames_with_levels ! ------------------------------------------------------------------------------ !> Return an array containing the names of JEDI variables storing individual channels of the -!> variable \p VarName. If \p JediVarHasChannels is false, the exact variable name is repeated -!> for each channel in the result. +!> variable \p VarName. If \p Channels is empty, the result contains the unsuffixed variable name +!> once. If \p JediVarHasChannels is false, the exact variable name is repeated for each channel. +!> \p JediVarHasChannels is optional and defaults to true. function opsinputs_fill_varnames_with_channels(VarName, Channels, JediVarHasChannels) result(VarNames) implicit none ! Subroutine arguments: diff --git a/src/opsinputs/opsinputs_varobswriter_mod.F90 b/src/opsinputs/opsinputs_varobswriter_mod.F90 index 3ff410fb..2b59f5d3 100644 --- a/src/opsinputs/opsinputs_varobswriter_mod.F90 +++ b/src/opsinputs/opsinputs_varobswriter_mod.F90 @@ -1037,23 +1037,19 @@ subroutine opsinputs_varobswriter_populateobservations( & ! fixes the problem. call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % RadialVelocSO, "RadialVelocSO", JediToOpsLayoutMapping, Ob % RadialVelocSO, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "radialVelocity", "ObsValue", & - JediVarHasChannels = .false.) + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "radialVelocity", "ObsValue") call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % RadialVelocity, "RadialVelocity", JediToOpsLayoutMapping, Ob % RadialVelocity, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "radialVelocity", "ObsValue", & - JediVarHasChannels = .false.) + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "radialVelocity", "ObsValue") case (VarField_Reflectivity) ! Write DerivedObsValue/reflectivity to both Ob % ReflectivitySO and Ob % Reflectivity. ! See the explanation given for RadialVelocity above. call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % ReflectivitySO, "ReflectivitySO", JediToOpsLayoutMapping, Ob % ReflectivitySO, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "reflectivity", "ObsValue", & - JediVarHasChannels = .false.) + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "reflectivity", "ObsValue") call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % Reflectivity, "Reflectivity", JediToOpsLayoutMapping, Ob % Reflectivity, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "reflectivity", "ObsValue", & - JediVarHasChannels = .false.) + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "reflectivity", "ObsValue") case (VarField_ReflectivityR) ! TODO(someone): handle this varfield ! call Ops_Alloc(Ob % Header % ReflectivityR, "ReflectivityR", Ob % Header % NumObsLocal, Ob % ReflectivityR) @@ -1145,8 +1141,7 @@ subroutine opsinputs_varobswriter_populateobservations( & ! However multiple wavelength options could be added in future. call opsinputs_fill_fillelementtype2dfromsimulatedvariable( & Ob % Header % AOD, "AOD", JediToOpsLayoutMapping, Ob % AOD, & - ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "aerosolOpticalDepth", "ObsValue", & - JediVarHasChannels = .false.) + ObsSpace, self % channels, Flags, ObsErrors, self % VarobsLength, "aerosolOpticalDepth", "ObsValue") ! NAODWaves is used by the Ops_VarobPGEs subroutine. if (Ob % Header % AOD % Present) NAODWaves = Ob % Header % AOD % NumLev case (VarField_BriTempVarError) diff --git a/test/testinput/055_VarField_channum.yaml b/test/testinput/055_VarField_channum.yaml index 071fbb0a..ffbbb5d5 100644 --- a/test/testinput/055_VarField_channum.yaml +++ b/test/testinput/055_VarField_channum.yaml @@ -40,6 +40,10 @@ observations: "1", "2", "1", "2", "1", "2"] + Plevel: ["100100.0", "100100.0", + "100200.0", "100200.0", + "100300.0", "100300.0", + "100400.0", "100400.0"] ob value: ["2.00000", "0.00000", "1.00000", "2.00000", "1.00000", "2.00000", @@ -105,6 +109,10 @@ observations: "1", "2", "1", "2", "1", "2"] + Plevel: ["100100.0", "100100.0", + "100200.0", "100200.0", + "100300.0", "100300.0", + "100400.0", "100400.0"] ob value: ["17.00000", "0.00000", "16.00000", "17.00000", "16.00000", "17.00000", From df2ce147b34abd254c0c832dabc7d5c817a30d0d Mon Sep 17 00:00:00 2001 From: lewisn-met Date: Tue, 24 Nov 2026 17:07:29 +0000 Subject: [PATCH 3/6] Efficiency improvements, remove from simulated-variable fill --- src/opsinputs/opsinputs_fill_mod.F90 | 71 +++++++++++++++----- src/opsinputs/opsinputs_varobswriter_mod.F90 | 5 +- 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/opsinputs/opsinputs_fill_mod.F90 b/src/opsinputs/opsinputs_fill_mod.F90 index 02e67f92..6779838f 100644 --- a/src/opsinputs/opsinputs_fill_mod.F90 +++ b/src/opsinputs/opsinputs_fill_mod.F90 @@ -688,8 +688,8 @@ end subroutine opsinputs_fill_fillelementtypefromnormalvariable !> Pointer to the array to be populated. !> \param[in] ObsSpace !> Pointer to ioda::ObsSpace object containing the specified JEDI variables. The variables can -!> have either no channel suffix (in which case \p El2 will have only a single row) or suffixes -!> representing the indices specified in \p Channels. +!> have suffixes representing the indices specified in \p Channels. If +!> \p JediVarHasChannels is false, the exact variable name is used for each output channel. !> \param[in] Channel indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediValueVarName !> Name of the JEDI variable containing observation values. @@ -707,13 +707,15 @@ end subroutine opsinputs_fill_fillelementtypefromnormalvariable !> they are needed for non-simulated variables. If necessary, it could be modified to retrieve !> them from the same group of JEDI variables, GrossErrorProbability, as !> opsinputs_fill_fillelementtype2dfromnormalvariable). +!> \param[in] JediVarHasChannels +!> Optional; defaults to true. If false, use the exact variable name for every output channel. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & Hdr, OpsVarName, NumObs, El2, ObsSpace, Channels, & - JediValueVarName, JediValueGroup, JediErrorVarName, JediErrorGroup, PackPGEs) + JediValueVarName, JediValueGroup, JediErrorVarName, JediErrorGroup, PackPGEs, JediVarHasChannels) implicit none ! Subroutine arguments: @@ -728,9 +730,11 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & character(len=*), optional, intent(in) :: JediErrorVarName character(len=*), optional, intent(in) :: JediErrorGroup logical, optional, intent(in) :: PackPGEs +logical, optional, intent(in) :: JediVarHasChannels ! Local declarations: logical :: DoPackPGEs +logical :: JediVarHasChannelsLocal real(kind=c_double) :: ObsValue(NumObs) real(kind=c_float) :: ObsError(NumObs) real(kind=c_double) :: MissingDouble @@ -757,13 +761,16 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & DoPackPGEs = .true. end if +JediVarHasChannelsLocal = .true. +if (present(JediVarHasChannels)) JediVarHasChannelsLocal = JediVarHasChannels + MissingDouble = missing_value(0.0_c_double) JediValueVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & - JediValueVarName, Channels) + JediValueVarName, Channels, JediVarHasChannelsLocal) if (present(JediErrorVarName)) then JediErrorVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & - JediErrorVarName, Channels) + JediErrorVarName, Channels, JediVarHasChannelsLocal) end if if (obsspace_has(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(1))) then @@ -771,13 +778,31 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & call Ops_Alloc(Hdr, OpsVarName, NumObs, El2, & num_levels = int(size(JediValueVarNamesWithChannels), kind=integer64)) + if (.not. JediVarHasChannelsLocal) then + call obsspace_get_db(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(1), ObsValue) + if (present(JediErrorVarName) .and. present(JediErrorGroup)) then + if (obsspace_has(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(1))) then + call obsspace_get_db(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(1), ObsError) + else + write (ErrorMessage, '("Variable ",A,"/",A," not found")') & + JediErrorGroup, JediErrorVarNamesWithChannels(1) + call gen_warn(RoutineName, ErrorMessage) + ObsError(:) = MissingDouble + end if + else + ObsError(:) = MissingDouble + end if + end if + do iChannel = 1, size(JediValueVarNamesWithChannels) ! Retrieve data from JEDI: ! - observation value - call obsspace_get_db(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(iChannel), & - ObsValue) + if (JediVarHasChannelsLocal) then + call obsspace_get_db(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(iChannel), & + ObsValue) + end if ! - observation error - if (present(JediErrorVarName) .and. present(JediErrorGroup)) then + if (JediVarHasChannelsLocal .and. present(JediErrorVarName) .and. present(JediErrorGroup)) then if (obsspace_has(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel))) then call obsspace_get_db(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel), & ObsError) @@ -787,7 +812,7 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & call gen_warn(RoutineName, ErrorMessage) ObsError(:) = MissingDouble end if - else + else if (JediVarHasChannelsLocal) then ObsError(:) = MissingDouble end if @@ -1104,8 +1129,13 @@ subroutine opsinputs_fill_fillreal2d_norecords( & ! Allocate OPS data structures call Ops_Alloc(Hdr, OpsVarName, NumObs, Real2, & num_levels = int(numchans, kind=integer64)) + if (.not. JediVarHasChannels) then + call obsspace_get_db(ObsSpace, JediVarGroup, JediVarNamesWithChannels(1), VarValue) + end if do iChannel = 1, size(JediVarNamesWithChannels) - call obsspace_get_db(ObsSpace, JediVarGroup, JediVarNamesWithChannels(iChannel), VarValue) + if (JediVarHasChannels) then + call obsspace_get_db(ObsSpace, JediVarGroup, JediVarNamesWithChannels(iChannel), VarValue) + end if arrayindex = iChannel ! if VAR channels have been assigned then jopa channels will be mapped to these var channels @@ -2167,10 +2197,16 @@ subroutine opsinputs_fill_filltimeoffsets2d_norecords( & ! Allocate OPS data structures call Ops_Alloc(Hdr, OpsVarName, NumObs, Real2, & num_levels = int(size(JediVarNamesWithChannels), kind=integer64)) - do iChannel = 1, size(JediVarNamesWithChannels) - ! Retrieve data from JEDI + if (.not. JediVarHasChannels) then call opsinputs_obsspace_get_db_datetime_offset_in_seconds( & - ObsSpace, JediVarGroup, JediVarNamesWithChannels(iChannel), ReferenceTime, VarValue) + ObsSpace, JediVarGroup, JediVarNamesWithChannels(1), ReferenceTime, VarValue) + end if + do iChannel = 1, size(JediVarNamesWithChannels) + if (JediVarHasChannels) then + ! Retrieve data from JEDI + call opsinputs_obsspace_get_db_datetime_offset_in_seconds( & + ObsSpace, JediVarGroup, JediVarNamesWithChannels(iChannel), ReferenceTime, VarValue) + end if ! Fill the OPS data structures where (VarValue /= MissingDouble) @@ -2415,10 +2451,15 @@ subroutine opsinputs_fill_fillcoord2d_norecords( & ! Allocate OPS data structures call Ops_Alloc(Hdr, OpsVarName, NumObs, Coord2, & num_levels = int(size(JediVarNamesWithChannels), kind=integer64)) + if (.not. JediVarHasChannels) then + call obsspace_get_db(ObsSpace, JediVarGroup, JediVarNamesWithChannels(1), VarValue) + end if do iChannel = 1, size(JediVarNamesWithChannels) - ! Retrieve data from JEDI - call obsspace_get_db(ObsSpace, JediVarGroup, JediVarNamesWithChannels(iChannel), VarValue) + if (JediVarHasChannels) then + ! Retrieve data from JEDI + call obsspace_get_db(ObsSpace, JediVarGroup, JediVarNamesWithChannels(iChannel), VarValue) + end if ! Fill the OPS data structures where (VarValue /= MissingDouble) diff --git a/src/opsinputs/opsinputs_varobswriter_mod.F90 b/src/opsinputs/opsinputs_varobswriter_mod.F90 index 2b59f5d3..23c1f92f 100644 --- a/src/opsinputs/opsinputs_varobswriter_mod.F90 +++ b/src/opsinputs/opsinputs_varobswriter_mod.F90 @@ -765,7 +765,7 @@ subroutine opsinputs_varobswriter_populateobservations( & call Ops_DeAlloc(Ob % Header % SatId, "SatId", Ob % SatId) end if -! Match the ObsGroup output: read the 1D pressure once per output channel. +! Match the ObsGroup output by filling each output-channel pressure level from the 1D variable. call opsinputs_fill_fillcoord2d( & Ob % Header % PlevelsA, "PlevelsA", JediToOpsLayoutMapping, Ob % PlevelsA, & ObsSpace, self % channels, "pressure", "MetaData", JediVarHasChannels = .false.) @@ -1125,7 +1125,8 @@ subroutine opsinputs_varobswriter_populateobservations( & else call opsinputs_fill_fillelementtype2dfromnormalvariable( & Ob % Header % ImpactParam, "ImpactParam", Ob % Header % NumObsLocal, Ob % ImpactParam, & - ObsSpace, self % channels, "impactParameterRO", "MetaData", PackPGEs = .false.) + ObsSpace, self % channels, "impactParameterRO", "MetaData", PackPGEs = .false., & + JediVarHasChannels = .false.) end if case (VarField_RO_Rad_Curv) call opsinputs_fill_fillelementtypefromnormalvariable( & From 9d39ae442f4a9815e6ad4ade9d814254a3ca4e37 Mon Sep 17 00:00:00 2001 From: lewisn-met Date: Tue, 24 Nov 2026 17:55:09 +0000 Subject: [PATCH 4/6] Amend comments 1 --- src/opsinputs/opsinputs_fill_mod.F90 | 46 +++++++++++++++------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/opsinputs/opsinputs_fill_mod.F90 b/src/opsinputs/opsinputs_fill_mod.F90 index 6779838f..3df1e768 100644 --- a/src/opsinputs/opsinputs_fill_mod.F90 +++ b/src/opsinputs/opsinputs_fill_mod.F90 @@ -225,8 +225,9 @@ end subroutine opsinputs_fill_fillelementtypefromsimulatedvariable !> Pointer to a ioda::ObsDataVector object containing observation errors. !> \param[in] JediVarName !> Name of the JEDI variables (in the ObsValue, ObsError and GrossErrorProbability groups) -!> used to populate El2 and Hdr. The variables can have suffixes representing the indices -!> specified in \p Channels. +!> used to populate El2 and Hdr. The variables can either have no channel suffix (in which case +!> \p El2 will have only a single row) or have suffixes representing the indices specified in +!> \p Channels. !> \param[in] JediGroupName !> Name of the JEDI Variable group, for example, ObsValue or BiasCorrObsValue. !> \param[in] PackPGEs @@ -518,8 +519,8 @@ end subroutine opsinputs_fill_fillelementtype2dfromsimulatedvariable_records !> \param[in] JediVarName !> Name of the JEDI variables (in the ObsValue, ObsError and GrossErrorProbability groups) used !> to populate El2 and Hdr. If each JEDI location needs to be mapped to a separate OPS -!> observation, the variables can have suffixes representing the indices specified in -!> \p Channels. +!> observation, the variables can either have no channel suffix (in which case \p El2 will have +!> only a single row) or have suffixes representing the indices specified in \p Channels. !> \param[in] JediGroupName !> Name of the JEDI Variable group, for example, ObsValue or BiasCorrObsValue. !> \param[in] PackPGEs @@ -687,9 +688,10 @@ end subroutine opsinputs_fill_fillelementtypefromnormalvariable !> \param[inout] El2 !> Pointer to the array to be populated. !> \param[in] ObsSpace -!> Pointer to ioda::ObsSpace object containing the specified JEDI variables. The variables can -!> have suffixes representing the indices specified in \p Channels. If -!> \p JediVarHasChannels is false, the exact variable name is used for each output channel. +!> Pointer to ioda::ObsSpace object containing the specified JEDI variables. The variables can +!> have either no channel suffix (when no channel numbers are provided, in which case \p El2 +!> will have only a single row) or suffixes representing the indices specified in \p Channels. +!> If \p JediVarHasChannels is false, the exact variable name is used for each output channel. !> \param[in] Channel indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediValueVarName !> Name of the JEDI variable containing observation values. @@ -800,20 +802,20 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & if (JediVarHasChannelsLocal) then call obsspace_get_db(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(iChannel), & ObsValue) - end if - ! - observation error - if (JediVarHasChannelsLocal .and. present(JediErrorVarName) .and. present(JediErrorGroup)) then - if (obsspace_has(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel))) then - call obsspace_get_db(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel), & - ObsError) - else - write (ErrorMessage, '("Variable ",A,"/",A," not found")') & - JediErrorGroup, JediErrorVarNamesWithChannels(iChannel) - call gen_warn(RoutineName, ErrorMessage) + ! - observation error + if (present(JediErrorVarName) .and. present(JediErrorGroup)) then + if (obsspace_has(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel))) then + call obsspace_get_db(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel), & + ObsError) + else + write (ErrorMessage, '("Variable ",A,"/",A," not found")') & + JediErrorGroup, JediErrorVarNamesWithChannels(iChannel) + call gen_warn(RoutineName, ErrorMessage) + ObsError(:) = MissingDouble + end if + else ObsError(:) = MissingDouble end if - else if (JediVarHasChannelsLocal) then - ObsError(:) = MissingDouble end if ! Fill the OPS data structures @@ -1053,8 +1055,10 @@ end subroutine opsinputs_fill_fillreal !> Indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediVarName !> Name of the JEDI variable used to populate \p Real2. This can represent a set of variables -!> with suffixes corresponding to the indices specified in \p Channels. If -!> \p JediVarHasChannels is false, the exact variable name is used for each output channel. +!> with suffixes corresponding to the indices specified in \p Channels, or a single variable +!> with no channel suffix (in which case Real2 will have a single row) when no channels are +!> specified. If \p JediVarHasChannels is false, the exact variable name is used for each output +!> channel. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Real2. !> \param[in] JediVarHasChannels From 075a1b9e018e810c442f4172d6206e3e4715bebd Mon Sep 17 00:00:00 2001 From: lewisn-met Date: Thu, 26 Nov 2026 09:41:46 +0000 Subject: [PATCH 5/6] Fix failing ctests --- src/opsinputs/opsinputs_fill_mod.F90 | 54 +++++--------------- src/opsinputs/opsinputs_varobswriter_mod.F90 | 5 +- test/testinput/055_VarField_channum.yaml | 8 --- 3 files changed, 16 insertions(+), 51 deletions(-) diff --git a/src/opsinputs/opsinputs_fill_mod.F90 b/src/opsinputs/opsinputs_fill_mod.F90 index 3df1e768..bc3ff466 100644 --- a/src/opsinputs/opsinputs_fill_mod.F90 +++ b/src/opsinputs/opsinputs_fill_mod.F90 @@ -691,7 +691,6 @@ end subroutine opsinputs_fill_fillelementtypefromnormalvariable !> Pointer to ioda::ObsSpace object containing the specified JEDI variables. The variables can !> have either no channel suffix (when no channel numbers are provided, in which case \p El2 !> will have only a single row) or suffixes representing the indices specified in \p Channels. -!> If \p JediVarHasChannels is false, the exact variable name is used for each output channel. !> \param[in] Channel indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediValueVarName !> Name of the JEDI variable containing observation values. @@ -709,15 +708,13 @@ end subroutine opsinputs_fill_fillelementtypefromnormalvariable !> they are needed for non-simulated variables. If necessary, it could be modified to retrieve !> them from the same group of JEDI variables, GrossErrorProbability, as !> opsinputs_fill_fillelementtype2dfromnormalvariable). -!> \param[in] JediVarHasChannels -!> Optional; defaults to true. If false, use the exact variable name for every output channel. !> !> \note This function returns early (without a warning) if the specified JEDI variable is not found. !> We rely on warnings printed by the OPS code whenever data needed to output a requested varfield !> are not found. subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & Hdr, OpsVarName, NumObs, El2, ObsSpace, Channels, & - JediValueVarName, JediValueGroup, JediErrorVarName, JediErrorGroup, PackPGEs, JediVarHasChannels) + JediValueVarName, JediValueGroup, JediErrorVarName, JediErrorGroup, PackPGEs) implicit none ! Subroutine arguments: @@ -732,11 +729,9 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & character(len=*), optional, intent(in) :: JediErrorVarName character(len=*), optional, intent(in) :: JediErrorGroup logical, optional, intent(in) :: PackPGEs -logical, optional, intent(in) :: JediVarHasChannels ! Local declarations: logical :: DoPackPGEs -logical :: JediVarHasChannelsLocal real(kind=c_double) :: ObsValue(NumObs) real(kind=c_float) :: ObsError(NumObs) real(kind=c_double) :: MissingDouble @@ -763,16 +758,13 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & DoPackPGEs = .true. end if -JediVarHasChannelsLocal = .true. -if (present(JediVarHasChannels)) JediVarHasChannelsLocal = JediVarHasChannels - MissingDouble = missing_value(0.0_c_double) JediValueVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & - JediValueVarName, Channels, JediVarHasChannelsLocal) + JediValueVarName, Channels) if (present(JediErrorVarName)) then JediErrorVarNamesWithChannels = opsinputs_fill_varnames_with_channels( & - JediErrorVarName, Channels, JediVarHasChannelsLocal) + JediErrorVarName, Channels) end if if (obsspace_has(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(1))) then @@ -780,43 +772,25 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & call Ops_Alloc(Hdr, OpsVarName, NumObs, El2, & num_levels = int(size(JediValueVarNamesWithChannels), kind=integer64)) - if (.not. JediVarHasChannelsLocal) then - call obsspace_get_db(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(1), ObsValue) + do iChannel = 1, size(JediValueVarNamesWithChannels) + ! Retrieve data from JEDI: + ! - observation value + call obsspace_get_db(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(iChannel), & + ObsValue) + ! - observation error if (present(JediErrorVarName) .and. present(JediErrorGroup)) then - if (obsspace_has(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(1))) then - call obsspace_get_db(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(1), ObsError) + if (obsspace_has(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel))) then + call obsspace_get_db(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel), & + ObsError) else write (ErrorMessage, '("Variable ",A,"/",A," not found")') & - JediErrorGroup, JediErrorVarNamesWithChannels(1) + JediErrorGroup, JediErrorVarNamesWithChannels(iChannel) call gen_warn(RoutineName, ErrorMessage) ObsError(:) = MissingDouble end if - else + else ObsError(:) = MissingDouble end if - end if - - do iChannel = 1, size(JediValueVarNamesWithChannels) - ! Retrieve data from JEDI: - ! - observation value - if (JediVarHasChannelsLocal) then - call obsspace_get_db(ObsSpace, JediValueGroup, JediValueVarNamesWithChannels(iChannel), & - ObsValue) - ! - observation error - if (present(JediErrorVarName) .and. present(JediErrorGroup)) then - if (obsspace_has(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel))) then - call obsspace_get_db(ObsSpace, JediErrorGroup, JediErrorVarNamesWithChannels(iChannel), & - ObsError) - else - write (ErrorMessage, '("Variable ",A,"/",A," not found")') & - JediErrorGroup, JediErrorVarNamesWithChannels(iChannel) - call gen_warn(RoutineName, ErrorMessage) - ObsError(:) = MissingDouble - end if - else - ObsError(:) = MissingDouble - end if - end if ! Fill the OPS data structures do iObs = 1, NumObs diff --git a/src/opsinputs/opsinputs_varobswriter_mod.F90 b/src/opsinputs/opsinputs_varobswriter_mod.F90 index 23c1f92f..3d336fb9 100644 --- a/src/opsinputs/opsinputs_varobswriter_mod.F90 +++ b/src/opsinputs/opsinputs_varobswriter_mod.F90 @@ -765,7 +765,7 @@ subroutine opsinputs_varobswriter_populateobservations( & call Ops_DeAlloc(Ob % Header % SatId, "SatId", Ob % SatId) end if -! Match the ObsGroup output by filling each output-channel pressure level from the 1D variable. +! Fill each output-channel pressure level from the 1D variable using JediVarHasChannels = .false. call opsinputs_fill_fillcoord2d( & Ob % Header % PlevelsA, "PlevelsA", JediToOpsLayoutMapping, Ob % PlevelsA, & ObsSpace, self % channels, "pressure", "MetaData", JediVarHasChannels = .false.) @@ -1125,8 +1125,7 @@ subroutine opsinputs_varobswriter_populateobservations( & else call opsinputs_fill_fillelementtype2dfromnormalvariable( & Ob % Header % ImpactParam, "ImpactParam", Ob % Header % NumObsLocal, Ob % ImpactParam, & - ObsSpace, self % channels, "impactParameterRO", "MetaData", PackPGEs = .false., & - JediVarHasChannels = .false.) + ObsSpace, self % channels, "impactParameterRO", "MetaData", PackPGEs = .false.) end if case (VarField_RO_Rad_Curv) call opsinputs_fill_fillelementtypefromnormalvariable( & diff --git a/test/testinput/055_VarField_channum.yaml b/test/testinput/055_VarField_channum.yaml index ffbbb5d5..071fbb0a 100644 --- a/test/testinput/055_VarField_channum.yaml +++ b/test/testinput/055_VarField_channum.yaml @@ -40,10 +40,6 @@ observations: "1", "2", "1", "2", "1", "2"] - Plevel: ["100100.0", "100100.0", - "100200.0", "100200.0", - "100300.0", "100300.0", - "100400.0", "100400.0"] ob value: ["2.00000", "0.00000", "1.00000", "2.00000", "1.00000", "2.00000", @@ -109,10 +105,6 @@ observations: "1", "2", "1", "2", "1", "2"] - Plevel: ["100100.0", "100100.0", - "100200.0", "100200.0", - "100300.0", "100300.0", - "100400.0", "100400.0"] ob value: ["17.00000", "0.00000", "16.00000", "17.00000", "16.00000", "17.00000", From 2bee8ff0126fab893c1a62b805dbd02c0566df3e Mon Sep 17 00:00:00 2001 From: lewisn-met Date: Thu, 26 Nov 2026 10:14:17 +0000 Subject: [PATCH 6/6] Fix trailing whitespace --- src/opsinputs/opsinputs_fill_mod.F90 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/opsinputs/opsinputs_fill_mod.F90 b/src/opsinputs/opsinputs_fill_mod.F90 index bc3ff466..575606c8 100644 --- a/src/opsinputs/opsinputs_fill_mod.F90 +++ b/src/opsinputs/opsinputs_fill_mod.F90 @@ -688,8 +688,8 @@ end subroutine opsinputs_fill_fillelementtypefromnormalvariable !> \param[inout] El2 !> Pointer to the array to be populated. !> \param[in] ObsSpace -!> Pointer to ioda::ObsSpace object containing the specified JEDI variables. The variables can -!> have either no channel suffix (when no channel numbers are provided, in which case \p El2 +!> Pointer to ioda::ObsSpace object containing the specified JEDI variables. The variables can +!> have either no channel suffix (when no channel numbers are provided, in which case \p El2 !> will have only a single row) or suffixes representing the indices specified in \p Channels. !> \param[in] Channel indices returned by ioda::ObsSpace::obsvariables().channels(). !> \param[in] JediValueVarName @@ -788,7 +788,7 @@ subroutine opsinputs_fill_fillelementtype2dfromnormalvariable( & call gen_warn(RoutineName, ErrorMessage) ObsError(:) = MissingDouble end if - else + else ObsError(:) = MissingDouble end if @@ -1030,8 +1030,8 @@ end subroutine opsinputs_fill_fillreal !> \param[in] JediVarName !> Name of the JEDI variable used to populate \p Real2. This can represent a set of variables !> with suffixes corresponding to the indices specified in \p Channels, or a single variable -!> with no channel suffix (in which case Real2 will have a single row) when no channels are -!> specified. If \p JediVarHasChannels is false, the exact variable name is used for each output +!> with no channel suffix (in which case Real2 will have a single row) when no channels are +!> specified. If \p JediVarHasChannels is false, the exact variable name is used for each output !> channel. !> \param[in] JediGroup !> Group name of the JEDI variable used to populate \p Real2.