User`s guide

Fully Inlined S-Function with the mdlRTW Routine
4-27
matlabroot/simulink/src/sfun_directlook.c
/*
* File : sfun_directlook.c
* Abstract:
*
* Direct 1-D lookup. Here we are trying to compute an approximate
* solution, p(x) to an unknown function f(x) at x=x0, given data point
* pairs (x,y) in the form of a x data vector and a y data vector. For a
* given data pair (say the i’th pair), we have y_i = f(x_i). It is
* assumed that the x data values are monotonically increasing. If the
* x0 is outside of the range of the x data vector, then the first or
* last point will be returned.
*
* This function returns the “nearest” y0 point for a given x0. No
* interpolation is performed.
*
* The S-function parameters are:
* XData - double vector
* YData - double vector
* XDataEvenlySpacing - double scalar 0 (false) or 1 (true)
* The third parameter cannot be changed during simulation.
*
* To build:
* mex sfun_directlook.c lookup_index.c
*
* Copyright (c) 1990-1998 by The MathWorks, Inc. All Rights Reserved.
* $Revision: 1.3 $
*/
#define S_FUNCTION_NAME sfun_directlook
#define S_FUNCTION_LEVEL 2
#include <math.h>
#include “simstruc.h
#include <float.h>
/*=========*
* Defines *
*=========*/
#define XVECT_PIDX 0
#define YVECT_PIDX 1
#define XDATAEVENLYSPACED_PIDX 2
#define NUM_PARAMS 3
#define XVECT(S) ssGetSFcnParam(S,XVECT_PIDX)
#define YVECT(S) ssGetSFcnParam(S,YVECT_PIDX)
#define XDATAEVENLYSPACED(S) ssGetSFcnParam(S,XDATAEVENLYSPACED_PIDX)