/
towed_array.cc
182 lines (163 loc) · 4.9 KB
/
towed_array.cc
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <su.h>
#include <segy.h>
#include <header.h>
#include <cubic.h>
#include <parser.h>
#define DT_TOL 0.001
const char * sdoc[] = {
"Usage: towed_array.x data= src= towed_src=",
"",
"Purpose: create towed streamer source traces, by transferring source",
"coordinates to both source and receiver coordinates of source trace",
"copies. As is standard throughout IWAVE, the source traces are regarded",
"as located at their receiver coordinates; since the output data traces",
"will get their source coordinates purely from the input data file, the",
"source coordinates of the input source traces and the receiver",
"coordinates of the input data traces are ignored. That is, if a source",
"trace has receiver coordinates src_gx, src_gy, and src_gelev, and an input",
"data trace has source coordinates data_sx, data_sy, and data_selev, then",
"a trace with coordinates ",
" sx = data_sx,",
" sy = data_sy,",
" selev = data_selev,",
" gx = src_gx+data_sx,",
" gy = src_gy+data_sy,",
" gelev = src_gelev+data_selev,",
"and the other headers and data samples of the source trace is written to",
"the output towed source file. This algorithm produces a towed source data ",
"file, representing the input source data translated by the source position",
"read from the data file. Note that this file need not exist before this",
"command is called.",
"",
"Required parameters:",
" data = filename for first modeled trace data",
" src = source traces to be translated, source and receiver",
" coordinates will be overwritten",
" towed = output file - input source data for IWAVE",
"",
"Optional Parameters:",
" tol [float] = relative error threshhold for sample-by-sample",
" comparison.",
"",
NULL};
int main(int argc, char ** argv) {
/* ARGUMENTS */
char * data; /* trace data file name */
char * src; /* source file name */
char * towed; /* towed source file name */
/* INTERNAL VARIABLES */
PARARRAY * par; /* param array */
FILE * fp1; /* input file pointer */
FILE * fp2; /* input file pointer */
FILE * fp3; /* output file pointer */
segy tr1; /* input 1 trace workspace */
segy * tr2; /* input 2 trace workspace */
int sx=0; /* workspace */
int sy=0; /* workspace */
int selev=0; /* workspace */
int tsx; /* workspace */
int tsy; /* workspace */
int tselev; /* workspace */
int tgx; /* workspace */
int tgy; /* workspace */
int tgelev; /* workspace */
/* int err; global error flag */
int itr; /* trace counter */
int jtr; /* trace counter */
int ktr; /* trace counter */
int ltr; /* trace counter */
int ntr; /* trace counter */
xargc=argc; xargv=argv;
requestdoc(1);
/* err=0; */
/* extract input parameters */
par=ps_new();
if ( ps_createargs(par, argc - 1, argv + 1) ) {
printf("Error parsing input data. ABORT.\n");
exit(1);
}
if (ps_flcstring(*par,"data",&data)) {
printf("TOWED_ARRAY reading data. ABORT.\n");
exit(1);
}
if (ps_flcstring(*par,"src",&src)) {
printf("TOWED_ARRAY reading src. ABORT.\n");
exit(1);
}
if (ps_flcstring(*par,"towed",&towed)) {
printf("TOWED_ARRAY reading towed. ABORT.\n");
exit(1);
}
/* open data files */
if (!(fp1=fopen(data,"r"))) {
printf("COMP: failed to open 1st input file = %s. ABORT.\n",data);
exit(1);
}
if (!(fp2=fopen(src,"r"))) {
printf("COMP: failed to open 2nd input file = %s. ABORT.\n",src);
exit(1);
}
if (!(fp3=fopen(towed,"w"))) {
printf("COMP: failed to open output file = %s. ABORT.\n",towed);
exit(1);
}
/* read loop */
ntr=0;
while (fgettr(fp2,&tr1)) ntr++;
tr2=(segy *)malloc(ntr*sizeof(segy));
fseek(fp2,0L,SEEK_SET);
jtr=0;
while (fgettr(fp2,&(tr2[jtr]))) jtr++;
itr=0;
ktr=0;
ltr=0;
while (fgettr(fp1,&tr1)) {
if (itr==0) {
sx=tr1.sx;
sy=tr1.sy;
selev=tr1.selev;
}
if ((itr==0) ||
(sx != tr1.sx) ||
(sy != tr1.sy) ||
(selev != tr1.selev)) {
for (jtr=0;jtr<ntr;jtr++) {
tsx=tr2[jtr].sx;
tsy=tr2[jtr].sy;
tselev=tr2[jtr].selev;
tgx=tr2[jtr].gx;
tgy=tr2[jtr].gy;
tgelev=tr2[jtr].gelev;
tr2[jtr].sx = tr1.sx;
tr2[jtr].sy = tr1.sy;
tr2[jtr].selev = tr1.selev;
tr2[jtr].gx += tr1.sx;
tr2[jtr].gy += tr1.sy;
tr2[jtr].gelev += tr1.selev;
tr2[jtr].tracl = ktr;
tr2[jtr].tracr = ktr;
tr2[jtr].tracf = jtr;
tr2[jtr].fldr = ltr;
fputtr(fp3,&(tr2[jtr]));
tr2[jtr].sx = tsx;
tr2[jtr].sy = tsy;
tr2[jtr].selev = tselev;
tr2[jtr].gx = tgx;
tr2[jtr].gy = tgy;
tr2[jtr].gelev = tgelev;
ktr++;
}
ltr++;
sx=tr1.sx;
sy=tr1.sy;
selev=tr1.selev;
}
itr++;
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
ps_delete(&par);
if (!itr) exit(1);
exit(0);
}