示例#1
0
main(int argc, char **argv)
{
	FILE *infp=stdin, *outfp=stdout;
	usghed usgh;
	int ierr;

	float *grid, *g, *g1;

	int i1, i2, i3;
	int k1, k2, k3;
	int h1, h2, h3;
	int n1, n2, n3;
	int j1, j2, j3;
	int m1, m2, m3;
	int i;
	float gmin, gmax;
	float tmp;
	int op, w1, w2, w3;
	int nz, iz;

	int si1, si2, si3, ni1, ni2, ni3;

    	/* initialization */
    	initargs(argc,argv);
    	askdoc(1);

	/* large than 2 GB files */
	file2g(infp);
	file2g(infp);

	/* read in the grid header */
	ierr = fgetusghdr(infp, &usgh);
	if(ierr!=0) err("non standard grid header input ");

	/* get the dimensions of input grid */
	n1 = usgh.n1;
	n2 = usgh.n2;
	n3 = usgh.n3;

	/* get input parameters */
	if (!getparint("op",&op)) op = 0;
	if (!getparint("w1",&w1)) w1 = 5;
	if (!getparint("w2",&w2)) w2 = 5;
	if (!getparint("w3",&w3)) w3 = 5;
	if(w1<1) w1 = 1; if(w1>n1) w1 = n1;
	if(w2<1) w2 = 1; if(w2>n2) w2 = n2;
	if(w3<1) w3 = 1; if(w3>n3) w3 = n3;

	if (!getparint("si1",&si1)) si1 = 1; if(si1<1)si1=1; if(si1>n1)si1=n1;
	if (!getparint("si2",&si2)) si2 = 1; if(si2<1)si2=1; if(si2>n2)si2=n2;
	if (!getparint("si3",&si3)) si3 = 1; if(si3<1)si3=1; if(si3>n3)si3=n3;
	if (!getparint("ni1",&ni1)) ni1 = n1; if(ni1<1)ni1=1;if(ni1>n1)ni1=n1;
	if (!getparint("ni2",&ni2)) ni2 = n2; if(ni2<1)ni2=1;if(ni2>n2)ni2=n2;
	if (!getparint("ni3",&ni3)) ni3 = n3; if(ni3<1)ni3=1;if(ni3>n3)ni3=n3;

	/* memory allocations */
	if(n1*n2*n3>1024*1024*1024/4) 
		err(" input grid too big; subsample recommended \n");

        grid = (float*)emalloc(n1*n2*n3*sizeof(float));
        g = (float*)emalloc(w1*w2*w3*sizeof(float));
	g1 = (float*) emalloc(n1*sizeof(float));

	fseek64(infp,0,0);
	efread(grid,sizeof(float),n1*n2*n3,infp);

	h1 = w1/2;
	h2 = w2/2;
	h3 = w3/2;

	nz = w1*w2*w3;
	iz = (50*nz/100.);

	si1 = si1 - 1;
	si2 = si2 - 1;
	si3 = si3 - 1;

	for (i3=0;i3<n3;i3++) {
	for (i2=0;i2<n2;i2++) {

	    k3 = i3 - h3;
	    k2 = i2 - h2;

	    for(i1=0;i1<n1;i1++) g1[i1] = grid[i1+i2*n1+i3*n1*n2];

	    if( i2>=si2 && i2<ni2 && i3>=si3 && i3<ni3 ) {

	    for (i1=si1-1;i1<ni1;i1++) {

	        i = 0;
		k1 = i1 - h1;

		for (j3=k3;j3<k3+w3;j3++) {
		    m3=j3; 
		    if(m3<0)m3=0;
		    if(m3>n3-1)m3=n3-1;

		    for (j2=k2;j2<k2+w2;j2++) {
		    	m2=j2; 
		        if(m2<0)m2=0;
		        if(m2>n2-1)m2=n2-1;

			for (j1=k1;j1<k1+w1;j1++) {
		    	    m1=j1; 
		            if(m1<0)m1=0;
		            if(m1>n1-1)m1=n1-1;

			    g[i] = grid[m1+m2*n1+m3*n1*n2];
			    i = i + 1;

			}
		    }
		}
		if(op==0) {
			qkfind(iz,nz,g);
			g1[i1] = g[iz];
		} else if(op==1) {
			tmp = 0.;
			for(i=0;i<nz;i++) {
				tmp = tmp + g[i];
			}
			g1[i1] = tmp/nz;
		}
	    }
	    }
	    if(i2==0 && i3==0) {
		gmin = g1[0];
		gmax = g1[0];
	    }
	    for(i1=0;i1<n1;i1++) {
		if(gmin>g1[i1]) gmin = g1[i1];
		if(gmax<g1[i1]) gmax = g1[i1];
	    }
	    fwrite(g1,sizeof(float),n1,outfp);
	}
	}

	/* update the output gridheader header */
	usgh.gmin = gmin;
	usgh.gmax = gmax;

	/* output the grid header */
	ierr = fputusghdr(outfp, &usgh);
	if(ierr!=0) err("output grid header error ");


	free(grid);
	free(g);
	free(g1);

	exit(0);

}
示例#2
0
int
main (int argc, char **argv)
{
	int n1,n2,n1tic,n2tic,nfloats,bbox[4],
		i1,i2,grid1,grid2,style,
		i3,n3,notitle2=0,
		n1c,n2c,n1s,n2s,i1beg,i1end,i2beg,i2end,i1c,i2c,
		n1dsp=0,n2dsp=0,n3dsp=0,loopdsp,
		nz,iz,i1step,i2step,verbose;
	float labelsize,titlesize,perc,clip,bperc,wperc,bclip,wclip,
		d1,f1,d2,f2,*z,*temp,zscale,zoffset,zi,
		f3,d3,f3s,
		xbox,ybox,wbox,hbox,
		x1beg,x1end,x2beg,x2end,
		x1min,x1max,x2min,x2max,
		d1num,f1num,d2num,f2num,
		p1beg,p1end,p2beg,p2end,matrix[6],
		d1s,d2s;
	unsigned char *cz,*czp,*sz;
	char *label1="",*label2="",*title="",*title2="",
		*labelfont="Helvetica",*titlefont="Helvetica-Bold",
		*styles="seismic",*grid1s="none",*grid2s="none";
	char title2s[80],c80[80];
	FILE *infp=stdin;

	/* initialize getpar */
	initargs(argc,argv);
	requestdoc(1);

	/* get parameters describing 1st dimension sampling */
	if (!getparint("n1",&n1)) err("must specify n1!\n");
	if (!getparfloat("d1",&d1)) d1 = 1.0;
	if (!getparfloat("f1",&f1)) f1 = 0.0;

	/* get parameters describing 2nd dimension sampling */
	if (!getparint("n2",&n2)) {
		if (efseeko(infp,(off_t) 0,SEEK_END)!=0)
			err("must specify n2 if in a pipe!\n");
		nfloats = (int) (eftello(infp)/((off_t) sizeof(float)));
		efseeko(infp,(off_t) 0,SEEK_SET);
		n2 = nfloats/n1;
		n3 = 1;
	}
	if (!getparfloat("d2",&d2)) d2 = 1.0;
	if (!getparfloat("f2",&f2)) f2 = 0.0;

	/* get parameters describing 3rd dimension sampling */
	if (!getparint("n3",&n3)) {
		if (efseeko(infp,(off_t) 0,SEEK_END)!=0)
			err("must specify n3 if in a pipe!\n");
		nfloats = (int) (eftello(infp)/((off_t) sizeof(float)));
		efseeko(infp,(off_t) 0,SEEK_SET);
		n3 = nfloats/n1/n2;
	}
	if (!getparfloat("d3",&d3)) d3 = 1.0;
	if (!getparfloat("f3",&f3)) f3 = d3;

	/* set up desired looping mode */
	if (!getparint("loopdsp",&loopdsp)) loopdsp = 3;
	if (loopdsp == 3) {
		n1dsp = n1;
		n2dsp=n2;
		n3dsp=n3;
	} else if (loopdsp == 1) {
		n1dsp = n2;
		n2dsp=n3;
		n3dsp=n1;
	} else if (loopdsp == 2) {
		n1dsp = n1;
		n2dsp=n3;
		n3dsp=n2;
	}

	x1min = (d1>0.0)?f1:f1+(n1dsp-1)*d1;
	x1max = (d1<0.0)?f1:f1+(n1dsp-1)*d1;
	x2min = (d2>0.0)?f2:f2+(n2dsp-1)*d2;
	x2max = (d2<0.0)?f2:f2+(n2dsp-1)*d2;

	/* read binary data to be plotted */
	nz = n1*n2*n3;
	z = ealloc1float(nz);
	if (fread(z,sizeof(float),nz,infp)!=nz)
		err("error reading input file!\n");

	/* if necessary, determine clips from percentiles */
	if (getparfloat("clip",&clip)) {
		bclip = clip;
		wclip = -clip;
	}
	if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) &&
		!getparfloat("clip",&clip)) {
		perc = 100.0;  getparfloat("perc",&perc);
		temp = ealloc1float(nz);
		for (iz=0; iz<nz; iz++)
			temp[iz] = z[iz];
		if (!getparfloat("bclip",&bclip)) {
			bperc = perc;	getparfloat("bperc",&bperc);
			iz = (nz*bperc/100.0);
			if (iz<0) iz = 0;
			if (iz>nz-1) iz = nz-1;
			qkfind(iz,nz,temp);
			bclip = temp[iz];
		}
		if (!getparfloat("wclip",&wclip)) {
			wperc = 100.0-perc;  getparfloat("wperc",&wperc);
			iz = (nz*wperc/100.0);
			if (iz<0) iz = 0;
			if (iz>nz-1) iz = nz-1;
			qkfind(iz,nz,temp);
			wclip = temp[iz];
		}
		free1float(temp);
	}

	/* transpose data if needed */
	if (loopdsp == 1) {
		temp = ealloc1float(nz);
		for (iz=0;iz<nz;iz++) temp[iz] = z[iz];
		for (i3=0;i3<n3;i3++) {
			for (i2=0;i2<n2;i2++) {
		 		for(i1=0;i1<n1;i1++) {
		    			z[i2+i3*n2+i1*n2*n3]
						= temp[i1+i2*n1+i3*n1*n2];
				}
			}
		}
		free1float(temp);
	} else if (loopdsp == 2) {
		temp = ealloc1float(nz);
		for (iz=0;iz<nz;iz++) temp[iz] = z[iz];
		for (i3=0;i3<n3;i3++) {
			for (i2=0;i2<n2;i2++) {
				for(i1=0;i1<n1;i1++) {
					z[i1+i3*n1+i2*n1*n3]
						= temp[i1+i2*n1+i3*n1*n2];
				}
			}
		}
		free1float(temp);
	}

	verbose = 1;  getparint("verbose",&verbose);
	if (verbose) warn("bclip=%g wclip=%g",bclip,wclip);

	/* get scaled sampling intervals */
	d1s = 1.0;  getparfloat("d1s",&d1s);
	d2s = 1.0;  getparfloat("d2s",&d2s);
	d1s = fabs(d1s);  d1s *= d1;
	d2s = fabs(d2s);  d2s *= d2;

	/* get axes parameters */
	xbox = 1.0; getparfloat("xbox",&xbox);
	ybox = 1.5; getparfloat("ybox",&ybox);
	wbox = 6.0; getparfloat("wbox",&wbox);
	hbox = 8.0; getparfloat("hbox",&hbox);
	x1beg = x1min; getparfloat("x1beg",&x1beg);
	x1end = x1max; getparfloat("x1end",&x1end);
	d1num = 0.0; getparfloat("d1num",&d1num);
	f1num = x1min; getparfloat("f1num",&f1num);
	n1tic = 1; getparint("n1tic",&n1tic);
	getparstring("grid1",&grid1s);
	if (STREQ("dot",grid1s))
		grid1 = DOT;
	else if (STREQ("dash",grid1s))
		grid1 = DASH;
	else if (STREQ("solid",grid1s))
		grid1 = SOLID;
	else
		grid1 = NONE;
	getparstring("label1",&label1);
	x2beg = x2min; getparfloat("x2beg",&x2beg);
	x2end = x2max; getparfloat("x2end",&x2end);
	d2num = 0.0; getparfloat("d2num",&d2num);
	f2num = 0.0; getparfloat("f2num",&f2num);
	n2tic = 1; getparint("n2tic",&n2tic);
	getparstring("grid2",&grid2s);
	if (STREQ("dot",grid2s))
		grid2 = DOT;
	else if (STREQ("dash",grid2s))
		grid2 = DASH;
	else if (STREQ("solid",grid2s))
		grid2 = SOLID;
	else
		grid2 = NONE;
	getparstring("label2",&label2);
	getparstring("labelfont",&labelfont);
	labelsize = 18.0; getparfloat("labelsize",&labelsize);
	getparstring("title",&title);
	if (!getparstring("title2",&title2)) notitle2=1;
	getparstring("titlefont",&titlefont);
	titlesize = 24.0; getparfloat("titlesize",&titlesize);
	getparstring("style",&styles);
	if (STREQ("normal",styles))
		style = NORMAL;
	else
		style = SEISMIC;

	/* adjust x1beg and x1end to fall on sampled values */

	i1beg = NINT((x1beg-f1)/d1);
	i1beg = MAX(0,MIN(n1dsp-1,i1beg));
	x1beg = f1+i1beg*d1;
	i1end = NINT((x1end-f1)/d1);
	i1end = MAX(0,MIN(n1dsp-1,i1end));
	x1end = f1+i1end*d1;

	/* adjust x2beg and x2end to fall on sampled values */
	i2beg = NINT((x2beg-f2)/d2);
	i2beg = MAX(0,MIN(n2dsp-1,i2beg));
	x2beg = f2+i2beg*d2;
	i2end = NINT((x2end-f2)/d2);
	i2end = MAX(0,MIN(n2dsp-1,i2end));
	x2end = f2+i2end*d2;

	/* allocate space for image bytes */
	n1c = 1+abs(i1end-i1beg);
	n2c = 1+abs(i2end-i2beg);

	/* convert data to be imaged into unsigned characters */
	zscale = (wclip!=bclip)?255.0/(wclip-bclip):1.0e10;
	zoffset = -bclip*zscale;
	i1step = (i1end>i1beg)?1:-1;
	i2step = (i2end>i2beg)?1:-1;

	/* determine sampling after scaling */
	n1s = MAX(1,NINT(1+(n1c-1)*d1/d1s));
	d1s = (n1s>1)?d1*(n1c-1)/(n1s-1):d1;
	n2s = MAX(1,NINT(1+(n2c-1)*d2/d2s));
	d2s = (n2s>1)?d2*(n2c-1)/(n2s-1):d2;

	/* convert axes box parameters from inches to points */
	xbox *= 72.0;
	ybox *= 72.0;
	wbox *= 72.0;
	hbox *= 72.0;

	/* set bounding box */
	psAxesBBox3(
		xbox,ybox,wbox,hbox,
		labelfont,labelsize,
		titlefont,titlesize,
		style,bbox);
	boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]);

	/* begin PostScript */
	beginps();

	/* loop over n3 */
	for(i3=0;i3<n3dsp;i3++) {
		cz = ealloc1(n1c*n2c,sizeof(char));
		czp = cz;
		for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) {
			for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) {
				zi = zoffset
					+z[i1+i2*n1dsp+i3*n1dsp*n2dsp]*zscale;
				if (zi<0.0) zi = 0.0;
				if (zi>255.0) zi = 255.0;
				*czp++ = (unsigned char)zi;
			}
		}

		/* if necessary, interpolate to scaled sampling intervals */
		if (n1s!=n1c || n2s!=n2c) {
			sz = ealloc1(n1s*n2s,sizeof(char));
			intl2b(n2c,d2,0.0,n1c,d1,0.0,cz,
				n2s,d2s,0.0,n1s,d1s,0.0,sz);
			free1(cz); 
		} else {
			sz = cz;
		}

		/* determine axes pads */
		p1beg = (x1end>x1beg)?-fabs(d1s)/2:fabs(d1s)/2;
		p1end = (x1end>x1beg)?fabs(d1s)/2:-fabs(d1s)/2;
		p2beg = (x2end>x2beg)?-fabs(d2s)/2:fabs(d2s)/2;
		p2end = (x2end>x2beg)?fabs(d2s)/2:-fabs(d2s)/2;

		newpage("1",i3+1);

		/* save graphics state */
		gsave();

		/* translate coordinate system by box offset */
		translate(xbox,ybox);

		/* determine image matrix */
		if (style==NORMAL) {
			matrix[0] = 0;  matrix[1] = n1s;  matrix[2] = n2s;
			matrix[3] = 0;  matrix[4] = 0;  matrix[5] = 0;
		} else {
			matrix[0] = n2s;  matrix[1] = 0;  matrix[2] = 0;
			matrix[3] = -n1s;  matrix[4] = 0;  matrix[5] = n1s;
		}

		scale(wbox,hbox);

		/* draw the image (before axes so grid lines are visible) */
		image(n2s,n1s,8,matrix,sz);

		/* restore graphics state */
		grestore();

		/* update title2 only if n3>1*/
		strcpy(title2s,title2);
		if ( notitle2 == 0 ) {
			char *nullchar="";	
			f3s = f3 + i3 * d3;
			sprintf(c80,"= %.4g %s",f3s,nullchar);
			strcat(title2s,c80);
		}

		/* draw axes and title */
		psAxesBox3(
			xbox,ybox,wbox,hbox,
			x1beg,x1end,p1beg,p1end,
			d1num,f1num,n1tic,grid1,label1,
			x2beg,x2end,p2beg,p2end,
			d2num,f2num,n2tic,grid2,label2,
			labelfont,labelsize,
			title,titlefont,titlesize,
			style, title2s); 

		showpage();
	}

	/* end PostScript */
	endps();

	return EXIT_SUCCESS;
}
示例#3
0
int
main (int argc, char **argv)
{
	int n1,n2,nz,iz,verbose,looping,nTic1,nTic2,width,height,interp;
	float d1,f1,d2,f2,*z,
		clip,bclip,wclip,white,wfrac,
		perc,bperc,wperc,*temp,
		bhue,whue,sat,bright,
		x1beg,x2beg,x1end,x2end,
		x1min,x1max,x2min,x2max,
		fframe,dframe;
	char *label1="",*label2="",*format="",*windowtitle="",
		*labelFont="",*titleFont="",
		*axesColor="",*gridColor="",*titleColor="",
		*style="normal",*grid1="none",*grid2="none",
		*cmap;
	ClientData cd;
	XrmValue from,to;
	Widget toplevel,axes;
	XtAppContext ac;
	Display *dpy;
	Window win;
	Arg args[98];
	int nargs;
	int scr;
	unsigned int depth;

	/* initialize getpar */
	initargs(argc,argv);
	requestdoc(1);

	/* get parameters describing colormaps */
	cmap = "gray";  getparstring("cmap",&cmap);
	if (STREQ("saturation",cmap)) cmap = "sat";
	bhue = 0;  getparfloat("bhue",&bhue);  bhue /= 360.0;
	whue = 240;  getparfloat("whue",&whue); whue /= 360.0;
	sat = 1.0; getparfloat("sat",&sat);
	if (sat<0.0 || sat>1.0) err("sat must be in range [0,1]!\n");
	bright = 1.0; getparfloat("bright",&bright);
	if (bright<0.0 || bright>1.0) err("bright must be in range [0,1]!\n");

	/* get parameters describing 1st dimension sampling */
	if (!getparint("n1",&n1))
		err("Must specify number of samples in 1st dimension!\n");
	if (!getparfloat("d1",&d1)) d1 = 1.0;
	if (!getparfloat("f1",&f1)) f1 = 0.0;
	x1min = (d1>0.0)?f1:f1+(n1-1)*d1;
	x1max = (d1<0.0)?f1:f1+(n1-1)*d1;
	if (!getparfloat("x1beg",&x1beg)) x1beg = x1min;
	if (!getparfloat("x1end",&x1end)) x1end = x1max;

	/* get parameters describing 2nd dimension sampling */
	if (!getparint("n2",&n2))
		err("Must specify number of samples in 2nd dimension!\n");
	if (!getparfloat("d2",&d2)) d2 = 1.0;
	if (!getparfloat("f2",&f2)) f2 = 0.0;
	x2min = (d2>0.0)?f2:f2+(n2-1)*d2;
	x2max = (d2<0.0)?f2:f2+(n2-1)*d2;
	if (!getparfloat("x2beg",&x2beg)) x2beg = x2min;
	if (!getparfloat("x2end",&x2end)) x2end = x2max;

	/* read first frame of float data */
	nz = n1*n2;
	z = ealloc1float(nz);
	if (fread(z,sizeof(float),nz,stdin)!=nz)
		err("error reading input file");

	/* if necessary, determine clips from percentiles */
	if (getparfloat("clip",&clip)) {
		bclip = clip;
		wclip = -clip;
	}
	if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) &&
		!getparfloat("clip",&clip)) {
		perc = 100.0;  getparfloat("perc",&perc);
		temp = ealloc1float(nz);
		for (iz=0; iz<nz; iz++)
			temp[iz] = z[iz];
		if (!getparfloat("bclip",&bclip)) {
			bperc = perc;	getparfloat("bperc",&bperc);
			iz = (nz*bperc/100.0);
			if (iz<0) iz = 0;
			if (iz>nz-1) iz = nz-1;
			qkfind(iz,nz,temp);
			bclip = temp[iz];
		}
		if (!getparfloat("wclip",&wclip)) {
			wperc = 100.0-perc;  getparfloat("wperc",&wperc);
			iz = (nz*wperc/100.0);
			if (iz<0) iz = 0;
			if (iz>nz-1) iz = nz-1;
			qkfind(iz,nz,temp);
			wclip = temp[iz];
		}
		free1float(temp);
	}
	if (!getparfloat("white",&white)) white = (bclip+wclip)/2.0;
	if (!getparint("verbose",&verbose)) verbose = 1;
	if (!getparint("sleep",&cd.sleep)) cd.sleep=0 ;
	if (!getparint("loop",&looping)) looping = 0;
	if (verbose) {
		if(STREQ(cmap,"sat") || STREQ(cmap,"customsat")) {
			warn("bclip=%g wclip=%g white=%g",bclip,wclip,white);
		} else {
			warn("bclip=%g wclip=%g",bclip,wclip);
		}
	}
	wfrac = (bclip!=wclip) ? (bclip-white)/(bclip-wclip) : 1.0;

	/* initialize toolkit and set toplevel parameters */
 	toplevel = XtAppInitialize(&ac,"XMovie_XAPP_DEF",NULL,0,&argc,argv,NULL,NULL,0);
	dpy = XtDisplay(toplevel);
	nargs = 0;
	if (getparstring("windowtitle",&windowtitle))
		{XtSetArg(args[nargs],XtNtitle,windowtitle); nargs++;}
	if (getparstring("windowtitle",&windowtitle))
		{XtSetArg(args[nargs],XtNiconName,windowtitle); nargs++;}
	if (getparint("width",&width))
		{XtSetArg(args[nargs],XtNwidth,width); nargs++;}
	if (getparint("height",&height))
		{XtSetArg(args[nargs],XtNheight,height); nargs++;}
	XtSetArg(args[nargs],XtNinput,TRUE);nargs++; 
	XtSetValues(toplevel,args,nargs);

	/* if necessary, make private colormap */
	win = XRootWindowOfScreen(XtScreen(toplevel));
	nargs = 0;

	scr=DefaultScreen(dpy);
	depth=(unsigned int)DefaultDepth(dpy,scr);

	if (depth<=8) {
	  if (STREQ(cmap,"gray")) {
	    Colormap cm=XtcwpCreateGrayColormap(dpy,win);
	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;
	  } else if (STREQ(cmap,"hue")) {
	    Colormap cm=XtcwpCreateHueColormap(dpy,win,
					       bhue,whue,sat,bright);
	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;
	  } else if (STREQ(cmap,"sat")) {
	    Colormap cm=XtcwpCreateSatColormap(dpy,win,
					       bhue,whue,wfrac,bright);

	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;
	  }
	  XtSetValues(toplevel,args,nargs);
	}

	/* create axes and set axes parameters */
	axes = XtCreateManagedWidget("axes",xtcwpAxesWidgetClass, 
		toplevel,NULL,0);
		
	nargs = 0;

	if (getparstring("grid1",&grid1)) {
		from.addr = (char *)grid1;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgrid1,*((int*)to.addr));
		nargs++;
	}
	if (getparstring("grid2",&grid2)) {
		from.addr = (char *)grid2;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgrid2,*((int*)to.addr));
		nargs++;
	}

	if (getparint("nTic1",&nTic1))
		{XtSetArg(args[nargs],XtNnTic1,nTic1); nargs++;}
	if (getparint("nTic2",&nTic2))
		{XtSetArg(args[nargs],XtNnTic2,nTic2); nargs++;}
	if (getparstring("label1",&label1))
		{XtSetArg(args[nargs],XtNlabel1,label1); nargs++;}
	if (getparstring("label2",&label2))
		{XtSetArg(args[nargs],XtNlabel2,label2); nargs++;}
	if (getparstring("title",&format))
		{XtSetArg(args[nargs],XtNtitle,format); nargs++;}
	if (getparstring("style",&style)) {
		from.size = (unsigned int) strlen(style);  from.addr = (char *)style;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesStyle,&to);
		if (to.addr) XtSetArg(args[nargs],XtNstyle,*((int*)to.addr));
		nargs++;
	}
	if (getparstring("axesColor",&axesColor)) {
		from.addr = (char *)axesColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNaxesColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("gridColor",&gridColor)) {
		from.addr = (char *)gridColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgridColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("titleColor",&titleColor)) {
		from.addr = (char *)titleColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNtitleColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("labelFont",&labelFont)) {
		from.addr = (char *)labelFont;
		XtConvertAndStore(axes,XtRString,&from,XtRFont,&to);
		if (to.addr) XtSetArg(args[nargs],XtNlabelFont,
			*((Font*)to.addr));
		nargs++;
	}
	if (getparstring("titleFont",&titleFont)) {
		from.addr = (char *)titleFont;
		XtConvertAndStore(axes,XtRString,&from,XtRFont,&to);
		if (to.addr) XtSetArg(args[nargs],XtNtitleFont,
			*((Font*)to.addr));
		nargs++;
	}
	XtSetValues(axes,args,nargs);
	x1beg = x1min; getparfloat("x1beg",&x1beg);
	x1end = x1max; getparfloat("x1end",&x1end);
	x2beg = x2min; getparfloat("x2beg",&x2beg);
	x2end = x2max; getparfloat("x2end",&x2end);
	adjustAxesValues(n1,d1,f1,n2,d2,f2,&x1beg,&x1end,&x2beg,&x2end);
	XtcwpSetAxesValues(axes,x1beg,x1end,x2beg,x2end);

	/* frame sampling */
	if (!getparfloat("fframe",&fframe)) fframe = 1.0;
	if (!getparfloat("dframe",&dframe)) dframe = 1.0;

	/* interpolation */
	if (!getparint("interp",&interp)) interp = 1;

	/* initial display mode: cont or step */
	if (!getparint("idm", &displayMode)) displayMode = DM_CONT;

	checkpars();

	/* initialize client data */
	cd.n1 = n1;  cd.d1 = d1;  cd.f1 = f1;
	cd.n2 = n2;  cd.d2 = d2;  cd.f2 = f2;
	cd.floats = z;
	cd.fmin = bclip;
	cd.fmax = wclip;
	cd.bmin = (unsigned char) (XtcwpGetFirstPixel(dpy));
	cd.bmax = (unsigned char) (XtcwpGetLastPixel(dpy));
	if(cd.bmax==0)cd.bmax=255;
	warn("bmin=%d bmax=%d",cd.bmin,cd.bmax);
	cd.x1bega = x1beg;
	cd.x1enda = x1end;
	cd.x2bega = x2beg;
	cd.x2enda = x2end;
	cd.abytes = NULL;
	cd.bbytes = NULL;
	cd.image = NULL;
	cd.exposed = 0;
	cd.noframes = 1;
	cd.axes = axes;
	cd.looping = looping;
	cd.frame = NULL;
	cd.format = format;
	cd.iframe = 0;
	cd.fframe = fframe;
	cd.dframe = dframe;
	cd.interp = interp;
	cd.forward = 1;
	cd.ac = ac;

	/* adjust axes title if formatted */
	if (strchr(cd.format,'%') && !strstr(cd.format,"%%")) {
		sprintf(cd.title,cd.format,cd.fframe+cd.iframe*cd.dframe);
		XtVaSetValues(cd.axes,XtNtitle,cd.title,NULL);
	}

	/* add work procedure */
	cd.wpid = XtAppAddWorkProc(ac,(XtWorkProc) readFrame,&cd);

	/* add callbacks to axes widget */
	XtAddCallback(axes,XtNresizeCallback,(XtCallbackProc) resizeCB,&cd);
	XtAddCallback(axes,XtNexposeCallback,(XtCallbackProc) exposeCB,&cd);
	XtAddCallback(axes,XtNinputCallback,(XtCallbackProc) inputCB,&cd);

	/* add Button2 translation for reversing the movie */
	XtOverrideTranslations(axes,
		XtParseTranslationTable("<Btn2Up>: input()"));

	/* add Button3 translation for pausing the movie */
	XtOverrideTranslations(axes,
		XtParseTranslationTable("<Btn3Up>: input()"));

	/* set up keypress */
	XtAddEventHandler(axes, KeyPress, FALSE,
			  (XtEventHandler) key_pressed, &cd);

	/* realize everything */
	XtRealizeWidget(toplevel);

	/* go */
	XtAppMainLoop(ac);

	return EXIT_SUCCESS;
}
示例#4
0
int main (int argc, char **argv)
{
  int n1,n2,n3,n1s,n2s,n3s,n1c,n2c,n3c,i1,i2,i3,i1c,i2c,i3c,
    i1beg,i1end,i2beg,i2end,i3beg,i3end,i1step,i2step,i3step,
    n1tic,n2tic,n3tic,grid1,grid2,grid3,nz,iz,
    verbose,faces,hls,bps,style=SEISMIC,bbox[4],
    legend,ugrid=SOLID,lstyle=VERTLEFT,lz,lbegsup=0,lendsup=0,ln=256,
    lbbox[4];
  float d1,d2,d3,d1s,d2s,d3s,f1,f2,f3,size1,size2,size3,xbox,ybox,angle,
    x1min,x1max,x2min,x2max,x3min,x3max,
    x1beg,x1end,x2beg,x2end,x3beg,x3end,
    d1num,f1num,d2num,f2num,d3num,f3num,
    p1beg,p1end,p2beg,p2end,p3beg,p3end,
    clip,bclip,wclip,perc,bperc,wperc,
    zscale,zoffset,zi,labelsize,titlesize,
    *z,*zfront,*zside,*ztop,*temp,matrix[6],colors[3][2],
    lwidth,lheight,lx,ly,lbeg,lend,
    lmin=(float)FLT_MAX,lmax=(float)-FLT_MAX,
    ldnum,lfnum,ld,lf=0,labmatrix[6];
  unsigned char *czfront,*czside,*cztop,
    *szfront,*szside,*sztop,*czp,
    *data_legend=NULL;
  char *label1="",*label2="",*label3="",*title="",
    *labelfont="Helvetica",*titlefont="Helvetica-Bold",
    *grid1s="none",*grid2s="none",*grid3s="none",
    *titlecolor="black",*axescolor="black",*gridcolor="black",
    *frontf,*sidef,*topf,
    *units="", *legendfont="times_roman10", *lstyles="vertleft",*lgrids="none";
  FILE *infp=stdin,*frontfp,*sidefp,*topfp;
  
  /* initialize getpar */
  initargs(argc,argv);
  requestdoc(1);
  
  /* get parameters describing 1st dimension sampling */
  if (!getparint("n1",&n1)) err("must specify n1!\n");
  if (!getparfloat("d1",&d1)) d1 = 1.0;
  if (!getparfloat("f1",&f1)) f1 = 0.0;
  
  /* get parameters describing 2nd dimension sampling */
  if (!getparint("n2",&n2)) err("must specify n2!\n");
  if (!getparfloat("d2",&d2)) d2 = 1.0;
  if (!getparfloat("f2",&f2)) f2 = 0.0;
  
  /* get parameters describing 3rd dimension sampling */
  if (!getparint("n3",&n3)) err("must specify n3!\n");
  if (!getparfloat("d3",&d3)) d3 = 1.0;
  if (!getparfloat("f3",&f3)) f3 = 0.0;
  
  /* determine input type */
  if (!getparint("faces",&faces)) faces = 0;
  
  /* read color parameters */
  bps = 8;
  hls = 0;
  colors[R][0] = colors[G][0] = colors[B][0] = 0.0;
  colors[R][1] = colors[G][1] = colors[B][1] = 1.0;
  if (countparval("brgb") || countparval("wrgb")) {
    float brgb[3],wrgb[3];
    brgb[R] = brgb[G] = brgb[B] = 0.0;
    wrgb[R] = wrgb[G] = wrgb[B] = 1.0;
    getparfloat("brgb",&brgb[0]);
    getparfloat("wrgb",&wrgb[0]);
    brgb[R] = MAX(0.0,MIN(1.0,brgb[R]));
    wrgb[R] = MAX(0.0,MIN(1.0,wrgb[R]));
    brgb[G] = MAX(0.0,MIN(1.0,brgb[G]));
    wrgb[G] = MAX(0.0,MIN(1.0,wrgb[G]));
    brgb[B] = MAX(0.0,MIN(1.0,brgb[B]));
    wrgb[B] = MAX(0.0,MIN(1.0,wrgb[B]));
    colors[R][0] = brgb[R];  colors[R][1] = wrgb[R];
    colors[G][0] = brgb[G];  colors[G][1] = wrgb[G];
    colors[B][0] = brgb[B];  colors[B][1] = wrgb[B];
		if (!getparint("bps",&bps)) bps = 12;
		if (bps!=12 && bps!=24)
		  err("bps must equal 12 or 24 for color plots!\n");
  } else if (countparval("bhls") || countparval("whls")) {
    float bhls[3],whls[3];
    hls = 1;
    bhls[H] = whls[H] = 0.0;
    bhls[L] = 0.0;  whls[L] = 1.0;
    bhls[S] = whls[S] = 0.0;
    getparfloat("bhls",&bhls[0]);
    getparfloat("whls",&whls[0]);
    bhls[L] = MAX(0.0,MIN(1.0,bhls[L]));
    whls[L] = MAX(0.0,MIN(1.0,whls[L]));
    bhls[S] = MAX(0.0,MIN(1.0,bhls[S]));
    whls[S] = MAX(0.0,MIN(1.0,whls[S]));
    colors[H][0] = bhls[0];  colors[H][1] = whls[0];
    colors[L][0] = bhls[1];  colors[L][1] = whls[1];
    colors[S][0] = bhls[2];  colors[S][1] = whls[2];
    if (!getparint("bps",&bps)) bps = 12;
    if (bps!=12 && bps!=24)
      err("bps must equal 12 or 24 for color plots!\n");
  }
  
  /* allocate space */
  nz = n1*n2+n1*n3+n2*n3;
  z = ealloc1float(nz);
  zfront = z;
  zside = zfront+n1*n2;
  ztop = zside+n1*n3;
  
  /* read data */
  if (getparstring("front",&frontf)
      && getparstring("side",&sidef)
      && getparstring("top",&topf)) {
    
    /* read face files */
    if ((frontfp = fopen(frontf,"r")) == NULL)
      err("error opening front file!\n");
    if (fread(zfront,sizeof(float),n1*n2,frontfp)!=n1*n2)
      err("error reading front file!\n");
    if ((sidefp = fopen(sidef,"r")) == NULL)
      err("error opening side file!\n");
    if (fread(zside,sizeof(float),n1*n3,sidefp)!=n1*n3)
      err("error reading side file!\n");
    if ((topfp = fopen(topf,"r")) == NULL)
      err("error opening top file!\n");
    if (fread(ztop,sizeof(float),n2*n3,topfp)!=n2*n3)
      err("error reading top file!\n");
    
  } else if (getparstring("front",&frontf)
	     || getparstring("side",&sidef)
	     || getparstring("top",&topf)) {
    
    err("must specify all or none of face, side, and top!\n");
    
  } else if (faces) {
    /* read faces from stdin */
    if (fread(zfront,sizeof(float),n1*n2,infp)!=n1*n2)
      err("error reading front from input!\n");
		if (fread(zside,sizeof(float),n1*n3, infp)!=n1*n3)
		  err("error reading side from input!\n");
		if (fread(ztop,sizeof(float),n2*n3, infp)!=n2*n3)
		  err("error reading top from input!\n");
  } else {
    /* read cube from stdin, pick off faces */
    temp = ealloc1float(n1);
    for (i3=0; i3<n3; i3++) {
      for (i2=0; i2<n2; i2++) {
	if (fread(temp,sizeof(float),n1,infp)!=n1)
	  err("error reading cube from input!\n");
	if (i3==0) 
	  for (i1=0; i1<n1; i1++)
	    zfront[i1+i2*n1] = temp[i1];
	if (i2==n2-1)
	  for (i1=0; i1<n1; i1++)
	    zside[i1+i3*n1] = temp[i1];
	ztop[i2+i3*n2] = temp[0];
      }
    }
    free1float(temp);
  }
  
  /* if necessary, determine clips from percentiles */
  if (getparfloat("clip",&clip)) {
    bclip = clip;
    wclip = -clip;
  }
  if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) &&
      !getparfloat("clip",&clip)) {
    perc = 100.0;  getparfloat("perc",&perc);
    temp = ealloc1float(nz);
    for (iz=0; iz<nz; iz++)
      temp[iz] = z[iz];
    if (!getparfloat("bclip",&bclip)) {
      bperc = perc;	getparfloat("bperc",&bperc);
      iz = (nz*bperc/100.0);
      if (iz<0) iz = 0;
      if (iz>nz-1) iz = nz-1;
      qkfind(iz,nz,temp);
      bclip = temp[iz];
    }
    if (!getparfloat("wclip",&wclip)) {
      wperc = 100.0-perc;  getparfloat("wperc",&wperc);
      iz = (nz*wperc/100.0);
      if (iz<0) iz = 0;
      if (iz>nz-1) iz = nz-1;
      qkfind(iz,nz,temp);
      wclip = temp[iz];
    }
    free1float(temp);
  }
  if (!getparint("verbose",&verbose)) verbose = 1;
  if (verbose) warn("bclip=%g wclip=%g",bclip,wclip);
  
  /* get scaled sampling intervals */
  if (!getparfloat("d1s",&d1s)) d1s = 1.0;
  if (!getparfloat("d2s",&d2s)) d2s = 1.0;
  if (!getparfloat("d3s",&d3s)) d3s = 1.0;
  d1s = fabs(d1s);  d1s *= d1;
  d2s = fabs(d2s);  d2s *= d2;
  d3s = fabs(d3s);  d3s *= d3;
  
  /* get projection angle, convert to radians */
  if(!getparfloat("angle",&angle)) angle = 45.0;
  angle = MAX(angle,0.00001);
  angle = MIN(angle,90.0);
  angle *= PI/180.0;
  
  /* get axes parameters */
  if(!getparfloat("size1",&size1)) size1 = 4.0;
  if(!getparfloat("size2",&size2)) size2 = 4.0;
  if(!getparfloat("size3",&size3)) size3 = 3.0;
  if (!getparfloat("xbox",&xbox)) xbox = 1.5;
  if (!getparfloat("ybox",&ybox)) ybox = 1.5;
 
  /* compute extreme values */
  x1min = (d1>0.0)?f1:f1+(n1-1)*d1;
  x1max = (d1<0.0)?f1:f1+(n1-1)*d1;
  x2min = (d2>0.0)?f2:f2+(n2-1)*d2;
  x2max = (d2<0.0)?f2:f2+(n2-1)*d2;
  x3min = (d3>0.0)?f3:f3+(n3-1)*d3;
  x3max = (d3<0.0)?f3:f3+(n3-1)*d3;
  
  /* get axis1 parameters */
  x1beg = x1min;
  x1end = x1max; getparfloat("x1end",&x1end);
  d1num = 0.0; getparfloat("d1num",&d1num);
  f1num = x1min; getparfloat("f1num",&f1num);
  n1tic = 1; getparint("n1tic",&n1tic);
  getparstring("grid1",&grid1s);
  if (STREQ("dot",grid1s)) grid1 = DOT;
  else if (STREQ("dash",grid1s)) grid1 = DASH;
  else if (STREQ("solid",grid1s)) grid1 = SOLID;
  else grid1 = NONE;
  getparstring("label1",&label1);
  
  /* get axis2 parameters */
  x2beg = x2min; getparfloat("x2beg",&x2beg);
  x2end = x2max; 
  d2num = 0.0; getparfloat("d2num",&d2num);
  f2num = x2min; getparfloat("f2num",&f2num);
  n2tic = 1; getparint("n2tic",&n2tic);
  getparstring("grid2",&grid2s);
  if (STREQ("dot",grid2s)) grid2 = DOT;
  else if (STREQ("dash",grid2s)) grid2 = DASH;
  else if (STREQ("solid",grid2s)) grid2 = SOLID;
  else grid2 = NONE;
  getparstring("label2",&label2);
  
  /* get axis3 parameters */
  x3beg = x3min; 
  x3end = x3max; getparfloat("x3end",&x3end);
  d3num = 0.0; getparfloat("d3num",&d3num);
  f3num = x3min; getparfloat("f3num",&f3num);
  n3tic = 1; getparint("n3tic",&n3tic);
  getparstring("grid3",&grid3s);
  if (STREQ("dot",grid3s)) grid3 = DOT;
  else if (STREQ("dash",grid3s)) grid3 = DASH;
  else if (STREQ("solid",grid3s)) grid3 = SOLID;
  else grid3 = NONE;
  getparstring("label3",&label3);
  
  /* get additional font parameters */
  getparstring("labelfont",&labelfont);
  labelsize = 18.0; getparfloat("labelsize",&labelsize);
  getparstring("title",&title);
  getparstring("titlefont",&titlefont);
  titlesize = 24.0; getparfloat("titlesize",&titlesize);
  getparstring("titlecolor",&titlecolor);
  getparstring("axescolor",&axescolor);
  getparstring("gridcolor",&gridcolor);
  style = SEISMIC;
  
 
  /* adjust x1beg and x1end to fall on sampled values */
  i1beg = NINT((x1beg-f1)/d1);
  i1beg = MAX(0,MIN(n1,i1beg));
  x1beg = f1+i1beg*d1;
  i1end = NINT((x1end-f1)/d1);
  i1end = MAX(0,MIN(n1-1,i1end));
  x1end = f1+i1end*d1;
  
  /* adjust x2beg and x2end to fall on sampled values */
  i2beg = NINT((x2beg-f2)/d2);
  i2beg = MAX(0,MIN(n2-1,i2beg));
  x2beg = f2+i2beg*d2;
  i2end = NINT((x2end-f2)/d2);
  i2end = MAX(0,MIN(n2-1,i2end));
  x2end = f2+i2end*d2;
  
  /* adjust x3beg and x3end to fall on sampled values */
  i3beg = NINT((x3beg-f3)/d3);
  i3beg = MAX(0,MIN(n3-1,i3beg));
  x3beg = f3+i3beg*d3;
  i3end = NINT((x3end-f3)/d3);
  i3end = MAX(0,MIN(n3-1,i3end));
  x3end = f3+i3end*d3;

  /* allocate space for image bytes */
  n1c = 1+abs(i1end-i1beg);
  n2c = 1+abs(i2end-i2beg);
  n3c = 1+abs(i3end-i3beg);
  czfront = ealloc1(n1c*n2c,sizeof(char));
  czside = ealloc1(n1c*n3c,sizeof(char));
  cztop = ealloc1(n2c*n3c,sizeof(char));
  
  /* compute conversion constants */
  zscale = (wclip!=bclip)?255.0/(wclip-bclip):1.0e10;
  zoffset = -bclip*zscale;
  i1step = (i1end>i1beg)?1:-1;
  i2step = (i2end>i2beg)?1:-1;
  i3step = (i3end>i3beg)?1:-1;
  
  /* convert front data to be imaged into unsigned characters */
  czp = czfront;
  for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) {
    for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) {
      zi = zoffset+zfront[i1+i2*n1]*zscale;
      if (zi<0.0) zi = 0.0;
      if (zi>255.0) zi = 255.0;
      *czp++ = (unsigned char)zi;
    }
  }
  
  /* convert side data to be imaged into unsigned characters */
  czp = czside;
  for (i3c=0,i3=i3beg; i3c<n3c; i3c++,i3+=i3step) {
    for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) {
      zi = zoffset+zside[i1+i3*n1]*zscale;
      if (zi<0.0) zi = 0.0;
      if (zi>255.0) zi = 255.0;
      *czp++ = (unsigned char)zi;
    }
  }

  /* convert top data to be imaged into unsigned characters */
  czp = cztop;
  for (i3c=0,i3=i3beg; i3c<n3c; i3c++,i3+=i3step) {
    for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) {
      zi = zoffset+ztop[i2+i3*n2]*zscale;
      if (zi<0.0) zi = 0.0;
      if (zi>255.0) zi = 255.0;
      *czp++ = (unsigned char)zi;
    }
  }
  free1float(z);
  
  /* determine sampling after scaling */
  n1s = MAX(1,NINT(1+(n1c-1)*d1/d1s));
  d1s = (n1s>1)?d1*(n1c-1)/(n1s-1):d1;
  n2s = MAX(1,NINT(1+(n2c-1)*d2/d2s));
  d2s = (n2s>1)?d2*(n2c-1)/(n2s-1):d2;
  n3s = MAX(1,NINT(1+(n3c-1)*d3/d3s));
  d3s = (n3s>1)?d3*(n3c-1)/(n3s-1):d3;
  
  /* if necessary, interpolate front to scaled sampling intervals */
  if (n1s!=n1c || n2s!=n2c) {
    szfront = ealloc1(n1s*n2s,sizeof(char));
    intl2b(n1c,d1,0.0,n2c,d2,0.0,czfront,
	   n1s,d1s,0.0,n2s,d2s,0.0,szfront);
    free1(czfront);
  } else {
    szfront = czfront;
  }
  
  /* if necessary, interpolate side to scaled sampling intervals */
  if (n1s!=n1c || n3s!=n3c) {
    szside = ealloc1(n1s*n3s,sizeof(char));
    intl2b(n1c,d1,0.0,n3c,d3,0.0,czside,
	   n1s,d1s,0.0,n3s,d3s,0.0,szside);
    free1(czside);
  } else {
    szside = czside;
  }
  
  /* if necessary, interpolate top to scaled sampling intervals */
  if (n2s!=n2c || n3s!=n3c) {
    sztop = ealloc1(n2s*n3s,sizeof(char));
    intl2b(n2c,d2,0.0,n3c,d3,0.0,cztop,
	   n2s,d2s,0.0,n3s,d3s,0.0,sztop);
    free1(cztop);
  } else {
    sztop = cztop;
  }
  
  /* determine axes pads */
  p1beg = (x1end>x1beg)?-fabs(d1s)/2:fabs(d1s)/2;
  p1end = (x1end>x1beg)?fabs(d1s)/2:-fabs(d1s)/2;
  p2beg = (x2end>x2beg)?-fabs(d2s)/2:fabs(d2s)/2;
  p2end = (x2end>x2beg)?fabs(d2s)/2:-fabs(d2s)/2;
  p3beg = (x3end>x3beg)?-fabs(d3s)/2:fabs(d3s)/2;
  p3end = (x3end>x3beg)?fabs(d3s)/2:-fabs(d3s)/2;
  
  /* get legend specs BEREND, Schoenfelder */
  legend = 0; getparint("legend", &legend); /* BEREND, Schoenfelder */
  getparstring("units", &units); /* BEREND, Schoenfelder */
  getparstring("legendfont", &legendfont);     /* BEREND, Schoenfelder */
  
  /* Get or calc legend parameters */
  /* Legend min and max: Calc from data read in */
  if (legend) {
    for (lz=0;lz<nz;lz++) {
      lmin=FMIN(lmin,z[lz]);
      lmax=FMAX(lmax,z[lz]);
    }
    if (verbose==2) warn("lmin=%g lmax=%g",lmin,lmax);
  
    lbeg = lmin; if (getparfloat("lbeg",&lbeg)) lbegsup=1;
    lend = lmax; if (getparfloat("lend",&lend)) lendsup=1;
    /* Change wclip,bclip to be inside legend range */
    wclip = FMAX(lbeg,wclip); /* [wclip,bclip] has to be in [lbeg,lend] */
    bclip = FMIN(lend,bclip);
    if (lbegsup!=1) { /* Add white and black areas to show possible clipping */ 
      float rangeperc=(bclip-wclip)/20.;
      lbeg=wclip-rangeperc;
    }
    if (lendsup!=1) {
      float rangeperc=(bclip-wclip)/20.;
      lend=bclip+rangeperc;
    }
    
    lfnum = lmin; getparfloat("lfnum",&lfnum);
    
    getparstring("lstyle",&lstyles);
    if (STREQ("vertright",lstyles))
      lstyle = VERTRIGHT;
    else if (STREQ("horibottom",lstyles))
      lstyle = HORIBOTTOM;
    /* legend dimensions (BEREND), Schoenfelder */
    lwidth = 0.1 ;lheight = size1+sin(angle)*size3/2;
    if (lstyle==HORIBOTTOM) {
      lwidth=size2+cos(angle)*size3/1.2 ;lheight = 0.24;
    }
    getparfloat("lwidth",&lwidth);
    getparfloat("lheight",&lheight);
    
    lx=.8;ly = ybox+(size1+sin(angle)*size3-lheight)/2;
    if (lstyle==VERTRIGHT) {
      lx=xbox+size2+cos(angle)*size3+0.1;
    } else if (lstyle==HORIBOTTOM) {
      lx=xbox+(size2+cos(angle)*size3-lwidth)/2.0;ly = 1.0;
    }
    getparfloat("lx",&lx);
    getparfloat("ly",&ly);
    
    getparstring("lgrid",&lgrids);
    if (STREQ("dot",lgrids))
      ugrid = DOT;
    else if (STREQ("dash",lgrids))
      ugrid = DASH;
    else if (STREQ("solid",lgrids))
      ugrid = SOLID;
    else
      ugrid = NONE;
  }
  

  if (legend) {
    /* Make legend color values */
    int lll=0,lcount,perc5=13,ilbeg,ilend; /* color scale */
    if (lbegsup!=1) {
      ln+=perc5; /* white area */
    }
    if (lendsup!=1) {
      ln+=perc5; /* black area */
    }
    data_legend = ealloc1(ln,sizeof(char));
    if (lbegsup!=1) {
      for (lll=0;lll<perc5;lll++) data_legend[lll]=(char) 255; /* white area */
    }
    for (lcount=255;lcount>=0;lcount--,lll++) data_legend[lll]=(char) lcount;
    if (lendsup!=1) {
      for (;lll<ln;lll++) data_legend[lll]=(char) 0; /* black area */
    }
    lf=lbeg;ld=(lend-lbeg)/(ln-1);
    if (!(getparfloat("ldnum",&ldnum)))	ldnum=0.0;
    
    /* adjust lbeg and lend to fall on sampled values */
    
    ilbeg = NINT((lbeg-lf)/ld);
    ilbeg = MAX(0,MIN(ln-1,ilbeg));
    lbeg = lf+ilbeg*ld;
    ilend = NINT((lend-lf)/ld);
    ilend = MAX(0,MIN(ln-1,ilend));
    lend = lf+ilend*ld;

    /* convert legend parameters to points */  
    lx *= 72.0; /* Schoenfelder */
    ly *= 72.0; /* Schoenfelder */
    lwidth *= 72.0; /* Schoenfelder */
    lheight *= 72.0; /* Schoenfelder */
  }

  /* convert axes parameters to points */  
  size1 *= 72;
  size2 *= 72;
  size3 *= 72;
  xbox *= 72;
  ybox *= 72;
  
  /* set bounding box */
  psAxesBBox(xbox,ybox,size2+cos(angle)*size3,size1+sin(angle)*size3,
	     labelfont,labelsize,titlefont,titlesize,style,bbox);
  if (legend) {
    psLegendBBox( /* Space for legend Schoenfelder */
		 lx,ly,lwidth,lheight,
		 labelfont,labelsize,
		 lstyle,lbbox);
    /* Include space for legend Schoenfelder */
    bbox[0]=MIN(bbox[0],lbbox[0]);
    bbox[1]=MIN(bbox[1],lbbox[1]);
    bbox[2]=MAX(bbox[2],lbbox[2]);
    bbox[3]=MAX(bbox[3],lbbox[3]);
  }
  boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]);
  
  /* begin PostScript */
  begineps();
  
  /* save graphics state */
  gsave();
  
  /* translate coordinate system by box offset */
  translate(xbox,ybox);
  
  /* begin front */
  gsave();
  
  /* transform coordinates */
  translate(0,0);
  scale(size2,size1);
  
  /* determine image matrix */
  matrix[0] = 0;  matrix[1] = n2s;  matrix[2] = -n1s;
  matrix[3] = 0;  matrix[4] = n1s;  matrix[5] = 0;
  
  /* draw the image */
  drawimage(hls,colors,n1s,n2s,bps,matrix,szfront);
  
  /* end front */
  grestore();
  
  /* begin side */
  gsave();
  
  /* transform and skew coordinates */
  matrix[0] = 1;  matrix[1] = tan(angle);  matrix[2] = 0;
  matrix[3] = 1;  matrix[4] = 0;  matrix[5] = 0;
  translate(size2,0);
  concat(matrix);
  scale(size3*cos(angle),size1);
  
  /* determine image matrix */
  matrix[0] = 0;  matrix[1] = n3s;  matrix[2] = -n1s;
  matrix[3] = 0;  matrix[4] = n1s;  matrix[5] = 0;
  
  /* draw the image */
  drawimage(hls,colors,n1s,n3s,bps,matrix,szside);
  
  /* end side */
  grestore();
  
  /* begin top */
  gsave();
  
  
  /* transform and skew coordinates */
  matrix[0] = 1;  matrix[1] = 0;  matrix[2] = 1.0/tan(angle);
  matrix[3] = 1;  matrix[4] = 0;  matrix[5] = 0;
  translate(0,size1);
  concat(matrix);
  scale(size2,size3*sin(angle));
  
  /* determine image matrix */
  matrix[0] = n2s;  matrix[1] = 0;  matrix[2] = 0;
  matrix[3] = n3s;  matrix[4] = 0;  matrix[5] = 0;
  
  /* draw the image */
  drawimage(hls,colors,n2s,n3s,bps,matrix,sztop);
  
  /* end top */
  grestore();
  
  if (legend) {
    gsave();
  /* translate coordinate system by box offset */
  translate(-xbox,-ybox);
    translate(lx,ly);
    scale(lwidth,lheight);
    if ((lstyle==VERTLEFT) || (lstyle==VERTRIGHT)) {
      labmatrix[0] = 1;	 labmatrix[1] = 0;  labmatrix[2] = 0;
      labmatrix[3] = ln; labmatrix[4] = 0;  labmatrix[5] = 0;
      drawimage(hls,colors,1,ln,bps,labmatrix,data_legend);
    } else {
      labmatrix[0] = -1; labmatrix[1] = 0;  labmatrix[2] = 0;
      labmatrix[3] = ln; labmatrix[4] = 0;  labmatrix[5] = 0;
      rotate(-90);
      drawimage(hls,colors,1,ln,bps,labmatrix,data_legend);
      rotate(90);
    }
    grestore();
  }
  /* restore graphics state */
  grestore();
  
  psCubeAxesBox(xbox,ybox,size1,size2,size3,angle,
		x1beg,x1end,p1beg,p1end,
		d1num,f1num,n1tic,grid1,label1,
		x2beg,x2end,p2beg,p2end,
		d2num,f2num,n2tic,grid2,label2,
		x3beg,x3end,p3beg,p3end,
		d3num,f3num,n3tic,grid3,label3,
		labelfont,labelsize,
		title,titlefont,titlesize,
		titlecolor,axescolor,gridcolor);
  
	/* draw axes and title for legend Schoenfelder*/
	if (legend) {
	  float lpbeg,lpend;
	  int lntic=1;
	  gsave();
	  lpbeg = 0.0; /*(lend>lbeg)?-fabs(d1s)/2:fabs(d1s)/2;*/
	  lpend = 0.0; /*(lend>lbeg)?fabs(d1s)/2:-fabs(d1s)/2;*/
  
	  psLegendBox(
		    lx,ly,lwidth,lheight,
		    lbeg,lend,lpbeg,lpend,
		    ldnum,lf,lntic,ugrid,units,
		    labelfont,labelsize,
		    axescolor,gridcolor,
		    lstyle);
	  grestore();
	}
  /* end PostScript */
  showpage();
  endeps();
  
  return 0;
}
示例#5
0
int 
main (int argc, char **argv)
{
	int n1,n2,n1tic,n2tic,nfloats,bbox[4],
	  i1,i2,grid1,grid2,style,
	  n1c,n2c,n1s,n2s,i1beg,i1end,i2beg,i2end,i1c,i2c,
	  nz,iz,i1step,i2step,verbose,hls,bps,
	  legend,ugrid=SOLID,lstyle=VERTLEFT,lz,lbegsup=0,lendsup=0,ln=256,
	  lbbox[4], threecolor=0; /* BEREND, Schoenfelder */
        int lnice; /* c liner */
	float labelsize,titlesize,perc,clip,bperc,wperc,bclip,wclip,
		d1,f1,d2,f2,*z,*temp,zscale,zoffset,zi,
		xbox,ybox,width,height,
		x1beg,x1end,x2beg,x2end,
		x1min,x1max,x2min,x2max,
		d1num,f1num,d2num,f2num,
		p1beg,p1end,p2beg,p2end,matrix[6],colors[3][3], /* for 3 color mode */
		d1s,d2s,
	  lwidth,lheight,lx,ly,lbeg,lend,lmin=(float) FLT_MAX,lmax=(float) -FLT_MAX,
	  ldnum,lfnum,ld,lf=0,labmatrix[6]; /* BEREND, Schoenfelder */
	float axeswidth, ticwidth, gridwidth;
	unsigned char *cz,*czp,*sz,*data_legend=NULL;
	char *label1="",*label2="",*title="",*units="",
	  *legendfont="times_roman10",
	  *labelfont="Helvetica",*titlefont="Helvetica-Bold",
	  *styles="seismic",*grid1s="none",*grid2s="none",
	  *titlecolor="black",*axescolor="black",*gridcolor="black",
	  *lstyles="vertleft",*lgrids="none";
	FILE *infp=stdin;

	float **x1curve=NULL,**x2curve=NULL,*curvewidth=NULL;
	int i,j,curve=0,*npair=NULL,ncurvecolor=0,ncurvewidth=0,ncurvedash=0,*curvedash=NULL;
	char **curvecolor=NULL,**curvefile=NULL;
	FILE *curvefp=NULL;
	cwp_Bool is_curve = cwp_false;

	/* initialize getpar */
	initargs(argc,argv);
	requestdoc(1);

	/* get parameters describing 1st dimension sampling */
	if (!getparint("n1",&n1)) err("must specify n1!\n");
	d1 = 1.0;  getparfloat("d1",&d1);
	f1 = 0.0;  getparfloat("f1",&f1);
	x1min = (d1>0.0)?f1:f1+(n1-1)*d1;
	x1max = (d1<0.0)?f1:f1+(n1-1)*d1;

	/* get parameters describing 2nd dimension sampling */
	if (!getparint("n2",&n2)) {
		if (efseeko(infp,(off_t) 0,SEEK_END)!=0)
			err("must specify n2 if in a pipe!\n");
		nfloats = (int) (eftello(infp)/((off_t) sizeof(float)));
		efseeko(infp,(off_t) 0,SEEK_SET);
		n2 = nfloats/n1;
	}
	d2 = 1.0;  getparfloat("d2",&d2);
	f2 = 0.0;  getparfloat("f2",&f2);
	x2min = (d2>0.0)?f2:f2+(n2-1)*d2;
	x2max = (d2<0.0)?f2:f2+(n2-1)*d2;

	/* read color parameters */
	if (!getparint("threecolor",&threecolor)) threecolor=1;
	bps = 8;
	hls = 0;
	/* color[][0] is black, color[][2] is white in 2 color mode */
	colors[R][0] = colors[G][0] = colors[B][0] = 0.0;
	colors[R][1] = colors[G][1] = colors[B][1] = 0.5;
	colors[R][2] = colors[G][2] = colors[B][2] = 1.0;
	if (countparval("brgb") || countparval("wrgb")) {
		float brgb[3],grgb[3],wrgb[3];
		brgb[R] = brgb[G] = brgb[B] = 0.0;
		wrgb[R] = wrgb[G] = wrgb[B] = 1.0;
		getparfloat("brgb",&brgb[0]);
		getparfloat("wrgb",&wrgb[0]);
		grgb[R] = (brgb[R] + wrgb[R])/2.;
		grgb[G] = (brgb[G] + wrgb[G])/2.;
		grgb[B] = (brgb[B] + wrgb[B])/2.;
		if (threecolor==1)
		  getparfloat("grgb",&grgb[0]);
		brgb[R] = MAX(0.0,MIN(1.0,brgb[R]));
		grgb[R] = MAX(0.0,MIN(1.0,grgb[R]));
		wrgb[R] = MAX(0.0,MIN(1.0,wrgb[R]));
		brgb[G] = MAX(0.0,MIN(1.0,brgb[G]));
		grgb[G] = MAX(0.0,MIN(1.0,grgb[G]));
		wrgb[G] = MAX(0.0,MIN(1.0,wrgb[G]));
		brgb[B] = MAX(0.0,MIN(1.0,brgb[B]));
		grgb[B] = MAX(0.0,MIN(1.0,grgb[B]));
		wrgb[B] = MAX(0.0,MIN(1.0,wrgb[B]));
		colors[R][0] = brgb[R];	 colors[R][1] = grgb[R];  colors[R][2] = wrgb[R];
		colors[G][0] = brgb[G];	 colors[G][1] = grgb[G];  colors[G][2] = wrgb[G];
		colors[B][0] = brgb[B];	 colors[B][1] = grgb[B];  colors[B][2] = wrgb[B];
		if (!getparint("bps",&bps)) bps = 12;
		if (bps!=12 && bps!=24)
			err("bps must equal 12 or 24 for color plots!\n");
	} else if (countparval("bhls") || countparval("whls")) {
		float bhls[3],ghls[3],whls[3];
		hls = 1;
		bhls[H] = ghls[H] = whls[H] = 0.0;
		bhls[L] = 0.0;	ghls[L] = 0.5;	whls[L] = 1.0;
		bhls[S] = ghls[S] = whls[S] = 0.0;
		getparfloat("bhls",&bhls[0]);
		getparfloat("whls",&whls[0]);
		ghls[H] = (bhls[H] + whls[H])/2.;
		ghls[L] = (bhls[L] + whls[L])/2.;
		ghls[S] = (bhls[S] + whls[S])/2.;
		if (threecolor==1)
		  getparfloat("ghls",&ghls[0]);
		bhls[L] = MAX(0.0,MIN(1.0,bhls[L]));
		ghls[L] = MAX(0.0,MIN(1.0,ghls[L]));
		whls[L] = MAX(0.0,MIN(1.0,whls[L]));
		bhls[S] = MAX(0.0,MIN(1.0,bhls[S]));
		ghls[S] = MAX(0.0,MIN(1.0,ghls[S]));
		whls[S] = MAX(0.0,MIN(1.0,whls[S]));
		colors[H][0] = bhls[0];	 colors[H][1] = ghls[0];  colors[H][2] = whls[0];
		colors[L][0] = bhls[1];	 colors[L][1] = ghls[1];  colors[L][2] = whls[1];
		colors[S][0] = bhls[2];	 colors[S][1] = ghls[2];  colors[S][2] = whls[2];
		if (!getparint("bps",&bps)) bps = 12;
		if (bps!=12 && bps!=24)
			err("bps must equal 12 or 24 for color plots!\n");
	}

	/* get legend specs BEREND, Schoenfelder */
	legend = 0; getparint("legend", &legend); /* BEREND, Schoenfelder */
	getparstring("units", &units); /* BEREND, Schoenfelder */
	getparstring("legendfont", &legendfont);     /* BEREND, Schoenfelder */

	/* set up curve plotting */
	if ((curve=countparval("curve"))!=0) {
		curvefile=(char**)ealloc1(curve,sizeof(void*));
		getparstringarray("curve",curvefile);
		if ((x1curve=(float**)malloc(curve*sizeof(void*)))==NULL)
			err("Could not allocate x1curve pointers\n");
		if ((x2curve=(float**)malloc(curve*sizeof(void*)))==NULL)
			err("Could not allocate x2curve pointers\n");
		npair=ealloc1int(curve);
		getparint("npair",npair);
		is_curve = cwp_true;
	} else {
		npair=(int *)NULL;
		curvefile=(char **)NULL;
		x1curve=(float **)NULL;
		x2curve=(float **)NULL;
		is_curve = cwp_false;
	}
	if (is_curve) {
	 if ((ncurvecolor=countparval("curvecolor"))<curve) {
		curvecolor=(char**)ealloc1(curve,sizeof(void*));
		if (!getparstringarray("curvecolor",curvecolor)) {
			curvecolor[0]=(char *)cwp_strdup("black\0");
			ncurvecolor=1;
		}
		for (i=ncurvecolor; i<curve; i++)
			curvecolor[i]=(char *)cwp_strdup(curvecolor[ncurvecolor-1]);
	 } else if (ncurvecolor) {
		curvecolor=(char**)ealloc1(ncurvecolor,sizeof(void*));
		getparstringarray("curvecolor",curvecolor);
	 }
	 for (j=0; j<curve; j++) {
		curvefp=efopen(curvefile[j],"r");
		x1curve[j]=ealloc1float(npair[j]);
		x2curve[j]=ealloc1float(npair[j]);
		for (i=0; i<npair[j]; i++) {
			fscanf(curvefp,"%f",&x1curve[j][i]);
			fscanf(curvefp,"%f",&x2curve[j][i]);
		}
		efclose(curvefp);
	 }
	}

	/* read binary data to be plotted */
	nz = n1*n2;
	z = ealloc1float(nz);
	if (fread(z,sizeof(float),nz,infp)!=nz)
		err("error reading input file!\n");

	/* if necessary, determine clips from percentiles */
	if (getparfloat("clip",&clip)) {
		bclip = clip;
		wclip = -clip;
	}
	if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) &&
		!getparfloat("clip",&clip)) {
		perc = 100.0;  getparfloat("perc",&perc);
		temp = ealloc1float(nz);
		for (iz=0; iz<nz; iz++)
			temp[iz] = z[iz];
		if (!getparfloat("bclip",&bclip)) {
			bperc = perc;	getparfloat("bperc",&bperc);
			iz = (nz*bperc/100.0);
			if (iz<0) iz = 0;
			if (iz>nz-1) iz = nz-1;
			qkfind(iz,nz,temp);
			bclip = temp[iz];
		}
		if (!getparfloat("wclip",&wclip)) {
			wperc = 100.0-perc;  getparfloat("wperc",&wperc);
			iz = (nz*wperc/100.0);
			if (iz<0) iz = 0;
			if (iz>nz-1) iz = nz-1;
			qkfind(iz,nz,temp);
			wclip = temp[iz];
		}
		free1float(temp);
	}
	verbose = 1;  getparint("verbose",&verbose);
	if (verbose) warn("bclip=%g wclip=%g",bclip,wclip);

	/* get scaled sampling intervals */
	d1s = 1.0;  getparfloat("d1s",&d1s);
	d2s = 1.0;  getparfloat("d2s",&d2s);
	d1s = fabs(d1s);  d1s *= d1;
	d2s = fabs(d2s);  d2s *= d2;

	/* get axes parameters */
	xbox = 1.5; getparfloat("xbox",&xbox); /* if psimage is called by ximage, it */
	ybox = 1.5; getparfloat("ybox",&ybox); /* will xbox=1.166 and ybox=1.167 */
	width = 6.0; getparfloat("wbox",&width); getparfloat("width",&width);
	height = 8.0;getparfloat("hbox",&height);getparfloat("height",&height);
         /* begin c liner */
	lnice = 0;  getparint("lnice",&lnice); 
        if (lnice==1) {
            ybox = 2.2;
            /* lx=8 is set below, after getpar on lx ... c liner */
            width = 5.4;
            height = 7.2;
        }
         /* end c liner */
	x1beg = x1min; getparfloat("x1beg",&x1beg);
	x1end = x1max; getparfloat("x1end",&x1end);
	d1num = 0.0; getparfloat("d1num",&d1num);
	f1num = x1min; getparfloat("f1num",&f1num);
	n1tic = 1; getparint("n1tic",&n1tic);
	getparstring("grid1",&grid1s);
	if (STREQ("dot",grid1s))
		grid1 = DOT;
	else if (STREQ("dash",grid1s))
		grid1 = DASH;
	else if (STREQ("solid",grid1s))
		grid1 = SOLID;
	else
		grid1 = NONE;
	getparstring("label1",&label1);
	x2beg = x2min; getparfloat("x2beg",&x2beg);
	x2end = x2max; getparfloat("x2end",&x2end);
	d2num = 0.0; getparfloat("d2num",&d2num);
	f2num = 0.0; getparfloat("f2num",&f2num);
	n2tic = 1; getparint("n2tic",&n2tic);
	getparstring("grid2",&grid2s);
	if (STREQ("dot",grid2s))
		grid2 = DOT;
	else if (STREQ("dash",grid2s))
		grid2 = DASH;
	else if (STREQ("solid",grid2s))
		grid2 = SOLID;
	else
		grid2 = NONE;
	getparstring("label2",&label2);
	getparstring("labelfont",&labelfont);
	labelsize = 18.0; getparfloat("labelsize",&labelsize);
	getparstring("title",&title);
	getparstring("titlefont",&titlefont);
	titlesize = 24.0; getparfloat("titlesize",&titlesize);
	getparstring("titlecolor",&titlecolor);
	getparstring("axescolor",&axescolor);
	getparstring("gridcolor",&gridcolor);

	/* axes and tic width */
        if(!getparfloat("axeswidth",&axeswidth)) axeswidth=1;
        if (!getparfloat("ticwidth",&ticwidth)) ticwidth=axeswidth;
        if(!getparfloat("gridwidth",&gridwidth)) gridwidth =axeswidth;

	if (is_curve) {
	 if ((ncurvewidth=countparval("curvewidth"))<curve) {
		curvewidth=ealloc1float(curve);
		if (!getparfloat("curvewidth",curvewidth)) {
			curvewidth[0]=axeswidth;
			ncurvewidth=1;
		}
		for (i=ncurvewidth; i<curve; i++)
			curvewidth[i]=curvewidth[ncurvewidth-1];
	 } else {
		curvewidth=ealloc1float(ncurvewidth);
		getparfloat("curvewidth",curvewidth);
	 }
	 if ((ncurvedash=countparval("curvedash"))<curve) {
		curvedash=ealloc1int(curve);
		if (!getparint("curvedash",curvedash)) {
		        curvedash[0]=0;
			ncurvedash=1;
		}
		for (i=ncurvedash; i<curve; i++)
			curvedash[i]=curvedash[ncurvedash-1];
	 } else {
		curvedash=ealloc1int(ncurvedash);
		getparint("curvedash",curvedash);
	 }
	}

	getparstring("style",&styles);

	if (STREQ("normal",styles))
		style = NORMAL;
	else
		style = SEISMIC;

	/* Get or calc legend parameters */
	/* Legend min and max: Calc from data read in */
	if (legend) {
	  for (lz=0;lz<nz;lz++) {
	    lmin=FMIN(lmin,z[lz]);
	    lmax=FMAX(lmax,z[lz]);
	  }
	  if (verbose==2) warn("lmin=%g lmax=%g",lmin,lmax);
	}

	if (legend) {
	  lbeg = lmin; if (getparfloat("lbeg",&lbeg)) lbegsup=1;
	  lend = lmax; if (getparfloat("lend",&lend)) lendsup=1;


	  /* Change wclip,bclip to be inside legend range */
	  wclip = FMAX(lbeg,wclip); /* [wclip,bclip] has to be in [lbeg,lend] */
	  bclip = FMIN(lend,bclip);
	  if (lbegsup!=1) { /* Add white and black areas to show possible clipping */ 
	    float rangeperc=(bclip-wclip)/20.;
	    lbeg=wclip-rangeperc;
	  }
	  if (lendsup!=1) {
	    float rangeperc=(bclip-wclip)/20.;
	    lend=bclip+rangeperc;
	  }
	  
	  lfnum = lmin; getparfloat("lfnum",&lfnum);
	
	  getparstring("lstyle",&lstyles);
	  if (STREQ("vertright",lstyles))
	    lstyle = VERTRIGHT;
	  else if (STREQ("horibottom",lstyles))
	    lstyle = HORIBOTTOM;

	  /* legend dimensions (BEREND), Schoenfelder */
	  lwidth = 0.1 ;lheight = height/2;
	  if (lstyle==HORIBOTTOM) {
	    lwidth=width/1.2 ;lheight = 0.24;
	  }
	  getparfloat("lwidth",&lwidth);
	  getparfloat("lheight",&lheight);
	  
	  lx=.8;ly = ybox+(height-lheight)/2;
	  if (lstyle==VERTRIGHT) {
	    lx=xbox+width+0.1;
	  } else if (lstyle==HORIBOTTOM) {
	    lx=xbox+(width-lwidth)/2.0;ly = 1.0;
	  }
	  getparfloat("lx",&lx);
          if (lnice==1) lx = 8;   /* c liner */
	  getparfloat("ly",&ly);
	  
	  getparstring("lgrid",&lgrids);
	  if (STREQ("dot",lgrids))
	    ugrid = DOT;
	  else if (STREQ("dash",lgrids))
	    ugrid = DASH;
	  else if (STREQ("solid",lgrids))
	    ugrid = SOLID;
	  else
	    ugrid = NONE;
	}

	/* adjust x1beg and x1end to fall on sampled values */
	/* This will not allow to display an area greater than the data supplied */
	i1beg = NINT((x1beg-f1)/d1);
	i1beg = MAX(0,MIN(n1-1,i1beg));
	x1beg = f1+i1beg*d1;
	i1end = NINT((x1end-f1)/d1);
	i1end = MAX(0,MIN(n1-1,i1end));
	x1end = f1+i1end*d1;

	/* adjust x2beg and x2end to fall on sampled values */
	i2beg = NINT((x2beg-f2)/d2);
	i2beg = MAX(0,MIN(n2-1,i2beg));
	x2beg = f2+i2beg*d2;
	i2end = NINT((x2end-f2)/d2);
	i2end = MAX(0,MIN(n2-1,i2end));
	x2end = f2+i2end*d2;

	if (legend) {
	  /* Make legend color values */
	  int lll=0,lcount,perc5=13,ilbeg,ilend; /* color scale */
	  if (lbegsup!=1) {
	    ln+=perc5; /* white area */
	  }
	  if (lendsup!=1) {
	    ln+=perc5; /* black area */
	  }
	  data_legend = ealloc1(ln,sizeof(char));
	  if (lbegsup!=1) {
	    for (lll=0;lll<perc5;lll++) data_legend[lll]=(char) 255; /* white area */
	  }
	  for (lcount=255;lcount>=0;lcount--,lll++) data_legend[lll]=(char) lcount;
	  if (lendsup!=1) {
	    for (;lll<ln;lll++) data_legend[lll]=(char) 0; /* black area */
	  }
	  lf=lbeg;ld=(lend-lbeg)/(ln-1);
	  if (!(getparfloat("ldnum",&ldnum)))	ldnum=0.0;

	  /* adjust lbeg and lend to fall on sampled values */
	  ilbeg = NINT((lbeg-lf)/ld);
	  ilbeg = MAX(0,MIN(ln-1,ilbeg));
	  lbeg = lf+ilbeg*ld;
	  ilend = NINT((lend-lf)/ld);
	  ilend = MAX(0,MIN(ln-1,ilend));
	  lend = lf+ilend*ld;
	}
	/* allocate space for image bytes */
	n1c = 1+abs(i1end-i1beg);
	n2c = 1+abs(i2end-i2beg);
	cz = ealloc1(n1c*n2c,sizeof(char));

	/* convert data to be imaged into unsigned characters */
	zscale = (wclip!=bclip)?255.0/(wclip-bclip):1.0e10;
	zoffset = -bclip*zscale;
	i1step = (i1end>i1beg)?1:-1;
	i2step = (i2end>i2beg)?1:-1;
	czp = cz;
	for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) {
		for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) {
			zi = zoffset+z[i1+i2*n1]*zscale;
			if (zi<0.0) zi = 0.0;
			if (zi>255.0) zi = 255.0;
			*czp++ = (unsigned char)zi;
		}
	}
	free1float(z);

	/* determine sampling after scaling */
	n1s = MAX(1,NINT(1+(n1c-1)*d1/d1s));
	d1s = (n1s>1)?d1*(n1c-1)/(n1s-1):d1;
	n2s = MAX(1,NINT(1+(n2c-1)*d2/d2s));
	d2s = (n2s>1)?d2*(n2c-1)/(n2s-1):d2;

	/* if necessary, interpolate to scaled sampling intervals */
	if (n1s!=n1c || n2s!=n2c) {
		sz = ealloc1(n1s*n2s,sizeof(char));
		intl2b(n2c,d2,0.0,n1c,d1,0.0,cz,n2s,d2s,0.0,n1s,d1s,0.0,sz); /* Interpol array */
		free1(cz);
	} else {
		sz = cz;
	}

	/* determine axes pads */
	p1beg = (x1end>x1beg)?-fabs(d1s)/2:fabs(d1s)/2;
	p1end = (x1end>x1beg)?fabs(d1s)/2:-fabs(d1s)/2;
	p2beg = (x2end>x2beg)?-fabs(d2s)/2:fabs(d2s)/2;
	p2end = (x2end>x2beg)?fabs(d2s)/2:-fabs(d2s)/2;

	/* convert axes box parameters from inches to points */
	xbox *= 72.0;
	ybox *= 72.0;
	width *= 72.0;
	height *= 72.0;
	if (legend) {
	  lx *= 72.0; /* Schoenfelder */
	  ly *= 72.0; /* Schoenfelder */
	  lwidth *= 72.0; /* Schoenfelder */
	  lheight *= 72.0; /* Schoenfelder */
	}

	/* set bounding box */
	psAxesBBox(
		   xbox,ybox,width,height,
		   labelfont,labelsize,
		   titlefont,titlesize,
		   style,bbox);
	if (legend) {
	  psLegendBBox( /* Space for legend Schoenfelder */
			lx,ly,lwidth,lheight,
			labelfont,labelsize,
			lstyle,lbbox);
	  /* Include space for legend Schoenfelder */
	  bbox[0]=MIN(bbox[0],lbbox[0]);
	  bbox[1]=MIN(bbox[1],lbbox[1]);
	  bbox[2]=MAX(bbox[2],lbbox[2]);
	  bbox[3]=MAX(bbox[3],lbbox[3]);
	}
	boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]);
	/* begin PostScript */
	begineps();

	/* save graphics state */
	gsave();

	/* translate coordinate system by box offset */
	translate(xbox,ybox);

	/* determine image matrix */
	if (style==NORMAL) {
		matrix[0] = 0;	matrix[1] = n1s;  matrix[2] = n2s;
		matrix[3] = 0;	matrix[4] = 0;	matrix[5] = 0;
	} else {
		matrix[0] = n2s;  matrix[1] = 0;  matrix[2] = 0;
		matrix[3] = -n1s;  matrix[4] = 0;  matrix[5] = n1s;
	}

	scale(width,height);

	/* draw the image (before axes so grid lines are visible) */
	drawimage(hls,colors,n2s,n1s,bps,matrix,sz);
	/***************************/
	/* main image has been drawn, restore graphics state */
	grestore();

	/* *********************************/
	/* draw the colorbar (before axes so grid lines are visible) Schoenfelder*/
	if (legend) {
	  gsave();
	  translate(lx,ly);
	  scale(lwidth,lheight);
	  if ((lstyle==VERTLEFT) || (lstyle==VERTRIGHT)) {
	    labmatrix[0] = 1;	 labmatrix[1] = 0;  labmatrix[2] = 0;
	    labmatrix[3] = ln; labmatrix[4] = 0;  labmatrix[5] = 0;
	    drawimage(hls,colors,1,ln,bps,labmatrix,data_legend);
	  } else {
	    labmatrix[0] = -1;	 labmatrix[1] = 0;  labmatrix[2] = 0;
	    labmatrix[3] = ln; labmatrix[4] = 0;  labmatrix[5] = 0;
	    rotate(-90);
	    drawimage(hls,colors,1,ln,bps,labmatrix,data_legend);
	    rotate(90);
	  }
	  
	  grestore();
	}

	/* draw curve */
	for (i=0; i<curve; i++) {
		gsave();
		psDrawCurve(
			xbox,ybox,width,height,
			x1beg,x1end,p1beg,p1end, 
			x2beg,x2end,p2beg,p2end,
			x1curve[i],x2curve[i],npair[i],
			curvecolor[i],curvewidth[i],curvedash[i],style);
		grestore();
	}


	gsave();
	/* draw axes and title */
	psAxesBox(
		  xbox,ybox,width,height,
		  x1beg,x1end,p1beg,p1end,
		  d1num,f1num,n1tic,grid1,label1,
		  x2beg,x2end,p2beg,p2end,
		  d2num,f2num,n2tic,grid2,label2,
		  labelfont,labelsize,
		  title,titlefont,titlesize,
		  titlecolor,axescolor,gridcolor,
		  ticwidth,axeswidth,gridwidth,
		  style);
	/* restore graphics state */
	grestore();

	/* draw axes and title for legend Schoenfelder*/
	if (legend) {
	  float lpbeg,lpend;
	  int lntic=1;
	  gsave();
	  lpbeg = 0.0; /*(lend>lbeg)?-fabs(d1s)/2:fabs(d1s)/2;*/
	  lpend = 0.0; /*(lend>lbeg)?fabs(d1s)/2:-fabs(d1s)/2;*/
	  
	  psLegendBox(
		    lx,ly,lwidth,lheight,
		    lbeg,lend,lpbeg,lpend,
		    ldnum,lf,lntic,ugrid,units,
		    labelfont,labelsize,
		    axescolor,gridcolor,
		    lstyle);
	  grestore();
	}

	/* end PostScript */
	showpage();
	endeps();

	if (curve) {
		free1int(npair);
		for (i=0; i<curve; i++) {
			free1float(x1curve[i]);
			free1float(x2curve[i]);
		}
		free1float(curvewidth);
		free1int(curvedash);
		free((void**)x1curve);
		free((void**)x2curve);
		free((void**)curvefile);
		free((void**)curvecolor);
	}

	return 0;
}