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