| 1 |
johnpye |
209 |
#include <stdio.h> |
| 2 |
|
|
|
| 3 |
|
|
#include <utilities/ascConfig.h> |
| 4 |
|
|
#include <compiler/fractions.h> |
| 5 |
|
|
#include <compiler/compiler.h> |
| 6 |
|
|
#include <compiler/dimen.h> |
| 7 |
|
|
#include <compiler/child.h> |
| 8 |
|
|
#include <general/list.h> |
| 9 |
|
|
#include <compiler/module.h> |
| 10 |
|
|
#include <compiler/childinfo.h> |
| 11 |
|
|
#include <compiler/slist.h> |
| 12 |
|
|
#include <compiler/type_desc.h> |
| 13 |
|
|
#include <compiler/packages.h> |
| 14 |
|
|
|
| 15 |
|
|
int addone_prepare(struct Slv_Interp *slv_interp, struct Instance *data, struct gl_list_t *arglist); |
| 16 |
|
|
int addone_calc(struct Slv_Interp *slv_interp, int ninputs, int noutputs, double *inputs, double *outputs, double *jacobian); |
| 17 |
|
|
|
| 18 |
|
|
/** |
| 19 |
|
|
This is the function called from "IMPORT extfntest_register FROM extfntest" |
| 20 |
|
|
|
| 21 |
|
|
It sets up the functions in this external function library |
| 22 |
|
|
*/ |
| 23 |
|
|
extern int |
| 24 |
|
|
DLEXPORT extfntest_register(struct Slv_Interp *dummy1, |
| 25 |
|
|
struct Instance *root, |
| 26 |
|
|
struct gl_list_t *arglist, |
| 27 |
|
|
unsigned long dummy4 |
| 28 |
|
|
){ |
| 29 |
|
|
const char *addone_help = "This is a test of the dynamic user packages functionality"; |
| 30 |
|
|
int result = 0; |
| 31 |
|
|
|
| 32 |
|
|
(void)dummy1;(void)root;(void)arglist;(void)dummy4; |
| 33 |
|
|
|
| 34 |
johnpye |
302 |
ERROR_REPORER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n"); |
| 35 |
johnpye |
209 |
|
| 36 |
|
|
result += CreateUserFunction("add_one", |
| 37 |
|
|
(ExtEvalFunc *)addone_prepare, |
| 38 |
|
|
(ExtEvalFunc **)addone_calc, |
| 39 |
|
|
(ExtEvalFunc **)NULL, |
| 40 |
|
|
(ExtEvalFunc **)NULL, |
| 41 |
|
|
1,1,addone_help); |
| 42 |
|
|
|
| 43 |
|
|
FPRINTF(ASCERR,"CreateUserFunction result = %d\n",result); |
| 44 |
|
|
return result; |
| 45 |
|
|
} |
| 46 |
|
|
|
| 47 |
|
|
int addone_prepare(struct Slv_Interp *slv_interp, |
| 48 |
|
|
struct Instance *data, |
| 49 |
|
|
struct gl_list_t *arglist |
| 50 |
|
|
){ |
| 51 |
|
|
FPRINTF(ASCERR,"PREPARING PKG EXTFNTEST...\n"); |
| 52 |
|
|
const char *mystring = "MY STRING IS HERE"; |
| 53 |
|
|
slv_interp->user_data = (void *)mystring; |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
|
|
int addone_calc(struct Slv_Interp *slv_interp, |
| 57 |
|
|
int ninputs, int noutputs, |
| 58 |
|
|
double *inputs, double *outputs, |
| 59 |
|
|
double *jacobian |
| 60 |
|
|
){ |
| 61 |
|
|
char *mystring = (char *)slv_interp->user_data; |
| 62 |
|
|
|
| 63 |
|
|
FPRINTF(ASCERR,"ADDONE_CALC: mystring = %s\n",mystring); |
| 64 |
|
|
|
| 65 |
|
|
FPRINTF(ASCERR,"NINPUTS = %d, NOUTPUTS = %d\n",ninputs, noutputs); |
| 66 |
|
|
|
| 67 |
|
|
double *x = &(inputs[0]); |
| 68 |
|
|
|
| 69 |
|
|
double *y = &(outputs[0]); |
| 70 |
|
|
|
| 71 |
|
|
y = x + 1; |
| 72 |
|
|
|
| 73 |
|
|
return 1; /* success */ |
| 74 |
|
|
} |