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

📄 xgraph.c

📁 seismic software,very useful
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) Colorado School of Mines, 1990. *//* All rights reserved.                       */char *sdoc ="XGRAPH - X GRAPHer\n""Graphs n[i] pairs of (x,y) coordinates, for i = 1 to nplot.\n""\n""xgraph n= [optional parameters] <binaryfile \n""\n""Required Parameters:\n""n                      array containing number of points per plot\n""\n""Optional Parameters:\n""nplot=number of n's    number of plots\n""d1=0.0,...             x sampling intervals (0.0 if x coordinates input)\n""f1=0.0,...             first x values (not used if x coordinates input)\n""d2=0.0,...             y sampling intervals (0.0 if y coordinates input)\n""f2=0.0,...             first y values (not used if y coordinates input)\n""linewidth=1,1,...      line widths in pixels (0 for no lines)\n""linecolor=2,3,...      line colors (black=0, white=1, 2,3,4 = RGB, ...)\n""mark=0,1,2,3,...       indices of marks used to represent plotted points\n""marksize=0,0,...       size of marks in pixels (0 for no marks)\n""x1beg=x1min            value at which axis 1 begins\n""x1end=x1max            value at which axis 1 ends\n""x2beg=x2min            value at which axis 2 begins\n""x2end=x2max            value at which axis 2 ends\n""\n""Optional resource parameters (defaults taken from resource database):\n""width=                 width in pixels of window\n""height=                height in pixels of window\n""nTic1=                 number of tics per numbered tic on axis 1\n""grid1=                 grid lines on axis 1 - none, dot, dash, or solid\n""label1=                label on axis 1\n""nTic2=                 number of tics per numbered tic on axis 2\n""grid2=                 grid lines on axis 2 - none, dot, dash, or solid\n""label2=                label on axis 2\n""labelFont=             font name for axes labels\n""title=                 title of plot\n""titleFont=             font name for title\n""titleColor=            color for title\n""axesColor=             color for axes\n""gridColor=             color for grid lines\n""style=                 normal (axis 1 horizontal, axis 2 vertical) or\n""                       seismic (axis 1 vertical, axis 2 horizontal)\n""\n""Data formats supported:\n""	1. x1,y1,x2,y2,...,xn,yn\n""	2. y1,y2,...,yn (must give non-zero d1[]=)\n""	3. x1,x2,...,xn (must give non-zero d2[]=)\n""	4. nil (must give non-zero d1[]= and non-zero d2[]=)\n""  The formats may be repeated and mixed in any order, but if\n""  formats 2-4 are used, the d1 and d2 arrays must be specified including\n""  d1[]=0.0 d2[]=0.0 entries for any internal occurences of format 1.\n""  Also, if formats 2-4 are used with non-zero f1[] or f2[] entries, then\n""  the corresponding array(s) must be fully specified including f1[]=0.0\n""  and/or f2[]=0.0 entries for any internal occurences of format 1 or\n""  formats 2-4 where the zero entries are desired.\n""\n""Note:	n1 and n2 are acceptable aliases for n and nplot, respectively.\n""\n""Example:\n""xgraph n=50,100,20 d1=2.5,1,0.33 <datafile\n""  plots three curves with equally spaced x values in one plot frame\n""  x1-coordinates are x1(i) = f1+i*d1 for i = 1 to n (f1=0 by default)\n""  number of x2's and then x2-coordinates for each curve are read\n""  sequentially from datafile.\n""\n""AUTHOR:  Dave Hale and Lydia Deng, Colorado School of Mines, 01/17/91\n""MODIFIED:  Dave Hale, Colorado School of Mines, 04/18/91\n""           fixed conversion of command line resource parameters\n""           Zhiming Li,       	12/18/92	\n""           added XIO error handler		\n"  "\n";#include <stdio.h>#include "par.h"#include "Xcwp/Xcwp.h"#include "Xcwp/Axes.h"/* client data structures for callbacks */typedef struct ExposeCDStruct {	int nplot;	int *n;	float **data;	int *linewidth;	int *linecolor;	int *mark;	int *marksize;} ExposeCD;/* callback functions *//*void resizeCB (XcwpAxesWidget w, 	caddr_t clientdata,	XcwpAxesCallbackStruct *calldata);void exposeCB (XcwpAxesWidget w, 	ExposeCD *clientdata,	XcwpAxesCallbackStruct *calldata);void inputCB (XcwpAxesWidget w, 	caddr_t clientdata,	XcwpAxesCallbackStruct *calldata);*/void resizeCB (Widget w, 	caddr_t clientdata,	XcwpAxesCallbackStruct *calldata);void exposeCB (Widget w, 	ExposeCD *clientdata,	XcwpAxesCallbackStruct *calldata);void inputCB (Widget w, 	caddr_t clientdata,	XcwpAxesCallbackStruct *calldata);/* functions defined and used internally */static void xDrawMark(Display *dpy, Drawable d, GC gc,	int x, int y, int index, int size);/* XIO error handler */int xIoErrorHandler();#define NPMAX 5000	/* Arbitrary maximum number of plots allowed	*/#define NMARKS 9#define MPLUS 0#define MASTERISK 1#define MCROSS 2#define MTRIANGLE 3#define MSQUARE 4#define MCIRCLE 5#define MFILLEDTRIANGLE 6#define MFILLEDSQUARE 7#define MFILLEDCIRCLE 8#ifdef __convex__#else	#define FLT_MAX MAXFLOAT#endifmain (int argc, char **argv){	int nplot,n[NPMAX],nn,iplot,npoint,nTic1,nTic2,		i,j,npar,ni,bbox[4],nd1,nf1,nd2,nf2,		linewidth[NPMAX],linecolor[NPMAX],		mark[NPMAX],marksize[NPMAX],width,height;	float d1[NPMAX],f1[NPMAX],d2[NPMAX],f2[NPMAX],		x1beg,x2beg,x1end,x2end,		x1min,x1max,x2min,x2max,		xsize,ysize,xscale,yscale;	char *label1="",*label2="",*title="",		*labelFont="",*titleFont="",		*axesColor="",*gridColor="",*titleColor="",		*style="normal",*grid1="none",*grid2="none";	float **data;	XrmValue from,to;	ExposeCD exposeCD;	Widget toplevel,axes;	Arg args[100];	int nargs;	/* initialize getpar */	initargs(argc,argv);	askdoc(1);	/* get parameters needed to interpret datafile */	for (i=0; i<NPMAX; i++) {		d1[i] = 0.0;		f1[i] = 0.0;		d2[i] = 0.0;		f2[i] = 0.0;	}	nd1 = getparfloat("d1",d1); 	nf1 = getparfloat("f1",f1);	nd2 = getparfloat("d2",d2); 	nf2 = getparfloat("f2",f2);	if (!(nn = getparint("n",n)))  nn = getparint("n1",n);	if (nn==0)  err("Must specify n, the number of points per plot!");	nplot = nn; getparint("n2",&nplot); getparint("nplot",&nplot);	if (nplot > NPMAX)  err("too many plots");	for (i=nn; i<nplot; ++i)		n[i] = n[nn-1];	for (i=nd1; i<nplot; ++i)		d1[i] = d1[nd1-1];	for (i=nf1; i<nplot; ++i)		f1[i] = f1[nf1-1];	for (i=nd2; i<nplot; ++i)		d2[i] = d2[nd2-1];	for (i=nf2; i<nplot; ++i)		f2[i] = f2[nf2-1];	/* read, regularize and compute extreme values of data */	data = (float **)malloc(nplot*sizeof(float*));	x2max = x1max = -FLT_MAX;	x2min = x1min =  FLT_MAX;	for (iplot=0; iplot<nplot; ++iplot) {		npoint = n[iplot];		data[iplot] = (float*)malloc(npoint*2*sizeof(float));		/* read data for this plot */		if (d1[iplot] && d2[iplot]) { /* straight line */			float x,y;			register int i;			float *pdata=data[iplot];			for (i=0; i<npoint; ++i) {				x = f1[iplot] + i*d1[iplot];				y = f2[iplot] + i*d2[iplot];				x1max = MAX(x, x1max);				x1min = MIN(x, x1min);				x2max = MAX(y, x2max);				x2min = MIN(y, x2min);				*pdata++ = x;				*pdata++ = y;			}		} else if (d1[iplot]) { /* equally spaced x's */			float x,y;			register int i;			float *pdata=data[iplot];			for (i=0; i<npoint; ++i) {				efread(&y, FSIZE, 1, stdin);				x = f1[iplot] + i*d1[iplot];				x1max = MAX(x, x1max);				x1min = MIN(x, x1min);				x2max = MAX(y, x2max);				x2min = MIN(y, x2min);				*pdata++ = x;				*pdata++ = y;			}		} else if (d2[iplot]) { /* equally spaced y's */			float x,y;			register int i;			float *pdata=data[iplot];			for (i=0; i<npoint; ++i) {				efread(&x, FSIZE, 1, stdin);				y = f2[iplot] + i*d2[iplot];				x1max = MAX(x, x1max);				x1min = MIN(x, x1min);				x2max = MAX(y, x2max);				x2min = MIN(y, x2min);				*pdata++ = x;				*pdata++ = y;			}		} else { /* pairs */			float x,y;			register int i;			float *pdata=data[iplot];			for (i=0; i<npoint; ++i) {				efread(&x, FSIZE, 1, stdin);				efread(&y, FSIZE, 1, stdin);				x1max = MAX(x, x1max);				x1min = MIN(x, x1min);				x2max = MAX(y, x2max);				x2min = MIN(y, x2min);				*pdata++ = x;				*pdata++ = y;			}		}	}	/* cope with special cases */	if (x1min==FLT_MAX) x1min = x1max = 0.0;	if (x2min==FLT_MAX) x2min = x2max = 0.0;	if (x1min == x1max) {		x1min -= 1.0;		x1max += 1.0;	}	if (x2min == x2max) {		x2min -= 1.0;		x2max += 1.0;	}	/* initialize toolkit intrinsics and set toplevel parameters */	toplevel = XtInitialize(argv[0],"Xgraph",NULL,0,&argc,argv);	nargs = 0;	if (getparint("width",&width))		{XtSetArg(args[nargs],XtNwidth,width); nargs++;}	if (getparint("height",&height))		{XtSetArg(args[nargs],XtNheight,height); nargs++;}	XtSetValues(toplevel,args,nargs);	/* create axes and set axes parameters */	axes = XtCreateManagedWidget("axes",xcwpAxesWidgetClass, 		toplevel,NULL,0);	nargs = 0;	if (getparstring("grid1",&grid1)) {		from.addr = (caddr_t)grid1;		XtConvert(axes,XtRString,&from,XcwpRAxesGrid,&to);		if (to.addr) XtSetArg(args[nargs],XtNgrid1,*((int*)to.addr));		nargs++;	}	if (getparstring("grid2",&grid2)) {		from.addr = (caddr_t)grid2;		XtConvert(axes,XtRString,&from,XcwpRAxesGrid,&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",&title))		{XtSetArg(args[nargs],XtNtitle,title); nargs++;}	if (getparstring("style",&style)) {		from.size = strlen(style);  from.addr = (caddr_t)style;		XtConvert(axes,XtRString,&from,XcwpRAxesStyle,&to);		if (to.addr) XtSetArg(args[nargs],XtNstyle,*((int*)to.addr));		nargs++;	}	if (getparstring("axesColor",&axesColor)) {		from.addr = (caddr_t)axesColor;		XtConvert(axes,XtRString,&from,XtRPixel,&to);		if (to.addr) XtSetArg(args[nargs],XtNaxesColor,			*((unsigned long*)to.addr));		nargs++;	}	if (getparstring("gridColor",&gridColor)) {		from.addr = (caddr_t)gridColor;		XtConvert(axes,XtRString,&from,XtRPixel,&to);		if (to.addr) XtSetArg(args[nargs],XtNgridColor,			*((unsigned long*)to.addr));		nargs++;	}	if (getparstring("titleColor",&titleColor)) {		from.addr = (caddr_t)titleColor;		XtConvert(axes,XtRString,&from,XtRPixel,&to);		if (to.addr) XtSetArg(args[nargs],XtNtitleColor,			*((unsigned long*)to.addr));		nargs++;	}	if (getparstring("labelFont",&labelFont)) {		from.addr = (caddr_t)labelFont;		XtConvert(axes,XtRString,&from,XtRFont,&to);		if (to.addr) XtSetArg(args[nargs],XtNlabelFont,			*((Font*)to.addr));		nargs++;

⌨️ 快捷键说明

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