nec2++ 2.1.1
RadiationInput.h
1/*
2 Copyright (C) 2004-2005 Timothy C.A. Molteno
3 tim@molteno.net
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19#pragma once
20
21#include <vector>
22#include <cctype>
23#include <cstdlib>
24
25#include "BaseInput.h"
26
28{
29public:
30 vector<double> theta, phi;
31 vector<double> power_v, power_h, power_t;
32 vector<double> pol_axial_ratio, pol_tilt;
33 string pol_sense; // ignore polarization sense
34 vector<double> E_theta_mag, E_phi_mag;
35 vector<double> E_theta_phase, E_phi_phase;
36
37 long n_items;
38
39 RadiationInput(std::string& filename)
40 : BaseInput(filename)
41 {
42 n_items = 0;
43
44 string searchString("RADIATION PATTERNS");
45 while (m_stream.good())
46 {
47 string line = readline();
48
49 if (line.find(searchString,0) != string::npos)
50 {
51
52 while (line.find("VOLTS/M",0) == string::npos)
53 line = readline();
54
55 /*
56 - - ANGLES - - - POWER GAINS - - - - POLARIZATION - - - - - - E(THETA) - - - - - - E(PHI) - - -
57 THETA PHI VERT. HOR. TOTAL AXIAL TILT SENSE MAGNITUDE PHASE MAGNITUDE PHASE
58 DEGREES DEGREES DB DB DB RATIO DEG. VOLTS/M DEGREES VOLTS/M DEGREES
59 .00 .00 -999.99 -3.23 -3.23 .00000 -90.00 LINEAR 0.00000E+00 -81.39 7.35700E-05 -195.64
60 */
61 line = readline();
62
63 while (line != "")
64 {
65 stringstream ss(line);
66
67 theta.push_back(read_fixed(ss));
68 phi.push_back(read_fixed(ss));
69 power_v.push_back(read_fixed(ss));
70 power_h.push_back(read_fixed(ss));
71 power_t.push_back(read_fixed(ss));
72 pol_axial_ratio.push_back(read_fixed(ss));
73 pol_tilt.push_back(read_fixed(ss));
74
75 string sense_token;
76 ss >> sense_token;
77 if (!sense_token.empty() && isalpha(static_cast<unsigned char>(sense_token[0])))
78 {
79 /* SENSE column present (LINEAR/LEFT/RIGHT) */
80 pol_sense = sense_token;
81 E_theta_mag.push_back(read_sci(ss));
82 }
83 else
84 {
85 /* SENSE column is blank when the polarization is
86 undefined (e.g. HORIZ gain = -999.99 at the horizon).
87 The token just read is E_theta_mag, not a sense. */
88 pol_sense = "";
89 E_theta_mag.push_back(sense_token.empty() ? 0.0 : atof(sense_token.c_str()));
90 }
91
92 E_theta_phase.push_back(read_fixed(ss));
93
94 E_phi_mag.push_back(read_sci(ss));
95 E_phi_phase.push_back(read_fixed(ss));
96
97 line = readline();
98 n_items++;
99 }
100 cout << "Radiation pattern: " << n_items << " lines" << endl;
101 }
102 }
103 }
104
105 bool equalto(const RadiationInput& ai)
106 {
107 if (difference(ai) > 1e-4)
108 return false;
109
110 return true;
111 }
112
113 double difference(const RadiationInput& ai)
114 {
115 double ret = 0.0;
116 // compart angles
117 if (n_items != ai.n_items)
118 return 1;
119
120 for (long i=0; i < n_items;i++)
121 {
122 if (theta[i] != ai.theta[i])
123 return 1;
124 if (phi[i] != ai.phi[i])
125 return 1;
126
127 try
128 {
129 ret += diff(power_v[i], ai.power_v[i]);
130 ret += diff(power_h[i], ai.power_h[i]);
131 ret += diff(power_t[i], ai.power_t[i]);
132 if (power_v[i] > -999.0)
133 {
134 ret += diff(pol_axial_ratio[i], ai.pol_axial_ratio[i]);
135 ret += diff(pol_tilt[i], ai.pol_tilt[i]);
136
137 ret += diff(deg_polar(E_theta_mag[i],E_theta_phase[i]), deg_polar(ai.E_theta_mag[i],ai.E_theta_phase[i]));
138 ret += diff(deg_polar(E_phi_mag[i],E_phi_phase[i]), deg_polar(ai.E_phi_mag[i],ai.E_phi_phase[i]));
139 }
140 }
141 catch (string message)
142 {
143 cout << "Diff at [" << theta[i] << "," << phi[i] << "] : " << message << endl;
144 }
145 }
146 return ret;
147 };
148};
Definition BaseInput.h:69
Definition RadiationInput.h:28