3 * Copyright (C) 2001 Albert Davis
4 * Author: Albert Davis <aldavis@gnu.org>
6 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 *------------------------------------------------------------------
23 * list and save commands.
24 * save is list with direction to file
26 #include "e_cardlist.h"
31 #include "u_nodemap.h"
38 /*--------------------------------------------------------------------------*/
40 /*--------------------------------------------------------------------------*/
41 class CMD_NODESET
: public CMD
{ //
43 void do_it(CS
& cmd
, CARD_LIST
* Scope
)
45 std::string
what(cmd
.ctos(TOKENTERM
));/* parameter */
47 unsigned paren
= cmd
.skip1b('(');
51 CKT_BASE::_sim
->init(false);
53 if(Umatch("v ", what
) || Umatch("a ", what
) ){
54 trace0("CMD_NODESET::do_it v|a");
57 paren
-= cmd
.skip1b(')');
59 if (paren
) {itested();
60 cmd
.warn(bWARNING
, "need )");
64 n
= NODE_BASE::lookup_node(name
, Scope
);
65 } catch (Exception_Cant_Find e
) { untested();
66 cmd
.warn(bWARNING
, "no such node: " + name
+ ": " + e
.message() +"\n");
72 cmd
.warn(bWARNING
, "no such node: " + name
+ "\n");
75 trace1("CMD_NODESET::do_it have node", n
->long_label());
78 if(what
=="V"||what
=="v"){ untested();
79 trace0("CMD_NODESET::do_it v");
83 CKT_BASE::_sim
->init();
84 CKT_NODE
* x
= dynamic_cast<CKT_NODE
*>(n
);
87 trace3(" setting node", x
->matrix_number(), _sim
->vdc()[ x
->matrix_number()], v
);
88 _sim
->vdc()[ x
->matrix_number() ] = v
;
90 cmd
.warn(bWARNING
, " no node "+ name
);
93 }else if (Umatch("a",what
)) {
94 trace0("CMD_NODESET::do_it a");
97 CKT_BASE::_sim
->init(false);
99 ADP_NODE
* a
= dynamic_cast<ADP_NODE
*>(n
);
101 cmd
.warn(bWARNING
, "not an adp node: " + name
+ "\n");
102 throw(Exception_Type_Mismatch("nodeset:", n
->long_label(), "adpnode"));
109 assert(CKT_BASE::_sim
->_tt
);
111 trace2("set adpnode", a
->m_(), a
->tt());
118 DISPATCHER
<CMD
>::INSTALL
d1(&command_dispatcher
, "nodeset", &p1
);
119 /*--------------------------------------------------------------------------*/
124 /*--------------------------------------------------------------------------*/
125 class CMD_DUMP
: public CMD
{ //
126 void dump(CS
&, OMSTREAM out
, CARD_LIST
*);
127 void printv( OMSTREAM _out
, const CARD_LIST
* scope
, unsigned what
=nCKT
);
130 void do_it(CS
& cmd
, CARD_LIST
* Scope
);
132 /*--------------------------------------------------------------------------*/
133 void CMD_DUMP::do_it(CS
& cmd
, CARD_LIST
* Scope
){
138 OMSTREAM _out
= IO::mstdout
;
139 _out
.setfloatwidth(OPT::numdgt
);
141 //out.setfloatwidth(7);
142 switch (ENV::run_mode
) { untested();
149 case rPIPE
: untested();
157 if (!OPT::language
) { untested();
158 throw Exception("no language");
161 unsigned here
= cmd
.cursor();
164 || Get(cmd
, "adp", &_a
)
165 || Get(cmd
, "debug", &_debug
)
166 || Get(cmd
, "volt{ages}", &_v
)
169 }while (cmd
.more() && !cmd
.stuck(&here
));
170 trace2("CMD_NODESET::do_it", _a
, _v
);
181 CKT_BASE::_sim
->init(false);
182 printv(_out
, Scope
, _v
+2*_a
);
186 DISPATCHER
<CMD
>::INSTALL
d2(&command_dispatcher
, "nodedump|dumpnodes", &p2
);
187 /*--------------------------------------------------------------------------*/
188 /*--------------------------------------------------------------------------*/
190 /*--------------------------------------------------------------------------*/
191 void CMD_DUMP::printv( OMSTREAM _out
, const CARD_LIST
* scope
, unsigned what
)
195 const NODE_MAP
* nm
= scope
->nodes();
196 for (NODE_MAP::const_iterator i
= nm
->begin(); i
!= nm
->end(); ++i
) {
197 if (i
->first
!= "0") {
202 // _out << "* " << scope->owner()->long_label() << " * " << i->second->short_label()<<" " << what<< "\n";
203 prefix
= scope
->owner()->long_label() + ".";
206 CKT_NODE
* N
=dynamic_cast<CKT_NODE
*>(i
->second
);
207 ADP_NODE
* A
=dynamic_cast<ADP_NODE
*>(i
->second
);
209 if(N
&& (what
& nCKT
) ){
210 _out
<< dot
<< "nodeset v(" << i
->second
->long_label() << ")=";
211 _out
<< setw(8) << N
->vdc();
214 if(A
&& (what
& nADP
) ){
215 assert(CKT_BASE::_sim
->_tt
);
216 trace3("CMD_NODESET::do_it FIXME", prefix
, i
->second
->short_label(), i
->second
->long_label());
217 if (_debug
) { untested();
218 _out
<< "* " << A
->m_() << "\n";
220 _out
<< dot
<< "nodeset a(" << prefix
<< i
->second
->short_label() << ")=";
221 _out
<< "" << setw(8) << A
->tt();
225 // _out << "Zero Node " << "\n";
229 for (CARD_LIST::const_iterator i
= scope
->begin(); i
!= scope
->end(); ++i
) {
230 const COMPONENT
* s
= dynamic_cast<const COMPONENT
*>(*i
);
231 if ((*i
)->is_device())
233 // _out << "* -" << s->long_label() <<"\n";
234 printv(_out
,s
->subckt(), what
);
239 /*--------------------------------------------------------------------------*/