IODA Bundle
XYVTool.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 "odc/tools/XYVTool.h"
12 
13 #include <fstream>
14 
15 #include "eckit/filesystem/PathName.h"
16 #include "eckit/log/Log.h"
17 #include "odc/Select.h"
18 
19 using namespace std;
20 using namespace eckit;
21 
22 namespace odc {
23 namespace tool {
24 
25 XYVTool::XYVTool(int argc,char **argv): Tool(argc, argv) {}
26 
28 
30 {
31  if (parameters().size() != 4)
32  {
33  Log::error() << "Usage: ";
35  Log::error() << std::endl;
36  return;// 1;
37  }
38 
39  PathName inputFile = parameters(1);
40  std::string valueColumn = parameters(2);
41  PathName outputFile = parameters(3);
42 
43  std::ofstream out;
44  out.open(outputFile.asString().c_str());
45 
46  out << "#GEO" << std::endl << std::endl;
47  out << "#FORMAT XYV" << std::endl << std::endl;
48  out << "PARAMETER = 12004" << std::endl << std::endl;
49  out << "x/long y/lat value" << std::endl;
50  out << "#DATA" << std::endl << std::endl;
51 
52  std::string select = std::string("select lat, lon, ") + valueColumn + " from \"" + inputFile + "\";";
53  Log::info() << select << std::endl;
54 
55  odc::Select oda(select);
56  for (odc::Select::iterator it = oda.begin();
57  it != oda.end();
58  ++it)
59  {
60  out << (*it)[0] << "\t" << (*it)[1] << "\t" << (*it)[2] << std::endl;
61  }
62  out.close();
63 }
64 
65 } // namespace tool
66 } // namespace odc
67 
void oda
const std::vector< std::string > parameters()
static void usage(const std::string &name, std::ostream &o)
Definition: XYVTool.h:30
virtual void run()
Definition: XYVTool.cc:29
Definition: ColumnInfo.h:23
Definition: encode.cc:30