1 package gov.sandia.geotess.examples.customdata;
3 import java.io.DataInputStream;
4 import java.io.DataOutputStream;
6 import java.io.IOException;
8 import java.util.ArrayList;
9 import java.util.HashMap;
10 import java.util.List;
12 import java.util.Scanner;
51 private Map<String, Map<SeismicPhase,Map<GeoAttributes, Integer>>>
indexMap;
75 public GeoTessModelGA(File modelInputFile, String relativeGridPath)
throws IOException
78 loadModel(modelInputFile, relativeGridPath);
97 loadModel(modelInputFile,
"");
122 public GeoTessModelGA(String modelInputFile, String relativeGridPath)
throws IOException
125 loadModel(modelInputFile, relativeGridPath);
144 loadModel(modelInputFile,
"");
175 public GeoTessModelGA(String gridFileName, GeoTessMetaData metaData)
throws IOException
177 super(gridFileName, metaData);
212 public GeoTessModelGA(GeoTessGrid grid, GeoTessMetaData metaData)
throws GeoTessException, IOException
214 super(grid, metaData);
228 super(baseModel.getGrid(), baseModel.getMetaData());
229 for (
int i = 0; i < baseModel.getNVertices(); ++i)
230 for (
int j=0; j<baseModel.getNLayers(); ++j)
231 setProfile(i,j,baseModel.getProfile(i, j));
251 {
return indexMap.get(station).get(phase).get(attribute); }
258 String inputDirectory, String relGridFilePath)
259 throws GeoTessException, IOException
262 super.loadModelBinary(input, inputDirectory, relGridFilePath);
266 String className = GeoTessUtils.readString(input);
267 if (!className.equals(
this.getClass().getSimpleName()))
268 throw new IOException(
"Found class name "+className
270 +this.getClass().getSimpleName());
276 int formatVersion = input.readInt();
278 if (formatVersion != 1)
279 throw new IOException(
"GAModel Format version "+formatVersion+
" is not supported.");
282 int nStations = input.readInt();
283 String[] stations =
new String[nStations];
284 for (
int i=0; i<nStations; ++i)
285 stations[i] = GeoTessUtils.readString(input);
288 int nPhases = input.readInt();
290 for (
int i=0; i<nPhases; ++i)
291 phases[i] =
SeismicPhase.valueOf(GeoTessUtils.readString(input));
294 int nAttributes = input.readInt();
296 for (
int i=0; i<nAttributes; ++i)
310 super.writeModelBinary(output, gridFileName);
314 GeoTessUtils.writeString(output, this.getClass().getSimpleName());
325 GeoTessUtils.writeString(output, station);
329 GeoTessUtils.writeString(output, phase.toString());
333 GeoTessUtils.writeString(output, a.toString());
341 String relGridFilePath)
throws GeoTessException, IOException
343 super.loadModelAscii(input, inputDirectory, relGridFilePath);
347 String className = input.nextLine();
348 if (!className.equals(
this.getClass().getSimpleName()))
349 throw new IOException(
"Found class name "+className
351 +this.getClass().getSimpleName());
357 int formatVersion = input.nextInt();
360 if (formatVersion != 1)
361 throw new IOException(
"GAModel Format version "+formatVersion+
" is not supported.");
364 int nStations = input.nextInt();
365 String[] stations =
new String[nStations];
366 for (
int i=0; i<nStations; ++i)
367 stations[i] = input.next();
370 int nPhases = input.nextInt();
372 for (
int i=0; i<nPhases; ++i)
376 int nAttributes = input.nextInt();
378 for (
int i=0; i<nAttributes; ++i)
387 this.stationNames = stations;
388 this.phaseNames = phases;
392 indexMap =
new HashMap<String, Map<SeismicPhase,Map<GeoAttributes,Integer>>>(stations.length);
396 Map<SeismicPhase, Map<GeoAttributes, Integer>> m2 =
397 new HashMap<SeismicPhase, Map<GeoAttributes,Integer>>(phases.length);
401 Map<GeoAttributes, Integer> m3 =
new HashMap<GeoAttributes, Integer>(
attributes.length);
420 super.writeModelAscii(output, gridFileName);
427 output.write(String.format(
"%s%n%d%n",
this.getClass().getSimpleName(), 1));
432 output.write(
' '+station);
437 output.write(
' '+phase.toString());
442 output.write(
' '+a.toString());