⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ximage.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 4 页
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//* XIMAGE: $Revision: 1.43 $ ; $Date: 2005/10/04 17:28:06 $	*/#include "par.h"#include "xplot.h"#include <X11/Xatom.h>#include <X11/keysym.h>/* ZM: interpolate the amplitude from dataset */float getamp(float *zz,float f1,float d1,int n1,             float f2,float d2,int n2,float x1,float x2,int verbose);/*********************** self documentation **********************/char *sdoc[] = {"									"," XIMAGE - X IMAGE plot of a uniformly-sampled function f(x1,x2)     	","									"," ximage n1= [optional parameters] <binaryfile			        ","									"," X Functionality:							"," Button 1	Zoom with rubberband box				"," Button 2	Show mouse (x1,x2) coordinates while pressed		"," q or Q key	Quit							"," s key		Save current mouse (x1,x2) location to file		"," p or P key	Plot current window with pswigb (only from disk files)	"," a or page up keys		enhance clipping by 10%			"," c or page down keys		reduce clipping by 10%			"," up,down,left,right keys	move zoom window by half width/height	"," i or +(keypad) 		zoom in by factor 2 			"," o or -(keypad) 		zoom out by factor 2 			","									"," ... change colormap interactively					"," r	     install next RGB - colormap				"," R	     install previous RGB - colormap				"," h	     install next HSV - colormap				"," H	     install previous HSV - colormap				"," H	     install previous HSV - colormap				"," (Move mouse cursor out and back into window for r,R,h,H to take effect)"," 									"," Required Parameters:							"," n1			 number of samples in 1st (fast) dimension	","									"," Optional Parameters:							"," d1=1.0		 sampling interval in 1st dimension		"," f1=0.0		 first sample in 1st dimension			"," n2=all		 number of samples in 2nd (slow) dimension	"," d2=1.0		 sampling interval in 2nd dimension		"," f2=0.0		 first sample in 2nd dimension			"," mpicks=/dev/tty	 file to save mouse picks in			"," perc=100.0		 percentile used to determine clip		"," clip=(perc percentile) clip used to determine bclip and wclip		"," bperc=perc		 percentile for determining black clip value	"," wperc=100.0-perc	 percentile for determining white clip value	"," bclip=clip		 data values outside of [bclip,wclip] are clipped"," wclip=-clip		 data values outside of [bclip,wclip] are clipped"," balance=0		 bclip & wclip individually			","			 =1 set them to the same abs value		","			   if specified via perc (avoids colorbar skew)	"," cmap=hsv\'n\' or rgb\'m\'	\'n\' is a number from 0 to 13		","				\'m\' is a number from 0 to 11		","				cmap=rgb0 is equal to cmap=gray		","				cmap=hsv1 is equal to cmap=hue		","				(compatibility to older versions)	"," legend=0	        =1 display the color scale			"," units=		unit label for legend				"," legendfont=times_roman10    font name for title			"," verbose=1		=1 for info printed on stderr (0 for no info)	"," xbox=50		x in pixels of upper left corner of window	"," ybox=50		y in pixels of upper left corner of window	"," wbox=550		width in pixels of window			"," hbox=700		height in pixels of window			"," lwidth=16		colorscale (legend) width in pixels		"," lheight=hbox/3	colorscale (legend) height in pixels		"," lx=3			colorscale (legend) x-position in pixels	"," ly=(hbox-lheight)/3   colorscale (legend) y-position in pixels	"," x1beg=x1min		value at which axis 1 begins			"," x1end=x1max		value at which axis 1 ends			"," d1num=0.0		numbered tic interval on axis 1 (0.0 for automatic)"," f1num=x1min		first numbered tic on axis 1 (used if d1num not 0.0)"," n1tic=1		number of tics per numbered tic on axis 1	"," grid1=none		grid lines on axis 1 - none, dot, dash, or solid"," label1=		label on axis 1					"," x2beg=x2min		value at which axis 2 begins			"," x2end=x2max		value at which axis 2 ends			"," d2num=0.0		numbered tic interval on axis 2 (0.0 for automatic)"," f2num=x2min		first numbered tic on axis 2 (used if d2num not 0.0)"," n2tic=1		number of tics per numbered tic on axis 2	"," grid2=none		grid lines on axis 2 - none, dot, dash, or solid"," label2=		label on axis 2					"," labelfont=Erg14	font name for axes labels			"," title=		title of plot					"," titlefont=Rom22	font name for title				"," windowtitle=ximage	title on window					"," labelcolor=blue	color for axes labels				"," titlecolor=red	color for title					"," gridcolor=blue	color for grid lines				"," style=seismic	        normal (axis 1 horizontal, axis 2 vertical) or  ","			seismic (axis 1 vertical, axis 2 horizontal)	"," blank=0		This indicates what portion of the lower range  ","			to blank out (make the background color).  The  ","			value should range from 0 to 1.			"," plotfile=plotfile.ps  filename for interactive ploting (P)  		"," curve=curve1,curve2,...  file(s) containing points to draw curve(s)   "," npair=n1,n2,n2,...            number(s) of pairs in each file         "," curvecolor=color1,color2,...  color(s) for curve(s)                   "," blockinterp=0       whether to use block interpolation (0=no, 1=yes)  ","									","									"," NOTES:								"," The curve file is an ascii file with the points  specified as x1 x2	"," pairs separated by a space, one pair to a line.  A \"vector\" of curve"," files and curve colors may be specified as curvefile=file1,file2,etc. "," and curvecolor=color1,color2,etc, and the number of pairs of values   "," in each file as npair=npair1,npair2,... .                             ","									",NULL};/* * AUTHOR:  Dave Hale, Colorado School of Mines, 08/09/90 * * Stewart A. Levin, Mobil - Added ps print option * * Brian Zook, Southwest Research Institute, 6/27/96, added blank option * * Toralf Foerster, Baltic Sea Research Institute, 9/15/96, new colormaps * * Berend Scheffers, Delft, colorbar (legend) * * Brian K. Macy, Phillips Petroleum, 11/27/98, added curve plotting option *  * G.Klein, GEOMAR Kiel, 2004-03-12, added cursor scrolling and *                                   interactive change of zoom and clipping. *  * Zhaobo Meng, ConocoPhillips, 12/02/04, added amplitude display *  * Garry Perratt, Geocon, 08/04/05, modified perc handling to center colorbar if balance==1. *//**************** end self doc ********************************//* functions defined and used internally */static void zoomBox (int x, int y, int w, int h, 	int xb, int yb, int wb, int hb,	int nx, int ix, float x1, float x2,	int ny, int iy, float y1, float y2,	int *nxb, int *ixb, float *x1b, float *x2b,	int *nyb, int *iby, float *y1b, float *y2b);static unsigned char *newInterpBytes (int n1in, int n2in, unsigned char *bin,	int n1out, int n2out, int newInterpBytes);void xMouseLoc(Display *dpy, Window win, XEvent event, int style, Bool show,	int x, int y, int width, int height,	float x1begb, float x1endb, float x2begb, float x2endb,        float *z, float f1, float d1, int n1,float f2, float d2,         int n2, int verbose);void xMousePrint(XEvent event, int style, FILE *mpicksfp,	int x, int y, int width, int height,	float x1begb, float x1endb, float x2begb, float x2endb);/* JG... */void intl2b_block(int nxin, float dxin, float fxin,				  int nyin, float dyin, float fyin, unsigned char *zin,				  int nxout, float dxout, float fxout,				  int nyout, float dyout, float fyout, unsigned char *zout);/* .... JG */intmain (int argc,char **argv){	int n1,n2,n1tic,n2tic,		i1,i2,grid1,grid2,style,		n1c,n2c,i1beg,i1end,i2beg,i2end,i1c,i2c,		nz,iz,i1step,i2step,verbose,		xbox,ybox,wbox,hbox,		xb,yb,wb,hb,		x,y,width,height,		i,j,nx,ny,nxb,nyb,ixb,iyb,		imageOutOfDate,winwidth=-1,winheight=-1,		showloc=0,		balance,		legend,lwidth,lheight,lx,ly; /* BEREND */	int blockinterp=0; /* JG */        int base;        float fact;        unsigned char* ptr;	unsigned long nfloats;	float labelsize,titlesize,perc,clip,bperc,wperc,bclip,wclip,		d1,f1,d2,f2,*z,*temp,zscale,zoffset,zi,dx,dy,		x1beg,x1end,x2beg,x2end,		x1min,x1max,x2min,x2max,		d1num,f1num,d2num,f2num,		x1begb,x1endb,x2begb,x2endb,blank; /* dx,dy added GK */	unsigned char *cz,*czp,*czb,*czbp,*czbi=NULL;	char *label1="",*label2="",*title="",*windowtitle="ximage",		*units="", *legendfont="times_roman10",		*labelfont="Erg14",*titlefont="Rom22",		*styles="seismic",*grid1s="none",*grid2s="none",		*labelcolor="blue",*titlecolor="red",		*gridcolor="blue",*cmap="",keybuf[256],*mpicks;	FILE *infp=stdin, *mpicksfp;	Display *dpy;	Window win;	XEvent event;	KeySym keysym;	XComposeStatus keystat;	XImage *image=NULL;	XImage *image_legend=NULL; /* BEREND */	unsigned char *data_legend; /* BEREND */	GC gci;	int scr;	unsigned long black,white,pmin,pmax;        float **x1curve,**x2curve;        int curve,*npair,ncurvecolor;        char **curvefile,**curvecolor=NULL;        FILE *curvefp;		char *plotfile;         /* filename of plotfile GK */	int lock=0;		/* lock/unlock zoom while scrolling */	float mve;		/* distance for scrolling */	float mvefac=8.;	/* window factor for scrolldistance 	                         * 2=half window size; 				 * 8=one eighths of the window size */	char  *msg="";		/* message on screen */	/* initialize getpar */	initargs(argc,argv);	requestdoc(1);	/* get parameters describing 1st dimension sampling */	if (!getparint("n1",&n1))		err("Must specify number of samples in 1st dimension!\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!");		nfloats = (int) (eftello(infp)/( (off_t) sizeof(float)));		efseeko(infp, (off_t) 0,SEEK_SET);		n2 = (int) (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;	/* set up file to save postscript plot * GK */	if (!getparstring("plotfile", &plotfile))  plotfile = "plotfile.ps" ;	/* set up file to save mouse picks */	if (!getparstring("mpicks", &mpicks)) mpicks = "/dev/tty";	mpicksfp = efopen(mpicks, "w");	/* 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);	} else {		npair=(int *)NULL;		curvefile=(char **)NULL;		x1curve=(float **)NULL;		x2curve=(float **)NULL;	}	if ((ncurvecolor=countparval("curvecolor"))<curve) {		curvecolor=(char**)ealloc1(curve,sizeof(void*));		if (!getparstringarray("curvecolor",curvecolor)) {			curvecolor[0]=(char *)cwp_strdup("blue\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);	}        if (!getparfloat("d2",&d2)) d2 = 1.0;	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 binary data to be plotted */	nz = n1*n2;	z = ealloc1float(nz);	if (fread(z,sizeof(float),nz,infp)!=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);		balance=0 ; getparint("balance",&balance);		temp = ealloc1float(nz);		/* Modded by GCP to balance bclip & wclip */		if (balance==0)			for (iz=0; iz<nz; ++iz) {				temp[iz] = z[iz];			} else { 				for (iz=0; iz<nz; ++iz) temp[iz] = abs(z[iz]);				perc=100.0;			}		/* End of modded code */		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);			/* Modded by GCP to balance bclip & wclip */			if (balance==0) wclip = temp[iz];			else wclip = -1*bclip;			/* End of modded code */		}		free1float(temp);	}	verbose = 1;  getparint("verbose",&verbose);	if (verbose) warn("bclip=%g wclip=%g",bclip,wclip);	/* get colormap specification */	if (!(getparstring("cmap",&cmap))) {		cmap = (char *)alloc1(5,1);		sprintf(cmap,"%s","gray");	}		/* get interpolation style JG */	if (!(getparint("blockinterp", &blockinterp))) blockinterp=0;	/* get legend specs BEREND */	legend = 0; getparint("legend", &legend); /* BEREND */	getparstring("units", &units); /* BEREND */	getparstring("legendfont", &legendfont);     /* BEREND */	blank = 0; getparfloat("blank",&blank);	/* get axes parameters */	xbox = 50; getparint("xbox",&xbox);	ybox = 50; getparint("ybox",&ybox);	wbox = 550; getparint("wbox",&wbox);	hbox = 700; getparint("hbox",&hbox);	/* legend dimensions */	if (!(getparint("lwidth",&lwidth)))	lwidth = 16;	if (!(getparint("lheight",&lheight)))	lheight = hbox/3;	if (!(getparint("lx",&lx)))	lx = 3;	if (!(getparint("ly",&ly)))	ly = (hbox-lheight)/3;	x1beg = x1min; getparfloat("x1beg",&x1beg);	x1end = x1max; getparfloat("x1end",&x1end);	d1num = 0.0; getparfloat("d1num",&d1num);	f1num = x1min; getparfloat("f1num",&f1num);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -