nec2++ 2.1.1
PowerBudget.h
1/*
2 Copyright (C) 2004-2005 Timothy C.A. Molteno
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18#pragma once
19
20#include <vector>
21#include "BaseInput.h"
22
23/*
24 ---------- POWER BUDGET ---------
25 INPUT POWER = 3.3203E-05 Watts
26 RADIATED POWER= 3.3203E-05 Watts
27 STRUCTURE LOSS= 0.0000E+00 Watts
28 NETWORK LOSS = 0.0000E+00 Watts
29 EFFICIENCY = 100.00 Percent
30*/
31class PowerBudget : public BaseInput
32{
33public:
34 vector<double> input_power, radiated_power, structure_loss, network_loss, efficiency;
35 long n_items;
36
37 double get_power_line()
38 {
39 string line = readline();
40 if (line.length() < 2)
41 line = readline();
42
43 // delete up to '=' character (+1 includes the = character)
44 line.erase(0, line.find("=",0) + 1);
45 stringstream ss(line);
46 double ret = read_sci(ss);
47 return ret;
48 }
49
50 PowerBudget(std::string& filename)
51 : BaseInput(filename)
52 {
53 n_items = 0;
54 string searchString("POWER BUDGET");
55 while (m_stream.good())
56 {
57 string line = readline();
58
59 if (line.find(searchString,0) != string::npos)
60 {
61 // check for a blank line here.
62
63 {
64 double p = get_power_line();
65 input_power.push_back(p);
66 }
67 {
68 double p = get_power_line();
69 radiated_power.push_back(p);
70 }
71 {
72 double p = get_power_line();
73 structure_loss.push_back(p);
74 }
75 {
76 double p = get_power_line();
77 network_loss.push_back(p);
78 }
79 {
80 double p = get_power_line();
81 efficiency.push_back(p);
82 }
83 n_items++;
84 }
85 }
86 }
87
88 bool equalto(const PowerBudget& pb)
89 {
90 if (difference(pb) > 1e-4)
91 return false;
92
93 return true;
94 }
95
96 double difference(const PowerBudget& pb)
97 {
98 double ret = 0;
99
100 if (n_items != pb.n_items)
101 return 1.0;
102
103 try
104 {
105 for (long i=0; i<n_items; i++)
106 {
107 ret += diff(pb.input_power[i],input_power[i]);
108 ret += diff(pb.radiated_power[i],radiated_power[i]);
109 ret += diff(pb.structure_loss[i],structure_loss[i]);
110 ret += diff(pb.network_loss[i],network_loss[i]);
111 ret += diff(pb.efficiency[i],efficiency[i]);
112 }
113 }
114 catch(string message)
115 {
116 cout << "diff : " << message << endl;
117 }
118 return ret;
119 };
120};
Definition BaseInput.h:69
Definition PowerBudget.h:32