15 #define PI 3.1415926535897932384626433832795029L
33 reftime = (time_t) (
starttime + (12 - (
double) eqxhour) * 3600);
34 refday = reftime / 86400;
35 refhour = (reftime % 86400) / 3600.0;
38 *dataday1 = *dataday0 = refday;
39 }
else if (refhour < 6) {
40 *dataday0 = refday - 1;
42 }
else if (refhour > 18) {
44 *dataday1 = refday + 1;
46 *dataday1 = *dataday0 = refday;
56 *dataday0 = refday - 1;
60 *dataday1 = refday + 1;
77 float maxlat, minlat, maxlon, minlon;
91 w180 = e180 = w000 = e000 = 0;
92 for (
p = 1;
p <= n;
p++) {
103 if (olon[pmodn] == -180 && olon[
p - 1] > 0) olon[pmodn] = 180;
104 else if (olon[pmodn] == 180 && olon[
p - 1] < 0) olon[pmodn] = -180;
106 deltalon = olon[pmodn] - olon[
p - 1] + 360 * (e180 - w180);
107 if (deltalon < -180) {
110 }
else if (deltalon > 180) {
113 }
else if (olon[pmodn] >= 0 && olon[
p - 1] - 360 * (e180 - w180) < 0) {
116 }
else if (olon[pmodn] < 0 && olon[
p - 1] - 360 * (e180 - w180) >= 0) {
120 if (
abs(e180 - w180) > 1) {
123 if (
abs(e000 - w000) > 1) {
126 olon[pmodn] += 360 * (e180 - w180);
128 if (olon[pmodn] > maxlon) maxlon = olon[pmodn];
129 if (olon[pmodn] < minlon) minlon = olon[pmodn];
130 if (olat[pmodn] > maxlat) maxlat = olat[pmodn];
131 if (olat[pmodn] < minlat) minlat = olat[pmodn];
140 if ((w000 + e000) == 0) {
143 }
else if ((w000 + e000) & 1) {
149 if (90 - maxlat < minlat + 90) {
166 if ((w180 + e180) == 0) {
169 }
else if ((w180 + e180) & 1) {
176 if (90 - maxlat < minlat + 90) {
195 for (
p = 0;
p < n;
p++) {
196 while (olon[
p] < -180) olon[
p] += 360;
197 while (olon[
p] >= 180) olon[
p] -= 360;
199 while (minlon < -180) minlon += 360;
200 while (maxlon > 180) maxlon -= 360;
216 if(
lat[
i] >= -90.0 &&
lat[
i] <= 90.0) {
227 if(
lat[
i] >= -90.0 &&
lat[
i] <= 90.0) {
234 if(
lat[*cpix] >= -90.0 &&
lat[*cpix] <= 90.0) {
247 int32_t *msecondOfDay,
261 int s, fgs, lgs, night_tally = 0;
264 int idayOfYear, iyear;
272 for (
s = 0;
s <
hgt;
s++) {
279 fprintf(
stderr,
"-W- %s line %d: ", __FILE__, __LINE__);
280 fprintf(
stderr,
"No valid latitudes found\n ");
287 for (
s =
hgt - 1;
s > fgs;
s--) {
295 fprintf(
stderr,
"-W- %s line %d: ", __FILE__, __LINE__);
296 fprintf(
stderr,
"Insufficient valid latitudes found\n ");
304 for (
s = fgs;
s <= lgs;
s += lgs - fgs) {
306 float sv[3], sundist;
310 secondOfDay = msecondOfDay[
s] / 1000.;
311 idayOfYear = dayOfYear[
s];
314 l_sun_(&iyear, &idayOfYear, &secondOfDay, sv, &sundist);
317 fprintf(
stderr,
"-W- %s line %d: ", __FILE__, __LINE__);
318 fprintf(
stderr,
"Insufficient valid latitudes found in scan %d\n",
s);
329 coslat = cos(
lat[
s][
p] *
PI / 180);
330 pv[0] = coslat * cos(
lon[
s][
p] *
PI / 180);
331 pv[1] = coslat * sin(
lon[
s][
p] *
PI / 180);
332 pv[2] = sin(
lat[
s][
p] *
PI / 180);
334 if (pv[0] * sv[0] + pv[1] * sv[1] + pv[2] * sv[2] <= 0) {
353 if (lgs - fgs < 1)
break;
356 if (night_tally == 0 || night_tally == 4) {
359 dn = night_tally / 4;
362 n[dn] = 2 * (wid + lgs - fgs - 1);
365 MALLOC(olat[dn],
float, n[dn]);
366 MALLOC(olon[dn],
float, n[dn]);
371 for (
i = 0;
i < wid;
i++) {
374 if ((tlat >= -90 && tlat <= 90) &&
375 (tlon >= -180 && tlon <= 180)) {
383 for (
i = fgs+1;
i < lgs;
i++) {
387 if ((tlat >= -90 && tlat <= 90) &&
388 (tlon >= -180 && tlon <= 180)) {
397 for (
i = wid - 1;
i >= 0;
i--) {
400 if ((tlat >= -90 && tlat <= 90) &&
401 (tlon >= -180 && tlon <= 180)) {
409 for (
i = lgs - 1;
i > fgs;
i--) {
413 if ((tlat >= -90 && tlat <= 90) &&
414 (tlon >= -180 && tlon <= 180)) {
434 for (
s = fgs;
s <= lgs;
s++) {
436 float sv[3], sundist, prevlat, prevlon;
440 secondOfDay = msecondOfDay[
s] / 1000.;
441 idayOfYear = dayOfYear[
s];
443 l_sun_(&iyear, &idayOfYear, &secondOfDay, sv, &sundist);
451 int daynightchange,
i;
460 if (
lat[
s][
i] < -90 ||
463 lon[
s][
i] > 180)
continue;
466 coslat = cos(
lat[
s][
i] *
PI / 180);
467 pv[0] = coslat * cos(
lon[
s][
i] *
PI / 180);
468 pv[1] = coslat * sin(
lon[
s][
i] *
PI / 180);
469 pv[2] = sin(
lat[
s][
i] *
PI / 180);
471 if (pv[0] * sv[0] + pv[1] * sv[1] + pv[2] * sv[2] > 0) {
478 daynightchange = isnight != 0;
481 daynightchange = isnight != 1;
490 if (
s == fgs ||
i ==
epix) {
492 }
else if (
i ==
spix) {
494 }
else if (
s == lgs) {
500 }
else if (daynightchange) {
509 dorn[
s][
i] = isnight;
514 for (
s = 0;
s < 2;
s++) {
517 float *
lats, *
lons, *latp, *lonp, prevlat = -999, prevlon = -999;
534 if (
p->lat != prevlat &&
p->lon != prevlon) {
535 prevlat = *latp++ =
p->lat;
536 prevlon = *lonp++ =
p->lon;
543 fprintf(
stderr,
"-E- %s line %d: ", __FILE__, __LINE__);
545 "Program logic error. Likely some bad navigation got in - fix the code!.\n");
579 struct coord *newvrtx;
587 newvrtx->
next = *vrtx;
601 for (
p = *vrtx;
p->next !=
NULL;
p =
p->next);