IODA Bundle
CountTool.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 #include "eckit/eckit.h"
12 #include "odc/core/MetaData.h"
13 #include "odc/core/TablesReader.h"
14 #include "odc/Reader.h"
15 #include "odc/tools/CountTool.h"
16 
17 using namespace eckit;
18 
19 namespace odc {
20 namespace tool {
21 
22 CountTool::CountTool (int argc, char *argv[]) : Tool(argc, argv) { }
23 
24 size_t CountTool::rowCount(const PathName &db)
25 {
26  odc::core::TablesReader reader(db);
27  auto it = reader.begin();
28  auto end = reader.end();
29 
30  size_t n = 0;
31 
32  for (; it != end; ++it) {
33  n += it->rowCount();
34  }
35 
36  return n;
37 }
38 
40 {
41  if (parameters().size() < 2)
42  {
43  Log::error() << "Usage: ";
45  Log::error() << std::endl;
46  return;
47  }
48 
49  unsigned long long n (0);
50  for (size_t i (1); i < parameters().size(); ++i)
51  {
52  const std::string fileName (parameters(i));
53 
54  Log::debug() << "CountTool: counting " << fileName << std::endl;
55 
56  n += rowCount(fileName);
57  }
58 
59  std::cout << n << std::endl;
60 }
61 
62 } // namespace tool
63 } // namespace odc
64 
size_t rowCount() const
Definition: Table.cc:50
const std::vector< std::string > parameters()
static void usage(const std::string &name, std::ostream &o)
Definition: CountTool.h:32
static size_t rowCount(const eckit::PathName &)
Definition: CountTool.cc:24
Definition: ColumnInfo.h:23