added moment calculation for epoch timestamp
This commit is contained in:
parent
bee7db499f
commit
1bd41ab42a
2 changed files with 67 additions and 41 deletions
|
|
@ -317,10 +317,35 @@ const char * pmom(int days, long epoch, double latitude, double longitude, int b
|
||||||
second = tmp->tm_sec;
|
second = tmp->tm_sec;
|
||||||
hours = (double) hour + (double) minute / 60 + (double) second / 3600;
|
hours = (double) hour + (double) minute / 60 + (double) second / 3600;
|
||||||
|
|
||||||
|
length += snprintf(Buffer+length, buflen-length, "{ ");
|
||||||
|
|
||||||
|
// calculate timestamp moment
|
||||||
|
solar_moment(latitude, longitude, epoch, solar);
|
||||||
|
planetary_moment(latitude, longitude, epoch, lunar, planet);
|
||||||
|
if ( epoch < solar[2]) {
|
||||||
|
start = solar[1];
|
||||||
|
interval = solar[5];
|
||||||
|
m = 0;
|
||||||
|
}
|
||||||
|
if ( solar[2] < epoch ) {
|
||||||
|
start = solar[2];
|
||||||
|
interval = solar[6];
|
||||||
|
m = 12;
|
||||||
|
}
|
||||||
|
for (hm = 1; hm <= 12; hm++) {
|
||||||
|
if (epoch < (start + hm * interval) ) {
|
||||||
|
hm = hm + m;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
length += snprintf(Buffer+length, buflen-length, "\"moment\":[{ \"ts\": %d, \"gst\": %f, \"lunar\": { \"day\": %d, \"angle\": %f, \"phase\": %f }, \"planetary\": { \"day\": { \"no\": %d, \"start\": %d, \"end\": %d }, \"night\": { \"start\": %d, \"end\": %d }, \"hour\": { \"no\": %d, \"start\": %d, \"end\": %d, \"length\": { \"day\": %d, \"night\": %d } } }, \"ephemeris\": { \"sun\": { \"deg\": %f, \"speed\": %f }, \"moon\": { \"deg\": %f, \"speed\": %f }, \"mercury\": { \"deg\": %f, \"speed\": %f }, \"venus\": { \"deg\": %f, \"speed\": %f }, \"mars\": { \"deg\": %f, \"speed\": %f }, \"jupiter\": { \"deg\": %f, \"speed\": %f }, \"saturn\": { \"deg\": %f, \"speed\": %f }, \"node\": { \"deg\": %f }, \"asc\": { \"deg\": %f }, \"mc\": { \"deg\": %f } } }], ", epoch, (planet[16] / 15.0), (int) lunar[0], lunar[1], lunar[2], solar[7], solar[1], solar[2]-1, solar[2], solar[3]-1, hm, (start + hm * interval), (start + hm * interval)+interval-1, solar[5], solar[6], planet[0], planet[7], planet[1], planet[8], planet[2], planet[9], planet[3], planet[10], planet[4], planet[11], planet[5], planet[12], planet[6], planet[13], planet[16], planet[14], planet[15] );
|
||||||
|
|
||||||
|
if ( days > 0 ) {
|
||||||
|
|
||||||
// start of Almanac
|
// start of Almanac
|
||||||
queryday = time_to_epoch(year, month, day, 0, 0, 0);
|
queryday = time_to_epoch(year, month, day, 0, 0, 0);
|
||||||
j = 0;
|
j = 0;
|
||||||
length += snprintf(Buffer+length, buflen-length, "{ \"query\":[");
|
length += snprintf(Buffer+length, buflen-length, "\"query\":[");
|
||||||
|
|
||||||
// calculate all hours for all days
|
// calculate all hours for all days
|
||||||
while ( j <= days ) {
|
while ( j <= days ) {
|
||||||
|
|
@ -357,6 +382,7 @@ const char * pmom(int days, long epoch, double latitude, double longitude, int b
|
||||||
}, j, days*2);
|
}, j, days*2);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
}
|
||||||
length += snprintf(Buffer+length, buflen-length, "]}");
|
length += snprintf(Buffer+length, buflen-length, "]}");
|
||||||
return Buffer;
|
return Buffer;
|
||||||
}
|
}
|
||||||
|
|
@ -388,7 +414,7 @@ int main(int argc,char* argv[]) // days, timestamp, latitude, longitude
|
||||||
}
|
}
|
||||||
|
|
||||||
timestamp = epoch;
|
timestamp = epoch;
|
||||||
buflen = days * 100000;
|
buflen = (1 + days) * 100000;
|
||||||
printf(pmom( days, epoch, latitude, longitude, buflen));
|
printf(pmom( days, epoch, latitude, longitude, buflen));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -402,7 +428,7 @@ const char * get(int days, long epoch, double latitude, double longitude) // day
|
||||||
int32 buflen;
|
int32 buflen;
|
||||||
|
|
||||||
timestamp = epoch;
|
timestamp = epoch;
|
||||||
buflen = days * 100000;
|
buflen = (1 + days) * 100000;
|
||||||
return pmom( days, epoch, latitude, longitude, buflen);
|
return pmom( days, epoch, latitude, longitude, buflen);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
2
pmom.php
2
pmom.php
|
|
@ -12,7 +12,7 @@ $lon = $_GET['lon'];
|
||||||
$lat = $_GET['lat'];
|
$lat = $_GET['lat'];
|
||||||
$days = $_GET['days'];
|
$days = $_GET['days'];
|
||||||
|
|
||||||
exec ("lib/sweph/pmom $days $ts $lat $lon", $output);
|
exec ("lib/sweph/pmom $days $ts $lat $lon $moment", $output);
|
||||||
|
|
||||||
echo $output[0];
|
echo $output[0];
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue