viminfo
[gnucap-felix.git] / apps / measure_min.cc
blob29f8d49d1948b655e6df60cce81439faa9971293
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)
10 * any later version.
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
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
23 #include "globals.h"
24 #include "u_parameter.h"
25 #include "m_wave.h"
26 #include "u_function.h"
27 /*--------------------------------------------------------------------------*/
28 namespace {
29 /*--------------------------------------------------------------------------*/
30 class MEASURE : public FUNCTION {
31 public:
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);
37 bool last = false;
38 bool arg = false;
40 unsigned here = Cmd.cursor();
41 Cmd >> probe_name;
42 WAVE* w = find_wave(probe_name);
44 if (!w) {
45 Cmd.reset(here);
46 }else{
49 here = Cmd.cursor();
50 do {
51 ONE_OF
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));
63 if (!w) {
64 w = find_wave(probe_name);
65 }else{
68 if (w) {
69 before.e_val(BIGBIG, Scope);
70 after.e_val(-BIGBIG, Scope);
72 double time = (last) ? -BIGBIG : BIGBIG;
73 double m = 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))) {
79 time = i->first;
80 m = val;
81 }else{
84 return to_string((arg) ? (time) : (m));
85 }else{
86 throw Exception_No_Match(probe_name);
89 } p2;
90 DISPATCHER<FUNCTION>::INSTALL d2(&measure_dispatcher, "min", &p2);
91 /*--------------------------------------------------------------------------*/
93 /*--------------------------------------------------------------------------*/
94 /*--------------------------------------------------------------------------*/
95 // vim:ts=8:sw=2:noet: