1 /*$Id: measure_integral.cc,v 1.3 2009-12-16 17:22:07 felix Exp $ -*- C++ -*-
3 * Copyright (C) 2008 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 *------------------------------------------------------------------
24 #include "u_parameter.h"
26 #include "u_function.h"
27 /*--------------------------------------------------------------------------*/
29 /*--------------------------------------------------------------------------*/
30 class MEASURE
: public WAVE_FUNCTION
{
31 PARAMETER
<double> before
;
32 PARAMETER
<double> after
;
39 virtual FUNCTION_BASE
* clone()const { return new MEASURE(*this);}
40 string
label()const{return "integral";}
41 void expand(CS
& Cmd
, const CARD_LIST
* Scope
)
44 unsigned here
= Cmd
.cursor();
46 _w
= find_wave(probe_name
);
56 || Get(Cmd
, "probe", &probe_name
)
57 || Get(Cmd
, "before", &before
)
58 || Get(Cmd
, "after", &after
)
59 || Get(Cmd
, "end", &before
)
60 || Get(Cmd
, "begin", &after
)
62 }while (Cmd
.more() && !Cmd
.stuck(&here
));
65 _w
= find_wave(probe_name
);
69 before
.e_val(BIGBIG
, Scope
);
70 after
.e_val(-BIGBIG
, Scope
);
73 fun_t
wave_eval()const
76 WAVE::const_iterator begin
= lower_bound(_w
->begin(), _w
->end(), DPAIR(after
, -BIGBIG
));
77 WAVE::const_iterator end
= upper_bound(_w
->begin(), _w
->end(), DPAIR(before
, BIGBIG
));
78 WAVE::const_iterator lower
= begin
;
81 for (WAVE::const_iterator i
= begin
; ++i
< end
; ) {
82 area
+= .5 * (lower
->second
+ i
->second
) * (i
->first
- lower
->first
);
85 return to_fun_t(area
);
87 throw Exception_No_Match(probe_name
);
91 DISPATCHER
<FUNCTION_BASE
>::INSTALL
d4(&measure_dispatcher
, "integrate|integral|area", &p4
);
92 /*--------------------------------------------------------------------------*/
94 /*--------------------------------------------------------------------------*/
95 /*--------------------------------------------------------------------------*/
96 // vim:ts=8:sw=2:noet: