/[ascend]/trunk/base/generic/packages/ascFreeAllVars.c
ViewVC logotype

Contents of /trunk/base/generic/packages/ascFreeAllVars.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 73 - (show annotations) (download) (as text)
Fri Dec 2 15:04:23 2005 UTC (18 years, 6 months ago) by johnpye
File MIME type: text/x-csrc
File size: 3750 byte(s)
Minor changes to error reporting
1 /*
2 * ascFreeAllVars.c
3 * by Ben Allan
4 * February 24, 1998
5 * Part of ASCEND
6 * Version: $Revision: 1.4 $
7 * Version control file: $RCSfile: ascFreeAllVars.c,v $
8 * Date last modified: $Date: 1998/06/16 16:42:09 $
9 * Last modified by: $Author: mthomas $
10 *
11 * This file is part of the Ascend Language Interpreter.
12 *
13 * Copyright (C) 1998 Carnegie Mellon University
14 *
15 * The Ascend Language Interpreter is free software; you can
16 * redistribute it and/or modify it under the terms of the GNU
17 * General Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at your option)
19 * any later version.
20 *
21 * The Ascend Language Interpreter is distributed in hope that it
22 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with the program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
29 * the file named COPYING.
30 */
31
32 #include "utilities/ascConfig.h"
33 #include "utilities/ascPrint.h"
34 #include "general/list.h"
35 #include "compiler/compiler.h"
36 #include "compiler/fractions.h"
37 #include "compiler/dimen.h"
38 #include "compiler/child.h"
39 #include "compiler/type_desc.h"
40 #include "compiler/symtab.h"
41 #include "compiler/instance_enum.h"
42 #include "compiler/instquery.h"
43 #include "compiler/atomvalue.h"
44 #include "compiler/visitinst.h"
45 #include "compiler/extfunc.h"
46 #include "compiler/parentchild.h"
47 #include "compiler/library.h"
48 #include "packages/ascFreeAllVars.h"
49
50
51 /*
52 * The following functions give an alternative
53 * to the recursive clear procedure found in most
54 * models.
55 */
56
57 struct cvpacket {
58 struct TypeDescription *g_solver_var_type;
59 symchar *fixed;
60 };
61
62 static
63 void Asc_ClearVars(struct Instance *i, struct cvpacket *cv)
64 {
65 struct Instance *c;
66 struct TypeDescription *type;
67
68 type = InstanceTypeDesc(i);
69 if ( GetBaseType(type) == real_type &&
70 type == MoreRefined(type,cv->g_solver_var_type) ) {
71 c = ChildByChar(i,cv->fixed);
72 if (c != NULL && InstanceKind(c)==BOOLEAN_INST) {
73 SetBooleanAtomValue(c,FALSE,0);
74 }
75 }
76 }
77
78
79 int DLEXPORT Asc_ClearVarsInTree(struct Instance *i)
80 {
81 struct cvpacket cv;
82 cv.g_solver_var_type = FindType(AddSymbol("solver_var"));
83 if (cv.g_solver_var_type == NULL){
84 error_reporter(ASC_PROG_ERROR,__FILE__,__LINE__,"CV.G_SOLVER_VAR_TYPE IS NULL");
85 return 1;
86 }/*else{
87 ERROR_REPORTER_DEBUG("solver_var was found :)\n");
88 }*/
89
90 if (i==NULL){
91 error_reporter(ASC_PROG_ERROR,__FILE__,__LINE__,"INSTANCE IS NULL");
92 return 1;
93 }
94 cv.fixed = AddSymbol("fixed");
95 VisitInstanceTreeTwo(i,(VisitTwoProc)Asc_ClearVars, 0, 0, &cv);
96 return 0;
97 }
98
99 extern int DLEXPORT Asc_FreeAllVars(struct Slv_Interp *dummy1,
100 struct Instance *root,
101 struct gl_list_t *arglist,
102 unsigned long dummy4)
103 {
104 /* arglist is a list of gllist of instances */
105 (void)dummy1;
106 (void)dummy4;
107 if (arglist == NULL ||
108 gl_length(arglist) == 0L ||
109 gl_length((struct gl_list_t *)gl_fetch(arglist,1)) != 1 ||
110 gl_fetch((struct gl_list_t *)gl_fetch(arglist,1),1) == NULL) {
111 /*error_reporter(ASC_PROG_NOTE,__FILE__,__LINE__,"About to call ClearVarsInTree(root)");*/
112 return Asc_ClearVarsInTree(root);
113 } else {
114 /*error_reporter(ASC_PROG_NOTE,__FILE__,__LINE__,"About to call ClearVarsInTree(arglist[1][1])\n");*/
115 return Asc_ClearVarsInTree((struct Instance *)gl_fetch(
116 (struct gl_list_t *)gl_fetch(arglist,1),1));
117 }
118 }

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