Commit 14beb822 authored by fabian.kuehn's avatar fabian.kuehn

Added Reverse Time Migration (RTM)

parent 04ca7c45
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -19,19 +19,19 @@ EXEC= ../bin
# LINUX with OpenMPI / IntelMPI and INTEL Compiler
# Use icc whenever possible, this will be much faster than gcc
#CC=mpiicc
#LFLAGS=-lm -lcseife -lstfinv -laff -lfourierxx -lfftw3 -lstdc++
#CFLAGS=-O3
#SFLAGS=-L./../contrib/libcseife -L./../contrib/bin
#IFLAGS=-I./../contrib/libcseife -I./../contrib/header -I.
# LINUX with OpenMPI / IntelMPI and GCC Compiler
CC=mpicc
LFLAGS=-lm -lcseife -lstfinv -laff -lfourierxx -lfftw3 -lstdc++
CFLAGS=-O3
SFLAGS=-L./../contrib/libcseife -L./../contrib/bin
IFLAGS=-I./../contrib/libcseife -I./../contrib/header -I.
# LINUX with OpenMPI / IntelMPI and GCC Compiler
#CC=mpicc
#LFLAGS=-lm -lcseife -lstfinv -laff -lfourierxx -lfftw3 -lstdc++
#CFLAGS=-O3
#SFLAGS=-L./../contrib/libcseife -L./../contrib/bin
#IFLAGS=-I./../contrib/libcseife -I./../contrib/header -I.
ifeq ($(TERM_PROGRAM),Apple_Terminal)
LFLAGS=-lm -lcseife -lstfinv -laff -lfourierxx -lfftw3 -lc++
CC=mpicc
......@@ -70,7 +70,6 @@ IFOS2D= \
IFOS2D.c \
stf.c \
window_cos.c \
alloc_sections.c \
calc_mat_change_test.c \
calc_res.c \
calc_misfit.c \
......@@ -206,4 +205,4 @@ clean:
install: clean all
-include $(IFOS_OBJ:.o=.d)
-include $(IFOS_OBJ:.o=.d)
\ No newline at end of file
/*-----------------------------------------------------------------------------------------
* Copyright (C) 2016 For the list of authors, see file AUTHORS.
*
* This file is part of IFOS.
*
* IFOS 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, version 2.0 of the License only.
*
* IFOS 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 IFOS. See file COPYING and/or <http://www.gnu.org/licenses/gpl-2.0.html>.
-----------------------------------------------------------------------------------------*/
/* Computation of local source coordinates
*
*
*/
#include "fd.h"
void alloc_sections(int ntr,int ns,float ***sectionvx,float ***sectionvy,float ***sectionvz,float ***sectionp,float ***sectionpnp1,float ***sectionpn,float ***sectioncurl,float ***sectiondiv,
float ***sectionpdata,float ***sectionpdiff,float ***sectionpdiffold,float ***sectionvxdata,float ***sectionvxdiff,float ***sectionvxdiffold,float ***sectionvydata,
float ***sectionvydiff,float ***sectionvydiffold,float ***sectionvzdata,float ***sectionvzdiff,float ***sectionvzdiffold)
{
extern int SEISMO, WAVETYPE;
extern FILE *FP;
switch (SEISMO){
case 1 : /* particle velocities only */
switch (WAVETYPE) {
case 1:
*sectionvx=matrix(1,ntr,1,ns);
*sectionvy=matrix(1,ntr,1,ns);
break;
case 2:
*sectionvz=matrix(1,ntr,1,ns);
break;
case 3:
*sectionvx=matrix(1,ntr,1,ns);
*sectionvy=matrix(1,ntr,1,ns);
*sectionvz=matrix(1,ntr,1,ns);
break;
}
break;
case 2 : /* pressure only */
*sectionp=matrix(1,ntr,1,ns);
*sectionpnp1=matrix(1,ntr,1,ns);
*sectionpn=matrix(1,ntr,1,ns);
break;
case 3 : /* curl and div only */
*sectioncurl=matrix(1,ntr,1,ns);
*sectiondiv=matrix(1,ntr,1,ns);
break;
case 4 : /* everything */
switch (WAVETYPE) {
case 1:
*sectionvx=matrix(1,ntr,1,ns);
*sectionvy=matrix(1,ntr,1,ns);
break;
case 2:
*sectionvz=matrix(1,ntr,1,ns);
break;
case 3:
*sectionvx=matrix(1,ntr,1,ns);
*sectionvy=matrix(1,ntr,1,ns);
*sectionvz=matrix(1,ntr,1,ns);
break;
}
*sectioncurl=matrix(1,ntr,1,ns);
*sectiondiv=matrix(1,ntr,1,ns);
*sectionp=matrix(1,ntr,1,ns);
break;
case 5 : /* everything except curl and div*/
switch (WAVETYPE) {
case 1:
*sectionvx=matrix(1,ntr,1,ns);
*sectionvy=matrix(1,ntr,1,ns);
break;
case 2:
*sectionvz=matrix(1,ntr,1,ns);
break;
case 3:
*sectionvx=matrix(1,ntr,1,ns);
*sectionvy=matrix(1,ntr,1,ns);
*sectionvz=matrix(1,ntr,1,ns);
break;
}
*sectionp=matrix(1,ntr,1,ns);
break;
}
*sectionpdata=matrix(1,ntr,1,ns);
*sectionpdiff=matrix(1,ntr,1,ns);
*sectionpdiffold=matrix(1,ntr,1,ns);
switch (WAVETYPE) {
case 1:
*sectionvxdata=matrix(1,ntr,1,ns);
*sectionvxdiff=matrix(1,ntr,1,ns);
*sectionvxdiffold=matrix(1,ntr,1,ns);
*sectionvydata=matrix(1,ntr,1,ns);
*sectionvydiff=matrix(1,ntr,1,ns);
*sectionvydiffold=matrix(1,ntr,1,ns);
break;
case 2:
*sectionvzdata=matrix(1,ntr,1,ns);
*sectionvzdiff=matrix(1,ntr,1,ns);
*sectionvzdiffold=matrix(1,ntr,1,ns);
break;
case 3:
*sectionvxdata=matrix(1,ntr,1,ns);
*sectionvxdiff=matrix(1,ntr,1,ns);
*sectionvxdiffold=matrix(1,ntr,1,ns);
*sectionvydata=matrix(1,ntr,1,ns);
*sectionvydiff=matrix(1,ntr,1,ns);
*sectionvydiffold=matrix(1,ntr,1,ns);
*sectionvzdata=matrix(1,ntr,1,ns);
*sectionvzdiff=matrix(1,ntr,1,ns);
*sectionvzdiffold=matrix(1,ntr,1,ns);
break;
}
}
void dealloc_sections(int ntr,int ns,int **recpos_loc,float **sectionvx,float **sectionvy,float **sectionvz,float **sectionp,float **sectionpnp1,float **sectionpn,float **sectioncurl,float **sectiondiv,
float **sectionpdata,float **sectionpdiff,float **sectionpdiffold,float **sectionvxdata,float **sectionvxdiff,float **sectionvxdiffold,float **sectionvydata,
float **sectionvydiff,float **sectionvydiffold,float **sectionvzdata,float **sectionvzdiff,float **sectionvzdiffold)
{
extern int SEISMO, WAVETYPE;
extern FILE *FP;
free_imatrix(recpos_loc,1,3,1,ntr);
switch (SEISMO){
case 1 : /* particle velocities only */
if (WAVETYPE==1 || WAVETYPE==3) {
free_matrix(sectionvx,1,ntr,1,ns);
free_matrix(sectionvy,1,ntr,1,ns);
}
if (WAVETYPE==2 || WAVETYPE==3) {
free_matrix(sectionvz,1,ntr,1,ns);
}
break;
case 2 : /* pressure only */
if (WAVETYPE==1 || WAVETYPE==3) {
free_matrix(sectionp,1,ntr,1,ns);
free_matrix(sectionpn,1,ntr,1,ns);
free_matrix(sectionpnp1,1,ntr,1,ns);
}
break;
case 3 : /* curl and div only */
if (WAVETYPE==1 || WAVETYPE==3) {
free_matrix(sectioncurl,1,ntr,1,ns);
free_matrix(sectiondiv,1,ntr,1,ns);
}
break;
case 4 : /* everything */
if (WAVETYPE==1 || WAVETYPE==3) {
free_matrix(sectionvx,1,ntr,1,ns);
free_matrix(sectionvy,1,ntr,1,ns);
free_matrix(sectionp,1,ntr,1,ns);
free_matrix(sectioncurl,1,ntr,1,ns);
free_matrix(sectiondiv,1,ntr,1,ns);
}
if (WAVETYPE==2 || WAVETYPE==3) {
free_matrix(sectionvz,1,ntr,1,ns);
}
break;
case 5 : /* everything except curl and div */
if (WAVETYPE==1 || WAVETYPE==3) {
free_matrix(sectionvx,1,ntr,1,ns);
free_matrix(sectionvy,1,ntr,1,ns);
free_matrix(sectionp,1,ntr,1,ns);
}
if (WAVETYPE==2 || WAVETYPE==3) {
free_matrix(sectionvz,1,ntr,1,ns);
}
break;
}
if (WAVETYPE==1 || WAVETYPE==3) {
free_matrix(sectionvxdata,1,ntr,1,ns);
free_matrix(sectionvxdiff,1,ntr,1,ns);
free_matrix(sectionvydata,1,ntr,1,ns);
free_matrix(sectionvydiff,1,ntr,1,ns);
free_matrix(sectionvydiffold,1,ntr,1,ns);
free_matrix(sectionvxdiffold,1,ntr,1,ns);
free_matrix(sectionpdata,1,ntr,1,ns);
free_matrix(sectionpdiff,1,ntr,1,ns);
free_matrix(sectionpdiffold,1,ntr,1,ns);
}
if (WAVETYPE==2 || WAVETYPE==3) {
free_matrix(sectionvzdata,1,ntr,1,ns);
free_matrix(sectionvzdiff,1,ntr,1,ns);
free_matrix(sectionvzdiffold,1,ntr,1,ns);
}
}
\ No newline at end of file
......@@ -31,14 +31,12 @@ void apply_workflow(float ** workflow,int workflow_lines,char workflow_header[ST
/* extern variables */
extern int INV_RHO_ITER,INV_VS_ITER,INV_VP_ITER;
extern int TIME_FILT,MYID;
extern float F_HIGH_PASS;
extern float PRO;
extern int WAVETYPE;
extern float JOINT_INVERSION_PSV_SH_ALPHA_VS;
extern float JOINT_INVERSION_PSV_SH_ALPHA_RHO;
extern int EPRECOND;
extern float EPSILON_WE;
extern float GAMMA;
extern int GRAD_METHOD;
extern int WORKFLOW_STAGE;
......@@ -90,49 +88,44 @@ void apply_workflow(float ** workflow,int workflow_lines,char workflow_header[ST
PRO=workflow[WORKFLOW_STAGE][5];
/* Frequency filtering */
if( TIME_FILT == 1 ) {
if(TIME_FILT==1) {
TIME_FILT=workflow[WORKFLOW_STAGE][6];
if( TIME_FILT > 0 ) {
if( F_HIGH_PASS != workflow[WORKFLOW_STAGE][7] ) *LBFGS_iter_start=*iter;
F_HIGH_PASS=workflow[WORKFLOW_STAGE][7];
if( *F_LOW_PASS != workflow[WORKFLOW_STAGE][8] ) *LBFGS_iter_start=*iter;
*F_LOW_PASS=workflow[WORKFLOW_STAGE][8];
if(*F_LOW_PASS>workflow[WORKFLOW_STAGE][7]&&(workflow[WORKFLOW_STAGE][6]>0)) {
if(MYID==0)printf("\n Due to the abort criteriom F_LOW_PASS is already higher than specified in workflow\n");
if(MYID==0)printf(" therefore instead of %.2f HZ F_LOW_PASS=%.2f HZ is used\n",workflow[WORKFLOW_STAGE][7],*F_LOW_PASS);
} else {
if(*F_LOW_PASS!=workflow[WORKFLOW_STAGE][7]) *LBFGS_iter_start=*iter;
*F_LOW_PASS=workflow[WORKFLOW_STAGE][7];
}
} else {
if(MYID==0&&(workflow[WORKFLOW_STAGE][6]>0))printf("\n TIME_FILT cannot be activated due to it is not activated in the JSON File \n");
}
/* Change of wavetype */
if(wavetype_start!=3&&(WAVETYPE!=workflow[WORKFLOW_STAGE][9])){
if(wavetype_start!=3&&(WAVETYPE!=workflow[WORKFLOW_STAGE][8])){
if(MYID==0)printf("\n Sorry, change of WAVETYPE with workflow only possible if WAVETYPE==3 in *.json");
if(MYID==0)printf("\n WAVETYPE will remain unchanged %i",WAVETYPE);
} else {
/* detect change and reset some things */
if(WAVETYPE!=workflow[WORKFLOW_STAGE][9]) {
if(WAVETYPE!=workflow[WORKFLOW_STAGE][8]) {
*change_wavetype_iter=*iter;
*LBFGS_iter_start=*iter;
}
WAVETYPE=workflow[WORKFLOW_STAGE][9];
WAVETYPE=workflow[WORKFLOW_STAGE][8];
}
/* Joint inversion PSV and SH */
JOINT_INVERSION_PSV_SH_ALPHA_VS=workflow[WORKFLOW_STAGE][10];
JOINT_INVERSION_PSV_SH_ALPHA_RHO=workflow[WORKFLOW_STAGE][11];
JOINT_INVERSION_PSV_SH_ALPHA_VS=workflow[WORKFLOW_STAGE][9];
JOINT_INVERSION_PSV_SH_ALPHA_RHO=workflow[WORKFLOW_STAGE][10];
/* Approx. Hessian */
if(EPRECOND==0 && workflow[WORKFLOW_STAGE][12]!=0){
if(EPRECOND==0 && workflow[WORKFLOW_STAGE][11]!=0){
if(MYID==0) printf(" WARNING: EPRECOND have to be set >0 in JSON (if so, ignore this message)");
}
EPRECOND=workflow[WORKFLOW_STAGE][12];
EPSILON_WE=workflow[WORKFLOW_STAGE][13];
GAMMA=workflow[WORKFLOW_STAGE][14];
EPRECOND=workflow[WORKFLOW_STAGE][11];
EPSILON_WE=workflow[WORKFLOW_STAGE][12];
if(*LBFGS_iter_start==*iter && GRAD_METHOD==2){
if(MYID==0)printf("\n L-BFGS will be used from iteration %d on.",*LBFGS_iter_start+1);
}
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ double calc_misfit(float **sectiondata, float **section, int ntr, int ns, int LN
extern int TRKILL, NORMALIZE, F_LOW_PASS, TIMEWIN;
extern char TRKILL_FILE[STRING_SIZE];
extern int VELOCITY;
extern int WRITE_FILTERED_DATA;
int i,j;
float l2;
int h;
......@@ -180,10 +180,8 @@ double calc_misfit(float **sectiondata, float **section, int ntr, int ns, int LN
abs_sectiondata+=intseis_sectiondata[i][j]*intseis_sectiondata[i][j];
abs_section+=intseis_section[i][j]*intseis_section[i][j];
}
if (abs_sectiondata==0) abs_sectiondata=1;
else abs_sectiondata=sqrt(abs_sectiondata);
if (abs_section==0) abs_section==1;
else abs_section=sqrt(abs_section);
abs_sectiondata=sqrt(abs_sectiondata);
abs_section=sqrt(abs_section);
}
/* calculate L2 residuals */
......@@ -202,15 +200,6 @@ double calc_misfit(float **sectiondata, float **section, int ntr, int ns, int LN
}
}
if(WRITE_FILTERED_DATA==2){
for(i=1;i<=ntr;i++){
for(j=1;j<=ns;j++){
sectiondata[i][j]=intseis_sectiondata[i][j];
section[i][j]=intseis_section[i][j];
}
}
}
l2=L2;
/* printf("\n MYID = %i IN CALC_MISFIT: L2 = %10.12f \n",MYID,l2); */
......
......@@ -27,6 +27,7 @@ double calc_res(float **sectiondata, float **section, float **sectiondiff, float
extern float DT, WATERLEVEL_LNORM8;
extern int REC1, REC2, MYID, ACOUSTIC;
extern int TRKILL, NORMALIZE, F_LOW_PASS, TIMEWIN;
extern int RTM;
extern char TRKILL_FILE[STRING_SIZE];
extern int VELOCITY, USE_WORKFLOW, WORKFLOW_STAGE;
float RMS, signL1;
......@@ -207,10 +208,8 @@ double calc_res(float **sectiondata, float **section, float **sectiondiff, float
abs_section+=intseis_section[i][j]*intseis_section[i][j];
sectiondata_mult_section+=intseis_sectiondata[i][j]*intseis_section[i][j]; /* calculation of dot product for measured (section) and synthetic (sectiondata) data*/
}
if (abs_sectiondata==0) abs_sectiondata=1;
else abs_sectiondata=sqrt(abs_sectiondata);
if (abs_section==0) abs_section==1;
else abs_section=sqrt(abs_section);
abs_sectiondata=sqrt(abs_sectiondata);
abs_section=sqrt(abs_section);
}
/* calculate residual seismograms and norm */
......@@ -275,6 +274,12 @@ double calc_res(float **sectiondata, float **section, float **sectiondiff, float
L2+=fabs(sectiondiff[i][invtime])*fabs(sectiondiffold[i][j]);
}
/* replace residuals for reverse time migration*/
if(RTM==1){
sectiondiff[i][invtime]=sectiondata[i][j];
}
sectiondiff[i][invtime]=sectiondata[i][j];
/*L2+=sectiondiff[i][invtime];*/
invtime--; /* reverse time direction */
......
......@@ -277,7 +277,7 @@ void checkfd(FILE *fp, float ** prho, float ** ppi, float ** pu, float ** ptaus,
therefore we determine the minimum/maximum position in y-direction by the ZREC1 variable and vice versa.
this has to be considered for the receiver line coordinates specified in both the input file and separate source/receiver files*/
if (READREC==0 || READREC==2) {
if (READREC==0) {
if (XREC1>XREC2) {
srec_maxx=XREC1;
srec_minx=XREC2;
......
......@@ -30,7 +30,7 @@ void exchange_par(void){
extern float XREC1, XREC2, YREC1, YREC2, FPML;
extern float REC_ARRAY_DEPTH, REC_ARRAY_DIST, MUN, EPSILON, EPSILON_u, EPSILON_rho;
extern int SEISMO, NDT, NGEOPH, SEIS_FORMAT, FREE_SURF, READMOD, READREC, SRCREC;
extern int BOUNDARY, REC_ARRAY, DRX, FW, STF_FULL;
extern int BOUNDARY, REC_ARRAY, DRX, FW;
extern int SNAPSHOT_START,SNAPSHOT_END,SNAPSHOT_INCR;
extern float TSNAP1, TSNAP2, TSNAPINC, REFREC[4];
extern char MFILE[STRING_SIZE], SIGNAL_FILE[STRING_SIZE],SIGNAL_FILE_SH[STRING_SIZE], LOG_FILE[STRING_SIZE];
......@@ -59,9 +59,10 @@ void exchange_par(void){
extern float npower, k_max_PML;
extern int INV_STF, N_STF, N_STF_START;
extern char PARA[STRING_SIZE];
extern int TIME_FILT, ORDER,WRITE_FILTERED_DATA;
extern int TIME_FILT, ORDER, ZERO_PHASE,WRITE_FILTERED_DATA;
extern float F_LOW_PASS_START, F_LOW_PASS_END, F_LOW_PASS_INCR, F_HIGH_PASS;
extern int LNORM, DTINV;
extern int RTM;
extern int STEPMAX;
extern float EPS_SCALE, SCALEFAC;
extern float PRO;
......@@ -95,7 +96,6 @@ void exchange_par(void){
extern int WAVETYPE;
extern int SOURCE_SHAPE_SH;
extern int JOINT_INVERSION_PSV_SH_TYPE;
extern int JOINT_EQUAL_WEIGHTING;
/* Workflow */
extern char FILE_WORKFLOW[STRING_SIZE];
extern int USE_WORKFLOW;
......@@ -326,7 +326,7 @@ void exchange_par(void){
idum[85] = NO_OF_TESTSHOTS;
// idum[86] = EMPTY;
idum[86] = ZERO_PHASE;
idum[87] = VELOCITY;
......@@ -375,9 +375,9 @@ void exchange_par(void){
idum[114]=TRKILL_OFFSET;
idum[115]=TRKILL_STF_OFFSET;
idum[116]=TRKILL_STF_OFFSET_INVERT;
idum[117]=RTM;
idum[117]=JOINT_EQUAL_WEIGHTING;
idum[118]=STF_FULL;
} /** if (MYID == 0) **/
MPI_Barrier(MPI_COMM_WORLD);
......@@ -612,7 +612,7 @@ void exchange_par(void){
NO_OF_TESTSHOTS = idum[85];
// EMPTY = idum[86];
ZERO_PHASE = idum[86];
VELOCITY = idum[87];
......@@ -662,9 +662,9 @@ void exchange_par(void){
TRKILL_OFFSET=idum[114];
TRKILL_STF_OFFSET=idum[115];
TRKILL_STF_OFFSET_INVERT=idum[116];
RTM=idum[117];
JOINT_EQUAL_WEIGHTING=idum[117];
STF_FULL=idum[118];
if ( MYID!=0 && L>0 ) {
FL=vector(1,L);
}
......
/*------------------------------------------------------------------------
* fd.h - include file for viscoelastic FD programs
* See COPYING file for copying and redistribution conditions.
* ---------------------------------------------------------------------*/
/* files to include */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <time.h>
#include <mpi.h>
#define iround(x) ((int)(floor)(x+0.5))
#define min(x,y) ((x<y)?x:y)
#define max(x,y) ((x<y)?y:x)
#define fsign(x) ((x<0.0)?(-1):1)
#define PI (3.141592653589793)
#define NPAR 120
#define STRING_SIZE 74
#define STRING_SIZE2 256
#define REQUEST_COUNT 4
#define WORKFLOW_MAX_VAR 14
/* declaration of functions */
void window_cos(float **win, int npad, int nsrc, float it1, float it2, float it3, float it4);
void catseis(float **data, float **fulldata, int *recswitch, int ntr_glob, MPI_Comm newcomm_nodentr);
void stf(FILE *fp, float **sectionvy, float ** sectionvy_obs, float ** sectionvy_conv, float * source_time_function, int **recpos, int **recpos_loc,
int ntr_glob,int ntr, float ** srcpos, int ishot, int ns, int iter, int nshots, float F_LOW_PASS, int SH,int nsrc_glob);
int **splitrec(int **recpos,int *ntr_loc, int ntr, int *recswitch);
void absorb(float ** absorb_coeff);
void taper_grad(float ** waveconv, float ** taper_coeff, float **srcpos, int nshots, int **recpos, int ntr, int sws);
void taper_grad_shot(float ** waveconv,float ** taper_coeff, float **srcpos, int nshots, int **recpos, int ntr, int ishot, int sws);
void spat_filt(float ** waveconv, int iter, int sws);
float norm(float ** waveconv, int iter, int sws);
void alloc_sections(int ntr,int ns,float ***sectionvx,float ***sectionvy,float ***sectionvz,float ***sectionp,float ***sectionpnp1,float ***sectionpn,float ***sectioncurl,float ***sectiondiv,
float ***sectionpdata,float ***sectionpdiff,float ***sectionpdiffold,float ***sectionvxdata,float ***sectionvxdiff,float ***sectionvxdiffold,float ***sectionvydata,
float ***sectionvydiff,float ***sectionvydiffold,float ***sectionvzdata,float ***sectionvzdiff,float ***sectionvzdiffold);
void av_mat(float ** pi, float ** u,
float ** ppijm, float ** puip, float ** pujm);
void av_mue(float ** u, float ** uipjp,float ** rho);
void av_rho(float **rho, float **rip, float **rjp);
void av_tau(float **taus, float **tausipjp);
float median2d(float **mat, int ny, int nx);
void calc_mat_change(float ** waveconv, float ** waveconv_rho, float ** waveconv_u, float ** rho, float ** rhonp1, float ** pi, float ** pinp1, float ** u,
float ** unp1, int iter, int epstest, int calcneweps, float eps_scale_vp, float eps_scale_vs);
void calc_mat_change_test(float ** waveconv, float ** waveconv_rho, float ** waveconv_u, float ** rho, float ** rhonp1, float ** pi, float ** pinp1, float ** u, float ** unp1, int iter,
int epstest, int FORWARD_ONLY, float eps_scale, int itest, int nfstart, float ** u_start, float ** pi_start, float ** rho_start,int wavetype_start,float **bfgsmod,int bfgsnum,int bfgspar,float Vs_avg,float Vp_avg,float rho_avg,int LBFGS_iter_start);
double calc_res(float **sectiondata, float **section, float **sectiondiff, float **sectiondiffold, int ntr, int ns, int LNORM, float L2, int itest, int sws, int swstestshot, int ntr_glob, int **recpos_loc, int nsrc_glob, int ishot, int iter, float ** srcpos, int ** recpos);
double calc_misfit(float **sectiondata, float **section, int ntr, int ns, int LNORM, float L2, int itest, int sws, int swstestshot,int ntr_glob, int **recpos_loc, int nsrc_glob, int ishot, int iter, float ** srcpos, int ** recpos);
float calc_opt_step(float * L2t, float ** waveconv, float ** gradp, float * epst, int sws, float C_vp);
float calc_opt_step_test(float * L2t, float ** waveconv, float ** gradp, float * epst, int sws, float C_vp);
double calc_energy(float **sectiondata, int ntr, int ns, float energy, int ntr_glob, int **recpos_loc, int nsrc_glob, int ishot, int iter, float ** srcpos, int ** recpos);
void checkfd(FILE *fp, float ** prho, float ** ppi, float ** pu, float ** ptaus, float ** ptaup, float * peta, float *hc, float **srcpos, int nsrc, int **recpos, int ntr);
void checkfd_hc(FILE *fp, float ** prho, float ** ppi, float ** pu,
float ** ptaus, float ** ptaup, float *peta, float *hc);
void checkfd_ssg_elastic(FILE *fp, float ** prho, float ** ppi, float ** pu, float *hc);
void checkfd_ssg_visc(FILE *fp, float ** prho, float ** ppi, float ** pu, float ** ptaus, float ** ptaup, float * peta, float *hc);
void checkfd_rsg(FILE *fp, float ** prho, float ** ppi, float ** pu,
float ** ptaus, float ** ptaup, float *peta);
void comm_ini(float ** bufferlef_to_rig, float ** bufferrig_to_lef,
float ** buffertop_to_bot, float ** bufferbot_to_top,
MPI_Request *req_send, MPI_Request *req_rec);
void conv_FD(float * temp_TS, float * temp_TS1, float * temp_conv, int ns);
void count_killed_traces(int ntr, int swstestshot, int ntr_glob, int **recpos_loc, int nsrc_glob, int ishot, int* ptr_killed_traces, int* ptr_killed_traces_testshots,float ** srcpos, int ** recpos);
void create_trkill_table(int ** killtable, int ntr_glob, int **recpos, int nsrc_glob, float **srcpos, int ishot, float kill_offset_lower, float kill_offset_upper);
void dealloc_sections(int ntr,int ns,int **recpos_loc,float **sectionvx,float **sectionvy,float **sectionvz,float **sectionp,float **sectionpnp1,float **sectionpn,float **sectioncurl,float **sectiondiv,
float **sectionpdata,float **sectionpdiff,float **sectionpdiffold,float **sectionvxdata,float **sectionvxdiff,float **sectionvxdiffold,float **sectionvydata,
float **sectionvydiff,float **sectionvydiffold,float **sectionvzdata,float **sectionvzdiff,float **sectionvzdiffold);
float exchange_L2(float L2, int sw, int bcast_l2);
void exchange_rsg(float ** vx, float ** vy, float ** vz,
float ** bufferlef_to_rig, float ** bufferrig_to_lef,
float ** buffertop_to_bot, float ** bufferbot_to_top);
void exchange_rsg_4th(float ** vx, float ** vy, float ** vz,
float ** bufferlef_to_rig, float ** bufferrig_to_lef,
float ** buffertop_to_bot, float ** bufferbot_to_top);
void exchange_v(float ** vx, float ** vy, float ** vz,
float ** bufferlef_to_rig, float ** bufferrig_to_lef,
float ** buffertop_to_bot, float ** bufferbot_to_top,
MPI_Request * req_send, MPI_Request * req_rec, int wavetyp_start);
void exchange_s(float ** sxx, float ** syy,
float ** sxy,float ** sxz,float ** syz, float ** bufferlef_to_rig, float ** bufferrig_to_lef,
float ** buffertop_to_bot, float ** bufferbot_to_top,
MPI_Request * req_send, MPI_Request * req_rec, int wavetyp_start);
void exchange_par(void);
void exchange_mod_es(float ** matmod, int ncptot, int nparameter);
void FFT_filt(float ** data, float freqshift, int ntr, int ns,int method);
/*short FFT(short int dir,long m,float *x,float *y);*/
void FFT(int isign, unsigned long nlog, float *re, float *im); /* NR version*/
float *filter_frequencies(int *nfrq);
float *holbergcoeff(void);
void info(FILE *fp);
void initproc(void);
void interpol(int ni1, int ni2, float ** intvar, int cfgt_check);
double LU_decomp(double **A, double *x, double *b,int n);
float minimum_m(float **mat, int nx, int ny);
float maximum_m(float **mat, int nx, int ny);
void model(float ** rho, float ** pi, float ** u,
float ** taus, float ** taup, float * eta);
void model_elastic(float ** rho, float ** pi, float ** u);
void model_ani(float ** rho, float ** c11, float ** c15, float ** c13,
float ** c35, float ** c33, float ** c55,
float ** taus, float ** taup, float * eta);
void matcopy(float ** prho, float ** ppi, float ** pu, float ** ptaup,
float ** ptaus);
void matcopy_elastic(float ** prho, float ** ppi, float ** pu);
void matcopy_ani(float ** rho, float ** c11, float ** c15, float ** c13,
float ** c35, float ** c33, float ** c55, float ** taus,
float ** taup);
void max_grad(float ** waveconv, float ** waveconv_rho, float ** waveconv_u, float ** rho, float ** pi, float ** u);
void merge(int nsnap, int type);
void merge2(int nsnap, int type);
void mergemod(char modfile[STRING_SIZE], int format);
void note(FILE *fp);
void outseis_glob(FILE *fp, FILE *fpdata, int comp, float **section,
int **recpos, int **recpos_loc, int ntr, float ** srcpos_loc,
int nsrc, int ns, int seis_form, int ishot, int sws);
void outseis_vector(FILE *fp, FILE *fpdata, int comp, float *section,
int **recpos, int **recpos_loc, int ntr, float ** srcpos_loc,
int nsrc, int ns, int seis_form, int ishot, int sws);
void inseis(FILE *fp, int comp, float **section, int ntr, int ns, int sws, int iter);
void inseis_source_wavelet(float *section, int ns, int ishot, int SH, int STF);
void taper(float *section, int ns, float fc);
void output_source_signal(FILE *fp, float **signals, int ns, int seis_form);
void PCG(float ** waveconv, float ** taper_coeff, int nsrc, float ** srcpos, int ** recpos, int ntr_glob, int iter, float C_vp, float ** gradp, int nfstart_jac, float ** waveconv_u, float C_vs, float ** gradp_u, float ** waveconv_rho, float C_rho, float ** gradp_rho, float Vs_avg, float F_LOW_PASS, int PCG_iter_start);
void PCG_SH(float ** taper_coeff, int nsrc, float ** srcpos, int ** recpos, int ntr_glob, int iter, int nfstart_jac, float ** waveconv_u, float C_vs, float ** gradp_u, float ** waveconv_rho, float C_rho, float ** gradp_rho, float Vs_avg, float F_LOW_PASS, int PCG_iter_start);
void PML_pro(float * d_x, float * K_x, float * alpha_prime_x, float * a_x, float * b_x,
float * d_x_half, float * K_x_half, float * alpha_prime_x_half, float * a_x_half, float * b_x_half,
float * d_y, float * K_y, float * alpha_prime_y, float * a_y, float * b_y,
float * d_y_half, float * K_y_half, float * alpha_prime_y_half, float * a_y_half, float * b_y_half);
void psource(int nt, float ** sxx, float ** syy, float ** sp,
float ** srcpos_loc, float ** signals, int nsrc, int sw);
void psource_rsg(int nt, float ** sxx, float ** syy,
float ** srcpos_loc, float ** signals, int nsrc);
float *rd_sour(int *nts,FILE* fp_source);
float readdsk(FILE *fp_in, int format);
void readbufs(float ** sxx, float ** syy,
float ** sxy,