Пример #1
0
/*...........................................................................*/
void derive_2( int n1, int n2, float d2,
               float **y, float **dyd2 )
/*< derive 2 >*/
{
    int n=6,i1,i2;
    float *yy=NULL,*der2=NULL;
/*
  hilbert_init(n2, n, 0.);
  der2 = sf_floatalloc(n2);
  
  for (i1=0;i1<n1;i1++) {
  for(i2=0;i2<n2;i2++) taux[i2] = tsg[i2*n1+i1];
  deriv(taux,der2);
  for(i2=0;i2<n2;i2++) dtdx[i2*n1+i1] = der2[i2]/d2;
  }
*/
    
    sf_deriv_init(n2, n, 0.);
    yy   = sf_floatalloc(n2);
    der2 = sf_floatalloc(n2);
    
    for (i1=0;i1<n1;i1++) {
	for(i2=0;i2<n2;i2++) yy[i2] = y[i2][i1];
	sf_deriv(yy,der2);
	for(i2=0;i2<n2;i2++) dyd2[i2][i1] = der2[i2]/d2;
    }
    
    free(yy); free(der2);
    sf_deriv_close();
    
}
Пример #2
0
/*-----------------------------------------------------------------------------*/
int angleMap(
    sf_complex **rays,  
    boxrays b, 
    float **map )
/*< angle >*/
{
    int flag=0, it, ig, norder=6;
    float *x, *z, *dxdg, *dzdg, zero=.00001, ang, halfpi;
    
    x    = (float *) malloc(b.ng*sizeof(float));
    z    = (float *) malloc(b.ng*sizeof(float));
    dxdg = (float *) malloc(b.ng*sizeof(float));
    dzdg = (float *) malloc(b.ng*sizeof(float));
    
    sf_deriv_init(b.ng, norder, 0.);
    
    halfpi = 2*atan(1);
    for(it=0;it<b.nt;it++){
	for(ig=0;ig<b.ng;ig++){
	    x[ig]=crealf(rays[it][ig]);
	    z[ig]=cimagf(rays[it][ig]);
	}
	sf_deriv(x,dxdg);
	sf_deriv(z,dzdg);    
	for(ig=0;ig<b.ng;ig++){
	    if(dxdg[ig]>zero) {ang=atan(dzdg[ig]/dxdg[ig]);
	    }else{ang=halfpi;}
	    map[it][ig]=fabs(ang);
	}
    }
    
    sf_deriv_free();
    free(x); free(z); free(dxdg); free(dzdg);
    flag = 1;
    
    return flag;
}
Пример #3
0
/*...........................................................................*/
void derive_1( int n1, int n2, float d1, 
               float **y, float **dyd1 )
