GPLIB++
plotsourcerel.cpp
Go to the documentation of this file.
1 #include "SeismicStationList.h"
2 #include <iostream>
3 #include <string>
4 #include "NetCDFTools.h"
5 #include "VecMat.h"
6 
7 using namespace std;
8 using namespace gplib;
9 
10 int main(int argc, char* argv[])
11  {
12  SeismicStationList Stations;
13  string listfilename, outfilename;
14 
15  string version = "$Id: plotsourcerel.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
16  cout << endl << endl;
17  cout << "Program " << version << endl;
18  cout << " Print a 2D histogram of backazimuth and distance relations"
19  << endl;
20  cout << " Input is a list of files, output a netcdf matrix file" << endl;
21  cout << endl << endl;
22  if (argc > 2)
23  {
24  listfilename = argv[1];
25  outfilename = argv[2];
26  }
27  else
28  {
29  cout << "List filename: ";
30  cin >> listfilename;
31  cout << "Output filename: ";
32  cin >> outfilename;
33  }
34  Stations.ReadList(listfilename);
35  const double bazbinsize = 10;
36  const double gcarcbinsize = 5;
37  const double minbaz = 0;
38  const double maxbaz = 360;
39  const double mingcarc = 30;
40  const double maxgcarc = 130;
41  const int nbazbins = (maxbaz - minbaz) / bazbinsize + 1;
42  const int ngcarcbins = (maxgcarc - mingcarc) / gcarcbinsize + 1;
43  gplib::rmat Hist(nbazbins, ngcarcbins);
44  Hist *= 0.0;
45  for (SeismicStationList::tseiscompvector::iterator CurrentStation =
46  Stations.GetList().begin(); CurrentStation != Stations.GetList().end(); CurrentStation++)
47  {
48  int bazindex = 0;
49  int gcarcindex = 0;
50  while ((bazindex + 1) * bazbinsize < (*CurrentStation)->GetBaz())
51  ++bazindex;
52  while ((gcarcindex + 1) * gcarcbinsize < (*CurrentStation)->GetGcarc())
53  ++gcarcindex;
54  Hist(bazindex, gcarcindex) += 1.0;
55  }
56 
57  NcFile mtrescdf(outfilename.c_str(), NcFile::Replace);
58  NcDim* xd = mtrescdf.add_dim("Baz", nbazbins);
59  NcDim* yd = mtrescdf.add_dim("Gcarc", ngcarcbins);
60  NcVar* x = mtrescdf.add_var("Baz", ncFloat, xd);
61  NcVar* y = mtrescdf.add_var("Gcarc", ncFloat, yd);
62  NcVar* z = mtrescdf.add_var("Count", ncFloat, xd, yd);
63  float *xvals = new float[xd->size()];
64  float *yvals = new float[yd->size()];
65  float *zvals = new float[xd->size() * yd->size()];
66  for (size_t i = 0; i < Hist.size1(); ++i)
67  {
68  xvals[i] = i * bazbinsize;
69  for (size_t j = 0; j < Hist.size2(); ++j)
70  {
71  yvals[j] = j * gcarcbinsize;
72  zvals[i * Hist.size2() + j] = Hist(i, j);
73  }
74  }
75  x->put(xvals, xd->size());
76  y->put(yvals, yd->size());
77  z->put(zvals, z->edges());
78  delete xvals;
79  delete yvals;
80  delete zvals;
81  }
tseiscompvector & GetList()
Return the content of the list for manipulation.
Manages a collection of seismic traces, mainly provides functionality to read in data specified in a ...
int main(int argc, char *argv[])
void ReadList(const std::string filename)
read in a file with names and optionally coordinates
string version
Definition: makeinput.cpp:16