Ejemplo n.º 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);
}
Ejemplo n.º 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);
}
Ejemplo n.º 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);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
0
int main(int argc, char* argv[])
{
    int n1,n2,n3, frame2,frame3, i1,i2,i3, iframe, np=3, orient;
    int n1pix,n2pix, m1pix,m2pix, n1front,n2front, movie, nframe=1; 
    float point1, point2, **front, **side, **top, **topt, *x, *y, o1, d1, o2, d2;    
    float min, max, f, frame1, dframe, oo1, dd1;
    bool nomin, nomax, yreverse;
    char *label1, *label2, *unit1, *unit2;
    off_t esize;
    bool flat;
    vp_contour cnt;
    sf_file in=NULL;

    sf_init(argc,argv);
    in = sf_input("in");
    vp_init();

    if (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);

    esize = sf_esize(in);
    sf_unpipe(in,n1*n2*n3*esize);

    if (!sf_getint("orient",&orient)) orient=1;
    /* function orientation */

    if (!sf_getbool("yreverse",&yreverse)) yreverse=false;

    front = sf_floatalloc2(n1,1);
    side = sf_floatalloc2(1,n2);
    top = sf_floatalloc2(n1,n2);
    topt = (2==orient)? sf_floatalloc2(n2,n1): NULL;

    nomin = (bool) !sf_getfloat("min",&min);
    /* minimum function value */
    nomax = (bool) !sf_getfloat("max",&max);
    /* maximum function value */

    if (nomin) min = +FLT_MAX;
    if (nomax) max = -FLT_MAX;
    if (nomin || nomax) {
	for (i3=0; i3 < n3; i3++) {
	    sf_floatread(top[0],n1*n2,in);
	    for (i2=0; i2 < n2; i2++) {
		for (i1=0; i1 < n1; i1++) {
		    f = top[i2][i1];
		    if (nomax && f > max) max=f;
		    if (nomin && f < min) min=f;
		}
	    }
	}
    }


    if (min == 0. && max == 0.) {
	min = -1.;
	max = 1.;
    } else if (min == max) {
        max *= 1.04;
        min *= 0.96;
    }

    if (!sf_histfloat(in,"o1",&o1)) o1=0.;
    if (!sf_histfloat(in,"d1",&d1)) d1=1.;
    if (!sf_histfloat(in,"o2",&o2)) o2=0.;
    if (!sf_histfloat(in,"d2",&d2)) d2=1.;

    switch(orient) {
	case 1:
	default:    
	    dd1 = (min-max)/np;
	    oo1 = max+0.5*dd1;

	    sf_putint(in,"n1",np);
	    sf_putfloat(in,"o1",oo1);
	    sf_putfloat(in,"d1",dd1);

	    sf_putint(in,"n2",n1);
	    sf_putfloat(in,"o2",o1);
	    sf_putfloat(in,"d2",d1);

	    sf_putint(in,"n3",n2);
	    sf_putfloat(in,"o3",o2);
	    sf_putfloat(in,"d3",d2);

	    break;
	case 2:
	    dd1 = (max-min)/np;
	    oo1 = min+0.5*dd1;

	    sf_putint(in,"n2",np);
	    sf_putfloat(in,"o2",oo1);
	    sf_putfloat(in,"d2",dd1);

	    sf_putint(in,"n3",n2);
	    sf_putfloat(in,"o3",o2);
	    sf_putfloat(in,"d3",d2);

	    break;
	case 3:
	    dd1 = (max-min)/np;
	    oo1 = min+0.5*dd1;

	    sf_putint(in,"n1",n2);
	    sf_putfloat(in,"o1",o2);
	    sf_putfloat(in,"d1",d2);

	    sf_putint(in,"n2",n1);
	    sf_putfloat(in,"o2",o1);
	    sf_putfloat(in,"d2",d1);

	    sf_putint(in,"n3",np);
	    sf_putfloat(in,"o3",oo1);
	    sf_putfloat(in,"d3",dd1);

	    break;
    }

    label1 = sf_histstring(in,"label1");
    label2 = sf_histstring(in,"label2");

    if (NULL != label1) {
	sf_putstring(in,"label1","");
	sf_putstring(in,"label2",label1);
	free(label1);
    }
    if (NULL != label2) {
	sf_putstring(in,"label3",label2);
	free(label2);
    }

    unit1 = sf_histstring(in,"unit1");
    unit2 = sf_histstring(in,"unit2");

    if (NULL != unit1) {
	sf_putstring(in,"unit1","");
	sf_putstring(in,"unit2",unit1);
	free(unit1);
    }
    if (NULL != unit2) {
	sf_putstring(in,"unit3",unit2);
	free(unit2);
    }

    if (!sf_getfloat("point1",&point1)) point1=0.5;
    /* fraction of the vertical axis for front face */
    if (!sf_getfloat("point2",&point2)) point2=0.5;
    /* fraction of the horizontal axis for front face */

    if (!sf_getfloat("frame1",&frame1)) frame1=0.5*(min+max);
    if (!sf_getint("frame2",&frame2)) frame2=n1-1;
    if (!sf_getint("frame3",&frame3)) frame3=0;
    /* frame numbers for cube faces */

    /* sanity check */
    if (min < max) {
	if (frame1 < min) frame1 = min;
	if (frame1 > max) frame1 = max;
    } else {
	if (frame1 > min) frame1 = min;
	if (frame1 < max) frame1 = max;
    }
    if (frame2 < 0) frame2 = 0;
    if (frame3 < 0) frame3 = 0;
    if (frame2 >= n1) frame2 = n1-1;
    if (frame3 >= n2) frame3 = n2-1;

    if (!sf_getint("movie",&movie)) movie=0;
    /* 0: no movie, 1: movie over axis 1, 2: axis 2, 3: axis 3 */

    if (!sf_getfloat("dframe",&dframe)) dframe=1;
    /* frame increment in a movie */

    switch (movie) {
	case 0:
	    nframe = 1;
	    break;
	case 1:
	    nframe = 0.5+(max-frame1)/dframe;
	    break;
	case 2:
	    nframe = (n1-frame2)/dframe;
	    break;
	case 3:
	    nframe = (n2-frame3)/dframe;
	    break;
	default:
	    sf_error("movie=%d is outside [0,3]",movie);
	    break;
    }

    if (sf_getint("nframe",&iframe) && iframe < nframe) nframe=iframe;
    /* number of frames in a movie */

    if (nframe < 1) nframe=1;

    if (!sf_getint("n1pix",&n1pix)) n1pix = n1/point1+n3/(1.-point1);
    /* number of vertical pixels */
    if (!sf_getint("n2pix",&n2pix)) n2pix = n2/point2+n3/(1.-point2);
    /* number of horizontal pixels */

    m1pix = VP_STANDARD_HEIGHT*72;
    m2pix = VP_STANDARD_HEIGHT*72/VP_SCREEN_RATIO;

    if (n1pix < m1pix) n1pix=m1pix;
    if (n2pix < m2pix) n2pix=m2pix;

    n1front = n1pix*point1;
    n2front = n2pix*point2;

    if (n1front <= 0) n1front=1;
    if (n2front <= 0) n2front=1;
    if (n1front >= n1pix) n1front=n1pix-1;
    if (n2front >= n2pix) n2front=n2pix-1;

    x = sf_floatalloc(n1);
    y = sf_floatalloc(n2);

    for (i1=0; i1 < n1; i1++) {
	x[i1] = o1 + i1*d1;
    }

    for (i2=0; i2 < n2; i2++) {
	y[i2] = o2 + i2*d2;
    }

    if (!sf_getbool("flat",&flat)) flat=true;
    /* if n, display perspective view */

    vp_cubeplot_init (n1pix, n2pix, n1front, n2front, flat, false); 
    vp_frame_init (in,"blt",false);
    vp_plot_init(n3);
    cnt = vp_contour_init(false,
			  n1,o1,d1,0.,
			  n2,o2,d2,0.); 

    for (iframe=0; iframe < nframe; iframe++) {
	if (iframe > 0) vp_erase (); 

	for (i3=0; i3 < n3; i3++) {
	    vp_plot_set (i3);

	    /* front face */

	    switch(orient) {
		case 1:
		default:
		    sf_seek(in,(off_t) (i3*n1*n2+frame3*n1)*esize,SEEK_SET);
		    sf_floatread(front[0],n1,in);
		    
		    vp_cubecoord(3,x[0],x[n1-1],min,max);
		    vp_umove(x[0],front[0][0]);
		    for (i1=1; i1 < n1; i1++) {
			vp_udraw(x[i1],front[0][i1]);
		    }

		    break;
		case 2:
		    sf_seek(in,(off_t) (i3*n1*n2+frame3*n1)*esize,SEEK_SET);
		    sf_floatread(front[0],n1,in);

		    if (yreverse) {
			vp_cubecoord(3,min,max,x[n1-1],x[0]);
			vp_umove(front[0][n1-1],x[n1-1]);
			for (i1=n1-2; i1 >= 0; i1--) {
			    vp_udraw(front[0][i1],x[i1]);
			}
		    } else {
			vp_cubecoord(3,min,max,x[0],x[n1-1]);
			vp_umove(front[0][0],x[0]);
			for (i1=1; i1 < n1; i1++) {
			    vp_udraw(front[0][i1],x[i1]);
			}
		    }
		    
		    break;
		case 3:
		    sf_seek(in,(off_t) (i3*n1*n2*esize),SEEK_SET);
		    sf_floatread(top[0],n1*n2,in);

		    vp_cubecoord(3,x[0],x[n1-1],y[0],y[n2-1]);
		    vp_contour_draw(cnt,false,top,frame1);

		    break;
	    }
		    

	    /* side face */

	    switch(orient) {
		case 1:
		default:	    
		    for (i2=0; i2 < n2; i2++) {
			sf_seek(in,(off_t) (i3*n1*n2+i2*n1+frame2)*esize,SEEK_SET);
			sf_floatread(side[i2],1,in);
		    }
		    
		    vp_cubecoord(2,y[0],y[n2-1],min,max);
		    vp_umove(y[0],side[0][0]);
		    for (i2=1; i2 < n2; i2++) {
			vp_udraw(y[i2],side[i2][0]);
		    }

		    break;
		case 2:
		    sf_seek(in,(off_t) (i3*n1*n2*esize),SEEK_SET);
		    sf_floatread(top[0],n1*n2,in);

		    /* transpose */
		    for (i2=0; i2 < n2; i2++) {
			for (i1=0; i1 < n1; i1++) {
			    topt[i1][i2] = top[i2][i1];
			}
		    }
		    
		    if (yreverse) {
			vp_cubecoord(2,y[0],y[n2-1],x[n1-1],x[0]);
		    } else {
			vp_cubecoord(2,y[0],y[n2-1],x[0],x[n1-1]);
		    }
		    vp_contour_draw(cnt,false,topt,frame1);
		    
		    break;
		case 3:
		    for (i2=0; i2 < n2; i2++) {
			sf_seek(in,(off_t) (i3*n1*n2+i2*n1+frame2)*esize,SEEK_SET);
			sf_floatread(side[i2],1,in);
		    }
		    
		    vp_cubecoord(2,min,max,y[0],y[n2-1]);
		    vp_umove(side[0][0],y[0]);
		    for (i2=1; i2 < n2; i2++) {
			vp_udraw(side[i2][0],y[i2]);
		    }

		    break;
	    }

	    /* top face */

	    switch(orient) {
		case 1:
		default:
		    sf_seek(in,(off_t) (i3*n1*n2*esize),SEEK_SET);
		    sf_floatread(top[0],n1*n2,in);
		    
		    vp_cubecoord(1,x[0],x[n1-1],y[0],y[n2-1]);
		    vp_contour_draw(cnt,false,top,frame1);

		    break;
		case 2:
		    for (i2=0; i2 < n2; i2++) {
			sf_seek(in,(off_t) (i3*n1*n2+i2*n1+frame2)*esize,SEEK_SET);
			sf_floatread(side[i2],1,in);
		    }
		    
		    vp_cubecoord(1,min,max,y[0],y[n2-1]);
		    vp_umove(side[0][0],y[0]);
		    for (i2=1; i2 < n2; i2++) {
			vp_udraw(side[i2][0],y[i2]);
		    }
		    
		    break;
		case 3:
		    sf_seek(in,(off_t) (i3*n1*n2+frame3*n1)*esize,SEEK_SET);
		    sf_floatread(front[0],n1,in);
		    
		    vp_cubecoord(1,x[0],x[n1-1],min,max);
		    vp_umove(x[0],front[0][0]);
		    for (i1=1; i1 < n1; i1++) {
			vp_udraw(x[i1],front[0][i1]);
		    }

		    break;
	    }
	}
	
	vp_plot_unset();
	vp_coordinates();

	switch(orient) {
	    case 1:
	    default:
		vp_cubeframe((frame1-oo1)/dd1,frame2,frame3);
		break;
	    case 2:
		vp_cubeframe(frame2,(frame1-oo1)/dd1,frame3);
		break;
	    case 3:
		vp_cubeframe(frame2,frame3,(frame1-oo1)/dd1);
		break;
	}
	
	switch (movie) {
	    case 2:
		frame2 += (int) dframe;
		break;
	    case 3:
		frame3 += (int) dframe;
		break;
	    case 1:
		frame1 += dframe;
		break;
	    default:
		break;
	}

	vp_purge(); 
    } /* frame loop */


    exit(0);
}