1 | |
---|
2 | /* file evt_extract_ms.c |
---|
3 | * ================ |
---|
4 | * |
---|
5 | * version 2, 16-Jan-2007 |
---|
6 | * |
---|
7 | * extracts MS values from evt file |
---|
8 | * K. Stammler, 6-Jul-95 |
---|
9 | * |
---|
10 | */ |
---|
11 | |
---|
12 | |
---|
13 | /* |
---|
14 | * |
---|
15 | * SeismicHandler, seismic analysis software |
---|
16 | * Copyright (C) 1996, Klaus Stammler, Federal Institute for Geosciences |
---|
17 | * and Natural Resources (BGR), Germany |
---|
18 | * |
---|
19 | * This program is free software; you can redistribute it and/or modify |
---|
20 | * it under the terms of the GNU General Public License as published by |
---|
21 | * the Free Software Foundation; either version 2 of the License, or |
---|
22 | * (at your option) any later version. |
---|
23 | * |
---|
24 | * This program is distributed in the hope that it will be useful, |
---|
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
27 | * GNU General Public License for more details. |
---|
28 | * |
---|
29 | * You should have received a copy of the GNU General Public License |
---|
30 | * along with this program; if not, write to the Free Software |
---|
31 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
32 | * |
---|
33 | */ |
---|
34 | |
---|
35 | |
---|
36 | #include <stdio.h> |
---|
37 | #include <string.h> |
---|
38 | #include "basecnst.h" |
---|
39 | #include "sysbase.h" |
---|
40 | #include "tcusrdef.h" |
---|
41 | #include "cpar.h" |
---|
42 | #include "eventdsc.h" |
---|
43 | #include "erusrdef.h" |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | /* prototypes of local routines */ |
---|
48 | static void WriteInfoLineAndClear( EvEventT *linfo ); |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | int main( int argc, char *argv[] ) |
---|
53 | { |
---|
54 | /* local variables */ |
---|
55 | char inpfile[cBcFileLth+1]; /* name of input file */ |
---|
56 | FILE *fp; /* pointer to input file */ |
---|
57 | EvEventT event; /* event (phase) info */ |
---|
58 | BOOLEAN eof; /* eof found */ |
---|
59 | EvStatusT status; /* return status */ |
---|
60 | long curr_evid; /* current event ID */ |
---|
61 | EvEventT linfo; /* L info */ |
---|
62 | |
---|
63 | /* executable code */ |
---|
64 | |
---|
65 | status = cBcNoError; |
---|
66 | pa_init( argc, argv ); |
---|
67 | |
---|
68 | if (pa_pnumber() != 1) { |
---|
69 | fprintf( stderr, "Usage: %s <inpfile>\n", pa_progname() ); |
---|
70 | return 1; |
---|
71 | } /*endif*/ |
---|
72 | strcpy( inpfile, pa_pvalue(1) ); |
---|
73 | |
---|
74 | /* open input file */ |
---|
75 | fp = sy_fopen( inpfile, "r" ); |
---|
76 | if (fp == NULL) { |
---|
77 | fprintf( stderr, "%s: input file %s not found\n", |
---|
78 | pa_progname(), inpfile ); |
---|
79 | return 1; |
---|
80 | } /*endif*/ |
---|
81 | |
---|
82 | /* loop all phases on input */ |
---|
83 | linfo.evid = 0; |
---|
84 | FOREVER { |
---|
85 | EvGetEvent( fp, &event, &eof, &status ); |
---|
86 | if (eof) break; |
---|
87 | if (Severe(&status)) err_writemsg( status, "", TRUE ); |
---|
88 | if (event.evid != linfo.evid) { |
---|
89 | /* new event, write out info */ |
---|
90 | WriteInfoLineAndClear( &linfo ); |
---|
91 | linfo.evid = event.evid; |
---|
92 | } /*endif*/ |
---|
93 | if (event.mag[EvcMagMs] != EvEMPTY_MAGNITUDE) { |
---|
94 | linfo.mag[EvcMagMs] = event.mag[EvcMagMs]; |
---|
95 | strcpy( linfo.station, event.station ); |
---|
96 | if (strcmp(event.phase,"L") != 0 |
---|
97 | && strcmp(event.phase,"(L)") != 0) { |
---|
98 | fprintf( stderr, "%s: MS not on L-phase (phase %s)\n", |
---|
99 | pa_progname(), event.phase ); |
---|
100 | } else { |
---|
101 | strcpy( linfo.onset_time, event.onset_time ); |
---|
102 | } /*endif*/ |
---|
103 | } /*endif*/ |
---|
104 | if (event.latitude != EvEMPTY_LATITUDE) { |
---|
105 | linfo.latitude = event.latitude; |
---|
106 | linfo.longitude = event.longitude; |
---|
107 | linfo.depth = event.depth; |
---|
108 | strcpy( linfo.origin_time, event.origin_time ); |
---|
109 | } /*endif*/ |
---|
110 | } /*endfor*/ |
---|
111 | WriteInfoLineAndClear( &linfo ); |
---|
112 | |
---|
113 | sy_fclose( fp ); |
---|
114 | |
---|
115 | } /* end of main */ |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | /*----------------------------------------------------------------------------*/ |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | static void WriteInfoLineAndClear( EvEventT *linfo ) |
---|
124 | |
---|
125 | /* write out information if available and clears variables |
---|
126 | * |
---|
127 | * parameters of routine |
---|
128 | * EvEventT *linfo; modify; L info |
---|
129 | */ |
---|
130 | { |
---|
131 | /* local variables */ |
---|
132 | |
---|
133 | /* executable code */ |
---|
134 | |
---|
135 | if (linfo->mag[EvcMagMs] != 0.0) { |
---|
136 | printf( "%d %24s %5s %3.1f %24s %6.2f %7.2f %5.1f\n", linfo->evid, |
---|
137 | linfo->onset_time, linfo->station, |
---|
138 | linfo->mag[EvcMagMs], linfo->origin_time, linfo->latitude, linfo->longitude, |
---|
139 | linfo->depth ); |
---|
140 | } /*endif*/ |
---|
141 | |
---|
142 | linfo->mag[EvcMagMs] = 0.0; |
---|
143 | linfo->latitude = 0.0; |
---|
144 | linfo->longitude = 0.0; |
---|
145 | linfo->depth = 0.0; |
---|
146 | linfo->onset_time[0] = '\0'; |
---|
147 | linfo->origin_time[0] = '\0'; |
---|
148 | linfo->station[0] = '\0'; |
---|
149 | |
---|
150 | } /* end of WriteInfoLineAndClear */ |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | /*----------------------------------------------------------------------------*/ |
---|