36 #include "CpuTimerC.h"
37 #include "GeoTessMetaDataC.h"
38 #include "GeoTessModelC.h"
39 #include "GeoTessUtilsC.h"
40 #include "GeoTessGridC.h"
41 #include "InterpolatorTypeC.h"
45 #include "DataTypeC.h"
46 #include "ErrorHandler.h"
50 static const double RAD_TO_DEG = 180./3.1415926535897932384626;
51 static const double DEG_TO_RAD = 3.1415926535897932384626/180.;
56 int main(
int argc,
char** argv)
59 int i,j, layerID, tmp;
60 GeoTessMetaDataC* metaData;
62 GeoTessGridC* grid, *gridnew;
65 GeoTessPositionC* position;
66 double lat, lon, distance, actualDistance;
74 char modelFileName[1000];
77 printf(
"%s",
"Start PopulateModel2D ...\n");
81 printf(
"%s\n",
"Must provide a single command line argument specifying path to the file geotess_grid_04000.geotess which resides in the GeoTessModels directory");
87 start = cpu_getCurrCPUTime();
91 metaData = geometadata_create();
96 geometadata_setEarthShape(metaData,
"WGS84");
99 strncat(s,
"Simple example of a GeoTess model\n",
len);
100 strncat(s,
"Storing the distance from station ANMO \n",
len);
101 strncat(s,
"near Albuquerque, New Mexico, USA\n",
len);
102 strncat(s,
"Lat, lon = 34.9462, -106.4567 degrees.\n",
len);
103 strncat(s,
"author: Sandy Ballard\n",
len);
104 strncat(s,
"contact: sballar@sandia.gov\n",
len);
105 strncat(s,
"November, 2011\n",
len);
106 geometadata_setDescription(metaData, s);
112 geometadata_setLayerNames1(metaData, (
char*)
"Surface");
120 geometadata_setAttributes1(metaData,
"Distance",
"degrees");
124 geometadata_setDataType1(metaData, FLOAT);
131 geometadata_setModelSoftwareVersion(metaData, (
char*)
"GeoTessCExamples.PopulateModel2D 1.0.0");
136 geometadata_setModelGenerationDate(metaData, strTmp);
143 model = geomodel_create3(gridFile, metaData);
149 geometadata_destroy(metaData);
153 EarthShapeC* ellipsoid = geomodel_getEarthShape(model);
158 strTmp = geomodel_toString(model);
159 printf(
"\n%s\n\n", strTmp);
164 earthshape_getVectorDegrees(ellipsoid, 34.9462, -106.4567, anmo);
169 grid = geomodel_getGrid(model);
174 for (i = 0; i < geogrid_getNVertices(grid); ++i)
177 double* vertex = geogrid_getVertex(grid, i);
180 value = (float) geoutils_angleDegrees(anmo, vertex);
182 geomodel_setProfSurfFloats(model, i, &value, 1);
189 geogrid_destroy(grid);
195 strncat(modelFileName,
"populate_model_2d.geotess",
len);
203 geomodel_writeModelParts(model, modelFileName,
"*");
206 geomodel_destroy(model);
208 printf (
"Read model %s\n", modelFileName);
211 model = geomodel_create(modelFileName);
216 strTmp = geomodel_toString(model);
217 printf(
"%s\n", strTmp);
227 position = geomodel_getPosition2(model, LINEAR);
235 earthshape_getVectorDegrees(ellipsoid, lat, lon, v);
236 geoposition_setTop1(position, layerID, v);
238 sprintf(ss,
"Interpolation lat, lon, depth = %7.3f deg, %7.3f deg",
239 earthshape_getLatDegrees(ellipsoid, geoposition_getVector(position)),
240 earthshape_getLonDegrees(ellipsoid, geoposition_getVector(position)));
244 distance = geoposition_getValue(position, 0);
248 sprintf(ss,
"Interpolated distance from station ANMO = %1.3f degrees", distance);
252 actualDistance = geoutils_angleDegrees(anmo, geoposition_getVector(position));
254 sprintf(ss,
"Actual distance from station ANMO = %1.3f degrees", actualDistance);
257 sprintf(ss,
"Interpolated point resides in triangle index = %d", geoposition_getTriangle(position));
263 printf(
"%s\n",
"Vertex Lat Lon Coeff");
265 x = geoposition_getVertices(position);
266 nx = geoposition_getNVertices(position);
269 geoposition_getHorizontalCoefficients(position, &coef, &tmp);
270 gridnew = geomodel_getGrid(model);
271 for (j = 0; j < nx; ++j)
273 sprintf(ss,
"%6d %10.4f %10.4f %10.6f", x[j],
274 earthshape_getLatDegrees(ellipsoid, geogrid_getVertex(gridnew, x[j])),
275 earthshape_getLonDegrees(ellipsoid, geogrid_getVertex(gridnew, x[j])), coef[j]);
281 earthshape_destroy(ellipsoid);
285 geoposition_destroy(position);
290 geogrid_destroy(gridnew);
294 geomodel_destroy(model);
296 printf(
"Cpu Time (msec): %f\n", cpu_getCurrCPUTime() - start);
297 printf(
"%s",
"End of PopulateModel2D\n\n");
306 while (error_exists())
308 fprintf(stderr,
"%s\n", error_getMessage());