From 6ce36a58d6c4e3ca38dcfb53850aa4b0381e4316 Mon Sep 17 00:00:00 2001 From: Guillaume Vernieres Date: Mon, 13 Nov 2023 16:43:19 -0500 Subject: [PATCH] fix refdate --- utils/obsproc/Ghrsst2Ioda.h | 15 ++++++++++++++- utils/obsproc/NetCDFToIodaConverter.h | 1 + utils/test/testref/ghrsst2ioda.test | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/utils/obsproc/Ghrsst2Ioda.h b/utils/obsproc/Ghrsst2Ioda.h index 1d1deebec..64b5ed28b 100644 --- a/utils/obsproc/Ghrsst2Ioda.h +++ b/utils/obsproc/Ghrsst2Ioda.h @@ -2,6 +2,7 @@ #include #include // NOLINT (using C API) +#include #include #include @@ -67,12 +68,24 @@ namespace gdasapp { } } - // datetime: Read Reference Time + // Read the reference time std::vector refTime(dimTime); ncFile.getVar("time").getVar(refTime.data()); std::string refDate; ncFile.getVar("time").getAtt("units").getValues(refDate); + // Reformat the reference time + std::regex dateRegex(R"(\b\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\b)"); + std::smatch match; + std::regex_search(refDate, match, dateRegex); + refDate = match.str(); + std::tm tmStruct = {}; + std::istringstream ss(refDate); + ss >> std::get_time(&tmStruct, "%Y-%m-%d %H:%M:%S"); + std::ostringstream isoFormatted; + isoFormatted << std::put_time(&tmStruct, "seconds since %Y-%m-%dT%H:%M:%SZ"); + refDate = isoFormatted.str(); + // Read sst_dtime to add to the reference time // TODO(AMG): What's below does not read the field the same way python does std::vector sstdTime(dimTime*dimLat*dimLon); diff --git a/utils/obsproc/NetCDFToIodaConverter.h b/utils/obsproc/NetCDFToIodaConverter.h index 49a372b83..428e2f69d 100644 --- a/utils/obsproc/NetCDFToIodaConverter.h +++ b/utils/obsproc/NetCDFToIodaConverter.h @@ -158,6 +158,7 @@ namespace gdasapp { // Testing void testOutput() { + oops::Log::test() << referenceDate_ << std::endl; oops::Log::test() << gdasapp::testutils::checksum(obsVal_, "obsVal") << std::endl; oops::Log::test() << diff --git a/utils/test/testref/ghrsst2ioda.test b/utils/test/testref/ghrsst2ioda.test index 652fd10bc..c8e895e1e 100644 --- a/utils/test/testref/ghrsst2ioda.test +++ b/utils/test/testref/ghrsst2ioda.test @@ -1,4 +1,5 @@ Reading ghrsst_sst_mb_202107010000.nc4 +seconds since 1981-01-01T00:00:00Z obsVal: Min: 276.708 Max: 276.9 @@ -24,6 +25,7 @@ datetime: Max: 1277942528 Sum: 23002965504 Reading ghrsst_sst_mb_202107010100.nc4 +seconds since 1981-01-01T00:00:00Z obsVal: Min: 281.547 Max: 281.714