astro.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2015-2019 Derick Rethans
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. /* This macro computes the length of the day, from sunrise to sunset. */
  25. /* Sunrise/set is considered to occur when the Sun's upper limb is */
  26. /* 35 arc minutes below the horizon (this accounts for the refraction */
  27. /* of the Earth's atmosphere). */
  28. #define day_length(year,month,day,lon,lat) \
  29. __daylen__( year, month, day, lon, lat, -35.0/60.0, 1 )
  30. /* This macro computes the length of the day, including civil twilight. */
  31. /* Civil twilight starts/ends when the Sun's center is 6 degrees below */
  32. /* the horizon. */
  33. #define day_civil_twilight_length(year,month,day,lon,lat) \
  34. __daylen__( year, month, day, lon, lat, -6.0, 0 )
  35. /* This macro computes the length of the day, incl. nautical twilight. */
  36. /* Nautical twilight starts/ends when the Sun's center is 12 degrees */
  37. /* below the horizon. */
  38. #define day_nautical_twilight_length(year,month,day,lon,lat) \
  39. __daylen__( year, month, day, lon, lat, -12.0, 0 )
  40. /* This macro computes the length of the day, incl. astronomical twilight. */
  41. /* Astronomical twilight starts/ends when the Sun's center is 18 degrees */
  42. /* below the horizon. */
  43. #define day_astronomical_twilight_length(year,month,day,lon,lat) \
  44. __daylen__( year, month, day, lon, lat, -18.0, 0 )
  45. /* This macro computes times for sunrise/sunset. */
  46. /* Sunrise/set is considered to occur when the Sun's upper limb is */
  47. /* 35 arc minutes below the horizon (this accounts for the refraction */
  48. /* of the Earth's atmosphere). */
  49. #define timelib_astro_sun_rise_set(ts,lon,lat,hrise,hset,rise,set) \
  50. timelib_astro_rise_set_altitude( ts, lon, lat, -35.0/60.0, 1, hrise, hset, rise, set )
  51. /* This macro computes the start and end times of civil twilight. */
  52. /* Civil twilight starts/ends when the Sun's center is 6 degrees below */
  53. /* the horizon. */
  54. #define civil_twilight(ts,lon,lat,start,end) \
  55. timelib_astro_rise_set_altitude( ts, lon, lat, -6.0, 0, start, end )
  56. /* This macro computes the start and end times of nautical twilight. */
  57. /* Nautical twilight starts/ends when the Sun's center is 12 degrees */
  58. /* below the horizon. */
  59. #define nautical_twilight(ts,lon,lat,start,end) \
  60. timelib_astro_rise_set_altitude( ts, lon, lat, -12.0, 0, start, end )
  61. /* This macro computes the start and end times of astronomical twilight. */
  62. /* Astronomical twilight starts/ends when the Sun's center is 18 degrees */
  63. /* below the horizon. */
  64. #define astronomical_twilight(ts,lon,lat,start,end) \
  65. timelib_astro_rise_set_altitude( ts, lon, lat, -18.0, 0, start, end )