6 #include <boost/filesystem/operations.hpp>
7 #include <boost/shared_ptr.hpp>
8 #include <boost/multi_array.hpp>
13 using namespace boost::filesystem;
14 using namespace gplib;
26 string version =
"$Id: plotlayer.cpp 1849 2010-05-07 11:53:45Z mmoorkamp $";
28 cout <<
"Program " << version << endl;
29 cout <<
"Reads in WinGLink or old Mackie format 3D Model grids " << endl;
31 <<
"and outputs the resistivity of a single layer for plotting with GMT "
33 cout <<
"No input parameters supported " << endl;
35 string infilename, outfilename;
38 double latmin, lonmin;
42 infilename = AskFilename(
"Modelfile name: ");
43 cout <<
"Type 1 for old Mackie, 2 for Winglink format: ";
46 cout <<
"Depth of layer to plot: ";
48 cout <<
"Latitude of lower border: ";
50 cout <<
"Longitude of left border: ";
52 outfilename = AskFilename(
"Outfile name: ");
56 const double kmlatitude = 111194;
57 const double kmlongitude = cos(latmin / 180. * PI) * kmlatitude;
64 const int xsize = Model.
GetXSizes().size();
65 const int ysize = Model.
GetYSizes().size();
66 typedef boost::multi_array<double, 1> tscalearray;
67 tscalearray lonscale(boost::extents[xsize]),
68 latscale(boost::extents[ysize]);
69 double currentdepth = 0;
72 while (currentdepth < maxdepth)
74 currentdepth += Model.
GetZSizes()[layerindex] / 1000;
75 cout << currentdepth << endl;
83 for (
int i = 1; i < ysize; ++i)
84 latscale[i] = latscale[i - 1] + Model.
GetYSizes()[i - 1];
85 for (
int i = 1; i < xsize; ++i)
86 lonscale[i] = lonscale[i - 1] + Model.
GetXSizes()[i - 1];
87 ofstream outfile(outfilename.c_str());
88 for (
int i = 0; i < xsize; ++i)
89 for (
int j = 0; j < ysize; ++j)
91 outfile << lonmin + lonscale[i] / kmlongitude <<
" " << latmin
92 + latscale[ysize - 1 - j] / kmlatitude <<
" "
97 NcFile cdf((outfilename +
".nc").c_str(), NcFile::Replace);
98 NcDim* latd = cdf.add_dim(
"lat", ysize);
99 NcDim* lond = cdf.add_dim(
"lon", xsize);
101 NcVar* lat = cdf.add_var(
"lat", ncFloat, latd);
102 lat->add_att(
"units",
"degrees_north");
103 lat->add_att(
"long_name",
"longitude");
105 NcVar* lon = cdf.add_var(
"lon", ncFloat, lond);
106 lon->add_att(
"units",
"degrees_east");
107 lon->add_att(
"long_name",
"latitude");
108 NcVar* res = cdf.add_var(
"res", ncFloat, latd, lond);
109 res->add_att(
"units",
"ohm meters");
110 res->add_att(
"long_name",
"Resistivity");
111 res->add_att(
"coordinates",
"lon lat");
112 float *lonvals =
new float[lond->size()];
113 float *latvals =
new float[latd->size()];
115 float *resvals =
new float[latd->size() * lond->size()];
117 for (
int i = 0; i < xsize; ++i)
119 lonvals[i] = lonmin + lonscale[i] / kmlongitude;
121 for (
int i = 0; i < ysize; ++i)
123 latvals[i] = latmin + latscale[i] / kmlatitude;
125 for (
int i = 0; i < xsize; ++i)
127 for (
int j = 0; j < ysize; ++j)
129 resvals[(ysize - j - 1) * xsize + i]
134 lon->put(lonvals, lond->size());
135 lat->put(latvals, latd->size());
136 res->put(resvals, res->edges());
const t3DModelDim & GetZSizes()
Get the cell sizes in z-direction (down) in m.
void ReadMackie(std::string filename)
Read an ascii file in the format use by Mackie's old code.
const t3DModelDim & GetXSizes()
Get the cell sizes in x-direction (North) in m.
The class 3DMTModel manages 3D models for magnetotelluric model calculations, at this point this is o...
const t3DModelDim & GetYSizes()
Get the cell sizes in y-direction (East) in m.
void ReadWinGLink(std::string filename)
Read an ascii file in the format written by WinGLink.
const t3DModelData & GetModel()
Return a three dimensional multi-array with the indices of the resistivity values in each model cell...
const t3DModelRes & GetResistivities()
Return the table of resistivity values that correspond to the index values in GetModel.