/[ascend]/trunk/models/johnpye/extfn/extfntest.c
ViewVC logotype

Contents of /trunk/models/johnpye/extfn/extfntest.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 471 - (show annotations) (download) (as text)
Mon Apr 17 03:44:25 2006 UTC (14 years, 4 months ago) by ben.allan
File MIME type: text/x-csrc
File size: 2208 byte(s)
fixed up per new extfunc.h. linking still not on.
1 #include <stdio.h>
2
3 #include <utilities/error.h>
4
5 #include <utilities/ascConfig.h>
6
7 #include <compiler/fractions.h>
8 #include <compiler/compiler.h>
9 #include <compiler/dimen.h>
10 #include <compiler/child.h>
11 #include <general/list.h>
12 #include <compiler/module.h>
13 #include <compiler/childinfo.h>
14 #include <compiler/slist.h>
15 #include <compiler/type_desc.h>
16 #include <compiler/packages.h>
17
18 int addone_prepare(struct Slv_Interp *slv_interp, struct Instance *data, struct gl_list_t *arglist);
19 int addone_calc(struct Slv_Interp *slv_interp, int ninputs, int noutputs, double *inputs, double *outputs, double *jacobian);
20
21 /**
22 This is the function called from "IMPORT extfntest"
23
24 It sets up the functions in this external function library
25 */
26
27 extern int
28 DLEXPORT extfntest_register(){
29 const char *addone_help = "This is a test of the dynamic user packages functionality";
30 int result = 0;
31
32 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n");
33
34 /*
35 result += CreateUserFunction("add_one",
36 (ExtEvalFunc *)addone_prepare,
37 (ExtEvalFunc **)addone_calc,
38 (ExtEvalFunc **)NULL,
39 (ExtEvalFunc **)NULL,
40 1,1,addone_help);
41 */
42 result += CreateUserFunctionBlackBox(
43 "add_one",
44 addone_prepare,
45 addone_calc,
46 (ExtBBoxFunc*)NULL, /* no grad */
47 (ExtBBoxFunc*)NULL, /* no hess */
48 (ExtBBoxFunc*)NULL, /* no final */
49 1,1,addone_help);
50
51
52 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
53 return result;
54 }
55
56 int addone_prepare(struct Slv_Interp *slv_interp,
57 struct Instance *data,
58 struct gl_list_t *arglist
59 ){
60 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
61 const char *mystring = "MY STRING IS HERE";
62 slv_interp->user_data = (void *)mystring;
63 }
64
65 int addone_calc(struct Slv_Interp *slv_interp,
66 int ninputs, int noutputs,
67 double *inputs, double *outputs,
68 double *jacobian
69 ){
70 char *mystring = (char *)slv_interp->user_data;
71
72 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"ADDONE_CALC: mystring = %s\n",mystring);
73
74 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"NINPUTS = %d, NOUTPUTS = %d\n",ninputs, noutputs);
75
76 double *x = &(inputs[0]);
77
78 double *y = &(outputs[0]);
79
80 y = x + 1;
81
82 return 1; /* success */
83 }

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