RCube
Rcube Rest Server calculates sail routes based on Grib files and sailing boat polar files
Loading...
Searching...
No Matches
readgriballwithouteccodes.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <sys/stat.h>
#include "../csources/glibwrapper.h"
#include "../csources/r3types.h"
#include "../csources/r3util.h"
#include "../csources/inline.h"
Include dependency graph for readgriballwithouteccodes.c:

Go to the source code of this file.

Data Structures

struct  BitReader
 
struct  Sec1Info
 
struct  Sec3Grid
 
struct  Sec4Info
 
struct  Sec5Info
 
struct  Sec6Info
 
struct  MsgParse
 

Macros

#define GRIB_DEBUG   0 /* set to 0 to disable diagnostics */
 GRIB2 reader without ecCodes/GLib Supports:
 

Functions

char * gribReaderVersion (char *str, size_t maxLen)
 return type of reader
 
static uint8_t rdU8 (const uint8_t *p)
 
static uint16_t rdU16BE (const uint8_t *p)
 
static uint32_t rdU32BE (const uint8_t *p)
 
static int32_t rdI32BE (const uint8_t *p)
 
static uint64_t rdU64BE (const uint8_t *p)
 
static int16_t readS16beFlexible (const uint8_t *p)
 
static float rdIEEE32BE (const uint8_t *p)
 
static void bitInit (BitReader *br, const uint8_t *buf, size_t len)
 
static uint32_t bitGet (BitReader *br, int nbits)
 
static void strCopySafe (char *dst, size_t cap, const char *src)
 
static size_t updateLongUnique (long value, size_t n, size_t maxN, long arr[])
 
static void sortLongAsc (long *a, size_t n)
 
static const uint8_t * findNextGrib (const uint8_t *p, const uint8_t *end)
 
static bool isCurrentTriplet (int disc, int cat, int par, bool *isU)
 
static const char * shortNameFor (int disc, int cat, int par)
 
static int unitToHours (uint8_t unit, int32_t val)
 
static int scoreHours (int h)
 
static int pdtLeadHours (int pdtn, const uint8_t *pdt, uint32_t pdtLen)
 
static bool parseSec1 (const uint8_t *s, uint32_t bodyLen, Sec1Info *out)
 
static bool parseSec3LatLon (const uint8_t *s, uint32_t bodyLen, Sec3Grid *out)
 
static bool scanIPlus (int scan)
 
static bool scanJPlus (int scan)
 
static bool scanAdjI (int scan)
 
static bool scanBoustro (int scan)
 
static bool parseSec4 (const uint8_t *s, uint32_t bodyLen, int discipline, Sec4Info *out)
 
static bool parseSec5 (const uint8_t *s, uint32_t bodyLen, Sec5Info *out)
 
static int bmBitAt (const uint8_t *bm, size_t bmBytes, size_t k)
 
static int parseGrib2Message (const uint8_t *buf, size_t len, int wantData, MsgParse *out, float **outValues)
 
static long indLat (double lat, const Zone *zone)
 
static long indLonWrap (double lon, const Zone *zone)
 
static long idxTij (int iT, int iLon, int iLat, const Zone *zone)
 
static int findTimeIndex (long timeStep, const Zone *zone)
 
bool readGribLists (const char *fileName, Zone *zone)
 Read lists zone.timeStamp, shortName, zone.dataDate, dataTime before full grib reading.
 
bool readGribParameters (const char *fileName, Zone *zone)
 Read grib parameters in zone before full grib reading.
 
bool readGribAll (const char *fileName, Zone *zone, int iFlow)
 read grib file using eccodes C API return true if OK
 

Variables

FlowPtGribData [2] = {NULL, NULL}
 grib data description
 

Macro Definition Documentation

◆ GRIB_DEBUG

#define GRIB_DEBUG   0 /* set to 0 to disable diagnostics */

GRIB2 reader without ecCodes/GLib Supports:

  • Section 3: GDT 3.0 (regular lat/lon), di/dj signs from La2/Lo2 (wrap 360°)
  • Section 4: PDT 4.x (lead time extracted), minimal metadata
  • Section 5: DRT 5.0 (simple packing) and 5.3 (IEEE float)
  • Section 6: bitmap indicator 255 (none) or 0 (bitmap here). 254 (prev) -> unsupported
  • Section 7: data unpacking with/without bitmap Variables mapped:
  • discipline 0, cat 2, param 2 -> "10u" (10 m U wind)
  • discipline 0, cat 2, param 3 -> "10v" (10 m V wind)
  • discipline 0, cat 2, param 22 -> "gust" (wind gust)
  • discipline 10, cat 0, param {3,5,8} -> "swh" (WW3 heights: HTSGW/WVHGT/SWELL) Only these 4 contribute to timeStamp list and to FlowP fields. Fot current, ucurr and vcurr replace 10 and 10v.

Build example: gcc -O2 -Wall -Wextra -c readgriballwithouteccodes.c

