38 #include "GeoTessGrid.h"
39 #include "GeoTessModel.h"
40 #include "GeoTessPosition.h"
55 int main(
int argc,
char** argv)
61 cout <<
"Must supply a single command line argument specifying path to the GeoTessModels directory" << endl;
65 string path = argv[1];
68 string gridFile = CPPUtils::insertPathSeparator(path,
"geotess_grid_04000.geotess");
72 cout <<
"Start very simple example ..." << endl << endl;
74 GeoTessMetaData *metaData =
new GeoTessMetaData();
78 metaData->setEarthShape(
"WGS84");
80 string s =
"Simple example of a GeoTess model\n";
81 s +=
"Storing the distance from station ANMO \n";
82 s +=
"near Albuquerque, New Mexico, USA\n";
83 s +=
"Lat, lon = 34.9462, -106.4567 degrees.\n";
84 s +=
"author: Sandy Ballard\n";
85 s +=
"contact: sballar@sandia.gov\n";
86 s +=
"November, 2011\n";
88 metaData->setDescription(s);
92 metaData->setLayerNames(
"Surface");
96 metaData->setAttributes(
"Distance",
"degrees");
100 metaData->setDataType(GeoTessDataType::FLOAT);
104 metaData->setModelSoftwareVersion(
"GeoTessCPPExamples.populateModel2D 1.0.0");
108 metaData->setModelGenerationDate(CpuTimer::now());
113 GeoTessModel* model =
new GeoTessModel(gridFile, metaData);
115 cout << endl << model->toString() << endl << endl;
120 EarthShape& ellipsoid = model->getEarthShape();
124 ellipsoid.getVectorDegrees(34.9462, -106.4567, anmo);
131 for (
int vertex = 0; vertex < model->getNVertices(); ++vertex)
134 const double* unit_vector = model->getGrid().getVertex(vertex);
137 float value = (float) GeoTessUtils::angleDegrees(anmo, unit_vector);
143 model->setProfile(vertex, &value, 1);
152 string modelFileName = CPPUtils::insertPathSeparator(path,
"populateModel2D.geotess");
161 model->writeModel(modelFileName);
168 model =
new GeoTessModel(modelFileName);
171 cout << model->toString() << endl;
177 GeoTessPosition* position = model->getPosition(GeoTessInterpolatorType::LINEAR);
186 ellipsoid.getVectorDegrees(lat, lon, v);
188 position->setTop(layerID, v);
191 sprintf(ss,
"Interpolation lat, lon, depth = %7.3f deg, %7.3f deg",
192 ellipsoid.getLatDegrees(position->getVector()),
193 ellipsoid.getLonDegrees(position->getVector()));
194 cout << ss << endl << endl;
198 double distance = position->getValue(0);
202 sprintf(ss,
"Interpolated distance from station ANMO = %1.3f degrees", distance);
204 cout << ss << endl << endl;
207 double actualDistance = GeoTessUtils::angleDegrees(anmo, position->getVector());
209 sprintf(ss,
"Actual distance from station ANMO = %1.3f degrees", actualDistance);
210 cout << ss << endl << endl;
213 sprintf(ss,
"Interpolated point resides in triangle index = %d", position->getTriangle());
219 cout <<
" Node Lat Lon Coeff" << endl;
222 const vector<int>& x = position->getVertices();
225 const vector<double>& coef = position->getHorizontalCoefficients();
227 const GeoTessGrid& gridnew = model->getGrid();
228 for (
int j = 0; j < (int) x.size(); ++j)
230 sprintf(ss,
"%6d %10.4f %10.4f %10.6f", x[j],
231 ellipsoid.getLatDegrees(gridnew.getVertex(x[j])),
232 ellipsoid.getLonDegrees(gridnew.getVertex(x[j])), coef[j]);
239 cout <<
"Cpu Time (msec): " << tmr.cpuTime() << endl;
240 cout << endl <<
"End of populateModel2D" << endl << endl;
242 catch (
const GeoTessException& ex)
244 cout << endl << ex.emessage << endl;
249 cout << endl <<
"Unidentified error detected " << endl
250 << __FILE__ <<
" " << __LINE__ << endl;