-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy paths_sweep.cc
117 lines (110 loc) · 3.48 KB
/
s_sweep.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* Copyright (C) 2021 Felix Salfelder
*
* This file is part of "Gnucap", the Gnu Circuit Analysis Package
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*------------------------------------------------------------------
* sweep command and objects
*/
#include "u_parameter.h"
#include "e_card.h"
#include "c_comand.h"
#include "globals.h"
#include "l_qucs.h" // QucsGet
#include "s__out.cc"
#include "s__init.cc"
namespace{
/*--------------------------------------------------------------------------*/
enum typeT{
tLin = 0,
tLog = 1
};
/*--------------------------------------------------------------------------*/
class SW_WRAP : public CARD, public CMD {
public:
SW_WRAP(): CARD(), CMD() {}
private:
CARD* clone()const override {return new SW_WRAP(*this);}
std::string value_name()const override { untested();unreachable(); return "";}
private:
double _start; // PARAMETER?
double _stop;
unsigned _points = 1;
std::string _sim;
std::string _param;
typeT _type;
void options(CS& cmd){
size_t here = cmd.cursor();
do{
ONE_OF
|| QucsGet(cmd, "Sim", &_sim)
|| QucsGet(cmd, "Start", &_start)
|| QucsGet(cmd, "Stop", &_stop)
|| QucsGet(cmd, "Param", &_param)
|| QucsGet(cmd, "Points", &_points)
|| (cmd.umatch( "Type") &&
(ONE_OF
|| QucsSet(cmd, "lin", &_type, tLin)
|| QucsSet(cmd, "log", &_type, tLog)
|| cmd.warn(bWARNING, "need lin, log... incomplete")
)
)
;
}while (cmd.more() && !cmd.stuck(&here));
assert(_points);
}
void do_it(CS& cmd, CARD_LIST* Scope)override {
assert(Scope);
if(cmd >> "go"){
error(bTRACE, "sweep " + cmd.fullstring() + "\n");
auto it = Scope->find_(_sim);
if(it==Scope->end()){ untested();
throw Exception_CS("unknown sim " + _sim, cmd);
}else if(auto c=dynamic_cast<CMD*>(*it)){
cmd.reset();
std::stringstream x;
x << cmd.fullstring() << " " << _param
<< " " << _start
<< " " << _stop
<< " " << (_stop-_start) / (_points - 1);
CS xx(CS::_STRING, x.str());
c->do_it(xx, Scope);
}else{ untested();
unreachable();
}
}else{
options(cmd);
trace4("sweep", _sim, _param, _start, _stop);
PARAM_LIST* pl = Scope->params();
assert(pl);
// pl->set(_param, _start);
#if 0
pl->set("__omit_"+_sim, "");
auto omit = pl->deep_lookup("__omit_"+_sim);
assert(!omit.has_hard_value());
#endif
pl->set("__omit_"+_sim, "1");
// BUG: modify clone instead.
auto cl = clone();
cl->CARD::set_label(CMD::short_label());
Scope->push_back(cl);
}
}
} psw;
DISPATCHER<CMD>::INSTALL dsw(&command_dispatcher, "SW", (CMD*)&psw);
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/