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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 471 - (hide annotations) (download) (as text)
Mon Apr 17 03:44:25 2006 UTC (14 years, 5 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 johnpye 209 #include <stdio.h>
2    
3 johnpye 380 #include <utilities/error.h>
4    
5 johnpye 209 #include <utilities/ascConfig.h>
6 johnpye 380
7 johnpye 209 #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 johnpye 381 This is the function called from "IMPORT extfntest"
23 johnpye 209
24     It sets up the functions in this external function library
25     */
26 johnpye 380
27 johnpye 209 extern int
28 johnpye 466 DLEXPORT extfntest_register(){
29 ben.allan 471 const char *addone_help = "This is a test of the dynamic user packages functionality";
30 johnpye 209 int result = 0;
31    
32 johnpye 381 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n");
33 johnpye 209
34 ben.allan 471 /*
35 johnpye 466 result += CreateUserFunction("add_one",
36 johnpye 209 (ExtEvalFunc *)addone_prepare,
37     (ExtEvalFunc **)addone_calc,
38     (ExtEvalFunc **)NULL,
39     (ExtEvalFunc **)NULL,
40     1,1,addone_help);
41 ben.allan 471 */
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 johnpye 209
51 ben.allan 471
52 johnpye 380 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
53 johnpye 209 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 johnpye 380 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
61 johnpye 209 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 johnpye 380 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"ADDONE_CALC: mystring = %s\n",mystring);
73 johnpye 209
74 johnpye 380 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"NINPUTS = %d, NOUTPUTS = %d\n",ninputs, noutputs);
75 johnpye 209
76     double *x = &(inputs[0]);
77 johnpye 367
78 johnpye 209 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