1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package edu.sc.seis.TauP;
29
30 import java.io.BufferedReader;
31 import java.io.DataOutputStream;
32 import java.io.File;
33 import java.io.FileNotFoundException;
34 import java.io.FileReader;
35 import java.io.IOException;
36 import java.io.StreamTokenizer;
37
38 /*** Creates a table of travel times for a phase. Only uses the first arrival at any distance.
39 *
40 * @version 1.1.3 Wed Jul 18 15:00:35 GMT 2001
41
42
43
44 * @author H. Philip Crotwell
45 *
46 */
47 public class TauP_Table extends TauP_Time {
48
49 public static final int GENERIC = 0;
50
51 public static final int LOCSAT = 1;
52
53 protected int outputType = TauP_Table.GENERIC;
54
55 protected String headerFile;
56
57 protected double[] depths = {
58 0.00f, 1.00f, 2.00f, 3.00f, 4.00f, 5.00f, 10.00f, 15.00f, 19.00f, 21.00f,
59 25.00f, 30.00f, 33.00f, 35.00f, 40.00f, 45.00f, 49.00f, 51.00f, 55.00f, 60.00f,
60 70.00f, 80.00f, 90.00f, 100.00f, 120.00f, 140.00f, 160.00f, 180.00f, 200.00f, 220.00f,
61 240.00f, 260.00f, 280.00f, 300.00f, 350.00f, 400.00f, 450.00f, 500.00f, 550.00f, 600.00f };
62
63 protected double[] distances = {
64 0.00f, 0.10f, 0.20f, 0.30f, 0.40f, 0.50f, 0.60f, 0.70f, 0.80f, 0.90f,
65 1.00f, 1.10f, 1.20f, 1.30f, 1.40f, 1.50f, 1.60f, 1.70f, 1.80f, 1.90f,
66 2.00f, 2.10f, 2.20f, 2.30f, 2.40f, 2.50f, 2.60f, 2.70f, 2.80f, 2.90f,
67 3.00f, 3.10f, 3.20f, 3.30f, 3.40f, 3.50f, 3.60f, 3.70f, 3.80f, 3.90f,
68 4.00f, 4.10f, 4.20f, 4.30f, 4.40f, 4.50f, 4.60f, 4.70f, 4.80f, 4.90f,
69 5.00f, 5.10f, 5.20f, 5.30f, 5.40f, 5.50f, 5.60f, 5.70f, 5.80f, 5.90f,
70 6.00f, 6.10f, 6.20f, 6.30f, 6.40f, 6.50f, 6.60f, 6.70f, 6.80f, 6.90f,
71 7.00f, 7.10f, 7.20f, 7.30f, 7.40f, 7.50f, 7.60f, 7.70f, 7.80f, 7.90f,
72 8.00f, 8.10f, 8.20f, 8.30f, 8.40f, 8.50f, 8.60f, 8.70f, 8.80f, 8.90f,
73 9.00f, 9.10f, 9.20f, 9.30f, 9.40f, 9.50f, 9.60f, 9.70f, 9.80f, 9.90f,
74 10.00f, 11.00f, 12.00f, 13.00f, 14.00f, 15.00f, 16.00f, 17.00f, 18.00f, 19.00f,
75 20.00f, 21.00f, 22.00f, 23.00f, 24.00f, 25.00f, 26.00f, 27.00f, 28.00f, 29.00f,
76 30.00f, 31.00f, 32.00f, 33.00f, 34.00f, 35.00f, 36.00f, 37.00f, 38.00f, 39.00f,
77 40.00f, 41.00f, 42.00f, 43.00f, 44.00f, 45.00f, 46.00f, 47.00f, 48.00f, 49.00f,
78 50.00f, 51.00f, 52.00f, 53.00f, 54.00f, 55.00f, 56.00f, 57.00f, 58.00f, 59.00f,
79 60.00f, 61.00f, 62.00f, 63.00f, 64.00f, 65.00f, 66.00f, 67.00f, 68.00f, 69.00f,
80 70.00f, 71.00f, 72.00f, 73.00f, 74.00f, 75.00f, 76.00f, 77.00f, 78.00f, 79.00f,
81 80.00f, 81.00f, 82.00f, 83.00f, 84.00f, 85.00f, 86.00f, 87.00f, 88.00f, 89.00f,
82 90.00f, 91.00f, 92.00f, 93.00f, 94.00f, 95.00f, 96.00f, 97.00f, 98.00f, 99.00f,
83 100.00f, 105.00f, 110.00f, 115.00f, 120.00f, 125.00f, 130.00f, 135.00f, 140.00f, 145.00f,
84 150.00f, 155.00f, 160.00f, 165.00f, 170.00f, 175.00f, 180.00f };
85
86 public TauP_Table() throws TauModelException {
87 super();
88 }
89
90 public void init() throws IOException {
91 super.init();
92 if (headerFile != null) {
93 try {
94 StreamTokenizer head =
95 new StreamTokenizer(
96 new BufferedReader(
97 new FileReader(headerFile)));
98 head.commentChar('#');
99 head.nextToken();
100 if (head.ttype == StreamTokenizer.TT_WORD &&
101 head.sval.equals("n")) {
102 head.nextToken();
103 } else {
104 Alert.warning("First character of header file is not 'n'",
105 "'"+head.ttype+"' "+head.sval);
106 }
107 if (head.ttype != StreamTokenizer.TT_NUMBER) {
108 if (head.ttype == StreamTokenizer.TT_WORD) {
109 Alert.error("Expected a number of depth samples, but got ",
110 head.sval);
111 } else {
112 Alert.error("Expected a number of depth samples, but got ",
113 "'"+head.ttype+"'");
114 }
115 System.exit(1);
116 }
117 if (head.nval != Math.rint(head.nval)) {
118 Alert.error("Expected a number of depth samples, but got ",
119 head.sval);
120 }
121 depths = new double[(int)head.nval];
122 for (int i=0; i< depths.length; i++) {
123 head.nextToken();
124 if (head.ttype != StreamTokenizer.TT_NUMBER) {
125 if (head.ttype == StreamTokenizer.TT_WORD) {
126 Alert.error("Expected a number of depth samples, but got ",
127 head.sval);
128 } else {
129 Alert.error("Expected a number of depth samples, but got ",
130 "'"+head.ttype+"'");
131 }
132 System.exit(1);
133 }
134 depths[i] = head.nval;
135 }
136
137 head.nextToken();
138 if (head.ttype != StreamTokenizer.TT_NUMBER) {
139 if (head.ttype == StreamTokenizer.TT_WORD) {
140 Alert.error("Expected a number of distance samples, but got ",
141 head.sval);
142 } else {
143 Alert.error("Expected a number of distance samples, but got ",
144 "'"+head.ttype+"'");
145 }
146 System.exit(1);
147 }
148 if (head.nval != Math.rint(head.nval)) {
149 Alert.error("Expected a number of distance samples, but got ",
150 head.sval);
151 }
152 distances = new double[(int)head.nval];
153 for (int i=0; i< distances.length; i++) {
154 head.nextToken();
155 if (head.ttype != StreamTokenizer.TT_NUMBER) {
156 if (head.ttype == StreamTokenizer.TT_WORD) {
157 Alert.error(
158 "Expected a distance sample, but got ",
159 head.sval);
160 } else {
161 Alert.error(
162 "Expected a distance sample, but got ",
163 "'"+head.ttype+"'");
164 }
165 System.exit(1);
166 }
167 distances[i] = head.nval;
168 }
169 } catch (FileNotFoundException e) {
170 Alert.error("Couldn't find file.", e.getMessage());
171 System.exit(1);
172 } catch (IOException e) {
173 Alert.error("Caught IOException.", e.getMessage());
174 System.exit(1);
175 }
176 }
177 }
178
179 public void start() throws TauModelException, TauPException, IOException {
180 switch (outputType) {
181 case TauP_Table.GENERIC:
182 genericTable(dos);
183 break;
184 case TauP_Table.LOCSAT:
185 locsatTable(dos);
186 break;
187 default:
188 throw new TauPException(
189 "TauP_Table: undefined state for output type: "+outputType);
190 }
191 }
192
193 protected void genericTable(DataOutputStream dos)
194 throws TauModelException,IOException {
195 Arrival[] arrivals;
196 Format decimal7 = new Format("%-7d");
197 Format float6_1 = new Format("%6.1f");
198 Format float8_1 = new Format("%8.1f");
199 Format float8_2 = new Format("%8.2f");
200 Format float8_3 = new Format("%8.3f");
201 Format float8_4 = new Format("%8.4f");
202 int aNum;
203 double moduloDist;
204 Arrival currArrival;
205
206 for (int depthNum = 0; depthNum < depths.length; depthNum++) {
207 depthCorrect(depths[depthNum]);
208 for (int distNum = 0; distNum < distances.length; distNum++) {
209 calculate(distances[distNum]);
210 if (getNumArrivals() > 0) {
211 arrivals = getArrivals();
212 for (aNum=0; aNum < getNumArrivals(); aNum++) {
213 currArrival = arrivals[aNum];
214 moduloDist = currArrival.getModuloDistDeg();
215
216 dos.writeBytes(modelName+" "+ outForms.formatDistance(moduloDist)+
217 " "+outForms.formatDepth(depth)+" ");
218
219 dos.writeBytes(currArrival.name);
220 dos.writeBytes(" "+outForms.formatTime(currArrival.time)+" ");
221 dos.writeBytes(outForms.formatRayParam(
222 Math.PI/180.0*currArrival.rayParam)+" ");
223 dos.writeBytes(outForms.formatDistance(currArrival.getDistDeg()));
224 dos.writeBytes(" "+currArrival.puristName+"\n");
225 }
226 }
227 }
228 }
229 dos.close();
230 }
231
232 protected void locsatTable(DataOutputStream dos)
233 throws TauModelException,IOException {
234 Arrival[] arrivals;
235 Format float15_4 = new Format("%15.4f");
236 Format float7_2 = new Format("%7.2f");
237 Format decimal7 = new Format("%-7d");
238 double maxDiff =
239 Double.valueOf(toolProps.getProperty("taup.table.locsat.maxdiff",
240 "105.0")).doubleValue();
241
242 dos.writeBytes("n # "+getPhaseNameString()+" travel-time tables for "+
243 modelName+" structure. (From TauP_Table)\n");
244 dos.writeBytes(decimal7.form(depths.length)+"# number of depth samples\n");
245 for (int depthNum = 0; depthNum < depths.length; depthNum++) {
246 dos.writeBytes(float7_2.form(depths[depthNum]));
247 if (depthNum % 10 == 9) { dos.writeBytes("\n"); }
248 }
249 if ((depths.length-1) % 10 != 9) { dos.writeBytes("\n"); }
250
251 dos.writeBytes(decimal7.form(distances.length)+"# number of distances\n");
252 for (int distNum = 0; distNum < distances.length; distNum++) {
253 dos.writeBytes(float7_2.form(distances[distNum]));
254 if (distNum % 10 == 9) { dos.writeBytes("\n"); }
255 }
256 if ((distances.length-1) % 10 != 9) { dos.writeBytes("\n"); }
257
258
259 for (int depthNum = 0; depthNum < depths.length; depthNum++) {
260 depthCorrect(depths[depthNum]);
261 dos.writeBytes("# Travel time for z = "+depths[depthNum]+"\n");
262 for (int distNum = 0; distNum < distances.length; distNum++) {
263 calculate(distances[distNum]);
264 if (getNumArrivals() > 0) {
265 arrivals = getArrivals();
266 if (distances[distNum] > maxDiff &&
267 (arrivals[0].name.endsWith("diff") )) {
268 if (getNumArrivals() > 1) {
269 int aNum=1;
270 while (arrivals[aNum].name.endsWith("diff") &&
271 aNum < getNumArrivals()-1) {
272 aNum++;
273 }
274 if ( ! arrivals[aNum].name.endsWith("diff")) {
275 dos.writeBytes(float15_4.form(arrivals[aNum].time)+
276 " "+arrivals[aNum].name+
277 "\n");
278 } else {
279 dos.writeBytes(float15_4.form(-1.0)+
280 " none\n");
281 }
282 } else {
283 dos.writeBytes(float15_4.form(-1.0)+" none\n");
284 }
285 } else {
286 dos.writeBytes(float15_4.form(arrivals[0].time)+" "+
287 arrivals[0].name+"\n");
288 }
289 } else {
290 dos.writeBytes(float15_4.form(-1.0)+" none\n");
291 }
292 }
293 }
294 dos.close();
295 }
296
297 public void printUsage() {
298 printStdUsageHead();
299 System.out.println(
300 "-ph phase list -- comma separated phase list\n"+
301 "-pf phasefile -- file containing phases\n\n"+
302 "-mod[el] modelname -- use velocity model \"modelname\" for calculations\n"+
303 " Default is iasp91.\n\n");
304
305 System.out.println(
306 "-header filename -- reads depth and distance spacing data\n"+
307 " from a LOCSAT style file.");
308 System.out.println(
309 "-generic -- outputs a \"generic\" ascii table\n");
310 System.out.println(
311 "-locsat -- outputs a \"locsat\" style ascii table\n");
312 printStdUsageTail();
313 }
314
315 public String[] parseCmdLineArgs(String[] args) throws IOException {
316 int i=0;
317 String[] leftOverArgs;
318 int numNoComprendoArgs = 0;
319 File tempFile;
320
321 leftOverArgs = super.parseCmdLineArgs(args);
322 String[] noComprendoArgs = new String[leftOverArgs.length];
323
324 while (i<leftOverArgs.length) {
325 if (leftOverArgs[i].equalsIgnoreCase("-header") &&
326 i<leftOverArgs.length-1) {
327 headerFile = leftOverArgs[i+1];
328 i++;
329 } else if (leftOverArgs[i].equals("-locsat")) {
330 outputType = LOCSAT;
331 } else if (leftOverArgs[i].equals("-generic")) {
332 outputType = GENERIC;
333 } else if (leftOverArgs[i].equals("-help")) {
334 noComprendoArgs[numNoComprendoArgs++] = leftOverArgs[i];
335 } else {
336 noComprendoArgs[numNoComprendoArgs++] = leftOverArgs[i];
337 }
338 i++;
339 }
340
341 if (numNoComprendoArgs > 0) {
342 String[] temp = new String[numNoComprendoArgs];
343 System.arraycopy(noComprendoArgs,0,temp,0,numNoComprendoArgs);
344 return temp;
345 } else {
346 return new String[0];
347 }
348 }
349
350 public static void main(String[] args) {
351 TauP_Table me;
352 try {
353 me = new TauP_Table();
354 String[] noComprendoArgs = me.parseCmdLineArgs(args);
355 if (noComprendoArgs.length > 0) {
356 for (int i=0;i<noComprendoArgs.length;i++) {
357 if (noComprendoArgs[i].equals("-help") ||
358 noComprendoArgs[i].equals("-version")) {
359 System.exit(0);
360 }
361 }
362 System.out.println("I don't understand the following arguments, continuing:");
363 for (int i=0;i<noComprendoArgs.length;i++) {
364 System.out.print(noComprendoArgs[i]+" ");
365 if (noComprendoArgs[i].equals("-help") ||
366 noComprendoArgs[i].equals("-version")) {
367 System.out.println();
368 System.exit(0);
369 }
370 }
371 System.out.println();
372 noComprendoArgs = null;
373 }
374
375 me.init();
376 me.start();
377 } catch (TauModelException e) {
378 System.err.println("Caught TauModelException: "+ e.getMessage());
379 e.printStackTrace();
380 } catch (TauPException e) {
381 System.err.println("Caught TauModelException: "+ e.getMessage());
382 e.printStackTrace();
383 } catch (IOException e) {
384 System.err.println("Caught IOException: "+ e.getMessage());
385 e.printStackTrace();
386 }
387 }
388
389 }