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 | |
---|
53 | |
---|
54 | |
---|
55 | /* global variable */ |
---|
56 | char shd_errors[BC_FILELTH+1]; |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | int main( int argc, char *argv[] ) |
---|
61 | { |
---|
62 | /* local variables */ |
---|
63 | double lat1, lon1; /* first location */ |
---|
64 | double lat2, lon2; /* second location */ |
---|
65 | double distance, azim, bazim; /* output values */ |
---|
66 | float p_slowness; /* P slowness */ |
---|
67 | float depth; /* depth of event */ |
---|
68 | char *depth_val; /* string of depth */ |
---|
69 | float fdist, fbazim; /* float output */ |
---|
70 | float flat1, flon1, flat2, flon2; |
---|
71 | STATUS status; /* return status */ |
---|
72 | char stat1[BC_LINELTH+1]; /* name of first station */ |
---|
73 | char stat2[BC_LINELTH+1]; /* name of second station */ |
---|
74 | char str[BC_LINELTH+1]; /* scratch */ |
---|
75 | BOOLEAN sphere; /* sphere computation */ |
---|
76 | char path[BC_FILELTH+1]; /* path to input files */ |
---|
77 | GLT_STATINF inf; /* station info */ |
---|
78 | # ifdef BC_SUN |
---|
79 | char *eptr; /* environment pointer */ |
---|
80 | # endif |
---|
81 | |
---|
82 | /* executable code */ |
---|
83 | |
---|
84 | # ifdef BC_SUN |
---|
85 | eptr = getenv( "SH_ERRORS" ); |
---|
86 | if (eptr != NULL) strcpy( shd_errors, eptr ); |
---|
87 | eptr = getenv( "SH_INPUTS" ); |
---|
88 | if (eptr != NULL) { |
---|
89 | strcpy( path, eptr ); |
---|
90 | } else { |
---|
91 | *path = '\0'; |
---|
92 | } /*endif*/ |
---|
93 | # else |
---|
94 | strcpy( path, IF_PATH ); |
---|
95 | # endif |
---|
96 | |
---|
97 | strcpy( str, path ); |
---|
98 | strcat( str, IF_STATINFFILE ); |
---|
99 | gl_locfile_name( str ); |
---|
100 | pt_settabledir( path, &status ); |
---|
101 | status = BC_NOERROR; |
---|
102 | pt_settabledir( path, &status ); |
---|
103 | if (Severe(&status)) { |
---|
104 | printf( "*** couldn't set table dir %s ***\n", path ); |
---|
105 | return 1; |
---|
106 | } /*endif*/ |
---|
107 | |
---|
108 | pa_init( argc, argv ); |
---|
109 | if (pa_pnumber() < 2 || pa_pnumber() > 4) { |
---|
110 | printf( " \n" ); |
---|
111 | printf( " locdiff determines distance and azimuth between\n" ); |
---|
112 | printf( " two locations. The location must be given either\n" ); |
---|
113 | printf( " explicitely or by station names.\n" ); |
---|
114 | printf( " Usage: locdiff <lat1> <lon1> <lat2> <lon2>\n" ); |
---|
115 | printf( " or: locdiff <lat> <lon> <station>\n" ); |
---|
116 | printf( " or: locdiff <station1> <station2>\n\n" ); |
---|
117 | return 0; |
---|
118 | } else if (pa_pnumber() == 2) { |
---|
119 | strcpy( stat1, pa_pvalue(1) ); |
---|
120 | ut_cap( stat1 ); |
---|
121 | /* gl_statloc( stat1, &lat1, &lon1, &status ); */ |
---|
122 | gl_statinf( stat1, &inf, &status ); |
---|
123 | if (status != BC_NOERROR) { |
---|
124 | printf( "*** couldn't get station location of %s\n", stat1 ); |
---|
125 | return 0; |
---|
126 | } /*endif*/ |
---|
127 | lat1 = inf.lat; |
---|
128 | lon1 = inf.lon; |
---|
129 | strcpy( stat2, pa_pvalue(2) ); |
---|
130 | ut_cap( stat2 ); |
---|
131 | /* gl_statloc( stat2, &lat2, &lon2, &status ); */ |
---|
132 | gl_statinf( stat2, &inf, &status ); |
---|
133 | if (status != BC_NOERROR) { |
---|
134 | printf( "*** couldn't get station location of %s\n", stat2 ); |
---|
135 | return 0; |
---|
136 | } /*endif*/ |
---|
137 | lat2 = inf.lat; |
---|
138 | lon2 = inf.lon; |
---|
139 | } else if (pa_pnumber() == 3) { |
---|
140 | strcpy( str, pa_pvalue(1) ); |
---|
141 | if (Cap(*str) == 'S') *str = '-'; |
---|
142 | if (Cap(*str) == 'N') *str = '+'; |
---|
143 | if (sscanf( str, "%lf", &lat1 ) != 1) { |
---|
144 | printf( "*** couldn't read latitude %s\n", str ); |
---|
145 | return 0; |
---|
146 | } /*endif*/ |
---|
147 | strcpy( str, pa_pvalue(2) ); |
---|
148 | if (Cap(*str) == 'W') *str = '-'; |
---|
149 | if (Cap(*str) == 'E') *str = '+'; |
---|
150 | if (sscanf( str, "%lf", &lon1 ) != 1) { |
---|
151 | printf( "*** couldn't read longitude %s\n", str ); |
---|
152 | return 0; |
---|
153 | } /*endif*/ |
---|
154 | strcpy( stat1, pa_pvalue(3) ); |
---|
155 | ut_cap( stat1 ); |
---|
156 | /* gl_statloc( stat1, &lat2, &lon2, &status ); */ |
---|
157 | gl_statinf( stat1, &inf, &status ); |
---|
158 | if (status != BC_NOERROR) { |
---|
159 | printf( "*** couldn't get station location of %s\n", stat1 ); |
---|
160 | return 0; |
---|
161 | } /*endif*/ |
---|
162 | lat2 = inf.lat; |
---|
163 | lon2 = inf.lon; |
---|
164 | } else { |
---|
165 | strcpy( str, pa_pvalue(1) ); |
---|
166 | if (Cap(*str) == 'S') *str = '-'; |
---|
167 | if (Cap(*str) == 'N') *str = '+'; |
---|
168 | if (sscanf( str, "%lf", &lat1 ) != 1) { |
---|
169 | printf( "*** couldn't read latitude 1 %s\n", str ); |
---|
170 | return 0; |
---|
171 | } /*endif*/ |
---|
172 | strcpy( str, pa_pvalue(2) ); |
---|
173 | if (Cap(*str) == 'W') *str = '-'; |
---|
174 | if (Cap(*str) == 'E') *str = '+'; |
---|
175 | if (sscanf( str, "%lf", &lon1 ) != 1) { |
---|
176 | printf( "*** couldn't read longitude 1 %s\n", str ); |
---|
177 | return 0; |
---|
178 | } /*endif*/ |
---|
179 | strcpy( str, pa_pvalue(3) ); |
---|
180 | if (Cap(*str) == 'S') *str = '-'; |
---|
181 | if (Cap(*str) == 'N') *str = '+'; |
---|
182 | if (sscanf( str, "%lf", &lat2 ) != 1) { |
---|
183 | printf( "*** couldn't read latitude 2 %s\n", str ); |
---|
184 | return 0; |
---|
185 | } /*endif*/ |
---|
186 | strcpy( str, pa_pvalue(4) ); |
---|
187 | if (Cap(*str) == 'W') *str = '-'; |
---|
188 | if (Cap(*str) == 'E') *str = '+'; |
---|
189 | if (sscanf( str, "%lf", &lon2 ) != 1) { |
---|
190 | printf( "*** couldn't read longitude 2 %s\n", str ); |
---|
191 | return 0; |
---|
192 | } /*endif*/ |
---|
193 | } /*endif*/ |
---|
194 | |
---|
195 | sphere = pa_qspecified( "-s" ); |
---|
196 | depth = 0.0; |
---|
197 | if (NULL != (depth_val = pa_qvalue("-d"))) { |
---|
198 | sscanf( depth_val, "%f", &depth ); |
---|
199 | } /*endif*/ |
---|
200 | |
---|
201 | if (sphere) { |
---|
202 | flat1 = lat1; flon1 = lon1; |
---|
203 | flat2 = lat2; flon2 = lon2; |
---|
204 | mb_spherediff( flat2, flon2, flat1, flon1, &fdist, &fbazim ); |
---|
205 | printf( "\n distance: %f deg\n", fdist ); |
---|
206 | printf( " backazimuth: %f deg\n", fbazim ); |
---|
207 | distance = fdist; |
---|
208 | } else { |
---|
209 | mb_locdiff( lat2, lon2, lat1, lon1, &distance, &azim, &bazim ); |
---|
210 | printf( "\n distance: %lf deg\n", distance ); |
---|
211 | printf( " azimuth: %lf deg\n", azim ); |
---|
212 | printf( " backazimuth: %lf deg\n", bazim ); |
---|
213 | } /*endif*/ |
---|
214 | |
---|
215 | p_slowness = pt_slowness( "P", distance, depth, &status ); |
---|
216 | if (Severe(&status)) { |
---|
217 | printf( " P-slowness: not computed\n\n" ); |
---|
218 | } else { |
---|
219 | printf( " P-slowness: %4.1f (depth %4.1fkm)\n\n", |
---|
220 | p_slowness, depth ); |
---|
221 | } /*endif*/ |
---|
222 | |
---|
223 | /*return 0;*/ |
---|
224 | |
---|
225 | } /* end of main */ |
---|