RCube
Rcube Rest Server calculates sail routes based on Grib files and sailing boat polar files
Loading...
Searching...
No Matches
r3util.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * epochToStr (time_t t, bool seconds, char *str, size_t len)
 functions defined in r3util.c
 
struct tm gribDateToTm (long intDate, double nHours)
 return tm struct equivalent to date hours found in grib (UTC time) struct tm gribDateToTm (long intDate, double nHours) { struct tm tm0 = {0}; tm0.tm_year = (intDate / 10000) - 1900; tm0.tm_mon = ((intDate % 10000) / 100) - 1; tm0.tm_mday = intDate % 100; tm0.tm_isdst = -1;
const int totalMinutes = (int)(nHours * 60); tm0.tm_min += totalMinutes; // adjust tm0 struct (manage day, mon year overflow) mktime (&tm0);
return tm0; }
 
bool isDayLight (struct tm *tm0, double t, double lat, double lon)
 
char * fSailName (int val, char *str, size_t maxLen)
 return the name of the sail
 
char * newFileNameSuffix (const char *fileName, const char *suffix, char *newFileName, size_t maxLen)
 replace former suffix (after last dot) by suffix example : "pol/bibi.toto.csv" with suffix "sailpol" will give: "pol/bibi.toto.sailpol"
 
double offsetLocalUTC (void)
 return offset Local UTC in seconds
 
char * formatThousandSep (char *buffer, size_t maxLen, int value)
 
char * buildRootName (const char *fileName, char *rootName, size_t maxLen)
 Build root name if not already a root name.
 
bool isNumber (const char *name)
 true if name contains a number
 
double getCoord (const char *str, double min, double max)
 translate str in double for latitude longitude
 
char * latToStr (double lat, int type, char *str, size_t maxLen)
 convert lat to str according to type
 
char * lonToStr (double lon, int type, char *str, size_t maxLen)
 convert lon to str according to type
 
char * durationToStr (double duration, char *res, size_t maxLen)
 convert hours in string with days, hours, minutes
 
time_t gribDateTimeToEpoch (long date, long time)
 convert long date/time from GRIB to time_t (UTC, via timegm)
 
double getDepartureTimeInHour (struct tm *startUtc)
 calculate difference in hours between departure time in UTC and time 0
 
char * gribDateTimeToStr (long date, long time, char *str, size_t len)
 return str representing grib date
 
char * newDate (long intDate, double myTime, char *res, size_t maxLen)
 return date and time using ISO notation after adding myTime (hours) to the Date
 
char * newDateWeekDay (long intDate, double myTime, char *res, size_t maxLen)
 return date and time using week day after adding myTime (hours) to the Date
 
char * newDateWeekDayVerbose (long intDate, double myTime, char *res, size_t maxLen)
 return date and time using week day after adding myTime (hours) to the Date
 
bool readParam (const char *fileName, bool initDisp)
 read parameter file and build par struct
 
bool writeParam (const char *fileName, bool header, bool password, bool yaml)
 write parameter file from struct par header or not, password or not yaml style or not
 
bool readIsSea (const char *fileName)
 read issea file and fill table tIsSea
 
void updateIsSeaWithForbiddenAreas (void)
 complement according to forbidden areas
 
bool hasSlash (const char *name)
 true if name terminates with slash
 
bool mostRecentFile (const char *directory, const char *pattern0, const char *pattern1, char *name, size_t maxLen)
 select most recent file in "directory" that contains "pattern0" and "pattern1" in name return true if found with name of selected file
 
double fPenalty (int shipIndex, int type, double tws, double energy, double *cStamina)
 
double fPointLoss (int shipIndex, int type, double tws, bool fullPack)
 for virtual Regatta.
 
double fTimeToRecupOnePoint (double tws)
 for virtual Regatta.
 
char * paramToStrJson (Par *par, char *buffer, size_t maxLen)
 Return JSON formatted subset of parameters into 'out'.
 
int nearestPort (double lat, double lon, const char *fileName, char *str, size_t maxLen)
 return id and name of nearest port found in file fileName from lat, lon.
 
double monotonic (void)
 return seconds with decimals
 
