13 using namespace gplib;
16 "$Id: mtutimefrequency.cpp 1850 2010-05-18 09:13:13Z mmoorkamp $";
26 void CalcTfAndWrite(ttsdata Data,
const double samplerate,
const int seglength,
27 const int timeavg,
const string name)
30 gplib::cmat result =
TimeFrequency(Data.begin(), Data.end(), seglength,
32 const size_t ylength = result.size2() - timeavg;
33 NcFile combrescdf(name.c_str(), NcFile::Replace);
34 NcDim* xd = combrescdf.add_dim(
"x", result.size1());
35 NcDim* yd = combrescdf.add_dim(
"y", ylength);
36 NcVar* x = combrescdf.add_var(
"x", ncFloat, xd);
37 NcVar* y = combrescdf.add_var(
"y", ncFloat, yd);
38 NcVar* z = combrescdf.add_var(
"z", ncFloat, xd, yd);
39 float *xvals =
new float[xd->size()];
40 float *yvals =
new float[yd->size()];
41 float *zvals =
new float[xd->size() * yd->size()];
43 for (
size_t i = 0; i < result.size1(); ++i)
47 for (
size_t j = 0; j < ylength; ++j)
50 for (
int k = 0; k < timeavg; ++k)
52 avg += abs(result(i, j + k));
54 zvals[i * ylength + j] = log10(avg);
58 for (
size_t j = 0; j < ylength; ++j)
59 yvals[j] = j * samplerate / seglength;
60 x->put(xvals, xd->size());
61 y->put(yvals, yd->size());
62 z->put(zvals, z->edges());
65 int main(
int argc,
char *argv[])
71 size_t seglength = 2400;
73 <<
"This is mtutf: Calculate time frequency matrix from Phoenix time series"
75 cout <<
" Usage: mtutf filename" << endl;
76 cout <<
"if no filename given, the program will ask for one" << endl;
78 <<
" Output will be 4 netcdf files with ending _tfex.nc, _tfey.nc etc."
80 cout <<
" This is Version: " <<
version << endl << endl;
88 cout <<
"Infilename: ";
92 cout <<
"Length of individual segments in points: ";
94 cout <<
"Number of segments for time averaging: ";
98 timeavg, (infilename +
"_tfex.nc"));
100 timeavg, (infilename +
"_tfey.nc"));
102 timeavg, (infilename +
"_tfhx.nc"));
104 timeavg, (infilename +
"_tfhy.nc"));
std::vector< double > & GetData()
Access for data vector, for ease of use and efficiency we return a reference.
TimeSeries & GetData()
return a reference to the actual object stored in the pointer
TimeSeriesComponent & GetEx()
void CalcTfAndWrite(ttsdata Data, const double samplerate, const int seglength, const int timeavg, const string name)
This functor rises steeply at the edges and then has a wide range where it is unity.
double GetSamplerate()
The samplerate is stored in each component, we just return the samplerate of Hx assuming they are all...
TimeSeriesComponent & GetHy()
TimeSeriesData stores a pointer to the different components of magnetotelluric data and provides func...
TimeSeriesComponent & GetEy()
TimeSeriesComponent & GetHx()
Access function for Hx, returns reference for efficiency.