/[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 721 - (hide annotations) (download) (as text)
Mon Jul 3 06:22:42 2006 UTC (14 years, 3 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 johnpye 534 /* 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 johnpye 209 #include <stdio.h>
22    
23 johnpye 534 #include <utilities/ascConfig.h>
24 johnpye 380 #include <utilities/error.h>
25    
26 johnpye 209 #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 johnpye 381 This is the function called from "IMPORT extfntest"
42 johnpye 209
43     It sets up the functions in this external function library
44     */
45 johnpye 380
46 johnpye 534 #ifndef ASC_EXPORT
47     # error "Where is ASC_EXPORT?"
48     #endif
49    
50     extern
51     ASC_EXPORT(int) extfntest_register(){
52 johnpye 485 const char *addone_help = "This is a test of the dynamic user packages functionality";
53 johnpye 209 int result = 0;
54    
55 johnpye 381 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n");
56 johnpye 209
57 johnpye 711 CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",addone_calc);
58    
59 johnpye 692 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 johnpye 209
69 johnpye 380 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
70 johnpye 209 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 johnpye 380 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
78 johnpye 209 const char *mystring = "MY STRING IS HERE";
79     slv_interp->user_data = (void *)mystring;
80 johnpye 709 return 0;
81 johnpye 209 }
82    
83 johnpye 719 /* return 0 on success */
84 johnpye 209 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 johnpye 719 /* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"ADDONE_CALC: mystring = %s\n",mystring); */
92 johnpye 209
93 johnpye 719 /* ERROR_REPORTER_HERE(ASC_PROG_NOTE,"NINPUTS = %d, NOUTPUTS = %d\n",ninputs, noutputs); */
94 johnpye 209
95 johnpye 719 /* CONSOLE_DEBUG("inputs[0] = %f, outputs[0] = %f",inputs[0],outputs[0]); */
96 johnpye 367
97 johnpye 711 outputs[0] = inputs[0] + 1;
98 johnpye 209
99 johnpye 719 /* CONSOLE_DEBUG("INPUT = %f, OUTPUT = %f",inputs[0],outputs[0]); */
100 johnpye 209
101 johnpye 719 return 0; /* success */
102 johnpye 209 }

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