char * readTextFile (const char *fileName, char *errMessage, size_t maxLen)
 read all text file in buffer.
 
bool readMarkCSVToJson (const char *fileName, char *out, size_t maxLen)
 read CSV file marks (Virtual Regatta) if check then polarCheck
 
void normalizeSpaces (char *s)
 replace multiple spaces by just one
 

Variables

Zone zone
 Zone description.
 
Zone currentZone
 
WayPointList wayPoints
 list of wayPoint
 
MyPolygon forbidZones [MAX_N_FORBID_ZONE]
 forbid zones
 
struct MeteoElmt meteoTab [N_METEO_ADMIN]
 Meteo service.
 
const size_t sailNameSize
 sail attributes
 
const char * sailName []
 
const char * colorStr []
 
PolMat polMat
 polar description
 
PolMat sailPolMat
 polar matrix for sails
 
PolMat wavePolMat
 polar matrix for waves
 
Par par
 parameters desciption
 
char * tIsSea
 table describing if sea or earth
 
CompetitorsList competitors
 for competitors
 

Function Documentation

◆ buildRootName()

char * buildRootName ( const char *  fileName,
char *  rootName,
size_t  maxLen 
)
extern

Build root name if not already a root name.

Combines the working directory with the file name if it is not absolute. Stores the result in rootName and ensures it does not exceed maxLen.

Parameters
fileNameThe name of the file (absolute or relative).
rootNameThe buffer to store the resulting root name.
maxLenThe maximum length of the buffer rootName.
Returns
A pointer to rootName, or NULL on error.

abolute path POSIX : begin with '/'

Definition at line 230 of file r3util.c.

References hasSlash(), par, WORKING_DIR, and Par::workingDir.

Referenced by checkParamAndUpdate(), gribToStrJson(), launchAction(), polToStrJson(), readParam(), updateCurrentGrib(), and updateWindGrib().

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

◆ durationToStr()

char * durationToStr ( double  duration,
char *  res,
size_t  maxLen 
)
extern

convert hours in string with days, hours, minutes

Definition at line 429 of file r3util.c.

Referenced by routeToStr().

Here is the caller graph for this function:

◆ epochToStr()

char * epochToStr ( time_t  t,
bool  seconds,
char *  str,
size_t  maxLen 
)
extern

functions defined in r3util.c

functions defined in r3util.c

Definition at line 247 of file r3util.c.

Referenced by optionManage().

Here is the caller graph for this function:

◆ formatThousandSep()

char * formatThousandSep ( char *  buffer,
size_t  maxLen,
int  value 
)
extern

◆ fPenalty()

double fPenalty ( int  shipIndex,
int  type,
double  tws,
double  energy,
double *  cStamina 
)
extern

◆ fPointLoss()

double fPointLoss ( int  shipIndex,
int  type,
double  tws,
bool  fullPack 
)
extern

for virtual Regatta.

return point loss with manoeuvre types. Depends on tws and fullPack

Definition at line 1002 of file r3util.c.

References cShip, fTws(), and shipParam.

Referenced by statRoute().

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

◆ fSailName()

char * fSailName ( int  val,
char *  str,
size_t  maxLen 
)
extern

return the name of the sail

Definition at line 68 of file r3util.c.

References g_strlcpy, PolMat::name, PolMat::nSail, polMat, and PolMat::tSail.

Referenced by routeToJson(), and routeToStr().

Here is the caller graph for this function:

◆ fTimeToRecupOnePoint()

double fTimeToRecupOnePoint ( double  tws)
extern

for virtual Regatta.

return type in second to get back one energy point

Definition at line 1014 of file r3util.c.

References fTws(), and G_PI.

Referenced by statRoute().

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

◆ getCoord()

double getCoord ( const char *  str,
double  min,
double  max 
)
extern

translate str in double for latitude longitude

Definition at line 179 of file r3util.c.

References CLAMP.

Referenced by forbidZoneAdd(), readMarkCSVToJson(), and readParam().

Here is the caller graph for this function:

◆ getDepartureTimeInHour()

double getDepartureTimeInHour ( struct tm *  startUtc)
extern

calculate difference in hours between departure time in UTC and time 0

Definition at line 420 of file r3util.c.

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

Here is the call graph for this function:

◆ gribDateTimeToEpoch()

time_t gribDateTimeToEpoch ( long  date,
long  time 
)
extern

convert long date/time from GRIB to time_t (UTC, via timegm)

Definition at line 408 of file r3util.c.

Referenced by checkParamAndUpdate(), getDepartureTimeInHour(), gribToStrJson(), infoCoordToJson(), optionManage(), timeIntersectGrib(), and zoneTimeDiff().

Here is the caller graph for this function:

◆ gribDateTimeToStr()

char * gribDateTimeToStr ( long  date,
long  time,
char *  str,
size_t  len 
)
extern

return str representing grib date

Definition at line 276 of file r3util.c.

Referenced by initContext(), and optionManage().

Here is the caller graph for this function:

◆ gribDateToTm()

struct tm gribDateToTm ( long  intDate,
double  nHours 
)
extern

return tm struct equivalent to date hours found in grib (UTC time) struct tm gribDateToTm (long intDate, double nHours) { struct tm tm0 = {0}; tm0.tm_year = (intDate / 10000) - 1900; tm0.tm_mon = ((intDate % 10000) / 100) - 1; tm0.tm_mday = intDate % 100; tm0.tm_isdst = -1;
const int totalMinutes = (int)(nHours * 60); tm0.tm_min += totalMinutes; // adjust tm0 struct (manage day, mon year overflow) mktime (&tm0);
return tm0; }

Definition at line 299 of file r3util.c.

Referenced by newDate(), newDateWeekDay(), and newDateWeekDayVerbose().

Here is the caller graph for this function:

◆ hasSlash()

bool hasSlash ( const char *  name)
extern

true if name terminates with slash

Definition at line 130 of file r3util.c.

References name.

Referenced by buildRootName(), checkParamAndUpdate(), initContext(), launchAction(), and mostRecentFile().

Here is the caller graph for this function:

◆ isDayLight()

bool isDayLight ( struct tm *  tm0,
double  t,
double  lat,
double  lon 
)
extern

◆ isNumber()

bool isNumber ( const char *  name)
extern

true if name contains a number

Definition at line 174 of file r3util.c.

References name.

Referenced by strtodNew().

Here is the caller graph for this function:

◆ latToStr()

char * latToStr ( double  lat,
int  type,
char *  str,
size_t  maxLen 
)
extern

convert lat to str according to type

Definition at line 440 of file r3util.c.

References BASIC, DD, DM, DMS, and g_strlcpy.

Referenced by gribToStr(), isoDescToStr(), logReport(), routeToStr(), and writeParam().

Here is the caller graph for this function:

◆ lonToStr()

char * lonToStr ( double  lon,
int  type,
char *  str,
size_t  maxLen 
)
extern

convert lon to str according to type

Definition at line 462 of file r3util.c.

References BASIC, DD, DM, DMS, and g_strlcpy.

Referenced by gribToStr(), isoDescToStr(), logReport(), routeToStr(), and writeParam().

Here is the caller graph for this function:

◆ monotonic()

double monotonic ( void  )
extern

return seconds with decimals

Definition at line 1099 of file r3util.c.

Referenced by handleClient(), main(), and optionManage().

Here is the caller graph for this function:

◆ mostRecentFile()

bool mostRecentFile ( const char *  directory,
const char *  pattern0,
const char *  pattern1,
char *  name,
size_t  maxLen 
)
extern

select most recent file in "directory" that contains "pattern0" and "pattern1" in name return true if found with name of selected file

Definition at line 138 of file r3util.c.

References hasSlash(), MAX_SIZE_DIR_NAME, MAX_SIZE_FILE_NAME, and name.

Referenced by checkParamAndUpdate(), initContext(), and launchAction().

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

◆ nearestPort()

int nearestPort ( double  lat,
double  lon,
const char *  fileName,
char *  res,
size_t  maxLen 
)
extern

return id and name of nearest port found in file fileName from lat, lon.

return empty string if not found

Definition at line 1063 of file r3util.c.

References g_strlcpy, g_strstrip(), MAX_SIZE_LINE, MAX_SIZE_NAME, and orthoDist().

