38 #include "GeoTessModel.h"
39 #include "GeoTessUtils.h"
40 #include "GeoTessPosition.h"
41 #include "GeoTessException.h"
54 int main(
int argc,
char** argv)
61 cout <<
"Must supply a single command line argument specifying path to the GeoTessModels directory" << endl;
65 path = CPPUtils::insertPathSeparator(argv[1],
"crust10.geotess");
67 cout <<
"GeoTess version " << GeoTessUtils::getVersion() << endl;
69 cout <<
"Loading model from file: " << path << endl << endl;
72 GeoTessModel* model =
new GeoTessModel(path);
74 cout << model->toString() << endl;
77 cout <<
"=============================================================================" << endl;
79 cout <<
"Interpolate Data" << endl;
81 cout <<
"=============================================================================" << endl;
87 GeoTessPosition* position = GeoTessPosition::getGeoTessPosition(
88 model, GeoTessInterpolatorType::LINEAR);
93 EarthShape& ellipsoid = model->getEarthShape();
95 cout <<
"EarthShape is " << ellipsoid.getShapeName() << endl << endl;
101 ellipsoid.getVectorDegrees(30., 90., tibet);
102 position->setTop(0, tibet);
105 printf(
"Interpolated model properties at lat, lon = %1.4f, %1.4f:\n\n",
106 ellipsoid.getLatDegrees(position->getVector()),
107 ellipsoid.getLonDegrees(position->getVector()));
111 cout <<
"Layer Depth Thick vP vS density" << endl;
112 for (
int layer = model->getMetaData().getNLayers() - 1; layer >= 0; --layer)
114 position->setTop(layer);
115 printf(
"%3d %10.4f %10.4f %10.4f %10.4f %10.4f\n",
116 layer, position->getDepth(),
117 position->getLayerThickness(), position->getValue(0),
118 position->getValue(1), position->getValue(2));
124 printf(
"Interpolated point resides in triangle index = %d\n", position->getTriangle());
135 cout << position->toString() << endl << endl;
141 map<int, double> weights;
142 position->getWeights(weights, 1.);
144 cout <<
"gposition->getWeights() returned weights for " << weights.size()
145 <<
" point indices:" << endl << endl;
146 cout <<
"pointIndex weight" << endl;
147 cout << fixed << setprecision(6);
152 double sumWeights = 0;
153 map<int,double>::iterator it;
154 for(it = weights.begin(); it != weights.end(); it++)
156 cout << setw(10) << it->first << setw(11) << it->second << endl;
157 sumWeights += it->second;
160 cout << endl <<
"Sum of the weights is " << sumWeights << endl << endl;
165 cout <<
"=============================================================================" << endl;
167 cout <<
"Query Model Data" << endl;
169 cout <<
"=============================================================================" << endl;
178 const double* u = model->getGrid().getVertex(vertexId);
180 double lat = ellipsoid.getLatDegrees(u);
181 double lon = ellipsoid.getLonDegrees(u);
182 double earthRadius = ellipsoid.getEarthRadius(u);
184 printf(
"Vertex=%d lat = %1.4f lon = %1.4f ellipsoid_radius = %1.3f\n\n", vertexId,
185 lat, lon, earthRadius);
188 cout <<
" layer profile depth ";
189 for (
int attribute=0; attribute<model->getMetaData().getNAttributes(); ++attribute)
190 cout << setw(9) << model->getMetaData().getAttributeName(attribute);
194 cout <<
"layer name type (km) ";
195 for (
int attribute=0; attribute<model->getMetaData().getNAttributes(); ++attribute)
196 cout << setw(9) << model->getMetaData().getAttributeUnit(attribute);
199 cout <<
"---------------------------------------------------------------------------" << endl;
201 string layerName, profileType;
202 GeoTessProfile* profile;
203 double radius, value;
205 for (
int layer=model->getNLayers()-1; layer >= 0; --layer)
207 layerName = model->getMetaData().getLayerName(layer);
209 profile = model->getProfile(vertexId, layer);
211 profileType = profile->getType().toString();
213 for (
int node = profile->getNRadii()-1; node >= 0; --node)
215 radius = profile->getRadius(node);
217 cout << setw(3) << right << layer;
218 cout <<
" " << setw(16) << left << layerName;
219 cout <<
" " << setw(16) << profileType;
220 cout << setw(9) << setprecision(3) << right << earthRadius - radius;
221 for (
int attribute=0; attribute < model->getMetaData().getNAttributes(); ++attribute)
223 value = profile->getValue(attribute, node);
224 cout << setw(9) << value;
231 cout <<
"=============================================================================" << endl;
233 cout <<
"Get Weights for a GreatCircle Raypath" << endl;
235 cout <<
"=============================================================================" << endl;
238 cout <<
"Compute travel time for a ray that travels along the top of the 'soft_sediments' " << endl <<
239 "layer of the Crust 1.0 model" << endl << endl;
242 double pointA[3], pointB[3];
245 ellipsoid.getVectorDegrees(0, 0, pointA);
246 ellipsoid.getVectorDegrees(-10, -10, pointB);
249 GeoTessGreatCircle greatCircle(pointA, pointB);
253 double requestedSpacing = 0.5 * DEG_TO_RAD;
257 int maxPoints = GeoTessGreatCircle::getNPoints(2*PI, requestedSpacing,
false);
260 double** rayPath = CPPUtils::new2DArray<double>(maxPoints, 3);
261 double* radii =
new double[maxPoints];
264 double actualSpacing = greatCircle.getPoints(requestedSpacing, rayPath, npoints);
266 for (
int i=0; i<npoints; ++i) radii[i] = 6378.;
272 int attributeIndex = 0;
276 model->getWeights(rayPath, radii, NULL, npoints, GeoTessInterpolatorType::LINEAR, GeoTessInterpolatorType::LINEAR, weights);
278 for(it = weights.begin(); it != weights.end(); it++)
279 integral += it->second/model->getPointMap()->getPointValue(it->first, attributeIndex);
281 cout <<
"model->getWeights() returned weights for " << weights.size()
282 <<
" point indices:" << endl << endl;
284 cout <<
"pointIndex weight lat lon depth vp [vtx, layer, node]" << endl;
285 cout << fixed << setprecision(3);
291 GeoTessPointMap* pointMap = model->getPointMap();
297 for(it = weights.begin(); it != weights.end(); it++)
299 pointIndex = it->first;
302 cout << setw(10) << pointIndex <<
304 setw(11) << weight <<
306 setw(22) << pointMap->getPointLatLonString(pointIndex) <<
307 setw(8) << pointMap->getPointDepth(pointIndex) <<
308 setw(8) << pointMap->getPointValue(pointIndex, attributeIndex) <<
310 setw(5) << pointMap->getVertexIndex(pointIndex) <<
311 setw(2) << pointMap->getLayerIndex(pointIndex) <<
312 setw(2) << pointMap->getNodeIndex(pointIndex) <<
315 sumWeights += it->second;
319 cout << setprecision(6);
320 cout <<
"requested point spacing = " << setw(8) << requestedSpacing*RAD_TO_DEG <<
322 cout <<
"actual point spacing = " << setw(8) << actualSpacing*RAD_TO_DEG <<
326 cout <<
"integral = " << integral <<
" seconds" << endl;
328 cout <<
"sum of weights = " << sumWeights <<
" km" << endl;
329 cout <<
"distance * 6378 = " << greatCircle.getDistance() * radii[0] <<
" km" << endl;
331 cout <<
"average velocity = " << sumWeights / integral <<
" km/sec" << endl;
334 CPPUtils::delete2DArray(rayPath);
340 cout <<
"Done." << endl << endl;
343 catch (GeoTessException& ex)
345 cout << ex.emessage << endl;
350 cout << endl <<
"Unidentified error detected " << endl
351 << __FILE__ <<
" " << __LINE__ << endl;