10

I need to determine sunrise and sunset times (local time) for the current day given a specific latitude and longitude and using Delphi (I am using XE2). I've found this article and used the SysTools library but the results do not agree with published tables for the UK.

Has anyone seen a pascal algorithm for this?

Brian Frost
  • 13,334
  • 11
  • 80
  • 154

3 Answers3

8

Some random sites:

menjaraz
  • 7,551
  • 4
  • 41
  • 81
4

Here you can find some implementations in c, c++, pascal and others:

http://www.sci.fi/~benefon/stuff.html

For the pascal one you can go here:

http://www.sci.fi/~benefon/SUNDAY.PAS

Also, are you taking into account the daylight saving time?

Another link you could find helpfull is:

http://www.delphiarea.com/products/delphi-components/suntime/

It's a component to calculate sunrise and sunset times.

Hope this helps you.

Diego
  • 1,531
  • 1
  • 15
  • 27
3

What kind of times do you need? There are several defintions for "rise" and "sunset" (i.e. civil, nautical, astronomical). When comparing to published tables, you also need to know how those tables were calculated (geocentric position or not, standard time or true local time, and so on) and what result the used algorithms gives you. There are also some approximated algorithms using just a few terms and more precise one using much more. Also, be aware of the IEEE floating point issues, in some situations they can decrease precision a lot.

One of the best sources for such algorithms is Jean Meeus' Astronomical Algorithms (1998), 2nd edition

Mad Hatter
  • 772
  • 5
  • 5
  • I thought it was only twilight that had different definitions and that rise and set were standard, or is it to do with how much of the sun is above the horizon? I'm interested to learn. – Richard A May 02 '12 at 20:53