15 #include "odc/Select.h"
16 #include "odc/api/odc.h"
27 for (
int i = 0; i <
columns_.size(); i++) {
39 size_t val =
getData(i, varno_index);
49 if (varno ==
varnos_.at(i))
return true;
66 odc::Select sodb(sql);
67 odc::Select::iterator begin = sodb.begin();
69 for (
size_t i = 0; i < begin->columns().size(); i++) {
72 for (
auto &row : sodb) {
73 for (
size_t i = 0; i < begin->columns().size(); i++) {
74 setData(rowNumber, i, (row)[i]);
88 NewDimensionScale<int>(
"nlocs", num_rows, num_rows, num_rows));
91 vertcos.push_back(NewDimensionScale<int>(
"nchans", number_of_levels,
92 number_of_levels, number_of_levels));
95 vertcos.push_back(NewDimensionScale<int>(
"nchans", number_of_levels,
96 number_of_levels, number_of_levels));
99 vertcos.push_back(NewDimensionScale<int>(
"nchans", number_of_levels,
100 number_of_levels, number_of_levels));
107 vertcos.push_back(NewDimensionScale<int>(
"nchans", number_of_levels,
108 number_of_levels, number_of_levels));
111 vertcos.push_back(NewDimensionScale<int>(
"nchans", number_of_levels,
112 number_of_levels, number_of_levels));
115 vertcos.push_back(NewDimensionScale<int>(
"nchans", number_of_levels,
116 number_of_levels, number_of_levels));
119 vertcos.push_back(NewDimensionScale<int>(
"nchans", number_of_levels,
120 number_of_levels, number_of_levels));
138 if (column_index != -1) {
142 size_t seqno_new =
getData(i, seqno_index);
143 int varno =
getData(i, varno_index);
152 arr[j] =
getData(i, column_index);
166 if (column_index != -1) {
170 size_t seqno_new =
getData(i, seqno_index);
171 int varno =
getData(i, varno_index);
180 arr[j] =
getData(i, column_index);
193 std::vector<std::string> arr;
194 if (column_index != -1) {
197 size_t seqno_new =
getData(i, seqno_index);
198 int varno =
getData(i, varno_index);
210 double ud =
getData(i, column_index);
211 strncpy(uc,
reinterpret_cast<char*
>(&ud), 8);
215 std::string s = std::string(uc);
216 size_t endpos = s.find_last_not_of(
" ");
217 size_t startpos = s.find_first_not_of(
" ");
218 if (std::string::npos != endpos) {
219 s = s.substr(0, endpos + 1);
220 s = s.substr(startpos);
222 s.erase(std::remove(std::begin(s), std::end(s),
' '), std::end(s));
236 std::string
const& col,
237 const int nchans = 1,
238 const int nchans_actual = 1)
const {
245 for (
auto& it : varnos) {
251 if (column_index != -1 && varno_index != -1) {
254 if (std::find(varnos.begin(), varnos.end(),
getData(i, varno_index)) != varnos.end()) {
255 arr[j] =
getData(i, column_index);
262 if (column_index != -1 && varno_index != -1) {
266 if (std::find(varnos.begin(), varnos.end(),
getData(i, varno_index)) != varnos.end()) {
268 arr[j] =
getData(i, column_index);
270 if (k_chan > nchans_actual) {
271 j += (nchans - nchans_actual);
282 const std::vector<int>& varnos,
const std::string& query) {
284 std::string sql =
"select ";
285 for (
int i = 0; i <
columns_.size(); i++) {
292 sql = sql +
" from \"" + filename +
"\" where (";
293 for (
int i = 0; i < varnos.size(); i++) {
295 sql = sql +
"varno = " + std::to_string(varnos.at(i));
297 sql = sql +
" or varno = " + std::to_string(varnos.at(i));
301 if (!query.empty()) {
302 sql = sql +
" and (" + query +
");";
313 int varno =
getData(i, varno_column);
328 size_t seqno_new =
getData(i, seqno_index);
329 if (seqno != seqno_new) {
346 std::string
const& time_col)
const {
349 std::vector<std::string> date_strings;
350 date_strings.reserve(var_date.size());
352 const std::string missingDateTime =
"9996-02-29T23:58:57Z";
353 for (
int i = 0; i < var_date.size(); i++) {
354 std::string datetimestring;
356 int year = var_date[i] / 10000;
357 int month = var_date[i] / 100 - year * 100;
358 int day = var_date[i] - 10000 * year - 100 * month;
359 int hour = var_time[i] / 10000;
360 int minute = var_time[i] / 100 - hour * 100;
361 int second = var_time[i] - 10000 * hour - 100 * minute;
362 std::ostringstream stream;
363 stream << year <<
"-" << std::setfill(
'0') << std::setw(2) << month <<
"-" << std::setfill(
'0')
364 << std::setw(2) << day <<
"T" << std::setfill(
'0') << std::setw(2) << hour <<
":"
365 << std::setfill(
'0') << std::setw(2) << minute <<
":" << std::setfill(
'0')
366 << std::setw(2) << second <<
"Z";
367 datetimestring = stream.str();
369 datetimestring = missingDateTime;
371 date_strings.push_back(std::move(datetimestring));
382 std::vector<std::string> vard;
393 v =
og.vars.createWithScales<
int>(column, {
og.vars[
"nlocs"]}, params_copy);
394 v.writeWithEigenRegular(vari);
398 v =
og.vars.createWithScales<
float>(column, {
og.vars[
"nlocs"]}, params_copy);
399 v.writeWithEigenRegular(var);
401 v =
og.vars.createWithScales<std::string>(column, {
og.vars[
"nlocs"]},
params);
427 const std::vector<int> varnos{varno};
430 const std::vector<int> varnos{varno};
439 const std::vector<int> varnos{varno};
442 const std::vector<int> varnos{varno};
445 const std::vector<int> varnos{varno};
452 int number_of_levels;
458 if (number_of_levels <= 0)
return v;
460 v =
og.vars.createWithScales<
float>(std::to_string(varno), {
og.vars[
"nlocs"]}, params_copy);
462 v =
og.vars.createWithScales<
float>(std::to_string(varno),
463 {
og.vars[
"nlocs"],
og.vars[
"nchans"]}, params_copy);
470 odc::Select sodb(sql);
471 odc::Select::iterator it = sodb.begin();
472 odc::Select::iterator end = sodb.end();
473 size_t totalRows = 0;
474 for (; it != end; ++it) {
std::map< int, size_t > varnos_and_levels_
std::vector< std::string > getDates(std::string const &date_col, std::string const &time_col) const
Returns a vector of date strings.
NewDimensionScales_t getVertcos() const
Returns the dimensions for the ODB.
size_t numberOfRowsForVarno(int varno) const
Returns the number of rows for a particular varno.
int getObsgroup() const
Returns the obsgroup number.
Eigen::ArrayXf getMetadataColumn(std::string const &column) const
Returns data for a (metadata) column.
Eigen::ArrayXf getVarnoColumn(const std::vector< int > &varnos, std::string const &column, const int nchans, const int nchans_actual) const
Returns data for a varno for a varno column.
Eigen::ArrayXi getMetadataColumnInt(std::string const &column) const
Returns data for a (metadata) column.
bool hasVarno(int varno) const
Returns true if a particular varno is present.
size_t numberOfMetadataRows() const
Returns the number of "metadata" rows, i.e. hdr-type rows.
ioda::Variable getIodaObsvalue(int varno, ioda::ObsGroup og, ioda::VariableCreationParameters params) const
Returns an ioda variable for a specified column.
std::vector< double > data_
DataFromSQL()
Simple constructor.
void setData(size_t row, size_t column, double val)
Set a value for a row,column element.
std::vector< int > varnos_
std::vector< int > column_types_
ioda::Variable getIodaVariable(std::string const &column, ioda::ObsGroup og, ioda::VariableCreationParameters params) const
Returns an ioda variable for a specified column.
size_t number_of_metadata_rows_
std::vector< std::string > getMetadataStringColumn(std::string const &column) const
Returns data for a (metadata) column.
int getColumnIndex(const std::string &column) const
Returns the index of a specified column.
size_t numberOfLevels(int varno) const
Returns the number of levels for each varno.
static size_t countRows(const std::string &sql)
Returns a count of the rows extracted by an sql.
double getData(size_t row, size_t column) const
Returns the value for a particular row/column.
const std::vector< std::string > & getColumns() const
Returns a vector of columns.
std::vector< std::string > columns_
int getColumnTypeByName(std::string const &column) const
Returns the type of a specified column.
void select(const std::vector< std::string > &columns, const std::string &filename, const std::vector< int > &varnos, const std::string &query)
Populate structure with data from specified columns, file and varnos.
An ObsGroup is a specialization of a ioda::Group. It provides convenience functions and guarantees th...
Variable_Implementation writeWithEigenRegular(const EigenClass &d, const Selection &mem_selection=Selection::all, const Selection &file_selection=Selection::all)
Write an Eigen object (a Matrix, an Array, a Block, a Map).
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.
static constexpr int obsgroup_ssmis
static constexpr int obsgroup_gmilow
static constexpr int varno_rawsca
static constexpr int obsgroup_surfacecloud
static constexpr int obsgroup_abiclr
static constexpr int obsgroup_sonde
static constexpr int obsgroup_gpsro
static constexpr int obsgroup_iasi
static constexpr int varno_cloud_fraction_covered
static constexpr int odb_type_real
static constexpr int varno_rawbt_amsu
static constexpr int obsgroup_atms
static constexpr int obsgroup_atovs
static constexpr int obsgroup_airs
static constexpr int varno_rawbt_mwts
static constexpr int obsgroup_ahiclr
static constexpr int obsgroup_cris
static constexpr int odb_missing_int
static constexpr int obsgroup_seviriclr
static constexpr int obsgroup_mwsfy3
static constexpr float odb_missing_float
static constexpr int odb_type_int
static constexpr int obsgroup_amsr
static constexpr int varno_rawbt_mwhs
static constexpr int obsgroup_mwri
static constexpr int obsgroup_gmihigh
static constexpr int obsgroup_hiras
static constexpr int varno_rawbt_amsr_89ghz
static constexpr int obsgroup_geocloud
static constexpr int odb_type_bitfield
static constexpr int varno_rawbt
static constexpr int obsgroup_scatwind
std::vector< std::shared_ptr< NewDimensionScale_Base > > NewDimensionScales_t
Used to specify Variable creation-time properties.
VariableCreationParameters & setFillValue(DataType fill)