void offruffp_init (float h0_in, int nh_in, float dh_in /* half-offset axis */, int nx_in, float dx /* midpoint axis */, float w /* frequency */, int num_in /* continuation */) /*< Initialize >*/ { float w2; h0 = h0_in/dx; nh = nh_in; dh = dh_in/dx; nx = nx_in; w2 = w*w; num = num_in; #ifdef SF_HAS_COMPLEX_H c1 = 3.*sf_cmplx(9. + w2,4.*w)/(w2*sf_cmplx(3.,-w)); c2 = 3.*sf_cmplx(w2 - 27.,8.*w)/(w2*sf_cmplx(3.,-w)); #else c1 = sf_cdiv(sf_cmplx(3.*(9. + w2), 3.*4.*w),sf_cmplx(w2*3.,-w2*w)); c2 = sf_cdiv(sf_cmplx(3.*(w2 - 27.),3.*8.*w),sf_cmplx(w2*3.,-w2*w)); #endif }
void rweone_thr( sf_complex *a, sf_complex *b, sf_complex *c, sf_complex *v, int n) /*< tridiagonal solver >*/ { int i; #ifdef SF_HAS_COMPLEX_H b[0]/=a[0]; v[0]/=a[0]; #else b[0] = sf_cdiv(b[0],a[0]); v[0] = sf_cdiv(v[0],a[0]); #endif for(i=1;i<n;i++) { #ifdef SF_HAS_COMPLEX_H a[i] -= c[i-1]*b[i-1]; if(i<n-1) b[i]/=a[i]; v[i]=( v[i]-c[i-1]*v[i-1] ) / a[i]; #else a[i] = sf_csub(a[i],sf_cmul(c[i-1],b[i-1])); if(i<n-1) b[i] = sf_cdiv(b[i],a[i]); v[i]=sf_cdiv(sf_csub(v[i],sf_cmul(c[i-1],v[i-1])),a[i]); #endif } for(i=n-2;i>=0;i--) { #ifdef SF_HAS_COMPLEX_H v[i] -= b[i]*v[i+1]; #else v[i] = sf_csub(v[i],sf_cmul(b[i],v[i+1])); #endif } }
kiss_fft_cpx sf_catanf(kiss_fft_cpx z) /*< complex arctangent >*/ { kiss_fft_cpx z2; z2.r = -z.r; z2.i = 1.0-z.i; z.i += 1.0; z2 = sf_clogf(sf_cdiv(z,z2)); z.r = -0.5*z2.i; z.i = 0.5*z2.r; /* signs? */ return z; }
void RytovSensitivity(float xx,float xy,float xz,float *output) /*< Rytov sensitivity >*/ { int iw; double omega,scale; sf_complex U,dU; sf_complex val; *output=0.; for (iw=0; iw<nw; iw++) { omega=ow+dw*iw; scale =cos((SF_PI/2)*(((double) iw+1)/((double) nw+1))); scale*=scale; #ifdef SF_HAS_COMPLEX_H /* background field */ U=Green(rx,ry,rz,sx,sy,sz,omega)*scale; /* scattered field */ val=Green(xx,xy,xz,sx,sy,sz,omega)*scale; val*=Green(rx,ry,rz,xx,xy,xz,omega); dU=val*(-omega*omega*dv); val=U*omega; *output -= scale*cimagf(dU/U); #else /* background field */ U=sf_crmul(Green(rx,ry,rz,sx,sy,sz,omega),scale); /* scattered field */ val=sf_crmul(Green(xx,xy,xz,sx,sy,sz,omega),scale); val=sf_cmul(val,Green(rx,ry,rz,xx,xy,xz,omega)); dU=sf_crmul(val,-omega*omega*dv); val=sf_crmul(U,omega); *output -= scale*cimagf(sf_cdiv(dU,U)); #endif } return; }
int propnewc(sf_complex **ini, sf_complex **lt, sf_complex **rt, int nz, int nx, int nt, int m2, int nkzx, char *mode, int pad1, int snap, sf_complex **cc, sf_complex ***wvfld, bool verb, bool correct, sf_complex *alpha, sf_complex *beta) /*^*/ { /* index variables */ int it,iz,ix,im,ik,i,j,wfit; int nz2,nx2,nk,nzx2; sf_complex c; /* wavefield */ sf_complex **wave,**wave2, *curr, *currm, *cwave, *cwavem, *curr1, *curr2; nk = cfft2_init(pad1,nz,nx,&nz2,&nx2); nzx2 = nz2*nx2; if (nk!=nkzx) sf_error("nk discrepancy!"); curr = sf_complexalloc(nzx2); if (correct) { curr1 = sf_complexalloc(nzx2); curr2 = sf_complexalloc(nzx2); } currm = sf_complexalloc(nzx2); cwave = sf_complexalloc(nk); cwavem = sf_complexalloc(nk); wave = sf_complexalloc2(nk,m2); wave2 = sf_complexalloc2(nzx2,m2); icfft2_allocate(cwavem); /* initialization */ for (ix = 0; ix < nx2; ix++) { for (iz=0; iz < nz2; iz++) { j = iz+ix*nz2; if (ix<nx && iz<nz) curr[j] = ini[ix][iz]; else curr[j] = sf_cmplx(0.,0.); } } wfit = 0; /* MAIN LOOP */ for (it=0; it<nt; it++) { if(verb) sf_warning("it=%d;",it); /* outout wavefield */ if(snap>0) { if(it%snap==0 && wfit<=(int)(nt-1)/snap) { for (ix=0; ix<nx; ix++) for (iz=0; iz<nz; iz++) wvfld[wfit][ix][iz] = curr[iz+ix*nz2]; wfit++; } } if (mode[0]=='m') { /* matrix multiplication */ for (im = 0; im < m2; im++) { for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ #ifdef SF_HAS_COMPLEX_H currm[j] = lt[im][i]*curr[j]; #else currm[j] = sf_cmul(lt[im][i], curr[j]); #endif } } cfft2(currm,wave[im]); } for (ik = 0; ik < nk; ik++) { c = sf_cmplx(0.,0.); for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += wave[im][ik]*rt[ik][im]; #else c += sf_cmul(wave[im][ik],rt[ik][im]); //complex multiplies complex #endif } cwave[ik] = c; } /* matrix multiplication */ for (im = 0; im < m2; im++) { for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]*rt[ik][im]; #else cwavem[ik] = sf_cmul(cwave[ik],rt[ik][im]); //complex multiplies complex #endif } icfft2(wave2[im],cwavem); } for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ c = sf_cmplx(0.,0.); for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += lt[im][i]*wave2[im][j]; #else c += sf_cmul(lt[im][i], wave2[im][j]); #endif } curr[j] = c; } } if (correct) { for (ix = 0; ix < nx2; ix++) { for (iz=0; iz < nz2; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ if (ix<nx && iz<nz) { #ifdef SF_HAS_COMPLEX_H currm[j] = curr[j]/alpha[i]; #else currm[j] = sf_cdiv(curr[j],alpha[i]); #endif } else { currm[j] = sf_cmplx(0.,0.); } } } cfft2(currm,cwave); for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]/beta[ik]; #else cwavem[ik] = sf_cdiv(cwave[ik],beta[ik]); #endif } icfft2(curr1,cwavem); for (ix = nx; ix < nx2; ix++) { for (iz=nz; iz < nz2; iz++) { j = iz+ix*nz2; /* padded grid */ curr1[j] = sf_cmplx(0.,0.); } } /**/ cfft2(curr,cwave); for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]/conjf(beta[ik]); #else cwavem[ik] = sf_cdiv(cwave[ik],conjf(beta[ik])); #endif } icfft2(curr,cwavem); for (ix = 0; ix < nx2; ix++) { for (iz=0; iz < nz2; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ if (ix<nx && iz<nz) { #ifdef SF_HAS_COMPLEX_H curr2[j] = curr[j]/conjf(alpha[i]); #else curr2[j] = sf_cdiv(curr[j],conjf(alpha[i])); #endif } else { curr2[j] = sf_cmplx(0.,0.); } } } for (ix = 0; ix < nx2; ix++) { for (iz=0; iz < nz2; iz++) { j = iz+ix*nz2; /* padded grid */ #ifdef SF_HAS_COMPLEX_H curr[j] = (curr1[j] + curr2[j])/2.; #else curr[j] = sf_crmul(curr1[j]+curr2[j],0.5); #endif } } } } else if (mode[0]=='x') { cfft2(curr,cwave); /* matrix multiplication */ for (im = 0; im < m2; im++) { for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]*rt[ik][im]; #else cwavem[ik] = sf_cmul(cwave[ik],rt[ik][im]); //complex multiplies complex #endif } icfft2(wave2[im],cwavem); } for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ c = sf_cmplx(0.,0.); for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += lt[im][i]*wave2[im][j]; #else c += sf_cmul(lt[im][i], wave2[im][j]); #endif } curr[j] = c; } } /* matrix multiplication */ for (im = 0; im < m2; im++) { for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ #ifdef SF_HAS_COMPLEX_H currm[j] = lt[im][i]*curr[j]; #else currm[j] = sf_cmul(lt[im][i], curr[j]); #endif } } cfft2(currm,wave[im]); } for (ik = 0; ik < nk; ik++) { c = sf_cmplx(0.,0.); for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += wave[im][ik]*rt[ik][im]; #else c += sf_cmul(wave[im][ik],rt[ik][im]); //complex multiplies complex #endif } cwavem[ik] = c; } icfft2(curr,cwavem); if (correct) { for (ix = 0; ix < nx2; ix++) { for (iz=0; iz < nz2; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ if (ix<nx && iz<nz) { #ifdef SF_HAS_COMPLEX_H currm[j] = curr[j]/alpha[i]; #else currm[j] = sf_cdiv(curr[j],alpha[i]); #endif } else { currm[j] = sf_cmplx(0.,0.); } } } cfft2(currm,cwave); for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]/beta[ik]; #else cwavem[ik] = sf_cdiv(cwave[ik],beta[ik]); #endif } icfft2(curr,cwavem); for (ix = nx; ix < nx2; ix++) { for (iz=nz; iz < nz2; iz++) { j = iz+ix*nz2; /* padded grid */ curr[j] = sf_cmplx(0.,0.); } } } } else if (mode[0]=='n') { /* matrix multiplication */ for (im = 0; im < m2; im++) { for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ #ifdef SF_HAS_COMPLEX_H currm[j] = lt[im][i]*curr[j]; #else currm[j] = sf_cmul(lt[im][i], curr[j]); #endif } } cfft2(currm,wave[im]); } for (ik = 0; ik < nk; ik++) { c = sf_cmplx(0.,0.); for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += wave[im][ik]*rt[ik][im]; #else c += sf_cmul(wave[im][ik],rt[ik][im]); //complex multiplies complex #endif } cwavem[ik] = c; } icfft2(curr,cwavem); /* matrix multiplication */ for (im = 0; im < m2; im++) { for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ #ifdef SF_HAS_COMPLEX_H currm[j] = lt[im][i]*curr[j]; #else currm[j] = sf_cmul(lt[im][i], curr[j]); #endif } } cfft2(currm,wave[im]); } for (ik = 0; ik < nk; ik++) { c = sf_cmplx(0.,0.); for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += wave[im][ik]*rt[ik][im]; #else c += sf_cmul(wave[im][ik],rt[ik][im]); //complex multiplies complex #endif } cwavem[ik] = c; } icfft2(curr,cwavem); } else if (mode[0]=='p') { cfft2(curr,cwave); /* matrix multiplication */ for (im = 0; im < m2; im++) { for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]*rt[ik][im]; #else cwavem[ik] = sf_cmul(cwave[ik],rt[ik][im]); //complex multiplies complex #endif } icfft2(wave2[im],cwavem); } for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ c = sf_cmplx(0.,0.); for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += lt[im][i]*wave2[im][j]; #else c += sf_cmul(lt[im][i], wave2[im][j]); #endif } curr[j] = c; } } cfft2(curr,cwave); /* matrix multiplication */ for (im = 0; im < m2; im++) { for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]*rt[ik][im]; #else cwavem[ik] = sf_cmul(cwave[ik],rt[ik][im]); //complex multiplies complex #endif } icfft2(wave2[im],cwavem); } for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ c = sf_cmplx(0.,0.); for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += lt[im][i]*wave2[im][j]; #else c += sf_cmul(lt[im][i], wave2[im][j]); #endif } curr[j] = c; } } } else sf_error("Check mode parameter!"); } /* time stepping */ if(verb) sf_warning("."); /* output final result*/ for (ix=0; ix<nx; ix++) for (iz=0; iz<nz; iz++) cc[ix][iz] = curr[iz+ix*nz2]; cfft2_finalize(); return 0; }
int main (int argc, char* argv[]) { bool opt, comp, phase, verb; double n1; float nw1, b, a, dw, pi; int nt, nw, i, j, N, m1, M, k, f; float *TDEx,*TDEy,*TDHx,*TDHy,*outp,*ExHyres,*EyHxres,*ExHypha,*EyHxpha; float *bb, *pp, *qq, *dd; sf_file in, out, Ey, Hx, Hy; kiss_fft_cpx *FDEx=NULL,*FDEy=NULL,*FDHx=NULL,*FDHy=NULL; kiss_fft_cpx *A=NULL,*B=NULL,*ExAs1=NULL,*HyBs1=NULL,*ExBs1=NULL; kiss_fft_cpx *HyAs1=NULL,*HxAs1=NULL,*HxBs1=NULL; kiss_fft_cpx *EyAs1=NULL,*EyBs1=NULL,*ExAs2=NULL; kiss_fft_cpx *HyBs2=NULL,*ExBs2=NULL,*HyAs2=NULL,*HxAs2=NULL; kiss_fft_cpx *HxBs2=NULL,*EyAs2=NULL,*EyBs2=NULL,*ExAs3=NULL; kiss_fft_cpx *HyBs3=NULL,*ExBs3=NULL,*HyAs3=NULL,*HxAs3=NULL; kiss_fft_cpx *HxBs3=NULL,*EyAs3=NULL,*EyBs3=NULL,*ExAs4=NULL; kiss_fft_cpx *HyBs4=NULL,*ExBs4=NULL,*HyAs4=NULL,*HxAs4=NULL; kiss_fft_cpx *HxBs4=NULL,*EyAs4=NULL,*EyBs4=NULL,*ExA1=NULL; kiss_fft_cpx *HyB1=NULL,*ExB1=NULL,*HyA1=NULL,*HxA1=NULL,*HxB1=NULL; kiss_fft_cpx *EyA1=NULL,*EyB1=NULL,*ExA2=NULL,*HyB2=NULL,*ExB2=NULL; kiss_fft_cpx *HyA2=NULL,*HxA2=NULL,*HxB2=NULL,*EyA2=NULL,*EyB2=NULL; kiss_fft_cpx *ExA3=NULL,*HyB3=NULL,*ExB3=NULL,*HyA3=NULL,*HxA3=NULL; kiss_fft_cpx *HxB3=NULL,*EyA3=NULL,*EyB3=NULL,*ExA4=NULL,*HyB4=NULL; kiss_fft_cpx *ExB4=NULL,*HyA4=NULL,*HxA4=NULL,*HxB4=NULL,*EyA4=NULL; kiss_fft_cpx *EyB4=NULL,*Zxys1=NULL,*Zyxs1=NULL,*Zxys2=NULL,*Zyxs2=NULL; kiss_fft_cpx *Zxys3=NULL,*Zyxs3=NULL,*Zxys4=NULL,*Zyxs4=NULL; kiss_fft_cpx *Zxy=NULL,*Zyx=NULL; kiss_fftr_cfg cfg; sf_init (argc, argv); in= sf_input("in"); Ey=sf_input("Ey"); Hx=sf_input("Hx"); Hy=sf_input("Hy"); out = sf_output("out"); if (!sf_getbool("opt",&opt)) opt=true; /* if y, determine optimal size for efficiency */ if (!sf_getbool("comp",&comp)) comp=true; /* component selection */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ if (!sf_getbool("phase",&phase)) phase=false; /* if y, calculate apparent resistivity, otherwise calculate phase */ if (!sf_histdouble(in,"n1",&n1)) sf_error("No n1= in input"); bb= sf_floatalloc(n1); pp= sf_floatalloc(n1); qq= sf_floatalloc(n1); dd= sf_floatalloc(n1); sf_floatread(bb,n1,in); sf_floatread(pp,n1,Ey); sf_floatread(qq,n1,Hx); sf_floatread(dd,n1,Hy); M=49; outp =sf_floatalloc(M); pi=3.14; f=1; b=-3; for(k=0;k<M;k++) { a=pow(10,b); nw=(int)(128000./(a*1000)); nt = opt? 2*kiss_fft_next_fast_size((nw+1)/2): nw; if (nt%2) nt++; nw1 = nt/2+1; dw = 128./nt; m1=n1; if(m1%nw) N=m1/nw+1; else N=m1/nw; if(verb) sf_warning("slice %d of %d, freq=%f, stack=%d;",k+1,M,a,N); FDEx= (kiss_fft_cpx*)sf_complexalloc(nt); FDEy= (kiss_fft_cpx*)sf_complexalloc(nt); FDHx= (kiss_fft_cpx*)sf_complexalloc(nt); FDHy= (kiss_fft_cpx*)sf_complexalloc(nt); TDEx= sf_floatalloc(nt); TDEy= sf_floatalloc(nt); TDHx= sf_floatalloc(nt); TDHy= sf_floatalloc(nt); sf_putint(out,"n1",M); sf_putfloat(out,"d1",0.1); sf_putfloat(out,"o1",-3); ExAs1=(kiss_fft_cpx*)sf_complexalloc(nt); HyBs1=(kiss_fft_cpx*)sf_complexalloc(nt); ExBs1=(kiss_fft_cpx*)sf_complexalloc(nt); HyAs1=(kiss_fft_cpx*)sf_complexalloc(nt); HxAs1=(kiss_fft_cpx*)sf_complexalloc(nt); HxBs1=(kiss_fft_cpx*)sf_complexalloc(nt); EyAs1=(kiss_fft_cpx*)sf_complexalloc(nt); EyBs1=(kiss_fft_cpx*)sf_complexalloc(nt); ExAs2=(kiss_fft_cpx*)sf_complexalloc(nt); HyBs2=(kiss_fft_cpx*)sf_complexalloc(nt); ExBs2=(kiss_fft_cpx*)sf_complexalloc(nt); HyAs2=(kiss_fft_cpx*)sf_complexalloc(nt); HxAs2=(kiss_fft_cpx*)sf_complexalloc(nt); HxBs2=(kiss_fft_cpx*)sf_complexalloc(nt); EyAs2=(kiss_fft_cpx*)sf_complexalloc(nt); EyBs2=(kiss_fft_cpx*)sf_complexalloc(nt); ExAs3=(kiss_fft_cpx*)sf_complexalloc(nt); HyBs3=(kiss_fft_cpx*)sf_complexalloc(nt); ExBs3=(kiss_fft_cpx*)sf_complexalloc(nt); HyAs3=(kiss_fft_cpx*)sf_complexalloc(nt); HxAs3=(kiss_fft_cpx*)sf_complexalloc(nt); HxBs3=(kiss_fft_cpx*)sf_complexalloc(nt); EyAs3=(kiss_fft_cpx*)sf_complexalloc(nt); EyBs3=(kiss_fft_cpx*)sf_complexalloc(nt); ExAs4=(kiss_fft_cpx*)sf_complexalloc(nt); HyBs4=(kiss_fft_cpx*)sf_complexalloc(nt); ExBs4=(kiss_fft_cpx*)sf_complexalloc(nt); HyAs4=(kiss_fft_cpx*)sf_complexalloc(nt); HxAs4=(kiss_fft_cpx*)sf_complexalloc(nt); HxBs4=(kiss_fft_cpx*)sf_complexalloc(nt); EyAs4=(kiss_fft_cpx*)sf_complexalloc(nt); EyBs4=(kiss_fft_cpx*)sf_complexalloc(nt); ExA1=(kiss_fft_cpx*)sf_complexalloc(nt); HyB1=(kiss_fft_cpx*)sf_complexalloc(nt); ExB1=(kiss_fft_cpx*)sf_complexalloc(nt); HyA1=(kiss_fft_cpx*)sf_complexalloc(nt); HxA1=(kiss_fft_cpx*)sf_complexalloc(nt); HxB1=(kiss_fft_cpx*)sf_complexalloc(nt); EyA1=(kiss_fft_cpx*)sf_complexalloc(nt); EyB1=(kiss_fft_cpx*)sf_complexalloc(nt); ExA2=(kiss_fft_cpx*)sf_complexalloc(nt); HyB2=(kiss_fft_cpx*)sf_complexalloc(nt); ExB2=(kiss_fft_cpx*)sf_complexalloc(nt); HyA2=(kiss_fft_cpx*)sf_complexalloc(nt); HxA2=(kiss_fft_cpx*)sf_complexalloc(nt); HxB2=(kiss_fft_cpx*)sf_complexalloc(nt); EyA2=(kiss_fft_cpx*)sf_complexalloc(nt); EyB2=(kiss_fft_cpx*)sf_complexalloc(nt); ExA3=(kiss_fft_cpx*)sf_complexalloc(nt); HyB3=(kiss_fft_cpx*)sf_complexalloc(nt); ExB3=(kiss_fft_cpx*)sf_complexalloc(nt); HyA3=(kiss_fft_cpx*)sf_complexalloc(nt); HxA3=(kiss_fft_cpx*)sf_complexalloc(nt); HxB3=(kiss_fft_cpx*)sf_complexalloc(nt); EyA3=(kiss_fft_cpx*)sf_complexalloc(nt); EyB3=(kiss_fft_cpx*)sf_complexalloc(nt); ExA4=(kiss_fft_cpx*)sf_complexalloc(nt); HyB4=(kiss_fft_cpx*)sf_complexalloc(nt); ExB4=(kiss_fft_cpx*)sf_complexalloc(nt); HyA4=(kiss_fft_cpx*)sf_complexalloc(nt); HxA4=(kiss_fft_cpx*)sf_complexalloc(nt); HxB4=(kiss_fft_cpx*)sf_complexalloc(nt); EyA4=(kiss_fft_cpx*)sf_complexalloc(nt); EyB4=(kiss_fft_cpx*)sf_complexalloc(nt); Zxys1=(kiss_fft_cpx*)sf_complexalloc(nt); Zyxs1=(kiss_fft_cpx*)sf_complexalloc(nt); Zxys2=(kiss_fft_cpx*)sf_complexalloc(nt); Zyxs2=(kiss_fft_cpx*)sf_complexalloc(nt); Zxys3=(kiss_fft_cpx*)sf_complexalloc(nt); Zyxs3=(kiss_fft_cpx*)sf_complexalloc(nt); Zxys4=(kiss_fft_cpx*)sf_complexalloc(nt); Zyxs4=(kiss_fft_cpx*)sf_complexalloc(nt); Zxy=(kiss_fft_cpx*)sf_complexalloc(nt); Zyx=(kiss_fft_cpx*)sf_complexalloc(nt); ExHyres=sf_floatalloc(nt); EyHxres=sf_floatalloc(nt); ExHypha=sf_floatalloc(nt); EyHxpha=sf_floatalloc(nt); cfg = kiss_fftr_alloc(nt,0,NULL,NULL); for(j=0;j<N;j++) { for(i=0;i<nt;i++){ if((i<nw)&&((j*nw+i)<n1)) { TDEx[i]=bb[j*nw+i]*0.5*(1-cos(2*pi*i/nt)); } else { TDEx[i]=0.; } } kiss_fftr(cfg,TDEx,FDEx); for(i=0;i<nt;i++){ if((i<nw)&&((j*nw+i)<n1)) { TDEy[i]=pp[j*nw+i]*0.5*(1-cos(2*pi*i/nt)); } else{ TDEy[i]=0.; } } kiss_fftr(cfg,TDEy,FDEy); for(i=0;i<nt;i++){ if((i<nw)&&((j*nw+i)<n1)) { TDHx[i]=qq[j*nw+i]*0.5*(1-cos(2*pi*i/nt)); } else{TDHx[i]=0.;} } kiss_fftr(cfg,TDHx,FDHx); for(i=0;i<nt;i++){ if((i<nw)&&((j*nw+i)<n1)) { TDHy[i]=dd[j*nw+i]*0.5*(1-cos(2*pi*i/nt)); } else{ TDHy[i]=0.; } } kiss_fftr(cfg,TDHy,FDHy); A=FDEx;B=FDEy; ExAs1[f]=sf_cadd(ExAs1[f],sf_cmul(FDEx[f],sf_conjf(A[f]))); HyBs1[f]=sf_cadd(HyBs1[f],sf_cmul(FDHy[f],sf_conjf(B[f]))); ExBs1[f]=sf_cadd(ExBs1[f],sf_cmul(FDEx[f],sf_conjf(B[f]))); HyAs1[f]=sf_cadd(HyAs1[f],sf_cmul(FDHy[f],sf_conjf(A[f]))); HxAs1[f]=sf_cadd(HxAs1[f],sf_cmul(FDHx[f],sf_conjf(A[f]))); HxBs1[f]=sf_cadd(HxBs1[f],sf_cmul(FDHx[f],sf_conjf(B[f]))); EyAs1[f]=sf_cadd(EyAs1[f],sf_cmul(FDEy[f],sf_conjf(A[f]))); EyBs1[f]=sf_cadd(EyBs1[f],sf_cmul(FDEy[f],sf_conjf(B[f]))); A=FDEx;B=FDHx; ExAs2[f]= sf_cadd(ExAs2[f],sf_cmul(FDEx[f],sf_conjf(A[f]))); HyBs2[f]= sf_cadd(HyBs2[f],sf_cmul(FDHy[f],sf_conjf(B[f]))); ExBs2[f]= sf_cadd(ExBs2[f],sf_cmul(FDEx[f],sf_conjf(B[f]))); HyAs2[f]= sf_cadd(HyAs2[f],sf_cmul(FDHy[f],sf_conjf(A[f]))); HxAs2[f]= sf_cadd(HxAs2[f],sf_cmul(FDHx[f],sf_conjf(A[f]))); HxBs2[f]= sf_cadd(HxBs2[f],sf_cmul(FDHx[f],sf_conjf(B[f]))); EyAs2[f]= sf_cadd(EyAs2[f],sf_cmul(FDEy[f],sf_conjf(A[f]))); EyBs2[f]= sf_cadd(EyBs2[f],sf_cmul(FDEy[f],sf_conjf(B[f]))); A=FDEy;B=FDHy; ExAs3[f]= sf_cadd(ExAs3[f],sf_cmul(FDEx[f],sf_conjf(A[f]))); HyBs3[f]= sf_cadd(HyBs3[f],sf_cmul(FDHy[f],sf_conjf(B[f]))); ExBs3[f]= sf_cadd(ExBs3[f],sf_cmul(FDEx[f],sf_conjf(B[f]))); HyAs3[f]= sf_cadd(HyAs3[f],sf_cmul(FDHy[f],sf_conjf(A[f]))); HxAs3[f]= sf_cadd(HxAs3[f],sf_cmul(FDHx[f],sf_conjf(A[f]))); HxBs3[f]= sf_cadd(HxBs3[f],sf_cmul(FDHx[f],sf_conjf(B[f]))); EyAs3[f]= sf_cadd(EyAs3[f],sf_cmul(FDEy[f],sf_conjf(A[f]))); EyBs3[f]= sf_cadd(EyBs3[f],sf_cmul(FDEy[f],sf_conjf(B[f]))); A=FDHx;B=FDHy; ExAs4[f]= sf_cadd(ExAs4[f],sf_cmul(FDEx[f],sf_conjf(A[f]))); HyBs4[f]= sf_cadd(HyBs4[f],sf_cmul(FDHy[f],sf_conjf(B[f]))); ExBs4[f]= sf_cadd(ExBs4[f],sf_cmul(FDEx[f],sf_conjf(B[f]))); HyAs4[f]= sf_cadd(HyAs4[f],sf_cmul(FDHy[f],sf_conjf(A[f]))); HxAs4[f]= sf_cadd(HxAs4[f],sf_cmul(FDHx[f],sf_conjf(A[f]))); HxBs4[f]= sf_cadd(HxBs4[f],sf_cmul(FDHx[f],sf_conjf(B[f]))); EyAs4[f]= sf_cadd(EyAs4[f],sf_cmul(FDEy[f],sf_conjf(A[f]))); EyBs4[f]= sf_cadd(EyBs4[f],sf_cmul(FDEy[f],sf_conjf(B[f]))); } ExA1[f]=sf_crmul(ExAs1[f],1./N); HyB1[f]=sf_crmul(HyBs1[f],1./N); ExB1[f]=sf_crmul(ExBs1[f],1./N); HyA1[f]=sf_crmul(HyAs1[f],1./N); HxA1[f]=sf_crmul(HxAs1[f],1./N); HxB1[f]=sf_crmul(HxBs1[f],1./N); EyA1[f]=sf_crmul(EyAs1[f],1./N); EyB1[f]=sf_crmul(EyBs1[f],1./N); ExA2[f]=sf_crmul(ExAs2[f],1./N); HyB2[f]=sf_crmul(HyBs2[f],1./N); ExB2[f]=sf_crmul(ExBs2[f],1./N); HyA2[f]=sf_crmul(HyAs2[f],1./N); HxA2[f]=sf_crmul(HxAs2[f],1./N); HxB2[f]=sf_crmul(HxBs2[f],1./N); EyA2[f]=sf_crmul(EyAs2[f],1./N); EyB2[f]=sf_crmul(EyBs2[f],1./N); ExA3[f]=sf_crmul(ExAs3[f],1./N); HyB3[f]=sf_crmul(HyBs3[f],1./N); ExB3[f]=sf_crmul(ExBs3[f],1./N); HyA3[f]=sf_crmul(HyAs3[f],1./N); HxA3[f]=sf_crmul(HxAs3[f],1./N); HxB3[f]=sf_crmul(HxBs3[f],1./N); EyA3[f]=sf_crmul(EyAs3[f],1./N); EyB3[f]=sf_crmul(EyBs3[f],1./N); ExA4[f]=sf_crmul(ExAs4[f],1./N); HyB4[f]=sf_crmul(HyBs4[f],1./N); ExB4[f]=sf_crmul(ExBs4[f],1./N); HyA4[f]=sf_crmul(HyAs4[f],1./N); HxA4[f]=sf_crmul(HxAs4[f],1./N); HxB4[f]=sf_crmul(HxBs4[f],1./N); EyA4[f]=sf_crmul(EyAs4[f],1./N); EyB4[f]=sf_crmul(EyBs4[f],1./N); Zxys1[f]=sf_cdiv((sf_csub(sf_cmul(ExA1[f],HxB1[f]), sf_cmul(ExB1[f],HxA1[f]))), (sf_csub(sf_cmul(HyA1[f],HxB1[f]), sf_cmul(HyB1[f],HxA1[f])))); Zyxs1[f]=sf_cdiv((sf_csub(sf_cmul(EyA1[f],HyB1[f]), sf_cmul(EyB1[f],HyA1[f]))), (sf_csub(sf_cmul(HxA1[f],HyB1[f]), sf_cmul(HxB1[f],HyA1[f])))); Zxys2[f]=sf_cdiv((sf_csub(sf_cmul(ExA2[f],HxB2[f]), sf_cmul(ExB2[f],HxA2[f]))), (sf_csub(sf_cmul(HyA2[f],HxB2[f]), sf_cmul(HyB2[f],HxA2[f])))); Zyxs2[f]=sf_cdiv((sf_csub(sf_cmul(EyA2[f],HyB2[f]), sf_cmul(EyB2[f],HyA2[f]))), (sf_csub(sf_cmul(HxA2[f],HyB2[f]), sf_cmul(HxB2[f],HyA2[f])))); Zxys3[f]=sf_cdiv((sf_csub(sf_cmul(ExA3[f],HxB3[f]), sf_cmul(ExB3[f],HxA3[f]))), (sf_csub(sf_cmul(HyA3[f],HxB3[f]), sf_cmul(HyB3[f],HxA3[f])))); Zyxs3[f]=sf_cdiv((sf_csub(sf_cmul(EyA3[f],HyB3[f]), sf_cmul(EyB3[f],HyA3[f]))), (sf_csub(sf_cmul(HxA3[f],HyB3[f]), sf_cmul(HxB3[f],HyA3[f])))); Zxys4[f]=sf_cdiv((sf_csub(sf_cmul(ExA4[f],HxB4[f]), sf_cmul(ExB4[f],HxA4[f]))), (sf_csub(sf_cmul(HyA4[f],HxB4[f]), sf_cmul(HyB4[f],HxA4[f])))); Zyxs4[f]=sf_cdiv((sf_csub(sf_cmul(EyA4[f],HyB4[f]), sf_cmul(EyB4[f],HyA4[f]))), (sf_csub(sf_cmul(HxA4[f],HyB4[f]), sf_cmul(HxB4[f],HyA4[f])))); Zxy[f]=sf_crmul(sf_cadd(sf_cadd(Zxys1[f],Zxys2[f]), sf_cadd(Zxys3[f],Zxys4[f])),0.25); Zyx[f]=sf_crmul(sf_cadd(sf_cadd(Zyxs1[f],Zyxs2[f]), sf_cadd(Zyxs3[f],Zyxs4[f])),0.25); ExHyres[f]=0.2*sf_cabsf(Zxy[f])*sf_cabsf(Zxy[f])/a; EyHxres[f]=0.2*sf_cabsf(Zyx[f])*sf_cabsf(Zyx[f])/a; ExHypha[f]=sf_cargf(Zxy[f]); EyHxpha[f]=sf_cargf(Zyx[f]); if(phase) { if(comp) { outp[k]= ExHypha[f]; } else { outp[k]= EyHxpha[f]; } } else { if(comp) { outp[k]= ExHyres[f]; } else { outp[k]= EyHxres[f]; } } b=b+0.1; } sf_floatwrite(outp,M,out); exit(0); }
int main(int argc, char* argv[]) { int dim, n[SF_MAX_DIM], i, j, s; float **der, **vel; float o[SF_MAX_DIM], d[SF_MAX_DIM], t0, shift, source, *t, dist; char key[6]; sf_complex *P, *Q, **beam; sf_file in, deriv, out; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); /* read input dimension */ dim = sf_filedims(in,n); if (dim > 2) sf_error("Only works for 2D."); for (i=0; i < dim; i++) { sprintf(key,"d%d",i+1); if (!sf_histfloat(in,key,d+i)) sf_error("No %s= in input.",key); sprintf(key,"o%d",i+1); if (!sf_histfloat(in,key,o+i)) o[i]=0.; } if (!sf_getfloat("t0",&t0)) t0=0.; /* time origin at source */ if (!sf_getfloat("shift",&shift)) shift=1.; /* complex source shift */ if (!sf_getfloat("source",&source)) source=o[1]+(n[1]-1)/2*d[1]; /* source location */ /* project source to grid point */ s = (source-o[1])/d[1]; /* read velocity model */ vel = sf_floatalloc2(n[0],n[1]); sf_floatread(vel[0],n[0]*n[1],in); /* read derivative file */ der = sf_floatalloc2(n[0],n[1]); if (NULL != sf_getstring("deriv")) { deriv = sf_input("deriv"); sf_floatread(der[0],n[0]*n[1],deriv); sf_fileclose(deriv); } else { deriv = NULL; /* use finite difference for derivative if available */ if (0 < s && s < n[1]-1) { for (i=0; i < n[0]; i++) der[s][i] = (vel[s+1][i]-2*vel[s][i]+vel[s-1][i])/(d[1]*d[1]); } else { for (i=0; i < n[0]; i++) der[s][i] = 0.; } } /* write output header */ sf_settype(out,SF_COMPLEX); /* allocate memory for temporary data */ t = sf_floatalloc(n[0]); P = sf_complexalloc(n[0]); Q = sf_complexalloc(n[0]); beam = sf_complexalloc2(n[0],n[1]); /* complex source initial condition */ t[0] = 0.; P[0] = sf_cmplx(0.,1./vel[s][0]); Q[0] = sf_cmplx(shift,0.); /* dynamic ray tracing along central ray (4th order Runge-Kutta) */ for (i=1; i<n[0]; i++) { t[i] = t[i-1]+d[0]/2./vel[s][i-1]+d[0]/(vel[s][i-1]+vel[s][i]); #ifdef SF_HAS_COMPLEX_H Q[i] = (P[i-1]-der[s][i-1]*Q[i-1]*d[0]/(vel[s][i-1]*vel[s][i-1]*4)) *vel[s][i-1]*d[0]+Q[i-1]; P[i] = -((1.5*der[s][i-1]+0.5*der[s][i])*Q[i-1]+(der[s][i-1]+der[s][i])/2*vel[s][i-1]*d[0]/2*P[i-1]) *d[0]/(vel[s][i-1]*vel[s][i-1]*2)+P[i-1]; #else Q[i] = sf_cadd(sf_crmul(sf_cadd(P[i-1],sf_crmul(Q[i-1],-der[s][i-1]*d[0]/(vel[s][i-1]*vel[s][i-1]*4))) ,vel[s][i-1]*d[0]),Q[i-1]); P[i] = sf_cadd(sf_crmul(sf_cadd(sf_crmul(Q[i-1],-((1.5*der[s][i-1]+0.5*der[s][i]))), sf_crmul(P[i-1],(der[s][i-1]+der[s][i])/2*vel[s][i-1]*d[0]/2)),d[0]/(vel[s][i-1]*vel[s][i-1]*2)),P[i-1]); #endif } /* Gaussian beam */ for (j=0; j<n[1]; j++) { dist = (j-s)*d[1]; for (i=0; i<n[0]; i++) { #ifdef SF_HAS_COMPLEX_H beam[j][i] = t0+t[i]+0.5*dist*dist*P[i]/Q[i]; #else beam[j][i] = sf_cadd(sf_cmplx(t0+t[i],0.),sf_crmul(sf_cdiv(P[i],Q[i]),0.5*dist*dist)); #endif } } sf_complexwrite(beam[0],n[0]*n[1],out); exit(0); }
int main(int argc, char* argv[]) { bool verb; char *sort; int j, k, n, m, i2, n2, niter, *map; sf_complex **a, *e, *old; float tol, dist, dk; sf_file poly, root; sf_init(argc,argv); poly = sf_input("in"); root = sf_output("out"); if (SF_COMPLEX != sf_gettype(poly)) sf_error("Need complex input"); if (!sf_histint(poly,"n1",&n)) sf_error("No n1= in input"); n2 = sf_leftsize(poly,1); if (!sf_getint("niter",&niter)) niter=10; /* number of iterations */ if (!sf_getfloat("tol",&tol)) tol=1.0e-6; /* tolerance for convergence */ if (!sf_getbool("verb",&verb)) verb=true; /* verbosity flag */ if (NULL == (sort = sf_getstring("sort"))) sort="real"; /* attribute for sorting (phase,amplitude,real,imaginary) */ switch (sort[0]) { case 'p': func = cargf; break; case 'a': func = cabsf; break; case 'i': func = cimagf; break; case 'r': default: func = crealf; break; } sf_putint(root,"n1",n-1); a = sf_complexalloc2(n,n); e = sf_complexalloc(n); old = sf_complexalloc(n-1); map = sf_intalloc(n-1); ceig_init(verb,n); for (i2=0; i2 < n2; i2++) { sf_complexread(e,n,poly); for (m = n; m > 0; m--) { if (cabsf(e[m-1]) > FLT_EPSILON) break; } m--; for (j=0; j < m; j++) { for (k=0; k < m; k++) { a[j][k] = sf_cmplx(0.,0.); } } for (j=0; j < m-1; j++) { a[j][j+1]=sf_cmplx(1.,0.); } for (j=0; j < m; j++) { #ifdef SF_HAS_COMPLEX_H a[m-1][j]=-e[j]/e[m]; #else a[m-1][j]=sf_cneg(sf_cdiv(e[j],e[m])); #endif } ceig(niter,tol,m,a,e); if (0==i2) { /* sort the first set of roots */ qsort(e,n-1,sizeof(sf_complex),compare); for (j=0; j < n-1; j++) { old[j]=e[j]; } } else { /* find nearest to previous */ for (j=0; j < n-1; j++) { map[j] = -1; } /* loop through old roots */ for (j=0; j < n-1; j++) { dist = SF_HUGE; /* find nearest not taken */ for (k=0; k < n-1; k++) { if (map[k] >= 0) continue; /* Euclidean distance */ #ifdef SF_HAS_COMPLEX_H dk = cabsf(old[j]-e[k]); #else dk = cabsf(sf_cadd(old[j],sf_crmul(e[k],-1.0))); #endif if (dk < dist) { m = k; dist = dk; } } map[m] = j; old[j] = e[m]; } } sf_complexwrite(old,n-1, root); } exit(0); }
int main(int argc, char* argv[]) { int nw,nh,nx, iw,ix,ih, k; float dw, h0,dh,dx, w0,w,w2, h,h2; sf_complex diag, diag2, *in=NULL, *out=NULL, offd, offd2, c1, c2; bool all; ctris slv; sf_file input=NULL, output=NULL; sf_init (argc,argv); input = sf_input("in"); output = sf_output("out"); if (SF_COMPLEX != sf_gettype(input)) sf_error("Need complex input"); if (!sf_histint(input,"n1",&nx)) sf_error("No n1= in input"); if (!sf_histint(input,"n2",&nw)) sf_error("No n2= in input"); if (!sf_histfloat(input,"d1",&dx)) sf_error("No d1= in input"); if (!sf_histfloat(input,"d2",&dw)) sf_error("No d2= in input"); if (!sf_histfloat(input,"o2",&w0)) sf_error("No o2= in input"); if (!sf_getint("nh",&nh)) sf_error("Need nh="); /* Number of steps in offset */ if (!sf_getfloat("dh",&dh)) sf_error("Need dh="); /* Offset step size */ if (!sf_getfloat("h0",&h0)) sf_error("Need h0="); /* Initial offset */ if (!sf_getbool("all",&all)) all=false; /* if y, output all offsets */ if (all) { sf_putint(output,"n2",nh+1); sf_putfloat(output,"d2",dh); sf_putfloat(output,"o2",h0); sf_putint(output,"n3",nw); sf_putfloat(output,"d3",dw); sf_putfloat(output,"o3",w0); } dh /= dx; h0 /= dx; w0 *= 2.*SF_PI; dw *= 2.*SF_PI; in = sf_complexalloc(nx); out = sf_complexalloc(nx); slv = ctridiagonal_init (nx); for (iw=0; iw < nw; iw++) { sf_warning("frequency %d of %d;",iw+1,nw); w = w0+iw*dw; w2 = w*w; sf_complexread(out,nx,input); if (fabsf(w) < dw) { for (ix=0; ix < nx; ix++) { out[ix]=sf_cmplx(0.,0.); } if (all) { for (ih=0; ih < nh; ih++) { sf_complexwrite (out,nx,output); } } sf_complexwrite (out,nx,output); continue; } #ifdef SF_HAS_COMPLEX_H c1 = 3.*sf_cmplx(9. + w2,4.*w)/(w2*sf_cmplx(3.,- w)); c2 = 3.*sf_cmplx(w2 - 27.,8.*w)/(w2*sf_cmplx(3.,- w)); #else c1 = sf_cdiv(sf_cmplx(3.*(9. + w2),3.*4.*w), sf_cmplx(w2*3.,-w2*w)); c2 = sf_cdiv(sf_cmplx(3.*(w2 - 27.),3.*8.*w), sf_cmplx(w2*3.,-w2*w)); #endif for (ih=0; ih < nh; ih++) { if (all) sf_complexwrite (out,nx,output); for (ix=0; ix < nx; ix++) { in[ix] = out[ix]; } h = h0 + ih*dh; h2 = h+dh; h *= h; h2 *= h2; #ifdef SF_HAS_COMPLEX_H offd = 1. - c1*h2 + c2*h; offd2 = 1. - c1*h + c2*h2; diag = 12. - 2.*offd; diag2 = 12. - 2.*offd2; #else offd = sf_cadd(sf_cmplx(1.,0.), sf_cadd(sf_crmul(c1,-h2), sf_crmul(c2,h))); offd2 = sf_cadd(sf_cmplx(1.,0.), sf_cadd(sf_crmul(c1,-h), sf_crmul(c2,h2))); diag = sf_cadd(sf_cmplx(12.,0.),sf_crmul(offd,-2.)); diag2 = sf_cadd(sf_cmplx(12.,0.),sf_crmul(offd2,-2.)); #endif ctridiagonal_const_define (slv, diag2, offd2); #ifdef SF_HAS_COMPLEX_H out[0] = diag*in[0] + offd*in[1]; #else out[0] = sf_cadd(sf_cmul(diag,in[0]), sf_cmul(offd,in[1])); #endif for (k = 1; k < nx - 1; k++) { #ifdef SF_HAS_COMPLEX_H out[k] = diag*in[k] + offd*(in[k+1]+in[k-1]); #else out[k] = sf_cadd(sf_cmul(diag,in[k]), sf_cmul(offd,sf_cadd(in[k+1],in[k-1]))); #endif } #ifdef SF_HAS_COMPLEX_H out[nx-1] = diag*in[nx-1] + offd*in[nx-2]; #else out[nx-1] = sf_cadd(sf_cmul(diag,in[nx-1]), sf_cmul(offd,in[nx-2])); #endif ctridiagonal_solve (slv, out); } sf_complexwrite (out,nx,output); } sf_warning("."); exit(0); }
void ocpredict_step(bool adj /* adjoint flag */, bool forw /* forward or backward */, float dw, int nx, float w /* log-stretch frequency */, float h, float h2 /* offset position */, sf_complex *trace /* common offset slice */) /*< offset continuation prediction step >*/ { int ix, k; float w2; sf_complex diag, diag2, *in, offd, offd2, c1, c2; ctris slv; in = sf_complexalloc(nx); slv = ctridiagonal_init (nx); w2 = w*w; if (fabsf(w) < dw) { return; /* for (ix=0; ix < nx; ix++) { trace[ix]=sf_cmplx(0.,0.); } */ } #ifdef SF_HAS_COMPLEX_H c1 = 3.*sf_cmplx(9. + w2,4.*w)/(w2*sf_cmplx(3.,- w)); c2 = 3.*sf_cmplx(w2 - 27.,8.*w)/(w2*sf_cmplx(3.,- w)); #else c1 = sf_cdiv(sf_cmplx(3.*(9. + w2),3.*4.*w), sf_cmplx(w2*3.,-w2*w)); c2 = sf_cdiv(sf_cmplx(3.*(w2 - 27.),3.*8.*w), sf_cmplx(w2*3.,-w2*w)); #endif for (ix=0; ix < nx; ix++) { in[ix] = trace[ix]; } h *= h; h2 *= h2; if (forw) { #ifdef SF_HAS_COMPLEX_H offd = 1. - c1*h2 + c2*h; offd2 = 1. - c1*h + c2*h2; diag = 12. - 2.*offd; diag2 = 12. - 2.*offd2; #else offd = sf_cadd(sf_cmplx(1.,0.), sf_cadd(sf_crmul(c1,-h2), sf_crmul(c2,h))); offd2 = sf_cadd(sf_cmplx(1.,0.), sf_cadd(sf_crmul(c1,-h), sf_crmul(c2,h2))); diag = sf_cadd(sf_cmplx(12.,0.),sf_crmul(offd,-2.)); diag2 = sf_cadd(sf_cmplx(12.,0.),sf_crmul(offd2,-2.)); #endif } else { #ifdef SF_HAS_COMPLEX_H offd = 1. - c1*h + c2*h2; offd2 = 1. - c1*h2 + c2*h; diag = 12. - 2.*offd; diag2 = 12. - 2.*offd2; #else offd = sf_cadd(sf_cmplx(1.,0.), sf_cadd(sf_crmul(c1,-h), sf_crmul(c2,h2))); offd2 = sf_cadd(sf_cmplx(1.,0.), sf_cadd(sf_crmul(c1,-h2), sf_crmul(c2,h))); diag = sf_cadd(sf_cmplx(12.,0.),sf_crmul(offd,-2.)); diag2 = sf_cadd(sf_cmplx(12.,0.),sf_crmul(offd2,-2.)); #endif } ctridiagonal_const_define (slv, diag2, offd2); #ifdef SF_HAS_COMPLEX_H trace[0] = diag*in[0] + offd*in[1]; #else trace[0] = sf_cadd(sf_cmul(diag,in[0]), sf_cmul(offd,in[1])); #endif for (k = 1; k < nx - 1; k++) { #ifdef SF_HAS_COMPLEX_H trace[k] = diag*in[k] + offd*(in[k+1]+in[k-1]); #else trace[k] = sf_cadd(sf_cmul(diag,in[k]), sf_cmul(offd,sf_cadd(in[k+1],in[k-1]))); #endif } #ifdef SF_HAS_COMPLEX_H trace[nx-1] = diag*in[nx-1] + offd*in[nx-2]; #else trace[nx-1] = sf_cadd(sf_cmul(diag,in[nx-1]), sf_cmul(offd,in[nx-2])); #endif ctridiagonal_solve (slv, trace); }
kiss_fft_cpx sf_ctanf(kiss_fft_cpx z) /*< complex tangent >*/ { return sf_cdiv(sf_csinf(z),sf_ccosf(z)); }