1 /*$Id: measure_min.cc,v 26.137 2010/04/10 02:37:05 al Exp $ -*- C++ -*-
2 * Copyright (C) 2008 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
24 #include "u_parameter.h"
26 #include "u_function.h"
27 /*--------------------------------------------------------------------------*/
29 /*--------------------------------------------------------------------------*/
30 class MEASURE
: public FUNCTION
{
32 std::string
eval(CS
& Cmd
, const CARD_LIST
* Scope
)const
34 std::string probe_name
;
35 PARAMETER
<double> before(BIGBIG
);
36 PARAMETER
<double> after(-BIGBIG
);
40 unsigned here
= Cmd
.cursor();
42 WAVE
* w
= find_wave(probe_name
);
52 || Get(Cmd
, "probe", &probe_name
)
53 || Get(Cmd
, "before", &before
)
54 || Get(Cmd
, "after", &after
)
55 || Get(Cmd
, "end", &before
)
56 || Get(Cmd
, "begin", &after
)
57 || Set(Cmd
, "arg", &arg
, true)
58 || Set(Cmd
, "last", &last
, true)
59 || Set(Cmd
, "first", &last
, false)
61 }while (Cmd
.more() && !Cmd
.stuck(&here
));
64 w
= find_wave(probe_name
);
69 before
.e_val(BIGBIG
, Scope
);
70 after
.e_val(-BIGBIG
, Scope
);
72 double time
= (last
) ? -BIGBIG
: BIGBIG
;
74 WAVE::const_iterator begin
= lower_bound(w
->begin(), w
->end(), DPAIR(after
, -BIGBIG
));
75 WAVE::const_iterator end
= upper_bound(w
->begin(), w
->end(), DPAIR(before
, BIGBIG
));
76 for (WAVE::const_iterator i
= begin
; i
< end
; ++i
) {
77 double val
= i
->second
;
78 if (val
< m
|| (last
&& (val
== m
))) {
84 return to_string((arg
) ? (time
) : (m
));
86 throw Exception_No_Match(probe_name
);
90 DISPATCHER
<FUNCTION
>::INSTALL
d2(&measure_dispatcher
, "min", &p2
);
91 /*--------------------------------------------------------------------------*/
93 /*--------------------------------------------------------------------------*/
94 /*--------------------------------------------------------------------------*/
95 // vim:ts=8:sw=2:noet: