View Javadoc

1   /*
2     The TauP Toolkit: Flexible Seismic Travel-Time and Raypath Utilities.
3     Copyright (C) 1998-2000 University of South Carolina
4   
5     This program is free software; you can redistribute it and/or
6     modify it under the terms of the GNU General Public License
7     as published by the Free Software Foundation; either version 2
8     of the License, or (at your option) any later version.
9   
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14  
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  
19    The current version can be found at 
20    <A HREF="www.seis.sc.edu">http://www.seis.sc.edu</A>
21  
22    Bug reports and comments should be directed to 
23    H. Philip Crotwell, crotwell@seis.sc.edu or
24    Tom Owens, owens@seis.sc.edu
25  
26  */
27  
28  package edu.sc.seis.TauP;
29  
30  import java.io.FileNotFoundException;
31  import java.io.IOException;
32  import java.io.InputStreamReader;
33  import java.io.OptionalDataException;
34  import java.io.StreamCorruptedException;
35  import java.io.StreamTokenizer;
36  
37  /***
38    * Allows peeking into the taumodel, slowness model and velocity model
39    * previously create by TauP_Create. Mainly used for debugging purposes
40    * and is probably not very useful to end users.
41    *
42    * @version 1.1.3 Wed Jul 18 15:00:35 GMT 2001
43  
44  
45  
46    * @author H. Philip Crotwell
47    *
48    */
49  public class TauP_Peek {
50  
51     TauModel tMod;
52  
53     public void readTauModel(String filename)
54        throws FileNotFoundException,
55               IOException,
56               StreamCorruptedException,
57               ClassNotFoundException,
58               OptionalDataException
59     {
60           tMod = TauModel.readModel(filename);
61     }
62  
63     public static void main(String[] args)
64        throws FileNotFoundException,
65               IOException,
66               StreamCorruptedException,
67               ClassNotFoundException,
68               OptionalDataException
69     {
70  
71  
72        String modelFilename;
73        if (args.length == 2 && (
74  		args[0].equals("-mod") || args[0].equals("-model"))) {
75           modelFilename = args[1];
76        } else {
77           modelFilename = "iasp91.taup";
78        }
79        boolean DEBUG = false;
80        TauModel tModDepth;
81        SeismicPhase sp;
82        double depth = 0.0;
83   
84        try {
85           TauP_Peek peek = new TauP_Peek();
86           peek.readTauModel(modelFilename);
87           tModDepth = peek.tMod;
88  
89  				// just so sp is initialized for compiler
90        	sp = new SeismicPhase("S", tModDepth);
91  	      sp.init();
92  
93           StreamTokenizer tokenIn = new StreamTokenizer(
94              new InputStreamReader(System.in));
95           tokenIn.parseNumbers();
96   
97           System.out.print(
98              "seismic (p)hase or (t)au model or (s)lowness model "+
99              "or (v)elocity model or tau (b)ranch? ");
100          char modelType = 't';
101          int branch, rayNum;
102          int layer;
103          tokenIn.nextToken();
104          while (tokenIn.nval != -1 && ! tokenIn.sval.equalsIgnoreCase("q")) {
105    
106             if (tokenIn.sval.equalsIgnoreCase("t")) {
107                modelType = 't';
108             } else if (tokenIn.sval.equalsIgnoreCase("b")) {
109                modelType = 'b';
110             } else if (tokenIn.sval.equalsIgnoreCase("s")) {
111                modelType = 's';
112             } else if (tokenIn.sval.equalsIgnoreCase("v")) {
113                modelType = 'v';
114             } else if (tokenIn.sval.equalsIgnoreCase("p")) {
115                modelType = 'p';
116             } else if (tokenIn.sval.equalsIgnoreCase("r")) {
117                modelType = 'r';
118             } else {
119                System.out.println("Unrecognized model type: "+modelType);
120                System.out.println("Using (t)au model.");
121                modelType = 't';
122             }
123 
124             switch (modelType) {
125 					case 'r':case 'R':
126 						System.out.println("Enter source depth");
127 						tokenIn.nextToken();
128                   depth = (double)tokenIn.nval;
129                   tModDepth = peek.tMod.depthCorrect(depth);
130 						double[] rayParams = tModDepth.getRayParams();
131 						for (int i=0;i<rayParams.length; i++) {
132 							System.out.print(rayParams[i]+"  ");
133 							if (i%5==0) {System.out.println();}
134 						}
135 						modelType = 'T';
136                   break;
137                case 't':case 'T':
138                   System.out.println("spherical="+peek.tMod.spherical+
139                      " sourceDepth="+peek.tMod.getSourceDepth()+
140                      " radiusOfEarth="+peek.tMod.getRadiusOfEarth()+
141                      " DEBUG="+peek.tMod.DEBUG+
142                      " rayParams.length="+peek.tMod.rayParams.length+
143                      " tauBranches[0].length="+peek.tMod.tauBranches[0].length+
144                      " tauBranches[1].length="+peek.tMod.tauBranches[1].length);
145 
146                   for (int i=0;i<peek.tMod.getNumBranches();i++) {
147                      System.out.println(
148                         "peek.tMod.tauBranches[0]["+i+"].dist.length="+
149                         peek.tMod.tauBranches[0][i].dist.length+
150                         " peek.tMod.tauBranches[1]["+i+"].dist.length="+
151                         peek.tMod.tauBranches[1][i].dist.length);
152                   }
153                   System.out.println("Enter source depth");
154                   tokenIn.nextToken();
155                   depth = (double)tokenIn.nval;
156                   tModDepth = peek.tMod.depthCorrect(depth);
157                   System.out.println("Enter branch rayNum");
158                   break;
159                case 's':case 'S':
160                   System.out.println(peek.tMod.sMod);
161                   System.out.println("Enter slowness layer");
162                   break;
163                case 'v':case 'V':
164                   System.out.println(peek.tMod.sMod.vMod);
165                   System.out.println("Enter velocity layer");
166                   break;
167                case 'p':case 'P':
168                   System.out.println("Enter depth");
169                   tokenIn.nextToken();
170                   depth = tokenIn.nval;
171                   tModDepth = peek.tMod.depthCorrect(depth);
172                   System.out.println("Enter phase name");
173                   tokenIn.nextToken();
174                   sp = new SeismicPhase(tokenIn.sval, tModDepth);
175 						sp.setDEBUG(true);
176                   sp.init();
177                   System.out.println("Enter degrees");
178                   break;
179                case 'b':case 'B':
180 						System.out.println("Enter source depth");
181 						tokenIn.nextToken();
182                   depth = (double)tokenIn.nval;
183                   tModDepth = peek.tMod.depthCorrect(depth);
184                   System.out.println("Enter Branch");
185                   break;
186                default:
187                   System.out.println("Unrecognized model type: "+modelType);
188                   System.out.println("Using (t)au model.");
189                   modelType = 't';
190                   break;
191             }
192             tokenIn.nextToken();
193     
194             while (tokenIn.ttype  == StreamTokenizer.TT_NUMBER) {
195                switch (modelType) {
196                   case 't':case 'T':
197                      branch = (int)tokenIn.nval;
198                      tokenIn.nextToken();
199                      rayNum = (int)tokenIn.nval;
200                      if (branch>=tModDepth.getNumBranches() ||
201                         rayNum>=tModDepth.rayParams.length) {
202                         System.out.println("Out of bounds!");
203                      } else {
204                         System.out.println(
205                            "ray parameter="+tModDepth.rayParams[rayNum]+
206                            " distance="+
207                               tModDepth.tauBranches[0][branch].getDist(rayNum)+
208                            " time="+tModDepth.tauBranches[0][branch].time[rayNum]+
209                            " tau="+tModDepth.tauBranches[0][branch].tau[rayNum]);
210                         System.out.println(
211                            "ray parameter="+tModDepth.rayParams[rayNum]+
212                            " distance="+
213                               tModDepth.tauBranches[1][branch].getDist(rayNum)+
214                            " time="+tModDepth.tauBranches[1][branch].time[rayNum]+
215                            " tau="+tModDepth.tauBranches[1][branch].tau[rayNum]);
216                      }
217                      System.out.println("Enter branch rayNum");
218                      break;
219                   case 's':case 'S':
220                      layer = (int)tokenIn.nval;
221                      if (layer>=peek.tMod.sMod.getNumLayers(true)) {
222                         System.out.println("P wave Out of bounds!");
223                      } else {
224                         System.out.println(
225                            peek.tMod.sMod.getSlownessLayer(layer, true));
226                      }
227                      if (layer>=peek.tMod.sMod.getNumLayers(false)) {
228                         System.out.println("S wave Out of bounds!");
229                      } else {
230                         System.out.println(
231                            peek.tMod.sMod.getSlownessLayer(layer, false));
232                      }
233                      System.out.println("Enter slowness layer");
234                      break;
235                   case 'b':case 'B':
236                      branch = (int)tokenIn.nval;
237                      if (branch>=tModDepth.getNumBranches() ) {
238                         System.out.println("Out of bounds!");
239                      } else {
240                         System.out.println(tModDepth.tauBranches[0][branch]);
241                         System.out.println(tModDepth.tauBranches[1][branch]);
242                      }
243                      System.out.println("Enter Branch");
244                      break;
245                   case 'v':case 'V':
246                      layer = (int)tokenIn.nval;
247                      if (layer>=peek.tMod.sMod.vMod.getNumLayers()) {
248                         System.out.println("Out of bounds!");
249                      } else {
250                         System.out.println(
251                            peek.tMod.sMod.vMod.getVelocityLayerClone(layer));
252                      }
253                      System.out.println("Enter velocity layer");
254                      break;
255                   case 'p':case 'P':
256                      sp.calcTime(tokenIn.nval);
257 							sp.calcPierce(tModDepth);
258                      System.out.println("MaxRayParamIndex="+sp.getMaxRayParamIndex()+" MinRayParamIndex="+sp.getMinRayParamIndex());
259                      Arrival[] arr = sp.getArrivals();
260                      for (int i=0;i<arr.length;i++) {
261                         System.out.println(arr[i]);
262                      }
263                      System.out.println("Enter degrees");
264                }
265  
266                tokenIn.nextToken();
267             }
268             System.out.print(
269                "(t)au model or (s)lowness model or (v)elocity model? ");
270             tokenIn.nextToken();
271          }
272       } catch (TauModelException e) {
273          System.out.println("Caught TauModelException "
274                             + e.getMessage());
275 			e.printStackTrace();
276       } catch (IOException e) {
277          System.out.println("Tried to read!\n Caught IOException "
278                             + e.getMessage());
279       } finally {
280          System.out.println("Done!\n");
281       }
282    }
283 }