-
Notifications
You must be signed in to change notification settings - Fork 0
/
Msilsprtm2d.c
196 lines (174 loc) · 7.46 KB
/
Msilsprtm2d.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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
/* least-squares prestack RTM in 2-D */
/*
Copyright (C)
- 2014 Xi'an Jiaotong University, UT Austin (Pengliang Yang)
- 2017, Uinversity of Calgary, Daniel Trad:
Operator modified to pass the adjoint. Added adjoint tests as well.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <rsf.h>
#include "prtm2d.h"
int main(int argc, char* argv[])
{
bool verb, fromBoundary;
int nb, nz, nx, nt, ns, ng, niter, csd, sxbeg, szbeg, jsx, jsz, gxbeg, gzbeg, jgx, jgz;
float dz, dx, dt, fm, o1, o2, amp;
float **v0, *mod, *dat;
int testadj;
sf_file shots, imglsm, imgrtm, velo, shots_born;/* I/O files */
/* initialize Madagascar */
sf_init(argc,argv);
shots = sf_input ("in"); /* shot records, data */
velo = sf_input ("vel"); /* velocity */
imglsm = sf_output("out"); /* output LSRTM imglsme, model */
imgrtm = sf_output("imgrtm"); /* output RTM imglsme */
shots_born = sf_output("shots_born"); /* output RTM imglsme */
if (!sf_histint(velo,"n1",&nz)) sf_error("n1");
/* 1st dimension size */
if (!sf_histint(velo,"n2",&nx)) sf_error("n2");
/* 2nd dimension size */
if (!sf_histfloat(velo,"d1",&dz)) sf_error("d1");
/* d1 */
if (!sf_histfloat(velo,"d2",&dx)) sf_error("d2");
/* d2 */
if (!sf_histfloat(velo,"o1",&o1)) sf_error("o1");
/* o1 */
if (!sf_histfloat(velo,"o2",&o2)) sf_error("o2");
/* o2 */
if (!sf_getbool("verb",&verb)) verb=true;
/* verbosity */
if (!sf_getint("niter",&niter)) niter=10;
/* totol number of least-squares iteration*/
if (!sf_getint("nb",&nb)) nb=20;
/* number (thickness) of ABC on each side */
if (!sf_getbool("fromBoundary",&fromBoundary)) fromBoundary=true;
/* if fromBoundary=true, reconstruct source wavefield from stored boundary */
if (!sf_getint("testadj",&testadj)) testadj=0;
/* if testadj = 1 then program only testadj without calculating */
if (!sf_histint(shots,"n1",&nt)) sf_error("no nt");
/* total modeling time steps */
if (!sf_histint(shots,"n2",&ng)) sf_error("no ng");
/* total receivers in each shot */
if (!sf_histint(shots,"n3",&ns)) sf_error("no ns");
/* number of shots */
if (!sf_histfloat(shots,"d1",&dt)) sf_error("no dt");
/* time sampling interval */
if (!sf_histfloat(shots,"amp",&)) sf_error("no amp");
/* maximum amplitude of ricker */
if (!sf_histfloat(shots,"fm",&fm)) sf_error("no fm");
/* dominant freq of ricker */
if (!sf_histint(shots,"sxbeg",&sxbeg)) sf_error("no sxbeg");
/* x-begining index of sources, starting from 0 */
if (!sf_histint(shots,"szbeg",&szbeg)) sf_error("no szbeg");
/* x-begining index of sources, starting from 0 */
if (!sf_histint(shots,"gxbeg",&gxbeg)) sf_error("no gxbeg");
/* x-begining index of receivers, starting from 0 */
if (!sf_histint(shots,"gzbeg",&gzbeg)) sf_error("no gzbeg");
/* x-begining index of receivers, starting from 0 */
if (!sf_histint(shots,"jsx",&jsx)) sf_error("no jsx");
/* source x-axis jump interval */
if (!sf_histint(shots,"jsz",&jsz)) sf_error("no jsz");
/* source z-axis jump interval */
if (!sf_histint(shots,"jgx",&jgx)) sf_error("no jgx");
/* receiver x-axis jump interval */
if (!sf_histint(shots,"jgz",&jgz)) sf_error("no jgz");
/* receiver z-axis jump interval */
if (!sf_histint(shots,"csdgather",&csd)) sf_error("csdgather or not required");
/* default, common shot-gather; if n, record at every point*/
sf_putint(imglsm,"n1",nz);
sf_putint(imglsm,"n2",nx);
sf_putint(imglsm,"n3",1);
sf_putfloat(imglsm,"d1",dz);
sf_putfloat(imglsm,"d2",dx);
sf_putfloat(imglsm,"o1",o1);
sf_putfloat(imglsm,"o2",o2);
sf_putstring(imglsm,"label1","Depth");
sf_putstring(imglsm,"label2","Distance");
sf_putint(imgrtm,"n1",nz);
sf_putint(imgrtm,"n2",nx);
sf_putint(imgrtm,"n3",1);
sf_putfloat(imgrtm,"d1",dz);
sf_putfloat(imgrtm,"d2",dx);
sf_putfloat(imgrtm,"o1",o1);
sf_putfloat(imgrtm,"o2",o2);
sf_putstring(imgrtm,"label1","Depth");
sf_putstring(imgrtm,"label2","Distance");
sf_putint(shots_born,"n1",nt);
sf_putint(shots_born,"n2",ng);
sf_putint(shots_born,"n3",ns);
sf_putfloat(shots_born,"d1",dt);
sf_putfloat(shots_born,"d2",jgx*dx);
sf_putfloat(shots_born,"o1",0);
/*sf_putstring(shots_born,"label1","Time");*/
/*sf_putstring(shots_born,"label2","Lateral");*/
/*sf_putstring(shots_born,"label3","Shot");*/
/*sf_putstring(shots_born,"unit1","sec");*/
/*sf_putstring(shots_born,"unit2","m");*/
/*sf_putfloat(shots_born,"amp",amp);*/
/*sf_putfloat(shots_born,"fm",fm);*/
/*sf_putint(shots_born,"ng",ng);*/
/*sf_putint(shots_born,"szbeg",szbeg);*/
/*sf_putint(shots_born,"sxbeg",sxbeg);*/
/*sf_putint(shots_born,"gzbeg",gzbeg);*/
/*sf_putint(shots_born,"gxbeg",gxbeg);*/
/*sf_putint(shots_born,"jsx",jsx);*/
/*sf_putint(shots_born,"jsz",jsz);*/
/*sf_putint(shots_born,"jgx",jgx);*/
/*sf_putint(shots_born,"jgz",jgz);*/
/*sf_putint(shots_born,"csdgather",csd?1:0);*/
/* In rtm, vv is the velocity model [modl], which is input parameter;
mod is the imglsme/reflectivity [imglsm]; dat is seismogram [data]! */
v0=sf_floatalloc2(nz,nx);
mod=sf_floatalloc(nz*nx);
dat=sf_floatalloc(nt*ng*ns);
/* initialize velocity, model and data */
sf_floatread(v0[0], nz*nx, velo);
memset(mod, 0, nz*nx*sizeof(float));
sf_floatread(dat, nt*ng*ns, shots);
prtm2d_init(verb, csd, fromBoundary, dz, dx, dt, amp, fm, nz, nx, nb, nt, ns, ng,
sxbeg, szbeg, jsx, jsz, gxbeg, gzbeg, jgx, jgz, v0, mod, dat);
// run adjoint test first.
sf_warning("adjoint test \n");
if (testadj){
prtm2d_adjtest();
sf_warning("exiting after testadj\n");
mod=NULL;
sf_floatwrite(mod,nz*nx,imgrtm);
sf_floatwrite(mod,nz*nx,imglsm);
prtm2d_close();
free(*v0); free(v0);
free(mod);
free(dat);
exit (0);
}
sf_warning("start migration\n");
/* original RTM is simply applying adjoint of prtm2d_lop once!*/
prtm2d_lop(true, false, nz*nx, nt*ng*ns, mod, dat);
sf_floatwrite(mod, nz*nx, imgrtm);/* output RTM image */
sf_warning("migration ends");
prtm2d_lop(false, false, nz*nx, nt*ng*ns, mod, dat);
sf_floatwrite(dat, nt*ng*ns, shots_born);/* shots generated by Born mod */
/*if (niter>0){*/
/*memset(mod, 0, nz*nx*sizeof(float));//very important*/
/*sf_warning("inside LS loop niter= %d\n",niter);*/
/*[> least squares migration <]*/
/*sf_solver(prtm2d_lop, sf_cgstep, nz*nx, nt*ng*ns, mod, dat, niter, "verb", verb, "end");*/
/*sf_floatwrite(mod, nz*nx, imglsm); [> output inverted image <]*/
/*sf_cgstep_close();*/
/*}*/
prtm2d_close();
free(*v0); free(v0);
free(mod);
free(dat);
exit(0);
}