38 #include "GeoTessModelC.h"
39 #include "GeoTessPositionC.h"
40 #include "InterpolatorTypeC.h"
41 #include "GeoTessUtilsC.h"
42 #include "PointMapC.h"
46 #include "ErrorHandler.h"
50 #define RAD_TO_DEG 57.295779513082320876798
52 #define DEG_TO_RAD 0.017453292519943295769237
56 fprintf(stderr,
"Error: %s\n", error_getMessage());
61 int main(
int argc,
char** argv)
67 GeoTessPositionC* position;
68 GeoTessMetaDataC* meta;
75 int vertex, node, attribute;
80 int nPoints, maxPoints;
81 double requestedDelta;
92 int tessId, levelId, vid, verticesSize, neighborsSize;
97 int *neighbors = NULL;
101 printf(
"\nMust provide a single command line argument specifying path to the GeoTessModels directory\n");
107 strncat(path, argv[1],
len);
108 strncat(path,
"/crust20.geotess",
len);
110 printf(
"Loading model from file: %s\n\n", path);
113 model = geomodel_create(path);
120 EarthShapeC* ellipsoid = geomodel_getEarthShape(model);
122 strTmp = geomodel_toString(model);
123 printf(
"%s", strTmp);
128 printf(
"=============================================================================\n");
130 printf(
"Interpolate Data\n");
132 printf(
"=============================================================================\n\n");
137 position = geoposition_getGeoTessPosition2(model, LINEAR);
141 earthshape_getVectorDegrees(ellipsoid, 30., 90., v);
142 geoposition_set2(position, v, 6371.);
145 printf(
"Interpolated model properties at lat, lon = %1.4f, %1.4f:\n\n",
146 earthshape_getLatDegrees(ellipsoid, geoposition_getVector(position)),
147 earthshape_getLonDegrees(ellipsoid, geoposition_getVector(position)));
151 printf(
"%s",
"Layer Depth Thick vP vS density\n");
152 meta = geomodel_getMetaData(model);
153 for (layer = geometadata_getNLayers(meta) - 1; layer >= 0; --layer)
155 geoposition_setTop2(position,layer);
156 printf(
"%3d %10.4f %10.4f %10.4f %10.4f %10.4f\n",
157 layer, geoposition_getDepth(position),
158 geoposition_getLayerThickness2(position), geoposition_getValue(position, 0),
159 geoposition_getValue(position,1), geoposition_getValue(position, 2));
163 printf(
"Interpolated point resides in triangle index = %d\n\n", geoposition_getTriangle(position));
173 strTmp = geoposition_toString(position);
174 printf(
"%s\n", strTmp);
181 pointIndices = (
int*)NULL;
182 weights = (
double*)NULL;
186 geoposition_getWeights(position, &pointIndices, &weights, &allocatedSize, &actualSize, 1.0);
188 printf(
"geoposition_getWeights() returned weights for %d point indices:\n\n", actualSize);
189 printf(
"pointIndex weight\n");
191 for (i=0; i<actualSize; ++i)
193 printf(
"%10d %10.6f\n", pointIndices[i], weights[i]);
194 sumWeights += weights[i];
196 printf(
"\nSum of the weights is %1.6f\n", sumWeights);
206 printf(
"=============================================================================\n");
208 printf(
"Query Model Data\n");
210 printf(
"=============================================================================\n\n");
213 grid = geomodel_getGrid(model);
221 u = geogrid_getVertex(grid, vertex);
223 earthRadius = earthshape_getEarthRadius(ellipsoid, u);
225 printf(
"Vertex=%d lat = %1.4f lon = %1.4f ellipsoid_radius = %1.3f\n\n", vertex,
226 earthshape_getLatDegrees(ellipsoid, u),
227 earthshape_getLonDegrees(ellipsoid, u),
231 printf(
" layer depth");
232 for (attribute=0; attribute<geometadata_getNAttributes(meta); ++attribute)
234 strTmp = geometadata_getAttributeName(meta, attribute);
235 printf(
" %8s", strTmp);
242 printf(
"layer name (km) ");
243 for (attribute=0; attribute<geometadata_getNAttributes(meta); ++attribute)
245 strTmp = geometadata_getAttributeUnit(meta, attribute);
246 printf(
" %8s", strTmp);
252 printf(
"---------------------------------------------------------------------------\n");
255 for (layer = geometadata_getNLayers(meta) - 1; layer >= 0; --layer)
258 strTmp = geometadata_getLayerName(meta, layer);
264 for (node=geomodel_getNRadii(model, vertex, layer)-1; node >= 0; --node)
267 radius = geomodel_getRadius(model, vertex, layer, node);
270 printf(
"%3d %-16s %8.3f", layer, strTmp, earthRadius-radius);
273 for (attribute=0; attribute<geometadata_getNAttributes(meta); ++attribute)
275 value = geomodel_getValueDouble(model, vertex, layer, node, attribute);
276 printf(
" %8.3f", value);
288 printf(
"=============================================================================\n");
290 printf(
"Get Weights for a GreatCircle Raypath\n");
292 printf(
"=============================================================================\n\n");
294 printf(
"Compute travel time for a ray that travels along the top of the 'soft_sediments' \n");
295 printf(
"layer of the crust 2.0 model\n\n");
299 pointMap = geomodel_getPointMap(model);
303 earthshape_getVectorDegrees(ellipsoid, 0., 0., pointA);
304 earthshape_getVectorDegrees(ellipsoid, -10., -10., pointB);
313 maxPoints = geoutils_getGreatCirclePointsN(pointA, pointB, requestedDelta, FALSE);
317 rayPath = (
double**)malloc(
sizeof(
double*) * maxPoints);
318 for (i=0; i<maxPoints; ++i)
320 rayPath[i] = (
double*)malloc(
sizeof(
double) * 3);
323 radii = (
double*)malloc(
sizeof(
double) * maxPoints);
330 actualDelta = geoutils_getGreatCirclePointsD(pointA, pointB, requestedDelta, FALSE, rayPath, &nPoints);
334 for (i=0; i<nPoints; ++i)
radii[i] = 6378. ;
358 geomodel_getWeights3D(model, rayPath,
radii, NULL, nPoints, LINEAR, LINEAR,
359 &pointIndices, &weights, &allocatedSize, &actualSize);
364 for (i=0; i<actualSize; ++i)
365 integral += weights[i]/geopoint_getPointValue(pointMap, pointIndices[i], attribute);
372 printf(
"pointIndex weight lat lon depth vp [vtx, layer, node]\n");
373 for (i=0; i<actualSize; ++i)
375 char* latLonStr = geopoint_getPointLatLonString(pointMap, pointIndices[i]);
376 printf(
"%10d %10.6f %s %6.1f %5.2f [%5d, %1d, %1d]\n", pointIndices[i], weights[i],
378 geopoint_getPointDepth(pointMap, pointIndices[i]),
379 geopoint_getPointValue(pointMap, pointIndices[i], attribute),
380 geopoint_getVertexIndex(pointMap, pointIndices[i]),
381 geopoint_getLayerIndex(pointMap, pointIndices[i]),
382 geopoint_getNodeIndex(pointMap, pointIndices[i])
384 sumWeights += weights[i];
389 printf(
"requestedDelta = %1.6f degrees\n", requestedDelta *
RAD_TO_DEG);
390 printf(
"actualDelta = %1.6f degrees\n", actualDelta *
RAD_TO_DEG);
393 printf(
"integral = %1.6f sec\n", integral);
394 printf(
"sumWeights = %1.6f km\n", sumWeights);
395 printf(
"distance*radius = %1.6f km\n", geoutils_angle(pointA, pointB) *
radii[0]);
396 printf(
"average velocity = %1.6f km/sec\n", sumWeights/integral);
399 printf(
"actualSize, allocatedSize = %d / %d\n", actualSize, allocatedSize);
404 for (i=0; i<nPoints; ++i)
418 geoposition_destroy(position);
421 geometadata_destroy(meta);
424 geopoint_destroy(pointMap);
427 geomodel_destroy(model);
444 levelId = geogrid_getNLevelsTess(grid, tessId)-1;
448 printf(
"Index of last level on tessellation %d is %d\n\n", tessId, levelId);
452 geogrid_getVertexIndices(grid, tessId, levelId, &vertices, &nVertices, &verticesSize);
456 printf(
"There are %d connected vertices\n\n", nVertices);
459 for (vid=0; vid<nVertices; vid += 10000)
464 geogrid_getVertexNeighbors(grid, tessId, levelId, vertices[vid], &neighbors, &size, &neighborsSize);
469 printf(
"vertex %6d neighbors:", vertices[vid]);
470 for (i=0; i<size; ++i)
471 printf(
" %5d", neighbors[i]);
473 printf(
" Edge lengths in deg:");
474 for (i=0; i<size; ++i)
475 printf(
" %5.2f", geoutils_angleDegrees(
476 geogrid_getVertex(grid, vertices[vid]),
477 geogrid_getVertex(grid, neighbors[i])));
496 geogrid_destroy(grid);