4 #include "NetCDFTools.h"
10 int main(
int argc,
char* argv[])
13 string listfilename, outfilename;
15 string version =
"$Id: plotsourcerel.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
17 cout <<
"Program " << version << endl;
18 cout <<
" Print a 2D histogram of backazimuth and distance relations"
20 cout <<
" Input is a list of files, output a netcdf matrix file" << endl;
24 listfilename = argv[1];
25 outfilename = argv[2];
29 cout <<
"List filename: ";
31 cout <<
"Output filename: ";
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);
45 for (SeismicStationList::tseiscompvector::iterator CurrentStation =
46 Stations.
GetList().begin(); CurrentStation != Stations.
GetList().end(); CurrentStation++)
50 while ((bazindex + 1) * bazbinsize < (*CurrentStation)->GetBaz())
52 while ((gcarcindex + 1) * gcarcbinsize < (*CurrentStation)->GetGcarc())
54 Hist(bazindex, gcarcindex) += 1.0;
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)
68 xvals[i] = i * bazbinsize;
69 for (
size_t j = 0; j < Hist.size2(); ++j)
71 yvals[j] = j * gcarcbinsize;
72 zvals[i * Hist.size2() + j] = Hist(i, j);
75 x->put(xvals, xd->size());
76 y->put(yvals, yd->size());
77 z->put(zvals, z->edges());
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