annotate lisp/calendar/solar.el @ 49583:ffebff40964c

(dired-find-buffer-nocreate): Avoid error if dired-directory is nil.
author Richard M. Stallman <rms@gnu.org>
date Tue, 04 Feb 2003 10:39:35 +0000
parents f1e846c193c7
children 0d8b17d428b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 20462
diff changeset
1 ;;; solar.el --- calendar functions for solar events
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
3 ;; Copyright (C) 1992, 1993, 1995, 1997 Free Software Foundation, Inc.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
6 ;; Denis B. Roegel <Denis.Roegel@loria.fr>
2249
94fc2ce49c55 Corrected Keywords header
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2248
diff changeset
7 ;; Keywords: calendar
94fc2ce49c55 Corrected Keywords header
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2248
diff changeset
8 ;; Human-Keywords: sunrise, sunset, equinox, solstice, calendar, diary,
94fc2ce49c55 Corrected Keywords header
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2248
diff changeset
9 ;; holidays
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12
6736
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
16 ;; any later version.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17
6736
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
21 ;; GNU General Public License for more details.
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
22
3e1323443b1a Fix copying conditions for current GPL version.
Richard M. Stallman <rms@gnu.org>
parents: 5835
diff changeset
23 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13874
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13874
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13874
diff changeset
26 ;; Boston, MA 02111-1307, USA.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 ;;; Commentary:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
30 ;; This collection of functions implements the features of calendar.el,
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
31 ;; diary.el, and holiday.el that deal with times of day, sunrise/sunset, and
13742
6896ecdd9378 Fix misspelling in comment.
Paul Eggert <eggert@twinsun.com>
parents: 13668
diff changeset
32 ;; equinoxes/solstices.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; Based on the ``Almanac for Computers 1984,'' prepared by the Nautical
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
35 ;; Almanac Office, United States Naval Observatory, Washington, 1984, on
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
36 ;; ``Astronomical Formulae for Calculators,'' 3rd ed., by Jean Meeus,
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
37 ;; Willmann-Bell, Inc., 1985, on ``Astronomical Algorithms'' by Jean Meeus,
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
38 ;; Willmann-Bell, Inc., 1991, and on ``Planetary Programs and Tables from
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
39 ;; -4000 to +2800'' by Pierre Bretagnon and Jean-Louis Simon, Willmann-Bell,
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
40 ;; Inc., 1986.
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
41
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;;
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
43 ;; Accuracy:
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
44 ;; 1. Sunrise/sunset times will be accurate to the minute for years
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
45 ;; 1951--2050. For other years the times will be within +/- 2 minutes.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;;
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
47 ;; 2. Equinox/solstice times will be accurate to the minute for years
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
48 ;; 1951--2050. For other years the times will be within +/- 1 minute.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49
20462
d179de7ad92e Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents: 19898
diff changeset
50 ;; Technical details of all the calendrical calculations can be found in
d179de7ad92e Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents: 19898
diff changeset
51 ;; ``Calendrical Calculations'' by Nachum Dershowitz and Edward M. Reingold,
d179de7ad92e Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents: 19898
diff changeset
52 ;; Cambridge University Press (1997).
d179de7ad92e Add reference to new Calendrical Calculations book.
Paul Eggert <eggert@twinsun.com>
parents: 19898
diff changeset
53
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 ;; Comments, corrections, and improvements should be sent to
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 ;; Edward M. Reingold Department of Computer Science
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 ;; Urbana, Illinois 61801
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 ;;; Code:
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 (if (fboundp 'atan)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 (require 'lisp-float-type)
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 20462
diff changeset
64 (error "Solar/lunar calculations impossible since floating point is unavailable"))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
66 (require 'cal-dst)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
67 (require 'cal-julian)
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
68
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
69 ;;;###autoload
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
70 (defcustom calendar-time-display-form
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
71 '(12-hours ":" minutes am-pm
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
72 (if time-zone " (") time-zone (if time-zone ")"))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
73 "*The pseudo-pattern that governs the way a time of day is formatted.
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
74
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
75 A pseudo-pattern is a list of expressions that can involve the keywords
47252
0fcc52168240 (calendar-time-display-form): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 46617
diff changeset
76 `12-hours', `24-hours', and `minutes', all numbers in string form,
0fcc52168240 (calendar-time-display-form): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 46617
diff changeset
77 and `am-pm' and `time-zone', both alphabetic strings.
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
78
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
79 For example, the form
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
80
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
81 '(24-hours \":\" minutes
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
82 (if time-zone \" (\") time-zone (if time-zone \")\"))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
83
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
84 would give military-style times like `21:07 (UTC)'."
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
85 :type 'sexp
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
86 :group 'calendar)
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
87
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
88 ;;;###autoload
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
89 (defcustom calendar-latitude nil
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
90 "*Latitude of `calendar-location-name' in degrees.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
91
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
92 The value can be either a decimal fraction (one place of accuracy is
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
93 sufficient), + north, - south, such as 40.7 for New York City, or the value
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
94 can be a vector [degrees minutes north/south] such as [40 50 north] for New
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
95 York City.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
96
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
97 This variable should be set in `site-start'.el."
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
98 :type '(choice (const nil)
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
99 (number :tag "Exact")
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
100 (vector :value [0 0 north]
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
101 (integer :tag "Degrees")
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
102 (integer :tag "Minutes")
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
103 (choice :tag "Position"
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
104 (const north)
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
105 (const south))))
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
106 :group 'calendar)
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
107
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
108 ;;;###autoload
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
109 (defcustom calendar-longitude nil
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
110 "*Longitude of `calendar-location-name' in degrees.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
111
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
112 The value can be either a decimal fraction (one place of accuracy is
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
113 sufficient), + east, - west, such as -73.9 for New York City, or the value
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
114 can be a vector [degrees minutes east/west] such as [73 55 west] for New
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
115 York City.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
116
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
117 This variable should be set in `site-start'.el."
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
118 :type '(choice (const nil)
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
119 (number :tag "Exact")
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
120 (vector :value [0 0 west]
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
121 (integer :tag "Degrees")
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
122 (integer :tag "Minutes")
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
123 (choice :tag "Position"
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
124 (const east)
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
125 (const west))))
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
126 :group 'calendar)
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
127
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
128 (defsubst calendar-latitude ()
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
129 "Convert calendar-latitude to a signed decimal fraction, if needed."
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
130 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
131 calendar-latitude
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
132 (let ((lat (+ (aref calendar-latitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
133 (/ (aref calendar-latitude 1) 60.0))))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
134 (if (equal (aref calendar-latitude 2) 'north)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
135 lat
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
136 (- lat)))))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
137
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
138 (defsubst calendar-longitude ()
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
139 "Convert calendar-longitude to a signed decimal fraction, if needed."
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
140 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
141 calendar-longitude
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
142 (let ((long (+ (aref calendar-longitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
143 (/ (aref calendar-longitude 1) 60.0))))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
144 (if (equal (aref calendar-longitude 2) 'east)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
145 long
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
146 (- long)))))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
147
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
148 ;;;###autoload
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
149 (defcustom calendar-location-name
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
150 '(let ((float-output-format "%.1f"))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
151 (format "%s%s, %s%s"
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
152 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
153 (abs calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
154 (+ (aref calendar-latitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
155 (/ (aref calendar-latitude 1) 60.0)))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
156 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
157 (if (> calendar-latitude 0) "N" "S")
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
158 (if (equal (aref calendar-latitude 2) 'north) "N" "S"))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
159 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
160 (abs calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
161 (+ (aref calendar-longitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
162 (/ (aref calendar-longitude 1) 60.0)))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
163 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
164 (if (> calendar-longitude 0) "E" "W")
12312
7816b2769014 Fix bug in determination of output string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 9829
diff changeset
165 (if (equal (aref calendar-longitude 2) 'east) "E" "W"))))
19898
ef7d802592ec (calendar-location-name): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 17626
diff changeset
166 "*Expression evaluating to name of `calendar-longitude', `calendar-latitude'.
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
167 For example, \"New York City\". Default value is just the latitude, longitude
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
168 pair.
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
169
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
170 This variable should be set in `site-start'.el."
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
171 :type 'sexp
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
172 :group 'calendar)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
173
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
174 (defcustom solar-error 0.5
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
175 "*Tolerance (in minutes) for sunrise/sunset calculations.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
176
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
177 A larger value makes the calculations for sunrise/sunset faster, but less
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
178 accurate. The default is half a minute (30 seconds), so that sunrise/sunset
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
179 times will be correct to the minute.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
180
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
181 It is useless to set the value smaller than 4*delta, where delta is the
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
182 accuracy in the longitude of the sun (given by the function
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
183 `solar-ecliptic-coordinates') in degrees since (delta/360) x (86400/60) = 4 x
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
184 delta. At present, delta = 0.01 degrees, so the value of the variable
17626
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
185 `solar-error' should be at least 0.04 minutes (about 2.5 seconds)."
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
186 :type 'number
68cce262538d Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 15095
diff changeset
187 :group 'calendar)
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188
4863
adfd03a381ca (solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 4766
diff changeset
189 (defvar solar-n-hemi-seasons
4766
ec8c8721b7e3 (s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents: 4660
diff changeset
190 '("Vernal Equinox" "Summer Solstice" "Autumnal Equinox" "Winter Solstice")
ec8c8721b7e3 (s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents: 4660
diff changeset
191 "List of season changes for the northern hemisphere.")
ec8c8721b7e3 (s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents: 4660
diff changeset
192
4863
adfd03a381ca (solar-n-hemi-seasons, solar-s-hemi-seasons): New vars.
Richard M. Stallman <rms@gnu.org>
parents: 4766
diff changeset
193 (defvar solar-s-hemi-seasons
4766
ec8c8721b7e3 (s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents: 4660
diff changeset
194 '("Autumnal Equinox" "Winter Solstice" "Vernal Equinox" "Summer Solstice")
ec8c8721b7e3 (s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents: 4660
diff changeset
195 "List of season changes for the southern hemisphere.")
ec8c8721b7e3 (s-hemi-seasons n-hemi-seasons): New constants are hemisphere
Brian Fox <bfox@gnu.org>
parents: 4660
diff changeset
196
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
197 (defvar solar-sidereal-time-greenwich-midnight
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
198 nil
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
199 "Sidereal time at Greenwich at midnight (universal time).")
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
200
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
201 (defvar solar-northern-spring-or-summer-season nil
44395
ff17e15cf8c8 (solar-northern-spring-or-summer-season): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 44367
diff changeset
202 "Non-nil if northern spring or summer and nil otherwise.
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
203 Needed for polar areas, in order to know whether the day lasts 0 or 24 hours.")
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
204
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 (defun solar-setup ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 "Prompt user for latitude, longitude, and time zone."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (beep)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (if (not calendar-longitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 (setq calendar-longitude
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 "Enter longitude (decimal fraction; + east, - west): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (if (not calendar-latitude)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (setq calendar-latitude
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 "Enter latitude (decimal fraction; + north, - south): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 (if (not calendar-time-zone)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 (setq calendar-time-zone
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (solar-get-number
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
219 "Enter difference from Coordinated Universal Time (in minutes): "))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (defun solar-get-number (prompt)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 "Return a number from the minibuffer, prompting with PROMPT.
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 Returns nil if nothing was entered."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (let ((x (read-string prompt "")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (if (not (string-equal x ""))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (string-to-int x))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
228 ;; The condition-case stuff is needed to catch bogus arithmetic
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
229 ;; exceptions that occur on some machines (like Sparcs)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
230 (defun solar-sin-degrees (x)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
231 (condition-case nil
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
232 (sin (degrees-to-radians (mod x 360.0)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
233 (solar-sin-degrees x)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
234 (defun solar-cosine-degrees (x)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
235 (condition-case nil
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
236 (cos (degrees-to-radians (mod x 360.0)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
237 (solar-cosine-degrees x)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
238 (defun solar-tangent-degrees (x)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
239 (condition-case nil
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
240 (tan (degrees-to-radians (mod x 360.0)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
241 (solar-tangent-degrees x)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
242
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (defun solar-xy-to-quadrant (x y)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 "Determines the quadrant of the point X, Y."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (if (> x 0)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (if (> y 0) 1 4)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 (if (> y 0) 2 3)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (defun solar-degrees-to-quadrant (angle)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 "Determines the quadrant of ANGLE."
4660
2516bc453477 Use integers instead of floating point where they will do.
Paul Eggert <eggert@twinsun.com>
parents: 4657
diff changeset
251 (1+ (floor (mod angle 360) 90)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (defun solar-arctan (x quad)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 "Arctangent of X in quadrant QUAD."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (let ((deg (radians-to-degrees (atan x))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (cond ((equal quad 2) (+ deg 180))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 ((equal quad 3) (+ deg 180))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 ((equal quad 4) (+ deg 360))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (t deg))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
261 (defun solar-atn2 (x y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
262 "Arctan of point X, Y."
14917
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
263 (if (= x 0)
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
264 (if (> y 0) 90 270)
48674
f1e846c193c7 (solar-atn2): Give correct quadrant for arctan.
Richard M. Stallman <rms@gnu.org>
parents: 47629
diff changeset
265 (solar-arctan (/ y x) (solar-xy-to-quadrant x y))))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
266
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (defun solar-arccos (x)
14917
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
268 "Arcos of X."
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
269 (let ((y (sqrt (- 1 (* x x)))))
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
270 (solar-atn2 x y)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (defun solar-arcsin (y)
14917
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
273 "Arcsin of Y."
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
274 (let ((x (sqrt (- 1 (* y y)))))
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
275 (solar-atn2 x y)
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
276 ))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
278 (defsubst solar-degrees-to-hours (degrees)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
279 "Convert DEGREES to hours."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
280 (/ degrees 15.0))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
282 (defsubst solar-hours-to-days (hour)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
283 "Convert HOUR to decimal fraction of a day."
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
284 (/ hour 24.0))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
286 (defun solar-right-ascension (longitude obliquity)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
287 "Right ascension of the sun, in hours, given LONGITUDE and OBLIQUITY.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
288 Both arguments are in degrees."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 (solar-degrees-to-hours
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 (solar-arctan
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
291 (* (solar-cosine-degrees obliquity) (solar-tangent-degrees longitude))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 (solar-degrees-to-quadrant longitude))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
294 (defun solar-declination (longitude obliquity)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
295 "Declination of the sun, in degrees, given LONGITUDE and OBLIQUITY.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
296 Both arguments are in degrees."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 (solar-arcsin
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
298 (* (solar-sin-degrees obliquity)
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (solar-sin-degrees longitude))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
301 (defun solar-sunrise-and-sunset (time latitude longitude height)
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
302 "Sunrise, sunset and length of day.
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
303 Parameters are the midday TIME and the LATITUDE, LONGITUDE of the location.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
304
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
305 TIME is a pair with the first component being the number of Julian centuries
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
306 elapsed at 0 Universal Time, and the second component being the universal
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
307 time. For instance, the pair corresponding to November 28, 1995 at 16 UT is
14267
da2d268f737f Fixed doc strings and references to calendar-latitude and calendar-longitude.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14169
diff changeset
308 \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
309 Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
310
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
311 HEIGHT is the angle the center of the sun has over the horizon for the contact
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
312 we are trying to find. For sunrise and sunset, it is usually -0.61 degrees,
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
313 accounting for the edge of the sun being on the horizon.
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
314
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
315 Coordinates are included because this function is called with latitude=1
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
316 degrees to find out if polar regions have 24 hours of sun or only night."
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
317 (let* ((rise-time (solar-moment -1 latitude longitude time height))
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
318 (set-time (solar-moment 1 latitude longitude time height))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
319 (day-length))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
320 (if (not (and rise-time set-time))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
321 (if (or (and (> latitude 0)
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
322 solar-northern-spring-or-summer-season)
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
323 (and (< latitude 0)
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
324 (not solar-northern-spring-or-summer-season)))
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
325 (setq day-length 24)
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
326 (setq day-length 0))
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
327 (setq day-length (- set-time rise-time)))
14917
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
328 (list (if rise-time (+ rise-time (/ calendar-time-zone 60.0)) nil)
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
329 (if set-time (+ set-time (/ calendar-time-zone 60.0)) nil)
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
330 day-length)))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
331
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
332 (defun solar-moment (direction latitude longitude time height)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
333 "Sunrise/sunset at location.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
334 Sunrise if DIRECTION =-1 or sunset if =1 at LATITUDE, LONGITUDE, with midday
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
335 being TIME.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
336
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
337 TIME is a pair with the first component being the number of Julian centuries
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
338 elapsed at 0 Universal Time, and the second component being the universal
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
339 time. For instance, the pair corresponding to November 28, 1995 at 16 UT is
14273
73b9ac33b161 (solar-moment, solar-ephemeris-time, solar-equatorial-coordinates,
Erik Naggum <erik@naggum.no>
parents: 14267
diff changeset
340 \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
341 Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
342
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
343 HEIGHT is the angle the center of the sun has over the horizon for the contact
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
344 we are trying to find. For sunrise and sunset, it is usually -0.61 degrees,
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
345 accounting for the edge of the sun being on the horizon.
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
346
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
347 Uses binary search."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
348 (let* ((ut (car (cdr time)))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
349 (possible t) ; we assume that rise or set are possible
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
350 (utmin (+ ut (* direction 12.0)))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
351 (utmax ut) ; the time searched is between utmin and utmax
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
352 ; utmin and utmax are in hours
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
353 (utmoment-old 0.0) ; rise or set approximation
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
354 (utmoment 1.0) ; rise or set approximation
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
355 (hut 0) ; sun height at utmoment
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
356 (t0 (car time))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
357 (hmin (car (cdr
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
358 (solar-horizontal-coordinates (list t0 utmin)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
359 latitude longitude t))))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
360 (hmax (car (cdr
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
361 (solar-horizontal-coordinates (list t0 utmax)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
362 latitude longitude t)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
363 ; -0.61 degrees is the height of the middle of the sun, when it rises
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
364 ; or sets.
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
365 (if (< hmin height)
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
366 (if (> hmax height)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
367 (while ;(< i 20) ; we perform a simple dichotomy
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
368 ; (> (abs (- hut height)) epsilon)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
369 (>= (abs (- utmoment utmoment-old))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
370 (/ solar-error 60))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
371 (setq utmoment-old utmoment)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
372 (setq utmoment (/ (+ utmin utmax) 2))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
373 (setq hut (car (cdr
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
374 (solar-horizontal-coordinates
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
375 (list t0 utmoment) latitude longitude t))))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
376 (if (< hut height) (setq utmin utmoment))
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
377 (if (> hut height) (setq utmax utmoment))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
378 )
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
379 (setq possible nil)) ; the sun never rises
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
380 (setq possible nil)) ; the sun never sets
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
381 (if (not possible) nil utmoment)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
383 (defun solar-time-string (time time-zone)
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
384 "Printable form for decimal fraction TIME in TIME-ZONE.
7778
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
385 Format used is given by `calendar-time-display-form'."
b0e2bd1e825a (solar-sunrise, solar-sunset): Fix doc string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7255
diff changeset
386 (let* ((time (round (* 60 time)))
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
387 (24-hours (/ time 60))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
388 (minutes (format "%02d" (% time 60)))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
389 (12-hours (format "%d" (1+ (% (+ 24-hours 11) 12))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 (am-pm (if (>= 24-hours 12) "pm" "am"))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 (24-hours (format "%02d" 24-hours)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 (mapconcat 'eval calendar-time-display-form "")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
394
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
395 (defun solar-daylight (time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
396 "Printable form for time expressed in hours."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
397 (format "%d:%02d"
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
398 (floor time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
399 (floor (* 60 (- time (floor time))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
400
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
401 (defun solar-exact-local-noon (date)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
402 "Date and Universal Time of local noon at *local date* date.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
403
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
404 The date may be different from the one asked for, but it will be the right
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
405 local date. The second component of date should be an integer."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
406 (let* ((nd date)
14267
da2d268f737f Fixed doc strings and references to calendar-latitude and calendar-longitude.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14169
diff changeset
407 (ut (- 12.0 (/ (calendar-longitude) 15)))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
408 (te (solar-time-equation date ut)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
409 (setq ut (- ut te))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
410 (if (>= ut 24)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
411 (progn
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
412 (setq nd (list (car date) (+ 1 (car (cdr date)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
413 (car (cdr (cdr date)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
414 (setq ut (- ut 24))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
415 (if (< ut 0)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
416 (progn
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
417 (setq nd (list (car date) (- (car (cdr date)) 1)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
418 (car (cdr (cdr date)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
419 (setq ut (+ ut 24))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
420 (setq nd (calendar-gregorian-from-absolute
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
421 (calendar-absolute-from-gregorian nd)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
422 ; date standardization
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
423 (list nd ut)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
424
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 (defun solar-sunrise-sunset (date)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
426 "List of *local* times of sunrise, sunset, and daylight on Gregorian DATE.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
427
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
428 Corresponding value is nil if there is no sunrise/sunset."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
429 (let* (; first, get the exact moment of local noon.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
430 (exact-local-noon (solar-exact-local-noon date))
42706
be541feb06cc Fix typo.
Pavel Janík <Pavel@Janik.cz>
parents: 40935
diff changeset
431 ; get the time from the 2000 epoch.
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
432 (t0 (solar-julian-ut-centuries (car exact-local-noon)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
433 ; store the sidereal time at Greenwich at midnight of UT time.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
434 ; find if summer or winter slightly above the equator
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
435 (equator-rise-set
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
436 (progn (setq solar-sidereal-time-greenwich-midnight
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
437 (solar-sidereal-time t0))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
438 (solar-sunrise-and-sunset
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
439 (list t0 (car (cdr exact-local-noon)))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
440 1.0
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
441 (calendar-longitude) 0)))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
442 ; store the spring/summer information,
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
443 ; compute sunrise and sunset (two first components of rise-set).
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
444 ; length of day is the third component (it is only the difference
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
445 ; between sunset and sunrise when there is a sunset and a sunrise)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
446 (rise-set
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
447 (progn
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
448 (setq solar-northern-spring-or-summer-season
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
449 (if (> (car (cdr (cdr equator-rise-set))) 12) t nil))
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
450 (solar-sunrise-and-sunset
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
451 (list t0 (car (cdr exact-local-noon)))
14267
da2d268f737f Fixed doc strings and references to calendar-latitude and calendar-longitude.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14169
diff changeset
452 (calendar-latitude)
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
453 (calendar-longitude) -0.61)))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
454 (rise (car rise-set))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
455 (adj-rise (if rise (dst-adjust-time date rise) nil))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
456 (set (car (cdr rise-set)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
457 (adj-set (if set (dst-adjust-time date set) nil))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
458 (length (car (cdr (cdr rise-set)))) )
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
459 (list
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
460 (and rise (calendar-date-equal date (car adj-rise)) (cdr adj-rise))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
461 (and set (calendar-date-equal date (car adj-set)) (cdr adj-set))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
462 (solar-daylight length))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
463
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
464 (defun solar-sunrise-sunset-string (date)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
465 "String of *local* times of sunrise, sunset, and daylight on Gregorian DATE."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
466 (let ((l (solar-sunrise-sunset date)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
467 (format
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
468 "%s, %s at %s (%s hours daylight)"
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
469 (if (car l)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
470 (concat "Sunrise " (apply 'solar-time-string (car l)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
471 "No sunrise")
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
472 (if (car (cdr l))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
473 (concat "sunset " (apply 'solar-time-string (car (cdr l))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
474 "no sunset")
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
475 (eval calendar-location-name)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
476 (car (cdr (cdr l))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
477
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
478 (defun solar-julian-ut-centuries (date)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
479 "Number of Julian centuries elapsed since 1 Jan, 2000 at noon U.T. for Gregorian DATE."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
480 (/ (- (calendar-absolute-from-gregorian date)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
481 (calendar-absolute-from-gregorian '(1 1.5 2000)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
482 36525.0))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
483
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
484 (defun solar-ephemeris-time(time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
485 "Ephemeris Time at moment TIME.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
486
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
487 TIME is a pair with the first component being the number of Julian centuries
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
488 elapsed at 0 Universal Time, and the second component being the universal
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
489 time. For instance, the pair corresponding to November 28, 1995 at 16 UT is
14273
73b9ac33b161 (solar-moment, solar-ephemeris-time, solar-equatorial-coordinates,
Erik Naggum <erik@naggum.no>
parents: 14267
diff changeset
490 \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
491 Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
492
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
493 Result is in julian centuries of ephemeris time."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
494 (let* ((t0 (car time))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
495 (ut (car (cdr time)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
496 (t1 (+ t0 (/ (/ ut 24.0) 36525)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
497 (y (+ 2000 (* 100 t1)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
498 (dt (* 86400 (solar-ephemeris-correction (floor y)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
499 (+ t1 (/ (/ dt 86400) 36525))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
501 (defun solar-date-next-longitude (d l)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
502 "First moment on or after Julian day number D when sun's longitude is a
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
503 multiple of L degrees at calendar-location-name with that location's
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
504 local time (including any daylight savings rules).
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
505
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
506 L must be an integer divisor of 360.
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
507
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
508 Result is in local time expressed astronomical (Julian) day numbers.
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
509
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
510 The values of calendar-daylight-savings-starts,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
511 calendar-daylight-savings-starts-time, calendar-daylight-savings-ends,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
512 calendar-daylight-savings-ends-time, calendar-daylight-time-offset, and
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
513 calendar-time-zone are used to interpret local time."
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
514 (let* ((long)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
515 (start d)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
516 (start-long (solar-longitude d))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
517 (next (mod (* l (1+ (floor (/ start-long l)))) 360))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
518 (end (+ d (* (/ l 360.0) 400)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
519 (end-long (solar-longitude end)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
520 (while ;; bisection search for nearest minute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
521 (< 0.00001 (- end start))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
522 ;; start <= d < end
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
523 ;; start-long <= next < end-long when next != 0
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
524 ;; when next = 0, we look for the discontinuity (start-long is near 360
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
525 ;; and end-long is small (less than l).
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
526 (setq d (/ (+ start end) 2.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
527 (setq long (solar-longitude d))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
528 (if (or (and (/= next 0) (< long next))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
529 (and (= next 0) (< l long)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
530 (progn
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
531 (setq start d)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
532 (setq start-long long))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
533 (setq end d)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
534 (setq end-long long)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
535 (/ (+ start end) 2.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
536
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
537 (defun solar-horizontal-coordinates
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
538 (time latitude longitude for-sunrise-sunset)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
539 "Azimuth and height of the sun at TIME, LATITUDE, and LONGITUDE.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
540
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
541 TIME is a pair with the first component being the number of Julian centuries
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
542 elapsed at 0 Universal Time, and the second component being the universal
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
543 time. For instance, the pair corresponding to November 28, 1995 at 16 UT is
14273
73b9ac33b161 (solar-moment, solar-ephemeris-time, solar-equatorial-coordinates,
Erik Naggum <erik@naggum.no>
parents: 14267
diff changeset
544 \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
545 Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
546
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
547 The azimuth is given in degrees as well as the height (between -180 and 180)."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
548 (let* ((ut (car (cdr time)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
549 (ec (solar-equatorial-coordinates time for-sunrise-sunset))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
550 (st (+ solar-sidereal-time-greenwich-midnight
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
551 (* ut 1.00273790935)))
14267
da2d268f737f Fixed doc strings and references to calendar-latitude and calendar-longitude.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14169
diff changeset
552 (ah (- (* st 15) (* 15 (car ec)) (* -1 (calendar-longitude))))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
553 ; hour angle (in degrees)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
554 (de (car (cdr ec)))
14917
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
555 (azimuth (solar-atn2 (- (* (solar-cosine-degrees ah)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
556 (solar-sin-degrees latitude))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
557 (* (solar-tangent-degrees de)
14917
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
558 (solar-cosine-degrees latitude)))
f353b7b88418 Fixed solar-arcsin/arcos stuff.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14331
diff changeset
559 (solar-sin-degrees ah)))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
560 (height (solar-arcsin
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
561 (+ (* (solar-sin-degrees latitude) (solar-sin-degrees de))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
562 (* (solar-cosine-degrees latitude)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
563 (solar-cosine-degrees de)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
564 (solar-cosine-degrees ah))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
565 (if (> height 180) (setq height (- height 360)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
566 (list azimuth height)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
567
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
568 (defun solar-equatorial-coordinates (time for-sunrise-sunset)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
569 "Right ascension (in hours) and declination (in degrees) of the sun at TIME.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
570
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
571 TIME is a pair with the first component being the number of Julian centuries
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
572 elapsed at 0 Universal Time, and the second component being the universal
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
573 time. For instance, the pair corresponding to November 28, 1995 at 16 UT is
14273
73b9ac33b161 (solar-moment, solar-ephemeris-time, solar-equatorial-coordinates,
Erik Naggum <erik@naggum.no>
parents: 14267
diff changeset
574 \(-0.040945 16), -0.040945 being the number of julian centuries elapsed between
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
575 Jan 1, 2000 at 12 UT and November 28, 1995 at 0 UT."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
576 (let* ((tm (solar-ephemeris-time time))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
577 (ec (solar-ecliptic-coordinates tm for-sunrise-sunset)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
578 (list (solar-right-ascension (car ec) (car (cdr ec)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
579 (solar-declination (car ec) (car (cdr ec))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
580
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
581 (defun solar-ecliptic-coordinates (time for-sunrise-sunset)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
582 "Apparent longitude of the sun, ecliptic inclination, (both in degrees)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
583 equation of time (in hours) and nutation in longitude (in seconds)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
584 at moment `time', expressed in julian centuries of Ephemeris Time
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
585 since January 1st, 2000, at 12 ET."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
586 (let* ((l (+ 280.46645
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
587 (* 36000.76983 time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
588 (* 0.0003032 time time))) ; sun mean longitude
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
589 (ml (+ 218.3165
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
590 (* 481267.8813 time))) ; moon mean longitude
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
591 (m (+ 357.52910
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
592 (* 35999.05030 time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
593 (* -0.0001559 time time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
594 (* -0.00000048 time time time))) ; sun mean anomaly
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
595 (i (+ 23.43929111 (* -0.013004167 time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
596 (* -0.00000016389 time time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
597 (* 0.0000005036 time time time))); mean inclination
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
598 (c (+ (* (+ 1.914600
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
599 (* -0.004817 time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
600 (* -0.000014 time time))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
601 (solar-sin-degrees m))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
602 (* (+ 0.019993 (* -0.000101 time))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
603 (solar-sin-degrees (* 2 m)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
604 (* 0.000290
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
605 (solar-sin-degrees (* 3 m))))) ; center equation
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
606 (L (+ l c)) ; total longitude
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
607 (omega (+ 125.04
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
608 (* -1934.136 time))) ; longitude of moon's ascending node
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
609 ; on the ecliptic
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
610 (nut (if (not for-sunrise-sunset)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
611 (+ (* -17.20 (solar-sin-degrees omega))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
612 (* -1.32 (solar-sin-degrees (* 2 l)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
613 (* -0.23 (solar-sin-degrees (* 2 ml)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
614 (* 0.21 (solar-sin-degrees (* 2 omega))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
615 nil))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
616 ; nut = nutation in longitude, measured in seconds of angle.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
617 (ecc (if (not for-sunrise-sunset)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
618 (+ 0.016708617
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
619 (* -0.000042037 time)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
620 (* -0.0000001236 time time)) ; eccentricity of earth's orbit
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
621 nil))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
622 (app (+ L
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
623 -0.00569
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
624 (* -0.00478
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
625 (solar-sin-degrees omega)))) ; apparent longitude of sun
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
626 (y (if (not for-sunrise-sunset)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
627 (* (solar-tangent-degrees (/ i 2))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
628 (solar-tangent-degrees (/ i 2)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
629 nil))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
630 (time-eq (if (not for-sunrise-sunset)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
631 (/ (* 12 (+ (* y (solar-sin-degrees (* 2 l)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
632 (* -2 ecc (solar-sin-degrees m))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
633 (* 4 ecc y (solar-sin-degrees m)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
634 (solar-cosine-degrees (* 2 l)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
635 (* -0.5 y y (solar-sin-degrees (* 4 l)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
636 (* -1.25 ecc ecc (solar-sin-degrees (* 2 m)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
637 3.1415926535)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
638 nil)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
639 ; equation of time, in hours
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
640 (list app i time-eq nut)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
641
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
642 (defun solar-longitude (d)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
643 "Longitude of sun on astronomical (Julian) day number D.
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
644 Accurary is about 0.0006 degree (about 365.25*24*60*0.0006/360 = 1 minutes).
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
645
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
646 The values of calendar-daylight-savings-starts,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
647 calendar-daylight-savings-starts-time, calendar-daylight-savings-ends,
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
648 calendar-daylight-savings-ends-time, calendar-daylight-time-offset, and
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
649 calendar-time-zone are used to interpret local time."
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
650 (let* ((a-d (calendar-absolute-from-astro d))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
651 ;; get Universal Time
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
652 (date (calendar-astro-from-absolute
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
653 (- a-d
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
654 (if (dst-in-effect a-d)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
655 (/ calendar-daylight-time-offset 24.0 60.0) 0)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
656 (/ calendar-time-zone 60.0 24.0))))
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
657 ;; get Ephemeris Time
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
658 (date (+ date (solar-ephemeris-correction
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
659 (extract-calendar-year
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
660 (calendar-gregorian-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
661 (floor
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
662 (calendar-absolute-from-astro
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
663 date)))))))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
664 (U (/ (- date 2451545) 3652500))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
665 (longitude
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
666 (+ 4.9353929
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
667 (* 62833.1961680 U)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
668 (* 0.0000001
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
669 (apply '+
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
670 (mapcar '(lambda (x)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
671 (* (car x)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
672 (sin (mod
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
673 (+ (car (cdr x))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
674 (* (car (cdr (cdr x))) U))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
675 (* 2 pi)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
676 solar-data-list)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
677 (aberration
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
678 (* 0.0000001 (- (* 17 (cos (+ 3.10 (* 62830.14 U)))) 973)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
679 (A1 (mod (+ 2.18 (* U (+ -3375.70 (* 0.36 U)))) (* 2 pi)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
680 (A2 (mod (+ 3.51 (* U (+ 125666.39 (* 0.10 U)))) (* 2 pi)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
681 (nutation (* -0.0000001 (+ (* 834 (sin A1)) (* 64 (sin A2))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
682 (mod (radians-to-degrees (+ longitude aberration nutation)) 360.0)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
683
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
684 (defconst solar-data-list
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
685 '((403406 4.721964 1.621043)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
686 (195207 5.937458 62830.348067)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
687 (119433 1.115589 62830.821524)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
688 (112392 5.781616 62829.634302)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
689 (3891 5.5474 125660.5691)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
690 (2819 1.5120 125660.984)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
691 (1721 4.1897 62832.4766)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
692 (0 1.163 0.813)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
693 (660 5.415 125659.31)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
694 (350 4.315 57533.85)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
695 (334 4.553 -33.931)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
696 (314 5.198 777137.715)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
697 (268 5.989 78604.191)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
698 (242 2.911 5.412)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
699 (234 1.423 39302.098)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
700 (158 0.061 -34.861)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
701 (132 2.317 115067.698)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
702 (129 3.193 15774.337)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
703 (114 2.828 5296.670)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
704 (99 0.52 58849.27)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
705 (93 4.65 5296.11)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
706 (86 4.35 -3980.70)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
707 (78 2.75 52237.69)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
708 (72 4.50 55076.47)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
709 (68 3.23 261.08)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
710 (64 1.22 15773.85)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
711 (46 0.14 188491.03)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
712 (38 3.44 -7756.55)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
713 (37 4.37 264.89)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
714 (32 1.14 117906.27)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
715 (29 2.84 55075.75)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
716 (28 5.96 -7961.39)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
717 (27 5.09 188489.81)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
718 (27 1.72 2132.19)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
719 (25 2.56 109771.03)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
720 (24 1.92 54868.56)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
721 (21 0.09 25443.93)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
722 (21 5.98 -55731.43)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
723 (20 4.03 60697.74)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
724 (18 4.47 2132.79)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
725 (17 0.79 109771.63)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
726 (14 4.24 -7752.82)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
727 (13 2.01 188491.91)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
728 (13 2.65 207.81)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
729 (13 4.98 29424.63)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
730 (12 0.93 -7.99)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
731 (10 2.21 46941.14)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
732 (10 3.59 -68.29)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
733 (10 1.50 21463.25)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
734 (10 2.55 157208.40)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 (defun solar-ephemeris-correction (year)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
737 "Ephemeris time minus Universal Time during Gregorian year.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
738 Result is in days.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
739
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
740 For the years 1800-1987, the maximum error is 1.9 seconds.
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
741 For the other years, the maximum error is about 30 seconds."
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
742 (cond ((and (<= 1988 year) (< year 2020))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
743 (/ (+ year -2000 67.0) 60.0 60.0 24.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
744 ((and (<= 1900 year) (< year 1988))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
745 (let* ((theta (/ (- (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
746 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
747 (list 7 1 year)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
748 (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
749 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
750 '(1 1 1900))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
751 36525.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
752 (theta2 (* theta theta))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
753 (theta3 (* theta2 theta))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
754 (theta4 (* theta2 theta2))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
755 (theta5 (* theta3 theta2)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
756 (+ -0.00002
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
757 (* 0.000297 theta)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
758 (* 0.025184 theta2)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
759 (* -0.181133 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
760 (* 0.553040 theta4)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
761 (* -0.861938 theta5)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
762 (* 0.677066 theta3 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
763 (* -0.212591 theta4 theta3))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
764 ((and (<= 1800 year) (< year 1900))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
765 (let* ((theta (/ (- (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
766 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
767 (list 7 1 year)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
768 (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
769 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
770 '(1 1 1900))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
771 36525.0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
772 (theta2 (* theta theta))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
773 (theta3 (* theta2 theta))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
774 (theta4 (* theta2 theta2))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
775 (theta5 (* theta3 theta2)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
776 (+ -0.000009
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
777 (* 0.003844 theta)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
778 (* 0.083563 theta2)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
779 (* 0.865736 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
780 (* 4.867575 theta4)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
781 (* 15.845535 theta5)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
782 (* 31.332267 theta3 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
783 (* 38.291999 theta4 theta3)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
784 (* 28.316289 theta4 theta4)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
785 (* 11.636204 theta4 theta5)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
786 (* 2.043794 theta5 theta5))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
787 ((and (<= 1620 year) (< year 1800))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
788 (let ((x (/ (- year 1600) 10.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
789 (/ (+ (* 2.19167 x x) (* -40.675 x) 196.58333) 60.0 60.0 24.0)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
790 (t (let* ((tmp (- (calendar-astro-from-absolute
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
791 (calendar-absolute-from-gregorian
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
792 (list 1 1 year)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
793 2382148))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
794 (second (- (/ (* tmp tmp) 41048480.0) 15)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
795 (/ second 60.0 60.0 24.0)))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
797 (defun solar-sidereal-time (t0)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
798 "Sidereal time (in hours) in Greenwich.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
799
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
800 At T0=Julian centuries of universal time.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
801 T0 must correspond to 0 hours UT."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
802 (let* ((mean-sid-time (+ 6.6973746
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
803 (* 2400.051337 t0)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
804 (* 0.0000258622 t0 t0)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
805 (* -0.0000000017222 t0 t0 t0)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
806 (et (solar-ephemeris-time (list t0 0.0)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
807 (nut-i (solar-ecliptic-coordinates et nil))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
808 (nut (car (cdr (cdr (cdr nut-i))))) ; nutation
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
809 (i (car (cdr nut-i)))) ; inclination
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
810 (mod (+ (mod (+ mean-sid-time
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
811 (/ (/ (* nut (solar-cosine-degrees i)) 15) 3600)) 24.0)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
812 24.0)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
813 24.0)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
814
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
815 (defun solar-time-equation (date ut)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
816 "Equation of time expressed in hours at Gregorian DATE at Universal time UT."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
817 (let* ((et (solar-date-to-et date ut))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
818 (ec (solar-ecliptic-coordinates et nil)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
819 (car (cdr (cdr ec)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
820
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
821 (defun solar-date-to-et (date ut)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
822 "Ephemeris Time at Gregorian DATE at Universal Time UT (in hours).
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
823 Expressed in julian centuries of Ephemeris Time."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
824 (let ((t0 (solar-julian-ut-centuries date)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
825 (solar-ephemeris-time (list t0 ut))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
826
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
827 ;;;###autoload
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
828 (defun sunrise-sunset (&optional arg)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
829 "Local time of sunrise and sunset for today. Accurate to a few seconds.
7255
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
830 If called with an optional prefix argument, prompt for date.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
831
7255
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
832 If called with an optional double prefix argument, prompt for longitude,
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
833 latitude, time zone, and date, and always use standard time.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
834
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
835 This function is suitable for execution in a .emacs file."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
836 (interactive "p")
5835
1c685c3bd5a9 (calendar-sunrise-sunset): Use new error arg to calendar-cursor-to-date.
Richard M. Stallman <rms@gnu.org>
parents: 5698
diff changeset
837 (or arg (setq arg 1))
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
838 (if (and (< arg 16)
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
839 (not (and calendar-latitude calendar-longitude calendar-time-zone)))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
840 (solar-setup))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
841 (let* ((calendar-longitude
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
842 (if (< arg 16) calendar-longitude
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
843 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
844 "Enter longitude (decimal fraction; + east, - west): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
845 (calendar-latitude
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
846 (if (< arg 16) calendar-latitude
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
847 (solar-get-number
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
848 "Enter latitude (decimal fraction; + north, - south): ")))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
849 (calendar-time-zone
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
850 (if (< arg 16) calendar-time-zone
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
851 (solar-get-number
3779
e9961fa24193 *solar.el (solar-setup, solar-ephemeris-time, sunrise-sunset): Change
Jim Blandy <jimb@redhat.com>
parents: 3591
diff changeset
852 "Enter difference from Coordinated Universal Time (in minutes): ")))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 (calendar-location-name
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
854 (if (< arg 16) calendar-location-name
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
855 (let ((float-output-format "%.1f"))
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
856 (format "%s%s, %s%s"
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
857 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
858 (abs calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
859 (+ (aref calendar-latitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
860 (/ (aref calendar-latitude 1) 60.0)))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
861 (if (numberp calendar-latitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
862 (if (> calendar-latitude 0) "N" "S")
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
863 (if (equal (aref calendar-latitude 2) 'north) "N" "S"))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
864 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
865 (abs calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
866 (+ (aref calendar-longitude 0)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
867 (/ (aref calendar-longitude 1) 60.0)))
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
868 (if (numberp calendar-longitude)
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
869 (if (> calendar-longitude 0) "E" "W")
12312
7816b2769014 Fix bug in determination of output string.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 9829
diff changeset
870 (if (equal (aref calendar-longitude 2) 'east)
9714
c14b023ca6fe Allow vector form of latitude/longitude. Fix documentation.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 7778
diff changeset
871 "E" "W"))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872 (calendar-standard-time-zone-name
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
873 (if (< arg 16) calendar-standard-time-zone-name
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
874 (cond ((= calendar-time-zone 0) "UTC")
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
875 ((< calendar-time-zone 0)
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
876 (format "UTC%dmin" calendar-time-zone))
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
877 (t (format "UTC+%dmin" calendar-time-zone)))))
7255
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
878 (calendar-daylight-savings-starts
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
879 (if (< arg 16) calendar-daylight-savings-starts))
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
880 (calendar-daylight-savings-ends
c79c14e28d71 (sunrise-sunset): Undo previous change.
Richard M. Stallman <rms@gnu.org>
parents: 7248
diff changeset
881 (if (< arg 16) calendar-daylight-savings-ends))
998
61c6983219ff entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 956
diff changeset
882 (date (if (< arg 4) (calendar-current-date) (calendar-read-date)))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883 (date-string (calendar-date-string date t))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
884 (time-string (solar-sunrise-sunset-string date))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
885 (msg (format "%s: %s" date-string time-string))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886 (one-window (one-window-p t)))
4651
7ca17b5fd85e * solar.el (solar-sunrise, solar-sunset, solar-longitude-of-sun):
Jim Blandy <jimb@redhat.com>
parents: 4519
diff changeset
887 (if (<= (length msg) (frame-width))
14331
b5434941b9b1 (sunrise-sunset): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents: 14273
diff changeset
888 (message "%s" msg)
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
889 (with-output-to-temp-buffer "*temp*"
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 (princ (concat date-string "\n" time-string)))
14331
b5434941b9b1 (sunrise-sunset): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents: 14273
diff changeset
891 (message "%s"
b5434941b9b1 (sunrise-sunset): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents: 14273
diff changeset
892 (substitute-command-keys
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 (if one-window
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894 (if pop-up-windows
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
895 "Type \\[delete-other-windows] to remove temp window."
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
896 "Type \\[switch-to-buffer] RET to remove temp window.")
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
897 "Type \\[switch-to-buffer-other-window] RET to restore old contents of temp window."))))))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
898
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
899 (defun calendar-sunrise-sunset ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
900 "Local time of sunrise and sunset for date under cursor.
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
901 Accurate to a few seconds."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
902 (interactive)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
903 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 (solar-setup))
5835
1c685c3bd5a9 (calendar-sunrise-sunset): Use new error arg to calendar-cursor-to-date.
Richard M. Stallman <rms@gnu.org>
parents: 5698
diff changeset
905 (let ((date (calendar-cursor-to-date t)))
5698
d127e0963a2c (calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents: 5010
diff changeset
906 (message "%s: %s"
d127e0963a2c (calendar-sunrise-sunset): Add date to message.
Richard M. Stallman <rms@gnu.org>
parents: 5010
diff changeset
907 (calendar-date-string date t t)
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
908 (solar-sunrise-sunset-string date))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 (defun diary-sunrise-sunset ()
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
911 "Local time of sunrise and sunset as a diary entry.
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
912 Accurate to a few seconds."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
913 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
914 (solar-setup))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
915 (solar-sunrise-sunset-string date))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
917 (defcustom diary-sabbath-candles-minutes 18
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
918 "*Number of minutes before sunset for sabbath candle lighting."
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
919 :group 'diary
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
920 :type 'integer
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
921 :version "21.1")
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
922
46617
b15eab0c85c1 (diary-sabbath-candles): Add optional MARK
Richard M. Stallman <rms@gnu.org>
parents: 44395
diff changeset
923 (defun diary-sabbath-candles (&optional mark)
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
924 "Local time of candle lighting diary entry--applies if date is a Friday.
46617
b15eab0c85c1 (diary-sabbath-candles): Add optional MARK
Richard M. Stallman <rms@gnu.org>
parents: 44395
diff changeset
925 No diary entry if there is no sunset on that date.
b15eab0c85c1 (diary-sabbath-candles): Add optional MARK
Richard M. Stallman <rms@gnu.org>
parents: 44395
diff changeset
926
b15eab0c85c1 (diary-sabbath-candles): Add optional MARK
Richard M. Stallman <rms@gnu.org>
parents: 44395
diff changeset
927 An optional parameter MARK specifies a face or single-character string to
b15eab0c85c1 (diary-sabbath-candles): Add optional MARK
Richard M. Stallman <rms@gnu.org>
parents: 44395
diff changeset
928 use when highlighting the day in the calendar."
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929 (if (not (and calendar-latitude calendar-longitude calendar-time-zone))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
930 (solar-setup))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
931 (if (= (% (calendar-absolute-from-gregorian date) 7) 5);; Friday
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
932 (let* ((sunset (car (cdr (solar-sunrise-sunset date))))
44367
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
933 (light (if sunset
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
934 (cons (- (car sunset)
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
935 (/ diary-sabbath-candles-minutes 60.0))
c652288e6fb7 (solar-spring-or-summer-season): Deleted.
Richard M. Stallman <rms@gnu.org>
parents: 42706
diff changeset
936 (cdr sunset)))))
15095
66db908addc7 Double DST correction removed!
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 14917
diff changeset
937 (if sunset
46617
b15eab0c85c1 (diary-sabbath-candles): Add optional MARK
Richard M. Stallman <rms@gnu.org>
parents: 44395
diff changeset
938 (cons mark
b15eab0c85c1 (diary-sabbath-candles): Add optional MARK
Richard M. Stallman <rms@gnu.org>
parents: 44395
diff changeset
939 (format "%s Sabbath candle lighting"
b15eab0c85c1 (diary-sabbath-candles): Add optional MARK
Richard M. Stallman <rms@gnu.org>
parents: 44395
diff changeset
940 (apply 'solar-time-string light)))))))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
941
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
942 (defun solar-equinoxes/solstices (k year)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
943 "Date of equinox/solstice K for YEAR.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
944 K=0, spring equinox; K=1, summer solstice; K=2, fall equinox;
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
945 K=3, winter solstice.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
946 RESULT is a gregorian local date.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
947
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
948 Accurate to less than a minute between 1951 and 2050."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
949 (let* ((JDE0 (solar-mean-equinoxes/solstices k year))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
950 (T (/ (- JDE0 2451545.0) 36525))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
951 (W (- (* 35999.373 T) 2.47))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
952 (Delta-lambda (+ 1 (* 0.0334 (solar-cosine-degrees W))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
953 (* 0.0007 (solar-cosine-degrees (* 2 W)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
954 (S (apply '+ (mapcar '(lambda(x)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
955 (* (car x) (solar-cosine-degrees
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
956 (+ (* (car (cdr (cdr x))) T)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
957 (car (cdr x))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
958 solar-seasons-data)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
959 (JDE (+ JDE0 (/ (* 0.00001 S) Delta-lambda)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
960 (correction (+ 102.3 (* 123.5 T) (* 32.5 T T)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
961 ; ephemeris time correction
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
962 (JD (- JDE (/ correction 86400)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
963 (date (calendar-gregorian-from-absolute (floor (- JD 1721424.5))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
964 (time (- (- JD 0.5) (floor (- JD 0.5))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
965 )
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
966 (list (car date) (+ (car (cdr date)) time
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
967 (/ (/ calendar-time-zone 60.0) 24.0))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
968 (car (cdr (cdr date))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
969
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
970 ; from Meeus, 1991, page 166
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
971 (defun solar-mean-equinoxes/solstices (k year)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
972 "Julian day of mean equinox/solstice K for YEAR.
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
973 K=0, spring equinox; K=1, summer solstice; K=2, fall equinox; K=3, winter
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
974 solstice. These formulas are only to be used between 1000 BC and 3000 AD."
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
975 (let ((y (/ year 1000.0))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
976 (z (/ (- year 2000) 1000.0)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
977 (if (< year 1000) ; actually between -1000 and 1000
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
978 (cond ((equal k 0) (+ 1721139.29189
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
979 (* 365242.13740 y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
980 (* 0.06134 y y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
981 (* 0.00111 y y y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
982 (* -0.00071 y y y y)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
983 ((equal k 1) (+ 1721233.25401
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
984 (* 365241.72562 y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
985 (* -0.05323 y y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
986 (* 0.00907 y y y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
987 (* 0.00025 y y y y)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
988 ((equal k 2) (+ 1721325.70455
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
989 (* 365242.49558 y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
990 (* -0.11677 y y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
991 (* -0.00297 y y y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
992 (* 0.00074 y y y y)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
993 ((equal k 3) (+ 1721414.39987
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
994 (* 365242.88257 y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
995 (* -0.00769 y y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
996 (* -0.00933 y y y)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
997 (* -0.00006 y y y y))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
998 ; actually between 1000 and 3000
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
999 (cond ((equal k 0) (+ 2451623.80984
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1000 (* 365242.37404 z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1001 (* 0.05169 z z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1002 (* -0.00411 z z z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1003 (* -0.00057 z z z z)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1004 ((equal k 1) (+ 2451716.56767
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1005 (* 365241.62603 z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1006 (* 0.00325 z z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1007 (* 0.00888 z z z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1008 (* -0.00030 z z z z)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1009 ((equal k 2) (+ 2451810.21715
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1010 (* 365242.01767 z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1011 (* -0.11575 z z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1012 (* 0.00337 z z z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1013 (* 0.00078 z z z z)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1014 ((equal k 3) (+ 2451900.05952
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1015 (* 365242.74049 z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1016 (* -0.06223 z z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1017 (* -0.00823 z z z)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1018 (* 0.00032 z z z z)))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1019
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1020 ; from Meeus, 1991, page 167
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1021 (defconst solar-seasons-data
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1022 '((485 324.96 1934.136)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1023 (203 337.23 32964.467)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1024 (199 342.08 20.186)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1025 (182 27.85 445267.112)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1026 (156 73.14 45036.886)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1027 (136 171.52 22518.443)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1028 (77 222.54 65928.934)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1029 (74 296.72 3034.906)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1030 (70 243.58 9037.513)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1031 (58 119.81 33718.147)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1032 (52 297.17 150.678)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1033 (50 21.02 2281.226)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1034 (45 247.54 29929.562)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1035 (44 325.15 31555.956)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1036 (29 60.93 4443.417)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1037 (18 155.12 67555.328)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1038 (17 288.79 4562.452)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1039 (16 198.04 62894.029)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1040 (14 199.76 31436.921)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1041 (12 95.39 14577.848)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1042 (12 287.11 31931.756)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1043 (12 320.81 34777.259)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1044 (9 227.73 1222.114)
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1045 (8 15.45 16859.074)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1046
5010
9595049f63a9 (solar-equinoxes-solstices): Add autoload.
Richard M. Stallman <rms@gnu.org>
parents: 4863
diff changeset
1047 ;;;###autoload
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
1048 (defun solar-equinoxes-solstices ()
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1049 "*local* date and time of equinoxes and solstices, if visible in the calendar window.
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1050 Requires floating point."
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
1051 (let ((m displayed-month)
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
1052 (y displayed-year))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1053 (increment-calendar-month m y (cond ((= 1 (% m 3)) -1)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1054 ((= 2 (% m 3)) 1)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1055 (t 0)))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1056 (let* ((calendar-standard-time-zone-name
3866
c97c63c1a920 * solar.el (calendar-holiday-solar-equinoxes-solstices): Renamed
Jim Blandy <jimb@redhat.com>
parents: 3779
diff changeset
1057 (if calendar-time-zone calendar-standard-time-zone-name "UTC"))
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1058 (calendar-daylight-savings-starts
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1059 (if calendar-time-zone calendar-daylight-savings-starts))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1060 (calendar-daylight-savings-ends
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1061 (if calendar-time-zone calendar-daylight-savings-ends))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1062 (calendar-time-zone (if calendar-time-zone calendar-time-zone 0))
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1063 (k (1- (/ m 3)))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1064 (d0 (solar-equinoxes/solstices k y))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1065 (d1 (list (car d0) (floor (car (cdr d0))) (car (cdr (cdr d0)))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1066 (h0 (* 24 (- (car (cdr d0)) (floor (car (cdr d0))))))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1067 (adj (dst-adjust-time d1 h0))
47629
392820ae24ce (solar-equinoxes-solstices): Use time properly adjusted for DST in the result.
Richard M. Stallman <rms@gnu.org>
parents: 47252
diff changeset
1068 (d (list (car (car adj))
392820ae24ce (solar-equinoxes-solstices): Use time properly adjusted for DST in the result.
Richard M. Stallman <rms@gnu.org>
parents: 47252
diff changeset
1069 (+ (car (cdr (car adj)) )
392820ae24ce (solar-equinoxes-solstices): Use time properly adjusted for DST in the result.
Richard M. Stallman <rms@gnu.org>
parents: 47252
diff changeset
1070 (/ (car (cdr adj)) 24.0))
392820ae24ce (solar-equinoxes-solstices): Use time properly adjusted for DST in the result.
Richard M. Stallman <rms@gnu.org>
parents: 47252
diff changeset
1071 (car (cdr (cdr (car adj))))))
13874
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1072 ; The following is nearly as accurate, but not quite:
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1073 ;(d0 (solar-date-next-longitude
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1074 ; (calendar-astro-from-absolute
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1075 ; (calendar-absolute-from-gregorian
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1076 ; (list (+ 3 (* k 3)) 15 y)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1077 ; 90))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1078 ;(abs-day (calendar-absolute-from-astro d)))
eec68643bcfb Rewrote completely for better accuracy.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 13742
diff changeset
1079 (abs-day (calendar-absolute-from-gregorian d)))
13045
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1080 (list
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1081 (list (calendar-gregorian-from-absolute (floor abs-day))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1082 (format "%s %s"
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1083 (nth k (if (and calendar-latitude
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1084 (< (calendar-latitude) 0))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1085 solar-s-hemi-seasons
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1086 solar-n-hemi-seasons))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1087 (solar-time-string
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1088 (* 24 (- abs-day (floor abs-day)))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1089 (if (dst-in-effect abs-day)
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1090 calendar-daylight-time-zone-name
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1091 calendar-standard-time-zone-name))))))))
2779e3cf6cfa Added code to support Chinese calendar. Minor fixes as well.
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents: 12908
diff changeset
1092
956
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1093
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1094 (provide 'solar)
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1095
c530dbc9a92a Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1096 ;;; solar.el ends here