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

Go to the source code of this file.

Macros

#define EPSILON   0.001
 compilation: gcc -c grib.c pkg-config --cflags glib-2.0
 

Functions

double zoneTimeDiff (const Zone *zone1, const Zone *zone0)
 return difference in hours between two zones (current zone and Wind zone)
 
float * buildUVGWarray (const Zone *zone, const char *initialOfNames, const FlowP *gribData, size_t *outNValues)
 return array of outNvalues floats n = nTimeStamp * nbLat * nbLon * nShortNames values = [u1, v0, g0, w0, u1, v1, g1, w1, ...] g, w are optionnal
 
void printGrib (const Zone *zone, const FlowP *gribData)
 print Grib u v ... for all lat lon time information
 
static bool checkGrib (const Zone *zone, int iFlow, CheckGrib *check)
 
static bool geoIntersectGrib (const Zone *zone1, const Zone *zone2)
 true if (wind) zone and currentZone intersect in geography
 
static bool timeIntersectGrib (const Zone *zone1, const Zone *zone2)
 true if (wind) zone and zone 2 intersect in time
 
static bool timeStepRegularGrib (const Zone *zone)
 check if time steps are regular
 
bool uvPresentGrib (const Zone *zone)
 true if u and v (or uCurr, vCurr) are in zone
 
bool isPresentGrib (const Zone *zone, const char *name)
 true if shortname in zone
 
static int consistentGrib (const Zone *zone, int iFlow, double epsilon, int *nLatSuspects, int *nLonSuspects)
 check lat, lon are consistent with indice return number of values
 
bool checkGribInfoToStr (int type, Zone *zone, char *buffer, size_t maxLen)
 check Grib information and write (add) report in the buffer return false if something wrong

 
bool checkGribToStr (bool hasCurrentGrib, char *buffer, size_t maxLen)
 check Grib information and write report in the buffer return false if something wrong

 
static void findTimeAround (double t, int *iTInf, int *iTSup, const Zone *zone)
 find iTinf and iTsup in order t : zone.timeStamp [iTInf] <= t <= zone.timeStamp [iTSup]
 
static double arrondiMin (double v, double step)
 ex arrondiMin (46.4, 0.25) = 46.25
 
static double arrondiMax (double v, double step)
 ex arrondiMax (46.4, 0.25) = 46.50
 
static void find4PointsAround (double lat, double lon, double *latMin, double *latMax, double *lonMin, double *lonMax, Zone *zone)
 provide 4 wind points around point lat, lon
 
static long indLat (double lat, const Zone *zone)
 return indice of lat in gribData wind or current

 
static long indLon (double lon, const Zone *zone)
 return indice of lon in gribData wind or current
 
static bool findFlow (double lat, double lon, double t, double *rU, double *rV, double *rG, double *rW, Zone *zone, const FlowP *gribData)
 interpolation to get u, v, g (gust), w (waves) at point (lat, lon) and time t
 
void findWindGrib (double lat, double lon, double t, double *u, double *v, double *gust, double *w, double *twd, double *tws)
 use findflow to get wind and waves
 
void findCurrentGrib (double lat, double lon, double t, double *uCurr, double *vCurr, double *tcd, double *tcs)
 use findflow to get current
 
char * gribToStr (const Zone *zone, char *str, size_t maxLen)
 write Grib information in string
 
char * gribToStrJson (const char *fileName, char *out, size_t maxLen)
 write grib meta information in string
 

Macro Definition Documentation

◆ EPSILON

#define EPSILON   0.001

compilation: gcc -c grib.c pkg-config --cflags glib-2.0

Definition at line 16 of file r3grib.c.

Function Documentation

◆ arrondiMax()

static double arrondiMax ( double  v,
double  step 
)
inlinestatic

ex arrondiMax (46.4, 0.25) = 46.50

Definition at line 373 of file r3grib.c.

Referenced by find4PointsAround().

Here is the caller graph for this function:

◆ arrondiMin()