Referenced by nearestPortToStrJson().

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

◆ newDate()

char * newDate ( long  intDate,
double  myTime,
char *  res,
size_t  maxLen 
)
extern

return date and time using ISO notation after adding myTime (hours) to the Date

Definition at line 386 of file r3util.c.

References gribDateToTm().

Referenced by allCompetitors(), exportRouteToGpx(), gribToStr(), gribToStrJson(), logReport(), optionManage(), and routeToStr().

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

◆ newDateWeekDay()

char * newDateWeekDay ( long  intDate,
double  myTime,
char *  res,
size_t  maxLen 
)
extern

return date and time using week day after adding myTime (hours) to the Date

Definition at line 394 of file r3util.c.

References gribDateToTm().

Here is the call graph for this function:

◆ newDateWeekDayVerbose()

char * newDateWeekDayVerbose ( long  intDate,
double  myTime,
char *  res,
size_t  maxLen 
)
extern

return date and time using week day after adding myTime (hours) to the Date

Definition at line 401 of file r3util.c.

References gribDateToTm().

Here is the call graph for this function:

◆ newFileNameSuffix()

char * newFileNameSuffix ( const char *  fileName,
const char *  suffix,
char *  newFileName,
size_t  maxLen 
)
extern

replace former suffix (after last dot) by suffix example : "pol/bibi.toto.csv" with suffix "sailpol" will give: "pol/bibi.toto.sailpol"

Definition at line 78 of file r3util.c.

References g_strlcpy.

Referenced by readPolar().

Here is the caller graph for this function:

◆ normalizeSpaces()

void normalizeSpaces ( char *  s)
extern

replace multiple spaces by just one

Definition at line 1196 of file r3util.c.

Referenced by launchAction().

Here is the caller graph for this function:

◆ offsetLocalUTC()

double offsetLocalUTC ( void  )
extern

return offset Local UTC in seconds

Definition at line 263 of file r3util.c.

Referenced by optionManage().

Here is the caller graph for this function:

◆ paramToStrJson()

char * paramToStrJson ( Par par,
char *  out,
size_t  maxLen 
)
extern

Return JSON formatted subset of parameters into 'out'.

Returns out on success, NULL on error or truncation.

Definition at line 1023 of file r3util.c.

References Par::currentGribFileName, g_path_get_basename(), Par::gribFileName, Par::isSeaFileName, Zone::latMax, Zone::latMin, Zone::lonLeft, Zone::lonRight, par, Par::polarFileName, Par::wavePolFileName, Par::workingDir, and zone.

Referenced by launchAction().

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

◆ readIsSea()

bool readIsSea ( const char *  fileName)
extern

read issea file and fill table tIsSea

Definition at line 484 of file r3util.c.

References SIZE_T_IS_SEA, and tIsSea.

Referenced by initContext().

Here is the caller graph for this function:

◆ readMarkCSVToJson()

bool readMarkCSVToJson ( const char *  fileName,
char *  out,
size_t  maxLen 
)
extern

read CSV file marks (Virtual Regatta) if check then polarCheck

Definition at line 1144 of file r3util.c.

References g_strfreev(), g_strsplit(), g_strstrip(), getCoord(), MAX_LAT, MAX_LON, MAX_SIZE_TEXT, MAX_SIZE_TEXT_FILE, MIN_LAT, MIN_LON, and name.

Referenced by launchAction().

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

◆ readParam()

bool readParam ( const char *  fileName,
bool  initDisp 
)
extern

read parameter file and build par struct

Definition at line 573 of file r3util.c.

