From 6d816823db84878f9de2724f0aac2da1096b604c Mon Sep 17 00:00:00 2001 From: adrian Date: Sun, 4 Dec 2011 11:28:59 +0200 Subject: [PATCH] Load pattern file from FG_HOME/antennas --- src/Radio/antenna.cxx | 30 ++++++++++++++++++++++++++---- src/Radio/antenna.hxx | 8 +++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Radio/antenna.cxx b/src/Radio/antenna.cxx index d61848907..8ebb154f0 100644 --- a/src/Radio/antenna.cxx +++ b/src/Radio/antenna.cxx @@ -22,18 +22,20 @@ #endif #include - +#include #include - +#include #include #include "antenna.hxx" +using namespace std; -FGRadioAntenna::FGRadioAntenna() { +FGRadioAntenna::FGRadioAntenna(string type) { _mirror_y = 1; _mirror_z = 1; _invert_ground = 0; + load_antenna_pattern(type); } FGRadioAntenna::~FGRadioAntenna() { @@ -48,6 +50,26 @@ double FGRadioAntenna::calculate_gain(double azimuth, double elevation) { /*** load external plot file generated by NEC4 ***/ -void FGRadioAntenna::load_antenna_pattern() { +void FGRadioAntenna::load_antenna_pattern(string type) { + + SGPath pattern_file(fgGetString("/sim/fg-home")); + pattern_file.append("antennas"); + pattern_file.append(type + ".txt"); + if (!pattern_file.exists()) { + return; + } + ifstream file_in(pattern_file.c_str()); + int heading, elevation; + double gain; + while(!file_in.eof()) { + file_in >> heading >> elevation >> gain; + cerr << "head: " << heading << " elev: " << elevation << " gain: " << gain << endl; + AntennaGain datapoint; + datapoint.azimuth = heading; + datapoint.elevation = elevation; + datapoint.gain = gain; + _pattern.push_back(datapoint); + } + } diff --git a/src/Radio/antenna.hxx b/src/Radio/antenna.hxx index 3e6da2566..f0c3877d8 100644 --- a/src/Radio/antenna.hxx +++ b/src/Radio/antenna.hxx @@ -27,10 +27,12 @@ #include #include +using std::string; + class FGRadioAntenna { private: - void load_antenna_pattern(); + void load_antenna_pattern(string type); int _mirror_y; int _mirror_z; int _invert_ground; @@ -41,13 +43,13 @@ private: double elevation; double gain; }; - + SGPath _pattern_file; typedef std::vector AntennaPattern; AntennaPattern _pattern; public: - FGRadioAntenna(); + FGRadioAntenna(string type); ~FGRadioAntenna(); double calculate_gain(double azimuth, double elevation);