-
Notifications
You must be signed in to change notification settings - Fork 2
/
travelt.c
148 lines (144 loc) · 4.12 KB
/
travelt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
Program to print out traveltime data for 1d linear gradeint layered models.
Einar Kjartransson, 2016
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define _GNU_SOURCE
#include <fenv.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include "ray.h"
char *velFile = "silp.vel" ;
double sourceDepth = 4.5 ;
double bottomDepth = 15 ;
double velReduce = 7.0 ;
int nPoint = 10 ;
double xSolve,zSolve ;
char *tableFile ;
double xEnd ;
int xCount ;
int nResample = 0 ;
double dzResample ;
char outputName[300] ;
VelModel m ;
void doXList()
{
int i ;
double x,t,dxdp,p,dtdx ;
FILE *fd ;
fd = fopen("travelt.xlist","w") ;
for( i = 0 ; i < xCount ; i++) {
x = (i + 0.5) * xEnd / xCount ;
t = timeFromDist(&m,x,sourceDepth,&p,&dtdx,&dxdp ) ;
if( 0.001 >= fabs(dxdp) )
fprintf(fd,"%10.6f %10.6f %10.6f %10.6f %10.6f\n",x,t,p,dtdx,dxdp) ;
}
fclose(fd) ;
}
void readFromTable()
{
FILE *table ;
char line[305] ;
int i,len ;
double x,z,t ;
double tt,dtdx,dxdp,p,dt,sum1,sigma,res,sum2,sigma2,drt ;
table = fopen(tableFile,"r") ;
sum1 = 0.0 ;
sum2 = 0.0 ;
i = 0 ;
len = 300 ;
while( fgets( line,len,table) ) {
sscanf(line,"%lf %lf %lf %lf",&x,&z,&t,&res) ;
tt = timeFromDist(&m,x,z,&p,&dtdx,&dxdp) ;
drt = tt-t+res ;
dt = tt-t ;
printf("%10.4f %10.4f %10.4f %10.4f %8.3f %8.3f %10.5f %s",x,z,t,tt,dt,drt,1.0/dxdp,line) ;
i++ ;
sum1 += dt*dt ;
sum2 += drt*drt ;
}
sigma = sqrt(sum1/i ) ;
sigma2 = sqrt(sum2/i ) ;
printf("n=%d sigma=%10.4f sigma2=%8.3f\n",i,sigma,sigma2) ;
}
void doIt()
{
double pMax, pBottom, p,pp , dp, x,t, reduce ;
double dtdx,dpdx,p1,x1,dxdp ;
int il,i, mmode ;
FILE *ofd ;
ofd = fopen(outputName,"w") ;
if( velReduce > 0.0 ) reduce = 1.0/velReduce ; else reduce = 0.0 ;
initVelModel(200, &m ) ;
readVelModel(velFile, &m) ;
if( nResample > 1 ) { m = resampleVelModel(&m,dzResample,nResample); }
if( shLogLevel >= 3 ) printVelModel( &m) ;
pMax = 1.0/velZ(sourceDepth,&m,&il ) ;
mmode = RayDown ;
if( sourceDepth <= 0.0 ) mmode = SURFACE ;
else for( i = 0 ; i < nPoint ; i++) {
p1 = (i + 0.8) *pMax / nPoint ;
x1 = traceUD( RayUP, p1, sourceDepth, &m, &t) ;
p = (i + 0.81) *pMax / nPoint ;
x = traceUD( RayUP, p, sourceDepth, &m, &t) ;
dpdx = ( p1-p) / (x1-x) ;
fprintf(ofd,"%10.5f %10.5f %6d %10.6f %10.6f\n",x,t-x*reduce,i,p,dpdx) ;
}
pBottom = 1.0/velZ(bottomDepth,&m,&il) ;
dp = pMax - pBottom ;
for( i = 0 ; i < nPoint ; i++) {
/* p = pMax - (i+0.1)*dp/nPoint ; */
p1 = 1.0/velZ( sourceDepth + (i+0.21)*(bottomDepth-sourceDepth)/nPoint,&m,&il);
x1 = traceUD( mmode , p1, sourceDepth, &m, &t) ;
p = 1.0/velZ( sourceDepth + (i+0.2)*(bottomDepth-sourceDepth)/nPoint,&m,&il);
x = traceUD( mmode , p, sourceDepth, &m, &t) ;
dpdx = ( p1-p) / (x1-x) ;
fprintf(ofd,"%10.5f %10.5f %6d %10.6f %10.6f %10.4f\n",x,t-x*reduce,i,p,dpdx,zBottom) ;
}
if( 0.0 != xSolve) t = timeFromDist(&m,xSolve,sourceDepth,&pp,&dtdx,&dxdp) ;
if( tableFile) readFromTable() ;
fclose(ofd) ;
}
void makeOutputName( int i , char *a )
{
char *b ;
b = outputName ;
if(*a == '.') a++ ;
if(*a == '/') a++ ;
b=strcpy(b,"P") ; b += 1 ;
while ( i > 0 ) {
*b = *a++ ;
if( *b++ == 0 ) { b-- ; i-- ; }
}
}
int main(int ac , char **av )
{
extern char *optarg ;
extern int optind ;
int cc ;
feenableexcept(FE_INVALID) ;
while( EOF != (cc = getopt(ac,av,"f:l:d:n:b:v:o:sr:x:t:X:hH?"))) {
switch(cc) {
case 'f': velFile=optarg ; break ;
case 'l' : shLogLevel = atoi(optarg) ; break ;
case 'd' : sourceDepth = atof(optarg) ; break ;
case 'n' : nPoint = atoi(optarg) ; break ;
case 'b' : bottomDepth = atof(optarg) ; break ;
case 'v' : velReduce = atof(optarg) ; break ;
case 'o' : strcpy( outputName,optarg) ; break ;
case 's' : splineTest() ; break ;
case 'r' : nResample = atoi(optarg) ; dzResample = atof(av[optind++]) ; break ;
case 'x' : xSolve = atof(optarg) ; break ;
case 't' : tableFile = optarg ; break ;
case 'X' : xEnd = atof(optarg) ; xCount = atof(av[optind++]) ; break ;
}}
if( 0 == *outputName ) makeOutputName(ac,*av) ;
fprintf(stderr,"_%s_\n",outputName) ;
doIt() ;
if( xCount ) doXList() ;
return 0 ;
}