/[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 2649 - (hide annotations) (download) (as text)
Wed Dec 12 12:39:25 2012 UTC (12 years, 10 months ago) by jpye
File MIME type: text/x-csrc
File size: 2901 byte(s)
Fixing GPL header, removing postal address (rpmlint incorrect-fsf-address)
1 johnpye 534 /* ASCEND modelling environment
2     Copyright (C) 2006 Carnegie Mellon University
3    
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2, or (at your option)
7     any later version.
8    
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     GNU General Public License for more details.
13    
14     You should have received a copy of the GNU General Public License
15 jpye 2649 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 johnpye 1039 *//**
17     This is intended to be a simplest-possible external function and was
18     used by John Pye to test his updates/fixes to the Black Box implementation.
19     Since Ben refactored the the black box stuff separately, this has stopped
20     working (and now causes a runtime crash. The aim now is to work out why
21     the crash occurs and ensure that it can't!
22    
23     Note that this external function does *not* provide its own jacobian; it is
24     counting on the default numerical diff function provided by ASCEND.
25     *//*
26     by John Pye, Jan 2006
27 johnpye 534 */
28    
29 johnpye 209 #include <stdio.h>
30    
31 jpye 2323 #include <ascend/general/platform.h>
32 jpye 2018 #include <ascend/utilities/error.h>
33 johnpye 380
34 jpye 2018 #include <ascend/compiler/extfunc.h>
35 johnpye 209
36 johnpye 908 ExtBBoxInitFunc addone_prepare;
37     ExtBBoxFunc addone_calc;
38 johnpye 209
39     /**
40 johnpye 381 This is the function called from "IMPORT extfntest"
41 johnpye 209
42     It sets up the functions in this external function library
43     */
44 johnpye 380
45 johnpye 534 #ifndef ASC_EXPORT
46     # error "Where is ASC_EXPORT?"
47     #endif
48    
49     extern
50 johnpye 1063 ASC_EXPORT int extfntest_register(){
51 johnpye 485 const char *addone_help = "This is a test of the dynamic user packages functionality";
52 johnpye 209 int result = 0;
53    
54 johnpye 381 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising EXTFNTEST...\n");
55 johnpye 209
56 johnpye 783 (void)CONSOLE_DEBUG("EVALUATION FUNCTION AT %p",addone_calc);
57 johnpye 711
58 johnpye 692 result += CreateUserFunctionBlackBox("add_one"
59     , addone_prepare
60     , addone_calc /* value */
61     , (ExtBBoxFunc*)NULL /* deriv */
62     , (ExtBBoxFunc*)NULL /* deriv2 */
63 johnpye 912 , (ExtBBoxFinalFunc*)NULL /* final */
64 johnpye 692 , 1,1 /* inputs, outputs */
65     , addone_help
66 johnpye 908 , 0.0
67 johnpye 758 ); /* returns 0 on success */
68 johnpye 209
69 johnpye 758 if(result){
70     ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
71     }
72 johnpye 209 return result;
73     }
74    
75 johnpye 908 int addone_prepare(struct BBoxInterp *slv_interp,
76 johnpye 209 struct Instance *data,
77     struct gl_list_t *arglist
78     ){
79 johnpye 763 const char *mystring = "MY STRING IS HERE";
80    
81 johnpye 380 ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING PKG EXTFNTEST...\n");
82 johnpye 209 slv_interp->user_data = (void *)mystring;
83 johnpye 763
84 johnpye 709 return 0;
85 johnpye 209 }
86    
87 johnpye 719 /* return 0 on success */
88 johnpye 908 int addone_calc(struct BBoxInterp *slv_interp,
89 johnpye 209 int ninputs, int noutputs,
90     double *inputs, double *outputs,
91     double *jacobian
92     ){
93 johnpye 1039 if(noutputs != 1)return -1;
94     if(ninputs != 1)return -2;
95     if(inputs==NULL)return -3;
96     if(outputs==NULL)return -4;
97     if(slv_interp==NULL)return -5;
98 johnpye 209
99 johnpye 711 outputs[0] = inputs[0] + 1;
100 johnpye 209
101 johnpye 1039 return 0;
102 johnpye 209 }

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