Beispiel #1
0
int main(int argc, char* argv[])
{
    int n1, n2, i2, esize;
    off_t pos;
    struct skey *sorted;
    float *unsorted;
    char *trace, *header;
    sf_file in, head, out;

    sf_init (argc,argv);
    in = sf_input ("in");
    out = sf_output ("out");
 
    header = sf_getstring("head");
    /* header file */
    if (NULL == header) { 
	header = sf_histstring(in,"head");
	if (NULL == header) sf_error("Need head=");
    }

    head = sf_input(header);
    if (SF_FLOAT != sf_gettype(head))
	sf_error("Need float header");
    n2 = sf_filesize(head);
 
    unsorted = sf_floatalloc(n2);
    sorted = (struct skey*) sf_alloc(n2,sizeof(struct skey));
    
    sf_floatread(unsorted,n2,head);
    for (i2 = 0; i2 < n2; i2++) {
	sorted[i2].key = unsorted[i2];
	sorted[i2].pos = i2;
    }
    free (unsorted);
    sf_fileclose(head);

    qsort(sorted,n2,sizeof(struct skey),key_compare);
 
    if (!sf_histint(in,"n1",&n1)) n1=1;
    esize = sf_esize(in);
    n1 *= esize;

    trace = sf_charalloc(n1);

    sf_unpipe(in,((off_t) n1)*((off_t) n2));
    sf_fileflush(out,in);
    sf_setform(in,SF_NATIVE);
    sf_setform(out,SF_NATIVE);

    pos = sf_tell(in);
    for (i2=0; i2<n2; i2++) {
	sf_seek(in,pos+(sorted[i2].pos)*n1,SEEK_SET);
	sf_charread(trace,n1,in);
	sf_charwrite(trace,n1,out);
    }


    exit(0);
}
Beispiel #2
0
int main(int argc, char* argv[])
{
    int n1, n2, n3, gainstep, panel, it, nreserve, i1, i2, i3, j, orient;
    float o1, o2, o3, d1, d2, d3, gpow, clip, pclip, phalf, bias=0., minmax[2];
    float pbias, gain=0., x1, y1, x2, y2, **data=NULL, f, barmin, barmax, dat;
    bool transp, yreverse, xreverse, allpos, polarity, symcp, verb;
    bool eclip=false, egpow=false, barreverse, mean=false;
    bool scalebar, nomin=true, nomax=true, framenum, sfbyte, sfbar, charin;
    char *gainpanel, *color, *barfile;
    unsigned char tbl[TSIZE+1], **buf, tmp, *barbuf[1];
    enum {GAIN_EACH=-3,GAIN_ALL=-2,NO_GAIN=-1};
    off_t pos;
    sf_file in, out=NULL, bar=NULL;
    
    sf_init(argc,argv);
    in = sf_input("in");

    sfbyte = (bool) (NULL != strstr (sf_getprog(),"byte"));
    sfbar = (bool) (NULL != strstr (sf_getprog(),"bar"));

    if (sfbyte) {
	out = sf_output("out");
	sf_settype(out,SF_UCHAR);
    } else if (sfbar) {
	bar = sf_output("out");
	sf_settype(bar,SF_UCHAR);
    } else {
	vp_init();
    }

    charin = (bool) (SF_UCHAR == sf_gettype(in));

    if (charin && sfbyte) sf_error("Cannot input uchar to byte");

    if (!charin && SF_FLOAT != sf_gettype(in)) sf_error("Need float input");

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

    if (!sf_histfloat(in,"o1",&o1)) o1=0.;
    if (!sf_histfloat(in,"o2",&o2)) o2=0.;
    if (!sf_histfloat(in,"o3",&o3)) o3=0.;

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

    if (!sf_getbool("transp",&transp)) transp=true;
    /* if y, transpose the display axes */
    if (!sf_getbool("yreverse",&yreverse)) yreverse=true;
    /* if y, reverse the vertical axis */
    if (!sf_getbool("xreverse",&xreverse)) xreverse=false;
    /* if y, reverse the horizontal axis */

    if (transp) {
	orient = 3;
    } else {	
	orient = (xreverse==yreverse)? 0:2;
    }

    if (!charin) {
	panel = NO_GAIN; /* no need for gain */
	
	phalf=85.;
	egpow = false;
	if (!sf_getfloat("gpow",&gpow)) {
	    gpow=1.;
	    /*( gpow=1 raise data to gpow power for display )*/
	} else if (gpow <= 0.) {
	    gpow=0.;
	    egpow = true;
	    sf_getfloat("phalf",&phalf);
	    /* percentage for estimating gpow */
	    if (phalf <=0. || phalf > 100.)
		sf_error("phalf=%g should be > 0 and <= 100",phalf);
	    panel = 0;
	}
	
	pclip=99.;
	eclip = (bool) (!sf_getfloat("clip",&clip));
	/* data clip */
	if (eclip) {	    
	    clip = 0.;
	    sf_getfloat("pclip",&pclip);
	    /* data clip percentile (default is 99) */
	    if (pclip <=0. || pclip > 100.)
		sf_error("pclip=%g should be > 0 and <= 100",pclip);
	    panel = 0;
	} else if (clip <= 0.) {
	    sf_warning("clip=%g <= 0",clip);
	    clip = FLT_EPSILON;
	}

	if (0==panel) {
	    if (!sf_getint("gainstep",&gainstep)) gainstep=0.5+n1/256.;
	    /* subsampling for gpow and clip estimation */
	    if (gainstep <= 0) gainstep=1;

	    gainpanel = sf_getstring("gainpanel");
	    /* gain reference: 'a' for all, 'e' for each, or number */
	    if (NULL != gainpanel) {
		switch (gainpanel[0]) {
		    case 'a': 
			panel=GAIN_ALL; 
			break;
		    case 'e': 
			panel=GAIN_EACH;
			break;
		    default:
			if (0 ==sscanf(gainpanel,"%d",&panel) || 
			    panel < 1 || panel > n3) 
			    sf_error("gainpanel= should be all,"
				     " each, or a number"
				     " between 1 and %d",n3);
			panel--;
			break;
		}
		free (gainpanel); 
	    } 

	    sf_unpipe(in,sf_filesize(in)*sizeof(float));
	} 

	if (!sf_getbool("allpos",&allpos)) allpos=false;
	/* if y, assume positive data */
	if (!sf_getbool("mean",&mean)) mean=false;
	/* if y, bias on the mean value */
	if (!sf_getfloat("bias",&pbias)) pbias=0.;
	/* value mapped to the center of the color table */
	if (!sf_getbool("polarity",&polarity)) polarity=false;
	/* if y, reverse polarity (white is high by default) */
	if (!sf_getbool("symcp",&symcp)) symcp=false;
	/* if y, assume symmetric color palette of 255 colors */
	if (!sf_getbool("verb",&verb)) verb=false;
	/* verbosity flag */
    } /* if !charin */

    barfile = sf_getstring("bar");
    /* file for scalebar data */

    if (sfbyte) {
	scalebar = (bool) (NULL != barfile);
	if (scalebar) sf_putstring(out,"bar",barfile);
    } else if (sfbar) {
	scalebar = true;
    } else {
	if (!sf_getbool ("wantscalebar",&scalebar) && 
	    !sf_getbool ("scalebar",&scalebar)) scalebar = false;
	/* if y, draw scalebar */	
    }
    if (scalebar) {
	nomin = (bool) (!sf_getfloat("minval",&barmin));
	/* minimum value for scalebar (default is the data minimum) */
	nomax = (bool) (!sf_getfloat("maxval",&barmax));
	/* maximum value for scalebar (default is the data maximum) */
	
	barbuf[0] = sf_ucharalloc(VP_BSIZE);

	if (!sf_getbool("barreverse",&barreverse)) barreverse=false;
	/* if y, go from small to large on the bar scale */

	if (sfbyte || sfbar) {
	    if (sfbyte) {
		bar = sf_output("bar");
		sf_settype(bar,SF_UCHAR);
	    }
	    sf_putint(bar,"n1",VP_BSIZE+2*sizeof(float));
	    sf_putint(bar,"n2",1);
	    sf_putint(bar,"n3",n3);

	    if (!nomin) sf_putfloat(bar,"minval",barmin);
	    if (!nomax) sf_putfloat(bar,"maxval",barmax);
	} else if (charin) {
	    if (NULL == barfile) {
		barfile=sf_histstring(in,"bar");
		if (NULL == barfile) sf_error("Need bar=");
	    }

	    bar = sf_input(barfile);
	    if (SF_UCHAR != sf_gettype(bar)) sf_error("Need uchar in bar");

	    if (nomin) nomin = (bool) (!sf_histfloat(bar,"minval",&barmin));
	    if (nomax) nomax = (bool) (!sf_histfloat(bar,"maxval",&barmax));
	}
    }

    if (!sf_getbool("wantframenum",&framenum)) framenum = (bool) (n3 > 1);
    /* if y, display third axis position in the corner */

    x1 = o1-0.5*d1;
    x2 = o1+(n1-1)*d1+0.5*d1;
    y1 = o2-0.5*d2;
    y2 = o2+(n2-1)*d2+0.5*d2;

    if (!sfbyte && !sfbar) {
	vp_stdplot_init (x1, x2, y1, y2, transp, false, yreverse, false);
	vp_frame_init(in,"tlb",false);
/*	if (scalebar && !nomin && !nomax) 
	vp_barframe_init (in,barmin,barmax); */
    }

    if (transp) {
	f=x1; x1=y1; y1=f;
	f=x2; x2=y2; y2=f;
    }

    if (yreverse) {
	f=y1; y1=y2; y2=f;
    }

    if (xreverse) {
	f=x1; x1=x2; x2=f;
    }

    buf = sf_ucharalloc2(n1,n2);

    if (!charin) {
	data = sf_floatalloc2(n1,n2);

	if (GAIN_ALL==panel || panel >= 0) {
	    pos = sf_tell(in);
	    if (panel > 0) sf_seek(in,
				   pos+panel*n1*n2*sizeof(float),
				   SEEK_SET);
	    vp_gainpar (in,data,n1,n2,gainstep,
			pclip,phalf,&clip,&gpow,mean,&pbias,
			n3,panel,panel);
	    if (verb) sf_warning("panel=%d bias=%g clip=%g gpow=%g",
				 panel,pbias,clip,gpow);
	    if (sfbyte) sf_putfloat(out,"clip",clip);
	    sf_seek(in,pos,SEEK_SET); /* rewind */
	}
    }

    if (!sfbyte && !sfbar) {
	/* initialize color table */
	if (NULL == (color = sf_getstring("color"))) color="i";
	/* color scheme (default is i) */
	if (!sf_getint ("nreserve",&nreserve)) nreserve = 8;
	/* reserved colors */
	vp_rascoltab (nreserve, color);
    }

    for (i3=0; i3 < n3; i3++) {	
	if (!charin) {
	    if (GAIN_EACH == panel) {
		if (eclip) clip=0.;
		if (egpow) gpow=0.;
		vp_gainpar (in,data,n1,n2,gainstep,
			    pclip,phalf,&clip,&gpow,
			    mean,&pbias,n3,0,n3);
		if (verb) sf_warning("bias=%g clip=%g gpow=%g",pbias,clip,gpow);
	    } else {
		sf_floatread(data[0],n1*n2,in);
	    }
	    
	    if (1 == panel || GAIN_EACH == panel || 0==i3) { 
		/* initialize the conversion table */
		if(!allpos) { /* negative and positive values */
		    for (it=1; it<=TSIZE/2; it++) {
		        if (symcp) {
			    tbl[TSIZE-it] = (gpow != 1.)?
			        254*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+1.:
			        254*(    ((TSIZE-2.0*it)/TSIZE)      +1.)/2.+1.;
			    tbl[it] = 255 - tbl[TSIZE-it] + 1.0;
			} else {
			    tbl[TSIZE-it] = (gpow != 1.)?
			        252*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+3.:
			        252*(    ((TSIZE-2.0*it)/TSIZE)      +1.)/2.+3.;
			    tbl[it] = 255 - tbl[TSIZE-it] + 2.0;
			}
		    }
		    bias = TSIZE/2.;
		    gain = TSIZE/(2.*clip);
		} else { /* all positive */
		    if (symcp) {
			for (it=1; it < TSIZE ; it++) {
			    tbl[it] = 255*((it-1.0)/TSIZE) + 1.0;
			}
		    } else {
			for (it=1; it < TSIZE ; it++) {
			    tbl[it] = 256*((it-1.0)/TSIZE);
			}
		    }
		    bias = 0.;
		    gain = TSIZE/clip;		
		}
		tbl[0] = tbl[1];
		tbl[TSIZE] = tbl[TSIZE-1];
		if (polarity) { /* switch polarity */
		    for (it=0; it<=TSIZE; it++) {
			tbl[it]=255-tbl[it];
		    }
		}
	    }
	    
	    /* convert to bytes */
	    for (i2=0; i2 < n2; i2++) {
		for (i1=0; i1 < n1; i1++) {
		    j = (data[i2][i1]-pbias)*gain + bias;
		    if      (j < 0) j=0;
		    else if (j > TSIZE) j=TSIZE;
		    buf[i2][i1] = tbl[j];
		}
	    }
	} else {
	    sf_ucharread(buf[0],n1*n2,in);
	}

	if (!sfbyte && !sfbar) {
	    if (yreverse) {
		for (i2=0; i2 < n2; i2++) {
		    for (i1=0; i1 < n1/2; i1++) {			
			tmp = buf[i2][i1];
			buf[i2][i1] = buf[i2][n1-1-i1];
			buf[i2][n1-1-i1] = tmp;
		    }
		}
	    } 
	    
	    if ((xreverse && transp) || (!xreverse && !transp)) {
		for (i2=0; i2 < n2/2; i2++) {
		    for (i1=0; i1 < n1; i1++) {
			tmp = buf[i2][i1];
			buf[i2][i1] = buf[n2-1-i2][i1];
			buf[n2-1-i2][i1] = tmp;
		    }
		}
	    }
	
	    if (i3 > 0) vp_erase (); 	

	    if (framenum) vp_framenum(o3+i3*d3);
	    vp_frame(); 
	    vp_uraster (buf, false, 256, n1, n2, 
			x1, y1, x2, y2, orient);
	    vp_simpleframe();
	}
	
	if (scalebar) {
	    if (!charin) {
		if (nomin) barmin = data[0][0];
		if (nomax) barmax = data[0][0];
		if (nomin || nomax) {
		    for (i2=0; i2 < n2; i2++) {
			for (i1=0; i1 < n1; i1++) {
			    dat = data[i2][i1];
			    if (nomin && barmin > dat) barmin = dat;
			    if (nomax && barmax < dat) barmax = dat;
			}
		    }
		}
		
		for (it=0; it < VP_BSIZE; it++) {
		    if (barreverse) {
			dat = (barmin*it + barmax*(VP_BSIZE-1-it))/(VP_BSIZE-1);
		    } else {
			dat = (barmax*it + barmin*(VP_BSIZE-1-it))/(VP_BSIZE-1);
		    }
		    j = (dat-pbias)*gain + bias;
		    if      (j < 0) j=0;
		    else if (j > TSIZE) j=TSIZE;
		    barbuf[0][it] = tbl[j];
		} 
	    } else {
		sf_floatread(minmax,2,bar);
		sf_ucharread(barbuf[0],VP_BSIZE,bar);

		if (nomin) barmin=minmax[0];
		if (nomax) barmax=minmax[1];
	    }

	    if (sfbyte || sfbar) {
		sf_floatwrite(&barmin,1,bar);
		sf_floatwrite(&barmax,1,bar);
		sf_ucharwrite(barbuf[0],VP_BSIZE,bar);
	    } else {
		if (barreverse) {
		    vp_barframe_init (in,barmax,barmin);
		} else {
		    vp_barframe_init (in,barmin,barmax);
		}
		vp_barraster(VP_BSIZE, barbuf);
	    }
	} /* if scalebar */

	if (sfbyte) {
	    sf_ucharwrite(buf[0],n1*n2,out);
	} else if (!sfbar) {
	    vp_purge();
	} 
    } /* i3 loop */


    exit (0);
}
Beispiel #3
0
int main (int argc, char *argv[])
{
    bool both;
    int ir, nr, n1,n2,n3,n4, m1, m2, m3, n12, n123, nw, nj1, nj2, i3;
    float *u1, *u2, *p;
    sf_file in, out, dip;
    off_t pos=0;
    allpass ap;

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

    if (SF_FLOAT != sf_gettype(in) ||
            SF_FLOAT != sf_gettype(dip)) sf_error("Need float type");

    if (!sf_histint(in,"n1",&n1)) sf_error("Need n1= in input");
    if (!sf_histint(in,"n2",&n2)) n2=1;
    if (!sf_histint(in,"n3",&n3)) n3=1;
    n12 = n1*n2;
    n123 = n12*n3;
    nr = sf_leftsize(in,3);

    if (!sf_histint(dip,"n1",&m1) || m1 != n1)
        sf_error("Need n1=%d in dip",n1);
    if (1 != n2 && (!sf_histint(dip,"n2",&m2) || m2 != n2))
        sf_error("Need n2=%d in dip",n2);
    if (1 != n3 && (!sf_histint(dip,"n3",&m3) || m3 != n3))
        sf_error("Need n3=%d in dip",n3);

    if (!sf_getbool("both",&both)) both=false;
    /* if y, compute both left and right predictions */

    if (1 == n3) {
        n4=0;
        if (both) sf_putint(out,"n3",2);
    } else {
        if (!sf_getint("n4",&n4)) n4=2;
        /* what to compute in 3-D. 0: in-line, 1: cross-line, 2: both */

        if (n4 > 2) n4=2;
        if (2==n4) sf_putint(out,"n4",both? 4:2);

        if (0 != n4 || both) {
            sf_unpipe(in,(off_t) n123*sizeof(float));
            pos = sf_tell(in);
        }
    }

    if (!sf_getint("order",&nw)) nw=1;
    /* accuracy */
    if (!sf_getint("nj1",&nj1)) nj1=1;
    /* in-line aliasing */
    if (!sf_getint("nj2",&nj2)) nj2=1;
    /* cross-line aliasing */

    for (ir=0; ir < nr; ir++) {

        if (1 != n4) { /* in-line */
            u1 = sf_floatalloc(n12);
            u2 = sf_floatalloc(n12);
            p  = sf_floatalloc(n12);

            for (i3=0; i3 < n3; i3++) {
                /* read data */
                sf_floatread(u1,n12,in);

                /* read t-x dip */
                sf_floatread(p,n12,dip);

                ap = allpass_init (nw,nj1,n1,n2,1,p);

                /* apply */
                allpass1(false, false, ap, u1, u2);

                /* write t-x destruction */
                sf_floatwrite(u2,n12,out);
            }

            free(u1);
            free(u2);
            free(p);

        }

        if (0 != n4) { /* cross-line */
            u1 = sf_floatalloc(n123);
            u2 = sf_floatalloc(n123);
            p  = sf_floatalloc(n123);

            /* read data */
            sf_seek(in,pos,SEEK_SET);
            sf_floatread(u1,n123,in);

            /* read t-y dip */
            sf_floatread(p,n123,dip);

            ap = allpass_init(nw,nj2,n1,n2,n3,p);

            /* apply */
            allpass2(false, false, ap, u1, u2);

            /* write t-y destruction */
            sf_floatwrite(u2,n123,out);
        }

        if (!both) continue;

        if (1 != n4) { /* in-line */
            u1 = sf_floatalloc(n12);
            u2 = sf_floatalloc(n12);
            p  = sf_floatalloc(n12);

            sf_seek(in,pos,SEEK_SET);

            for (i3=0; i3 < n3; i3++) {
                /* read data */
                sf_floatread(u1,n12,in);

                /* read t-x dip */
                sf_floatread(p,n12,dip);

                ap = allpass_init (nw,nj1,n1,n2,1,p);

                /* apply */
                allpass1(true, false, ap, u1, u2);

                /* write t-x destruction */
                sf_floatwrite(u2,n12,out);
            }

            free(u1);
            free(u2);
            free(p);
        }

        if (0 != n4) { /* cross-line */
            u1 = sf_floatalloc(n123);
            u2 = sf_floatalloc(n123);
            p  = sf_floatalloc(n123);

            /* read data */
            sf_seek(in,pos,SEEK_SET);
            sf_floatread(u1,n123,in);

            /* read t-y dip */
            sf_floatread(p,n123,dip);

            ap = allpass_init(nw,nj2,n1,n2,n3,p);

            /* apply */
            allpass2(true, false, ap, u1, u2);

            /* write t-y destruction */
            sf_floatwrite(u2,n123,out);
        }
    }

    exit (0);
}
Beispiel #4
0
void mexFunction(int nlhs, mxArray *plhs[], 
		 int nrhs, const mxArray *prhs[])
{
    int taglen, status, argc=2, dim, n[SF_MAX_DIM], i, esize, len;
    size_t nbuf = BUFSIZ, nd, j;
    char *tag, *argv[] = {"matlab","-"}, *par;
    double *pr, *pi=NULL;
    char buf[BUFSIZ];
    off_t pos;
    static off_t shift=0;
    bool same;
    sf_datatype type;
    sf_file file;

    /* Check for proper number of arguments. */
    if (nrhs < 2 || nrhs > 3) mexErrMsgTxt("Two or three inputs required.");

    /* Second input must be a string. */
    if (!mxIsChar(prhs[1]))
	mexErrMsgTxt("Second input must be a string.");

    /* Second input must be a row vector. */
    if (mxGetM(prhs[1]) != 1)
	mexErrMsgTxt("Second input must be a row vector.");

    /* Get the length of the input string. */
    taglen = mxGetN(prhs[1]) + 1;

    /* Allocate memory for input string. */
    tag = mxCalloc(taglen, sizeof(char));

    /* Copy the input filename into a C string. */
    status = mxGetString(prhs[1], tag, taglen);
    if (status != 0) 
	mexWarnMsgTxt("Not enough space. String is truncated.");

    if (3 == nrhs) {
        /* Input 3 must be a string. */
	if (!mxIsChar(prhs[2]))
	    mexErrMsgTxt("Input 3 must be a string.");

	/* Input 3 must be a row vector. */
	if (mxGetM(prhs[2]) != 1)
	    mexErrMsgTxt("Input 3 must be a row vector.");

	/* Get the length of the input string. */
	len = mxGetN(prhs[2]) + 1;

	/* Allocate memory for input string. */
	par = mxCalloc(len, sizeof(char));

	/* Copy the string data from prhs[2] into a C string. */
	status = mxGetString(prhs[2], par, len);
	if (status != 0) 
	    mexWarnMsgTxt("Not enough space. String is truncated.");

	same = (0 == (strncmp(par,"same",4)));
    } else {
	same = false;
    }

    sf_init(argc,argv);
    file = sf_input(tag);

    dim = sf_filedims(file,n);
    type = sf_gettype (file);
    esize = sf_esize(file);

    /* data pointers */
    pr = mxGetPr(prhs[0]);

    /* get data size */
    nd = mxGetNumberOfElements(prhs[0]);

    pos = sf_tell(file);
    if (same) sf_seek(file,shift,SEEK_CUR);

    for (j=0, nbuf /= esize; nd > 0; nd -= nbuf) {
	if (nbuf > nd) nbuf=nd;

	switch(type) {
	    case SF_FLOAT:
		if (!mxIsDouble(prhs[0])) mexErrMsgTxt("First input must be double.");

		sf_floatread((float*) buf,nbuf,file);
		for (i=0; i < nbuf; i++, j++) {
		    pr[j] = (double) ((float*) buf)[i];
		}
		break;
	    case SF_INT:
		if (!mxIsDouble(prhs[0])) mexErrMsgTxt("First input must be double.");

		sf_intread((int*) buf,nbuf,file);
		for (i=0; i < nbuf; i++, j++) {
		    pr[j] = (double) ((int*) buf)[i];
		}
		break;
	    case SF_COMPLEX:
		if(!mxIsComplex(prhs[0])) mexErrMsgTxt("First input must be complex.");

		pi = mxGetPi(prhs[0]);

		sf_complexread((sf_complex*) buf,nbuf,file);
		for (i=0; i < nbuf; i++, j++) {
		    pr[j] = (double) crealf(((sf_complex*) buf)[i]);
		    pi[j] = (double) cimagf(((sf_complex*) buf)[i]);
		}
		break;
	    default:
		mexErrMsgTxt("Unsupported file type.");
		break;
	}
    }

    shift = sf_tell(file) - pos;
    sf_close();
}
Beispiel #5
0
int main(int argc, char* argv[])
{

    off_t pos;
    bool sign, half;
    int   nsx, nsy,   nmx, nmy,   nhx, nhy,   nmhx, nmhy,   nt;
    int   isx, isy,   imx, imy,   ihx, ihy;
    float osx, osy, dsx, dsy, omx, omy, dmx, dmy, ohx, ohy, dhx, dhy, dmhx, dmhy, binx, biny;
    float s_xmin, s_ymin, r_xmin, r_ymin, s_xmax, s_ymax, r_xmax, r_ymax, survey_xmin, survey_ymin, survey_xmax, survey_ymax;
    char *trace, *zero;
    sf_file in, out;


    sf_init(argc,argv);
    in  = sf_input ( "in");
    out = sf_output("out");
    sf_warning("WARNING: This 3-D CMP sorting code is not yet ready for use--this message will be removed when it is. ");

    if (!sf_histint  (in,"n1",&nt)) sf_error("No n1= in input");
    /* Number of samples per trace */

    if (!sf_histint  (in,"n2",&nhx)) sf_error("No n2= in input");
    /* Number of offsets per shot gather in x-direction*/
    if (!sf_histfloat(in,"o2",&ohx)) sf_error("No o2= in input");
    /* First offset x-component */
    if (!sf_histfloat(in,"d2",&dhx)) sf_error("No d2= in input");
    /* Offset increment in x-direction */
    if (!sf_histint  (in,"n3",&nhy)) sf_error("No n3= in input");
    /* Number of offsets per shot gather in y-direction*/
    if (!sf_histfloat(in,"o3",&ohy)) sf_error("No o3= in input");
    /* First offset y-component */
    if (!sf_histfloat(in,"d3",&dhy)) sf_error("No d3= in input");
    /* Offset increment in y-direction */
    if (!sf_histint  (in,"n4",&nsx)) sf_error("No n4= in input");
    /* Number of sources along x-direction*/
    if (!sf_histfloat(in,"d4",&dsx)) sf_error("No d4= in input");
    /* Source spacing in x-direction*/
    if (!sf_histfloat(in,"o4",&osx)) sf_error("No o4= in input");
    /* First source x-coordinate*/
    if (!sf_histint  (in,"n5",&nsy)) sf_error("No n5= in input");
    /* Number of sources along y-direction*/
    if (!sf_histfloat(in,"d5",&dsy)) sf_error("No d5= in input");
    /* Source spacing in y-direction*/
    if (!sf_histfloat(in,"o5",&osy)) sf_error("No o5= in input");
    /* First source y-coordinate*/
    
    if (!sf_getfloat("binx",&binx)) sf_error("No x bin size specified. Please set binx=");
    /*Number of bins along x-direction*/
    if (!sf_getfloat("biny",&biny)) sf_error("No y bin size specified. Please set biny=");
    /*Number of bins along y-direction*/

    if (!sf_getbool("positive",&sign)) sign=true;
    /* initial offset orientation:
       yes is generally for off-end surveys, where the first offsets are positive.  
       no is generally for split-spread surveys with first negative then positive offsets. */

    if (!sf_getbool("half",&half)) half=true;
    /* if y, the second axis is half-offset instead of full offset*/

    if (!half) {
	dhx /= 2;
	ohx /= 2;
	dhy /= 2;
	ohy /= 2;
    }

    s_xmin = osx;
    s_ymin = osy;
    s_xmax = osx+(nsx*dsx);
    s_ymax = osy+(nsy*dsy);
    
    r_xmin = s_xmin+2*ohx;
    r_ymin = s_ymin+2*ohy;
    r_xmax = s_xmax+2*(ohx+dhx*nhx);
    r_ymax = s_ymax+2*(ohy+dhy*nhy);

    if (s_xmin <= r_xmin){
      survey_xmin = s_xmin;
    }else{
      survey_xmin = r_xmin;
    }

    if (s_ymin <= r_ymin){
      survey_ymin = s_ymin;
    }else{
      survey_ymin = r_ymin;
    }

    if (s_xmax <= r_xmax){
      survey_xmax = r_xmax;
    }else{
      survey_xmax = s_xmax;
    }

    if (s_ymax <= r_ymax){
      survey_ymax = r_ymax;
    }else{
      survey_ymax = s_ymax;
    }
    
    dmx = (survey_xmax - survey_xmin)/binx;
    dmy = (survey_ymax - survey_ymin)/biny;
    omx = survey_xmin + dmx/2.;
    omy = survey_ymin + dmy/2.;
    nmx = binx;
    nmy = biny;
    nmhx = (int)(nhx*nsx/nmx);
    nmhy = (int)(nhy*nsy/nmy);
    dmhx = dhx;
    dmhy = dhy;

    sf_putint  (out,"n2",nmhx);
    sf_putint  (out,"n3",nmhy);
    sf_putfloat(out,"d2",dmhx);
    sf_putfloat(out,"d3",dmhy);

    sf_putint  (out,"n4",nmx);
    sf_putint  (out,"n5",nmy);
    sf_putfloat(out,"d4",dmx);
    sf_putfloat(out,"d5",dmy);
    sf_putfloat(out,"o4",omx);
    sf_putfloat(out,"o5",omy);

    sf_putstring(out,"label3","hx");
    sf_putstring(out,"label4","hy");
    sf_putstring(out,"label5","mx");
    sf_putstring(out,"label6","my");
    
    nt *= sf_esize(in);

    trace = sf_charalloc(nt);
    zero  = sf_charalloc(nt);
    memset(zero,0,nt);

    sf_fileflush(out,in);
    sf_setform( in,SF_NATIVE);
    sf_setform(out,SF_NATIVE);
    
    sf_unpipe(in,(off_t) nsx*nsy*nhx*nhy*nt);
    pos = sf_tell(in);

    for (isx=0; isx < nsx; isx++) {
      for (isy=0; isy < nsy; isy++) {

	for (ihx=0; ihx < nhx; ihx++) {
	  for (ihy=0; ihy < nhy; ihy++) {

	    imx = (int)((isx + ihx)/2.0);
	    imy = (int)((isy + ihy)/2.0);

	    if (isx >= 0 && isx < nsx && ihx < nhx) {
	      if (isy >= 0 && isy < nsy && ihy < nhy) {
		sf_seek(in,pos+((isx*nhx+ihx)+(isy*nhy+ihy))*nt,SEEK_SET);
		sf_charread(trace,nt,in);
		sf_charwrite(trace,nt,out);
	      }
	    } else {
		sf_charwrite(zero,nt,out);
	    }
	  }
	}
      }
    }


    exit(0);
}
Beispiel #6
0
int main(int argc, char* argv[])
{
    sf_file in, out;
    char *buf, *buf2, key[5];
/* Want them to be arbitrary, neither float nor complex */
/* Just pretend they are character pointers so we multiply offsets ourselves.*/
    int i, dim, dim1, dim2, rot[SF_MAX_DIM], esize;
    int mem; /* for avoiding int to off_t typecast warning */
    off_t n[SF_MAX_DIM], pos=0, pos3=0, memsize, *k1 = NULL, *k2 = NULL;
    size_t n1, i1, i2, i3, n2, n3, size;
    bool verb;

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

    dim   = sf_largefiledims(in,n);
    esize = sf_esize(in);

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

    if (!sf_getint("memsize",&mem))
        mem=sf_memsize();
    /* Max amount of RAM (in Mb) to be used */
    memsize = (off_t) mem * (1<<20); /* convert Mb to bytes */

    dim2=0;
    for (i=0; i < dim; i++) {	
	snprintf(key,5,"rot%d",i+1);
	if (!sf_getint(key,rot+i)) rot[i]=0;
	/*( rot#=(0,0,...) length of #-th axis that is moved to the end )*/
	if (rot[i] < 0) rot[i] += n[i];
	if (rot[i] >= n[i]) 
	    sf_error("rot%d=%d must be smaller than n%d=%d",
		     i,rot[i],i,n[i]);
	if (rot[i]) dim2=i;
    }
    dim2++;
    /* dim2 is the last dimension involved */

    sf_fileflush(out,in);
    sf_setform(in,SF_NATIVE);
    sf_setform(out,SF_NATIVE);

    n1=n2=n3=1;
    dim1=0;
    for (i=0; i < dim; i++) {
	if (i < dim2) {
	    size = n1*n[i];
	    if (1==n2 && size*esize < memsize) {
		n1=size;
		dim1=i;
	    } else {
		n2*=n[i];
	    }
	} else {
	    n3 *= n[i];
	}
    }
    dim1++;
    /* dim1 is the last dimension that fits in memory,
       n1 is the size up to this dimension
       n2 is the size of other dimensions involved 
       n3 is the size of all other dimensions so that
       n1*n2*n3 is the total data size
    */
    
    buf  = sf_charalloc(n1*esize);
    buf2 = sf_charalloc(n1*esize);

    if (n1>1) {
	k1 = sf_largeintalloc(n1);
	rotate(n1,dim1,n,rot,k1);
    }

    if (n2>1) {
	if (verb) sf_warning("Going out of core...");

	sf_unpipe(in,n1*n2*n3*esize); /* prepare for random access */
	pos = sf_tell(in);

	k2 = sf_largeintalloc(n2);
	rotate(n2,dim2-dim1,n+dim1,rot+dim1,k2);
    } 

    if (verb) sf_warning("n1=%d, n2=%d, n3=%d",
			 (int) n1,(int) n2,(int) n3);

    /* k1 is a table for in-core     reversal 
       k2 is a table for out-of-core reversal */
    
    for (i3=0; i3 < n3; i3++) {
	if (n2 > 1) pos3 = pos+(off_t) i3*n2*n1*esize;
	for (i2=0; i2 < n2; i2++) {
	    if (n2 > 1) /* if out of core */
		sf_seek(in,pos3+k2[i2]*n1*esize,SEEK_SET);

	    sf_charread(buf,n1*esize,in);
	    for (i1=0; i1 < n1; i1++) {
		memcpy(buf2+k1[i1]*esize,buf+i1*esize,esize);
	    }
	    sf_charwrite(buf2,n1*esize,out);
	}
    }
    

    exit (0);
}