scaxis.c

来自「seismic software,very useful」· C语言 代码 · 共 72 行

C
72
字号
/* Copyright (c) Colorado School of Mines, 1990./* All rights reserved.                       */#include <math.h>voidscaxis (float x1, float x2, int *nxnum, float *dxnum, float *fxnum)/*****************************************************************************compute a readable scale for use in plotting axes******************************************************************************Input:x1		first x valuex2		second x valuenxnum		desired number of numbered valuesOutput:nxnum		number of numbered valuesdxnum		increment between numbered values (dxnum>0.0)fxnum		first numbered value******************************************************************************Notes:scaxis attempts to honor the user-specified nxnum.  However, nxnumwill be modified if necessary for readability.  Also, fxnum and nxnumwill be adjusted to compensate for roundoff error; in particular, fxnum will not be less than xmin-eps, and fxnum+(nxnum-1)*dxnum will not be greater than xmax+eps, where eps = 0.0001*(xmax-xmin).xmin is the minimum of x1 and x2.  xmax is the maximum of x1 and x2.******************************************************************************Author:		Dave Hale, Colorado School of Mines, 01/13/89*****************************************************************************/{	int n,i,iloga;	float d,f,rint[4],eps,a,b,xmin,xmax;	/* set readable intervals */	rint[0] = 1.0;  rint[1] = 2.0;  rint[2] = 5.0;  rint[3] = 10.0;	/* handle x1==x2 as a special case */	if  (x1==x2) {		*nxnum = 1;		*dxnum = 1.0;		*fxnum = x1;		return;	}	/* determine minimum and maximum x */	xmin = (x1<x2)?x1:x2;	xmax = (x1>x2)?x1:x2;		/* get desired number of numbered values */	n = *nxnum;	n = (2>n)?2:n;		/* determine output parameters, adjusted for roundoff */	a = (xmax-xmin)/(float)(n-1);	iloga = (int)log10(a);	if (a<1.0) iloga = iloga - 1;	b = a/pow(10.0,(double)iloga);	for (i=0; i<3 && b>=sqrt(rint[i]*rint[i+1]); i++);	d = rint[i]*pow(10.0,(float)iloga);	f = ((int)(xmin/d))*d-d;	eps = 0.0001*(xmax-xmin);	while(f<(xmin-eps))		 f = f+d;	n = 1+(int)((xmax+eps-f)/d);         	/* set output parameters before returning */	*nxnum = n;	*dxnum = d;	*fxnum = f;}

⌨️ 快捷键说明

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