static double arrondiMin ( double  v,
double  step 
)
inlinestatic

ex arrondiMin (46.4, 0.25) = 46.25

Definition at line 368 of file r3grib.c.

Referenced by find4PointsAround().

Here is the caller graph for this function:

◆ buildUVGWarray()

float * buildUVGWarray ( const Zone zone,
const char *  initialOfNames,
const FlowP gribData,
size_t *  outNValues 
)

return array of outNvalues floats n = nTimeStamp * nbLat * nbLon * nShortNames values = [u1, v0, g0, w0, u1, v1, g1, w1, ...] g, w are optionnal

Definition at line 33 of file r3grib.c.

References FlowP::g, Zone::nbLat, Zone::nbLon, Zone::nTimeStamp, FlowP::u, FlowP::v, FlowP::w, and zone.

Referenced by launchAction().

Here is the caller graph for this function:

◆ checkGrib()

◆ checkGribInfoToStr()

bool checkGribInfoToStr ( int  type,
Zone zone,
char *  buffer,
size_t  maxLen 
)

◆ checkGribToStr()

bool checkGribToStr ( bool  hasCurrentGrib,
char *  buffer,
size_t  maxLen 
)

check Grib information and write report in the buffer return false if something wrong

Definition at line 316 of file r3grib.c.

References checkGribInfoToStr(), CURRENT, currentZone, g_strlcat, geoIntersectGrib(), MAX_SIZE_LINE, Zone::nbLat, timeIntersectGrib(), WIND, and zone.

Referenced by launchAction(), and optionManage().

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

◆ consistentGrib()

static int consistentGrib ( const Zone zone,
int  iFlow,
double  epsilon,
int *  nLatSuspects,
int *  nLonSuspects 
)
static

check lat, lon are consistent with indice return number of values

Definition at line 178 of file r3grib.c.

References Zone::anteMeridian, Zone::latMin, Zone::latStep, lonCanonize(), Zone::lonLeft, Zone::lonStep, Zone::nbLat, Zone::nbLon, Zone::nTimeStamp, tGribData, and zone.

Referenced by checkGribInfoToStr().

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

◆ find4PointsAround()

static void find4PointsAround ( double  lat,
double  lon,
double *  latMin,
double *  latMax,
double *  lonMin,
double *  lonMax,
Zone zone 
)
inlinestatic

provide 4 wind points around point lat, lon

Definition at line 378 of file r3grib.c.

References arrondiMax(), arrondiMin(), Zone::latMax, Zone::latMin, Zone::latStep, Zone::lonLeft, Zone::lonRight, Zone::lonStep, and zone.

Referenced by findFlow().

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

◆ findCurrentGrib()

void findCurrentGrib ( double  lat,
double  lon,
double  t,
double *  uCurr,
double *  vCurr,
double *  tcd,
double *  tcs 
)

use findflow to get current

Definition at line 507 of file r3grib.c.

References Par::constCurrentD, Par::constCurrentS, CURRENT, currentZone, DEG_TO_RAD, findFlow(), fTwd(), fTws(), KN_TO_MS, Zone::nTimeStamp, par, tGribData, and Zone::timeStamp.

Referenced by buildNextIsochrone().

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

◆ findFlow()

static bool findFlow ( double  lat,
double  lon,
double  t,
double *  rU,
double *  rV,
double *  rG,
double *  rW,
Zone zone,
const FlowP gribData 
)
static

interpolation to get u, v, g (gust), w (waves) at point (lat, lon) and time t

Definition at line 410 of file r3grib.c.

References Par::constWindTws, find4PointsAround(), findTimeAround(), FlowP::g, indLat(), indLon(), interpolate(), isInZone(), FlowP::lat, FlowP::lon, Zone::nbLat, Zone::nbLon, par, Zone::timeStamp, FlowP::u, FlowP::v, FlowP::w, Zone::wellDefined, and zone.

Referenced by findCurrentGrib(), and findWindGrib().

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

◆ findTimeAround()

