Move GFS weather data url into global setup

Summary:
The GFS weather data url so far was hard coded. With this commit, it is
moved into the global setup (bootstrap file).
Also the url type was changed from QUrl to CUrl, which simplified the
generation of the url including its query by using CUrl::appendQuery().
Finally it fixes sampleweatherdata, which did not have a CApplication yet.

Reviewers: #swift_pilot_client, msutcliffe

Reviewed By: #swift_pilot_client, msutcliffe

Subscribers: jenkins

Tags: #swift_pilot_client

Maniphest Tasks: T151

Differential Revision: https://dev.swift-project.org/D57
This commit is contained in:
Roland Winklmeier
2017-10-25 16:08:33 +02:00
parent 4001fad023
commit c553d24d0e
7 changed files with 30 additions and 19 deletions

View File

@@ -24,6 +24,7 @@ using namespace BlackMisc::Geo;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Weather;
using namespace BlackMisc::Math;
using namespace BlackMisc::Network;
namespace BlackWxPlugin
{
@@ -71,7 +72,7 @@ namespace BlackWxPlugin
return;
}
const QUrl url = getDownloadUrl();
const QUrl url = getDownloadUrl().toQUrl();
CLogMessage(this).debug() << "Started to download GFS data from" << url.toString();
QNetworkRequest request(url);
sApp->getFromNetwork(request, { this, &CWeatherDataGfs::ps_parseGfsFile });
@@ -114,9 +115,9 @@ namespace BlackWxPlugin
m_parseGribFileWorker->then(this, &CWeatherDataGfs::ps_fetchingWeatherDataFinished);
}
QUrl CWeatherDataGfs::getDownloadUrl() const
CUrl CWeatherDataGfs::getDownloadUrl() const
{
QString baseurl = "http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p50.pl?";
CUrl downloadUrl = sApp->getGlobalSetup().getNcepGlobalForecastSystemUrl();
static const QStringList grib2Levels =
{
@@ -183,24 +184,21 @@ namespace BlackWxPlugin
directory = directory.arg(cnow.toString("yyyyMMdd"));
directory = directory.arg(hourLastPublishedCycle, 2, 10, QLatin1Char('0'));
QStringList params;
params.reserve(grib2Levels.size() + grib2Variables.size() + 6);
params.append("file=" + filename);
downloadUrl.appendQuery("file", filename);
for (const auto &level : grib2Levels)
{
params.append("lev_" + level + "=on");
downloadUrl.appendQuery("lev_" + level, "on");
}
for (const auto &variable : grib2Variables)
{
params.append("var_" + variable + "=on");
downloadUrl.appendQuery("var_" + variable, "on");
}
params.append("leftlon=0");
params.append("rightlon=360");
params.append("toplat=90");
params.append("bottomlat=-90");
params.append("dir=%2F" + directory);
return QUrl(baseurl + params.join('&'));
downloadUrl.appendQuery("leftlon", "0");
downloadUrl.appendQuery("rightlon", "360");
downloadUrl.appendQuery("toplat", "90");
downloadUrl.appendQuery("bottomlat", "-90");
downloadUrl.appendQuery("dir", "%2F" + directory);
return downloadUrl;
}
void CWeatherDataGfs::parseGfsFileImpl(const QByteArray &gribData)

View File

@@ -13,6 +13,7 @@
#define BLACKWXPLUGIN_GFS_H
#include "g2clib/grib2.h"
#include "blackmisc/network/url.h"
#include "blackmisc/weather/gridpoint.h"
#include "blackmisc/worker.h"
#include "blackcore/weatherdata.h"
@@ -136,7 +137,7 @@ namespace BlackWxPlugin
double surfaceTemperature = 0;
};
QUrl getDownloadUrl() const;
BlackMisc::Network::CUrl getDownloadUrl() const;
void parseGfsFileImpl(const QByteArray &gribData);
void findNextGribMessage(unsigned char *buffer, g2int size, g2int iseek, g2int *lskip, g2int *lgrib);