Skip to content

Commit

Permalink
Added GRIB2 decoding library.
Browse files Browse the repository at this point in the history
Added classes to download, decode and query GRIB wind layers.
GRIB code can be disabled with variable ATOOLS_NO_GRIB.

albar965/littlenavmap#283
  • Loading branch information
albar965 committed May 4, 2019
1 parent 3c57c73 commit 20bbc49
Show file tree
Hide file tree
Showing 68 changed files with 12,871 additions and 15 deletions.
77 changes: 76 additions & 1 deletion atools.pro
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
# Optional. Set this to "true" to omit all flight simulator code if not needed.
# Reduces compilation time.
#
# ATOOLS_NO_GRIB
# Optional. Set this to "true" to omit all GRIB2 decoding code if not needed.
# Reduces compilation time.
#
# This project has no deploy or install target. The include and library should
# be used directly from the source tree.
#
Expand All @@ -56,6 +60,7 @@ GIT_PATH=$$(ATOOLS_GIT_PATH)
SIMCONNECT_PATH=$$(ATOOLS_SIMCONNECT_PATH)
QUIET=$$(ATOOLS_QUIET)
ATOOLS_NO_FS=$$(ATOOLS_NO_FS)
ATOOLS_NO_GRIB=$$(ATOOLS_NO_GRIB)

# =======================================================================
# Set compiler flags and paths
Expand Down Expand Up @@ -100,6 +105,7 @@ message(-----------------------------------)
message(GIT_PATH: $$GIT_PATH)
message(GIT_REVISION: $$GIT_REVISION)
message(ATOOLS_NO_FS: $$ATOOLS_NO_FS)
message(ATOOLS_NO_GRIB: $$ATOOLS_NO_GRIB)
message(SIMCONNECT_PATH: $$SIMCONNECT_PATH)
message(DEFINES: $$DEFINES)
message(INCLUDEPATH: $$INCLUDEPATH)
Expand Down Expand Up @@ -594,14 +600,83 @@ SOURCES += \
src/fs/xp/xpfixwriter.cpp \
src/fs/xp/xpnavwriter.cpp \
src/fs/xp/xpwriter.cpp
}
} # ATOOLS_NO_FS


# =====================================================================
# GRIB2 decoding files

!isEqual(ATOOLS_NO_GRIB, "true") {
HEADERS += \
src/g2clib/drstemplates.h \
src/g2clib/grib2.h \
src/g2clib/gridtemplates.h \
src/g2clib/pdstemplates.h \
src/grib/gribcommon.h \
src/grib/gribdownloader.h \
src/grib/gribreader.h \
src/grib/gribwindquery.h

SOURCES += \
src/g2clib/cmplxpack.c \
src/g2clib/compack.c \
src/g2clib/comunpack.c \
src/g2clib/dec_jpeg2000.c \
src/g2clib/dec_png.c \
src/g2clib/drstemplates.c \
src/g2clib/enc_jpeg2000.c \
src/g2clib/enc_png.c \
src/g2clib/g2_addfield.c \
src/g2clib/g2_addgrid.c \
src/g2clib/g2_addlocal.c \
src/g2clib/g2_create.c \
src/g2clib/g2_free.c \
src/g2clib/g2_getfld.c \
src/g2clib/g2_gribend.c \
src/g2clib/g2_info.c \
src/g2clib/g2_miss.c \
src/g2clib/g2_unpack1.c \
src/g2clib/g2_unpack2.c \
src/g2clib/g2_unpack3.c \
src/g2clib/g2_unpack4.c \
src/g2clib/g2_unpack5.c \
src/g2clib/g2_unpack6.c \
src/g2clib/g2_unpack7.c \
src/g2clib/gbits.c \
src/g2clib/getdim.c \
src/g2clib/getpoly.c \
src/g2clib/gridtemplates.c \
src/g2clib/int_power.c \
src/g2clib/jpcpack.c \
src/g2clib/jpcunpack.c \
src/g2clib/misspack.c \
src/g2clib/mkieee.c \
src/g2clib/pack_gp.c \
src/g2clib/pdstemplates.c \
src/g2clib/pngpack.c \
src/g2clib/pngunpack.c \
src/g2clib/rdieee.c \
src/g2clib/reduce.c \
src/g2clib/seekgb.c \
src/g2clib/simpack.c \
src/g2clib/simunpack.c \
src/g2clib/specpack.c \
src/g2clib/specunpack.c \
src/grib/gribcommon.cpp \
src/grib/gribdownloader.cpp \
src/grib/gribreader.cpp \
src/grib/gribwindquery.cpp
} # ATOOLS_NO_GRIB


RESOURCES += \
atools.qrc

OTHER_FILES += \
resources/sql/fs/db/README.txt \
*.ts \
.travis.yml \
.gitignore \
BUILD.txt \
CHANGELOG.txt \
LICENSE.txt \
Expand Down
7 changes: 6 additions & 1 deletion src/atools.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,19 @@ Q_DECL_CONSTEXPR int roundToInt(TYPE value)
template<typename TYPE>
Q_DECL_CONSTEXPR TYPE interpolate(TYPE f0, TYPE f1, TYPE x0, TYPE x1, TYPE x)
{
return f0 + ((f1 - f0) / (x1 - x0)) * (x - x0);
if(f0 == f1)
return f0;
else
return f0 + ((f1 - f0) / (x1 - x0)) * (x - x0);
}

/* Get coordinate where x crosses the line */
Q_DECL_CONSTEXPR QPointF interpolateForX(const QLineF& line, double x)
{
return line.pointAt((x - line.x1()) / line.dx());
}

/* Get coordinate where y crosses the line */
Q_DECL_CONSTEXPR QPointF interpolateForY(const QLineF& line, double y)
{
return line.pointAt((y - line.y1()) / line.dy());
Expand Down
4 changes: 2 additions & 2 deletions src/fs/weather/weathernetdownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void WeatherNetDownload::downloadFinished(const QByteArray& data, QString url)
emit weatherUpdated();
}

void WeatherNetDownload::downloadFailed(const QString& error, QString url)
void WeatherNetDownload::downloadFailed(const QString& error, int errorCode, QString url)
{
qWarning() << Q_FUNC_INFO << "Error downloading from" << url << ":" << error;
qWarning() << Q_FUNC_INFO << "Error downloading from" << url << ":" << error << errorCode;
}

void WeatherNetDownload::setUpdatePeriod(int seconds)
Expand Down
2 changes: 1 addition & 1 deletion src/fs/weather/weathernetdownload.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class WeatherNetDownload :

private:
void downloadFinished(const QByteArray& data, QString url);
void downloadFailed(const QString& error, QString url);
void downloadFailed(const QString& error, int errorCode, QString url);
void parseFile(const QByteArray& data);

std::function<atools::geo::Pos(const QString&)> fetchAirportCoords;
Expand Down
71 changes: 71 additions & 0 deletions src/g2clib/CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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

g2libc-1.6.0 - October 2015 - Added PDT 4.57, 4.60, 4.61 and
- Allow a forecast time to be negative
68 changes: 68 additions & 0 deletions src/g2clib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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/.


75 changes: 75 additions & 0 deletions src/g2clib/cmplxpack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#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;
}

}
Loading

0 comments on commit 20bbc49

Please sign in to comment.