示例#1
0
文件: Mshape.c 项目: 1014511134/src
int main(int argc, char* argv[])
{
    int i, dim, nm, niter, n[SF_MAX_DIM], rect[SF_MAX_DIM];
    char key[6];
    float *rough, *smooth, *limit, lsum, li;
    sf_file inp, out, lim;

    sf_init(argc,argv);
    inp = sf_input("in");
    out = sf_output("out");
    lim = sf_input("limit");
    /* limiter */

    if (SF_FLOAT != sf_gettype(inp) ||
	SF_FLOAT != sf_gettype(lim)) sf_error("Need float input");
    dim = sf_filedims (inp,n);

    nm = 1;
    for (i=0; i < dim; i++) {
		nm *= n[i];

		if (n[i] > 1) {
			snprintf(key,6,"rect%d",i+1);
			if (!sf_getint(key,rect+i)) rect[i]=1;
			/*( rect#=(1,1,...) smoothing radius on #-th axis )*/ 
		} else {
			rect[i]=1;
		}
    }

    if (!sf_getint("niter",&niter)) niter=100;
    /* number of iterations */
    
    sf_divn_init(dim,nm,n,rect,niter,true);
    
    rough = sf_floatalloc(nm);
    smooth = sf_floatalloc(nm);
    limit = sf_floatalloc(nm);

    sf_floatread(rough,nm,inp);
    sf_floatread(limit,nm,lim);

    lsum = 0.;
    for (i = 0; i < nm; i++) {
		li = limit[i];
		lsum += li*li;
    }
    lsum = sqrtf (lsum/nm);

    for (i=0; i < nm; i++) {
		limit[i] /= lsum;
		rough[i] *= limit[i];
    }
    
    sf_divn(rough,limit,smooth);

    sf_floatwrite(smooth,nm,out);

    exit(0);
}
示例#2
0
文件: fbdip.c 项目: 1014511134/src
void fbdip(int n3, int n4, float ****in, float **dip, int nit, float eta)
/*< omnidirectional dip estimation >*/
{
	int it, i1, j1, j2;
	double  norm, s1, c1;

	for(i1=0; i1<n1*n2; i1++)
		p[0][i1] = p0;

	for (it=0; it<nit; it++)
	{
		for(i1=0; i1<n1*n2; i1++)
		{
			s1 = cimagf(p[0][i1]);
			c1 = crealf(p[0][i1]);
			u1[0][i1] = 0.0;
			u2[0][i1] = 0.0;
			u3[0][i1] = 0.0;
			for(j2=0; j2<n4; j2++)
			for(j1=0; j1<n3; j1++)
			{
				if((j1+j2)%2==0) continue;
				u1[0][i1] += 2.0*in[j2][j1][0][i1]*POW(s1, j1)*POW(c1,j2);
				u2[0][i1] += 2.0*in[j2][j1][0][i1]*j1*POW(s1, j1-1)*POW(c1,j2);
				u3[0][i1] += 2.0*in[j2][j1][0][i1]*POW(s1, j1)*j2*POW(c1,j2-1);
			}
		}

		if(verb)
		{
			for(i1=0, norm=0.0; i1<n1*n2; i1++)
				norm += (u1[0][i1]*u1[0][i1]);
			sf_warning("res1 %d %g", it+1, sqrtf(norm/n1/n2));
		}

		if(use_divn)
		{
			for(i1=0, c1=0.0, s1=0.0; i1<n1*n2; i1++)
			{
				c1 += (u2[0][i1]*u2[0][i1]);
				s1 += (u3[0][i1]*u3[0][i1]);
			}
			c1=sqrtf(c1/(n1*n2));
			s1=sqrtf(s1/(n1*n2));
			for(i1=0; i1<n1*n2; i1++)
			{
				u1[0][i1] /= c1;
				u2[0][i1] /= c1;
			}
			sf_divn(u1[0], u2[0], u4[0]);
			for(i1=0; i1<n1*n2; i1++)
			{
				u1[0][i1] *= c1/s1;
				u3[0][i1] /= s1;
			}
			sf_divn(u1[0], u3[0], u5[0]);
		}else{
			for(i1=0; i1<n1*n2; i1++)
			{
				u4[0][i1] = divn(u1[0][i1], u2[0][i1]);
				u5[0][i1] = divn(u1[0][i1], u3[0][i1]);
			}
		}
		for(i1=0; i1<n1*n2; i1++)
		{
			p[0][i1] -= eta * sf_cmplx(u5[0][i1], u4[0][i1]);
			p[0][i1] = p[0][i1]*r/(cabsf(p[0][i1])+ 1E-15);
		}

	}
	for(i1=0; i1<n1*n2; i1++)
		dip[0][i1] = atan(tan(cargf(p[0][i1])));
}
示例#3
0
文件: Mpick31.c 项目: nicklinyi/src
int main(int argc, char* argv[])
{
    int dim, n[SF_MAX_DIM], rect;
    int it0, it1, niter, n1, n2, i2, n3, i3, i1, gate1, gate2, k2, k3, i5, n5;
    float ***scan, ***weight, **pick, *ampl, **pick2;
    float o2, d2, o3, d3, an1, an2, asum, a, ct0, ct1, vel2, vel3;
    bool smooth, verb;
    sf_file scn, pik;

    sf_init(argc,argv);
    scn = sf_input("in");
    pik = sf_output("out");

    if (SF_FLOAT != sf_gettype(scn)) sf_error("Need float input");
    dim = sf_filedims (scn,n);
    /* if (dim != 3) sf_error("Need three dimensions"); */

    n1 = n[0];
    n2 = n[1];
    n3 = n[2];

    n5 = sf_leftsize(scn,3);

    if (!sf_histfloat(scn,"o2",&o2)) o2=0.;
    if (!sf_histfloat(scn,"d2",&d2)) d2=1.;

    if (!sf_histfloat(scn,"o3",&o3)) o3=0.;
    if (!sf_histfloat(scn,"d3",&d3)) d3=1.;
 
    if (!sf_getfloat("vel1",&vel2)) vel2=o2;
    if (!sf_getfloat("vel2",&vel3)) vel3=o3;
    /* surface velocity */

    k2 = 0.5 + (vel2-o2)/d2;
    if (k2 < 0) k2=0;
    if (k2 >= n2) k2=n2-1;

    k3 = 0.5 + (vel3-o3)/d2;
    if (k3 < 0) k3=0;
    if (k3 >= n3) k3=n3-1;

    sf_putint(pik,"n2",1);
    sf_putint(pik,"n3",1);
    sf_putint(pik,"n4",2);
    sf_putint(pik,"n5",n5);

    
    if (!sf_getint("rect1",&rect)) rect=1;
    /* smoothing radius */

    if (!sf_getint("niter",&niter)) niter=100;
    /* number of iterations */

    if (!sf_getfloat("an1",&an1)) an1=1.;
    if (!sf_getfloat("an2",&an2)) an2=1.;
    /* axes anisotropy */
    if (!sf_getint("gate1",&gate1)) gate1=3;
    if (!sf_getint("gate2",&gate2)) gate2=3;
    /* picking gate */
    if (!sf_getbool("smooth",&smooth)) smooth=true;
    /* if apply smoothing */

    if (!sf_getbool("verb",&verb)) verb=true;
    /* verbosity */

    scan = sf_floatalloc3(n1,n2,n3);
    weight = sf_floatalloc3(n2,n3,n1);

    (void) dynprog3_init(n1,n2,n3,gate1,gate2,an1,an2,false);

    if (smooth) {
	pick = sf_floatalloc2(n1,2);
	pick2 = sf_floatalloc2(n1,2);	
	ampl = sf_floatalloc(n1);

	sf_divn_init(1,n1,&n1,&rect,niter,verb);
    } else {
	pick = NULL;
	pick2 = sf_floatalloc2(n1,2);
	ampl = NULL;
    }

    for(i5=0; i5 < n5; i5++) {
	sf_warning("slice %d of %d;",i5+1,n5);

	sf_floatread(scan[0][0],n1*n2*n3,scn);
	
	/* transpose and reverse */
	for (i3=0; i3 < n3; i3++) {
	    for (i2=0; i2 < n2; i2++) {
		for (i1=0; i1 < n1; i1++) {
		    weight[i1][i3][i2] = expf(-scan[i3][i2][i1]);
		}
	    }
	}
	
	dynprog3(k2, k3, weight);
	dynprog3_traj(pick2);
	
	if (smooth) {
	    for (i1=0; i1 < n1; i1++) {
		ct0 = pick2[0][i1];
		it0 = floorf(ct0);
		ct0 -= it0;
		
		if (it0 >= n2-1) {
		    it0 = n2-2;
		    ct0 = 0.;
		} else if (it0 < 0) {
		    it0 = 0;
		    ct0 = 0.;
		}
		
		ct1 = pick2[1][i1];
		it1 = floorf(ct1);
		ct1 -= it1;
		
		if (it1 >= n3-1) {
		    it1 = n3-2;
		    ct1 = 0.;
		} else if (it1 < 0) {
		    it1 = 0;
		    ct1 = 0.;
		}
		
		ampl[i1]=
		    scan[it1  ][it0  ][i1]*(1.-ct0)*(1.-ct1) +
		    scan[it1+1][it0  ][i1]*(1.-ct0)*ct1 +
		    scan[it1  ][it0+1][i1]*ct0*(1.-ct1) +
		    scan[it1+1][it0+1][i1]*ct0*ct1;
	    }
	} else {
	    for (i1=0; i1 < n1; i1++) {
		pick2[0][i1] = o2+pick2[0][i1]*d2;
		pick2[1][i1] = o3+pick2[1][i1]*d3;
	    }
	}
	
	if (smooth) {
	    /* normalize amplitudes */
	    asum = 0.;
	    for (i1 = 0; i1 < n1; i1++) {
		a = ampl[i1];
		asum += a*a;
	    }
	    asum = sqrtf (asum/n1);
	    for(i1=0; i1 < n1; i1++) {
		ampl[i1] /= asum;
		pick[0][i1] = (o2+pick2[0][i1]*d2-vel2)*ampl[i1];
		pick[1][i1] = (o3+pick2[1][i1]*d3-vel3)*ampl[i1];
	    }
	    
	    sf_divn(pick[0],ampl,pick2[0]);
	    sf_divn(pick[1],ampl,pick2[1]);
	    
	    for(i1=0; i1 < n1; i1++) {
		pick2[0][i1] += vel2;
		pick2[1][i1] += vel3;
	    }
	}
	
	sf_floatwrite(pick2[0],n1*2,pik);
    }
    sf_warning(".");
    exit(0);
}
示例#4
0
文件: Mshearer.c 项目: 1014511134/src
int main (int argc, char* argv[])
{
    int nh, n1,n2, i1,i2, i, n12, niter, dim, n[SF_MAX_DIM], rect[SF_MAX_DIM];
    int shrt, lng;
    float *trace, *hilb, *num, *den, *phase, mean, c;
    char key[6];
    sf_triangle ts, tl;
    sf_file in, out;

    sf_init (argc,argv);
    in = sf_input("in");
    out = sf_output("out");

    if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input");
    
    dim = sf_filedims (in,n);
    n1 = n[0];
    n12 = 1;
    for (i=0; i < dim; i++) {
	snprintf(key,6,"rect%d",i+1);
	if (!sf_getint(key,rect+i)) rect[i]=1;
	n12 *= n[i];
    }
    n2 = n12/n1;

    num = sf_floatalloc(n12);
    den = sf_floatalloc(n12);
    phase = sf_floatalloc(n12);

    if (!sf_getint("niter",&niter)) niter=100;
    /* number of iterations */

    if (!sf_getint("order",&nh)) nh=10;
    /* Hilbert transformer order */
    if (!sf_getfloat("ref",&c)) c=1.;
    /* Hilbert transformer reference (0.5 < ref <= 1) */

    sf_hilbert_init(n1, nh, c);

    if (!sf_getint("short",&shrt)) shrt=1;
    /* short smoothing radius */
    if (!sf_getint("long",&lng)) lng=10;
    /* long smoothing radius */

    ts = sf_triangle_init(shrt,n1,false);
    tl = sf_triangle_init(lng,n1,false);

    mean=0.;
    for (i2=0; i2 < n2; i2++) {
	trace = num+n1*i2;
	hilb = den+n1*i2;

	sf_floatread(trace,n1,in);
	sf_hilbert(trace,hilb);

	for (i1=0; i1 < n1; i1++) {
	    trace[i1] = hypotf(trace[i1],hilb[i1]);
	    hilb[i1] = trace[i1];
	}

	sf_smooth2 (ts, 0, 1, false, trace);
	sf_smooth2 (tl, 0, 1, false, hilb);
	
	for (i1=0; i1 < nh; i1++) {
	    trace[i1] = 0.;
	    hilb[i1] = 0.;
	}
	for (i1=nh; i1 < n1-nh; i1++) {
	    mean += hilb[i1]*hilb[i1];
	}
	for (i1=n1-nh; i1 < n1; i1++) {
	    trace[i1] = 0.;
	    hilb[i1] = 0.;
	}
    }
    mean = sqrtf(n12/mean);

    for (i=0; i < n12; i++) {
	num[i] *= mean;
	den[i] *= mean;
    }

    sf_divn_init(dim, n12, n, rect, niter, true);
    sf_divn (num, den, phase);

    sf_floatwrite(phase,n12,out);

    exit(0);
}
示例#5
0
文件: Mpick2.c 项目: Seislet/src
int main(int argc, char* argv[])
{
    int it, niter, nm, n1, n2, n3, i3, i2, i1, i, gate, i0, rect1, rect2, n123, n[2], rect[2];
    float **scan, **weight, *pick, *ampl, *pick2, o2, d2, an, asum, a, ct, vel0;
    char *label;
    sf_file scn, pik;

    sf_init(argc,argv);
    scn = sf_input("in");
    pik = sf_output("out");

    if (SF_FLOAT != sf_gettype(scn)) sf_error("Need float input");

    if (!sf_histint(scn,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(scn,"n2",&n2)) sf_error("No n2= in input");
    if (!sf_histint(scn,"n3",&n3)) sf_error("No n3= in input");

    nm = n1*n3;
    n123 = nm*n2;
    n[0]=n1;
    n[1]=n3;

    if (!sf_histfloat(scn,"o2",&o2)) o2=0.;
    if (!sf_histfloat(scn,"d2",&d2)) d2=1.;
 
    if (!sf_getfloat("vel0",&vel0)) vel0=o2;
    /* surface velocity */
    i0 = 0.5 + (vel0-o2)/d2;
    if (i0 < 0) i0=0;
    if (i0 >= n2) i0=n2-1;

    sf_unshiftdim(scn,pik,2);

    if (NULL != (label = sf_histstring(scn,"label2"))) 
		sf_putstring(pik,"label",label);
    if (NULL != (label = sf_histstring(scn,"unit2"))) 
		sf_putstring(pik,"unit",label);

    if (!sf_getint("rect1",&rect1)) rect1=1;
    /* smoothing radius on the first axis */ 
    if (!sf_getint("rect2",&rect2)) rect2=1;
    /* smoothing radius on the second axis */ 
    rect[0]=rect1;
    rect[1]=rect2;

    if (!sf_getint("niter",&niter)) niter=100;
    /* number of iterations */

    if (!sf_getfloat("an",&an)) an=1.; 
    /* axes anisotropy */
    if (!sf_getint("gate",&gate)) gate=3; 
    /* picking gate */

    scan = sf_floatalloc2(n1,n2);
    weight = sf_floatalloc2(n2,n1);

    (void) dynprog_init(n1,n2,gate,an,false);

    pick = sf_floatalloc(nm);
    pick2 = sf_floatalloc(nm);	
    ampl = sf_floatalloc(nm);
    
    sf_divn_init(2,nm,n,rect,niter,true);

    for (i3=0; i3 < n3; i3++) {
	sf_warning("cmp %d of %d;",i3+1,n3);
	sf_floatread(scan[0],n1*n2,scn);

	/* transpose and reverse */
	for (i2=0; i2 < n2; i2++) {
	    for (i1=0; i1 < n1; i1++) {
		weight[i1][i2] = expf(-scan[i2][i1]);
	    }
	}

	dynprog(i0, weight);
	dynprog_traj(pick2);

	for (i1=0; i1 < n1; i1++) {
	    i = i1 + i3*n1;
	    ct = pick2[i1];
	    pick[i] = ct;
	    it = floorf(ct);
	    ct -= it;
	    if (it >= n2-1) {
		ampl[i]=scan[n2-1][i1];
	    } else if (it < 0) {
		ampl[i]=scan[0][i1];
	    } else {
		ampl[i]=scan[it][i1]*(1.-ct)+scan[it+1][i1]*ct;
	    }
	}
    }
    sf_warning(".");
    
    /* normalize amplitudes */
    asum = 0.;
    for (i = 0; i < nm; i++) {
	a = ampl[i];
	asum += a*a;
    }
    asum = sqrtf (asum/nm);
    for(i=0; i < nm; i++) {
	ampl[i] /= asum;
	pick[i] = (o2+pick[i]*d2-vel0)*ampl[i];
    }
    
    sf_divn(pick,ampl,pick2);

    for(i=0; i < nm; i++) {
	pick2[i] += vel0;
    }

    sf_floatwrite(pick2,nm,pik);

    exit(0);
}
示例#6
0
文件: Mdivn2d.c 项目: 1014511134/src
int main(int argc, char* argv[])
{
    bool verb;
    int i1, i3, n12, n3, niter, n[2], rect[2];
    float *u1, *u2, *u3, norm;
    sf_file inp, out, den;

    sf_init(argc,argv);
    inp = sf_input("in");
    den = sf_input("den");
    out = sf_output("out");

    if (SF_FLOAT != sf_gettype(inp)) sf_error("Need float input");
    
    if (!sf_histint(inp,"n1",n)) sf_error("No n1= in input");
    if (!sf_histint(inp,"n2",n+1)) sf_error("No n2= in input");
    n3 = sf_leftsize(inp,2);
    n12 = n[0]*n[1];

    if (!sf_getint("rect1",&rect[0])) rect[0]=1;
    if (!sf_getint("rect2",&rect[1])) rect[1]=1;
    /* smoothing radius */

    if (!sf_getint("niter",&niter)) niter=100;
    /* number of iterations */

    if (!sf_getbool("verb",&verb)) verb=false;
    /* verbosity */

    u1 = sf_floatalloc(n12);
    u2 = sf_floatalloc(n12);
    u3 = sf_floatalloc(n12);

	runtime_init(n12*sizeof(float));
    for (i3=0; i3 < n3; i3++) 
	{
		sf_floatread(u1, n12, inp);
		sf_floatread(u2, n12, den);

    	sf_divn_init(2, n12, n, rect, niter, verb);
		/* smooth division */
		norm = 0.;
		for (i1=0; i1 < n12; i1++) 
		    norm += u2[i1] * u2[i1];
		norm = sqrtf(n12/norm);

		for (i1=0; i1 < n12; i1++) 
		{
			u1[i1] *= norm;
			u2[i1] *= norm;
		}
		sf_divn (u1, u2, u3);

		sf_floatwrite(u3, n12, out);

		sf_divn_close();
		norm = runtime(1);
		sf_warning("%d of %d, %f MB/sec;", i3, n3, norm);
	}

	free(u1);
	free(u2);
	free(u3);
    exit(0);
}
示例#7
0
void phasescan(float** inp /* input data [ntr][n1] */, 
	      float** oth /* target data [ntr][n2] */,
	      float* rat1)
/*< scan >*/
{
    float doth, dout; /* doth and dout are for normalization*/
    int i1, i2, ia, i;/*i1 is time index, i2 is trace index*/
    float *htrace;
    htrace =  sf_floatalloc(n2);
    float theta,expc,exps,tmp;

    doth = 0.;
    dout = 0.;
    angle0 *= 1/180.0*SF_PI; 
    dangle *= 1/180.0*SF_PI; 
    sf_hilbert_init(n1,n2,1.0);
    for (i2=0; i2 < ntr; i2++) {
//	sf_banded_solve (spl, inp[i2]);

	for (i1=0; i1 < n2; i1++) {
	    doth += oth[i2][i1]*oth[i2][i1];
	}
        
	/*Hilbert Transform inp[i2] */
        sf_hilbert(inp[i2],htrace);
        
        /*rotate to angle theta */
        /*multiply by exp(i*theta*pi/180)*/
        for (ia=0; ia < na; ia++) {
            theta = angle0+ia*dangle;
            //sf_warning("theta=%g",theta);
            expc = cosf(theta);
            exps = sinf(theta);
            for (i1=0; i1 < n1; i1++){
                tmp = inp[i2][i1]*expc-htrace[i1]*exps;
                if(i1<n2) out[i2][ia][i1] = tmp;
            }
            for (i1=n1; i1 < n2; i1++) out[i2][ia][i1] = 0.0; 
            
            for (i1=0; i1 < n2; i1++) {
	        dout += out[i2][ia][i1]*out[i2][ia][i1];
    	    }
        }
     
      
	
    }

    doth = sqrtf(ntr*n2/doth);
    dout = sqrtf(n2g/dout);
    /* calculate local correlation*/
    for (i2=0; i2 < ntr; i2++) {
	for (ia=0; ia < na; ia++) {
	    for (i1=0; i1 < n2; i1++) {
		i = (i2*na + ia)*n2+i1;
		den[i] = out[i2][ia][i1]*dout;
		num[i] = oth[i2][i1]*dout;
	    }
	}
    }

    sf_divn(num,den,rat1);
	
    for (i2=0; i2 < ntr; i2++) {
	for (ia=0; ia < na; ia++) {
	    for (i1=0; i1 < n2; i1++) {
		i = (i2*na+ia)*n2+i1;
		num[i] = out[i2][ia][i1]*doth;
		den[i] = oth[i2][i1]*doth;
	    }
	}
    }
    sf_divn(num,den,rat2);
    
    sf_divn_combine(rat1,rat2,rat1);
}
示例#8
0
文件: Modip2.c 项目: 1014511134/src
int main(int argc, char *argv[])
{
    int i, k, n1, n2, n12, n[2], niter, iter, liter, rect[2];
    float mean, a0, ai, norm, norm2, lam;
    float **dat, **ang, **p1, **p2, ***den, *dena, *rat, **out;
    sf_file inp, dip;

    sf_init(argc,argv);
    inp = sf_input("in");
    dip = sf_output("out");

    if (SF_FLOAT != sf_gettype(inp)) sf_error("Need float input");
    if (!sf_histint(inp,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(inp,"n2",&n2)) sf_error("No n2= in input");
    n12 = n1*n2;
    n[0] = n1;
    n[1] = n2;

    if (!sf_getint("liter",&liter)) liter=100;
    /* number of linear iterations */
    if (!sf_getint("niter",&niter)) niter=10;
    /* number of iterations */

    if (!sf_getint("rect1",&rect[0])) rect[0]=1;
    /* vertical smoothing */
    if (!sf_getint("rect2",&rect[1])) rect[1]=1;
    /* horizontal smoothing */

    if (!sf_getfloat("a0",&a0)) a0=0;
    /* initial angle */

    dat = sf_floatalloc2(n1,n2);
    ang = sf_floatalloc2(n1,n2);
    out = sf_floatalloc2(n1,n2);
    
    p1 = sf_floatalloc2(n1,n2);
    p2 = sf_floatalloc2(n1,n2);

    den  = sf_floatalloc3(n1,n2,2);
    dena = sf_floatalloc(n12);
    rat  = sf_floatalloc(n12);

    sf_floatread(dat[0],n12,inp);

    for (i=0; i < n12; i++) {
	ang[0][i] = a0;
	p1[0][i] = sinf(a0);
	p2[0][i] = cosf(a0);
    }

    opwd_init(n1,n2);
    sf_divn_init(2, n12, n, rect, liter, true); 

    opwd_filter(lagrange,lagrange,NULL,NULL,p1,p2,dat,out);
    
    norm = 0.;
    for (i=0; i < n12; i++) {
	out[0][i] = dat[0][i] - out[0][i];
	norm += out[0][i]*out[0][i];
    }

    for (iter=0; iter < niter; iter++) {
	sf_warning("iter=%d of %d",iter+1,niter);

	opwd_filter(lagrange_der,lagrange,NULL,NULL,p1,p2,dat,den[0]);
	opwd_filter(lagrange,lagrange_der,NULL,NULL,p1,p2,dat,den[1]);

	for(i=0; i < n12; i++) {
	    dena[i] = den[0][0][i]*p2[0][i]-den[1][0][i]*p1[0][i];
	}

        mean = 0.;
	for(i=0; i < n12; i++) {
	    mean += dena[i]*dena[i];
	}
	mean = sqrtf (n12/mean);
    
	for(i=0; i < n12; i++) {
	    out[0][i] *= mean;
	    dena[i] *= mean;
	}
    
	sf_divn (out[0],dena,rat);

	/* Choose step size */
	lam = 1.;
	for (k=0; k < 8; k++) {	    
	    for(i=0; i < n12; i++) {
		ai = ang[0][i] + lam*rat[i];
		if      (ai < -0.5*SF_PI) ai=-0.5*SF_PI;
		else if (ai >  0.5*SF_PI) ai= 0.5*SF_PI;

		p1[0][i] = sinf(ai);
		p2[0][i] = cosf(ai);
	    }
	    opwd_filter(lagrange,lagrange,NULL,NULL,p1,p2,dat,out);

	    norm2 = 0.;
	    for (i=0; i < n12; i++) {
		out[0][i] = dat[0][i] - out[0][i];
		norm2 += out[0][i]*out[0][i];
	    }
	    if (norm2 < norm) break;
	    lam *= 0.5;
	}

	for(i=0; i < n12; i++) {
	    ang[0][i] += lam*rat[i];
	    norm = norm2;
	}	
    }
    
    sf_floatwrite(ang[0],n12,dip);

    exit(0);
}
示例#9
0
int main(int argc, char* argv[])
{
    bool phase;
    char *label;
    int i1, n1, iw, nt, nw, i2, n2, rect, niter;
    float t, d1, w, w0, dw, *trace, *bs, *bc, *ss, *cc, *mm;
    sf_file time, timefreq, mask;
    
    sf_init(argc,argv);
    time = sf_input("in");
    timefreq = sf_output("out");

    if (!sf_histint(time,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histfloat(time,"d1",&d1)) d1=1.;
    n2 = sf_leftsize(time,1);

    if (!sf_getint("nw",&nw)) { /* number of frequencies */
		nt = 2*kiss_fft_next_fast_size((n1+1)/2);
		nw = nt/2+1;
		dw = 1./(nt*d1);
		w0 = 0.;
    } else {
		if (	!sf_getfloat("dw",&dw)) {
			/* f	requency step */
			nt =	2*kiss_fft_next_fast_size((n1+1)/2);
			dw =	1./(nt*d1);
		}
		if (!sf_getfloat("w0",&w0)) w0=0.;
		/* first frequency */
    }

    sf_shiftdim(time, timefreq, 2);
    
    sf_putint(timefreq,"n2",nw);
    sf_putfloat(timefreq,"d2",dw);
    sf_putfloat(timefreq,"o2",w0);

    if (NULL != (label = sf_histstring(time,"label1")) && !sf_fft_label(2,label,timefreq)) 
		sf_putstring(timefreq,"label2","Wavenumber");
    sf_fft_unit(2,sf_histstring(time,"unit1"),timefreq);

    dw *= 2.*SF_PI;
    w0 *= 2.*SF_PI;

    trace = sf_floatalloc(n1);
    bs    = sf_floatalloc(n1);
    bc    = sf_floatalloc(n1);
    ss    = sf_floatalloc(n1);
    cc    = sf_floatalloc(n1);
    
    if (!sf_getint("rect",&rect)) rect=10;
    /* smoothing radius */
    if (!sf_getint("niter",&niter)) niter=100;
    /* number of inversion iterations */

    if (!sf_getbool("phase",&phase)) phase=false;
    /* output phase instead of amplitude */

    sf_divn_init(1,n1,&n1,&rect,niter,false);

    if (NULL != sf_getstring("mask")) {
		mask = sf_input("mask");
		mm = sf_floatalloc(n1);
    } else {
		mask = NULL;
		mm = NULL;
    }

    for (i2=0; i2 < n2; i2++) {
		sf_floatread(trace,n1,time);
		if (NULL != mm) {
			sf_floatread(mm,n1,mask);
			for (i1=0; i1 < n1; i1++) {
				trace[i1] *= mm[i1];
			}
		}

		for (iw=0; iw < nw; iw++) {
			w = w0 + iw*dw;

			if (0.==w) { /* zero frequency */
				for (i1=0; i1 < n1; i1++) {
					ss[i1] = 0.;
					bc[i1] = 0.5;
					if (NULL != mm) bc[i1] *= mm[i1];
				}
				sf_divn(trace,bc,cc);
			} else {
				for (i1=0; i1 < n1; i1++) {
					t = i1*d1;
					bs[i1] = sinf(w*t);
					bc[i1] = cosf(w*t);
					if (NULL != mm) {
						bs[i1] *= mm[i1];
						bc[i1] *= mm[i1];
					}
				}
				sf_divn(trace,bs,ss);
				sf_divn(trace,bc,cc);
			}

			for (i1=0; i1 < n1; i1++) {
				ss[i1] = phase? atan2f(ss[i1],cc[i1]): hypotf(ss[i1],cc[i1]);
			}

			sf_floatwrite(ss,n1,timefreq);
		}
    }
    

    exit(0);
}