LOOS  v2.3.2
griddiff.cpp
1 /*
2  griddiff.cpp
3 
4  Subtract one grid from another (required grids to match)
5 
6 */
7 
8 /*
9  This file is part of LOOS.
10 
11  LOOS (Lightweight Object-Oriented Structure library)
12  Copyright (c) 2012, Tod D. Romo, Alan Grossfield
13  Department of Biochemistry and Biophysics
14  School of Medicine & Dentistry, University of Rochester
15 
16  This package (LOOS) is free software: you can redistribute it and/or modify
17  it under the terms of the GNU General Public License as published by
18  the Free Software Foundation under version 3 of the License.
19 
20  This package is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28 
29 
30 
31 #include <loos.hpp>
32 
33 #include <DensityGrid.hpp>
34 #include <DensityTools.hpp>
35 
36 using namespace std;
37 using namespace loos;
38 using namespace loos::DensityTools;
39 
40 
41 int main(int argc, char *argv[]) {
42  if (argc != 3) {
43  cerr << "Usage- griddiff grid1 grid2 >grid1-grid2\n";
44  exit(-1);
45  }
46 
47  string hdr = invocationHeader(argc, argv);
48 
49  DensityGrid<double> grid1;
50  DensityGrid<double> grid2;
51 
52  int k = 1;
53  ifstream ifs1(argv[k++]);
54  ifs1 >> grid1;
55 
56  ifstream ifs2(argv[k++]);
57  ifs2 >> grid2;
58 
59  DensityGridpoint dims1 = grid1.gridDims();
60  DensityGridpoint dims2 = grid2.gridDims();
61 
62  if (dims1 != dims2) {
63  cerr << "Error- the grid sizes must match\n";
64  exit(-2);
65  }
66 
67  if (grid1.minCoord() != grid2.minCoord()
68  || grid1.maxCoord() != grid2.maxCoord()) {
69  cerr << "Error- the extents of the grids do not match\n";
70  exit(-3);
71  }
72 
73  for (long i = 0; i<grid1.size(); ++i)
74  grid1(i) -= grid2(i);
75 
76  grid1.addMetadata(hdr);
77  cout << grid1;
78 }
STL namespace.
std::string invocationHeader(int argc, char *argv[])
Create an invocation header.
Definition: utils.cpp:124
Namespace for Density package.
Definition: DensityGrid.hpp:48
Namespace for most things not already encapsulated within a class.