1 /*$Id: c_list.cc,v 1.3 2009-12-13 17:55:01 felix Exp $ -*- 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)
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 //testing=script 2006.07.17
27 #include "e_cardlist.h"
35 /*--------------------------------------------------------------------------*/
38 /*--------------------------------------------------------------------------*/
39 void volts_load( fstream
*in
, CARD_LIST
* )
47 trace1("volts_load", Last
);
48 CKT_BASE::_sim
->init();
49 assert(CKT_BASE::_sim
->vdc());
50 CKT_BASE::_sim
->_last_Time
= Last
;
51 while ( ! (in
->eof() ) ){
52 assert( i
< CKT_BASE::_sim
->_total_nodes
+2 + CKT_BASE::_sim
->_adp_nodes
);
55 if( '\n' == in
->peek()
56 ||' ' == in
->peek() ){
58 } else if( 'n' == in
->peek() ){
59 *in
>> inss
>> skipws
;
61 trace1(" putting nan ", i
);
62 CKT_BASE::_sim
->vdc()[i
] = NAN
;
65 } else if(*in
>> ind
){
67 trace2(" putting ", i
, ind
);
68 CKT_BASE::_sim
->vdc()[i
] = ind
;
71 //*in >> skipws >> inss;
72 inss
= (char) in
->get();
73 trace1((" garbage ->" + inss
+ "<- ").c_str(), (int)inss
[0]);
77 /*--------------------------------------------------------------------------*/
78 void volts_save(CS
&, OMSTREAM out
, CARD_LIST
*)
80 CARD_LIST::card_list
.precalc_first();
82 //out.setfloatwidth(7);
83 switch (ENV::run_mode
) {
90 case rPIPE
: untested();
91 case rBATCH
: itested();
92 case rINTERACTIVE
: itested();
99 throw Exception("no language");
103 if (! CKT_BASE::_sim
->_nstat
) return;
104 trace2( "save", CKT_BASE::_sim
->_total_nodes
, CKT_BASE::_sim
->_adp_nodes
);
106 out
<< CKT_BASE::_sim
->_last_Time
<< "\n";
108 for ( uint_t i
= 1; CKT_BASE::_sim
->_total_nodes
+ 1 + CKT_BASE::_sim
->_adp_nodes
> i
; ++i
){
109 out
<< CKT_BASE::_sim
->vdc()[i
] << "\n";
112 /*--------------------------------------------------------------------------*/
113 class CMD_LIST
: public CMD
{
115 void do_it(CS
& cmd
, CARD_LIST
* Scope
)
117 std::string filename
;
119 fstream
inFile(filename
.c_str());
121 cerr
<< "Unable to open " << filename
<< " for reading." << endl
;
124 volts_load(&inFile
, Scope
);
128 DISPATCHER
<CMD
>::INSTALL
d1(&command_dispatcher
, "vload", &p1
);
129 /*--------------------------------------------------------------------------*/
130 class CMD_SAVE
: public CMD
{
132 void do_it(CS
& cmd
, CARD_LIST
* Scope
)
134 OMSTREAM out
= IO::mstdout
;
135 out
.setfloatwidth(30);
137 volts_save(cmd
, out
, Scope
);
141 DISPATCHER
<CMD
>::INSTALL
d2(&command_dispatcher
, "vdump|vsave", &p2
);
142 /*--------------------------------------------------------------------------*/
144 /*--------------------------------------------------------------------------*/
145 /*--------------------------------------------------------------------------*/