Commit bac9692e authored by Jan Becker's avatar Jan Becker
Browse files

[LocSAT] Clean up some code, fix variable initializations and make compute_ttime work

parent fafa2944
......@@ -18,32 +18,16 @@
typedef struct arrival
{
char sta[16];
char chan[9];
double time;
long arid;
long stassid;
long chanid;
long jdate;
char iphase[9];
char stype[2];
float deltim;
float azimuth;
float delaz;
float slow;
float delslo;
float ema;
float rect;
float amp;
float per;
float logat;
char clip[2];
char fm[3];
float snr;
char qual[2];
char auth[16];
long commid;
char lddate[18];
char sta[16];
double time;
long arid;
char iphase[9];
char stype[2];
float deltim;
float azimuth;
float delaz;
float slow;
float delslo;
} Arrival;
#endif /* DB_ARRIVAL_H */
......@@ -17,25 +17,22 @@
#define DB_ASSOC_H
typedef struct assoc {
long arid;
long orid;
char sta[16];
char phase[9];
float belief;
float delta;
float seaz;
float esaz;
float timeres;
char timedef[2];
float azres;
char azdef[2];
float slores;
char slodef[2];
float emares;
float wgt;
char vmodel[16];
long commid;
char lddate[18];
long arid;
char sta[16];
char phase[9];
float belief;
float delta;
float seaz;
float esaz;
float timeres;
char timedef[2];
float azres;
char azdef[2];
float slores;
char slodef[2];
float emares;
float wgt;
char vmodel[16];
} Assoc;
#endif /* DB_ASSOC_H */
......@@ -17,26 +17,23 @@
#define DB_ORIGERR_H
typedef struct origerr {
long orid;
float sxx;
float syy;
float szz;
float stt;
float sxy;
float sxz;
float syz;
float stx;
float sty;
float stz;
float sdobs;
float smajax;
float sminax;
float strike;
float sdepth;
float stime;
float conf;
long commid;
char lddate[18];
float sxx;
float syy;
float szz;
float stt;
float sxy;
float sxz;
float syz;
float stx;
float sty;
float stz;
float sdobs;
float smajax;
float sminax;
float strike;
float sdepth;
float stime;
float conf;
} Origerr;
#endif /* DB_ORIGERR_H */
......@@ -17,31 +17,14 @@
#define DB_ORIGIN_H
typedef struct origin {
float lat;
float lon;
float depth;
double time;
long orid;
long evid;
long jdate;
long nass;
long ndef;
long ndp;
long grn;
long srn;
char etype[8];
float depdp;
char dtype[2];
float mb;
long mbid;
float ms;
long msid;
float ml;
long mlid;
char algorithm[16];
char auth[16];
long commid;
char lddate[18];
float lat;
float lon;
float depth;
double time;
long nass;
long ndef;
long ndp;
char auth[16];
} Origin;
#endif /* DB_ORIGIN_H */
......@@ -21,18 +21,12 @@
typedef struct site
{
char sta[16];
long ondate;
long offdate;
float lat;
float lon;
float elev;
char staname[256];
char statype[5];
char refsta[7];
float dnorth;
float deast;
char lddate[18];
char sta[16];
long ondate;
long offdate;
float lat;
float lon;
float elev;
} Site;
#endif /* DB_SITE_H */
/***************************************************************************
* Copyright (C) by gempa GmbH *
* *
* You can redistribute and/or modify this program under the *
* terms of the SeisComP Public License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* SeisComP Public License for more details. *
***************************************************************************/
#ifndef __SEISCOMP_LOCSAT_UTILS_H__
#define __SEISCOMP_LOCSAT_UTILS_H__
#include <stdlib.h>
#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (double)min(a,b)
#define dmax(a,b) (double)max(a,b)
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (double)abs(x)
#endif
......@@ -43,7 +43,7 @@ integer f_end(alist *a)
if(b->ufd==NULL) {
char nbuf[10];
sprintf(nbuf,"fort.%ld",(long)a->aunit);
if (tf = FOPEN(nbuf, f__w_mode[0]))
if ((tf = FOPEN(nbuf, f__w_mode[0])))
fclose(tf);
return(0);
}
......
......@@ -106,7 +106,7 @@ flag f__lquit;
int f__lcount,f__ltype,nml_read;
char *f__lchar;
double f__lx,f__ly;
#define ERR(x) if(n=(x)) return(n)
#define ERR(x) if((n=(x))) return(n)
#define GETC(x) (x=(*l_getc)())
#define Ungetc(x,y) (*l_ungetc)(x,y)
......@@ -291,11 +291,12 @@ l_C(Void)
f__lquit = 2;
return 0;
}
if (rd_count(ch))
if (rd_count(ch)) {
if(!f__cf || !feof(f__cf))
errfl(f__elist->cierr,112,"complex format");
else
err(f__elist->cierr,(EOF),"lread");
}
if(GETC(ch)!='*')
{
if(!f__cf || !feof(f__cf))
......@@ -314,7 +315,7 @@ l_C(Void)
Ungetc(ch,f__cf);
nml_save = nml_read;
nml_read = 0;
if (ch = l_R(1,0))
if ((ch = l_R(1,0)))
return ch;
if (!f__ltype)
errfl(f__elist->cierr,112,"no real part");
......@@ -326,7 +327,7 @@ l_C(Void)
}
while(iswhit(GETC(ch)));
(void) Ungetc(ch,f__cf);
if (ch = l_R(1,0))
if ((ch = l_R(1,0)))
return ch;
if (!f__ltype)
errfl(f__elist->cierr,112,"no imaginary part");
......@@ -353,7 +354,7 @@ l_C(Void)
nmL_getc(Void)
{
int rv;
if (rv = *nmL_next++)
if ((rv = *nmL_next++))
return rv;
l_getc = nmL_getc_save;
l_ungetc = nmL_ungetc_save;
......@@ -435,11 +436,12 @@ l_L(Void)
if(isdigit(ch))
{
rd_count(ch);
if(GETC(ch)!='*')
if(GETC(ch)!='*') {
if(!f__cf || !feof(f__cf))
errfl(f__elist->cierr,112,"no star");
else
err(f__elist->cierr,(EOF),"lread");
}
GETC(ch);
}
sawdot = 0;
......@@ -787,7 +789,7 @@ integer s_rsle(cilist *a)
f__reading=1;
f__external=1;
f__formatted=1;
if(n=c_le(a)) return(n);
if((n=c_le(a))) return(n);
f__lioproc = l_read;
f__lquit = 0;
f__lcount = 0;
......
......@@ -138,7 +138,7 @@ l_g(char *buf, double n)
switch(*b) {
#ifndef WANT_LEAD_0
case '0':
while(b[0] = b[1])
while((b[0] = b[1]))
b++;
break;
#endif
......@@ -163,8 +163,7 @@ l_g(char *buf, double n)
while(*++b);
goto f__ret;
case 'E':
for(c1 = '.', c = 'E'; *b = c1;
c1 = c, c = *++b);
for(c1 = '.', c = 'E'; (*b = c1); c1 = c, c = *++b);
goto f__ret;
}
}
......@@ -187,7 +186,7 @@ l_put(register char *s)
#endif
register int c;
while(c = *s++)
while((c = *s++))
(*pn)(c);
}
......
......@@ -243,7 +243,7 @@ integer f_open(olist *a)
#ifdef NON_ANSI_STDIO
replace:
#endif
if (tf = FOPEN(buf,f__w_mode[0]))
if ((tf = FOPEN(buf,f__w_mode[0])))
fclose(tf);
}
......@@ -253,9 +253,9 @@ integer f_open(olist *a)
if ((s = a->oacc) && b->url)
ufmt = 0;
if(!(tf = FOPEN(buf, f__w_mode[ufmt|2]))) {
if (tf = FOPEN(buf, f__r_mode[ufmt]))
if ((tf = FOPEN(buf, f__r_mode[ufmt])))
b->urw = 1;
else if (tf = FOPEN(buf, f__w_mode[ufmt])) {
else if ((tf = FOPEN(buf, f__w_mode[ufmt]))) {
b->uwrt = 1;
b->urw = 2;
}
......@@ -267,12 +267,13 @@ integer f_open(olist *a)
if((b->uinode = f__inode(buf,&b->udev)) == -1)
opnerr(a->oerr,108,"open")
#endif
if(b->useek)
if(b->useek) {
if (a->orl)
rewind(b->ufd);
else if ((s = a->oacc) && (*s == 'a' || *s == 'A')
&& FSEEK(b->ufd, 0L, SEEK_END))
opnerr(a->oerr,129,"open");
}
return(0);
}
......
......@@ -36,10 +36,10 @@ rd_Z(Uint *n, int w, ftnlen len)
if (!hex['0']) {
sc = "0123456789";
while(ch = *sc++)
while( (ch = *sc++) )
hex[ch] = ch - '0' + 1;
sc = "ABCDEF";
while(ch = *sc++)
while( (ch = *sc++) )
hex[ch] = hex[ch + 'a' - 'A'] = ch - 'A' + 11;
}
s = s0 = (char *)x;
......@@ -68,7 +68,7 @@ rd_Z(Uint *n, int w, ftnlen len)
return errno = 115;
w = (int)len;
w1 = s - s0;
w2 = w1+1 >> 1;
w2 = (w1+1) >> 1;
t = (char *)n;
if (*(char *)&one) {
/* little endian */
......@@ -90,7 +90,7 @@ rd_Z(Uint *n, int w, ftnlen len)
t += i;
}
do {
*t = hex[*s0 & 0xff]-1 << 4 | hex[s0[1] & 0xff]-1;
*t = ((hex[*s0 & 0xff]-1) << 4) | (hex[s0[1] & 0xff]-1);
t += i;
s0 += 2;
}
......
......@@ -64,7 +64,7 @@ integer s_rsfe(cilist *a) /* start */
f__sequential=1;
f__formatted=1;
f__external=1;
if(n=c_sfe(a)) return(n);
if((n=c_sfe(a))) return(n);
f__elist=a;
f__cursor=f__recpos=0;
f__scale=0;
......
......@@ -137,7 +137,7 @@ nogood:
/* exponent field if it fits. */
#else
if (!e0) {
for(s -= 2, e1 = 2; s[0] = s[1]; s++)
for(s -= 2, e1 = 2; (s[0] = s[1]); s++)
#ifdef CRAY
delta--;
if ((delta += 4) < 0)
......@@ -233,11 +233,12 @@ wrt_F(ufloat *p, int w, int d, ftnlen len)
#endif
}
if (n = f__scale)
if ( (n = f__scale) ) {
if (n > 0)
do x *= 10.; while(--n > 0);
else
do x *= 0.1; while(++n < 0);
}
#ifdef USE_STRLEN
sprintf(b = buf, "%#.*f", d, x);
......@@ -283,7 +284,7 @@ wrt_F(ufloat *p, int w, int d, ftnlen len)
PUT('-');
else if (f__cplus)
PUT('+');
while(n = *b++)
while( (n = *b++) )
PUT(n);
while(--d1 >= 0)
PUT('0');
......
......@@ -52,7 +52,7 @@ integer s_wsfe(cilist *a) /*start*/
f__sequential=1;
f__formatted=1;
f__external=1;
if(n=c_sfe(a)) return(n);
if((n=c_sfe(a))) return(n);
f__elist=a;
f__hiwater = f__cursor=f__recpos=0;
f__nonl = 0;
......
......@@ -14,7 +14,7 @@ integer s_wsle(cilist *a)
#endif
{
int n;
if(n=c_le(a)) return(n);
if((n=c_le(a))) return(n);
f__reading=0;
f__external=1;
f__formatted=1;
......
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
#include "f2c.h"
/* Common Block Declarations */
struct sccsazcros_1_ {
char sccsid[80];
};
#define sccsazcros_1 (*(struct sccsazcros_1_ *) &sccsazcros_)
/* Initialized data */
struct {
char e_1[80];
} sccsazcros_ = { {'@', '(', '#', ')', 'a', 'z', 'c', 'r', 'o', 's', '.',
'f', '\t', '4', '3', '.', '1', '\t', '9', '/', '9', '/', '9', '1',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' '} };
#include "utils.h"
#include <math.h>
/* Table of constant values */
static real c_b2 = (float)1.;
static float c_b2 = (float)1.;
/* Given the locations of two reference points and two azimuths of */
/* great circles passing through those points, the */
......@@ -36,128 +12,128 @@ static real c_b2 = (float)1.;
/* and the distances from two reference points. */
/* -- by Steve Bratt and Donna Williams, June 1986. */
/* Subroutine */ int azcros_(alat1, alon1, aza, alat2, alon2, azb, dista,
distb, alat, alon, ierr)
real *alat1, *alon1, *aza, *alat2, *alon2, *azb, *dista, *distb, *alat, *alon;
integer *ierr;
{
/* System generated locals */
real r__1;
int azcros_(float *alat1, float *alon1, float *aza, float *alat2, float *alon2,
float *azb, float *dista, float *distb, float *alat, float *alon,
int *ierr) {
/* System generated locals */
float r__1;
/* Builtin functions */
double asin(), r_sign(), tan(), sin(), cos(), atan();
/* Builtin functions */
double r_sign();
/* Local variables */
static real dist, e, f, g, h__, delta, c1, c2, c3, c4, c5, ra, rb, rc, az,
alatin, alonin;
extern /* Subroutine */ int latlon_(), distaz_();
static real baz, azi, degtrad;
/* Local variables */
float dist, e, f, g, h__, delta, c1, c2, c3, c4, c5, ra, rb, rc, az,
alatin, alonin;
extern /* Subroutine */ int latlon_(), distaz_();
float baz, azi, degtrad;
/* INPUT: */
/* alat1,alon1,alat2,alon2: locations of reference points */
/* aza,azb: azimuths of great circles passing through points points */
/* 1 and 2, respectively */
/* OUTPUT: */
/* dista,distb: distance from points 1 and 2 to point */
/* great circles cross */
/* alat,alon: location of crossing point. */
/* INPUT: */
/* alat1,alon1,alat2,alon2: locations of reference points */
/* aza,azb: azimuths of great circles passing through points points */
/* 1 and 2, respectively */
/* OUTPUT: */
/* dista,distb: distance from points 1 and 2 to point */
/* great circles cross */
/* alat,alon: location of crossing point. */
/* All distances, azimuths, and locations are input and output */
/* in degrees. */
/* All distances, azimuths, and locations are input and output */
/* in degrees. */
/* ierr : = 0 all O.K., = 1 lines do not cross within reasonable */
/* distance. */
/* ierr : = 0 all O.K., = 1 lines do not cross within reasonable */
/* distance. */
/* SUBROUTINES CALLED: */
/* distaz */
/* latlon, which calls cart */
/* rotate */
/* geog */
/* SUBROUTINES CALLED: */
/* distaz */
/* latlon, which calls cart */
/* rotate */
/* geog */
degtrad = 2 * asin((float)1.) / (float)180.;
degtrad = 2 * asin((float)1.) / (float)180.;
/* Find azimuth, back azimuth and radial distance between */
/* stations. */
distaz_(alat1, alon1, alat2, alon2, &delta, &azi, &baz);
distaz_(alat1, alon1, alat2, alon2, &delta, &azi, &baz);
/* Find sign (clockwise = +) and value of angle measured from line */
/* between two stations to aza and azb. */
ra = *aza - azi;
if (dabs(ra) > (float)180.) {
r__1 = (float)360. - dabs(ra);
ra = -r_sign(&r__1, &ra);
}
rb = *azb - baz;
if (dabs(rb) > (float)180.) {
r__1 = (float)360. - dabs(rb);