IODA Bundle
CompareTool.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/exception/Exceptions.h"
12 #include "eckit/filesystem/PathName.h"
13 #include "eckit/log/Log.h"
14 #include "eckit/utils/StringTools.h"
15 #include "eckit/log/Timer.h"
16 #include "odc/Comparator.h"
17 #include "odc/Reader.h"
18 #include "odc/tools/CompareTool.h"
19 
20 using namespace std;
21 using namespace eckit;
22 
23 namespace odc {
24 namespace tool {
25 
26 CompareTool::CompareTool (int argc, char *argv[])
27 : Tool(argc, argv)
28 {
29  registerOptionWithArgument("-excludeColumnsTypes");
30  registerOptionWithArgument("-excludeColumns");
31  if (parameters().size() != 3)
32  {
33  Log::error() << "Usage:";
35  Log::error() << std::endl;
36  throw Exception("Wrong number of parameters.");
37  }
38 
39  PathName p;
40  if (! (p = PathName(parameters()[1])).exists()
41  || ! (p = PathName(parameters()[2])).exists())
42  {
43  stringstream s;
44  s << "File " << p << " does not exist.";
45  throw Exception(s.str());
46  }
47 
48  file1_ = new PathName(parameters()[1]);
49  file2_ = new PathName(parameters()[2]);
50 }
51 
52 
54 {
55  Timer t(std::string("Comparing files ") + *file1_ + " and " + *file2_);
56  odc::Reader oda1(*file1_);
57  odc::Reader oda2(*file2_);
58 
59  odc::Reader::iterator it1(oda1.begin());
60  odc::Reader::iterator end1(oda1.end());
61  odc::Reader::iterator it2(oda2.begin());
62  odc::Reader::iterator end2(oda2.end());
63 
64  std::vector<std::string> excludedColumnsTypes = StringTools::split(",", optionArgument("-excludeColumnsTypes", std::string("")));
65  std::vector<std::string> excludedColumns = StringTools::split(",", optionArgument("-excludeColumns", std::string("")));
66 
67  if (excludedColumnsTypes.size()) {
68  Log::info() << "excludedColumnsTypes:" << excludedColumnsTypes << std::endl;
69  }
70 
71  if (excludedColumns.size()) {
72  Log::info() << "excludedColumns:" << excludedColumns << std::endl;
73  }
74 
75  bool checkMissing = ! optionIsSet("-dontCheckMissing");
76  odc::Comparator(checkMissing).compare(it1, end1, it2, end2, *file1_, *file2_, excludedColumnsTypes, excludedColumns);
77 }
78 
79 } // namespace tool
80 } // namespace odc
81 
bool compare(T1 &it1, const T1 &end1, T2 &it2, const T2 &end2, const std::string &desc1, const std::string &desc2)
Definition: Comparator.h:108
const iterator end() const
Definition: Reader.cc:81
iterator begin()
Definition: Reader.cc:74
bool optionIsSet(const std::string &)
T optionArgument(const std::string &, T defaultValue)
void registerOptionWithArgument(const std::string &)
const std::vector< std::string > parameters()
static void usage(const std::string &name, std::ostream &o)
Definition: CompareTool.h:33
eckit::PathName * file1_
Definition: CompareTool.h:46
eckit::PathName * file2_
Definition: CompareTool.h:47
Definition: ColumnInfo.h:23
Definition: encode.cc:30