yanera_postfix.c File Reference


Detailed Description

In order to evaluate a user supplied function expression of a layer (eg. a function like: a*exp(-(x-12.2)/b), where a,b are adjustable varaibles.), we have to convert the expression from infix to postfix notation. This file has all the required functions for this. The conversion of infix to postfix only occurs when the yanera->models_complete are formed.

The file also contains the required evaluation functions, when it comes time to evaluate the expression to calculate the SLD profile.

There are two local variables that are file in scope; evaluation_stack and operator_stack, two linked-list stacks.

operator_stack is only used to convert to the postfix expression. It should be empty after the conversion.

evaluation_stack is only used in evaluation of the postfix expression. It also should be empty when evalutation is complete.

Definition in file yanera_postfix.c.

Go to the source code of this file.

Functions

short parmindex (char c, char *parm_name)
 From the string of parameter names, find the character.
void parse_expression (yanera_postfix *pq, char *expression, char *parm_name, short *parm)
 Parse the prefix expression into a postfix expression.
void parameter_decision (yanera_postfix *pq, const char c[4], short indx)
 Check for recurrence of same variable.
void append_number_string (char c)
 Append a numeric character to the number_string.
void stop_number_string (yanera_postfix *pq)
 Take the number_string and push onto yanera_postfix.
yanera_postfixinitizlize_postfix_queue (void)
 Initialize the yanera_postfix.
void enqueue_postfix_queue (yanera_postfix *pq, const char *c, double d, short indx, short type)
 Initialize the yanera_postfix.
void print_postfix (yanera_postfix *pq, double x, double *params)
 Print the yanera_postfix for examination.
double evaluate_postfix (yanera_postfix *pq, double z, double *params)
 Evaluate the yanera_postfix.
void free_postfix_queue (yanera_postfix *pq)
 Free the yanera_postfix.
void initizlize_operator_stack (void)
 Initalize the operator_stack.
struct operator_stack_elementoperator_stack_element_new (const char *oper, short prec, short type)
 Load data into an operator_stack_element.
void push_operator_stack (struct operator_stack_element *o)
 Push an operator_stack_element onto the operator_stack.
struct operator_stack_elementpop_operator_stack (void)
 Pop the top operator_stack_element from the operator_stack.
short operator_stack_is_empty (void)
 Returns whether the operator_stack is empty.
short operator_stack_top_precedence (void)
 Returns the precendence of the top operator_stack_element.
void operator_decision (yanera_postfix *pq, const char oper[4], short prec, short type)
 The heart of the prefix to postfix conversion algorithm.
void initizlize_evaluation_stack (void)
 Initalize the evaluation_stack.
void push_evaluation_stack (double d)
 Push a number onto the evaluation_stack.
double pop_evaluation_stack (void)
 Pop a number from the evaluation_stack.


Function Documentation

short parmindex ( char  c,
char *  parm_name 
)

Parameters:
c The character to match.
parm_name The string of parameter names.
Returns the index from the string of parameter names that matches the character.

Definition at line 39 of file yanera_postfix.c.

void parse_expression ( yanera_postfix pq,
char *  expression,
char *  parm_name,
short *  parm 
)

Parameters:
pq The yanera_postfix which will hold the expression
expression The prefix expression as a character string
parm_name A character array containing only one leter
parm The index array for the parameters
Parse the prefix expression into a postfix expression.

The parm_name and parm arrays together form a look-up table. Every variable name appears once in the parm_name array. The parm array conatins the index for the paramter array that carries the actual values of that variable.

Example:

 parm_name = "acbd"
 parm      = {4,0,2,1}
 parmamter = {1.2, 3.5, 5.4, 0.2, 10.2}
Leads to:
 a = parameter[4] = 10.2
 d = parameter[1] =  3.5

Definition at line 76 of file yanera_postfix.c.

void parameter_decision ( yanera_postfix pq,
const char  c[4],
short  indx 
)

