plotsourcerel.cpp
Go to the documentation of this file.00001 #include "SeismicStationList.h"
00002 #include <iostream>
00003 #include <string>
00004 #include "NetCDFTools.h"
00005 #include "VecMat.h"
00006
00007 using namespace std;
00008 using namespace gplib;
00009
00010 int main(int argc, char* argv[])
00011 {
00012 SeismicStationList Stations;
00013 string listfilename, outfilename;
00014
00015 string version = "$Id: plotsourcerel.cpp 1816 2009-09-07 11:28:35Z mmoorkamp $";
00016 cout << endl << endl;
00017 cout << "Program " << version << endl;
00018 cout << " Print a 2D histogram of backazimuth and distance relations"
00019 << endl;
00020 cout << " Input is a list of files, output a netcdf matrix file" << endl;
00021 cout << endl << endl;
00022 if (argc > 2)
00023 {
00024 listfilename = argv[1];
00025 outfilename = argv[2];
00026 }
00027 else
00028 {
00029 cout << "List filename: ";
00030 cin >> listfilename;
00031 cout << "Output filename: ";
00032 cin >> outfilename;
00033 }
00034 Stations.ReadList(listfilename);
00035 const double bazbinsize = 10;
00036 const double gcarcbinsize = 5;
00037 const double minbaz = 0;
00038 const double maxbaz = 360;
00039 const double mingcarc = 30;
00040 const double maxgcarc = 130;
00041 const int nbazbins = (maxbaz - minbaz) / bazbinsize + 1;
00042 const int ngcarcbins = (maxgcarc - mingcarc) / gcarcbinsize + 1;
00043 gplib::rmat Hist(nbazbins, ngcarcbins);
00044 Hist *= 0.0;
00045 for (SeismicStationList::tseiscompvector::iterator CurrentStation =
00046 Stations.GetList().begin(); CurrentStation != Stations.GetList().end(); CurrentStation++)
00047 {
00048 int bazindex = 0;
00049 int gcarcindex = 0;
00050 while ((bazindex + 1) * bazbinsize < (*CurrentStation)->GetBaz())
00051 ++bazindex;
00052 while ((gcarcindex + 1) * gcarcbinsize < (*CurrentStation)->GetGcarc())
00053 ++gcarcindex;
00054 Hist(bazindex, gcarcindex) += 1.0;
00055 }
00056
00057 NcFile mtrescdf(outfilename.c_str(), NcFile::Replace);
00058 NcDim* xd = mtrescdf.add_dim("Baz", nbazbins);
00059 NcDim* yd = mtrescdf.add_dim("Gcarc", ngcarcbins);
00060 NcVar* x = mtrescdf.add_var("Baz", ncFloat, xd);
00061 NcVar* y = mtrescdf.add_var("Gcarc", ncFloat, yd);
00062 NcVar* z = mtrescdf.add_var("Count", ncFloat, xd, yd);
00063 float *xvals = new float[xd->size()];
00064 float *yvals = new float[yd->size()];
00065 float *zvals = new float[xd->size() * yd->size()];
00066 for (size_t i = 0; i < Hist.size1(); ++i)
00067 {
00068 xvals[i] = i * bazbinsize;
00069 for (size_t j = 0; j < Hist.size2(); ++j)
00070 {
00071 yvals[j] = j * gcarcbinsize;
00072 zvals[i * Hist.size2() + j] = Hist(i, j);
00073 }
00074 }
00075 x->put(xvals, xd->size());
00076 y->put(yvals, yd->size());
00077 z->put(zvals, z->edges());
00078 delete xvals;
00079 delete yvals;
00080 delete zvals;
00081 }