testing
[gnucap-felix.git] / modules / c_nodeset.cc
blob9b88c991c816e3c228ca16a2b306b91a3d56f289
1 /* -*- C++ -*-
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)
11 * any later version.
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
21 * 02110-1301, USA.
22 *------------------------------------------------------------------
23 * list and save commands.
24 * save is list with direction to file
26 #include "e_cardlist.h"
27 #include "u_lang.h"
28 #include "c_comand.h"
29 #include "globals.h"
30 #include "e_node.h"
31 #include "u_nodemap.h"
32 #include "e_adp.h"
33 #include <iostream>
34 #include <fstream>
35 #include <string>
36 #include <iomanip>
37 using namespace std;
38 /*--------------------------------------------------------------------------*/
39 namespace { //
40 /*--------------------------------------------------------------------------*/
41 class CMD_NODESET : public CMD { //
42 public:
43 void do_it(CS& cmd, CARD_LIST* Scope)
45 std::string what(cmd.ctos(TOKENTERM));/* parameter */
47 unsigned paren = cmd.skip1b('(');
48 string name;
49 NODE_BASE* n =0;
51 CKT_BASE::_sim->init(false);
53 if(Umatch("v ", what) || Umatch("a ", what) ){
54 trace0("CMD_NODESET::do_it v|a");
55 name = cmd.ctos();
57 paren -= cmd.skip1b(')');
59 if (paren) {itested();
60 cmd.warn(bWARNING, "need )");
61 return;
63 try{
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");
67 return;
70 if (!n){ untested();
71 unreachable();
72 cmd.warn(bWARNING, "no such node: " + name + "\n");
73 return;
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");
80 cmd.skip1b('=');
81 double v;
82 cmd >> v;
83 CKT_BASE::_sim->init();
84 CKT_NODE* x = dynamic_cast<CKT_NODE*>(n);
86 if(x){ untested();
87 trace3(" setting node", x->matrix_number(), _sim->vdc()[ x->matrix_number()], v);
88 _sim->vdc()[ x->matrix_number() ] = v;
89 } else{ untested();
90 cmd.warn(bWARNING, " no node "+ name);
93 }else if (Umatch("a",what)) {
94 trace0("CMD_NODESET::do_it a");
95 assert(n);
97 CKT_BASE::_sim->init(false);
99 ADP_NODE* a = dynamic_cast<ADP_NODE*>(n);
100 if (!a){ untested();
101 cmd.warn(bWARNING, "not an adp node: " + name + "\n");
102 throw(Exception_Type_Mismatch("nodeset:", n->long_label(), "adpnode"));
105 cmd.skip1b('=');
106 double v;
107 cmd >> v;
109 assert(CKT_BASE::_sim->_tt);
110 a->set_tt(v);
111 trace2("set adpnode", a->m_(), a->tt());
112 }else{ untested();
113 incomplete();
114 assert(false);
117 } p1;
118 DISPATCHER<CMD>::INSTALL d1(&command_dispatcher, "nodeset", &p1);
119 /*--------------------------------------------------------------------------*/
120 enum NODETYPE { //
121 nCKT = 1,
122 nADP = 2
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);
128 bool _debug;
129 public:
130 void do_it(CS& cmd, CARD_LIST* Scope);
131 } p2;
132 /*--------------------------------------------------------------------------*/
133 void CMD_DUMP::do_it(CS& cmd, CARD_LIST* Scope){
134 bool _a = false;
135 bool _v = false;
136 _debug = false;
138 OMSTREAM _out = IO::mstdout;
139 _out.setfloatwidth(OPT::numdgt);
141 //out.setfloatwidth(7);
142 switch (ENV::run_mode) { untested();
143 case rPRE_MAIN:
144 unreachable();
145 return;
146 case rPRESET:
147 /* do nothing */
148 return;
149 case rPIPE: untested();
150 case rBATCH:
151 case rINTERACTIVE:
152 case rSCRIPT:
153 /* keep going */
154 break;
157 if (!OPT::language) { untested();
158 throw Exception("no language");
159 }else{
161 unsigned here = cmd.cursor();
163 ONE_OF
164 || Get(cmd, "adp", &_a)
165 || Get(cmd, "debug", &_debug)
166 || Get(cmd, "volt{ages}", &_v)
167 || _out.outset(cmd)
169 }while (cmd.more() && !cmd.stuck(&here));
170 trace2("CMD_NODESET::do_it", _a, _v);
172 if (!_a && !_v) {
173 _v = 1;
174 } else {
177 // if spice, hrm..
178 string dot=".";
180 if (_v || _a) {
181 CKT_BASE::_sim->init(false);
182 printv(_out, Scope, _v+2*_a);
184 _out.outreset();
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)
193 string dot(".");
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") {
198 stringstream s;
199 string prefix="";
201 if(scope->owner()){
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();
223 _out <<"\n";
224 }else{
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())
232 if (s->subckt()) {
233 // _out << "* -" << s->long_label() <<"\n";
234 printv(_out,s->subckt(), what);
239 /*--------------------------------------------------------------------------*/