References Par::aisDisp, Par::allwaysSea, Par::authent, buildRootName(), CLAMP, Par::cliHelpFileName, Par::closestDisp, Par::cogStep, Competitor::colorIndex, competitors, Par::constCurrentD, Par::constCurrentS, Par::constWave, Par::constWindTwd, Par::constWindTws, Par::curlSys, Par::currentDisp, Par::currentGribFileName, Par::dashboardUTC, Par::dashboardVR, Par::dayEfficiency, Par::description, Par::dispDms, Par::dumpIFileName, Par::dumpRFileName, Pp::father, Par::feedbackFileName, Par::focalDisp, forbidZoneAdd(), g_strstrip(), getCoord(), Par::googleApiKey, Par::gribFileName, Par::gribResolution, Par::gribTimeMax, Par::gribTimeStep, Par::gridDisp, Par::helpFileName, Pp::id, Par::imapMailBox, Par::imapScript, Par::imapServer, Par::imapToSeen, Par::imapUserName, Par::indicatorDisp, Par::infoDisp, Par::isSeaFileName, Par::jFactor, Par::kFactor, Pp::lat, WayPoint::lat, Competitor::lat, Par::logFileName, Pp::lon, WayPoint::lon, Competitor::lon, Par::mailPw, Par::marksFileName, MAX_LAT, MAX_LON, MAX_N_COMPETITORS, MAX_N_FORBID_ZONE, MAX_N_SECTORS, MAX_N_SHP_FILES, MAX_N_WAY_POINT, MAX_SIZE_LINE, MAX_SIZE_NAME, MAX_SIZE_TEXT, Par::maxPoiVisible, Par::maxWind, Par::midFileName, MIN, MIN_LAT, MIN_LON, Par::mostRecentGrib, Par::motorSpeed, WayPointList::n, CompetitorsList::n, N_MAX_NMEA_PORTS, Competitor::name, Par::nForbidZone, Par::nightEfficiency, Par::nmea, Par::nNmea, Par::nSectors, Par::nShpFiles, Par::opt, par, Par::parInfoFileName, Par::pDest, Par::pDestName, Par::penalty0, Par::penalty1, Par::penalty2, Par::poiFileName, Par::polarFileName, Par::pOr, Par::pOrName, Par::portFileName, Par::portName, Par::python, Par::rangeCog, CompetitorsList::runIndex, Par::showColors, Par::shpFileName, Par::shpPointsDisp, Par::smtpScript, Par::smtpServer, Par::smtpTo, Par::smtpUserName, Par::special, Par::speed, Par::speedDisp, Par::staminaVR, Par::startTimeInHours, Par::stepIsocDisp, Par::storeMailPw, Par::style, CompetitorsList::t, WayPointList::t, Par::techno, Par::threshold, Par::tidesFileName, WayPointList::totLoxoDist, WayPointList::totOrthoDist, Par::traceFileName, Par::tStep, Par::waveDisp, Par::wavePolFileName, wayPoints, Par::web, Par::webkit, Par::windDisp, Par::windyApiKey, Par::withCurrent, Par::withWaves, Par::workingDir, Par::wpGpxFileName, and Par::xWind.

Referenced by initContext().

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

◆ readTextFile()

char * readTextFile ( const char *  fileName,
char *  errMessage,
size_t  maxLen 
)
extern

read all text file in buffer.

Allocate memory

Definition at line 1106 of file r3util.c.

Referenced by launchAction(), and readPolarJson().

Here is the caller graph for this function:

◆ updateIsSeaWithForbiddenAreas()

void updateIsSeaWithForbiddenAreas ( void  )
extern

complement according to forbidden areas

Definition at line 534 of file r3util.c.

References isInForbidArea(), Par::nForbidZone, par, SIZE_T_IS_SEA, and tIsSea.

Referenced by initContext().

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

◆ writeParam()

bool writeParam ( const char *  fileName,
bool  header,
bool  password,
bool  yaml 
)
extern

write parameter file from struct par header or not, password or not yaml style or not

Definition at line 826 of file r3util.c.

