22 double w, twa, tws, lon, lat, lat2, lon2, cog, t, hours;
24 int sail, intRes, nTries;
26 const long nIter = 1e9;
29 fprintf (stderr,
"In optionManage, Error Malloc %d\n",
MAX_SIZE_BUFFER);
38 if (scanf (
"%lf", &lon) < 1)
break;
40 if (scanf (
"%lf", &lat) < 1)
break;
42 if (scanf (
"%lf", &lon2) < 1)
break;
44 if (scanf (
"%lf", &lat2) < 1)
break;
45 printf (
"Ortho cap1: %.2lf°, Ortho cap2: %.2lf°\n",
orthoCap (lat, lon, lat2, lon2),
orthoCap (lat2, lon2, lat, lon));
46 printf (
"Ortho2 cap1: %.2lf°, Ortho2 cap2: %.2lf°\n",
orthoCap2 (lat, lon, lat2, lon2),
orthoCap2 (lat2, lon2, lat, lon));
47 printf (
"Orthodist1 : %.2lf, Orthodist2: %.2lf\n",
orthoDist (lat, lon, lat2, lon2),
orthoDist (lat2, lon2, lat, lon));
48 printf (
"Orthodist1 : %.2lf, Orthodist2: %.2lf\n",
orthoDist2 (lat, lon, lat2, lon2),
orthoDist (lat2, lon2, lat, lon));
49 printf (
"Loxodist1 : %.2lf, Loxodist2 : %.2lf\n",
loxoDist(lat, lon, lat2, lon2),
loxoDist (lat2, lon2, lat, lon));
53 printf (
"%s\n", buffer);
54 printf (
"grib print...\n");
56 printf (
"\n\nFollowing lines are suspects info...\n");
58 printf (
"%s\n", buffer);
62 printf (
"%s\n", buffer);
63 printf (
"grib print...\n");
65 printf (
"\n\nFollowing lines are suspects info...\n");
67 printf (
"%s\n", buffer);
70 printf (
"Size of size_t : %zu bytes\n",
sizeof (
size_t));
72 fprintf (stderr,
"In optionManage, Error help: Impossible to read: %s\n",
par.
cliHelpFileName);
81 printf (
"%s\n", buffer);
85 printf (
"twa true wind angle = ");
86 if (scanf (
"%lf", &twa) < 1)
break;
87 printf (
"tws true wind speed = ");
88 if (scanf (
"%lf", &tws) < 1)
break;
92 printf (
"Sail: %d\n", sail);
95 for (
long i = 0; i < nIter; i += 1)
findPolar (fmod (twa+=10.0, 180.0), fmod (tws+=13.0, 90.0), &
polMat, &
sailPolMat, &sail);
101 for (
long i = 0; i < nIter; i += 1)
findPolar2 (fmod (twa+=10.0, 180.0), fmod (tws+=13.0, 90.0), &
polMat, &
sailPolMat, &sail);
105 printf (
"✅ findPolar.: %.2lf seconds\n", t1 - t0);
106 printf (
"✅ findPolar1: %.2lf seconds\n", t2 - t1);
107 printf (
"✅ findPolar2: %.2lf seconds\n", t3 - t2);
113 printf (
"%s\n", buffer);
115 printf (
"angle = " );
116 if (scanf (
"%lf", &twa) < 1)
break;
118 if (scanf (
"%lf", &w) < 1)
break;
124 printf (
"%s\n", buffer);
127 if (scanf (
"%lf", &tws) < 1)
break;
134 printf (
"%s\n", buffer);
135 printf (
"%s\n", footer);
139 if (scanf (
"%d", &nTries) != 1)
break;
142 printf (
"%s\n", buffer);
143 printf (
"%s\n", footer);
146 if (
tIsSea == NULL) printf (
"in readIsSea : bizarre\n");
150 if (scanf (
"%lf", &lat) < 1)
break;
152 if (scanf (
"%lf", &lon) < 1)
break;
155 else printf (
"Earth\n");
163 if (scanf (
"%lf", &lat) < 1)
break;
165 if (scanf (
"%lf", &lon) < 1)
break;
167 if (scanf (
"%lf", &t) < 1)
break;
169 printf(
"res: %s\n", intRes ?
"day" :
"night");
175 time_t t = time (NULL);
176 printf (
"now epochToStr: %s\n",
epochToStr (t,
true, str,
sizeof str));
178 printf (
"grib start epochToStr: %s\n",
epochToStr (t,
true, str,
sizeof str));
181 if (scanf (
"%ld", &dataDate) < 1)
break;
182 printf (
"decimal hours: ");
183 if (scanf (
"%lf", &hours) < 1)
break;
184 printf (
"DateUtc: %s\n",
newDate (dataDate, hours, str,
sizeof str));
189 printf (
"Compilation-date: %s\n", __DATE__);
194 if (scanf (
"%lf", &cog) < 1)
break;
196 if (scanf (
"%lf", &twa) < 1)
break;
197 printf (
"fTwa = %.2lf\n",
fTwa (cog, twa));
205 printf (
"Option unknown: -%c\n", option);
bool routeToStr(const SailRoute *route, char *str, size_t maxLen, char *footer, size_t maxLenFooter)
copy route in a string true if enough space, false if truncated
void * routingLaunch()
launch routing with parameters
SailRoute route
store sail route calculated in engine.c by routing
char * gribToStr(const Zone *zone, char *str, size_t maxLen)
write Grib information in string
void printGrib(const Zone *zone, const FlowP *gribData)
print Grib u v ... for all lat lon time information
bool checkGribToStr(bool hasCurrentGrib, char *buffer, size_t maxLen)
check Grib information and write report in the buffer return false if something wrong
static double fTwa(double heading, double twd)
return TWA between -180 and 180 note : tribord amure if twa < 0
static double maxSpeedInPolarAt(double tws, const PolMat *mat)
return max speed of boat at tws for all twa
static bool isSea(char *isSeaArray, double lat, double lon)
this file contains small inlines functions to be included in source files
static double findPolar2(double twa, double w, const PolMat *mat, const PolMat *sailMat, int *sail)
find in polar boat speed or wave coeff and sail number if sailMat != NULL
static double findPolar(double twa, double w, const PolMat *mat, const PolMat *sailMat, int *sail)
find in polar boat speed or wave coeff
static double orthoDist(double lat1, double lon1, double lat2, double lon2)
return orthodromic distance in nautical miles from origin to destination
static double orthoCap(double lat1, double lon1, double lat2, double lon2)
return initial orthodromic cap from origin to destination equivalent to : return directCap (lat1,...
static double orthoDist2(double lat1, double lon1, double lat2, double lon2)
return orthodomic distance in nautical miles from origin to destinationi, Haversine formula time cons...
static bool isDay(double t, long dataDate, long dataTime, double lat, double lon)
true if day light, false if night
static double loxoDist(double lat1, double lon1, double lat2, double lon2)
return loxodromic distance in nautical miles from origin to destination
static double findPolar1(double twa, double w, const PolMat *mat, const PolMat *sailMat, int *sail)
find in polar boat speed or wave coeff and sail number if sailMat != NULL
static double orthoCap2(double lat1, double lon1, double lat2, double lon2)
return initial orthodromic cap from origin to destination, no givry correction
void optionManage(char option)
compilation: gcc -c option.c
char * polToStr(const PolMat *mat, char *str, size_t maxLen)
write polar information in string
char * epochToStr(time_t t, bool seconds, char *str, size_t maxLen)
convert epoch time to string with or without seconds
double offsetLocalUTC(void)
return offset Local UTC in seconds
double monotonic(void)
return seconds with decimals
PolMat wavePolMat
polar matrix for waves
char * tIsSea
table describing if sea or earth
PolMat polMat
polar matrix description
char * newDate(long intDate, double nHours, char *res, size_t maxLen)
return date and time using ISO notation after adding myTime (hours) to the Date
PolMat sailPolMat
polar matrix for sails
Zone zone
geographic zone covered by grib file
char * gribDateTimeToStr(long date, long time, char *str, size_t maxLen)
return str representing grib date
time_t gribDateTimeToEpoch(long date, long hhmm)
convert long date/time from GRIB to time_t (UTC, via timegm)
FlowP * tGribData[]
grib data description
bool readGribAll(const char *fileName, Zone *zone, int iFlow)
read grib file using eccodes C API return true if OK
char mailPw[MAX_SIZE_NAME]
char cliHelpFileName[MAX_SIZE_FILE_NAME]
long dataTime[MAX_N_DATA_TIME]
long dataDate[MAX_N_DATA_DATE]