/*< derive 1 >*/
{
    int n=6,i1,i2;
    
    sf_deriv_init(n1, n, 0.);
    
    for (i2=0;i2<n2;i2++) {
	sf_deriv(y[i2],dyd1[i2]);
	for(i1=0;i1<n1;i1++) dyd1[i2][i1] /= d1;
    }
    
    sf_deriv_close();
    
}
Пример #4
0
int main (int argc, char* argv[])
{
    bool scale;
    int n1,n2, i1,i2, n;
    float d1, *dat, *der;
    sf_file in=NULL, out=NULL;

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

    if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input");
    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
    n2 = sf_leftsize(in,1);

    dat = sf_floatalloc(n1);
    der = sf_floatalloc(n1);

    if (!sf_getint("order",&n)) n=6;
    /* filter order */

    if (!sf_getbool("scale",&scale) || 
	!sf_histfloat(in,"d1",&d1)) scale=false;
    /*(scale=n if scale by 1/dx )*/

    sf_deriv_init(n1, n, 0.);

    for (i2=0; i2 < n2; i2++) {
	sf_floatread(dat,n1,in);
	sf_deriv(dat,der);

	if (scale) {
	    for (i1=0; i1 < n1; i1++) {
		der[i1] /= d1;
	    }
	}

	sf_floatwrite(der,n1,out);
    }


    exit(0);
}
Пример #5
0
int main (int argc, char* argv[])
{
    int nh, n1, n2, i1,i2, i, dim, n[SF_MAX_DIM];
    float *trace, *hilb, *dtrace, *dhilb, *attr, *dert=NULL, c, d1;
    char *type;
    bool hertz, hires, der2, verb;
    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];
    n2 = 1;
    for (i=0; i < dim; i++) {
	n2 *= n[i];
    }
    n2 /= n1;

    if (NULL == (type=sf_getstring("type"))) type="amplitude";
    /* [amplitude,phase,frequency] attribute type, the default is amplitude */

    if (!sf_histfloat(in,"d1",&d1)) d1=1.;

    if (!sf_getint("order",&nh)) nh=10;
    /* Hilbert transformer order */

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

    if (!sf_getbool("hertz",&hertz)) hertz=true;
    /* if y, convert output to Hertz */

    if (!sf_getbool("hires",&hires)) hires=false;
    /* if y, compute high resolution instantaneous attributes */

    if (hires) {
	if (!sf_getbool("der2",&der2)) der2=false;
	/* if y, compute 2nd-order derivative to use with hires=y */
    }

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

    if (hires) dert = sf_floatalloc(n1);
    trace = sf_floatalloc(n1);
    hilb = sf_floatalloc(n1);
    dtrace = sf_floatalloc(n1);
    dhilb = sf_floatalloc(n1);
    attr = sf_floatalloc(n1);

    sf_hilbert_init(n1, nh, c);
    if ('f'==type[0] || hires) sf_deriv_init(n1, nh, c);
    
    d1 = 1./(2.*SF_PI*d1);
    for (i2=0; i2 < n2; i2++) {
	if (verb) sf_warning("trace %d of %d;",i2+1,n2);

	sf_floatread(trace,n1,in);

	for (i1=0; i1 < n1; i1++) {
	    hilb[i1] = 0.;
	    dtrace[i1] = 0.;
	    dhilb[i1] = 0.;
	    if (hires) dert[i1] = 0.;
	}
	if (hires) {
	    sf_deriv(trace,dert);
	    if (der2) {
		sf_deriv(dert,trace);
	    } else {
		for (i1=0; i1 < n1; i1++) {
		    trace[i1] = dert[i1];
		}
	    }
	}
	sf_hilbert(trace,hilb);
	switch(type[0]) {
	    case 'a':
		for (i1=0; i1 < n1; i1++) {
		    attr[i1] = hypotf(trace[i1],hilb[i1]);
		}
		break;

	    case 'p':
		for (i1=0; i1 < n1; i1++) {
		    attr[i1] = atanf(hilb[i1]/
				     (trace[i1]+FLT_EPSILON))*90./SF_PI;
		    if (hires) {
			if (der2) {
			    attr[i1] *= -1.;
			} 
		    }
		}

		break;

	    case 'f':
		sf_deriv(trace,dtrace);
		sf_deriv(hilb,dhilb);
		for (i1=0; i1 < n1; i1++) {
		    attr[i1] = (trace[i1]*dhilb[i1]-dtrace[i1]*hilb[i1])/
			(trace[i1]*trace[i1]+hilb[i1]*hilb[i1]+FLT_EPSILON);
		}

		if (hertz) {
		    /* convert to Hertz */    
		    for (i1=0; i1 < n1; i1++) {
			attr[i1] *= d1;
		    }
		}
		break;

	    default:
		sf_error("Unknown attribute type=%c",type[0]);
		break;
	}
	sf_floatwrite(attr,n1,out);
    }
    if (verb) sf_warning(".");   
    exit(0);
}
Пример #6
0
/*-----------------------------------------------------------------------------*/
int indexMap(
    sf_complex **rays,
    boxrays b, 
    float **vel, 
    sf_axis ax, 
    sf_axis az, 
    float dx, 
    float dz,
    int nf, 
    float df, 
    float fmax, 
    int **map )
