Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryMartin-NOAA committed Aug 7, 2023
1 parent e51dfad commit 233fb7a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions utils/ioda_example/gdas_meanioda.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include "oops/util/Logger.h"

namespace gdasapp {
// this is an example of how one can use OOPS and IODA to do something
// in this code, we will read in configuration from YAML
// and then use that configuration to read in a IODA formatted file,
// read one group/variable (with optional channel)
// and compute and print out the mean of the variable.
// Nothing fancy, but you can see how this could be expanded!

class IodaExample : public oops::Application {
public:
Expand All @@ -23,7 +29,7 @@ namespace gdasapp {
// get the obs space configuration
const eckit::LocalConfiguration obsConfig(fullConfig, "obs space");
ioda::ObsTopLevelParameters obsparams;
obsparams.validateAndDeserialize(obsConfig);
obsparams.validateAndDeserialize(obsConfig); // TODO CRM, can I remove this and then the simulated vars junk??
oops::Log::info() << "obs space: " << std::endl << obsConfig << std::endl;
// time window stuff
std::string winbegin;
Expand All @@ -40,20 +46,25 @@ namespace gdasapp {
fullConfig.get("channel", chan);
}
// read the obs space
// Note, the below line does a lot of heavy lifting
// we can probably go to a lower level function (and more of them) to accomplish the same thing
ioda::ObsSpace ospace(obsparams, oops::mpi::world(), util::DateTime(winbegin), util::DateTime(winend), oops::mpi::myself());
const size_t nlocs = ospace.nlocs();
oops::Log::info() << "nlocs =" << nlocs << std::endl;
std::vector<float> buffer(nlocs);
// below is grabbing from the IODA obs space the specified group/variable and putting it into the buffer
if (chan == 0) {
// no channel is selected
ospace.get_db(group, variable, buffer);
} else {
// give it the channel as a single item list
ospace.get_db(group, variable, buffer, {chan});
}
// the below line computes the mean, aka sum divided by count
const float mean = std::reduce(buffer.begin(), buffer.end()) / float(nlocs);
// write the mean out to the stdout
oops::Log::info() << "mean value for " << group << "/" << variable << "=" << mean << std::endl;

// a better program should return a real exit code depending on result, but this is just an example!
return 0;
}
// -----------------------------------------------------------------------------
Expand Down

0 comments on commit 233fb7a

Please sign in to comment.