36 #include "Tomography2D.h"
75 int main(
int argc,
char** argv)
80 GeoTessModelC* hitCountModel;
81 GeoTessModelC* hitCountModelRefined;
82 GeoTessModelC* refinedModel;
83 EarthShapeC* ellipsoid;
86 double*** rayPaths=NULL;
90 float* attributeChanges=NULL;
94 ellipsoid = earthshape_create(
"WGS84");
99 earthshape_getVectorDegrees(ellipsoid, 34.9462, -106.4567, ANMO);
126 polygon = geopoly_create2(ANMO, 38*
dtr, 100);
128 geomodel_setActiveRegionPoly(model, polygon);
133 geopoly_destroy(polygon);
156 nChanges = geomodel_getNPoints(model);
157 attributeChanges = (
float*)malloc(nChanges *
sizeof(
float));
158 for (i=0; i<nChanges; ++i)
159 attributeChanges[i] = 0.01F;
164 free(attributeChanges);
166 geomodel_writeModel(model,
"attenuation_model.geotess");
184 hitCountModel =
hitCount(model, rayPaths, nRayPaths);
187 geomodel_writeModel(hitCountModel,
"hitcount_model_original.geotess");
190 geomodel_destroy(model);
191 geomodel_destroy(hitCountModel);
192 earthshape_destroy(ellipsoid);
208 model = geomodel_create(
"attenuation_model.geotess");
215 hitCountModelRefined = geomodel_create(
"hitcount_model_refined.geotess");
223 refinedModel =
refineModel(model, hitCountModelRefined);
226 geomodel_writeModel(refinedModel,
"attenuation_model_refined.geotess");
229 geomodel_destroy(model);
230 geomodel_destroy(hitCountModelRefined);
231 geomodel_destroy(refinedModel);
234 for (i=0; i<nRayPaths; ++i)
236 free(rayPaths[i][0]);
237 free(rayPaths[i][1]);
245 printf(
"Tomography2D completed successfully.\n");
262 GeoTessMetaDataC* metaData;
263 GeoTessModelC* model;
268 printf(
"************************************************************\n");
270 printf(
"* startingModel()\n");
272 printf(
"************************************************************\n");
281 metaData = geometadata_create();
286 geometadata_setEarthShape(metaData,
"WGS84");
288 geometadata_setDescription(metaData,
"GeoTessModel for example program Tomography2D\n");
293 geometadata_setLayerNames1(metaData,
"surface");
297 geometadata_setAttributes1(metaData,
"Distance",
"degrees");
301 geometadata_setDataType1(metaData, FLOAT);
306 geometadata_setModelSoftwareVersion(metaData,
"GeoTessCExamples.Tomography2D 1.0.0");
311 geometadata_setModelGenerationDate(metaData, str);
317 model = geomodel_create3(gridFile, metaData);
328 geometadata_destroy(metaData);
333 for (i = 0; i < geomodel_getNVertices(model); ++i)
334 geomodel_setProfSurfFloats(model, i, &attenuation, 1);
372 printf(
"************************************************************\n");
374 printf(
"* generateRayPaths()\n");
376 printf(
"************************************************************\n\n");
378 wgs84 = earthshape_create(
"WGS84");
385 *rayPaths = (
double***)malloc((*nRays) *
sizeof(
double**));
386 for (i=0; i<*nRays; ++i)
388 rayPath = (*rayPaths)[i] = (
double**)malloc(2 *
sizeof(
double*));
389 event = rayPath[0] = (
double*)malloc(3*
sizeof(
double));
390 station = rayPath[1] = (
double*)malloc(3*
sizeof(
double));
392 station[0] = ANMO[0];
393 station[1] = ANMO[1];
394 station[2] = ANMO[2];
398 geoutils_moveDistAz(station, i*5*
dtr, i*36*
dtr, event);
402 printf(
" id event station distance azimuth\n");
403 for (i = 0; i < *nRays; ++i)
405 rayPath = (*rayPaths)[i];
407 station = rayPath[1];
409 str1 = earthshape_getLatLonString(wgs84, event);
410 str2 = earthshape_getLatLonString(wgs84, station);
411 printf(
"%3d %s %s %10.4f %10.4f\n", i,
412 str1, str2, geoutils_angleDegrees(station, event),
413 geoutils_azimuthDegrees(station, event, -999999.0));
419 earthshape_destroy(wgs84);
457 double pointSpacing = 0.1*
rtd;
463 double earthRadius = -1;
466 InterpolatorTypeC interpType = NATURAL_NEIGHBOR;
471 int* pointIndices=NULL;
472 double* weights=NULL;
476 PointMapC* pointMap = geomodel_getPointMap(model);
478 EarthShapeC* ellipsoid = geomodel_getEarthShape(model);
487 double attenuation, sumWeights;
489 printf(
"************************************************************\n");
491 printf(
"* rayTrace()\n");
493 printf(
"************************************************************\n\n");
515 for (i = 0; i < nRays; ++i)
519 rayPath = rayPaths[i];
521 station = rayPath[1];
526 attenuation = geomodel_getPathIntegral2DW(model, attribute,
527 event, station, pointSpacing, earthRadius, LINEAR,
528 &pointIndices, &weights, &allocatedSize, &nWeights);
541 str1 = earthshape_getLatLonString(ellipsoid, station);
542 str2 = earthshape_getLatLonString(ellipsoid, event);
543 printf(
"----------------------------------------------------------------------------\n");
544 printf(
"ray station event distance azimuth attenuation\n");
545 printf(
"%3d %s %s %10.4f %10.4f %12.5f\n\n", i, str1, str2,
546 geoutils_angleDegrees(station, event),
547 geoutils_azimuthDegrees(station, event, -999.0),
553 printf(
"pointId weight | point lat, lon, distance and azimuth from station\n");
558 printf(
"No weights because event-station distance = 0\n");
560 for (j=0; j<nWeights; ++j)
562 sumWeights += weights[j];
564 if (pointIndices[j] < 0)
566 printf(
"%7d %9.2f | outside polygon\n", pointIndices[j], weights[j]);
570 vertex = geopoint_getPointUnitVector(pointMap, pointIndices[j]);
572 str1 = earthshape_getLatLonString(ellipsoid, vertex);
573 printf(
"%7d %9.2f | %s %10.4f %10.4f\n",
574 pointIndices[j], weights[j], str1,
575 geoutils_angleDegrees(station, vertex),
576 geoutils_azimuthDegrees(station, vertex, -999.));
583 printf(
"Sum of weights (length of ray path) = %10.4f km \n\n", sumWeights);
590 if (pointIndices) free(pointIndices);
591 if (weights) free(weights);
594 geopoint_destroy(pointMap);
595 earthshape_destroy(ellipsoid);
610 GeoTessGridC* grid = geomodel_getGrid(model);
611 PointMapC* pointMap = geomodel_getPointMap(model);
612 EarthShapeC* ellipsoid = geomodel_getEarthShape(model);
619 int level = geogrid_getNLevelsTess(grid, tessId)-1;
626 int pointIndex, vertexIndex;
628 double* neighborVertex;
636 printf(
"************************************************************\n");
638 printf(
"* regularization()\n");
640 printf(
"************************************************************\n\n");
642 for (pointIndex = 0; pointIndex < geopoint_size(pointMap); ++pointIndex)
649 vertexIndex = geopoint_getVertexIndex(pointMap, pointIndex);
652 vertex = geogrid_getVertex(grid, vertexIndex);
655 geogrid_getVertexNeighborsWithOrder(grid, tessId, level, vertexIndex, order,
656 &neighbors, &nNeighbors, &allocatedSize);
662 if (pointIndex % 100 == 0)
664 printf(
"--------------------------------------------------------\n");
665 tmp = earthshape_getLatLonString(ellipsoid, vertex);
666 printf(
"point %d, vertex %d, lat,lon %s:\n\n",
667 pointIndex, vertexIndex, tmp);
670 printf(
"neighbor neighbor distance azimuth\n");
671 printf(
"vertexid pointid (deg) (deg)\n");
672 for (i=0; i<nNeighbors; ++i)
677 neighborVertex = geogrid_getVertex(grid, neighbors[i]);
680 neighborPointId = geopoint_getPointIndex(pointMap, neighbors[i], 0, 0);
682 printf(
"%8d %8d %8.2f %8.2f\n", neighbors[i], neighborPointId,
683 geoutils_angleDegrees(vertex, neighborVertex),
684 geoutils_azimuthDegrees(vertex, neighborVertex, -999.));
693 if (neighbors) free(neighbors);
695 geogrid_destroy(grid);
696 geopoint_destroy(pointMap);
697 earthshape_destroy(ellipsoid);
715 PointMapC* pointMap = geomodel_getPointMap(model);
718 for (pointIndex = 0; pointIndex < nChanges; ++pointIndex)
720 attenuation = geopoint_getPointValue(pointMap, pointIndex, attributeIndex);
721 attenuation += attributeChanges[pointIndex];
722 geopoint_setPointValue(pointMap, pointIndex, attributeIndex, attenuation);
724 geopoint_destroy(pointMap);
740 GeoTessModelC*
hitCount(GeoTessModelC* model,
double*** rayPaths,
int nRays)
742 GeoTessMetaDataC* metadata;
744 GeoTessModelC* hitCountModel;
746 InterpolatorTypeC interpType;
763 int* pointIndices=NULL;
764 double* weights=NULL;
773 printf(
"************************************************************\n");
775 printf(
"* hitCount()\n");
777 printf(
"************************************************************\n");
781 metadata = geometadata_create();
786 geometadata_setEarthShape(metadata,
"WGS84");
789 geometadata_setDescription(metadata,
"GeoTessModel of hit count for example program Tomography2D");
792 geometadata_setLayerNames1(metadata,
"surface");
795 geometadata_setAttributes1(metadata,
"HIT_COUNT",
"count");
798 geometadata_setDataType1(metadata, INT);
802 geometadata_setModelSoftwareVersion(metadata,
"Tomography2D hitCount()");
807 geometadata_setModelGenerationDate(metadata, str1);
815 grid = geomodel_getGrid(model);
819 hitCountModel = geomodel_create4(grid, metadata);
824 geometadata_destroy(metadata);
828 for (vertexId = 0; vertexId < geogrid_getNVertices(grid); ++vertexId)
829 geomodel_setProfSurfInts(hitCountModel, vertexId, &count, 1);
834 geogrid_destroy(grid);
836 polygon = geomodel_getPolygon(model);
839 geomodel_setActiveRegionPoly(hitCountModel, polygon);
840 geopoly_destroy(polygon);
846 pointMap = geomodel_getPointMap(hitCountModel);
855 pointSpacing = 0.1*
rtd;
864 interpType = NATURAL_NEIGHBOR;
871 for (i = 0; i < nRays; ++i)
874 rayPath = rayPaths[i];
876 station = rayPath[1];
881 geomodel_getPathIntegral2DW(model, attributeIndex, event, station,
882 pointSpacing, earthRadius, interpType,
883 &pointIndices, &weights, &allocatedSize, &nPoints);
885 for (j=0; j<nPoints; ++j)
887 if (pointIndices[j] >= 0)
889 hitcount = geopoint_getPointValueInt(pointMap, pointIndices[j], attributeIndex);
891 geopoint_setPointValue(pointMap, pointIndices[j], attributeIndex, hitcount);
898 printf(
" point vertex lat lon distance hitcount\n");
899 for (pointIndex = 0; pointIndex < geopoint_size(pointMap); ++pointIndex)
900 if (geopoint_getPointValueInt(pointMap, pointIndex, attributeIndex) > 0)
903 u = geopoint_getPointUnitVector(pointMap, pointIndex);
906 str1 = geopoint_getPointLatLonString(pointMap, pointIndex);
907 printf(
"%8d %8d %s %9.2f %6d\n",
909 geopoint_getVertexIndex(pointMap, pointIndex), str1,
910 geoutils_angleDegrees(ANMO, u),
911 geopoint_getPointValueInt(pointMap, pointIndex, attributeIndex));
917 geopoint_destroy(pointMap);
920 if (pointIndices) free(pointIndices);
921 if (weights) free(weights);
923 return hitCountModel;
941 GeoTessModelC*
refineModel(GeoTessModelC* oldModel, GeoTessModelC* hitCountModelRefined)
944 GeoTessGridC* oldGrid = geomodel_getGrid(oldModel);
948 GeoTessMetaDataC* metaData = geomodel_getMetaData(oldModel);
951 GeoTessGridC* refinedGrid = geomodel_getGrid(hitCountModelRefined);
955 GeoTessModelC* newModel = geomodel_create4(refinedGrid, metaData);
960 GeoTessPositionC* pos = geomodel_getPosition2(oldModel, LINEAR);
967 int attributeIndex = 0;
973 printf(
"************************************************************\n");
975 printf(
"* refineModel()\n");
977 printf(
"************************************************************\n\n");
984 for (vtx = 0; vtx < geomodel_getNVertices(newModel); ++vtx)
989 u = geogrid_getVertex(refinedGrid, vtx);
994 oldVtx = geogrid_getVertexIndex1(oldGrid, u);
998 attenuation = geomodel_getValueFloat(oldModel, oldVtx, layerIndex, nodeIndex, attributeIndex);
1002 geoposition_set4(pos, layerIndex, u, 6371.);
1003 attenuation = (float)geoposition_getValue(pos, attributeIndex);
1007 geomodel_setProfSurfFloats(newModel, vtx, &attenuation, 1);
1010 geogrid_destroy(oldGrid);
1011 geogrid_destroy(refinedGrid);
1012 geometadata_destroy(metaData);
1013 geoposition_destroy(pos);
1026 while (error_exists())
1028 fprintf(stderr,
"%s\n", error_getMessage());
1033 if (!error_exists())