CSM R5-3
csmbase.c File Reference

implement function table More...

#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "csmbase.h"

Go to the source code of this file.

Macros

#define CSM_TRUE   1
 for type csm_bool
#define CSM_FALSE   0
 for type csm_bool

Functions

double csm_x (csm_function *func, double y)
 compute x from a given y
double csm_y (csm_function *func, double x)
 compute y from a given x
double csm_dx (csm_function *func, double y)
 compute delta-x from a given delta-y
double csm_dy (csm_function *func, double x)
 compute delta-y from a given delta-x
double csm_z (csm_function *func, double x, double y)
 compute z from a given x and y
void csm_clear (csm_function *func)
 clear a function
void csm_free (csm_function *func)
 free a function-structure
void csm_def_linear (csm_function *func, double a, double b)
 define a linear function
csm_bool csm_def_linear_offset (csm_function *func, double a)
 re-define the offset of a linear function
csm_bool csm_fill_1d_table (double *x, double *y, int len, csm_function *func)
 fill one-dimensional function table from double arrays.
csm_bool csm_read_1d_table (char *filename, csm_function *func)
 read parameters of one-dimensional function table
csm_bool csm_read_2d_table (char *filename, csm_function *func)
 read parameters of two-dimensional function table
void csm_init (void)
 initialize the module
csm_functioncsm_new_function (void)
 create a new function object
void csm_pr_func (csm_function *func)
 dump a new function object

Detailed Description

Author
Götz Pfeiffer (goetz.pfeiffer@helmholtz-berlin.de)
Version
1.0

This module implements one and two dimensional function tables. The tables can be specified by simple ascii files. The points defined in the file don't have to be in the same distance.

Definition in file csmbase.c.

Function Documentation

◆ csm_x()

double csm_x ( csm_function * func,
double y )

This function computes x when y is given. Note that is doesn't work for two-dimensional function tables. For these, the function returns 0

Parameters
funcpointer to the function object
ythe value of y
Returns
x

Definition at line 1000 of file csmbase.c.

◆ csm_y()

double csm_y ( csm_function * func,
double x )

This function computes y when x is given. Note that is doesn't work for two-dimensional function tables. For these, the function returns 0

Parameters
funcpointer to the function object
xthe value of x
Returns
y

Definition at line 1031 of file csmbase.c.

◆ csm_dx()

double csm_dx ( csm_function * func,
double y )

This function computes a delta-x when a delta-y is given. Note that this function only works with linear functions. For all other types, this function returns 0.

Parameters
funcpointer to the function object
ythe given delta-y
Returns
delta-x

Definition at line 1062 of file csmbase.c.

◆ csm_dy()

double csm_dy ( csm_function * func,
double x )

This function computes a delta-y when a delta-x is given. Note that this function only works with linear functions. For all other types, this function returns 0.

Parameters
funcpointer to the function object
xthe given delta-x
Returns
delta-y

Definition at line 1083 of file csmbase.c.

◆ csm_z()

double csm_z ( csm_function * func,
double x,
double y )

This function computes z for two-dimensional function table when x and y are given. For all other function types, it returns 0.

Parameters
funcpointer to the function object
xthe value of x
ythe value of y
Returns
z

Definition at line 1104 of file csmbase.c.

◆ csm_clear()

void csm_clear ( csm_function * func)

This function clears the csm_function structure. All allocated memory is released, the internal type is set to CSM_NOTHING.

Parameters
funcpointer to the function object

Definition at line 1224 of file csmbase.c.

◆ csm_free()

void csm_free ( csm_function * func)

This function frees the csm_function structure. All allocated memory is released, even the memory of the basic internal structure. This means that the cmd_function structure becomes invalid and cannot be used again later. Use this function with caution.

Parameters
funcpointer to the function object

Definition at line 1236 of file csmbase.c.

◆ csm_def_linear()

void csm_def_linear ( csm_function * func,
double a,
double b )

This function initializes a csm_function structure as a linear function (y= a+b*x).

Parameters
funcpointer to the function object
aoffset of y= a+b*x
bmultiplier of y= a+b*x

Definition at line 1244 of file csmbase.c.

◆ csm_def_linear_offset()

csm_bool csm_def_linear_offset ( csm_function * func,
double a )

This function re-defines the offset-factor of a linear function (y= a+b*x).

Parameters
funcpointer to the function object
aoffset of y= a+b*x
Returns
returns CSM_FALSE in case of an error, CSM_TRUE otherwise

Definition at line 1259 of file csmbase.c.

◆ csm_fill_1d_table()

csm_bool csm_fill_1d_table ( double * x,
double * y,
int len,
csm_function * func )

This function uses two arrays of double to fill a one-dimensional function table.

Parameters
xan array of double with x coordinate values
yan array of double with y coordinate values
lenthe length of the table, it's number of rows
funcpointer to the function object
Returns
returns CSM_FALSE in case of an error, CSM_TRUE otherwise

Definition at line 1273 of file csmbase.c.

◆ csm_read_1d_table()

csm_bool csm_read_1d_table ( char * filename,
csm_function * func )

This function reads a one-dimensional function-table from a file.

Parameters
filenamethe name of the file
funcpointer to the function object
Returns
returns CSM_FALSE in case of an error, CSM_TRUE otherwise

Definition at line 1325 of file csmbase.c.

◆ csm_read_2d_table()

csm_bool csm_read_2d_table ( char * filename,
csm_function * func )

This function reads a two-dimensional function-table from a file.

Parameters
filenamethe name of the file
funcpointer to the function object
Returns
returns CSM_FALSE in case of an error, CSM_TRUE otherwise

Definition at line 1430 of file csmbase.c.

◆ csm_init()

void csm_init ( void )

This function should be called once to initialize the module.

Definition at line 1596 of file csmbase.c.

◆ csm_new_function()

csm_function * csm_new_function ( void )

This function returns a pointer to a new function object. The object is initialized as an empty function

Returns
returns NULL in case of an error. Otherwise the pointer to the csm_function is returned

Definition at line 1608 of file csmbase.c.

◆ csm_pr_func()

void csm_pr_func ( csm_function * func)

This printfs information about the given function to stdout.

Parameters
funcpointer to the function object

Definition at line 1731 of file csmbase.c.