/[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 692 - (show annotations) (download) (as text)
Thu Jun 22 02:45:47 2006 UTC (16 years, 5 months ago) by johnpye
File MIME type: text/x-csrc
File size: 3095 byte(s)
Fixed up behaviour of default ASCENDLIBRARY in python interface (for the case
where you're using ascpy without using the PyGTK GUI).
Removed some debug output when loading external libraries.
Fixed up the 'extfntest' example & SConscript file.
1 /* ASCEND modelling environment
2 Copyright (C) 1999 Benjamin A Allan
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21 #include <stdio.h>
22
23 #include <utilities/ascConfig.h>
24 #include <utilities/error.h>
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
37 int addone_prepare(struct Slv_Interp *slv_interp, struct Instance *data, struct gl_list_t *arglist);
38 int addone_calc(struct Slv_Interp *slv_interp, int ninputs, int noutputs, double *inputs, double *outputs, double *jacobian);
39
40 /**
41 This is the function called from "IMPORT extfntest"
42
43 It sets up the functions in this external function library
44 */
45
46 #ifndef ASC_EXPORT
47 # error "Where is ASC_EXPORT?"
48 #endif
49
50 extern
51 ASC_EXPORT(int) extfntest_register(){
52 const char *addone_help = "This is a test of the dynamic user packages functionality";
53 int result = 0;
54
55 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n");
56
57 /*
58 result += CreateUserFunction("add_one",
59 (ExtEvalFunc *)addone_prepare,
60 (ExtEvalFunc **)addone_calc,
61 (ExtEvalFunc **)NULL,
62 (ExtEvalFunc **)NULL,
63 1,1,addone_help);
64 */
65 result += CreateUserFunctionBlackBox("add_one"
66 , addone_prepare
67 , addone_calc /* value */
68 , (ExtBBoxFunc*)NULL /* deriv */
69 , (ExtBBoxFunc*)NULL /* deriv2 */
70 , (ExtBBoxInitFunc*)NULL /* final */
71 , 1,1 /* inputs, outputs */
72 , addone_help
73 );
74
75 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
76 return result;
77 }
78
79 int addone_prepare(struct Slv_Interp *slv_interp,
80 struct Instance *data,
81 struct gl_list_t *arglist
82 ){
83 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
84 const char *mystring = "MY STRING IS HERE";
85 slv_interp->user_data = (void *)mystring;
86 }
87
88 int addone_calc(struct Slv_Interp *slv_interp,
89 int ninputs, int noutputs,
90 double *inputs, double *outputs,
91 double *jacobian
92 ){
93 char *mystring = (char *)slv_interp->user_data;
94
95 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"ADDONE_CALC: mystring = %s\n",mystring);
96
97 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"NINPUTS = %d, NOUTPUTS = %d\n",ninputs, noutputs);
98
99 double *x = &(inputs[0]);
100
101 double *y = &(outputs[0]);
102
103 y = x + 1;
104
105 return 1; /* success */
106 }

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