intlin.c

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

C
82
字号
/* Copyright (c) Colorado School of Mines, 1990./* All rights reserved.                       */#include "cwp.h"voidintlin (int nin, float xin[], float yin[], float yinl, float yinr, 	int nout, float xout[], float yout[])/*****************************************************************************evaluate y(x) via linear interpolation of y(x[0]), y(x[1]), ...******************************************************************************Input:nin		length of xin and yin arraysxin		array[nin] of monotonically increasing or decreasing x valuesyin		array[nin] of input y(x) valuesyinl		value used to extraplate y(x) to left of input yin valuesyinr		value used to extraplate y(x) to right of input yin valuesnout		length of xout and yout arraysxout		array[nout] of x values at which to evaluate y(x)Output:yout		array[nout] of linearly interpolated y(x) values******************************************************************************Notes:xin values must be monotonically increasing or decreasing.Extrapolation of the function y(x) for xout values outside the rangespanned by the xin values in performed as follows:	For monotonically increasing xin values,		yout=yinl if xout<xin[0], and yout=yinr if xout>xin[nin-1].	For monotonically decreasing xin values, 		yout=yinl if xout>xin[0], and yout=yinr if xout<xin[nin-1].If nin==1, then the monotonically increasing case is used.******************************************************************************Author:		Dave Hale, Colorado School of Mines, 06/02/89*****************************************************************************/{	static int index;	int jout;	float x;	/* if input x values are monotonically increasing, then */	if (xin[0]<=xin[nin-1]) {		for (jout=0; jout<nout; jout++) {			x = xout[jout];			if (x<xin[0])				yout[jout] = yinl;			else if (x>xin[nin-1])				yout[jout] = yinr;			else if (x==xin[nin-1] || nin==1)				yout[jout] = yin[nin-1];			else {				xindex(nin,xin,x,&index);				yout[jout] = yin[index]+(x-xin[index])					*(yin[index+1]-yin[index])					/(xin[index+1]-xin[index]);			}		}		/* else, if input x values are monotonically decreasing, then */	} else {		for (jout=0; jout<nout; jout++) {			x = xout[jout];			if (x>xin[0])				yout[jout] = yinl;			else if (x<xin[nin-1])				yout[jout] = yinr;			else if (x==xin[nin-1] || nin==1)				yout[jout] = yin[nin-1];			else {				xindex(nin,xin,x,&index);				yout[jout] = yin[index]+(x-xin[index])					*(yin[index+1]-yin[index])					/(xin[index+1]-xin[index]);			}		}	}}

⌨️ 快捷键说明

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