/[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 719 - (show annotations) (download) (as text)
Sat Jul 1 09:35:23 2006 UTC (14 years, 4 months ago) by johnpye
File MIME type: text/x-csrc
File size: 3312 byte(s)
Added 'invars' and 'outvars' pointers (to var_variable pointer arrays) in ExtRelCache.
This will allow the ExtRel_MapDataToMtx function to be reimplemented using solver-side pointers
instead of going back to the arglist stuff in ExtCallNode.
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 CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",addone_calc);
66
67 result += CreateUserFunctionBlackBox("add_one"
68 , addone_prepare
69 , addone_calc /* value */
70 , (ExtBBoxFunc*)NULL /* deriv */
71 , (ExtBBoxFunc*)NULL /* deriv2 */
72 , (ExtBBoxInitFunc*)NULL /* final */
73 , 1,1 /* inputs, outputs */
74 , addone_help
75 );
76
77 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
78 return result;
79 }
80
81 int addone_prepare(struct Slv_Interp *slv_interp,
82 struct Instance *data,
83 struct gl_list_t *arglist
84 ){
85 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
86 const char *mystring = "MY STRING IS HERE";
87 slv_interp->user_data = (void *)mystring;
88 return 0;
89 }
90
91 /* return 0 on success */
92 int addone_calc(struct Slv_Interp *slv_interp,
93 int ninputs, int noutputs,
94 double *inputs, double *outputs,
95 double *jacobian
96 ){
97 char *mystring = (char *)slv_interp->user_data;
98
99 /* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"ADDONE_CALC: mystring = %s\n",mystring); */
100
101 /* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"NINPUTS = %d, NOUTPUTS = %d\n",ninputs, noutputs); */
102
103 /* CONSOLE_DEBUG("inputs[0] = %f, outputs[0] = %f",inputs[0],outputs[0]); */
104
105 outputs[0] = inputs[0] + 1;
106
107 /* CONSOLE_DEBUG("INPUT = %f, OUTPUT = %f",inputs[0],outputs[0]); */
108
109 return 0; /* success */
110 }

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