/*< index >*/
{
    int flag=0, it, ig, norder=6, index;
    float *x, *z, *dxdg, *dzdg, zero=.02, tg, tg90=9999.;
    float fx, fz, fc, arg, vv;
    pt2d p;
    
    x    = (float *) malloc(b.ng*sizeof(float));
    z    = (float *) malloc(b.ng*sizeof(float));
    dxdg = (float *) malloc(b.ng*sizeof(float));
    dzdg = (float *) malloc(b.ng*sizeof(float));
    
    sf_deriv_init(b.ng, norder, 0.);
    hwt2d_init(vel,az,ax,az,ax);
    
    for(it=0;it<b.nt;it++){
	for(ig=0;ig<b.ng;ig++){
	    x[ig]=crealf(rays[it][ig]);
	    z[ig]=cimagf(rays[it][ig]);
	}
	sf_deriv(x,dxdg);
	sf_deriv(z,dzdg);
	for(ig=0;ig<b.ng;ig++){
	    if(dxdg[ig]>zero) {tg=fabs(dzdg[ig]/dxdg[ig]);
	    }else{tg=tg90;}
	    arg = sqrt(1+tg*tg);
	    p.x = crealf(rays[it][ig]);
	    p.z = cimagf(rays[it][ig]);
	    vv  = hwt2d_getv(p);
	    fx  = vv/(2*dx*arg);
	    /* REVER fz
	       if(tg==tg90) fz=vv/(2*dz);
	       else fz=vv*tg/(2*dz*arg);*/
	    fz=vv/(2*dz);
	    if(fx<fz) fc=fx;
	    else fc=fz;
	    /* DUVIDA
	       if(fc>(fmax-df)) index=0;
	       else index = floor((fmax-df-fc)/df);*/
	    if(fc>fmax) index=0;
	    else index = floor((fmax-fc)/df);
	    if(index<0) index=0;
	    if(index>(nf-1)) index=nf-1;
	    map[it][ig]=index;
	}
    }
    
    sf_deriv_free();
    free(x); free(z); free(dxdg); free(dzdg);
    flag = 1;
    
    return flag;
}
Пример #7
0
/*-----------------------------------------------------------------------------*/
int indexMap2( 
    sf_complex **rays,  
    boxrays b, 
    float **vel, 
    sf_axis ax, 
    sf_axis az, 
    float dx, 
    float dz,
    int nf, 
    float df, 
    float fmax, 
    int **map )
/*< index 2 >*/
{
/* this functions was not tested */
    int flag=0, it, ig, norder=6, index;
    float *x, *z, *dxdt, *dzdt, zero=.02, tg, tg90=9999.;
    float fx, fz, fc, arg, vv;
    pt2d p;
    
    x    = (float *) malloc(b.nt*sizeof(float));
    z    = (float *) malloc(b.nt*sizeof(float));
    dxdt = (float *) malloc(b.nt*sizeof(float));
    dzdt = (float *) malloc(b.nt*sizeof(float));
    
    sf_deriv_init(b.nt, norder, 0.);
    hwt2d_init(vel,az,ax,az,ax);
    
    for(ig=0;ig<b.ng;ig++){
	for(it=0;it<b.nt;it++){
	    x[it]=crealf(rays[it][ig]);
	    z[it]=cimagf(rays[it][ig]);
	}
	sf_deriv(x,dxdt);
	sf_deriv(z,dzdt);
	for(it=0;it<b.nt;it++){
	    if(dxdt[it]>zero) {tg=fabs(dzdt[it]/dxdt[it]);
	    }else{tg=tg90;}
	    arg = sqrt(1+tg*tg);
	    p.x = x[it];
	    p.z = z[it];
	    vv  = hwt2d_getv(p);
	    fx  = vv/(2*dx*arg);
	    /* REVER fz
	       if(tg>zero) fz=tg*vv/(2*dz*arg);
	       else fz=vv/(2*dz);*/
	    fz=vv*tg/(2*dz*arg);
	    if(fx<fz) fc=fx;
	    else fc=fz;
	    if(fz<fx)  fprintf(stderr,"theta=%f fx=%f fz=%f fc=%f\n",57.2957795*atan(tg),fx,fz,fc);
	    if(fc>(fmax-df)) index=0;
	    else index = floor((fmax-df-fc)/df);
	    map[it][ig]=index;
	}
    }
    
    sf_deriv_free();
    free(x); free(z); free(dxdt); free(dzdt);
    flag = 1;
    
    return flag;
}