IODA Bundle
StrVecDataObject.cpp
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 NOAA/NWS/NCEP/EMC
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #include <iostream>
9 
10 #include "StrVecDataObject.h"
11 
12 
13 namespace Ingester
14 {
15  StrVecDataObject::StrVecDataObject(const std::vector<std::string>& strVector) :
16  strVector_(strVector)
17  {
18  }
19 
21  const std::string& name,
22  const std::vector<ioda::Variable>& dimensions,
23  const std::vector<ioda::Dimensions_t>& chunks,
24  int compressionLevel)
25  {
26  auto params = makeCreationParams(chunks, compressionLevel);
27  auto var = obsGroup.vars.createWithScales<std::string>(name, dimensions, params);
28  var.write(strVector_);
29  return var;
30  }
31 
33  {
34  for (const auto& str : strVector_)
35  {
36  std::cout << str << std::endl;
37  }
38  }
39 
40  size_t StrVecDataObject::nrows() const
41  {
42  return strVector_.size();
43  }
44 
45  size_t StrVecDataObject::ncols() const
46  {
47  return 1;
48  }
49 
51  const std::vector<ioda::Dimensions_t>& chunks,
52  int compressionLevel)
53  {
55  params.chunk = true;
56  params.chunks = chunks;
57  params.compressWithGZIP(compressionLevel);
58 
59  return params;
60  }
61 } // namespace Ingester
const std::vector< std::string > strVector_
The data.
void print() const final
Print data to stdout for debug purposes.
StrVecDataObject(const std::vector< std::string > &strVector)
static ioda::VariableCreationParameters makeCreationParams(const std::vector< ioda::Dimensions_t > &chunks, int compressionLevel)
Create an ioda::VariableCreationParameters for the data.
ioda::Variable createVariable(ioda::ObsGroup &obsGroup, const std::string &name, const std::vector< ioda::Variable > &dimensions, const std::vector< ioda::Dimensions_t > &chunks, int compressionLevel) final
Makes an ioda::Variable and ads it to the given ioda::ObsGroup.
size_t ncols() const final
Get the number of columns represented in the data.
size_t nrows() const final
Get the number of rows represented in the data.
An ObsGroup is a specialization of a ioda::Group. It provides convenience functions and guarantees th...
Definition: ObsGroup.h:32
Has_Variables vars
Use this to access variables.
Definition: Group.h:123
Variable createWithScales(const std::string &name, const std::vector< Variable > &dimension_scales, const VariableCreationParameters &params=VariableCreationParameters::defaulted< DataType >())
Convenience function to create a Variable from certain dimension scales.
virtual Variable write(gsl::span< char > data, const Type &in_memory_dataType, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all)
The fundamental write function. Backends overload this function to implement all write operations.
Definition: Variable.cpp:317
Used to specify Variable creation-time properties.
Definition: Has_Variables.h:57