We need to determine whether a variable has already been added to the yanera_postfix. If it has, then add it again, but using the same index as before. This allows varaibles (a,b,c,etc.) to appear more than once in the expression.

Definition at line 615 of file yanera_postfix.c.

void append_number_string ( char  c  ) 

Append a numeric character to the number_string

Definition at line 644 of file yanera_postfix.c.

void stop_number_string ( yanera_postfix pq  ) 

Take the number_string and push onto yanera_postfix. Free the string memory.

Definition at line 669 of file yanera_postfix.c.

yanera_postfix* initizlize_postfix_queue ( void   ) 

Initialize the yanera_postfix.

Definition at line 684 of file yanera_postfix.c.

void enqueue_postfix_queue ( yanera_postfix pq,
const char *  c,
double  d,
short  indx,
short  type 
)

Parameters:
pq The yanera_postfix with the postfix expression
c A size 4 character string of the operator or variable
d A double number.
indx For variables, the paramter array index.
type The type of element store See below.
This function initializes the yanera_postfix.

The queue contains either a number, symbolic operators (+,-,*,/,^), word operators (cos,sin,tan,exp,log,abs), varaibles (a,b,c,etc.) or the ordinate value (z).

Definition at line 711 of file yanera_postfix.c.

void print_postfix ( yanera_postfix pq,
double  x,
double *  params 
)

Parameters:
pq The yanera_postfix with the postfix expression
x The ordinate
params A parameter array.
This function works like the evaluation of the yanera_postfix, however it mearly prints to stderr the contents of the queue, to see if the prefix expression was evaluated properly.

Definition at line 756 of file yanera_postfix.c.

double evaluate_postfix ( yanera_postfix pq,
double  z,
double *  params 
)

Parameters:
pq The yanera_postfix with the postfix expression
z The ordinate
params A parameter array.
The function evaluates the postfix expression at ordinate z and with variables in the params array. When the ordinate is encountered, substitute the value z.

Definition at line 800 of file yanera_postfix.c.

void free_postfix_queue ( yanera_postfix pq  ) 

FILL IN

Definition at line 871 of file yanera_postfix.c.

void initizlize_operator_stack ( void   ) 

Initalize the operator_stack. The stack will be empty at the end and not need to be freed.

Definition at line 897 of file yanera_postfix.c.

struct operator_stack_element* operator_stack_element_new ( const char *  oper,
short  prec,
short  type 
) [read]

Allocate a new operator_stack_element , and fill with data.

Definition at line 908 of file yanera_postfix.c.

void push_operator_stack ( struct operator_stack_element o  ) 

Push an operator_stack_element onto teh operator_stack.

Definition at line 925 of file yanera_postfix.c.

struct operator_stack_element* pop_operator_stack ( void   )  [read]

Pop the top operator_stack_element from the operator_stack. Creates a copy of the operator_stack_element which MUST BE FREE

Definition at line 938 of file yanera_postfix.c.

short operator_stack_is_empty ( void   ) 

Returns whether the operator_stack is empty.

Definition at line 965 of file yanera_postfix.c.

short operator_stack_top_precedence ( void   ) 

Returns the precendence of the top operator_stack_element. Returns 0 is stack is empty.

Definition at line 976 of file yanera_postfix.c.

void operator_decision ( yanera_postfix pq,
const char  oper[4],
short  prec,
short  type 
)

The heart of the prefix to postfix conversion algorithm.

Definition at line 988 of file yanera_postfix.c.

void initizlize_evaluation_stack ( void   ) 

Initalize the evaluation_stack. The stack will be empty at the end and not need to be freed.

Definition at line 1021 of file yanera_postfix.c.

void push_evaluation_stack ( double  d  ) 

Push a number onto the evaluation_stack

Definition at line 1032 of file yanera_postfix.c.

double pop_evaluation_stack ( void   ) 

Pop a number from the evaluation_stack.

Definition at line 1048 of file yanera_postfix.c.


Generated on Thu May 29 10:56:33 2008 by  doxygen 1.5.5