nec2++  1.7.0
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 #ifndef __PowerBudget__
19 #define __PowerBudget__
20 
21 #include <vector>
22 #include "BaseInput.h"
23 
24 /*
25  ---------- POWER BUDGET ---------
26  INPUT POWER = 3.3203E-05 Watts
27  RADIATED POWER= 3.3203E-05 Watts
28  STRUCTURE LOSS= 0.0000E+00 Watts
29  NETWORK LOSS = 0.0000E+00 Watts
30  EFFICIENCY = 100.00 Percent
31 */
32 class PowerBudget : public BaseInput
33 {
34 public:
35  vector<double> input_power, radiated_power, structure_loss, network_loss, efficiency;
36  long n_items;
37 
38  double get_power_line()
39  {
40  string line = readline();
41  if (line.length() < 2)
42  line = readline();
43 
44  // delete up to '=' character (+1 includes the = character)
45  line.erase(0, line.find("=",0) + 1);
46  stringstream ss(line);
47  double ret = read_sci(ss);
48  return ret;
49  }
50 
51  PowerBudget(std::string& filename)
52  : BaseInput(filename)
53  {
54  n_items = 0;
55  string searchString("POWER BUDGET");
56  while (m_stream.good())
57  {
58  string line = readline();
59 
60  if (line.find(searchString,0) != string::npos)
61  {
62  // check for a blank line here.
63 
64  {
65  double p = get_power_line();
66  input_power.push_back(p);
67  }
68  {
69  double p = get_power_line();
70  radiated_power.push_back(p);
71  }
72  {
73  double p = get_power_line();
74  structure_loss.push_back(p);
75  }
76  {
77  double p = get_power_line();
78  network_loss.push_back(p);
79  }
80  {
81  double p = get_power_line();
82  efficiency.push_back(p);
83  }
84  n_items++;
85  }
86  }
87  }
88 
89  bool equalto(const PowerBudget& pb)
90  {
91  if (difference(pb) > 1e-4)
92  return false;
93 
94  return true;
95  }
96 
97  double difference(const PowerBudget& pb)
98  {
99  double ret = 0;
100 
101  if (n_items != pb.n_items)
102  return 1.0;
103 
104  try
105  {
106  for (long i=0; i<n_items; i++)
107  {
108  ret += diff(pb.input_power[i],input_power[i]);
109  ret += diff(pb.radiated_power[i],radiated_power[i]);
110  ret += diff(pb.structure_loss[i],structure_loss[i]);
111  ret += diff(pb.network_loss[i],network_loss[i]);
112  ret += diff(pb.efficiency[i],efficiency[i]);
113  }
114  }
115  catch(string message)
116  {
117  cout << "diff : " << message << endl;
118  }
119  return ret;
120  };
121 };
122 
123 #endif /* __PowerBudget__ */
Definition: BaseInput.h:69
Definition: PowerBudget.h:32