36 package gov.sandia.geotess.examples;
42 import gov.
sandia.gmp.util.globals.InterpolatorType;
43 import gov.
sandia.gmp.util.globals.OptimizationType;
44 import gov.
sandia.gmp.util.numerical.polygon.GreatCircle;
45 import gov.
sandia.gmp.util.numerical.vector.VectorGeo;
48 import java.util.ArrayList;
49 import java.util.Arrays;
50 import java.util.HashMap;
71 public static void main(String[] args)
77 "\nMust specify a single command line argument specifying " +
78 "the path to the file crust20.geotess\n");
81 File inputFile =
new File(args[0]);
83 System.out.printf(
"Loading model from file %s%n%n",
84 inputFile.getCanonicalPath());
87 GeoTessModel model =
new GeoTessModel(inputFile, OptimizationType.SPEED);
90 System.out.println(model);
92 System.out.printf(
"\n");
93 System.out.printf(
"=============================================================================\n");
94 System.out.printf(
"\n");
95 System.out.printf(
"Interpolate Data\n");
96 System.out.printf(
"\n");
97 System.out.printf(
"=============================================================================\n\n");
102 GeoTessPosition position = model.getGeoTessPosition(InterpolatorType.LINEAR);
107 position.setTop(0, VectorGeo.getVectorDegrees(30., 90.));
110 System.out.printf(
"Interpolated model properties at lat, lon = %1.4f, %1.4f:%n%n",
111 VectorGeo.getLatDegrees(position.getVector()),
112 VectorGeo.getLonDegrees(position.getVector()));
116 System.out.println(
"Layer Depth Thick vP vS density");
117 for (
int layer = model.getMetaData().getNLayers() - 1; layer >= 0; --layer)
121 position.setTop(layer);
123 System.out.printf(
"%3d %10.4f %10.4f %10.4f %10.4f %10.4f%n",
126 position.getLayerThickness(),
127 position.getValue(0),
128 position.getValue(1),
129 position.getValue(2));
132 System.out.println();
135 System.out.printf(
"Interpolated point resides in triangle index = %d%n%n",
136 position.getTriangle());
147 System.out.println(position.toString());
150 System.out.println(
"Call position.getWeights()");
151 HashMap<Integer, Double> weights =
new HashMap<Integer, Double>();
152 position.getWeights(weights, 1.0);
154 System.out.printf(
"geoposition_getWeights() returned weights for %d point indices:\n\n", weights.size());
155 System.out.printf(
"pointIndex weight\n");
156 double sumWeights = 0;
157 for (Integer pointIndex : weights.keySet())
159 double weight = weights.get(pointIndex);
161 System.out.printf(
"%10d %10.6f\n", pointIndex, weight);
162 sumWeights += weight;
164 System.out.printf(
"\nSum of the weights is %1.6f\n", sumWeights);
166 System.out.printf(
"\n");
167 System.out.printf(
"=============================================================================\n");
168 System.out.printf(
"\n");
169 System.out.printf(
"Query Model Data\n");
170 System.out.printf(
"\n");
171 System.out.printf(
"=============================================================================\n\n");
179 double[] u = model.getGrid().getVertex(vertexId);
181 double earthRadius = VectorGeo.getEarthRadius(u);
183 System.out.printf(
"Vertex=%d lat = %1.4f lon = %1.4f ellipsoid_radius = %1.3f\n\n", vertexId,
184 VectorGeo.getLatDegrees(u),
185 VectorGeo.getLonDegrees(u),
189 System.out.printf(
" layer profile depth");
190 for (
int attribute=0; attribute < model.getNAttributes(); ++attribute)
191 System.out.printf(
" %8s", model.getMetaData().getAttributeName(attribute));
192 System.out.printf(
"\n");
195 System.out.printf(
"layer name type (km) ");
196 for (
int attribute=0; attribute < model.getNAttributes(); ++attribute)
197 System.out.printf(
" %8s", model.getMetaData().getAttributeUnit(attribute));
198 System.out.printf(
"\n");
200 System.out.printf(
"---------------------------------------------------------------------------\n");
203 for (
int layer = model.getNLayers() - 1; layer >= 0; --layer)
206 String layerName = model.getMetaData().getLayerName(layer);
209 Profile profile = model.getProfile(vertexId, layer);
212 ProfileType pType = profile.getType();
218 for (
int node=profile.getNRadii()-1; node >= 0; --node)
221 double radius = profile.getRadius(node);
224 System.out.printf(
"%3d %-16s %-16s %8.3f", layer, layerName, pType, earthRadius-radius);
227 for (
int attribute=0; attribute<model.getNAttributes(); ++attribute)
229 double value = profile.getValue(attribute, node);
230 System.out.printf(
" %8.3f", value);
232 System.out.printf(
"\n");
234 System.out.printf(
"\n");
237 System.out.printf(
"\n");
238 System.out.printf(
"=============================================================================\n");
239 System.out.printf(
"\n");
240 System.out.printf(
"Get Weights for a GreatCircle Raypath\n");
241 System.out.printf(
"\n");
242 System.out.printf(
"=============================================================================\n\n");
246 double[] pointA =
new double[3];
247 double[] pointB =
new double[3];
249 VectorGeo.getVectorDegrees(0., 0., pointA);
250 VectorGeo.getVectorDegrees(10., 10., pointB);
252 GreatCircle greatCircle =
new GreatCircle(pointA, pointB);
254 ArrayList<double[]> rayPath = greatCircle.getPoints(31,
false);
257 double[] radii =
new double[rayPath.size()];
258 Arrays.fill(radii, 6371.);
261 model.getWeights(rayPath, radii,
null,
262 InterpolatorType.LINEAR, InterpolatorType.LINEAR, weights);
264 System.out.printf(
"model.getWeights() returned weights for %d point indices:\n\n",
274 System.out.printf(
"pointIndex weight\n");
275 for (Integer pointIndex : weights.keySet())
277 System.out.printf(
"%10d %10.6f\n", pointIndex, weights.get(pointIndex));
278 sumWeights += weights.get(pointIndex);
281 System.out.printf(
"\n");
282 System.out.printf(
"sumWeights = %1.6f km\n", sumWeights);
283 System.out.printf(
"distance * 6371 = %1.6f km\n\n", greatCircle.getDistance() * 6371.);
285 System.out.println(
"Done.");