/[emacs]/emacs/lisp/calendar/solar.el
ViewVC logotype

Diff of /emacs/lisp/calendar/solar.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.41 by pj, Sun Jan 13 10:01:42 2002 UTC revision 1.42 by rms, Wed Apr 3 14:33:57 2002 UTC
# Line 198  delta.  At present, delta = 0.01 degrees Line 198  delta.  At present, delta = 0.01 degrees
198     nil     nil
199     "Sidereal time at Greenwich at midnight (universal time).")     "Sidereal time at Greenwich at midnight (universal time).")
200    
201  (defvar solar-spring-or-summer-season nil    (defvar solar-northern-spring-or-summer-season nil
202    "T if spring or summer and nil otherwise.    "T if northern spring or summer and nil otherwise.
203  Needed for polar areas, in order to know whether the day lasts 0 or 24 hours.")  Needed for polar areas, in order to know whether the day lasts 0 or 24 hours.")
204    
205  (defun solar-setup ()  (defun solar-setup ()
# Line 298  Both arguments are in degrees." Line 298  Both arguments are in degrees."
298     (* (solar-sin-degrees obliquity)     (* (solar-sin-degrees obliquity)
299        (solar-sin-degrees longitude))))        (solar-sin-degrees longitude))))
300    
301  (defun solar-sunrise-and-sunset (time latitude longitude)  (defun solar-sunrise-and-sunset (time latitude longitude height)
302    "Sunrise, sunset and length of day.    "Sunrise, sunset and length of day.
303  Parameters are the midday TIME and the LATITUDE, LONGITUDE of the location.  Parameters are the midday TIME and the LATITUDE, LONGITUDE of the location.
304    
305  TIME is a pair with the first component being the number of Julian centuries  TIME is a pair with the first component being the number of Julian centuries
# Line 308  time.  For instance, the pair correspond Line 308  time.  For instance, the pair correspond
308  \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between  \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between
309  Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.  Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.
310    
311  Coordinates are included because this function is called with latitude=10  HEIGHT is the angle the center of the sun has over the horizon for the contact
312    we are trying to find. For sunrise and sunset, it is usually -0.61 degrees,
313    accounting for the edge of the sun being on the horizon.
314    
315    Coordinates are included because this function is called with latitude=1
316  degrees to find out if polar regions have 24 hours of sun or only night."  degrees to find out if polar regions have 24 hours of sun or only night."
317    (let* ((rise-time (solar-moment -1 latitude longitude time))    (let* ((rise-time (solar-moment -1 latitude longitude time height))
318           (set-time (solar-moment 1 latitude longitude time))           (set-time (solar-moment 1 latitude longitude time height))
319           (day-length))           (day-length))
320      (if (not (and rise-time set-time))      (if (not (and rise-time set-time))
321          (if (or (and (> latitude 0) solar-spring-or-summer-season)          (if (or (and (> latitude 0)
322                  (and (< latitude 0) (not solar-spring-or-summer-season)))                       solar-northern-spring-or-summer-season)
323              (setq day-length 0)                  (and (< latitude 0)
324            (setq day-length 24))                       (not solar-northern-spring-or-summer-season)))
325          (setq day-length (- set-time rise-time)))              (setq day-length 24)
326              (setq day-length 0))
327          (setq day-length (- set-time rise-time)))
328      (list (if rise-time (+ rise-time (/ calendar-time-zone 60.0)) nil)      (list (if rise-time (+ rise-time (/ calendar-time-zone 60.0)) nil)
329            (if set-time (+ set-time (/ calendar-time-zone 60.0)) nil)            (if set-time (+ set-time (/ calendar-time-zone 60.0)) nil)
330            day-length)))            day-length)))
331    
332  (defun solar-moment (direction latitude longitude time)  (defun solar-moment (direction latitude longitude time height)
333    "Sunrise/sunset at location.    "Sunrise/sunset at location.
334  Sunrise if DIRECTION =-1 or sunset if =1 at LATITUDE, LONGITUDE, with midday  Sunrise if DIRECTION =-1 or sunset if =1 at LATITUDE, LONGITUDE, with midday
335  being TIME.  being TIME.
# Line 334  time.  For instance, the pair correspond Line 340  time.  For instance, the pair correspond
340  \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between  \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between
341  Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.  Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.
342    
343    HEIGHT is the angle the center of the sun has over the horizon for the contact
344    we are trying to find. For sunrise and sunset, it is usually -0.61 degrees,
345    accounting for the edge of the sun being on the horizon.
346    
347  Uses binary search."  Uses binary search."
348    (let* ((ut (car (cdr time)))    (let* ((ut (car (cdr time)))
349           (possible 1) ; we assume that rise or set are possible           (possible t) ; we assume that rise or set are possible
350           (utmin (+ ut (* direction 12.0)))           (utmin (+ ut (* direction 12.0)))
351           (utmax ut)    ; the time searched is between utmin and utmax           (utmax ut)    ; the time searched is between utmin and utmax
352              ; utmin and utmax are in hours              ; utmin and utmax are in hours
353           (utmoment-old 0.0)    ; rise or set approximation           (utmoment-old 0.0)    ; rise or set approximation
354           (utmoment 1.0) ; rise or set approximation           (utmoment 1.0) ; rise or set approximation
355           (hut 0)         ; sun height at utmoment           (hut 0)         ; sun height at utmoment
356           (t0 (car time))           (t0 (car time))
357           (hmin (car (cdr           (hmin (car (cdr
358                 (solar-horizontal-coordinates (list t0 utmin)                 (solar-horizontal-coordinates (list t0 utmin)
359                                                  latitude longitude t))))                                                  latitude longitude t))))
360           (hmax (car (cdr           (hmax (car (cdr
361                 (solar-horizontal-coordinates (list t0 utmax)                 (solar-horizontal-coordinates (list t0 utmax)
362                                                  latitude longitude t)))))                                                  latitude longitude t)))))
363         ; -0.61 degrees is the height of the middle of the sun, when it rises         ; -0.61 degrees is the height of the middle of the sun, when it rises
364         ;   or sets.         ;   or sets.
365       (if (< hmin -0.61)       (if (< hmin height)
366                (if (> hmax -0.61)                (if (> hmax height)
367                    (while ;(< i 20) ; we perform a simple dichotomy                    (while ;(< i 20) ; we perform a simple dichotomy
368                           ; (> (abs (+ hut 0.61)) epsilon)                           ; (> (abs (- hut height)) epsilon)
369                           (>= (abs (- utmoment utmoment-old))                           (>= (abs (- utmoment utmoment-old))
370                               (/ solar-error 60))                               (/ solar-error 60))
371                      (setq utmoment-old utmoment)                      (setq utmoment-old utmoment)
372                      (setq utmoment (/ (+ utmin utmax) 2))                      (setq utmoment (/ (+ utmin utmax) 2))
373                      (setq hut (car (cdr                      (setq hut (car (cdr
374                                      (solar-horizontal-coordinates                                      (solar-horizontal-coordinates
375                                     (list t0 utmoment) latitude longitude t))))                                     (list t0 utmoment) latitude longitude t))))
376                      (if (< hut -0.61) (setq utmin utmoment))                      (if (< hut height) (setq utmin utmoment))
377                      (if (> hut -0.61) (setq utmax utmoment))                      (if (> hut height) (setq utmax utmoment))
378                     )                     )
379                  (setq possible 0)) ; the sun never rises                  (setq possible nil)) ; the sun never rises
380                  (setq possible 0)) ; the sun never sets                  (setq possible nil)) ; the sun never sets
381       (if (equal possible 0) nil utmoment)))       (if (not possible) nil utmoment)))
382    
383  (defun solar-time-string (time time-zone)  (defun solar-time-string (time time-zone)
384    "Printable form for decimal fraction TIME in TIME-ZONE.    "Printable form for decimal fraction TIME in TIME-ZONE.
# Line 423  Corresponding value is nil if there is n Line 433  Corresponding value is nil if there is n
433           ; store the sidereal time at Greenwich at midnight of UT time.           ; store the sidereal time at Greenwich at midnight of UT time.
434           ; find if summer or winter slightly above the equator           ; find if summer or winter slightly above the equator
435           (equator-rise-set           (equator-rise-set
436            (progn (setq solar-sidereal-time-greenwich-midnight            (progn (setq solar-sidereal-time-greenwich-midnight
437                         (solar-sidereal-time t0))                         (solar-sidereal-time t0))
438                   (solar-sunrise-and-sunset                   (solar-sunrise-and-sunset
439                    (list t0 (car (cdr exact-local-noon)))                    (list t0 (car (cdr exact-local-noon)))
440                    10.0                    1.0
441                    (calendar-longitude))))                    (calendar-longitude) 0)))
442           ; store the spring/summer information,           ; store the spring/summer information,
443           ; compute sunrise and sunset (two first components of rise-set).           ; compute sunrise and sunset (two first components of rise-set).
444           ; length of day is the third component (it is only the difference           ; length of day is the third component (it is only the difference
445           ; between sunset and sunrise when there is a sunset and a sunrise)           ; between sunset and sunrise when there is a sunset and a sunrise)
446           (rise-set           (rise-set
447            (progn            (progn
448              (setq solar-spring-or-summer-season              (setq solar-northern-spring-or-summer-season
449                    (if (> (car (cdr (cdr equator-rise-set))) 12) 1 0))                    (if (> (car (cdr (cdr equator-rise-set))) 12) t nil))
450              (solar-sunrise-and-sunset              (solar-sunrise-and-sunset
451               (list t0 (car (cdr exact-local-noon)))               (list t0 (car (cdr exact-local-noon)))
452               (calendar-latitude)               (calendar-latitude)
453               (calendar-longitude))))               (calendar-longitude) -0.61)))
454           (rise (car rise-set))           (rise (car rise-set))
455           (adj-rise (if rise (dst-adjust-time date rise) nil))           (adj-rise (if rise (dst-adjust-time date rise) nil))
456           (set (car (cdr rise-set)))           (set (car (cdr rise-set)))
# Line 904  Accurate to a few seconds." Line 914  Accurate to a few seconds."
914        (solar-setup))        (solar-setup))
915    (solar-sunrise-sunset-string date))    (solar-sunrise-sunset-string date))
916    
917    (defcustom diary-sabbath-candles-minutes 18
918      "*Number of minutes before sunset for sabbath candle lighting."
919      :group 'diary
920      :type 'integer
921      :version "21.1")
922    
923  (defun diary-sabbath-candles ()  (defun diary-sabbath-candles ()
924    "Local time of candle lighting diary entry--applies if date is a Friday.    "Local time of candle lighting diary entry--applies if date is a Friday.
925  No diary entry if there is no sunset on that date."  No diary entry if there is no sunset on that date."
# Line 911  No diary entry if there is no sunset on Line 927  No diary entry if there is no sunset on
927        (solar-setup))        (solar-setup))
928    (if (= (% (calendar-absolute-from-gregorian date) 7) 5);;  Friday    (if (= (% (calendar-absolute-from-gregorian date) 7) 5);;  Friday
929        (let* ((sunset (car (cdr (solar-sunrise-sunset date))))        (let* ((sunset (car (cdr (solar-sunrise-sunset date))))
930                    (light (if sunset               (light (if sunset
931                          (cons (- (car sunset) (/ 18.0 60.0)) (cdr sunset)))))                          (cons (- (car sunset)
932                                     (/ diary-sabbath-candles-minutes 60.0))
933                                  (cdr sunset)))))
934          (if sunset          (if sunset
935              (format "%s Sabbath candle lighting"              (format "%s Sabbath candle lighting"
936                      (apply 'solar-time-string light))))))                      (apply 'solar-time-string light))))))

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26