static void findTimeAround ( double  t,
int *  iTInf,
int *  iTSup,
const Zone zone 
)
inlinestatic

find iTinf and iTsup in order t : zone.timeStamp [iTInf] <= t <= zone.timeStamp [iTSup]

Definition at line 344 of file r3grib.c.

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

Referenced by findFlow().

Here is the caller graph for this function:

◆ findWindGrib()

void findWindGrib ( double  lat,
double  lon,
double  t,
double *  u,
double *  v,
double *  gust,
double *  w,
double *  twd,
double *  tws 
)

use findflow to get wind and waves

Definition at line 488 of file r3grib.c.

References Par::constWave, Par::constWindTwd, Par::constWindTws, DEG_TO_RAD, findFlow(), fTwd(), fTws(), KN_TO_MS, par, tGribData, WIND, and zone.

Referenced by buildNextIsochrone(), goalP(), infoCoordToJson(), simpleGoalP(), and statRoute().

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

◆ geoIntersectGrib()

static bool geoIntersectGrib ( const Zone zone1,
const Zone zone2 
)
static

true if (wind) zone and currentZone intersect in geography

Definition at line 120 of file r3grib.c.

References Zone::latMax, Zone::latMin, Zone::lonLeft, and Zone::lonRight.

Referenced by checkGribToStr().

Here is the caller graph for this function:

◆ gribToStr()

char * gribToStr ( const Zone zone,
char *  str,
size_t  maxLen 
)

◆ gribToStrJson()

char * gribToStrJson ( const char *  fileName,
char *  out,
size_t  maxLen 
)

◆ indLat()

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

return indice of lat in gribData wind or current

Definition at line 399 of file r3grib.c.

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

Referenced by findFlow().

Here is the caller graph for this function:

◆ indLon()

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

return indice of lon in gribData wind or current

Definition at line 404 of file r3grib.c.

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

Referenced by findFlow().

Here is the caller graph for this function:

◆ isPresentGrib()

bool isPresentGrib ( const Zone zone,
const char *  name 
)

true if shortname in zone

Definition at line 169 of file r3grib.c.

References name, Zone::nShortName, Zone::shortName, and zone.

Referenced by buildInitialOfShortNameList().

Here is the caller graph for this function:

◆ printGrib()

void printGrib ( const Zone zone,
const FlowP gribData 
)

print Grib u v ... for all lat lon time information

Definition at line 69 of file r3grib.c.

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

Referenced by optionManage().

Here is the caller graph for this function:

◆ timeIntersectGrib()

static bool timeIntersectGrib ( const Zone zone1,
const Zone zone2 
)
static

true if (wind) zone and zone 2 intersect in time

Definition at line 129 of file r3grib.c.

References Zone::dataDate, Zone::dataTime, and gribDateTimeToEpoch().

Referenced by checkGribToStr().

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

◆ timeStepRegularGrib()

static bool timeStepRegularGrib ( const Zone zone)
static

check if time steps are regular

Definition at line 139 of file r3grib.c.

References Zone::intervalBegin, Zone::intervalEnd, Zone::intervalLimit, Zone::nTimeStamp, Zone::timeStamp, and zone.

Referenced by checkGribInfoToStr().

Here is the caller graph for this function:

◆ uvPresentGrib()

bool uvPresentGrib ( const Zone zone)

true if u and v (or uCurr, vCurr) are in zone

Definition at line 155 of file r3grib.c.

References Zone::nShortName, Zone::shortName, and zone.

Referenced by buildInitialOfShortNameList(), and checkGribInfoToStr().

Here is the caller graph for this function:

◆ zoneTimeDiff()

double zoneTimeDiff ( const Zone zone1,
const Zone zone0 
)

return difference in hours between two zones (current zone and Wind zone)

Definition at line 19 of file r3grib.c.

References Zone::dataDate, Zone::dataTime, gribDateTimeToEpoch(), and Zone::wellDefined.

Referenced by initRouting().

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