source: SH_SHM/trunk/util/evt2phasetimes.c @ 92

Revision 16, 6.6 KB checked in by marcus, 15 years ago (diff)

r1 | svn | 2007-12-13 11:10:29 +0100 (Do, 13 Dez 2007) | 2 lines

Initial import

Line 
1
2/* file evt2phasetimes.c
3 *      ================
4 *
5 * version 3, 3-Jan-2006
6 *
7 * Writes out realtive arrival times (to origin time) and epicentral distances
8 * K. Stammler, 8-Aug-96
9 */
10
11
12/*
13 *
14 *  SeismicHandler, seismic analysis software
15 *  Copyright (C) 1996,  Klaus Stammler, Federal Institute for Geosciences
16 *                                       and Natural Resources (BGR), Germany
17 *
18 *  This program is free software; you can redistribute it and/or modify
19 *  it under the terms of the GNU General Public License as published by
20 *  the Free Software Foundation; either version 2 of the License, or
21 *  (at your option) any later version.
22 *
23 *  This program is distributed in the hope that it will be useful,
24 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 *  GNU General Public License for more details.
27 *
28 *  You should have received a copy of the GNU General Public License
29 *  along with this program; if not, write to the Free Software
30 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
31 *
32 */
33
34
35#include <stdio.h>
36#include <string.h>
37#include <math.h>
38#include "basecnst.h"
39#ifdef BC_INC_STDLIB
40#include BC_INC_STDLIB
41#endif
42#include "sysbase.h"
43#include "cpar.h"
44#include "earthloc.h"
45#include "glusrdef.h"
46#include "erusrdef.h"
47#include "tcusrdef.h"
48#include "eventdsc.h"
49
50
51/* constants */
52#define cPtStatLth 5
53#define cPtMaxPhases 100
54
55
56/* types */
57typedef struct {
58        char     station[cPtStatLth+1];     /* station code */
59        double   slat;                      /* station latitude in deg */
60        double   slon;                      /* station longitude in deg */
61        float    elev;                      /* station elevation */
62        char     abstime[cBcTimeLth+1];     /* absolute onset time */
63        float    reltime;                   /* relative onset time */
64        float    epidist;                   /* epicentral distance */
65        float    resid;                     /* computed relidual for best fit */
66        char     phase[EvPHASELTH+1];       /* phase name */
67} TPtReltime;
68
69
70/* global variables */
71static TPtReltime tpv_inf[cPtMaxPhases];  /* phase info */
72
73
74
75int main( int argc, char *argv[] )
76{
77        /* local variables */
78        char     *inputs;                     /* pointer to environment variables */
79        char     str[cBcLineLth+1];           /* scratch string */
80        char     evtfile[cBcFileLth+1];       /* evt filename */
81        FILE     *evt;                        /* pointer to evt file */
82        EvEventT phinf;                       /* phase info */
83        TSyBoolean eof;                       /* EOF found */
84        TSyStatus status;                     /* return status */
85        int      phcnt;                       /* phase counter */
86        int      i;                           /* counter */
87        char     origin[cBcTimeLth+1];        /* origin time */
88        GLT_STATINF statinf;                  /* station info */
89        float    epilat, epilon;              /* epicenter */
90        double   d_dist, d_azim, d_bazim;     /* epicentral distance, azimuths */
91        TSyBoolean longdesc;                  /* for longdesc entry */
92        TSyBoolean origok;                    /* origin time found */
93        TSyBoolean epicok;                    /* epicentre found */
94
95        /* executable code */
96
97        status = cBcNoError;
98
99        pa_init( argc, argv );
100        if  (pa_pnumber() != 1)  {
101                fprintf( stderr, "Usage: %s <evtfile>\n",
102                        pa_progname() );
103                return 1;
104        } /*endif*/
105
106        /* get parameters (overwrite defaults) */
107        strcpy( evtfile, pa_pvalue(1) );
108
109        longdesc = pa_qspecified( "-longdesc" );
110
111        /* initialization of libraries */
112        inputs = (char *)getenv( "SH_INPUTS" );
113        if  (inputs == NULL)  {
114                fprintf( stderr, "%s: environment SH_INPUTS not set\n", pa_progname() );
115                return 1;
116        } /*endif*/
117        /* station location file */
118        strcpy( str, inputs );
119        strcat( str, "/" );
120        strcat( str, "STATINF.DAT" );
121        gl_locfile_name( str );
122
123#ifdef XXX
124        /* travel time tables */
125        strcpy( str, inputs );
126        strcat( str, "/" );
127        status = cBcNoError;
128        pt_settabledir( str, &status );
129        if  (SySevere(&status))  err_writemsg( status, "", TRUE );
130#endif
131
132        evt = fopen( evtfile, "r" );
133        if  (evt == NULL)  {
134                fprintf( stderr, "%s: input file %s not found.  Abort.\n",
135                        pa_progname(), evtfile );
136                return 1;
137        } /*endif*/
138
139        /* read through all phases */
140        eof = FALSE;
141        phcnt = 0;
142        *origin = '\0';
143        epilat = epilon = 0.0;
144        FOREVER  {
145
146                EvInitializeEvent( &phinf );
147                EvGetEvent( evt, &phinf, &eof, &status );
148                if  (eof)  break;
149                if  (phcnt == cPtMaxPhases)  {
150                        fprintf( stderr, "%s: too many phases.  Abort.\n", pa_progname() );
151                        exit( 1 );
152                } /*endif*/
153
154                if  (strcmp(phinf.phase,"L") == 0)  continue;
155                if  (strcmp(phinf.phase,"X") == 0)  continue;
156                if  (strcmp(phinf.station,"BEAM") == 0)  continue;
157                if  (strcmp(phinf.station,"ALIGN") == 0)  continue;
158
159                strcpy( tpv_inf[phcnt].station, phinf.station );
160                strcpy( tpv_inf[phcnt].phase, phinf.phase );
161                strcpy( tpv_inf[phcnt].abstime, phinf.onset_time );
162
163                if  (phinf.origin_time[0] != '\0')  strcpy( origin, phinf.origin_time );
164                if  (phinf.latitude != EvEMPTY_LATITUDE)  epilat = phinf.latitude;
165                if  (phinf.longitude != EvEMPTY_LONGITUDE)  epilon = phinf.longitude;
166
167                phcnt++;
168
169        } /*endwhile*/
170
171        fclose( evt );
172
173        origok = epicok = TRUE;
174        if  (*origin == '\0')  {
175                if  (longdesc)  {
176                        origok = FALSE;
177                } else {
178                        fprintf( stderr, "%s: no origin time found in %s.  Abort.\n",
179                                pa_progname(), evtfile );
180                        exit( 1 );
181                } /*endif*/
182        } /*endif*/
183        if  (epilat == 0.0 && epilon == 0.0)  {
184                if  (longdesc)  {
185                        epicok = FALSE;
186                } else {
187                        fprintf( stderr, "%s: no epicenter found in %s.  Abort.\n",
188                                pa_progname(), evtfile );
189                        exit( 1 );
190                } /*endif*/
191        } /*endif*/
192
193        for  (i=0; i<phcnt; i++)  {
194                if  (!origok || !epicok)  {
195                        tpv_inf[i].reltime = 0.0;
196                        tpv_inf[i].epidist = 0.0;
197                        continue;
198                } /*endif*/
199                tpv_inf[i].reltime = tc_tdiff( tpv_inf[i].abstime, origin, &status );
200                if  (SySevere(&status))  err_writemsg( status, "", TRUE );
201                gl_statinf( tpv_inf[i].station, &statinf, &status );
202                if  (SySevere(&status))  err_writemsg( status, "", TRUE );
203                mb_locdiff( statinf.lat, statinf.lon, (double)epilat, (double)epilon,
204                        &d_dist, &d_azim, &d_bazim );
205                tpv_inf[i].epidist = (float)d_dist * 111.19;
206        } /*endif*/
207
208        if  (longdesc)  {
209                for  (i=0; i<phcnt; i++)  {
210                        printf( "%-5s time: %s phase: %-6s", tpv_inf[i].station,
211                                tpv_inf[i].abstime, tpv_inf[i].phase );
212                        if  (origok && epicok)
213                                printf( "ttime: %7.2f dist: %8.1f",
214                                        tpv_inf[i].reltime, tpv_inf[i].epidist );
215                        printf( "\n" );
216                } /*endif*/
217        } else {
218                for  (i=0; i<phcnt; i++)  {
219                        printf( "%-4s %-5s %7.2f %8.1f    %s\n", tpv_inf[i].phase,
220                                tpv_inf[i].station,  tpv_inf[i].reltime, tpv_inf[i].epidist,
221                                tpv_inf[i].abstime );
222                } /*endif*/
223        } /*endif*/
224
225        return 0;
226
227} /* end of main */
228
229
230
Note: See TracBrowser for help on using the repository browser.