Skip to content

Commit

Permalink
fix refdate
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumevernieres committed Nov 13, 2023
1 parent 5c8526f commit 6ce36a5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion utils/obsproc/Ghrsst2Ioda.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <iostream>
#include <netcdf> // NOLINT (using C API)
#include <regex>
#include <string>
#include <vector>

Expand Down Expand Up @@ -67,12 +68,24 @@ namespace gdasapp {
}
}

// datetime: Read Reference Time
// Read the reference time
std::vector<int32_t> 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<int32_t> sstdTime(dimTime*dimLat*dimLon);
Expand Down
1 change: 1 addition & 0 deletions utils/obsproc/NetCDFToIodaConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() <<
Expand Down
2 changes: 2 additions & 0 deletions utils/test/testref/ghrsst2ioda.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Reading ghrsst_sst_mb_202107010000.nc4
seconds since 1981-01-01T00:00:00Z
obsVal:
Min: 276.708
Max: 276.9
Expand All @@ -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
Expand Down

0 comments on commit 6ce36a5

Please sign in to comment.