1 | |
---|
2 | /* file locdiff.c |
---|
3 | * ========= |
---|
4 | * |
---|
5 | * version 4, 12-Dec-94 |
---|
6 | * |
---|
7 | * computes distance and azimuth between two locations |
---|
8 | * K. Stammler, 5-Aug-92 |
---|
9 | * |
---|
10 | * Usage: locdiff <station1> <station2> |
---|
11 | * or: locdiff <lat> <lon> <station> |
---|
12 | * or: locdiff <lat1> <lon1> <lat2> <lon2> |
---|
13 | */ |
---|
14 | |
---|
15 | |
---|
16 | /* |
---|
17 | * |
---|
18 | * SeismicHandler, seismic analysis software |
---|
19 | * Copyright (C) 1996, Klaus Stammler, Federal Institute for Geosciences |
---|
20 | * and Natural Resources (BGR), Germany |
---|
21 | * |
---|
22 | * This program is free software; you can redistribute it and/or modify |
---|
23 | * it under the terms of the GNU General Public License as published by |
---|
24 | * the Free Software Foundation; either version 2 of the License, or |
---|
25 | * (at your option) any later version. |
---|
26 | * |
---|
27 | * This program is distributed in the hope that it will be useful, |
---|
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
30 | * GNU General Public License for more details. |
---|
31 | * |
---|
32 | * You should have received a copy of the GNU General Public License |
---|
33 | * along with this program; if not, write to the Free Software |
---|
34 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
35 | * |
---|
36 | */ |
---|
37 | |
---|
38 | |
---|
39 | #include <stdio.h> |
---|
40 | #include <string.h> |
---|
41 | #include BASECNST |
---|
42 | #ifdef BC_STDLIB_EX |
---|
43 | #include <stdlib.h> |
---|
44 | #endif |
---|
45 | #include BC_SYSBASE |
---|
46 | #include BC_CPAR |
---|
47 | #include BC_UTUSRDEF |
---|
48 | #include BC_GLUSRDEF |
---|
49 | #include BC_EARTHLOC |
---|
50 | #include BC_PTUSRDEF |
---|
51 | #include BC_INPFILES |
---|
52 | #include "globalparams.h" |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | /* global variable */ |
---|
57 | char shd_errors[BC_FILELTH+1]; |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | int main( int argc, char *argv[] ) |
---|
62 | { |
---|
63 | /* local variables */ |
---|
64 | double lat1, lon1; /* first location */ |
---|
65 | double lat2, lon2; /* second location */ |
---|
66 | double distance, azim, bazim; /* output values */ |
---|
67 | float p_slowness; /* P slowness */ |
---|
68 | float depth; /* depth of event */ |
---|
69 | char *depth_val; /* string of depth */ |
---|
70 | float fdist, fbazim; /* float output */ |
---|
71 | float flat1, flon1, flat2, flon2; |
---|
72 | STATUS status; /* return status */ |
---|
73 | char stat1[BC_LINELTH+1]; /* name of first station */ |
---|
74 | char stat2[BC_LINELTH+1]; /* name of second station */ |
---|
75 | char str[BC_LINELTH+1]; /* scratch */ |
---|
76 | BOOLEAN sphere; /* sphere computation */ |
---|
77 | char path[BC_FILELTH+1]; /* path to input files */ |
---|
78 | GLT_STATINF inf; /* station info */ |
---|
79 | # ifdef BC_SUN |
---|
80 | char *eptr; /* environment pointer */ |
---|
81 | # endif |
---|
82 | |
---|
83 | /* executable code */ |
---|
84 | |
---|
85 | # ifdef BC_SUN |
---|
86 | eptr = getenv( "SH_ERRORS" ); |
---|
87 | if (eptr != NULL) strcpy( shd_errors, eptr ); |
---|
88 | eptr = getenv( "SH_INPUTS" ); |
---|
89 | if (eptr != NULL) { |
---|
90 | strcpy( path, eptr ); |
---|
91 | } else { |
---|
92 | *path = '\0'; |
---|
93 | } /*endif*/ |
---|
94 | # else |
---|
95 | strcpy( path, IF_PATH ); |
---|
96 | # endif |
---|
97 | |
---|
98 | GpReadParfile(); |
---|
99 | |
---|
100 | strcpy( str, path ); |
---|
101 | strcat( str, IF_STATINFFILE ); |
---|
102 | gl_locfile_name( str ); |
---|
103 | pt_settabledir( path, &status ); |
---|
104 | status = BC_NOERROR; |
---|
105 | pt_settabledir( path, &status ); |
---|
106 | if (Severe(&status)) { |
---|
107 | printf( "*** couldn't set table dir %s ***\n", path ); |
---|
108 | return 1; |
---|
109 | } /*endif*/ |
---|
110 | |
---|
111 | pa_init( argc, argv ); |
---|
112 | if (pa_pnumber() < 2 || pa_pnumber() > 4) { |
---|
113 | printf( " \n" ); |
---|
114 | printf( " locdiff determines distance and azimuth between\n" ); |
---|
115 | printf( " two locations. The location must be given either\n" ); |
---|
116 | printf( " explicitely or by station names.\n" ); |
---|
117 | printf( " Usage: locdiff <lat1> <lon1> <lat2> <lon2>\n" ); |
---|
118 | printf( " or: locdiff <lat> <lon> <station>\n" ); |
---|
119 | printf( " or: locdiff <station1> <station2>\n\n" ); |
---|
120 | return 0; |
---|
121 | } else if (pa_pnumber() == 2) { |
---|
122 | strcpy( stat1, pa_pvalue(1) ); |
---|
123 | ut_cap( stat1 ); |
---|
124 | /* gl_statloc( stat1, &lat1, &lon1, &status ); */ |
---|
125 | gl_statinf( stat1, &inf, &status ); |
---|
126 | if (status != BC_NOERROR) { |
---|
127 | printf( "*** couldn't get station location of %s\n", stat1 ); |
---|
128 | return 0; |
---|
129 | } /*endif*/ |
---|
130 | lat1 = inf.lat; |
---|
131 | lon1 = inf.lon; |
---|
132 | strcpy( stat2, pa_pvalue(2) ); |
---|
133 | ut_cap( stat2 ); |
---|
134 | /* gl_statloc( stat2, &lat2, &lon2, &status ); */ |
---|
135 | gl_statinf( stat2, &inf, &status ); |
---|
136 | if (status != BC_NOERROR) { |
---|
137 | printf( "*** couldn't get station location of %s\n", stat2 ); |
---|
138 | return 0; |
---|
139 | } /*endif*/ |
---|
140 | lat2 = inf.lat; |
---|
141 | lon2 = inf.lon; |
---|
142 | } else if (pa_pnumber() == 3) { |
---|
143 | strcpy( str, pa_pvalue(1) ); |
---|
144 | if (Cap(*str) == 'S') *str = '-'; |
---|
145 | if (Cap(*str) == 'N') *str = '+'; |
---|
146 | if (sscanf( str, "%lf", &lat1 ) != 1) { |
---|
147 | printf( "*** couldn't read latitude %s\n", str ); |
---|
148 | return 0; |
---|
149 | } /*endif*/ |
---|
150 | strcpy( str, pa_pvalue(2) ); |
---|
151 | if (Cap(*str) == 'W') *str = '-'; |
---|
152 | if (Cap(*str) == 'E') *str = '+'; |
---|
153 | if (sscanf( str, "%lf", &lon1 ) != 1) { |
---|
154 | printf( "*** couldn't read longitude %s\n", str ); |
---|
155 | return 0; |
---|
156 | } /*endif*/ |
---|
157 | strcpy( stat1, pa_pvalue(3) ); |
---|
158 | ut_cap( stat1 ); |
---|
159 | /* gl_statloc( stat1, &lat2, &lon2, &status ); */ |
---|
160 | gl_statinf( stat1, &inf, &status ); |
---|
161 | if (status != BC_NOERROR) { |
---|
162 | printf( "*** couldn't get station location of %s\n", stat1 ); |
---|
163 | return 0; |
---|
164 | } /*endif*/ |
---|
165 | lat2 = inf.lat; |
---|
166 | lon2 = inf.lon; |
---|
167 | } else { |
---|
168 | strcpy( str, pa_pvalue(1) ); |
---|
169 | if (Cap(*str) == 'S') *str = '-'; |
---|
170 | if (Cap(*str) == 'N') *str = '+'; |
---|
171 | if (sscanf( str, "%lf", &lat1 ) != 1) { |
---|
172 | printf( "*** couldn't read latitude 1 %s\n", str ); |
---|
173 | return 0; |
---|
174 | } /*endif*/ |
---|
175 | strcpy( str, pa_pvalue(2) ); |
---|
176 | if (Cap(*str) == 'W') *str = '-'; |
---|
177 | if (Cap(*str) == 'E') *str = '+'; |
---|
178 | if (sscanf( str, "%lf", &lon1 ) != 1) { |
---|
179 | printf( "*** couldn't read longitude 1 %s\n", str ); |
---|
180 | return 0; |
---|
181 | } /*endif*/ |
---|
182 | strcpy( str, pa_pvalue(3) ); |
---|
183 | if (Cap(*str) == 'S') *str = '-'; |
---|
184 | if (Cap(*str) == 'N') *str = '+'; |
---|
185 | if (sscanf( str, "%lf", &lat2 ) != 1) { |
---|
186 | printf( "*** couldn't read latitude 2 %s\n", str ); |
---|
187 | return 0; |
---|
188 | } /*endif*/ |
---|
189 | strcpy( str, pa_pvalue(4) ); |
---|
190 | if (Cap(*str) == 'W') *str = '-'; |
---|
191 | if (Cap(*str) == 'E') *str = '+'; |
---|
192 | if (sscanf( str, "%lf", &lon2 ) != 1) { |
---|
193 | printf( "*** couldn't read longitude 2 %s\n", str ); |
---|
194 | return 0; |
---|
195 | } /*endif*/ |
---|
196 | } /*endif*/ |
---|
197 | |
---|
198 | sphere = pa_qspecified( "-s" ); |
---|
199 | depth = 0.0; |
---|
200 | if (NULL != (depth_val = pa_qvalue("-d"))) { |
---|
201 | sscanf( depth_val, "%f", &depth ); |
---|
202 | } /*endif*/ |
---|
203 | |
---|
204 | if (sphere) { |
---|
205 | flat1 = lat1; flon1 = lon1; |
---|
206 | flat2 = lat2; flon2 = lon2; |
---|
207 | mb_spherediff( flat2, flon2, flat1, flon1, &fdist, &fbazim ); |
---|
208 | printf( "\n distance: %f deg\n", fdist ); |
---|
209 | printf( " backazimuth: %f deg\n", fbazim ); |
---|
210 | distance = fdist; |
---|
211 | } else { |
---|
212 | mb_locdiff( lat2, lon2, lat1, lon1, &distance, &azim, &bazim ); |
---|
213 | printf( "\n distance: %lf deg\n", distance ); |
---|
214 | printf( " azimuth: %lf deg\n", azim ); |
---|
215 | printf( " backazimuth: %lf deg\n", bazim ); |
---|
216 | } /*endif*/ |
---|
217 | |
---|
218 | p_slowness = pt_slowness( "P", distance, depth, &status ); |
---|
219 | if (Severe(&status)) { |
---|
220 | printf( " P-slowness: not computed\n\n" ); |
---|
221 | } else { |
---|
222 | printf( " P-slowness: %4.1f (depth %4.1fkm)\n\n", |
---|
223 | p_slowness, depth ); |
---|
224 | } /*endif*/ |
---|
225 | |
---|
226 | /*return 0;*/ |
---|
227 | |
---|
228 | } /* end of main */ |
---|