nec2++  1.7.0
CurrentInput.h
1 /*
2  Copyright (C) 2004 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 __Current_Input__
19 #define __Current_Input__
20 
21 #include "math_util.h"
22 #include <vector>
23 
24 #include "BaseInput.h"
25 
26 class segment
27 {
28 public:
29  int number;
30  int tag;
31  nec_float x,y,z;
32  nec_float length;
33 
34  nec_complex current;
35 
36  // Read the segment data from a NEC-2 output file
37  segment(istream& m_stream)
38  {
39  }
40 };
41 
42 class CurrentInput : public BaseInput
43 {
44 public:
45  vector<segment> segments;
46 
47  long n_items;
48 
49  CurrentInput(std::string& filename)
50  : BaseInput(filename)
51  {
52  n_items = 0;
53 
54  string searchString("CURRENTS AND LOCATION");
55  while (m_stream.good())
56  {
57  string line = readline();
58 
59  if (line.find(searchString,0) != string::npos)
60  {
61 
62  while (line.find("PHASE",0) == string::npos)
63  line = readline();
64 
65  line = readline();
66 
67  while (line != "")
68  {
69  stringstream ss(line);
70 
71  segment s(ss);
72  segments.push_back(s);
73 
74  line = readline();
75  n_items++;
76  }
77  cout << "Currents and Location: " << n_items << " lines" << endl;
78  }
79  }
80  }
81 
82  bool equalto(const CurrentInput& ai)
83  {
84  if (difference(ai) > 1e-5)
85  return false;
86 
87  return true;
88  }
89 
90  nec_float difference(const CurrentInput& ai)
91  {
92  nec_float ret = 0.0;
93 
94  if (n_items != ai.n_items)
95  return 1;
96 
97  for (long i=0; i < n_items;i++)
98  {
99  try
100  {
101  ret += segments[i].diff(ai.segments[i]);
102  }
103  catch (string message)
104  {
105  cout << "Diff at segment [" << i << "] : " << message << endl;
106  }
107  }
108  return ret;
109  };
110 };
111 
112 #endif /* __Current_Input__ */
Definition: BaseInput.h:69
Definition: CurrentInput.h:26
Definition: CurrentInput.h:42