< SolarCoordinates.c | index | AstronomicalAlgorithms.h >

Copyright (c) 1999-2012

Permission to use, copy, modify, and distribute this software and its documentation under the terms of the GNU eneral Public License is hereby granted. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

See the GNU General Public License.

AstronomicalAlgorithms.c

  1. /*
  2. AstronomicalAlgorithms main source file, implementing the book examples.
  3. The \#ifdef PAGE_nnn_TEST directives in AstronomicalAlgorithms.h are used
  4. to include/exclude the related code.
  5.  
  6. - 0 : completed successfully
  7.  
  8. The screen output of this program is quite long.
  9. It is easier to re-direct it to a file and then read this file with an editor
  10. - AstronomicalAlgorithms > aa.txt
  11. - edit aa.txt
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <limits.h>
  16. #include <math.h>
  17. #include <time.h>
  18.  
  19. #if 0
  20. #include <assert.h>
  21. #endif
  22.  
  23. /****************************************************************************/
  24.  
  25. #include "AstronomicalAlgorithms.h"
  26.  
  27. #include "InterpolationDifferences.c"
  28. #include "IsLeapYear.c"
  29. #include "JulianDay.c"
  30. #include "DateFromJulianDay.c"
  31. #include "DayOfWeek.c"
  32. #include "DayOfYear.c"
  33. #include "DateFromYearDay.c"
  34. #include "EasterSunday.c"
  35. #include "RhoSinPhiTwo.c"
  36. #include "RhoCosPhiTwo.c"
  37. #include "MoonPhasesJDE.c"
  38. #include "SolarCoordinates.c"
  39. #include "eclipsesJDE.c"
  40.  
  41. /****************************************************************************/
  42.  
  43.  
  44. int main(int iArgumentsCount, char *aszArguments[], char *aszEnvironment[])
  45.    {
  46.    char       sz1[LO_DEFAULT_WORKSTRING_LENGTH] = {(char) 0};
  47.    int        iReturnValue                      = 0;
  48.    struct tm *ptmTimeNow                        = NULL;
  49.    time_t     ttSecondsNow                      = (time_t) 0;
  50.  
  51.    if (iArgumentsCount < 1)
  52.       {
  53.       iReturnValue = 1;
  54.       }
  55.    else if (aszArguments == NULL)
  56.       {
  57.       iReturnValue = 2;
  58.       }
  59.    else if (aszEnvironment == NULL)
  60.       {
  61.       iReturnValue = 3;
  62.       }
  63.    else
  64.       {
  65.       (void) fprintf(stdout,
  66.                      "\n%s%s%s\n%s\n%s\n",
  67.                      __FILE__,
  68.                      ", by Christophe DAVID, compiled ",
  69.                      __DATE__,
  70.                      "christophe.david@christophedavid.org",
  71.                      "http://www.christophedavid.org/"
  72.                     );
  73.  
  74.       ttSecondsNow = time(NULL);
  75.       ptmTimeNow   = localtime(&ttSecondsNow);
  76.  
  77.       if (strftime(sz1, (size_t) (sizeof(sz1) - (size_t) 1),
  78.                    "\nCurrent local time : %A %B %d, %Y - %H:%M:%S\n\n",
  79.                    ptmTimeNow) == (size_t) 0)
  80.          {
  81.          *sz1 = (char) 0;
  82.          }
  83.       (void) fprintf(stdout, "%s", sz1);
  84.  
  85.       /**********************************************************************/
  86.  
  87.       #ifdef PAGE_007_TEST
  88.       (void) fprintf(stdout, "\npage 007 : sine(36000030) = %f\n",
  89.                      sin(DEGREES2RADIAN(36000030)));
  90.       (void) fprintf(stdout, "page 007 : 23d26m49s      = %f degrees\n",
  91.                      DEGMINSEC2DECIMAL(+, 23, 26, 49));
  92.       #endif
  93.  
  94.       /**********************************************************************/
  95.  
  96.       #ifdef PAGE_008_TEST
  97.       (void) fprintf(stdout,
  98.                  "\npage 008 : 9h14m55.8s     = %f degrees, tan(alpha) = %f\n",
  99.                      RIGHTASC2DECIMAL(9,14,55.8),
  100.                      tan(DEGREES2RADIAN(RIGHTASC2DECIMAL(9,14,55.8)))
  101.                     );
  102.       #endif
  103.  
  104.       /**********************************************************************/
  105.  
  106.       #ifdef PAGE_009_TEST
  107.       (void) fprintf(stdout, "\npage 009 : -13d47m22s     = %f degrees\n",
  108.                      DEGMINSEC2DECIMAL(-, 13,47,22));
  109.       #endif
  110.  
  111.       /**********************************************************************/
  112.  
  113.       #ifdef PAGE_013_TEST
  114.  
  115.       /* swap trick given in the book */
  116.       if (1)                                             /*lint !e506 !e774 */
  117.          {
  118.          double doX = do_pi;
  119.          double doY = do_e;
  120.          (void) fprintf(stdout,
  121.                         "\npage 013 : before swap : X = %.20f, Y = %.20f\n",
  122.                          doX, doY);
  123.  
  124.          doX = doX + doY;
  125.          doY = doX - doY;
  126.          doX = doX - doY;
  127.          (void) fprintf(stdout,
  128.                         "page 013 : after  swap : Y = %.20f, X = %.20f\n",
  129.                         doY, doX);
  130.          }
  131.  
  132.       /* this is pure intellectual curiosity here, but could be useful to swap
  133.          large arrays (strings, matrices, etc.) */
  134.  
  135.       if (1)                                             /*lint !e506 !e774 */
  136.          {
  137.          size_t         st1   = (size_t) 0;
  138.          unsigned char *puchX = NULL;
  139.          unsigned char *puchY = NULL;
  140.  
  141.          double doX = do_pi;
  142.          double doY = do_e;
  143.  
  144.          (void) fprintf(stdout,
  145.                         "\npage 013 : before swap : X = %.20f, Y = %.20f\n",
  146.                         doX, doY);
  147.  
  148.          puchX = (unsigned char *) &doX;
  149.          puchY = (unsigned char *) &doY;
  150.  
  151.          for (st1 = (size_t) 0 ; st1 < sizeof(doX) ; st1++)
  152.             {
  153.             *puchX = *puchX ^ *puchY;
  154.             *puchY = *puchY ^ *puchX;
  155.             *puchX = *puchX ^ *puchY;
  156.             puchX++;
  157.             puchY++;
  158.             }
  159.          (void) fprintf(stdout,
  160.                         "page 013 : after  swap : Y = %.20f, X = %.20f\n",
  161.                         doY, doX);
  162.          }
  163.  
  164.       if (1)                                           /*lint !e506 !e774 */
  165.          {
  166.          size_t         st1   = (size_t) 0;
  167.          unsigned char *puchX = NULL;
  168.          unsigned char *puchY = NULL;
  169.  
  170.          char szX[] = "0123456789abcd";
  171.          char szY[] = "ABCDEFGHIJKLMN";
  172.  
  173.          (void) fprintf(stdout,
  174.                         "\npage 013 : before swap : X = %s, Y = %s\n",
  175.                         szX, szY);
  176.  
  177.          puchX = (unsigned char *) szX;
  178.          puchY = (unsigned char *) szY;
  179.  
  180.          for (st1 = (size_t) 0 ; st1 < sizeof(szX) ; st1++)
  181.             {
  182.             *puchX = *puchX ^ *puchY;
  183.             *puchY = *puchY ^ *puchX;
  184.             *puchX = *puchX ^ *puchY;
  185.             puchX++;
  186.             puchY++;
  187.             }
  188.          (void) fprintf(stdout,
  189.                         "page 013 : after  swap : Y = %s, X = %s\n", szY, szX);
  190.          }
  191.  
  192.       #endif
  193.  
  194.       /**********************************************************************/
  195.  
  196.       #ifdef PAGE_017_TEST
  197.  
  198.       if (1)                                             /*lint !e506 !e774 */
  199.          {
  200.          float flX = (float) 1;
  201.          long  loJ = (long) 0;
  202.  
  203.          (void) fprintf(stdout, "%s", "\n");
  204.  
  205.          while (1)                                      /*lint !e506 !e716 */
  206.             {
  207.             flX = flX * (float) 2;
  208.  
  209.             if (flX + (float) 1 == flX)                       /*lint !e777 */
  210.                {
  211.                break;
  212.                }
  213.             loJ += (long) 1;
  214.             }
  215.  
  216.          (void) fprintf(stdout,
  217.                         "page 017 : float  : J = %ld, J * 0.30103 = %f\n",
  218.                         loJ, (double) ((float)((float) loJ * (float) 0.30103)));
  219.          }
  220.  
  221.       if (1)                                             /*lint !e506 !e774 */
  222.          {
  223.          double doX = (double) 1;
  224.          long  loJ = (long) 0;
  225.  
  226.          while (1)                                       /*lint !e506 !e716 */
  227.             {
  228.             doX = doX * (double) 2;
  229.  
  230.             if (doX + (double) 1 == doX)                       /*lint !e777 */
  231.                {
  232.                break;
  233.                }
  234.             loJ += (long) 1;
  235.             }
  236.  
  237.          (void) fprintf(stdout,
  238.                         "page 017 : double : J = %ld, J * 0.30103 = %f\n",
  239.                         loJ, (double)((double) loJ * (double) 0.30103));
  240.          }
  241.       #endif
  242.  
  243.       /**********************************************************************/
  244.  
  245.       #ifdef PAGE_018_TEST
  246.  
  247.       (void) fprintf(stdout,
  248.                      "\npage 018 : 4 * atan(1) = %21.20f\n"
  249.                      "           PI          = 3.14159265358979323846\n\n"
  250.                      ,
  251.                      (double) ((double) 4 * atan((double) 1)));
  252.  
  253.  
  254.       if (1)                                            /*lint !e506 !e774 */
  255.          {
  256.          double doX = (double) ((double) 1 / (double) 3);
  257.          long   loJ = (long) 0;
  258.  
  259.          for (loJ = (long) 1 ; loJ <= 30 ; loJ++)
  260.             {
  261.             doX = ((((double) 9 * doX) + (double) 1) * doX) - (double) 1;
  262.             (void) fprintf(stdout,
  263.                            "page 018 : %2ld %21.20f\n",
  264.                            loJ, doX);
  265.  
  266.             }
  267.          }
  268.  
  269.       if (1)                                            /*lint !e506 !e774 */
  270.          {
  271.          double doX = (double) 1.0000001;
  272.          long   loJ = (long) 0;
  273.  
  274.  
  275.          for (loJ = (long) 1 ; loJ <= 27 ; loJ++)
  276.             {
  277.             doX *= doX;
  278.             }
  279.  
  280.          (void) fprintf(stdout,
  281.                "\npage 018 : 27 iterations of 1.0000001 ^ 2 give %.4f\n",
  282.                         doX);
  283.          }
  284.  
  285.       #endif
  286.  
  287.       /**********************************************************************/
  288.  
  289.       #ifdef PAGE_019_TEST
  290.  
  291.       (void) fprintf(stdout,
  292.                      "\npage 019 : floor(100 * (4.34 - floor(4.34))) = %.3f\n",
  293.                      floor(100 * ((double) 4.34 - floor((double) 4.34)))
  294.                     );
  295.  
  296.       (void) fprintf(stdout,
  297.                      "\npage 019 : 2 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 - 3 = %e\n",
  298.                      ((double) 2 + (double) 0.2 + (double) 0.2 + (double) 0.2
  299.                       + (double) 0.2 + (double) 0.2 - (double) 3)
  300.                     );
  301.  
  302.       (void) fprintf(stdout,
  303.                      "\npage 019 : 0.2 + 0.2 + 0.2 + 0.2 + 0.2 + 2 - 3 = %e\n",
  304.                      ((double) 0.2 + (double) 0.2 + (double) 0.2 + (double) 0.2
  305.                       + (double) 0.2 + (double) 2 - (double) 3)
  306.                     );
  307.  
  308.       (void) fprintf(stdout,
  309.                      "\npage 019 : 2 + (5 * 0.2) - 3  = %e\n",
  310.                      (double) 2 + ((double) 5 * (double) 0.2) - (double) 3
  311.                     );
  312.  
  313.  
  314.       if (1)                                            /*lint !e506 !e774 */
  315.          {
  316.          double doA = (double) 0;
  317.          double doB = (double) 0;
  318.          double doC = (double) 0;
  319.  
  320.          doA =    (double) 0.2
  321.                 + (double) 0.2 + (double) 0.2 + (double) 0.2 + (double) 0.2;
  322.          doB = (double) 2 + doA;
  323.          doC = doB - (double) 3;
  324.          (void) fprintf(stdout, "\npage 019 : C = %e\n", doC);
  325.          }
  326.  
  327.       if (1)                                            /*lint !e506 !e774 */
  328.          {
  329.          double doI = (double) 0;
  330.          double doU = (double) 0;
  331.  
  332.          for (doI = (double) 0 ; doI < 100 ; doI += (double) 0.1)
  333.             {
  334.             doU = doI;
  335.             }
  336.          (void) fprintf(stdout, "\npage 019 : U = %.20f\n", doU);
  337.  
  338.          }
  339.       #endif
  340.  
  341.       /**********************************************************************/
  342.  
  343.       #ifdef PAGE_020_TEST
  344.  
  345.       if (1)                                            /*lint !e506 !e774 */
  346.          {
  347.          double doI = (double) 0;
  348.          double doJ = (double) 0;
  349.          double doU = (double) 0;
  350.  
  351.          for (doJ = (double) 0 ; doI < 1000 ; doJ ++)
  352.             {
  353.             doI = doJ / (double) 10;
  354.             doU = doI;
  355.             }
  356.          (void) fprintf(stdout, "\npage 020 : U = %.20f\n", doU);
  357.          }
  358.  
  359.       (void) fprintf(stdout,
  360.                      "\npage 020 : 3 * (1/3) = %f\n",
  361.                      (double) 3 * ((double) 1 / (double) 3)
  362.                     );
  363.  
  364.  
  365.       if (1)                                            /*lint !e506 !e774 */
  366.          {
  367.          double doA = (double) 0.1;
  368.  
  369.          (void) fprintf(stdout, "\npage 020 : floor(1000 * 0.1) = %.20f\n",
  370.                         (floor((double) 1000 * doA)));
  371.          }
  372.  
  373.  
  374.  
  375.       (void) fprintf(stdout, "\npage 020 : LONG_MAX = %ld\n", LONG_MAX);
  376.  
  377.  
  378.       (void) fprintf(stdout,
  379.                      "\npage 020 : sqrt(25) - 5 = %f\n",
  380.                      sqrt((double) 25) - floor(sqrt((double) 25))
  381.                     );
  382.  
  383.       #endif
  384.  
  385.       /**********************************************************************/
  386.  
  387.       #ifdef PAGE_021_TEST
  388.  
  389.       (void) fprintf(stdout, "\npage 021 : ROUND(pi) = %f\n", ROUND(do_pi));
  390.       (void) fprintf(stdout, "\npage 021 : ROUND(e)  = %f\n", ROUND(do_e));
  391.  
  392.       #endif
  393.  
  394.       /**********************************************************************/
  395.  
  396.       #ifdef PAGE_024_TEST
  397.  
  398.       if (1)                                            /*lint !e506 !e774 */
  399.          {
  400.          double adoTableValues[5]  = {(double) 0.898013,
  401.                                       (double) 0.891109,
  402.                                       (double) 0.884226,
  403.                                       (double) 0.877366,
  404.                                       (double) 0.870531
  405.                                      };
  406.  
  407.          double adoDifferences[5]  = {(double) 0};  /*lint !e785 */
  408.          short shTemp1             = (short) 0;
  409.          short shTemp2             = (short) 0;
  410.  
  411.          for (shTemp1 = (short) 1 ; shTemp1 <= 3 ; shTemp1++)
  412.             {
  413.             shTemp2 = ShInterpolationDifferences(adoTableValues,
  414.                                                  (short) 5,
  415.                                                  adoDifferences,
  416.                                                  sizeof(adoDifferences),
  417.                                                  shTemp1
  418.                                                 );
  419.             if (shTemp2 != 0)
  420.                {
  421.                (void) fprintf(stdout, "\npage 024 : shTemp2 = %hd\n", shTemp2);
  422.                }
  423.             else
  424.                {
  425.                (void) fprintf(stdout,
  426.                      "\npage 024 : differences %hd: %10f %10f %10f %10f %10f",
  427.                               shTemp1,
  428.                               adoDifferences[0],
  429.                               adoDifferences[1],
  430.                               adoDifferences[2],
  431.                               adoDifferences[3],
  432.                               adoDifferences[4]
  433.                              );
  434.                }
  435.             }
  436.          (void) fprintf(stdout, "%s", "\n");
  437.          }
  438.       #endif
  439.  
  440.  
  441.       /**********************************************************************/
  442.  
  443.       #ifdef PAGE_061_TEST
  444.  
  445.       if (1)                                            /*lint !e506 !e774 */
  446.          {
  447.          double doJD = (double) 0;
  448.          short  sh1  = (short)  0;
  449.  
  450.          sh1 = ShJulianDay(&doJD,
  451.                           (double) 1957, (double) 10, (double) 4.81, (short) 1);
  452.          if (sh1 == 0)
  453.             {
  454.             (void) fprintf(stdout, "\npage 059 : JD 7.a = %.2f\n", doJD);
  455.             }
  456.          else
  457.             {
  458.             (void) fprintf(stdout, "\npage 059 : ShJulianDay returns %hd\n",
  459.                            sh1);
  460.             }
  461.  
  462.          sh1 = ShJulianDay(&doJD,
  463.                           (double) 333, (double) 1, (double) 27.5, (short) 0);
  464.  
  465.          if (sh1 == 0)
  466.             {
  467.             (void) fprintf(stdout, "\npage 061 : JD 7.b = %.2f\n", doJD);
  468.             }
  469.          else
  470.             {
  471.             (void) fprintf(stdout, "\npage 061 : ShJulianDay returns %hd\n",
  472.                            sh1);
  473.             }
  474.          }
  475.  
  476.       #endif
  477.  
  478.       /**********************************************************************/
  479.  
  480.       #ifdef PAGE_062_TEST
  481.  
  482.       if (1)                                            /*lint !e506 !e774 */
  483.          {
  484.          short  sh1  = (short)  0;
  485.          short  sh2  = (short)  0;
  486.          short  sh3  = (short)  0;
  487.  
  488.          double ado1[16][5] = { { 2000,  1,  1.5,   0, 2451545.0},
  489.                                 { 1999,  1,  1  ,   0, 2451179.5},
  490.                                 { 1987,  1, 27  ,   0, 2446822.5},
  491.                                 { 1987,  6, 19.5,   0, 2446966.0},
  492.                                 { 1988,  1, 27  ,   0, 2447187.5},
  493.                                 { 1988,  6, 19.5,   0, 2447332.0},
  494.                                 { 1900,  1,  1  ,   0, 2415020.5},
  495.                                 { 1600,  1,  1  ,   0, 2305447.5},
  496.                                 { 1600, 12, 31  ,   0, 2305812.5},
  497.                                 {  837,  4, 10.3,   0, 2026871.8},
  498.                                 { -123, 12, 31  ,   0, 1676496.5},
  499.                                 { -122,  1,  1  ,   0, 1676497.5},
  500.                                 {-1000,  7, 12.5,   0, 1356001.0},
  501.                                 {-1000,  2, 29  ,   0, 1355866.5},
  502.                                 {-1001,  8, 17.9,   0, 1355671.4},
  503.                                 {-4712,  1,  1.5,   0,       0.0}
  504.                              };
  505.  
  506.          for (sh1 = (short) 0 ; sh1 < 16 ; sh1++)
  507.             {
  508.             sh2 = ShJulianDay(&(ado1[sh1][3]),
  509.                                 ado1[sh1][0],
  510.                                 ado1[sh1][1],
  511.                                 ado1[sh1][2],
  512.                                 (short) (ado1[sh1][0] < 1582 ?
  513.                                          JULIAN : GREGORIAN)
  514.                              );
  515.             if (sh2 == 0)
  516.                {
  517.                (void) fprintf(stdout,
  518.                               "\npage 062 : %10.2f %10.2f %10.2f %12.2f %5.2f",
  519.                               ado1[sh1][0],
  520.                               ado1[sh1][1],
  521.                               ado1[sh1][2],
  522.                               ado1[sh1][3],
  523.                               ado1[sh1][4] - ado1[sh1][3]
  524.                              );
  525.                }
  526.             else
  527.                {
  528.                (void) fprintf(stdout, "\npage 062 : ShJulianDay returns %hd\n",
  529.                               sh2);
  530.                }
  531.             }
  532.          (void) fprintf(stdout, "%s", "\n");
  533.  
  534.          /*********************/
  535.  
  536.          sh1 = (short) 2000;
  537.          sh2 = ShIsLeapYear(&sh3, sh1, (short) GREGORIAN);
  538.          (void) fprintf(stdout,
  539.                         "\npage 062 : ShIsLeapYear(%hd) returns"
  540.                         " %hd and result is %hd\n"
  541.                         ,
  542.                         sh1, sh2, sh3);
  543.          }
  544.       #endif
  545.  
  546.       /**********************************************************************/
  547.  
  548.       #ifdef PAGE_063_TEST
  549.  
  550.       if (1)                                            /*lint !e506 !e774 */
  551.          {
  552.          double adoJD[3] = {(double) 2436116.31,
  553.                             (double) 1842713.0,
  554.                             (double) 1507900.13
  555.                            };
  556.  
  557.          short  sh1  = (short )          0;
  558.          short  sh2  = (short )          0;
  559.  
  560.          for (sh1 = (short) 0 ; sh1 < 3 ; sh1++)
  561.             {
  562.             double doY  = (double) 0;
  563.             double doM  = (double) 0;
  564.             double doD  = (double) 0;
  565.             double doH  = (double) 0;
  566.             double dom  = (double) 0;
  567.             double doS  = (double) 0;
  568.  
  569.             sh2 = ShDateFromJulianDay(adoJD[sh1], &doY, &doM, &doD,
  570.                                                   &doH, &dom, &doS);
  571.             if (sh2 == 0)
  572.                {
  573.                (void) fprintf(stdout, "\npage 064 : D=%5.2f, M=%2.0f, Y=%2.0f",
  574.                               doD, doM, doY);
  575.                }
  576.             else
  577.                {
  578.                (void) fprintf(stdout,
  579.                               "\npage 064 : ShDateFromJulianDay returns %hd",
  580.                               sh2);
  581.                }
  582.             }
  583.          (void) fprintf(stdout, "%s", "\n");
  584.          }
  585.  
  586.       #endif
  587.  
  588.       /**********************************************************************/
  589.  
  590.       #ifdef PAGE_064_TEST
  591.  
  592.       if (1)                                            /*lint !e506 !e774 */
  593.          {
  594.          double doJD1 = (double) 0;
  595.          double doJD2 = (double) 0;
  596.  
  597.          if (  (ShJulianDay(&doJD1,
  598.                            (double) 1910, (double) 4, (double) 20,
  599.                            (short) GREGORIAN) == 0
  600.                )
  601.  
  602.              && (ShJulianDay(&doJD2,
  603.                            (double) 1986, (double) 2, (double) 9,
  604.                            (short) GREGORIAN) == 0
  605.                 )
  606.             )
  607.  
  608.             {
  609.             (void) fprintf(stdout,
  610.                            "\npage 064 : ex. 7.d = %.0f",
  611.                            doJD1 - doJD2);
  612.             }
  613.  
  614.  
  615.          if (ShJulianDay(&doJD1,
  616.                            (double) 1991, (double) 7, (double) 11,
  617.                            (short) GREGORIAN) == 0)
  618.              {
  619.              double doY  = (double) 0;
  620.              double doM  = (double) 0;
  621.              double doD  = (double) 0;
  622.              double doH  = (double) 0;
  623.              double dom  = (double) 0;
  624.              double doS  = (double) 0;
  625.  
  626.              if (ShDateFromJulianDay(doJD1 + (double) 10000,
  627.                                      &doY, &doM, &doD,
  628.                                      &doH, &dom, &doS) == 0)
  629.                 {
  630.                 (void) fprintf(stdout,
  631.                                "\npage 064 : D=%5.2f, M=%2.0f, Y=%2.0f\n",
  632.                                doD, doM, doY);
  633.                 }
  634.              }
  635.          }
  636.       #endif
  637.  
  638.       /**********************************************************************/
  639.  
  640.       #ifdef PAGE_065_TEST
  641.  
  642.       if (1)                                            /*lint !e506 !e774 */
  643.          {
  644.          short sh1   = (short) 0;
  645.          short shDOW = (short) 0;
  646.  
  647.          sh1 = ShDayOfWeek(&shDOW, (double) 1954, (double) 6, (double) 30);
  648.  
  649.          if (sh1 == 0)
  650.             {
  651.             (void) fprintf(stdout, "\npage 065 : shDOW = %hd", shDOW);
  652.             }
  653.          else
  654.             {
  655.             (void) fprintf(stdout,
  656.                            "\npage 065 : ShDayOfWeek returns %hd",
  657.                            sh1);
  658.             }
  659.          }
  660.  
  661.       if (1)                                            /*lint !e506 !e774 */
  662.          {
  663.          short sh1   = (short) 0;
  664.          short shDOY = (short) 0;
  665.  
  666.          sh1 = ShDayOfYear(&shDOY, (double) 1988, (double) 4, (double) 22);
  667.  
  668.          if (sh1 == 0)
  669.             {
  670.             (void) fprintf(stdout, "\npage 065 : ex. 7.g = %hd", shDOY);
  671.             }
  672.          else
  673.             {
  674.             (void) fprintf(stdout,
  675.                            "\npage 065 : ShDayOfyear returns %hd",
  676.                            sh1);
  677.             }
  678.          (void) fprintf(stdout, "%s", "\n");
  679.          }
  680.       #endif
  681.  
  682.       /**********************************************************************/
  683.       #ifdef PAGE_066_TEST
  684.       if (1)                                            /*lint !e506 !e774 */
  685.          {
  686.          short  sh1  = (short)  0;
  687.          double doM  = (double) 0;
  688.          double doD  = (double) 0;
  689.  
  690.          sh1 = ShDateFromYearDay((double) 113, (short) 1988, &doM, &doD);
  691.          if (sh1 == 0)
  692.             {
  693.             (void) fprintf(stdout, "\npage 066 : D = %2.0f, M = %2.0f",
  694.                            doD, doM);
  695.             }
  696.          else
  697.             {
  698.             (void) fprintf(stdout,
  699.                            "\npage 066 : ShDateFromYearDay returns %hd",
  700.                            sh1);
  701.             }
  702.          (void) fprintf(stdout, "%s", "\n");
  703.          }
  704.       #endif
  705.       /**********************************************************************/
  706.  
  707.       #ifdef PAGE_067_TEST
  708.       if (1)                                            /*lint !e506 !e774 */
  709.          {
  710.          short sh1    = (short)  0;
  711.          short shYear = (short)  0;
  712.          short shM    = (short) 0;
  713.          short shD    = (short) 0;
  714.  
  715.          (void) fprintf(stdout, "%s", "\npage 067 : \n");
  716.          for (shYear = (short) 1583 ; shYear <= 2303 ; shYear++)
  717.             {
  718.             sh1 = ShEasterSunday(shYear, &shM, &shD, GREGORIAN, CHRISTIAN);
  719.             if (sh1 == 0)
  720.                {
  721.                (void) fprintf(stdout, "%04hd/%02hd/%02hd ", shYear, shM, shD);
  722.                }
  723.             else
  724.                {
  725.                (void) fprintf(stdout,
  726.                               "\npage 067 : ShDateFromYearDay returns %hd",
  727.                               sh1);
  728.                }
  729.             if (shYear % 7 == 0)
  730.                {
  731.                (void) fprintf(stdout, "%s", "\n");
  732.                }
  733.             }
  734.          (void) fprintf(stdout, "%s", "\n");
  735.          }
  736.       #endif
  737.       /**********************************************************************/
  738.  
  739.       #ifdef PAGE_082_TEST
  740.       if (1)                                            /*lint !e506 !e774 */
  741.          {
  742.          double doTemp01 = DEGMINSEC2DECIMAL(+, 33, 21, 22);
  743.  
  744.          double b = (double)(  DO_EARTH_EQUATORIAL_RADIUS
  745.                              * ((double) 1 - DO_EARTH_FLATTENING));
  746.          (void) fprintf(stdout, "\npage 082 : b   = %8.3f", b);
  747.          (void) fprintf(stdout, "\npage 082 : b/a = %10.8f",
  748.                                 (double)( b / DO_EARTH_EQUATORIAL_RADIUS));
  749.          (void) fprintf(stdout, "\npage 082 : 1-f = %10.8f",
  750.                                 (double) (1 - DO_EARTH_FLATTENING));
  751.          (void) fprintf(stdout, "\npage 082 : e   = %10.8f",
  752.                                 (double)
  753.  
  754.                                 sqrt(   ((double) 2 * DO_EARTH_FLATTENING)
  755.                                      -  (  DO_EARTH_FLATTENING
  756.                                          * DO_EARTH_FLATTENING)));
  757.  
  758.          (void) fprintf(stdout, "\npage 082 : ex. 11.a phi          = %8.6f",
  759.                                 doTemp01);
  760.          (void) fprintf(stdout, "\npage 082 :          RhoSinPhiTwo = %9.6f",
  761.                                    DoRhoSinPhiTwo(doTemp01, (double) 1706));
  762.          (void) fprintf(stdout, "\npage 082 :          RhoCosPhiTwo = %9.6f",
  763.                                    DoRhoCosPhiTwo(doTemp01, (double) 1706));
  764.  
  765.          }
  766.       #endif
  767.       /**********************************************************************/
  768.       #ifdef PAGE_165_TEST
  769.       if (1)                                            /*lint !e506 !e774 */
  770.          {
  771.          short sh1 = (short) 0;
  772.  
  773.          double doJD     = (double) 2448908.5;
  774.          double doalpha  = (double)       0;
  775.          double dodelta  = (double)       0;
  776.          short  shMethod = (short)        1;
  777.  
  778.          sh1 = ShSolarCoordinates(doJD, &doalpha, &dodelta, shMethod);
  779.          if (sh1 != 0)
  780.             {
  781.             (void) fprintf(stdout,
  782.                        "\npage 165 : ShSolarCoordinates() returns %hd",
  783.                            sh1);
  784.             }
  785.          else
  786.             {
  787.             (void) fprintf(stdout,
  788.                            "\npage 165 : doalpha = %f, dodelta = %f",
  789.                            doalpha, dodelta);
  790.             }
  791.          }
  792.       #endif
  793.       /**********************************************************************/
  794.       #ifdef PAGE_169_TEST
  795.       if (1)                                            /*lint !e506 !e774 */
  796.          {
  797.          }
  798.       #endif
  799.       /**********************************************************************/
  800.       #ifdef PAGE_353_TEST
  801.       if (1)                                            /*lint !e506 !e774 */
  802.          {
  803.          short  sh1   = (short)  0;
  804.          double doJDE = (double) 0;
  805.  
  806.          sh1 = ShMoonPhaseJDE(&doJDE, (double) 1977.13, (short) 0);
  807.          if (sh1 == 0)
  808.             {
  809.             (void) fprintf(stdout, "\npage 353 : ex. 49.a JDE = %13.5f", doJDE);
  810.             }
  811.          else
  812.             {
  813.             (void) fprintf(stdout,
  814.                    "\npage 353 : ex. 49.a ShMoonPhaseJDE returns %hd", sh1);
  815.             }
  816.  
  817.          sh1 = ShMoonPhaseJDE(&doJDE, (double) 2044, (short) 3);
  818.          if (sh1 == 0)
  819.             {
  820.             (void) fprintf(stdout, "\npage 353 : ex. 49.b JDE = %13.5f", doJDE);
  821.             }
  822.          else
  823.             {
  824.             (void) fprintf(stdout,
  825.                    "\npage 353 : ex. 49.b ShMoonPhaseJDE returns %hd", sh1);
  826.             }
  827.          }
  828.  
  829.       if (1)                                            /*lint !e506 !e774 */
  830.          {
  831.          short  sh1                = (short)   0;
  832.          short  sh2                = (short)   0;
  833.          double doJDE              = (double)  0;
  834.          double doY                = (double)  0;
  835.          double doYear             = (double)  0;
  836.          double doMonth            = (double)  0;
  837.          double doDay              = (double)  0;
  838.          double doHour             = (double)  0;
  839.          double doMin              = (double)  0;
  840.          double doSec              = (double)  0;
  841.          double doPreviousNew[2]   = {(double) 0, (double) 0};
  842.          unsigned long uloLunation = (unsigned long) 0;
  843.  
  844.          (void) fprintf(stdout, "\n\n%s\n",
  845.                   "Lunation              New Moon                            First Quarter                          Full Moon                            Last Quarter              Lunation Duration");
  846.          (void) fprintf(stdout, "%s\n",
  847.                   "-------- ------------------------------------  ------------------------------------  ------------------------------------  ------------------------------------  -----------------");
  848.  
  849.          doY = (double) 1920;             /* min -2000 */
  850.          while (doY < (double) 2020)      /* max +6000 */
  851.             {
  852.             if (uloLunation > 0)
  853.                {
  854.                (void) fprintf(stdout, "%05ld : " , uloLunation);
  855.                uloLunation++;
  856.                }
  857.             else
  858.                {
  859.                (void) fprintf(stdout, "%8s", "");
  860.                }
  861.             for (sh1 = (short) 0 ; sh1 < 4 ; sh1++)
  862.                {
  863.                sh2 = ShMoonPhaseJDE(&doJDE, doY, sh1);
  864.                if (sh2 != 0)
  865.                   {
  866.                   break;
  867.                   }
  868.                else
  869.                   {
  870.                   if (sh1 == 0)
  871.                      {
  872.                      doPreviousNew[0] = doPreviousNew[1];
  873.                      doPreviousNew[1] = doJDE;
  874.                      if (floor(doJDE) == 2423407)
  875.                         {
  876.                         uloLunation = (unsigned long) 1;
  877.                         }
  878.                      }
  879.                   sh2 = ShDateFromJulianDay(doJDE, &doYear, &doMonth, &doDay,
  880.                                                    &doHour, &doMin,   &doSec);
  881.                   if (sh2 != 0)
  882.                      {
  883.                      break;
  884.                      }
  885.                   else
  886.                      {
  887.                      (void) fprintf(stdout,
  888.                                    "%04.0f/%02.0f/%02.0f"
  889.                                    " %02.0f:%02.0f:%02.0f (%14f)  "
  890.                                    ,
  891.                                    doYear, doMonth, doDay, doHour,
  892.                                    doMin, doSec, doJDE);
  893.                      }
  894.                   }
  895.                }
  896.             (void) fprintf(stdout, "%9f\n",
  897.                            (double) (doPreviousNew[0] > 0 ?
  898.                                      (doPreviousNew[1] - doPreviousNew[0])
  899.                                      : 0));
  900.  
  901.             doY += ((double) 29.530589 / (double) 365.25);
  902.             }
  903.          (void) fprintf(stdout, "%s", "\n");
  904.          }
  905.  
  906.       #endif
  907.       /**********************************************************************/
  908.  
  909.       #ifdef PAGE_384_TEST
  910.       if (1)                                            /*lint !e506 !e774 */
  911.          {
  912.          short  sh1   = (short)  0;
  913.          double doResult = (double) 0;
  914.  
  915.          sh1 = ShEclipsesJDE(&doResult, (double) 1993.38, (short) 0);
  916.  
  917.          if (sh1 == 0)
  918.             {
  919.             (void) fprintf(stdout, "\npage 384 : ex. 54.a result = %13.5f", doResult);
  920.             }
  921.          else
  922.             {
  923.             (void) fprintf(stdout,
  924.                    "\npage 384 : ex. 49.a ShMoonPhaseJDE returns %hd", sh1);
  925.             }
  926.          }
  927.       #endif
  928.       /**********************************************************************/
  929.       }
  930.  
  931.    return iReturnValue;
  932.    }
  933.  
  934. /****************************************************************************/
  935.  
  936.  
  937. /* eod of file */
  938.  

< SolarCoordinates.c | index | AstronomicalAlgorithms.h >


printer friendly view

   
Google
 
Web www.christophedavid.org