References Par::aisDisp, Par::allwaysSea, Par::authent, Par::cliHelpFileName, Par::closestDisp, Par::cogStep, Competitor::colorIndex, competitors, Par::constCurrentD, Par::constCurrentS, Par::constWave, Par::constWindTwd, Par::constWindTws, Par::curlSys, Par::currentDisp, Par::currentGribFileName, Par::dashboardUTC, Par::dashboardVR, Par::dayEfficiency, Par::description, Par::dispDms, Par::dumpIFileName, Par::dumpRFileName, Par::feedbackFileName, Par::focalDisp, forbidZones, fprintfNoNull(), fprintfNoZero(), Par::googleApiKey, Par::gribFileName, Par::gribResolution, Par::gribTimeMax, Par::gribTimeStep, Par::gridDisp, Par::helpFileName, Par::imapMailBox, Par::imapScript, Par::imapServer, Par::imapToSeen, Par::imapUserName, Par::indicatorDisp, Par::infoDisp, Par::isSeaFileName, Par::jFactor, Par::kFactor, Pp::lat, WayPoint::lat, Competitor::lat, latToStr(), Par::logFileName, Pp::lon, WayPoint::lon, Competitor::lon, lonToStr(), Par::mailPw, Par::marksFileName, MAX_SIZE_NAME, Par::maxPoiVisible, Par::maxWind, Par::midFileName, Par::mostRecentGrib, Par::motorSpeed, MyPolygon::n, WayPointList::n, CompetitorsList::n, Competitor::name, Par::nForbidZone, Par::nightEfficiency, Par::nmea, Par::nNmea, Par::nSectors, Par::nShpFiles, Par::opt, par, Par::parInfoFileName, Par::pDest, Par::pDestName, Par::penalty0, Par::penalty1, Par::penalty2, Par::poiFileName, Par::polarFileName, Par::pOr, Par::pOrName, Par::portFileName, Par::portName, Par::python, Par::rangeCog, Par::showColors, Par::shpFileName, Par::shpPointsDisp, Par::smtpScript, Par::smtpServer, Par::smtpTo, Par::smtpUserName, Par::special, Par::speed, Par::speedDisp, Par::staminaVR, Par::startTimeInHours, Par::stepIsocDisp, Par::style, CompetitorsList::t, WayPointList::t, Par::techno, Par::threshold, Par::tidesFileName, Par::traceFileName, Par::tStep, Par::waveDisp, Par::wavePolFileName, wayPoints, Par::web, Par::webkit, Par::windDisp, Par::windyApiKey, Par::withCurrent, Par::withWaves, Par::workingDir, Par::wpGpxFileName, and Par::xWind.

Referenced by launchAction().

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

Variable Documentation

◆ colorStr

const char* colorStr[]
extern

Definition at line 40 of file r3util.c.

◆ competitors

CompetitorsList competitors
extern

for competitors

for competitors

Definition at line 46 of file r3util.c.

Referenced by allCompetitors(), checkParamAndUpdate(), launchAction(), readParam(), routeToJson(), routeToStr(), routing(), routingLaunch(), and writeParam().

◆ currentZone

◆ forbidZones

MyPolygon forbidZones[MAX_N_FORBID_ZONE]
extern

forbid zones

forbid zones

Definition at line 32 of file r3util.c.

Referenced by forbidToJson(), forbidZoneAdd(), isInForbidArea(), and writeParam().

◆ meteoTab

struct MeteoElmt meteoTab[N_METEO_ADMIN]
extern

Meteo service.

Meteo service.

Definition at line 35 of file r3util.c.

Referenced by gribToStr(), and gribToStrJson().

◆ par

◆ polMat

PolMat polMat
extern

polar description

polar description

Definition at line 49 of file r3util.c.

Referenced by addSail(), buildNextIsochrone(), checkParamAndUpdate(), findListPol(), findSailPol(), fSailName(), goalP(), initContext(), optionManage(), readPolarJson(), and simpleGoalP().

◆ sailName

const char* sailName[]
extern

Definition at line 39 of file r3util.c.

Referenced by findSailPol(), and readPolar().

◆ sailNameSize

const size_t sailNameSize
extern

sail attributes

Definition at line 38 of file r3util.c.

Referenced by readPolar().

◆ sailPolMat

PolMat sailPolMat
extern

◆ tIsSea

char* tIsSea
extern

◆ wavePolMat

PolMat wavePolMat
extern

polar matrix for waves

Definition at line 55 of file r3util.c.

Referenced by buildNextIsochrone(), checkParamAndUpdate(), goalP(), initContext(), optionManage(), and simpleGoalP().

◆ wayPoints

WayPointList wayPoints
extern

list of wayPoint

Definition at line 43 of file r3util.c.

Referenced by checkParamAndUpdate(), logReport(), readParam(), routingLaunch(), and writeParam().

◆ zone