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