diff options
| author | Glenn Morris | 2008-03-08 23:07:56 +0000 |
|---|---|---|
| committer | Glenn Morris | 2008-03-08 23:07:56 +0000 |
| commit | a603b7dbaa2dbe6a751096b0f90b2666654b5eec (patch) | |
| tree | db2bfc46eda725933ae144cb147a5c37bf45303c | |
| parent | f0a51f2a94e9010ed827c7dfe8c337403e7d0fd9 (diff) | |
| download | emacs-a603b7dbaa2dbe6a751096b0f90b2666654b5eec.tar.gz emacs-a603b7dbaa2dbe6a751096b0f90b2666654b5eec.zip | |
(calendar-location-name, calendar-latitude)
(calendar-longitude, solar-setup, solar-sin-degrees)
(solar-cosine-degrees, solar-tangent-degrees, solar-xy-to-quadrant)
(solar-degrees-to-quadrant, solar-atn2, solar-arccos)
(solar-sunrise-and-sunset, solar-moment, solar-daylight)
(solar-exact-local-noon, solar-julian-ut-centuries)
(solar-ephemeris-time, solar-date-next-longitude)
(solar-horizontal-coordinates, solar-equatorial-coordinates)
(solar-ecliptic-coordinates, solar-data-list, solar-longitude)
(solar-ephemeris-correction, solar-sidereal-time, solar-date-to-et)
(sunrise-sunset, solar-seasons-data, solar-equinoxes/solstices):
Doc fixes.
(solar-horizontal-coordinates, solar-equatorial-coordinates)
(solar-ecliptic-coordinates): Rename argument `for-sunrise-sunset'.
(solar-ecliptic-coordinates): Use unless.
(calendar-sunrise-sunset, diary-sunrise-sunset, diary-sabbath-candles):
Use or.
| -rw-r--r-- | lisp/ChangeLog | 18 | ||||
| -rw-r--r-- | lisp/calendar/solar.el | 215 |
2 files changed, 120 insertions, 113 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fd981dedbf6..fb4272b02b8 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -157,6 +157,24 @@ | |||
| 157 | * calendar/cal-hebrew.el, calendar/holidays.el, calendar/lunar.el: | 157 | * calendar/cal-hebrew.el, calendar/holidays.el, calendar/lunar.el: |
| 158 | * calendar/solar.el: Unquote lambda functions. | 158 | * calendar/solar.el: Unquote lambda functions. |
| 159 | 159 | ||
| 160 | * calendar/solar.el (calendar-location-name, calendar-latitude) | ||
| 161 | (calendar-longitude, solar-setup, solar-sin-degrees) | ||
| 162 | (solar-cosine-degrees, solar-tangent-degrees, solar-xy-to-quadrant) | ||
| 163 | (solar-degrees-to-quadrant, solar-atn2, solar-arccos) | ||
| 164 | (solar-sunrise-and-sunset, solar-moment, solar-daylight) | ||
| 165 | (solar-exact-local-noon, solar-julian-ut-centuries) | ||
| 166 | (solar-ephemeris-time, solar-date-next-longitude) | ||
| 167 | (solar-horizontal-coordinates, solar-equatorial-coordinates) | ||
| 168 | (solar-ecliptic-coordinates, solar-data-list, solar-longitude) | ||
| 169 | (solar-ephemeris-correction, solar-sidereal-time, solar-date-to-et) | ||
| 170 | (sunrise-sunset, solar-seasons-data, solar-equinoxes/solstices): | ||
| 171 | Doc fixes. | ||
| 172 | (solar-horizontal-coordinates, solar-equatorial-coordinates) | ||
| 173 | (solar-ecliptic-coordinates): Rename argument `for-sunrise-sunset'. | ||
| 174 | (solar-ecliptic-coordinates): Use unless. | ||
| 175 | (calendar-sunrise-sunset, diary-sunrise-sunset, diary-sabbath-candles): | ||
| 176 | Use or. | ||
| 177 | |||
| 160 | * calendar/todo-mode.el: Remove un-needed eval-when-compile. | 178 | * calendar/todo-mode.el: Remove un-needed eval-when-compile. |
| 161 | 179 | ||
| 162 | * textmodes/org.el (list-diary-entries-hook): Declare for compiler. | 180 | * textmodes/org.el (list-diary-entries-hook): Declare for compiler. |
diff --git a/lisp/calendar/solar.el b/lisp/calendar/solar.el index ecb5321c5a7..fe61c0d8562 100644 --- a/lisp/calendar/solar.el +++ b/lisp/calendar/solar.el | |||
| @@ -55,7 +55,6 @@ | |||
| 55 | 55 | ||
| 56 | ;;; Code: | 56 | ;;; Code: |
| 57 | 57 | ||
| 58 | (defvar date) | ||
| 59 | (defvar displayed-month) | 58 | (defvar displayed-month) |
| 60 | (defvar displayed-year) | 59 | (defvar displayed-year) |
| 61 | 60 | ||
| @@ -87,7 +86,6 @@ would give military-style times like `21:07 (UTC)'." | |||
| 87 | 86 | ||
| 88 | (defcustom calendar-latitude nil | 87 | (defcustom calendar-latitude nil |
| 89 | "Latitude of `calendar-location-name' in degrees. | 88 | "Latitude of `calendar-location-name' in degrees. |
| 90 | |||
| 91 | The value can be either a decimal fraction (one place of accuracy is | 89 | The value can be either a decimal fraction (one place of accuracy is |
| 92 | sufficient), + north, - south, such as 40.7 for New York City, or the value | 90 | sufficient), + north, - south, such as 40.7 for New York City, or the value |
| 93 | can be a vector [degrees minutes north/south] such as [40 50 north] for New | 91 | can be a vector [degrees minutes north/south] such as [40 50 north] for New |
| @@ -106,7 +104,6 @@ This variable should be set in `site-start'.el." | |||
| 106 | 104 | ||
| 107 | (defcustom calendar-longitude nil | 105 | (defcustom calendar-longitude nil |
| 108 | "Longitude of `calendar-location-name' in degrees. | 106 | "Longitude of `calendar-location-name' in degrees. |
| 109 | |||
| 110 | The value can be either a decimal fraction (one place of accuracy is | 107 | The value can be either a decimal fraction (one place of accuracy is |
| 111 | sufficient), + east, - west, such as -73.9 for New York City, or the value | 108 | sufficient), + east, - west, such as -73.9 for New York City, or the value |
| 112 | can be a vector [degrees minutes east/west] such as [73 55 west] for New | 109 | can be a vector [degrees minutes east/west] such as [73 55 west] for New |
| @@ -140,9 +137,9 @@ This variable should be set in `site-start'.el." | |||
| 140 | (if (numberp calendar-longitude) | 137 | (if (numberp calendar-longitude) |
| 141 | (if (> calendar-longitude 0) "E" "W") | 138 | (if (> calendar-longitude 0) "E" "W") |
| 142 | (if (equal (aref calendar-longitude 2) 'east) "E" "W")))) | 139 | (if (equal (aref calendar-longitude 2) 'east) "E" "W")))) |
| 143 | "Expression evaluating to name of `calendar-longitude', `calendar-latitude'. | 140 | "Expression evaluating to the name of the calendar location. |
| 144 | For example, \"New York City\". Default value is just the latitude, longitude | 141 | For example, \"New York City\". The default value is just the |
| 145 | pair. | 142 | variable `calendar-latitude' paired with the variable `calendar-longitude'. |
| 146 | 143 | ||
| 147 | This variable should be set in `site-start'.el." | 144 | This variable should be set in `site-start'.el." |
| 148 | :type 'sexp | 145 | :type 'sexp |
| @@ -191,7 +188,7 @@ Needed for polar areas, in order to know whether the day lasts 0 or 24 hours.") | |||
| 191 | 188 | ||
| 192 | 189 | ||
| 193 | (defsubst calendar-latitude () | 190 | (defsubst calendar-latitude () |
| 194 | "Convert calendar-latitude to a signed decimal fraction, if needed." | 191 | "Ensure the variable `calendar-latitude' is a signed decimal fraction." |
| 195 | (if (numberp calendar-latitude) | 192 | (if (numberp calendar-latitude) |
| 196 | calendar-latitude | 193 | calendar-latitude |
| 197 | (let ((lat (+ (aref calendar-latitude 0) | 194 | (let ((lat (+ (aref calendar-latitude 0) |
| @@ -201,7 +198,7 @@ Needed for polar areas, in order to know whether the day lasts 0 or 24 hours.") | |||
| 201 | (- lat))))) | 198 | (- lat))))) |
| 202 | 199 | ||
| 203 | (defsubst calendar-longitude () | 200 | (defsubst calendar-longitude () |
| 204 | "Convert calendar-longitude to a signed decimal fraction, if needed." | 201 | "Ensure the variable `calendar-longitude' is a signed decimal fraction." |
| 205 | (if (numberp calendar-longitude) | 202 | (if (numberp calendar-longitude) |
| 206 | calendar-longitude | 203 | calendar-longitude |
| 207 | (let ((long (+ (aref calendar-longitude 0) | 204 | (let ((long (+ (aref calendar-longitude 0) |
| @@ -211,7 +208,7 @@ Needed for polar areas, in order to know whether the day lasts 0 or 24 hours.") | |||
| 211 | (- long))))) | 208 | (- long))))) |
| 212 | 209 | ||
| 213 | (defun solar-setup () | 210 | (defun solar-setup () |
| 214 | "Prompt user for latitude, longitude, and time zone." | 211 | "Prompt for `calendar-longitude', `calendar-latitude', `calendar-time-zone'." |
| 215 | (beep) | 212 | (beep) |
| 216 | (or calendar-longitude | 213 | (or calendar-longitude |
| 217 | (setq calendar-longitude | 214 | (setq calendar-longitude |
| @@ -235,22 +232,25 @@ Returns nil if nothing was entered." | |||
| 235 | (string-to-number x)))) | 232 | (string-to-number x)))) |
| 236 | 233 | ||
| 237 | (defun solar-sin-degrees (x) | 234 | (defun solar-sin-degrees (x) |
| 235 | "Return sin of X degrees." | ||
| 238 | (sin (degrees-to-radians (mod x 360.0)))) | 236 | (sin (degrees-to-radians (mod x 360.0)))) |
| 239 | 237 | ||
| 240 | (defun solar-cosine-degrees (x) | 238 | (defun solar-cosine-degrees (x) |
| 239 | "Return cosine of X degrees." | ||
| 241 | (cos (degrees-to-radians (mod x 360.0)))) | 240 | (cos (degrees-to-radians (mod x 360.0)))) |
| 242 | 241 | ||
| 243 | (defun solar-tangent-degrees (x) | 242 | (defun solar-tangent-degrees (x) |
| 243 | "Return tangent of X degrees." | ||
| 244 | (tan (degrees-to-radians (mod x 360.0)))) | 244 | (tan (degrees-to-radians (mod x 360.0)))) |
| 245 | 245 | ||
| 246 | (defun solar-xy-to-quadrant (x y) | 246 | (defun solar-xy-to-quadrant (x y) |
| 247 | "Determines the quadrant of the point X, Y." | 247 | "Determine the quadrant of the point X, Y." |
| 248 | (if (> x 0) | 248 | (if (> x 0) |
| 249 | (if (> y 0) 1 4) | 249 | (if (> y 0) 1 4) |
| 250 | (if (> y 0) 2 3))) | 250 | (if (> y 0) 2 3))) |
| 251 | 251 | ||
| 252 | (defun solar-degrees-to-quadrant (angle) | 252 | (defun solar-degrees-to-quadrant (angle) |
| 253 | "Determines the quadrant of ANGLE." | 253 | "Determine the quadrant of ANGLE degrees." |
| 254 | (1+ (floor (mod angle 360) 90))) | 254 | (1+ (floor (mod angle 360) 90))) |
| 255 | 255 | ||
| 256 | (defun solar-arctan (x quad) | 256 | (defun solar-arctan (x quad) |
| @@ -262,13 +262,13 @@ Returns nil if nothing was entered." | |||
| 262 | (t deg)))) | 262 | (t deg)))) |
| 263 | 263 | ||
| 264 | (defun solar-atn2 (x y) | 264 | (defun solar-atn2 (x y) |
| 265 | "Arctan of point X, Y." | 265 | "Arctangent of point X, Y." |
| 266 | (if (zerop x) | 266 | (if (zerop x) |
| 267 | (if (> y 0) 90 270) | 267 | (if (> y 0) 90 270) |
| 268 | (solar-arctan (/ y x) (solar-xy-to-quadrant x y)))) | 268 | (solar-arctan (/ y x) (solar-xy-to-quadrant x y)))) |
| 269 | 269 | ||
| 270 | (defun solar-arccos (x) | 270 | (defun solar-arccos (x) |
| 271 | "Arcos of X." | 271 | "Arccosine of X." |
| 272 | (let ((y (sqrt (- 1 (* x x))))) | 272 | (let ((y (sqrt (- 1 (* x x))))) |
| 273 | (solar-atn2 x y))) | 273 | (solar-atn2 x y))) |
| 274 | 274 | ||
| @@ -307,11 +307,11 @@ Parameters are the midday TIME and the LATITUDE, LONGITUDE of the location. | |||
| 307 | TIME is a pair with the first component being the number of Julian centuries | 307 | TIME is a pair with the first component being the number of Julian centuries |
| 308 | elapsed at 0 Universal Time, and the second component being the universal | 308 | elapsed at 0 Universal Time, and the second component being the universal |
| 309 | time. For instance, the pair corresponding to November 28, 1995 at 16 UT is | 309 | time. For instance, the pair corresponding to November 28, 1995 at 16 UT is |
| 310 | \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between | 310 | \(-0.040945 16), -0.040945 being the number of Julian centuries elapsed between |
| 311 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. | 311 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. |
| 312 | 312 | ||
| 313 | HEIGHT is the angle the center of the sun has over the horizon for the contact | 313 | HEIGHT is the angle the center of the sun has over the horizon for the contact |
| 314 | we are trying to find. For sunrise and sunset, it is usually -0.61 degrees, | 314 | we are trying to find. For sunrise and sunset, it is usually -0.61 degrees, |
| 315 | accounting for the edge of the sun being on the horizon. | 315 | accounting for the edge of the sun being on the horizon. |
| 316 | 316 | ||
| 317 | Coordinates are included because this function is called with latitude=1 | 317 | Coordinates are included because this function is called with latitude=1 |
| @@ -339,11 +339,11 @@ being TIME. | |||
| 339 | TIME is a pair with the first component being the number of Julian centuries | 339 | TIME is a pair with the first component being the number of Julian centuries |
| 340 | elapsed at 0 Universal Time, and the second component being the universal | 340 | elapsed at 0 Universal Time, and the second component being the universal |
| 341 | time. For instance, the pair corresponding to November 28, 1995 at 16 UT is | 341 | time. For instance, the pair corresponding to November 28, 1995 at 16 UT is |
| 342 | \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between | 342 | \(-0.040945 16), -0.040945 being the number of Julian centuries elapsed between |
| 343 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. | 343 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. |
| 344 | 344 | ||
| 345 | HEIGHT is the angle the center of the sun has over the horizon for the contact | 345 | HEIGHT is the angle the center of the sun has over the horizon for the contact |
| 346 | we are trying to find. For sunrise and sunset, it is usually -0.61 degrees, | 346 | we are trying to find. For sunrise and sunset, it is usually -0.61 degrees, |
| 347 | accounting for the edge of the sun being on the horizon. | 347 | accounting for the edge of the sun being on the horizon. |
| 348 | 348 | ||
| 349 | Uses binary search." | 349 | Uses binary search." |
| @@ -395,14 +395,13 @@ Format used is given by `calendar-time-display-form'." | |||
| 395 | 395 | ||
| 396 | 396 | ||
| 397 | (defun solar-daylight (time) | 397 | (defun solar-daylight (time) |
| 398 | "Printable form for time expressed in hours." | 398 | "Printable form for TIME expressed in hours." |
| 399 | (format "%d:%02d" | 399 | (format "%d:%02d" |
| 400 | (floor time) | 400 | (floor time) |
| 401 | (floor (* 60 (- time (floor time)))))) | 401 | (floor (* 60 (- time (floor time)))))) |
| 402 | 402 | ||
| 403 | (defun solar-exact-local-noon (date) | 403 | (defun solar-exact-local-noon (date) |
| 404 | "Date and Universal Time of local noon at *local date* date. | 404 | "Date and Universal Time of local noon at *local date* DATE. |
| 405 | |||
| 406 | The date may be different from the one asked for, but it will be the right | 405 | The date may be different from the one asked for, but it will be the right |
| 407 | local date. The second component of date should be an integer." | 406 | local date. The second component of date should be an integer." |
| 408 | (let* ((nd date) | 407 | (let* ((nd date) |
| @@ -426,7 +425,6 @@ local date. The second component of date should be an integer." | |||
| 426 | 425 | ||
| 427 | (defun solar-sunrise-sunset (date) | 426 | (defun solar-sunrise-sunset (date) |
| 428 | "List of *local* times of sunrise, sunset, and daylight on Gregorian DATE. | 427 | "List of *local* times of sunrise, sunset, and daylight on Gregorian DATE. |
| 429 | |||
| 430 | Corresponding value is nil if there is no sunrise/sunset." | 428 | Corresponding value is nil if there is no sunrise/sunset." |
| 431 | ;; First, get the exact moment of local noon. | 429 | ;; First, get the exact moment of local noon. |
| 432 | (let* ((exact-local-noon (solar-exact-local-noon date)) | 430 | (let* ((exact-local-noon (solar-exact-local-noon date)) |
| @@ -478,21 +476,20 @@ Corresponding value is nil if there is no sunrise/sunset." | |||
| 478 | (car (cdr (cdr l)))))) | 476 | (car (cdr (cdr l)))))) |
| 479 | 477 | ||
| 480 | (defun solar-julian-ut-centuries (date) | 478 | (defun solar-julian-ut-centuries (date) |
| 481 | "Number of Julian centuries elapsed since 1 Jan, 2000 at noon U.T. for Gregorian DATE." | 479 | "Number of Julian centuries since 1 Jan, 2000 at noon UT for Gregorian DATE." |
| 482 | (/ (- (calendar-absolute-from-gregorian date) | 480 | (/ (- (calendar-absolute-from-gregorian date) |
| 483 | (calendar-absolute-from-gregorian '(1 1.5 2000))) | 481 | (calendar-absolute-from-gregorian '(1 1.5 2000))) |
| 484 | 36525.0)) | 482 | 36525.0)) |
| 485 | 483 | ||
| 486 | (defun solar-ephemeris-time(time) | 484 | (defun solar-ephemeris-time (time) |
| 487 | "Ephemeris Time at moment TIME. | 485 | "Ephemeris Time at moment TIME. |
| 488 | |||
| 489 | TIME is a pair with the first component being the number of Julian centuries | 486 | TIME is a pair with the first component being the number of Julian centuries |
| 490 | elapsed at 0 Universal Time, and the second component being the universal | 487 | elapsed at 0 Universal Time, and the second component being the universal |
| 491 | time. For instance, the pair corresponding to November 28, 1995 at 16 UT is | 488 | time. For instance, the pair corresponding to November 28, 1995 at 16 UT is |
| 492 | \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between | 489 | \(-0.040945 16), -0.040945 being the number of Julian centuries elapsed between |
| 493 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. | 490 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. |
| 494 | 491 | ||
| 495 | Result is in julian centuries of ephemeris time." | 492 | Result is in Julian centuries of ephemeris time." |
| 496 | (let* ((t0 (car time)) | 493 | (let* ((t0 (car time)) |
| 497 | (ut (car (cdr time))) | 494 | (ut (car (cdr time))) |
| 498 | (t1 (+ t0 (/ (/ ut 24.0) 36525))) | 495 | (t1 (+ t0 (/ (/ ut 24.0) 36525))) |
| @@ -501,18 +498,14 @@ Result is in julian centuries of ephemeris time." | |||
| 501 | (+ t1 (/ (/ dt 86400) 36525)))) | 498 | (+ t1 (/ (/ dt 86400) 36525)))) |
| 502 | 499 | ||
| 503 | (defun solar-date-next-longitude (d l) | 500 | (defun solar-date-next-longitude (d l) |
| 504 | "First moment on or after Julian day number D when sun's longitude is a | 501 | "First time after day D when solar longitude is a multiple of L degrees. |
| 505 | multiple of L degrees at calendar-location-name with that location's | 502 | D is a Julian day number. L must be an integer divisor of 360. |
| 506 | local time (including any daylight saving rules). | 503 | The result is for `calendar-location-name', and is in local time |
| 507 | 504 | \(including any daylight saving rules) expressed in astronomical (Julian) | |
| 508 | L must be an integer divisor of 360. | 505 | day numbers. The values of `calendar-daylight-savings-starts', |
| 509 | 506 | `calendar-daylight-savings-starts-time', `calendar-daylight-savings-ends', | |
| 510 | Result is in local time expressed astronomical (Julian) day numbers. | 507 | `calendar-daylight-savings-ends-time', `calendar-daylight-time-offset', |
| 511 | 508 | and `calendar-time-zone' are used to interpret local time." | |
| 512 | The values of calendar-daylight-savings-starts, | ||
| 513 | calendar-daylight-savings-starts-time, calendar-daylight-savings-ends, | ||
| 514 | calendar-daylight-savings-ends-time, calendar-daylight-time-offset, and | ||
| 515 | calendar-time-zone are used to interpret local time." | ||
| 516 | (let* ((long) | 509 | (let* ((long) |
| 517 | (start d) | 510 | (start d) |
| 518 | (start-long (solar-longitude d)) | 511 | (start-long (solar-longitude d)) |
| @@ -536,24 +529,23 @@ calendar-time-zone are used to interpret local time." | |||
| 536 | (setq end-long long))) | 529 | (setq end-long long))) |
| 537 | (/ (+ start end) 2.0))) | 530 | (/ (+ start end) 2.0))) |
| 538 | 531 | ||
| 539 | (defun solar-horizontal-coordinates | 532 | (defun solar-horizontal-coordinates (time latitude longitude sunrise-flag) |
| 540 | (time latitude longitude for-sunrise-sunset) | ||
| 541 | "Azimuth and height of the sun at TIME, LATITUDE, and LONGITUDE. | 533 | "Azimuth and height of the sun at TIME, LATITUDE, and LONGITUDE. |
| 542 | 534 | TIME is a pair with the first component being the number of | |
| 543 | TIME is a pair with the first component being the number of Julian centuries | 535 | Julian centuries elapsed at 0 Universal Time, and the second |
| 544 | elapsed at 0 Universal Time, and the second component being the universal | 536 | component being the universal time. For instance, the pair |
| 545 | time. For instance, the pair corresponding to November 28, 1995 at 16 UT is | 537 | corresponding to November 28, 1995 at 16 UT is (-0.040945 16), |
| 546 | \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between | 538 | -0.040945 being the number of Julian centuries elapsed between |
| 547 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. | 539 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. SUNRISE-FLAG |
| 548 | 540 | is passed to `solar-ecliptic-coordinates'. Azimuth and | |
| 549 | The azimuth is given in degrees as well as the height (between -180 and 180)." | 541 | height (between -180 and 180) are both in degrees." |
| 550 | (let* ((ut (car (cdr time))) | 542 | (let* ((ut (cadr time)) |
| 551 | (ec (solar-equatorial-coordinates time for-sunrise-sunset)) | 543 | (ec (solar-equatorial-coordinates time sunrise-flag)) |
| 552 | (st (+ solar-sidereal-time-greenwich-midnight | 544 | (st (+ solar-sidereal-time-greenwich-midnight |
| 553 | (* ut 1.00273790935))) | 545 | (* ut 1.00273790935))) |
| 554 | ;; Hour angle (in degrees). | 546 | ;; Hour angle (in degrees). |
| 555 | (ah (- (* st 15) (* 15 (car ec)) (* -1 (calendar-longitude)))) | 547 | (ah (- (* st 15) (* 15 (car ec)) (* -1 (calendar-longitude)))) |
| 556 | (de (car (cdr ec))) | 548 | (de (cadr ec)) |
| 557 | (azimuth (solar-atn2 (- (* (solar-cosine-degrees ah) | 549 | (azimuth (solar-atn2 (- (* (solar-cosine-degrees ah) |
| 558 | (solar-sin-degrees latitude)) | 550 | (solar-sin-degrees latitude)) |
| 559 | (* (solar-tangent-degrees de) | 551 | (* (solar-tangent-degrees de) |
| @@ -567,24 +559,26 @@ The azimuth is given in degrees as well as the height (between -180 and 180)." | |||
| 567 | (if (> height 180) (setq height (- height 360))) | 559 | (if (> height 180) (setq height (- height 360))) |
| 568 | (list azimuth height))) | 560 | (list azimuth height))) |
| 569 | 561 | ||
| 570 | (defun solar-equatorial-coordinates (time for-sunrise-sunset) | 562 | (defun solar-equatorial-coordinates (time sunrise-flag) |
| 571 | "Right ascension (in hours) and declination (in degrees) of the sun at TIME. | 563 | "Right ascension (in hours) and declination (in degrees) of the sun at TIME. |
| 572 | 564 | TIME is a pair with the first component being the number of | |
| 573 | TIME is a pair with the first component being the number of Julian centuries | 565 | Julian centuries elapsed at 0 Universal Time, and the second |
| 574 | elapsed at 0 Universal Time, and the second component being the universal | 566 | component being the universal time. For instance, the pair |
| 575 | time. For instance, the pair corresponding to November 28, 1995 at 16 UT is | 567 | corresponding to November 28, 1995 at 16 UT is (-0.040945 16), |
| 576 | \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between | 568 | -0.040945 being the number of Julian centuries elapsed between |
| 577 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT." | 569 | Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT. SUNRISE-FLAG is passed |
| 570 | to `solar-ecliptic-coordinates'." | ||
| 578 | (let* ((tm (solar-ephemeris-time time)) | 571 | (let* ((tm (solar-ephemeris-time time)) |
| 579 | (ec (solar-ecliptic-coordinates tm for-sunrise-sunset))) | 572 | (ec (solar-ecliptic-coordinates tm sunrise-flag))) |
| 580 | (list (solar-right-ascension (car ec) (car (cdr ec))) | 573 | (list (solar-right-ascension (car ec) (car (cdr ec))) |
| 581 | (solar-declination (car ec) (car (cdr ec)))))) | 574 | (solar-declination (car ec) (car (cdr ec)))))) |
| 582 | 575 | ||
| 583 | (defun solar-ecliptic-coordinates (time for-sunrise-sunset) | 576 | (defun solar-ecliptic-coordinates (time sunrise-flag) |
| 584 | "Apparent longitude of the sun, ecliptic inclination, (both in degrees) | 577 | "Return solar longitude, ecliptic inclination, equation of time, nutation. |
| 585 | equation of time (in hours) and nutation in longitude (in seconds) | 578 | Values are for TIME in Julian centuries of Ephemeris Time since |
| 586 | at moment `time', expressed in julian centuries of Ephemeris Time | 579 | January 1st, 2000, at 12 ET. Longitude and inclination are in |
| 587 | since January 1st, 2000, at 12 ET." | 580 | degrees, equation of time in hours, and nutation in seconds of longitude. |
| 581 | If SUNRISE-FLAG is non-nil, only calculate longitude and inclination." | ||
| 588 | (let* ((l (+ 280.46645 | 582 | (let* ((l (+ 280.46645 |
| 589 | (* 36000.76983 time) | 583 | (* 36000.76983 time) |
| 590 | (* 0.0003032 time time))) ; sun mean longitude | 584 | (* 0.0003032 time time))) ; sun mean longitude |
| @@ -610,35 +604,31 @@ since January 1st, 2000, at 12 ET." | |||
| 610 | (omega (+ 125.04 | 604 | (omega (+ 125.04 |
| 611 | (* -1934.136 time))) | 605 | (* -1934.136 time))) |
| 612 | ;; nut = nutation in longitude, measured in seconds of angle. | 606 | ;; nut = nutation in longitude, measured in seconds of angle. |
| 613 | (nut (if (not for-sunrise-sunset) | 607 | (nut (unless sunrise-flag |
| 614 | (+ (* -17.20 (solar-sin-degrees omega)) | 608 | (+ (* -17.20 (solar-sin-degrees omega)) |
| 615 | (* -1.32 (solar-sin-degrees (* 2 l))) | 609 | (* -1.32 (solar-sin-degrees (* 2 l))) |
| 616 | (* -0.23 (solar-sin-degrees (* 2 ml))) | 610 | (* -0.23 (solar-sin-degrees (* 2 ml))) |
| 617 | (* 0.21 (solar-sin-degrees (* 2 omega)))) | 611 | (* 0.21 (solar-sin-degrees (* 2 omega)))))) |
| 618 | nil)) | 612 | (ecc (unless sunrise-flag ; eccentricity of earth's orbit |
| 619 | (ecc (if (not for-sunrise-sunset) | 613 | (+ 0.016708617 |
| 620 | (+ 0.016708617 | 614 | (* -0.000042037 time) |
| 621 | (* -0.000042037 time) | 615 | (* -0.0000001236 time time)))) |
| 622 | (* -0.0000001236 time time)) ; eccentricity of earth's orbit | 616 | (app (+ L ; apparent longitude of sun |
| 623 | nil)) | ||
| 624 | (app (+ L | ||
| 625 | -0.00569 | 617 | -0.00569 |
| 626 | (* -0.00478 | 618 | (* -0.00478 |
| 627 | (solar-sin-degrees omega)))) ; apparent longitude of sun | 619 | (solar-sin-degrees omega)))) |
| 628 | (y (if (not for-sunrise-sunset) | 620 | (y (unless sunrise-flag |
| 629 | (* (solar-tangent-degrees (/ i 2)) | 621 | (* (solar-tangent-degrees (/ i 2)) |
| 630 | (solar-tangent-degrees (/ i 2))) | 622 | (solar-tangent-degrees (/ i 2))))) |
| 631 | nil)) | ||
| 632 | ;; Equation of time, in hours. | 623 | ;; Equation of time, in hours. |
| 633 | (time-eq (if (not for-sunrise-sunset) | 624 | (time-eq (unless sunrise-flag |
| 634 | (/ (* 12 (+ (* y (solar-sin-degrees (* 2 l))) | 625 | (/ (* 12 (+ (* y (solar-sin-degrees (* 2 l))) |
| 635 | (* -2 ecc (solar-sin-degrees m)) | 626 | (* -2 ecc (solar-sin-degrees m)) |
| 636 | (* 4 ecc y (solar-sin-degrees m) | 627 | (* 4 ecc y (solar-sin-degrees m) |
| 637 | (solar-cosine-degrees (* 2 l))) | 628 | (solar-cosine-degrees (* 2 l))) |
| 638 | (* -0.5 y y (solar-sin-degrees (* 4 l))) | 629 | (* -0.5 y y (solar-sin-degrees (* 4 l))) |
| 639 | (* -1.25 ecc ecc (solar-sin-degrees (* 2 m))))) | 630 | (* -1.25 ecc ecc (solar-sin-degrees (* 2 m))))) |
| 640 | 3.1415926535) | 631 | 3.1415926535)))) |
| 641 | nil))) | ||
| 642 | (list app i time-eq nut))) | 632 | (list app i time-eq nut))) |
| 643 | 633 | ||
| 644 | (defconst solar-data-list | 634 | (defconst solar-data-list |
| @@ -691,16 +681,16 @@ since January 1st, 2000, at 12 ET." | |||
| 691 | (10 2.21 46941.14) | 681 | (10 2.21 46941.14) |
| 692 | (10 3.59 -68.29) | 682 | (10 3.59 -68.29) |
| 693 | (10 1.50 21463.25) | 683 | (10 1.50 21463.25) |
| 694 | (10 2.55 157208.40))) | 684 | (10 2.55 157208.40)) |
| 685 | "Data used for calculation of solar longitude.") | ||
| 695 | 686 | ||
| 696 | (defun solar-longitude (d) | 687 | (defun solar-longitude (d) |
| 697 | "Longitude of sun on astronomical (Julian) day number D. | 688 | "Longitude of sun on astronomical (Julian) day number D. |
| 698 | Accurary is about 0.0006 degree (about 365.25*24*60*0.0006/360 = 1 minutes). | 689 | Accuracy is about 0.0006 degree (about 365.25*24*60*0.0006/360 = 1 minutes). |
| 699 | 690 | The values of `calendar-daylight-savings-starts', | |
| 700 | The values of calendar-daylight-savings-starts, | 691 | `calendar-daylight-savings-starts-time', `calendar-daylight-savings-ends', |
| 701 | calendar-daylight-savings-starts-time, calendar-daylight-savings-ends, | 692 | `calendar-daylight-savings-ends-time', `calendar-daylight-time-offset', and |
| 702 | calendar-daylight-savings-ends-time, calendar-daylight-time-offset, and | 693 | `calendar-time-zone' are used to interpret local time." |
| 703 | calendar-time-zone are used to interpret local time." | ||
| 704 | (let* ((a-d (calendar-absolute-from-astro d)) | 694 | (let* ((a-d (calendar-absolute-from-astro d)) |
| 705 | ;; Get Universal Time. | 695 | ;; Get Universal Time. |
| 706 | (date (calendar-astro-from-absolute | 696 | (date (calendar-astro-from-absolute |
| @@ -736,11 +726,9 @@ calendar-time-zone are used to interpret local time." | |||
| 736 | (mod (radians-to-degrees (+ longitude aberration nutation)) 360.0))) | 726 | (mod (radians-to-degrees (+ longitude aberration nutation)) 360.0))) |
| 737 | 727 | ||
| 738 | (defun solar-ephemeris-correction (year) | 728 | (defun solar-ephemeris-correction (year) |
| 739 | "Ephemeris time minus Universal Time during Gregorian year. | 729 | "Ephemeris time minus Universal Time during Gregorian YEAR. |
| 740 | Result is in days. | 730 | Result is in days. For the years 1800-1987, the maximum error is |
| 741 | 731 | 1.9 seconds. For the other years, the maximum error is about 30 seconds." | |
| 742 | For the years 1800-1987, the maximum error is 1.9 seconds. | ||
| 743 | For the other years, the maximum error is about 30 seconds." | ||
| 744 | (cond ((and (<= 1988 year) (< year 2020)) | 732 | (cond ((and (<= 1988 year) (< year 2020)) |
| 745 | (/ (+ year -2000 67.0) 60.0 60.0 24.0)) | 733 | (/ (+ year -2000 67.0) 60.0 60.0 24.0)) |
| 746 | ((and (<= 1900 year) (< year 1988)) | 734 | ((and (<= 1900 year) (< year 1988)) |
| @@ -797,9 +785,7 @@ For the other years, the maximum error is about 30 seconds." | |||
| 797 | (/ second 60.0 60.0 24.0))))) | 785 | (/ second 60.0 60.0 24.0))))) |
| 798 | 786 | ||
| 799 | (defun solar-sidereal-time (t0) | 787 | (defun solar-sidereal-time (t0) |
| 800 | "Sidereal time (in hours) in Greenwich. | 788 | "Sidereal time (in hours) in Greenwich at T0 Julian centuries. |
| 801 | |||
| 802 | At T0=Julian centuries of universal time. | ||
| 803 | T0 must correspond to 0 hours UT." | 789 | T0 must correspond to 0 hours UT." |
| 804 | (let* ((mean-sid-time (+ 6.6973746 | 790 | (let* ((mean-sid-time (+ 6.6973746 |
| 805 | (* 2400.051337 t0) | 791 | (* 2400.051337 t0) |
| @@ -822,17 +808,16 @@ T0 must correspond to 0 hours UT." | |||
| 822 | 808 | ||
| 823 | (defun solar-date-to-et (date ut) | 809 | (defun solar-date-to-et (date ut) |
| 824 | "Ephemeris Time at Gregorian DATE at Universal Time UT (in hours). | 810 | "Ephemeris Time at Gregorian DATE at Universal Time UT (in hours). |
| 825 | Expressed in julian centuries of Ephemeris Time." | 811 | Expressed in Julian centuries of Ephemeris Time." |
| 826 | (let ((t0 (solar-julian-ut-centuries date))) | 812 | (let ((t0 (solar-julian-ut-centuries date))) |
| 827 | (solar-ephemeris-time (list t0 ut)))) | 813 | (solar-ephemeris-time (list t0 ut)))) |
| 828 | 814 | ||
| 829 | ;;;###autoload | 815 | ;;;###autoload |
| 830 | (defun sunrise-sunset (&optional arg) | 816 | (defun sunrise-sunset (&optional arg) |
| 831 | "Local time of sunrise and sunset for today. Accurate to a few seconds. | 817 | "Local time of sunrise and sunset for today. Accurate to a few seconds. |
| 832 | If called with an optional prefix argument, prompt for date. | 818 | If called with an optional prefix argument ARG, prompt for date. |
| 833 | 819 | If called with an optional double prefix argument, prompt for | |
| 834 | If called with an optional double prefix argument, prompt for longitude, | 820 | longitude, latitude, time zone, and date, and always use standard time. |
| 835 | latitude, time zone, and date, and always use standard time. | ||
| 836 | 821 | ||
| 837 | This function is suitable for execution in a .emacs file." | 822 | This function is suitable for execution in a .emacs file." |
| 838 | (interactive "p") | 823 | (interactive "p") |
| @@ -896,33 +881,38 @@ This function is suitable for execution in a .emacs file." | |||
| 896 | (if pop-up-windows | 881 | (if pop-up-windows |
| 897 | "Type \\[delete-other-windows] to remove temp window." | 882 | "Type \\[delete-other-windows] to remove temp window." |
| 898 | "Type \\[switch-to-buffer] RET to remove temp window.") | 883 | "Type \\[switch-to-buffer] RET to remove temp window.") |
| 899 | "Type \\[switch-to-buffer-other-window] RET to restore old contents of temp window.")))))) | 884 | "Type \\[switch-to-buffer-other-window] RET to restore old \ |
| 885 | contents of temp window.")))))) | ||
| 900 | 886 | ||
| 901 | (defun calendar-sunrise-sunset () | 887 | (defun calendar-sunrise-sunset () |
| 902 | "Local time of sunrise and sunset for date under cursor. | 888 | "Local time of sunrise and sunset for date under cursor. |
| 903 | Accurate to a few seconds." | 889 | Accurate to a few seconds." |
| 904 | (interactive) | 890 | (interactive) |
| 905 | (if (not (and calendar-latitude calendar-longitude calendar-time-zone)) | 891 | (or (and calendar-latitude calendar-longitude calendar-time-zone) |
| 906 | (solar-setup)) | 892 | (solar-setup)) |
| 907 | (let ((date (calendar-cursor-to-date t))) | 893 | (let ((date (calendar-cursor-to-date t))) |
| 908 | (message "%s: %s" | 894 | (message "%s: %s" |
| 909 | (calendar-date-string date t t) | 895 | (calendar-date-string date t t) |
| 910 | (solar-sunrise-sunset-string date)))) | 896 | (solar-sunrise-sunset-string date)))) |
| 911 | 897 | ||
| 898 | (defvar date) | ||
| 899 | |||
| 900 | ;; To be called from list-sexp-diary-entries, where DATE is bound. | ||
| 912 | (defun diary-sunrise-sunset () | 901 | (defun diary-sunrise-sunset () |
| 913 | "Local time of sunrise and sunset as a diary entry. | 902 | "Local time of sunrise and sunset as a diary entry. |
| 914 | Accurate to a few seconds." | 903 | Accurate to a few seconds." |
| 915 | (if (not (and calendar-latitude calendar-longitude calendar-time-zone)) | 904 | (or (and calendar-latitude calendar-longitude calendar-time-zone) |
| 916 | (solar-setup)) | 905 | (solar-setup)) |
| 917 | (solar-sunrise-sunset-string date)) | 906 | (solar-sunrise-sunset-string date)) |
| 918 | 907 | ||
| 908 | ;; To be called from list-sexp-diary-entries, where DATE is bound. | ||
| 919 | (defun diary-sabbath-candles (&optional mark) | 909 | (defun diary-sabbath-candles (&optional mark) |
| 920 | "Local time of candle lighting diary entry--applies if date is a Friday. | 910 | "Local time of candle lighting diary entry--applies if date is a Friday. |
| 921 | No diary entry if there is no sunset on that date. | 911 | No diary entry if there is no sunset on that date. |
| 922 | 912 | ||
| 923 | An optional parameter MARK specifies a face or single-character string to | 913 | An optional parameter MARK specifies a face or single-character string to |
| 924 | use when highlighting the day in the calendar." | 914 | use when highlighting the day in the calendar." |
| 925 | (if (not (and calendar-latitude calendar-longitude calendar-time-zone)) | 915 | (or (and calendar-latitude calendar-longitude calendar-time-zone) |
| 926 | (solar-setup)) | 916 | (solar-setup)) |
| 927 | (if (= (% (calendar-absolute-from-gregorian date) 7) 5) ; Friday | 917 | (if (= (% (calendar-absolute-from-gregorian date) 7) 5) ; Friday |
| 928 | (let* ((sunset (car (cdr (solar-sunrise-sunset date)))) | 918 | (let* ((sunset (car (cdr (solar-sunrise-sunset date)))) |
| @@ -960,15 +950,14 @@ use when highlighting the day in the calendar." | |||
| 960 | (12 287.11 31931.756) | 950 | (12 287.11 31931.756) |
| 961 | (12 320.81 34777.259) | 951 | (12 320.81 34777.259) |
| 962 | (9 227.73 1222.114) | 952 | (9 227.73 1222.114) |
| 963 | (8 15.45 16859.074))) | 953 | (8 15.45 16859.074)) |
| 954 | "Data for solar equinox/solstice calculations.") | ||
| 964 | 955 | ||
| 965 | (defun solar-equinoxes/solstices (k year) | 956 | (defun solar-equinoxes/solstices (k year) |
| 966 | "Date of equinox/solstice K for YEAR. | 957 | "Date of equinox/solstice K for YEAR. |
| 967 | K=0, spring equinox; K=1, summer solstice; K=2, fall equinox; | 958 | K=0, spring equinox; K=1, summer solstice; K=2, fall equinox; |
| 968 | K=3, winter solstice. | 959 | K=3, winter solstice. RESULT is a Gregorian local date. |
| 969 | RESULT is a gregorian local date. | 960 | Accurate to within a minute between 1951 and 2050." |
| 970 | |||
| 971 | Accurate to less than a minute between 1951 and 2050." | ||
| 972 | (let* ((JDE0 (solar-mean-equinoxes/solstices k year)) | 961 | (let* ((JDE0 (solar-mean-equinoxes/solstices k year)) |
| 973 | (T (/ (- JDE0 2451545.0) 36525)) | 962 | (T (/ (- JDE0 2451545.0) 36525)) |
| 974 | (W (- (* 35999.373 T) 2.47)) | 963 | (W (- (* 35999.373 T) 2.47)) |