1
0
Fork 0

Move the new metar class from FlightGear to SimGear

This commit is contained in:
ehofman 2004-02-02 10:14:20 +00:00
parent e3a584ffd0
commit 7ffce3ac6a
5 changed files with 39 additions and 1405 deletions

View file

@ -7,16 +7,6 @@ noinst_LIBRARIES = libEnvironment.a
libEnvironment_a_SOURCES = \
environment.cxx environment.hxx \
environment_mgr.cxx environment_mgr.hxx \
environment_ctrl.cxx environment_ctrl.hxx \
metar.cxx metar.hxx
bin_PROGRAMS = metar
metar_SOURCES = metar-main.cxx metar.cxx metar.hxx
metar_LDADD = \
-lsgio -lsgbucket -lsgmisc -lsgstructure -lsgdebug \
-lplibnet -lplibul \
-lz $(base_LIBS)
environment_ctrl.cxx environment_ctrl.hxx
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src

File diff suppressed because it is too large Load diff

View file

@ -1,261 +0,0 @@
// metar interface class
//
// Written by Melchior FRANZ, started December 2003.
//
// Copyright (C) 2003 Melchior FRANZ - mfranz@aon.at
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
//
// $Id$
#ifndef _METAR_HXX
#define _METAR_HXX
#include <vector>
#include <map>
#include <string>
#include <simgear/constants.h>
SG_USING_STD(vector);
SG_USING_STD(map);
SG_USING_STD(string);
const double FGMetarNaN = -1E20;
#define NaN FGMetarNaN
struct Token {
char *id;
char *text;
};
class Metar;
class FGMetarVisibility {
friend class Metar;
public:
FGMetarVisibility() :
_distance(NaN),
_direction(-1),
_modifier(EQUALS),
_tendency(NONE) {}
enum Modifier {
NOGO,
EQUALS,
LESS_THAN,
GREATER_THAN
};
enum Tendency {
NONE,
STABLE,
INCREASING,
DECREASING
};
inline double getVisibility_m() const { return _distance; }
inline double getVisibility_ft() const { return _distance == NaN ? NaN : _distance * SG_METER_TO_FEET; }
inline double getVisibility_sm() const { return _distance == NaN ? NaN : _distance * SG_METER_TO_SM; }
inline int getDirection() const { return _direction; }
inline int getModifier() const { return _modifier; }
inline int getTendency() const { return _tendency; }
protected:
double _distance;
int _direction;
int _modifier;
int _tendency;
};
// runway condition (surface and visibility)
class FGMetarRunway {
friend class Metar;
public:
FGMetarRunway() :
_deposit(0),
_extent(-1),
_extent_string(0),
_depth(NaN),
_friction(NaN),
_friction_string(0),
_comment(0),
_wind_shear(false) {}
inline const char *getDeposit() const { return _deposit; }
inline double getExtent() const { return _extent; }
inline const char *getExtentString() const { return _extent_string; }
inline double getDepth() const { return _depth; }
inline double getFriction() const { return _friction; }
inline const char *getFrictionString() const { return _friction_string; }
inline const char *getComment() const { return _comment; }
inline const bool getWindShear() const { return _wind_shear; }
inline FGMetarVisibility getMinVisibility() const { return _min_visibility; }
inline FGMetarVisibility getMaxVisibility() const { return _max_visibility; }
protected:
FGMetarVisibility _min_visibility;
FGMetarVisibility _max_visibility;
const char *_deposit;
int _extent;
const char *_extent_string;
double _depth;
double _friction;
const char *_friction_string;
const char *_comment;
bool _wind_shear;
};
// cloud layer
class FGMetarCloud {
friend class Metar;
public:
FGMetarCloud() :
_coverage(-1),
_altitude(NaN),
_type(0),
_type_long(0) {}
inline int getCoverage() const { return _coverage; }
inline double getAltitude_m() const { return _altitude; }
inline double getAltitude_ft() const { return _altitude == NaN ? NaN : _altitude * SG_METER_TO_FEET; }
inline char *getTypeString() const { return _type; }
inline char *getTypeLongString() const { return _type_long; }
protected:
int _coverage; // quarters: 0 -> clear ... 4 -> overcast
double _altitude; // 1000 m
char *_type; // CU
char *_type_long; // cumulus
};
class Metar {
public:
Metar(const char *m);
Metar(const string m) { Metar(m.c_str()); }
~Metar();
enum ReportType {
NONE,
AUTO,
COR,
RTD
};
inline const char *getData() const { return _data; }
inline const char *getUnusedData() const { return _m; }
inline const char *getId() const { return _icao; }
inline int getYear() const { return _year; }
inline int getMonth() const { return _month; }
inline int getDay() const { return _day; }
inline int getHour() const { return _hour; }
inline int getMinute() const { return _minute; }
inline int getReportType() const { return _report_type; }
inline int getWindDir() const { return _wind_dir; }
inline double getWindSpeed_mps() const { return _wind_speed; }
inline double getWindSpeed_kmh() const { return _wind_speed == NaN ? NaN : _wind_speed * 3.6; }
inline double getWindSpeed_kt() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KT; }
inline double getWindSpeed_mph() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_MPH; }
inline double getGustSpeed_mps() const { return _gust_speed; }
inline double getGustSpeed_kmh() const { return _gust_speed == NaN ? NaN : _gust_speed * 3.6; }
inline double getGustSpeed_kt() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KT; }
inline double getGustSpeed_mph() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_MPH; }
inline int getWindRangeFrom() const { return _wind_range_from; }
inline int getWindRangeTo() const { return _wind_range_to; }
inline FGMetarVisibility& getMinVisibility() { return _min_visibility; }
inline FGMetarVisibility& getMaxVisibility() { return _max_visibility; }
inline FGMetarVisibility& getVertVisibility() { return _vert_visibility; }
inline FGMetarVisibility *getDirVisibility() { return _dir_visibility; }
inline double getTemperature_C() const { return _temp; }
inline double getTemperature_F() const { return _temp == NaN ? NaN : 1.8 * _temp + 32; }
inline double getDewpoint_C() const { return _dewp; }
inline double getDewpoint_F() const { return _dewp == NaN ? NaN : 1.8 * _dewp + 32; }
inline double getPressure_hPa() const { return _pressure == NaN ? NaN : _pressure / 100; }
inline double getPressure_inHg() const { return _pressure == NaN ? NaN : _pressure * SG_PA_TO_INHG; }
double getRelHumidity() const;
inline vector<FGMetarCloud>& getClouds() { return _clouds; }
inline map<string, FGMetarRunway>& getRunways() { return _runways; }
inline vector<string>& getWeather() { return _weather; }
protected:
int _grpcount;
char *_data;
char *_m;
char _icao[5];
int _year;
int _month;
int _day;
int _hour;
int _minute;
int _report_type;
int _wind_dir;
double _wind_speed;
double _gust_speed;
int _wind_range_from;
int _wind_range_to;
double _temp;
double _dewp;
double _pressure;
FGMetarVisibility _min_visibility;
FGMetarVisibility _max_visibility;
FGMetarVisibility _vert_visibility;
FGMetarVisibility _dir_visibility[8];
vector<FGMetarCloud> _clouds;
map<string, FGMetarRunway> _runways;
vector<string> _weather;
bool scanPreambleDate();
bool scanPreambleTime();
bool scanType();
bool scanId();
bool scanDate();
bool scanModifier();
bool scanWind();
bool scanVariability();
bool scanVisibility();
bool scanRwyVisRange();
bool scanSkyCondition();
bool scanWeather();
bool scanTemperature();
bool scanPressure();
bool scanRunwayReport();
bool scanWindShear();
bool scanTrendForecast();
bool scanColorState();
bool scanRemark();
bool scanRemainder();
int scanNumber(char **str, int *num, int min, int max = 0);
bool scanBoundary(char **str);
const struct Token *scanToken(char **str, const struct Token *list);
char *loadData(const char *id);
void normalizeData();
};
#undef NaN
#endif // _METAR_HXX

