/[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 721 - (show annotations) (download) (as text)
Mon Jul 3 06:22:42 2006 UTC (14 years, 4 months ago) by johnpye
File MIME type: text/x-csrc
File size: 3089 byte(s)
Added '--models' option to ascend-config.
Fixed a bug with packages.c wrt generating absolute paths to library files.
Added SCons directives to install header files in INSTALL_INCLUDE subdirs.
Changed rel.c so that init function is only run if provided in the package.
Added 'ospath_getabs' to convert relative paths into absolute paths by adding prefix of fully-resolved '.'
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 CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",addone_calc);
58
59 result += CreateUserFunctionBlackBox("add_one"
60 , addone_prepare
61 , addone_calc /* value */
62 , (ExtBBoxFunc*)NULL /* deriv */
63 , (ExtBBoxFunc*)NULL /* deriv2 */
64 , (ExtBBoxInitFunc*)NULL /* final */
65 , 1,1 /* inputs, outputs */
66 , addone_help
67 );
68
69 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
70 return result;
71 }
72
73 int addone_prepare(struct Slv_Interp *slv_interp,
74 struct Instance *data,
75 struct gl_list_t *arglist
76 ){
77 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
78 const char *mystring = "MY STRING IS HERE";
79 slv_interp->user_data = (void *)mystring;
80 return 0;
81 }
82
83 /* return 0 on success */
84 int addone_calc(struct Slv_Interp *slv_interp,
85 int ninputs, int noutputs,
86 double *inputs, double *outputs,
87 double *jacobian
88 ){
89 char *mystring = (char *)slv_interp->user_data;
90
91 /* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"ADDONE_CALC: mystring = %s\n",mystring); */
92
93 /* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"NINPUTS = %d, NOUTPUTS = %d\n",ninputs, noutputs); */
94
95 /* CONSOLE_DEBUG("inputs[0] = %f, outputs[0] = %f",inputs[0],outputs[0]); */
96
97 outputs[0] = inputs[0] + 1;
98
99 /* CONSOLE_DEBUG("INPUT = %f, OUTPUT = %f",inputs[0],outputs[0]); */
100
101 return 0; /* success */
102 }

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