Skip to content

Commit

Permalink
write out a file using IODA
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryMartin-NOAA committed Aug 11, 2023
1 parent d34ab08 commit 2980657
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
42 changes: 42 additions & 0 deletions utils/ioda_example/gdas_meanioda.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include <string>
#include <vector>
#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"
Expand Down Expand Up @@ -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<int>("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<float>(-999); // set the fill value to -999
ioda::Variable outVar = og.vars.createWithScales<float>(varname, {LocationVar}, float_params);

// write to file
std::vector<float> 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;
Expand Down
1 change: 1 addition & 0 deletions utils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions utils/test/testinput/gdas_meanioda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2980657

Please sign in to comment.