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