Function: solar-moment
solar-moment is a byte-compiled function defined in solar.el.gz.
Signature
(solar-moment DIRECTION LATITUDE LONGITUDE TIME HEIGHT)
Documentation
Sunrise/sunset at location.
Sunrise if DIRECTION =-1 or sunset if =1 at LATITUDE, LONGITUDE, with midday being TIME.
TIME is a pair with the first component being the number of Julian centuries
elapsed at 0 Universal Time, and the second component counting Universal Time
hours. For instance, the pair corresponding to November 28, 1995 at 16 UT is
(-0.040945 16), -0.040945 being the number of Julian centuries elapsed between
Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.
HEIGHT is the angle the center of the sun has over the horizon for the contact we are trying to find. For sunrise and sunset, it is usually -0.61 degrees, accounting for the edge of the sun being on the horizon.
Uses binary search.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/solar.el.gz
(defun solar-moment (direction latitude longitude time height)
"Sunrise/sunset at location.
Sunrise if DIRECTION =-1 or sunset if =1 at LATITUDE, LONGITUDE, with midday
being TIME.
TIME is a pair with the first component being the number of Julian centuries
elapsed at 0 Universal Time, and the second component counting Universal Time
hours. For instance, the pair corresponding to November 28, 1995 at 16 UT is
\(-0.040945 16), -0.040945 being the number of Julian centuries elapsed between
Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.
HEIGHT is the angle the center of the sun has over the horizon for the contact
we are trying to find. For sunrise and sunset, it is usually -0.61 degrees,
accounting for the edge of the sun being on the horizon.
Uses binary search."
(let* ((ut (cadr time))
(possible t) ; we assume that rise or set are possible
(utmin (+ ut (* direction 12.0)))
(utmax ut) ; the time searched is between utmin and utmax
;; utmin and utmax are in hours.
(utmoment-old utmin) ; rise or set approximation
(utmoment utmax) ; rise or set approximation
(hut 0) ; sun height at utmoment
(t0 (car time))
(hmin (cadr (solar-horizontal-coordinates (list t0 utmin)
latitude longitude t)))
(hmax (cadr (solar-horizontal-coordinates (list t0 utmax)
latitude longitude t))))
;; -0.61 degrees is the height of the middle of the sun, when it
;; rises or sets.
(if (< hmin height)
(if (> hmax height)
(while ;;; (< i 20) ; we perform a simple dichotomy
;;; (> (abs (- hut height)) epsilon)
(>= (abs (- utmoment utmoment-old))
(/ solar-error 60))
(setq utmoment-old utmoment
utmoment (/ (+ utmin utmax) 2)
hut (cadr (solar-horizontal-coordinates
(list t0 utmoment) latitude longitude t)))
(if (< hut height) (setq utmin utmoment))
(if (> hut height) (setq utmax utmoment)))
(setq possible nil)) ; the sun never rises
(setq possible nil)) ; the sun never sets
(if possible utmoment)))