Definition at line 37 of file readgriballwithouteccodes.c.

Function Documentation

◆ bitGet()

static uint32_t bitGet ( BitReader br,
int  nbits 
)
static

Definition at line 84 of file readgriballwithouteccodes.c.

References BitReader::bitpos, BitReader::buf, and BitReader::len.

Referenced by parseGrib2Message().

Here is the caller graph for this function:

◆ bitInit()

static void bitInit ( BitReader br,
const uint8_t *  buf,
size_t  len 
)
static

Definition at line 81 of file readgriballwithouteccodes.c.

References BitReader::bitpos, BitReader::buf, and BitReader::len.

Referenced by parseGrib2Message().

Here is the caller graph for this function:

◆ bmBitAt()

static int bmBitAt ( const uint8_t *  bm,
size_t  bmBytes,
size_t  k 
)
static

Definition at line 414 of file readgriballwithouteccodes.c.

Referenced by parseGrib2Message().

Here is the caller graph for this function:

◆ findNextGrib()

static const uint8_t * findNextGrib ( const uint8_t *  p,
const uint8_t *  end 
)
static

Definition at line 132 of file readgriballwithouteccodes.c.

Referenced by readGribAll(), and readGribLists().

Here is the caller graph for this function:

◆ findTimeIndex()

static int findTimeIndex ( long  timeStep,
const Zone zone 
)
static

Definition at line 575 of file readgriballwithouteccodes.c.

References Zone::nTimeStamp, Zone::timeStamp, and zone.

Referenced by readGribAll().

Here is the caller graph for this function:

◆ gribReaderVersion()

char * gribReaderVersion ( char *  str,
size_t  maxLen 
)

return type of reader

return version of ECCODE API

Definition at line 41 of file readgriballwithouteccodes.c.

Referenced by testToJson().

Here is the caller graph for this function:

◆ idxTij()

static long idxTij ( int  iT,
int  iLon,
int  iLat,
const Zone zone 
)
inlinestatic

Definition at line 569 of file readgriballwithouteccodes.c.

References Zone::nbLat, Zone::nbLon, and zone.

Referenced by readGribAll().

Here is the caller graph for this function:

◆ indLat()

static long indLat ( double  lat,
const Zone zone 
)
inlinestatic

Definition at line 551 of file readgriballwithouteccodes.c.

References Zone::latMin, Zone::latStep, and zone.

Referenced by readGribAll().

Here is the caller graph for this function:

◆ indLonWrap()

static long indLonWrap ( double  lon,
const Zone zone 
)
inlinestatic

Definition at line 556 of file readgriballwithouteccodes.c.

References Zone::lonLeft, Zone::lonStep, Zone::nbLon, and zone.

Referenced by readGribAll().

Here is the caller graph for this function:

◆ isCurrentTriplet()

static bool isCurrentTriplet ( int  disc,
int  cat,
int  par,
bool *  isU 
)
static

Definition at line 140 of file readgriballwithouteccodes.c.

References par.

Referenced by readGribAll(), readGribLists(), and shortNameFor().

Here is the caller graph for this function:

◆ parseGrib2Message()

◆ parseSec1()

static bool parseSec1 ( const uint8_t *  s,
uint32_t  bodyLen,
Sec1Info out 
)
static

Definition at line 246 of file readgriballwithouteccodes.c.

References Sec1Info::centerId, rdU16BE(), rdU8(), Sec1Info::refDay, Sec1Info::refHour, Sec1Info::refMinute, Sec1Info::refMonth, Sec1Info::refSecond, Sec1Info::refYear, Sec1Info::subcenterId, and Sec1Info::tableVersion.

Referenced by parseGrib2Message(), readGribLists(), and readGribParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseSec3LatLon()

static bool parseSec3LatLon ( const uint8_t *  s,
uint32_t  bodyLen,
Sec3Grid out 
)
static

Definition at line 271 of file readgriballwithouteccodes.c.

References Sec3Grid::di, Sec3Grid::dj, Sec3Grid::lat1, Sec3Grid::lon1, Sec3Grid::Ni, Sec3Grid::Nj, rdU16BE(), rdU32BE(), rdU8(), and Sec3Grid::scanFlags.

Referenced by parseGrib2Message(), and readGribParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseSec4()

static bool parseSec4 ( const uint8_t *  s,
uint32_t  bodyLen,
int  discipline,
Sec4Info out 
)
static

Definition at line 348 of file readgriballwithouteccodes.c.

References Sec4Info::category, Sec4Info::discipline, Sec4Info::parameter, Sec4Info::pdt, Sec4Info::pdtLen, Sec4Info::pdtn, rdU16BE(), and rdU8().

Referenced by parseGrib2Message(), and readGribLists().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseSec5()

static bool parseSec5 ( const uint8_t *  s,
uint32_t  bodyLen,
Sec5Info out 
)
static

Definition at line 371 of file readgriballwithouteccodes.c.