View file

@ -26,7 +26,7 @@ AM_CXXFLAGS = -DPKGLIBDIR=\"$(pkglibdir)\"
EXTRA_DIST = 3dfx.sh runfgfs.in runfgfs.bat.in
bin_PROGRAMS = fgfs
bin_PROGRAMS = fgfs metar
noinst_SCRIPTS = runfgfs.bat runfgfs
@ -95,4 +95,11 @@ fgfs_LDADD = \
$(opengl_LIBS) \
$(audio_LIBS)
metar_SOURCES = metar_main.cxx
metar_LDADD = \
-lsgenvironment -lsgio -lsgbucket -lsgmisc -lsgstructure -lsgdebug \
-lplibnet -lplibul \
-lz $(base_LIBS)
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src

View file

@ -25,8 +25,7 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
#include "metar.hxx"
#include <simgear/environment/metar.hxx>
using std::ostringstream;
@ -54,9 +53,9 @@ using std::ostringstream;
const char *azimuthName(double d);
double rnd(double number, int digits);
void printReport(Metar *m);
void printVisibility(FGMetarVisibility *v);
void printArgs(Metar *m, double airport_elevation);
void printReport(SGMetar *m);
void printVisibility(SGMetarVisibility *v);
void printArgs(SGMetar *m, double airport_elevation);
const char *azimuthName(double d)
@ -84,14 +83,14 @@ double rnd(double r, int g = 0)
}
ostream& operator<<(ostream& s, FGMetarVisibility& v)
ostream& operator<<(ostream& s, SGMetarVisibility& v)
{
ostringstream buf;
int m = v.getModifier();
const char *mod;
if (m == FGMetarVisibility::GREATER_THAN)
if (m == SGMetarVisibility::GREATER_THAN)
mod = ">=";
else if (m == FGMetarVisibility::LESS_THAN)
else if (m == SGMetarVisibility::LESS_THAN)
mod = "<";
else
mod = "";
@ -114,19 +113,19 @@ ostream& operator<<(ostream& s, FGMetarVisibility& v)
}
void printReport(Metar *m)
void printReport(SGMetar *m)
{
#define NaN FGMetarNaN
#define NaN SGMetarNaN
const char *s;
char buf[256];
double d;
int i, lineno;
if ((i = m->getReportType()) == Metar::AUTO)
if ((i = m->getReportType()) == SGMetar::AUTO)
s = "\t\t(automatically generated)";
else if (i == Metar::COR)
else if (i == SGMetar::COR)
s = "\t\t(manually corrected)";
else if (i == Metar::RTD)
else if (i == SGMetar::RTD)
s = "\t\t(routine delayed)";
else
s = "";
@ -147,8 +146,8 @@ void printReport(Metar *m)
// visibility
FGMetarVisibility minvis = m->getMinVisibility();
FGMetarVisibility maxvis = m->getMaxVisibility();
SGMetarVisibility minvis = m->getMinVisibility();
SGMetarVisibility maxvis = m->getMaxVisibility();
double min = minvis.getVisibility_m();
double max = maxvis.getVisibility_m();
if (min != NaN) {
@ -161,17 +160,17 @@ void printReport(Metar *m)
// directed visibility
FGMetarVisibility *dirvis = m->getDirVisibility();
SGMetarVisibility *dirvis = m->getDirVisibility();
for (i = 0; i < 8; i++, dirvis++)
if (dirvis->getVisibility_m() != NaN)
cout << "\t\t\t" << *dirvis << endl;
// vertical visibility
FGMetarVisibility vertvis = m->getVertVisibility();
SGMetarVisibility vertvis = m->getVertVisibility();
if ((d = vertvis.getVisibility_ft()) != NaN)
cout << "Vert. visibility:\t" << vertvis << endl;
else if (vertvis.getModifier() == FGMetarVisibility::NOGO)
else if (vertvis.getModifier() == SGMetarVisibility::NOGO)
cout << "Vert. visibility:\timpossible to determine" << endl;
@ -241,8 +240,8 @@ void printReport(Metar *m)
const char *coverage_string[5] = {
"clear skies", "few clouds", "scattered clouds", "broken clouds", "sky overcast"
};
vector<FGMetarCloud> cv = m->getClouds();
vector<FGMetarCloud>::iterator cloud;
vector<SGMetarCloud> cv = m->getClouds();
vector<SGMetarCloud>::iterator cloud;
for (lineno = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, lineno++) {
cout << (lineno ? "\t\t\t" : "Sky condition:\t\t");
@ -259,15 +258,15 @@ void printReport(Metar *m)
// runways
map<string, FGMetarRunway> rm = m->getRunways();
map<string, FGMetarRunway>::iterator runway;
map<string, SGMetarRunway> rm = m->getRunways();
map<string, SGMetarRunway>::iterator runway;
for (runway = rm.begin(); runway != rm.end(); runway++) {
lineno = 0;
if (!strcmp(runway->first.c_str(), "ALL"))
cout << "All runways:\t\t";
else
cout << "Runway " << runway->first << ":\t\t";
FGMetarRunway rwy = runway->second;
SGMetarRunway rwy = runway->second;
// assemble surface string
vector<string> surface;
@ -297,8 +296,8 @@ void printReport(Metar *m)
}
// assemble visibility string
FGMetarVisibility minvis = rwy.getMinVisibility();
FGMetarVisibility maxvis = rwy.getMaxVisibility();
SGMetarVisibility minvis = rwy.getMinVisibility();
SGMetarVisibility maxvis = rwy.getMaxVisibility();
if ((d = minvis.getVisibility_m()) != NaN) {
if (lineno++)
cout << endl << "\t\t\t";
@ -321,9 +320,9 @@ void printReport(Metar *m)
}
void printArgs(Metar *m, double airport_elevation)
void printArgs(SGMetar *m, double airport_elevation)
{
#define NaN FGMetarNaN
#define NaN SGMetarNaN
vector<string> args;
char buf[256];
int i;
@ -342,8 +341,8 @@ void printArgs(Metar *m, double airport_elevation)
const char *coverage_string[5] = {
"clear", "few", "scattered", "broken", "overcast"
};
vector<FGMetarCloud> cv = m->getClouds();
vector<FGMetarCloud>::iterator cloud;
vector<SGMetarCloud> cv = m->getClouds();
vector<SGMetarCloud>::iterator cloud;
for (i = 0, cloud = cv.begin(); i < 5; i++) {
int coverage = 0;
double altitude = -99999;
@ -460,8 +459,8 @@ int main(int argc, char *argv[])
const char *icao = src[i];
try {
Metar *m = new Metar(icao);
//Metar *m = new Metar("2004/01/11 01:20\nLOWG 110120Z AUTO VRB01KT 0050 1600N R35/0600 FG M06/M06 Q1019 88//////\n");
SGMetar *m = new SGMetar(icao);
//SGMetar *m = new SGMetar("2004/01/11 01:20\nLOWG 110120Z AUTO VRB01KT 0050 1600N R35/0600 FG M06/M06 Q1019 88//////\n");
printf(G"INPUT: %s\n"N, m->getData());
const char *unused = m->getUnusedData();