forked from yuanyuxin0077/FD-RTM-FWI-2018.01.31backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Toa_rtm_vti_adcig_cdp_rs.c
1785 lines (1566 loc) · 63.9 KB
/
Toa_rtm_vti_adcig_cdp_rs.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//#############################################################a
//##s
//##s 2D Acoustic VTI Medium RTM & Pick Up ADCIG
//##s
//##s----------------------------------------------------------
//##s PML , P&SV , VTI , Acoustic , RTM , -SV , Adcig,
//##s Migration , Both sides receive , SU or dat(v,e,d) ,
//##s Adcig( poynting , s-r , offset-domain ),
//##s
//##s----------------------------------------------------------
//##s Rong Tao
//##s 2016
//############################################################a
#include<stdio.h>
#include<malloc.h>
#include<math.h>
#include<stdlib.h>
#include "mpi.h"
#include "hc/alloc.c"
#include "hc/alloc.h"
#include "hc/complex.c"
#include "hc/complex.h"
#include "hc/bhdr.h"
#include "hc/hdr.h"
#include "hc/fft.h"
#include "hc/fft.c"
#include "hc/mute_direct.h"
#include "hc/cjbsegy.h"
/********* SEG-Y header *********/
typedef cjbsegy segy;
/********** SU & SEG-Y **********/
#define SU_NKEYS 80 /* Number of key header words */
#define HDRBYTES 240 /* Bytes in the trace header */
#define EBCBYTES 3200 /* Bytes in the card image EBCDIC block */
#define BNYBYTES 400 /* Bytes in the binary coded block */
#define SEGY_HDRBYTES 240 /* Bytes in the tape trace header */
#define SEGY_NKEYS 71 /* Number of mandated header fields */
#define BHED_NKEYS 27 /* Number of mandated binary fields */
#define pi 3.1415926535898
/********* SEG-Y header *********/
Y_3200 y3200;
bhed head_400;
cjbsegy tr, vtr;
/********* SEG-Y header *********/
/********** SU function *********/
void swap_short_2(short *tni2);
void swap_u_short_2(unsigned short *tni2);
void swap_int_4(int *tni4);
void swap_u_int_4(unsigned int *tni4);
void swap_long_4(long *tni4);
void swap_u_long_4(unsigned long *tni4);
void swap_float_4(float *tnf4);
void swap_double_8(double *tndd8);
void swaphval(segy *tr, int index);
/********* SU function *********/
/* MAIN */
main(int argc,char *argv[])
{
/*************************************** function ********************************************/
void model_vti_get_boundry(int nx,int nz,int vnx,int vnz,int nt,int npd,float dx,float dz,
float vdx,float vdz,float favg,float tmax,float dt,float dtout,float pfac,
float **vp,float **epsilu,float **deta,float **rho,
int ns_sxd,int ds_sxd,int fs_sxd,int zs_sxd,int is,
float **p_cal_x,float **p_cal_z,
float **p_top_x,float **p_bottom_x,float **p_left_x,float **p_right_x,
float **p_top_z,float **p_bottom_z,float **p_left_z,float **p_right_z,int _Circle_,
int mm,int wtype,int hsx,int myid,float *mu_v,int flag_snap,int seismic);
void mute_directwave(int flag_mu,int nx,int nt,float dt,float favg,
float dx,float dz,int fs_sxd,int ds_sxd,int zs_sxd,int is,
float mu_v,float **p_cal,int tt);
void RTM_corr_adcig(int nx,int nz,int vnx,int vnz,int nt,int npd,float dx,float dz,
float vdx,float vdz,float favg,float tmax,float dt,float dtout,
float pfac,float **vp,float **epsilu,float **deta,float **rho,
int ns_sxd,int ds_sxd,int fs_sxd,int ds_initial,int fs_initial,int zs_sxd,int is,int flag_cdp,
float **p_top_x,float **p_bottom_x,float **p_left_x,float **p_right_x,////////////////////////////////
float **p_top_z,float **p_bottom_z,float **p_left_z,float **p_right_z,float **p_obs_x,float **p_obs_z,
int mm,int wtype,int hsx,int myid,float **mig_is,float **mig_ns0,
float ***adcig_is,float ***adcig_ns0,//float ***Ixhz_is,float ***Ixhz_ns0,int nh,
int flag_snap,int seismic,int flag_adcig);
void smooth1float(float *v,int r,int n);
void smooth2float(int nx,int rx,int nz,int rz,float **v);
void pad_vv(int nx,int nz,int npd,float **ee);
void read_v_e_d_r(char FN1[],char FN2[],char FN3[],int nx,int nz,float **vv,float **epsilu,float **deta,
float **rho0,int npd,int seismic);
/*************************** parameter statement ***********************/
int i,j,k,l,m,ih,is,nx,nz,nt,vnx,vnz,i_start,i_end,mm,wtype,hsx,ia,nxs,flag_cdp,flag_adcig,nh;
int ns_sxd,ds_sxd,fs_sxd,zs_sxd,fs,ds,npd;
float dx,dz,vdx,vdz,tmax,dt,dtout,pfac,favg;
int myid,numprocs,_Circle_,flag_mu,flag_snap,seismic,nangle,dangle,fangle;
float mu_v;
/***************** wave float **************/
float **p_cal_x,**p_cal_z,**p_top_x,**p_bottom_x,**p_left_x,**p_right_x,**p_obs_x,**p_obs_z;
float **p_top_z,**p_bottom_z,**p_left_z,**p_right_z;
/***************** image float *************/
float **mig_is,**mig_ns,**mig_ns0,***adcig_is,***adcig_ns,***adcig_ns0,**adcig2d;
// float ***Ixhz_ns0,***Ixhz_ns,***Ixhz_is;
float **vp,**rho,**deta,**epsilu;
float **vps,**rhos,**detas,**epsilus;
//a###########################################################################
//#### input the parameter and confirm ####
//a###########################################################################
/************************ dat document **********************/
/* Input velocity */char FN1[250]={"vel901151small.dat"};
/* Input epsilu */char FN2[250]={"epsilu901151small.dat"};
/* Input deta */char FN3[250]={"deta901151small.dat"};
/* Cal data */char FN4[250]={"shot_cal.dat"};
/* Input Obs data */char FN5[250]={"shot_obs.dat"};
/* Migration */char FN6[250]={"mig_ns_small.dat"};
/* IS tempor migration */char FN7[250]={"mig_is_tempor_small.dat"};
/* Adcig initial */char FN8[250]={"adcig_small.dat"};
/* Adcig smooth */char FN9[250]={"adcig_smooth.dat"};
/* Migration adcig stack */char FN10[250]={"mig_stack_adcig_small.dat"};
/* Half offset I(x,h,z) */char FN11[250]={"Image_x_h_z.dat"};
/*************************** type ***************************/
/* Wavelet type (1-3) */ wtype=1;
/* 1-mute , 0->don't mute */ flag_mu=1;
/* 1-snap , 0->nosnap */ flag_snap=1;
/* 1.dat, 2.su (v,e,d) */ seismic=1;
/*************************** cdp ****************************/
/* Activate "nxs"(=1) */ flag_cdp=0; /* 1-activate ;0-invaliable */
/* CDP of each shot */ nxs=301; /* Must be odd number */
/*************************** cdp ****************************/
/* choice adcig type */ flag_adcig=1; /* 1-poynting */
/* 2-source-receivers domain */
//NULL /* 3-half-offset-domain */
/*************************** wave ***************************/
hsx=1;mm=4;npd=50;_Circle_=15;
/******************** observation system ********************/
favg=20; pfac=1000.0;
nx=301; dx=10.0;
nz=151; dz=10.0;
tmax=2.5;
dt=1.0;
nt=2501;
ns_sxd=60;
fs_sxd=2;
ds_sxd=5;
zs_sxd=1;
nangle=90;
fangle=0;
dangle=1;
/*************************v****************************/
vdz=dz;vdx=dx;vnx=nx;vnz=nz;dtout=dt;
/************************FILE**************************/
FILE *fp4,*fp6,*fp7,*fp8,*fp9,*fp10,*fp11;
fp4=fopen(FN4,"wb"); /* Cal data */
fp6=fopen(FN6,"wb"); /* Migration */
fp7=fopen(FN7,"wb"); /* IS tempor migration */
fp8=fopen(FN8,"wb"); /* Adcig initial */
fp9=fopen(FN9,"wb"); /* Adcig smooth */
fp10=fopen(FN10,"wb"); /* Migration adcig stack */
if(flag_adcig==3)
fp11=fopen(FN11,"wb"); /* Image half-offset */
/************************** read_file ******************************/
vp = alloc2float(nz+2*npd,nx+2*npd); zero2float(vp,nz+2*npd,nx+2*npd);
rho = alloc2float(nz+2*npd,nx+2*npd); zero2float(rho,nz+2*npd,nx+2*npd);
epsilu = alloc2float(nz+2*npd,nx+2*npd); zero2float(epsilu,nz+2*npd,nx+2*npd);
deta = alloc2float(nz+2*npd,nx+2*npd); zero2float(deta,nz+2*npd,nx+2*npd);
read_v_e_d_r(FN1,FN2,FN3,vnx,vnz,vp,epsilu,deta,rho,npd,seismic);
pad_vv(nx,nz,npd,vp);
pad_vv(nx,nz,npd,rho);
pad_vv(nx,nz,npd,epsilu);
pad_vv(nx,nz,npd,deta);
/** determine NXS and nh **/
if(flag_cdp==1){
nxs=nxs;
nh=nxs/2+1;
}else{
nxs=nx;
nh=0;
}
vps = alloc2float(nz+2*npd,nxs+2*npd); zero2float(vps,nz+2*npd,nxs+2*npd);
rhos = alloc2float(nz+2*npd,nxs+2*npd); zero2float(rhos,nz+2*npd,nxs+2*npd);
epsilus = alloc2float(nz+2*npd,nxs+2*npd); zero2float(epsilus,nz+2*npd,nxs+2*npd);
detas = alloc2float(nz+2*npd,nxs+2*npd); zero2float(detas,nz+2*npd,nxs+2*npd);
/********************* alloc ***********************/
p_cal_x=alloc2float(nt,nxs);
p_cal_z=alloc2float(nt,nxs);
p_obs_x=alloc2float(nt,nxs);
p_obs_z=alloc2float(nt,nxs);
p_top_x=alloc2float(nt,nxs); p_bottom_x=alloc2float(nt,nxs);
p_top_z=alloc2float(nt,nxs); p_bottom_z=alloc2float(nt,nxs);
p_left_x=alloc2float(nt,nz); p_right_x=alloc2float(nt,nz);
p_left_z=alloc2float(nt,nz); p_right_z=alloc2float(nt,nz);
/********************* image alloc *************************/
mig_is=alloc2float(nz,nxs); zero2float(mig_is,nz,nxs);
adcig_is=alloc3float(nz,nxs,90); zero3float(adcig_is,nz,nxs,90);
/* half-offset domain image alloc */
/* if(flag_adcig==3)
{ Ixhz_is=alloc3float(nz,nh,nxs); zero3float(Ixhz_is,nz,nh,nxs); }*/
mig_ns=alloc2float(nz,nx); zero2float(mig_ns,nz,nx);
mig_ns0=alloc2float(nz,nx); zero2float(mig_ns0,nz,nx);
adcig_ns=alloc3float(nz,nx,90); zero3float(adcig_ns,nz,nx,90);
adcig_ns0=alloc3float(nz,nx,90); zero3float(adcig_ns0,nz,nx,90);
/* half-offset domain image alloc */
/* if(flag_adcig==3)
{ Ixhz_ns=alloc3float(nz,nh,nx); zero3float(Ixhz_ns,nz,nh,nx);
Ixhz_ns0=alloc3float(nz,nh,nx); zero3float(Ixhz_ns0,nz,nh,nx);}*/
adcig2d=alloc2float(nz,90); zero2float(adcig2d,nz,90);
/*******************MPI************************/
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);
MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
/*******************MPI***********************/
MPI_Barrier(MPI_COMM_WORLD);
if(myid==0)
{
printf("--------------------------------------------------------\n");
printf(" ####################################################\n");
printf(" ### Please confirm the parameter ! ###\n");
printf(" ####################################################\n");
printf(" ### ###\n");
printf(" ### mm=%d, wtype=%d, hsx=%d, flag_mu=%d\n",mm,wtype,hsx,flag_mu);
printf(" ###\n");
printf(" ### nx=vnx=%3d, dx=vdx=%.1f\n",nx,dx);
printf(" ### nz=vnz=%3d, dz=vdz=%.1f\n",nz,dz);
printf(" ###\n");
printf(" ### npd=%3d, favg=%.1f, pfac=%.1f\n",npd,favg,pfac);
printf(" ### tmax=%.2f(s), dt=%.2f(ms), nt=%d\n",tmax,dt,nt);
printf(" ###\n");
printf(" ### ns=%3d\n",ns_sxd);
printf(" ### fs=%3d\n",fs_sxd);
printf(" ### ds=%3d\n",ds_sxd);
printf(" ### zs=%3d\n",zs_sxd);
printf(" ###\n");
printf(" ### _Circle_=%3d\n",_Circle_);
printf(" ###\n");
printf(" ### numprocs= %2d\n",numprocs);
printf(" ### ###\n");
printf(" ####################################################\n");
//system("pause");
}if( ( flag_cdp==1 ) && ( nx<nxs ) ){
if(myid==0)printf("\n\n\nERROR: nx must more than nxs!\n\n\n\n");
exit(0);
}if( ( flag_cdp==1 ) && ( ( fs_sxd<(nxs/2+1) ) || ( (fs_sxd+(ns_sxd-1)*ds_sxd+nxs/2)>nx ) ) ){
if(myid==0)printf("\n\n\nERROR: Receivers location out of model boundary ! \n\n\n\n");
exit(0);
}if(ns_sxd%numprocs){
if(myid==0)printf("\n\n\nERROR: Can't distribute the nodes ! \n\n\n\n");
exit(0);
}
FILE *fp5;
if((fp5=fopen(FN5,"rb"))==NULL) printf("Open %s error!\n",FN5);
/************************IS Loop start**************************/
/************************IS Loop start**************************/
for(is=1+myid;is<=ns_sxd;is+=numprocs)
{
if(myid==0)
{
printf("--------------------------------------------------------\n");
printf("--------------------------------------------------------\n");
printf("--- IS========%d \n",is);
printf("--- The forward is start ! \n");
}
zero2float(p_cal_x,nt,nxs); zero2float(p_cal_z,nt,nxs);
zero2float(p_obs_x,nt,nxs); zero2float(p_obs_z,nt,nxs);
zero2float(p_top_x,nt,nxs); zero2float(p_bottom_x,nt,nxs);
zero2float(p_top_z,nt,nxs); zero2float(p_bottom_z,nt,nxs);
zero2float(p_left_x,nt,nz); zero2float(p_right_x,nt,nz);
zero2float(p_left_z,nt,nz); zero2float(p_right_z,nt,nz);
/* determine IS vp,rho,deta,epsilu */
if(flag_cdp==1){
k=fs_sxd+(is-1)*ds_sxd;
for(i=k-nxs/2+npd;i<=k+nxs/2+npd;i++)
for(j=npd;j<nz+npd;j++)
{
vps[i-k+nxs/2][j]=vp[i][j];
rhos[i-k+nxs/2][j]=rho[i][j];
detas[i-k+nxs/2][j]=deta[i][j];
epsilus[i-k+nxs/2][j]=epsilu[i][j];
}
ds=0;
fs=nxs/2+1;
}else{
for(i=npd;i<nx+npd;i++)
for(j=npd;j<nz+npd;j++)
{
vps[i][j]=vp[i][j];
rhos[i][j]=rho[i][j];
detas[i][j]=deta[i][j];
epsilus[i][j]=epsilu[i][j];
}
fs=fs_sxd;
ds=ds_sxd;
}
pad_vv(nxs,nz,npd,vps);
pad_vv(nxs,nz,npd,rhos);
pad_vv(nxs,nz,npd,epsilus);
pad_vv(nxs,nz,npd,detas);
/**************** model vti forwarding**************/
model_vti_get_boundry(nxs,nz,nxs,vnz,nt,npd,dx,dz,vdx,vdz,favg,tmax,dt,dtout,pfac,
vps,epsilus,detas,rhos,ns_sxd,ds,fs,zs_sxd,is,
p_cal_x,p_cal_z,
p_top_x,p_bottom_x,p_left_x,p_right_x,
p_top_z,p_bottom_z,p_left_z,p_right_z,
_Circle_,mm,wtype,hsx,myid,&mu_v,flag_snap,seismic);
if(myid==0)printf("--- The forward is over ! \n");
/* make the vp back to real */
for(i=0;i<=nxs+2*npd-1;i++)
{
for(j=0;j<=nz+2*npd-1;j++)
{
rhos[i][j]=1.0/rhos[i][j];
vps[i][j]=sqrtf(vps[i][j]/rhos[i][j]);
}
}
/**************** mute direct wave **************/
mute_directwave(flag_mu,nxs,nt,dt,favg,dx,dz,fs,ds,zs_sxd,is,mu_v,p_cal_x,85);
mute_directwave(flag_mu,nxs,nt,dt,favg,dx,dz,fs,ds,zs_sxd,is,mu_v,p_cal_z,85);
/**************** output p_cal **************/
fseek(fp4,(is-1)*nxs*nt*4L,0);
for(i=0;i<nxs;i++)
for(j=0;j<nt;j++)
fwrite(&p_cal_x[i][j],4L,1,fp4);
/**************** RTM correlation **************/
if(myid==0)
{
printf("--------------------------------------------\n");
printf("---\n");
printf("--- The RTM correlation is start ! \n");
}
MPI_Barrier(MPI_COMM_WORLD);
zero2float(mig_is,nz,nxs);
zero3float(adcig_is,nz,nxs,90);
fseek(fp5,(is-1)*nxs*nt*4L,0);
for(i=0;i<nxs;i++)
for(j=0;j<nt;j++){
fread(&p_obs_x[i][j],4L,1,fp5);p_obs_z[i][j]=p_obs_x[i][j];
}
/* if(flag_adcig==3)
{ zero3float(Ixhz_is,nz,nh,nxs); }*/
RTM_corr_adcig(nxs,nz,nxs,vnz,nt,npd,dx,dz,vdx,vdz,favg,tmax,dt,dtout,pfac,
vps,epsilus,detas,rhos,ns_sxd,ds,fs,ds_sxd,fs_sxd,zs_sxd,is,flag_cdp,
p_top_x,p_bottom_x,p_left_x,p_right_x,
p_top_z,p_bottom_z,p_left_z,p_right_z,p_obs_x,p_obs_z, /* p_cal->p_obs */
mm,wtype,hsx,myid,mig_is,mig_ns0,adcig_is,adcig_ns0,//Ixhz_is,Ixhz_ns0,nh,
flag_snap,seismic,flag_adcig);
/**************** output tempor migration **************/
fseek(fp7,(is-1)*nxs*nz*4L,0);
for(i=0;i<nxs;i++)
for(j=0;j<nz;j++)
fwrite(&mig_is[i][j],4L,1,fp7);
MPI_Barrier(MPI_COMM_WORLD);
}//is loop ending
/*****************IS Loop end******************/
MPI_Barrier(MPI_COMM_WORLD);
MPI_Reduce(mig_ns0[0], mig_ns[0], nx*nz, MPI_FLOAT, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Reduce(adcig_ns0[0][0], adcig_ns[0][0], 90*nx*nz, MPI_FLOAT, MPI_SUM, 0, MPI_COMM_WORLD);
/* if(flag_adcig==3)
MPI_Reduce(Ixhz_ns0[0][0], Ixhz_ns[0][0], nh*nx*nz, MPI_FLOAT, MPI_SUM, 0, MPI_COMM_WORLD);*/
if(myid==0)
{
for(i=0;i<nx;i++)
for(j=0;j<nz;j++)
fwrite(&mig_ns[i][j],4L,1,fp6);
for(i=0;i<nx;i++)
for(ia=0;ia<90;ia++)
for(j=0;j<nz;j++)
fwrite(&adcig_ns[ia][i][j],4L,1,fp8);
/* if(flag_adcig==3)
for(i=0;i<nx;i++)
for(ih=0;ih<nh;ih++)
for(j=0;j<nz;j++)
fwrite(&Ixhz_ns[i][ih][j],4L,1,fp11);*/
/************** smooth the adcig & stack ***************/
zero2float(mig_ns0,nz,nx);
for(i=0;i<nx;i++)
{
for(ia=0;ia<90;ia++)
for(j=0;j<nz;j++)
adcig2d[ia][j]=adcig_ns[ia][i][j];
smooth2float(90,5,nz,5,adcig2d);
for(ia=0;ia<90;ia++)
for(j=0;j<nz;j++)
{
adcig_ns[ia][i][j]=adcig2d[ia][j];
mig_ns0[i][j]+=adcig2d[ia][j];
}
}
for(i=0;i<nx;i++)
for(ia=0;ia<90;ia++)
for(j=0;j<nz;j++)
fwrite(&adcig_ns[ia][i][j],4L,1,fp9);
for(i=0;i<nx;i++)
for(j=0;j<nz;j++)
fwrite(&mig_ns0[i][j],4L,1,fp10);
}
MPI_Barrier(MPI_COMM_WORLD);
if(myid==0)printf("--- The RTM correlation is over ! \n");
if(myid==0)printf("--- Complete!!!!!!!!! \n");
/************** fclose ***************/
fclose(fp4);
fclose(fp5);
fclose(fp6);
fclose(fp7);
fclose(fp8);
fclose(fp9);
fclose(fp10);
if(flag_adcig==3)
fclose(fp11);
/************** free ***************/
free2float(rho); free2float(vp); free2float(epsilu); free2float(deta);
free2float(rhos); free2float(vps); free2float(epsilus); free2float(detas);
free2float(p_cal_x); free2float(p_cal_z);
free2float(p_obs_x); free2float(p_obs_z);
free2float(p_top_x); free2float(p_top_z);
free2float(p_bottom_x); free2float(p_bottom_z);
free2float(p_left_x); free2float(p_left_z);
free2float(p_right_x); free2float(p_right_z);
free2float(mig_is);
free2float(mig_ns);
free2float(mig_ns0);
free3float(adcig_is);
free3float(adcig_ns);
free3float(adcig_ns0);
free2float(adcig2d);
/* if(flag_adcig==3)
{ free3float(Ixhz_is);
free3float(Ixhz_ns);
free3float(Ixhz_ns0); }*/
/******************MPI************************/
MPI_Finalize();
}
/***********************************func********************************************/
void model_vti_get_boundry(int nx,int nz,int vnx,int vnz,int nt,int npd,float dx,float dz,
float vdx,float vdz,float favg,float tmax,float dt,float dtout,float pfac,
float **vp,float **epsilu,float **deta,float **rho,
int ns_sxd,int ds_sxd,int fs_sxd,int zs_sxd,int is,
float **p_cal_x,float **p_cal_z,
float **p_top_x,float **p_bottom_x,float **p_left_x,float **p_right_x,
float **p_top_z,float **p_bottom_z,float **p_left_z,float **p_right_z,
int _Circle_,int mm,int wtype,int hsx,int myid,float *mu_v,int flag_snap,int seismic)
/*****************************************************a**
Function for VTI medium modeling,2016.9.24
Ps: the function of modeling following:
du/dt=1/rho*dp/dx ,
dw/dt=1/rho*dq/dz ,
dp/dt=rho*vpx^2*du/dx+rho*vp0*vpn*dw/dz ,
dq/dt=rho*vp0*vpn*du/dx+rho*vp0^2*dw/dz ,
vpx^2=vp0^2*(1+2*epsilu);
vpn^2=vp0^2*(1+2*deta);
Rong Tao
******************************************************a**/
{
void cal_c(int mm,float c[]);
void ptsource(float pfac,float xsn,float zsn,int nx,int nz,float dt,float t,
float favg,float **s,int wtype,int npd,int is,int ds_sxd);
void update_vel(int nx,int nz,int npd,int mm,float dt,float dx,float dz,
float **u0,float **w0,float **txx0,float **tzz0,
float **u1,float **w1,float **txx1,float **tzz1,
float **rho,float c[],float *coffx1,float *coffx2,float *coffz1,float *coffz2);
void update_stress(int nx,int nz,float dt,float dx,float dz,int mm,
float **u0,float **w0,float **txx0,float **tzz0,
float **u1,float **w1,float **txx1,float **tzz1,
float **s,float **vp,float c[],int npd,
float **tpx1,float **tpx0,float **tpz1,float **tpz0,
float **tqx1,float **tqx0,float **tqz1,float **tqz0,
float *acoffx1,float *acoffx2,float *acoffz1,float *acoffz2,
float **deta,float **epsilu,int fs_sxd,int ds_sxd,int zs_sxd,int is,int _Circle_);
float get_constant(float dx,float dz,int nx,int nz,int nt,int ntout,
int npd,float tmax,float favg,float dtout,float dt,float **vp,float ndtt,int myid);
void initial_coffe(float dt,float d0,int nx,int nz,float *coffx1,float *coffx2,float *coffz1,float *coffz2,
float *acoffx1,float *acoffx2,float *acoffz1,float *acoffz2,int npd);
int i,j;
int ntout,it;
float t,ndtt,d0;
float **u0; float **u1;
float **w0; float **w1;
float **tpx0; float **tqx0;
float **tpx1; float **tqx1;
float **tpz0; float **tqz0;
float **tpz1; float **tqz1;
float **txx0; float **txx1;
float **tzz0; float **tzz1;
float **s;
float c[mm];
ndtt=dtout/dt;
ntout=(int)(1000*tmax/dtout+0.5)+1;
cal_c(mm,c);
/********************************************************/
*mu_v=vp[1+npd][1+npd]*sqrtf((1+2*epsilu[1+npd][1+npd]));/////////////
/********************************************************/
u0=alloc2float(nz+2*npd,nx+2*npd);
u1=alloc2float(nz+2*npd,nx+2*npd);
w0=alloc2float(nz+2*npd,nx+2*npd);
w1=alloc2float(nz+2*npd,nx+2*npd);
txx0=alloc2float(nz+2*npd,nx+2*npd);
txx1=alloc2float(nz+2*npd,nx+2*npd);
tzz0=alloc2float(nz+2*npd,nx+2*npd);
tzz1=alloc2float(nz+2*npd,nx+2*npd);
tpx0=alloc2float(nz+2*npd,nx+2*npd);
tpx1=alloc2float(nz+2*npd,nx+2*npd);
tpz0=alloc2float(nz+2*npd,nx+2*npd);
tpz1=alloc2float(nz+2*npd,nx+2*npd);
tqx0=alloc2float(nz+2*npd,nx+2*npd);
tqx1=alloc2float(nz+2*npd,nx+2*npd);
tqz0=alloc2float(nz+2*npd,nx+2*npd);
tqz1=alloc2float(nz+2*npd,nx+2*npd);
s=alloc2float(nz+2*npd,nx+2*npd);
d0=get_constant(dx,dz,nx,nz,nt,ntout,npd,tmax,favg,dtout,dt,vp,ndtt,myid);
dt=dt/1000;
/**************************** boundry *******************************/
float *coffx1; float *coffx2; float *coffz1; float *coffz2;
float *acoffx1; float *acoffx2; float *acoffz1; float *acoffz2;
coffx1=alloc1float(nx+2*npd);
coffx2=alloc1float(nx+2*npd);
coffz1=alloc1float(nz+2*npd);
coffz2=alloc1float(nz+2*npd);
acoffx1=alloc1float(nx+2*npd);
acoffx2=alloc1float(nx+2*npd);
acoffz1=alloc1float(nz+2*npd);
acoffz2=alloc1float(nz+2*npd);
zero1float(coffx1,nx+2*npd);
zero1float(coffx2,nx+2*npd);
zero1float(acoffx1,nx+2*npd);
zero1float(acoffx2,nx+2*npd);
zero1float(coffz1,nz+2*npd);
zero1float(coffz2,nz+2*npd);
zero1float(acoffz1,nz+2*npd);
zero1float(acoffz2,nz+2*npd);
initial_coffe(dt,d0,nx,nz,coffx1,coffx2,coffz1,coffz2,acoffx1,acoffx2,acoffz1,acoffz2,npd);
/***********************************************************/
ndtt=(int)ndtt;
/*******************zero************************/
zero2float(p_cal_x,nt,nx);
zero2float(p_cal_z,nt,nx);
zero2float(u0,nz+2*npd,nx+2*npd);
zero2float(u1,nz+2*npd,nx+2*npd);
zero2float(w0,nz+2*npd,nx+2*npd);
zero2float(w1,nz+2*npd,nx+2*npd);
zero2float(txx0,nz+2*npd,nx+2*npd);
zero2float(txx1,nz+2*npd,nx+2*npd);
zero2float(tzz0,nz+2*npd,nx+2*npd);
zero2float(tzz1,nz+2*npd,nx+2*npd);
zero2float(tpx0,nz+2*npd,nx+2*npd);
zero2float(tpx1,nz+2*npd,nx+2*npd);
zero2float(tpz0,nz+2*npd,nx+2*npd);
zero2float(tpz1,nz+2*npd,nx+2*npd);
zero2float(tqx0,nz+2*npd,nx+2*npd);
zero2float(tqx1,nz+2*npd,nx+2*npd);
zero2float(tqz0,nz+2*npd,nx+2*npd);
zero2float(tqz1,nz+2*npd,nx+2*npd);
zero2float(s,nz+2*npd,nx+2*npd);
for(i=0;i<=nx+2*npd-1;i++)
{
for(j=0;j<=nz+2*npd-1;j++)
{
vp[i][j]=rho[i][j]*(vp[i][j]*vp[i][j]);
rho[i][j]=1.0/rho[i][j];
}
}
FILE *fpsnap,*fpsnap1;
if((is==1)&&(flag_snap))
{
fpsnap=fopen("snap_forward_txx.dat","wb");
fpsnap1=fopen("snap_forward_tzz.dat","wb");
}
for(it=0,t=0.0;it<nt;it++,t+=dt)
{
if(it%100==0&&myid==0)printf("--- FOR is===%d it===%d\n",is,it);
ptsource(pfac,fs_sxd,zs_sxd,nx,nz,dt,t,favg,s,wtype,npd,is,ds_sxd);
update_vel(nx,nz,npd,mm,dt,dx,dz,u0,w0,txx0,tzz0,
u1,w1,txx1,tzz1,rho,c,coffx1,coffx2,coffz1,coffz2);
update_stress(nx,nz,dt,dx,dz,mm,u0,w0,txx0,tzz0,
u1,w1,txx1,tzz1,s,vp,c,npd,
tpx1,tpx0,tpz1,tpz0,tqx1,tqx0,tqz1,tqz0,
acoffx1,acoffx2,acoffz1,acoffz2,deta,epsilu,
fs_sxd,ds_sxd,zs_sxd,is,_Circle_);
for(i=npd;i<npd+nx;i++)
{
p_cal_x[i-npd][it] = txx1[i][npd+hsx-1];//////
p_cal_z[i-npd][it] = tzz1[i][npd+hsx-1];//////
p_top_x[i-npd][it] = txx1[i][npd];
p_bottom_x[i-npd][it] = txx1[i][npd+nz-1];
p_top_z[i-npd][it] = tzz1[i][npd];
p_bottom_z[i-npd][it] = tzz1[i][npd+nz-1];
}
for(j=npd;j<npd+nz;j++)
{
p_left_x[j-npd][it] = txx1[npd][j];
p_right_x[j-npd][it] = txx1[npd+nx-1][j];
p_left_z[j-npd][it] = tzz1[npd][j];
p_right_z[j-npd][it] = tzz1[npd+nx-1][j];
}
for(j=0;j<nz+2*npd;j++)
{
for(i=0;i<nx+2*npd;i++)
{
u0[i][j]=u1[i][j];
w0[i][j]=w1[i][j];
tpx0[i][j]=tpx1[i][j];
tpz0[i][j]=tpz1[i][j];
tqx0[i][j]=tqx1[i][j];
tqz0[i][j]=tqz1[i][j];
txx0[i][j]=txx1[i][j];
tzz0[i][j]=tzz1[i][j];
}
}
if((is==1)&&(it%100==0)&&(flag_snap))
{
fseek(fpsnap,(int)(it/100)*(nx)*(nz)*4L,0);
for(i=npd;i<nx+npd;i++)
for(j=npd;j<nz+npd;j++)
fwrite(&txx1[i][j],4L,1,fpsnap);
fseek(fpsnap1,(int)(it/100)*(nx)*(nz)*4L,0);
for(i=npd;i<nx+npd;i++)
for(j=npd;j<nz+npd;j++)
fwrite(&tzz1[i][j],4L,1,fpsnap1);
}
}//it loop end
/**********************close************************/
if((is==1)&&(flag_snap))
{
fclose(fpsnap);fclose(fpsnap1);
}
/**********************free*************************/
free1float(coffx1);free1float(coffx2);
free1float(coffz1);free1float(coffz2);
free1float(acoffx1);free1float(acoffx2);
free1float(acoffz1);free1float(acoffz2);
free2float(u0); free2float(u1);
free2float(w0); free2float(w1);
free2float(txx0); free2float(txx1); free2float(tzz0); free2float(tzz1);
free2float(tpx0); free2float(tpx1); free2float(tpz0); free2float(tpz1);
free2float(tqx0); free2float(tqx1); free2float(tqz0); free2float(tqz1);
free2float(s);
}
/************************************func***************************************/
void RTM_corr_adcig(int nx,int nz,int vnx,int vnz,int nt,int npd,float dx,float dz,
float vdx,float vdz,float favg,float tmax,float dt,float dtout,float pfac,
float **vp,float **epsilu,float **deta,float **rho,
int ns_sxd,int ds_sxd,int fs_sxd,int ds_initial,int fs_initial,int zs_sxd,int is,int flag_cdp,
float **p_top_x,float **p_bottom_x,float **p_left_x,float **p_right_x,
float **p_top_z,float **p_bottom_z,float **p_left_z,float **p_right_z,float **p_obs_x,float **p_obs_z,
int mm,int wtype,int hsx,int myid,float **mig_is,float **mig_ns0,
float ***adcig_is,float ***adcig_ns0,//float ***Ixhz_is,float ***Ixhz_ns0,int nh,
int flag_snap,int seismic,int flag_adcig)
/************************************************************a*
function for RTM
PS:correlation image condition
pick up the adcig and stack
Rong Tao
*************************************************************b*/
{
void cal_c(int mm,float c[]);
void update_vel(int nx,int nz,int npd,int mm,float dt,float dx,float dz,
float **s_u0,float **s_w0,float **s_txx0,float **s_tzz0,
float **s_u1,float **s_w1,float **s_txx1,float **s_tzz1,
float **rho,float c[],float *coffx1,float *coffx2,float *coffz1,float *coffz2);
void inv_update_stress(int nx,int nz,float dt,float dx,float dz,int mm,
float **s_u0,float **s_w0,float **s_txx0,float **s_tzz0,
float **s_u1,float **s_w1,float **s_txx1,float **s_tzz1,
float **vp,float c[],int npd,
float **s_tpx1,float **s_tpx0,float **s_tpz1,float **s_tpz0,
float **s_tqx1,float **s_tqx0,float **s_tqz1,float **s_tqz0,
float *acoffx1,float *acoffx2,float *acoffz1,float *acoffz2,
float **deta,float **epsilu,int fs_sxd,int ds_sxd,int zs_sxd,int is);
float get_constant(float dx,float dz,int nx,int nz,int nt,int ntout,
int npd,float tmax,float favg,float dtout,float dt,float **vp,float ndtt,int myid);
void initial_coffe(float dt,float d0,int nx,int nz,float *coffx1,float *coffx2,float *coffz1,float *coffz2,
float *acoffx1,float *acoffx2,float *acoffz1,float *acoffz2,int npd);
int i,j,k,ih;
int ntout,it,ia;
float t,ndtt,d0,atan_s,atan_g,angle,sx,sz,gx,gz,b1,b2,a,a1,a2;
/****************** source wavefiled **************/
float **s_u0; float **s_u1;
float **s_w0; float **s_w1;
float **s_tpx0; float **s_tqx0;
float **s_tpx1; float **s_tqx1;
float **s_tpz0; float **s_tqz0;
float **s_tpz1; float **s_tqz1;
float **s_txx0; float **s_txx1;
float **s_tzz0; float **s_tzz1;
/***************** reciever wavefiled *************/
float **g_u0; float **g_u1;
float **g_w0; float **g_w1;
float **g_tpx0; float **g_tqx0;
float **g_tpx1; float **g_tqx1;
float **g_tpz0; float **g_tqz0;
float **g_tpz1; float **g_tqz1;
float **g_txx0; float **g_txx1;
float **g_tzz0; float **g_tzz1;
/***************** Lighting source ***************/
float **source_x,**source_z;//,***sourceI;
/***************** float end *************/
float c[mm];
ndtt=dtout/dt;
ntout=(int)(1000*tmax/dtout+0.5)+1;
cal_c(mm,c);
/********************************************************/
/********************************************************/
/****************** source wavefiled *********************** reciever wavefiled *************/
s_u0=alloc2float(nz+2*npd,nx+2*npd); g_u0=alloc2float(nz+2*npd,nx+2*npd);
s_u1=alloc2float(nz+2*npd,nx+2*npd); g_u1=alloc2float(nz+2*npd,nx+2*npd);
s_w0=alloc2float(nz+2*npd,nx+2*npd); g_w0=alloc2float(nz+2*npd,nx+2*npd);
s_w1=alloc2float(nz+2*npd,nx+2*npd); g_w1=alloc2float(nz+2*npd,nx+2*npd);
s_txx0=alloc2float(nz+2*npd,nx+2*npd); g_txx0=alloc2float(nz+2*npd,nx+2*npd);
s_txx1=alloc2float(nz+2*npd,nx+2*npd); g_txx1=alloc2float(nz+2*npd,nx+2*npd);
s_tzz0=alloc2float(nz+2*npd,nx+2*npd); g_tzz0=alloc2float(nz+2*npd,nx+2*npd);
s_tzz1=alloc2float(nz+2*npd,nx+2*npd); g_tzz1=alloc2float(nz+2*npd,nx+2*npd);
s_tpx0=alloc2float(nz+2*npd,nx+2*npd); g_tpx0=alloc2float(nz+2*npd,nx+2*npd);
s_tpx1=alloc2float(nz+2*npd,nx+2*npd); g_tpx1=alloc2float(nz+2*npd,nx+2*npd);
s_tpz0=alloc2float(nz+2*npd,nx+2*npd); g_tpz0=alloc2float(nz+2*npd,nx+2*npd);
s_tpz1=alloc2float(nz+2*npd,nx+2*npd); g_tpz1=alloc2float(nz+2*npd,nx+2*npd);
s_tqx0=alloc2float(nz+2*npd,nx+2*npd); g_tqx0=alloc2float(nz+2*npd,nx+2*npd);
s_tqx1=alloc2float(nz+2*npd,nx+2*npd); g_tqx1=alloc2float(nz+2*npd,nx+2*npd);
s_tqz0=alloc2float(nz+2*npd,nx+2*npd); g_tqz0=alloc2float(nz+2*npd,nx+2*npd);
s_tqz1=alloc2float(nz+2*npd,nx+2*npd); g_tqz1=alloc2float(nz+2*npd,nx+2*npd);
/*************zero source wavefiled ****************** zero reciever wavefiled *************/
zero2float(s_u0,nz+2*npd,nx+2*npd); zero2float(g_u0,nz+2*npd,nx+2*npd);
zero2float(s_u1,nz+2*npd,nx+2*npd); zero2float(g_u1,nz+2*npd,nx+2*npd);
zero2float(s_w0,nz+2*npd,nx+2*npd); zero2float(g_w0,nz+2*npd,nx+2*npd);
zero2float(s_w1,nz+2*npd,nx+2*npd); zero2float(g_w1,nz+2*npd,nx+2*npd);
zero2float(s_txx0,nz+2*npd,nx+2*npd); zero2float(g_txx0,nz+2*npd,nx+2*npd);
zero2float(s_txx1,nz+2*npd,nx+2*npd); zero2float(g_txx1,nz+2*npd,nx+2*npd);
zero2float(s_tzz0,nz+2*npd,nx+2*npd); zero2float(g_tzz0,nz+2*npd,nx+2*npd);
zero2float(s_tzz1,nz+2*npd,nx+2*npd); zero2float(g_tzz1,nz+2*npd,nx+2*npd);
zero2float(s_tpx0,nz+2*npd,nx+2*npd); zero2float(g_tpx0,nz+2*npd,nx+2*npd);
zero2float(s_tpx1,nz+2*npd,nx+2*npd); zero2float(g_tpx1,nz+2*npd,nx+2*npd);
zero2float(s_tpz0,nz+2*npd,nx+2*npd); zero2float(g_tpz0,nz+2*npd,nx+2*npd);
zero2float(s_tpz1,nz+2*npd,nx+2*npd); zero2float(g_tpz1,nz+2*npd,nx+2*npd);
zero2float(s_tqx0,nz+2*npd,nx+2*npd); zero2float(g_tqx0,nz+2*npd,nx+2*npd);
zero2float(s_tqx1,nz+2*npd,nx+2*npd); zero2float(g_tqx1,nz+2*npd,nx+2*npd);
zero2float(s_tqz0,nz+2*npd,nx+2*npd); zero2float(g_tqz0,nz+2*npd,nx+2*npd);
zero2float(s_tqz1,nz+2*npd,nx+2*npd); zero2float(g_tqz1,nz+2*npd,nx+2*npd);
/************************* Lighting source alloc & zero ******************************/
source_x=alloc2float(nz,nx); zero2float(source_x,nz,nx);
source_z=alloc2float(nz,nx); zero2float(source_z,nz,nx);
// sourceI=alloc3float(nz,2*nh+1,nx); zero3float(sourceI,nz,2*nh+1,nx);
d0=get_constant(dx,dz,nx,nz,nt,ntout,npd,tmax,favg,dtout,dt,vp,ndtt,myid);
dt=dt/1000;
/***********************************************************/
float *coffx1;float *coffx2;float *coffz1;float *coffz2;
float *acoffx1;float *acoffx2;float *acoffz1;float *acoffz2;
coffx1=alloc1float(nx+2*npd);
coffx2=alloc1float(nx+2*npd);
coffz1=alloc1float(nz+2*npd);
coffz2=alloc1float(nz+2*npd);
acoffx1=alloc1float(nx+2*npd);
acoffx2=alloc1float(nx+2*npd);
acoffz1=alloc1float(nz+2*npd);
acoffz2=alloc1float(nz+2*npd);
zero1float(coffx1,nx+2*npd);
zero1float(coffx2,nx+2*npd);
zero1float(acoffx1,nx+2*npd);
zero1float(acoffx2,nx+2*npd);
zero1float(coffz1,nz+2*npd);
zero1float(coffz2,nz+2*npd);
zero1float(acoffz1,nz+2*npd);
zero1float(acoffz2,nz+2*npd);
initial_coffe(dt,d0,nx,nz,coffx1,coffx2,coffz1,coffz2,acoffx1,acoffx2,acoffz1,acoffz2,npd);
/***********************************************************/
ndtt=(int)ndtt;
for(i=0;i<=nx+2*npd-1;i++)
{
for(j=0;j<=nz+2*npd-1;j++)
{
vp[i][j]=rho[i][j]*(vp[i][j]*vp[i][j]);
rho[i][j]=1.0/rho[i][j];
}
}
FILE *fpsnap,*fpsnap1,*fpsnap2,*fpsnap3;
if((is==1)&&(flag_snap))
{
fpsnap=fopen("snap_construction_txx.dat","wb");
fpsnap1=fopen("snap_construction_tzz.dat","wb");
fpsnap2=fopen("snap_backpropagation_txx.dat","wb");
fpsnap3=fopen("snap_backpropagation_tzz.dat","wb");
}
for(it=nt-1;it>=0;it--)
{
if(it%100==0&&myid==0)printf("--- RTM is===%d it===%d\n",is,it);
/************************ construction waveform start *************************/
for(i=0;i<nx;i++)
{
s_txx0[npd+i][npd]=p_top_x[i][it];
s_txx0[npd+i][npd+nz-1]=p_bottom_x[i][it];
s_tzz0[npd+i][npd]=p_top_z[i][it];
s_tzz0[npd+i][npd+nz-1]=p_bottom_z[i][it];
}
for(j=0;j<nz;j++)
{
s_txx0[npd][npd+j]=p_left_x[j][it];
s_txx0[npd+nx-1][npd+j]=p_right_x[j][it];
s_tzz0[npd][npd+j]=p_left_z[j][it];
s_tzz0[npd+nx-1][npd+j]=p_right_z[j][it];
}
update_vel(nx,nz,npd,mm,dt,dx,dz,s_u0,s_w0,s_txx0,s_tzz0,
s_u1,s_w1,s_txx1,s_tzz1,rho,c,coffx1,coffx2,coffz1,coffz2);
inv_update_stress(nx,nz,dt,dx,dz,mm,s_u0,s_w0,s_txx0,s_tzz0,
s_u1,s_w1,s_txx1,s_tzz1,vp,c,npd,
s_tpx1,s_tpx0,s_tpz1,s_tpz0,s_tqx1,s_tqx0,s_tqz1,s_tqz0,
acoffx1,acoffx2,acoffz1,acoffz2,deta,epsilu,fs_sxd,ds_sxd,zs_sxd,is);
for(j=0;j<nz+2*npd;j++)
{
for(i=0;i<nx+2*npd;i++)
{
s_u0[i][j]=s_u1[i][j];
s_w0[i][j]=s_w1[i][j];
s_tpx0[i][j]=s_tpx1[i][j];
s_tpz0[i][j]=s_tpz1[i][j];
s_tqx0[i][j]=s_tqx1[i][j];
s_tqz0[i][j]=s_tqz1[i][j];
s_txx0[i][j]=s_txx1[i][j];
s_tzz0[i][j]=s_tzz1[i][j];
}
}
/************************ construction waveform end ************************/
/************************** back propagation start *************************/
for(i=0;i<nx;i++)
{
g_txx0[npd+i][npd]=p_obs_x[i][it];
g_tzz0[npd+i][npd]=p_obs_z[i][it];
}
update_vel(nx,nz,npd,mm,dt,dx,dz,g_u0,g_w0,g_txx0,g_tzz0,
g_u1,g_w1,g_txx1,g_tzz1,rho,c,coffx1,coffx2,coffz1,coffz2);
inv_update_stress(nx,nz,dt,dx,dz,mm,g_u0,g_w0,g_txx0,g_tzz0,
g_u1,g_w1,g_txx1,g_tzz1,vp,c,npd,
g_tpx1,g_tpx0,g_tpz1,g_tpz0,g_tqx1,g_tqx0,g_tqz1,g_tqz0,
acoffx1,acoffx2,acoffz1,acoffz2,deta,epsilu,fs_sxd,ds_sxd,zs_sxd,is);
for(j=0;j<nz+2*npd;j++)
{
for(i=0;i<nx+2*npd;i++)
{
g_u0[i][j]=g_u1[i][j];
g_w0[i][j]=g_w1[i][j];
g_tpx0[i][j]=g_tpx1[i][j];
g_tpz0[i][j]=g_tpz1[i][j];
g_tqx0[i][j]=g_tqx1[i][j];
g_tqz0[i][j]=g_tqz1[i][j];
g_txx0[i][j]=g_txx1[i][j];
g_tzz0[i][j]=g_tzz1[i][j];
}
}
/************************** back propagation end *************************/
/************************** snap *************************/
if((is==1)&&(it%100==0)&&(flag_snap))
{