diff --git a/installer/installbuilder/swift-plugin-weatherdata.xml b/installer/installbuilder/swift-plugin-weatherdata.xml deleted file mode 100644 index e59340ad5..000000000 --- a/installer/installbuilder/swift-plugin-weatherdata.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - weatherdata - WeatherData Plugins - 1 - 1 - 1 - - - weatherdatagfs - GFS WeatherData - 1 - WeatherData fetched from NCEP Global Forecast System in 0.5 degrees worldwide - 1 - 1 - - - bin/plugins/weatherdata - ${installdir}/bin/plugins/weatherdata - bin_plugins_simulator - all - - - 1 - ../../dist/bin/plugins/weatherdata/*weatherdatagfs* - */*.pdb;*/*.debug;*/*.dSYM - - - - - - - diff --git a/installer/installbuilder/swift.xml b/installer/installbuilder/swift.xml index 29b16247d..e44825132 100644 --- a/installer/installbuilder/swift.xml +++ b/installer/installbuilder/swift.xml @@ -16,9 +16,6 @@ swift-plugin-simulators.xml - - swift-plugin-weatherdata.xml - swift-externals.xml diff --git a/resources/share/shared/bootstrap/bootstrap.json b/resources/share/shared/bootstrap/bootstrap.json index d8842c61d..2e37cd48d 100644 --- a/resources/share/shared/bootstrap/bootstrap.json +++ b/resources/share/shared/bootstrap/bootstrap.json @@ -5,9 +5,6 @@ "url": "https://datastore.swift-project.org/" }, "mappingMinimumVersion": "0.9.0", - "ncepGlobalForecastSystemUrl25": { - "url": "http://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25.pl" - }, "onlineHelpUrl": { "url": "https://datastore.swift-project.org/page/swifthelpdispatcher.html" }, diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 204830771..123a005a8 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -8,4 +8,3 @@ add_subdirectory(blackmiscquantities) add_subdirectory(blackmiscsim) add_subdirectory(fsd) add_subdirectory(hotkey) -add_subdirectory(weatherdata) diff --git a/samples/weatherdata/CMakeLists.txt b/samples/weatherdata/CMakeLists.txt deleted file mode 100644 index c8ceced1d..000000000 --- a/samples/weatherdata/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-FileCopyrightText: Copyright (C) swift Project Community / Contributors -# SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -add_executable(samples_weatherdata - main.cpp - reader.cpp - reader.h - sampleweatherdata.h - weatherdataprinter.cpp - weatherdataprinter.h - ) -target_link_libraries(samples_weatherdata core misc Qt::Core) diff --git a/samples/weatherdata/main.cpp b/samples/weatherdata/main.cpp deleted file mode 100644 index 772d92a0f..000000000 --- a/samples/weatherdata/main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file -//! \ingroup sampleweatherdata - -#include "blackcore/application.h" -#include "blackmisc/directoryutils.h" -#include "blackmisc/loghandler.h" -#include "blackmisc/registermetadata.h" -#include "reader.h" -#include "weatherdataprinter.h" - -#include -#include -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackCore; - -//! main -int main(int argc, char *argv[]) -{ - QCoreApplication qa(argc, argv); - CApplication a(CApplicationInfo::Sample); - BlackMisc::registerMetadata(); - CLogHandler::instance()->install(true); - CLogHandler::instance()->enableConsoleOutput(false); // default disable - - CLineReader lineReader(&a); - CWeatherDataPrinter printer(&a); - QObject::connect(&lineReader, &CLineReader::weatherDataRequest, &printer, &CWeatherDataPrinter::fetchAndPrintWeatherData); - QObject::connect(&lineReader, &CLineReader::wantsToQuit, &lineReader, &CLineReader::terminate); - QObject::connect(&lineReader, &CLineReader::finished, &a, &QCoreApplication::quit); - - QTextStream qtout(stdout); - qtout << "Usage: " << Qt::endl; - qtout << "Example: 48.5 11.5" << Qt::endl; - qtout << "Type x to quit" << Qt::endl; - - lineReader.start(); - return a.exec(); -} diff --git a/samples/weatherdata/reader.cpp b/samples/weatherdata/reader.cpp deleted file mode 100644 index 52bfbc99b..000000000 --- a/samples/weatherdata/reader.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file -//! \ingroup sampleweatherdata - -#include "reader.h" -#include "blackmisc/geo/latitude.h" -#include "blackmisc/geo/longitude.h" -#include "blackmisc/pq/units.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace BlackMisc::Geo; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::PhysicalQuantities; - -void CLineReader::run() -{ - QFile file; - file.open(stdin, QIODevice::ReadOnly | QIODevice::Text); - - forever - { - QString line = file.readLine().simplified(); - - if (line == "x") - { - emit wantsToQuit(); - continue; - } - - const QStringList parts = line.split(' '); - if (parts.size() == 2) - { - const CLatitude latitude(CAngle::parsedFromString(parts.front(), CPqString::SeparatorBestGuess, CAngleUnit::deg())); - const CLongitude longitude(CAngle::parsedFromString(parts.back(), CPqString::SeparatorBestGuess, CAngleUnit::deg())); - const CAltitude alt(600, CLengthUnit::m()); - - const CCoordinateGeodetic position { latitude, longitude, alt }; - emit weatherDataRequest(position); - } - else - { - QTextStream qtout(stdout); - qtout << "Invalid command." << Qt::endl; - qtout << "Usage: " << Qt::endl; - } - } -} diff --git a/samples/weatherdata/reader.h b/samples/weatherdata/reader.h deleted file mode 100644 index 5cb2fb344..000000000 --- a/samples/weatherdata/reader.h +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#ifndef BLACKSAMPLE_WEATHERDATA_LINEREADER_H -#define BLACKSAMPLE_WEATHERDATA_LINEREADER_H - -//! \file -//! \ingroup sampleweatherdata - -#include "blackmisc/geo/coordinategeodetic.h" - -#include -#include - -/*! - * Class reading line input and triggering commands - */ -class CLineReader : public QThread -{ - Q_OBJECT - -public: - //! Constructor - CLineReader(QObject *parent = nullptr) : QThread(parent) {} - -protected: - //! \copydoc QThread::run - virtual void run() override; - -signals: - //! User is asking for weather data - void weatherDataRequest(const BlackMisc::Geo::CCoordinateGeodetic &position); - - //! User is asking to quit - void wantsToQuit(); -}; - -#endif // guard diff --git a/samples/weatherdata/sampleweatherdata.h b/samples/weatherdata/sampleweatherdata.h deleted file mode 100644 index 025045e30..000000000 --- a/samples/weatherdata/sampleweatherdata.h +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#ifndef BLACKSAMPLE_WEATHERDATA_H -#define BLACKSAMPLE_WEATHERDATA_H - -//! \file -//! \ingroup sampleweatherdata - -// just a dummy header, documentation will go here - -/*! - * \defgroup sampleweatherdata Sample Weather Data - * \ingroup samples - * \brief Sample demonstrating how to download and use weather data - * through the IWeatherData plugins. - * - * After startup it will accept input by latitude and longitude - * and print the current weather status received from all installed - * and loaded weather plugins. - */ - -#endif diff --git a/samples/weatherdata/weatherdataprinter.cpp b/samples/weatherdata/weatherdataprinter.cpp deleted file mode 100644 index 75c8ebbfd..000000000 --- a/samples/weatherdata/weatherdataprinter.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file -//! \ingroup sampleweatherdata - -#include "weatherdataprinter.h" -#include "blackmisc/logmessage.h" -#include - -#include "weatherdataprinter.h" -#include "blackmisc/aviation/altitude.h" -#include "blackmisc/geo/latitude.h" -#include "blackmisc/geo/longitude.h" -#include "blackmisc/pq/angle.h" -#include "blackmisc/pq/physicalquantity.h" -#include "blackmisc/pq/pressure.h" -#include "blackmisc/pq/speed.h" -#include "blackmisc/pq/temperature.h" -#include "blackmisc/range.h" -#include "blackmisc/sequence.h" -#include "blackmisc/weather/cloudlayer.h" -#include "blackmisc/weather/cloudlayerlist.h" -#include "blackmisc/weather/gridpoint.h" -#include "blackmisc/weather/temperaturelayer.h" -#include "blackmisc/weather/temperaturelayerlist.h" -#include "blackmisc/weather/windlayer.h" -#include "blackmisc/weather/windlayerlist.h" - -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::Weather; -using namespace BlackMisc::Geo; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackCore; - -CWeatherDataPrinter::CWeatherDataPrinter(QObject *parent) : QObject(parent) -{} - -void CWeatherDataPrinter::fetchAndPrintWeatherData(const CCoordinateGeodetic &position) -{ - QTextStream qtout(stdout); - qtout << "Position:" << position.toQString(true) << Qt::endl; - qtout << "Fetching weather data. This may take a while..." << Qt::endl; - - const CWeatherGrid weatherGrid { { "", position } }; - m_weatherManger.requestWeatherGrid(weatherGrid, { this, &CWeatherDataPrinter::printWeatherData }); -} - -void CWeatherDataPrinter::printWeatherData(const CWeatherGrid &weatherGrid) -{ - QTextStream qtout(stdout); - qtout << "... finished." << Qt::endl; - qtout << weatherGrid.getDescription(); - qtout << Qt::endl; -} diff --git a/samples/weatherdata/weatherdataprinter.h b/samples/weatherdata/weatherdataprinter.h deleted file mode 100644 index 756e08cb4..000000000 --- a/samples/weatherdata/weatherdataprinter.h +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#ifndef BLACKSAMPLE_WEATERDATA_WEATHERDATAPRINTER_H -#define BLACKSAMPLE_WEATERDATA_WEATHERDATAPRINTER_H - -//! \file -//! \ingroup sampleweatherdata - -#include "blackcore/weathermanager.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/weather/weathergrid.h" - -#include - -/*! - * CWeatherDataPrinter fetches and prints weather data - */ -class CWeatherDataPrinter : public QObject -{ - Q_OBJECT - -public: - //! Constructor - CWeatherDataPrinter(QObject *parent = nullptr); - - //! Fetch new weather data for given position and print it once received - void fetchAndPrintWeatherData(const BlackMisc::Geo::CCoordinateGeodetic &position); - -private: - //! Print weather data to stdout - void printWeatherData(const BlackMisc::Weather::CWeatherGrid &weatherGrid); - - BlackCore::CWeatherManager m_weatherManger { this }; -}; - -#endif // guard diff --git a/scripts/build.py b/scripts/build.py index 58fbba1b9..4c81322c4 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -312,7 +312,6 @@ class LinuxBuilder(Builder): "bin/plugins/simulator/libsimulatorflightgearconfig.so", "bin/plugins/simulator/libsimulatorxplane.so", "bin/plugins/simulator/libsimulatorxplaneconfig.so", - "bin/plugins/weatherdata/libweatherdatagfs.so", "xswiftbus/64/lin.xpl", ] dist_path = path.join(utils.get_swift_source_path(), "dist") @@ -358,7 +357,6 @@ class MacOSBuilder(Builder): "bin/plugins/simulator/libsimulatorflightgearconfig.dylib", "bin/plugins/simulator/libsimulatorxplane.dylib", "bin/plugins/simulator/libsimulatorxplaneconfig.dylib", - "bin/plugins/weatherdata/libweatherdatagfs.dylib", "xswiftbus/64/mac.xpl", ] dist_path = path.join(utils.get_swift_source_path(), "dist") diff --git a/src/blackcore/CMakeLists.txt b/src/blackcore/CMakeLists.txt index 25e922f19..b99795662 100644 --- a/src/blackcore/CMakeLists.txt +++ b/src/blackcore/CMakeLists.txt @@ -228,8 +228,6 @@ add_library(core SHARED pluginmanager.h pluginmanagersimulator.cpp pluginmanagersimulator.h - pluginmanagerweatherdata.cpp - pluginmanagerweatherdata.h progress.h registermetadata.cpp registermetadata.h @@ -239,9 +237,6 @@ add_library(core SHARED simulator.h threadedreader.cpp threadedreader.h - weatherdata.h - weathermanager.cpp - weathermanager.h webdataservices.cpp webdataservices.h webdataservicesms.cpp diff --git a/src/blackcore/context/contextsimulator.h b/src/blackcore/context/contextsimulator.h index e8c156062..46e9b4c21 100644 --- a/src/blackcore/context/contextsimulator.h +++ b/src/blackcore/context/contextsimulator.h @@ -11,7 +11,6 @@ #include "blackcore/corefacadeconfig.h" #include "blackcore/simulator.h" #include "blackcore/blackcoreexport.h" -#include "blackmisc/weather/weathergrid.h" #include "blackmisc/simulation/settings/simulatorsettings.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/aircraftmatchersetup.h" @@ -134,9 +133,6 @@ namespace BlackCore::Context //! An airspace snapshot was handled void airspaceSnapshotHandled(); - //! A weather grid, requested with requestWeatherGrid(), is received - void weatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); - //! Relevant simulator messages to be explicitly displayed void driverMessages(const BlackMisc::CStatusMessageList &messages); @@ -285,15 +281,6 @@ namespace BlackCore::Context //! Reset model by matching it again virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) = 0; - //! Is simulator weather activated or deactivated? - virtual bool isWeatherActivated() const = 0; - - //! Activates or deactivates simulator weather - virtual void setWeatherActivated(bool activated) = 0; - - //! Request weather grid. Argument identifier is past in the signal to identify the requestor - virtual void requestWeatherGrid(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::CIdentifier &identifier) = 0; - //! \copydoc BlackMisc::Simulation::ISimulationEnvironmentProvider::requestElevationBySituation virtual bool requestElevationBySituation(const BlackMisc::Aviation::CAircraftSituation &situation) = 0; diff --git a/src/blackcore/context/contextsimulatorempty.h b/src/blackcore/context/contextsimulatorempty.h index ce1cdb46b..d5e74ee21 100644 --- a/src/blackcore/context/contextsimulatorempty.h +++ b/src/blackcore/context/contextsimulatorempty.h @@ -325,29 +325,7 @@ namespace BlackCore::Context return false; } - //! \copydoc IContextSimulator::isWeatherActivated - virtual bool isWeatherActivated() const override - { - logEmptyContextWarning(Q_FUNC_INFO); - return false; - } - - //! \copydoc IContextSimulator::setWeatherActivated - virtual void setWeatherActivated(bool activated) override - { - Q_UNUSED(activated) - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextSimulator::requestWeatherGrid - virtual void requestWeatherGrid(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::CIdentifier &identifier) override - { - Q_UNUSED(position) - Q_UNUSED(identifier) - logEmptyContextWarning(Q_FUNC_INFO); - } - - //! \copydoc IContextSimulator::requestWeatherGrid + //! \copydoc IContextSimulator::requestElevationBySituation virtual bool requestElevationBySituation(const BlackMisc::Aviation::CAircraftSituation &situation) override { Q_UNUSED(situation) diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index 2d0bc4bfd..b4604cc7d 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -65,7 +65,6 @@ namespace BlackCore::Context m_plugins->collectPlugins(); this->restoreSimulatorPlugins(); - connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::onWeatherGridReceived, Qt::QueuedConnection); connect(&m_aircraftMatcher, &CAircraftMatcher::setupChanged, this, &CContextSimulator::matchingSetupChanged); connect(&CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance(), &CCentralMultiSimulatorModelSetCachesProvider::cacheChanged, this, &CContextSimulator::modelSetChanged); @@ -470,7 +469,7 @@ namespace BlackCore::Context IOwnAircraftProvider *ownAircraftProvider = this->getRuntime()->getCContextOwnAircraft(); IRemoteAircraftProvider *renderedAircraftProvider = this->getRuntime()->getCContextNetwork(); IClientProvider *clientProvider = this->getRuntime()->getCContextNetwork(); - ISimulator *simulator = factory->create(simulatorPluginInfo, ownAircraftProvider, renderedAircraftProvider, &m_weatherManager, clientProvider); + ISimulator *simulator = factory->create(simulatorPluginInfo, ownAircraftProvider, renderedAircraftProvider, clientProvider); Q_ASSERT_X(simulator, Q_FUNC_INFO, "no simulator driver can be created"); this->setRemoteAircraftProvider(renderedAircraftProvider); @@ -543,8 +542,6 @@ namespace BlackCore::Context return false; } - simulator->setWeatherActivated(m_isWeatherActivated); - // when everything is set up connected, update the current plugin info m_simulatorPlugin.first = simulatorPluginInfo; m_simulatorPlugin.second = simulator; @@ -560,9 +557,6 @@ namespace BlackCore::Context << simulatorPluginInfo.toQString(true) << boolToYesNo(connected); - // weather in sim. - this->setWeatherActivated(m_isWeatherActivated); - // use the real driver as this will also work eith emulated driver emit this->simulatorPluginChanged(m_simulatorPlugin.second->getSimulatorPluginInfo()); emit this->simulatorChanged(m_simulatorPlugin.second->getSimulatorInfo()); @@ -864,24 +858,6 @@ namespace BlackCore::Context emit this->addingRemoteModelFailed(remoteAircraft, disabled, failover, message); } - void CContextSimulator::onWeatherGridReceived(const CWeatherGrid &weatherGrid, const CIdentifier &identifier) - { - if (!sApp || sApp->isShuttingDown()) { return; } - emit this->weatherGridReceived(weatherGrid, identifier); - - if (!this->isSimulatorPluginAvailable()) { return; } - if (!m_simulatorPlugin.second) { return; } - - if (m_simulatorPlugin.second && m_simulatorPlugin.second->identifier() == identifier) - { - // ONLY send if WEATHER is ON - if (m_simulatorPlugin.second->isWeatherActivated()) - { - m_simulatorPlugin.second->injectWeatherGrid(weatherGrid); - } - } - } - void CContextSimulator::xCtxUpdateSimulatorCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator) { if (!this->isSimulatorAvailable()) { return; } @@ -1095,26 +1071,6 @@ namespace BlackCore::Context return true; } - bool CContextSimulator::isWeatherActivated() const - { - if (isDebugEnabled()) { CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO; } - if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) { return m_isWeatherActivated; } - return m_simulatorPlugin.second->isWeatherActivated(); - } - - void CContextSimulator::setWeatherActivated(bool activated) - { - if (isDebugEnabled()) { CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO; } - if (!m_simulatorPlugin.second || m_simulatorPlugin.first.isUnspecified()) { return; } - m_simulatorPlugin.second->setWeatherActivated(activated); - } - - void CContextSimulator::requestWeatherGrid(const CCoordinateGeodetic &position, const CIdentifier &identifier) - { - if (isDebugEnabled()) { CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO << identifier; } - m_weatherManager.requestWeatherGrid(position, identifier); - } - bool CContextSimulator::requestElevationBySituation(const CAircraftSituation &situation) { if (isDebugEnabled()) { CLogMessage(this, CLogCategories::contextSlot()).debug() << Q_FUNC_INFO << situation; } diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 93668244a..d38000d18 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -12,7 +12,6 @@ #include "blackcore/corefacadeconfig.h" #include "blackcore/aircraftmatcher.h" #include "blackcore/blackcoreexport.h" -#include "blackcore/weathermanager.h" #include "blackmisc/network/connectionstatus.h" #include "blackmisc/simulation/data/modelcaches.h" #include "blackmisc/simulation/settings/modelmatchersettings.h" @@ -186,15 +185,6 @@ namespace BlackCore //! \copydoc BlackCore::Context::IContextSimulator::resetToModelMatchingAircraft virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; - //! \copydoc BlackCore::Context::IContextSimulator::isWeatherActivated - virtual bool isWeatherActivated() const override; - - //! \copydoc BlackCore::Context::IContextSimulator::setWeatherActivated - virtual void setWeatherActivated(bool activated) override; - - //! \copydoc BlackCore::Context::IContextSimulator::requestWeatherGrid - virtual void requestWeatherGrid(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::CIdentifier &identifier) override; - //! \copydoc BlackCore::Context::IContextSimulator::requestElevationBySituation virtual bool requestElevationBySituation(const BlackMisc::Aviation::CAircraftSituation &situation) override; @@ -340,9 +330,6 @@ namespace BlackCore //! Failed adding remote aircraft void onAddingRemoteAircraftFailed(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, bool disabled, bool requestFailover, const BlackMisc::CStatusMessage &message); - //! Weather request was received - void onWeatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); - //! Relay status message to simulator under consideration of settings void relayStatusMessageToSimulator(const BlackMisc::CStatusMessage &message); @@ -387,12 +374,10 @@ namespace BlackCore QMap m_failoverAddingCounts; CPluginManagerSimulator *m_plugins = nullptr; //!< plugin manager BlackMisc::CRegularThread m_listenersThread; //!< waiting for plugin - CWeatherManager m_weatherManager { this }; //!< weather management CAircraftMatcher m_aircraftMatcher { this }; //!< model matcher bool m_wasSimulating = false; bool m_initallyAddAircraft = false; - bool m_isWeatherActivated = false; // used to activate after plugin is loaded BlackMisc::Simulation::MatchingLog m_logMatchingMessages = BlackMisc::Simulation::MatchingLogSimplified; QString m_networkSessionId; //!< Network session of CServer::getServerSessionId, if not connected empty (for statistics, ..) diff --git a/src/blackcore/context/contextsimulatorproxy.cpp b/src/blackcore/context/contextsimulatorproxy.cpp index 6f1f4bec5..6c788bd47 100644 --- a/src/blackcore/context/contextsimulatorproxy.cpp +++ b/src/blackcore/context/contextsimulatorproxy.cpp @@ -84,9 +84,6 @@ namespace BlackCore::Context s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "airspaceSnapshotHandled", this, SIGNAL(airspaceSnapshotHandled())); Q_ASSERT(s); - s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), - "weatherGridReceived", this, SIGNAL(weatherGridReceived(BlackMisc::Weather::CWeatherGrid, BlackMisc::CIdentifier))); - Q_ASSERT(s); s = connection.connect(serviceName, IContextSimulator::ObjectPath(), IContextSimulator::InterfaceName(), "driverMessages", this, SIGNAL(driverMessages(BlackMisc::CStatusMessageList))); @@ -296,21 +293,6 @@ namespace BlackCore::Context return m_dBusInterface->callDBusRet(QLatin1String("resetToModelMatchingAircraft"), callsign); } - bool CContextSimulatorProxy::isWeatherActivated() const - { - return m_dBusInterface->callDBusRet(QLatin1String("isWeatherActivated")); - } - - void CContextSimulatorProxy::setWeatherActivated(bool activated) - { - m_dBusInterface->callDBus(QLatin1String("setWeatherActivated"), activated); - } - - void CContextSimulatorProxy::requestWeatherGrid(const CCoordinateGeodetic &position, const CIdentifier &identifier) - { - m_dBusInterface->callDBus(QLatin1String("requestWeatherGrid"), position, identifier); - } - bool CContextSimulatorProxy::requestElevationBySituation(const CAircraftSituation &situation) { return m_dBusInterface->callDBusRet(QLatin1String("requestElevationBySituation"), situation); diff --git a/src/blackcore/context/contextsimulatorproxy.h b/src/blackcore/context/contextsimulatorproxy.h index 8504e5c10..ed13ebe43 100644 --- a/src/blackcore/context/contextsimulatorproxy.h +++ b/src/blackcore/context/contextsimulatorproxy.h @@ -174,15 +174,6 @@ namespace BlackCore //! \copydoc BlackCore::Context::IContextSimulator::resetToModelMatchingAircraft virtual bool resetToModelMatchingAircraft(const BlackMisc::Aviation::CCallsign &callsign) override; - //! \copydoc BlackCore::Context::IContextSimulator::isWeatherActivated - virtual bool isWeatherActivated() const override; - - //! \copydoc BlackCore::Context::IContextSimulator::setWeatherActivated - virtual void setWeatherActivated(bool activated) override; - - //! \copydoc BlackCore::Context::IContextSimulator::requestWeatherGrid - virtual void requestWeatherGrid(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::CIdentifier &identifier) override; - //! \copydoc BlackCore::Context::IContextSimulator::requestElevationBySituation virtual bool requestElevationBySituation(const BlackMisc::Aviation::CAircraftSituation &situation) override; diff --git a/src/blackcore/data/globalsetup.h b/src/blackcore/data/globalsetup.h index c29c48aa2..89bc1f03c 100644 --- a/src/blackcore/data/globalsetup.h +++ b/src/blackcore/data/globalsetup.h @@ -127,9 +127,6 @@ namespace BlackCore::Data //! \remark only valid if wasLoaded() is \c true bool isSwiftVersionMinimumMappingVersion() const; - //! NCEP GFS Forecasts (0.25 degree grid) data url - BlackMisc::Network::CUrl getNcepGlobalForecastSystemUrl25() const { return m_ncepGlobalForecastSystemUrl25; } - //! COM/NAV equipment code help URL BlackMisc::Network::CUrl getComNavEquipmentHelpUrl() const { return m_comNavEquipmentHelpUrl; } @@ -175,7 +172,6 @@ namespace BlackCore::Data BlackMisc::Network::CUrl m_sharedUrl; //!< where we can obtain shared info files such as bootstrap, .. BlackMisc::Network::CUrl m_onlineHelpUrl; //!< online help URL BlackMisc::Network::CServerList m_predefinedServers; //!< Predefined servers loaded from setup file - BlackMisc::Network::CUrl m_ncepGlobalForecastSystemUrl25; //!< NCEP GFS url 0.25 degree resolution BlackMisc::Network::CUrl m_comNavEquipmentHelpUrl; //!< Help URL for COM/NAV equipment codes BlackMisc::Network::CUrl m_ssrEquipmentHelpUrl; //!< Help URL for SSR equipment codes BlackMisc::Network::CUrl m_afvApiServerUrl; //!< AFV API server URL @@ -196,7 +192,6 @@ namespace BlackCore::Data BLACK_METAMEMBER(onlineHelpUrl, 0, RequiredForJson), BLACK_METAMEMBER(predefinedServers, 0, RequiredForJson), BLACK_METAMEMBER(mappingMinimumVersion, 0, RequiredForJson), - BLACK_METAMEMBER(ncepGlobalForecastSystemUrl25, 0, RequiredForJson), BLACK_METAMEMBER(comNavEquipmentHelpUrl, 0, RequiredForJson), BLACK_METAMEMBER(ssrEquipmentHelpUrl, 0, RequiredForJson), BLACK_METAMEMBER(dbDebugFlag, 0, RequiredForJson), diff --git a/src/blackcore/pluginmanagerweatherdata.cpp b/src/blackcore/pluginmanagerweatherdata.cpp deleted file mode 100644 index f6775a056..000000000 --- a/src/blackcore/pluginmanagerweatherdata.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackcore/application.h" -#include "blackcore/pluginmanagerweatherdata.h" -#include "blackcore/weatherdata.h" -#include "blackmisc/swiftdirectories.h" -#include "blackmisc/directoryutils.h" - -#include -#include -#include - -namespace BlackCore -{ - using namespace BlackMisc; - using namespace BlackMisc::Weather; - - CPluginManagerWeatherData::CPluginManagerWeatherData(QObject *parent) : IPluginManager(parent) - {} - - IWeatherDataFactory *CPluginManagerWeatherData::getFactory(const QString &pluginId) - { - return getPluginById(pluginId); - } - - Weather::CWeatherDataPluginInfoList CPluginManagerWeatherData::getAvailableWeatherDataPlugins() const - { - CWeatherDataPluginInfoList list; - for (const auto &i : m_plugins) - { - list.push_back(i.info); - } - return list; - } - - void CPluginManagerWeatherData::collectPlugins() - { - IPluginManager::collectPlugins(); - - const CSequence &plugins = getPlugins(); - for (const QJsonObject &json : plugins) - { - QString iid = json["IID"].toString(); - if (iid == QStringLiteral("org.swift-project.blackcore.weatherdata")) - { - auto it = m_plugins.insert(pluginIdentifier(json), {}); - it->info.convertFromJson(json); - } - } - } - - BlackMisc::CSequence CPluginManagerWeatherData::acceptedIids() const - { - return { - QStringLiteral("org.swift-project.blackcore.weatherdata") - }; - } - - const QString &CPluginManagerWeatherData::pluginDirectory() const - { - static const QString d(CFileUtils::appendFilePaths(CSwiftDirectories::pluginsDirectory(), "weatherdata")); - return d; - } -} diff --git a/src/blackcore/pluginmanagerweatherdata.h b/src/blackcore/pluginmanagerweatherdata.h deleted file mode 100644 index f189cdd55..000000000 --- a/src/blackcore/pluginmanagerweatherdata.h +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKCORE_PLUGINMANAGERWEATHERDATA_H -#define BLACKCORE_PLUGINMANAGERWEATHERDATA_H - -#include "blackcore/blackcoreexport.h" -#include "blackcore/pluginmanager.h" -#include "blackmisc/sequence.h" -#include "blackmisc/weather/weatherdataplugininfo.h" -#include "blackmisc/weather/weatherdataplugininfolist.h" - -#include -#include -#include -#include - -namespace BlackMisc -{ - class CVariant; -} -namespace BlackCore -{ - class IWeatherDataFactory; - - /*! - * Manages plugins of type WeatherData. - */ - class BLACKCORE_EXPORT CPluginManagerWeatherData : - public BlackCore::IPluginManager - { - Q_OBJECT - - public: - //! Ctor - CPluginManagerWeatherData(QObject *parent = nullptr); - - //! Get weatherdata factory from the plugin - IWeatherDataFactory *getFactory(const QString &pluginId); - - //! Get all weather data plugins - BlackMisc::Weather::CWeatherDataPluginInfoList getAvailableWeatherDataPlugins() const; - - //! \copydoc BlackCore::IPluginManager::collectPlugins() - virtual void collectPlugins() override; - - protected: - //! \copydoc BlackCore::IPluginManager::acceptedIids() - virtual BlackMisc::CSequence acceptedIids() const override; - - //! \copydoc BlackCore::IPluginManager::pluginDirectory() - virtual const QString &pluginDirectory() const override; - - private: - //! Extended data for plugin - struct PluginExtended - { - BlackMisc::Weather::CWeatherDataPluginInfo info; - }; - - QMap m_plugins; //!< Id <-> extended data pairs - }; -} // namespace - -#endif // guard diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index 1b9c95616..992cf80cf 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -112,75 +112,11 @@ namespace BlackCore this->setUpdateAllRemoteAircraft(); } - bool ISimulator::isWeatherActivated() const - { - return m_isWeatherActivated; - } - - void ISimulator::setWeatherActivated(bool activated) - { - m_isWeatherActivated = activated; - if (m_isWeatherActivated) - { - const auto selectedWeatherScenario = m_weatherScenarioSettings.get(); - if (CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) - { - if (m_lastWeatherPosition.isNull()) - { - const CCoordinateGeodetic p = this->getOwnAircraftPosition(); - if (!p.isNull()) - { - m_lastWeatherPosition = p; - this->requestWeatherGrid(p, this->identifier()); - } - } - } - else - { - m_lastWeatherPosition.setNull(); - this->injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); - } - } - else - { - m_lastWeatherPosition.setNull(); // clean up so next time we fetch weather again - } - } - void ISimulator::setFlightNetworkConnected(bool connected) { m_networkConnected = connected; } - void ISimulator::reloadWeatherSettings() - { - // log crash info about weather - if (!this->isShuttingDown()) { CCrashHandler::instance()->crashAndLogAppendInfo(u"Simulator weather: " % boolToYesNo(m_isWeatherActivated)); } - if (!m_isWeatherActivated) { return; } - - m_lastWeatherPosition.setNull(); - const CWeatherScenario selectedWeatherScenario = m_weatherScenarioSettings.get(); - if (CWeatherScenario::isRealWeatherScenario(selectedWeatherScenario)) - { - if (m_lastWeatherPosition.isNull()) - { - const CCoordinateGeodetic p = this->getOwnAircraftPosition(); - if (!p.isNull()) - { - m_lastWeatherPosition = p; - this->requestWeatherGrid(p, this->identifier()); - } - } - } - else - { - this->injectWeatherGrid(CWeatherGrid::getByScenario(selectedWeatherScenario)); - } - - // log crash info about weather - if (!this->isShuttingDown()) { CCrashHandler::instance()->crashAndLogAppendInfo(selectedWeatherScenario.toQString(true)); } - } - void ISimulator::clearAllRemoteAircraftData() { // rendering related stuff @@ -301,11 +237,6 @@ namespace BlackCore m_timerId = -1; } - void ISimulator::injectWeatherGrid(const CWeatherGrid &weatherGrid) - { - Q_UNUSED(weatherGrid) - } - CInterpolationAndRenderingSetupPerCallsign ISimulator::getInterpolationSetupConsolidated(const CCallsign &callsign, bool forceFullUpdate) const { CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(callsign); @@ -674,12 +605,10 @@ namespace BlackCore ISimulator::ISimulator(const CSimulatorPluginInfo &pluginInfo, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, QObject *parent) : QObject(parent), COwnAircraftAware(ownAircraftProvider), CRemoteAircraftAware(remoteAircraftProvider), - CWeatherGridAware(weatherGridProvider), CClientAware(clientProvider), ISimulationEnvironmentProvider(pluginInfo), IInterpolationSetupProvider(), diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 865f9d96c..9f5e81f3e 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -23,7 +23,6 @@ #include "blackmisc/aviation/airportlist.h" #include "blackmisc/aviation/callsignset.h" #include "blackmisc/network/clientprovider.h" -#include "blackmisc/weather/weathergridprovider.h" #include "blackmisc/geo/elevationplane.h" #include "blackmisc/pq/length.h" #include "blackmisc/pq/time.h" @@ -52,7 +51,6 @@ namespace BlackCore public QObject, public BlackMisc::Simulation::COwnAircraftAware, // access to in memory own aircraft data public BlackMisc::Simulation::CRemoteAircraftAware, // access to in memory remote aircraft data - public BlackMisc::Weather::CWeatherGridAware, // access to in memory weather grid public BlackMisc::Network::CClientAware, // the network client with its capabilities public BlackMisc::Simulation::ISimulationEnvironmentProvider, // give access to elevation etc. public BlackMisc::Simulation::IInterpolationSetupProvider, // setup @@ -159,12 +157,6 @@ namespace BlackCore //! Recalculate all aircraft virtual void recalculateAllAircraft(); - //! Weather activated - virtual bool isWeatherActivated() const; - - //! Activates or deactivates simulator weather - virtual void setWeatherActivated(bool activated); - //! Flight network has been connected //! \remark hint if network connected and we expect any planes //! \sa ISimulator::isFlightNetworkConnected @@ -173,9 +165,6 @@ namespace BlackCore //! Is the flight network connected bool isFlightNetworkConnected() const { return m_networkConnected; } - //! Reload weather settings - void reloadWeatherSettings(); - //! Settings for current simulator BlackMisc::Simulation::Settings::CSpecializedSimulatorSettings getSimulatorSettings() const { return m_multiSettings.getSpecializedSettings(this->getSimulatorInfo()); } @@ -252,9 +241,6 @@ namespace BlackCore //! \remark public for testing purposes virtual void callbackReceivedRequestedElevation(const BlackMisc::Geo::CElevationPlane &plane, const BlackMisc::Aviation::CCallsign &callsign, bool isWater); - //! Inject weather grid to simulator - virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid); - //! Allows to print out simulator specific statistics virtual QString getStatisticsSimulatorSpecific() const { return {}; } @@ -396,7 +382,6 @@ namespace BlackCore ISimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &pluginInfo, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); @@ -590,11 +575,6 @@ namespace BlackCore // general settings BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_multiSettings { this }; //!< simulator settings for all simulators - // weather - bool m_isWeatherActivated = false; //!< Is simulator weather activated? - BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last - BlackMisc::CSettingReadOnly m_weatherScenarioSettings { this, &ISimulator::reloadWeatherSettings }; //!< Selected weather scenario - private: // remote aircraft provider ("rap") bound void rapOnRecalculatedRenderedAircraft(const BlackMisc::Simulation::CAirspaceAircraftSnapshot &snapshot); @@ -699,7 +679,6 @@ namespace BlackCore //! \param info metadata about simulator //! \param ownAircraftProvider in memory access to own aircraft data //! \param remoteAircraftProvider in memory access to rendered aircraft data such as situation history and aircraft itself - //! \param weatherGridProvider in memory access to weather grid data //! \param clientProvider in memory access to client data //! \return driver instance //! @@ -707,7 +686,6 @@ namespace BlackCore const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider) = 0; //! Simulator listener instance diff --git a/src/blackcore/weatherdata.h b/src/blackcore/weatherdata.h deleted file mode 100644 index a5f4b86eb..000000000 --- a/src/blackcore/weatherdata.h +++ /dev/null @@ -1,64 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKCORE_WEATHERDATA_H -#define BLACKCORE_WEATHERDATA_H - -#include "blackcore/blackcoreexport.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/weather/weathergrid.h" -#include - -namespace BlackCore -{ - /*! - * Interface to weather data - */ - class BLACKCORE_EXPORT IWeatherData : public QObject - { - Q_OBJECT - - public: - //! Destructor - virtual ~IWeatherData() {} - - //! Fetch new weather data around grid - virtual void fetchWeatherData(const BlackMisc::Weather::CWeatherGrid &grid, - const BlackMisc::PhysicalQuantities::CLength &range) = 0; - - //! Fetch new weather around grid from file - virtual void fetchWeatherDataFromFile(const QString &filePath, - const BlackMisc::Weather::CWeatherGrid &grid, - const BlackMisc::PhysicalQuantities::CLength &range) = 0; - - //! Get fetched weather data - virtual BlackMisc::Weather::CWeatherGrid getWeatherData() const = 0; - - signals: - //! Finished fetching data - void fetchingFinished(); - - protected: - //! Default constructor - IWeatherData(QObject *parent = nullptr) : QObject(parent) {} - }; - - /*! - * Factory pattern class to create instances of IWeatherData - */ - class BLACKCORE_EXPORT IWeatherDataFactory - { - public: - //! Virtual destructor - virtual ~IWeatherDataFactory() {} - - //! Create a new instance - virtual IWeatherData *create(QObject *parent = nullptr) = 0; - }; -} // namespace - -Q_DECLARE_INTERFACE(BlackCore::IWeatherDataFactory, "org.swift-project.blackcore.weatherdata") - -#endif // guard diff --git a/src/blackcore/weathermanager.cpp b/src/blackcore/weathermanager.cpp deleted file mode 100644 index e568100fb..000000000 --- a/src/blackcore/weathermanager.cpp +++ /dev/null @@ -1,232 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackcore/weatherdata.h" -#include "blackcore/weathermanager.h" -#include "blackcore/application.h" - -#include "blackmisc/weather/gridpoint.h" -#include "blackmisc/weather/weatherdataplugininfo.h" -#include "blackmisc/weather/weatherdataplugininfolist.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/range.h" -#include "blackmisc/verify.h" -#include "blackmisc/statusmessage.h" -#include "blackconfig/buildconfig.h" - -#include -#include - -using namespace BlackConfig; -using namespace BlackMisc; -using namespace BlackMisc::Geo; -using namespace BlackMisc::Weather; -using namespace BlackMisc::PhysicalQuantities; - -namespace BlackCore -{ - CWeatherManager::CWeatherManager(QObject *parent) : QObject(parent) - { - m_pluginManagerWeatherData.collectPlugins(); - loadWeatherDataPlugins(); - } - - void CWeatherManager::setWeatherToClear(bool value) - { - m_isWeatherClear = value; - // todo: send weather grid to drivers from here - } - - void CWeatherManager::requestWeatherGrid(const ICoordinateGeodetic &position, const CIdentifier &identifier) - { - const CWeatherGrid weatherGrid = CWeatherGrid { { "GLOB", position } }; - this->requestWeatherGrid(weatherGrid, identifier); - } - - void CWeatherManager::appendRequest(const WeatherRequest &request) - { - const qint64 now = QDateTime::currentMSecsSinceEpoch(); - if (!m_pendingRequests.isEmpty() && m_lastPendingRequestTs > 0) - { - const qint64 pendingMs = now - m_lastPendingRequestTs; - if (pendingMs > 30 * 1000) - { - BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Time out of pending weather request"); - CLogMessage(this).warning(u"Time out of pending weather request, cleaning all requests!"); - m_pendingRequests.clear(); - } - } - - m_pendingRequests.append(request); - m_lastPendingRequestTs = now; - } - - void CWeatherManager::requestWeatherGrid(const CWeatherGrid &initialWeatherGrid, const CIdentifier &identifier) - { - if (identifier.isNull() || initialWeatherGrid.isEmpty() || initialWeatherGrid.frontOrDefault().getPosition().isNull()) - { - if (CBuildConfig::isLocalDeveloperDebugBuild()) - { - BLACK_VERIFY_X(!identifier.isNull(), Q_FUNC_INFO, "Missing callback"); - BLACK_VERIFY_X(!initialWeatherGrid.isEmpty(), Q_FUNC_INFO, "Empty grid, need position"); - BLACK_VERIFY_X(!initialWeatherGrid.frontOrDefault().getPosition().isNull(), Q_FUNC_INFO, "NULL position"); - } - return; - } - - const WeatherRequest weatherRequest { {}, identifier, initialWeatherGrid, {} }; - this->appendRequest(weatherRequest); - - // Serialize the requests, since plugins can handle only one at a time - if (m_pendingRequests.size() == 1) { fetchNextWeatherDataDeferred(); } - } - - void CWeatherManager::requestWeatherGrid(const CWeatherGrid &initialWeatherGrid, - const CSlot &callback) - { - if (!callback || initialWeatherGrid.isEmpty() || initialWeatherGrid.frontOrDefault().getPosition().isNull()) - { - if (CBuildConfig::isLocalDeveloperDebugBuild()) - { - BLACK_VERIFY_X(callback, Q_FUNC_INFO, "Missing callback"); - BLACK_VERIFY_X(!initialWeatherGrid.isEmpty(), Q_FUNC_INFO, "Empty grid, need position"); - BLACK_VERIFY_X(!initialWeatherGrid.frontOrDefault().getPosition().isNull(), Q_FUNC_INFO, "NULL position"); - } - return; - } - - if (m_isWeatherClear) - { - callback.singleShot(CWeatherGrid::getClearWeatherGrid()); - return; - } - - const WeatherRequest weatherRequest { {}, CIdentifier::null(), initialWeatherGrid, callback }; - this->appendRequest(weatherRequest); - - // Serialize the requests, since plugins can handle only one at a time - if (m_pendingRequests.size() == 1) { fetchNextWeatherDataDeferred(); } - } - - void CWeatherManager::requestWeatherGridFromFile(const QString &filePath, const CWeatherGrid &initialWeatherGrid, - const CSlot &callback) - { - if (m_isWeatherClear && callback) - { - callback.singleShot(CWeatherGrid::getClearWeatherGrid()); - return; - } - - WeatherRequest weatherRequest { filePath, CIdentifier::null(), initialWeatherGrid, callback }; - this->appendRequest(weatherRequest); - - // Serialize the requests, since plugins can handle only one at a time - if (m_pendingRequests.size() == 1) { fetchNextWeatherDataDeferred(); } - } - - bool CWeatherManager::loadWeatherDataPlugins() - { - const CWeatherDataPluginInfoList weatherDataPluginInfos = m_pluginManagerWeatherData.getAvailableWeatherDataPlugins(); - if (weatherDataPluginInfos.isEmpty()) - { - CLogMessage(this).warning(u"No weather data plugin found!"); - return false; - } - - for (const auto &pluginInfo : weatherDataPluginInfos) - { - IWeatherDataFactory *factory = m_pluginManagerWeatherData.getPluginById(pluginInfo.getIdentifier()); - if (!factory) - { - CLogMessage(this).error(u"Failed to create IWeatherDataFactory for %1") << pluginInfo.getIdentifier(); - return false; - } - - IWeatherData *weatherData = factory->create(this); - if (!weatherData) - { - CLogMessage(this).error(u"Failed to create IWeatherData instance for %1") << pluginInfo.getIdentifier(); - return false; - } - - connect(weatherData, &IWeatherData::fetchingFinished, this, &CWeatherManager::handleNextRequest, Qt::QueuedConnection); - m_weatherDataPlugins.append(weatherData); - delete factory; - } - return true; - } - - void CWeatherManager::fetchNextWeatherData() - { - const WeatherRequest weatherRequest = m_pendingRequests.constFirst(); - const CLength maxDistance(100.0, CLengthUnit::km()); - - for (IWeatherData *plugin : std::as_const(m_weatherDataPlugins)) - { - if (!plugin) { continue; } - if (weatherRequest.filePath.isEmpty()) - { - plugin->fetchWeatherData(weatherRequest.weatherGrid, maxDistance); - } - else - { - plugin->fetchWeatherDataFromFile(weatherRequest.filePath, weatherRequest.weatherGrid, maxDistance); - } - } - } - - void CWeatherManager::fetchNextWeatherDataDeferred() - { - QPointer myself(this); - QTimer::singleShot(0, this, [=] { - if (!myself || !sApp || sApp->isShuttingDown()) { return; } - myself->fetchNextWeatherData(); - }); - } - - void CWeatherManager::handleNextRequest() - { - if (m_pendingRequests.isEmpty()) - { - // we should normally never get here, only if a request timedout - CLogMessage(this).warning(u"No pending weather request, ignoring ...."); - BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "No pending weather request, ignoring ...."); - return; - } - - IWeatherData *weatherDataPlugin = qobject_cast(sender()); - Q_ASSERT(weatherDataPlugin); - const auto fetchedWeatherGrid = weatherDataPlugin->getWeatherData(); - - const WeatherRequest weatherRequest = m_pendingRequests.front(); - CWeatherGrid requestedWeatherGrid = weatherRequest.weatherGrid; - - // Interpolation. So far it just picks the closest point without interpolation. - for (CGridPoint &gridPoint : requestedWeatherGrid) - { - const auto nearestGridPoint = fetchedWeatherGrid.findClosest(1, gridPoint.getPosition()).frontOrDefault(); - gridPoint.copyWeatherDataFrom(nearestGridPoint); - gridPoint.setPosition(nearestGridPoint.getPosition()); - } - - if (weatherRequest.callback) - { - weatherRequest.callback.singleShot(requestedWeatherGrid); - } - - if (!weatherRequest.identifier.isAnonymous()) { emit weatherGridReceived(requestedWeatherGrid, weatherRequest.identifier); } - m_pendingRequests.pop_front(); - - // In case there are pending requests, start over again - if (!m_pendingRequests.isEmpty()) - { - fetchNextWeatherData(); - } - else - { - m_lastPendingRequestTs = -1; - } - } -} diff --git a/src/blackcore/weathermanager.h b/src/blackcore/weathermanager.h deleted file mode 100644 index 1d7031372..000000000 --- a/src/blackcore/weathermanager.h +++ /dev/null @@ -1,86 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKCORE_WEATHERMANAGER_H -#define BLACKCORE_WEATHERMANAGER_H - -#include "blackcore/pluginmanagerweatherdata.h" -#include "blackcore/blackcoreexport.h" -#include "blackmisc/weather/weathergrid.h" -#include "blackmisc/weather/weathergridprovider.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/identifier.h" -#include "blackmisc/slot.h" - -#include -#include - -namespace BlackCore -{ - class IWeatherData; - - /*! - * CWeatherManager - */ - class BLACKCORE_EXPORT CWeatherManager : - public QObject, - public BlackMisc::Weather::IWeatherGridProvider - { - Q_OBJECT - Q_INTERFACES(BlackMisc::Weather::IWeatherGridProvider) - - public: - //! Default constructor - CWeatherManager(QObject *parent = nullptr); - - //! Override weather to clear - void setWeatherToClear(bool value); - - //! Is weather overwritten to clear? - bool isWeatherClear() const { return m_isWeatherClear; } - - //! \copydoc BlackMisc::Weather::IWeatherGridProvider::requestWeatherGrid - virtual void requestWeatherGrid(const BlackMisc::Geo::ICoordinateGeodetic &position, const BlackMisc::CIdentifier &identifier) override; - - //! \copydoc BlackMisc::Weather::IWeatherGridProvider::requestWeatherGrid - virtual void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &initialWeatherGrid, - const BlackMisc::CSlot &callback) override; - - //! \copydoc BlackMisc::Weather::IWeatherGridProvider::requestWeatherGrid - virtual void requestWeatherGridFromFile(const QString &filePath, - const BlackMisc::Weather::CWeatherGrid &initialWeatherGrid, - const BlackMisc::CSlot &callback) override; - - signals: - //! The weather grid, requested from identified, is available - void weatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); - - private: - //! Pending weather request - struct WeatherRequest - { - QString filePath; - BlackMisc::CIdentifier identifier; - BlackMisc::Weather::CWeatherGrid weatherGrid; - BlackMisc::CSlot callback; - }; - - void requestWeatherGrid(const BlackMisc::Weather::CWeatherGrid &initialWeatherGrid, const BlackMisc::CIdentifier &identifier); - bool loadWeatherDataPlugins(); - void fetchNextWeatherData(); - void fetchNextWeatherDataDeferred(); - void appendRequest(const WeatherRequest &request); - void handleNextRequest(); - - CPluginManagerWeatherData m_pluginManagerWeatherData { this }; - QVector m_weatherDataPlugins; - QVector m_pendingRequests; - qint64 m_lastPendingRequestTs = -1; - BlackMisc::Weather::CWeatherGrid m_weatherGrid; - bool m_isWeatherClear = false; - }; -} // ns - -#endif // guard diff --git a/src/blackgui/CMakeLists.txt b/src/blackgui/CMakeLists.txt index 7fac80bcd..5923ba74c 100644 --- a/src/blackgui/CMakeLists.txt +++ b/src/blackgui/CMakeLists.txt @@ -100,8 +100,6 @@ add_library(gui SHARED models/statusmessagefilter.h models/listmodelbasenontemplate.cpp models/countrylistmodel.h - models/temperaturelayerlistmodel.h - models/temperaturelayerlistmodel.cpp models/serverlistmodel.cpp models/countryfilter.cpp models/applicationinfolistmodel.h @@ -128,7 +126,6 @@ add_library(gui SHARED views/viewbase.h views/viewbasemisc.cpp views/windlayerview.cpp - views/temperaturelayerview.h views/distributorview.h views/checkboxdelegate.cpp views/viewbaseproxystyle.cpp @@ -142,7 +139,6 @@ add_library(gui SHARED views/viewtimestampobjects.h views/atcstationview.h views/aircraftsituationview.cpp - views/temperaturelayerview.cpp views/viewbaseproxystyle.h views/identifierview.h views/simulatedaircraftview.cpp @@ -374,7 +370,6 @@ add_library(gui SHARED components/usercomponent.ui components/dbreducemodelduplicates.ui components/installfsxterrainprobecomponent.cpp - components/weathercomponent.h components/interpolationsetupcomponent.h components/registermetadatacomponents.cpp components/networkaircraftvaluescomponent.h @@ -396,7 +391,6 @@ add_library(gui SHARED components/dbstashcomponent.cpp components/texteditdialog.ui components/dbownmodelsetcomponent.ui - components/weathercomponent.cpp components/scalescreenfactor.h components/rawfsdmessagesdialog.cpp components/flightplancomponent.h @@ -690,7 +684,6 @@ add_library(gui SHARED components/otherswiftversionsdialog.ui components/dbreducemodelduplicates.h components/colorselector.h - components/weathercomponent.ui components/dbstashcomponent.h components/transpondercodespinbox.cpp components/interpolationcomponent.h diff --git a/src/blackgui/components/maininfoareacomponent.cpp b/src/blackgui/components/maininfoareacomponent.cpp index f82770d9b..12dab8df1 100644 --- a/src/blackgui/components/maininfoareacomponent.cpp +++ b/src/blackgui/components/maininfoareacomponent.cpp @@ -68,11 +68,6 @@ namespace BlackGui::Components return ui->comp_Settings; } - CWeatherComponent *CMainInfoAreaComponent::getWeatherComponent() - { - return ui->comp_Weather; - } - CLogComponent *CMainInfoAreaComponent::getLogComponent() { return ui->comp_Log; @@ -146,7 +141,6 @@ namespace BlackGui::Components case InfoAreaInterpolation: case InfoAreaSettings: case InfoAreaTextMessages: - case InfoAreaWeather: case InfoAreaRadar: return QSize(600, 400); case InfoAreaFlightPlan: @@ -175,7 +169,6 @@ namespace BlackGui::Components { case InfoAreaCockpit: return CIcons::appCockpit16(); case InfoAreaUsers: return CIcons::appUsers16(); - case InfoAreaWeather: return CIcons::appWeather16(); case InfoAreaAtc: return CIcons::appAtc16(); case InfoAreaAircraft: return CIcons::appAircraft16(); case InfoAreaSettings: return CIcons::appSettings16(); diff --git a/src/blackgui/components/maininfoareacomponent.h b/src/blackgui/components/maininfoareacomponent.h index 626e5f1c3..2728cc4d6 100644 --- a/src/blackgui/components/maininfoareacomponent.h +++ b/src/blackgui/components/maininfoareacomponent.h @@ -34,7 +34,6 @@ namespace BlackGui::Components class CSimulatorComponent; class CTextMessageComponent; class CUserComponent; - class CWeatherComponent; //! Main info area of pilot client class BLACKGUI_EXPORT CMainInfoAreaComponent : public BlackGui::CInfoArea @@ -59,12 +58,11 @@ namespace BlackGui::Components InfoAreaTextMessages = 4, InfoAreaSimulator = 5, InfoAreaFlightPlan = 6, - InfoAreaWeather = 7, - InfoAreaMapping = 8, //!< aka rendering, models - InfoAreaInterpolation = 9, - InfoAreaSettings = 10, - InfoAreaLog = 11, - InfoAreaRadar = 12, + InfoAreaMapping = 7, //!< aka rendering, models + InfoAreaInterpolation = 8, + InfoAreaSettings = 9, + InfoAreaLog = 10, + InfoAreaRadar = 11, InfoAreaNone = -1 }; @@ -92,9 +90,6 @@ namespace BlackGui::Components //! Settings CSettingsComponent *getSettingsComponent(); - //! Weather component - CWeatherComponent *getWeatherComponent(); - //! Log messages CLogComponent *getLogComponent(); diff --git a/src/blackgui/components/maininfoareacomponent.ui b/src/blackgui/components/maininfoareacomponent.ui index b7d0423c7..92bbcbc39 100644 --- a/src/blackgui/components/maininfoareacomponent.ui +++ b/src/blackgui/components/maininfoareacomponent.ui @@ -482,72 +482,6 @@ - - - - 157 - 78 - - - - Qt::NoDockWidgetArea - - - Weather - - - 4 - - - - - 0 - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - - - 0 - - - 2 - - - 0 - - - 0 - - - - - - - - - - Qt::NoDockWidgetArea @@ -914,12 +848,6 @@
blackgui/components/mappingcomponent.h
1 - - BlackGui::Components::CWeatherComponent - QTabWidget -
blackgui/components/weathercomponent.h
- 1 -
BlackGui::Components::CInterpolationComponent QFrame diff --git a/src/blackgui/components/mainkeypadareacomponent.cpp b/src/blackgui/components/mainkeypadareacomponent.cpp index 18adfae71..9b9bc921a 100644 --- a/src/blackgui/components/mainkeypadareacomponent.cpp +++ b/src/blackgui/components/mainkeypadareacomponent.cpp @@ -46,7 +46,6 @@ namespace BlackGui::Components connect(ui->pb_MainSimulator, &QPushButton::released, this, &CMainKeypadAreaComponent::buttonSelected); connect(ui->pb_MainTextMessages, &QPushButton::released, this, &CMainKeypadAreaComponent::buttonSelected); connect(ui->pb_MainUsers, &QPushButton::released, this, &CMainKeypadAreaComponent::buttonSelected); - connect(ui->pb_MainWeather, &QPushButton::released, this, &CMainKeypadAreaComponent::buttonSelected); // non info areas connect(ui->pb_Connect, &QPushButton::released, this, &CMainKeypadAreaComponent::buttonSelected); @@ -207,7 +206,6 @@ namespace BlackGui::Components if (button == ui->pb_MainSimulator) return CMainInfoAreaComponent::InfoAreaSimulator; if (button == ui->pb_MainTextMessages) return CMainInfoAreaComponent::InfoAreaTextMessages; if (button == ui->pb_MainUsers) return CMainInfoAreaComponent::InfoAreaUsers; - if (button == ui->pb_MainWeather) return CMainInfoAreaComponent::InfoAreaWeather; return CMainInfoAreaComponent::InfoAreaNone; } @@ -227,7 +225,6 @@ namespace BlackGui::Components case CMainInfoAreaComponent::InfoAreaSimulator: return ui->pb_MainSimulator; case CMainInfoAreaComponent::InfoAreaTextMessages: return ui->pb_MainTextMessages; case CMainInfoAreaComponent::InfoAreaUsers: return ui->pb_MainUsers; - case CMainInfoAreaComponent::InfoAreaWeather: return ui->pb_MainWeather; default: break; } return nullptr; @@ -247,7 +244,6 @@ namespace BlackGui::Components ui->pb_MainSimulator->setChecked(false); ui->pb_MainTextMessages->setChecked(false); ui->pb_MainUsers->setChecked(false); - ui->pb_MainWeather->setChecked(false); this->updateConnectionStatus(); } diff --git a/src/blackgui/components/mainkeypadareacomponent.ui b/src/blackgui/components/mainkeypadareacomponent.ui index 9d32cb001..5e56c5f9c 100644 --- a/src/blackgui/components/mainkeypadareacomponent.ui +++ b/src/blackgui/components/mainkeypadareacomponent.ui @@ -126,22 +126,6 @@
- - - - - 0 - 0 - - - - Weather - - - true - - - @@ -425,7 +409,6 @@ pb_MainFlightplan pb_MainLog pb_MainSettings - pb_MainWeather pb_MainUsers pb_Opacity050 pb_Opacity100 diff --git a/src/blackgui/components/weathercomponent.cpp b/src/blackgui/components/weathercomponent.cpp deleted file mode 100644 index 896809a6f..000000000 --- a/src/blackgui/components/weathercomponent.cpp +++ /dev/null @@ -1,272 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackgui/components/weathercomponent.h" -#include "blackgui/infoarea.h" -#include "blackgui/views/viewbase.h" -#include "blackgui/guiapplication.h" -#include "blackgui/guiactionbind.h" -#include "blackcore/context/contextapplication.h" -#include "blackcore/context/contextsimulator.h" -#include "blackcore/context/contextownaircraft.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/logmessage.h" -#include "blackmisc/weather/weathergrid.h" -#include "ui_weathercomponent.h" - -#include -#include -#include -#include -#include -#include - -using namespace BlackCore; -using namespace BlackCore::Context; -using namespace BlackGui; -using namespace BlackGui::Models; -using namespace BlackGui::Views; -using namespace BlackMisc; -using namespace BlackMisc::Geo; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Weather; - -namespace BlackGui::Components -{ - CWeatherComponent::CWeatherComponent(QWidget *parent) : COverlayMessagesFrameEnableForDockWidgetInfoArea(parent), - CIdentifiable(this), - ui(new Ui::CWeatherComponent) - { - ui->setupUi(this); - m_coordinateDialog->showElevation(false); - m_coordinateDialog->setReadOnly(ui->cb_UseOwnAcftPosition->isChecked()); - connect(ui->pb_SetPosition, &QPushButton::clicked, this, &CWeatherComponent::showCoordinateDialog); - connect(ui->pb_Update, &QPushButton::clicked, this, &CWeatherComponent::updateWeatherInformationForced); - - m_weatherScenarios = CWeatherGrid::getAllScenarios(); - for (const auto &scenario : std::as_const(m_weatherScenarios)) - { - ui->cb_weatherScenario->addItem(scenario.getName(), QVariant::fromValue(scenario)); - } - - const CWeatherScenario scenario = m_weatherScenarioSetting.get(); - ui->cb_weatherScenario->setCurrentIndex(scenario.getIndex()); - ui->pb_ActivateWeather->setIcon(CIcons::metar()); - - this->setupConnections(); - ui->lbl_Status->setText({}); - - // hotkeys - const QString swift(CGuiActionBindHandler::pathSwiftPilotClient()); - m_hotkeyBindings.append(CGuiActionBindHandler::bindButton(ui->pb_ActivateWeather, swift + "Weather/Toggle weather", true)); - m_hotkeyBindings.append(CGuiActionBindHandler::bindButton(ui->pb_ActivateWeather, swift + "Weather/Force CAVOK", true)); - - // Set interval to 5 mins - m_weatherUpdateTimer.setInterval(1000 * 60 * 5); - - // Call this method deferred in order to have the component fully initialized, e.g. object name set by the parent - QPointer myself(this); - QTimer::singleShot(1000, this, [=] { - if (!myself) { return; } - myself->updateWeatherInformation(true); - myself->updateWeatherInfoLine(); - }); - } - - CWeatherComponent::~CWeatherComponent() - {} - - bool CWeatherComponent::setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget) - { - CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(parentDockableWidget); - const bool c = connect(this->getParentInfoArea(), &CInfoArea::changedInfoAreaTabBarIndex, this, &CWeatherComponent::infoAreaTabBarChanged, Qt::QueuedConnection); - Q_ASSERT_X(c, Q_FUNC_INFO, "failed connect"); - Q_ASSERT_X(parentDockableWidget, Q_FUNC_INFO, "missing parent"); - return c && parentDockableWidget; - } - - void CWeatherComponent::infoAreaTabBarChanged(int index) - { - // ignore in those cases - if (!this->isVisibleWidget()) { return; } - if (this->isParentDockWidgetFloating()) { return; } - - // here I know I am the selected widget, update, but keep GUI responsive (-> timer) - // QTimer::singleShot(1000, this, &CWeatherComponent::update); - Q_UNUSED(index) - } - - void CWeatherComponent::toggleUseOwnAircraftPosition(bool useOwnAircraftPosition) - { - m_lastOwnAircraftPosition = {}; - m_coordinateDialog->setReadOnly(useOwnAircraftPosition); - if (useOwnAircraftPosition) - { - m_weatherUpdateTimer.start(); - ui->pb_SetPosition->setText("Show Position"); - } - else - { - m_weatherUpdateTimer.stop(); - const CCoordinateGeodetic c; - m_coordinateDialog->setCoordinate(c); - ui->pb_SetPosition->setText("Select Position"); - } - updateWeatherInformation(false); - } - - void CWeatherComponent::toggleWeatherActivation() - { - if (!sGui || !sGui->getIContextSimulator()) { return; } - if (m_isWeatherActivated) - { - m_isWeatherActivated = false; - ui->pb_ActivateWeather->setText("Activate"); - } - else - { - m_isWeatherActivated = true; - ui->pb_ActivateWeather->setText("Deactivate"); - } - sGui->getIContextSimulator()->setWeatherActivated(m_isWeatherActivated); - this->updateWeatherInfoLine(); - } - - void CWeatherComponent::showCoordinateDialog() - { - m_coordinateDialog->show(); - } - - void CWeatherComponent::setWeatherScenario(int index) - { - if (index == -1) { return; } - m_lastOwnAircraftPosition = {}; - const CWeatherScenario scenario = m_weatherScenarios[index]; - m_weatherScenarioSetting.set(scenario); - this->updateWeatherInformation(false); - this->updateWeatherInfoLine(); - } - - void CWeatherComponent::setCavok() - { - QPointer myself(this); - for (int index = 0; index < m_weatherScenarios.size(); index++) - { - if (m_weatherScenarios[index].getIndex() == CWeatherScenario::ClearSky) - { - // call queued - QTimer::singleShot(0, this, [=] { if (myself) { myself->setWeatherScenario(index); } }); - break; - } - } - } - - void CWeatherComponent::updateWeatherInfoLine() - { - if (m_isWeatherActivated) - { - const CWeatherScenario scenario = m_weatherScenarioSetting.get(); - ui->lbl_WeatherEngineInfo->setText(QStringLiteral("swift weather is on, '%1'").arg(scenario.getName())); - } - else - { - ui->lbl_WeatherEngineInfo->setText(QStringLiteral("swift weather is off")); - } - } - - void CWeatherComponent::updateWeatherInformation(bool forceRealWeatherReload) - { - setWeatherGrid({}); - ui->lbl_Status->setText({}); - const bool useOwnAcftPosition = ui->cb_UseOwnAcftPosition->isChecked(); - CCoordinateGeodetic position; - Q_ASSERT(ui->cb_weatherScenario->currentData().canConvert()); - const CWeatherScenario scenario = ui->cb_weatherScenario->currentData().value(); - - if (useOwnAcftPosition) - { - Q_ASSERT(sGui->getIContextOwnAircraft()); - position = sGui->getIContextOwnAircraft()->getOwnAircraft().getPosition(); - m_coordinateDialog->setCoordinate(position); - } - else - { - position = m_coordinateDialog->getCoordinate(); - if (position.isNull()) - { - ui->lbl_Status->setText("No position selected."); - return; - } - } - - if (CWeatherScenario::isRealWeatherScenario(scenario)) - { - if (m_lastOwnAircraftPosition.isNull() || forceRealWeatherReload || - calculateGreatCircleDistance(position, m_lastOwnAircraftPosition).value(CLengthUnit::km()) > 20) - { - this->requestWeatherGrid(position); - m_lastOwnAircraftPosition = position; - showOverlayHTMLMessage("Weather loading,
this may take a while", 7500); - } - } - else - { - setWeatherGrid(CWeatherGrid::getByScenario(scenario)); - } - } - - void CWeatherComponent::onWeatherGridReceived(const CWeatherGrid &weatherGrid, const CIdentifier &identifier) - { - if (!isMyIdentifier(identifier)) - { - // not from myself - const CWeatherScenario scenario = ui->cb_weatherScenario->currentData().value(); - if (!CWeatherScenario::isRealWeatherScenario(scenario)) { return; } - - // we have received weather grid data and assume those are real weather updates - closeOverlay(); - } - ui->lbl_Status->setText({}); - setWeatherGrid(weatherGrid); - } - - void CWeatherComponent::setupConnections() - { - // UI connections - connect(m_coordinateDialog.data(), &CCoordinateDialog::changedCoordinate, this, &CWeatherComponent::updateWeatherInformationForced); - connect(&m_weatherUpdateTimer, &QTimer::timeout, this, &CWeatherComponent::updateWeatherInformationChecked); - connect(ui->cb_weatherScenario, qOverload(&QComboBox::currentIndexChanged), this, &CWeatherComponent::setWeatherScenario); - connect(ui->cb_UseOwnAcftPosition, &QCheckBox::toggled, this, &CWeatherComponent::toggleUseOwnAircraftPosition); - connect(ui->pb_ActivateWeather, &QPushButton::clicked, this, &CWeatherComponent::toggleWeatherActivation); - - // Context connections - Q_ASSERT(sGui->getIContextSimulator()); - connect(sGui->getIContextSimulator(), &IContextSimulator::weatherGridReceived, this, &CWeatherComponent::onWeatherGridReceived, Qt::QueuedConnection); - } - - void CWeatherComponent::setWeatherGrid(const CWeatherGrid &weatherGrid) - { - const CGridPoint gridPoint = weatherGrid.frontOrDefault(); - ui->tvp_TemperatureLayers->updateContainer(gridPoint.getTemperatureLayers()); - ui->tvp_CloudLayers->updateContainer(gridPoint.getCloudLayers()); - ui->tvp_WindLayers->updateContainer(gridPoint.getWindLayers()); - const CCoordinateGeodetic position = gridPoint.getPosition(); - const double pressureAtMslHpa = gridPoint.getPressureAtMsl().value(CPressureUnit::hPa()); - const double pressureAtMslInHg = gridPoint.getPressureAtMsl().value(CPressureUnit::inHg()); - const QString status = QStringLiteral("Weather Position: %1 %2\nPressure (MSL): %3 hPa / %4 inHg").arg(position.latitude().toWgs84(), position.longitude().toWgs84()).arg(pressureAtMslHpa, 0, 'f', 0).arg(pressureAtMslInHg, 0, 'f', 2); - ui->lbl_Status->setText(status); - } - - void CWeatherComponent::requestWeatherGrid(const CCoordinateGeodetic &position) - { - if (!sGui || sGui->isShuttingDown() || !sGui->getIContextSimulator()) { return; } - ui->lbl_Status->setText(QStringLiteral("Loading around %1 %2").arg(position.latitude().toWgs84(), position.longitude().toWgs84())); - sGui->getIContextSimulator()->requestWeatherGrid(position, this->identifier()); - } - - void CWeatherComponent::onScenarioChanged() - { - this->updateWeatherInfoLine(); - } - -} // namespace diff --git a/src/blackgui/components/weathercomponent.h b/src/blackgui/components/weathercomponent.h deleted file mode 100644 index 2fad170db..000000000 --- a/src/blackgui/components/weathercomponent.h +++ /dev/null @@ -1,92 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKGUI_WEATHERCOMPONENT_H -#define BLACKGUI_WEATHERCOMPONENT_H - -#include "blackgui/enablefordockwidgetinfoarea.h" -#include "blackgui/components/coordinatedialog.h" -#include "blackgui/blackguiexport.h" -#include "blackcore/actionbind.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/simulation/settings/simulatorsettings.h" -#include "blackmisc/weather/weatherscenario.h" -#include "blackmisc/identifiable.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace BlackMisc::Weather -{ - class CWeatherGrid; -} -namespace Ui -{ - class CWeatherComponent; -} - -namespace BlackGui -{ - class CDockWidgetInfoArea; - - namespace Components - { - //! Weather component - class BLACKGUI_EXPORT CWeatherComponent : - public COverlayMessagesFrameEnableForDockWidgetInfoArea, - public BlackMisc::CIdentifiable - { - Q_OBJECT - - public: - //! Constructor - explicit CWeatherComponent(QWidget *parent = nullptr); - - //! Destructor - virtual ~CWeatherComponent() override; - - //! \copydoc CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea - virtual bool setParentDockWidgetInfoArea(BlackGui::CDockWidgetInfoArea *parentDockableWidget) override; - - private: - void infoAreaTabBarChanged(int index); - - void toggleUseOwnAircraftPosition(bool useOwnAircraftPosition); - void toggleWeatherActivation(); - void showCoordinateDialog(); - void setWeatherScenario(int index); - void setCavok(); - - void updateWeatherInfoLine(); - void updateWeatherInformationForced() { this->updateWeatherInformation(true); } - void updateWeatherInformationChecked() { this->updateWeatherInformation(false); } - void updateWeatherInformation(bool forceRealWeatherReload); - void onWeatherGridReceived(const BlackMisc::Weather::CWeatherGrid &weatherGrid, const BlackMisc::CIdentifier &identifier); - - void setupConnections(); - - void setWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid); - void requestWeatherGrid(const BlackMisc::Geo::CCoordinateGeodetic &position); - - void onScenarioChanged(); - - QScopedPointer ui; - QScopedPointer m_coordinateDialog { new CCoordinateDialog(this) }; - QVector m_weatherScenarios; - QTimer m_weatherUpdateTimer; //!< this is the timer for weather updates - BlackMisc::Geo::CCoordinateGeodetic m_lastOwnAircraftPosition; - BlackMisc::CSetting m_weatherScenarioSetting { this, &CWeatherComponent::onScenarioChanged }; - BlackCore::CActionBindings m_hotkeyBindings; //!< allow binding of hotkey - bool m_isWeatherActivated = false; - }; - } // namespace -} // namespace -#endif // guard diff --git a/src/blackgui/components/weathercomponent.ui b/src/blackgui/components/weathercomponent.ui deleted file mode 100644 index ae00ccd88..000000000 --- a/src/blackgui/components/weathercomponent.ui +++ /dev/null @@ -1,308 +0,0 @@ - - - CWeatherComponent - - - - 0 - 0 - 307 - 459 - - - - Weather - - - 0 - - - - 1 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 0 - 100 - - - - Weather Control - - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - - - activate - - - - - - - info goes here - - - - - - - update - - - - - - - - - - Weather Display - - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 0 - 0 - - - - show Position - - - - - - - - 0 - 0 - - - - Use own aircraft position - - - true - - - - - - - - - - <status will go here> - - - true - - - - - - - 0 - - - - Temperature - - - - 0 - - - 0 - - - 1 - - - 0 - - - 0 - - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - - - - - - Clouds - - - - 0 - - - 0 - - - 1 - - - 0 - - - 0 - - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - - - - - - Winds - - - - 0 - - - 0 - - - 1 - - - 0 - - - 0 - - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - - - - - - - - - - - - - BlackGui::Views::CTemperatureLayerView - QTableView -
blackgui/views/temperaturelayerview.h
-
- - BlackGui::Views::CCloudLayerView - QTableView -
blackgui/views/cloudlayerview.h
-
- - BlackGui::Views::CWindLayerView - QTableView -
blackgui/views/windlayerview.h
-
-
- - cb_weatherScenario - pb_ActivateWeather - pb_Update - cb_UseOwnAcftPosition - pb_SetPosition - tw_weatherGrid - tvp_TemperatureLayers - tvp_CloudLayers - tvp_WindLayers - - - -
diff --git a/src/blackgui/models/allmodelcontainers.h b/src/blackgui/models/allmodelcontainers.h index 92a6ba705..0dc38306b 100644 --- a/src/blackgui/models/allmodelcontainers.h +++ b/src/blackgui/models/allmodelcontainers.h @@ -25,7 +25,6 @@ #include "blackmisc/network/userlist.h" #include "blackmisc/weather/cloudlayerlist.h" #include "blackmisc/weather/presentweatherlist.h" -#include "blackmisc/weather/temperaturelayerlist.h" #include "blackmisc/weather/windlayerlist.h" #include "blackmisc/input/actionhotkeylist.h" #include "blackmisc/applicationinfolist.h" diff --git a/src/blackgui/models/allmodels.h b/src/blackgui/models/allmodels.h index 52ad722df..e68cbcf39 100644 --- a/src/blackgui/models/allmodels.h +++ b/src/blackgui/models/allmodels.h @@ -28,7 +28,6 @@ #include "blackgui/models/serverlistmodel.h" #include "blackgui/models/simulatedaircraftlistmodel.h" #include "blackgui/models/statusmessagelistmodel.h" -#include "blackgui/models/temperaturelayerlistmodel.h" #include "blackgui/models/textmessagelistmodel.h" #include "blackgui/models/userlistmodel.h" #include "blackgui/models/windlayerlistmodel.h" diff --git a/src/blackgui/models/listmodelbaseweather.cpp b/src/blackgui/models/listmodelbaseweather.cpp index 5c1d1d43b..a2f079917 100644 --- a/src/blackgui/models/listmodelbaseweather.cpp +++ b/src/blackgui/models/listmodelbaseweather.cpp @@ -8,7 +8,6 @@ namespace BlackGui::Models // see here for the reason of thess forward instantiations // https://isocpp.org/wiki/faq/templates#separate-template-fn-defn-from-decl template class CListModelBase; - template class CListModelBase; template class CListModelBase; } // namespace diff --git a/src/blackgui/models/temperaturelayerlistmodel.cpp b/src/blackgui/models/temperaturelayerlistmodel.cpp deleted file mode 100644 index 5e53977ef..000000000 --- a/src/blackgui/models/temperaturelayerlistmodel.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackgui/models/temperaturelayerlistmodel.h" -#include "blackgui/models/columnformatters.h" - -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Weather; - -namespace BlackGui::Models -{ - - //! Temperature in degrees - class CTemperatureFormatter : public CPhysiqalQuantiyFormatter - { - public: - //! Constructor - CTemperatureFormatter(int alignment = alignRightVCenter(), bool withUnit = true, bool i18n = true) : CPhysiqalQuantiyFormatter(CTemperatureUnit::C(), 0, alignment, withUnit, i18n) {} - }; - - //! Relative Humidity - class CRelativeHumidityFormatter : public CDefaultFormatter - { - public: - //! Constructor - CRelativeHumidityFormatter(int alignment = alignDefault()) : CDefaultFormatter(alignment, false, roleDisplay()) {} - - //! \copydoc CDefaultFormatter::displayRole - virtual CVariant displayRole(const CVariant &dataCVariant) const override - { - if (dataCVariant.canConvert()) - { - int rh = dataCVariant.value(); - QString formattedString = QString::number(rh) + " %"; - return formattedString; - } - Q_ASSERT_X(false, "CRelativeHumidityFormatter", "no double value"); - return CVariant(); - } - }; - - CTemperatureLayerListModel::CTemperatureLayerListModel(QObject *parent) : CListModelBase("TemperatureLayerListModel", parent) - { - m_columns.addColumn(CColumn("level", CTemperatureLayer::IndexLevel, new CAltitudeFormatter())); - m_columns.addColumn(CColumn("temperature", CTemperatureLayer::IndexTemperature, new CTemperatureFormatter())); - m_columns.addColumn(CColumn("dew point", CTemperatureLayer::IndexDewPoint, new CTemperatureFormatter())); - m_columns.addColumn(CColumn("relative humidity", CTemperatureLayer::IndexRelativeHumidity, new CRelativeHumidityFormatter())); - - // default sort order - this->setSortColumnByPropertyIndex(CTemperatureLayer::IndexLevel); - m_sortOrder = Qt::AscendingOrder; - - // force strings for translation in resource files - (void)QT_TRANSLATE_NOOP("ModelTemperatureLayerList", "level"); - (void)QT_TRANSLATE_NOOP("ModelTemperatureLayerList", "temperature"); - (void)QT_TRANSLATE_NOOP("ModelTemperatureLayerList", "dew point"); - (void)QT_TRANSLATE_NOOP("ModelTemperatureLayerList", "relative humidity"); - } -} // ns diff --git a/src/blackgui/models/temperaturelayerlistmodel.h b/src/blackgui/models/temperaturelayerlistmodel.h deleted file mode 100644 index 63bc592a4..000000000 --- a/src/blackgui/models/temperaturelayerlistmodel.h +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKGUI_TEMPERATURELAYERLISTMODEL_H -#define BLACKGUI_TEMPERATURELAYERLISTMODEL_H - -#include "blackgui/blackguiexport.h" -#include "blackgui/models/listmodelbase.h" -#include "blackmisc/weather/temperaturelayer.h" -#include "blackmisc/weather/temperaturelayerlist.h" - -class QObject; - -namespace BlackGui::Models -{ - //! Temperature layer list model - class BLACKGUI_EXPORT CTemperatureLayerListModel : - public CListModelBase - { - Q_OBJECT - - public: - //! Constructor - explicit CTemperatureLayerListModel(QObject *parent = nullptr); - - //! Destructor - virtual ~CTemperatureLayerListModel() {} - }; -} -#endif // guard diff --git a/src/blackgui/views/temperaturelayerview.cpp b/src/blackgui/views/temperaturelayerview.cpp deleted file mode 100644 index cd9c69ab5..000000000 --- a/src/blackgui/views/temperaturelayerview.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackgui/models/temperaturelayerlistmodel.h" -#include "blackgui/views/temperaturelayerview.h" - -using namespace BlackMisc; -using namespace BlackGui::Models; - -namespace BlackGui::Views -{ - CTemperatureLayerView::CTemperatureLayerView(QWidget *parent) : CViewBase(parent) - { - this->standardInit(new CTemperatureLayerListModel(this)); - } -} // namespace diff --git a/src/blackgui/views/temperaturelayerview.h b/src/blackgui/views/temperaturelayerview.h deleted file mode 100644 index 28c1bed9a..000000000 --- a/src/blackgui/views/temperaturelayerview.h +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKGUI_VIEWS_TEMPERATURELAYERVIEW_H -#define BLACKGUI_VIEWS_TEMPERATURELAYERVIEW_H - -#include "blackgui/blackguiexport.h" -#include "blackgui/models/temperaturelayerlistmodel.h" -#include "blackgui/views/viewbase.h" - -namespace BlackMisc::Weather -{ - class CTemperatureLayer; -} -namespace BlackGui::Views -{ - //! Airports view - class BLACKGUI_EXPORT CTemperatureLayerView : public CViewBase - { - Q_OBJECT - - public: - //! Constructor - explicit CTemperatureLayerView(QWidget *parent = nullptr); - }; -} -#endif // guard diff --git a/src/blackgui/views/viewbaseweather.cpp b/src/blackgui/views/viewbaseweather.cpp index e774d7b61..1fb481da7 100644 --- a/src/blackgui/views/viewbaseweather.cpp +++ b/src/blackgui/views/viewbaseweather.cpp @@ -6,6 +6,5 @@ namespace BlackGui::Views { template class CViewBase; - template class CViewBase; template class CViewBase; } // namespace diff --git a/src/blackmisc/CMakeLists.txt b/src/blackmisc/CMakeLists.txt index 9c40a7e92..4f7a133f6 100644 --- a/src/blackmisc/CMakeLists.txt +++ b/src/blackmisc/CMakeLists.txt @@ -656,8 +656,6 @@ add_library(misc SHARED weather/cloudlayer.h weather/cloudlayerlist.cpp weather/cloudlayerlist.h - weather/gridpoint.cpp - weather/gridpoint.h weather/metar.cpp weather/metar.h weather/metardecoder.cpp @@ -670,24 +668,6 @@ add_library(misc SHARED weather/presentweatherlist.h weather/registermetadataweather.cpp weather/registermetadataweather.h - weather/temperaturelayer.cpp - weather/temperaturelayer.h - weather/temperaturelayerlist.cpp - weather/temperaturelayerlist.h - weather/visibilitylayer.cpp - weather/visibilitylayer.h - weather/visibilitylayerlist.cpp - weather/visibilitylayerlist.h - weather/weatherdataplugininfo.cpp - weather/weatherdataplugininfo.h - weather/weatherdataplugininfolist.cpp - weather/weatherdataplugininfolist.h - weather/weathergrid.cpp - weather/weathergrid.h - weather/weathergridprovider.cpp - weather/weathergridprovider.h - weather/weatherscenario.cpp - weather/weatherscenario.h weather/windlayer.cpp weather/windlayer.h weather/windlayerlist.cpp diff --git a/src/blackmisc/propertyindexref.h b/src/blackmisc/propertyindexref.h index e0cfc9916..9315d2900 100644 --- a/src/blackmisc/propertyindexref.h +++ b/src/blackmisc/propertyindexref.h @@ -59,9 +59,6 @@ namespace BlackMisc GlobalIndexCCloudLayer = 4100, GlobalIndexCPresentWeather = 4200, GlobalIndexCWindLayer = 4300, - GlobalIndexCTemperatureLayer = 4400, - GlobalIndexCGridPoint = 4500, - GlobalIndexCVisibilityLayer = 4600, GlobalIndexCWeatherScenario = 4700, GlobalIndexICoordinateGeodetic = 5000, GlobalIndexICoordinateWithRelativePosition = 5100, diff --git a/src/blackmisc/simulation/fsx/simconnectutilities.cpp b/src/blackmisc/simulation/fsx/simconnectutilities.cpp index 30f8c0b04..5ec8dfd7d 100644 --- a/src/blackmisc/simulation/fsx/simconnectutilities.cpp +++ b/src/blackmisc/simulation/fsx/simconnectutilities.cpp @@ -17,8 +17,6 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Weather; namespace BlackMisc::Simulation::Fsx { @@ -200,262 +198,12 @@ namespace BlackMisc::Simulation::Fsx return lightMask; } - QString CSimConnectUtilities::convertToSimConnectMetar(const CGridPoint &gridPoint, bool isFSX, bool useWindLayers, bool useVisibilityLayers, bool useCloudLayers, bool useTempLayers) - { - // STATION ID - Q_ASSERT(!gridPoint.getIdentifier().isEmpty()); - QString simconnectMetar = gridPoint.getIdentifier(); - - // SURFACE WINDS/WINDS ALOFT - const CWindLayerList windLayers = useWindLayers ? gridPoint.getWindLayers().sortedBy(&CWindLayer::getLevel) : CWindLayerList(); - simconnectMetar += windsToSimConnectMetar(windLayers, isFSX); - - // VISIBILITY - const CVisibilityLayerList visibilityLayers = useVisibilityLayers ? gridPoint.getVisibilityLayers().sortedBy(&CVisibilityLayer::getBase) : CVisibilityLayerList(); - simconnectMetar += visibilitiesToSimConnectMetar(visibilityLayers); - - // PRESENT CONDITIONS - // todo - - // PARTIAL OBSCURATION - // todo - - // SKY CONDITIONS - const CCloudLayerList cloudLayers = useCloudLayers ? gridPoint.getCloudLayers().sortedBy(&CCloudLayer::getBase) : CCloudLayerList(); - simconnectMetar += cloudsToSimConnectMetar(cloudLayers); - - // TEMPERATURE - const CTemperatureLayerList temperatureLayers = useTempLayers ? gridPoint.getTemperatureLayers().sortedBy(&CTemperatureLayer::getLevel) : CTemperatureLayerList(); - simconnectMetar += temperaturesToSimConnectMetar(temperatureLayers); - - // ALTIMETER - // Format: - // QNNNN - // Q = specifier for altimeter in millibars - // NNNN = altimeter in millibars - if (!gridPoint.getPressureAtMsl().isNull()) - { - static const QString arg1s(" Q%1"); - const int altimeter = gridPoint.getPressureAtMsl().valueInteger(CPressureUnit::mbar()); - simconnectMetar += arg1s.arg(altimeter, 4, 10, QLatin1Char('0')); - } - return simconnectMetar.simplified(); - } - void CSimConnectUtilities::registerMetadata() { qRegisterMetaType(); qRegisterMetaType(); } - QString CSimConnectUtilities::windsToSimConnectMetar(const CWindLayerList &windLayers, bool isFSX) - { - static const QString arg1s("%1"); - - QString simConnectWinds; - bool surface = true; - for (const CWindLayer &windLayer : windLayers) - { - simConnectWinds += QLatin1Char(' '); - - // Format: - // DDDSSSUUU (steady) - // DDDSSSGXXUUU (gusts) - if (windLayer.isDirectionVariable()) - { - // DDD = VRB for variable - simConnectWinds += QLatin1String("VRB"); - } - else - { - if (!windLayer.getSpeed().isNull() && !windLayer.getDirection().isNull()) - { - const int speedKts = windLayer.getSpeed().valueInteger(CSpeedUnit::kts()); - const int directionDeg = windLayer.getDirection().valueInteger(CAngleUnit::deg()); - - simConnectWinds += arg1s.arg(directionDeg, 3, 10, QLatin1Char('0')) % // DDD = Direction (0-360 degrees) - arg1s.arg(speedKts, 3, 10, QLatin1Char('0')); // SSS = Speed - } - } - // XX = Gust speed - const int gustSpeedKts = windLayer.getGustSpeed().valueInteger(CSpeedUnit::kts()); - if (gustSpeedKts > 0) { simConnectWinds += u'G' % arg1s.arg(gustSpeedKts, 2, 10, QLatin1Char('0')); } - - // UUU = Speed units - simConnectWinds += QStringLiteral("KT"); - - if (surface) - { - // Surface extension: - // &DNNNNTS - static const QString surfaceWinds = - "&D" // D = specifier for surface layer - "305" // Surface default depth is 1000 feet or 305m - "NG"; // We don't have turbulence or wind shear information, hence we use the defaults - simConnectWinds += surfaceWinds; - surface = false; - } - else - { - CAltitude altitude = windLayer.getLevel(); - - // this seems to crash FSX, P3D works - // https://www.fsdeveloper.com/forum/threads/setting-winds-aloft.18862/ - if (!altitude.isNull() && !isFSX) - { - altitude.toMeanSeaLevel(); - int altitudeValueMeters = altitude.valueInteger(CLengthUnit::m()); - - // Winds aloft extension: - // &ANNNNTS - simConnectWinds += - u"&A" % // A = specifier for altitude above mean sea-level (MSL) - arg1s.arg(altitudeValueMeters, 4, 10, QLatin1Char('0')) % // NNNN = depth (height) in meters. - u"NG"; // We don't have turbulence or wind shear information, hence we use the defaults - } - } - } - - return QStringLiteral(" ") % simConnectWinds.simplified(); - } - - QString CSimConnectUtilities::visibilitiesToSimConnectMetar(const CVisibilityLayerList &visibilityLayers) - { - // There are several format options, we use the meter format: - // NNNND&BXXXX&DYYYY - QString simconnectVisibilities; - for (const auto &visibilityLayer : visibilityLayers) - { - simconnectVisibilities += QLatin1Char(' '); - - // NNNN = in meters - auto visibility = visibilityLayer.getVisibility().valueInteger(CLengthUnit::m()); - visibility = qMin(9999, visibility); - simconnectVisibilities += QStringLiteral("%1").arg(visibility, 4, 10, QLatin1Char('0')); - - // D = directional variation - // We set NDV - no directional variation - simconnectVisibilities += QLatin1String("NDV"); - - // XXXX = base of visibility layer in meters - const auto base = visibilityLayer.getBase().valueInteger(CLengthUnit::m()); - simconnectVisibilities += QStringLiteral("&B%1").arg(base, 4, 10, QLatin1Char('0')); - - // YYYY = depth of visibility layer in meters - const auto depth = visibilityLayer.getTop().valueInteger(CLengthUnit::m()); - simconnectVisibilities += QStringLiteral("&D%1").arg(depth, 4, 10, QLatin1Char('0')); - } - return simconnectVisibilities; - } - - QString CSimConnectUtilities::cloudsToSimConnectMetar(const CCloudLayerList &cloudLayers) - { - // Format: - // CCCNNN&BXXXX&DYYYY - QString simconnectClouds; - static const QString arg1s("%1"); - for (const CCloudLayer &cloudLayer : cloudLayers) - { - simconnectClouds += QLatin1Char(' '); - - // CCC = Coverage string - switch (cloudLayer.getCoverage()) - { - case CCloudLayer::None: simconnectClouds += QLatin1String("CLR"); break; - case CCloudLayer::Few: simconnectClouds += QLatin1String("FEW"); break; - case CCloudLayer::Broken: simconnectClouds += QLatin1String("BKN"); break; - case CCloudLayer::Overcast: simconnectClouds += QLatin1String("OVC"); break; - case CCloudLayer::Scattered: - default: - simconnectClouds += QLatin1String("SCT"); - } - - // NNN = coded height - // If NNN is 999 the level is 100,000 feet, otherwise it is 100 x NNN in feet - auto level = cloudLayer.getTop().valueInteger(CLengthUnit::ft()) / 100; - // Ignore clouds higher than 99900 feet - if (level > 999) { continue; } - simconnectClouds += arg1s.arg(level, 3, 10, QLatin1Char('0')) % - u'&'; - - // TT = Cloud type - switch (cloudLayer.getClouds()) - { - case CCloudLayer::Cirrus: simconnectClouds += QLatin1String("CI"); break; - case CCloudLayer::Stratus: simconnectClouds += QLatin1String("ST"); break; - case CCloudLayer::Thunderstorm: simconnectClouds += QLatin1String("CB"); break; - case CCloudLayer::Cumulus: - default: - simconnectClouds += QLatin1String("CU"); - } - - // 000 - Unused. - simconnectClouds += QLatin1String("000"); - - // F = Top of cloud - // Default to F - flat - simconnectClouds += QLatin1Char('F'); - // T = Turbulence - // N - None (default) - simconnectClouds += QLatin1Char('N'); - - // P = precipitation rate - // http://wiki.sandaysoft.com/a/Rain_measurement#Rain_Rate - auto precipitationRate = cloudLayer.getPrecipitationRate(); - // Very light rain: precipitation rate is < 0.25 mm/hour - if (precipitationRate < 0.25) { simconnectClouds += QLatin1Char('V'); } - // Light rain: precipitation rate is between 0.25mm/hour and 1.0mm/hour - else if (precipitationRate >= 0.25 && precipitationRate < 1.0) { simconnectClouds += QLatin1Char('L'); } - // Moderate rain: precipitation rate is between 1.0 mm/hour and 4.0 mm/hour - else if (precipitationRate >= 1.0 && precipitationRate < 4.0) { simconnectClouds += QLatin1Char('M'); } - // Heavy rain: recipitation rate is between 4.0 mm/hour and 16.0 mm/hour - else if (precipitationRate >= 4.0 && precipitationRate < 16.0) { simconnectClouds += QLatin1Char('H'); } - // Very heavy rain: precipitation rate is > 16.0 mm/hour - else if (precipitationRate >= 16.0) { simconnectClouds += QLatin1Char('D'); } - - // Q = Type of precipitation - switch (cloudLayer.getPrecipitation()) - { - case CCloudLayer::Rain: simconnectClouds += QLatin1Char('R'); break; - case CCloudLayer::Snow: simconnectClouds += QLatin1Char('S'); break; - default: simconnectClouds += QLatin1Char('N'); - } - - // BBB = Coded base height - // the precipitation ends at this height, set to 0 for it to land on the ground - simconnectClouds += QLatin1String("000"); - - // I = icing rate - // Set to None for now - simconnectClouds += QLatin1String("N"); - } - return simconnectClouds; - } - - QString CSimConnectUtilities::temperaturesToSimConnectMetar(const CTemperatureLayerList &temperatureLayers) - { - // Format: - // TT/DD&ANNNNN - QString simconnectTemperatures; - static const QString arg1s("%1"); - - for (const CTemperatureLayer &temperatureLayer : temperatureLayers) - { - simconnectTemperatures += QLatin1Char(' '); - - const int temperature = temperatureLayer.getTemperature().valueInteger(CTemperatureUnit::C()); - const int dewPoint = temperatureLayer.getDewPoint().valueInteger(CTemperatureUnit::C()); - const int altitude = temperatureLayer.getLevel().valueInteger(CLengthUnit::m()); - - simconnectTemperatures += arg1s.arg(temperature, 2, 10, QLatin1Char('0')) % // TT = temperature in Celsius - u'/' % - arg1s.arg(dewPoint, 2, 10, QLatin1Char('0')) % // DD = dewpoint in Celsius - u"&A" % - arg1s.arg(altitude, 5, 10, QLatin1Char('0')); // NNNNN = altitude of the temperatures in meters. - } - return simconnectTemperatures; - } - CWinDllUtils::DLLInfo CSimConnectUtilities::simConnectDllInfo() { const QList modules = CWinDllUtils::getModules(-1, "simconnect"); diff --git a/src/blackmisc/simulation/fsx/simconnectutilities.h b/src/blackmisc/simulation/fsx/simconnectutilities.h index 5c12fe48b..26c22179a 100644 --- a/src/blackmisc/simulation/fsx/simconnectutilities.h +++ b/src/blackmisc/simulation/fsx/simconnectutilities.h @@ -8,7 +8,6 @@ #include "blackmisc/simulation/simulatorinfo.h" #include "blackmisc/aviation/aircraftlights.h" -#include "blackmisc/weather/gridpoint.h" #include "blackmisc/blackmiscexport.h" #include "blackmisc/windllutils.h" @@ -227,9 +226,6 @@ namespace BlackMisc::Simulation::Fsx //! Lights to states static int lightsToLightStates(const Aviation::CAircraftLights &lights); - //! Converts the weather at gridPoint to a SimConnect METAR string - static QString convertToSimConnectMetar(const Weather::CGridPoint &gridPoint, bool isFSX, bool useWindLayers = true, bool useVisibilityLayers = true, bool useCloudLayers = true, bool useTempLayers = true); - //! Get info about SimConnect DLL static BlackMisc::CWinDllUtils::DLLInfo simConnectDllInfo(); @@ -247,11 +243,6 @@ namespace BlackMisc::Simulation::Fsx //! \return enum element's name static QString resolveEnumToString(const DWORD id, const char *enumName); - static QString windsToSimConnectMetar(const BlackMisc::Weather::CWindLayerList &windLayers, bool isFSX); - static QString visibilitiesToSimConnectMetar(const BlackMisc::Weather::CVisibilityLayerList &visibilityLayers); - static QString cloudsToSimConnectMetar(const BlackMisc::Weather::CCloudLayerList &cloudLayers); - static QString temperaturesToSimConnectMetar(const BlackMisc::Weather::CTemperatureLayerList &temperatureLayers); - //! Hidden constructor CSimConnectUtilities(); }; diff --git a/src/blackmisc/simulation/settings/simulatorsettings.h b/src/blackmisc/simulation/settings/simulatorsettings.h index b540d814f..4d2a62bfe 100644 --- a/src/blackmisc/simulation/settings/simulatorsettings.h +++ b/src/blackmisc/simulation/settings/simulatorsettings.h @@ -9,7 +9,6 @@ #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatorinfo.h" #include "blackmisc/network/textmessage.h" -#include "blackmisc/weather/weatherscenario.h" #include "blackmisc/pq/length.h" #include "blackmisc/settingscache.h" #include "blackmisc/statusmessage.h" @@ -649,26 +648,6 @@ namespace BlackMisc::Simulation::Settings } }; - //! Selected weather scenario - struct TSelectedWeatherScenario : public TSettingTrait - { - //! \copydoc BlackMisc::TSettingTrait::key - static const char *key() { return "simulator/selectedweatherscenario"; } - - //! \copydoc BlackMisc::TSettingTrait::humanReadable - static const QString &humanReadable() - { - static const QString name("Weather scenario"); - return name; - } - - //! \copydoc BlackMisc::TSettingTrait::defaultValue - static const Weather::CWeatherScenario &defaultValue() - { - static const Weather::CWeatherScenario scenario {}; - return scenario; - } - }; } // ns Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSimulatorSettings) diff --git a/src/blackmisc/weather/gridpoint.cpp b/src/blackmisc/weather/gridpoint.cpp deleted file mode 100644 index 6e992c864..000000000 --- a/src/blackmisc/weather/gridpoint.cpp +++ /dev/null @@ -1,109 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/weather/gridpoint.h" -#include "blackmisc/propertyindexref.h" - -#include - -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Geo; -using namespace BlackMisc::PhysicalQuantities; - -BLACK_DEFINE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CGridPoint) - -namespace BlackMisc::Weather -{ - CGridPoint::CGridPoint(const QString &identifier, - const ICoordinateGeodetic &position) : m_identifier(identifier), - m_position(position) - {} - - CGridPoint::CGridPoint(const QString &identifier, - const Geo::ICoordinateGeodetic &position, - const CCloudLayerList &cloudLayers, - const CTemperatureLayerList &temperatureLayers, - const CVisibilityLayerList &visibilityLayers, - const CWindLayerList &windLayers, - const CPressure &pressureAtMsl) : m_identifier(identifier), - m_position(position), - m_cloudLayers(cloudLayers), - m_temperatureLayers(temperatureLayers), - m_visibilityLayers(visibilityLayers), - m_windLayers(windLayers), - m_pressureAtMsl(pressureAtMsl) - {} - - void CGridPoint::copyWeatherDataFrom(const CGridPoint &other) - { - setCloudLayers(other.getCloudLayers()); - setTemperatureLayers(other.getTemperatureLayers()); - setVisibilityLayers(other.getVisibilityLayers()); - setWindLayers(other.getWindLayers()); - setPressureAtMsl(other.getPressureAtMsl()); - } - - QVariant CGridPoint::propertyByIndex(BlackMisc::CPropertyIndexRef index) const - { - if (index.isMyself()) { return QVariant::fromValue(*this); } - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexIdentifier: - return QVariant::fromValue(m_identifier); - case IndexPosition: - return QVariant::fromValue(m_position); - case IndexCloudLayers: - return QVariant::fromValue(m_cloudLayers); - case IndexTemperatureLayers: - return QVariant::fromValue(m_temperatureLayers); - case IndexWindLayers: - return QVariant::fromValue(m_windLayers); - case IndexPressureAtMsl: - return QVariant::fromValue(m_pressureAtMsl); - default: - return CValueObject::propertyByIndex(index); - } - } - - void CGridPoint::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant) - { - if (index.isMyself()) - { - (*this) = variant.value(); - return; - } - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexIdentifier: - setIdentifier(variant.value()); - break; - case IndexPosition: - setPosition(variant.value()); - break; - case IndexCloudLayers: - setCloudLayers(variant.value()); - break; - case IndexTemperatureLayers: - setTemperatureLayers(variant.value()); - break; - case IndexWindLayers: - setWindLayers(variant.value()); - break; - case IndexPressureAtMsl: - setPressureAtMsl(variant.value()); - break; - default: - CValueObject::setPropertyByIndex(index, variant); - break; - } - } - - QString CGridPoint::convertToQString(bool /** i18n **/) const - { - qFatal("Not yet implemented!"); - return {}; - } - -} // namespace diff --git a/src/blackmisc/weather/gridpoint.h b/src/blackmisc/weather/gridpoint.h deleted file mode 100644 index b69ca7952..000000000 --- a/src/blackmisc/weather/gridpoint.h +++ /dev/null @@ -1,140 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_GRIDPOINT_H -#define BLACKMISC_WEATHER_GRIDPOINT_H - -#include "blackmisc/weather/cloudlayerlist.h" -#include "blackmisc/weather/temperaturelayerlist.h" -#include "blackmisc/weather/visibilitylayerlist.h" -#include "blackmisc/weather/windlayerlist.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/pq/pressure.h" -#include "blackmisc/pq/constants.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/propertyindexref.h" -#include "blackmisc/valueobject.h" -#include "blackmisc/metaclass.h" - -#include -#include - -BLACK_DECLARE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CGridPoint) - -namespace BlackMisc::Weather -{ - /*! - * Value object for a cloud layer - */ - class BLACKMISC_EXPORT CGridPoint : public CValueObject - { - public: - //! Properties by index - enum ColumnIndex - { - IndexIdentifier = CPropertyIndexRef::GlobalIndexCGridPoint, - IndexPosition, - IndexCloudLayers, - IndexTemperatureLayers, - IndexWindLayers, - IndexPressureAtMsl - }; - - //! Default constructor. - CGridPoint() = default; - - //! Constructor - CGridPoint(const QString &identifier, - const Geo::ICoordinateGeodetic &position); - - //! Constructor - CGridPoint(const QString &identifier, - const Geo::ICoordinateGeodetic &position, - const CCloudLayerList &cloudLayers, - const CTemperatureLayerList &temperatureLayers, - const CVisibilityLayerList &visibilityLayers, - const CWindLayerList &windLayers, - const PhysicalQuantities::CPressure &pressureAtMsl); - - //! Set identifier - void setIdentifier(const QString &identifier) { m_identifier = identifier; } - - //! Get identifier - const QString &getIdentifier() const { return m_identifier; } - - //! Set position - void setPosition(const Geo::CCoordinateGeodetic &position) { m_position = position; } - - //! Get position - const Geo::CCoordinateGeodetic &getPosition() const { return m_position; } - - //! Set cloud layers - void setCloudLayers(const CCloudLayerList &cloudLayers) { m_cloudLayers = cloudLayers; } - - //! Get cloud layers - const CCloudLayerList &getCloudLayers() const { return m_cloudLayers; } - - //! Set temperature layers - void setTemperatureLayers(const CTemperatureLayerList &temperatureLayers) { m_temperatureLayers = temperatureLayers; } - - //! Get temperature layers - const CTemperatureLayerList &getTemperatureLayers() const { return m_temperatureLayers; } - - //! Set visibility layers - void setVisibilityLayers(const CVisibilityLayerList &visibilityLayers) { m_visibilityLayers = visibilityLayers; } - - //! Get visibility layers - const CVisibilityLayerList &getVisibilityLayers() const { return m_visibilityLayers; } - - //! Set wind layers - void setWindLayers(const CWindLayerList &windLayers) { m_windLayers = windLayers; } - - //! Get wind layers - const CWindLayerList &getWindLayers() const { return m_windLayers; } - - //! Copies all weather data from other without modifying identifier and position. - void copyWeatherDataFrom(const CGridPoint &other); - - //! Set pressure at mean sea level - void setPressureAtMsl(const PhysicalQuantities::CPressure &pressure) { m_pressureAtMsl = pressure; } - - //! Get pressure at mean sea level - const PhysicalQuantities::CPressure &getPressureAtMsl() const { return m_pressureAtMsl; } - - //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - QVariant propertyByIndex(BlackMisc::CPropertyIndexRef index) const; - - //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex - void setPropertyByIndex(BlackMisc::CPropertyIndexRef index, const QVariant &variant); - - //! \copydoc BlackMisc::Mixin::String::toQString - QString convertToQString(bool i18n = false) const; - - private: - QString m_identifier; //!< Identifier is intentionally string based. MSFS uses ICAO, but others don't. - Geo::CCoordinateGeodetic m_position; - CCloudLayerList m_cloudLayers; - CTemperatureLayerList m_temperatureLayers; - CVisibilityLayerList m_visibilityLayers; - CWindLayerList m_windLayers; - PhysicalQuantities::CPressure m_pressureAtMsl = { PhysicalQuantities::CPhysicalQuantitiesConstants::ISASeaLevelPressure() }; - - BLACK_METACLASS( - CGridPoint, - BLACK_METAMEMBER(identifier), - BLACK_METAMEMBER(position), - BLACK_METAMEMBER(cloudLayers), - BLACK_METAMEMBER(temperatureLayers), - BLACK_METAMEMBER(visibilityLayers), - BLACK_METAMEMBER(windLayers), - BLACK_METAMEMBER(pressureAtMsl) - ); - }; -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::Weather::CGridPoint) - -#endif // guard diff --git a/src/blackmisc/weather/registermetadataweather.cpp b/src/blackmisc/weather/registermetadataweather.cpp index 7cbd3dd6f..a060a5fbc 100644 --- a/src/blackmisc/weather/registermetadataweather.cpp +++ b/src/blackmisc/weather/registermetadataweather.cpp @@ -8,19 +8,10 @@ // Weather headers #include "blackmisc/weather/cloudlayer.h" #include "blackmisc/weather/cloudlayerlist.h" -#include "blackmisc/weather/gridpoint.h" #include "blackmisc/weather/metar.h" #include "blackmisc/weather/metarlist.h" #include "blackmisc/weather/presentweather.h" #include "blackmisc/weather/presentweatherlist.h" -#include "blackmisc/weather/temperaturelayer.h" -#include "blackmisc/weather/temperaturelayerlist.h" -#include "blackmisc/weather/visibilitylayer.h" -#include "blackmisc/weather/visibilitylayerlist.h" -#include "blackmisc/weather/weatherdataplugininfo.h" -#include "blackmisc/weather/weatherdataplugininfolist.h" -#include "blackmisc/weather/weathergrid.h" -#include "blackmisc/weather/weatherscenario.h" #include "blackmisc/weather/windlayer.h" #include "blackmisc/weather/windlayerlist.h" @@ -30,19 +21,10 @@ namespace BlackMisc::Weather { CCloudLayer::registerMetadata(); CCloudLayerList::registerMetadata(); - CGridPoint::registerMetadata(); CMetar::registerMetadata(); CMetarList::registerMetadata(); CPresentWeather::registerMetadata(); CPresentWeatherList::registerMetadata(); - CTemperatureLayer::registerMetadata(); - CTemperatureLayerList::registerMetadata(); - CVisibilityLayer::registerMetadata(); - CVisibilityLayerList::registerMetadata(); - CWeatherDataPluginInfo::registerMetadata(); - CWeatherDataPluginInfoList::registerMetadata(); - CWeatherGrid::registerMetadata(); - CWeatherScenario::registerMetadata(); CWindLayer::registerMetadata(); CWindLayerList::registerMetadata(); } diff --git a/src/blackmisc/weather/temperaturelayer.cpp b/src/blackmisc/weather/temperaturelayer.cpp deleted file mode 100644 index c23f1ae92..000000000 --- a/src/blackmisc/weather/temperaturelayer.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/weather/temperaturelayer.h" -#include "blackmisc/propertyindexref.h" - -using namespace BlackMisc::Aviation; -using namespace BlackMisc::PhysicalQuantities; - -BLACK_DEFINE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CTemperatureLayer) - -namespace BlackMisc::Weather -{ - - CTemperatureLayer::CTemperatureLayer(const CAltitude &level, - const CTemperature &value, - const CTemperature &dewPoint, - double relativeHumidity) : m_level(level), m_temperature(value), m_dewPoint(dewPoint), m_relativeHumidity(relativeHumidity) - {} - - QVariant CTemperatureLayer::propertyByIndex(BlackMisc::CPropertyIndexRef index) const - { - if (index.isMyself()) { return QVariant::fromValue(*this); } - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexLevel: - return QVariant::fromValue(m_level); - case IndexTemperature: - return QVariant::fromValue(m_temperature); - case IndexDewPoint: - return QVariant::fromValue(m_dewPoint); - case IndexRelativeHumidity: - return QVariant::fromValue(m_relativeHumidity); - default: - return CValueObject::propertyByIndex(index); - } - } - - void CTemperatureLayer::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant) - { - if (index.isMyself()) - { - (*this) = variant.value(); - return; - } - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexLevel: - setLevel(variant.value()); - break; - case IndexTemperature: - setTemperature(variant.value()); - break; - case IndexDewPoint: - setDewPoint(variant.value()); - break; - case IndexRelativeHumidity: - setRelativeHumidity(variant.value()); - break; - default: - CValueObject::setPropertyByIndex(index, variant); - break; - } - } - - QString CTemperatureLayer::convertToQString(bool /** i18n **/) const - { - return QStringLiteral("%1 %2 at %3").arg(m_temperature.toQString(), QString::number(m_relativeHumidity), m_level.toQString()); - } - -} // namespace diff --git a/src/blackmisc/weather/temperaturelayer.h b/src/blackmisc/weather/temperaturelayer.h deleted file mode 100644 index 79d695d67..000000000 --- a/src/blackmisc/weather/temperaturelayer.h +++ /dev/null @@ -1,100 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_TEMPERATURELAYER_H -#define BLACKMISC_WEATHER_TEMPERATURELAYER_H - -#include "blackmisc/aviation/altitude.h" -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/metaclass.h" -#include "blackmisc/pq/temperature.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/propertyindexref.h" -#include "blackmisc/valueobject.h" - -#include -#include - -BLACK_DECLARE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CTemperatureLayer) - -namespace BlackMisc::Weather -{ - /*! - * Value object for a temperature layer - */ - class BLACKMISC_EXPORT CTemperatureLayer : public CValueObject - { - public: - //! Properties by index - enum ColumnIndex - { - IndexTemperatureLayer = BlackMisc::CPropertyIndexRef::GlobalIndexCTemperatureLayer, - IndexLevel, - IndexTemperature, - IndexDewPoint, - IndexRelativeHumidity - }; - - //! Default constructor. - CTemperatureLayer() = default; - - //! Constructor - CTemperatureLayer(const BlackMisc::Aviation::CAltitude &level, - const PhysicalQuantities::CTemperature &temperature, - const PhysicalQuantities::CTemperature &dewPoint, - double relativeHumidity); - - //! Set level - void setLevel(const BlackMisc::Aviation::CAltitude &level) { m_level = level; } - - //! Get level - BlackMisc::Aviation::CAltitude getLevel() const { return m_level; } - - //! Set temperature - void setTemperature(const PhysicalQuantities::CTemperature &value) { m_temperature = value; } - - //! Get temperature - PhysicalQuantities::CTemperature getTemperature() const { return m_temperature; } - - //! Set dew point - void setDewPoint(const PhysicalQuantities::CTemperature &value) { m_dewPoint = value; } - - //! Get dew point - PhysicalQuantities::CTemperature getDewPoint() const { return m_dewPoint; } - - //! Set relative humidity - void setRelativeHumidity(double value) { m_relativeHumidity = value; } - - //! Get relative humidity - double getRelativeHumidity() const { return m_relativeHumidity; } - - //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - QVariant propertyByIndex(BlackMisc::CPropertyIndexRef index) const; - - //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex - void setPropertyByIndex(BlackMisc::CPropertyIndexRef index, const QVariant &variant); - - //! \copydoc BlackMisc::Mixin::String::toQString - QString convertToQString(bool i18n = false) const; - - private: - BlackMisc::Aviation::CAltitude m_level; - PhysicalQuantities::CTemperature m_temperature = { 15.0, PhysicalQuantities::CTemperatureUnit::C() }; - PhysicalQuantities::CTemperature m_dewPoint; - double m_relativeHumidity = 0; - - BLACK_METACLASS( - CTemperatureLayer, - BLACK_METAMEMBER(level), - BLACK_METAMEMBER(temperature), - BLACK_METAMEMBER(dewPoint), - BLACK_METAMEMBER(relativeHumidity) - ); - }; -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::Weather::CTemperatureLayer) - -#endif // guard diff --git a/src/blackmisc/weather/temperaturelayerlist.cpp b/src/blackmisc/weather/temperaturelayerlist.cpp deleted file mode 100644 index 66b682fae..000000000 --- a/src/blackmisc/weather/temperaturelayerlist.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/aviation/altitude.h" -#include "blackmisc/mixin/mixincompare.h" -#include "blackmisc/weather/temperaturelayerlist.h" - -using namespace BlackMisc::Aviation; - -BLACK_DEFINE_SEQUENCE_MIXINS(BlackMisc::Weather, CTemperatureLayer, CTemperatureLayerList) - -namespace BlackMisc::Weather -{ - CTemperatureLayerList::CTemperatureLayerList(const CSequence &other) : CSequence(other) - {} - - bool CTemperatureLayerList::containsLevel(const CAltitude &level) const - { - return contains(&CTemperatureLayer::getLevel, level); - } - - CTemperatureLayer CTemperatureLayerList::findByLevel(const CAltitude &level) const - { - return findFirstByOrDefault(&CTemperatureLayer::getLevel, level); - } - -} // namespace diff --git a/src/blackmisc/weather/temperaturelayerlist.h b/src/blackmisc/weather/temperaturelayerlist.h deleted file mode 100644 index 96d84a05d..000000000 --- a/src/blackmisc/weather/temperaturelayerlist.h +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_TEMPERATURELAYERLIST_H -#define BLACKMISC_WEATHER_TEMPERATURELAYERLIST_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/sequence.h" -#include "blackmisc/weather/temperaturelayer.h" - -#include -#include -#include - -BLACK_DECLARE_SEQUENCE_MIXINS(BlackMisc::Weather, CTemperatureLayer, CTemperatureLayerList) - -namespace BlackMisc -{ - namespace Aviation - { - class CAltitude; - } - - namespace Weather - { - /*! - * Value object encapsulating a set of temperature layers - */ - class BLACKMISC_EXPORT CTemperatureLayerList : - public CSequence, - public BlackMisc::Mixin::MetaType - { - public: - BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CTemperatureLayerList) - using CSequence::CSequence; - - //! Default constructor. - CTemperatureLayerList() = default; - - //! Construct from a base class object. - CTemperatureLayerList(const CSequence &other); - - //! Contains temperature layer with level? - bool containsLevel(const BlackMisc::Aviation::CAltitude &level) const; - - //! Find cloud layer by level - CTemperatureLayer findByLevel(const BlackMisc::Aviation::CAltitude &level) const; - }; - - } // namespace -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::Weather::CTemperatureLayerList) - -#endif // guard diff --git a/src/blackmisc/weather/visibilitylayer.cpp b/src/blackmisc/weather/visibilitylayer.cpp deleted file mode 100644 index 25b27b8d2..000000000 --- a/src/blackmisc/weather/visibilitylayer.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/weather/visibilitylayer.h" -#include "blackmisc/propertyindexref.h" - -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Aviation; - -BLACK_DEFINE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CVisibilityLayer) - -namespace BlackMisc::Weather -{ - - CVisibilityLayer::CVisibilityLayer(const BlackMisc::Aviation::CAltitude &base, - const BlackMisc::Aviation::CAltitude &top, - const PhysicalQuantities::CLength &visibility) : m_base(base), m_top(top), m_visibility(visibility) - {} - - QVariant CVisibilityLayer::propertyByIndex(BlackMisc::CPropertyIndexRef index) const - { - if (index.isMyself()) { return QVariant::fromValue(*this); } - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexBase: - return QVariant::fromValue(m_base); - case IndexTop: - return QVariant::fromValue(m_top); - case IndexVisibility: - return QVariant::fromValue(m_visibility); - default: - return CValueObject::propertyByIndex(index); - } - } - - void CVisibilityLayer::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant) - { - if (index.isMyself()) - { - (*this) = variant.value(); - return; - } - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexBase: - setBase(variant.value()); - break; - case IndexTop: - setTop(variant.value()); - break; - case IndexVisibility: - setVisibility(variant.value()); - break; - default: - CValueObject::setPropertyByIndex(index, variant); - break; - } - } - - QString CVisibilityLayer::convertToQString(bool /** i18n **/) const - { - QString visibilityAsString = QStringLiteral("Visibility: %1 from %2 to %3"); - visibilityAsString = visibilityAsString.arg(m_visibility.toQString(), m_base.toQString(), m_top.toQString()); - return visibilityAsString; - } - -} // namespace diff --git a/src/blackmisc/weather/visibilitylayer.h b/src/blackmisc/weather/visibilitylayer.h deleted file mode 100644 index 52b602120..000000000 --- a/src/blackmisc/weather/visibilitylayer.h +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_VISIBILITYLAYER_H -#define BLACKMISC_WEATHER_VISIBILITYLAYER_H - -#include "blackmisc/aviation/altitude.h" -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/metaclass.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/propertyindexref.h" -#include "blackmisc/valueobject.h" - -#include -#include - -BLACK_DECLARE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CVisibilityLayer) - -namespace BlackMisc::Weather -{ - /*! - * Value object for a visibility layer - */ - class BLACKMISC_EXPORT CVisibilityLayer : public CValueObject - { - public: - //! Properties by index - enum ColumnIndex - { - IndexBase = BlackMisc::CPropertyIndexRef::GlobalIndexCVisibilityLayer, - IndexTop, - IndexVisibility, - }; - - //! Default constructor. - CVisibilityLayer() = default; - - //! Constructor - CVisibilityLayer(const BlackMisc::Aviation::CAltitude &base, - const BlackMisc::Aviation::CAltitude &top, - const PhysicalQuantities::CLength &visibility); - - //! Set base - void setBase(const BlackMisc::Aviation::CAltitude &base) { m_base = base; } - - //! Get base - BlackMisc::Aviation::CAltitude getBase() const { return m_base; } - - //! Set top - void setTop(const BlackMisc::Aviation::CAltitude &top) { m_top = top; } - - //! Get top - BlackMisc::Aviation::CAltitude getTop() const { return m_top; } - - //! Set visibility - void setVisibility(const PhysicalQuantities::CLength &visibility) { m_visibility = visibility; } - - //! Get visibility - PhysicalQuantities::CLength getVisibility() const { return m_visibility; } - - //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - QVariant propertyByIndex(BlackMisc::CPropertyIndexRef index) const; - - //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex - void setPropertyByIndex(BlackMisc::CPropertyIndexRef index, const QVariant &variant); - - //! \copydoc BlackMisc::Mixin::String::toQString - QString convertToQString(bool i18n = false) const; - - private: - BlackMisc::Aviation::CAltitude m_base; - BlackMisc::Aviation::CAltitude m_top; - PhysicalQuantities::CLength m_visibility { 100, PhysicalQuantities::CLengthUnit::km() }; - - BLACK_METACLASS( - CVisibilityLayer, - BLACK_METAMEMBER(base), - BLACK_METAMEMBER(top), - BLACK_METAMEMBER(visibility) - ); - }; - -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::Weather::CVisibilityLayer) - -#endif // guard diff --git a/src/blackmisc/weather/visibilitylayerlist.cpp b/src/blackmisc/weather/visibilitylayerlist.cpp deleted file mode 100644 index fbdcb8a8f..000000000 --- a/src/blackmisc/weather/visibilitylayerlist.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/aviation/altitude.h" -#include "blackmisc/mixin/mixincompare.h" -#include "blackmisc/weather/visibilitylayerlist.h" - -using namespace BlackMisc::Aviation; - -BLACK_DEFINE_SEQUENCE_MIXINS(BlackMisc::Weather, CVisibilityLayer, CVisibilityLayerList) - -namespace BlackMisc::Weather -{ - CVisibilityLayerList::CVisibilityLayerList(const CSequence &other) : CSequence(other) - {} - - bool CVisibilityLayerList::containsBase(const CAltitude &base) const - { - return contains(&CVisibilityLayer::getBase, base); - } - - CVisibilityLayer CVisibilityLayerList::findByBase(const CAltitude &base) const - { - return findFirstByOrDefault(&CVisibilityLayer::getBase, base); - } - -} // namespace diff --git a/src/blackmisc/weather/visibilitylayerlist.h b/src/blackmisc/weather/visibilitylayerlist.h deleted file mode 100644 index b454e2748..000000000 --- a/src/blackmisc/weather/visibilitylayerlist.h +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_VISIBILITYLAYERLIST_H -#define BLACKMISC_WEATHER_VISIBILITYLAYERLIST_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/sequence.h" -#include "blackmisc/weather/visibilitylayer.h" - -#include -#include -#include - -BLACK_DECLARE_SEQUENCE_MIXINS(BlackMisc::Weather, CVisibilityLayer, CVisibilityLayerList) - -namespace BlackMisc -{ - namespace Aviation - { - class CAltitude; - } - - namespace Weather - { - /*! - * Value object encapsulating a set of visibility layers - */ - class BLACKMISC_EXPORT CVisibilityLayerList : - public CSequence, - public BlackMisc::Mixin::MetaType - { - public: - BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CVisibilityLayerList) - using CSequence::CSequence; - - //! Default constructor. - CVisibilityLayerList() = default; - - //! Construct from a base class object. - CVisibilityLayerList(const CSequence &other); - - //! Contains visibility layer with base? - bool containsBase(const BlackMisc::Aviation::CAltitude &base) const; - - //! Find visibility layer by base - CVisibilityLayer findByBase(const BlackMisc::Aviation::CAltitude &base) const; - }; - - } // namespace -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::Weather::CVisibilityLayerList) - -#endif // guard diff --git a/src/blackmisc/weather/weatherdataplugininfo.cpp b/src/blackmisc/weather/weatherdataplugininfo.cpp deleted file mode 100644 index 7f8b8fb37..000000000 --- a/src/blackmisc/weather/weatherdataplugininfo.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/weather/weatherdataplugininfo.h" - -#include -#include - -using namespace BlackMisc; - -BLACK_DEFINE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CWeatherDataPluginInfo) - -namespace BlackMisc::Weather -{ - CWeatherDataPluginInfo::CWeatherDataPluginInfo(const QString &identifier, const QString &name, const QString &description, bool valid) : m_identifier(identifier), m_name(name), m_description(description), m_valid(valid) - {} - - void CWeatherDataPluginInfo::convertFromJson(const QJsonObject &json) - { - if (json.contains("IID")) // comes from the plugin - { - if (!json.contains("MetaData")) { throw CJsonException("Missing 'MetaData'"); } - - // json data is already validated by CPluginManagerWeatherData - CJsonScope scope("MetaData"); // for stack trace - Q_UNUSED(scope); - CValueObject::convertFromJson(json["MetaData"].toObject()); - m_valid = true; - } - else - { - CValueObject::convertFromJson(json); - } - } - - QString CWeatherDataPluginInfo::convertToQString(bool i18n) const - { - Q_UNUSED(i18n); - return QStringLiteral("%1 (%2)").arg(m_name, m_identifier); - } - -} // ns diff --git a/src/blackmisc/weather/weatherdataplugininfo.h b/src/blackmisc/weather/weatherdataplugininfo.h deleted file mode 100644 index aa552620c..000000000 --- a/src/blackmisc/weather/weatherdataplugininfo.h +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_WEATHERDATAPLUGININFO_H -#define BLACKMISC_WEATHER_WEATHERDATAPLUGININFO_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/metaclass.h" -#include "blackmisc/valueobject.h" - -#include -#include -#include - -BLACK_DECLARE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CWeatherDataPluginInfo) - -namespace BlackMisc::Weather -{ - //! Describing a weather data plugin - class BLACKMISC_EXPORT CWeatherDataPluginInfo : public BlackMisc::CValueObject - { - public: - //! Default constructor - CWeatherDataPluginInfo() = default; - - //! Constructor (used with unit tests) - CWeatherDataPluginInfo(const QString &identifier, const QString &name, - const QString &description, bool valid); - - //! \copydoc BlackMisc::CValueObject::convertFromJson - void convertFromJson(const QJsonObject &json); - - //! Check if the provided plugin metadata is valid. - //! Weather data plugin has to meet the following requirements: - //! * implements org.swift-project.blackcore.weatherdata; - //! * provides plugin name; - bool isValid() const { return m_valid; } - - //! Identifier - const QString &getIdentifier() const { return m_identifier; } - - //! Name - const QString &getName() const { return m_name; } - - //! Description - const QString &getDescription() const { return m_description; } - - //! \copydoc BlackMisc::Mixin::String::toQString - QString convertToQString(bool i18n = false) const; - - private: - QString m_identifier; - QString m_name; - QString m_description; - bool m_valid { false }; - - BLACK_METACLASS( - CWeatherDataPluginInfo, - BLACK_METAMEMBER(identifier, 0, CaseInsensitiveComparison), - BLACK_METAMEMBER(name, 0, DisabledForComparison | DisabledForHashing), - BLACK_METAMEMBER(description, 0, DisabledForComparison | DisabledForHashing), - BLACK_METAMEMBER(valid, 0, DisabledForComparison | DisabledForHashing) - ); - }; -} // ns - -Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherDataPluginInfo) - -#endif // guard diff --git a/src/blackmisc/weather/weatherdataplugininfolist.cpp b/src/blackmisc/weather/weatherdataplugininfolist.cpp deleted file mode 100644 index d42ab0f26..000000000 --- a/src/blackmisc/weather/weatherdataplugininfolist.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/range.h" -#include "blackmisc/weather/weatherdataplugininfo.h" -#include "blackmisc/weather/weatherdataplugininfolist.h" - -#include - -BLACK_DEFINE_SEQUENCE_MIXINS(BlackMisc::Weather, CWeatherDataPluginInfo, CWeatherDataPluginInfoList) - -namespace BlackMisc::Weather -{ - - CWeatherDataPluginInfoList::CWeatherDataPluginInfoList() {} - - QStringList CWeatherDataPluginInfoList::toStringList(bool i18n) const - { - return this->transform([i18n](const CWeatherDataPluginInfo &info) { return info.toQString(i18n); }); - } - -} // namespace diff --git a/src/blackmisc/weather/weatherdataplugininfolist.h b/src/blackmisc/weather/weatherdataplugininfolist.h deleted file mode 100644 index 64470df9e..000000000 --- a/src/blackmisc/weather/weatherdataplugininfolist.h +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_WEATHERDATAPLUGININFOLIST_H -#define BLACKMISC_WEATHER_WEATHERDATAPLUGININFOLIST_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/collection.h" -#include "blackmisc/sequence.h" -#include "blackmisc/weather/weatherdataplugininfo.h" - -#include -#include - -BLACK_DECLARE_SEQUENCE_MIXINS(BlackMisc::Weather, CWeatherDataPluginInfo, CWeatherDataPluginInfoList) - -namespace BlackMisc::Weather -{ - class CWeatherDataPluginInfo; - - //! Value object encapsulating a list of CWeatherDataPluginInfo objects. - class BLACKMISC_EXPORT CWeatherDataPluginInfoList : - public BlackMisc::CSequence, - public BlackMisc::Mixin::MetaType - { - public: - BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CWeatherDataPluginInfoList) - using CSequence::CSequence; - - //! Default constructor - CWeatherDataPluginInfoList(); - - //! Construct from a base class object. - CWeatherDataPluginInfoList(const CSequence &other); - - //! String list with meaningful representations - QStringList toStringList(bool i18n = false) const; - }; -} // ns - -Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherDataPluginInfoList) -Q_DECLARE_METATYPE(BlackMisc::CCollection) - -#endif // guard diff --git a/src/blackmisc/weather/weathergrid.cpp b/src/blackmisc/weather/weathergrid.cpp deleted file mode 100644 index fca75f79c..000000000 --- a/src/blackmisc/weather/weathergrid.cpp +++ /dev/null @@ -1,224 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/weather/cloudlayer.h" -#include "blackmisc/weather/cloudlayerlist.h" -#include "blackmisc/weather/temperaturelayer.h" -#include "blackmisc/weather/temperaturelayerlist.h" -#include "blackmisc/weather/visibilitylayer.h" -#include "blackmisc/weather/visibilitylayerlist.h" -#include "blackmisc/weather/weathergrid.h" -#include "blackmisc/weather/windlayer.h" -#include "blackmisc/weather/windlayerlist.h" - -#include "blackmisc/aviation/altitude.h" -#include "blackmisc/geo/coordinategeodetic.h" -#include "blackmisc/pq/angle.h" -#include "blackmisc/pq/physicalquantity.h" -#include "blackmisc/pq/speed.h" -#include "blackmisc/pq/temperature.h" -#include "blackmisc/pq/units.h" -#include "blackmisc/range.h" -#include "blackmisc/verify.h" - -#include "blackconfig/buildconfig.h" - -using namespace BlackConfig; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Geo; - -BLACK_DEFINE_SEQUENCE_MIXINS(BlackMisc::Weather, CGridPoint, CWeatherGrid) - -namespace BlackMisc::Weather -{ - CWeatherGrid::CWeatherGrid(const CSequence &other) : CSequence(other) - {} - - CWeatherGrid::CWeatherGrid(const ICoordinateGeodetic &coordinate) - { - const CGridPoint p("GLOB", coordinate); - this->push_back(p); - } - - CWeatherGrid CWeatherGrid::findWithinRange(const ICoordinateGeodetic &coordinate, const PhysicalQuantities::CLength &range) const - { - return findBy([&](const CGridPoint &gridPoint) { - return calculateGreatCircleDistance(gridPoint.getPosition(), coordinate) <= range; - }); - } - - CWeatherGrid CWeatherGrid::findClosest(int number, const ICoordinateGeodetic &coordinate) const - { - CWeatherGrid closest = partiallySorted(number, [&](const CGridPoint &a, const CGridPoint &b) { - return calculateEuclideanDistanceSquared(a.getPosition(), coordinate) < calculateEuclideanDistanceSquared(b.getPosition(), coordinate); - }); - closest.truncate(number); - return closest; - } - - QString CWeatherGrid::getDescription(const QString &sep) const - { - QString s; - QTextStream qtout(&s); - for (const CGridPoint &gridPoint : *this) - { - qtout << "Latitude: " << gridPoint.getPosition().latitude().toQString() << sep; - qtout << "Longitude: " << gridPoint.getPosition().longitude().toQString() << sep; - qtout << " MSL Pressure: " << gridPoint.getPressureAtMsl().toQString() << sep; - - CTemperatureLayerList temperatureLayers = gridPoint.getTemperatureLayers(); - temperatureLayers.sort([](const CTemperatureLayer &a, const CTemperatureLayer &b) { return a.getLevel() < b.getLevel(); }); - qtout << " Temperature Layers: " << sep; - for (const auto &temperatureLayer : std::as_const(temperatureLayers)) - { - qtout << " Level: " << temperatureLayer.getLevel().toQString() << sep; - qtout << " Temperature: " << temperatureLayer.getTemperature().toQString() << sep; - qtout << " Relative Humidity: " << temperatureLayer.getRelativeHumidity() << " %" << sep; - } - qtout << sep; - - CWindLayerList windLayers = gridPoint.getWindLayers(); - windLayers.sort([](const CWindLayer &a, const CWindLayer &b) { return a.getLevel() < b.getLevel(); }); - qtout << " Wind Layers: " << sep; - for (const auto &windLayer : std::as_const(windLayers)) - { - qtout << " Level: " << windLayer.getLevel().toQString() << sep; - qtout << " Wind: " << windLayer.getDirection().toQString() << " at " << windLayer.getSpeed().toQString() << sep; - } - qtout << sep; - - qtout << " Cloud Layers: " << sep; - CCloudLayerList cloudLayers = gridPoint.getCloudLayers(); - cloudLayers.sort([](const CCloudLayer &a, const CCloudLayer &b) { return a.getBase() < b.getBase(); }); - for (int i = 0; i < cloudLayers.size(); i++) - { - const CCloudLayer &cloudLayer = cloudLayers[i]; - qtout << " Top: " << cloudLayer.getTop().toQString() << sep; - qtout << " Coverage: " << cloudLayer.getCoveragePercent() << " %" << sep; - qtout << " Precipitation type: " << cloudLayer.getPrecipitation() << sep; - qtout << " Precipitation rate: " << cloudLayer.getPrecipitationRate() << sep; - qtout << " Base: " << cloudLayer.getBase().toQString() << sep; - } - qtout << sep << sep; - } - - qtout.flush(); - return s; - } - - const QVector &CWeatherGrid::getAllScenarios() - { - static const QVector scenarios = { - { CWeatherScenario::ClearSky }, - { CWeatherScenario::Thunderstorm }, - { CWeatherScenario::RealWeather }, - }; - return scenarios; - } - - const CWeatherGrid &CWeatherGrid::getByScenario(const CWeatherScenario &scenario) - { - static const CWeatherGrid emptyGrid {}; - switch (scenario.getIndex()) - { - case CWeatherScenario::ClearSky: return getClearWeatherGrid(); - case CWeatherScenario::Thunderstorm: return getThunderStormGrid(); - default: - // in release versions just return, no need to ASSERT - BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Unknown fixed scenario index requested."); - return emptyGrid; - } - } - - const CWeatherGrid &CWeatherGrid::getClearWeatherGrid() - { - static const CVisibilityLayer visibilityLayer( - CAltitude(0, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CAltitude(2728, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CLength(50, CLengthUnit::mi())); - - static const CTemperatureLayer temperatureLayer( - CAltitude(0, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CTemperature(22, CTemperatureUnit::C()), - CTemperature(7, CTemperatureUnit::C()), - 0); - - static const CCloudLayer cloudLayer( - CAltitude(0, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CAltitude(5000, CAltitude::MeanSeaLevel, CLengthUnit::m()), - 0, CCloudLayer::NoPrecipitation, CCloudLayer::NoClouds, - CCloudLayer::None); - - static const CWindLayer windLayer( - CAltitude(0, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CAngle(0, CAngleUnit::deg()), - CSpeed(0, CSpeedUnit::kts()), - CSpeed(0, CSpeedUnit::kts())); - - static const CGridPoint gridPointGLOB = { - "GLOB", - CCoordinateGeodetic::null(), - CCloudLayerList { cloudLayer }, - CTemperatureLayerList { temperatureLayer }, - CVisibilityLayerList { visibilityLayer }, - CWindLayerList { windLayer }, - { CAltitude::standardISASeaLevelPressure() } - }; - - static const CWeatherGrid weatherGrid = { gridPointGLOB }; - return weatherGrid; - } - - const CWeatherGrid &CWeatherGrid::getThunderStormGrid() - { - static const CVisibilityLayer visibilityLayer( - CAltitude(0, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CAltitude(2728, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CLength(50, CLengthUnit::mi())); - - static const CTemperatureLayer temperatureLayer( - CAltitude(0, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CTemperature(20, CTemperatureUnit::C()), - CTemperature(18, CTemperatureUnit::C()), // min 55 Fahrenheit, 13 Celsius for thunderstorm - 83.1); // Dampness: a moist air layer at ground level with a larger extension and relative humidity above 80%; - - static const CCloudLayer cloudLayer1( - CAltitude(630, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CAltitude(4630, CAltitude::MeanSeaLevel, CLengthUnit::m()), - 5, CCloudLayer::Rain, CCloudLayer::Thunderstorm, - CCloudLayer::Overcast); - - static const CCloudLayer cloudLayer2( - CAltitude(10130, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CAltitude(11130, CAltitude::MeanSeaLevel, CLengthUnit::m()), - 0, CCloudLayer::NoPrecipitation, CCloudLayer::Cirrus, - CCloudLayer::Scattered); - - static const CWindLayer windLayer1( - CAltitude(1110, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CAngle(325.6, CAngleUnit::deg()), - CSpeed(18, CSpeedUnit::kts()), - CSpeed(0, CSpeedUnit::kts())); - - static const CWindLayer windLayer2( - CAltitude(1130, CAltitude::MeanSeaLevel, CLengthUnit::m()), - CAngle(334.8, CAngleUnit::deg()), - CSpeed(21, CSpeedUnit::kts()), - CSpeed(8, CSpeedUnit::kts())); - - static const CGridPoint gridPointGLOB { - "GLOB", - CCoordinateGeodetic::null(), - CCloudLayerList { cloudLayer1, cloudLayer2 }, - CTemperatureLayerList { temperatureLayer }, - CVisibilityLayerList { visibilityLayer }, - CWindLayerList { windLayer1, windLayer2 }, - { CAltitude::standardISASeaLevelPressure() } - }; - - static const CWeatherGrid weatherGrid({ gridPointGLOB }); - return weatherGrid; - } - -} // namespace diff --git a/src/blackmisc/weather/weathergrid.h b/src/blackmisc/weather/weathergrid.h deleted file mode 100644 index fb6512222..000000000 --- a/src/blackmisc/weather/weathergrid.h +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_WEATHERGRID_H -#define BLACKMISC_WEATHER_WEATHERGRID_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/pq/length.h" -#include "blackmisc/sequence.h" -#include "blackmisc/weather/gridpoint.h" -#include "blackmisc/weather/weatherscenario.h" - -#include -#include - -BLACK_DECLARE_SEQUENCE_MIXINS(BlackMisc::Weather, CGridPoint, CWeatherGrid) - -namespace BlackMisc -{ - namespace Geo - { - class ICoordinateGeodetic; - } - namespace Weather - { - /*! - * Value object a list of weather grid points - */ - class BLACKMISC_EXPORT CWeatherGrid : - public CSequence, - public Mixin::MetaType - { - public: - BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CWeatherGrid) - using CSequence::CSequence; - - //! Default constructor. - CWeatherGrid() = default; - - //! Construct from a base class object. - CWeatherGrid(const CSequence &other); - - //! Grid with an initial point at coordinates given - CWeatherGrid(const BlackMisc::Geo::ICoordinateGeodetic &coordinate); - - //! \copydoc Geo::IGeoObjectList::findWithinRange - CWeatherGrid findWithinRange(const BlackMisc::Geo::ICoordinateGeodetic &coordinate, const BlackMisc::PhysicalQuantities::CLength &range) const; - - //! \copydoc Geo::IGeoObjectList::findClosest - CWeatherGrid findClosest(int number, const BlackMisc::Geo::ICoordinateGeodetic &coordinate) const; - - //! Allow to describe myself - QString getDescription(const QString &sep = "\n") const; - - //! Get all available weather scenarios - static const QVector &getAllScenarios(); - - //! Get weather grid by fixed scenario - static const CWeatherGrid &getByScenario(const CWeatherScenario &scenario); - - //! Clear weather grid - static const BlackMisc::Weather::CWeatherGrid &getClearWeatherGrid(); - - //! Thunderstorm grid - static const BlackMisc::Weather::CWeatherGrid &getThunderStormGrid(); - }; - - } // namespace -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherGrid) - -#endif // guard diff --git a/src/blackmisc/weather/weathergridprovider.cpp b/src/blackmisc/weather/weathergridprovider.cpp deleted file mode 100644 index ad5b018e3..000000000 --- a/src/blackmisc/weather/weathergridprovider.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/weather/weathergridprovider.h" - -namespace BlackMisc::Weather -{ - void CWeatherGridAware::requestWeatherGrid(const Geo::ICoordinateGeodetic &position, const CIdentifier &identifier) - { - Q_ASSERT_X(this->hasProvider(), Q_FUNC_INFO, "No object available"); - this->provider()->requestWeatherGrid(position, identifier); - } - - void CWeatherGridAware::requestWeatherGrid( - const CWeatherGrid &weatherGrid, - const CSlot &callback) - { - Q_ASSERT_X(this->hasProvider(), Q_FUNC_INFO, "No object available"); - this->provider()->requestWeatherGrid(weatherGrid, callback); - } -} // namespace diff --git a/src/blackmisc/weather/weathergridprovider.h b/src/blackmisc/weather/weathergridprovider.h deleted file mode 100644 index c9689f306..000000000 --- a/src/blackmisc/weather/weathergridprovider.h +++ /dev/null @@ -1,72 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_WEATHERGRIDPROVIDER_H -#define BLACKMISC_WEATHER_WEATHERGRIDPROVIDER_H - -#include "blackmisc/weather/weathergrid.h" -#include "blackmisc/provider.h" -#include "blackmisc/slot.h" -#include "blackmisc/blackmiscexport.h" - -#include -#include - -namespace BlackMisc -{ - class CIdentifier; - - namespace Weather - { - //! Direct threadsafe in memory access to weather grid - class BLACKMISC_EXPORT IWeatherGridProvider - { - public: - //! Copy constructor - IWeatherGridProvider() = default; - - //! Copy constructor - IWeatherGridProvider(const IWeatherGridProvider &) = delete; - - //! Copy assignment operator - IWeatherGridProvider &operator=(const IWeatherGridProvider &) = delete; - - //! Destructor - virtual ~IWeatherGridProvider() {} - - //! Request weather grid with identifier - virtual void requestWeatherGrid(const BlackMisc::Geo::ICoordinateGeodetic &position, const BlackMisc::CIdentifier &identifier) = 0; - - //! Request weather grid - //! \deprecated Use the position/identifier based version if possible. It will inject the result "in the simulator" - virtual void requestWeatherGrid(const CWeatherGrid &weatherGrid, const CSlot &callback) = 0; - - //! Request weather grid from file - virtual void requestWeatherGridFromFile(const QString &filePath, - const BlackMisc::Weather::CWeatherGrid &weatherGrid, - const BlackMisc::CSlot &callback) = 0; - }; - - //! Delegating class which can be directly used to access an \sa IWeatherGridProvider instance - class BLACKMISC_EXPORT CWeatherGridAware : public IProviderAware - { - public: - //! \copydoc IWeatherGridProvider::requestWeatherGrid - void requestWeatherGrid(const BlackMisc::Geo::ICoordinateGeodetic &position, const BlackMisc::CIdentifier &identifier); - - //! \copydoc IWeatherGridProvider::requestWeatherGrid - //! \deprecated Use the position/identifier based version if possible. It will inject the result "in the simulator" - void requestWeatherGrid(const CWeatherGrid &weatherGrid, const CSlot &callback); - - protected: - //! Constructor - CWeatherGridAware(IWeatherGridProvider *weatherGridProvider) : IProviderAware(weatherGridProvider) { Q_ASSERT(weatherGridProvider); } - }; - } // namespace -} // namespace - -Q_DECLARE_INTERFACE(BlackMisc::Weather::IWeatherGridProvider, "org.swift-project.blackmisc::weather::iweathergridprovider") - -#endif // guard diff --git a/src/blackmisc/weather/weatherscenario.cpp b/src/blackmisc/weather/weatherscenario.cpp deleted file mode 100644 index d8e0b539a..000000000 --- a/src/blackmisc/weather/weatherscenario.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "blackmisc/weather/weatherscenario.h" - -BLACK_DEFINE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CWeatherScenario) - -namespace BlackMisc::Weather -{ - void CWeatherScenario::registerMetadata() - { - CValueObject::registerMetadata(); - qRegisterMetaType(); - } - - CWeatherScenario::CWeatherScenario(CWeatherScenario::ScenarioIndex index) : CWeatherScenario::CWeatherScenario(index, enumToString(index), enumToDescription(index)) - {} - - CWeatherScenario::CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description) : m_scenarioIndex(index), - m_scenarioName(name), - m_scenarioDescription(description) - {} - - QVariant CWeatherScenario::propertyByIndex(BlackMisc::CPropertyIndexRef index) const - { - if (index.isMyself()) { return QVariant::fromValue(*this); } - const ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexScenarioIndex: return QVariant::fromValue(m_scenarioIndex); - case IndexScenarioName: return QVariant::fromValue(m_scenarioName); - case IndexScenarioDescription: return QVariant::fromValue(m_scenarioDescription); - default: - return CValueObject::propertyByIndex(index); - } - } - - void CWeatherScenario::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant) - { - if (index.isMyself()) - { - (*this) = variant.value(); - return; - } - const ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexScenarioIndex: setIndex(variant.value()); break; - case IndexScenarioName: setName(variant.value()); break; - case IndexScenarioDescription: setDescription(variant.value()); break; - default: - CValueObject::setPropertyByIndex(index, variant); - break; - } - } - - QString CWeatherScenario::convertToQString(bool i18n) const - { - Q_UNUSED(i18n) - return m_scenarioName; - } - - const QString &CWeatherScenario::enumToString(CWeatherScenario::ScenarioIndex index) - { - static const QString cs("Clear Sky"); - static const QString thunder("Thunderstorm"); - static const QString real("Realtime Weather"); - switch (index) - { - case ClearSky: return cs; - case Thunderstorm: return thunder; - case RealWeather: return real; - default: break; - } - - static const QString unknown("???"); - return unknown; - } - - const QString &CWeatherScenario::enumToDescription(CWeatherScenario::ScenarioIndex index) - { - static const QString cs("Clear sky, no clouds"); - static const QString thunder("Raining, lightning, several cloud layers"); - static const QString real("As real as it gets..."); - switch (index) - { - case ClearSky: return cs; - case Thunderstorm: return thunder; - case RealWeather: return real; - default: break; - } - - static const QString unknown("???"); - return unknown; - } - -} // namespace diff --git a/src/blackmisc/weather/weatherscenario.h b/src/blackmisc/weather/weatherscenario.h deleted file mode 100644 index 81c4801d0..000000000 --- a/src/blackmisc/weather/weatherscenario.h +++ /dev/null @@ -1,106 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKMISC_WEATHER_WEATHERSCENARIO_H -#define BLACKMISC_WEATHER_WEATHERSCENARIO_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/valueobject.h" - -#include -#include - -BLACK_DECLARE_VALUEOBJECT_MIXINS(BlackMisc::Weather, CWeatherScenario) - -namespace BlackMisc::Weather -{ - /*! - * Value object for fixed weather scenario - */ - class BLACKMISC_EXPORT CWeatherScenario : public CValueObject - { - public: - //! Scenario Index - enum ScenarioIndex - { - ClearSky, - Thunderstorm, - RealWeather - }; - - //! Properties by index - enum ColumnIndex - { - IndexScenarioIndex = CPropertyIndexRef::GlobalIndexCWeatherScenario, - IndexScenarioName, - IndexScenarioDescription - }; - - //! \copydoc BlackMisc::CValueObject::registerMetadata - static void registerMetadata(); - - //! Default constructor. - CWeatherScenario() = default; - - //! Constructor - CWeatherScenario(ScenarioIndex index); - - //! Constructor - CWeatherScenario(ScenarioIndex index, const QString &name, const QString &description); - - //! Set scenario index - void setIndex(ScenarioIndex index) { m_scenarioIndex = index; } - - //! Get scenario index - ScenarioIndex getIndex() const { return m_scenarioIndex; } - - //! Set scenario name - void setName(const QString &name) { m_scenarioName = name; } - - //! Get scenario name - QString getName() const { return m_scenarioName; } - - //! Set scenario description - void setDescription(const QString &description) { m_scenarioDescription = description; } - - //! Get scenario description - QString getDescription() const { return m_scenarioDescription; } - - //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - QVariant propertyByIndex(BlackMisc::CPropertyIndexRef index) const; - - //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex - void setPropertyByIndex(BlackMisc::CPropertyIndexRef index, const QVariant &variant); - - //! \copydoc BlackMisc::Mixin::String::toQString - QString convertToQString(bool i18n = false) const; - - //! Is scenario the real weather scenario? - static bool isRealWeatherScenario(const CWeatherScenario &scenario) { return scenario.getIndex() == RealWeather; } - - //! As string - static const QString &enumToString(ScenarioIndex index); - - //! As string - static const QString &enumToDescription(ScenarioIndex index); - - private: - ScenarioIndex m_scenarioIndex = ClearSky; - QString m_scenarioName = enumToString(ClearSky); - QString m_scenarioDescription = enumToDescription(ClearSky); - - BLACK_METACLASS( - CWeatherScenario, - BLACK_METAMEMBER(scenarioIndex), - BLACK_METAMEMBER(scenarioName), - BLACK_METAMEMBER(scenarioDescription) - ); - }; -} // namespace - -Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherScenario) -Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherScenario::ScenarioIndex) - -#endif // guard diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index fcc32cbef..ac30cf68b 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -2,4 +2,3 @@ # SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 add_subdirectory(simulator) -add_subdirectory(weatherdata/gfs) diff --git a/src/plugins/simulator/emulated/simulatoremulated.cpp b/src/plugins/simulator/emulated/simulatoremulated.cpp index 7aa923795..9f7f91f37 100644 --- a/src/plugins/simulator/emulated/simulatoremulated.cpp +++ b/src/plugins/simulator/emulated/simulatoremulated.cpp @@ -21,7 +21,6 @@ using namespace BlackMisc::Network; using namespace BlackMisc::Math; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::Settings; -using namespace BlackMisc::Weather; using namespace BlackCore; using namespace BlackCore::Context; @@ -30,9 +29,8 @@ namespace BlackSimPlugin::Emulated CSimulatorEmulated::CSimulatorEmulated(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent) { Q_ASSERT_X(sApp && sApp->getIContextSimulator(), Q_FUNC_INFO, "Need context"); @@ -111,13 +109,6 @@ namespace BlackSimPlugin::Emulated return ISimulator::physicallyRemoveMultipleRemoteAircraft(callsigns); } - void CSimulatorEmulated::injectWeatherGrid(const CWeatherGrid &weatherGrid) - { - const QString wg = QStringLiteral("Weather grid with %1 entries").arg(weatherGrid.size()); - if (canLog()) m_monitorWidget->appendReceivingCall(Q_FUNC_INFO, wg); - m_monitorWidget->receivedWeather(weatherGrid); - } - bool CSimulatorEmulated::changeRemoteAircraftModel(const CSimulatedAircraft &aircraft) { if (canLog()) { m_monitorWidget->appendReceivingCall(Q_FUNC_INFO, aircraft.toQString()); } @@ -310,20 +301,6 @@ namespace BlackSimPlugin::Emulated if (m_myAircraft.getSituation() == situation) { return false; } m_myAircraft.setSituation(situation); - if (m_isWeatherActivated) - { - const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() }; - if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get())) - { - if (m_lastWeatherPosition.isNull() || - calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) - { - m_lastWeatherPosition = currentPosition; - requestWeatherGrid(currentPosition, this->identifier()); - } - } - } - return this->updateOwnSituationAndGroundElevation(situation); } @@ -568,22 +545,6 @@ namespace BlackSimPlugin::Emulated this->finishUpdateRemoteAircraftAndSetStatistics(now); } - bool CSimulatorEmulated::requestWeather() - { - if (!m_isWeatherActivated) { return false; } - - this->getOwnAircraftPosition(); - const CCoordinateGeodetic currentPosition = this->getOwnAircraftPosition(); - this->requestWeatherGrid(currentPosition, this->identifier()); - - // crashing version - // kept for testing purposes - // CWeatherGrid g(currentPosition); - // this->requestWeatherGrid(g, { this, &CSimulatorEmulated::injectWeatherGrid}); - - return true; - } - CSimulatorEmulatedListener::CSimulatorEmulatedListener(const CSimulatorPluginInfo &info) : ISimulatorListener(info) {} diff --git a/src/plugins/simulator/emulated/simulatoremulated.h b/src/plugins/simulator/emulated/simulatoremulated.h index 4737725d9..45cffa99a 100644 --- a/src/plugins/simulator/emulated/simulatoremulated.h +++ b/src/plugins/simulator/emulated/simulatoremulated.h @@ -39,7 +39,6 @@ namespace BlackSimPlugin::Emulated const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); @@ -67,7 +66,6 @@ namespace BlackSimPlugin::Emulated virtual BlackMisc::CStatusMessageList getInterpolationMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual bool testSendSituationAndParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CAircraftParts &parts) override; virtual bool requestElevation(const BlackMisc::Geo::ICoordinateGeodetic &reference, const BlackMisc::Aviation::CCallsign &callsign) override; - virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override; // ----- functions just logged ------- virtual bool logicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override; @@ -160,9 +158,6 @@ namespace BlackSimPlugin::Emulated //! \remarks basically does the same as a real driver, obtains data from the interpolator void updateRemoteAircraft(); - //! Request weather - bool requestWeather(); - bool m_log = false; //!< from settings bool m_paused = false; bool m_connected = true; diff --git a/src/plugins/simulator/emulated/simulatoremulatedfactory.cpp b/src/plugins/simulator/emulated/simulatoremulatedfactory.cpp index d938fc978..8f86872af 100644 --- a/src/plugins/simulator/emulated/simulatoremulatedfactory.cpp +++ b/src/plugins/simulator/emulated/simulatoremulatedfactory.cpp @@ -14,10 +14,10 @@ namespace BlackSimPlugin::Emulated BlackCore::ISimulator *CSimulatorEmulatedFactory::create(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, Network::IClientProvider *clientProvider) + Network::IClientProvider *clientProvider) { Q_ASSERT(ownAircraftProvider); - return new CSimulatorEmulated(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, this); + return new CSimulatorEmulated(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, this); } BlackCore::ISimulatorListener *CSimulatorEmulatedFactory::createListener(const CSimulatorPluginInfo &info) diff --git a/src/plugins/simulator/emulated/simulatoremulatedfactory.h b/src/plugins/simulator/emulated/simulatoremulatedfactory.h index c0adad916..834918caa 100644 --- a/src/plugins/simulator/emulated/simulatoremulatedfactory.h +++ b/src/plugins/simulator/emulated/simulatoremulatedfactory.h @@ -28,7 +28,6 @@ namespace BlackSimPlugin::Emulated virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider) override; //! \copydoc BlackCore::ISimulatorFactory::createListener diff --git a/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.cpp b/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.cpp index 49cc31d14..b071116fa 100644 --- a/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.cpp +++ b/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.cpp @@ -15,7 +15,6 @@ using namespace BlackConfig; using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; -using namespace BlackMisc::Weather; using namespace BlackGui; using namespace BlackGui::Components; using namespace BlackGui::Editors; @@ -65,7 +64,6 @@ namespace BlackSimPlugin::Emulated connect(ui->pb_InterpolatorFetch, &QPushButton::clicked, this, &CSimulatorEmulatedMonitorDialog::interpolatorLogButton); connect(ui->pb_EmitAddedFailed, &QPushButton::clicked, this, &CSimulatorEmulatedMonitorDialog::emitSignal); connect(ui->pb_AddAutoPublishData, &QPushButton::clicked, this, &CSimulatorEmulatedMonitorDialog::addAutoPublishTestData); - connect(ui->pb_RequestWeather, &QPushButton::clicked, this, &CSimulatorEmulatedMonitorDialog::requestWeather); ui->led_Receiving->setToolTips("receiving", "idle"); ui->led_Receiving->setShape(CLedWidget::Rounded); @@ -150,11 +148,6 @@ namespace BlackSimPlugin::Emulated this->setSimulatorUiValues(); } - void CSimulatorEmulatedMonitorDialog::receivedWeather(const CWeatherGrid &weatherGrid) - { - ui->te_Weather->setText(weatherGrid.getDescription()); - } - void CSimulatorEmulatedMonitorDialog::onSimulatorValuesChanged() { m_simulator->setCombinedStatus( @@ -323,27 +316,4 @@ namespace BlackSimPlugin::Emulated { return (m_simulator && sGui && !sGui->isShuttingDown()); } - - void CSimulatorEmulatedMonitorDialog::requestWeather() - { - if (!this->canUseSimulator()) { return; } - - /** - if (sGui && sGui->getIContextSimulator()) - { - const CSimulatedAircraft ownAircraft = m_simulator->getOwnAircraft(); - const CWeatherGrid grid{ { "GLOB", ownAircraft.getSituation() } }; - sGui->getIContextSimulator()->requestWeatherGrid(grid, m_simulator->identifier()); - } - **/ - - if (m_simulator->requestWeather()) - { - ui->te_Weather->setText("Requested weather"); - } - else - { - ui->te_Weather->setText("Cannot requested weather, weather activated?"); - } - } } // ns diff --git a/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.h b/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.h index d980deaf3..6c30d65db 100644 --- a/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.h +++ b/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.h @@ -8,7 +8,6 @@ #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/network/textmessage.h" -#include "blackmisc/weather/weathergrid.h" #include "blackmisc/statusmessagelist.h" #include "blackmisc/logcategories.h" #include "blackmisc/identifiable.h" @@ -63,9 +62,6 @@ namespace BlackSimPlugin::Emulated //! The title void updateWindowTitleAndUiValues(const BlackMisc::Simulation::CSimulatorInfo &info); - //! Display weather grid - void receivedWeather(const BlackMisc::Weather::CWeatherGrid &weatherGrid); - private: static int constexpr MaxLogMessages = 500; //!< desired log message number @@ -117,9 +113,6 @@ namespace BlackSimPlugin::Emulated //! Can use the emulated simulator bool canUseSimulator() const; - //! Request weather - void requestWeather(); - QScopedPointer ui; CSimulatorEmulated *m_simulator = nullptr; QTimer m_uiUpdateTimer; diff --git a/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.ui b/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.ui index d6138dfb6..0af536296 100644 --- a/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.ui +++ b/src/plugins/simulator/emulated/simulatoremulatedmonitordialog.ui @@ -457,32 +457,6 @@
- - - Weather - - - - - - Request weather - - - - - - request weather - - - - - - - - - - - API/Log information diff --git a/src/plugins/simulator/flightgear/simulatorflightgear.cpp b/src/plugins/simulator/flightgear/simulatorflightgear.cpp index 2948bafea..205002468 100644 --- a/src/plugins/simulator/flightgear/simulatorflightgear.cpp +++ b/src/plugins/simulator/flightgear/simulatorflightgear.cpp @@ -11,11 +11,6 @@ #include "blackmisc/simulation/simulatedaircraftlist.h" #include "blackmisc/weather/cloudlayer.h" #include "blackmisc/weather/cloudlayerlist.h" -#include "blackmisc/weather/gridpoint.h" -#include "blackmisc/weather/temperaturelayer.h" -#include "blackmisc/weather/temperaturelayerlist.h" -#include "blackmisc/weather/visibilitylayer.h" -#include "blackmisc/weather/visibilitylayerlist.h" #include "blackmisc/weather/windlayer.h" #include "blackmisc/weather/windlayerlist.h" #include "blackmisc/aviation/aircraftengine.h" @@ -84,9 +79,8 @@ namespace BlackSimPlugin::Flightgear CSimulatorFlightgear::CSimulatorFlightgear(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent) { m_watcher = new QDBusServiceWatcher(this); m_watcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); @@ -1004,10 +998,9 @@ namespace BlackSimPlugin::Flightgear ISimulator *CSimulatorFlightgearFactory::create(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider) { - return new CSimulatorFlightgear(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, this); + return new CSimulatorFlightgear(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, this); } CSimulatorFlightgearListener::CSimulatorFlightgearListener(const CSimulatorPluginInfo &info) : ISimulatorListener(info) diff --git a/src/plugins/simulator/flightgear/simulatorflightgear.h b/src/plugins/simulator/flightgear/simulatorflightgear.h index 213c02548..6462a5cfa 100644 --- a/src/plugins/simulator/flightgear/simulatorflightgear.h +++ b/src/plugins/simulator/flightgear/simulatorflightgear.h @@ -14,7 +14,6 @@ #include "blackmisc/simulation/settings/simulatorsettings.h" #include "blackmisc/simulation/settings/fgswiftbussettings.h" #include "blackmisc/simulation/simulatedaircraftlist.h" -#include "blackmisc/weather/weathergrid.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/aviation/callsignset.h" #include "blackmisc/geo/coordinategeodetic.h" @@ -56,10 +55,6 @@ namespace BlackMisc class IOwnAircraftProvider; class IRemoteAircraftProvider; } - namespace Weather - { - class IWeatherGridProvider; - } } namespace BlackSimPlugin::Flightgear @@ -120,7 +115,6 @@ namespace BlackSimPlugin::Flightgear CSimulatorFlightgear(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); @@ -299,7 +293,6 @@ namespace BlackSimPlugin::Flightgear virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider) override; //! \copydoc BlackCore::ISimulatorFactory::createListener diff --git a/src/plugins/simulator/fs9/simulatorfs9.cpp b/src/plugins/simulator/fs9/simulatorfs9.cpp index 49f57b181..40fa7f5cb 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.cpp +++ b/src/plugins/simulator/fs9/simulatorfs9.cpp @@ -29,7 +29,6 @@ using namespace BlackMisc::Geo; using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::FsCommon; -using namespace BlackMisc::Weather; using namespace BlackCore; using namespace BlackSimPlugin::FsCommon; using namespace BlackConfig; @@ -41,9 +40,8 @@ namespace BlackSimPlugin::Fs9 const QSharedPointer &lobbyClient, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent), + QObject *parent) : CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent), m_fs9Host(fs9Host), m_lobbyClient(lobbyClient), m_fsuipc(new CFsuipc(this)) @@ -364,19 +362,6 @@ namespace BlackSimPlugin::Fs9 this->updateOwnParts(simDataOwnAircraft.getParts()); - if (m_isWeatherActivated) - { - if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get())) - { - if (m_lastWeatherPosition.isNull() || - calculateGreatCircleDistance(m_lastWeatherPosition, aircraftSituation).value(CLengthUnit::mi()) > 20) - { - m_lastWeatherPosition = aircraftSituation; - requestWeatherGrid(aircraftSituation, this->identifier()); - } - } - } // weather - // slow updates if (m_ownAircraftUpdateCycles % 25 == 0) { @@ -430,32 +415,6 @@ namespace BlackSimPlugin::Fs9 m_fsuipc->setSimulatorTime(h, m); } - void CSimulatorFs9::injectWeatherGrid(const CWeatherGrid &weatherGrid) - { - if (this->isShuttingDownOrDisconnected()) { return; } - if (weatherGrid.isEmpty()) { return; } - - if (!CThreadUtils::isInThisThread(this)) - { - BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread"); - QPointer myself(this); - QTimer::singleShot(0, this, [=] { - if (!myself) { return; } - myself->injectWeatherGrid(weatherGrid); - }); - return; - } - - if (!m_fsuipc) { return; } - if (!m_fsuipc->isOpened()) { return; } - if (weatherGrid.isEmpty()) - { - CLogMessage(this).info(u"Empty FS9 weather grid"); - return; - } - m_fsuipc->write(weatherGrid); - } - CSimulatorFs9Listener::CSimulatorFs9Listener(const CSimulatorPluginInfo &info, const QSharedPointer &fs9Host, const QSharedPointer &lobbyClient) : ISimulatorListener(info), @@ -554,10 +513,9 @@ namespace BlackSimPlugin::Fs9 ISimulator *CSimulatorFs9Factory::create(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider) { - return new CSimulatorFs9(info, m_fs9Host, m_lobbyClient, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, this); + return new CSimulatorFs9(info, m_fs9Host, m_lobbyClient, ownAircraftProvider, remoteAircraftProvider, clientProvider, this); } ISimulatorListener *CSimulatorFs9Factory::createListener(const CSimulatorPluginInfo &info) diff --git a/src/plugins/simulator/fs9/simulatorfs9.h b/src/plugins/simulator/fs9/simulatorfs9.h index be29abd25..7a4b8d959 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.h +++ b/src/plugins/simulator/fs9/simulatorfs9.h @@ -37,7 +37,6 @@ namespace BlackSimPlugin::Fs9 const QSharedPointer &lobbyClient, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); @@ -59,7 +58,6 @@ namespace BlackSimPlugin::Fs9 virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const override; virtual BlackMisc::CStatusMessageList getInterpolationMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual bool testSendSituationAndParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CAircraftParts &parts) override; - virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override; //! @} protected: @@ -162,7 +160,6 @@ namespace BlackSimPlugin::Fs9 const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider) override; //! \copydoc BlackCore::ISimulatorFactory::createListener diff --git a/src/plugins/simulator/fscommon/fsuipc.h b/src/plugins/simulator/fscommon/fsuipc.h index cc045aec2..cca040009 100644 --- a/src/plugins/simulator/fscommon/fsuipc.h +++ b/src/plugins/simulator/fscommon/fsuipc.h @@ -8,7 +8,6 @@ #include "plugins/simulator/fscommon/fscommonexport.h" #include "blackmisc/simulation/simulatedaircraft.h" -#include "blackmisc/weather/weathergrid.h" #include namespace BlackSimPlugin::FsCommon @@ -40,9 +39,6 @@ namespace BlackSimPlugin::FsCommon //! Write variables bool write(const BlackMisc::Aviation::CTransponder &xpdr); - //! Write weather grid to simulator - bool write(const BlackMisc::Weather::CWeatherGrid &weatherGrid); - //! Set simulator time bool setSimulatorTime(int hour, int minute); @@ -106,17 +102,7 @@ namespace BlackSimPlugin::FsCommon return unknown; } - protected: - //! \copydoc QObject::timerEvent - void timerEvent(QTimerEvent *event) override; - private: - //! Clear weather - void clearAllWeather(); - - //! Process weather - void processWeatherMessages(); - bool m_opened = false; int m_openCount = 0; //!< statistics int m_closeCount = 0; //!< statistics @@ -124,8 +110,6 @@ namespace BlackSimPlugin::FsCommon QString m_lastErrorMessage; QString m_fsuipcVersion; - struct FsuipcWeatherMessage; - QVector m_weatherMessageQueue; unsigned int m_lastTimestamp = 0; //! Integer representing fractional diff --git a/src/plugins/simulator/fscommon/fsuipcdummy.cpp b/src/plugins/simulator/fscommon/fsuipcdummy.cpp index 6dc237adf..8bf2d89b8 100644 --- a/src/plugins/simulator/fscommon/fsuipcdummy.cpp +++ b/src/plugins/simulator/fscommon/fsuipcdummy.cpp @@ -7,16 +7,11 @@ using namespace BlackMisc::Simulation; using namespace BlackMisc::Aviation; -using namespace BlackMisc::Weather; namespace BlackSimPlugin { namespace FsCommon { - //! Dummy FsuipcWeatherMessage - struct CFsuipc::FsuipcWeatherMessage - {}; - CFsuipc::CFsuipc(QObject *parent) : QObject(parent) {} @@ -49,12 +44,6 @@ namespace BlackSimPlugin return false; } - bool CFsuipc::write(const CWeatherGrid &weatherGrid) - { - Q_UNUSED(weatherGrid); - return false; - } - bool CFsuipc::setSimulatorTime(int hour, int minute) { Q_UNUSED(hour); @@ -76,12 +65,6 @@ namespace BlackSimPlugin Q_UNUSED(aircraftParts); return false; } - - void CFsuipc::timerEvent(QTimerEvent *event) - { - Q_UNUSED(event); - } - } // namespace } // namespace diff --git a/src/plugins/simulator/fscommon/fsuipcimpl.cpp b/src/plugins/simulator/fscommon/fsuipcimpl.cpp index ce73072d3..17ec35720 100644 --- a/src/plugins/simulator/fscommon/fsuipcimpl.cpp +++ b/src/plugins/simulator/fscommon/fsuipcimpl.cpp @@ -42,20 +42,9 @@ using namespace BlackMisc::Network; using namespace BlackMisc::Geo; using namespace BlackMisc::Simulation; using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Weather; namespace BlackSimPlugin::FsCommon { - //! Fsuipc weather message - struct CFsuipc::FsuipcWeatherMessage - { - FsuipcWeatherMessage() = default; - FsuipcWeatherMessage(unsigned int offset, const QByteArray &data, int leftTrials); - int m_offset = 0; - QByteArray m_messageData; - int m_leftTrials = 0; - }; - CFsuipc::CFsuipc(QObject *parent) : QObject(parent) { startTimer(100); @@ -162,143 +151,6 @@ namespace BlackSimPlugin::FsCommon return ok && dwResult == 0; } - bool CFsuipc::write(const CWeatherGrid &weatherGrid) - { - Q_ASSERT_X(CThreadUtils::isInThisThread(this), Q_FUNC_INFO, "Open not threadsafe"); - if (!this->isOpened()) { return false; } - - if (weatherGrid.isEmpty()) { return false; } - this->clearAllWeather(); - CLogMessage(this).debug(u"FSUIPC cleared weather"); - - const CGridPoint gridPoint = weatherGrid.front(); - NewWeather nw; - - // Clear new weather - nw.uCommand = NW_SET; - nw.uFlags = 0; - nw.ulSignature = 0; - nw.uDynamics = 0; - for (std::size_t i = 0; i < sizeof(nw.uSpare) / sizeof(nw.uSpare[0]); i++) { nw.uSpare[i] = 0; } - - nw.dLatitude = 0.0; - nw.dLongitude = 0.0; - nw.nElevation = 0; - nw.ulTimeStamp = 0; - nw.nTempCtr = 0; - nw.nWindsCtr = 0; - nw.nCloudsCtr = 0; - nw.nElevation = 0; // meters * 65536; - nw.nUpperVisCtr = 0; - - // todo: Take station from weather grid - memcpy(nw.chICAO, "GLOB", 4); - - const CVisibilityLayerList visibilityLayers = gridPoint.getVisibilityLayers().sortedBy(&CVisibilityLayer::getBase); - const auto surfaceVisibility = visibilityLayers.frontOrDefault(); - NewVis vis; - vis.LowerAlt = static_cast(surfaceVisibility.getBase().valueInteger(CLengthUnit::m())); - vis.UpperAlt = static_cast(surfaceVisibility.getTop().valueInteger(CLengthUnit::m())); - // Range is measured in: 1/100ths sm - vis.Range = static_cast(surfaceVisibility.getVisibility().value(CLengthUnit::SM()) * 100); - vis.Spare = 0; - nw.Vis = vis; - - for (const auto &visibilityLayer : visibilityLayers) - { - vis.LowerAlt = static_cast(visibilityLayer.getBase().valueInteger(CLengthUnit::m())); - vis.UpperAlt = static_cast(visibilityLayer.getTop().valueInteger(CLengthUnit::m())); - vis.Range = static_cast(visibilityLayer.getVisibility().value(CLengthUnit::SM()) * 100); - vis.Spare = 0; - nw.UpperVis[nw.nUpperVisCtr++] = vis; - } - CLogMessage(this).debug(u"FSUIPC updated %1 visibility layers") << visibilityLayers.size(); - - const CTemperatureLayerList temperatureLayers = gridPoint.getTemperatureLayers().sortedBy(&CTemperatureLayer::getLevel); - for (const auto &temperatureLayer : temperatureLayers) - { - NewTemp temp; - temp.Alt = static_cast(temperatureLayer.getLevel().valueInteger(CLengthUnit::m())); - temp.Day = static_cast(temperatureLayer.getTemperature().valueInteger(CTemperatureUnit::C())); - temp.DayNightVar = 3; - temp.DewPoint = static_cast(temperatureLayer.getDewPoint().value(CTemperatureUnit::C())); - nw.Temp[nw.nTempCtr++] = temp; - } - CLogMessage(this).debug(u"FSUIPC updated %1 temperature layers") << temperatureLayers.size(); - - const CCloudLayerList cloudLayers = gridPoint.getCloudLayers().sortedBy(&CCloudLayer::getBase); - for (const auto &cloudLayer : cloudLayers) - { - NewCloud cloud; - switch (cloudLayer.getCoverage()) - { - case CCloudLayer::None: cloud.Coverage = 0; break; - case CCloudLayer::Few: cloud.Coverage = 2; break; - case CCloudLayer::Scattered: cloud.Coverage = 4; break; - case CCloudLayer::Broken: cloud.Coverage = 6; break; - case CCloudLayer::Overcast: cloud.Coverage = 8; break; - default: cloud.Coverage = 0; break; - } - - cloud.Deviation = 0; - cloud.Icing = 0; - cloud.LowerAlt = static_cast(cloudLayer.getBase().valueInteger(CLengthUnit::m())); - cloud.PrecipBase = 0; - - // Light rain - when the precipitation rate is < 2.5 mm (0.098 in) per hour - // Moderate rain - when the precipitation rate is between 2.5 mm (0.098 in) - 7.6 mm (0.30 in) or 10 mm (0.39 in) per hour - // Heavy rain - when the precipitation rate is > 7.6 mm (0.30 in) per hour, or between 10 mm (0.39 in) and 50 mm (2.0 in) per hour - // Violent rain - when the precipitation rate is > 50 mm (2.0 in) per hour - - cloud.PrecipRate = 2 * static_cast(cloudLayer.getPrecipitationRate()); - cloud.PrecipType = static_cast(cloudLayer.getPrecipitation()); - cloud.TopShape = 0; - cloud.Turbulence = 0; - - switch (cloudLayer.getClouds()) - { - case CCloudLayer::NoClouds: cloud.Type = 0; break; - case CCloudLayer::Cirrus: cloud.Type = 1; break; - case CCloudLayer::Stratus: cloud.Type = 8; break; - case CCloudLayer::Cumulus: cloud.Type = 9; break; - case CCloudLayer::Thunderstorm: cloud.Type = 10; break; - default: cloud.Type = 0; - } - - cloud.UpperAlt = static_cast(cloudLayer.getTop().valueInteger(CLengthUnit::m())); - nw.Cloud[nw.nCloudsCtr++] = cloud; - } - CLogMessage(this).debug(u"FSUIPC updated %1 cloud layers") << cloudLayers.size(); - - const CWindLayerList windLayers = gridPoint.getWindLayers().sortedBy(&CWindLayer::getLevel); - for (const auto &windLayer : windLayers) - { - NewWind wind; - wind.Direction = static_cast(windLayer.getDirection().value(CAngleUnit::deg()) * 65536 / 360.0); - wind.GapAbove = 0; - wind.Gust = static_cast(windLayer.getGustSpeed().valueInteger(CSpeedUnit::kts())); - wind.Shear = 0; - wind.Speed = static_cast(windLayer.getSpeed().valueInteger(CSpeedUnit::kts())); - wind.SpeedFract = 0; - wind.Turbulence = 0; - wind.UpperAlt = static_cast(windLayer.getLevel().valueInteger(CLengthUnit::m())); - wind.Variance = 0; - nw.Wind[nw.nWindsCtr++] = wind; - } - CLogMessage(this).debug(u"FSUIPC updated %1 wind layers") << windLayers.size(); - - NewPress press; - press.Drift = 0; - // Pressure is measured in: 16 x mb - press.Pressure = static_cast(gridPoint.getPressureAtMsl().value(CPressureUnit::mbar()) * 16); - nw.Press = press; - - // writing will take place in - QByteArray weatherData(reinterpret_cast(&nw), sizeof(NewWeather)); - m_weatherMessageQueue.append(FsuipcWeatherMessage(0xC800, weatherData, 5)); - return true; - } - bool CFsuipc::setSimulatorTime(int hour, int minute) { Q_ASSERT_X(CThreadUtils::isInThisThread(this), Q_FUNC_INFO, "Open not threadsafe"); @@ -540,67 +392,6 @@ namespace BlackSimPlugin::FsCommon return read; } - void CFsuipc::timerEvent(QTimerEvent *event) - { - Q_UNUSED(event) - processWeatherMessages(); - } - - CFsuipc::FsuipcWeatherMessage::FsuipcWeatherMessage(unsigned int offset, const QByteArray &data, int leftTrials) : m_offset(static_cast(offset)), m_messageData(data), m_leftTrials(leftTrials) - {} - - void CFsuipc::clearAllWeather() - { - if (!this->isOpened()) { return; } - - // clear all weather - NewWeather nw; - - // Clear new weather - nw.uCommand = NW_CLEAR; - nw.uFlags = 0; - nw.ulSignature = 0; - nw.uDynamics = 0; - for (std::size_t i = 0; i < sizeof(nw.uSpare) / sizeof(nw.uSpare[0]); i++) { nw.uSpare[i] = 0; } - - nw.dLatitude = 0.0; - nw.dLongitude = 0.0; - nw.nElevation = 0; - nw.ulTimeStamp = 0; - nw.nTempCtr = 0; - nw.nWindsCtr = 0; - nw.nCloudsCtr = 0; - const QByteArray clearWeather(reinterpret_cast(&nw), sizeof(NewWeather)); - m_weatherMessageQueue.append(FsuipcWeatherMessage(0xC800, clearWeather, 1)); - } - - void CFsuipc::processWeatherMessages() - { - if (m_weatherMessageQueue.isEmpty()) { return; } - if (!m_opened) { return; } - FsuipcWeatherMessage &weatherMessage = m_weatherMessageQueue.first(); - - DWORD dwResult; - weatherMessage.m_leftTrials--; - FSUIPC_Write(static_cast(weatherMessage.m_offset), static_cast(weatherMessage.m_messageData.size()), reinterpret_cast(weatherMessage.m_messageData.data()), &dwResult); - - unsigned int timeStamp = 0; - FSUIPC_Read(0xC824, sizeof(timeStamp), &timeStamp, &dwResult); - FSUIPC_Process(&dwResult); - if (timeStamp > m_lastTimestamp) - { - m_weatherMessageQueue.removeFirst(); - m_lastTimestamp = timeStamp; - return; - } - - if (weatherMessage.m_leftTrials < 1) - { - CLogMessage(this).debug() << "Number of trials reached for weather message. Dropping it."; - m_weatherMessageQueue.removeFirst(); - } - } - double CFsuipc::intToFractional(double fractional) { const double f = fractional / 10.0; diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.cpp b/src/plugins/simulator/fscommon/simulatorfscommon.cpp index d693a88a3..f9dd473e9 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.cpp +++ b/src/plugins/simulator/fscommon/simulatorfscommon.cpp @@ -14,7 +14,6 @@ using namespace BlackMisc::Geo; using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::FsCommon; -using namespace BlackMisc::Weather; using namespace BlackCore; using namespace BlackSimPlugin::Common; @@ -24,9 +23,8 @@ namespace BlackSimPlugin::FsCommon const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *renderedAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, renderedAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, renderedAircraftProvider, clientProvider, parent) { CSimulatorFsCommon::registerHelp(); } diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.h b/src/plugins/simulator/fscommon/simulatorfscommon.h index 311d6cfb1..b7309a85c 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.h +++ b/src/plugins/simulator/fscommon/simulatorfscommon.h @@ -42,7 +42,6 @@ namespace BlackSimPlugin::FsCommon CSimulatorFsCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); diff --git a/src/plugins/simulator/fsx/simulatorfsx.cpp b/src/plugins/simulator/fsx/simulatorfsx.cpp index a11d401fd..b333f974b 100644 --- a/src/plugins/simulator/fsx/simulatorfsx.cpp +++ b/src/plugins/simulator/fsx/simulatorfsx.cpp @@ -11,7 +11,6 @@ using namespace BlackMisc::Geo; using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::FsCommon; -using namespace BlackMisc::Weather; using namespace BlackCore; namespace BlackSimPlugin::Fsx @@ -19,9 +18,8 @@ namespace BlackSimPlugin::Fsx CSimulatorFsx::CSimulatorFsx(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorFsxCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : CSimulatorFsxCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent) { this->setDefaultModel( { "Boeing 737-800 Paint1", diff --git a/src/plugins/simulator/fsx/simulatorfsx.h b/src/plugins/simulator/fsx/simulatorfsx.h index 138d9d5f3..e2dd0c0eb 100644 --- a/src/plugins/simulator/fsx/simulatorfsx.h +++ b/src/plugins/simulator/fsx/simulatorfsx.h @@ -20,7 +20,6 @@ namespace BlackSimPlugin::Fsx CSimulatorFsx(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); diff --git a/src/plugins/simulator/fsx/simulatorfsxfactory.cpp b/src/plugins/simulator/fsx/simulatorfsxfactory.cpp index c8b4cd11d..5f492b21c 100644 --- a/src/plugins/simulator/fsx/simulatorfsxfactory.cpp +++ b/src/plugins/simulator/fsx/simulatorfsxfactory.cpp @@ -7,7 +7,6 @@ using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; -using namespace BlackMisc::Weather; using namespace BlackCore; namespace BlackSimPlugin::Fsx @@ -15,11 +14,10 @@ namespace BlackSimPlugin::Fsx ISimulator *CSimulatorFsxFactory::create(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider) { Q_ASSERT(ownAircraftProvider); - return new CSimulatorFsx(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, this); + return new CSimulatorFsx(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, this); } ISimulatorListener *CSimulatorFsxFactory::createListener(const CSimulatorPluginInfo &info) diff --git a/src/plugins/simulator/fsx/simulatorfsxfactory.h b/src/plugins/simulator/fsx/simulatorfsxfactory.h index 04b0922ee..56e437e3b 100644 --- a/src/plugins/simulator/fsx/simulatorfsxfactory.h +++ b/src/plugins/simulator/fsx/simulatorfsxfactory.h @@ -28,7 +28,6 @@ namespace BlackSimPlugin::Fsx virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider) override; //! \copydoc BlackCore::ISimulatorFactory::createListener diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index f7215cd37..48e49fba2 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -41,7 +41,6 @@ using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::FsCommon; using namespace BlackMisc::Simulation::Fsx; using namespace BlackMisc::Simulation::Settings; -using namespace BlackMisc::Weather; using namespace BlackCore; using namespace BlackSimPlugin::FsCommon; @@ -50,9 +49,8 @@ namespace BlackSimPlugin::FsxCommon CSimulatorFsxCommon::CSimulatorFsxCommon(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent) { Q_ASSERT_X(ownAircraftProvider, Q_FUNC_INFO, "Missing provider"); Q_ASSERT_X(remoteAircraftProvider, Q_FUNC_INFO, "Missing provider"); @@ -797,20 +795,6 @@ namespace BlackSimPlugin::FsxCommon // slower updates if (m_ownAircraftUpdateCycles % 10 == 0) { - if (m_isWeatherActivated) - { - const auto currentPosition = CCoordinateGeodetic { aircraftSituation.latitude(), aircraftSituation.longitude() }; - if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get())) - { - if (m_lastWeatherPosition.isNull() || - calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20) - { - m_lastWeatherPosition = currentPosition; - requestWeatherGrid(currentPosition, this->identifier()); - } - } - } - // init terrain probes here has the advantage we can also switch it on/off at runtime if (m_useFsxTerrainProbe && !m_initFsxTerrainProbes) { @@ -2379,41 +2363,6 @@ namespace BlackSimPlugin::FsxCommon } } - void CSimulatorFsxCommon::injectWeatherGrid(const CWeatherGrid &weatherGrid) - { - if (this->isShuttingDownOrDisconnected()) { return; } - if (weatherGrid.isEmpty()) { return; } - - if (!CThreadUtils::isInThisThread(this)) - { - BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread"); - QPointer myself(this); - QTimer::singleShot(0, this, [=] { - if (!myself) { return; } - myself->injectWeatherGrid(weatherGrid); - }); - return; - } - - // So far, there is only global weather - const bool isFSX = this->getSimulatorPluginInfo().getSimulatorInfo().isFSX(); - CGridPoint glob = weatherGrid.frontOrDefault(); - glob.setIdentifier("GLOB"); - const QString metar = CSimConnectUtilities::convertToSimConnectMetar(glob, isFSX); - const QByteArray metarBa = toFsxChar(metar); - - // send - SimConnect_WeatherSetModeCustom(m_hSimConnect); - SimConnect_WeatherSetModeGlobal(m_hSimConnect); - - if (!metarBa.isEmpty()) - { - // Q_ASSERT_X(metarBa.back() == 0, Q_FUNC_INFO, "Need 0 terminated string"); - SimConnect_WeatherSetObservation(m_hSimConnect, 0, metarBa.constData()); - CLogMessage(this).debug(u"Injecting weather: %1") << metar; - } - } - bool CSimulatorFsxCommon::requestPositionDataForSimObject(const CSimConnectObject &simObject, SIMCONNECT_PERIOD period) { if (this->isShuttingDownOrDisconnected()) { return false; } diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h index 2ff2c5cbe..448f00c13 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.h @@ -127,7 +127,6 @@ namespace BlackSimPlugin::FsxCommon CSimulatorFsxCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); @@ -153,7 +152,6 @@ namespace BlackSimPlugin::FsxCommon virtual void setFlightNetworkConnected(bool connected) override; virtual BlackMisc::CStatusMessageList getInterpolationMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual bool testSendSituationAndParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CAircraftParts &parts) override; - virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override; //! @} //! \copydoc BlackMisc::Simulation::ISimulationEnvironmentProvider::requestElevation diff --git a/src/plugins/simulator/msfs/simulatormsfs.cpp b/src/plugins/simulator/msfs/simulatormsfs.cpp index e5aef72e9..90f389343 100644 --- a/src/plugins/simulator/msfs/simulatormsfs.cpp +++ b/src/plugins/simulator/msfs/simulatormsfs.cpp @@ -11,7 +11,6 @@ using namespace BlackMisc::Geo; using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::FsCommon; -using namespace BlackMisc::Weather; using namespace BlackCore; using namespace BlackSimPlugin::FsxCommon; @@ -20,9 +19,8 @@ namespace BlackSimPlugin::Msfs CSimulatorMsFs::CSimulatorMsFs(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorFsxCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : CSimulatorFsxCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent) { this->setDefaultModel( { "Airbus A320 Neo Asobo", diff --git a/src/plugins/simulator/msfs/simulatormsfs.h b/src/plugins/simulator/msfs/simulatormsfs.h index beb079664..8178a2ffb 100644 --- a/src/plugins/simulator/msfs/simulatormsfs.h +++ b/src/plugins/simulator/msfs/simulatormsfs.h @@ -20,7 +20,6 @@ namespace BlackSimPlugin::Msfs CSimulatorMsFs(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); diff --git a/src/plugins/simulator/msfs/simulatormsfsfactory.cpp b/src/plugins/simulator/msfs/simulatormsfsfactory.cpp index f7e7d2309..aa33ced45 100644 --- a/src/plugins/simulator/msfs/simulatormsfsfactory.cpp +++ b/src/plugins/simulator/msfs/simulatormsfsfactory.cpp @@ -7,7 +7,6 @@ using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; -using namespace BlackMisc::Weather; using namespace BlackCore; namespace BlackSimPlugin::Msfs @@ -15,11 +14,10 @@ namespace BlackSimPlugin::Msfs ISimulator *CSimulatorMsFsFactory::create(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider) { Q_ASSERT(ownAircraftProvider); - return new CSimulatorMsFs(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, this); + return new CSimulatorMsFs(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, this); } ISimulatorListener *CSimulatorMsFsFactory::createListener(const CSimulatorPluginInfo &info) diff --git a/src/plugins/simulator/msfs/simulatormsfsfactory.h b/src/plugins/simulator/msfs/simulatormsfsfactory.h index 7169694a7..7cf639031 100644 --- a/src/plugins/simulator/msfs/simulatormsfsfactory.h +++ b/src/plugins/simulator/msfs/simulatormsfsfactory.h @@ -28,7 +28,6 @@ namespace BlackSimPlugin::Msfs virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider) override; //! \copydoc BlackCore::ISimulatorFactory::createListener diff --git a/src/plugins/simulator/p3d/simulatorp3d.cpp b/src/plugins/simulator/p3d/simulatorp3d.cpp index e1135e4b7..bdee10e57 100644 --- a/src/plugins/simulator/p3d/simulatorp3d.cpp +++ b/src/plugins/simulator/p3d/simulatorp3d.cpp @@ -17,7 +17,6 @@ using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::FsCommon; using namespace BlackSimPlugin::FsxCommon; -using namespace BlackMisc::Weather; using namespace BlackCore; using namespace BlackSimPlugin::FsCommon; @@ -26,9 +25,8 @@ namespace BlackSimPlugin::P3D CSimulatorP3D::CSimulatorP3D(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorFsxCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : CSimulatorFsxCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent) { // set build/sim specific SimConnectProc, which is the FSX SimConnectProc on WIN32 systems if (CBuildConfig::isCompiledWithP3DSupport() && CBuildConfig::isRunningOnWindowsNtPlatform() && CBuildConfig::buildWordSize() == 64) diff --git a/src/plugins/simulator/p3d/simulatorp3d.h b/src/plugins/simulator/p3d/simulatorp3d.h index c1539ff77..ac1aca80e 100644 --- a/src/plugins/simulator/p3d/simulatorp3d.h +++ b/src/plugins/simulator/p3d/simulatorp3d.h @@ -32,7 +32,6 @@ namespace BlackSimPlugin::P3D CSimulatorP3D(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); diff --git a/src/plugins/simulator/p3d/simulatorp3dfactory.cpp b/src/plugins/simulator/p3d/simulatorp3dfactory.cpp index ad2e16a83..30c6a4739 100644 --- a/src/plugins/simulator/p3d/simulatorp3dfactory.cpp +++ b/src/plugins/simulator/p3d/simulatorp3dfactory.cpp @@ -6,7 +6,6 @@ #include "blackmisc/simulation/simulatorplugininfo.h" using namespace BlackMisc::Simulation; -using namespace BlackMisc::Weather; using namespace BlackMisc::Network; namespace BlackSimPlugin::P3D @@ -14,11 +13,10 @@ namespace BlackSimPlugin::P3D BlackCore::ISimulator *CSimulatorP3DFactory::create(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider) { Q_ASSERT(ownAircraftProvider); - return new CSimulatorP3D(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, this); + return new CSimulatorP3D(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, this); } BlackCore::ISimulatorListener *CSimulatorP3DFactory::createListener(const CSimulatorPluginInfo &info) diff --git a/src/plugins/simulator/p3d/simulatorp3dfactory.h b/src/plugins/simulator/p3d/simulatorp3dfactory.h index bed65a4bd..de40044ca 100644 --- a/src/plugins/simulator/p3d/simulatorp3dfactory.h +++ b/src/plugins/simulator/p3d/simulatorp3dfactory.h @@ -28,7 +28,6 @@ namespace BlackSimPlugin::P3D virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider) override; //! \copydoc BlackCore::ISimulatorFactory::createListener diff --git a/src/plugins/simulator/plugincommon/simulatorplugincommon.cpp b/src/plugins/simulator/plugincommon/simulatorplugincommon.cpp index db7941c50..4656012f5 100644 --- a/src/plugins/simulator/plugincommon/simulatorplugincommon.cpp +++ b/src/plugins/simulator/plugincommon/simulatorplugincommon.cpp @@ -12,7 +12,6 @@ using namespace BlackCore; using namespace BlackMisc; using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; -using namespace BlackMisc::Weather; namespace BlackSimPlugin::Common { @@ -20,9 +19,8 @@ namespace BlackSimPlugin::Common const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *renderedAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : ISimulator(info, ownAircraftProvider, renderedAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : ISimulator(info, ownAircraftProvider, renderedAircraftProvider, clientProvider, parent) { CSimulatorPluginCommon::registerHelp(); } diff --git a/src/plugins/simulator/plugincommon/simulatorplugincommon.h b/src/plugins/simulator/plugincommon/simulatorplugincommon.h index 46921da17..07c1ed85a 100644 --- a/src/plugins/simulator/plugincommon/simulatorplugincommon.h +++ b/src/plugins/simulator/plugincommon/simulatorplugincommon.h @@ -38,7 +38,6 @@ namespace BlackSimPlugin::Common CSimulatorPluginCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); diff --git a/src/plugins/simulator/xplane/CMakeLists.txt b/src/plugins/simulator/xplane/CMakeLists.txt index 6e9843b21..78a9d5bc1 100644 --- a/src/plugins/simulator/xplane/CMakeLists.txt +++ b/src/plugins/simulator/xplane/CMakeLists.txt @@ -11,8 +11,6 @@ add_library(simulatorxplane SHARED xswiftbusserviceproxy.h xswiftbustrafficproxy.cpp xswiftbustrafficproxy.h - xswiftbusweatherproxy.cpp - xswiftbusweatherproxy.h ) include(${PROJECT_SOURCE_DIR}/cmake/xswiftbus_tools.cmake) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 7f5091225..fa74eb8ef 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -5,7 +5,6 @@ #include "qcompilerdetection.h" #include "xswiftbusserviceproxy.h" #include "xswiftbustrafficproxy.h" -#include "xswiftbusweatherproxy.h" #include "blackcore/aircraftmatcher.h" #include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/simulation/simulatedaircraft.h" @@ -13,11 +12,6 @@ #include "blackmisc/simulation/settings/xswiftbussettingsqtfree.inc" #include "blackmisc/weather/cloudlayer.h" #include "blackmisc/weather/cloudlayerlist.h" -#include "blackmisc/weather/gridpoint.h" -#include "blackmisc/weather/temperaturelayer.h" -#include "blackmisc/weather/temperaturelayerlist.h" -#include "blackmisc/weather/visibilitylayer.h" -#include "blackmisc/weather/visibilitylayerlist.h" #include "blackmisc/weather/windlayer.h" #include "blackmisc/weather/windlayerlist.h" #include "blackmisc/aviation/aircraftengine.h" @@ -91,9 +85,8 @@ namespace BlackSimPlugin::XPlane CSimulatorXPlane::CSimulatorXPlane(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider, - QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, parent) + QObject *parent) : CSimulatorPluginCommon(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, parent) { m_watcher = new QDBusServiceWatcher(this); m_watcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); @@ -382,19 +375,6 @@ namespace BlackSimPlugin::XPlane { this->updateCockpit(com1, com2, transponder, identifier()); } - - if (m_isWeatherActivated) - { - if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get())) - { - if (m_lastWeatherPosition.isNull() || - calculateGreatCircleDistance(m_lastWeatherPosition, situation).value(CLengthUnit::mi()) > 20) - { - m_lastWeatherPosition = situation; - requestWeatherGrid(situation, this->identifier()); - } - } - } // weather } } @@ -484,7 +464,7 @@ namespace BlackSimPlugin::XPlane bool CSimulatorXPlane::isConnected() const { - return m_serviceProxy && m_trafficProxy && m_weatherProxy; + return m_serviceProxy && m_trafficProxy; } bool CSimulatorXPlane::connectTo() @@ -506,13 +486,12 @@ namespace BlackSimPlugin::XPlane m_serviceProxy = new CXSwiftBusServiceProxy(m_dBusConnection, this); m_trafficProxy = new CXSwiftBusTrafficProxy(m_dBusConnection, this); - m_weatherProxy = new CXSwiftBusWeatherProxy(m_dBusConnection, this); // hook up disconnected slot of connection bool s = m_dBusConnection.connect(QString(), DBUS_PATH_LOCAL, DBUS_INTERFACE_LOCAL, "Disconnected", this, SLOT(onDBusServiceUnregistered())); Q_ASSERT(s); - if (!m_serviceProxy->isValid() || !m_trafficProxy->isValid() || !m_weatherProxy->isValid()) + if (!m_serviceProxy->isValid() || !m_trafficProxy->isValid()) { this->disconnectFrom(); return false; @@ -551,10 +530,8 @@ namespace BlackSimPlugin::XPlane if (m_watcher) { m_watcher->setConnection(m_dBusConnection); } delete m_serviceProxy; delete m_trafficProxy; - delete m_weatherProxy; m_serviceProxy = nullptr; m_trafficProxy = nullptr; - m_weatherProxy = nullptr; m_fastTimerCalls = 0; m_slowTimerCalls = 0; @@ -572,10 +549,8 @@ namespace BlackSimPlugin::XPlane if (m_watcher) { m_watcher->setConnection(m_dBusConnection); } delete m_serviceProxy; delete m_trafficProxy; - delete m_weatherProxy; m_serviceProxy = nullptr; m_trafficProxy = nullptr; - m_weatherProxy = nullptr; this->emitSimulatorCombinedStatus(); } @@ -927,111 +902,6 @@ namespace BlackSimPlugin::XPlane return true; } - void CSimulatorXPlane::injectWeatherGrid(const CWeatherGrid &weatherGrid) - { - if (this->isShuttingDownOrDisconnected()) { return; } - if (weatherGrid.isEmpty()) { return; } - if (!this->isWeatherActivated()) { return; } - - if (!CThreadUtils::isInThisThread(this)) - { - - BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Wrong thread"); - QPointer myself(this); - QTimer::singleShot(0, this, [=] { - if (!myself) { return; } - myself->injectWeatherGrid(weatherGrid); - }); - return; - } - - // XPlane weather off - m_weatherProxy->setUseRealWeather(false); - - //! TODO: find the closest - if (weatherGrid.isEmpty()) { return; } - const CGridPoint gridPoint = weatherGrid.front(); - - // todo: find the closest - auto visibilityLayers = gridPoint.getVisibilityLayers(); - visibilityLayers.sortBy(&CVisibilityLayer::getBase); - const CVisibilityLayer visibilityLayer = visibilityLayers.frontOrDefault(); - m_weatherProxy->setVisibility(visibilityLayer.getVisibility().value(CLengthUnit::m())); - - CTemperatureLayerList temperatureLayers = gridPoint.getTemperatureLayers(); - temperatureLayers.sortBy(&CTemperatureLayer::getLevel); - const CTemperatureLayer temperatureLayer = temperatureLayers.frontOrDefault(); - m_weatherProxy->setTemperature(temperatureLayer.getTemperature().valueInteger(CTemperatureUnit::C())); - m_weatherProxy->setDewPoint(temperatureLayer.getDewPoint().valueInteger(CTemperatureUnit::C())); - m_weatherProxy->setQNH(gridPoint.getPressureAtMsl().value(CPressureUnit::inHg())); - - int layerNumber = 0; - CCloudLayerList cloudLayers = gridPoint.getCloudLayers(); - auto numberOfLayers = cloudLayers.size(); - // Fill cloud layers if less then 3 - while (numberOfLayers < 3) - { - cloudLayers.push_back(CCloudLayer()); - numberOfLayers++; - } - cloudLayers.sortBy(&CCloudLayer::getBase); - // todo: Instead of truncate, find the 3 vertical closest cloud layers - cloudLayers.truncate(3); - for (const auto &cloudLayer : std::as_const(cloudLayers)) - { - const int base = cloudLayer.getBase().valueInteger(CLengthUnit::m()); - const int top = cloudLayer.getTop().valueInteger(CLengthUnit::m()); - - int coverage = 0; - switch (cloudLayer.getCoverage()) - { - case CCloudLayer::None: coverage = 0; break; - case CCloudLayer::Few: coverage = 2; break; - case CCloudLayer::Scattered: coverage = 3; break; - case CCloudLayer::Broken: coverage = 4; break; - case CCloudLayer::Overcast: coverage = 6; break; - default: coverage = 0; break; - } - - // Clear = 0, High Cirrus = 1, Scattered = 2, Broken = 3, Overcast = 4, Stratus = 5 - int type = 0; - switch (cloudLayer.getClouds()) - { - case CCloudLayer::NoClouds: type = 0; break; - case CCloudLayer::Cirrus: type = 1; break; - case CCloudLayer::Stratus: type = 5; break; - default: type = 0; break; - } - - m_weatherProxy->setCloudLayer(layerNumber, base, top, type, coverage); - layerNumber++; - } - - layerNumber = 0; - CWindLayerList windLayers = gridPoint.getWindLayers(); - numberOfLayers = windLayers.size(); - // Fill cloud layers if less then 3 - while (numberOfLayers < 3) - { - windLayers.push_back(CWindLayer()); - numberOfLayers++; - } - windLayers.sortBy(&CWindLayer::getLevel); - // todo: Instead of truncate, find the 3 vertical closest cloud layers - windLayers.truncate(3); - for (const auto &windLayer : windLayers) - { - const int altitudeMeter = windLayer.getLevel().valueInteger(CLengthUnit::m()); - const double directionDeg = windLayer.getDirection().value(CAngleUnit::deg()); - const int speedKts = windLayer.getSpeed().valueInteger(CSpeedUnit::kts()); - m_weatherProxy->setWindLayer(layerNumber, altitudeMeter, directionDeg, speedKts, 0, 0, 0); - layerNumber++; - } - - m_weatherProxy->setPrecipitationRatio(cloudLayers.frontOrDefault().getPrecipitationRate()); - m_weatherProxy->setThunderstormRatio(0.0); - } - void CSimulatorXPlane::updateRemoteAircraft() { Q_ASSERT_X(CThreadUtils::isInThisThread(this), Q_FUNC_INFO, "thread"); @@ -1459,10 +1329,9 @@ namespace BlackSimPlugin::XPlane ISimulator *CSimulatorXPlaneFactory::create(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, - IWeatherGridProvider *weatherGridProvider, IClientProvider *clientProvider) { - return new CSimulatorXPlane(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, clientProvider, this); + return new CSimulatorXPlane(info, ownAircraftProvider, remoteAircraftProvider, clientProvider, this); } CSimulatorXPlaneListener::CSimulatorXPlaneListener(const CSimulatorPluginInfo &info) : ISimulatorListener(info) @@ -1548,9 +1417,8 @@ namespace BlackSimPlugin::XPlane { CXSwiftBusServiceProxy service(m_DBusConnection); CXSwiftBusTrafficProxy traffic(m_DBusConnection); - CXSwiftBusWeatherProxy weather(m_DBusConnection); - const bool result = service.isValid() && traffic.isValid() && weather.isValid(); + const bool result = service.isValid() && traffic.isValid(); if (!result) { return; } const QString swiftVersion = CBuildConfig::getVersionString(); diff --git a/src/plugins/simulator/xplane/simulatorxplane.h b/src/plugins/simulator/xplane/simulatorxplane.h index e41749561..ef53dcdcd 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.h +++ b/src/plugins/simulator/xplane/simulatorxplane.h @@ -14,7 +14,6 @@ #include "blackmisc/simulation/settings/simulatorsettings.h" #include "blackmisc/simulation/settings/xswiftbussettings.h" #include "blackmisc/simulation/simulatedaircraftlist.h" -#include "blackmisc/weather/weathergrid.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/aviation/callsignset.h" #include "blackmisc/geo/coordinategeodetic.h" @@ -56,17 +55,12 @@ namespace BlackMisc class IOwnAircraftProvider; class IRemoteAircraftProvider; } - namespace Weather - { - class IWeatherGridProvider; - } } namespace BlackSimPlugin::XPlane { class CXSwiftBusServiceProxy; class CXSwiftBusTrafficProxy; - class CXSwiftBusWeatherProxy; //! X-Plane data struct XPlaneData @@ -125,7 +119,6 @@ namespace BlackSimPlugin::XPlane CSimulatorXPlane(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider, QObject *parent = nullptr); @@ -152,7 +145,6 @@ namespace BlackSimPlugin::XPlane virtual void resetAircraftStatistics() override; virtual BlackMisc::CStatusMessageList getInterpolationMessages(const BlackMisc::Aviation::CCallsign &callsign) const override; virtual bool testSendSituationAndParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftSituation &situation, const BlackMisc::Aviation::CAircraftParts &parts) override; - virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override; virtual void callbackReceivedRequestedElevation(const BlackMisc::Geo::CElevationPlane &plane, const BlackMisc::Aviation::CCallsign &callsign, bool isWater) override; virtual void setFlightNetworkConnected(bool connected) override; //! @} @@ -269,7 +261,6 @@ namespace BlackSimPlugin::XPlane QDBusServiceWatcher *m_watcher { nullptr }; CXSwiftBusServiceProxy *m_serviceProxy { nullptr }; CXSwiftBusTrafficProxy *m_trafficProxy { nullptr }; - CXSwiftBusWeatherProxy *m_weatherProxy { nullptr }; QTimer m_fastTimer; QTimer m_slowTimer; QTimer m_airportUpdater; @@ -344,7 +335,6 @@ namespace BlackSimPlugin::XPlane virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, - BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider, BlackMisc::Network::IClientProvider *clientProvider) override; //! \copydoc BlackCore::ISimulatorFactory::createListener diff --git a/src/plugins/simulator/xplane/xswiftbusweatherproxy.cpp b/src/plugins/simulator/xplane/xswiftbusweatherproxy.cpp deleted file mode 100644 index 2917032a4..000000000 --- a/src/plugins/simulator/xplane/xswiftbusweatherproxy.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#include "xswiftbusweatherproxy.h" - -#include - -class QDBusConnection; - -#define XSWIFTBUS_SERVICENAME "org.swift-project.xswiftbus" - -namespace BlackSimPlugin::XPlane -{ - - CXSwiftBusWeatherProxy::CXSwiftBusWeatherProxy(QDBusConnection &connection, QObject *parent) : QObject(parent) - { - m_dbusInterface = new BlackMisc::CGenericDBusInterface(XSWIFTBUS_SERVICENAME, ObjectPath(), InterfaceName(), connection, this); - } - - bool CXSwiftBusWeatherProxy::isUsingRealWeather() const - { - return m_dbusInterface->callDBusRet(QLatin1String("isUsingRealWeather")); - } - - void CXSwiftBusWeatherProxy::setUseRealWeather(bool enable) - { - m_dbusInterface->callDBus(QLatin1String("setUseRealWeather"), enable); - } - - void CXSwiftBusWeatherProxy::setVisibility(double visibilityM) - { - m_dbusInterface->callDBus(QLatin1String("setVisibility"), visibilityM); - } - - void CXSwiftBusWeatherProxy::setTemperature(int degreesC) - { - m_dbusInterface->callDBus(QLatin1String("setTemperature"), degreesC); - } - - void CXSwiftBusWeatherProxy::setDewPoint(int degreesC) - { - m_dbusInterface->callDBus(QLatin1String("setDewPoint"), degreesC); - } - - void CXSwiftBusWeatherProxy::setQNH(double inHg) - { - m_dbusInterface->callDBus(QLatin1String("setQNH"), inHg); - } - - void CXSwiftBusWeatherProxy::setPrecipitationRatio(double precipRatio) - { - m_dbusInterface->callDBus(QLatin1String("setPrecipitationRatio"), precipRatio); - } - - void CXSwiftBusWeatherProxy::setThunderstormRatio(double cbRatio) - { - m_dbusInterface->callDBus(QLatin1String("setThunderstormRatio"), cbRatio); - } - - void CXSwiftBusWeatherProxy::setTurbulenceRatio(double turbulenceRatio) - { - m_dbusInterface->callDBus(QLatin1String("setTurbulenceRatio"), turbulenceRatio); - } - - void CXSwiftBusWeatherProxy::setRunwayFriction(int friction) - { - m_dbusInterface->callDBus(QLatin1String("setRunwayFriction"), friction); - } - - void CXSwiftBusWeatherProxy::setCloudLayer(int layer, int baseM, int topsM, int type, int coverage) - { - m_dbusInterface->callDBus(QLatin1String("setCloudLayer"), layer, baseM, topsM, type, coverage); - } - - void CXSwiftBusWeatherProxy::setWindLayer(int layer, int altitudeM, double directionDeg, int speedKt, int shearDirectionDeg, int shearSpeedKt, int turbulence) - { - m_dbusInterface->callDBus(QLatin1String("setWindLayer"), layer, altitudeM, directionDeg, speedKt, shearDirectionDeg, shearSpeedKt, turbulence); - } - -} diff --git a/src/plugins/simulator/xplane/xswiftbusweatherproxy.h b/src/plugins/simulator/xplane/xswiftbusweatherproxy.h deleted file mode 100644 index d92028fa5..000000000 --- a/src/plugins/simulator/xplane/xswiftbusweatherproxy.h +++ /dev/null @@ -1,97 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKSIMPLUGIN_XSWIFTBUS_WEATHER_PROXY_H -#define BLACKSIMPLUGIN_XSWIFTBUS_WEATHER_PROXY_H - -#include "blackmisc/genericdbusinterface.h" - -#include -#include - -// clazy:excludeall=const-signal-or-slot - -class QDBusConnection; - -//! \cond PRIVATE -#define XSWIFTBUS_WEATHER_INTERFACENAME "org.swift_project.xswiftbus.weather" -#define XSWIFTBUS_WEATHER_OBJECTPATH "/xswiftbus/weather" -//! \endcond - -namespace BlackSimPlugin::XPlane -{ - - /*! - * Proxy object connected to a real XSwiftBus::CWeather object via DBus - */ - class CXSwiftBusWeatherProxy : public QObject - { - Q_OBJECT - - public: - //! Service name - static const QString &InterfaceName() - { - static QString s(XSWIFTBUS_WEATHER_INTERFACENAME); - return s; - } - - //! Service path - static const QString &ObjectPath() - { - static QString s(XSWIFTBUS_WEATHER_OBJECTPATH); - return s; - } - - //! Constructor - CXSwiftBusWeatherProxy(QDBusConnection &connection, QObject *parent = nullptr); - - //! Does the remote object exist? - bool isValid() const { return m_dbusInterface->isValid(); } - - private: - BlackMisc::CGenericDBusInterface *m_dbusInterface = nullptr; - - public slots: - //! \copydoc XSwiftBus::CWeather::isUsingRealWeather - bool isUsingRealWeather() const; - - //! \copydoc XSwiftBus::CWeather::setUseRealWeather - void setUseRealWeather(bool enable); - - //! \copydoc XSwiftBus::CWeather::setVisibility - void setVisibility(double visibilityM); - - //! \copydoc XSwiftBus::CWeather::setTemperature - void setTemperature(int degreesC); - - //! \copydoc XSwiftBus::CWeather::setDewPoint - void setDewPoint(int degreesC); - - //! \copydoc XSwiftBus::CWeather::setQNH - void setQNH(double inHg); - - //! \copydoc XSwiftBus::CWeather::setPrecipitationRatio - void setPrecipitationRatio(double precipRatio); - - //! \copydoc XSwiftBus::CWeather::setThunderstormRatio - void setThunderstormRatio(double cbRatio); - - //! \copydoc XSwiftBus::CWeather::setTurbulenceRatio - void setTurbulenceRatio(double turbulenceRatio); - - //! \copydoc XSwiftBus::CWeather::setRunwayFriction - void setRunwayFriction(int friction); - - //! \copydoc XSwiftBus::CWeather::setCloudLayer - void setCloudLayer(int layer, int baseM, int topsM, int type, int coverage); - - //! \copydoc XSwiftBus::CWeather::setWindLayer - void setWindLayer(int layer, int altitudeM, double directionDeg, int speedKt, int shearDirectionDeg, int shearSpeedKt, int turbulence); - }; - -} - -#endif // guard diff --git a/src/plugins/weatherdata/gfs/CMakeLists.txt b/src/plugins/weatherdata/gfs/CMakeLists.txt deleted file mode 100644 index 28f7530b8..000000000 --- a/src/plugins/weatherdata/gfs/CMakeLists.txt +++ /dev/null @@ -1,74 +0,0 @@ -# SPDX-FileCopyrightText: Copyright (C) swift Project Community / Contributors -# SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -add_library(weatherdatagfs SHARED - weatherdatagfs.cpp - weatherdatagfs.h - weatherdatagfs.json - - # g2clib - g2clib/drstemplates.h - g2clib/grib2.h - g2clib/gridtemplates.h - g2clib/pdstemplates.h - g2clib/cmplxpack.c - g2clib/compack.c - g2clib/comunpack.c - g2clib/drstemplates.c - g2clib/g2_addfield.c - g2clib/g2_addgrid.c - g2clib/g2_addlocal.c - g2clib/g2_create.c - g2clib/g2_free.c - g2clib/g2_getfld.c - g2clib/g2_gribend.c - g2clib/g2_info.c - g2clib/g2_miss.c - g2clib/g2_unpack1.c - g2clib/g2_unpack2.c - g2clib/g2_unpack3.c - g2clib/g2_unpack4.c - g2clib/g2_unpack5.c - g2clib/g2_unpack6.c - g2clib/g2_unpack7.c - g2clib/gbits.c - g2clib/getdim.c - g2clib/getpoly.c - g2clib/gridtemplates.c - g2clib/int_power.c - g2clib/misspack.c - g2clib/mkieee.c - g2clib/pack_gp.c - g2clib/pdstemplates.c - g2clib/rdieee.c - g2clib/reduce.c - g2clib/seekgb.c - g2clib/simpack.c - g2clib/simunpack.c - g2clib/specpack.c - g2clib/specunpack.c -) - -set_target_properties(weatherdatagfs PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/weatherdata) -set_target_properties(weatherdatagfs PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin/plugins/weatherdata) - - -target_include_directories(weatherdatagfs PUBLIC ${PROJECT_SOURCE_DIR}/src) - -target_link_libraries(weatherdatagfs - PUBLIC - Qt::Core - misc - core -) - -install(TARGETS weatherdatagfs - LIBRARY DESTINATION bin/plugins/weatherdata - RUNTIME DESTINATION bin/plugins/weatherdata -) - -if(APPLE) - set_target_properties(weatherdatagfs PROPERTIES INSTALL_RPATH @loader_path/../../../lib) -elseif(UNIX) - set_target_properties(weatherdatagfs PROPERTIES INSTALL_RPATH \$ORIGIN/../../../lib) -endif() diff --git a/src/plugins/weatherdata/gfs/g2clib/CHANGES b/src/plugins/weatherdata/gfs/g2clib/CHANGES deleted file mode 100644 index e6beba874..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/CHANGES +++ /dev/null @@ -1,68 +0,0 @@ -glib-1.0 - August 2003 - Original version - -g2libc-1.0.1 - May 2004 - Changed the library name from "libg2c.a" to - "libgrib2c.a" to avoid conflict with the g77 libg2c - library. - - Added support for Grid Definition Template 3.31, - Albers Equal Area. - - Changed most PDT templates in module pdstemplates to - allow negative surface values. - - Many minor changes to help get clean compiles. - -g2libc-1.0.2 - December 2004 - WMO approved the JPEG2000 and PNG Data - Representation Templates ( 5.40000 and 5.40010, - respectively ) for operational use. The templates - were assigned WMO values of 5.40 and 5.41, - respectively. Changes were made to the source to - recognize either template number. - - Fixed bug encountered when packing a near constant - field with DRT 5.40 or 5.40000 (JPEG2000). - - Added consistency check, provided by - Arthur Taylor/MDL, used when unpacking Data - Templates 7.2 and 7.3. - - Added functionality to support encoding of - "Missing" data values within the data field when - using Data Representation Templates 5.2 - (complex packing) and 5.3 (complex packing and - spatial differencing). See octets 23 - 31 in DRTs - 5.2 and 5.3 for more info on missing value - management. - - Increased the packing efficiency of Data - Representation Templates 5.2 and 5.3 by adding - MDL/Glahn algorithm for determining effective - groupings. - -g2libc-1.0.3 - December 2005 - Two bug fixes: 1) Error encoding constant - data field. 2) Error encoding grid with - large bitmap using DRT 5.40 - JPEG2000. - -g2libc-1.0.5 - August 2007 - Added GDT 3.204 Curvilinear Orthogonal Grid - -g2libc-1.1.7 - August 2008 - Added GDT 3.32768 Rot Lat/Lon E-grid (Arakawa) - -g2libc-1.1.8 - January 2009 - Initialize variable lencsec2 in routine g2_unpack2.c - variable ndpts in routine g2_unpack7.c - - Changed the structure name template to gtemplate to avoid - of reserved word in C++ - - Change routine seekgb.c to use 4 bytes instead of sizeof(g2int) - -g2libc-1.1.9 - June 2009 - Updated version jasper-1.900.1, libpng-1.2.35 and zlib-1.2.3 - - Fixed bug causing seg fault when using PNG 1.2.35 - -g2libc-1.2.0 - March 2010 - Added PDT 4.31 Satellite Product - - Added PDT 4.15 WAFS Product - -g2libc-1.2.1 - August 2010 - Added PDT 4.40,4.41,4.42,4.43 for Atmospheric Chemical Constituents - - Added GDT 3.32769 Rot Lat/Lon None E-grid (Arakawa) - - If section 2 has zero length, return IERR=0 - -g2libc-1.2.2 - March 2011 - Corrected PDT 4.42,4.43 for Atmospheric Chemical Constituents - -g2libc-1.2.3 - November 2011 - Fixed bugs in routines dec_png.c and enc_png.c - -g2libc-1.4.0 - May 2012 - Added PDT 4.44,4.45,4.46,4.47,4.48 for Aerosol products - - PDT 4.50,4.51,4.52 iand 4.91 for Categorical forecast at a horizonal - -g2libc-1.5.0 - Sept. 2013 - Added PDT 4.33,4.34,4.53,4.54,4.50 - - Added GDT 3.4,3.5,3.12,3.101,3.140 - - Free up memory igds diff --git a/src/plugins/weatherdata/gfs/g2clib/README b/src/plugins/weatherdata/gfs/g2clib/README deleted file mode 100644 index ed6428190..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/README +++ /dev/null @@ -1,68 +0,0 @@ - August 06, 2013 - W/SIB:VUONG - - -g2clib Library. - -This library contains "C" decoder/encoder -routines for GRIB edition 2. The user API for the GRIB2 routines -is described in file "grib2c.doc". - -This "C" source code conatins many uses of the C++ -comment style "//". Please make sure you include the -appropriate compiler option in the CFLAGS variable in the -makefile to allow the use of "//" comment indicators. - - -We have added support for PNG and JPEG2000 image compression -algorithms within the GRIB2 standard. If you would like -to compile this library to utilize these GRIB2 Templates, -make sure that -DUSE_PNG and -DUSE_JPEG2000 are specified -in the DEFS variable in the makefile. You will also need -to download and install the external libraries listed below, -if they are not already installed on your system. - -If you do not wish to bother with the external libs and -don't need PNG and JPEG2000 support, you can remove the --DUSE_PNG and -DUSE_JPEG2000 flags from the DEFS variable -in the makefile. - - -------------------------------------------------------------------------------- - - External Libraries: - -libjasper.a - This library is a C implementation of the JPEG-2000 Part-1 - standard (i.e., ISO/IEC 15444-1). This library is required - if JPEG2000 support in GRIB2 is desired. If not, remove - the -DUSE_JPEG2000 option from the DEFS variable - in the makefile. - - Download version jasper-1.900.1 from the JasPer Project's - home page, http://www.ece.uvic.ca/~mdadams/jasper/. - - More information about JPEG2000 can be found at - http://www.jpeg.org/JPEG2000.html. - -libpng.a This library is a C implementation of the Portable Network - Graphics PNG image compression format. This library is required - if PNG support in GRIB2 is desired. If not, remove - the -DUSE_PNG option from the DEFS variable - in the makefile. - - If not already installed on your system, download version - libpng-1.2.44 from http://www.libpng.org/pub/png/libpng.html. - - More information about PNG can be found at - http://www.libpng.org/pub/png/. - -libz.a This library contains compression/decompression routines - used by libpng.a for PNG image compression support. - This library is required if PNG support in GRIB2 is desired. - If not, remove the -DUSE_PNG option from the DEFS variable - in g2lib/makefile. - - If not already installed on your system, download version - zlib-1.2.6 from http://www.gzip.org/zlib/. - - diff --git a/src/plugins/weatherdata/gfs/g2clib/cmplxpack.c b/src/plugins/weatherdata/gfs/g2clib/cmplxpack.c deleted file mode 100644 index 4d9908cc0..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/cmplxpack.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "grib2.h" - -void cmplxpack(g2float *fld,g2int ndpts, g2int idrsnum,g2int *idrstmpl, - unsigned char *cpack, g2int *lcpack) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: cmplxpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2004-08-27 -// -// ABSTRACT: This subroutine packs up a data field using a complex -// packing algorithm as defined in the GRIB2 documention. It -// supports GRIB2 complex packing templates with or without -// spatial differences (i.e. DRTs 5.2 and 5.3). -// It also fills in GRIB2 Data Representation Template 5.2 or 5.3 -// with the appropriate values. -// -// PROGRAM HISTORY LOG: -// 2004-08-27 Gilbert -// -// USAGE: cmplxpack(g2float *fld,g2int ndpts, g2int idrsnum,g2int *idrstmpl, -// unsigned char *cpack, g2int *lcpack) -// INPUT ARGUMENT LIST: -// fld[] - Contains the data values to pack -// ndpts - The number of data values in array fld[] -// idrsnum - Data Representation Template number 5.N -// Must equal 2 or 3. -// idrstmpl - Contains the array of values for Data Representation -// Template 5.2 or 5.3 -// [0] = Reference value - ignored on input -// [1] = Binary Scale Factor -// [2] = Decimal Scale Factor -// . -// . -// [6] = Missing value management -// [7] = Primary missing value -// [8] = Secondary missing value -// . -// . -// [16] = Order of Spatial Differencing ( 1 or 2 ) -// . -// . -// -// OUTPUT ARGUMENT LIST: -// idrstmpl - Contains the array of values for Data Representation -// Template 5.3 -// [0] = Reference value - set by compack routine. -// [1] = Binary Scale Factor - unchanged from input -// [2] = Decimal Scale Factor - unchanged from input -// . -// . -// cpack - The packed data field (character*1 array) -// lcpack - length of packed field cpack[]. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - - - if ( idrstmpl[6] == 0 ) { // No internal missing values - compack(fld,ndpts,idrsnum,idrstmpl,cpack,lcpack); - } - else if ( idrstmpl[6] == 1 || idrstmpl[6] == 2) { - misspack(fld,ndpts,idrsnum,idrstmpl,cpack,lcpack); - } - else { - printf("cmplxpack: Don:t recognize Missing value option."); - *lcpack=-1; - } - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/compack.c b/src/plugins/weatherdata/gfs/g2clib/compack.c deleted file mode 100644 index 2adb9ac53..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/compack.c +++ /dev/null @@ -1,416 +0,0 @@ -#include -#include -#include "grib2.h" - - -void compack(g2float *fld,g2int ndpts,g2int idrsnum,g2int *idrstmpl, - unsigned char *cpack,g2int *lcpack) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: compack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-11-07 -// -// ABSTRACT: This subroutine packs up a data field using a complex -// packing algorithm as defined in the GRIB2 documention. It -// supports GRIB2 complex packing templates with or without -// spatial differences (i.e. DRTs 5.2 and 5.3). -// It also fills in GRIB2 Data Representation Template 5.2 or 5.3 -// with the appropriate values. -// -// PROGRAM HISTORY LOG: -// 2002-11-07 Gilbert -// -// USAGE: void compack(g2float *fld,g2int ndpts,g2int idrsnum, -// g2int *idrstmpl,unsigned char *cpack,g2int *lcpack) -// -// INPUT ARGUMENTS: -// fld[] - Contains the data values to pack -// ndpts - The number of data values in array fld[] -// idrsnum - Data Representation Template number 5.N -// Must equal 2 or 3. -// idrstmpl - Contains the array of values for Data Representation -// Template 5.2 or 5.3 -// [0] = Reference value - ignored on input -// [1] = Binary Scale Factor -// [2] = Decimal Scale Factor -// . -// . -// [6] = Missing value management -// [7] = Primary missing value -// [8] = Secondary missing value -// . -// . -// [16] = Order of Spatial Differencing ( 1 or 2 ) -// . -// . -// -// OUTPUT ARGUMENTS: -// idrstmpl - Contains the array of values for Data Representation -// Template 5.3 -// [0] = Reference value - set by compack routine. -// [1] = Binary Scale Factor - unchanged from input -// [2] = Decimal Scale Factor - unchanged from input -// . -// . -// cpack - The packed data field -// lcpack - length of packed field cpack. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - static g2int zero=0; - g2int *ifld,*gref,*glen,*gwidth; - g2int *jmin, *jmax, *lbit; - g2int i,j,n,imin,imax,left; - g2int isd,itemp,ilmax,ngwidthref=0,nbitsgwidth=0; - g2int nglenref=0,nglenlast=0,iofst,ival1,ival2; - g2int minsd,nbitsd=0,maxorig,nbitorig,ngroups; - g2int lg,ng,igmax,iwmax,nbitsgref; - g2int glength,grpwidth,nbitsglen=0; - g2int kfildo, minpk, inc, maxgrps, ibit, jbit, kbit, novref, lbitref; - g2int missopt, miss1, miss2, ier; - g2float bscale,dscale,rmax,rmin,temp; - static g2int simple_alg = 0; - static g2float alog2=0.69314718f; // ln(2.0) - static g2int one=1; - ival1 = 0; - - bscale=(g2float)int_power(2.0,-idrstmpl[1]); - dscale=(g2float)int_power(10.0,idrstmpl[2]); -// -// Find max and min values in the data -// - rmax=fld[0]; - rmin=fld[0]; - for (j=1;j rmax) rmax=fld[j]; - if (fld[j] < rmin) rmin=fld[j]; - } - -// -// If max and min values are not equal, pack up field. -// If they are equal, we have a constant field, and the reference -// value (rmin) is the value for each point in the field and -// set nbits to 0. -// - if (rmin != rmax) { - iofst=0; - ifld=calloc(ndpts,sizeof(g2int)); - gref=calloc(ndpts,sizeof(g2int)); - gwidth=calloc(ndpts,sizeof(g2int)); - glen=calloc(ndpts,sizeof(g2int)); - // - // Scale original data - // - if (idrstmpl[1] == 0) { // No binary scaling - imin=(g2int)rint(rmin*dscale); - //imax=(g2int)rint(rmax*dscale); - rmin=(g2float)imin; - for (j=0;j0;j--) - ifld[j]=ifld[j]-ifld[j-1]; - ifld[0]=0; - } - else if (idrstmpl[16] == 2) { // second order - ival1=ifld[0]; - ival2=ifld[1]; - for (j=ndpts-1;j>1;j--) - ifld[j]=ifld[j]-(2*ifld[j-1])+ifld[j-2]; - ifld[0]=0; - ifld[1]=0; - } - // - // subtract min value from spatial diff field - // - isd=idrstmpl[16]; - minsd=ifld[isd]; - for (j=isd;jival1) maxorig=ival2; - temp=(g2float)log((double)(maxorig+1))/alog2; - nbitorig=(g2int)ceil(temp)+1; - if (nbitorig > nbitsd) nbitsd=nbitorig; - // increase number of bits to even multiple of 8 ( octet ) - if ( (nbitsd%8) != 0) nbitsd=nbitsd+(8-(nbitsd%8)); - // - // Store extra spatial differencing info into the packed - // data section. - // - if (nbitsd != 0) { - // pack first original value - if (ival1 >= 0) { - sbit(cpack,&ival1,iofst,nbitsd); - iofst=iofst+nbitsd; - } - else { - sbit(cpack,&one,iofst,1); - iofst=iofst+1; - itemp=abs(ival1); - sbit(cpack,&itemp,iofst,nbitsd-1); - iofst=iofst+nbitsd-1; - } - if (idrstmpl[16] == 2) { - // pack second original value - if (ival2 >= 0) { - sbit(cpack,&ival2,iofst,nbitsd); - iofst=iofst+nbitsd; - } - else { - sbit(cpack,&one,iofst,1); - iofst=iofst+1; - itemp=abs(ival2); - sbit(cpack,&itemp,iofst,nbitsd-1); - iofst=iofst+nbitsd-1; - } - } - // pack overall min of spatial differences - if (minsd >= 0) { - sbit(cpack,&minsd,iofst,nbitsd); - iofst=iofst+nbitsd; - } - else { - sbit(cpack,&one,iofst,1); - iofst=iofst+1; - itemp=abs(minsd); - sbit(cpack,&itemp,iofst,nbitsd-1); - iofst=iofst+nbitsd-1; - } - } - //printf("SDp %ld %ld %ld %ld\n",ival1,ival2,minsd,nbitsd); - } // end of spatial diff section - // - // Determine Groups to be used. - // - if ( simple_alg == 1 ) { - // set group length to 10; calculate number of groups - // and length of last group - ngroups=ndpts/10; - for (j=0;j imax) imax=ifld[j]; - j++; - } - // calc num of bits needed to hold data - if ( gref[ng] != imax ) { - temp=(g2float)log((double)(imax-gref[ng]+1))/alog2; - gwidth[ng]=(g2int)ceil(temp); - } - else - gwidth[ng]=0; - // Subtract min from data - j=n; - for (lg=0;lg igmax) igmax=gref[j]; - if (igmax != 0) { - temp=(g2float)log((double)(igmax+1))/alog2; - nbitsgref=(g2int)ceil(temp); - sbits(cpack,gref,iofst,nbitsgref,0,ngroups); - itemp=nbitsgref*ngroups; - iofst=iofst+itemp; - // Pad last octet with Zeros, if necessary, - if ( (itemp%8) != 0) { - left=8-(itemp%8); - sbit(cpack,&zero,iofst,left); - iofst=iofst+left; - } - } - else - nbitsgref=0; - // - // Find max/min of the group widths and calc num of bits needed - // to pack each groups width value, then - // pack up group width values - // - iwmax=gwidth[0]; - ngwidthref=gwidth[0]; - for (j=1;j iwmax) iwmax=gwidth[j]; - if (gwidth[j] < ngwidthref) ngwidthref=gwidth[j]; - } - if (iwmax != ngwidthref) { - temp=(g2float)log((double)(iwmax-ngwidthref+1))/alog2; - nbitsgwidth=(g2int)ceil(temp); - for (i=0;i ilmax) ilmax=glen[j]; - if (glen[j] < nglenref) nglenref=glen[j]; - } - nglenlast=glen[ngroups-1]; - if (ilmax != nglenref) { - temp=(g2float)log((double)(ilmax-nglenref+1))/alog2; - nbitsglen=(g2int)ceil(temp); - for (i=0;i -#include -#include "grib2.h" - - -int comunpack(unsigned char *cpack,g2int lensec,g2int idrsnum,g2int *idrstmpl,g2int ndpts,g2float *fld) -////$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: comunpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-29 -// -// ABSTRACT: This subroutine unpacks a data field that was packed using a -// complex packing algorithm as defined in the GRIB2 documention, -// using info from the GRIB2 Data Representation Template 5.2 or 5.3. -// Supports GRIB2 complex packing templates with or without -// spatial differences (i.e. DRTs 5.2 and 5.3). -// -// PROGRAM HISTORY LOG: -// 2002-10-29 Gilbert -// 2004-12-16 Gilbert - Added test ( provided by Arthur Taylor/MDL ) -// to verify that group widths and lengths are -// consistent with section length. -// -// USAGE: int comunpack(unsigned char *cpack,g2int lensec,g2int idrsnum, -// g2int *idrstmpl, g2int ndpts,g2float *fld) -// INPUT ARGUMENT LIST: -// cpack - pointer to the packed data field. -// lensec - length of section 7 (used for error checking). -// idrsnum - Data Representation Template number 5.N -// Must equal 2 or 3. -// idrstmpl - pointer to the array of values for Data Representation -// Template 5.2 or 5.3 -// ndpts - The number of data values to unpack -// -// OUTPUT ARGUMENT LIST: -// fld - Contains the unpacked data values. fld must be allocated -// with at least ndpts*sizeof(g2float) bytes before -// calling this routine. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$// -{ - - g2int nbitsd=0,isign; - g2int j,iofst,ival1,ival2,minsd,itemp,l,k,n,non=0; - g2int *ifld,*ifldmiss=0; - g2int *gref,*gwidth,*glen; - g2int itype,ngroups,nbitsgref,nbitsgwidth,nbitsglen; - g2int msng1,msng2; - g2float ref,bscale,dscale,rmiss1,rmiss2; - g2int totBit, totLen; - - //printf('IDRSTMPL: ',(idrstmpl(j),j=1,16) - rdieee(idrstmpl+0,&ref,1); -// printf("SAGTref: %f\n",ref); - bscale = (g2float)int_power(2.0,idrstmpl[1]); - dscale = (g2float)int_power(10.0,-idrstmpl[2]); - nbitsgref = idrstmpl[3]; - itype = idrstmpl[4]; - ngroups = idrstmpl[9]; - nbitsgwidth = idrstmpl[11]; - nbitsglen = idrstmpl[15]; - if (idrsnum == 3) - nbitsd=idrstmpl[17]*8; - - // Constant field - - if (ngroups == 0) { - for (j=0;j lensec) { - free(ifld); - free(gref); - free(gwidth); - return 1; - } -// -// For each group, unpack data values -// - if ( idrstmpl[6] == 0 ) { // no missing values - n=0; - for (j=0;j -#include -#include -#include "grib2.h" -#include "jasper/jasper.h" -#define JAS_1_700_2 - - - int dec_jpeg2000(char *injpc,g2int bufsize,g2int *outfld) -/*$$$ SUBPROGRAM DOCUMENTATION BLOCK -* . . . . -* SUBPROGRAM: dec_jpeg2000 Decodes JPEG2000 code stream -* PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-02 -* -* ABSTRACT: This Function decodes a JPEG2000 code stream specified in the -* JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer -* Software version 1.500.4 (or 1.700.2) written by the University of British -* Columbia and Image Power Inc, and others. -* JasPer is available at http://www.ece.uvic.ca/~mdadams/jasper/. -* -* PROGRAM HISTORY LOG: -* 2002-12-02 Gilbert -* -* USAGE: int dec_jpeg2000(char *injpc,g2int bufsize,g2int *outfld) -* -* INPUT ARGUMENTS: -* injpc - Input JPEG2000 code stream. -* bufsize - Length (in bytes) of the input JPEG2000 code stream. -* -* OUTPUT ARGUMENTS: -* outfld - Output matrix of grayscale image values. -* -* RETURN VALUES : -* 0 = Successful decode -* -3 = Error decode jpeg2000 code stream. -* -5 = decoded image had multiple color components. -* Only grayscale is expected. -* -* REMARKS: -* -* Requires JasPer Software version 1.500.4 or 1.700.2 -* -* ATTRIBUTES: -* LANGUAGE: C -* MACHINE: IBM SP -* -*$$$*/ - -{ - g2int i,j,k; - jas_image_t *image=0; - jas_stream_t *jpcstream; - jas_image_cmpt_t *pcmpt; - char *opts=0; - jas_matrix_t *data; - -// jas_init(); - -// -// Create jas_stream_t containing input JPEG200 codestream in memory. -// - - jpcstream=jas_stream_memopen(injpc,bufsize); - -// -// Decode JPEG200 codestream into jas_image_t structure. -// - image=jpc_decode(jpcstream,opts); - if ( image == 0 ) { - printf(" jpc_decode return\n"); - return -3; - } - - pcmpt=image->cmpts_[0]; -/* - printf(" SAGOUT DECODE:\n"); - printf(" tlx %d \n",image->tlx_); - printf(" tly %d \n",image->tly_); - printf(" brx %d \n",image->brx_); - printf(" bry %d \n",image->bry_); - printf(" numcmpts %d \n",image->numcmpts_); - printf(" maxcmpts %d \n",image->maxcmpts_); -#ifdef JAS_1_500_4 - printf(" colormodel %d \n",image->colormodel_); -#endif -#ifdef JAS_1_700_2 - printf(" colorspace %d \n",image->clrspc_); -#endif - printf(" inmem %d \n",image->inmem_); - printf(" COMPONENT:\n"); - printf(" tlx %d \n",pcmpt->tlx_); - printf(" tly %d \n",pcmpt->tly_); - printf(" hstep %d \n",pcmpt->hstep_); - printf(" vstep %d \n",pcmpt->vstep_); - printf(" width %d \n",pcmpt->width_); - printf(" height %d \n",pcmpt->height_); - printf(" prec %d \n",pcmpt->prec_); - printf(" sgnd %d \n",pcmpt->sgnd_); - printf(" cps %d \n",pcmpt->cps_); -#ifdef JAS_1_700_2 - printf(" type %d \n",pcmpt->type_); -#endif -*/ - -// Expecting jpeg2000 image to be grayscale only. -// No color components. -// - if (image->numcmpts_ != 1 ) { - printf("dec_jpeg2000: Found color image. Grayscale expected.\n"); - return (-5); - } - -// -// Create a data matrix of grayscale image values decoded from -// the jpeg2000 codestream. -// - data=jas_matrix_create(jas_image_height(image), jas_image_width(image)); - jas_image_readcmpt(image,0,0,0,jas_image_width(image), - jas_image_height(image),data); -// -// Copy data matrix to output integer array. -// - k=0; - for (i=0;iheight_;i++) - for (j=0;jwidth_;j++) - outfld[k++]=data->rows_[i][j]; -// -// Clean up JasPer work structures. -// - jas_matrix_destroy(data); - jas_stream_close(jpcstream); - jas_image_destroy(image); - - return 0; - -} -#endif /* USE_JPEG2000 */ diff --git a/src/plugins/weatherdata/gfs/g2clib/dec_png.c b/src/plugins/weatherdata/gfs/g2clib/dec_png.c deleted file mode 100644 index f7f958e12..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/dec_png.c +++ /dev/null @@ -1,144 +0,0 @@ -#ifndef USE_PNG - void dummy(void) {} -#else /* USE_PNG */ - -#include -#include -#include -#include -#include "grib2.h" - - -struct png_stream { - unsigned char *stream_ptr; /* location to write PNG stream */ - g2int stream_len; /* number of bytes written */ -}; -typedef struct png_stream png_stream; - -void user_read_data(png_structp , png_bytep , png_uint_32 ); - -void user_read_data(png_structp png_ptr,png_bytep data, png_uint_32 length) -/* - Custom read function used so that libpng will read a PNG stream - from memory instead of a file on disk. -*/ -{ - char *ptr; - g2int offset; - png_stream *mem; - - mem=(png_stream *)png_get_io_ptr(png_ptr); - ptr=(void *)mem->stream_ptr; - offset=mem->stream_len; -/* printf("SAGrd %ld %ld %x\n",offset,length,ptr); */ - memcpy(data,ptr+offset,length); - mem->stream_len += length; -} - - - -int dec_png(unsigned char *pngbuf,g2int *width,g2int *height,char *cout) -{ - int interlace,color,compres,filter,bit_depth; - g2int j,k,n,bytes,clen; - png_structp png_ptr; - png_infop info_ptr,end_info; - png_bytepp row_pointers; - png_stream read_io_ptr; - png_uint_32 h32, w32; - -/* check if stream is a valid PNG format */ - - if ( png_sig_cmp(pngbuf,0,8) != 0) - return (-3); - -/* create and initialize png_structs */ - - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, - NULL, NULL); - if (!png_ptr) - return (-1); - - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_read_struct(&png_ptr,(png_infopp)NULL,(png_infopp)NULL); - return (-2); - } - - end_info = png_create_info_struct(png_ptr); - if (!end_info) - { - png_destroy_read_struct(&png_ptr,(png_infopp)info_ptr,(png_infopp)NULL); - return (-2); - } - -/* Set Error callback */ - - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_read_struct(&png_ptr, &info_ptr,&end_info); - return (-3); - } - -/* Initialize info for reading PNG stream from memory */ - - read_io_ptr.stream_ptr=(png_voidp)pngbuf; - read_io_ptr.stream_len=0; - -/* Set new custom read function */ - - png_set_read_fn(png_ptr,(png_voidp)&read_io_ptr,(png_rw_ptr)user_read_data); -/* png_init_io(png_ptr, fptr); */ - -/* Read and decode PNG stream */ - - png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); - -/* Get pointer to each row of image data */ - - row_pointers = png_get_rows(png_ptr, info_ptr); - -/* Get image info, such as size, depth, colortype, etc... */ - - /*printf("SAGT:png %d %d %d\n",info_ptr->width,info_ptr->height,info_ptr->bit_depth);*/ - // (void)png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *)width, (png_uint_32 *)height, - (void)png_get_IHDR(png_ptr, info_ptr, &w32, &h32, - &bit_depth, &color, &interlace, &compres, &filter); - - *height = h32; - *width = w32; - -/* Check if image was grayscale */ - -/* - if (color != PNG_COLOR_TYPE_GRAY ) { - fprintf(stderr,"dec_png: Grayscale image was expected. \n"); - } -*/ - if ( color == PNG_COLOR_TYPE_RGB ) { - bit_depth=24; - } - else if ( color == PNG_COLOR_TYPE_RGB_ALPHA ) { - bit_depth=32; - } -/* Copy image data to output string */ - - n=0; - bytes=bit_depth/8; - clen=(*width)*bytes; - for (j=0;j<*height;j++) { - for (k=0;k -#include "grib2.h" -#include "drstemplates.h" - -const struct drstemplate templatesdrs[MAXDRSTEMP] = { - // 5.0: Grid point data - Simple Packing - { 0, 5, 0, {4,-2,-2,1,1} }, - // 5.2: Grid point data - Complex Packing - { 2, 16, 0, {4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1} }, - // 5.3: Grid point data - Complex Packing and spatial differencing - { 3, 18, 0, {4,-2,-2,1,1,1,1,4,4,4,1,1,4,1,4,1,1,1} }, - // 5.50: Spectral Data - Simple Packing - { 50, 5, 0, {4,-2,-2,1,4} }, - // 5.51: Spherical Harmonics data - Complex packing - { 51, 10, 0, {4,-2,-2,1,-4,2,2,2,4,1} }, -// // 5.1: Matrix values at gridpoint - Simple packing -// { 1, 15, 1, {4,-2,-2,1,1,1,4,2,2,1,1,1,1,1,1} }, - // 5.40: Grid point data - JPEG2000 encoding - { 40, 7, 0, {4,-2,-2,1,1,1,1} }, - // 5.41: Grid point data - PNG encoding - { 41, 5, 0, {4,-2,-2,1,1} }, - // 5.40000: Grid point data - JPEG2000 encoding - { 40000, 7, 0, {4,-2,-2,1,1,1,1} }, - // 5.40010: Grid point data - PNG encoding - { 40010, 5, 0, {4,-2,-2,1,1} } -} ; - -g2int getdrsindex(g2int number) -/*!$$$ SUBPROGRAM DOCUMENTATION BLOCK -! . . . . -! SUBPROGRAM: getdrsindex -! PRGMMR: Gilbert ORG: W/NP11 DATE: 2001-06-28 -! -! ABSTRACT: This function returns the index of specified Data -! Representation Template 5.NN (NN=number) in array templates. -! -! PROGRAM HISTORY LOG: -! 2001-06-28 Gilbert -! 2009-01-14 Vuong Changed structure name template to gtemplate -! -! USAGE: index=getdrsindex(number) -! INPUT ARGUMENT LIST: -! number - NN, indicating the number of the Data Representation -! Template 5.NN that is being requested. -! -! RETURNS: Index of DRT 5.NN in array gtemplates, if gtemplate exists. -! = -1, otherwise. -! -! REMARKS: None -! -! ATTRIBUTES: -! LANGUAGE: C -! MACHINE: IBM SP -! -!$$$*/ -{ - g2int j,getdrsindex=-1; - - for (j=0;jtype=5; - new->num=templatesdrs[index].template_num; - new->maplen=templatesdrs[index].mapdrslen; - new->needext=templatesdrs[index].needext; - new->map=(g2int *)templatesdrs[index].mapdrs; - new->extlen=0; - new->ext=0; //NULL - return(new); - } - else { - printf("getdrstemplate: DRS Template 5.%d not defined.\n",(int)number); - return(0); //NULL - } - - return(0); //NULL -} - -gtemplate *extdrstemplate(g2int number,g2int *list) -/*!$$$ SUBPROGRAM DOCUMENTATION BLOCK -! . . . . -! SUBPROGRAM: extdrstemplate -! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-11 -! -! ABSTRACT: This subroutine generates the remaining octet map for a -! given Data Representation Template, if required. Some Templates can -! vary depending on data values given in an earlier part of the -! Template, and it is necessary to know some of the earlier entry -! values to generate the full octet map of the Template. -! -! PROGRAM HISTORY LOG: -! 2000-05-11 Gilbert -! 2009-01-14 Vuong Changed structure name template to gtemplate -! -! USAGE: new=extdrstemplate(number,list); -! INPUT ARGUMENT LIST: -! number - NN, indicating the number of the Data Representation -! Template 5.NN that is being requested. -! list() - The list of values for each entry in the -! the Data Representation Template 5.NN. -! -! RETURN VALUE: -! - Pointer to the returned template struct. -! Returns NULL pointer, if template not found. -! -! ATTRIBUTES: -! LANGUAGE: C -! MACHINE: IBM SP -! -!$$$*/ -{ - gtemplate *new; - g2int index,i; - - index=getdrsindex(number); - if (index == -1) return(0); - - new=getdrstemplate(number); - - if ( ! new->needext ) return(new); - - if ( number == 1 ) { - new->extlen=list[10]+list[12]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=4; - } - } - return(new); - -} - diff --git a/src/plugins/weatherdata/gfs/g2clib/drstemplates.h b/src/plugins/weatherdata/gfs/g2clib/drstemplates.h deleted file mode 100644 index b33ef64ee..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/drstemplates.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _drstemplates_H -#define _drstemplates_H -#include "grib2.h" - -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-26 -// -// ABSTRACT: This Fortran Module contains info on all the available -// GRIB2 Data Representation Templates used in Section 5 (DRS). -// The information decribing each template is stored in the -// drstemplate structure defined below. -// -// Each Template has three parts: The number of entries in the template -// (mapdrslen); A map of the template (mapdrs), which contains the -// number of octets in which to pack each of the template values; and -// a logical value (needext) that indicates whether the Template needs -// to be extended. In some cases the number of entries in a template -// can vary depending upon values specified in the "static" part of -// the template. ( See Template 5.1 as an example ) -// -// NOTE: Array mapdrs contains the number of octets in which the -// corresponding template values will be stored. A negative value in -// mapdrs is used to indicate that the corresponding template entry can -// contain negative values. This information is used later when packing -// (or unpacking) the template data values. Negative data values in GRIB -// are stored with the left most bit set to one, and a negative number -// of octets value in mapdrs[] indicates that this possibility should -// be considered. The number of octets used to store the data value -// in this case would be the absolute value of the negative value in -// mapdrs[]. -// -// -/////////////////////////////////////////////////////////////////////// - - #define MAXDRSTEMP 9 // maximum number of templates - #define MAXDRSMAPLEN 200 // maximum template map length - - struct drstemplate - { - g2int template_num; - g2int mapdrslen; - g2int needext; - g2int mapdrs[MAXDRSMAPLEN]; - }; - - extern const struct drstemplate templatesdrs[]; - - g2int getdrsindex(g2int number); - -#endif /* _drstemplates_H */ diff --git a/src/plugins/weatherdata/gfs/g2clib/enc_jpeg2000.c b/src/plugins/weatherdata/gfs/g2clib/enc_jpeg2000.c deleted file mode 100644 index 5c2fb3089..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/enc_jpeg2000.c +++ /dev/null @@ -1,179 +0,0 @@ -#ifndef USE_JPEG2000 - void dummy(void) {} -#else /* USE_JPEG2000 */ - -#include -#include -#include "grib2.h" -#include "jasper/jasper.h" -#define JAS_1_700_2 - - -int enc_jpeg2000(unsigned char *cin,g2int width,g2int height,g2int nbits, - g2int ltype, g2int ratio, g2int retry, char *outjpc, - g2int jpclen) -/*$$$ SUBPROGRAM DOCUMENTATION BLOCK -* . . . . -* SUBPROGRAM: enc_jpeg2000 Encodes JPEG2000 code stream -* PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-02 -* -* ABSTRACT: This Function encodes a grayscale image into a JPEG2000 code stream -* specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) -* using JasPer Software version 1.500.4 (or 1.700.2 ) written by the -* University of British Columbia, Image Power Inc, and others. -* JasPer is available at http://www.ece.uvic.ca/~mdadams/jasper/. -* -* PROGRAM HISTORY LOG: -* 2002-12-02 Gilbert -* 2004-12-16 Gilbert - Added retry argument/option to allow option of -* increasing the maximum number of guard bits to the -* JPEG2000 algorithm. -* -* USAGE: int enc_jpeg2000(unsigned char *cin,g2int width,g2int height, -* g2int nbits, g2int ltype, g2int ratio, -* g2int retry, char *outjpc, g2int jpclen) -* -* INPUT ARGUMENTS: -* cin - Packed matrix of Grayscale image values to encode. -* width - width of image -* height - height of image -* nbits - depth (in bits) of image. i.e number of bits -* used to hold each data value -* ltype - indicator of lossless or lossy compression -* = 1, for lossy compression -* != 1, for lossless compression -* ratio - target compression ratio. (ratio:1) -* Used only when ltype == 1. -* retry - Pointer to option type. -* 1 = try increasing number of guard bits -* otherwise, no additional options -* jpclen - Number of bytes allocated for new JPEG2000 code stream in -* outjpc. -* -* INPUT ARGUMENTS: -* outjpc - Output encoded JPEG2000 code stream -* -* RETURN VALUES : -* > 0 = Length in bytes of encoded JPEG2000 code stream -* -3 = Error decode jpeg2000 code stream. -* -5 = decoded image had multiple color components. -* Only grayscale is expected. -* -* REMARKS: -* -* Requires JasPer Software version 1.500.4 or 1.700.2 -* -* ATTRIBUTES: -* LANGUAGE: C -* MACHINE: IBM SP -* -*$$$*/ -{ - int ier,rwcnt; - jas_image_t image; - jas_stream_t *jpcstream,*istream; - jas_image_cmpt_t cmpt,*pcmpt; -#define MAXOPTSSIZE 1024 - char opts[MAXOPTSSIZE]; - -/* - printf(" enc_jpeg2000:width %ld\n",width); - printf(" enc_jpeg2000:height %ld\n",height); - printf(" enc_jpeg2000:nbits %ld\n",nbits); - printf(" enc_jpeg2000:jpclen %ld\n",jpclen); -*/ -// jas_init(); - -// -// Set lossy compression options, if requested. -// - if ( ltype != 1 ) { - opts[0]=(char)0; - } - else { - snprintf(opts,MAXOPTSSIZE,"mode=real\nrate=%f",1.0/(float)ratio); - } - if ( retry == 1 ) { // option to increase number of guard bits - strcat(opts,"\nnumgbits=4"); - } - //printf("SAGopts: %s\n",opts); - -// -// Initialize the JasPer image structure describing the grayscale -// image to encode into the JPEG2000 code stream. -// - image.tlx_=0; - image.tly_=0; -#ifdef JAS_1_500_4 - image.brx_=(uint_fast32_t)width; - image.bry_=(uint_fast32_t)height; -#endif -#ifdef JAS_1_700_2 - image.brx_=(jas_image_coord_t)width; - image.bry_=(jas_image_coord_t)height; -#endif - image.numcmpts_=1; - image.maxcmpts_=1; -#ifdef JAS_1_500_4 - image.colormodel_=JAS_IMAGE_CM_GRAY; /* grayscale Image */ -#endif -#ifdef JAS_1_700_2 - image.clrspc_=JAS_CLRSPC_SGRAY; /* grayscale Image */ - image.cmprof_=0; -#endif - image.inmem_=1; - - cmpt.tlx_=0; - cmpt.tly_=0; - cmpt.hstep_=1; - cmpt.vstep_=1; -#ifdef JAS_1_500_4 - cmpt.width_=(uint_fast32_t)width; - cmpt.height_=(uint_fast32_t)height; -#endif -#ifdef JAS_1_700_2 - cmpt.width_=(jas_image_coord_t)width; - cmpt.height_=(jas_image_coord_t)height; - cmpt.type_=JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y); -#endif - cmpt.prec_=nbits; - cmpt.sgnd_=0; - cmpt.cps_=(nbits+7)/8; - - pcmpt=&cmpt; - image.cmpts_=&pcmpt; - -// -// Open a JasPer stream containing the input grayscale values -// - istream=jas_stream_memopen((char *)cin,height*width*cmpt.cps_); - cmpt.stream_=istream; - -// -// Open an output stream that will contain the encoded jpeg2000 -// code stream. -// - jpcstream=jas_stream_memopen(outjpc,(int)jpclen); - -// -// Encode image. -// - ier=jpc_encode(&image,jpcstream,opts); - if ( ier != 0 ) { - printf(" jpc_encode return = %d \n",ier); - return -3; - } -// -// Clean up JasPer work structures. -// - rwcnt=jpcstream->rwcnt_; - jas_stream_close(istream); - jas_stream_close(jpcstream); -// -// Return size of jpeg2000 code stream -// - return (rwcnt); - -} - -#endif /* USE_JPEG2000 */ diff --git a/src/plugins/weatherdata/gfs/g2clib/enc_png.c b/src/plugins/weatherdata/gfs/g2clib/enc_png.c deleted file mode 100644 index 96284ef6e..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/enc_png.c +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef USE_PNG - void dummy(void) {} -#else /* USE_PNG */ - -#include -#include -#include -#include -#include "grib2.h" - - -struct png_stream { - unsigned char *stream_ptr; /* location to write PNG stream */ - g2int stream_len; /* number of bytes written */ -}; -typedef struct png_stream png_stream; - -void user_write_data(png_structp ,png_bytep , png_uint_32 ); -void user_flush_data(png_structp ); - -void user_write_data(png_structp png_ptr,png_bytep data, png_uint_32 length) -/* - Custom write function used to that libpng will write - to memory location instead of a file on disk -*/ -{ - unsigned char *ptr; - g2int offset; - png_stream *mem; - - mem=(png_stream *)png_get_io_ptr(png_ptr); - ptr=mem->stream_ptr; - offset=mem->stream_len; -/* printf("SAGwr %ld %ld %x\n",offset,length,ptr); */ - /*for (j=offset,k=0;kstream_len += length; -} - - -void user_flush_data(png_structp png_ptr) -/* - Dummy Custom flush function -*/ -{ -} - - -int enc_png(char *data,g2int width,g2int height,g2int nbits,char *pngbuf) -{ - - int color_type; - g2int j,bytes,pnglen,bit_depth; - png_structp png_ptr; - png_infop info_ptr; -// png_bytep *row_pointers[height]; - png_bytep **row_pointers; - png_stream write_io_ptr; - -/* create and initialize png_structs */ - - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, - NULL, NULL); - if (!png_ptr) - return (-1); - - info_ptr = png_create_info_struct(png_ptr); - if (!info_ptr) - { - png_destroy_write_struct(&png_ptr,(png_infopp)NULL); - return (-2); - } - -/* Set Error callback */ - - if (setjmp(png_jmpbuf(png_ptr))) - { - png_destroy_write_struct(&png_ptr, &info_ptr); - return (-3); - } - -/* Initialize info for writing PNG stream to memory */ - - write_io_ptr.stream_ptr=(png_voidp)pngbuf; - write_io_ptr.stream_len=0; - -/* Set new custom write functions */ - - png_set_write_fn(png_ptr,(png_voidp)&write_io_ptr,(png_rw_ptr)user_write_data, - (png_flush_ptr)user_flush_data); -/* png_init_io(png_ptr, fptr); */ -/* png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); */ - -/* Set the image size, colortype, filter type, etc... */ - -/* printf("SAGTsettingIHDR %d %d %d\n",width,height,bit_depth); */ - bit_depth=nbits; - color_type=PNG_COLOR_TYPE_GRAY; - if (nbits == 24 ) { - bit_depth=8; - color_type=PNG_COLOR_TYPE_RGB; - } - else if (nbits == 32 ) { - bit_depth=8; - color_type=PNG_COLOR_TYPE_RGB_ALPHA; - } - png_set_IHDR(png_ptr, info_ptr, width, height, - bit_depth, color_type, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - -/* Put image data into the PNG info structure */ - - /*bytes=bit_depth/8;*/ - bytes=nbits/8; - row_pointers=malloc(height*sizeof(png_bytep)); - for (j=0;j -#include -#include -#include "grib2.h" - -g2int getdim(unsigned char *,g2int *,g2int *,g2int *); -g2int getpoly(unsigned char *,g2int *,g2int *,g2int *); -void simpack(g2float *, g2int, g2int *, unsigned char *, g2int *); -void cmplxpack(g2float *, g2int, g2int, g2int *, unsigned char *, g2int *); -void specpack(g2float *,g2int,g2int,g2int,g2int,g2int *,unsigned char *, - g2int *); -#ifdef USE_PNG - void pngpack(g2float *,g2int,g2int,g2int *,unsigned char *,g2int *); -#endif /* USE_PNG */ -#ifdef USE_JPEG2000 - void jpcpack(g2float *,g2int,g2int,g2int *,unsigned char *,g2int *); -#endif /* USE_JPEG2000 */ - - -g2int g2_addfield(unsigned char *cgrib,g2int ipdsnum,g2int *ipdstmpl, - g2float *coordlist,g2int numcoord,g2int idrsnum,g2int *idrstmpl, - g2float *fld,g2int ngrdpts,g2int ibmap,g2int *bmap) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_addfield -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-11-05 -// -// ABSTRACT: This routine packs up Sections 4 through 7 for a given field -// and adds them to a GRIB2 message. They are Product Definition Section, -// Data Representation Section, Bit-Map Section and Data Section, -// respectively. -// This routine is used with routines "g2_create", "g2_addlocal", -// "g2_addgrid", and "g2_gribend" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// Also, routine g2_addgrid must be called after g2_create and -// before this routine to add the appropriate grid description to -// the GRIB2 message. Also, a call to g2_gribend is required to complete -// GRIB2 message after all fields have been added. -// -// PROGRAM HISTORY LOG: -// 2002-11-05 Gilbert -// 2002-12-23 Gilbert - Added complex spherical harmonic packing -// 2003-08-27 Gilbert - Added support for new templates using -// PNG and JPEG2000 algorithms/templates. -// 2004-11-29 Gilbert - JPEG2000 now allowed to use WMO Template no. 5.40 -// PNG now allowed to use WMO Template no. 5.41 -// - Added check to determine if packing algorithm failed. -// 2005-05-10 Gilbert - Imposed minimum size on cpack, used to hold encoded -// bit string. -// 2009-01-14 Vuong Changed structure name template to gtemplate -// -// USAGE: int g2_addfield(unsigned char *cgrib,g2int ipdsnum,g2int *ipdstmpl, -// g2float *coordlist,g2int numcoord,g2int idrsnum,g2int *idrstmpl, -// g2float *fld,g2int ngrdpts,g2int ibmap,g2int *bmap) -// INPUT ARGUMENT LIST: -// cgrib - Char array that contains the GRIB2 message to which sections -// 4 through 7 should be added. -// ipdsnum - Product Definition Template Number ( see Code Table 4.0) -// ipdstmpl - Contains the data values for the specified Product Definition -// Template ( N=ipdsnum ). Each element of this integer -// array contains an entry (in the order specified) of Product -// Defintion Template 4.N -// coordlist- Array containg floating point values intended to document -// the vertical discretisation associated to model data -// on hybrid coordinate vertical levels. -// numcoord - number of values in array coordlist. -// idrsnum - Data Representation Template Number ( see Code Table 5.0 ) -// idrstmpl - Contains the data values for the specified Data Representation -// Template ( N=idrsnum ). Each element of this integer -// array contains an entry (in the order specified) of Data -// Representation Template 5.N -// Note that some values in this template (eg. reference -// values, number of bits, etc...) may be changed by the -// data packing algorithms. -// Use this to specify scaling factors and order of -// spatial differencing, if desired. -// fld[] - Array of data points to pack. -// ngrdpts - Number of data points in grid. -// i.e. size of fld and bmap. -// ibmap - Bitmap indicator ( see Code Table 6.0 ) -// 0 = bitmap applies and is included in Section 6. -// 1-253 = Predefined bitmap applies -// 254 = Previously defined bitmap applies to this field -// 255 = Bit map does not apply to this product. -// bmap[] - Integer array containing bitmap to be added. ( if ibmap=0 ) -// -// OUTPUT ARGUMENT LIST: -// cgrib - Character array to contain the updated GRIB2 message. -// Must be allocated large enough to store the entire -// GRIB2 message. -// -// RETURN VALUES: -// ierr - Return code. -// > 0 = Current size of updated GRIB2 message -// -1 = GRIB message was not initialized. Need to call -// routine g2_create first. -// -2 = GRIB message already complete. Cannot add new section. -// -3 = Sum of Section byte counts doesn't add to total byte count -// -4 = Previous Section was not 3 or 7. -// -5 = Could not find requested Product Definition Template. -// -6 = Section 3 (GDS) not previously defined in message -// -7 = Tried to use unsupported Data Representationi Template -// -8 = Specified use of a previously defined bitmap, but one -// does not exist in the GRIB message. -// -9 = GDT of one of 5.50 through 5.53 required to pack field -// using DRT 5.51. -// -10 = Error packing data field. -// -// REMARKS: Note that the Sections 4 through 7 can only follow -// Section 3 or Section 7 in a GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - g2int ierr; - static unsigned char G=0x47; // 'G' - static unsigned char R=0x52; // 'R' - static unsigned char I=0x49; // 'I' - static unsigned char B=0x42; // 'B' - static unsigned char s7=0x37; // '7' - - unsigned char *cpack; - static g2int zero=0,one=1,four=4,five=5,six=6,seven=7; - const g2int minsize=50000; - g2int iofst,ibeg,lencurr,len,nsize; - g2int ilen,isecnum,i,nbits,temp,left; - g2int ibmprev,j,lcpack,ioctet,newlen,ndpts; - g2int lensec4,lensec5,lensec6,lensec7; - g2int issec3,isprevbmap,lpos3=0,JJ,KK,MM; - g2int *coordieee; - g2int width=0,height=0,iscan=0,itemp=0; - g2float *pfld; - gtemplate *mappds,*mapdrs; - unsigned int allones=4294967295u; - - (void) width; - (void) height; - (void) iscan; - (void) itemp; - (void) allones; - - ierr=0; -// -// Check to see if beginning of GRIB message exists -// - if ( cgrib[0]!=G || cgrib[1]!=R || cgrib[2]!=I || cgrib[3]!=B ) { - printf("g2_addfield: GRIB not found in given message.\n"); - printf("g2_addfield: Call to routine g2_create required to initialize GRIB messge.\n"); - ierr=-1; - return(ierr); - } -// -// Get current length of GRIB message -// - gbit(cgrib,&lencurr,96,32); -// -// Check to see if GRIB message is already complete -// - if ( cgrib[lencurr-4]==s7 && cgrib[lencurr-3]==s7 && - cgrib[lencurr-2]==s7 && cgrib[lencurr-1]==s7 ) { - printf("g2_addfield: GRIB message already complete. Cannot add new section.\n"); - ierr=-2; - return(ierr); - } -// -// Loop through all current sections of the GRIB message to -// find the last section number. -// - issec3=0; - isprevbmap=0; - len=16; // length of Section 0 - for (;;) { - // Get number and length of next section - iofst=len*8; - gbit(cgrib,&ilen,iofst,32); - iofst=iofst+32; - gbit(cgrib,&isecnum,iofst,8); - iofst=iofst+8; - // Check if previous Section 3 exists - if (isecnum == 3) { - issec3=1; - lpos3=len; - } - // Check if a previous defined bitmap exists - if (isecnum == 6) { - gbit(cgrib,&ibmprev,iofst,8); - iofst=iofst+8; - if ((ibmprev >= 0) && (ibmprev <= 253)) isprevbmap=1; - } - len=len+ilen; - // Exit loop if last section reached - if ( len == lencurr ) break; - // If byte count for each section doesn't match current - // total length, then there is a problem. - if ( len > lencurr ) { - printf("g2_addfield: Section byte counts don''t add to total.\n"); - printf("g2_addfield: Sum of section byte counts = %"PRId32"\n",len); - printf("g2_addfield: Total byte count in Section 0 = %"PRId32"\n",lencurr); - ierr=-3; - return(ierr); - } - } -// -// Sections 4 through 7 can only be added after section 3 or 7. -// - if ( (isecnum != 3) && (isecnum != 7) ) { - printf("g2_addfield: Sections 4-7 can only be added after Section 3 or 7.\n"); - printf("g2_addfield: Section ',isecnum,' was the last found in given GRIB message.\n"); - ierr=-4; - return(ierr); -// -// Sections 4 through 7 can only be added if section 3 was previously defined. -// - } - else if ( ! issec3) { - printf("g2_addfield: Sections 4-7 can only be added if Section 3 was previously included.\n"); - printf("g2_addfield: Section 3 was not found in given GRIB message.\n"); - printf("g2_addfield: Call to routine addgrid required to specify Grid definition.\n"); - ierr=-6; - return(ierr); - } -// -// Add Section 4 - Product Definition Section -// - ibeg=lencurr*8; // Calculate offset for beginning of section 4 - iofst=ibeg+32; // leave space for length of section - sbit(cgrib,&four,iofst,8); // Store section number ( 4 ) - iofst=iofst+8; - sbit(cgrib,&numcoord,iofst,16); // Store num of coordinate values - iofst=iofst+16; - sbit(cgrib,&ipdsnum,iofst,16); // Store Prod Def Template num. - iofst=iofst+16; - // - // Get Product Definition Template - // - mappds=getpdstemplate(ipdsnum); - if (mappds == 0) { // undefined template - ierr=-5; - return(ierr); - } - // - // Extend the Product Definition Template, if necessary. - // The number of values in a specific template may vary - // depending on data specified in the "static" part of the - // template. - // - if ( mappds->needext ) { - free(mappds); - mappds=extpdstemplate(ipdsnum,ipdstmpl); - } - // - // Pack up each input value in array ipdstmpl into the - // the appropriate number of octets, which are specified in - // corresponding entries in array mappds. - // - for (i=0;imaplen;i++) { - nbits=abs(mappds->map[i])*8; - if ( (mappds->map[i] >= 0) || (ipdstmpl[i] >= 0) ) - sbit(cgrib,ipdstmpl+i,iofst,nbits); - else { - sbit(cgrib,&one,iofst,1); - temp=abs(ipdstmpl[i]); - sbit(cgrib,&temp,iofst+1,nbits-1); - } - iofst=iofst+nbits; - } - // Pack template extension, if appropriate - j=mappds->maplen; - if ( mappds->needext && (mappds->extlen > 0) ) { - for (i=0;iextlen;i++) { - nbits=abs(mappds->ext[i])*8; - if ( (mappds->ext[i] >= 0) || (ipdstmpl[j] >= 0) ) - sbit(cgrib,ipdstmpl+j,iofst,nbits); - else { - sbit(cgrib,&one,iofst,1); - temp=abs(ipdstmpl[j]); - sbit(cgrib,&temp,iofst+1,nbits-1); - } - iofst=iofst+nbits; - j++; - } - } - free(mappds); - // - // Add Optional list of vertical coordinate values - // after the Product Definition Template, if necessary. - // - if ( numcoord != 0 ) { - coordieee=(g2int *)calloc(numcoord,sizeof(g2int)); - mkieee(coordlist,coordieee,numcoord); - sbits(cgrib,coordieee,iofst,32,0,numcoord); - iofst=iofst+(32*numcoord); - free(coordieee); - } - // - // Calculate length of section 4 and store it in octets - // 1-4 of section 4. - // - lensec4=(iofst-ibeg)/8; - sbit(cgrib,&lensec4,ibeg,32); -// -// Pack Data using appropriate algorithm -// - // - // Get Data Representation Template - // - mapdrs=getdrstemplate(idrsnum); - if (mapdrs == 0) { - ierr=-5; - return(ierr); - } - // - // contract data field, removing data at invalid grid points, - // if bit-map is provided with field. - // - if ( ibmap == 0 || ibmap==254 ) { - pfld=(g2float *)malloc(ngrdpts*sizeof(g2float)); - ndpts=0; - for (j=0;jmaplen;i++) { - nbits=abs(mapdrs->map[i])*8; - if ( (mapdrs->map[i] >= 0) || (idrstmpl[i] >= 0) ) - sbit(cgrib,idrstmpl+i,iofst,nbits); - else { - sbit(cgrib,&one,iofst,1); - temp=abs(idrstmpl[i]); - sbit(cgrib,&temp,iofst+1,nbits-1); - } - iofst=iofst+nbits; - } - free(mapdrs); - // - // Calculate length of section 5 and store it in octets - // 1-4 of section 5. - // - lensec5=(iofst-ibeg)/8; - sbit(cgrib,&lensec5,ibeg,32); - -// -// Add Section 6 - Bit-Map Section -// - ibeg=iofst; // Calculate offset for beginning of section 6 - iofst=ibeg+32; // leave space for length of section - sbit(cgrib,&six,iofst,8); // Store section number ( 6 ) - iofst=iofst+8; - sbit(cgrib,&ibmap,iofst,8); // Store Bit Map indicator - iofst=iofst+8; - // - // Store bitmap, if supplied - // - if (ibmap == 0) { - sbits(cgrib,bmap,iofst,1,0,ngrdpts); // Store BitMap - iofst=iofst+ngrdpts; - } - // - // If specifying a previously defined bit-map, make sure - // one already exists in the current GRIB message. - // - if ((ibmap==254) && ( ! isprevbmap)) { - printf("g2_addfield: Requested previously defined bitmap,"); - printf(" but one does not exist in the current GRIB message.\n"); - ierr=-8; - return(ierr); - } - // - // Calculate length of section 6 and store it in octets - // 1-4 of section 6. Pad to end of octect, if necessary. - // - left=8-(iofst%8); - if (left != 8) { - sbit(cgrib,&zero,iofst,left); // Pad with zeros to fill Octet - iofst=iofst+left; - } - lensec6=(iofst-ibeg)/8; - sbit(cgrib,&lensec6,ibeg,32); - -// -// Add Section 7 - Data Section -// - ibeg=iofst; // Calculate offset for beginning of section 7 - iofst=ibeg+32; // leave space for length of section - sbit(cgrib,&seven,iofst,8); // Store section number ( 7 ) - iofst=iofst+8; - // Store Packed Binary Data values, if non-constant field - if (lcpack != 0) { - ioctet=iofst/8; - //cgrib(ioctet+1:ioctet+lcpack)=cpack(1:lcpack) - for (j=0;j -#include -#include -#include "grib2.h" - - -g2int g2_addgrid(unsigned char *cgrib,g2int *igds,g2int *igdstmpl,g2int *ideflist,g2int idefnum) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_addgrid -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-11-01 -// -// ABSTRACT: This routine packs up a Grid Definition Section (Section 3) -// and adds it to a GRIB2 message. It is used with routines "g2_create", -// "g2_addlocal", "g2_addfield", -// and "g2_gribend" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// -// PROGRAM HISTORY LOG: -// 2002-11-01 Gilbert -// 2009-01-14 Vuong Changed structure name template to gtemplate -// -// USAGE: int g2_addgrid(unsigned char *cgrib,g2int *igds,g2int *igdstmpl, -// g2int *ideflist,g2int idefnum) -// INPUT ARGUMENTS: -// cgrib - Char array that contains the GRIB2 message to which -// section should be added. -// igds - Contains information needed for GRIB Grid Definition Section 3 -// Must be dimensioned >= 5. -// igds[0]=Source of grid definition (see Code Table 3.0) -// igds[1]=Number of grid points in the defined grid. -// igds[2]=Number of octets needed for each -// additional grid points definition. -// Used to define number of -// points in each row ( or column ) for -// non-regular grids. -// = 0, if using regular grid. -// igds[3]=Interpretation of list for optional points -// definition. (Code Table 3.11) -// igds[4]=Grid Definition Template Number (Code Table 3.1) -// igdstmpl - Contains the data values for the specified Grid Definition -// Template ( NN=igds[4] ). Each element of this integer -// array contains an entry (in the order specified) of Grid -// Defintion Template 3.NN -// ideflist - (Used if igds[2] != 0) This array contains the -// number of grid points contained in each row ( or column ) -// idefnum - (Used if igds[2] != 0) The number of entries -// in array ideflist. i.e. number of rows ( or columns ) -// for which optional grid points are defined. -// -// OUTPUT ARGUMENTS: -// cgrib - Char array to contain the updated GRIB2 message. -// Must be allocated large enough to store the entire -// GRIB2 message. -// -// RETURN VALUES: -// ierr - Return code. -// > 0 = Current size of updated GRIB2 message -// -1 = GRIB message was not initialized. Need to call -// routine gribcreate first. -// -2 = GRIB message already complete. Cannot add new section. -// -3 = Sum of Section byte counts doesn't add to total byte count -// -4 = Previous Section was not 1, 2 or 7. -// -5 = Could not find requested Grid Definition Template. -// -// REMARKS: Note that the Grid Def Section ( Section 3 ) can only follow -// Section 1, 2 or Section 7 in a GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int ierr; - static unsigned char G=0x47; // 'G' - static unsigned char R=0x52; // 'R' - static unsigned char I=0x49; // 'I' - static unsigned char B=0x42; // 'B' - static unsigned char seven=0x37; // '7' - - static g2int one=1,three=3,miss=65535; - g2int lensec3,iofst,ibeg,lencurr,len; - g2int i,j,temp,ilen,isecnum,nbits; - gtemplate *mapgrid=0; - - ierr=0; -// -// Check to see if beginning of GRIB message exists -// - if ( cgrib[0]!=G || cgrib[1]!=R || cgrib[2]!=I || cgrib[3]!=B ) { - printf("g2_addgrid: GRIB not found in given message.\n"); - printf("g2_addgrid: Call to routine gribcreate required to initialize GRIB messge.\n"); - ierr=-1; - return(ierr); - } -// -// Get current length of GRIB message -// - gbit(cgrib,&lencurr,96,32); -// -// Check to see if GRIB message is already complete -// - if ( cgrib[lencurr-4]==seven && cgrib[lencurr-3]==seven && - cgrib[lencurr-2]==seven && cgrib[lencurr-1]==seven ) { - printf("g2_addgrid: GRIB message already complete. Cannot add new section.\n"); - ierr=-2; - return(ierr); - } -// -// Loop through all current sections of the GRIB message to -// find the last section number. -// - len=16; // length of Section 0 - for (;;) { - // Get section number and length of next section - iofst=len*8; - gbit(cgrib,&ilen,iofst,32); - iofst=iofst+32; - gbit(cgrib,&isecnum,iofst,8); - len=len+ilen; - // Exit loop if last section reached - if ( len == lencurr ) break; - // If byte count for each section doesn't match current - // total length, then there is a problem. - if ( len > lencurr ) { - printf("g2_addgrid: Section byte counts don''t add to total.\n"); - printf("g2_addgrid: Sum of section byte counts = %"PRId32"\n",len); - printf("g2_addgrid: Total byte count in Section 0 = %"PRId32"\n",lencurr); - ierr=-3; - return(ierr); - } - } -// -// Section 3 can only be added after sections 1, 2 and 7. -// - if ( (isecnum!=1) && (isecnum!=2) && (isecnum!=7) ) { - printf("g2_addgrid: Section 3 can only be added after Section 1, 2 or 7.\n"); - printf("g2_addgrid: Section ',isecnum,' was the last found in given GRIB message.\n"); - ierr=-4; - return(ierr); - } -// -// Add Section 3 - Grid Definition Section -// - ibeg=lencurr*8; // Calculate offset for beginning of section 3 - iofst=ibeg+32; // leave space for length of section - sbit(cgrib,&three,iofst,8); // Store section number ( 3 ) - iofst=iofst+8; - sbit(cgrib,igds+0,iofst,8); // Store source of Grid def. - iofst=iofst+8; - sbit(cgrib,igds+1,iofst,32); // Store number of data pts. - iofst=iofst+32; - sbit(cgrib,igds+2,iofst,8); // Store number of extra octets. - iofst=iofst+8; - sbit(cgrib,igds+3,iofst,8); // Store interp. of extra octets. - iofst=iofst+8; - // if Octet 6 is not equal to zero, Grid Definition Template may - // not be supplied. - if ( igds[0] == 0 ) - sbit(cgrib,igds+4,iofst,16); // Store Grid Def Template num. - else - sbit(cgrib,&miss,iofst,16); // Store missing value as Grid Def Template num. - iofst=iofst+16; - // - // Get Grid Definition Template - // - if (igds[0] == 0) { - mapgrid=getgridtemplate(igds[4]); - if (mapgrid == 0) { // undefined template - ierr=-5; - return(ierr); - } - // - // Extend the Grid Definition Template, if necessary. - // The number of values in a specific template may vary - // depending on data specified in the "static" part of the - // template. - // - if ( mapgrid->needext ) { - free(mapgrid); - mapgrid=extgridtemplate(igds[4],igdstmpl); - } - } - if (mapgrid==0) { - ierr=-5; - return(ierr); - } - // - // Pack up each input value in array igdstmpl into the - // the appropriate number of octets, which are specified in - // corresponding entries in array mapgrid. - // - for (i=0;imaplen;i++) { - nbits=abs(mapgrid->map[i])*8; - if ( (mapgrid->map[i] >= 0) || (igdstmpl[i] >= 0) ) - sbit(cgrib,igdstmpl+i,iofst,nbits); - else { - sbit(cgrib,&one,iofst,1); - temp=abs(igdstmpl[i]); - sbit(cgrib,&temp,iofst+1,nbits-1); - } - iofst=iofst+nbits; - } - // Pack template extension, if appropriate - j=mapgrid->maplen; - if ( mapgrid->needext && (mapgrid->extlen > 0) ) { - for (i=0;iextlen;i++) { - nbits=abs(mapgrid->ext[i])*8; - if ( (mapgrid->ext[i] >= 0) || (igdstmpl[j] >= 0) ) - sbit(cgrib,igdstmpl+j,iofst,nbits); - else { - sbit(cgrib,&one,iofst,1); - temp=abs(igdstmpl[j]); - sbit(cgrib,&temp,iofst+1,nbits-1); - } - iofst=iofst+nbits; - j++; - } - } - free(mapgrid); - // - // If requested, - // Insert optional list of numbers defining number of points - // in each row or column. This is used for non regular - // grids. - // - if ( igds[2] != 0 ) { - nbits=igds[2]*8; - sbits(cgrib,ideflist,iofst,nbits,0,idefnum); - iofst=iofst+(nbits*idefnum); - } - // - // Calculate length of section 3 and store it in octets - // 1-4 of section 3. - // - lensec3=(iofst-ibeg)/8; - sbit(cgrib,&lensec3,ibeg,32); - -// -// Update current byte total of message in Section 0 -// - lencurr+=lensec3; - sbit(cgrib,&lencurr,96,32); - - return(lencurr); - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_addlocal.c b/src/plugins/weatherdata/gfs/g2clib/g2_addlocal.c deleted file mode 100644 index e4f295142..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_addlocal.c +++ /dev/null @@ -1,148 +0,0 @@ -#include -#include -#include "grib2.h" - -g2int g2_addlocal(unsigned char *cgrib,unsigned char *csec2,g2int lcsec2) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_addlocal -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-11-01 -// -// ABSTRACT: This routine adds a Local Use Section (Section 2) to -// a GRIB2 message. It is used with routines "g2_create", -// "g2_addgrid", "g2_addfield", -// and "g2_gribend" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// -// PROGRAM HISTORY LOG: -// 2002-11-01 Gilbert -// -// USAGE: int g2_addlocal(unsigned char *cgrib,unsigned char *csec2, -// g2int lcsec2) -// INPUT ARGUMENTS: -// cgrib - Char array that contains the GRIB2 message to which section -// 2 should be added. -// csec2 - Character array containing information to be added in -// Section 2. -// lcsec2 - Number of bytes of character array csec2 to be added to -// Section 2. -// -// OUTPUT ARGUMENT: -// cgrib - Char array to contain the updated GRIB2 message. -// Must be allocated large enough to store the entire -// GRIB2 message. -// -// RETURN VALUES: -// ierr - Return code. -// > 0 = Current size of updated GRIB2 message -// -1 = GRIB message was not initialized. Need to call -// routine gribcreate first. -// -2 = GRIB message already complete. Cannot add new section. -// -3 = Sum of Section byte counts doesn't add to total byte count -// -4 = Previous Section was not 1 or 7. -// -// REMARKS: Note that the Local Use Section ( Section 2 ) can only follow -// Section 1 or Section 7 in a GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int ierr; - static unsigned char G=0x47; // 'G' - static unsigned char R=0x52; // 'R' - static unsigned char I=0x49; // 'I' - static unsigned char B=0x42; // 'B' - static unsigned char seven=0x37; // '7' - - static g2int two=2; - g2int j,k,lensec2,iofst,ibeg,lencurr,ilen,len,istart; - g2int isecnum; - - ierr=0; -// -// Check to see if beginning of GRIB message exists -// - if ( cgrib[0]!=G || cgrib[1]!=R || cgrib[2]!=I || cgrib[3]!=B ) { - printf("g2_addlocal: GRIB not found in given message.\n"); - printf("g2_addlocal: Call to routine g2_create required to initialize GRIB messge.\n"); - ierr=-1; - return(ierr); - } -// -// Get current length of GRIB message -// - gbit(cgrib,&lencurr,96,32); -// -// Check to see if GRIB message is already complete -// - if ( cgrib[lencurr-4]==seven && cgrib[lencurr-3]==seven && - cgrib[lencurr-2]==seven && cgrib[lencurr-1]==seven ) { - printf("g2_addlocal: GRIB message already complete. Cannot add new section.\n"); - ierr=-2; - return(ierr); - } -// -// Loop through all current sections of the GRIB message to -// find the last section number. -// - len=16; // length of Section 0 - for (;;) { - // Get section number and length of next section - iofst=len*8; - gbit(cgrib,&ilen,iofst,32); - iofst=iofst+32; - gbit(cgrib,&isecnum,iofst,8); - len=len+ilen; - // Exit loop if last section reached - if ( len == lencurr ) break; - // If byte count for each section doesn't match current - // total length, then there is a problem. - if ( len > lencurr ) { - printf("g2_addlocal: Section byte counts don't add to total.\n"); - printf("g2_addlocal: Sum of section byte counts = %"PRId32"\n",len); - printf("g2_addlocal: Total byte count in Section 0 = %"PRId32"\n",lencurr); - ierr=-3; - return(ierr); - } - } -// -// Section 2 can only be added after sections 1 and 7. -// - if ( (isecnum!=1) && (isecnum!=7) ) { - printf("g2_addlocal: Section 2 can only be added after Section 1 or Section 7.\n"); - printf("g2_addlocal: Section %"PRId32" was the last found in given GRIB message.\n",isecnum); - ierr=-4; - return(ierr); - } -// -// Add Section 2 - Local Use Section -// - ibeg=lencurr*8; // Calculate offset for beginning of section 2 - iofst=ibeg+32; // leave space for length of section - sbit(cgrib,&two,iofst,8); // Store section number ( 2 ) - istart=lencurr+5; - //cgrib(istart+1:istart+lcsec2)=csec2(1:lcsec2) - k=0; - for (j=istart;j -#include "grib2.h" - -#define MAPSEC1LEN 13 - -g2int g2_create(unsigned char *cgrib,g2int *listsec0,g2int *listsec1) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_create -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This routine initializes a new GRIB2 message and packs -// GRIB2 sections 0 (Indicator Section) and 1 (Identification Section). -// This routine is used with routines "g2_addlocal", "g2_addgrid", -// "g2_addfield", and "g2_gribend" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// Also, a call to g2_gribend is required to complete GRIB2 message -// after all fields have been added. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// -// USAGE: int g2_create(unsigned char *cgrib,g2int *listsec0,g2int *listsec1) -// INPUT ARGUMENTS: -// cgrib - Character array to contain the GRIB2 message -// listsec0 - Contains information needed for GRIB Indicator Section 0. -// Must be dimensioned >= 2. -// listsec0[0]=Discipline-GRIB Master Table Number -// (see Code Table 0.0) -// listsec0[1]=GRIB Edition Number (currently 2) -// listsec1 - Contains information needed for GRIB Identification Section 1. -// Must be dimensioned >= 13. -// listsec1[0]=Id of orginating centre (Common Code Table C-1) -// listsec1[1]=Id of orginating sub-centre (local table) -// listsec1[2]=GRIB Master Tables Version Number (Code Table 1.0) -// listsec1[3]=GRIB Local Tables Version Number (Code Table 1.1) -// listsec1[4]=Significance of Reference Time (Code Table 1.2) -// listsec1[5]=Reference Time - Year (4 digits) -// listsec1[6]=Reference Time - Month -// listsec1[7]=Reference Time - Day -// listsec1[8]=Reference Time - Hour -// listsec1[9]=Reference Time - Minute -// listsec1[10]=Reference Time - Second -// listsec1[11]=Production status of data (Code Table 1.3) -// listsec1[12]=Type of processed data (Code Table 1.4) -// -// OUTPUT ARGUMENTS: -// cgrib - Char array to contain the new GRIB2 message. -// Must be allocated large enough to store the entire -// GRIB2 message. -// -// RETURN VALUES: -// ierr - return code. -// > 0 = Current size of new GRIB2 message -// -1 = Tried to use for version other than GRIB Edition 2 -// -// REMARKS: This routine is intended for use with routines "g2_addlocal", -// "g2_addgrid", "g2_addfield", and "g2_gribend" to create a complete -// GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int ierr; - g2int zero=0,one=1; - g2int mapsec1len=MAPSEC1LEN; - g2int mapsec1[MAPSEC1LEN]={ 2,2,1,1,1,2,1,1,1,1,1,1,1 }; - g2int i,lensec0,lensec1,iofst,ibeg,nbits,len; - - ierr=0; -// -// Currently handles only GRIB Edition 2. -// - if (listsec0[1] != 2) { - printf("g2_create: can only code GRIB edition 2."); - ierr=-1; - return (ierr); - } -// -// Pack Section 0 - Indicator Section -// ( except for total length of GRIB message ) -// - cgrib[0]=0x47; // 'G' // Beginning of GRIB message - cgrib[1]=0x52; // 'R' - cgrib[2]=0x49; // 'I' - cgrib[3]=0x42; // 'B' - sbit(cgrib,&zero,32,16); // reserved for future use - sbit(cgrib,listsec0+0,48,8); // Discipline - sbit(cgrib,listsec0+1,56,8); // GRIB edition number - lensec0=16; // bytes (octets) -// -// Pack Section 1 - Identification Section -// - ibeg=lensec0*8; // Calculate offset for beginning of section 1 - iofst=ibeg+32; // leave space for length of section - sbit(cgrib,&one,iofst,8); // Store section number ( 1 ) - iofst=iofst+8; - // - // Pack up each input value in array listsec1 into the - // the appropriate number of octets, which are specified in - // corresponding entries in array mapsec1. - // - for (i=0;i -#include "grib2.h" - -void g2_free(gribfield *gfld) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_free -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-28 -// -// ABSTRACT: This routine frees up memory that was allocated for -// struct gribfield. -// -// PROGRAM HISTORY LOG: -// 2002-10-28 Gilbert -// -// USAGE: g2_free(gribfield *gfld) -// ARGUMENT: -// gfld - pointer to gribfield structure (defined in include file grib2.h) -// returned from routine g2_getfld. -// -// REMARKS: This routine must be called to free up memory used by -// the decode routine, g2_getfld, when user no longer needs to -// reference this data. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - if (gfld->idsect != 0 ) free(gfld->idsect); - if (gfld->local != 0 ) free(gfld->local); - if (gfld->list_opt != 0 ) free(gfld->list_opt); - if (gfld->igdtmpl != 0 ) free(gfld->igdtmpl); - if (gfld->ipdtmpl != 0 ) free(gfld->ipdtmpl); - if (gfld->coord_list != 0 ) free(gfld->coord_list); - if (gfld->idrtmpl != 0 ) free(gfld->idrtmpl); - if (gfld->bmap != 0 ) free(gfld->bmap); - if (gfld->fld != 0 ) free(gfld->fld); - free(gfld); - - return; -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_getfld.c b/src/plugins/weatherdata/gfs/g2clib/g2_getfld.c deleted file mode 100644 index d4935ad9f..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_getfld.c +++ /dev/null @@ -1,552 +0,0 @@ -#include -#include -#include -#include "grib2.h" - -g2int g2_unpack1(unsigned char *,g2int *,g2int **,g2int *); -g2int g2_unpack2(unsigned char *,g2int *,g2int *,unsigned char **); -g2int g2_unpack3(unsigned char *,g2int *,g2int **,g2int **, - g2int *,g2int **,g2int *); -g2int g2_unpack4(unsigned char *,g2int *,g2int *,g2int **, - g2int *,g2float **,g2int *); -g2int g2_unpack5(unsigned char *,g2int *,g2int *,g2int *, g2int **,g2int *); -g2int g2_unpack6(unsigned char *,g2int *,g2int ,g2int *, g2int **); -g2int g2_unpack7(unsigned char *,g2int *,g2int ,g2int *, - g2int ,g2int *,g2int ,g2float **); - -g2int g2_getfld(unsigned char *cgrib,g2int ifldnum,g2int unpack,g2int expand, - gribfield **gfld) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_getfld -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-28 -// -// ABSTRACT: This subroutine returns all the metadata, template values, -// Bit-map ( if applicable ), and the unpacked data for a given data -// field. All of the information returned is stored in a gribfield -// structure, which is defined in file grib2.h. -// Users of this routine will need to include "grib2.h" in their source -// code that calls this routine. Each component of the gribfield -// struct is also described in the OUTPUT ARGUMENTS section below. -// -// Since there can be multiple data fields packed into a GRIB2 -// message, the calling routine indicates which field is being requested -// with the ifldnum argument. -// -// PROGRAM HISTORY LOG: -// 2002-10-28 Gilbert -// 2013-08-08 Vuong Free up memory in array igds - free(igds) -// -// USAGE: #include "grib2.h" -// int g2_getfld(unsigned char *cgrib,g2int ifldnum,g2int unpack, -// g2int expand,gribfield **gfld) -// INPUT ARGUMENTS: -// cgrib - Character pointer to the GRIB2 message -// ifldnum - Specifies which field in the GRIB2 message to return. -// unpack - Boolean value indicating whether to unpack bitmap/data field -// 1 = unpack bitmap (if present) and data values -// 0 = do not unpack bitmap and data values -// expand - Boolean value indicating whether the data points should be -// expanded to the correspond grid, if a bit-map is present. -// 1 = if possible, expand data field to grid, inserting zero -// values at gridpoints that are bitmapped out. -// (SEE REMARKS2) -// 0 = do not expand data field, leaving it an array of -// consecutive data points for each "1" in the bitmap. -// This argument is ignored if unpack == 0 OR if the -// returned field does not contain a bit-map. -// -// OUTPUT ARGUMENT: -// gribfield gfld; - pointer to structure gribfield containing -// all decoded data for the data field. -// -// gfld->version = GRIB edition number ( currently 2 ) -// gfld->discipline = Message Discipline ( see Code Table 0.0 ) -// gfld->idsect = Contains the entries in the Identification -// Section ( Section 1 ) -// This element is a pointer to an array -// that holds the data. -// gfld->idsect[0] = Identification of originating Centre -// ( see Common Code Table C-1 ) -// 7 - US National Weather Service -// gfld->idsect[1] = Identification of originating Sub-centre -// gfld->idsect[2] = GRIB Master Tables Version Number -// ( see Code Table 1.0 ) -// 0 - Experimental -// 1 - Initial operational version number -// gfld->idsect[3] = GRIB Local Tables Version Number -// ( see Code Table 1.1 ) -// 0 - Local tables not used -// 1-254 - Number of local tables version used -// gfld->idsect[4] = Significance of Reference Time (Code Table 1.2) -// 0 - Analysis -// 1 - Start of forecast -// 2 - Verifying time of forecast -// 3 - Observation time -// gfld->idsect[5] = Year ( 4 digits ) -// gfld->idsect[6] = Month -// gfld->idsect[7) = Day -// gfld->idsect[8] = Hour -// gfld->idsect[9] = Minute -// gfld->idsect[10] = Second -// gfld->idsect[11] = Production status of processed data -// ( see Code Table 1.3 ) -// 0 - Operational products -// 1 - Operational test products -// 2 - Research products -// 3 - Re-analysis products -// gfld->idsect[12] = Type of processed data ( see Code Table 1.4 ) -// 0 - Analysis products -// 1 - Forecast products -// 2 - Analysis and forecast products -// 3 - Control forecast products -// 4 - Perturbed forecast products -// 5 - Control and perturbed forecast products -// 6 - Processed satellite observations -// 7 - Processed radar observations -// gfld->idsectlen = Number of elements in gfld->idsect[]. -// gfld->local = Pointer to character array containing contents -// of Local Section 2, if included -// gfld->locallen = length of array gfld->local[] -// gfld->ifldnum = field number within GRIB message -// gfld->griddef = Source of grid definition (see Code Table 3.0) -// 0 - Specified in Code table 3.1 -// 1 - Predetermined grid Defined by originating centre -// gfld->ngrdpts = Number of grid points in the defined grid. -// gfld->numoct_opt = Number of octets needed for each -// additional grid points definition. -// Used to define number of -// points in each row ( or column ) for -// non-regular grids. -// = 0, if using regular grid. -// gfld->interp_opt = Interpretation of list for optional points -// definition. (Code Table 3.11) -// gfld->igdtnum = Grid Definition Template Number (Code Table 3.1) -// gfld->igdtmpl = Contains the data values for the specified Grid -// Definition Template ( NN=gfld->igdtnum ). Each -// element of this integer array contains an entry (in -// the order specified) of Grid Defintion Template 3.NN -// This element is a pointer to an array -// that holds the data. -// gfld->igdtlen = Number of elements in gfld->igdtmpl[]. i.e. number of -// entries in Grid Defintion Template 3.NN -// ( NN=gfld->igdtnum ). -// gfld->list_opt = (Used if gfld->numoct_opt .ne. 0) This array -// contains the number of grid points contained in -// each row ( or column ). (part of Section 3) -// This element is a pointer to an array -// that holds the data. This pointer is nullified -// if gfld->numoct_opt=0. -// gfld->num_opt = (Used if gfld->numoct_opt .ne. 0) -// The number of entries -// in array ideflist. i.e. number of rows ( or columns ) -// for which optional grid points are defined. This value -// is set to zero, if gfld->numoct_opt=0. -// gfdl->ipdtnum = Product Definition Template Number(see Code Table 4.0) -// gfld->ipdtmpl = Contains the data values for the specified Product -// Definition Template ( N=gfdl->ipdtnum ). Each element -// of this integer array contains an entry (in the -// order specified) of Product Defintion Template 4.N. -// This element is a pointer to an array -// that holds the data. -// gfld->ipdtlen = Number of elements in gfld->ipdtmpl[]. i.e. number of -// entries in Product Defintion Template 4.N -// ( N=gfdl->ipdtnum ). -// gfld->coord_list = Real array containing floating point values -// intended to document the vertical discretisation -// associated to model data on hybrid coordinate -// vertical levels. (part of Section 4) -// This element is a pointer to an array -// that holds the data. -// gfld->num_coord = number of values in array gfld->coord_list[]. -// gfld->ndpts = Number of data points unpacked and returned. -// gfld->idrtnum = Data Representation Template Number -// ( see Code Table 5.0) -// gfld->idrtmpl = Contains the data values for the specified Data -// Representation Template ( N=gfld->idrtnum ). Each -// element of this integer array contains an entry -// (in the order specified) of Product Defintion -// Template 5.N. -// This element is a pointer to an array -// that holds the data. -// gfld->idrtlen = Number of elements in gfld->idrtmpl[]. i.e. number -// of entries in Data Representation Template 5.N -// ( N=gfld->idrtnum ). -// gfld->unpacked = logical value indicating whether the bitmap and -// data values were unpacked. If false, -// gfld->bmap and gfld->fld pointers are nullified. -// gfld->expanded = Logical value indicating whether the data field -// was expanded to the grid in the case where a -// bit-map is present. If true, the data points in -// gfld->fld match the grid points and zeros were -// inserted at grid points where data was bit-mapped -// out. If false, the data values in gfld->fld were -// not expanded to the grid and are just a consecutive -// array of data points corresponding to each value of -// "1" in gfld->bmap. -// gfld->ibmap = Bitmap indicator ( see Code Table 6.0 ) -// 0 = bitmap applies and is included in Section 6. -// 1-253 = Predefined bitmap applies -// 254 = Previously defined bitmap applies to this field -// 255 = Bit map does not apply to this product. -// gfld->bmap = integer array containing decoded bitmap, -// if gfld->ibmap=0 or gfld->ibap=254. Otherwise nullified -// This element is a pointer to an array -// that holds the data. -// gfld->fld = Array of gfld->ndpts unpacked data points. -// This element is a pointer to an array -// that holds the data. -// -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 1 = Beginning characters "GRIB" not found. -// 2 = GRIB message is not Edition 2. -// 3 = The data field request number was not positive. -// 4 = End string "7777" found, but not where expected. -// 6 = GRIB message did not contain the requested number of -// data fields. -// 7 = End string "7777" not found at end of message. -// 8 = Unrecognized Section encountered. -// 9 = Data Representation Template 5.NN not yet implemented. -// 15 = Error unpacking Section 1. -// 16 = Error unpacking Section 2. -// 10 = Error unpacking Section 3. -// 11 = Error unpacking Section 4. -// 12 = Error unpacking Section 5. -// 13 = Error unpacking Section 6. -// 14 = Error unpacking Section 7. -// 17 = Previous bitmap specified, yet none exists. -// -// REMARKS: Note that struct gribfield is allocated by this routine and it -// also contains pointers to many arrays of data that were allocated -// during decoding. Users are encouraged to free up this memory, -// when it is no longer needed, by an explicit call to routine g2_free. -// EXAMPLE: -// #include "grib2.h" -// gribfield *gfld; -// ret=g2_getfld(cgrib,1,1,1,&gfld); -// ... -// g2_free(gfld); -// -// Routine g2_info can be used to first determine -// how many data fields exist in a given GRIB message. -// -// REMARKS2: It may not always be possible to expand a bit-mapped data field. -// If a pre-defined bit-map is used and not included in the GRIB2 -// message itself, this routine would not have the necessary -// information to expand the data. In this case, gfld->expanded would -// would be set to 0 (false), regardless of the value of input -// argument expand. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int have3,have4,have5,have6,have7,ierr,jerr; - g2int numfld,j,n,istart,iofst,ipos; - g2int disc,ver,lensec0,lengrib,lensec,isecnum; - g2int *igds; - g2int *bmpsave; - g2float *newfld; - gribfield *lgfld; - - have3=0; - have4=0; - have5=0; - have6=0; - have7=0; - ierr=0; - numfld=0; - - lgfld=(gribfield *)malloc(sizeof(gribfield)); - *gfld=lgfld; - - lgfld->locallen=0; - lgfld->idsect=0; - lgfld->local=0; - lgfld->list_opt=0; - lgfld->igdtmpl=0; - lgfld->ipdtmpl=0; - lgfld->idrtmpl=0; - lgfld->coord_list=0; - lgfld->bmap=0; - lgfld->fld=0; -// -// Check for valid request number -// - if (ifldnum <= 0) { - printf("g2_getfld: Request for field number must be positive.\n"); - ierr=3; - return(ierr); - } -// -// Check for beginning of GRIB message in the first 100 bytes -// - istart=-1; - for (j=0;j<100;j++) { - if (cgrib[j]=='G' && cgrib[j+1]=='R' &&cgrib[j+2]=='I' && - cgrib[j+3]=='B') { - istart=j; - break; - } - } - if (istart == -1) { - printf("g2_getfld: Beginning characters GRIB not found.\n"); - ierr=1; - return(ierr); - } -// -// Unpack Section 0 - Indicator Section -// - iofst=8*(istart+6); - gbit(cgrib,&disc,iofst,8); // Discipline - iofst=iofst+8; - gbit(cgrib,&ver,iofst,8); // GRIB edition number - iofst=iofst+8; - iofst=iofst+32; - gbit(cgrib,&lengrib,iofst,32); // Length of GRIB message - iofst=iofst+32; - lensec0=16; - ipos=istart+lensec0; -// -// Currently handles only GRIB Edition 2. -// - if (ver != 2) { - printf("g2_getfld: can only decode GRIB edition 2.\n"); - ierr=2; - return(ierr); - } -// -// Loop through the remaining sections keeping track of the -// length of each. Also keep the latest Grid Definition Section info. -// Unpack the requested field number. -// - for (;;) { - // Check to see if we are at end of GRIB message - if (cgrib[ipos]=='7' && cgrib[ipos+1]=='7' && cgrib[ipos+2]=='7' && - cgrib[ipos+3]=='7') { - ipos=ipos+4; - // If end of GRIB message not where expected, issue error - if (ipos != (istart+lengrib)) { - printf("g2_getfld: '7777' found, but not where expected.\n"); - ierr=4; - return(ierr); - } - break; - } - // Get length of Section and Section number - iofst=ipos*8; - gbit(cgrib,&lensec,iofst,32); // Get Length of Section - iofst=iofst+32; - gbit(cgrib,&isecnum,iofst,8); // Get Section number - iofst=iofst+8; - //printf(" lensec= %"PRId32" secnum= %"PRId32" \n",lensec,isecnum); - // - // Check to see if section number is valid - // - if ( isecnum<1 || isecnum>7 ) { - printf("g2_getfld: Unrecognized Section Encountered=%"PRId32"\n",isecnum); - ierr=8; - return(ierr); - } - // - // If found Section 1, decode elements in Identification Section - // - if (isecnum == 1) { - iofst=iofst-40; // reset offset to beginning of section - jerr=g2_unpack1(cgrib,&iofst,&lgfld->idsect,&lgfld->idsectlen); - if (jerr !=0 ) { - ierr=15; - return(ierr); - } - } - // - // If found Section 2, Grab local section - // Save in case this is the latest one before the requested field. - // - if (isecnum == 2) { - iofst=iofst-40; // reset offset to beginning of section - if (lgfld->local!=0) free(lgfld->local); - jerr=g2_unpack2(cgrib,&iofst,&lgfld->locallen,&lgfld->local); - if (jerr != 0) { - ierr=16; - return(ierr); - } - } - // - // If found Section 3, unpack the GDS info using the - // appropriate template. Save in case this is the latest - // grid before the requested field. - // - if (isecnum == 3) { - iofst=iofst-40; // reset offset to beginning of section - if (lgfld->igdtmpl!=0) free(lgfld->igdtmpl); - if (lgfld->list_opt!=0) free(lgfld->list_opt); - jerr=g2_unpack3(cgrib,&iofst,&igds,&lgfld->igdtmpl, - &lgfld->igdtlen,&lgfld->list_opt,&lgfld->num_opt); - if (jerr == 0) { - have3=1; - lgfld->griddef=igds[0]; - lgfld->ngrdpts=igds[1]; - lgfld->numoct_opt=igds[2]; - lgfld->interp_opt=igds[3]; - lgfld->igdtnum=igds[4]; - free(igds); - } - else { - ierr=10; - return(ierr); - } - } - // - // If found Section 4, check to see if this field is the - // one requested. - // - if (isecnum == 4) { - numfld=numfld+1; - if (numfld == ifldnum) { - lgfld->discipline=disc; - lgfld->version=ver; - lgfld->ifldnum=ifldnum; - lgfld->unpacked=unpack; - lgfld->expanded=0; - iofst=iofst-40; // reset offset to beginning of section - jerr=g2_unpack4(cgrib,&iofst,&lgfld->ipdtnum, - &lgfld->ipdtmpl,&lgfld->ipdtlen,&lgfld->coord_list, - &lgfld->num_coord); - if (jerr == 0) - have4=1; - else { - ierr=11; - return(ierr); - } - } - } - // - // If found Section 5, check to see if this field is the - // one requested. - // - if (isecnum == 5 && numfld == ifldnum) { - iofst=iofst-40; // reset offset to beginning of section - jerr=g2_unpack5(cgrib,&iofst,&lgfld->ndpts,&lgfld->idrtnum, - &lgfld->idrtmpl,&lgfld->idrtlen); - if (jerr == 0) - have5=1; - else { - ierr=12; - return(ierr); - } - } - // - // If found Section 6, Unpack bitmap. - // Save in case this is the latest - // bitmap before the requested field. - // - if (isecnum == 6) { - if (unpack) { // unpack bitmap - iofst=iofst-40; // reset offset to beginning of section - bmpsave=lgfld->bmap; // save pointer to previous bitmap - jerr=g2_unpack6(cgrib,&iofst,lgfld->ngrdpts,&lgfld->ibmap, - &lgfld->bmap); - if (jerr == 0) { - have6=1; - if (lgfld->ibmap == 254) // use previously specified bitmap - if( bmpsave!=0 ) - lgfld->bmap=bmpsave; - else { - printf("g2_getfld: Prev bit-map specified, but none exist.\n"); - ierr=17; - return(ierr); - } - else // get rid of it - if( bmpsave!=0 ) free(bmpsave); - } - else { - ierr=13; - return(ierr); - } - } - else { // do not unpack bitmap - gbit(cgrib,&lgfld->ibmap,iofst,8); // Get BitMap Indicator - have6=1; - } - } - // - // If found Section 7, check to see if this field is the - // one requested. - // - if (isecnum==7 && numfld==ifldnum && unpack) { - iofst=iofst-40; // reset offset to beginning of section - jerr=g2_unpack7(cgrib,&iofst,lgfld->igdtnum,lgfld->igdtmpl, - lgfld->idrtnum,lgfld->idrtmpl,lgfld->ndpts, - &lgfld->fld); - if (jerr == 0) { - have7=1; - // If bitmap is used with this field, expand data field - // to grid, if possible. - if ( lgfld->ibmap != 255 && lgfld->bmap != 0 ) { - if ( expand == 1 ) { - n=0; - newfld=(g2float *)calloc(lgfld->ngrdpts,sizeof(g2float)); - for (j=0;jngrdpts;j++) { - if (lgfld->bmap[j]==1) newfld[j]=lgfld->fld[n++]; - } - free(lgfld->fld); - lgfld->fld=newfld; - lgfld->expanded=1; - } - else { - lgfld->expanded=0; - } - } - else { - lgfld->expanded=1; - } - } - else { - printf("g2_getfld: return from g2_unpack7 = %d \n",(int)jerr); - ierr=14; - return(ierr); - } - } - // - // Check to see if we read pass the end of the GRIB - // message and missed the terminator string '7777'. - // - ipos=ipos+lensec; // Update beginning of section pointer - if (ipos > (istart+lengrib)) { - printf("g2_getfld: '7777' not found at end of GRIB message.\n"); - ierr=7; - return(ierr); - } - // - // If unpacking requested, return when all sections have been - // processed - // - if (unpack && have3 && have4 && have5 && have6 && have7) - return(ierr); - // - // If unpacking is not requested, return when sections - // 3 through 6 have been processed - // - if ((! unpack) && have3 && have4 && have5 && have6) - return(ierr); - - } - -// -// If exited from above loop, the end of the GRIB message was reached -// before the requested field was found. -// - printf("g2_getfld: GRIB message contained %"PRId32" different fields.\n",numfld); - printf("g2_getfld: The request was for field %"PRId32".\n",ifldnum); - ierr=6; - - return(ierr); - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_gribend.c b/src/plugins/weatherdata/gfs/g2clib/g2_gribend.c deleted file mode 100644 index b50f2c001..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_gribend.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include "grib2.h" - -g2int g2_gribend(unsigned char *cgrib) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_gribend -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This routine finalizes a GRIB2 message after all grids -// and fields have been added. It adds the End Section ( "7777" ) -// to the end of the GRIB message and calculates the length and stores -// it in the appropriate place in Section 0. -// This routine is used with routines "g2_create", "g2_addlocal", -// "g2_addgrid", and "g2_addfield" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// -// USAGE: int g2_gribend(unsigned char *cgrib) -// INPUT ARGUMENT: -// cgrib - Char array containing all the data sections added -// be previous calls to g2_create, g2_addlocal, g2_addgrid, -// and g2_addfield. -// -// OUTPUT ARGUMENTS: -// cgrib - Char array containing the finalized GRIB2 message -// -// RETURN VALUES: -// ierr - Return code. -// > 0 = Length of the final GRIB2 message in bytes. -// -1 = GRIB message was not initialized. Need to call -// routine g2_create first. -// -2 = GRIB message already complete. -// -3 = Sum of Section byte counts doesn't add to total byte count -// -4 = Previous Section was not 7. -// -// REMARKS: This routine is intended for use with routines "g2_create", -// "g2_addlocal", "g2_addgrid", and "g2_addfield" to create a complete -// GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int iofst,lencurr,len,ilen,isecnum; - g2int ierr,lengrib; - static unsigned char G=0x47; // 'G' - static unsigned char R=0x52; // 'R' - static unsigned char I=0x49; // 'I' - static unsigned char B=0x42; // 'B' - static unsigned char seven=0x37; // '7' - - ierr=0; -// -// Check to see if beginning of GRIB message exists -// - if ( cgrib[0]!=G || cgrib[1]!=R || cgrib[2]!=I || cgrib[3]!=B ) { - printf("g2_gribend: GRIB not found in given message.\n"); - ierr=-1; - return (ierr); - } -// -// Get current length of GRIB message -// - gbit(cgrib,&lencurr,96,32); -// -// Loop through all current sections of the GRIB message to -// find the last section number. -// - len=16; // Length of Section 0 - for (;;) { - // Get number and length of next section - iofst=len*8; - gbit(cgrib,&ilen,iofst,32); - iofst=iofst+32; - gbit(cgrib,&isecnum,iofst,8); - len=len+ilen; - // Exit loop if last section reached - if ( len == lencurr ) break; - // If byte count for each section doesn't match current - // total length, then there is a problem. - if ( len > lencurr ) { - printf("g2_gribend: Section byte counts don''t add to total.\n"); - printf("g2_gribend: Sum of section byte counts = %d\n",(int)len); - printf("g2_gribend: Total byte count in Section 0 = %d\n",(int)lencurr); - ierr=-3; - return (ierr); - } - } -// -// Can only add End Section (Section 8) after Section 7. -// - if ( isecnum != 7 ) { - printf("g2_gribend: Section 8 can only be added after Section 7.\n"); - printf("g2_gribend: Section %"PRId32" was the last found in given GRIB message.\n",isecnum); - ierr=-4; - return (ierr); - } -// -// Add Section 8 - End Section -// - //cgrib(lencurr+1:lencurr+4)=c7777 - cgrib[lencurr]=seven; - cgrib[lencurr+1]=seven; - cgrib[lencurr+2]=seven; - cgrib[lencurr+3]=seven; - -// -// Update current byte total of message in Section 0 -// - lengrib=lencurr+4; - sbit(cgrib,&lengrib,96,32); - - return (lengrib); - -} - diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_info.c b/src/plugins/weatherdata/gfs/g2clib/g2_info.c deleted file mode 100644 index 4b9fdeb56..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_info.c +++ /dev/null @@ -1,191 +0,0 @@ -#include -#include -#include -#include "grib2.h" - -g2int g2_info(unsigned char *cgrib,g2int *listsec0,g2int *listsec1, - g2int *numfields,g2int *numlocal) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_info -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-28 -// -// ABSTRACT: This subroutine searches through a GRIB2 message and -// returns the number of gridded fields found in the message and -// the number (and maximum size) of Local Use Sections. -// Also various checks are performed -// to see if the message is a valid GRIB2 message. -// -// PROGRAM HISTORY LOG: -// 2002-10-28 Gilbert -// -// USAGE: int g2_info(unsigned char *cgrib,g2int *listsec0,g2int *listsec1, -// g2int *numfields,g2int *numlocal) -// INPUT ARGUMENT: -// cgrib - Character pointer to the GRIB2 message -// -// OUTPUT ARGUMENTS: -// listsec0 - pointer to an array containing information decoded from -// GRIB Indicator Section 0. -// Must be allocated with >= 3 elements. -// listsec0[0]=Discipline-GRIB Master Table Number -// (see Code Table 0.0) -// listsec0[1]=GRIB Edition Number (currently 2) -// listsec0[2]=Length of GRIB message -// listsec1 - pointer to an array containing information read from GRIB -// Identification Section 1. -// Must be allocated with >= 13 elements. -// listsec1[0]=Id of orginating centre (Common Code Table C-1) -// listsec1[1]=Id of orginating sub-centre (local table) -// listsec1[2]=GRIB Master Tables Version Number (Code Table 1.0) -// listsec1[3]=GRIB Local Tables Version Number -// listsec1[4]=Significance of Reference Time (Code Table 1.1) -// listsec1[5]=Reference Time - Year (4 digits) -// listsec1[6]=Reference Time - Month -// listsec1[7]=Reference Time - Day -// listsec1[8]=Reference Time - Hour -// listsec1[9]=Reference Time - Minute -// listsec1[10]=Reference Time - Second -// listsec1[11]=Production status of data (Code Table 1.2) -// listsec1[12]=Type of processed data (Code Table 1.3) -// numfields- The number of gridded fields found in the GRIB message. -// That is, the number of occurences of Sections 4 - 7. -// numlocal - The number of Local Use Sections ( Section 2 ) found in -// the GRIB message. -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 1 = Beginning characters "GRIB" not found. -// 2 = GRIB message is not Edition 2. -// 3 = Could not find Section 1, where expected. -// 4 = End string "7777" found, but not where expected. -// 5 = End string "7777" not found at end of message. -// 6 = Invalid section number found. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int ierr,mapsec1len=13; - g2int mapsec1[13]={2,2,1,1,1,2,1,1,1,1,1,1,1}; - g2int i,j,istart,iofst,lengrib,lensec0,lensec1; - g2int ipos,isecnum,nbits,lensec; - - ierr=0; - *numlocal=0; - *numfields=0; -// -// Check for beginning of GRIB message in the first 100 bytes -// - istart=-1; - for (j=0;j<100;j++) { - if (cgrib[j]=='G' && cgrib[j+1]=='R' &&cgrib[j+2]=='I' && - cgrib[j+3]=='B') { - istart=j; - break; - } - } - if (istart == -1) { - printf("g2_info: Beginning characters GRIB not found."); - ierr=1; - return(ierr); - } -// -// Unpack Section 0 - Indicator Section -// - iofst=8*(istart+6); - gbit(cgrib,listsec0+0,iofst,8); // Discipline - iofst=iofst+8; - gbit(cgrib,listsec0+1,iofst,8); // GRIB edition number - iofst=iofst+8; - iofst=iofst+32; - gbit(cgrib,&lengrib,iofst,32); // Length of GRIB message - iofst=iofst+32; - listsec0[2]=lengrib; - lensec0=16; - ipos=istart+lensec0; -// -// Currently handles only GRIB Edition 2. -// - if (listsec0[1] != 2) { - printf("g2_info: can only decode GRIB edition 2."); - ierr=2; - return(ierr); - } -// -// Unpack Section 1 - Identification Section -// - gbit(cgrib,&lensec1,iofst,32); // Length of Section 1 - iofst=iofst+32; - gbit(cgrib,&isecnum,iofst,8); // Section number ( 1 ) - iofst=iofst+8; - if (isecnum != 1) { - printf("g2_info: Could not find section 1."); - ierr=3; - return(ierr); - } - // - // Unpack each input value in array listsec1 into the - // the appropriate number of octets, which are specified in - // corresponding entries in array mapsec1. - // - for (i=0;i (istart+lengrib)) { - printf("g2_info: '7777' not found at end of GRIB message.\n"); - ierr=5; - return(ierr); - } - if ( isecnum>=2 && isecnum<=7 ) { - if (isecnum == 2) // Local Section 2 - // increment counter for total number of local sections found - (*numlocal)++; - - else if (isecnum == 4) - // increment counter for total number of fields found - (*numfields)++; - } - else { - printf("g2_info: Invalid section number found in GRIB message: %"PRId32"\n" ,isecnum); - ierr=6; - return(ierr); - } - - } - - return(0); - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_miss.c b/src/plugins/weatherdata/gfs/g2clib/g2_miss.c deleted file mode 100644 index 3dab744b0..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_miss.c +++ /dev/null @@ -1,69 +0,0 @@ -#include "grib2.h" - -void g2_miss( gribfield *gfld, float *rmiss, int *nmiss ) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_miss -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2004-12-16 -// -// ABSTRACT: This routine checks the Data Representation Template to see if -// missing value management is used, and returns the missing value(s) -// in the data field. -// -// PROGRAM HISTORY LOG: -// 2004-12-16 Gilbert -// -// USAGE: g2_miss( gribfield *gfld, float *rmiss, int *nmiss ) -// -// INPUT ARGUMENT LIST: -// *gfld - pointer to gribfield structure (defined in include file -// grib2.h) -// -// OUTPUT ARGUMENT LIST: -// rmiss - List of the missing values used -// nmiss - NUmber of the missing values included in the field -// -// REMARKS: rmiss must be allocated in the calling program with enough space -// hold all the missing values. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - g2int itype; - - /* - * Missing value management currnetly only used in - * DRT's 5.2 and 5.3. - */ - if ( gfld->idrtnum != 2 && gfld->idrtnum != 3 ) { - *nmiss=0; - return; - } - - itype = gfld->idrtmpl[4]; - if ( gfld->idrtmpl[6] == 1 ) { - *nmiss=1; - if (itype == 0) - rdieee(gfld->idrtmpl+7,rmiss+0,1); - else - rmiss[0]=(float)gfld->idrtmpl[7]; - } - else if ( gfld->idrtmpl[6] == 2 ) { - *nmiss=2; - if (itype == 0) { - rdieee(gfld->idrtmpl+7,rmiss+0,1); - rdieee(gfld->idrtmpl+8,rmiss+1,1); - } - else { - rmiss[0]=(float)gfld->idrtmpl[7]; - rmiss[1]=(float)gfld->idrtmpl[8]; - } - } - else { - *nmiss=0; - } - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_unpack1.c b/src/plugins/weatherdata/gfs/g2clib/g2_unpack1.c deleted file mode 100644 index 02114e909..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_unpack1.c +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include -#include "grib2.h" - -g2int g2_unpack1(unsigned char *cgrib,g2int *iofst,g2int **ids,g2int *idslen) -/*//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_unpack1 -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-29 -// -// ABSTRACT: This subroutine unpacks Section 1 (Identification Section) -// as defined in GRIB Edition 2. -// -// PROGRAM HISTORY LOG: -// 2002-10-29 Gilbert -// -// USAGE: int g2_unpack1(unsigned char *cgrib,g2int *iofst,g2int **ids, -// g2int *idslen) -// INPUT ARGUMENTS: -// cgrib - char array containing Section 1 of the GRIB2 message -// iofst - Bit offset for the beginning of Section 1 in cgrib. -// -// OUTPUT ARGUMENTS: -// iofst - Bit offset at the end of Section 1, returned. -// ids - address of pointer to integer array containing information -// read from Section 1, the Identification section. -// ids[0] = Identification of originating Centre -// ( see Common Code Table C-1 ) -// ids[1] = Identification of originating Sub-centre -// ids[2] = GRIB Master Tables Version Number -// ( see Code Table 1.0 ) -// ids[3] = GRIB Local Tables Version Number -// ( see Code Table 1.1 ) -// ids[4] = Significance of Reference Time (Code Table 1.2) -// ids[5] = Year ( 4 digits ) -// ids[6] = Month -// ids[7] = Day -// ids[8] = Hour -// ids[9] = Minute -// ids[10] = Second -// ids[11] = Production status of processed data -// ( see Code Table 1.3 ) -// ids[12] = Type of processed data ( see Code Table 1.4 ) -// idslen - Number of elements in ids[]. -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 2 = Array passed is not section 1 -// 6 = memory allocation error -// -// REMARKS: -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -*/ -{ - - g2int i,lensec,nbits,ierr,isecnum; - g2int mapid[13]={2,2,1,1,1,2,1,1,1,1,1,1,1}; - - ierr=0; - *idslen=13; - *ids=0; - - gbit(cgrib,&lensec,*iofst,32); // Get Length of Section - *iofst=*iofst+32; - gbit(cgrib,&isecnum,*iofst,8); // Get Section Number - *iofst=*iofst+8; - - if ( isecnum != 1 ) { - ierr=2; - *idslen=13; - fprintf(stderr,"g2_unpack1: Not Section 1 data.\n"); - return(ierr); - } - - // - // Unpack each value into array ids from the - // the appropriate number of octets, which are specified in - // corresponding entries in array mapid. - // - *ids=(g2int *)calloc(*idslen,sizeof(g2int)); - if (*ids == 0) { - ierr=6; - return(ierr); - } - - for (i=0;i<*idslen;i++) { - nbits=mapid[i]*8; - gbit(cgrib,*ids+i,*iofst,nbits); - *iofst=*iofst+nbits; - } - - return(ierr); // End of Section 1 processing -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_unpack2.c b/src/plugins/weatherdata/gfs/g2clib/g2_unpack2.c deleted file mode 100644 index 08d9ef592..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_unpack2.c +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include -#include "grib2.h" - -g2int g2_unpack2(unsigned char *cgrib,g2int *iofst,g2int *lencsec2,unsigned char **csec2) -////$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_unpack2 -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This subroutine unpacks Section 2 (Local Use Section) -// as defined in GRIB Edition 2. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// 2008-12-23 Wesley - Initialize lencsec2 Length of Local Use data -// 2010-08-05 Vuong - If section 2 has zero length, ierr=0 -// -// USAGE: int g2_unpack2(unsigned char *cgrib,g2int *iofst,g2int *lencsec2, -// unsigned char **csec2) -// INPUT ARGUMENT LIST: -// cgrib - char array containing Section 2 of the GRIB2 message -// iofst - Bit offset for the beginning of Section 2 in cgrib. -// -// OUTPUT ARGUMENT LIST: -// iofst - Bit offset at the end of Section 2, returned. -// lencsec2 - Length (in octets) of Local Use data -// csec2 - Pointer to a char array containing local use data -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 2 = Array passed is not section 2 -// 6 = memory allocation error -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$// -{ - - g2int ierr,isecnum; - g2int lensec,ipos,j; - - ierr=0; - *lencsec2=0; - *csec2=0; // NULL - - gbit(cgrib,&lensec,*iofst,32); // Get Length of Section - *iofst=*iofst+32; - *lencsec2=lensec-5; - gbit(cgrib,&isecnum,*iofst,8); // Get Section Number - *iofst=*iofst+8; - ipos=(*iofst/8); - - if ( isecnum != 2 ) { - ierr=2; - *lencsec2=0; - fprintf(stderr,"g2_unpack2: Not Section 2 data.\n"); - return(ierr); - } - - if (*lencsec2 == 0) { - ierr = 0; - return(ierr); - } - - *csec2=(unsigned char *)malloc(*lencsec2+1); - if (*csec2 == 0) { - ierr=6; - *lencsec2=0; - return(ierr); - } - - //printf(" SAGIPO %d \n",(int)ipos); - for (j=0;j<*lencsec2;j++) { - *(*csec2+j)=cgrib[ipos+j]; - } - *iofst=*iofst+(*lencsec2*8); - - return(ierr); // End of Section 2 processing - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_unpack3.c b/src/plugins/weatherdata/gfs/g2clib/g2_unpack3.c deleted file mode 100644 index c8667f850..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_unpack3.c +++ /dev/null @@ -1,213 +0,0 @@ -#include -#include -#include "grib2.h" - - -g2int g2_unpack3(unsigned char *cgrib,g2int *iofst,g2int **igds,g2int **igdstmpl, - g2int *mapgridlen,g2int **ideflist,g2int *idefnum) -////$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_unpack3 -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This routine unpacks Section 3 (Grid Definition Section) -// as defined in GRIB Edition 2. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// 2009-01-14 Vuong Changed structure name template to gtemplate -// -// USAGE: int g2_unpack3(unsigned char *cgrib,g2int *iofst,g2int **igds, -// g2int **igdstmpl,g2int *mapgridlen, -// g2int **ideflist,g2int *idefnum) -// INPUT ARGUMENTS: -// cgrib - Char array ontaining Section 3 of the GRIB2 message -// iofst - Bit offset for the beginning of Section 3 in cgrib. -// -// OUTPUT ARGUMENTS: -// iofst - Bit offset at the end of Section 3, returned. -// igds - Contains information read from the appropriate GRIB Grid -// Definition Section 3 for the field being returned. -// igds[0]=Source of grid definition (see Code Table 3.0) -// igds[1]=Number of grid points in the defined grid. -// igds[2]=Number of octets needed for each -// additional grid points definition. -// Used to define number of -// points in each row ( or column ) for -// non-regular grids. -// = 0, if using regular grid. -// igds[3]=Interpretation of list for optional points -// definition. (Code Table 3.11) -// igds[4]=Grid Definition Template Number (Code Table 3.1) -// igdstmpl - Pointer to integer array containing the data values for -// the specified Grid Definition -// Template ( NN=igds[4] ). Each element of this integer -// array contains an entry (in the order specified) of Grid -// Defintion Template 3.NN -// mapgridlen- Number of elements in igdstmpl[]. i.e. number of entries -// in Grid Defintion Template 3.NN ( NN=igds[4] ). -// ideflist - (Used if igds[2] .ne. 0) Pointer to integer array containing -// the number of grid points contained in each row ( or column ). -// (part of Section 3) -// idefnum - (Used if igds[2] .ne. 0) The number of entries -// in array ideflist. i.e. number of rows ( or columns ) -// for which optional grid points are defined. -// ierr - Error return code. -// 0 = no error -// 2 = Not Section 3 -// 5 = "GRIB" message contains an undefined Grid Definition -// Template. -// 6 = memory allocation error -// -// REMARKS: -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ - -{ - g2int ierr,i,j,nbits,isecnum; - g2int lensec,ibyttem=0,isign,newlen; - g2int *ligds,*ligdstmpl=0,*lideflist=0; - gtemplate *mapgrid; - - ierr=0; - *igds=0; // NULL - *igdstmpl=0; // NULL - *ideflist=0; // NULL - - gbit(cgrib,&lensec,*iofst,32); // Get Length of Section - *iofst=*iofst+32; - gbit(cgrib,&isecnum,*iofst,8); // Get Section Number - *iofst=*iofst+8; - - if ( isecnum != 3 ) { - ierr=2; - *idefnum=0; - *mapgridlen=0; - // fprintf(stderr,"g2_unpack3: Not Section 3 data.\n"); - return(ierr); - } - - ligds=(g2int *)calloc(5,sizeof(g2int)); - *igds=ligds; - - gbit(cgrib,ligds+0,*iofst,8); // Get source of Grid def. - *iofst=*iofst+8; - gbit(cgrib,ligds+1,*iofst,32); // Get number of grid pts. - *iofst=*iofst+32; - gbit(cgrib,ligds+2,*iofst,8); // Get num octets for opt. list - *iofst=*iofst+8; - gbit(cgrib,ligds+3,*iofst,8); // Get interpret. for opt. list - *iofst=*iofst+8; - gbit(cgrib,ligds+4,*iofst,16); // Get Grid Def Template num. - *iofst=*iofst+16; - - if (ligds[4] != 65535) { - // Get Grid Definition Template - mapgrid=getgridtemplate(ligds[4]); - if (mapgrid == 0) { // undefined template - ierr=5; - return(ierr); - } - *mapgridlen=mapgrid->maplen; - // - // Unpack each value into array igdstmpl from the - // the appropriate number of octets, which are specified in - // corresponding entries in array mapgrid. - // - if (*mapgridlen > 0) { - ligdstmpl=(g2int *)calloc(*mapgridlen,sizeof(g2int)); - if (ligdstmpl == 0) { - ierr=6; - *mapgridlen=0; - *igdstmpl=0; //NULL - free(mapgrid); - return(ierr); - } - else { - *igdstmpl=ligdstmpl; - } - } - ibyttem=0; - for (i=0;i<*mapgridlen;i++) { - nbits=abs(mapgrid->map[i])*8; - if ( mapgrid->map[i] >= 0 ) { - gbit(cgrib,ligdstmpl+i,*iofst,nbits); - } - else { - gbit(cgrib,&isign,*iofst,1); - gbit(cgrib,ligdstmpl+i,*iofst+1,nbits-1); - if (isign == 1) ligdstmpl[i]=-1*ligdstmpl[i]; - } - *iofst=*iofst+nbits; - ibyttem=ibyttem+abs(mapgrid->map[i]); - } - // - // Check to see if the Grid Definition Template needs to be - // extended. - // The number of values in a specific template may vary - // depending on data specified in the "static" part of the - // gtemplate. - // - if ( mapgrid->needext == 1 ) { - free(mapgrid); - mapgrid=extgridtemplate(ligds[4],ligdstmpl); - // Unpack the rest of the Grid Definition Template - newlen=mapgrid->maplen+mapgrid->extlen; - ligdstmpl=(g2int *)realloc(ligdstmpl,newlen*sizeof(g2int)); - *igdstmpl=ligdstmpl; - j=0; - for (i=*mapgridlen;iext[j])*8; - if ( mapgrid->ext[j] >= 0 ) { - gbit(cgrib,ligdstmpl+i,*iofst,nbits); - } - else { - gbit(cgrib,&isign,*iofst,1); - gbit(cgrib,ligdstmpl+i,*iofst+1,nbits-1); - if (isign == 1) ligdstmpl[i]=-1*ligdstmpl[i]; - } - *iofst=*iofst+nbits; - ibyttem=ibyttem+abs(mapgrid->ext[j]); - j++; - } - *mapgridlen=newlen; - } - if( mapgrid->ext != 0 ) free(mapgrid->ext); - if( mapgrid != 0 ) free(mapgrid); - } - else { // No Grid Definition Template - *mapgridlen=0; - *igdstmpl=0; - } - // - // Unpack optional list of numbers defining number of points - // in each row or column, if included. This is used for non regular - // grids. - // - if ( ligds[2] != 0 ) { - nbits=ligds[2]*8; - *idefnum=(lensec-14-ibyttem)/ligds[2]; - if (*idefnum > 0) lideflist=(g2int *)calloc(*idefnum,sizeof(g2int)); - if (lideflist == 0) { - ierr=6; - *idefnum=0; - *ideflist=0; //NULL - return(ierr); - } - else { - *ideflist=lideflist; - } - gbits(cgrib,lideflist,*iofst,nbits,0,*idefnum); - *iofst=*iofst+(nbits*(*idefnum)); - } - else { - *idefnum=0; - *ideflist=0; // NULL - } - - return(ierr); // End of Section 3 processing -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_unpack4.c b/src/plugins/weatherdata/gfs/g2clib/g2_unpack4.c deleted file mode 100644 index 608f39894..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_unpack4.c +++ /dev/null @@ -1,185 +0,0 @@ -#include -#include -#include "grib2.h" - - -g2int g2_unpack4(unsigned char *cgrib,g2int *iofst,g2int *ipdsnum,g2int **ipdstmpl, - g2int *mappdslen,g2float **coordlist,g2int *numcoord) -////$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_unpack4 -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This subroutine unpacks Section 4 (Product Definition Section) -// as defined in GRIB Edition 2. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// 2009-01-14 Vuong Changed structure name template to gtemplate -// -// USAGE: int g2_unpack4(unsigned char *cgrib,g2int *iofst,g2int *ipdsnum, -// g2int **ipdstmpl,g2int *mappdslen, -// g2float **coordlist,g2int *numcoord) -// INPUT ARGUMENTS: -// cgrib - Char array containing Section 4 of the GRIB2 message -// iofst - Bit offset of the beginning of Section 4 in cgrib. -// -// OUTPUT ARGUMENTS: -// iofst - Bit offset of the end of Section 4, returned. -// ipdsnum - Product Definition Template Number ( see Code Table 4.0) -// ipdstmpl - Pointer to integer array containing the data values for -// the specified Product Definition -// Template ( N=ipdsnum ). Each element of this integer -// array contains an entry (in the order specified) of Product -// Defintion Template 4.N -// mappdslen- Number of elements in ipdstmpl[]. i.e. number of entries -// in Product Defintion Template 4.N ( N=ipdsnum ). -// coordlist- Pointer to real array containing floating point values -// intended to document -// the vertical discretisation associated to model data -// on hybrid coordinate vertical levels. (part of Section 4) -// numcoord - number of values in array coordlist. -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 2 = Not section 4 -// 5 = "GRIB" message contains an undefined Product Definition -// Template. -// 6 = memory allocation error -// -// REMARKS: -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$// -{ - - g2int ierr,needext,i,j,nbits,isecnum; - g2int lensec,isign,newlen; - g2int *coordieee; - g2int *lipdstmpl=0; - g2float *lcoordlist; - gtemplate *mappds; - - ierr=0; - *ipdstmpl=0; // NULL - *coordlist=0; // NULL - - gbit(cgrib,&lensec,*iofst,32); // Get Length of Section - *iofst=*iofst+32; - gbit(cgrib,&isecnum,*iofst,8); // Get Section Number - *iofst=*iofst+8; - - if ( isecnum != 4 ) { - ierr=2; - *numcoord=0; - *mappdslen=0; - // fprintf(stderr,"g2_unpack4: Not Section 4 data.\n"); - return(ierr); - } - - gbit(cgrib,numcoord,*iofst,16); // Get num of coordinate values - *iofst=*iofst+16; - gbit(cgrib,ipdsnum,*iofst,16); // Get Prod. Def Template num. - *iofst=*iofst+16; - - // Get Product Definition Template - mappds=getpdstemplate(*ipdsnum); - if (mappds == 0) { // undefine template - ierr=5; - *mappdslen=0; - return(ierr); - } - *mappdslen=mappds->maplen; - needext=mappds->needext; - // - // Unpack each value into array ipdstmpl from the - // the appropriate number of octets, which are specified in - // corresponding entries in array mappds. - // - if (*mappdslen > 0) lipdstmpl=(g2int *)calloc(*mappdslen,sizeof(g2int)); - if (lipdstmpl == 0) { - ierr=6; - *mappdslen=0; - *ipdstmpl=0; //NULL - free(mappds); - return(ierr); - } - else { - *ipdstmpl=lipdstmpl; - } - for (i=0;imaplen;i++) { - nbits=abs(mappds->map[i])*8; - if ( mappds->map[i] >= 0 ) { - gbit(cgrib,lipdstmpl+i,*iofst,nbits); - } - else { - gbit(cgrib,&isign,*iofst,1); - gbit(cgrib,lipdstmpl+i,*iofst+1,nbits-1); - if (isign == 1) lipdstmpl[i]=-1*lipdstmpl[i]; - } - *iofst=*iofst+nbits; - } - // - // Check to see if the Product Definition Template needs to be - // extended. - // The number of values in a specific template may vary - // depending on data specified in the "static" part of the - // gtemplate. - // - if ( needext ==1 ) { - free(mappds); - mappds=extpdstemplate(*ipdsnum,lipdstmpl); - newlen=mappds->maplen+mappds->extlen; - lipdstmpl=(g2int *)realloc(lipdstmpl,newlen*sizeof(g2int)); - *ipdstmpl=lipdstmpl; - // Unpack the rest of the Product Definition Template - j=0; - for (i=*mappdslen;iext[j])*8; - if ( mappds->ext[j] >= 0 ) { - gbit(cgrib,lipdstmpl+i,*iofst,nbits); - } - else { - gbit(cgrib,&isign,*iofst,1); - gbit(cgrib,lipdstmpl+i,*iofst+1,nbits-1); - if (isign == 1) lipdstmpl[i]=-1*lipdstmpl[i]; - } - *iofst=*iofst+nbits; - j++; - } - *mappdslen=newlen; - } - if( mappds->ext != 0 ) free(mappds->ext); - if( mappds != 0 ) free(mappds); - // - // Get Optional list of vertical coordinate values - // after the Product Definition Template, if necessary. - // - *coordlist=0; // NULL - if ( *numcoord != 0 ) { - coordieee=(g2int *)calloc(*numcoord,sizeof(g2int)); - lcoordlist=(g2float *)calloc(*numcoord,sizeof(g2float)); - if (coordieee == 0 || lcoordlist == 0) { - ierr=6; - *numcoord=0; - *coordlist=0; // NULL - if( coordieee != 0 ) free(coordieee); - if( lcoordlist != 0 ) free(lcoordlist); - return(ierr); - } - else { - *coordlist=lcoordlist; - } - gbits(cgrib,coordieee,*iofst,32,0,*numcoord); - rdieee(coordieee,*coordlist,*numcoord); - free(coordieee); - *iofst=*iofst+(32*(*numcoord)); - } - - return(ierr); // End of Section 4 processing - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_unpack5.c b/src/plugins/weatherdata/gfs/g2clib/g2_unpack5.c deleted file mode 100644 index 27e9a55cd..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_unpack5.c +++ /dev/null @@ -1,152 +0,0 @@ -#include -#include -#include "grib2.h" - - -g2int g2_unpack5(unsigned char *cgrib,g2int *iofst,g2int *ndpts,g2int *idrsnum, - g2int **idrstmpl,g2int *mapdrslen) -////$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_unpack5 -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This subroutine unpacks Section 5 (Data Representation Section) -// as defined in GRIB Edition 2. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// 2009-01-14 Vuong Changed structure name template to gtemplate -// -// USAGE: int g2_unpack5(unsigned char *cgrib,g2int *iofst,g2int *ndpts, -// g2int *idrsnum,g2int **idrstmpl,g2int *mapdrslen) -// INPUT ARGUMENTS: -// cgrib - char array containing Section 5 of the GRIB2 message -// iofst - Bit offset for the beginning of Section 5 in cgrib. -// -// OUTPUT ARGUMENTS: -// iofst - Bit offset at the end of Section 5, returned. -// ndpts - Number of data points unpacked and returned. -// idrsnum - Data Representation Template Number ( see Code Table 5.0) -// idrstmpl - Pointer to an integer array containing the data values for -// the specified Data Representation -// Template ( N=idrsnum ). Each element of this integer -// array contains an entry (in the order specified) of Data -// Representation Template 5.N -// mapdrslen- Number of elements in idrstmpl[]. i.e. number of entries -// in Data Representation Template 5.N ( N=idrsnum ). -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 2 = Not Section 5 -// 6 = memory allocation error -// 7 = "GRIB" message contains an undefined Data -// Representation Template. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$// -{ - g2int ierr,needext,i,j,nbits,isecnum; - g2int lensec,isign,newlen; - g2int *lidrstmpl=0; - gtemplate *mapdrs; - - ierr=0; - *idrstmpl=0; //NULL - - gbit(cgrib,&lensec,*iofst,32); // Get Length of Section - *iofst=*iofst+32; - gbit(cgrib,&isecnum,*iofst,8); // Get Section Number - *iofst=*iofst+8; - - if ( isecnum != 5 ) { - ierr=2; - *ndpts=0; - *mapdrslen=0; - // fprintf(stderr,"g2_unpack5: Not Section 5 data.\n"); - return(ierr); - } - - gbit(cgrib,ndpts,*iofst,32); // Get num of data points - *iofst=*iofst+32; - gbit(cgrib,idrsnum,*iofst,16); // Get Data Rep Template Num. - *iofst=*iofst+16; - - // Gen Data Representation Template - mapdrs=getdrstemplate(*idrsnum); - if (mapdrs == 0) { - ierr=7; - *mapdrslen=0; - return(ierr); - } - *mapdrslen=mapdrs->maplen; - needext=mapdrs->needext; - // - // Unpack each value into array ipdstmpl from the - // the appropriate number of octets, which are specified in - // corresponding entries in array mapdrs. - // - if (*mapdrslen > 0) lidrstmpl=(g2int *)calloc(*mapdrslen,sizeof(g2int)); - if (lidrstmpl == 0) { - ierr=6; - *mapdrslen=0; - *idrstmpl=0; //NULL - free(mapdrs); - return(ierr); - } - else { - *idrstmpl=lidrstmpl; - } - for (i=0;imaplen;i++) { - nbits=abs(mapdrs->map[i])*8; - if ( mapdrs->map[i] >= 0 ) { - gbit(cgrib,lidrstmpl+i,*iofst,nbits); - } - else { - gbit(cgrib,&isign,*iofst,1); - gbit(cgrib,lidrstmpl+i,*iofst+1,nbits-1); - if (isign == 1) lidrstmpl[i]=-1*lidrstmpl[i]; - } - *iofst=*iofst+nbits; - } - // - // Check to see if the Data Representation Template needs to be - // extended. - // The number of values in a specific gtemplate may vary - // depending on data specified in the "static" part of the - // gtemplate. - // - if ( needext == 1 ) { - free(mapdrs); - mapdrs=extdrstemplate(*idrsnum,lidrstmpl); - newlen=mapdrs->maplen+mapdrs->extlen; - lidrstmpl=(g2int *)realloc(lidrstmpl,newlen*sizeof(g2int)); - *idrstmpl=lidrstmpl; - // Unpack the rest of the Data Representation Template - j=0; - for (i=*mapdrslen;iext[j])*8; - if ( mapdrs->ext[j] >= 0 ) { - gbit(cgrib,lidrstmpl+i,*iofst,nbits); - } - else { - gbit(cgrib,&isign,*iofst,1); - gbit(cgrib,lidrstmpl+i,*iofst+1,nbits-1); - if (isign == 1) lidrstmpl[i]=-1*lidrstmpl[i]; - } - *iofst=*iofst+nbits; - j++; - } - *mapdrslen=newlen; - } - if( mapdrs->ext != 0 ) free(mapdrs->ext); - if( mapdrs != 0 ) free(mapdrs); - - return(ierr); // End of Section 5 processing - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/g2_unpack6.c b/src/plugins/weatherdata/gfs/g2clib/g2_unpack6.c deleted file mode 100644 index 9f6da7ee5..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/g2_unpack6.c +++ /dev/null @@ -1,97 +0,0 @@ -#include -#include -#include "grib2.h" - -g2int g2_unpack6(unsigned char *cgrib,g2int *iofst,g2int ngpts,g2int *ibmap, - g2int **bmap) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_unpack6 -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This subroutine unpacks Section 6 (Bit-Map Section) -// as defined in GRIB Edition 2. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// -// USAGE: int g2_unpack6(unsigned char *cgrib,g2int *iofst,g2int ngpts, -// g2int *ibmap,g2int **bmap) -// INPUT ARGUMENTS: -// cgrib - char array containing Section 6 of the GRIB2 message -// iofst - Bit offset of the beginning of Section 6 in cgrib. -// ngpts - Number of grid points specified in the bit-map -// -// OUTPUT ARGUMENTS: -// iofst - Bit offset at the end of Section 6, returned. -// ibmap - Bitmap indicator ( see Code Table 6.0 ) -// 0 = bitmap applies and is included in Section 6. -// 1-253 = Predefined bitmap applies -// 254 = Previously defined bitmap applies to this field -// 255 = Bit map does not apply to this product. -// bmap - Pointer to an integer array containing decoded bitmap. -// ( if ibmap=0 ) -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 2 = Not Section 6 -// 4 = Unrecognized pre-defined bit-map. -// 6 = memory allocation error -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$// -{ - g2int j,ierr,isecnum; - g2int *lbmap=0; - g2int *intbmap; - - ierr=0; - *bmap=0; //NULL - - *iofst=*iofst+32; // skip Length of Section - gbit(cgrib,&isecnum,*iofst,8); // Get Section Number - *iofst=*iofst+8; - - if ( isecnum != 6 ) { - ierr=2; - fprintf(stderr,"g2_unpack6: Not Section 6 data.\n"); - return(ierr); - } - - gbit(cgrib,ibmap,*iofst,8); // Get bit-map indicator - *iofst=*iofst+8; - - if (*ibmap == 0) { // Unpack bitmap - if (ngpts > 0) lbmap=(g2int *)calloc(ngpts,sizeof(g2int)); - if (lbmap == 0) { - ierr=6; - return(ierr); - } - else { - *bmap=lbmap; - } - intbmap=(g2int *)calloc(ngpts,sizeof(g2int)); - gbits(cgrib,intbmap,*iofst,1,0,ngpts); - *iofst=*iofst+ngpts; - for (j=0;j -#include -#include -#include -#include "grib2.h" - -g2int simunpack(unsigned char *,g2int *, g2int,g2float *); -int comunpack(unsigned char *,g2int,g2int,g2int *,g2int,g2float *); -g2int specunpack(unsigned char *,g2int *,g2int,g2int,g2int, g2int, g2float *); -#ifdef USE_PNG - g2int pngunpack(unsigned char *,g2int,g2int *,g2int, g2float *); -#endif /* USE_PNG */ -#ifdef USE_JPEG2000 - g2int jpcunpack(unsigned char *,g2int,g2int *,g2int, g2float *); -#endif /* USE_JPEG2000 */ - -g2int g2_unpack7(unsigned char *cgrib,g2int *iofst,g2int igdsnum,g2int *igdstmpl, - g2int idrsnum,g2int *idrstmpl,g2int ndpts,g2float **fld) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_unpack7 -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This subroutine unpacks Section 7 (Data Section) -// as defined in GRIB Edition 2. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// 2002-12-20 Gilbert - Added GDT info to arguments -// and added 5.51 processing. -// 2003-08-29 Gilbert - Added support for new templates using -// PNG and JPEG2000 algorithms/templates. -// 2004-11-29 Gilbert - JPEG2000 now allowed to use WMO Template no. 5.40 -// PNG now allowed to use WMO Template no. 5.41 -// 2004-12-16 Taylor - Added check on comunpack return code. -// 2008-12-23 Wesley - Initialize Number of data points unpacked -// -// USAGE: int g2_unpack7(unsigned char *cgrib,g2int *iofst,g2int igdsnum, -// g2int *igdstmpl, g2int idrsnum, -// g2int *idrstmpl, g2int ndpts,g2float **fld) -// INPUT ARGUMENTS: -// cgrib - char array containing Section 7 of the GRIB2 message -// iofst - Bit offset of the beginning of Section 7 in cgrib. -// igdsnum - Grid Definition Template Number ( see Code Table 3.0) -// ( Only used for DRS Template 5.51 ) -// igdstmpl - Pointer to an integer array containing the data values for -// the specified Grid Definition -// Template ( N=igdsnum ). Each element of this integer -// array contains an entry (in the order specified) of Grid -// Definition Template 3.N -// ( Only used for DRS Template 5.51 ) -// idrsnum - Data Representation Template Number ( see Code Table 5.0) -// idrstmpl - Pointer to an integer array containing the data values for -// the specified Data Representation -// Template ( N=idrsnum ). Each element of this integer -// array contains an entry (in the order specified) of Data -// Representation Template 5.N -// ndpts - Number of data points unpacked and returned. -// -// OUTPUT ARGUMENTS: -// iofst - Bit offset at the end of Section 7, returned. -// fld - Pointer to a float array containing the unpacked data field. -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 2 = Not section 7 -// 4 = Unrecognized Data Representation Template -// 5 = need one of GDT 3.50 through 3.53 to decode DRT 5.51 -// 6 = memory allocation error -// 7 = corrupt section 7. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$// -{ - g2int ierr,isecnum; - g2int ipos,lensec; - g2float *lfld; - - ierr=0; - *fld=0; //NULL - - gbit(cgrib,&lensec,*iofst,32); // Get Length of Section - *iofst=*iofst+32; - gbit(cgrib,&isecnum,*iofst,8); // Get Section Number - *iofst=*iofst+8; - - if ( isecnum != 7 ) { - ierr=2; - //fprintf(stderr,"g2_unpack7: Not Section 7 data.\n"); - return(ierr); - } - - ipos=(*iofst/8); - lfld=(g2float *)calloc(ndpts ? ndpts : 1,sizeof(g2float)); - if (lfld == 0) { - ierr=6; - return(ierr); - } - else { - *fld=lfld; - } - - if (idrsnum == 0) - simunpack(cgrib+ipos,idrstmpl,ndpts,lfld); - else if (idrsnum == 2 || idrsnum == 3) { - if (comunpack(cgrib+ipos,lensec,idrsnum,idrstmpl,ndpts,lfld) != 0) { - return 7; - } - } - else if (idrsnum == 50) { // Spectral Simple - simunpack(cgrib+ipos,idrstmpl,ndpts-1,lfld+1); - rdieee(idrstmpl+4,lfld+0,1); - } - else if (idrsnum == 51) // Spectral complex - if ( igdsnum>=50 && igdsnum <=53 ) - specunpack(cgrib+ipos,idrstmpl,ndpts,igdstmpl[0],igdstmpl[2],igdstmpl[2],lfld); - else { - fprintf(stderr,"g2_unpack7: Cannot use GDT 3.%d to unpack Data Section 5.51.\n",(int)igdsnum); - ierr=5; - if ( lfld != 0 ) free(lfld); - *fld=0; //NULL - return(ierr); - } -#ifdef USE_JPEG2000 - else if (idrsnum == 40 || idrsnum == 40000) { - jpcunpack(cgrib+ipos,lensec-5,idrstmpl,ndpts,lfld); - } -#endif /* USE_JPEG2000 */ -#ifdef USE_PNG - else if (idrsnum == 41 || idrsnum == 40010) { - pngunpack(cgrib+ipos,lensec-5,idrstmpl,ndpts,lfld); - } -#endif /* USE_PNG */ - else { - fprintf(stderr,"g2_unpack7: Data Representation Template 5.%d not yet implemented.\n",(int)idrsnum); - ierr=4; - if ( lfld != 0 ) free(lfld); - *fld=0; //NULL - return(ierr); - } - - *iofst=*iofst+(8*lensec); - - return(ierr); // End of Section 7 processing - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/gbits.c b/src/plugins/weatherdata/gfs/g2clib/gbits.c deleted file mode 100644 index 34709dab3..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/gbits.c +++ /dev/null @@ -1,124 +0,0 @@ -#include "grib2.h" - -void gbit(unsigned char *in,g2int *iout,g2int iskip,g2int nbyte) -{ - gbits(in,iout,iskip,nbyte,(g2int)0,(g2int)1); -} - -void sbit(unsigned char *out,g2int *in,g2int iskip,g2int nbyte) -{ - sbits(out,in,iskip,nbyte,(g2int)0,(g2int)1); -} - - -void gbits(unsigned char *in,g2int *iout,g2int iskip,g2int nbyte,g2int nskip, - g2int n) -/* Get bits - unpack bits: Extract arbitrary size values from a -/ packed bit string, right justifying each value in the unpacked -/ iout array. -/ *in = pointer to character array input -/ *iout = pointer to unpacked array output -/ iskip = initial number of bits to skip -/ nbyte = number of bits to take -/ nskip = additional number of bits to skip on each iteration -/ n = number of iterations -/ v1.1 -*/ -{ - g2int i,tbit,bitcnt,ibit,itmp; - g2int nbit,index; - static g2int ones[]={1,3,7,15,31,63,127,255}; - -// nbit is the start position of the field in bits - nbit = iskip; - for (i=0;i>= (8-ibit-tbit); - index++; - bitcnt = bitcnt - tbit; - -// now transfer whole bytes - while (bitcnt >= 8) { - itmp = itmp<<8 | (int)*(in+index); - bitcnt = bitcnt - 8; - index++; - } - -// get data from last byte - if (bitcnt > 0) { - itmp = ( itmp << bitcnt ) | ( ((int)*(in+index) >> (8-bitcnt)) & ones[bitcnt-1] ); - } - - *(iout+i) = itmp; - } -} - - -void sbits(unsigned char *out,g2int *in,g2int iskip,g2int nbyte,g2int nskip, - g2int n) -/*C Store bits - pack bits: Put arbitrary size values into a -/ packed bit string, taking the low order bits from each value -/ in the unpacked array. -/ *iout = pointer to packed array output -/ *in = pointer to unpacked array input -/ iskip = initial number of bits to skip -/ nbyte = number of bits to pack -/ nskip = additional number of bits to skip on each iteration -/ n = number of iterations -/ v1.1 -*/ -{ - g2int i,bitcnt,tbit,ibit,itmp,imask,itmp2,itmp3; - g2int nbit,index; - static g2int ones[]={1,3,7,15,31,63,127,255}; - -// number bits from zero to ... -// nbit is the last bit of the field to be filled - - nbit = iskip + nbyte - 1; - for (i=0;i> tbit; - index--; - } - -// now byte aligned - -// do by bytes - while (bitcnt >= 8) { - out[index] = (unsigned char)(itmp & 255); - itmp = itmp >> 8; - bitcnt = bitcnt - 8; - index--; - } - -// do last byte - - if (bitcnt > 0) { - itmp2 = itmp & ones[bitcnt-1]; - itmp3 = (int)*(out+index) & (255-ones[bitcnt-1]); - out[index] = (unsigned char)(itmp2 | itmp3); - } - } - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/getdim.c b/src/plugins/weatherdata/gfs/g2clib/getdim.c deleted file mode 100644 index c86228fc9..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/getdim.c +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include -#include "grib2.h" - -g2int g2_unpack3(unsigned char *,g2int *,g2int **,g2int **, - g2int *,g2int **,g2int *); - -g2int getdim(unsigned char *csec3,g2int *width,g2int *height,g2int *iscan) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: getdim -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-11 -// -// ABSTRACT: This subroutine returns the dimensions and scanning mode of -// a grid definition packed in GRIB2 Grid Definition Section 3 format. -// -// PROGRAM HISTORY LOG: -// 2002-12-11 Gilbert -// -// USAGE: int getdim(unsigned char *csec3,g2int *width, -// g2int *height, g2int *iscan) -// INPUT ARGUMENT LIST: -// csec3 - Character array that contains the packed GRIB2 GDS -// -// OUTPUT ARGUMENT LIST: -// width - x (or i) dimension of the grid. -// height - y (or j) dimension of the grid. -// iscan - Scanning mode ( see Code Table 3.4 ) -// -// REMARKS: Returns width and height set to zero, if grid template -// not recognized. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - - g2int *igdstmpl,*list_opt; - g2int *igds; - g2int iofst,igdtlen,num_opt,jerr; - - igdstmpl=0; - list_opt=0; - igds=0; - iofst=0; // set offset to beginning of section - jerr= g2_unpack3(csec3,&iofst,&igds,&igdstmpl, - &igdtlen,&list_opt,&num_opt); - if (jerr == 0) { - switch ( igds[4] ) // Template number - { - case 0: // Lat/Lon - case 1: - case 2: - case 3: - { - *width=igdstmpl[7]; - *height=igdstmpl[8]; - *iscan=igdstmpl[18]; - break; - } - case 10: // Mercator - { - *width=igdstmpl[7]; - *height=igdstmpl[8]; - *iscan=igdstmpl[15]; - break; - } - case 20: // Polar Stereographic - { - *width=igdstmpl[7]; - *height=igdstmpl[8]; - *iscan=igdstmpl[17]; - break; - } - case 30: // Lambert Conformal - { - *width=igdstmpl[7]; - *height=igdstmpl[8]; - *iscan=igdstmpl[17]; - break; - } - case 40: // Gaussian - case 41: - case 42: - case 43: - { - *width=igdstmpl[7]; - *height=igdstmpl[8]; - *iscan=igdstmpl[18]; - break; - } - case 90: // Space View/Orthographic - { - *width=igdstmpl[7]; - *height=igdstmpl[8]; - *iscan=igdstmpl[16]; - break; - } - case 110: // Equatorial Azimuthal - { - *width=igdstmpl[7]; - *height=igdstmpl[8]; - *iscan=igdstmpl[15]; - break; - } - default: - { - *width=0; - *height=0; - *iscan=0; - break; - } - } // end switch - } - else { - *width=0; - *height=0; - } - - if (igds != 0) free(igds); - if (igdstmpl != 0) free(igdstmpl); - if (list_opt != 0) free(list_opt); - - return 0; -} diff --git a/src/plugins/weatherdata/gfs/g2clib/getpoly.c b/src/plugins/weatherdata/gfs/g2clib/getpoly.c deleted file mode 100644 index 9e2a5a69b..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/getpoly.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include "grib2.h" - -g2int g2_unpack3(unsigned char *,g2int *,g2int **,g2int **, - g2int *,g2int **,g2int *); - -g2int getpoly(unsigned char *csec3,g2int *jj,g2int *kk,g2int *mm) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: getpoly -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-11 -// -// ABSTRACT: This subroutine returns the J, K, and M pentagonal resolution -// parameters specified in a GRIB Grid Definition Section used -// spherical harmonic coefficients using GDT 5.50 through 5.53 -// -// PROGRAM HISTORY LOG: -// 2002-12-11 Gilbert -// -// USAGE: int getpoly(unsigned char *csec3,g2int *jj,g2int *kk,g2int *mm) -// INPUT ARGUMENTS: -// csec3 - Character array that contains the packed GRIB2 GDS -// -// OUTPUT ARGUMENTS: -// JJ = J - pentagonal resolution parameter -// KK = K - pentagonal resolution parameter -// MM = M - pentagonal resolution parameter -// -// REMARKS: Returns JJ, KK, and MM set to zero, if grid template -// not recognized. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - - g2int *igdstmpl,*list_opt; - g2int *igds; - g2int iofst,igdtlen,num_opt,jerr; - - iofst=0; // set offset to beginning of section - jerr=g2_unpack3(csec3,&iofst,&igds,&igdstmpl, - &igdtlen,&list_opt,&num_opt); - if (jerr == 0) { - switch ( igds[4] ) // Template number - { - case 50: // Spherical harmonic coefficients - case 51: - case 52: - case 53: - { - *jj=igdstmpl[0]; - *kk=igdstmpl[1]; - *mm=igdstmpl[2]; - break; - } - default: - { - *jj=0; - *kk=0; - *mm=0; - break; - } - } // end switch - } - else { - *jj=0; - *kk=0; - *mm=0; - } - - if (igds != 0) free(igds); - if (igdstmpl != 0) free(igdstmpl); - if (list_opt != 0) free(list_opt); - - return 0; -} diff --git a/src/plugins/weatherdata/gfs/g2clib/grib2.h b/src/plugins/weatherdata/gfs/g2clib/grib2.h deleted file mode 100644 index ddbebd446..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/grib2.h +++ /dev/null @@ -1,254 +0,0 @@ -#ifndef _grib2_H -#define _grib2_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define G2_VERSION "g2clib-1.5.0" -/* . . . . -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-25 -// -// PROGRAM HISTORY LOG: -// 2002-10-25 Gilbert -// 2009-01-14 Vuong Changed struct template to gtemplate -// -// Each element of structure gribfield is defined as: -// -// gribfield gfld; -// -// gfld->version = GRIB edition number ( currently 2 ) -// gfld->discipline = Message Discipline ( see Code Table 0.0 ) -// gfld->idsect = Contains the entries in the Identification -// Section ( Section 1 ) -// This element is a pointer to an array -// that holds the data. -// gfld->idsect[0] = Identification of originating Centre -// ( see Common Code Table C-1 ) -// 7 - US National Weather Service -// gfld->idsect[1] = Identification of originating Sub-centre -// gfld->idsect[2] = GRIB Master Tables Version Number -// ( see Code Table 1.0 ) -// 0 - Experimental -// 1 - Initial operational version number -// gfld->idsect[3] = GRIB Local Tables Version Number -// ( see Code Table 1.1 ) -// 0 - Local tables not used -// 1-254 - Number of local tables version used -// gfld->idsect[4] = Significance of Reference Time (Code Table 1.2) -// 0 - Analysis -// 1 - Start of forecast -// 2 - Verifying time of forecast -// 3 - Observation time -// gfld->idsect[5] = Year ( 4 digits ) -// gfld->idsect[6] = Month -// gfld->idsect[7) = Day -// gfld->idsect[8] = Hour -// gfld->idsect[9] = Minute -// gfld->idsect[10] = Second -// gfld->idsect[11] = Production status of processed data -// ( see Code Table 1.3 ) -// 0 - Operational products -// 1 - Operational test products -// 2 - Research products -// 3 - Re-analysis products -// gfld->idsect[12] = Type of processed data ( see Code Table 1.4 ) -// 0 - Analysis products -// 1 - Forecast products -// 2 - Analysis and forecast products -// 3 - Control forecast products -// 4 - Perturbed forecast products -// 5 - Control and perturbed forecast products -// 6 - Processed satellite observations -// 7 - Processed radar observations -// gfld->idsectlen = Number of elements in gfld->idsect[]. -// gfld->local = Pointer to character array containing contents -// of Local Section 2, if included -// gfld->locallen = length of array gfld->local[] -// gfld->ifldnum = field number within GRIB message -// gfld->griddef = Source of grid definition (see Code Table 3.0) -// 0 - Specified in Code table 3.1 -// 1 - Predetermined grid Defined by originating centre -// gfld->ngrdpts = Number of grid points in the defined grid. -// gfld->numoct_opt = Number of octets needed for each -// additional grid points definition. -// Used to define number of -// points in each row ( or column ) for -// non-regular grids. -// = 0, if using regular grid. -// gfld->interp_opt = Interpretation of list for optional points -// definition. (Code Table 3.11) -// gfld->igdtnum = Grid Definition Template Number (Code Table 3.1) -// gfld->igdtmpl = Contains the data values for the specified Grid -// Definition Template ( NN=gfld->igdtnum ). Each -// element of this integer array contains an entry (in -// the order specified) of Grid Defintion Template 3.NN -// This element is a pointer to an array -// that holds the data. -// gfld->igdtlen = Number of elements in gfld->igdtmpl[]. i.e. number of -// entries in Grid Defintion Template 3.NN -// ( NN=gfld->igdtnum ). -// gfld->list_opt = (Used if gfld->numoct_opt .ne. 0) This array -// contains the number of grid points contained in -// each row ( or column ). (part of Section 3) -// This element is a pointer to an array -// that holds the data. This pointer is nullified -// if gfld->numoct_opt=0. -// gfld->num_opt = (Used if gfld->numoct_opt .ne. 0) The number of entries -// in array ideflist. i.e. number of rows ( or columns ) -// for which optional grid points are defined. This value -// is set to zero, if gfld->numoct_opt=0. -// gfdl->ipdtnum = Product Definition Template Number (see Code Table 4.0) -// gfld->ipdtmpl = Contains the data values for the specified Product -// Definition Template ( N=gfdl->ipdtnum ). Each element -// of this integer array contains an entry (in the -// order specified) of Product Defintion Template 4.N. -// This element is a pointer to an array -// that holds the data. -// gfld->ipdtlen = Number of elements in gfld->ipdtmpl[]. i.e. number of -// entries in Product Defintion Template 4.N -// ( N=gfdl->ipdtnum ). -// gfld->coord_list = Real array containing floating point values -// intended to document the vertical discretisation -// associated to model data on hybrid coordinate -// vertical levels. (part of Section 4) -// This element is a pointer to an array -// that holds the data. -// gfld->num_coord = number of values in array gfld->coord_list[]. -// gfld->ndpts = Number of data points unpacked and returned. -// gfld->idrtnum = Data Representation Template Number -// ( see Code Table 5.0) -// gfld->idrtmpl = Contains the data values for the specified Data -// Representation Template ( N=gfld->idrtnum ). Each -// element of this integer array contains an entry -// (in the order specified) of Product Defintion -// Template 5.N. -// This element is a pointer to an array -// that holds the data. -// gfld->idrtlen = Number of elements in gfld->idrtmpl[]. i.e. number -// of entries in Data Representation Template 5.N -// ( N=gfld->idrtnum ). -// gfld->unpacked = logical value indicating whether the bitmap and -// data values were unpacked. If false, -// gfld->bmap and gfld->fld pointers are nullified. -// gfld->expanded = Logical value indicating whether the data field -// was expanded to the grid in the case where a -// bit-map is present. If true, the data points in -// gfld->fld match the grid points and zeros were -// inserted at grid points where data was bit-mapped -// out. If false, the data values in gfld->fld were -// not expanded to the grid and are just a consecutive -// array of data points corresponding to each value of -// "1" in gfld->bmap. -// gfld->ibmap = Bitmap indicator ( see Code Table 6.0 ) -// 0 = bitmap applies and is included in Section 6. -// 1-253 = Predefined bitmap applies -// 254 = Previously defined bitmap applies to this field -// 255 = Bit map does not apply to this product. -// gfld->bmap = integer array containing decoded bitmap, -// if gfld->ibmap=0 or gfld->ibap=254. Otherwise nullified. -// This element is a pointer to an array -// that holds the data. -// gfld->fld = Array of gfld->ndpts unpacked data points. -// This element is a pointer to an array -// that holds the data. -*/ - -typedef int32_t g2int; -typedef uint32_t g2intu; -typedef float g2float; - -struct gtemplate { - g2int type; /* 3=Grid Defintion Template. */ - /* 4=Product Defintion Template. */ - /* 5=Data Representation Template. */ - g2int num; /* template number. */ - g2int maplen; /* number of entries in the static part */ - /* of the template. */ - g2int *map; /* num of octets of each entry in the */ - /* static part of the template. */ - g2int needext; /* indicates whether or not the template needs */ - /* to be extended. */ - g2int extlen; /* number of entries in the template extension. */ - g2int *ext; /* num of octets of each entry in the extension */ - /* part of the template. */ -}; - -typedef struct gtemplate gtemplate; - -struct gribfield { - g2int version,discipline; - g2int *idsect; - g2int idsectlen; - unsigned char *local; - g2int locallen; - g2int ifldnum; - g2int griddef,ngrdpts; - g2int numoct_opt,interp_opt,num_opt; - g2int *list_opt; - g2int igdtnum,igdtlen; - g2int *igdtmpl; - g2int ipdtnum,ipdtlen; - g2int *ipdtmpl; - g2int num_coord; - g2float *coord_list; - g2int ndpts,idrtnum,idrtlen; - g2int *idrtmpl; - g2int unpacked; - g2int expanded; - g2int ibmap; - g2int *bmap; - g2float *fld; -}; - -typedef struct gribfield gribfield; - - -/* Prototypes for unpacking API */ -void seekgb(FILE *,g2int ,g2int ,g2int *,g2int *); -g2int g2_info(unsigned char *,g2int *,g2int *,g2int *,g2int *); -g2int g2_getfld(unsigned char *,g2int ,g2int ,g2int ,gribfield **); -void g2_free(gribfield *); - -/* Prototypes for packing API */ -g2int g2_create(unsigned char *,g2int *,g2int *); -g2int g2_addlocal(unsigned char *,unsigned char *,g2int ); -g2int g2_addgrid(unsigned char *,g2int *,g2int *,g2int *,g2int ); -g2int g2_addfield(unsigned char *,g2int ,g2int *, - g2float *,g2int ,g2int ,g2int *, - g2float *,g2int ,g2int ,g2int *); -g2int g2_gribend(unsigned char *); - -/* Prototypes for supporting routines */ -extern double int_power(double, g2int ); -extern void mkieee(g2float *,g2int *,g2int); -void rdieee(g2int *,g2float *,g2int ); -extern gtemplate *getpdstemplate(g2int); -extern gtemplate *extpdstemplate(g2int,g2int *); -extern gtemplate *getdrstemplate(g2int); -extern gtemplate *extdrstemplate(g2int,g2int *); -extern gtemplate *getgridtemplate(g2int); -extern gtemplate *extgridtemplate(g2int,g2int *); -extern void simpack(g2float *,g2int,g2int *,unsigned char *,g2int *); -extern void compack(g2float *,g2int,g2int,g2int *,unsigned char *,g2int *); -void misspack(g2float *,g2int ,g2int ,g2int *, unsigned char *, g2int *); -void gbit(unsigned char *,g2int *,g2int ,g2int ); -void sbit(unsigned char *,g2int *,g2int ,g2int ); -void gbits(unsigned char *,g2int *,g2int ,g2int ,g2int ,g2int ); -void sbits(unsigned char *,g2int *,g2int ,g2int ,g2int ,g2int ); - -int pack_gp(g2int *, g2int *, g2int *, - g2int *, g2int *, g2int *, g2int *, g2int *, - g2int *, g2int *, g2int *, g2int *, - g2int *, g2int *, g2int *, g2int *, g2int *, - g2int *, g2int *, g2int *); - -#ifdef __cplusplus -} -#endif - -#endif /* _grib2_H */ - diff --git a/src/plugins/weatherdata/gfs/g2clib/grib2c.doc b/src/plugins/weatherdata/gfs/g2clib/grib2c.doc deleted file mode 100644 index 4ad7c3411..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/grib2c.doc +++ /dev/null @@ -1,946 +0,0 @@ - GRIB2 USERS GUIDE (C) - -Contents: - -- Introduction -- GRIB2 Tables/Templates -- GRIB2 Encoding Routines -- GRIB2 Decoding Routines -- Decoding all GRIB2 Fields in a File -- Extracting Selected GRIB2 Fields from a GRIB2 file -- GRIB2 Routine Documentation - -=============================================================================== - - Introduction - -This document briefly describes the routines available for encoding/decoding -GRIB Edition 2 (GRIB2) messages. A basic familiarity with GRIB is assumed. - -A GRIB Edition 2 message is a machine independent format for storing -one or more gridded data fields. Each GRIB2 message consists of the -following sections: - -SECTION 0 - Indicator Section -SECTION 1 - Identification Section -SECTION 2 - (Local Use Section) - optional } -SECTION 3 - Grid Definition Section } } -SECTION 4 - Product Definition Section } } }(repeated) -SECTION 5 - Data Representation Section } }(repeated) } -SECTION 6 - Bit-map Section }(repeated) } } -SECTION 7 - Data Section } } } -SECTION 8 - End Section } } } - -Sequences of GRIB sections 2 to 7, 3 to 7, or sections 4 to 7 may be repeated -within a single GRIB message. All sections within such repeated sequences -must be present and shall appear in the numerical order noted above. -Unrepeated sections remain in effect until redefined. - -The above overview was taken from WMO's FM 92-XII GRIB description -of the GRIB Edition 2 form. - -=============================================================================== - - GRIB2 Tables/Templates - -WMO's GRIB2 specification "FM 92-XII GRIB - General Regularly-distributed -Information in Binary Form" contains descriptions of each template -and code table information. This document can be found at -http://www.wmo.ch/web/www/WMOCodes.html -(PDF and MSWord formats are available) - -=============================================================================== - - GRIB2 Encoding Routines - -Since a GRIB2 message can contain gridded fields for many parameters on -a number of different grids, several routines are used to encode a message. -This should give users more flexibility in how to organize data -within one or more GRIB2 messages. - -To start a new GRIB2 message, call function g2_create. G2_create -encodes Sections 0 and 1 at the beginning of the message. This routine -must be used to create each message. - -Routine g2_addlocal can be used to add a Local Use Section ( Section 2 ). -Note that this section is optional and need not appear in a GRIB2 message. - -Function g2_addgrid is used to encode a grid definition into Section 3. -This grid definition defines the geometry of the the data values in the -fields that follow it. g2_addgrid can be called again to change the grid -definition describing subsequent data fields. - -Each data field is added to the GRIB2 message using routine g2_addfield, -which adds Sections 4, 5, 6, and 7 to the message. - -After all desired data fields have been added to the GRIB2 message, a -call to function g2_gribend is needed to add the final section 8 to the -message and to update the length of the message. A call to g2_gribend -is required for each GRIB2 message. - -Please see the "GRIB2 Routine Documentation" section below for subroutine -argument usage for the routines mentioned above. - -=============================================================================== - - GRIB2 Decoding Routines - -Routine g2_info can be used to find out how many Local Use sections -and data fields are contained in a given GRIB2 message. This routine also -returns all the information stored in Sections 0 and 1 of the GRIB2 -message. - -g2_getfld can be used to get all information pertaining to the nth -data field in the message. The subroutine returns all the unpacked metadata -for each Section and Template in a gribfield structure, -which is defined in include file grib2.h. An option exists that lets the -user decide if the decoder should unpack the Bit-map ( if applicable ) -and the data values or just return the field description information. - -Note that a struct gribfield is allocated by g2_getfld, and it also -contains pointers to many arrays of data that are alloated during decoding. -Because of this, users are encouraged to free up this memory, when it is -no longer needed, by an explicit call to routine g2_free. - -Please see the "GRIB2 Routine Documentation" section below for subroutine -argument usage for the routines mentioned above. - -=============================================================================== - Decoding all GRIB2 Fields in a File - -Routines seekgb, g2_info and g2_getfld can be used to sequentially decode -all the GRIB2 fields in a file. This is illustrated by the following example: - - #include - #include - #include "grib2.h" - - unsigned char *cgrib; - g2int listsec0[3],listsec1[13],numlocal,numfields; - long lskip,n,lgrib,iseek; - int unpack,ret,ierr; - gribfield *gfld; - FILE *fptr; - size_t lengrib; - - iseek=0; - unpack=1; - expand=1; - fptr=fopen("inputgribfile","r"); - for (;;) { - seekgb(fptr,iseek,32000,&lskip,&lgrib); - if (lgrib == 0) break; // end loop at EOF or problem - cgrib=(unsigned char *)malloc(lgrib); - ret=fseek(fptr,lskip,SEEK_SET); - lengrib=fread(cgrib,sizeof(unsigned char),lgrib,fptr); - iseek=lskip+lgrib; - ierr=g2_info(cgrib,listsec0,listsec1,&numfields,&numlocal); - for (n=0;nversion = GRIB edition number ( currently 2 ) -// gfld->discipline = Message Discipline ( see Code Table 0.0 ) -// gfld->idsect = Contains the entries in the Identification -// Section ( Section 1 ) -// This element is a pointer to an array -// that holds the data. -// gfld->idsect[0] = Identification of originating Centre -// ( see Common Code Table C-1 ) -// 7 - US National Weather Service -// gfld->idsect[1] = Identification of originating Sub-centre -// gfld->idsect[2] = GRIB Master Tables Version Number -// ( see Code Table 1.0 ) -// 0 - Experimental -// 1 - Initial operational version number -// gfld->idsect[3] = GRIB Local Tables Version Number -// ( see Code Table 1.1 ) -// 0 - Local tables not used -// 1-254 - Number of local tables version used -// gfld->idsect[4] = Significance of Reference Time (Code Table 1.2) -// 0 - Analysis -// 1 - Start of forecast -// 2 - Verifying time of forecast -// 3 - Observation time -// gfld->idsect[5] = Year ( 4 digits ) -// gfld->idsect[6] = Month -// gfld->idsect[7) = Day -// gfld->idsect[8] = Hour -// gfld->idsect[9] = Minute -// gfld->idsect[10] = Second -// gfld->idsect[11] = Production status of processed data -// ( see Code Table 1.3 ) -// 0 - Operational products -// 1 - Operational test products -// 2 - Research products -// 3 - Re-analysis products -// gfld->idsect[12] = Type of processed data ( see Code Table 1.4 ) -// 0 - Analysis products -// 1 - Forecast products -// 2 - Analysis and forecast products -// 3 - Control forecast products -// 4 - Perturbed forecast products -// 5 - Control and perturbed forecast products -// 6 - Processed satellite observations -// 7 - Processed radar observations -// gfld->idsectlen = Number of elements in gfld->idsect[]. -// gfld->local = Pointer to character array containing contents -// of Local Section 2, if included -// gfld->locallen = length of array gfld->local[] -// gfld->ifldnum = field number within GRIB message -// gfld->griddef = Source of grid definition (see Code Table 3.0) -// 0 - Specified in Code table 3.1 -// 1 - Predetermined grid Defined by originating centre -// gfld->ngrdpts = Number of grid points in the defined grid. -// gfld->numoct_opt = Number of octets needed for each -// additional grid points definition. -// Used to define number of -// points in each row ( or column ) for -// non-regular grids. -// = 0, if using regular grid. -// gfld->interp_opt = Interpretation of list for optional points -// definition. (Code Table 3.11) -// gfld->igdtnum = Grid Definition Template Number (Code Table 3.1) -// gfld->igdtmpl = Contains the data values for the specified Grid -// Definition Template ( NN=gfld->igdtnum ). Each -// element of this integer array contains an entry (in -// the order specified) of Grid Defintion Template 3.NN -// This element is a pointer to an array -// that holds the data. -// gfld->igdtlen = Number of elements in gfld->igdtmpl[]. i.e. number of -// entries in Grid Defintion Template 3.NN -// ( NN=gfld->igdtnum ). -// gfld->list_opt = (Used if gfld->numoct_opt .ne. 0) This array -// contains the number of grid points contained in -// each row ( or column ). (part of Section 3) -// This element is a pointer to an array -// that holds the data. This pointer is nullified -// if gfld->numoct_opt=0. -// gfld->num_opt = (Used if gfld->numoct_opt .ne. 0) -// The number of entries -// in array ideflist. i.e. number of rows ( or columns ) -// for which optional grid points are defined. This value -// is set to zero, if gfld->numoct_opt=0. -// gfdl->ipdtnum = Product Definition Template Number(see Code Table 4.0) -// gfld->ipdtmpl = Contains the data values for the specified Product -// Definition Template ( N=gfdl->ipdtnum ). Each element -// of this integer array contains an entry (in the -// order specified) of Product Defintion Template 4.N. -// This element is a pointer to an array -// that holds the data. -// gfld->ipdtlen = Number of elements in gfld->ipdtmpl[]. i.e. number of -// entries in Product Defintion Template 4.N -// ( N=gfdl->ipdtnum ). -// gfld->coord_list = Real array containing floating point values -// intended to document the vertical discretisation -// associated to model data on hybrid coordinate -// vertical levels. (part of Section 4) -// This element is a pointer to an array -// that holds the data. -// gfld->num_coord = number of values in array gfld->coord_list[]. -// gfld->ndpts = Number of data points unpacked and returned. -// gfld->idrtnum = Data Representation Template Number -// ( see Code Table 5.0) -// gfld->idrtmpl = Contains the data values for the specified Data -// Representation Template ( N=gfld->idrtnum ). Each -// element of this integer array contains an entry -// (in the order specified) of Product Defintion -// Template 5.N. -// This element is a pointer to an array -// that holds the data. -// gfld->idrtlen = Number of elements in gfld->idrtmpl[]. i.e. number -// of entries in Data Representation Template 5.N -// ( N=gfld->idrtnum ). -// gfld->unpacked = logical value indicating whether the bitmap and -// data values were unpacked. If false, -// gfld->bmap and gfld->fld pointers are nullified. -// gfld->expanded = Logical value indicating whether the data field -// was expanded to the grid in the case where a -// bit-map is present. If true, the data points in -// gfld->fld match the grid points and zeros were -// inserted at grid points where data was bit-mapped -// out. If false, the data values in gfld->fld were -// not expanded to the grid and are just a consecutive -// array of data points corresponding to each value of -// "1" in gfld->bmap. -// gfld->ibmap = Bitmap indicator ( see Code Table 6.0 ) -// 0 = bitmap applies and is included in Section 6. -// 1-253 = Predefined bitmap applies -// 254 = Previously defined bitmap applies to this field -// 255 = Bit map does not apply to this product. -// gfld->bmap = integer array containing decoded bitmap, -// if gfld->ibmap=0 or gfld->ibap=254. -// Otherwise nullified. -// This element is a pointer to an array -// that holds the data. -// gfld->fld = Array of gfld->ndpts unpacked data points. -// This element is a pointer to an array -// that holds the data. -/////////////////////////////////////////////////////////////////////////// - - - -//$$$ SUBPROGRAM DOCUMENTATION BLOCK //////////////////////////////////// -// -// SUBPROGRAM: seekgb Searches a file for the next GRIB message. -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-28 -// -// ABSTRACT: This subprogram searches a file for the next GRIB Message. -// The search is done starting at byte offset iseek of the file referenced -// by lugb for mseek bytes at a time. -// If found, the starting position and length of the message are returned -// in lskip and lgrib, respectively. -// The search is terminated when an EOF or I/O error is encountered. -// -// PROGRAM HISTORY LOG: -// 2002-10-28 GILBERT Modified from Iredell's skgb subroutine -// -// USAGE: seekgb(FILE *lugb,long iseek,long mseek,int *lskip,int *lgrib) -// INPUT ARGUMENTS: -// lugb - FILE pointer for the file to search. File must be -// opened before this routine is called. -// iseek - number of bytes in the file to skip before search -// mseek - number of bytes to search at a time -// OUTPUT ARGUMENTS: -// lskip - number of bytes to skip from the beggining of the file -// to where the GRIB message starts -// lgrib - number of bytes in message (set to 0, if no message found) -// -// ATTRIBUTES: -// LANGUAGE: C -// -////////////////////////////////////////////////////////////////////////// - - - -//$$$ SUBPROGRAM DOCUMENTATION BLOCK /////////////////////////////////// -// . . . . -// SUBPROGRAM: g2_info -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-28 -// -// ABSTRACT: This subroutine searches through a GRIB2 message and -// returns the number of gridded fields found in the message and -// the number (and maximum size) of Local Use Sections. -// Also various checks are performed -// to see if the message is a valid GRIB2 message. -// -// PROGRAM HISTORY LOG: -// 2002-10-28 Gilbert -// -// USAGE: int g2_info(unsigned char *cgrib,g2int *listsec0,g2int *listsec1, -// g2int *numfields,g2int *numlocal) -// INPUT ARGUMENT: -// cgrib - Character pointer to the GRIB2 message -// -// OUTPUT ARGUMENTS: -// listsec0 - pointer to an array containing information decoded from -// GRIB Indicator Section 0. -// Must be allocated with >= 3 elements. -// listsec0[0]=Discipline-GRIB Master Table Number -// (see Code Table 0.0) -// listsec0[1]=GRIB Edition Number (currently 2) -// listsec0[2]=Length of GRIB message -// listsec1 - pointer to an array containing information read from GRIB -// Identification Section 1. -// Must be allocated with >= 13 elements. -// listsec1[0]=Id of orginating centre (Common Code Table C-1) -// listsec1[1]=Id of orginating sub-centre (local table) -// listsec1[2]=GRIB Master Tables Version Number (Code Table 1.0) -// listsec1[3]=GRIB Local Tables Version Number -// listsec1[4]=Significance of Reference Time (Code Table 1.1) -// listsec1[5]=Reference Time - Year (4 digits) -// listsec1[6]=Reference Time - Month -// listsec1[7]=Reference Time - Day -// listsec1[8]=Reference Time - Hour -// listsec1[9]=Reference Time - Minute -// listsec1[10]=Reference Time - Second -// listsec1[11]=Production status of data (Code Table 1.2) -// listsec1[12]=Type of processed data (Code Table 1.3) -// numfields- The number of gridded fields found in the GRIB message. -// That is, the number of occurences of Sections 4 - 7. -// numlocal - The number of Local Use Sections ( Section 2 ) found in -// the GRIB message. -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 1 = Beginning characters "GRIB" not found. -// 2 = GRIB message is not Edition 2. -// 3 = Could not find Section 1, where expected. -// 4 = End string "7777" found, but not where expected. -// 5 = End string "7777" not found at end of message. -// 6 = Invalid section number found. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -////////////////////////////////////////////////////////////////////////// - - - -//$$$ SUBPROGRAM DOCUMENTATION BLOCK /////////////////////////////////// -// . . . . -// SUBPROGRAM: g2_getfld -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-28 -// -// ABSTRACT: This subroutine returns all the metadata, template values, -// Bit-map ( if applicable ), and the unpacked data for a given data -// field. All of the information returned is stored in a gribfield -// structure, which is defined in file grib2.h. -// Users of this routine will need to include "grib2.h" in their source -// code that calls this routine. Each component of the gribfield -// struct is also described in the OUTPUT ARGUMENTS section below. -// -// Since there can be multiple data fields packed into a GRIB2 -// message, the calling routine indicates which field is being requested -// with the ifldnum argument. -// -// PROGRAM HISTORY LOG: -// 2002-10-28 Gilbert -// -// USAGE: #include "grib2.h" -// int g2_getfld(unsigned char *cgrib,g2int ifldnum,g2int unpack, -// g2int expand,gribfield **gfld) -// INPUT ARGUMENTS: -// cgrib - Character pointer to the GRIB2 message -// ifldnum - Specifies which field in the GRIB2 message to return. -// unpack - Boolean value indicating whether to unpack bitmap/data -// 1 = unpack bitmap and data values -// 0 = do not unpack bitmap and data values -// expand - Boolean value indicating whether the data points should be -// expanded to the correspond grid, if a bit-map is present. -// 1 = if possible, expand data field to grid, inserting zero -// values at gridpoints that are bitmapped out. -// (SEE REMARKS2) -// 0 = do not expand data field, leaving it an array of -// consecutive data points for each "1" in the bitmap. -// This argument is ignored if unpack == 0 OR if the -// returned field does not contain a bit-map. -// -// OUTPUT ARGUMENT: -// gribfield gfld; - pointer to structure gribfield containing -// all decoded data for the data field. -// -// gfld->version = GRIB edition number ( currently 2 ) -// gfld->discipline = Message Discipline ( see Code Table 0.0 ) -// gfld->idsect = Contains the entries in the Identification -// Section ( Section 1 ) -// This element is a pointer to an array -// that holds the data. -// gfld->idsect[0] = Identification of originating Centre -// ( see Common Code Table C-1 ) -// 7 - US National Weather Service -// gfld->idsect[1] = Identification of originating Sub-centre -// gfld->idsect[2] = GRIB Master Tables Version Number -// ( see Code Table 1.0 ) -// 0 - Experimental -// 1 - Initial operational version number -// gfld->idsect[3] = GRIB Local Tables Version Number -// ( see Code Table 1.1 ) -// 0 - Local tables not used -// 1-254 - Number of local tables version used -// gfld->idsect[4] = Significance of Reference Time (Code Table 1.2) -// 0 - Analysis -// 1 - Start of forecast -// 2 - Verifying time of forecast -// 3 - Observation time -// gfld->idsect[5] = Year ( 4 digits ) -// gfld->idsect[6] = Month -// gfld->idsect[7) = Day -// gfld->idsect[8] = Hour -// gfld->idsect[9] = Minute -// gfld->idsect[10] = Second -// gfld->idsect[11] = Production status of processed data -// ( see Code Table 1.3 ) -// 0 - Operational products -// 1 - Operational test products -// 2 - Research products -// 3 - Re-analysis products -// gfld->idsect[12] = Type of processed data ( see Code Table 1.4 ) -// 0 - Analysis products -// 1 - Forecast products -// 2 - Analysis and forecast products -// 3 - Control forecast products -// 4 - Perturbed forecast products -// 5 - Control and perturbed forecast products -// 6 - Processed satellite observations -// 7 - Processed radar observations -// gfld->idsectlen = Number of elements in gfld->idsect[]. -// gfld->local = Pointer to character array containing contents -// of Local Section 2, if included -// gfld->locallen = length of array gfld->local[] -// gfld->ifldnum = field number within GRIB message -// gfld->griddef = Source of grid definition (see Code Table 3.0) -// 0 - Specified in Code table 3.1 -// 1 - Predetermined grid Defined by originating centre -// gfld->ngrdpts = Number of grid points in the defined grid. -// gfld->numoct_opt = Number of octets needed for each -// additional grid points definition. -// Used to define number of -// points in each row ( or column ) for -// non-regular grids. -// = 0, if using regular grid. -// gfld->interp_opt = Interpretation of list for optional points -// definition. (Code Table 3.11) -// gfld->igdtnum = Grid Definition Template Number (Code Table 3.1) -// gfld->igdtmpl = Contains the data values for the specified Grid -// Definition Template ( NN=gfld->igdtnum ). Each -// element of this integer array contains an entry (in -// the order specified) of Grid Defintion Template 3.NN -// This element is a pointer to an array -// that holds the data. -// gfld->igdtlen = Number of elements in gfld->igdtmpl[]. i.e. number of -// entries in Grid Defintion Template 3.NN -// ( NN=gfld->igdtnum ). -// gfld->list_opt = (Used if gfld->numoct_opt .ne. 0) This array -// contains the number of grid points contained in -// each row ( or column ). (part of Section 3) -// This element is a pointer to an array -// that holds the data. This pointer is nullified -// if gfld->numoct_opt=0. -// gfld->num_opt = (Used if gfld->numoct_opt .ne. 0) -// The number of entries -// in array ideflist. i.e. number of rows ( or columns ) -// for which optional grid points are defined. This value -// is set to zero, if gfld->numoct_opt=0. -// gfdl->ipdtnum = Product Definition Template Number(see Code Table 4.0) -// gfld->ipdtmpl = Contains the data values for the specified Product -// Definition Template ( N=gfdl->ipdtnum ). Each element -// of this integer array contains an entry (in the -// order specified) of Product Defintion Template 4.N. -// This element is a pointer to an array -// that holds the data. -// gfld->ipdtlen = Number of elements in gfld->ipdtmpl[]. i.e. number of -// entries in Product Defintion Template 4.N -// ( N=gfdl->ipdtnum ). -// gfld->coord_list = Real array containing floating point values -// intended to document the vertical discretisation -// associated to model data on hybrid coordinate -// vertical levels. (part of Section 4) -// This element is a pointer to an array -// that holds the data. -// gfld->num_coord = number of values in array gfld->coord_list[]. -// gfld->ndpts = Number of data points unpacked and returned. -// gfld->idrtnum = Data Representation Template Number -// ( see Code Table 5.0) -// gfld->idrtmpl = Contains the data values for the specified Data -// Representation Template ( N=gfld->idrtnum ). Each -// element of this integer array contains an entry -// (in the order specified) of Product Defintion -// Template 5.N. -// This element is a pointer to an array -// that holds the data. -// gfld->idrtlen = Number of elements in gfld->idrtmpl[]. i.e. number -// of entries in Data Representation Template 5.N -// ( N=gfld->idrtnum ). -// gfld->unpacked = logical value indicating whether the bitmap and -// data values were unpacked. If false, -// gfld->bmap and gfld->fld pointers are nullified. -// gfld->expanded = Logical value indicating whether the data field -// was expanded to the grid in the case where a -// bit-map is present. If true, the data points in -// gfld->fld match the grid points and zeros were -// inserted at grid points where data was bit-mapped -// out. If false, the data values in gfld->fld were -// not expanded to the grid and are just a consecutive -// array of data points corresponding to each value of -// "1" in gfld->bmap. -// gfld->ibmap = Bitmap indicator ( see Code Table 6.0 ) -// 0 = bitmap applies and is included in Section 6. -// 1-253 = Predefined bitmap applies -// 254 = Previously defined bitmap applies to this field -// 255 = Bit map does not apply to this product. -// gfld->bmap = integer array containing decoded bitmap, -// if gfld->ibmap=0 or gfld->ibap=254. Otherwise nullified -// This element is a pointer to an array -// that holds the data. -// gfld->fld = Array of gfld->ndpts unpacked data points. -// This element is a pointer to an array -// that holds the data. -// -// -// RETURN VALUES: -// ierr - Error return code. -// 0 = no error -// 1 = Beginning characters "GRIB" not found. -// 2 = GRIB message is not Edition 2. -// 3 = The data field request number was not positive. -// 4 = End string "7777" found, but not where expected. -// 6 = GRIB message did not contain the requested number of -// data fields. -// 7 = End string "7777" not found at end of message. -// 8 = Unrecognized Section encountered. -// 9 = Data Representation Template 5.NN not yet implemented. -// 15 = Error unpacking Section 1. -// 16 = Error unpacking Section 2. -// 10 = Error unpacking Section 3. -// 11 = Error unpacking Section 4. -// 12 = Error unpacking Section 5. -// 13 = Error unpacking Section 6. -// 14 = Error unpacking Section 7. -// -// REMARKS: Note that struct gribfield is allocated by this routine and it -// also contains pointers to many arrays of data that were allocated -// during decoding. Users are encouraged to free up this memory, -// when it is no longer needed, by an explicit call to routine g2_free. -// EXAMPLE: -// #include "grib2.h" -// gribfield *gfld; -// ret=g2_getfld(cgrib,1,1,1,&gfld); -// ... -// g2_free(gfld); -// -// Routine g2_info can be used to first determine -// how many data fields exist in a given GRIB message. -// -// REMARKS2: It may not always be possible to expand a bit-mapped data field. -// If a pre-defined bit-map is used and not included in the GRIB2 -// message itself, this routine would not have the necessary -// information to expand the data. In this case, gfld->expanded would -// would be set to 0 (false), regardless of the value of input -// argument expand. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -/////////////////////////////////////////////////////////////////////////// - - - -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_create -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This routine initializes a new GRIB2 message and packs -// GRIB2 sections 0 (Indicator Section) and 1 (Identification Section). -// This routine is used with routines "g2_addlocal", "g2_addgrid", -// "g2_addfield", and "g2_gribend" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// Also, a call to g2_gribend is required to complete GRIB2 message -// after all fields have been added. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// -// USAGE: int g2_create(unsigned char *cgrib,long *listsec0,long *listsec1) -// INPUT ARGUMENTS: -// cgrib - Character array to contain the GRIB2 message -// listsec0 - Contains information needed for GRIB Indicator Section 0. -// Must be dimensioned >= 2. -// listsec0[0]=Discipline-GRIB Master Table Number -// (see Code Table 0.0) -// listsec0[1]=GRIB Edition Number (currently 2) -// listsec1 - Contains information needed for GRIB Identification Section 1. -// Must be dimensioned >= 13. -// listsec1[0]=Id of orginating centre (Common Code Table C-1) -// listsec1[1]=Id of orginating sub-centre (local table) -// listsec1[2]=GRIB Master Tables Version Number (Code Table 1.0) -// listsec1[3]=GRIB Local Tables Version Number (Code Table 1.1) -// listsec1[4]=Significance of Reference Time (Code Table 1.2) -// listsec1[5]=Reference Time - Year (4 digits) -// listsec1[6]=Reference Time - Month -// listsec1[7]=Reference Time - Day -// listsec1[8]=Reference Time - Hour -// listsec1[9]=Reference Time - Minute -// listsec1[10]=Reference Time - Second -// listsec1[11]=Production status of data (Code Table 1.3) -// listsec1[12]=Type of processed data (Code Table 1.4) -// -// OUTPUT ARGUMENTS: -// cgrib - Char array to contain the new GRIB2 message. -// Must be allocated large enough to store the entire -// GRIB2 message. -// -// RETURN VALUES: -// ierr - return code. -// > 0 = Current size of new GRIB2 message -// -1 = Tried to use for version other than GRIB Edition 2 -// -// REMARKS: This routine is intended for use with routines "g2_addlocal", -// "g2_addgrid", "g2_addfield", and "g2_gribend" to create a complete -// GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ - - - -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_addlocal -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-11-01 -// -// ABSTRACT: This routine adds a Local Use Section (Section 2) to -// a GRIB2 message. It is used with routines "g2_create", -// "g2_addgrid", "g2_addfield", -// and "g2_gribend" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// -// PROGRAM HISTORY LOG: -// 2002-11-01 Gilbert -// -// USAGE: int g2_addlocal(unsigned char *cgrib,unsigned char *csec2, -// long lcsec2) -// INPUT ARGUMENTS: -// cgrib - Char array that contains the GRIB2 message to which section -// 2 should be added. -// csec2 - Character array containing information to be added in -// Section 2. -// lcsec2 - Number of bytes of character array csec2 to be added to -// Section 2. -// -// OUTPUT ARGUMENT: -// cgrib - Char array to contain the updated GRIB2 message. -// Must be allocated large enough to store the entire -// GRIB2 message. -// -// RETURN VALUES: -// ierr - Return code. -// > 0 = Current size of updated GRIB2 message -// -1 = GRIB message was not initialized. Need to call -// routine gribcreate first. -// -2 = GRIB message already complete. Cannot add new section. -// -3 = Sum of Section byte counts doesn't add to total byte count -// -4 = Previous Section was not 1 or 7. -// -// REMARKS: Note that the Local Use Section ( Section 2 ) can only follow -// Section 1 or Section 7 in a GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ - - - -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_addgrid -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-11-01 -// -// ABSTRACT: This routine packs up a Grid Definition Section (Section 3) -// and adds it to a GRIB2 message. It is used with routines "g2_create", -// "g2_addlocal", "g2_addfield", -// and "g2_gribend" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// -// PROGRAM HISTORY LOG: -// 2002-11-01 Gilbert -// -// USAGE: int g2_addgrid(unsigned char *cgrib,long *igds,g2int *igdstmpl, -// long *ideflist,long idefnum) -// INPUT ARGUMENTS: -// cgrib - Char array that contains the GRIB2 message to which -// section should be added. -// igds - Contains information needed for GRIB Grid Definition Section 3 -// Must be dimensioned >= 5. -// igds[0]=Source of grid definition (see Code Table 3.0) -// igds[1]=Number of grid points in the defined grid. -// igds[2]=Number of octets needed for each -// additional grid points definition. -// Used to define number of -// points in each row ( or column ) for -// non-regular grids. -// = 0, if using regular grid. -// igds[3]=Interpretation of list for optional points -// definition. (Code Table 3.11) -// igds[4]=Grid Definition Template Number (Code Table 3.1) -// igdstmpl - Contains the data values for the specified Grid Definition -// Template ( NN=igds[4] ). Each element of this integer -// array contains an entry (in the order specified) of Grid -// Defintion Template 3.NN -// ideflist - (Used if igds[2] != 0) This array contains the -// number of grid points contained in each row ( or column ) -// idefnum - (Used if igds[2] != 0) The number of entries -// in array ideflist. i.e. number of rows ( or columns ) -// for which optional grid points are defined. -// -// OUTPUT ARGUMENTS: -// cgrib - Char array to contain the updated GRIB2 message. -// Must be allocated large enough to store the entire -// GRIB2 message. -// -// RETURN VALUES: -// ierr - Return code. -// > 0 = Current size of updated GRIB2 message -// -1 = GRIB message was not initialized. Need to call -// routine gribcreate first. -// -2 = GRIB message already complete. Cannot add new section. -// -3 = Sum of Section byte counts doesn't add to total byte count -// -4 = Previous Section was not 1, 2 or 7. -// -5 = Could not find requested Grid Definition Template. -// -// REMARKS: Note that the Grid Def Section ( Section 3 ) can only follow -// Section 1, 2 or Section 7 in a GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ - - - -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_addfield -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-11-05 -// -// ABSTRACT: This routine packs up Sections 4 through 7 for a given field -// and adds them to a GRIB2 message. They are Product Definition Section, -// Data Representation Section, Bit-Map Section and Data Section, -// respectively. -// This routine is used with routines "g2_create", "g2_addlocal", -// "g2_addgrid", and "g2_gribend" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// Also, routine g2_addgrid must be called after g2_create and -// before this routine to add the appropriate grid description to -// the GRIB2 message. Also, a call to g2_gribend is required to complete -// GRIB2 message after all fields have been added. -// -// PROGRAM HISTORY LOG: -// 2002-11-05 Gilbert -// -// USAGE: int g2_addfield(unsigned char *cgrib,g2int ipdsnum,g2int *ipdstmpl, -// g2float *coordlist,g2int numcoord,g2int idrsnum,g2int *idrstmpl, -// g2float *fld,g2int ngrdpts,g2int ibmap,g2int *bmap) -// INPUT ARGUMENT LIST: -// cgrib - Char array that contains the GRIB2 message to which sections -// 4 through 7 should be added. -// ipdsnum - Product Definition Template Number ( see Code Table 4.0) -// ipdstmpl - Contains the data values for the specified Product Definition -// Template ( N=ipdsnum ). Each element of this integer -// array contains an entry (in the order specified) of Product -// Defintion Template 4.N -// coordlist- Array containg floating point values intended to document -// the vertical discretisation associated to model data -// on hybrid coordinate vertical levels. -// numcoord - number of values in array coordlist. -// idrsnum - Data Representation Template Number ( see Code Table 5.0 ) -// idrstmpl - Contains the data values for the specified Data Representation -// Template ( N=idrsnum ). Each element of this integer -// array contains an entry (in the order specified) of Data -// Representation Template 5.N -// Note that some values in this template (eg. reference -// values, number of bits, etc...) may be changed by the -// data packing algorithms. -// Use this to specify scaling factors and order of -// spatial differencing, if desired. -// fld[] - Array of data points to pack. -// ngrdpts - Number of data points in grid. -// i.e. size of fld and bmap. -// ibmap - Bitmap indicator ( see Code Table 6.0 ) -// 0 = bitmap applies and is included in Section 6. -// 1-253 = Predefined bitmap applies -// 254 = Previously defined bitmap applies to this field -// 255 = Bit map does not apply to this product. -// bmap[] - Integer array containing bitmap to be added. ( if ibmap=0 ) -// -// OUTPUT ARGUMENT LIST: -// cgrib - Character array to contain the updated GRIB2 message. -// Must be allocated large enough to store the entire -// GRIB2 message. -// -// RETURN VALUES: -// ierr - Return code. -// > 0 = Current size of updated GRIB2 message -// -1 = GRIB message was not initialized. Need to call -// routine gribcreate first. -// -2 = GRIB message already complete. Cannot add new section. -// -3 = Sum of Section byte counts doesn't add to total byte count -// -4 = Previous Section was not 3 or 7. -// -5 = Could not find requested Product Definition Template. -// -6 = Section 3 (GDS) not previously defined in message -// -7 = Tried to use unsupported Data Representationi Template -// -8 = Specified use of a previously defined bitmap, but one -// does not exist in the GRIB message. -// -// REMARKS: Note that the Sections 4 through 7 can only follow -// Section 3 or Section 7 in a GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ - - - -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: g2_gribend -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-31 -// -// ABSTRACT: This routine finalizes a GRIB2 message after all grids -// and fields have been added. It adds the End Section ( "7777" ) -// to the end of the GRIB message and calculates the length and stores -// it in the appropriate place in Section 0. -// This routine is used with routines "g2_create", "g2_addlocal", -// "g2_addgrid", and "g2_addfield" to create a complete GRIB2 message. -// g2_create must be called first to initialize a new GRIB2 message. -// -// PROGRAM HISTORY LOG: -// 2002-10-31 Gilbert -// -// USAGE: int g2_gribend(unsigned char *cgrib) -// INPUT ARGUMENT: -// cgrib - Char array containing all the data sections added -// be previous calls to g2_create, g2_addlocal, g2_addgrid, -// and g2_addfield. -// -// OUTPUT ARGUMENTS: -// cgrib - Char array containing the finalized GRIB2 message -// -// RETURN VALUES: -// ierr - Return code. -// > 0 = Length of the final GRIB2 message in bytes. -// -1 = GRIB message was not initialized. Need to call -// routine g2_create first. -// -2 = GRIB message already complete. -// -3 = Sum of Section byte counts doesn't add to total byte count -// -4 = Previous Section was not 7. -// -// REMARKS: This routine is intended for use with routines "g2_create", -// "g2_addlocal", "g2_addgrid", and "g2_addfield" to create a complete -// GRIB2 message. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ diff --git a/src/plugins/weatherdata/gfs/g2clib/gridtemplates.c b/src/plugins/weatherdata/gfs/g2clib/gridtemplates.c deleted file mode 100644 index f1b7a5d50..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/gridtemplates.c +++ /dev/null @@ -1,278 +0,0 @@ -#include -#include "grib2.h" -#include "gridtemplates.h" - -const struct gridtemplate templatesgrid[MAXGRIDTEMP] = { - // 3.0: Lat/Lon grid - { 0, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} }, - // 3.1: Rotated Lat/Lon grid - { 1, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4} }, - // 3.2: Stretched Lat/Lon grid - { 2, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4} }, - // 3.3: Stretched & Rotated Lat/Lon grid - { 3, 25, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4,-4,4,-4} }, -// Added GDT 3.4,3.5 (08/05/2013) - // 3.4: Variable resolution Latitude/Longitude - { 4, 13, 1, {1,1,4,1,4,1,4,4,4,4,4,1,1} }, - // 3.5: Variable resolution rotate Latitude/Longitude - { 5, 16, 1, {1,1,4,1,4,1,4,4,4,4,4,1,1,-4,4,4} }, - // 3.12: Transverse Mercator - {12, 22, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,1,4,4,-4,-4,-4,-4} }, - // 3.101: General unstructured grid - {101, 4, 0, {1,4,1,-4} }, - // 3.140: Lambert Azimuthal Equal Area Projection - {140, 17, 0, {1,1,4,1,4,1,4,4,4,-4,4,4,4,1,4,4,1} }, -// - // 3.10: Mercator - {10, 19, 0, {1,1,4,1,4,1,4,4,4,-4,-4,1,-4,-4,-4,1,4,4,4} }, - // 3.20: Polar Stereographic Projection - {20, 18, 0, {1,1,4,1,4,1,4,4,4,-4,-4,1,-4,-4,4,4,1,1} }, - // 3.30: Lambert Conformal - {30, 22, 0, {1,1,4,1,4,1,4,4,4,-4,-4,1,-4,-4,4,4,1,1,-4,-4,-4,-4} }, - // 3.31: Albers equal area - {31, 22, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,-4,4,4,4,1,1,-4,-4,-4,4} }, - // 3.40: Guassian Lat/Lon - {40, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} }, - // 3.41: Rotated Gaussian Lat/Lon - {41, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4} }, - // 3.42: Stretched Gaussian Lat/Lon - {42, 22, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,-4} }, - // 3.43: Stretched and Rotated Gaussian Lat/Lon - {43, 25, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,-4,4,4,-4,4,-4} }, - // 3.50: Spherical Harmonic Coefficients - {50, 5, 0, {4,4,4,1,1} }, - // 3.51: Rotated Spherical Harmonic Coefficients - {51, 8, 0, {4,4,4,1,1,-4,4,4} }, - // 3.52: Stretched Spherical Harmonic Coefficients - {52, 8, 0, {4,4,4,1,1,-4,4,-4} }, - // 3.53: Stretched and Rotated Spherical Harmonic Coefficients - {53, 11, 0, {4,4,4,1,1,-4,4,4,-4,4,-4} }, - // 3.90: Space View Perspective or orthographic - {90, 21, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,4,4,4,4,1,4,4,4,4} }, - // 3.100: Triangular grid based on an icosahedron - {100, 11, 0, {1,1,2,1,-4,4,4,1,1,1,4} }, - // 3.110: Equatorial Azimuthal equidistant - {110, 16, 0, {1,1,4,1,4,1,4,4,4,-4,4,1,4,4,1,1} }, - // 3.120: Azimuth-range projection - {120, 7, 1, {4,4,-4,4,4,4,1} }, - // 3.204: Curvilinear Orthogonal Grid - {204, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} }, - // 3.32768: Rot Lat/Lon E-grid (Arakawa) - {32768, 19, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1} }, - // 3.32769: Rot Lat/Lon Non-E Staggered grid (Arakawa) - {32769, 21, 0, {1,1,4,1,4,1,4,4,4,4,4,-4,4,1,-4,4,4,4,1,4,4} }, - // 3.1000: Cross Section Grid - {1000, 20, 1, {1,1,4,1,4,1,4,4,4,4,-4,4,1,4,4,1,2,1,1,2} }, - // 3.1100: Hovmoller Diagram Grid - {1100, 28, 0, {1,1,4,1,4,1,4,4,4,4,-4,4,1,-4,4,1,4,1,-4,1,1,-4,2,1,1,1,1,1} }, - // 3.1200: Time Section Grid - {1200, 16, 1, {4,1,-4,1,1,-4,2,1,1,1,1,1,2,1,1,2} } - -} ; - -g2int getgridindex(g2int number) -/*!$$$ SUBPROGRAM DOCUMENTATION BLOCK -! . . . . -! SUBPROGRAM: getgridindex -! PRGMMR: Gilbert ORG: W/NP11 DATE: 2001-06-28 -! -! ABSTRACT: This function returns the index of specified Grid -! Definition Template 3.NN (NN=number) in array templates. -! -! PROGRAM HISTORY LOG: -! 2001-06-28 Gilbert -! 2007-08-16 Vuong - Added GDT 3.204 Curvilinear Orthogonal Grid -! 2008-07-08 Vuong - Added GDT 3.32768 Rotate Lat/Lon E-grid (Arakawa) -! 2009-01-14 Vuong - Changed structure name template to gtemplate -! 2010-05-11 Vuong - Added GDT 3.32769 Rotate Lat/Lon Non-E Staggered grid (Arakawa) -! 2013-08-06 Vuong - Added GDT 3.4,3.5,3.12,3.101,3.140 -! -! USAGE: index=getgridindex(number) -! INPUT ARGUMENT LIST: -! number - NN, indicating the number of the Grid Definition -! Template 3.NN that is being requested. -! -! RETURNS: Index of GDT 3.NN in array templates, if template exists. -! = -1, otherwise. -! -! REMARKS: None -! -! ATTRIBUTES: -! LANGUAGE: C -! MACHINE: IBM SP -! -!$$$*/ -{ - g2int j,getgridindex=-1; - - for (j=0;jtype=3; - new->num=templatesgrid[index].template_num; - new->maplen=templatesgrid[index].mapgridlen; - new->needext=templatesgrid[index].needext; - new->map=(g2int *)templatesgrid[index].mapgrid; - new->extlen=0; - new->ext=0; //NULL - return(new); - } - else { - printf("getgridtemplate: GDT Template 3.%d not defined.\n",(int)number); - return(0); //NULL - } - - return(0); //NULL -} - - -gtemplate *extgridtemplate(g2int number,g2int *list) -/*!$$$ SUBPROGRAM DOCUMENTATION BLOCK -! . . . . -! SUBPROGRAM: extgridtemplate -! PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-09 -! -! ABSTRACT: This subroutine generates the remaining octet map for a -! given Grid Definition Template, if required. Some Templates can -! vary depending on data values given in an earlier part of the -! Template, and it is necessary to know some of the earlier entry -! values to generate the full octet map of the Template. -! -! PROGRAM HISTORY LOG: -! 2000-05-09 Gilbert -! 2008-07-08 Vuong - Added GDT 3.32768 Rotate Lat/Lon E-grid (Arakawa) -! 2009-01-14 Vuong - Changed structure name template to gtemplate -! 2010-05-11 Vuong - Added GDT 3.32769 Rotate Lat/Lon Non-E Staggered grid (Arakawa) -! 2013-08-06 Vuong - Added GDT 3.4,3.5,3.12,3.101,3.140 -! -! USAGE: CALL extgridtemplate(number,list) -! INPUT ARGUMENT LIST: -! number - NN, indicating the number of the Grid Definition -! Template 3.NN that is being requested. -! list() - The list of values for each entry in -! the Grid Definition Template. -! -! RETURN VALUE: -! - Pointer to the returned template struct. -! Returns NULL pointer, if template not found. -! -! ATTRIBUTES: -! LANGUAGE: C -! MACHINE: IBM SP -! -!$$$*/ -{ - gtemplate *new; - g2int index,i; - - index=getgridindex(number); - if (index == -1) return(0); - - new=getgridtemplate(number); - - if ( ! new->needext ) return(new); - - if ( number == 120 ) { - new->extlen=list[1]*2; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - if ( i%2 == 0 ) { - new->ext[i]=2; - } - else { - new->ext[i]=-2; - } - } - } - else if ( number == 4 ) { - new->extlen=list[7]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=4; - } - new->extlen=list[8]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=-4; - } - } - else if ( number == 5 ) { - new->extlen=list[7]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=4; - } - new->extlen=list[8]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=-4; - } - } - else if ( number == 1000 ) { - new->extlen=list[19]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=4; - } - } - else if ( number == 1200 ) { - new->extlen=list[15]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=4; - } - } - - return(new); - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/gridtemplates.h b/src/plugins/weatherdata/gfs/g2clib/gridtemplates.h deleted file mode 100644 index d2d80cba3..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/gridtemplates.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _gridtemplates_H -#define _gridtemplates_H -#include "grib2.h" - -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2001-10-26 -// -// ABSTRACT: This Fortran Module contains info on all the available -// GRIB2 Grid Definition Templates used in Section 3 (GDS). -// The information decribing each template is stored in the -// gridtemplate structure defined below. -// -// Each Template has three parts: The number of entries in the template -// (mapgridlen); A map of the template (mapgrid), which contains the -// number of octets in which to pack each of the template values; and -// a logical value (needext) that indicates whether the Template needs -// to be extended. In some cases the number of entries in a template -// can vary depending upon values specified in the "static" part of -// the template. ( See Template 3.120 as an example ) -// -// NOTE: Array mapgrid contains the number of octets in which the -// corresponding template values will be stored. A negative value in -// mapgrid is used to indicate that the corresponding template entry can -// contain negative values. This information is used later when packing -// (or unpacking) the template data values. Negative data values in GRIB -// are stored with the left most bit set to one, and a negative number -// of octets value in mapgrid[] indicates that this possibility should -// be considered. The number of octets used to store the data value -// in this case would be the absolute value of the negative value in -// mapgrid[]. -// -// PROGRAM HISTORY LOG: -// -// 2001-10-26 Gilbert -// 2007-08-16 Vuong - Added GDT 3.204 Curvilinear Orthogonal Grid -// 2008-07-08 Vuong - Added GDT 3.32768 Rot Lat/Lon E-grid (Arakawa) -// 2010-05-11 Vuong - Added GDT 3.32769 Rotate Lat/Lon Non-E Staggered grid (Arakawa) -// 2013-08-06 Vuong - Added GDT 3.4,3.5,3.12,3.101,3.140 -// -//////////////////////////////////////////////////////////////////// - - #define MAXGRIDTEMP 31 // maximum number of templates - #define MAXGRIDMAPLEN 200 // maximum template map length - - struct gridtemplate - { - g2int template_num; - g2int mapgridlen; - g2int needext; - g2int mapgrid[MAXGRIDMAPLEN]; - }; - - extern const struct gridtemplate templatesgrid[]; - - g2int getgridindex(g2int number); - -#endif /* _gridtemplates_H */ diff --git a/src/plugins/weatherdata/gfs/g2clib/int_power.c b/src/plugins/weatherdata/gfs/g2clib/int_power.c deleted file mode 100644 index 76f645abd..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/int_power.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "grib2.h" -/* - * w. ebisuzaki - * - * return x**y - * - * - * input: double x - * int y - */ -double int_power(double x, g2int y) { - - double value; - - if (y < 0) { - y = -y; - x = 1.0 / x; - } - value = 1.0; - - while (y) { - if (y & 1) { - value *= x; - } - x = x * x; - y >>= 1; - } - return value; -} - diff --git a/src/plugins/weatherdata/gfs/g2clib/jpcpack.c b/src/plugins/weatherdata/gfs/g2clib/jpcpack.c deleted file mode 100644 index 266666868..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/jpcpack.c +++ /dev/null @@ -1,175 +0,0 @@ -#include -#include -#include "grib2.h" - -int enc_jpeg2000(unsigned char *,g2int ,g2int ,g2int , - g2int , g2int, g2int , char *, g2int ); - -void jpcpack(g2float *fld,g2int width,g2int height,g2int *idrstmpl, - unsigned char *cpack,g2int *lcpack) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: jpcpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2003-08-17 -// -// ABSTRACT: This subroutine packs up a data field into a JPEG2000 code stream. -// After the data field is scaled, and the reference value is subtracted out, -// it is treated as a grayscale image and passed to a JPEG2000 encoder. -// It also fills in GRIB2 Data Representation Template 5.40 or 5.40000 with -// the appropriate values. -// -// PROGRAM HISTORY LOG: -// 2003-08-17 Gilbert -// 2004-11-92 Gilbert - Fixed bug encountered when packing a near constant -// field. -// 2004-07-19 Gilbert - Added check on whether the jpeg2000 encoding was -// successful. If not, try again with different encoder -// options. -// 2005-05-10 Gilbert - Imposed minimum size on cpack, used to hold encoded -// bit string. -// -// USAGE: jpcpack(g2float *fld,g2int width,g2int height,g2int *idrstmpl, -// unsigned char *cpack,g2int *lcpack); -// INPUT ARGUMENT LIST: -// fld[] - Contains the data values to pack -// width - number of points in the x direction -// height - number of points in the y direction -// idrstmpl - Contains the array of values for Data Representation -// Template 5.40 or 5.40000 -// [0] = Reference value - ignored on input -// [1] = Binary Scale Factor -// [2] = Decimal Scale Factor -// [3] = number of bits for each data value - ignored on input -// [4] = Original field type - currently ignored on input -// Data values assumed to be reals. -// [5] = 0 - use lossless compression -// = 1 - use lossy compression -// [6] = Desired compression ratio, if idrstmpl[5]=1. -// Set to 255, if idrstmpl[5]=0. -// lcpack - size of array cpack[] -// -// OUTPUT ARGUMENT LIST: -// idrstmpl - Contains the array of values for Data Representation -// Template 5.0 -// [0] = Reference value - set by jpcpack routine. -// [1] = Binary Scale Factor - unchanged from input -// [2] = Decimal Scale Factor - unchanged from input -// [3] = Number of bits containing each grayscale pixel value -// [4] = Original field type - currently set = 0 on output. -// Data values assumed to be reals. -// [5] = 0 - use lossless compression -// = 1 - use lossy compression -// [6] = Desired compression ratio, if idrstmpl[5]=1 -// cpack - The packed data field -// lcpack - length of packed field in cpack. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - g2int *ifld; - static g2float alog2=0.69314718; // ln(2.0) - g2int j,nbits,imin,imax,maxdif; - g2int ndpts,nbytes,nsize,retry; - g2float bscale,dscale,rmax,rmin,temp; - unsigned char *ctemp; - - ifld=0; - ndpts=width*height; - bscale=int_power(2.0,-idrstmpl[1]); - dscale=int_power(10.0,idrstmpl[2]); -// -// Find max and min values in the data -// - rmax=fld[0]; - rmin=fld[0]; - for (j=1;j rmax) rmax=fld[j]; - if (fld[j] < rmin) rmin=fld[j]; - } - if (idrstmpl[1] == 0) - maxdif = (g2int) (rint(rmax*dscale) - rint(rmin*dscale)); - else - maxdif = (g2int)rint( (rmax-rmin)*dscale*bscale ); -// -// If max and min values are not equal, pack up field. -// If they are equal, we have a constant field, and the reference -// value (rmin) is the value for each point in the field and -// set nbits to 0. -// - if ( rmin != rmax && maxdif != 0 ) { - ifld=(g2int *)malloc(ndpts*sizeof(g2int)); - // - // Determine which algorithm to use based on user-supplied - // binary scale factor and number of bits. - // - if (idrstmpl[1] == 0) { - // - // No binary scaling and calculate minumum number of - // bits in which the data will fit. - // - imin=(g2int)rint(rmin*dscale); - imax=(g2int)rint(rmax*dscale); - maxdif=imax-imin; - temp=log((double)(maxdif+1))/alog2; - nbits=(g2int)ceil(temp); - rmin=(g2float)imin; - // scale data - for(j=0;j -#include -#include "grib2.h" - - int dec_jpeg2000(char *,g2int ,g2int *); - -g2int jpcunpack(unsigned char *cpack,g2int len,g2int *idrstmpl,g2int ndpts, - g2float *fld) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: jpcunpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2003-08-27 -// -// ABSTRACT: This subroutine unpacks a data field that was packed into a -// JPEG2000 code stream -// using info from the GRIB2 Data Representation Template 5.40 or 5.40000. -// -// PROGRAM HISTORY LOG: -// 2003-08-27 Gilbert -// -// USAGE: jpcunpack(unsigned char *cpack,g2int len,g2int *idrstmpl,g2int ndpts, -// g2float *fld) -// INPUT ARGUMENT LIST: -// cpack - The packed data field (character*1 array) -// len - length of packed field cpack(). -// idrstmpl - Pointer to array of values for Data Representation -// Template 5.40 or 5.40000 -// ndpts - The number of data values to unpack -// -// OUTPUT ARGUMENT LIST: -// fld[] - Contains the unpacked data values -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - - g2int *ifld; - g2int j,nbits; - g2float ref,bscale,dscale; - - rdieee(idrstmpl+0,&ref,1); - bscale = int_power(2.0,idrstmpl[1]); - dscale = int_power(10.0,-idrstmpl[2]); - nbits = idrstmpl[3]; -// -// if nbits equals 0, we have a constant field where the reference value -// is the data value at each gridpoint -// - if (nbits != 0) { - - ifld=(g2int *)calloc(ndpts,sizeof(g2int)); - if ( ifld == 0 ) { - fprintf(stderr,"Could not allocate space in jpcunpack.\n Data field NOT upacked.\n"); - return(1); - } - dec_jpeg2000(cpack,len,ifld); - for (j=0;j -#include -#include "grib2.h" - -void misspack(g2float *fld,g2int ndpts,g2int idrsnum,g2int *idrstmpl, - unsigned char *cpack, g2int *lcpack) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: misspack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-06-21 -// -// ABSTRACT: This subroutine packs up a data field using a complex -// packing algorithm as defined in the GRIB2 documention. It -// supports GRIB2 complex packing templates with or without -// spatial differences (i.e. DRTs 5.2 and 5.3). -// It also fills in GRIB2 Data Representation Template 5.2 or 5.3 -// with the appropriate values. -// This version assumes that Missing Value Management is being used and that -// 1 or 2 missing values appear in the data. -// -// PROGRAM HISTORY LOG: -// 2000-06-21 Gilbert -// -// USAGE: misspack(g2float *fld,g2int ndpts,g2int idrsnum,g2int *idrstmpl, -// unsigned char *cpack, g2int *lcpack) -// INPUT ARGUMENT LIST: -// fld[] - Contains the data values to pack -// ndpts - The number of data values in array fld[] -// idrsnum - Data Representation Template number 5.N -// Must equal 2 or 3. -// idrstmpl - Contains the array of values for Data Representation -// Template 5.2 or 5.3 -// [0] = Reference value - ignored on input -// [1] = Binary Scale Factor -// [2] = Decimal Scale Factor -// . -// . -// [6] = Missing value management -// [7] = Primary missing value -// [8] = Secondary missing value -// . -// . -// [16] = Order of Spatial Differencing ( 1 or 2 ) -// . -// . -// -// OUTPUT ARGUMENT LIST: -// idrstmpl - Contains the array of values for Data Representation -// Template 5.3 -// [0] = Reference value - set by misspack routine. -// [1] = Binary Scale Factor - unchanged from input -// [2] = Decimal Scale Factor - unchanged from input -// . -// . -// cpack - The packed data field (character*1 array) -// *lcpack - length of packed field cpack(). -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int *ifld, *ifldmiss, *jfld; - g2int *jmin, *jmax, *lbit; - static g2int zero=0; - g2int *gref, *gwidth, *glen; - g2int glength, grpwidth; - g2int i, n, iofst, imin, ival1, ival2, isd, minsd, nbitsd; - g2int nbitsgref, left, iwmax, ngwidthref, nbitsgwidth, ilmax; - g2int nglenref, nglenlast, nbitsglen, ij; - g2int j, missopt, nonmiss, itemp, maxorig, nbitorig, miss1, miss2; - g2int ngroups, ng, num0, num1, num2; - g2int imax, lg, mtemp, ier, igmax; - g2int kfildo, minpk, inc, maxgrps, ibit, jbit, kbit, novref, lbitref; - g2float rmissp, rmisss, bscale, dscale, rmin, temp; - static g2int simple_alg = 0; - static g2float alog2=0.69314718f; // ln(2.0) - static g2int one=1; - ival1 = 0; - nbitsd = 0; - - (void) ij; - - bscale=(g2float)int_power(2.0,-idrstmpl[1]); - dscale=(g2float)int_power(10.0,idrstmpl[2]); - missopt=idrstmpl[6]; - if ( missopt != 1 && missopt != 2 ) { - printf("misspack: Unrecognized option.\n"); - *lcpack=-1; - return; - } - else { // Get missing values - rdieee(idrstmpl+7,&rmissp,1); - if (missopt == 2) rdieee(idrstmpl+8,&rmisss,1); - } -// -// Find min value of non-missing values in the data, -// AND set up missing value mapping of the field. -// - ifldmiss = calloc(ndpts,sizeof(g2int)); - rmin=1E+37f; - if ( missopt == 1 ) { // Primary missing value only - for ( j=0; j0; j--) - jfld[j]=jfld[j]-jfld[j-1]; - jfld[0]=0; - } - else if (idrstmpl[16] == 2) { // second order - ival1=jfld[0]; - ival2=jfld[1]; - for ( j=nonmiss-1; j>1; j--) - jfld[j]=jfld[j]-(2*jfld[j-1])+jfld[j-2]; - jfld[0]=0; - jfld[1]=0; - } - // - // subtract min value from spatial diff field - // - isd=idrstmpl[16]; - minsd=jfld[isd]; - for ( j=isd; jival1) maxorig=ival2; - temp=(g2float)log((double)(maxorig+1))/alog2; - nbitorig=(g2int)ceil(temp)+1; - if (nbitorig > nbitsd) nbitsd=nbitorig; - // increase number of bits to even multiple of 8 ( octet ) - if ( (nbitsd%8) != 0) nbitsd=nbitsd+(8-(nbitsd%8)); - // - // Store extra spatial differencing info into the packed - // data section. - // - if (nbitsd != 0) { - // pack first original value - if (ival1 >= 0) { - sbit(cpack,&ival1,iofst,nbitsd); - iofst=iofst+nbitsd; - } - else { - sbit(cpack,&one,iofst,1); - iofst=iofst+1; - itemp=abs(ival1); - sbit(cpack,&itemp,iofst,nbitsd-1); - iofst=iofst+nbitsd-1; - } - if (idrstmpl[16] == 2) { - // pack second original value - if (ival2 >= 0) { - sbit(cpack,&ival2,iofst,nbitsd); - iofst=iofst+nbitsd; - } - else { - sbit(cpack,&one,iofst,1); - iofst=iofst+1; - itemp=abs(ival2); - sbit(cpack,&itemp,iofst,nbitsd-1); - iofst=iofst+nbitsd-1; - } - } - // pack overall min of spatial differences - if (minsd >= 0) { - sbit(cpack,&minsd,iofst,nbitsd); - iofst=iofst+nbitsd; - } - else { - sbit(cpack,&one,iofst,1); - iofst=iofst+1; - itemp=abs(minsd); - sbit(cpack,&itemp,iofst,nbitsd-1); - iofst=iofst+nbitsd-1; - } - } - //print *,'SDp ',ival1,ival2,minsd,nbitsd - } // end of spatial diff section - // - // Expand non-missing data values to original grid. - // - miss1=jfld[0]; - for ( j=0; j imax) imax=ifld[j]; - } - j++; - } - if (missopt == 1) imax=imax+1; - if (missopt == 2) imax=imax+2; - // calc num of bits needed to hold data - if ( gref[ng] != imax ) { - temp=(g2float)log((double)(imax-gref[ng]+1))/alog2; - gwidth[ng]=(g2int)ceil(temp); - } - else { - gwidth[ng]=0; - } - } - // Subtract min from data - j=n; - mtemp=(g2int)int_power(2.,gwidth[ng]); - for ( lg=0; lg igmax) igmax=gref[j]; - if (missopt == 1) igmax=igmax+1; - if (missopt == 2) igmax=igmax+2; - if (igmax != 0) { - temp=(g2float)log((double)(igmax+1))/alog2; - nbitsgref=(g2int)ceil(temp); - // reset the ref values of any "missing only" groups. - mtemp=(g2int)int_power(2.,nbitsgref); - for ( j=0; j iwmax) iwmax=gwidth[j]; - if (gwidth[j] < ngwidthref) ngwidthref=gwidth[j]; - } - if (iwmax != ngwidthref) { - temp=(g2float)log((double)(iwmax-ngwidthref+1))/alog2; - nbitsgwidth=(g2int)ceil(temp); - for ( i=0; i ilmax) ilmax=glen[j]; - if (glen[j] < nglenref) nglenref=glen[j]; - } - nglenlast=glen[ngroups-1]; - if (ilmax != nglenref) { - temp=(g2float)log((double)(ilmax-nglenref+1))/alog2; - nbitsglen=(g2int)ceil(temp); - for ( i=0; i -#include -#include "grib2.h" - - -void mkieee(g2float *a,g2int *rieee,g2int num) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: mkieee -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-29 -// -// ABSTRACT: This subroutine stores a list of real values in -// 32-bit IEEE floating point format. -// -// PROGRAM HISTORY LOG: -// 2002-10-29 Gilbert -// -// USAGE: mkieee(g2float *a,g2int *rieee,g2int num); -// INPUT ARGUMENT LIST: -// a - Input array of floating point values. -// num - Number of floating point values to convert. -// -// OUTPUT ARGUMENT LIST: -// rieee - Output array of data values in 32-bit IEEE format -// stored in g2int integer array. rieee must be allocated -// with at least 4*num bytes of memory before calling this -// function. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int j,n,ieee,iexp,imant; - //double alog2,atemp; - double atemp; - - static double two23,two126; - static g2int test=0; - //g2intu msk1=0x80000000; // 10000000000000000000000000000000 binary - //g2int msk2=0x7F800000; // 01111111100000000000000000000000 binary - //g2int msk3=0x007FFFFF; // 00000000011111111111111111111111 binary - - if ( test == 0 ) { - two23=(double)int_power(2.0,23); - two126=(double)int_power(2.0,126); - test=1; - } - - //alog2=0.69314718; // ln(2.0) - - for (j=0;j= 1.0 ) { - n = 0; - while ( int_power(2.0,n+1) <= atemp ) { - n++; - } - } - else { - n = -1; - while ( int_power(2.0,n) > atemp ) { - n--; - } - } - //n=(g2int)floor(log(atemp)/alog2); - iexp=n+127; - if (n > 127) iexp=255; // overflow - if (n < -127) iexp=0; - //printf("exp %ld %ld \n",iexp,n); - // set exponent bits ( bits 30-23 ) - ieee = ieee | ( iexp << 23 ); -// -// Determine Mantissa -// - if (iexp != 255) { - if (iexp != 0) - atemp=(atemp/int_power(2.0,n))-1.0; - else - atemp=atemp*two126; - imant=(g2int)rint(atemp*two23); - } - else { - imant=0; - } - //printf("mant %ld %x \n",imant,imant); - // set mantissa bits ( bits 22-0 ) - ieee = ieee | imant; -// -// Transfer IEEE bit string to rieee array -// - rieee[j]=ieee; - - } - - return; - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/pack_gp.c b/src/plugins/weatherdata/gfs/g2clib/pack_gp.c deleted file mode 100644 index 2eaa00ee5..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/pack_gp.c +++ /dev/null @@ -1,1447 +0,0 @@ -/* pack_gp.f -- translated by f2c (version 20031025). - You must link the resulting object file with libf2c: - on Microsoft Windows system, link with libf2c.lib; - on Linux or Unix systems, link with .../path/to/libf2c.a -lm - or, if you install libf2c.a in a standard place, with -lf2c -lm - -- in that order, at the end of the command line, as in - cc *.o -lf2c -lm - Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., - - http://www.netlib.org/f2c/libf2c.zip -*/ - -/*#include "f2c.h"*/ -#include -#include "grib2.h" -typedef g2int integer; -typedef g2int logical; -#define TRUE_ (1) -#define FALSE_ (0) - -/* Subroutine */ int pack_gp(integer *kfildo, integer *ic, integer *nxy, - integer *is523, integer *minpk, integer *inc, integer *missp, integer - *misss, integer *jmin, integer *jmax, integer *lbit, integer *nov, - integer *ndg, integer *lx, integer *ibit, integer *jbit, integer * - kbit, integer *novref, integer *lbitref, integer *ier) -{ - /* Initialized data */ - - const integer mallow = 1073741825; /* MALLOW=2**30+1 */ - static integer ifeed = 12; - static integer ifirst = 0; - - /* System generated locals */ - integer i__1, i__2, i__3; - - /* Local variables */ - static integer j, k, l; - static logical adda; - static integer ired, kinc, mina, maxa, minb, maxb, minc, maxc, ibxx2[31]; - static char cfeed[1]; - static integer nenda, nendb, ibita, ibitb, minak, minbk, maxak, maxbk, - minck, maxck, nouta, lmiss, itest, nount; - extern /* Subroutine */ int reduce(integer *, integer *, integer *, - integer *, integer *, integer *, integer *, integer *, integer *, - integer *, integer *, integer *, integer *); - static integer ibitbs, mislla, misllb, misllc, iersav, lminpk, ktotal, - kounta, kountb, kstart, mstart, mintst, maxtst, - kounts, mintstk, maxtstk; - integer *misslx; - - -/* FEBRUARY 1994 GLAHN TDL MOS-2000 */ -/* JUNE 1995 GLAHN MODIFIED FOR LMISS ERROR. */ -/* JULY 1996 GLAHN ADDED MISSS */ -/* FEBRUARY 1997 GLAHN REMOVED 4 REDUNDANT TESTS FOR */ -/* MISSP.EQ.0; INSERTED A TEST TO BETTER */ -/* HANDLE A STRING OF 9999'S */ -/* FEBRUARY 1997 GLAHN ADDED LOOPS TO ELIMINATE TEST FOR */ -/* MISSS WHEN MISSS = 0 */ -/* MARCH 1997 GLAHN CORRECTED FOR SECONDARY MISSING VALUE */ -/* MARCH 1997 GLAHN CORRECTED FOR USE OF LOCAL VALUE */ -/* OF MINPK */ -/* MARCH 1997 GLAHN CORRECTED FOR SECONDARY MISSING VALUE */ -/* MARCH 1997 GLAHN CHANGED CALCULATING NUMBER OF BITS */ -/* THROUGH EXPONENTS TO AN ARRAY (IMPROVED */ -/* OVERALL PACKING PERFORMANCE BY ABOUT */ -/* 35 PERCENT!). ALLOWED 0 BITS FOR */ -/* PACKING JMIN( ), LBIT( ), AND NOV( ). */ -/* MAY 1997 GLAHN A NUMBER OF CHANGES FOR EFFICIENCY. */ -/* MOD FUNCTIONS ELIMINATED AND ONE */ -/* IFTHEN ADDED. JOUNT REMOVED. */ -/* RECOMPUTATION OF BITS NOT MADE UNLESS */ -/* NECESSARY AFTER MOVING POINTS FROM */ -/* ONE GROUP TO ANOTHER. NENDB ADJUSTED */ -/* TO ELIMINATE POSSIBILITY OF VERY */ -/* SMALL GROUP AT THE END. */ -/* ABOUT 8 PERCENT IMPROVEMENT IN */ -/* OVERALL PACKING. ISKIPA REMOVED; */ -/* THERE IS ALWAYS A GROUP B THAT CAN */ -/* BECOME GROUP A. CONTROL ON SIZE */ -/* OF GROUP B (STATEMENT BELOW 150) */ -/* ADDED. ADDED ADDA, AND USE */ -/* OF GE AND LE INSTEAD OF GT AND LT */ -/* IN LOOPS BETWEEN 150 AND 160. */ -/* IBITBS ADDED TO SHORTEN TRIPS */ -/* THROUGH LOOP. */ -/* MARCH 2000 GLAHN MODIFIED FOR GRIB2; CHANGED NAME FROM */ -/* PACKGP */ -/* JANUARY 2001 GLAHN COMMENTS; IER = 706 SUBSTITUTED FOR */ -/* STOPS; ADDED RETURN1; REMOVED STATEMENT */ -/* NUMBER 110; ADDED IER AND * RETURN */ -/* NOVEMBER 2001 GLAHN CHANGED SOME DIAGNOSTIC FORMATS TO */ -/* ALLOW PRINTING LARGER NUMBERS */ -/* NOVEMBER 2001 GLAHN ADDED MISSLX( ) TO PUT MAXIMUM VALUE */ -/* INTO JMIN( ) WHEN ALL VALUES MISSING */ -/* TO AGREE WITH GRIB STANDARD. */ -/* NOVEMBER 2001 GLAHN CHANGED TWO TESTS ON MISSP AND MISSS */ -/* EQ 0 TO TESTS ON IS523. HOWEVER, */ -/* MISSP AND MISSS CANNOT IN GENERAL BE */ -/* = 0. */ -/* NOVEMBER 2001 GLAHN ADDED CALL TO REDUCE; DEFINED ITEST */ -/* BEFORE LOOPS TO REDUCE COMPUTATION; */ -/* STARTED LARGE GROUP WHEN ALL SAME */ -/* VALUE */ -/* DECEMBER 2001 GLAHN MODIFIED AND ADDED A FEW COMMENTS */ -/* JANUARY 2002 GLAHN REMOVED LOOP BEFORE 150 TO DETERMINE */ -/* A GROUP OF ALL SAME VALUE */ -/* JANUARY 2002 GLAHN CHANGED MALLOW FROM 9999999 TO 2**30+1, */ -/* AND MADE IT A PARAMETER */ -/* MARCH 2002 GLAHN ADDED NON FATAL IER = 716, 717; */ -/* REMOVED NENDB=NXY ABOVE 150; */ -/* ADDED IERSAV=0; COMMENTS */ - -/* PURPOSE */ -/* DETERMINES GROUPS OF VARIABLE SIZE, BUT AT LEAST OF */ -/* SIZE MINPK, THE ASSOCIATED MAX (JMAX( )) AND MIN (JMIN( )), */ -/* THE NUMBER OF BITS NECESSARY TO HOLD THE VALUES IN EACH */ -/* GROUP (LBIT( )), THE NUMBER OF VALUES IN EACH GROUP */ -/* (NOV( )), THE NUMBER OF BITS NECESSARY TO PACK THE JMIN( ) */ -/* VALUES (IBIT), THE NUMBER OF BITS NECESSARY TO PACK THE */ -/* LBIT( ) VALUES (JBIT), AND THE NUMBER OF BITS NECESSARY */ -/* TO PACK THE NOV( ) VALUES (KBIT). THE ROUTINE IS DESIGNED */ -/* TO DETERMINE THE GROUPS SUCH THAT A SMALL NUMBER OF BITS */ -/* IS NECESSARY TO PACK THE DATA WITHOUT EXCESSIVE */ -/* COMPUTATIONS. IF ALL VALUES IN THE GROUP ARE ZERO, THE */ -/* NUMBER OF BITS TO USE IN PACKING IS DEFINED AS ZERO WHEN */ -/* THERE CAN BE NO MISSING VALUES; WHEN THERE CAN BE MISSING */ -/* VALUES, THE NUMBER OF BITS MUST BE AT LEAST 1 TO HAVE */ -/* THE CAPABILITY TO RECOGNIZE THE MISSING VALUE. HOWEVER, */ -/* IF ALL VALUES IN A GROUP ARE MISSING, THE NUMBER OF BITS */ -/* NEEDED IS 0, AND THE UNPACKER RECOGNIZES THIS. */ -/* ALL VARIABLES ARE INTEGER. EVEN THOUGH THE GROUPS ARE */ -/* INITIALLY OF SIZE MINPK OR LARGER, AN ADJUSTMENT BETWEEN */ -/* TWO GROUPS (THE LOOKBACK PROCEDURE) MAY MAKE A GROUP */ -/* SMALLER THAN MINPK. THE CONTROL ON GROUP SIZE IS THAT */ -/* THE SUM OF THE SIZES OF THE TWO CONSECUTIVE GROUPS, EACH OF */ -/* SIZE MINPK OR LARGER, IS NOT DECREASED. WHEN DETERMINING */ -/* THE NUMBER OF BITS NECESSARY FOR PACKING, THE LARGEST */ -/* VALUE THAT CAN BE ACCOMMODATED IN, SAY, MBITS, IS */ -/* 2**MBITS-1; THIS LARGEST VALUE (AND THE NEXT SMALLEST */ -/* VALUE) IS RESERVED FOR THE MISSING VALUE INDICATOR (ONLY) */ -/* WHEN IS523 NE 0. IF THE DIMENSION NDG */ -/* IS NOT LARGE ENOUGH TO HOLD ALL THE GROUPS, THE LOCAL VALUE */ -/* OF MINPK IS INCREASED BY 50 PERCENT. THIS IS REPEATED */ -/* UNTIL NDG WILL SUFFICE. A DIAGNOSTIC IS PRINTED WHENEVER */ -/* THIS HAPPENS, WHICH SHOULD BE VERY RARELY. IF IT HAPPENS */ -/* OFTEN, NDG IN SUBROUTINE PACK SHOULD BE INCREASED AND */ -/* A CORRESPONDING INCREASE IN SUBROUTINE UNPACK MADE. */ -/* CONSIDERABLE CODE IS PROVIDED SO THAT NO MORE CHECKING */ -/* FOR MISSING VALUES WITHIN LOOPS IS DONE THAN NECESSARY; */ -/* THE ADDED EFFICIENCY OF THIS IS RELATIVELY MINOR, */ -/* BUT DOES NO HARM. FOR GRIB2, THE REFERENCE VALUE FOR */ -/* THE LENGTH OF GROUPS IN NOV( ) AND FOR THE NUMBER OF */ -/* BITS NECESSARY TO PACK GROUP VALUES ARE DETERMINED, */ -/* AND SUBTRACTED BEFORE JBIT AND KBIT ARE DETERMINED. */ - -/* WHEN 1 OR MORE GROUPS ARE LARGE COMPARED TO THE OTHERS, */ -/* THE WIDTH OF ALL GROUPS MUST BE AS LARGE AS THE LARGEST. */ -/* A SUBROUTINE REDUCE BREAKS UP LARGE GROUPS INTO 2 OR */ -/* MORE TO REDUCE TOTAL BITS REQUIRED. IF REDUCE SHOULD */ -/* ABORT, PACK_GP WILL BE EXECUTED AGAIN WITHOUT THE CALL */ -/* TO REDUCE. */ - -/* DATA SET USE */ -/* KFILDO - UNIT NUMBER FOR OUTPUT (PRINT) FILE. (OUTPUT) */ - -/* VARIABLES IN CALL SEQUENCE */ -/* KFILDO = UNIT NUMBER FOR OUTPUT (PRINT) FILE. (INPUT) */ -/* IC( ) = ARRAY TO HOLD DATA FOR PACKING. THE VALUES */ -/* DO NOT HAVE TO BE POSITIVE AT THIS POINT, BUT */ -/* MUST BE IN THE RANGE -2**30 TO +2**30 (THE */ -/* THE VALUE OF MALLOW). THESE INTEGER VALUES */ -/* WILL BE RETAINED EXACTLY THROUGH PACKING AND */ -/* UNPACKING. (INPUT) */ -/* NXY = NUMBER OF VALUES IN IC( ). ALSO TREATED */ -/* AS ITS DIMENSION. (INPUT) */ -/* IS523 = missing value management */ -/* 0=data contains no missing values */ -/* 1=data contains Primary missing values */ -/* 2=data contains Primary and secondary missing values */ -/* (INPUT) */ -/* MINPK = THE MINIMUM SIZE OF EACH GROUP, EXCEPT POSSIBLY */ -/* THE LAST ONE. (INPUT) */ -/* INC = THE NUMBER OF VALUES TO ADD TO AN ALREADY */ -/* EXISTING GROUP IN DETERMINING WHETHER OR NOT */ -/* TO START A NEW GROUP. IDEALLY, THIS WOULD BE */ -/* 1, BUT EACH TIME INC VALUES ARE ATTEMPTED, THE */ -/* MAX AND MIN OF THE NEXT MINPK VALUES MUST BE */ -/* FOUND. THIS IS "A LOOP WITHIN A LOOP," AND */ -/* A SLIGHTLY LARGER VALUE MAY GIVE ABOUT AS GOOD */ -/* RESULTS WITH SLIGHTLY LESS COMPUTATIONAL TIME. */ -/* IF INC IS LE 0, 1 IS USED, AND A DIAGNOSTIC IS */ -/* OUTPUT. NOTE: IT IS EXPECTED THAT INC WILL */ -/* EQUAL 1. THE CODE USES INC PRIMARILY IN THE */ -/* LOOPS STARTING AT STATEMENT 180. IF INC */ -/* WERE 1, THERE WOULD NOT NEED TO BE LOOPS */ -/* AS SUCH. HOWEVER, KINC (THE LOCAL VALUE OF */ -/* INC) IS SET GE 1 WHEN NEAR THE END OF THE DATA */ -/* TO FORESTALL A VERY SMALL GROUP AT THE END. */ -/* (INPUT) */ -/* MISSP = WHEN MISSING POINTS CAN BE PRESENT IN THE DATA, */ -/* THEY WILL HAVE THE VALUE MISSP OR MISSS. */ -/* MISSP IS THE PRIMARY MISSING VALUE AND MISSS */ -/* IS THE SECONDARY MISSING VALUE . THESE MUST */ -/* NOT BE VALUES THAT WOULD OCCUR WITH SUBTRACTING */ -/* THE MINIMUM (REFERENCE) VALUE OR SCALING. */ -/* FOR EXAMPLE, MISSP = 0 WOULD NOT BE ADVISABLE. */ -/* (INPUT) */ -/* MISSS = SECONDARY MISSING VALUE INDICATOR (SEE MISSP). */ -/* (INPUT) */ -/* JMIN(J) = THE MINIMUM OF EACH GROUP (J=1,LX). (OUTPUT) */ -/* JMAX(J) = THE MAXIMUM OF EACH GROUP (J=1,LX). THIS IS */ -/* NOT REALLY NEEDED, BUT SINCE THE MAX OF EACH */ -/* GROUP MUST BE FOUND, SAVING IT HERE IS CHEAP */ -/* IN CASE THE USER WANTS IT. (OUTPUT) */ -/* LBIT(J) = THE NUMBER OF BITS NECESSARY TO PACK EACH GROUP */ -/* (J=1,LX). IT IS ASSUMED THE MINIMUM OF EACH */ -/* GROUP WILL BE REMOVED BEFORE PACKING, AND THE */ -/* VALUES TO PACK WILL, THEREFORE, ALL BE POSITIVE. */ -/* HOWEVER, IC( ) DOES NOT NECESSARILY CONTAIN */ -/* ALL POSITIVE VALUES. IF THE OVERALL MINIMUM */ -/* HAS BEEN REMOVED (THE USUAL CASE), THEN IC( ) */ -/* WILL CONTAIN ONLY POSITIVE VALUES. (OUTPUT) */ -/* NOV(J) = THE NUMBER OF VALUES IN EACH GROUP (J=1,LX). */ -/* (OUTPUT) */ -/* NDG = THE DIMENSION OF JMIN( ), JMAX( ), LBIT( ), AND */ -/* NOV( ). (INPUT) */ -/* LX = THE NUMBER OF GROUPS DETERMINED. (OUTPUT) */ -/* IBIT = THE NUMBER OF BITS NECESSARY TO PACK THE JMIN(J) */ -/* VALUES, J=1,LX. (OUTPUT) */ -/* JBIT = THE NUMBER OF BITS NECESSARY TO PACK THE LBIT(J) */ -/* VALUES, J=1,LX. (OUTPUT) */ -/* KBIT = THE NUMBER OF BITS NECESSARY TO PACK THE NOV(J) */ -/* VALUES, J=1,LX. (OUTPUT) */ -/* NOVREF = REFERENCE VALUE FOR NOV( ). (OUTPUT) */ -/* LBITREF = REFERENCE VALUE FOR LBIT( ). (OUTPUT) */ -/* IER = ERROR RETURN. */ -/* 706 = VALUE WILL NOT PACK IN 30 BITS--FATAL */ -/* 714 = ERROR IN REDUCE--NON-FATAL */ -/* 715 = NGP NOT LARGE ENOUGH IN REDUCE--NON-FATAL */ -/* 716 = MINPK INCEASED--NON-FATAL */ -/* 717 = INC SET = 1--NON-FATAL */ -/* (OUTPUT) */ -/* * = ALTERNATE RETURN WHEN IER NE 0 AND FATAL ERROR. */ - -/* INTERNAL VARIABLES */ -/* CFEED = CONTAINS THE CHARACTER REPRESENTATION */ -/* OF A PRINTER FORM FEED. */ -/* IFEED = CONTAINS THE INTEGER VALUE OF A PRINTER */ -/* FORM FEED. */ -/* KINC = WORKING COPY OF INC. MAY BE MODIFIED. */ -/* MINA = MINIMUM VALUE IN GROUP A. */ -/* MAXA = MAXIMUM VALUE IN GROUP A. */ -/* NENDA = THE PLACE IN IC( ) WHERE GROUP A ENDS. */ -/* KSTART = THE PLACE IN IC( ) WHERE GROUP A STARTS. */ -/* IBITA = NUMBER OF BITS NEEDED TO HOLD VALUES IN GROUP A. */ -/* MINB = MINIMUM VALUE IN GROUP B. */ -/* MAXB = MAXIMUM VALUE IN GROUP B. */ -/* NENDB = THE PLACE IN IC( ) WHERE GROUP B ENDS. */ -/* IBITB = NUMBER OF BITS NEEDED TO HOLD VALUES IN GROUP B. */ -/* MINC = MINIMUM VALUE IN GROUP C. */ -/* MAXC = MAXIMUM VALUE IN GROUP C. */ -/* KTOTAL = COUNT OF NUMBER OF VALUES IN IC( ) PROCESSED. */ -/* NOUNT = NUMBER OF VALUES ADDED TO GROUP A. */ -/* LMISS = 0 WHEN IS523 = 0. WHEN PACKING INTO A */ -/* SPECIFIC NUMBER OF BITS, SAY MBITS, */ -/* THE MAXIMUM VALUE THAT CAN BE HANDLED IS */ -/* 2**MBITS-1. WHEN IS523 = 1, INDICATING */ -/* PRIMARY MISSING VALUES, THIS MAXIMUM VALUE */ -/* IS RESERVED TO HOLD THE PRIMARY MISSING VALUE */ -/* INDICATOR AND LMISS = 1. WHEN IS523 = 2, */ -/* THE VALUE JUST BELOW THE MAXIMUM (I.E., */ -/* 2**MBITS-2) IS RESERVED TO HOLD THE SECONDARY */ -/* MISSING VALUE INDICATOR AND LMISS = 2. */ -/* LMINPK = LOCAL VALUE OF MINPK. THIS WILL BE ADJUSTED */ -/* UPWARD WHENEVER NDG IS NOT LARGE ENOUGH TO HOLD */ -/* ALL THE GROUPS. */ -/* MALLOW = THE LARGEST ALLOWABLE VALUE FOR PACKING. */ -/* MISLLA = SET TO 1 WHEN ALL VALUES IN GROUP A ARE MISSING. */ -/* THIS IS USED TO DISTINGUISH BETWEEN A REAL */ -/* MINIMUM WHEN ALL VALUES ARE NOT MISSING */ -/* AND A MINIMUM THAT HAS BEEN SET TO ZERO WHEN */ -/* ALL VALUES ARE MISSING. 0 OTHERWISE. */ -/* NOTE THAT THIS DOES NOT DISTINGUISH BETWEEN */ -/* PRIMARY AND SECONDARY MISSINGS WHEN SECONDARY */ -/* MISSINGS ARE PRESENT. THIS MEANS THAT */ -/* LBIT( ) WILL NOT BE ZERO WITH THE RESULTING */ -/* COMPRESSION EFFICIENCY WHEN SECONDARY MISSINGS */ -/* ARE PRESENT. ALSO NOTE THAT A CHECK HAS BEEN */ -/* MADE EARLIER TO DETERMINE THAT SECONDARY */ -/* MISSINGS ARE REALLY THERE. */ -/* MISLLB = SET TO 1 WHEN ALL VALUES IN GROUP B ARE MISSING. */ -/* THIS IS USED TO DISTINGUISH BETWEEN A REAL */ -/* MINIMUM WHEN ALL VALUES ARE NOT MISSING */ -/* AND A MINIMUM THAT HAS BEEN SET TO ZERO WHEN */ -/* ALL VALUES ARE MISSING. 0 OTHERWISE. */ -/* MISLLC = PERFORMS THE SAME FUNCTION FOR GROUP C THAT */ -/* MISLLA AND MISLLB DO FOR GROUPS B AND C, */ -/* RESPECTIVELY. */ -/* IBXX2(J) = AN ARRAY THAT WHEN THIS ROUTINE IS FIRST ENTERED */ -/* IS SET TO 2**J, J=0,30. IBXX2(30) = 2**30, WHICH */ -/* IS THE LARGEST VALUE PACKABLE, BECAUSE 2**31 */ -/* IS LARGER THAN THE INTEGER WORD SIZE. */ -/* IFIRST = SET BY DATA STATEMENT TO 0. CHANGED TO 1 ON */ -/* FIRST */ -/* ENTRY WHEN IBXX2( ) IS FILLED. */ -/* MINAK = KEEPS TRACK OF THE LOCATION IN IC( ) WHERE THE */ -/* MINIMUM VALUE IN GROUP A IS LOCATED. */ -/* MAXAK = DOES THE SAME AS MINAK, EXCEPT FOR THE MAXIMUM. */ -/* MINBK = THE SAME AS MINAK FOR GROUP B. */ -/* MAXBK = THE SAME AS MAXAK FOR GROUP B. */ -/* MINCK = THE SAME AS MINAK FOR GROUP C. */ -/* MAXCK = THE SAME AS MAXAK FOR GROUP C. */ -/* ADDA = KEEPS TRACK WHETHER OR NOT AN ATTEMPT TO ADD */ -/* POINTS TO GROUP A WAS MADE. IF SO, THEN ADDA */ -/* KEEPS FROM TRYING TO PUT ONE BACK INTO B. */ -/* (LOGICAL) */ -/* IBITBS = KEEPS CURRENT VALUE IF IBITB SO THAT LOOP */ -/* ENDING AT 166 DOESN'T HAVE TO START AT */ -/* IBITB = 0 EVERY TIME. */ -/* MISSLX(J) = MALLOW EXCEPT WHEN A GROUP IS ALL ONE VALUE (AND */ -/* LBIT(J) = 0) AND THAT VALUE IS MISSING. IN */ -/* THAT CASE, MISSLX(J) IS MISSP OR MISSS. THIS */ -/* GETS INSERTED INTO JMIN(J) LATER AS THE */ -/* MISSING INDICATOR; IT CAN'T BE PUT IN UNTIL */ -/* THE END, BECAUSE JMIN( ) IS USED TO CALCULATE */ -/* THE MAXIMUM NUMBER OF BITS (IBITS) NEEDED TO */ -/* PACK JMIN( ). */ -/* 1 2 3 4 5 6 7 X */ - -/* NON SYSTEM SUBROUTINES CALLED */ -/* NONE */ - - - -/* MISSLX( ) was AN AUTOMATIC ARRAY. */ - misslx = (integer *)calloc(*ndg,sizeof(integer)); - - - /* Parameter adjustments */ - --ic; - --nov; - --lbit; - --jmax; - --jmin; - - /* Function Body */ - - *ier = 0; - iersav = 0; -/* CALL TIMPR(KFILDO,KFILDO,'START PACK_GP ') */ - *(unsigned char *)cfeed = (char) ifeed; - - ired = 0; -/* IRED IS A FLAG. WHEN ZERO, REDUCE WILL BE CALLED. */ -/* IF REDUCE ABORTS, IRED = 1 AND IS NOT CALLED. IN */ -/* THIS CASE PACK_GP EXECUTES AGAIN EXCEPT FOR REDUCE. */ - - if (*inc <= 0) { - iersav = 717; -/* WRITE(KFILDO,101)INC */ -/* 101 FORMAT(/' ****INC ='I8,' NOT CORRECT IN PACK_GP. 1 IS USED.') */ - } - -/* THERE WILL BE A RESTART OF PACK_GP IF SUBROUTINE REDUCE */ -/* ABORTS. THIS SHOULD NOT HAPPEN, BUT IF IT DOES, PACK_GP */ -/* WILL COMPLETE WITHOUT SUBROUTINE REDUCE. A NON FATAL */ -/* DIAGNOSTIC RETURN IS PROVIDED. */ - -L102: - /*kinc = max(*inc,1);*/ - kinc = (*inc > 1) ? *inc : 1; - lminpk = *minpk; - -/* CALCULATE THE POWERS OF 2 THE FIRST TIME ENTERED. */ - - if (ifirst == 0) { - ifirst = 1; - ibxx2[0] = 1; - - for (j = 1; j <= 30; ++j) { - ibxx2[j] = ibxx2[j - 1] << 1; -/* L104: */ - } - - } - -/* THERE WILL BE A RESTART AT 105 IS NDG IS NOT LARGE ENOUGH. */ -/* A NON FATAL DIAGNOSTIC RETURN IS PROVIDED. */ - -L105: - kstart = 1; - ktotal = 0; - *lx = 0; - adda = FALSE_; - lmiss = 0; - if (*is523 == 1) { - lmiss = 1; - } - if (*is523 == 2) { - lmiss = 2; - } - -/* ************************************* */ - -/* THIS SECTION COMPUTES STATISTICS FOR GROUP A. GROUP A IS */ -/* A GROUP OF SIZE LMINPK. */ - -/* ************************************* */ - - ibita = 0; - mina = mallow; - maxa = -mallow; - minak = mallow; - maxak = -mallow; - -/* FIND THE MIN AND MAX OF GROUP A. THIS WILL INITIALLY BE OF */ -/* SIZE LMINPK (IF THERE ARE STILL LMINPK VALUES IN IC( )), BUT */ -/* WILL INCREASE IN SIZE IN INCREMENTS OF INC UNTIL A NEW */ -/* GROUP IS STARTED. THE DEFINITION OF GROUP A IS DONE HERE */ -/* ONLY ONCE (UPON INITIAL ENTRY), BECAUSE A GROUP B CAN ALWAYS */ -/* BECOME A NEW GROUP A AFTER A IS PACKED, EXCEPT IF LMINPK */ -/* HAS TO BE INCREASED BECAUSE NDG IS TOO SMALL. THEREFORE, */ -/* THE SEPARATE LOOPS FOR MISSING AND NON-MISSING HERE BUYS */ -/* ALMOST NOTHING. */ - -/* Computing MIN */ - i__1 = kstart + lminpk - 1; - /*nenda = min(i__1,*nxy);*/ - nenda = (i__1 < *nxy) ? i__1 : *nxy; - if (*nxy - nenda <= lminpk / 2) { - nenda = *nxy; - } -/* ABOVE STATEMENT GUARANTEES THE LAST GROUP IS GT LMINPK/2 BY */ -/* MAKING THE ACTUAL GROUP LARGER. IF A PROVISION LIKE THIS IS */ -/* NOT INCLUDED, THERE WILL MANY TIMES BE A VERY SMALL GROUP */ -/* AT THE END. USE SEPARATE LOOPS FOR MISSING AND NO MISSING */ -/* VALUES FOR EFFICIENCY. */ - -/* DETERMINE WHETHER THERE IS A LONG STRING OF THE SAME VALUE */ -/* UNLESS NENDA = NXY. THIS MAY ALLOW A LARGE GROUP A TO */ -/* START WITH, AS WITH MISSING VALUES. SEPARATE LOOPS FOR */ -/* MISSING OPTIONS. THIS SECTION IS ONLY EXECUTED ONCE, */ -/* IN DETERMINING THE FIRST GROUP. IT HELPS FOR AN ARRAY */ -/* OF MOSTLY MISSING VALUES OR OF ONE VALUE, SUCH AS */ -/* RADAR OR PRECIP DATA. */ - - if (nenda != *nxy && ic[kstart] == ic[kstart + 1]) { -/* NO NEED TO EXECUTE IF FIRST TWO VALUES ARE NOT EQUAL. */ - - if (*is523 == 0) { -/* THIS LOOP IS FOR NO MISSING VALUES. */ - - i__1 = *nxy; - for (k = kstart + 1; k <= i__1; ++k) { - - if (ic[k] != ic[kstart]) { -/* Computing MAX */ - i__2 = nenda, i__3 = k - 1; - /*nenda = max(i__2,i__3);*/ - nenda = (i__2 > i__3) ? i__2 : i__3; - goto L114; - } - -/* L111: */ - } - - nenda = *nxy; -/* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ - - } else if (*is523 == 1) { -/* THIS LOOP IS FOR PRIMARY MISSING VALUES ONLY. */ - - i__1 = *nxy; - for (k = kstart + 1; k <= i__1; ++k) { - - if (ic[k] != *missp) { - - if (ic[k] != ic[kstart]) { -/* Computing MAX */ - i__2 = nenda, i__3 = k - 1; - /*nenda = max(i__2,i__3);*/ - nenda = (i__2 > i__3) ? i__2 : i__3; - goto L114; - } - - } - -/* L112: */ - } - - nenda = *nxy; -/* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ - - } else { -/* THIS LOOP IS FOR PRIMARY AND SECONDARY MISSING VALUES. */ - - i__1 = *nxy; - for (k = kstart + 1; k <= i__1; ++k) { - - if (ic[k] != *missp && ic[k] != *misss) { - - if (ic[k] != ic[kstart]) { -/* Computing MAX */ - i__2 = nenda, i__3 = k - 1; - /*nenda = max(i__2,i__3);*/ - nenda = (i__2 > i__3) ? i__2 : i__3; - goto L114; - } - - } - -/* L113: */ - } - - nenda = *nxy; -/* FALL THROUGH THE LOOP MEANS ALL VALUES ARE THE SAME. */ - } - - } - -L114: - if (*is523 == 0) { - - i__1 = nenda; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] < mina) { - mina = ic[k]; - minak = k; - } - if (ic[k] > maxa) { - maxa = ic[k]; - maxak = k; - } -/* L115: */ - } - - } else if (*is523 == 1) { - - i__1 = nenda; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] == *missp) { - goto L117; - } - if (ic[k] < mina) { - mina = ic[k]; - minak = k; - } - if (ic[k] > maxa) { - maxa = ic[k]; - maxak = k; - } -L117: - ; - } - - } else { - - i__1 = nenda; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] == *missp || ic[k] == *misss) { - goto L120; - } - if (ic[k] < mina) { - mina = ic[k]; - minak = k; - } - if (ic[k] > maxa) { - maxa = ic[k]; - maxak = k; - } -L120: - ; - } - - } - - kounta = nenda - kstart + 1; - -/* INCREMENT KTOTAL AND FIND THE BITS NEEDED TO PACK THE A GROUP. */ - - ktotal += kounta; - mislla = 0; - if (mina != mallow) { - goto L125; - } -/* ALL MISSING VALUES MUST BE ACCOMMODATED. */ - mina = 0; - maxa = 0; - mislla = 1; - ibitb = 0; - if (*is523 != 2) { - goto L130; - } -/* WHEN ALL VALUES ARE MISSING AND THERE ARE NO */ -/* SECONDARY MISSING VALUES, IBITA = 0. */ -/* OTHERWISE, IBITA MUST BE CALCULATED. */ - -L125: - itest = maxa - mina + lmiss; - - for (ibita = 0; ibita <= 30; ++ibita) { - if (itest < ibxx2[ibita]) { - goto L130; - } -/* *** THIS TEST IS THE SAME AS: */ -/* *** IF(MAXA-MINA.LT.IBXX2(IBITA)-LMISS)GO TO 130 */ -/* L126: */ - } - -/* WRITE(KFILDO,127)MAXA,MINA */ -/* 127 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ -/* 1 ' MAXA ='I13,' MINA ='I13,'. ERROR AT 127.') */ - *ier = 706; - goto L900; - -L130: - -/* ***D WRITE(KFILDO,131)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA */ -/* ***D131 FORMAT(' AT 130, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ -/* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3) */ - -L133: - if (ktotal >= *nxy) { - goto L200; - } - -/* ************************************* */ - -/* THIS SECTION COMPUTES STATISTICS FOR GROUP B. GROUP B IS A */ -/* GROUP OF SIZE LMINPK IMMEDIATELY FOLLOWING GROUP A. */ - -/* ************************************* */ - -L140: - minb = mallow; - maxb = -mallow; - minbk = mallow; - maxbk = -mallow; - ibitbs = 0; - mstart = ktotal + 1; - -/* DETERMINE WHETHER THERE IS A LONG STRING OF THE SAME VALUE. */ -/* THIS WORKS WHEN THERE ARE NO MISSING VALUES. */ - - nendb = 1; - - if (mstart < *nxy) { - - if (*is523 == 0) { -/* THIS LOOP IS FOR NO MISSING VALUES. */ - - i__1 = *nxy; - for (k = mstart + 1; k <= i__1; ++k) { - - if (ic[k] != ic[mstart]) { - nendb = k - 1; - goto L150; - } - -/* L145: */ - } - - nendb = *nxy; -/* FALL THROUGH THE LOOP MEANS ALL REMAINING VALUES */ -/* ARE THE SAME. */ - } - - } - -L150: -/* Computing MAX */ -/* Computing MIN */ - i__3 = ktotal + lminpk; - /*i__1 = nendb, i__2 = min(i__3,*nxy);*/ - i__1 = nendb, i__2 = (i__3 < *nxy) ? i__3 : *nxy; - /*nendb = max(i__1,i__2);*/ - nendb = (i__1 > i__2) ? i__1 : i__2; -/* **** 150 NENDB=MIN(KTOTAL+LMINPK,NXY) */ - - if (*nxy - nendb <= lminpk / 2) { - nendb = *nxy; - } -/* ABOVE STATEMENT GUARANTEES THE LAST GROUP IS GT LMINPK/2 BY */ -/* MAKING THE ACTUAL GROUP LARGER. IF A PROVISION LIKE THIS IS */ -/* NOT INCLUDED, THERE WILL MANY TIMES BE A VERY SMALL GROUP */ -/* AT THE END. USE SEPARATE LOOPS FOR MISSING AND NO MISSING */ - -/* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ -/* FOR EFFICIENCY. */ - - if (*is523 == 0) { - - i__1 = nendb; - for (k = mstart; k <= i__1; ++k) { - if (ic[k] <= minb) { - minb = ic[k]; -/* NOTE LE, NOT LT. LT COULD BE USED BUT THEN A */ -/* RECOMPUTE OVER THE WHOLE GROUP WOULD BE NEEDED */ -/* MORE OFTEN. SAME REASONING FOR GE AND OTHER */ -/* LOOPS BELOW. */ - minbk = k; - } - if (ic[k] >= maxb) { - maxb = ic[k]; - maxbk = k; - } -/* L155: */ - } - - } else if (*is523 == 1) { - - i__1 = nendb; - for (k = mstart; k <= i__1; ++k) { - if (ic[k] == *missp) { - goto L157; - } - if (ic[k] <= minb) { - minb = ic[k]; - minbk = k; - } - if (ic[k] >= maxb) { - maxb = ic[k]; - maxbk = k; - } -L157: - ; - } - - } else { - - i__1 = nendb; - for (k = mstart; k <= i__1; ++k) { - if (ic[k] == *missp || ic[k] == *misss) { - goto L160; - } - if (ic[k] <= minb) { - minb = ic[k]; - minbk = k; - } - if (ic[k] >= maxb) { - maxb = ic[k]; - maxbk = k; - } -L160: - ; - } - - } - - kountb = nendb - ktotal; - misllb = 0; - if (minb != mallow) { - goto L165; - } -/* ALL MISSING VALUES MUST BE ACCOMMODATED. */ - minb = 0; - maxb = 0; - misllb = 1; - ibitb = 0; - - if (*is523 != 2) { - goto L170; - } -/* WHEN ALL VALUES ARE MISSING AND THERE ARE NO SECONDARY */ -/* MISSING VALUES, IBITB = 0. OTHERWISE, IBITB MUST BE */ -/* CALCULATED. */ - -L165: - for (ibitb = ibitbs; ibitb <= 30; ++ibitb) { - if (maxb - minb < ibxx2[ibitb] - lmiss) { - goto L170; - } -/* L166: */ - } - -/* WRITE(KFILDO,167)MAXB,MINB */ -/* 167 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ -/* 1 ' MAXB ='I13,' MINB ='I13,'. ERROR AT 167.') */ - *ier = 706; - goto L900; - -/* COMPARE THE BITS NEEDED TO PACK GROUP B WITH THOSE NEEDED */ -/* TO PACK GROUP A. IF IBITB GE IBITA, TRY TO ADD TO GROUP A. */ -/* IF NOT, TRY TO ADD A'S POINTS TO B, UNLESS ADDITION TO A */ -/* HAS BEEN DONE. THIS LATTER IS CONTROLLED WITH ADDA. */ - -L170: - -/* ***D WRITE(KFILDO,171)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA, */ -/* ***D 1 MINB,MAXB,IBITB,MISLLB */ -/* ***D171 FORMAT(' AT 171, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ -/* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3, */ -/* ***D 2 ' MINB ='I8,' MAXB ='I8,' IBITB ='I3,' MISLLB ='I3) */ - - if (ibitb >= ibita) { - goto L180; - } - if (adda) { - goto L200; - } - -/* ************************************* */ - -/* GROUP B REQUIRES LESS BITS THAN GROUP A. PUT AS MANY OF A'S */ -/* POINTS INTO B AS POSSIBLE WITHOUT EXCEEDING THE NUMBER OF */ -/* BITS NECESSARY TO PACK GROUP B. */ - -/* ************************************* */ - - kounts = kounta; -/* KOUNTA REFERS TO THE PRESENT GROUP A. */ - mintst = minb; - maxtst = maxb; - mintstk = minbk; - maxtstk = maxbk; - -/* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ -/* FOR EFFICIENCY. */ - - if (*is523 == 0) { - - i__1 = kstart; - for (k = ktotal; k >= i__1; --k) { -/* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ - if (ic[k] < minb) { - mintst = ic[k]; - mintstk = k; - } else if (ic[k] > maxb) { - maxtst = ic[k]; - maxtstk = k; - } - if (maxtst - mintst >= ibxx2[ibitb]) { - goto L174; - } -/* NOTE THAT FOR THIS LOOP, LMISS = 0. */ - minb = mintst; - maxb = maxtst; - minbk = mintstk; - maxbk = maxtstk; - --kounta; -/* THERE IS ONE LESS POINT NOW IN A. */ -/* L1715: */ - } - - } else if (*is523 == 1) { - - i__1 = kstart; - for (k = ktotal; k >= i__1; --k) { -/* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ - if (ic[k] == *missp) { - goto L1718; - } - if (ic[k] < minb) { - mintst = ic[k]; - mintstk = k; - } else if (ic[k] > maxb) { - maxtst = ic[k]; - maxtstk = k; - } - if (maxtst - mintst >= ibxx2[ibitb] - lmiss) { - goto L174; - } -/* FOR THIS LOOP, LMISS = 1. */ - minb = mintst; - maxb = maxtst; - minbk = mintstk; - maxbk = maxtstk; - misllb = 0; -/* WHEN THE POINT IS NON MISSING, MISLLB SET = 0. */ -L1718: - --kounta; -/* THERE IS ONE LESS POINT NOW IN A. */ -/* L1719: */ - } - - } else { - - i__1 = kstart; - for (k = ktotal; k >= i__1; --k) { -/* START WITH THE END OF THE GROUP AND WORK BACKWARDS. */ - if (ic[k] == *missp || ic[k] == *misss) { - goto L1729; - } - if (ic[k] < minb) { - mintst = ic[k]; - mintstk = k; - } else if (ic[k] > maxb) { - maxtst = ic[k]; - maxtstk = k; - } - if (maxtst - mintst >= ibxx2[ibitb] - lmiss) { - goto L174; - } -/* FOR THIS LOOP, LMISS = 2. */ - minb = mintst; - maxb = maxtst; - minbk = mintstk; - maxbk = maxtstk; - misllb = 0; -/* WHEN THE POINT IS NON MISSING, MISLLB SET = 0. */ -L1729: - --kounta; -/* THERE IS ONE LESS POINT NOW IN A. */ -/* L173: */ - } - - } - -/* AT THIS POINT, KOUNTA CONTAINS THE NUMBER OF POINTS TO CLOSE */ -/* OUT GROUP A WITH. GROUP B NOW STARTS WITH KSTART+KOUNTA AND */ -/* ENDS WITH NENDB. MINB AND MAXB HAVE BEEN ADJUSTED AS */ -/* NECESSARY TO REFLECT GROUP B (EVEN THOUGH THE NUMBER OF BITS */ -/* NEEDED TO PACK GROUP B HAVE NOT INCREASED, THE END POINTS */ -/* OF THE RANGE MAY HAVE). */ - -L174: - if (kounta == kounts) { - goto L200; - } -/* ON TRANSFER, GROUP A WAS NOT CHANGED. CLOSE IT OUT. */ - -/* ONE OR MORE POINTS WERE TAKEN OUT OF A. RANGE AND IBITA */ -/* MAY HAVE TO BE RECOMPUTED; IBITA COULD BE LESS THAN */ -/* ORIGINALLY COMPUTED. IN FACT, GROUP A CAN NOW CONTAIN */ -/* ONLY ONE POINT AND BE PACKED WITH ZERO BITS */ -/* (UNLESS MISSS NE 0). */ - - nouta = kounts - kounta; - ktotal -= nouta; - kountb += nouta; - if (nenda - nouta > minak && nenda - nouta > maxak) { - goto L200; - } -/* WHEN THE ABOVE TEST IS MET, THE MIN AND MAX OF THE */ -/* CURRENT GROUP A WERE WITHIN THE OLD GROUP A, SO THE */ -/* RANGE AND IBITA DO NOT NEED TO BE RECOMPUTED. */ -/* NOTE THAT MINAK AND MAXAK ARE NO LONGER NEEDED. */ - ibita = 0; - mina = mallow; - maxa = -mallow; - -/* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ -/* FOR EFFICIENCY. */ - - if (*is523 == 0) { - - i__1 = nenda - nouta; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] < mina) { - mina = ic[k]; - } - if (ic[k] > maxa) { - maxa = ic[k]; - } -/* L1742: */ - } - - } else if (*is523 == 1) { - - i__1 = nenda - nouta; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] == *missp) { - goto L1744; - } - if (ic[k] < mina) { - mina = ic[k]; - } - if (ic[k] > maxa) { - maxa = ic[k]; - } -L1744: - ; - } - - } else { - - i__1 = nenda - nouta; - for (k = kstart; k <= i__1; ++k) { - if (ic[k] == *missp || ic[k] == *misss) { - goto L175; - } - if (ic[k] < mina) { - mina = ic[k]; - } - if (ic[k] > maxa) { - maxa = ic[k]; - } -L175: - ; - } - - } - - mislla = 0; - if (mina != mallow) { - goto L1750; - } -/* ALL MISSING VALUES MUST BE ACCOMMODATED. */ - mina = 0; - maxa = 0; - mislla = 1; - if (*is523 != 2) { - goto L177; - } -/* WHEN ALL VALUES ARE MISSING AND THERE ARE NO SECONDARY */ -/* MISSING VALUES IBITA = 0 AS ORIGINALLY SET. OTHERWISE, */ -/* IBITA MUST BE CALCULATED. */ - -L1750: - itest = maxa - mina + lmiss; - - for (ibita = 0; ibita <= 30; ++ibita) { - if (itest < ibxx2[ibita]) { - goto L177; - } -/* *** THIS TEST IS THE SAME AS: */ -/* *** IF(MAXA-MINA.LT.IBXX2(IBITA)-LMISS)GO TO 177 */ -/* L176: */ - } - -/* WRITE(KFILDO,1760)MAXA,MINA */ -/* 1760 FORMAT(' ****ERROR IN PACK_GP. VALUE WILL NOT PACK IN 30 BITS.', */ -/* 1 ' MAXA ='I13,' MINA ='I13,'. ERROR AT 1760.') */ - *ier = 706; - goto L900; - -L177: - goto L200; - -/* ************************************* */ - -/* AT THIS POINT, GROUP B REQUIRES AS MANY BITS TO PACK AS GROUPA. */ -/* THEREFORE, TRY TO ADD INC POINTS TO GROUP A WITHOUT INCREASING */ -/* IBITA. THIS AUGMENTED GROUP IS CALLED GROUP C. */ - -/* ************************************* */ - -L180: - if (mislla == 1) { - minc = mallow; - minck = mallow; - maxc = -mallow; - maxck = -mallow; - } else { - minc = mina; - maxc = maxa; - minck = minak; - maxck = minak; - } - - nount = 0; - if (*nxy - (ktotal + kinc) <= lminpk / 2) { - kinc = *nxy - ktotal; - } -/* ABOVE STATEMENT CONSTRAINS THE LAST GROUP TO BE NOT LESS THAN */ -/* LMINPK/2 IN SIZE. IF A PROVISION LIKE THIS IS NOT INCLUDED, */ -/* THERE WILL MANY TIMES BE A VERY SMALL GROUP AT THE END. */ - -/* USE SEPARATE LOOPS FOR MISSING AND NO MISSING VALUES */ -/* FOR EFFICIENCY. SINCE KINC IS USUALLY 1, USING SEPARATE */ -/* LOOPS HERE DOESN'T BUY MUCH. A MISSING VALUE WILL ALWAYS */ -/* TRANSFER BACK TO GROUP A. */ - - if (*is523 == 0) { - -/* Computing MIN */ - i__2 = ktotal + kinc; - /*i__1 = min(i__2,*nxy);*/ - i__1 = (i__2 < *nxy) ? i__2 : *nxy; - for (k = ktotal + 1; k <= i__1; ++k) { - if (ic[k] < minc) { - minc = ic[k]; - minck = k; - } - if (ic[k] > maxc) { - maxc = ic[k]; - maxck = k; - } - ++nount; -/* L185: */ - } - - } else if (*is523 == 1) { - -/* Computing MIN */ - i__2 = ktotal + kinc; - /*i__1 = min(i__2,*nxy);*/ - i__1 = (i__2 < *nxy) ? i__2 : *nxy; - for (k = ktotal + 1; k <= i__1; ++k) { - if (ic[k] == *missp) { - goto L186; - } - if (ic[k] < minc) { - minc = ic[k]; - minck = k; - } - if (ic[k] > maxc) { - maxc = ic[k]; - maxck = k; - } -L186: - ++nount; -/* L187: */ - } - - } else { - -/* Computing MIN */ - i__2 = ktotal + kinc; - /*i__1 = min(i__2,*nxy);*/ - i__1 = (i__2 < *nxy) ? i__2 : *nxy; - for (k = ktotal + 1; k <= i__1; ++k) { - if (ic[k] == *missp || ic[k] == *misss) { - goto L189; - } - if (ic[k] < minc) { - minc = ic[k]; - minck = k; - } - if (ic[k] > maxc) { - maxc = ic[k]; - maxck = k; - } -L189: - ++nount; -/* L190: */ - } - - } - -/* ***D WRITE(KFILDO,191)KOUNTA,KTOTAL,MINA,MAXA,IBITA,MISLLA, */ -/* ***D 1 MINC,MAXC,NOUNT,IC(KTOTAL),IC(KTOTAL+1) */ -/* ***D191 FORMAT(' AT 191, KOUNTA ='I8,' KTOTAL ='I8,' MINA ='I8, */ -/* ***D 1 ' MAXA ='I8,' IBITA ='I3,' MISLLA ='I3, */ -/* ***D 2 ' MINC ='I8,' MAXC ='I8, */ -/* ***D 3 ' NOUNT ='I5,' IC(KTOTAL) ='I9,' IC(KTOTAL+1) =',I9) */ - -/* IF THE NUMBER OF BITS NEEDED FOR GROUP C IS GT IBITA, */ -/* THEN THIS GROUP A IS A GROUP TO PACK. */ - - if (minc == mallow) { - minc = mina; - maxc = maxa; - minck = minak; - maxck = maxak; - misllc = 1; - goto L195; -/* WHEN THE NEW VALUE(S) ARE MISSING, THEY CAN ALWAYS */ -/* BE ADDED. */ - - } else { - misllc = 0; - } - - if (maxc - minc >= ibxx2[ibita] - lmiss) { - goto L200; - } - -/* THE BITS NECESSARY FOR GROUP C HAS NOT INCREASED FROM THE */ -/* BITS NECESSARY FOR GROUP A. ADD THIS POINT(S) TO GROUP A. */ -/* COMPUTE THE NEXT GROUP B, ETC., UNLESS ALL POINTS HAVE BEEN */ -/* USED. */ - -L195: - ktotal += nount; - kounta += nount; - mina = minc; - maxa = maxc; - minak = minck; - maxak = maxck; - mislla = misllc; - adda = TRUE_; - if (ktotal >= *nxy) { - goto L200; - } - - if (minbk > ktotal && maxbk > ktotal) { - mstart = nendb + 1; -/* THE MAX AND MIN OF GROUP B WERE NOT FROM THE POINTS */ -/* REMOVED, SO THE WHOLE GROUP DOES NOT HAVE TO BE LOOKED */ -/* AT TO DETERMINE THE NEW MAX AND MIN. RATHER START */ -/* JUST BEYOND THE OLD NENDB. */ - ibitbs = ibitb; - nendb = 1; - goto L150; - } else { - goto L140; - } - -/* ************************************* */ - -/* GROUP A IS TO BE PACKED. STORE VALUES IN JMIN( ), JMAX( ), */ -/* LBIT( ), AND NOV( ). */ - -/* ************************************* */ - -L200: - ++(*lx); - if (*lx <= *ndg) { - goto L205; - } - lminpk += lminpk / 2; -/* WRITE(KFILDO,201)NDG,LMINPK,LX */ -/* 201 FORMAT(' ****NDG ='I5,' NOT LARGE ENOUGH.', */ -/* 1 ' LMINPK IS INCREASED TO 'I3,' FOR THIS FIELD.'/ */ -/* 2 ' LX = 'I10) */ - iersav = 716; - goto L105; - -L205: - jmin[*lx] = mina; - jmax[*lx] = maxa; - lbit[*lx] = ibita; - nov[*lx] = kounta; - kstart = ktotal + 1; - - if (mislla == 0) { - misslx[*lx - 1] = mallow; - } else { - misslx[*lx - 1] = ic[ktotal]; -/* IC(KTOTAL) WAS THE LAST VALUE PROCESSED. IF MISLLA NE 0, */ -/* THIS MUST BE THE MISSING VALUE FOR THIS GROUP. */ - } - -/* ***D WRITE(KFILDO,206)MISLLA,IC(KTOTAL),KTOTAL,LX,JMIN(LX),JMAX(LX), */ -/* ***D 1 LBIT(LX),NOV(LX),MISSLX(LX) */ -/* ***D206 FORMAT(' AT 206, MISLLA ='I2,' IC(KTOTAL) ='I5,' KTOTAL ='I8, */ -/* ***D 1 ' LX ='I6,' JMIN(LX) ='I8,' JMAX(LX) ='I8, */ -/* ***D 2 ' LBIT(LX) ='I5,' NOV(LX) ='I8,' MISSLX(LX) =',I7) */ - - if (ktotal >= *nxy) { - goto L209; - } - -/* THE NEW GROUP A WILL BE THE PREVIOUS GROUP B. SET LIMITS, ETC. */ - - ibita = ibitb; - mina = minb; - maxa = maxb; - minak = minbk; - maxak = maxbk; - mislla = misllb; - nenda = nendb; - kounta = kountb; - ktotal += kounta; - adda = FALSE_; - goto L133; - -/* ************************************* */ - -/* CALCULATE IBIT, THE NUMBER OF BITS NEEDED TO HOLD THE GROUP */ -/* MINIMUM VALUES. */ - -/* ************************************* */ - -L209: - *ibit = 0; - - i__1 = *lx; - for (l = 1; l <= i__1; ++l) { -L210: - if (jmin[l] < ibxx2[*ibit]) { - goto L220; - } - ++(*ibit); - goto L210; -L220: - ; - } - -/* INSERT THE VALUE IN JMIN( ) TO BE USED FOR ALL MISSING */ -/* VALUES WHEN LBIT( ) = 0. WHEN SECONDARY MISSING */ -/* VALUES CAN BE PRESENT, LBIT(L) WILL NOT = 0. */ - - if (*is523 == 1) { - - i__1 = *lx; - for (l = 1; l <= i__1; ++l) { - - if (lbit[l] == 0) { - - if (misslx[l - 1] == *missp) { - jmin[l] = ibxx2[*ibit] - 1; - } - - } - -/* L226: */ - } - - } - -/* ************************************* */ - -/* CALCULATE JBIT, THE NUMBER OF BITS NEEDED TO HOLD THE BITS */ -/* NEEDED TO PACK THE VALUES IN THE GROUPS. BUT FIND AND */ -/* REMOVE THE REFERENCE VALUE FIRST. */ - -/* ************************************* */ - -/* WRITE(KFILDO,228)CFEED,LX */ -/* 228 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP WIDTHS LBIT( ) FOR ',I8,' GROUPS' */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,229) (LBIT(J),J=1,MIN(LX,100)) */ -/* 229 FORMAT(/' '20I6) */ - - *lbitref = lbit[1]; - - i__1 = *lx; - for (k = 1; k <= i__1; ++k) { - if (lbit[k] < *lbitref) { - *lbitref = lbit[k]; - } -/* L230: */ - } - - if (*lbitref != 0) { - - i__1 = *lx; - for (k = 1; k <= i__1; ++k) { - lbit[k] -= *lbitref; -/* L240: */ - } - - } - -/* WRITE(KFILDO,241)CFEED,LBITREF */ -/* 241 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP WIDTHS LBIT( ) AFTER REMOVING REFERENCE ', */ -/* 2 I8, */ -/* 3 /' *****************************************') */ -/* WRITE(KFILDO,242) (LBIT(J),J=1,MIN(LX,100)) */ -/* 242 FORMAT(/' '20I6) */ - - *jbit = 0; - - i__1 = *lx; - for (k = 1; k <= i__1; ++k) { -L310: - if (lbit[k] < ibxx2[*jbit]) { - goto L320; - } - ++(*jbit); - goto L310; -L320: - ; - } - -/* ************************************* */ - -/* CALCULATE KBIT, THE NUMBER OF BITS NEEDED TO HOLD THE NUMBER */ -/* OF VALUES IN THE GROUPS. BUT FIND AND REMOVE THE */ -/* REFERENCE FIRST. */ - -/* ************************************* */ - -/* WRITE(KFILDO,321)CFEED,LX */ -/* 321 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP SIZES NOV( ) FOR ',I8,' GROUPS' */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,322) (NOV(J),J=1,MIN(LX,100)) */ -/* 322 FORMAT(/' '20I6) */ - - *novref = nov[1]; - - i__1 = *lx; - for (k = 1; k <= i__1; ++k) { - if (nov[k] < *novref) { - *novref = nov[k]; - } -/* L400: */ - } - - if (*novref > 0) { - - i__1 = *lx; - for (k = 1; k <= i__1; ++k) { - nov[k] -= *novref; -/* L405: */ - } - - } - -/* WRITE(KFILDO,406)CFEED,NOVREF */ -/* 406 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP SIZES NOV( ) AFTER REMOVING REFERENCE ',I8, */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,407) (NOV(J),J=1,MIN(LX,100)) */ -/* 407 FORMAT(/' '20I6) */ -/* WRITE(KFILDO,408)CFEED */ -/* 408 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP REFERENCES JMIN( )' */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,409) (JMIN(J),J=1,MIN(LX,100)) */ -/* 409 FORMAT(/' '20I6) */ - - *kbit = 0; - - i__1 = *lx; - for (k = 1; k <= i__1; ++k) { -L410: - if (nov[k] < ibxx2[*kbit]) { - goto L420; - } - ++(*kbit); - goto L410; -L420: - ; - } - -/* DETERMINE WHETHER THE GROUP SIZES SHOULD BE REDUCED */ -/* FOR SPACE EFFICIENCY. */ - - if (ired == 0) { - reduce(kfildo, &jmin[1], &jmax[1], &lbit[1], &nov[1], lx, ndg, ibit, - jbit, kbit, novref, ibxx2, ier); - - if (*ier == 714 || *ier == 715) { -/* REDUCE HAS ABORTED. REEXECUTE PACK_GP WITHOUT REDUCE. */ -/* PROVIDE FOR A NON FATAL RETURN FROM REDUCE. */ - iersav = *ier; - ired = 1; - *ier = 0; - goto L102; - } - - } - - if ( misslx != 0 ) { - free(misslx); - misslx=0; - } -/* CALL TIMPR(KFILDO,KFILDO,'END PACK_GP ') */ - if (iersav != 0) { - *ier = iersav; - return 0; - } - -/* 900 IF(IER.NE.0)RETURN1 */ - -L900: - if ( misslx != 0 ) free(misslx); - return 0; -} /* pack_gp__ */ - diff --git a/src/plugins/weatherdata/gfs/g2clib/pdstemplates.c b/src/plugins/weatherdata/gfs/g2clib/pdstemplates.c deleted file mode 100644 index bd040d921..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/pdstemplates.c +++ /dev/null @@ -1,580 +0,0 @@ -#include -#include "grib2.h" -#include "pdstemplates.h" - -const struct pdstemplate templatespds[MAXPDSTEMP] = { - // 4.0: Analysis or Forecast at Horizontal Level/Layer - // at a point in time - {0,15,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4} }, - // 4.1: Individual Ensemble Forecast at Horizontal Level/Layer - // at a point in time - {1,18,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1} }, - // 4.2: Derived Fcst based on whole Ensemble at Horiz Level/Layer - // at a point in time - {2,17,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1} }, - // 4.3: Derived Fcst based on Ensemble cluster over rectangular - // area at Horiz Level/Layer at a point in time - {3,31,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,1,1,1,1,-4,-4,4,4,1,-1,4,-1,4} }, - // 4.4: Derived Fcst based on Ensemble cluster over circular - // area at Horiz Level/Layer at a point in time - {4,30,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,1,1,1,1,-4,4,4,1,-1,4,-1,4} }, - // 4.5: Probablility Forecast at Horiz Level/Layer - // at a point in time - {5,22,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,-1,-4,-1,-4} }, - // 4.6: Percentile Forecast at Horiz Level/Layer - // at a point in time - {6,16,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1} }, - // 4.7: Analysis or Forecast Error at Horizontal Level/Layer - // at a point in time - {7,15,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4} }, - // 4.8: Ave/Accum/etc... at Horiz Level/Layer - // in a time interval - {8,29,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.9: Probablility Forecast at Horiz Level/Layer - // in a time interval - {9,36,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,-1,-4,-1,-4,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.10: Percentile Forecast at Horiz Level/Layer - // in a time interval - {10,30,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.11: Individual Ensemble Forecast at Horizontal Level/Layer - // in a time interval - {11,32,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.12: Derived Fcst based on whole Ensemble at Horiz Level/Layer - // in a time interval - {12,31,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.13: Derived Fcst based on Ensemble cluster over rectangular - // area at Horiz Level/Layer in a time interval - {13,45,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,1,1,1,1,-4,-4,4,4,1,-1,4,-1,4,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.14: Derived Fcst based on Ensemble cluster over circular - // area at Horiz Level/Layer in a time interval - {14,44,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,1,1,1,1,-4,4,4,1,-1,4,-1,4,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.15: Average, accumulation, extreme values or other statistically-processed values over a - // spatial area at a horizontal level or in a horizontal layer at a point in time - {15,18,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1} }, - // 4.20: Radar Product - {20,19,0, {1,1,1,1,1,-4,4,2,4,2,1,1,1,1,1,2,1,3,2} }, - // 4.30: Satellite Product - {30,5,1, {1,1,1,1,1} }, - // 4.31: Satellite Product - {31,5,1, {1,1,1,1,1} }, - // 4.40: Analysis or forecast at a horizontal level or in a horizontal layer - // at a point in time for atmospheric chemical constituents - {40,16,0, {1,1,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4} }, - // 4.41: Individual ensemble forecast, control and perturbed, at a horizontal level or - // in a horizontal layer at a point in time for atmospheric chemical constituents - {41,19,0, {1,1,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1} }, - // 4.42: Average, accumulation, and/or extreme values or other statistically-processed values - // at a horizontal level or in a horizontal layer in a continuous or non-continuous - // time interval for atmospheric chemical constituents - {42,30,1, {1,1,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.43: Individual ensemble forecast, control and perturbed, at a horizontal level - // or in a horizontal layer in a continuous or non-continuous - // time interval for atmospheric chemical constituents - {43,33,1, {1,1,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.254: CCITT IA5 Character String - {254,3,0, {1,1,4} }, - // 4.1000: Cross section of analysis or forecast - // at a point in time - {1000,9,0, {1,1,1,1,1,2,1,1,4} }, - // 4.1001: Cross section of Ave/Accum/etc... analysis or forecast - // in a time interval - {1001,16,0, {1,1,1,1,1,2,1,1,4,4,1,1,1,4,1,4} }, - // 4.1001: Cross section of Ave/Accum/etc... analysis or forecast - // over latitude or longitude - {1002,15,0, {1,1,1,1,1,2,1,1,4,1,1,1,4,4,2} }, - // 4.1100: Hovmoller-type grid w/ no averaging or other - // statistical processing - {1100,15,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4} }, - // 4.1100: Hovmoller-type grid with averaging or other - // statistical processing - {1101,22,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,4,1,1,1,4,1,4} }, - // 4.32:Simulate (synthetic) Satellite Product - {32,10,1, {1,1,1,1,1,2,1,1,2,1} }, - // 4.44: Analysis or forecast at a horizontal level or in a horizontal layer - // at a point in time for Aerosol - {44,21,0, {1,1,2,1,-1,-4,-1,-4,1,1,1,2,1,1,2,1,-1,-4,1,-1,-4} }, - // 4.45: Individual ensemble forecast, control and - // perturbed, at a horizontal level or in a horizontal layer - // at a point in time for Aerosol - {45,24,0, {1,1,2,1,-1,-4,-1,-4,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1} }, - // 4.46: Ave or Accum or Extreme value at level/layer - // at horizontal level or in a horizontal in a continuous or - // non-continuous time interval for Aerosol - {46,35,1, {1,1,2,1,-1,-4,-1,-4,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - // 4.47: Individual ensemble forecast, control and - // perturbed, at horizontal level or in a horizontal - // in a continuous or non-continuous time interval for Aerosol - {47,38,1, {1,1,1,2,1,-1,-4,-1,-4,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, - - // PDT 4.48 - // 4.48: Analysis or forecast at a horizontal level or in a horizontal layer - // at a point in time for Optical Properties of Aerosol - {48,26,0, {1,1,2,1,-1,-4,-1,-4,1,-1,-4,-1,-4,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4} }, - - // VALIDATION --- PDT 4.50 - // 4.50: Analysis or forecast of multi component parameter or - // matrix element at a point in time - {50,21,0, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,4,4,4,4} }, - - // VALIDATION --- PDT 4.52 - // 4.52: Analysis or forecast of Wave parameters - // at the Sea surface at a point in time - {52,15,0, {1,1,1,1,1,1,1,1,2,1,1,4,1,-1,-4} }, - - // 4.51: Categorical forecasts at a horizontal level or - // in a horizontal layer at a point in time - {51,16,1, {1,1,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1} }, - - // 4.91: Categorical forecasts at a horizontal level or - // in a horizontal layer at a point in time - // in a continuous or non-continuous time interval - {91,36,1, {1,1,2,1,-1,-4,-1,-4,1,-1,-4,-1,-4,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4} }, -// PDT 4.33 (07/29/2013) - // 4.33: Individual ensemble forecast, control, perturbed, - // at a horizontal level or in a horizontal layer - // at a point in time for simulated (synthetic) Satellite data - {33,18,1, {1,1,1,1,1,2,1,1,4,1,2,2,2,-1,-4,1,1,1} }, -// PDT 4.34 (07/29/2013) - // 4.34: Individual ensemble forecast, control, perturbed, - // at a horizontal level or in a horizontal layer,in a continuous or - // non-continuous interval for simulated (synthetic) Satellite data - {34,32,1, {1,1,1,1,1,2,1,1,4,1,2,2,2,-1,-4,1,1,1,2,1,1,1,1,1,1,4,1,1,1,4,1,4} }, -// PDT 4.53 (07/29/2013) - // 4.53: Partitioned parameters at - // horizontal level or horizontal layer - // at a point in time - {53,19,1, {1,1,1,1,4,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4} }, -// PDT 4.54 (07/29/2013) - // 4.54: Individual ensemble forecast, control, perturbed, - // at a horizontal level or in a horizontal layer - // at a point in time for partitioned parameters - {54,22,1, {1,1,1,1,4,2,1,1,1,2,1,1,4,1,-1,-4,1,-1,-4,1,1,1} } - -} ; - -g2int getpdsindex(g2int number) -///$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: getpdsindex -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2001-06-28 -// -// ABSTRACT: This function returns the index of specified Product -// Definition Template 4.NN (NN=number) in array templates. -// -// PROGRAM HISTORY LOG: -// 2001-06-28 Gilbert -// 2009-01-14 Vuong Changed structure name template to gtemplate -// 2009-12-15 Vuong Added Product Definition Template 4.31 -// Added Product Definition Template 4.15 -// 2010-08-03 Vuong Added Product Definition Template 4.42 and 4.43 -// 2010-12-08 Vuong Corrected Product Definition Template 4.42 and 4.43 -// 2012-03-29 Vuong Added Templates 4.44,4.45,4.46,4.47,4.48,4.50, -// 4.51,4.91,4.32 and 4.52 -// 2013-08-05 Vuong Corrected 4.91 and added Templates 4.33,4.34,4.53,4.54 -// -// USAGE: index=getpdsindex(number) -// INPUT ARGUMENT LIST: -// number - NN, indicating the number of the Product Definition -// Template 4.NN that is being requested. -// -// RETURNS: Index of PDT 4.NN in array templates, if template exists. -// = -1, otherwise. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$/ -{ - g2int j,getpdsindex=-1; - - for (j=0;jtype=4; - new->num=templatespds[index].template_num; - new->maplen=templatespds[index].mappdslen; - new->needext=templatespds[index].needext; - new->map=(g2int *)templatespds[index].mappds; - new->extlen=0; - new->ext=0; //NULL - return(new); - } - else { - printf("getpdstemplate: PDS Template 4.%d not defined.\n",(int)number); - return(0); //NULL - } - - return(0); //NULL -} - - -gtemplate *extpdstemplate(g2int number,g2int *list) -///$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: extpdstemplate -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-05-11 -// -// ABSTRACT: This subroutine generates the remaining octet map for a -// given Product Definition Template, if required. Some Templates can -// vary depending on data values given in an earlier part of the -// Template, and it is necessary to know some of the earlier entry -// values to generate the full octet map of the Template. -// -// PROGRAM HISTORY LOG: -// 2000-05-11 Gilbert -// 2009-01-14 Vuong Changed structure name template to gtemplate -// 2009-08-05 Vuong Added Product Definition Template 4.31 -// 2010-08-03 Vuong Added Product Definition Template 4.42 and 4.43 -// 2010-12-08 Vuong Corrected Product Definition Template 4.42 and 4.43 -// 2012-02-15 Vuong Added Templates 4.44,4.45,4.46,4.47,4.48,4.50, -// 4.51,4.91,4.32 and 4.52 -// 2013-08-05 Vuong Corrected 4.91 and added Templates 4.33,4.34,4.53,4.54 -// -// USAGE: CALL extpdstemplate(number,list) -// INPUT ARGUMENT LIST: -// number - NN, indicating the number of the Product Definition -// Template 4.NN that is being requested. -// list() - The list of values for each entry in the -// the Product Definition Template 4.NN. -// -// RETURN VALUE: -// - Pointer to the returned template struct. -// Returns NULL pointer, if template not found. -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - gtemplate *new; - g2int index,i,j,k,l; - - index=getpdsindex(number); - if (index == -1) return(0); - - new=getpdstemplate(number); - - if ( ! new->needext ) return(new); - - if ( number == 3 ) { - new->extlen=list[26]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=1; - } - } - else if ( number == 4 ) { - new->extlen=list[25]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=1; - } - } - else if ( number == 8 ) { - if ( list[21] > 1 ) { - new->extlen=(list[21]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[21];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[23+k]; - } - } - } - } - else if ( number == 9 ) { - if ( list[28] > 1 ) { - new->extlen=(list[28]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[28];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[30+k]; - } - } - } - } - else if ( number == 10 ) { - if ( list[22] > 1 ) { - new->extlen=(list[22]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[22];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[24+k]; - } - } - } - } - else if ( number == 11 ) { - if ( list[24] > 1 ) { - new->extlen=(list[24]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[24];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[26+k]; - } - } - } - } - else if ( number == 12 ) { - if ( list[23] > 1 ) { - new->extlen=(list[23]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[23];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[25+k]; - } - } - } - } - else if ( number == 13 ) { - new->extlen=((list[37]-1)*6)+list[26]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - if ( list[37] > 1 ) { - for (j=2;j<=list[37];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[39+k]; - } - } - } - l=(list[37]-1)*6; - if ( l<0 ) l=0; - for (i=0;iext[l+i]=1; - } - } - else if ( number == 14 ) { - new->extlen=((list[36]-1)*6)+list[25]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - if ( list[36] > 1 ) { - for (j=2;j<=list[36];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[38+k]; - } - } - } - l=(list[36]-1)*6; - if ( l<0 ) l=0; - for (i=0;iext[l+i]=1; - } - } - else if ( number == 30 ) { - new->extlen=list[4]*5; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iext[l]=2; - new->ext[l+1]=2; - new->ext[l+2]=1; - new->ext[l+3]=1; - new->ext[l+4]=4; - } - } - else if ( number == 31 ) { - new->extlen=list[4]*5; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iext[l]=2; - new->ext[l+1]=2; - new->ext[l+2]=2; - new->ext[l+3]=1; - new->ext[l+4]=4; - } - } - else if ( number == 42 ) { - if ( list[22] > 1 ) { - new->extlen=(list[22]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[22];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[24+k]; - } - } - } - } - else if ( number == 43 ) { - if ( list[25] > 1 ) { - new->extlen=(list[25]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[25];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[27+k]; - } - } - } - } - else if ( number == 32 ) { - new->extlen=list[9]*10; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iext[l]=2; - new->ext[l+1]=2; - new->ext[l+2]=2; - new->ext[l+3]=-1; - new->ext[l+4]=-4; - } - } - else if ( number == 46 ) { - if ( list[27] > 1 ) { - new->extlen=(list[27]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[27];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[29+k]; - } - } - } - } - else if ( number == 47 ) { - if ( list[30] > 1 ) { - new->extlen=(list[30]-1)*6; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (j=2;j<=list[30];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[32+k]; - } - } - } - } - else if ( number == 51 ) { - new->extlen=list[15]*11; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iext[l]=1; - new->ext[l+1]=1; - new->ext[l+2]=-1; - new->ext[l+3]=-4; - new->ext[l+4]=-1; - new->ext[l+5]=-4; - } - } - else if ( number == 33 ) { - new->extlen=list[9]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=1; - } - } - else if ( number == 34 ) { - new->extlen=((list[24]-1)*6)+list[9]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - if ( list[24] > 1 ) { - for (j=2;j<=list[24];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[26+k]; - } - } - } - l=(list[24]-1)*6; - if ( l<0 ) l=0; - for (i=0;iext[l+i]=1; - } - } - else if ( number == 53 ) { - new->extlen=list[3]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=1; - } - } - else if ( number == 54 ) { - new->extlen=list[3]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - for (i=0;iextlen;i++) { - new->ext[i]=1; - } - } - else if ( number == 91 ) { - new->extlen=((list[28]-1)*6)+list[15]; - new->ext=(g2int *)malloc(sizeof(g2int)*new->extlen); - if ( list[28] > 1 ) { - for (j=2;j<=list[28];j++) { - l=(j-2)*6; - for (k=0;k<6;k++) { - new->ext[l+k]=new->map[30+k]; - } - } - } - l=(list[29]-1)*6; - if ( l<0 ) l=0; - for (i=0;iext[l+i]=1; - } - } - - return(new); - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/pdstemplates.h b/src/plugins/weatherdata/gfs/g2clib/pdstemplates.h deleted file mode 100644 index 5fe8f8187..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/pdstemplates.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef _pdstemplates_H -#define _pdstemplates_H -#include "grib2.h" - -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-26 -// -// ABSTRACT: This inculde file contains info on all the available -// GRIB2 Product Definition Templates used in Section 4 (PDS). -// The information decribing each template is stored in the -// pdstemplate structure defined below. -// -// Each Template has three parts: The number of entries in the template -// (mappdslen); A map of the template (mappds), which contains the -// number of octets in which to pack each of the template values; and -// a logical value (needext) that indicates whether the Template needs -// to be extended. In some cases the number of entries in a template -// can vary depending upon values specified in the "static" part of -// the template. ( See Template 4.3 as an example ) -// -// NOTE: Array mappds contains the number of octets in which the -// corresponding template values will be stored. A negative value in -// mappds is used to indicate that the corresponding template entry can -// contain negative values. This information is used later when packing -// (or unpacking) the template data values. Negative data values in GRIB -// are stored with the left most bit set to one, and a negative number -// of octets value in mappds[] indicates that this possibility should -// be considered. The number of octets used to store the data value -// in this case would be the absolute value of the negative value in -// mappds[]. -// -// 2005-12-08 Gilbert Allow negative scale factors and limits for -// Templates 4.5 and 4.9 -// 2009-12-15 Vuong Added Product Definition Template 4.31 -// Added Product Definition Template 4.15 -// 2010-08-03 Vuong Added Product Definition Template 4.40,4.41,4.42,4.43 -// 2010-12-08 Vuong Corrected Definition Template 4.42,4.43 -// 2010-12-08 Vuong Corrected Definition Template 4.42,4.43 -// 2012-03-29 Vuong Added Templates 4.44,4.45,4.46,4.47,4.48,4.50, -// 4.51,4.91,4.32 and 4.52 -// 2013-08-05 Vuong Corrected 4.91 and added Templates 4.33,4.34,4.53,4.54 -// -//$$$ - - #define MAXPDSTEMP 43 // maximum number of templates - #define MAXPDSMAPLEN 200 // maximum template map length - - struct pdstemplate - { - g2int template_num; - g2int mappdslen; - g2int needext; - g2int mappds[MAXPDSMAPLEN]; - }; - - extern const struct pdstemplate templatespds[]; - - g2int getpdsindex(g2int number); - -#endif /* _pdstemplates_H */ diff --git a/src/plugins/weatherdata/gfs/g2clib/pngpack.c b/src/plugins/weatherdata/gfs/g2clib/pngpack.c deleted file mode 100644 index f81ee4165..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/pngpack.c +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include -#include "grib2.h" - -int enc_png(char *,g2int ,g2int ,g2int ,char *); - -void pngpack(g2float *fld,g2int width,g2int height,g2int *idrstmpl, - unsigned char *cpack,g2int *lcpack) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: pngpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2003-08-27 -// -// ABSTRACT: This subroutine packs up a data field into PNG image format. -// After the data field is scaled, and the reference value is subtracted out, -// it is treated as a grayscale image and passed to a PNG encoder. -// It also fills in GRIB2 Data Representation Template 5.41 or 5.40010 with -// the appropriate values. -// -// PROGRAM HISTORY LOG: -// 2003-08-27 Gilbert -// -// USAGE: pngpack(g2float *fld,g2int width,g2int height,g2int *idrstmpl, -// unsigned char *cpack,g2int *lcpack); -// INPUT ARGUMENT LIST: -// fld[] - Contains the data values to pack -// width - number of points in the x direction -// height - number of points in the y direction -// idrstmpl - Contains the array of values for Data Representation -// Template 5.41 or 5.40010 -// [0] = Reference value - ignored on input -// [1] = Binary Scale Factor -// [2] = Decimal Scale Factor -// [3] = number of bits for each data value - ignored on input -// [4] = Original field type - currently ignored on input -// Data values assumed to be reals. -// -// OUTPUT ARGUMENT LIST: -// idrstmpl - Contains the array of values for Data Representation -// Template 5.41 or 5.40010 -// [0] = Reference value - set by pngpack routine. -// [1] = Binary Scale Factor - unchanged from input -// [2] = Decimal Scale Factor - unchanged from input -// [3] = Number of bits containing each grayscale pixel value -// [4] = Original field type - currently set = 0 on output. -// Data values assumed to be reals. -// cpack - The packed data field -// lcpack - length of packed field cpack. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - g2int *ifld; - static g2float alog2=0.69314718; // ln(2.0) - g2int j,nbits,imin,imax,maxdif; - g2int ndpts,nbytes; - g2float bscale,dscale,rmax,rmin,temp; - unsigned char *ctemp; - - ifld=0; - ndpts=width*height; - bscale=int_power(2.0,-idrstmpl[1]); - dscale=int_power(10.0,idrstmpl[2]); -// -// Find max and min values in the data -// - rmax=fld[0]; - rmin=fld[0]; - for (j=1;j rmax) rmax=fld[j]; - if (fld[j] < rmin) rmin=fld[j]; - } - maxdif = (g2int)rint( (rmax-rmin)*dscale*bscale ); -// -// If max and min values are not equal, pack up field. -// If they are equal, we have a constant field, and the reference -// value (rmin) is the value for each point in the field and -// set nbits to 0. -// - if (rmin != rmax && maxdif != 0 ) { - ifld=(g2int *)malloc(ndpts*sizeof(g2int)); - // - // Determine which algorithm to use based on user-supplied - // binary scale factor and number of bits. - // - if (idrstmpl[1] == 0) { - // - // No binary scaling and calculate minumum number of - // bits in which the data will fit. - // - imin=(g2int)rint(rmin*dscale); - imax=(g2int)rint(rmax*dscale); - maxdif=imax-imin; - temp=log((double)(maxdif+1))/alog2; - nbits=(g2int)ceil(temp); - rmin=(g2float)imin; - // scale data - for(j=0;j -#include -#include "grib2.h" - -int dec_png(unsigned char *,g2int *,g2int *,char *); - -g2int pngunpack(unsigned char *cpack,g2int len,g2int *idrstmpl,g2int ndpts, - g2float *fld) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: pngunpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2003-08-27 -// -// ABSTRACT: This subroutine unpacks a data field that was packed into a -// PNG image format -// using info from the GRIB2 Data Representation Template 5.41 or 5.40010. -// -// PROGRAM HISTORY LOG: -// 2003-08-27 Gilbert -// -// USAGE: pngunpack(unsigned char *cpack,g2int len,g2int *idrstmpl,g2int ndpts, -// g2float *fld) -// INPUT ARGUMENT LIST: -// cpack - The packed data field (character*1 array) -// len - length of packed field cpack(). -// idrstmpl - Pointer to array of values for Data Representation -// Template 5.41 or 5.40010 -// ndpts - The number of data values to unpack -// -// OUTPUT ARGUMENT LIST: -// fld[] - Contains the unpacked data values -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - - g2int *ifld; - g2int j,nbits,width,height; - g2float ref,bscale,dscale; - unsigned char *ctemp; - - rdieee(idrstmpl+0,&ref,1); - bscale = int_power(2.0,idrstmpl[1]); - dscale = int_power(10.0,-idrstmpl[2]); - nbits = idrstmpl[3]; -// -// if nbits equals 0, we have a constant field where the reference value -// is the data value at each gridpoint -// - if (nbits != 0) { - - ifld=(g2int *)calloc(ndpts,sizeof(g2int)); - ctemp=(unsigned char *)calloc(ndpts*4,1); - if ( ifld == 0 || ctemp == 0) { - fprintf(stderr,"Could not allocate space in jpcunpack.\n Data field NOT upacked.\n"); - if ( ctemp != 0 ) free(ctemp); - if ( ifld != 0 ) free(ifld); - return(1); - } - dec_png(cpack,&width,&height,ctemp); - gbits(ctemp,ifld,0,nbits,0,ndpts); - for (j=0;j>31; - iexp=(rieee[j]&msk2)>>23; - imant=(rieee[j]&msk3); - //printf("SAGieee= %ld %ld %ld\n",isign,iexp,imant); - - sign=1.0; - if (isign == 1) sign=-1.0; - - if ( (iexp > 0) && (iexp < 255) ) { - temp=(g2float)int_power(2.0,(iexp-127)); - a[j]=sign*temp*(1.0f+(two23*(g2float)imant)); - } - else if ( iexp == 0 ) { - if ( imant != 0 ) - a[j]=sign*two126*two23*(g2float)imant; - else - a[j]=sign*0.0f; - - } - else if ( iexp == 255 ) - a[j]=sign*(1E+37f); - - - } - -} diff --git a/src/plugins/weatherdata/gfs/g2clib/reduce.c b/src/plugins/weatherdata/gfs/g2clib/reduce.c deleted file mode 100644 index 5f597e5e1..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/reduce.c +++ /dev/null @@ -1,412 +0,0 @@ -/* reduce.f -- translated by f2c (version 20031025). - You must link the resulting object file with libf2c: - on Microsoft Windows system, link with libf2c.lib; - on Linux or Unix systems, link with .../path/to/libf2c.a -lm - or, if you install libf2c.a in a standard place, with -lf2c -lm - -- in that order, at the end of the command line, as in - cc *.o -lf2c -lm - Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., - - http://www.netlib.org/f2c/libf2c.zip -*/ - -/*#include "f2c.h"*/ -#include -#include "grib2.h" -typedef g2int integer; -typedef g2float real; - -/* Subroutine */ int reduce(integer *kfildo, integer *jmin, integer *jmax, - integer *lbit, integer *nov, integer *lx, integer *ndg, integer *ibit, - integer *jbit, integer *kbit, integer *novref, integer *ibxx2, - integer *ier) -{ - /* Initialized data */ - - static integer ifeed = 12; - - /* System generated locals */ - integer i__1, i__2; - - /* Local variables */ - static integer newboxtp, j, l, m, jj, lxn, left; - static real pimp; - static integer move, novl; - static char cfeed[1]; - static integer nboxj[31], lxnkp, iorigb, ibxx2m1, movmin, - ntotbt[31], ntotpr, newboxt; - integer *newbox, *newboxp; - - (void) kfildo; - (void) nboxj; - -/* NOVEMBER 2001 GLAHN TDL GRIB2 */ -/* MARCH 2002 GLAHN COMMENT IER = 715 */ -/* MARCH 2002 GLAHN MODIFIED TO ACCOMMODATE LX=1 ON ENTRY */ - -/* PURPOSE */ -/* DETERMINES WHETHER THE NUMBER OF GROUPS SHOULD BE */ -/* INCREASED IN ORDER TO REDUCE THE SIZE OF THE LARGE */ -/* GROUPS, AND TO MAKE THAT ADJUSTMENT. BY REDUCING THE */ -/* SIZE OF THE LARGE GROUPS, LESS BITS MAY BE NECESSARY */ -/* FOR PACKING THE GROUP SIZES AND ALL THE INFORMATION */ -/* ABOUT THE GROUPS. */ - -/* THE REFERENCE FOR NOV( ) WAS REMOVED IN THE CALLING */ -/* ROUTINE SO THAT KBIT COULD BE DETERMINED. THIS */ -/* FURNISHES A STARTING POINT FOR THE ITERATIONS IN REDUCE. */ -/* HOWEVER, THE REFERENCE MUST BE CONSIDERED. */ - -/* DATA SET USE */ -/* KFILDO - UNIT NUMBER FOR OUTPUT (PRINT) FILE. (OUTPUT) */ - -/* VARIABLES IN CALL SEQUENCE */ -/* KFILDO = UNIT NUMBER FOR OUTPUT (PRINT) FILE. (INPUT) */ -/* JMIN(J) = THE MINIMUM OF EACH GROUP (J=1,LX). IT IS */ -/* POSSIBLE AFTER SPLITTING THE GROUPS, JMIN( ) */ -/* WILL NOT BE THE MINIMUM OF THE NEW GROUP. */ -/* THIS DOESN'T MATTER; JMIN( ) IS REALLY THE */ -/* GROUP REFERENCE AND DOESN'T HAVE TO BE THE */ -/* SMALLEST VALUE. (INPUT/OUTPUT) */ -/* JMAX(J) = THE MAXIMUM OF EACH GROUP (J=1,LX). */ -/* (INPUT/OUTPUT) */ -/* LBIT(J) = THE NUMBER OF BITS NECESSARY TO PACK EACH GROUP */ -/* (J=1,LX). (INPUT/OUTPUT) */ -/* NOV(J) = THE NUMBER OF VALUES IN EACH GROUP (J=1,LX). */ -/* (INPUT/OUTPUT) */ -/* LX = THE NUMBER OF GROUPS. THIS WILL BE INCREASED */ -/* IF GROUPS ARE SPLIT. (INPUT/OUTPUT) */ -/* NDG = THE DIMENSION OF JMIN( ), JMAX( ), LBIT( ), AND */ -/* NOV( ). (INPUT) */ -/* IBIT = THE NUMBER OF BITS NECESSARY TO PACK THE JMIN(J) */ -/* VALUES, J=1,LX. (INPUT) */ -/* JBIT = THE NUMBER OF BITS NECESSARY TO PACK THE LBIT(J) */ -/* VALUES, J=1,LX. (INPUT) */ -/* KBIT = THE NUMBER OF BITS NECESSARY TO PACK THE NOV(J) */ -/* VALUES, J=1,LX. IF THE GROUPS ARE SPLIT, KBIT */ -/* IS REDUCED. (INPUT/OUTPUT) */ -/* NOVREF = REFERENCE VALUE FOR NOV( ). (INPUT) */ -/* IBXX2(J) = 2**J (J=0,30). (INPUT) */ -/* IER = ERROR RETURN. (OUTPUT) */ -/* 0 = GOOD RETURN. */ -/* 714 = PROBLEM IN ALGORITHM. REDUCE ABORTED. */ -/* 715 = NGP NOT LARGE ENOUGH. REDUCE ABORTED. */ -/* NTOTBT(J) = THE TOTAL BITS USED FOR THE PACKING BITS J */ -/* (J=1,30). (INTERNAL) */ -/* NBOXJ(J) = NEW BOXES NEEDED FOR THE PACKING BITS J */ -/* (J=1,30). (INTERNAL) */ -/* NEWBOX(L) = NUMBER OF NEW BOXES (GROUPS) FOR EACH ORIGINAL */ -/* GROUP (L=1,LX) FOR THE CURRENT J. (AUTOMATIC) */ -/* (INTERNAL) */ -/* NEWBOXP(L) = SAME AS NEWBOX( ) BUT FOR THE PREVIOUS J. */ -/* THIS ELIMINATES RECOMPUTATION. (AUTOMATIC) */ -/* (INTERNAL) */ -/* CFEED = CONTAINS THE CHARACTER REPRESENTATION */ -/* OF A PRINTER FORM FEED. (CHARACTER) (INTERNAL) */ -/* IFEED = CONTAINS THE INTEGER VALUE OF A PRINTER */ -/* FORM FEED. (INTERNAL) */ -/* IORIGB = THE ORIGINAL NUMBER OF BITS NECESSARY */ -/* FOR THE GROUP VALUES. (INTERNAL) */ -/* 1 2 3 4 5 6 7 X */ - -/* NON SYSTEM SUBROUTINES CALLED */ -/* NONE */ - - -/* NEWBOX( ) AND NEWBOXP( ) were AUTOMATIC ARRAYS. */ - newbox = (integer *)calloc(*ndg,sizeof(integer)); - newboxp = (integer *)calloc(*ndg,sizeof(integer)); - - /* Parameter adjustments */ - --nov; - --lbit; - --jmax; - --jmin; - - /* Function Body */ - - *ier = 0; - if (*lx == 1) { - goto L410; - } -/* IF THERE IS ONLY ONE GROUP, RETURN. */ - - *(unsigned char *)cfeed = (char) ifeed; - -/* INITIALIZE NUMBER OF NEW BOXES PER GROUP TO ZERO. */ - - i__1 = *lx; - for (l = 1; l <= i__1; ++l) { - newbox[l - 1] = 0; -/* L110: */ - } - -/* INITIALIZE NUMBER OF TOTAL NEW BOXES PER J TO ZERO. */ - - for (j = 1; j <= 31; ++j) { - ntotbt[j - 1] = 999999999; - nboxj[j - 1] = 0; -/* L112: */ - } - - iorigb = (*ibit + *jbit + *kbit) * *lx; -/* IBIT = BITS TO PACK THE JMIN( ). */ -/* JBIT = BITS TO PACK THE LBIT( ). */ -/* KBIT = BITS TO PACK THE NOV( ). */ -/* LX = NUMBER OF GROUPS. */ - ntotbt[*kbit - 1] = iorigb; -/* THIS IS THE VALUE OF TOTAL BITS FOR THE ORIGINAL LX */ -/* GROUPS, WHICH REQUIRES KBITS TO PACK THE GROUP */ -/* LENGHTS. SETTING THIS HERE MAKES ONE LESS LOOPS */ -/* NECESSARY BELOW. */ - -/* COMPUTE BITS NOW USED FOR THE PARAMETERS DEFINED. */ - -/* DETERMINE OTHER POSSIBILITES BY INCREASING LX AND DECREASING */ -/* NOV( ) WITH VALUES GREATER THAN THRESHOLDS. ASSUME A GROUP IS */ -/* SPLIT INTO 2 OR MORE GROUPS SO THAT KBIT IS REDUCED WITHOUT */ -/* CHANGING IBIT OR JBIT. */ - - jj = 0; - -/* Computing MIN */ - i__1 = 30, i__2 = *kbit - 1; - /*for (j = min(i__1,i__2); j >= 2; --j) {*/ - for (j = (i__1 < i__2) ? i__1 : i__2; j >= 2; --j) { -/* VALUES GE KBIT WILL NOT REQUIRE SPLITS. ONCE THE TOTAL */ -/* BITS START INCREASING WITH DECREASING J, STOP. ALSO, THE */ -/* NUMBER OF BITS REQUIRED IS KNOWN FOR KBITS = NTOTBT(KBIT). */ - - newboxt = 0; - - i__1 = *lx; - for (l = 1; l <= i__1; ++l) { - - if (nov[l] < ibxx2[j]) { - newbox[l - 1] = 0; -/* NO SPLITS OR NEW BOXES. */ - goto L190; - } else { - novl = nov[l]; - - m = (nov[l] - 1) / (ibxx2[j] - 1) + 1; -/* M IS FOUND BY SOLVING THE EQUATION BELOW FOR M: */ -/* (NOV(L)+M-1)/M LT IBXX2(J) */ -/* M GT (NOV(L)-1)/(IBXX2(J)-1) */ -/* SET M = (NOV(L)-1)/(IBXX2(J)-1)+1 */ -L130: - novl = (nov[l] + m - 1) / m; -/* THE +M-1 IS NECESSARY. FOR INSTANCE, 15 WILL FIT */ -/* INTO A BOX 4 BITS WIDE, BUT WON'T DIVIDE INTO */ -/* TWO BOXES 3 BITS WIDE EACH. */ - - if (novl < ibxx2[j]) { - goto L185; - } else { - ++m; -/* *** WRITE(KFILDO,135)L,NOV(L),NOVL,M,J,IBXX2(J) */ -/* *** 135 FORMAT(/' AT 135--L,NOV(L),NOVL,M,J,IBXX2(J)',6I10) */ - goto L130; - } - -/* THE ABOVE DO LOOP WILL NEVER COMPLETE. */ - } - -L185: - newbox[l - 1] = m - 1; - newboxt = newboxt + m - 1; -L190: - ; - } - - nboxj[j - 1] = newboxt; - ntotpr = ntotbt[j]; - ntotbt[j - 1] = (*ibit + *jbit) * (*lx + newboxt) + j * (*lx + - newboxt); - - if (ntotbt[j - 1] >= ntotpr) { - jj = j + 1; -/* THE PLUS IS USED BECAUSE J DECREASES PER ITERATION. */ - goto L250; - } else { - -/* SAVE THE TOTAL NEW BOXES AND NEWBOX( ) IN CASE THIS */ -/* IS THE J TO USE. */ - - newboxtp = newboxt; - - i__1 = *lx; - for (l = 1; l <= i__1; ++l) { - newboxp[l - 1] = newbox[l - 1]; -/* L195: */ - } - -/* WRITE(KFILDO,197)NEWBOXT,IBXX2(J) */ -/* 197 FORMAT(/' *****************************************' */ -/* 1 /' THE NUMBER OF NEWBOXES PER GROUP OF THE TOTAL', */ -/* 2 I10,' FOR GROUP MAXSIZE PLUS 1 ='I10 */ -/* 3 /' *****************************************') */ -/* WRITE(KFILDO,198) (NEWBOX(L),L=1,LX) */ -/* 198 FORMAT(/' '20I6/(' '20I6)) */ - } - -/* 205 WRITE(KFILDO,209)KBIT,IORIGB */ -/* 209 FORMAT(/' ORIGINAL BITS WITH KBIT OF',I5,' =',I10) */ -/* WRITE(KFILDO,210)(N,N=2,10),(IBXX2(N),N=2,10), */ -/* 1 (NTOTBT(N),N=2,10),(NBOXJ(N),N=2,10), */ -/* 2 (N,N=11,20),(IBXX2(N),N=11,20), */ -/* 3 (NTOTBT(N),N=11,20),(NBOXJ(N),N=11,20), */ -/* 4 (N,N=21,30),(IBXX2(N),N=11,20), */ -/* 5 (NTOTBT(N),N=21,30),(NBOXJ(N),N=21,30) */ -/* 210 FORMAT(/' THE TOTAL BYTES FOR MAXIMUM GROUP LENGTHS BY ROW'// */ -/* 1 ' J = THE NUMBER OF BITS PER GROUP LENGTH'/ */ -/* 2 ' IBXX2(J) = THE MAXIMUM GROUP LENGTH PLUS 1 FOR THIS J'/ */ -/* 3 ' NTOTBT(J) = THE TOTAL BITS FOR THIS J'/ */ -/* 4 ' NBOXJ(J) = THE NEW GROUPS FOR THIS J'/ */ -/* 5 4(/10X,9I10)/4(/10I10)/4(/10I10)) */ - -/* L200: */ - } - -L250: - pimp = (iorigb - ntotbt[jj - 1]) / (real) iorigb * 100.f; -/* WRITE(KFILDO,252)PIMP,KBIT,JJ */ -/* 252 FORMAT(/' PERCENT IMPROVEMENT =',F6.1, */ -/* 1 ' BY DECREASING GROUP LENGTHS FROM',I4,' TO',I4,' BITS') */ - if (pimp >= 2.f) { - -/* WRITE(KFILDO,255)CFEED,NEWBOXTP,IBXX2(JJ) */ -/* 255 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE NUMBER OF NEWBOXES PER GROUP OF THE TOTAL', */ -/* 2 I10,' FOR GROUP MAXSIZE PLUS 1 ='I10 */ -/* 2 /' *****************************************') */ -/* WRITE(KFILDO,256) (NEWBOXP(L),L=1,LX) */ -/* 256 FORMAT(/' '20I6) */ - -/* ADJUST GROUP LENGTHS FOR MAXIMUM LENGTH OF JJ BITS. */ -/* THE MIN PER GROUP AND THE NUMBER OF BITS REQUIRED */ -/* PER GROUP ARE NOT CHANGED. THIS MAY MEAN THAT A */ -/* GROUP HAS A MIN (OR REFERENCE) THAT IS NOT ZERO. */ -/* THIS SHOULD NOT MATTER TO THE UNPACKER. */ - - lxnkp = *lx + newboxtp; -/* LXNKP = THE NEW NUMBER OF BOXES */ - - if (lxnkp > *ndg) { -/* DIMENSIONS NOT LARGE ENOUGH. PROBABLY AN ERROR */ -/* OF SOME SORT. ABORT. */ -/* WRITE(KFILDO,257)NDG,LXNPK */ -/* 1 2 3 4 5 6 7 X */ -/* 257 FORMAT(/' DIMENSIONS OF JMIN, ETC. IN REDUCE =',I8, */ -/* 1 ' NOT LARGE ENOUGH FOR THE EXPANDED NUMBER OF', */ -/* 2 ' GROUPS =',I8,'. ABORT REDUCE.') */ - *ier = 715; - goto L410; -/* AN ABORT CAUSES THE CALLING PROGRAM TO REEXECUTE */ -/* WITHOUT CALLING REDUCE. */ - } - - lxn = lxnkp; -/* LXN IS THE NUMBER OF THE BOX IN THE NEW SERIES BEING */ -/* FILLED. IT DECREASES PER ITERATION. */ - ibxx2m1 = ibxx2[jj] - 1; -/* IBXX2M1 IS THE MAXIMUM NUMBER OF VALUES PER GROUP. */ - - for (l = *lx; l >= 1; --l) { - -/* THE VALUES IS NOV( ) REPRESENT THOSE VALUES + NOVREF. */ -/* WHEN VALUES ARE MOVED TO ANOTHER BOX, EACH VALUE */ -/* MOVED TO A NEW BOX REPRESENTS THAT VALUE + NOVREF. */ -/* THIS HAS TO BE CONSIDERED IN MOVING VALUES. */ - - if (newboxp[l - 1] * (ibxx2m1 + *novref) + *novref > nov[l] + * - novref) { -/* IF THE ABOVE TEST IS MET, THEN MOVING IBXX2M1 VALUES */ -/* FOR ALL NEW BOXES WILL LEAVE A NEGATIVE NUMBER FOR */ -/* THE LAST BOX. NOT A TOLERABLE SITUATION. */ - movmin = (nov[l] - newboxp[l - 1] * *novref) / newboxp[l - 1]; - left = nov[l]; -/* LEFT = THE NUMBER OF VALUES TO MOVE FROM THE ORIGINAL */ -/* BOX TO EACH NEW BOX EXCEPT THE LAST. LEFT IS THE */ -/* NUMBER LEFT TO MOVE. */ - } else { - movmin = ibxx2m1; -/* MOVMIN VALUES CAN BE MOVED FOR EACH NEW BOX. */ - left = nov[l]; -/* LEFT IS THE NUMBER OF VALUES LEFT TO MOVE. */ - } - - if (newboxp[l - 1] > 0) { - if ((movmin + *novref) * newboxp[l - 1] + *novref <= nov[l] + - *novref && (movmin + *novref) * (newboxp[l - 1] + 1) - >= nov[l] + *novref) { - goto L288; - } else { -/* ***D WRITE(KFILDO,287)L,MOVMIN,NOVREF,NEWBOXP(L),NOV(L) */ -/* ***D287 FORMAT(/' AT 287 IN REDUCE--L,MOVMIN,NOVREF,', */ -/* ***D 1 'NEWBOXP(L),NOV(L)',5I12 */ -/* ***D 2 ' REDUCE ABORTED.') */ -/* WRITE(KFILDO,2870) */ -/* 2870 FORMAT(/' AN ERROR IN REDUCE ALGORITHM. ABORT REDUCE.') */ - *ier = 714; - goto L410; -/* AN ABORT CAUSES THE CALLING PROGRAM TO REEXECUTE */ -/* WITHOUT CALLING REDUCE. */ - } - - } - -L288: - i__1 = newboxp[l - 1] + 1; - for (j = 1; j <= i__1; ++j) { - /*move = min(movmin,left);*/ - move = (movmin < left) ? movmin : left; - jmin[lxn] = jmin[l]; - jmax[lxn] = jmax[l]; - lbit[lxn] = lbit[l]; - nov[lxn] = move; - --lxn; - left -= move + *novref; -/* THE MOVE OF MOVE VALUES REALLY REPRESENTS A MOVE OF */ -/* MOVE + NOVREF VALUES. */ -/* L290: */ - } - - if (left != -(*novref)) { -/* *** WRITE(KFILDO,292)L,LXN,MOVE,LXNKP,IBXX2(JJ),LEFT,NOV(L), */ -/* *** 1 MOVMIN */ -/* *** 292 FORMAT(' AT 292 IN REDUCE--L,LXN,MOVE,LXNKP,', */ -/* *** 1 'IBXX2(JJ),LEFT,NOV(L),MOVMIN'/8I12) */ - } - -/* L300: */ - } - - *lx = lxnkp; -/* LX IS NOW THE NEW NUMBER OF GROUPS. */ - *kbit = jj; -/* KBIT IS NOW THE NEW NUMBER OF BITS REQUIRED FOR PACKING */ -/* GROUP LENGHTS. */ - } - -/* WRITE(KFILDO,406)CFEED,LX */ -/* 406 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP SIZES NOV( ) AFTER REDUCTION IN SIZE', */ -/* 2 ' FOR'I10,' GROUPS', */ -/* 3 /' *****************************************') */ -/* WRITE(KFILDO,407) (NOV(J),J=1,LX) */ -/* 407 FORMAT(/' '20I6) */ -/* WRITE(KFILDO,408)CFEED,LX */ -/* 408 FORMAT(A1,/' *****************************************' */ -/* 1 /' THE GROUP MINIMA JMIN( ) AFTER REDUCTION IN SIZE', */ -/* 2 ' FOR'I10,' GROUPS', */ -/* 3 /' *****************************************') */ -/* WRITE(KFILDO,409) (JMIN(J),J=1,LX) */ -/* 409 FORMAT(/' '20I6) */ - -L410: - if ( newbox != 0 ) free(newbox); - if ( newboxp != 0 ) free(newboxp); - return 0; -} /* reduce_ */ - diff --git a/src/plugins/weatherdata/gfs/g2clib/seekgb.c b/src/plugins/weatherdata/gfs/g2clib/seekgb.c deleted file mode 100644 index e7f5d8c74..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/seekgb.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include "grib2.h" - -void seekgb(FILE *lugb,g2int iseek,g2int mseek,g2int *lskip,g2int *lgrib) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// -// SUBPROGRAM: seekgb Searches a file for the next GRIB message. -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-28 -// -// ABSTRACT: This subprogram searches a file for the next GRIB Message. -// The search is done starting at byte offset iseek of the file referenced -// by lugb for mseek bytes at a time. -// If found, the starting position and length of the message are returned -// in lskip and lgrib, respectively. -// The search is terminated when an EOF or I/O error is encountered. -// -// PROGRAM HISTORY LOG: -// 2002-10-28 GILBERT Modified from Iredell's skgb subroutine -// 2009-01-16 VUONG Changed lskip to 4 instead of sizof(g2int) -// -// USAGE: seekgb(FILE *lugb,g2int iseek,g2int mseek,int *lskip,int *lgrib) -// INPUT ARGUMENTS: -// lugb - FILE pointer for the file to search. File must be -// opened before this routine is called. -// iseek - number of bytes in the file to skip before search -// mseek - number of bytes to search at a time -// OUTPUT ARGUMENTS: -// lskip - number of bytes to skip from the beggining of the file -// to where the GRIB message starts -// lgrib - number of bytes in message (set to 0, if no message found) -// -// ATTRIBUTES: -// LANGUAGE: C -// -//$$$ -{ - g2int k,k4,ipos,nread,lim,start,vers,lengrib; - int end=0; - unsigned char *cbuf; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *lgrib=0; - cbuf=(unsigned char *)malloc(mseek); - nread=mseek; - ipos=iseek; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// LOOP UNTIL GRIB MESSAGE IS FOUND - - while (*lgrib==0 && nread==mseek) { - -// READ PARTIAL SECTION - - fseek(lugb,ipos,SEEK_SET); - nread=(g2int)fread(cbuf,sizeof(unsigned char),mseek,lugb); - lim=nread-8; - -// LOOK FOR 'GRIB...' IN PARTIAL SECTION - - for (k=0;k -#include -#include "grib2.h" - - -void simpack(g2float *fld,g2int ndpts,g2int *idrstmpl,unsigned char *cpack,g2int *lcpack) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: simpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-11-06 -// -// ABSTRACT: This subroutine packs up a data field using the simple -// packing algorithm as defined in the GRIB2 documention. It -// also fills in GRIB2 Data Representation Template 5.0 with the -// appropriate values. -// -// PROGRAM HISTORY LOG: -// 2002-11-06 Gilbert -// -// USAGE: CALL simpack(fld,ndpts,idrstmpl,cpack,lcpack) -// INPUT ARGUMENT LIST: -// fld[] - Contains the data values to pack -// ndpts - The number of data values in array fld[] -// idrstmpl - Contains the array of values for Data Representation -// Template 5.0 -// [0] = Reference value - ignored on input -// [1] = Binary Scale Factor -// [2] = Decimal Scale Factor -// [3] = Number of bits used to pack data, if value is -// > 0 and <= 31. -// If this input value is 0 or outside above range -// then the num of bits is calculated based on given -// data and scale factors. -// [4] = Original field type - currently ignored on input -// Data values assumed to be reals. -// -// OUTPUT ARGUMENT LIST: -// idrstmpl - Contains the array of values for Data Representation -// Template 5.0 -// [0] = Reference value - set by simpack routine. -// [1] = Binary Scale Factor - unchanged from input -// [2] = Decimal Scale Factor - unchanged from input -// [3] = Number of bits used to pack data, unchanged from -// input if value is between 0 and 31. -// If this input value is 0 or outside above range -// then the num of bits is calculated based on given -// data and scale factors. -// [4] = Original field type - currently set = 0 on output. -// Data values assumed to be reals. -// cpack - The packed data field -// lcpack - length of packed field starting at cpack. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - static g2int zero=0; - g2int *ifld; - g2int j,nbits,imin,imax,maxdif,nbittot,left; - g2float bscale,dscale,rmax,rmin,temp; - double maxnum; - static g2float alog2=0.69314718f; // ln(2.0) - - bscale=(g2float)int_power(2.0,-idrstmpl[1]); - dscale=(g2float)int_power(10.0,idrstmpl[2]); - if (idrstmpl[3] <= 0 || idrstmpl[3] > 31) - nbits=0; - else - nbits=idrstmpl[3]; -// -// Find max and min values in the data -// - rmax=fld[0]; - rmin=fld[0]; - for (j=1;j rmax) rmax=fld[j]; - if (fld[j] < rmin) rmin=fld[j]; - } - - ifld=calloc(ndpts,sizeof(g2int)); -// -// If max and min values are not equal, pack up field. -// If they are equal, we have a constant field, and the reference -// value (rmin) is the value for each point in the field and -// set nbits to 0. -// - if (rmin != rmax) { - // - // Determine which algorithm to use based on user-supplied - // binary scale factor and number of bits. - // - if (nbits==0 && idrstmpl[1]==0) { - // - // No binary scaling and calculate minumum number of - // bits in which the data will fit. - // - imin=(g2int)rint(rmin*dscale); - imax=(g2int)rint(rmax*dscale); - maxdif=imax-imin; - temp=(g2float)log((double)(maxdif+1))/alog2; - nbits=(g2int)ceil(temp); - rmin=(g2float)imin; - // scale data - for(j=0;j -#include -#include "grib2.h" - - -g2int simunpack(unsigned char *cpack,g2int *idrstmpl,g2int ndpts,g2float *fld) -////$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: simunpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-10-29 -// -// ABSTRACT: This subroutine unpacks a data field that was packed using a -// simple packing algorithm as defined in the GRIB2 documention, -// using info from the GRIB2 Data Representation Template 5.0. -// -// PROGRAM HISTORY LOG: -// 2002-10-29 Gilbert -// -// USAGE: int simunpack(unsigned char *cpack,g2int *idrstmpl,g2int ndpts, -// g2float *fld) -// INPUT ARGUMENT LIST: -// cpack - pointer to the packed data field. -// idrstmpl - pointer to the array of values for Data Representation -// Template 5.0 -// ndpts - The number of data values to unpack -// -// OUTPUT ARGUMENT LIST: -// fld - Contains the unpacked data values. fld must be allocated -// with at least ndpts*sizeof(g2float) bytes before -// calling this routine. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$// -{ - - g2int *ifld; - g2int j,nbits; - g2float ref,bscale,dscale; - - rdieee(idrstmpl+0,&ref,1); - bscale = (g2float)int_power(2.0,idrstmpl[1]); - dscale = (g2float)int_power(10.0,-idrstmpl[2]); - nbits = idrstmpl[3]; - - ifld=(g2int *)calloc((ndpts ? ndpts : 1),sizeof(g2int)); - if ( ifld == 0 ) { - fprintf(stderr,"Could not allocate space in simunpack.\n Data field NOT upacked.\n"); - return(1); - } - -// -// if nbits equals 0, we have a constant field where the reference value -// is the data value at each gridpoint -// - if (nbits != 0) { - gbits(cpack,ifld,0,nbits,0,ndpts); - for (j=0;j -#include -#include -#include "grib2.h" - - -void specpack(g2float *fld,g2int ndpts,g2int JJ,g2int KK,g2int MM, - g2int *idrstmpl,unsigned char *cpack,g2int *lcpack) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: specpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-19 -// -// ABSTRACT: This subroutine packs a spectral data field using the complex -// packing algorithm for spherical harmonic data as -// defined in the GRIB2 Data Representation Template 5.51. -// -// PROGRAM HISTORY LOG: -// 2002-12-19 Gilbert -// -// USAGE: void specpack(g2float *fld,g2int ndpts,g2int JJ,g2int KK,g2int MM, -// g2int *idrstmpl,insigned char *cpack,g2int *lcpack) -// INPUT ARGUMENT LIST: -// fld[] - Contains the packed data values -// ndpts - The number of data values to pack -// JJ - J - pentagonal resolution parameter -// KK - K - pentagonal resolution parameter -// MM - M - pentagonal resolution parameter -// idrstmpl - Contains the array of values for Data Representation -// Template 5.51 -// -// OUTPUT ARGUMENT LIST: -// cpack - The packed data field (character*1 array) -// lcpack - length of packed field cpack(). -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: IBM SP -// -//$$$ -{ - - g2int *ifld,tmplsim[5]; - g2float *unpk,*tfld; - g2float *pscale,tscale; - g2int Js,Ks,Ms,Ts,Ns,inc,incu,incp,n,Nm,m,ipos; - - int_power(2.0,-idrstmpl[1]); - int_power(10.0,idrstmpl[2]); - - Js=idrstmpl[5]; - Ks=idrstmpl[6]; - Ms=idrstmpl[7]; - Ts=idrstmpl[8]; - -// -// Calculate Laplacian scaling factors for each possible wave number. -// - pscale=(g2float *)malloc((JJ+MM)*sizeof(g2float)); - tscale=(g2float)idrstmpl[4]*1E-6f; - for (n=Js;n<=JJ+MM;n++) - pscale[n]=(g2float)pow((g2float)(n*(n+1)),tscale); -// -// Separate spectral coeffs into two lists; one to contain unpacked -// values within the sub-spectrum Js, Ks, Ms, and the other with values -// outside of the sub-spectrum to be packed. -// - tfld=(g2float *)malloc(ndpts*sizeof(g2float)); - unpk=(g2float *)malloc(ndpts*sizeof(g2float)); - ifld=(g2int *)malloc(ndpts*sizeof(g2int)); - inc=0; - incu=0; - incp=0; - for (m=0;m<=MM;m++) { - Nm=JJ; // triangular or trapezoidal - if ( KK == JJ+MM ) Nm=JJ+m; // rhombodial - Ns=Js; // triangular or trapezoidal - if ( Ks == Js+Ms ) Ns=Js+m; // rhombodial - for (n=m;n<=Nm;n++) { - if (n<=Ns && m<=Ms) { // save unpacked value - unpk[incu++]=fld[inc++]; // real part - unpk[incu++]=fld[inc++]; // imaginary part - } - else { // Save value to be packed and scale - // Laplacian scale factor - tfld[incp++]=fld[inc++]*pscale[n]; // real part - tfld[incp++]=fld[inc++]*pscale[n]; // imaginary part - } - } - } - - free(pscale); - - if (incu != Ts) { - printf("specpack: Incorrect number of unpacked values %d given:\n",(int)Ts); - printf("specpack: Resetting idrstmpl[8] to %d\n",(int)incu); - Ts=incu; - } -// -// Add unpacked values to the packed data array in 32-bit IEEE format -// - mkieee(unpk,(g2int *)cpack,Ts); - ipos=4*Ts; -// -// Scale and pack the rest of the coefficients -// - tmplsim[1]=idrstmpl[1]; - tmplsim[2]=idrstmpl[2]; - tmplsim[3]=idrstmpl[3]; - simpack(tfld,ndpts-Ts,tmplsim,cpack+ipos,lcpack); - *lcpack=(*lcpack)+ipos; -// -// Fill in Template 5.51 -// - idrstmpl[0]=tmplsim[0]; - idrstmpl[1]=tmplsim[1]; - idrstmpl[2]=tmplsim[2]; - idrstmpl[3]=tmplsim[3]; - idrstmpl[8]=Ts; - idrstmpl[9]=1; // Unpacked spectral data is 32-bit IEEE - - free(tfld); - free(unpk); - free(ifld); - - return; -} diff --git a/src/plugins/weatherdata/gfs/g2clib/specunpack.c b/src/plugins/weatherdata/gfs/g2clib/specunpack.c deleted file mode 100644 index e0840040c..000000000 --- a/src/plugins/weatherdata/gfs/g2clib/specunpack.c +++ /dev/null @@ -1,115 +0,0 @@ -#include -#include -#include -#include "grib2.h" - - -g2int specunpack(unsigned char *cpack,g2int *idrstmpl,g2int ndpts,g2int JJ, - g2int KK, g2int MM, g2float *fld) -//$$$ SUBPROGRAM DOCUMENTATION BLOCK -// . . . . -// SUBPROGRAM: specunpack -// PRGMMR: Gilbert ORG: W/NP11 DATE: 2000-06-21 -// -// ABSTRACT: This subroutine unpacks a spectral data field that was packed -// using the complex packing algorithm for spherical harmonic data as -// defined in the GRIB2 documention, -// using info from the GRIB2 Data Representation Template 5.51. -// -// PROGRAM HISTORY LOG: -// 2000-06-21 Gilbert -// -// USAGE: int specunpack(unsigned char *cpack,g2int *idrstmpl, -// g2int ndpts,g2int JJ,g2int KK,g2int MM,g2float *fld) -// INPUT ARGUMENT LIST: -// cpack - pointer to the packed data field. -// idrstmpl - pointer to the array of values for Data Representation -// Template 5.51 -// ndpts - The number of data values to unpack (real and imaginary parts) -// JJ - J - pentagonal resolution parameter -// KK - K - pentagonal resolution parameter -// MM - M - pentagonal resolution parameter -// -// OUTPUT ARGUMENT LIST: -// fld() - Contains the unpacked data values. fld must be allocated -// with at least ndpts*sizeof(g2float) bytes before -// calling this routine. -// -// REMARKS: None -// -// ATTRIBUTES: -// LANGUAGE: C -// MACHINE: -// -//$$$ -{ - - g2int *ifld,j,iofst,nbits; - g2float ref,bscale,dscale,*unpk; - g2float *pscale,tscale; - g2int Js,Ks,Ms,Ts,Ns,Nm,n,m; - g2int inc,incu,incp; - - rdieee(idrstmpl+0,&ref,1); - bscale = (g2float)int_power(2.0,idrstmpl[1]); - dscale = (g2float)int_power(10.0,-idrstmpl[2]); - nbits = idrstmpl[3]; - Js=idrstmpl[5]; - Ks=idrstmpl[6]; - Ms=idrstmpl[7]; - Ts=idrstmpl[8]; - - if (idrstmpl[9] == 1) { // unpacked floats are 32-bit IEEE - - unpk=(g2float *)malloc(ndpts*sizeof(g2float)); - ifld=(g2int *)malloc(ndpts*sizeof(g2int)); - - gbits(cpack,ifld,0,32,0,Ts); - iofst=32*Ts; - rdieee(ifld,unpk,Ts); // read IEEE unpacked floats - gbits(cpack,ifld,iofst,nbits,0,ndpts-Ts); // unpack scaled data -// -// Calculate Laplacian scaling factors for each possible wave number. -// - pscale=(g2float *)malloc((JJ+MM+1)*sizeof(g2float)); - tscale=(g2float)idrstmpl[4]*1E-6f; - for (n=Js;n<=JJ+MM;n++) - pscale[n]=(g2float)pow((g2float)(n*(n+1)),-tscale); -// -// Assemble spectral coeffs back to original order. -// - inc=0; - incu=0; - incp=0; - for (m=0;m<=MM;m++) { - Nm=JJ; // triangular or trapezoidal - if ( KK == JJ+MM ) Nm=JJ+m; // rhombodial - Ns=Js; // triangular or trapezoidal - if ( Ks == Js+Ms ) Ns=Js+m; // rhombodial - for (n=m;n<=Nm;n++) { - if (n<=Ns && m<=Ms) { // grab unpacked value - fld[inc++]=unpk[incu++]; // real part - fld[inc++]=unpk[incu++]; // imaginary part - } - else { // Calc coeff from packed value - fld[inc++]=(((g2float)ifld[incp++]*bscale)+ref)* - dscale*pscale[n]; // real part - fld[inc++]=(((g2float)ifld[incp++]*bscale)+ref)* - dscale*pscale[n]; // imaginary part - } - } - } - - free(pscale); - free(unpk); - free(ifld); - - } - else { - printf("specunpack: Cannot handle 64 or 128-bit floats.\n"); - for (j=0;j -#include -#include -#include -#include - -using namespace BlackConfig; -using namespace BlackMisc; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::Geo; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Weather; -using namespace BlackMisc::Math; -using namespace BlackMisc::Network; - -namespace BlackWxPlugin::Gfs -{ - //! \cond PRIVATE - enum Grib2CloudLevel - { - LowCloud, - MiddleCloud, - HighCloud - }; - - enum Grib2ParameterCode - { - UNKNOWN, - TMP, - RH, - UGRD, - VGRD, - PRATE, - PRES, - PRMSL, - TCDC, - CRAIN, - CSNOW - }; - - enum Grib2FixedSurfaceTypes - { - GroundOrWaterSurface = 1, - IsobaricSurface = 100, - MeanSeaLevel = 101, - LowCloudBottomLevel = 212, - LowCloudTopLevel = 213, - LowCloudLayer = 214, - MiddleCloudBottomLevel = 222, - MiddleCloudTopLevel = 223, - MiddleCloudLayer = 224, - HighCloudBottomLevel = 232, - HighCloudTopLevel = 233, - HighCloudLayer = 234 - }; - - struct Grib2ParameterValue - { - Grib2ParameterValue() = default; - Grib2ParameterValue(Grib2ParameterCode code_, const QString &name_, const QString &unit_) : code(code_), name(name_), unit(unit_) {} - Grib2ParameterCode code = UNKNOWN; - QString name; - QString unit; - }; - - struct GfsIsobaricLayer - { - float temperature = 0.0; - float relativeHumidity = 0.0; - float windU = 0.0; - float windV = 0.0; - }; - - inline bool operator==(const GfsIsobaricLayer &lhs, const GfsIsobaricLayer &rhs) - { - return qFuzzyCompare(lhs.temperature, rhs.temperature) && - qFuzzyCompare(lhs.relativeHumidity, rhs.relativeHumidity) && - qFuzzyCompare(lhs.windU, rhs.windU) && - qFuzzyCompare(lhs.windV, rhs.windV); - } - - struct GfsCloudLayer - { - float bottomLevelPressure = 0.0; - float topLevelPressure = 0.0; - float totalCoverage = 0.0; - float topLevelTemperature = 0.0; - }; - - struct GfsGridPoint - { - float latitude = 0.0; - float longitude = 0.0; - int fieldPosition = 0; - QHash cloudLayers; - QHash isobaricLayers; - float surfaceRain = 0; - float surfaceSnow = 0; - float surfacePrecipitationRate = 0; - float pressureAtMsl = 0.0; - }; - //! \endcond - - const CWeatherDataGfs::Grib2ParameterTable CWeatherDataGfs::m_grib2ParameterTable { - { { { 0, 0 } }, { TMP, "Temperature", "K" } }, - { { { 1, 1 } }, { RH, "Relative Humidity", "%" } }, - { { { 1, 7 } }, { PRATE, "Precipitation Rate", "kg m-2 s-1" } }, - { { { 1, 192 } }, { CRAIN, "Categorical Rain", "-" } }, - { { { 1, 195 } }, { CSNOW, "Categorical Snow", "-" } }, - { { { 2, 2 } }, { UGRD, "U-Component of Wind", "m s-1" } }, - { { { 2, 3 } }, { VGRD, "V-Component of Wind", "m s-1" } }, - { { { 3, 0 } }, { PRES, "Pressure", "Pa" } }, - { { { 3, 1 } }, { PRMSL, "Pressure Reduced to MSL", "Pa" } }, - { { { 6, 1 } }, { TCDC, "Total Cloud Cover", "%" } }, - }; - - // https://physics.stackexchange.com/questions/333475/how-to-calculate-altitude-from-current-temperature-and-pressure - double calculateAltitudeFt(float seaLevelPressurePa, float atmosphericPressurePa, float temperatureK) - { - double altitude = (std::pow(seaLevelPressurePa / atmosphericPressurePa, 0.19022) - 1) * temperatureK * 3.28084 / 0.0065; - return altitude; - } - - CWeatherDataGfs::CWeatherDataGfs(QObject *parent) : IWeatherData(parent) - {} - - CWeatherDataGfs::~CWeatherDataGfs() - { - if (m_parseGribFileWorker && !m_parseGribFileWorker->isFinished()) { m_parseGribFileWorker->abandonAndWait(); } - } - - void CWeatherDataGfs::fetchWeatherData(const CWeatherGrid &initialGrid, const CLength &range) - { - if (!sApp || sApp->isShuttingDown()) { return; } - m_grid = initialGrid; - m_maxRange = range; - if (m_gribData.isEmpty()) - { - const QUrl url = getDownloadUrl().toQUrl(); - CLogMessage(this).debug() << "Started to download GFS data from" << url.toString(); - QNetworkRequest request(url); - sApp->getFromNetwork(request, { this, &CWeatherDataGfs::parseGfsFile }); - } - else - { - CLogMessage(this).debug() << "Using cached data"; - Q_ASSERT_X(!m_parseGribFileWorker, Q_FUNC_INFO, "Worker already running"); - m_parseGribFileWorker = CWorker::fromTask(this, "parseGribFile", [this]() { - parseGfsFileImpl(m_gribData); - }); - m_parseGribFileWorker->then(this, &CWeatherDataGfs::fetchingWeatherDataFinished); - } - } - - void CWeatherDataGfs::fetchWeatherDataFromFile(const QString &filePath, const CWeatherGrid &grid, const CLength &range) - { - m_grid = grid; - m_maxRange = range; - - QFile file(filePath); - if (!file.exists() || !file.open(QIODevice::ReadOnly)) { return; } - m_gribData = file.readAll(); - - Q_ASSERT_X(!m_parseGribFileWorker, Q_FUNC_INFO, "Worker already running"); - m_parseGribFileWorker = CWorker::fromTask(this, "parseGribFile", [this]() { - parseGfsFileImpl(m_gribData); - }); - m_parseGribFileWorker->then(this, &CWeatherDataGfs::fetchingWeatherDataFinished); - } - - CWeatherGrid CWeatherDataGfs::getWeatherData() const - { - QReadLocker l(&m_lockData); - return m_weatherGrid; - } - - void CWeatherDataGfs::fetchingWeatherDataFinished() - { - // If the worker is not destroyed yet, try again in 10 ms. - if (m_parseGribFileWorker) - { - QPointer myself(this); - QTimer::singleShot(25, this, [=] { - // try again until finished - if (!myself) { return; } - myself->fetchingWeatherDataFinished(); - }); - } - else - { - emit fetchingFinished(); - } - } - - void CWeatherDataGfs::parseGfsFile(QNetworkReply *nwReplyPtr) - { - // wrap pointer, make sure any exit cleans up reply - // required to use delete later as object is created in a different thread - QScopedPointer nwReply(nwReplyPtr); - - m_gribData = nwReply->readAll(); - Q_ASSERT_X(!m_parseGribFileWorker, Q_FUNC_INFO, "Worker already running"); - m_parseGribFileWorker = CWorker::fromTask(this, "parseGribFile", [this]() { - parseGfsFileImpl(m_gribData); - }); - m_parseGribFileWorker->then(this, &CWeatherDataGfs::fetchingWeatherDataFinished); - } - - CUrl CWeatherDataGfs::getDownloadUrl() const - { - CUrl downloadUrl = sApp->getGlobalSetup().getNcepGlobalForecastSystemUrl25(); - - static const QStringList grib2Levels = { - "mean_sea_level", - "surface", - "100_mb", - "150_mb", - "200_mb", - "300_mb", - "400_mb", - "500_mb", - "600_mb", - "700_mb", - "800_mb", - "900_mb", - "1000_mb", - "high_cloud_bottom_level", - "high_cloud_layer", - "high_cloud_top_level", - "low_cloud_bottom_level", - "low_cloud_layer", - "low_cloud_top_level", - "middle_cloud_bottom_level", - "middle_cloud_layer", - "middle_cloud_top_level", - }; - - static const QStringList grib2Variables = { - "PRATE", - "PRES", - "PRMSL", - "RH", - "TCDC", - "TMP", - "UGRD", - "VGRD", - "CRAIN", - "CSNOW" - }; - - static const std::array cycles = { { 0, 6, 12, 18 } }; - const QDateTime now = QDateTime::currentDateTimeUtc(); - - // GFS data is published after 5 yours. - const QDateTime cnow = now.addSecs(-5 * 60 * 60); - - int hourLastPublishedCycle = 0; - for (const auto &cycle : cycles) - { - if (cnow.time().hour() > cycle) { hourLastPublishedCycle = cycle; } - } - - // Forecast is published in 3 hours steps. - // Round down to a multiple of 3 - int forecast = now.time().hour() - hourLastPublishedCycle; - if (forecast < 0) { forecast += 24; } - - // The 0 hour forecast, does not contain all required parameters. Hence use 1 hour forecast instead. - if (forecast == 0) { forecast = 1; } - - const QString filename = u"gfs." % QStringLiteral("t%1z").arg(hourLastPublishedCycle, 2, 10, QLatin1Char('0')) % u".pgrb2.0p25." % QStringLiteral("f%2").arg(forecast, 3, 10, QLatin1Char('0')); - const QString directory = u"/gfs." % cnow.toString("yyyyMMdd") % u"/" % QStringLiteral("%1").arg(hourLastPublishedCycle, 2, 10, QLatin1Char('0')) % u"/atmos"; - - downloadUrl.appendQuery("file", filename); - for (const auto &level : grib2Levels) - { - downloadUrl.appendQuery("lev_" + level, "on"); - } - for (const auto &variable : grib2Variables) - { - downloadUrl.appendQuery("var_" + variable, "on"); - } - downloadUrl.appendQuery("leftlon", "0"); - downloadUrl.appendQuery("rightlon", "360"); - downloadUrl.appendQuery("toplat", "90"); - downloadUrl.appendQuery("bottomlat", "-90"); - downloadUrl.appendQuery("dir", directory); - return downloadUrl; - } - - bool CWeatherDataGfs::parseGfsFileImpl(const QByteArray &gribData) - { - if (!m_lockData.tryLockForWrite(1000)) - { - CLogMessage(this).warning(u"Cannot log CWeatherDataGfs data"); - return false; - } - - m_lockData.unlock(); - QWriteLocker lock(&m_lockData); - - m_gfsWeatherGrid.clear(); - m_weatherGrid.clear(); - - // Messages should be 76. This is a combination - // of requested values (e.g. temperature, clouds etc) at specific layers (2 mbar, 10 mbar, surface). - constexpr int maxMessages = 76; - int messageNo = 0; - g2int iseek = 0; - for (;;) - { - if (QThread::currentThread()->isInterruptionRequested()) { return false; } - - // Search next grib field - g2int lskip = 0; - g2int lgrib = 0; - auto constData = reinterpret_cast(const_cast(gribData.data())); - findNextGribMessage(constData, gribData.size(), iseek, &lskip, &lgrib); - if (lgrib == 0) { break; } - - unsigned char *readPtr = constData + lskip; - iseek = lskip + lgrib; - - g2int sec0[3]; - g2int sec1[13]; - g2int numlocal = 0; - g2int numfields = 0; - g2_info(readPtr, sec0, sec1, &numfields, &numlocal); - - for (int n = 0; n < numfields; n++) - { - g2int unpack = 1; - g2int expand = 1; - gribfield *gfld = nullptr; - g2_getfld(readPtr, n + 1, unpack, expand, &gfld); - if (gfld->idsectlen < 12) - { - CLogMessage(this).warning(u"Identification section: wrong length!"); - continue; - } - - if (gfld->igdtnum != 0) { CLogMessage(this).warning(u"Can handle only grid definition template number = 0"); } - - int nscan = gfld->igdtmpl[18]; - int npnts = gfld->ngrdpts; - int nx = gfld->igdtmpl[7]; - int ny = gfld->igdtmpl[8]; - if (nscan != 0) { CLogMessage(this).error(u"Can only handle scanning mode NS:WE."); } - if (npnts != nx * ny) { CLogMessage(this).error(u"Cannot handle non-regular grid."); } - - if (m_gfsWeatherGrid.isEmpty()) { createWeatherGrid(gfld); } - - if (gfld->ipdtnum == 0) { handleProductDefinitionTemplate40(gfld); } - else if (gfld->ipdtnum == 8) { handleProductDefinitionTemplate48(gfld); } - else - { - CLogMessage(this).warning(u"Cannot handle product definition template %1") << gfld->ipdtnum; - continue; - } - - g2_free(gfld); - } - messageNo++; - } - - // validate - if (messageNo > maxMessages && CBuildConfig::isLocalDeveloperDebugBuild()) - { - // as discussed this means a format change - BLACK_VERIFY_X(false, Q_FUNC_INFO, "Format change in GRIB, too many messages"); - } - - const int weatherGridPointsNo = m_gfsWeatherGrid.size(); - CLogMessage(this).debug() << "Parsed" << messageNo << "GRIB messages."; - CLogMessage(this).debug() << "Obtained" << weatherGridPointsNo << "grid points."; - - constexpr int maxPoints = 200; - for (const GfsGridPoint &gfsGridPoint : std::as_const(m_gfsWeatherGrid)) - { - if (QThread::currentThread()->isInterruptionRequested()) { return false; } - - CTemperatureLayerList temperatureLayers; - CWindLayerList windLayers; - for (const GfsIsobaricLayer &isobaricLayer : gfsGridPoint.isobaricLayers) - { - float level = gfsGridPoint.isobaricLayers.key(isobaricLayer); - double altitudeFt = calculateAltitudeFt(gfsGridPoint.pressureAtMsl, level, isobaricLayer.temperature); - - CAltitude altitude(altitudeFt, CAltitude::MeanSeaLevel, CLengthUnit::ft()); - - auto temperature = CTemperature { isobaricLayer.temperature, CTemperatureUnit::K() }; - auto dewPoint = calculateDewPoint(temperature, isobaricLayer.relativeHumidity); - - CTemperatureLayer temperatureLayer(altitude, temperature, dewPoint, isobaricLayer.relativeHumidity); - temperatureLayers.push_back(temperatureLayer); - - double windDirection = -1 * CMathUtils::rad2deg(std::atan2(-isobaricLayer.windU, isobaricLayer.windV)); - windDirection += 180.0; - if (windDirection < 0.0) { windDirection += 360.0; } - if (windDirection >= 360.0) { windDirection -= 360.0; } - double windSpeed = std::hypot(isobaricLayer.windU, isobaricLayer.windV); - CWindLayer windLayer(altitude, CAngle(windDirection, CAngleUnit::deg()), CSpeed(windSpeed, CSpeedUnit::m_s()), {}); - windLayers.push_back(windLayer); - } - - CCloudLayerList cloudLayers; - for (const GfsCloudLayer &gfsCloudLayer : std::as_const(gfsGridPoint.cloudLayers)) - { - if (std::isnan(gfsCloudLayer.bottomLevelPressure) || std::isnan(gfsCloudLayer.topLevelPressure) || std::isnan(gfsCloudLayer.topLevelTemperature)) { continue; } - - CCloudLayer cloudLayer; - double bottomLevelFt = calculateAltitudeFt(gfsGridPoint.pressureAtMsl, gfsCloudLayer.bottomLevelPressure, gfsCloudLayer.topLevelTemperature); - double topLevelFt = calculateAltitudeFt(gfsGridPoint.pressureAtMsl, gfsCloudLayer.topLevelPressure, gfsCloudLayer.topLevelTemperature); - cloudLayer.setBase(CAltitude(bottomLevelFt, CAltitude::MeanSeaLevel, CLengthUnit::ft())); - cloudLayer.setTop(CAltitude(topLevelFt, CAltitude::MeanSeaLevel, CLengthUnit::ft())); - cloudLayer.setCoveragePercent(qRound(gfsCloudLayer.totalCoverage)); - if (gfsGridPoint.surfaceSnow > 0.0) { cloudLayer.setPrecipitation(CCloudLayer::Snow); } - if (gfsGridPoint.surfaceRain > 0.0) { cloudLayer.setPrecipitation(CCloudLayer::Rain); } - - // Precipitation rate is in kg m-2 s-1, which is equal to mm/s - // Multiply with 3600 to convert to mm/h - cloudLayer.setPrecipitationRate(gfsGridPoint.surfacePrecipitationRate * 3600.0); - cloudLayer.setClouds(CCloudLayer::CloudsUnknown); - cloudLayers.push_back(cloudLayer); - } - - auto pressureAtMsl = PhysicalQuantities::CPressure { gfsGridPoint.pressureAtMsl, PhysicalQuantities::CPressureUnit::Pa() }; - - const CLatitude latitude(gfsGridPoint.latitude, CAngleUnit::deg()); - const CLongitude longitude(gfsGridPoint.longitude, CAngleUnit::deg()); - const auto position = CCoordinateGeodetic { latitude, longitude }; - const CGridPoint gridPoint({}, position, cloudLayers, temperatureLayers, {}, windLayers, pressureAtMsl); - m_weatherGrid.push_back(gridPoint); - if (m_weatherGrid.size() >= maxPoints) - { - // too many points lead to extreme memory consumption and CPU usage - // we stop here, no use case so far in swift where we need that - BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Too many grid points"); - CLogMessage(this).warning(u"Too many weather grid points: %1") << m_weatherGrid.size(); - break; - } - } - - return true; - } - - void CWeatherDataGfs::findNextGribMessage(unsigned char *buffer, g2int size, g2int iseek, g2int *lskip, g2int *lgrib) - { - *lgrib = 0; - - if (iseek >= size) return; - g2int ipos = iseek; - unsigned char *bufferStart = buffer + iseek; - - // READ PARTIAL SECTION - g2int lim = size - 8; - - for (g2int k = 0; k < lim; k++) - { - g2int start; - g2int vers; - // Look for "GRIB" at the beginning - gbit(bufferStart, &start, (k + 0) * 8, 4 * 8); - gbit(bufferStart, &vers, (k + 7) * 8, 1 * 8); - if (start == 1196575042 && (vers == 1 || vers == 2)) - { - g2int lengrib = 0; - // Look for '7777' at end of GRIB message - if (vers == 1) gbit(bufferStart, &lengrib, (k + 4) * 8, 3 * 8); - if (vers == 2) gbit(bufferStart, &lengrib, (k + 12) * 8, 4 * 8); - - // Check the limits - g2int endPos = ipos + k + lengrib; - if (endPos > size) return; - unsigned char *bufferEnd = buffer + endPos - 4; - // Hard code to 4 instead of sizeof(g2int) - g2int end; - gbit(bufferEnd, &end, 0, 4 * 8); - if (end == 926365495) - { - // GRIB message found - *lskip = ipos + k; - *lgrib = lengrib; - return; - } - } - } - } - - void CWeatherDataGfs::createWeatherGrid(const gribfield *gfld) - { - int npnts = gfld->ngrdpts; - int nx = gfld->igdtmpl[7]; - int ny = gfld->igdtmpl[8]; - float units = 0.000001f; - float latitude1 = gfld->igdtmpl[11] * units; - float longitude1 = gfld->igdtmpl[12] * units; - int nres = gfld->igdtmpl[13]; - float latitude2 = gfld->igdtmpl[14] * units; - float longitude2 = gfld->igdtmpl[15] * units; - float dlatitude = gfld->igdtmpl[16] * units; - float dlongitude = gfld->igdtmpl[17] * units; - - if (latitude1 < -90.0f || latitude2 < -90.0f || latitude1 > 90.0f || latitude2 > 90.0f) - { - CLogMessage(this).warning(u"Invalid grid definition: lat1 = %1 - lat2 = %2") << latitude1 << latitude2; - return; - } - if (longitude1 < 0.0f || longitude2 < 0.0f || longitude1 > 360.0f || longitude2 > 360.0f) - { - CLogMessage(this).warning(u"Invalid grid definition: lon1 = %1 - lon2 = %2") << longitude1 << longitude2; - return; - } - if (npnts != nx * ny) - { - CLogMessage(this).warning(u"Invalid grid definition: npnts != nx * ny!"); - return; - } - - // Scan direction is North -> South - float north = latitude1; - float south = latitude2; - - if (south > north) - { - CLogMessage(this).warning(u"Invalid grid definition: South = %1 - North = %2") << south << north; - return; - } - - float dy = 0.0f; - if (ny != 1) - { - dy = (north - south) / (ny - 1.0f); - if (nres & 16) - { - if (fabs(dy - dlatitude) > 0.001f) - { - CLogMessage(this).warning(u"Invalid grid definition: delta latitude is inconsistent"); - return; - } - } - } - else - { - dy = 0.0; - } - - // Scan direction is West -> East - float west = longitude1; - float east = longitude2; - if (east <= west) { east += 360.0f; } - if (east - west > 360.0f) { east -= 360.0f; } - if (west < 0) - { - west += 360.0f; - east += 360.0f; - } - - float dx = 0; - if (nx != 1) - { - dx = (east - west) / (nx - 1); - dx = fabs(dx); - if (nres & 32) - { - if (fabs(dx - fabs(dlongitude)) > 0.001f) - { - CLogMessage(this).warning(u"Invalid grid definition: delta longitude is inconsistent"); - return; - } - } - } - else - { - dx = 0.0; - } - dy = fabs(dy); - - if (nx > 0 && ny > 0) - { - for (int iy = 0; iy < ny; iy++) - { - int i = nx * iy; - for (int ix = 0; ix < nx; ix++) - { - GfsGridPoint gridPoint; - gridPoint.latitude = latitude1 - iy * dy; - gridPoint.longitude = longitude1 + ix * dx; - if (gridPoint.longitude >= 360.0f) { gridPoint.longitude -= 360.0f; } - if (gridPoint.longitude < 0.0f) { gridPoint.longitude += 360.0f; } - gridPoint.fieldPosition = ix + i; - const CCoordinateGeodetic gridPointPosition(gridPoint.latitude, gridPoint.longitude, 0); - if (m_maxRange == CLength()) - { - m_gfsWeatherGrid.append(gridPoint); - } - else - { - for (const CGridPoint &fixedGridPoint : std::as_const(m_grid)) - { - const CLength distance = calculateGreatCircleDistance(gridPointPosition, fixedGridPoint.getPosition()); - if (distance.isNull()) - { - BLACK_VERIFY_X(!CBuildConfig::isLocalDeveloperDebugBuild(), Q_FUNC_INFO, "Suspicious value, why is that?"); - } - else - { - if (distance < m_maxRange) - { - m_gfsWeatherGrid.append(gridPoint); - break; - } - } - } - } - } // for - } // for - } // if - } - - void CWeatherDataGfs::handleProductDefinitionTemplate40(const gribfield *gfld) - { - if (gfld->ipdtlen != 15) - { - CLogMessage(this).warning(u"Template 4.0 has wrong length"); - return; - } - - // https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp4-0.shtml - g2int parameterCategory = gfld->ipdtmpl[0]; - g2int parameterNumber = gfld->ipdtmpl[1]; - g2int typeFirstFixedSurface = gfld->ipdtmpl[9]; - g2int valueFirstFixedSurface = gfld->ipdtmpl[11]; - - std::array key { { parameterCategory, parameterNumber } }; - // Make sure the key exists - if (!m_grib2ParameterTable.contains(key)) - { - CLogMessage(this).warning(u"Unknown GRIB2 parameter: %1 - %2") << parameterCategory << parameterNumber; - return; - } - - float level = 0.0; - - switch (typeFirstFixedSurface) - { - case GroundOrWaterSurface: level = 0.0; break; - case IsobaricSurface: level = valueFirstFixedSurface; break; - case MeanSeaLevel: level = 0.0; break; - default: CLogMessage(this).warning(u"Unexpected first fixed surface type: %1") << typeFirstFixedSurface; return; - } - - auto parameterValue = m_grib2ParameterTable[key]; - switch (parameterValue.code) - { - case TMP: setTemperature(gfld->fld, level); break; - case RH: setHumidity(gfld->fld, level); break; - case UGRD: setWindU(gfld->fld, level); break; - case VGRD: setWindV(gfld->fld, level); break; - case PRMSL: setPressureAtMsl(gfld->fld); break; - case PRES: /* Do nothing */ break; - case TCDC: /* Do nothing */ break; - case PRATE: /* Do nothing */ break; - case CSNOW: break; - case CRAIN: break; - default: CLogMessage(this).error(u"Unexpected parameterValue in Template 4.0: %1 (%2)") << parameterValue.code << parameterValue.name; return; - } - } - - void CWeatherDataGfs::handleProductDefinitionTemplate48(const gribfield *gfld) - { - if (gfld->ipdtlen != 29) - { - CLogMessage(this).warning(u"Template 4.8 has wrong length."); - return; - } - - g2int parameterCategory = gfld->ipdtmpl[0]; - g2int parameterNumber = gfld->ipdtmpl[1]; - g2int typeFirstFixedSurface = gfld->ipdtmpl[9]; - - std::array key { { parameterCategory, parameterNumber } }; - // Make sure the key exists - if (!m_grib2ParameterTable.contains(key)) - { - CLogMessage(this).warning(u"Unknown GRIB2 parameter: %1 - %2") << parameterCategory << parameterNumber; - return; - } - - static const QHash grib2CloudLevelHash = { - { LowCloudBottomLevel, LowCloud }, - { LowCloudTopLevel, LowCloud }, - { LowCloudLayer, LowCloud }, - { MiddleCloudBottomLevel, MiddleCloud }, - { MiddleCloudTopLevel, MiddleCloud }, - { MiddleCloudLayer, MiddleCloud }, - { HighCloudBottomLevel, HighCloud }, - { HighCloudTopLevel, HighCloud }, - { HighCloudLayer, HighCloud }, - }; - - auto parameterValue = m_grib2ParameterTable[key]; - switch (parameterValue.code) - { - case TCDC: setCloudCoverage(gfld->fld, grib2CloudLevelHash.value(typeFirstFixedSurface)); break; - case PRES: setCloudLevel(gfld->fld, typeFirstFixedSurface, grib2CloudLevelHash.value(typeFirstFixedSurface)); break; - case PRATE: setPrecipitationRate(gfld->fld); break; - case CRAIN: setSurfaceRain(gfld->fld); break; - case CSNOW: setSurfaceSnow(gfld->fld); break; - case TMP: setCloudTemperature(gfld->fld, typeFirstFixedSurface, grib2CloudLevelHash.value(typeFirstFixedSurface)); break; - default: CLogMessage(this).warning(u"Unexpected parameterValue in Template 4.8: %1 (%2)") << parameterValue.code << parameterValue.name; return; - } - } - - void CWeatherDataGfs::setTemperature(const g2float *fld, float level) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - if (level > 0) { gridPoint.isobaricLayers[level].temperature = fld[gridPoint.fieldPosition]; } - } - } - - void CWeatherDataGfs::setHumidity(const g2float *fld, float level) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - gridPoint.isobaricLayers[level].relativeHumidity = fld[gridPoint.fieldPosition]; - } - } - - void CWeatherDataGfs::setWindV(const g2float *fld, float level) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - gridPoint.isobaricLayers[level].windV = fld[gridPoint.fieldPosition]; - } - } - - void CWeatherDataGfs::setWindU(const g2float *fld, float level) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - gridPoint.isobaricLayers[level].windU = fld[gridPoint.fieldPosition]; - } - } - - void CWeatherDataGfs::setCloudCoverage(const g2float *fld, int level) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - if (fld[gridPoint.fieldPosition] > 0.0f) { gridPoint.cloudLayers[level].totalCoverage = fld[gridPoint.fieldPosition]; } - } - } - - void CWeatherDataGfs::setCloudLevel(const g2float *fld, int surfaceType, int level) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - static const g2float minimumLevel = 1000.0; - float levelPressure = std::numeric_limits::quiet_NaN(); - g2float fieldValue = fld[gridPoint.fieldPosition]; - // A value of 9.999e20 is undefined. Check that the pressure value is below - if (fieldValue < 9.998e20f && fieldValue > minimumLevel) { levelPressure = fld[gridPoint.fieldPosition]; } - switch (surfaceType) - { - case LowCloudBottomLevel: - case MiddleCloudBottomLevel: - case HighCloudBottomLevel: - gridPoint.cloudLayers[level].bottomLevelPressure = levelPressure; - break; - case LowCloudTopLevel: - case MiddleCloudTopLevel: - case HighCloudTopLevel: - gridPoint.cloudLayers[level].topLevelPressure = levelPressure; - break; - default: - Q_ASSERT(false); - break; - } - } - } - - void CWeatherDataGfs::setCloudTemperature(const g2float *fld, int surfaceType, int level) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - float temperature = std::numeric_limits::quiet_NaN(); - g2float fieldValue = fld[gridPoint.fieldPosition]; - if (fieldValue < 9.998e20f) { temperature = fld[gridPoint.fieldPosition]; } - switch (surfaceType) - { - case LowCloudTopLevel: - case MiddleCloudTopLevel: - case HighCloudTopLevel: - gridPoint.cloudLayers[level].topLevelTemperature = temperature; - break; - default: - Q_ASSERT(false); - break; - } - } - } - - void CWeatherDataGfs::setPressureAtMsl(const g2float *fld) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - gridPoint.pressureAtMsl = fld[gridPoint.fieldPosition]; - } - } - - void CWeatherDataGfs::setSurfaceRain(const g2float *fld) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - gridPoint.surfaceRain = fld[gridPoint.fieldPosition]; - } - } - - void CWeatherDataGfs::setSurfaceSnow(const g2float *fld) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - gridPoint.surfaceSnow = fld[gridPoint.fieldPosition]; - } - } - - void CWeatherDataGfs::setPrecipitationRate(const g2float *fld) - { - for (auto &gridPoint : m_gfsWeatherGrid) - { - gridPoint.surfacePrecipitationRate = fld[gridPoint.fieldPosition]; - } - } - - CTemperature CWeatherDataGfs::calculateDewPoint(const CTemperature &temperature, double relativeHumidity) - { - // https://en.wikipedia.org/wiki/Dew_point#Calculating_the_dew_point - const double a = 6.112; - const double b = 17.67; - const double c = 243.5; - - double temperatureInCelsius = temperature.value(CTemperatureUnit::C()); - double saturationVaporPressure = a * std::exp((b * temperatureInCelsius) / (c + temperatureInCelsius)); - - double vaporPressure = (relativeHumidity / 100.0) * saturationVaporPressure; - // std::log(0.0) is not defined. Hence we use the smallest value possible close to 0.0, if RH is 0.0. - // In real weather, RH 0.0 % will never exist. - vaporPressure = qMax(vaporPressure, std::numeric_limits::min()); - - double dewPointInCelsius = c * std::log(vaporPressure / a) / (b - std::log(vaporPressure / a)); - return { dewPointInCelsius, CTemperatureUnit::C() }; - } - - BlackCore::IWeatherData *CWeatherDataGfsFactory::create(QObject *parent) - { - return new CWeatherDataGfs(parent); - } - -} // namespace diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.h b/src/plugins/weatherdata/gfs/weatherdatagfs.h deleted file mode 100644 index 7294ac8c1..000000000 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.h +++ /dev/null @@ -1,116 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \file - -#ifndef BLACKWXPLUGIN_GFS_H -#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" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace BlackMisc::PhysicalQuantities -{ - class CTemperature; -} -namespace BlackWxPlugin::Gfs -{ - struct Grib2ParameterKey; - struct Grib2ParameterValue; - struct GfsGridPoint; - - /*! - * GFS implemenation - */ - class CWeatherDataGfs : public BlackCore::IWeatherData - { - Q_OBJECT - - public: - //! Constructor - CWeatherDataGfs(QObject *parent = nullptr); - - //! Destructor - virtual ~CWeatherDataGfs() override; - - //! \copydoc BlackCore::IWeatherData::fetchWeatherData - virtual void fetchWeatherData(const BlackMisc::Weather::CWeatherGrid &initialGrid, - const BlackMisc::PhysicalQuantities::CLength &range) override; - - //! \copydoc BlackCore::IWeatherData::fetchWeatherDataFromFile - virtual void fetchWeatherDataFromFile(const QString &filePath, - const BlackMisc::Weather::CWeatherGrid &grid, - const BlackMisc::PhysicalQuantities::CLength &range) override; - - //! \copydoc BlackCore::IWeatherData::getWeatherData() - virtual BlackMisc::Weather::CWeatherGrid getWeatherData() const override; - - private: - //! Asyncronous fetching finished - //! \threadsafe - void fetchingWeatherDataFinished(); - - void parseGfsFile(QNetworkReply *nwReplyPtr); - BlackMisc::Network::CUrl getDownloadUrl() const; - bool parseGfsFileImpl(const QByteArray &gribData); - void findNextGribMessage(unsigned char *buffer, g2int size, g2int iseek, g2int *lskip, g2int *lgrib); - void createWeatherGrid(const gribfield *gfld); - void handleProductDefinitionTemplate40(const gribfield *gfld); - void handleProductDefinitionTemplate48(const gribfield *gfld); - void setTemperature(const g2float *fld, float level); - void setHumidity(const g2float *fld, float level); - void setWindV(const g2float *fld, float level); - void setWindU(const g2float *fld, float level); - void setCloudCoverage(const g2float *fld, int level); - void setCloudLevel(const g2float *fld, int surfaceType, int level); - void setCloudTemperature(const g2float *fld, int surfaceType, int level); - void setPressureAtMsl(const g2float *fld); - void setSurfaceRain(const g2float *fld); - void setSurfaceSnow(const g2float *fld); - void setPrecipitationRate(const g2float *fld); - - BlackMisc::PhysicalQuantities::CTemperature calculateDewPoint(const BlackMisc::PhysicalQuantities::CTemperature &temperature, double relativeHumidity); - - BlackMisc::Weather::CWeatherGrid m_grid; - BlackMisc::PhysicalQuantities::CLength m_maxRange; - - mutable QReadWriteLock m_lockData; - QByteArray m_gribData; - - QVector m_gfsWeatherGrid; - BlackMisc::Weather::CWeatherGrid m_weatherGrid; - - QPointer m_parseGribFileWorker; //!< worker will destroy itself, so weak pointer - - using Grib2ParameterKey = std::array; - using Grib2ParameterTable = QMap; - static const Grib2ParameterTable m_grib2ParameterTable; - }; - - //! Factory for creating CWeatherDataGfs instance - class CWeatherDataGfsFactory : public QObject, public BlackCore::IWeatherDataFactory - { - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.swift-project.blackcore.weatherdata" FILE "weatherdatagfs.json") - Q_INTERFACES(BlackCore::IWeatherDataFactory) - - public: - //! \copydoc BlackCore::IWeatherDataFactory::create() - virtual BlackCore::IWeatherData *create(QObject *parent = nullptr) override; - }; - -} // ns - -#endif // guard diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.json b/src/plugins/weatherdata/gfs/weatherdatagfs.json deleted file mode 100644 index 4fd1633a4..000000000 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "identifier" : "org.swift-project.plugins.weatherdata.gfs", - "name" : "gfs", - "description" : "Global forecast from National Centers for Environmental Prediction." -} diff --git a/src/plugins/weatherdata/gfs/weatherdatagfs.json.license b/src/plugins/weatherdata/gfs/weatherdatagfs.json.license deleted file mode 100644 index 4eaf3369b..000000000 --- a/src/plugins/weatherdata/gfs/weatherdatagfs.json.license +++ /dev/null @@ -1,3 +0,0 @@ -Copyright (C) swift Project Community / Contributors - -SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 diff --git a/src/xswiftbus/CMakeLists.txt b/src/xswiftbus/CMakeLists.txt index dbf8925ad..91ddc4827 100644 --- a/src/xswiftbus/CMakeLists.txt +++ b/src/xswiftbus/CMakeLists.txt @@ -8,7 +8,6 @@ endif() add_library(xswiftbus SHARED org.swift_project.xswiftbus.service.xml org.swift_project.xswiftbus.traffic.xml - org.swift_project.xswiftbus.weather.xml xswiftbus.conf command.h config.cpp @@ -47,8 +46,6 @@ add_library(xswiftbus SHARED traffic.h utils.cpp utils.h - weather.cpp - weather.h xplanemp2/src/CSL.cpp xplanemp2/src/CSL.h diff --git a/src/xswiftbus/org.swift_project.xswiftbus.weather.xml b/src/xswiftbus/org.swift_project.xswiftbus.weather.xml deleted file mode 100644 index f0761129a..000000000 --- a/src/xswiftbus/org.swift_project.xswiftbus.weather.xml +++ /dev/null @@ -1,50 +0,0 @@ -R"XML( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -)XML" diff --git a/src/xswiftbus/plugin.cpp b/src/xswiftbus/plugin.cpp index 83a67542b..91d0d4c5f 100644 --- a/src/xswiftbus/plugin.cpp +++ b/src/xswiftbus/plugin.cpp @@ -4,7 +4,6 @@ #include "plugin.h" #include "service.h" #include "traffic.h" -#include "weather.h" #include "utils.h" #include "XPLM/XPLMProcessing.h" #include @@ -90,7 +89,6 @@ namespace XSwiftBus m_service = std::make_unique(this); m_traffic = std::make_unique(this); - m_weather = std::make_unique(this); m_traffic->setPlaneViewMenu(m_planeViewSubMenu); @@ -114,8 +112,6 @@ namespace XSwiftBus m_service->registerDBusObjectPath(m_service->InterfaceName(), m_service->ObjectPath()); m_traffic->setDBusConnection(m_dbusConnection); m_traffic->registerDBusObjectPath(m_traffic->InterfaceName(), m_traffic->ObjectPath()); - m_weather->setDBusConnection(m_dbusConnection); - m_weather->registerDBusObjectPath(m_weather->InterfaceName(), m_weather->ObjectPath()); }); } else @@ -136,8 +132,6 @@ namespace XSwiftBus m_service->registerDBusObjectPath(m_service->InterfaceName(), m_service->ObjectPath()); m_traffic->setDBusConnection(m_dbusConnection); m_traffic->registerDBusObjectPath(m_traffic->InterfaceName(), m_traffic->ObjectPath()); - m_weather->setDBusConnection(m_dbusConnection); - m_weather->registerDBusObjectPath(m_weather->InterfaceName(), m_weather->ObjectPath()); } //! todo RR: Send all logs to the the message window. @@ -190,7 +184,6 @@ namespace XSwiftBus plugin->m_dbusDispatcher.runOnce(); if (plugin->m_service) { plugin->m_service->process(); } - if (plugin->m_weather) { plugin->m_weather->process(); } if (plugin->m_traffic) { plugin->m_traffic->process(); } return -1; } diff --git a/src/xswiftbus/plugin.h b/src/xswiftbus/plugin.h index 643633012..c6a25902e 100644 --- a/src/xswiftbus/plugin.h +++ b/src/xswiftbus/plugin.h @@ -31,7 +31,6 @@ namespace XSwiftBus { class CService; class CTraffic; - class CWeather; /*! * Main plugin class @@ -73,7 +72,6 @@ namespace XSwiftBus std::shared_ptr m_dbusConnection; std::unique_ptr m_service; std::unique_ptr m_traffic; - std::unique_ptr m_weather; CMenu m_menu; CMenuItem m_showHideLabelsMenuItem; CMenuItem m_enableDisableXPlaneAtisMenuItem; diff --git a/src/xswiftbus/weather.cpp b/src/xswiftbus/weather.cpp deleted file mode 100644 index 00c78e443..000000000 --- a/src/xswiftbus/weather.cpp +++ /dev/null @@ -1,233 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -//! \cond PRIVATE - -#include "weather.h" -#include "utils.h" - -namespace XSwiftBus -{ - CWeather::CWeather(CSettingsProvider *settingsProvider) : CDBusObject(settingsProvider) - { - // void - } - - //! Set cloud layer - template - void setCloudLayerImpl(T &layer, int base, int tops, int type, int coverage) - { - layer.base.setAsInt(base); - layer.tops.setAsInt(tops); - layer.type.set(type); - layer.coverage.setAsInt(coverage); - } - - void CWeather::setCloudLayer(int layer, int baseM, int topsM, int type, int coverage) - { - switch (layer) - { - case 0: setCloudLayerImpl(m_cloudLayer0, baseM, topsM, type, coverage); break; - case 1: setCloudLayerImpl(m_cloudLayer1, baseM, topsM, type, coverage); break; - case 2: setCloudLayerImpl(m_cloudLayer2, baseM, topsM, type, coverage); break; - default: DEBUG_LOG("Invalid cloud layer"); break; - } - } - - //! Set wind layer - template - void setWindLayerImpl(T &layer, int altitude, double direction, int speed, int shearDirection, int shearSpeed, int turbulence) - { - layer.altitude.setAsInt(altitude); - layer.direction.set(static_cast(direction)); - layer.speed.setAsInt(speed); - layer.shearDirection.setAsInt(shearDirection); - layer.shearSpeed.setAsInt(shearSpeed); - layer.turbulence.setAsInt(turbulence); - } - - void CWeather::setWindLayer(int layer, int altitudeM, double directionDeg, int speedKt, int shearDirectionDeg, int shearSpeedKt, int turbulence) - { - switch (layer) - { - case 0: setWindLayerImpl(m_windLayer0, altitudeM, directionDeg, speedKt, shearDirectionDeg, shearSpeedKt, turbulence); break; - case 1: setWindLayerImpl(m_windLayer1, altitudeM, directionDeg, speedKt, shearDirectionDeg, shearSpeedKt, turbulence); break; - case 2: setWindLayerImpl(m_windLayer2, altitudeM, directionDeg, speedKt, shearDirectionDeg, shearSpeedKt, turbulence); break; - default: DEBUG_LOG("Invalid wind layer"); break; - } - } - - static const char *introspection_weather = - DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE -#include "org.swift_project.xswiftbus.weather.xml" - ; - - DBusHandlerResult CWeather::dbusMessageHandler(const CDBusMessage &message_) - { - CDBusMessage message(message_); - const std::string sender = message.getSender(); - const dbus_uint32_t serial = message.getSerial(); - const bool wantsReply = message.wantsReply(); - - if (message.getInterfaceName() == DBUS_INTERFACE_INTROSPECTABLE) - { - if (message.getMethodName() == "Introspect") - { - sendDBusReply(sender, serial, introspection_weather); - } - } - else if (message.getInterfaceName() == XSWIFTBUS_WEATHER_INTERFACENAME) - { - if (message.getMethodName() == "isUsingRealWeather") - { - queueDBusCall([=]() { - sendDBusReply(sender, serial, isUsingRealWeather()); - }); - } - else if (message.getMethodName() == "setUseRealWeather") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - bool enable = false; - message.beginArgumentRead(); - message.getArgument(enable); - queueDBusCall([=]() { - setUseRealWeather(enable); - }); - } - else if (message.getMethodName() == "setVisibility") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - double visibilityM = 10.0; - message.beginArgumentRead(); - message.getArgument(visibilityM); - queueDBusCall([=]() { - setVisibility(visibilityM); - }); - } - else if (message.getMethodName() == "setTemperature") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - int degreesC = 10; - message.beginArgumentRead(); - message.getArgument(degreesC); - queueDBusCall([=]() { - setTemperature(degreesC); - }); - } - else if (message.getMethodName() == "setDewPoint") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - int degreesC = 10; - message.beginArgumentRead(); - message.getArgument(degreesC); - queueDBusCall([=]() { - setDewPoint(degreesC); - }); - } - else if (message.getMethodName() == "setQNH") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - double inHg = 29.92; - message.beginArgumentRead(); - message.getArgument(inHg); - queueDBusCall([=]() { - setQNH(inHg); - }); - } - else if (message.getMethodName() == "setPrecipitationRatio") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - double precipRatio = 0.0; - message.beginArgumentRead(); - message.getArgument(precipRatio); - queueDBusCall([=]() { - setPrecipitationRatio(precipRatio); - }); - } - else if (message.getMethodName() == "setThunderstormRatio") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - double cbRatio = 0.0; - message.beginArgumentRead(); - message.getArgument(cbRatio); - queueDBusCall([=]() { - setThunderstormRatio(cbRatio); - }); - } - else if (message.getMethodName() == "setTurbulenceRatio") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - double turbulenceRatio = 0.0; - message.beginArgumentRead(); - message.getArgument(turbulenceRatio); - queueDBusCall([=]() { - setTurbulenceRatio(turbulenceRatio); - }); - } - else if (message.getMethodName() == "setRunwayFriction") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - int friction = 10; - message.beginArgumentRead(); - message.getArgument(friction); - queueDBusCall([=]() { - setRunwayFriction(friction); - }); - } - else if (message.getMethodName() == "setCloudLayer") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - int layer = 0; - int base = 0; - int tops = 0; - int type = 0; - int coverage = 0; - message.beginArgumentRead(); - message.getArgument(layer); - message.getArgument(base); - message.getArgument(tops); - message.getArgument(type); - message.getArgument(coverage); - queueDBusCall([=]() { - setCloudLayer(layer, base, tops, type, coverage); - }); - } - else if (message.getMethodName() == "setWindLayer") - { - maybeSendEmptyDBusReply(wantsReply, sender, serial); - int layer = 0; - int altitudeM = 0; - double directionDeg = 0; - int speedKt = 0; - int shearDirectionDeg = 0; - int shearSpeedKt = 0; - int turbulence = 0; - message.beginArgumentRead(); - message.getArgument(layer); - message.getArgument(altitudeM); - message.getArgument(directionDeg); - message.getArgument(speedKt); - message.getArgument(shearDirectionDeg); - message.getArgument(shearSpeedKt); - message.getArgument(turbulence); - queueDBusCall([=]() { - setWindLayer(layer, altitudeM, directionDeg, speedKt, shearDirectionDeg, shearSpeedKt, turbulence); - }); - } - else - { - // Unknown message. Tell DBus that we cannot handle it - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - } - return DBUS_HANDLER_RESULT_HANDLED; - } - - int CWeather::process() - { - invokeQueuedDBusCalls(); - return 1; - } -} - -//! \endcond diff --git a/src/xswiftbus/weather.h b/src/xswiftbus/weather.h deleted file mode 100644 index 11879dff5..000000000 --- a/src/xswiftbus/weather.h +++ /dev/null @@ -1,161 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 - -#ifndef BLACKSIM_XSWIFTBUS_WEATHER_H -#define BLACKSIM_XSWIFTBUS_WEATHER_H - -//! \file - -#ifndef NOMINMAX -# define NOMINMAX -#endif -#include "dbusobject.h" -#include "datarefs.h" - -//! \cond PRIVATE -#define XSWIFTBUS_WEATHER_INTERFACENAME "org.swift_project.xswiftbus.weather" -#define XSWIFTBUS_WEATHER_OBJECTPATH "/xswiftbus/weather" -//! \endcond - -namespace XSwiftBus -{ - /*! - * xswiftbus weather object which is accessible through DBus - */ - class CWeather : public CDBusObject - { - public: - //! Constructor - CWeather(CSettingsProvider *settingsProvider); - - //! DBus interface name - static const std::string &InterfaceName() - { - static std::string s(XSWIFTBUS_WEATHER_INTERFACENAME); - return s; - } - - //! DBus object path - static const std::string &ObjectPath() - { - static std::string s(XSWIFTBUS_WEATHER_OBJECTPATH); - return s; - } - - //! True if the sim is using X-Plane built-in real weather source. - bool isUsingRealWeather() const { return m_useRealWeather.get(); } - - //! Set whether or not to use X-Plane built-in real weather source. - void setUseRealWeather(bool enable) { m_useRealWeather.set(enable ? 1 : 0); } - - //! Set reported visibility in meters. - void setVisibility(double visibilityM) { m_visibilityM.set(static_cast(visibilityM)); } - - //! Set temperature at sea level in degrees C. - void setTemperature(int degreesC) { m_temperatureC.setAsInt(degreesC); } - - //! Set dew point at sea level in degrees C. - void setDewPoint(int degreesC) { m_dewPointC.setAsInt(degreesC); } - - //! Set barometric pressure at sea level in inches of mercury. - void setQNH(double inHg) { m_qnhInhg.set(static_cast(inHg)); } - - //! Set amount of precipitation between 0 and 1. - void setPrecipitationRatio(double precipRatio) { m_precipRatio.set(static_cast(precipRatio)); } - - //! Set amount of thunderstorms between 0 and 1. - void setThunderstormRatio(double cbRatio) { m_cbRatio.set(static_cast(cbRatio)); } - - //! Set amount of turbulence between 0 and 1. - void setTurbulenceRatio(double turbulenceRatio) { m_turbulenceRatio.set(static_cast(turbulenceRatio)); } - - //! Set runway friction, 0=dry, 1=damp, 2=wet. - void setRunwayFriction(int friction) { m_runwayFriction.setAsInt(friction); } - - //! Set a cloud layer. - //! \param layer Layer 0, 1, or 2. - //! \param baseM Cloud base in meters above mean sea level. - //! \param topsM Cloud tops in meters above mean sea level. - //! \param type Type of cloud: 0=clear, 1=cirrus, 2=scattered, 3=broken, 4=overcast, 5=stratus. - //! \param coverage Amount of sky covered [0,6]. - void setCloudLayer(int layer, int baseM, int topsM, int type, int coverage); - - //! Set a wind layer. - //! \param layer Layer 0, 1, or 2. - //! \param altitudeM Altitude in middle of layer in meters above mean sea level. - //! \param directionDeg Direction from which wind is blowing in degrees true. - //! \param speedKt Wind speed in knots. - //! \param shearDirectionDeg Direction from which wind shears blow in degrees true. - //! \param shearSpeedKt Wind speed gain in knots (e.g. speed=10 and shearSpeed=5 means speed varies between 10 and 15). - //! \param turbulence Amount of turbulence [0,10]. - void setWindLayer(int layer, int altitudeM, double directionDeg, int speedKt, int shearDirectionDeg, int shearSpeedKt, int turbulence); - - //! Perform generic processing - int process(); - - protected: - virtual DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override; - - private: - DataRef m_useRealWeather; - DataRef m_visibilityM; - DataRef m_precipRatio; - DataRef m_cbRatio; - DataRef m_turbulenceRatio; - DataRef m_temperatureC; - DataRef m_dewPointC; - DataRef m_qnhInhg; - DataRef m_runwayFriction; - struct - { - DataRef base; - DataRef tops; - DataRef type; - DataRef coverage; - } m_cloudLayer0; - struct - { - DataRef base; - DataRef tops; - DataRef type; - DataRef coverage; - } m_cloudLayer1; - struct - { - DataRef base; - DataRef tops; - DataRef type; - DataRef coverage; - } m_cloudLayer2; - struct - { - DataRef altitude; - DataRef direction; - DataRef speed; - DataRef shearDirection; - DataRef shearSpeed; - DataRef turbulence; - } m_windLayer0; - struct - { - DataRef altitude; - DataRef direction; - DataRef speed; - DataRef shearDirection; - DataRef shearSpeed; - DataRef turbulence; - } m_windLayer1; - struct - { - DataRef altitude; - DataRef direction; - DataRef speed; - DataRef shearDirection; - DataRef shearSpeed; - DataRef turbulence; - } m_windLayer2; - }; - -} - -#endif // guard diff --git a/tests/blackmisc/weather/testweather/testweather.cpp b/tests/blackmisc/weather/testweather/testweather.cpp index cc8691ff6..500397612 100644 --- a/tests/blackmisc/weather/testweather/testweather.cpp +++ b/tests/blackmisc/weather/testweather/testweather.cpp @@ -22,10 +22,6 @@ #include "blackmisc/weather/metardecoder.h" #include "blackmisc/weather/presentweather.h" #include "blackmisc/weather/presentweatherlist.h" -#include "blackmisc/weather/temperaturelayer.h" -#include "blackmisc/weather/temperaturelayerlist.h" -#include "blackmisc/weather/visibilitylayer.h" -#include "blackmisc/weather/visibilitylayerlist.h" #include "blackmisc/weather/windlayer.h" #include "blackmisc/weather/windlayerlist.h" #include "test.h" @@ -47,12 +43,6 @@ namespace BlackMiscTest //! Testing CCloudLayer/CCloudLayerList void cloudLayer(); - //! Testing CTemperatureLayer/CTemperatureLayerList - void temperatureLayer(); - - //! Testing CVisibilityLayer/CVisibilityLayerList - void visibilityLayer(); - //! Testing CWindLayer/CWindLayerList void windLayer(); @@ -94,46 +84,6 @@ namespace BlackMiscTest QVERIFY(cll.findByBase(base3) == CCloudLayer()); } - void CTestWeather::temperatureLayer() - { - const CAltitude level1 { 0, CAltitude::AboveGround, CLengthUnit::ft() }; - const CTemperature temp1 { 25, CTemperatureUnit::C() }; - const CTemperature dp1 { 15, CTemperatureUnit::C() }; - const double rh = 80.0; - - CTemperatureLayer tl1(level1, temp1, dp1, rh); - QVERIFY(tl1.getLevel() == level1); - QVERIFY(tl1.getTemperature() == temp1); - QVERIFY(tl1.getDewPoint() == dp1); - QCOMPARE(tl1.getRelativeHumidity(), rh); - - CAltitude level2 { 25000, CAltitude::AboveGround, CLengthUnit::ft() }; - CTemperatureLayerList tll { tl1 }; - QVERIFY(tll.containsLevel(level1)); - QVERIFY(!tll.containsLevel(level2)); - QVERIFY(tll.findByLevel(level1) != CTemperatureLayer()); - QVERIFY(tll.findByLevel(level2) == CTemperatureLayer()); - } - - void CTestWeather::visibilityLayer() - { - const CAltitude base1 { 0, CAltitude::AboveGround, CLengthUnit::ft() }; - const CAltitude top1 { 5000, CAltitude::AboveGround, CLengthUnit::ft() }; - const CLength visibility1 { 10, CLengthUnit::SM() }; - - CVisibilityLayer vl1(base1, top1, visibility1); - QVERIFY(vl1.getBase() == base1); - QVERIFY(vl1.getTop() == top1); - QVERIFY(vl1.getVisibility() == visibility1); - - const CAltitude base2 { 25000, CAltitude::AboveGround, CLengthUnit::ft() }; - CVisibilityLayerList vll { vl1 }; - QVERIFY(vll.containsBase(base1)); - QVERIFY(!vll.containsBase(base2)); - QVERIFY(vll.findByBase(base1) != CVisibilityLayer()); - QVERIFY(vll.findByBase(base2) == CVisibilityLayer()); - } - void CTestWeather::windLayer() { const CAltitude level1 { 0, CAltitude::AboveGround, CLengthUnit::ft() };