/[ascend]/trunk/base/generic/compiler/extfunc.h
ViewVC logotype

Contents of /trunk/base/generic/compiler/extfunc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 89 - (show annotations) (download) (as text)
Wed Dec 7 15:44:43 2005 UTC (14 years ago) by johnpye
File MIME type: text/x-chdr
File size: 7054 byte(s)
Small changes to eliminate GCC warnings
1 /*
2 * External Functions Module
3 * by Kirk Andre Abbott
4 * Created: July 4, 1994.
5 * Version: $Revision: 1.5 $
6 * Version control file: $RCSfile: extfunc.h,v $
7 * Date last modified: $Date: 1997/07/18 12:29:30 $
8 * Last modified by: $Author: mthomas $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly, Kirk Andre Abbott
13 *
14 * The Ascend Language Interpreter is free software; you can redistribute
15 * it and/or modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * The Ascend Language Interpreter is distributed in hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with the program; if not, write to the Free Software Foundation, Inc., 675
26 * Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
27 */
28
29 /** @file
30 * External Functions Module.
31 * <pre>
32 * When #including extfunc.h, make sure these files are #included first:
33 * #include "utilities/ascConfig.h"
34 * #include "compiler.h"
35 * </pre>
36 * @todo Complete documentation of compiler/extfunc.h.
37 */
38
39 #ifndef ASC_EXTFUNC_H
40 #define ASC_EXTFUNC_H
41
42 /**
43 ExtEvalFunc type is a function pointer.
44 @see rootfind.c:51
45
46 @param mode 'to pass to the eval function' (?)
47 @param m relation index
48 @param n variable index
49 @param x 'x' vector (?)
50 @param u 'u' vector (?)
51 @param f vector of residuals
52 @param g vector of gradients
53 */
54 typedef int ExtEvalFunc(int *mode, int *m, int *n,
55 double *x, double *u, double *f, double *g);
56
57 /**
58 ExtProcFunc type is a function pointer.
59
60 @param mode
61 @param m
62 @param n
63 @param x
64 @param u
65 @param f
66 @param g
67 */
68 typedef int ExtProcFunc(int *mode, int *m, unsigned long *n,
69 double *x, double *u, double *f, double *g);
70
71
72 struct ExternalFunc {
73 CONST char *name;
74 unsigned long n_inputs;
75 unsigned long n_outputs;
76 char *help;
77 ExtEvalFunc *init;
78 ExtEvalFunc **value;
79 ExtEvalFunc **deriv;
80 ExtEvalFunc **deriv2;
81 };
82
83 enum Calc_status {
84 calc_converged, calc_diverged, calc_fp_error, calc_incorrect_args,
85 calc_error, calc_all_ok
86 };
87
88 struct Slv_Interp {
89 int nodestamp;
90 enum Calc_status status;
91 void *user_data;
92 unsigned first_call :1;
93 unsigned last_call :1;
94 unsigned check_args :1;
95 unsigned recalculate :1;
96 unsigned deriv_eval :1;
97 unsigned func_eval :1;
98 unsigned single_step :1;
99 };
100
101 typedef int ExtBBoxFunc(struct Slv_Interp *,
102 int ninputs, int noutputs,
103 double *inputs, double *outputs, double *jacobian);
104
105 extern void InitExternalFuncLibrary(void);
106 /**<
107 * The main external functions library initialization routine. This
108 * function must be called before all others.
109 */
110
111 extern void DestroyExtFuncLibrary(void);
112 /**<
113 * Destroys the external function library and deallocates all the
114 * information associated with it.
115 */
116
117
118 extern struct ExternalFunc *CreateExternalFunc(CONST char *name);
119 /**<
120 * Creates and returns and ExternalFunc node, with all attributes
121 * initialized to 0 or NULL.
122 */
123
124 extern int AddExternalFunc(struct ExternalFunc *efunc, int force);
125 /**<
126 * Given an external function node, add it to the external function
127 * library. We look up the external function before adding it to the
128 * library. If force is zero and the function exists then nothing
129 * is done and 0 is returned. If force is true, then the old entry is
130 * removed and the new one is added; 1 is returned. If the name is not
131 * found then the information is added to the library.
132 */
133
134 extern struct ExternalFunc *LookupExtFunc(CONST char *funcname);
135 /**<
136 * Returns the external function corresponding to the name, or NULL if
137 * not found.
138 */
139
140
141 extern int CreateUserFunction(CONST char *name,
142 ExtEvalFunc *init,
143 ExtEvalFunc **value,
144 ExtEvalFunc **deriv,
145 ExtEvalFunc **deriv2,
146 CONST unsigned long n_inputs,
147 CONST unsigned long n_outputs,
148 CONST char *help);
149 /**<
150 @param name name of the function being added (or updated)
151 @param init initialisation function
152 @param value location where pointer to evaluation function can be found???
153 @param deriv location where pointer to first partial derivative function will be returned???
154 @param deriv2 location where pointer to second derivative function can be found???
155
156 This function is used to add external functions to the ASCEND system. The name of the function is looked up. If it already exists, the information will be updated. If the name was not found in the external function library, then an external function node will be created and added to the external function library. We make a *copy* of the help string if it is provided. We also make a copy of the name. Anyone desirous of ASCEND knowing about there functions must use this protocol.
157 */
158
159 extern struct ExternalFunc *RemoveExternalFunc(char *name);
160 /**<
161 * Given the name of an external function will remove it from the
162 * External function library.
163 */
164
165 extern void DestroyExternalFunc(struct ExternalFunc *name);
166 /**<
167 * Destroys an external function, but does *not* remove it from the
168 * library. Use the RemoveExternalFunc library first to retrieve the
169 * information, then call this function.
170 */
171
172 extern int (*GetInitFunc(struct ExternalFunc *efunc))(/* */);
173 extern ExtBBoxFunc *GetValueFunc(struct ExternalFunc *efunc);
174 extern ExtBBoxFunc *GetDerivFunc(struct ExternalFunc *efunc);
175 extern ExtBBoxFunc *GetDeriv2Func(struct ExternalFunc *efunc);
176
177 extern ExtEvalFunc **GetValueJumpTable(struct ExternalFunc *efunc);
178 extern ExtEvalFunc **GetDerivJumpTable(struct ExternalFunc *efunc);
179 extern ExtEvalFunc **GetDeriv2JumpTable(struct ExternalFunc *efunc);
180
181 extern CONST char *ExternalFuncName(CONST struct ExternalFunc *efunc);
182 /**<
183 * Returns the name of an external function.
184 */
185
186 extern unsigned long NumberInputArgs(CONST struct ExternalFunc *efunc);
187 extern unsigned long NumberOutputArgs(CONST struct ExternalFunc *efunc);
188
189
190 extern void PrintExtFuncLibrary(FILE *f);
191 /**<
192 * Prints the contents of the external function library to the given
193 * file. The file must be opened for writing.
194 */
195
196 extern char *WriteExtFuncLibraryString(void);
197 /**<
198 * Returns a string of formatted information about the external functions
199 * defined. the string looks like "{{name1} {help1}} {{name2} {help2}} "
200 * The string may be empty/NULL if there are no external functions loaded.
201 */
202
203 /**
204 This provides a way for other code to visit the external function list
205 */
206 extern void TraverseExtFuncLibrary(void (*)(void *,void *),void *secondparam);
207
208 #endif /* ASC_EXTFUNC_H */
209

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22