IODA Bundle
TestIntegerValues.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
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  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// \file TestIntegerValues.h
12 ///
13 /// @author Piotr Kuchta, ECMWF, Jan 2011
14 
15 #include "eckit/filesystem/PathName.h"
16 #include "eckit/io/FileHandle.h"
17 
18 #include "odc/Reader.h"
19 #include "odc/api/Odb.h"
20 
21 
22 #include "TestCase.h"
23 
24 
25 
26 
27 
28 using namespace std;
29 using namespace eckit;
30 using namespace odc;
31 
32 static void setUp()
33 {
34  const char* data =
35  "date:REAL\n"
36  "20101130\n"
37  "20101201\n"
38  "20101202\n";
39  FileHandle dh("TestIntegerValues.odb");
40  dh.openForWrite(0);
41  AutoClose close(dh);
42  odc::api::odbFromCSV(data, dh);
43 }
44 
45 
46 static void test()
47 {
48  //Log::info() << fixed;
49  ////////////////////////////// ODB from MARS //////////////////////////////
50 
51  const std::string fileNameOdb="TestIntegerValues.odb";
52 
53  odc::Reader odb(fileNameOdb);
54  odc::Reader::iterator it = odb.begin();
55 
56  for (unsigned int i=0; i < it->columns().size(); ++i) {
57  std::cout << "Name = " << it->columns()[i]->name() << " " ;
58  }
59 
60  std::cout << std::endl;
61  int nrows=0;
62  for(; it != odb.end(); ++it)
63  {
64  ++nrows;
65  for (size_t i=0; i < it->columns().size(); ++i)
66  {
67  //float nr = ((*it)[i]); /// <- WRONG!
68  double nr = ((*it)[i]);
69  switch(it->columns()[i]->type())
70  {
71  case odc::api::INTEGER:
72  case odc::api::BITFIELD:
73  std::cout << static_cast<int>(nr) << " ";
74  //cout << "* should be: " << it->integer(i) << " ";
75  break;
76  case odc::api::REAL:
77  std::cout << nr << " ";
78  break;
79  case odc::api::IGNORE:
80  default:
81  ASSERT("Unknown type" && false);
82  break;
83  }
84  }
85  std::cout << std::endl;
86  }
87 }
88 
89 static void tearDown() { }
90 
91 
92 SIMPLE_TEST(IntegerValues)
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
static void tearDown()
static void test()
static void setUp()
const iterator end() const
Definition: Reader.cc:81
iterator begin()
Definition: Reader.cc:74
const core::MetaData & columns() const
Definition: IteratorProxy.h:94
size_t odbFromCSV(DataHandle &dh_in, DataHandle &dh_out, const std::string &delimiter)
odbFromCSV returns number of lines imported
Definition: Odb.cc:375
@ BITFIELD
Definition: ColumnType.h:27
Definition: ColumnInfo.h:23
Definition: encode.cc:30