From 298065701bc89c569d50d9b3d17fac179c7506aa Mon Sep 17 00:00:00 2001 From: CoryMartin-NOAA Date: Fri, 11 Aug 2023 13:56:25 +0000 Subject: [PATCH 1/2] write out a file using IODA --- utils/ioda_example/gdas_meanioda.h | 42 +++++++++++++++++++++++++ utils/test/CMakeLists.txt | 1 + utils/test/testinput/gdas_meanioda.yaml | 4 +++ 3 files changed, 47 insertions(+) diff --git a/utils/ioda_example/gdas_meanioda.h b/utils/ioda_example/gdas_meanioda.h index 4184abefb..d61e5f7e9 100644 --- a/utils/ioda_example/gdas_meanioda.h +++ b/utils/ioda_example/gdas_meanioda.h @@ -5,7 +5,10 @@ #include #include #include "eckit/config/LocalConfiguration.h" +#include "ioda/Engines/EngineUtils.h" #include "ioda/Group.h" +#include "ioda/ObsDataIoParameters.h" +#include "ioda/ObsGroup.h" #include "ioda/ObsSpace.h" #include "ioda/ObsVector.h" #include "oops/base/PostProcessor.h" @@ -80,6 +83,45 @@ namespace gdasapp { oops::Log::info() << "mean value for " << group << "/" << variable << "=" << mean << std::endl; + // let's try writing the mean out to a IODA file now! + //////////////////////////////////////////////////// + // get the configuration for the obsdataout + eckit::LocalConfiguration outconf(fullConfig, "obsdataout"); + ioda::ObsDataOutParameters outparams; + outparams.validateAndDeserialize(outconf); + + // set up the backend + auto backendParams = ioda::Engines::BackendCreationParameters(); + backendParams.fileName = outconf.getString("engine.obsfile"); + backendParams.createMode = ioda::Engines::BackendCreateModes::Truncate_If_Exists; + backendParams.action = ioda::Engines::BackendFileActions::Create; + backendParams.flush = true; + backendParams.allocBytes = 1024*1024*50; // no idea what this number should be + + // construct the output group(s) + ioda::Group grpFromFile = ioda::Engines::constructBackend(ioda::Engines::BackendNames::Hdf5File, backendParams); + const int numLocs = 1; + ioda::NewDimensionScales_t newDims; + newDims.push_back(ioda::NewDimensionScale("Location", numLocs, ioda::Unlimited, numLocs)); + ioda::ObsGroup og = ioda::ObsGroup::generate(grpFromFile, newDims); + + // create the output variables + ioda::Variable LocationVar = og.vars["Location"]; + std::string varname = "mean/" + group + "/" + variable; + ioda::VariableCreationParameters float_params; + float_params.chunk = true; // allow chunking + float_params.compressWithGZIP(); // compress using gzip + float_params.setFillValue(-999); // set the fill value to -999 + ioda::Variable outVar = og.vars.createWithScales(varname, {LocationVar}, float_params); + + // write to file + std::vector meanVec(numLocs); + meanVec[0] = mean; + outVar.write(meanVec); + + // print a message + oops::Log::info() << "mean written to" << backendParams.fileName << std::endl; + // a better program should return a real exit code depending on result, // but this is just an example! return 0; diff --git a/utils/test/CMakeLists.txt b/utils/test/CMakeLists.txt index 42f0a9de1..23a126909 100644 --- a/utils/test/CMakeLists.txt +++ b/utils/test/CMakeLists.txt @@ -4,6 +4,7 @@ list( APPEND utils_test_input ) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testinput) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testrun) CREATE_SYMLINK( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${utils_test_input} ) # copy the cpp linter script diff --git a/utils/test/testinput/gdas_meanioda.yaml b/utils/test/testinput/gdas_meanioda.yaml index ff71b1870..ef4dc0ed5 100644 --- a/utils/test/testinput/gdas_meanioda.yaml +++ b/utils/test/testinput/gdas_meanioda.yaml @@ -14,3 +14,7 @@ group: ObsValue variable: brightnessTemperature # channel is optional, depends on what variable you are reading channel: 6 +obsdataout: + engine: + type: H5File + obsfile: testrun/gmi_gpm_mean.nc From 4effcb2586003aa4d9450d52c4f5b64ff89e2dd4 Mon Sep 17 00:00:00 2001 From: CoryMartin-NOAA Date: Fri, 11 Aug 2023 14:01:05 +0000 Subject: [PATCH 2/2] de-lint --- utils/ioda_example/gdas_meanioda.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/ioda_example/gdas_meanioda.h b/utils/ioda_example/gdas_meanioda.h index d61e5f7e9..de382ad9c 100644 --- a/utils/ioda_example/gdas_meanioda.h +++ b/utils/ioda_example/gdas_meanioda.h @@ -99,10 +99,12 @@ namespace gdasapp { backendParams.allocBytes = 1024*1024*50; // no idea what this number should be // construct the output group(s) - ioda::Group grpFromFile = ioda::Engines::constructBackend(ioda::Engines::BackendNames::Hdf5File, backendParams); + ioda::Group grpFromFile + = ioda::Engines::constructBackend(ioda::Engines::BackendNames::Hdf5File, backendParams); const int numLocs = 1; ioda::NewDimensionScales_t newDims; - newDims.push_back(ioda::NewDimensionScale("Location", numLocs, ioda::Unlimited, numLocs)); + newDims.push_back(ioda::NewDimensionScale("Location", + numLocs, ioda::Unlimited, numLocs)); ioda::ObsGroup og = ioda::ObsGroup::generate(grpFromFile, newDims); // create the output variables @@ -112,7 +114,7 @@ namespace gdasapp { float_params.chunk = true; // allow chunking float_params.compressWithGZIP(); // compress using gzip float_params.setFillValue(-999); // set the fill value to -999 - ioda::Variable outVar = og.vars.createWithScales(varname, {LocationVar}, float_params); + ioda::Variable outVar = og.vars.createWithScales(varname, {LocationVar}, float_params); // write to file std::vector meanVec(numLocs);