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

📄 xgraph.c

📁 seismic software,very useful
💻 C
📖 第 1 页 / 共 2 页
字号:
	}	if (getparstring("titleFont",&titleFont)) {		from.addr = (caddr_t)titleFont;		XtConvert(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);	XcwpSetAxesValues(axes,x1beg,x1end,x2beg,x2end);	/* get graph parameters */	for (i=0; i<nplot; i++) {		mark[i] = i%NMARKS;		marksize[i] = 0;		linewidth[i] = 1;		linecolor[i] = 2+i%6;	}	if (npar=getparint("mark",mark))		for (j=npar; j<nplot; j++)			mark[j] = mark[npar-1];	if (npar=getparint("marksize",marksize))		for (j=npar; j<nplot; j++)			marksize[j] = marksize[npar-1];	if (npar=getparint("linewidth",linewidth))		for (j=npar; j<nplot; j++)			linewidth[j] = linewidth[npar-1];	if (npar=getparint("linecolor",linecolor))		for (j=npar; j<nplot; j++)			linecolor[j] = linecolor[npar-1];	/* add callbacks to axes widget */	XtAddCallback(axes,XtNresizeCallback,resizeCB,NULL);	exposeCD.nplot = nplot;	exposeCD.n = &n[0];	exposeCD.data = data;	exposeCD.linewidth = &linewidth[0];	exposeCD.linecolor = &linecolor[0];	exposeCD.mark = &mark[0];	exposeCD.marksize = &marksize[0];	XtAddCallback(axes,XtNexposeCallback,exposeCB,&exposeCD);	XtAddCallback(axes,XtNinputCallback,inputCB,NULL);	/* avoid XIO message */	XSetIOErrorHandler(xIoErrorHandler);	/* realize and go */	XtRealizeWidget(toplevel);	XtMainLoop();}void resizeCB (Widget w, 	caddr_t clientdata,	XcwpAxesCallbackStruct *ca){	/* printf("resize callback\n"); */}#define NCOLOR 8static char *color[NCOLOR] = {	"black",	"white",	"red",	"green",	"blue",	"cyan",	"magenta",	"yellow",};void exposeCB (Widget w, 	ExposeCD *cd,	XcwpAxesCallbackStruct *ca){	int nplot=cd->nplot;	int *n=cd->n;	float **data=cd->data;	int *linewidth=cd->linewidth;	int *linecolor=cd->linecolor;	int *mark=cd->mark;	int *marksize=cd->marksize;	Position x=ca->x,y=ca->y;	Dimension width=ca->width,height=ca->height;	float x1beg=ca->x1beg,x1end=ca->x1end,		x2beg=ca->x2beg,x2end=ca->x2end;	int style=ca->style;	Display *dpy=XtDisplay(w);	Window win=XtWindow(w);	XWindowAttributes wa;	Colormap cmap;	XColor scolor,ecolor;	XRectangle rect;	long black=BlackPixelOfScreen(XtScreen(w));	GC gc;	int iplot,icolor;	float xmin,xmax,ymin,ymax,xbase,xscale,ybase,yscale;	static int firstexpose=1;	/* if first expose, check style and, if necessary, swap x,y coords */	if (firstexpose) {		if (style==XcwpSEISMIC) {			for (iplot=0; iplot<nplot; ++iplot) {				int ni=n[iplot],i;				for (i=0; i<ni; ++i) {					float temp=data[iplot][2*i];					data[iplot][2*i] = data[iplot][2*i+1];					data[iplot][2*i+1] = temp;				}			}		}		firstexpose = 0;	}		/* determine current colormap */	XGetWindowAttributes(dpy,win,&wa);	cmap = wa.colormap;	/* create GC */	gc = XCreateGC(dpy,win,0L,NULL);		/* set clip to axes box */	rect.x = x;  rect.y = y;  rect.width = width;  rect.height = height;	XSetClipRectangles(dpy,gc,0,0,&rect,1,Unsorted);	/* determine min and max coordinates */	xmin = x;	xmax = x+(float)width;	ymin = y;	ymax = y+(float)height;	/* determine base and scale factors */	if (style==XcwpNORMAL) {		xscale = (float)width/(x1end-x1beg);		xbase = x-x1beg*xscale;		yscale = (float)height/(x2beg-x2end);		ybase = y-x2end*yscale;	} else {		xscale = (float)width/(x2end-x2beg);		xbase = x-x2beg*xscale;		yscale = (float)height/(x1end-x1beg);		ybase = y-x1beg*yscale;	}		/* loop over plots */	for (iplot=0; iplot<nplot; ++iplot) {		/* set line width */		XSetLineAttributes(dpy,gc,			linewidth[iplot],			LineSolid,			CapButt,			JoinMiter);				/* set line color */		icolor = linecolor[iplot];		if (icolor<0) icolor = 0;		else if (icolor>=NCOLOR) icolor = NCOLOR-1;		if (XAllocNamedColor(dpy,cmap,color[icolor],&scolor,&ecolor))			XSetForeground(dpy,gc,ecolor.pixel);		else			XSetForeground(dpy,gc,black);				/* draw lines between points */		if (linewidth[iplot]!=0) {			int xi,yi,in,xilast,yilast,inlast,i,ni=n[iplot];			float *pdata;						pdata = data[iplot];			xi = xbase+xscale*(*pdata++);			yi = ybase+yscale*(*pdata++);			in = (xi>=xmin && xi<=xmax && yi>=ymin && yi<=ymax);			for (i=1; i<ni; ++i) {				xilast = xi;				yilast = yi;				inlast = in;				xi = xbase+xscale*(*pdata++);				yi = ybase+yscale*(*pdata++);				in = (xi>=xmin && xi<=xmax && 					yi>=ymin && yi<=ymax);				if (in || inlast)					XDrawLine(dpy,win,gc,						xilast,yilast,xi,yi);			}		}		/* draw marks at points */		if (marksize[iplot]!=0) {			int xi,yi,in,i,ni=n[iplot];			float *pdata;						pdata = data[iplot];			for (i=0; i<ni; ++i) {				xi = xbase+xscale*(*pdata++);				yi = ybase+yscale*(*pdata++);				in = (xi>=xmin && xi<=xmax && 					yi>=ymin && yi<=ymax);				if (in) xDrawMark(dpy,win,gc,xi,yi,					mark[iplot],marksize[iplot]);			}		}	}	/* free GC */	XFreeGC(dpy,gc);}void inputCB (Widget w, 	caddr_t clientdata,	XcwpAxesCallbackStruct *ca){	int x=ca->x,y=ca->y,width=ca->width,height=ca->height;	float x1beg=ca->x1beg,x1end=ca->x1end,x2beg=ca->x2beg,x2end=ca->x2end;	int style=ca->style;	XEvent *event=ca->event;	int xb,yb,wb,hb;	float x1begn,x1endn,x2begn,x2endn;	static int firstinput=1;	static float x1begs,x1ends,x2begs,x2ends;	/* if first input, save initial axes limits */	if (firstinput) {		x1begs = x1beg;		x1ends = x1end;		x2begs = x2beg;		x2ends = x2end;		firstinput = 0;	}		/* track pointer and get rubber box */	xRubberBox(XtDisplay(w),XtWindow(w),*event,&xb,&yb,&wb,&hb);	/* if new box has zero width or height */	if (wb==0 || hb==0) {		/* restore initial limits */		XcwpSetAxesValues(w,x1begs,x1ends,x2begs,x2ends);		/* else if non-zero zoom box */	} else {			/* clip box */		if (xb<x) {			wb -= x-xb;			xb = x;		}		if (yb<y) {			hb -= y-yb;			yb = y;		}		if (xb+wb>x+width) wb = x-xb+width;		if (yb+hb>y+height) hb = y-yb+height;			/* determine axes limits */		if (style==XcwpNORMAL) {			x1begn = x1beg+(xb-x)*(x1end-x1beg)/width;			x1endn = x1beg+(xb+wb-x)*(x1end-x1beg)/width;			x2begn = x2end+(yb+hb-y)*(x2beg-x2end)/height;			x2endn = x2end+(yb-y)*(x2beg-x2end)/height;		} else {			x1endn = x1beg+(yb+hb-y)*(x1end-x1beg)/height;			x1begn = x1beg+(yb-y)*(x1end-x1beg)/height;			x2begn = x2beg+(xb-x)*(x2end-x2beg)/width;			x2endn = x2beg+(xb+wb-x)*(x2end-x2beg)/width;		}			/* set axes limits */		XcwpSetAxesValues(w,x1begn,x1endn,x2begn,x2endn);	}		/* force an expose event */	XClearArea(XtDisplay(w),XtWindow(w),0,0,0,0,True);}static void xDrawMark(Display *dpy, Drawable d, GC gc,	int x, int y, int index, int size){	XPoint points[4];	switch (index%NMARKS) {	case MPLUS: /* plus */		XDrawLine(dpy,d,gc,x-(int)(0.5*size),y,x+(int)(0.5*size),y);		XDrawLine(dpy,d,gc,x,y-(int)(0.5*size),x,y+(int)(0.5*size));		break;	case MASTERISK: /* asterisk */		XDrawLine(dpy,d,gc,x-(int)(0.5*size),y,x+(int)(0.5*size),y);		XDrawLine(dpy,d,gc,x-(int)(0.25*size),y-(int)(0.433*size),			x+(int)(0.25*size),y+(int)(0.433*size));		XDrawLine(dpy,d,gc,x+(int)(0.25*size),y-(int)(0.433*size),			x-(int)(0.25*size),y+(int)(0.433*size));		break;	case MCROSS: /* X */		XDrawLine(dpy,d,gc,x-(int)(0.5*size),y-(int)(0.5*size),			x+(int)(0.5*size),y+(int)(0.5*size));		XDrawLine(dpy,d,gc,x+(int)(0.5*size),y-(int)(0.5*size),			x-(int)(0.5*size),y+(int)(0.5*size));		break;	case MTRIANGLE: /* triangle */		points[0].x = x-(int)(0.5*size);  		points[0].y = y+(int)(0.25*size);		points[1].x = x+(int)(0.5*size);  		points[1].y = y+(int)(0.25*size);		points[2].x = x;           		points[2].y = y-(int)(0.559*size);		points[3].x = x-(int)(0.5*size);  		points[3].y = y+(int)(0.25*size);		XDrawLines(dpy,d,gc,points,4,CoordModeOrigin);		break;	case MSQUARE: /* square */		XDrawRectangle(dpy,d,gc,x-(int)(0.5*size),y-(int)(0.5*size),			size,size);		break;	case MCIRCLE: /* circle */		XDrawArc(dpy,d,gc,x-(int)(0.5*size),y-(int)(0.5*size),			size,size,0,360*64);		break;	case MFILLEDTRIANGLE: /* filled triangle */		points[0].x = x-(int)(0.75*size);  		points[0].y = y+(int)(0.375*size);		points[1].x = x+(int)(0.75*size);  		points[1].y = y+(int)(0.375*size);		points[2].x = x;           		points[2].y = y-(int)(0.838*size);		points[3].x = x-(int)(0.75*size);  		points[3].y = y+(int)(0.375*size);		XFillPolygon(dpy,d,gc,points,4,Convex,CoordModeOrigin);		break;	case MFILLEDSQUARE: /* filled square */		XFillRectangle(dpy,d,gc,x-(int)(0.5*size),y-(int)(0.5*size),			size,size);		break;	case MFILLEDCIRCLE: /* filled circle */		XFillArc(dpy,d,gc,x-(int)(0.5*size),y-(int)(0.5*size),			size,size,0,360*64);		break;	}}int xIoErrorHandler() {	exit(0);}

⌨️ 快捷键说明

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