1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 2006 Carnegie Mellon University |
3 |
|
4 |
This program is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2, or (at your option) |
7 |
any later version. |
8 |
|
9 |
This program is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
13 |
|
14 |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc., 59 Temple Place - Suite 330, |
17 |
Boston, MA 02111-1307, USA. |
18 |
*/ |
19 |
|
20 |
#include <stdio.h> |
21 |
|
22 |
#include <utilities/ascConfig.h> |
23 |
#include <utilities/error.h> |
24 |
|
25 |
/* |
26 |
#include <compiler/fractions.h> |
27 |
#include <compiler/compiler.h> |
28 |
#include <compiler/dimen.h> |
29 |
#include <compiler/child.h> |
30 |
#include <general/list.h> |
31 |
#include <compiler/module.h> |
32 |
#include <compiler/childinfo.h> |
33 |
#include <compiler/slist.h> |
34 |
#include <compiler/type_desc.h> |
35 |
#include <compiler/packages.h>*/ |
36 |
#include <compiler/extfunc.h> |
37 |
|
38 |
ExtBBoxInitFunc addone_prepare; |
39 |
ExtBBoxFunc addone_calc; |
40 |
|
41 |
/** |
42 |
This is the function called from "IMPORT extfntest" |
43 |
|
44 |
It sets up the functions in this external function library |
45 |
*/ |
46 |
|
47 |
#ifndef ASC_EXPORT |
48 |
# error "Where is ASC_EXPORT?" |
49 |
#endif |
50 |
|
51 |
extern |
52 |
ASC_EXPORT(int) extfntest_register(){ |
53 |
const char *addone_help = "This is a test of the dynamic user packages functionality"; |
54 |
int result = 0; |
55 |
|
56 |
ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n"); |
57 |
|
58 |
(void)CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",addone_calc); |
59 |
|
60 |
result += CreateUserFunctionBlackBox("add_one" |
61 |
, addone_prepare |
62 |
, addone_calc /* value */ |
63 |
, (ExtBBoxFunc*)NULL /* deriv */ |
64 |
, (ExtBBoxFunc*)NULL /* deriv2 */ |
65 |
, (ExtBBoxFinalFunc*)NULL /* final */ |
66 |
, 1,1 /* inputs, outputs */ |
67 |
, addone_help |
68 |
, 0.0 |
69 |
); /* returns 0 on success */ |
70 |
|
71 |
if(result){ |
72 |
ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result); |
73 |
} |
74 |
return result; |
75 |
} |
76 |
|
77 |
int addone_prepare(struct BBoxInterp *slv_interp, |
78 |
struct Instance *data, |
79 |
struct gl_list_t *arglist |
80 |
){ |
81 |
const char *mystring = "MY STRING IS HERE"; |
82 |
|
83 |
ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n"); |
84 |
slv_interp->user_data = (void *)mystring; |
85 |
|
86 |
return 0; |
87 |
} |
88 |
|
89 |
/* return 0 on success */ |
90 |
int addone_calc(struct BBoxInterp *slv_interp, |
91 |
int ninputs, int noutputs, |
92 |
double *inputs, double *outputs, |
93 |
double *jacobian |
94 |
){ |
95 |
/* char *mystring = (char *)slv_interp->user_data; */ |
96 |
|
97 |
/* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"ADDONE_CALC: mystring = %s\n",mystring); */ |
98 |
|
99 |
/* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"NINPUTS = %d, NOUTPUTS = %d\n",ninputs, noutputs); */ |
100 |
|
101 |
/* CONSOLE_DEBUG("inputs[0] = %f, outputs[0] = %f",inputs[0],outputs[0]); */ |
102 |
|
103 |
outputs[0] = inputs[0] + 1; |
104 |
|
105 |
/* CONSOLE_DEBUG("INPUT = %f, OUTPUT = %f",inputs[0],outputs[0]); */ |
106 |
|
107 |
return 0; /* success */ |
108 |
} |