44 enum RESULT_FORMAT m_format;
50 : os(in_os), m_format(in_format), m_in_section(
false)
59 inline void separator() {
61 case RESULT_FORMAT_CSV:
65 case RESULT_FORMAT_NEC:
72 inline void start_record() {
74 case RESULT_FORMAT_XML:
83 inline void end_record() {
85 case RESULT_FORMAT_XML:
86 os <<
"</record>" << endl;
95 inline void padding(
const char* s) {
97 case RESULT_FORMAT_NEC:
106 void center_text(
const std::string& text,
const string& border) {
107 size_t len = text.length() + 2*(border.length() + 1);
108 size_t offset = 40 - len/2;
109 for (
size_t i=0;i<offset;i++)
111 os << border <<
" " << text <<
" " << border << endl;
114 inline void section_start(
const std::string& section_name) {
119 case RESULT_FORMAT_NEC:
120 os << endl << endl << endl;
121 center_text(section_name,
"-----");
124 case RESULT_FORMAT_XML:
125 os <<
"<section name=\"" << section_name <<
"\">" << endl;
129 os << endl << endl << endl;
135 inline void section_end() {
136 m_in_section =
false;
139 case RESULT_FORMAT_NEC:
140 os << endl << endl << endl;
143 case RESULT_FORMAT_XML:
144 os <<
"</section>" << endl;
148 os << endl << endl << endl;
153 inline void int_out(
int w,
int i) {
157 inline void string_out(
int w,
const std::string& s) {
158 os << right << setw(w) << s;
160 inline void string_out(
int w,
const char* s) {
161 os << right << setw(w) << s;
164 inline void real_out(
int w,
int p, nec_float f,
bool sci =
true) {
165 ios::fmtflags flags = ios::showpoint | ios::uppercase | ios::right;
167 flags |= ios::scientific;
171 os.unsetf(ios::adjustfield | ios::basefield | ios::floatfield);
178 inline void complex_out(
int w,
int p, nec_complex c,
bool sci =
true) {
179 real_out(w,p,real(c),sci);
181 real_out(w,p,imag(c),sci);
184 inline void polar_out(
int w,
int p, nec_complex c,
bool sci =
true) {
185 real_out(w,p,abs(c),sci);
187 real_out(w,p,arg_degrees(c),sci);
211 nec_float _frequency;
214 enum RESULT_FORMAT _result_format;
217 virtual void write_to_file(ostream& os) = 0;
218 virtual enum nec_result_type get_result_type() = 0;
221 : _write_file(
true), _result_format(RESULT_FORMAT_NEC)
228 inline bool write_file()
const {
232 inline void set_write_file(
bool f) {
236 inline void set_frequency(nec_float f) {
240 nec_float get_frequency() {
244 inline void set_result_format(
enum RESULT_FORMAT f) {
255 nec_float _eta, _axial_ratio;
261 nec_float _theta0, _theta_step;
262 nec_float _phi0, _phi_step;
268 int in_n_theta,
int in_n_phi,
270 nec_float theta0, nec_float theta_step,
271 nec_float phi0, nec_float phi_step,
273 nec_float in_axial_ratio,
274 int in_segment_number,
277 n_theta = in_n_theta;
281 _mag.resize(n_theta, n_phi);
284 _theta_step = theta_step;
287 _phi_step = phi_step;
290 _axial_ratio = in_axial_ratio;
291 _segment_number = in_segment_number;
294 _mag.resize(n_theta, n_phi);
300 virtual enum nec_result_type get_result_type()
override {
301 return RESULT_NORMALIZED_RECEIVING_PATTERN;
304 void set_input(
int theta_index,
int phi_index, nec_float mag) {
305 _mag(theta_index,phi_index) = mag;
319 nec_float get_theta_start() {
323 nec_float get_phi_start() {
327 nec_float get_delta_theta() {
331 nec_float get_delta_phi() {
335 nec_float get_eta() {
339 nec_float get_axial_ratio() {
343 int get_segment_number() {
344 return _segment_number;
357 nec_float get_mag(
int theta_index,
int phi_index) {
358 return _mag(theta_index, phi_index);
361 nec_float get_norm_factor() {
362 return _mag.maxCoeff();
365 virtual void write_to_file(ostream& os)
override {
371 nec_float norm_factor = get_norm_factor();
375 oh.section_start(
"NORMALIZED RECEIVING PATTERN");
376 os <<
" NORMALIZATION FACTOR: ";oh.real_out(11,4,norm_factor);os << endl;
377 os <<
" ETA: ";oh.real_out(7,2,_eta,
false); os <<
" DEGREES" << endl;
378 os <<
" TYPE: " << _type << endl;
379 os <<
" AXIAL RATIO: "; oh.real_out(6,3,_axial_ratio,
false); os << endl;
380 os <<
" SEGMENT No: ";oh.int_out( 5, _segment_number); os << endl << endl;
381 os <<
" THETA PHI ---- PATTERN ----" << endl;
382 os <<
" (DEG) (DEG) DB MAGNITUDE" << endl;
384 nec_float theta = _theta0;
386 for (
int t=0; t<n_theta; t++) {
387 nec_float phi = _phi0;
389 for (
int p=0; p<n_phi;p++) {
390 nec_float magnitude = _mag(t,p) / norm_factor;
391 nec_float gain = db20(magnitude);
395 oh.real_out(7,2, theta,
false); oh.separator();
396 oh.real_out(7,2, phi,
false); oh.separator();
397 oh.padding(
" "); oh.real_out(7,2, gain,
false); oh.separator();
398 oh.padding(
" "); oh.real_out(11,4, magnitude);
403 theta += _theta_step;
414 vector<int> _tag, _segment;
415 vector<nec_complex> _voltage, _current, _impedance, _admittance;
416 vector<nec_float> _power;
418 nec_complex voli, curi;
429 virtual enum nec_result_type get_result_type()
override {
430 return RESULT_STRUCTURE_EXCITATION;
435 void add(
int segment,
int tag, nec_complex voltage, nec_complex current, nec_float power) {
439 _voltage.push_back(voltage);
440 _current.push_back(current);
441 _impedance.push_back(voltage/current);
442 _admittance.push_back(current/voltage);
443 _power.push_back(power);
447 virtual void write_to_file(ostream& os)
override {
449 oh.section_start(
"STRUCTURE EXCITATION DATA AT NETWORK CONNECTION POINTS");
450 os <<
" TAG SEG VOLTAGE (VOLTS) CURRENT (AMPS) IMPEDANCE (OHMS) ADMITTANCE (MHOS) POWER" << endl;
451 os <<
" No: No: REAL IMAGINARY REAL IMAGINARY REAL IMAGINARY REAL IMAGINARY (WATTS)" << endl;
453 for (
int i=0; i<n_items; i++) {
455 oh.int_out(4, _tag[i]); oh.separator();
456 oh.int_out(5, _segment[i]); oh.separator();
457 oh.complex_out(11,4, _voltage[i]); oh.separator();
458 oh.complex_out(11,4, _current[i]); oh.separator();
459 oh.complex_out(11,4, _impedance[i]); oh.separator();
460 oh.complex_out(11,4, _admittance[i]); oh.separator();
461 oh.real_out(11,4, _power[i]);
468 vector<int> get_tag() {
472 vector<int> get_segment() {
476 vector<nec_complex> get_current() {
480 vector<nec_complex> get_voltage() {
484 vector<nec_float> get_power() {
496 vector<int> _tag, _segment;
497 vector<nec_float> _power;
498 vector<nec_complex> _voltage, _current, _impedance, _admittance;
509 virtual enum nec_result_type get_result_type()
override {
510 return RESULT_ANTENNA_INPUT;
513 void set_input(
int tag,
int segment, nec_complex voltage, nec_complex current, nec_complex impedance, nec_complex admittance, nec_float power);
515 virtual void write_to_file(ostream& os)
override {
520 oh.section_start(
"ANTENNA INPUT PARAMETERS");
521 os <<
" TAG SEG VOLTAGE (VOLTS) CURRENT (AMPS) IMPEDANCE (OHMS) ADMITTANCE (MHOS) POWER" << endl;
522 os <<
" NO. NO. REAL IMAGINARY REAL IMAGINARY REAL IMAGINARY REAL IMAGINARY (WATTS)" << endl;
523 for (
int i=0; i<n_items; i++) {
525 oh.int_out(4, _tag[i]); oh.separator();
526 oh.int_out(5, _segment[i]); oh.separator();
527 oh.complex_out(11,4, _voltage[i]); oh.separator();
528 oh.complex_out(11,4, _current[i]); oh.separator();
529 oh.complex_out(11,4, _impedance[i]); oh.separator();
530 oh.complex_out(11,4, _admittance[i]); oh.separator();
531 oh.real_out(11,4, _power[i]);
538 vector<int> get_tag() {
542 vector<int> get_segment() {
546 vector<nec_complex> get_current() {
550 vector<nec_complex> get_voltage() {
554 vector<nec_complex>& get_impedance();
556 vector<nec_float> get_power() {
568 vector<nec_float> _x, _y, _z;
569 vector<nec_complex> _field_x, _field_y, _field_z;
581 virtual enum nec_result_type get_result_type()
override {
582 return RESULT_NEAR_FIELD_PATTERN;
585 void set_input(nec_float x, nec_float y, nec_float z, nec_complex field_x, nec_complex field_y, nec_complex field_z);
587 virtual void write_to_file(ostream& os)
override {
594 oh.section_start(
"NEAR ELECTRIC FIELDS");
595 os <<
" ------- LOCATION ------- ------- EX ------ ------- EY ------ ------- EZ ------" << endl;
596 os <<
" X Y Z MAGNITUDE PHASE MAGNITUDE PHASE MAGNITUDE PHASE" << endl;
597 os <<
" METERS METERS METERS VOLTS/M DEGREES VOLTS/M DEGREES VOLTS/M DEGREES" << endl;
599 oh.section_start(
"NEAR MAGNETIC FIELDS");
600 os <<
" ------- LOCATION ------- ------- HX ------ ------- HY ------ ------- HZ ------" << endl;
601 os <<
" X Y Z MAGNITUDE PHASE MAGNITUDE PHASE MAGNITUDE PHASE" << endl;
602 os <<
" METERS METERS METERS AMPS/M DEGREES AMPS/M DEGREES AMPS/M DEGREES" << endl;
604 for (
int i=0; i<n_items; i++) {
607 oh.real_out(9, 4, _x[i],
false); oh.separator();
608 oh.real_out(9, 4, _y[i],
false); oh.separator();
609 oh.real_out(9, 4, _z[i],
false); oh.separator();
611 oh.real_out(11, 4, abs(_field_x[i]),
true); oh.separator();
612 oh.real_out(7, 2, arg_degrees(_field_x[i]),
false); oh.separator();
614 oh.real_out(11, 4, abs(_field_y[i]),
true); oh.separator();
615 oh.real_out(7, 2, arg_degrees(_field_y[i]),
false); oh.separator();
617 oh.real_out(11, 4, abs(_field_z[i]),
true); oh.separator();
618 oh.real_out(7, 2, arg_degrees(_field_z[i]),
false); oh.separator();
629 vector<nec_float> get_x() {
633 vector<nec_float> get_y() {
637 vector<nec_float> get_z() {
641 vector<nec_complex> get_field_x() {
645 vector<nec_complex> get_field_y() {
649 vector<nec_complex> get_field_z() {
nec_base_result * get_result(const long index, const enum nec_result_type result_type)
Get the nth result that matches the specified result type.
Definition nec_results.h:711