References Sec5Info::bScale, Sec5Info::drt, Sec5Info::dScale, Sec5Info::nBits, rdIEEE32BE(), rdU16BE(), rdU8(), readS16beFlexible(), and Sec5Info::refV.

Referenced by parseGrib2Message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pdtLeadHours()

static int pdtLeadHours ( int  pdtn,
const uint8_t *  pdt,
uint32_t  pdtLen 
)
static

Definition at line 205 of file readgriballwithouteccodes.c.

References scoreHours(), and unitToHours().

Referenced by readGribAll(), and readGribLists().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdI32BE()

static int32_t rdI32BE ( const uint8_t *  p)
inlinestatic

Definition at line 50 of file readgriballwithouteccodes.c.

References rdU32BE().

Here is the call graph for this function:

◆ rdIEEE32BE()

static float rdIEEE32BE ( const uint8_t *  p)
inlinestatic

Definition at line 68 of file readgriballwithouteccodes.c.

References rdU32BE().

Referenced by parseGrib2Message(), and parseSec5().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdU16BE()

static uint16_t rdU16BE ( const uint8_t *  p)
inlinestatic

Definition at line 48 of file readgriballwithouteccodes.c.

Referenced by parseSec1(), parseSec3LatLon(), parseSec4(), parseSec5(), and readS16beFlexible().

Here is the caller graph for this function:

◆ rdU32BE()

static uint32_t rdU32BE ( const uint8_t *  p)
inlinestatic

Definition at line 49 of file readgriballwithouteccodes.c.

Referenced by parseGrib2Message(), parseSec3LatLon(), rdI32BE(), rdIEEE32BE(), rdU64BE(), readGribLists(), and readGribParameters().

Here is the caller graph for this function:

◆ rdU64BE()

static uint64_t rdU64BE ( const uint8_t *  p)
inlinestatic

Definition at line 51 of file readgriballwithouteccodes.c.

References rdU32BE().

Referenced by parseGrib2Message(), readGribAll(), readGribLists(), and readGribParameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdU8()

static uint8_t rdU8 ( const uint8_t *  p)
inlinestatic

Definition at line 47 of file readgriballwithouteccodes.c.

Referenced by parseGrib2Message(), parseSec1(), parseSec3LatLon(), parseSec4(), parseSec5(), readGribAll(), readGribLists(), and readGribParameters().

Here is the caller graph for this function:

◆ readGribAll()

◆ readGribLists()

◆ readGribParameters()

bool readGribParameters ( const char *  fileName,
Zone zone 
)

◆ readS16beFlexible()

static int16_t readS16beFlexible ( const uint8_t *  p)
static

Definition at line 56 of file readgriballwithouteccodes.c.

References rdU16BE().

Referenced by parseSec5().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanAdjI()

static bool scanAdjI ( int  scan)
inlinestatic

Definition at line 337 of file readgriballwithouteccodes.c.

Referenced by readGribAll().

Here is the caller graph for this function:

◆ scanBoustro()

static bool scanBoustro ( int  scan)
inlinestatic

Definition at line 338 of file readgriballwithouteccodes.c.

Referenced by readGribAll().

Here is the caller graph for this function:

◆ scanIPlus()

static bool scanIPlus ( int  scan)
inlinestatic

Definition at line 335 of file readgriballwithouteccodes.c.

◆ scanJPlus()

static bool scanJPlus ( int  scan)
inlinestatic

Definition at line 336 of file readgriballwithouteccodes.c.

◆ scoreHours()

static int scoreHours ( int  h)
static

Definition at line 187 of file readgriballwithouteccodes.c.

Referenced by pdtLeadHours().

Here is the caller graph for this function:

◆ shortNameFor()

static const char * shortNameFor ( int  disc,
int  cat,
int  par 
)
static

Definition at line 159 of file readgriballwithouteccodes.c.

References isCurrentTriplet(), and par.

Referenced by parseGrib2Message(), readGribAll(), and readGribLists().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sortLongAsc()

static void sortLongAsc ( long *  a,
size_t  n 
)
static

Definition at line 124 of file readgriballwithouteccodes.c.

Referenced by readGribLists().

Here is the caller graph for this function:

◆ strCopySafe()

static void strCopySafe ( char *  dst,
size_t  cap,
const char *  src 
)
static

Definition at line 111 of file readgriballwithouteccodes.c.

Referenced by readGribLists().

Here is the caller graph for this function:

◆ unitToHours()

static int unitToHours ( uint8_t  unit,
int32_t  val 
)
static

Definition at line 172 of file readgriballwithouteccodes.c.

Referenced by pdtLeadHours().

Here is the caller graph for this function:

◆ updateLongUnique()

static size_t updateLongUnique ( long  value,
size_t  n,
size_t  maxN,
long  arr[] 
)
static

Definition at line 118 of file readgriballwithouteccodes.c.

Referenced by readGribLists().

Here is the caller graph for this function:

Variable Documentation

◆ tGribData

FlowP* tGribData[2] = {NULL, NULL}