[net.sources.bugs] Bug in sunrise/sunset program

frodo@wcom.UUCP (Jim Scardelis) (05/13/85)

	Has anyone else had trouble with Robert Bond's sunrise/sunset
calculation program? I compiled it on my Xenix-286 system, changed

<sys/time.h> to <time.h> as he suggested, changed the default timezone,
latitude and longitude to that of my site, and ran it.

	Instead of giving me an hour and minute for sunrise and sunset,
it gave me something like:

	Sunrise -18032: -53
	Sunset  -18056: -8

	Has this happened to anyone else? Is it what's supposed to
happen???? The other options seem to work ok, giving real numbers anyway...


			Jim Scardelis
-- 

uucp: {vax135|ihnp4}!timeinc!wcom!frodo		
ARPA: 1891@NJIT-EIES.MAILNET@MIT-MULTICS.ARPA
"The opinions expressed herein are those of my computer, and not necessarily
      those of myself, Warner Computer Systems, or any other computer or
        company along the line. "

twb@hoqam.UUCP (BEATTIE) (05/28/85)

> 
> 	Has anyone else had trouble with Robert Bond's sunrise/sunset
> calculation program? 
I tried to understand the various arguments, like -t to change the time.
What does the current time have to do with when the sun rises??

I got out my almanac and it says that on January 1,1981 the sun rose at
06:36 GMT and set at 17:32 GMT,
so I tried sun -z 0 -a 51.5 -o 0 -d 01/01/1981
it says the sun rises at 08:06 and sets at 16:02.
What is the problem?
Tom.

rgb@nsc-pdc.UUCP (Robert Bond) (05/30/85)

In article <144@hoqam.UUCP> twb@hoqam.UUCP (BEATTIE) writes:

>I tried to understand the various arguments, like -t to change the time.
>What does the current time have to do with when the sun rises??

The program also prints the current postion of the sun.  The -t option
lets you specify some time other than the current system time.

>I got out my almanac and it says that on January 1,1981 the sun rose at
>06:36 GMT and set at 17:32 GMT,
>so I tried sun -z 0 -a 51.5 -o 0 -d 01/01/1981
>it says the sun rises at 08:06 and sets at 16:02.

A little common sense says that the sun doesn't rise at 6:30 in the morning
at latitude 51 degrees in the middle of the winter.  Some experimentation
with latitude says that your almanac used latitude about 20.5 degrees north.
Was it an Egyptian almanac? :-)  Seriously, responses from several other
sources around the U.S. indicate that the program is within a few minutes
of the time posted in the paper.

I do have some bugs with Xenix implementations (mostly pointer kinds of
things) that I am working on.  I will post the corrections when I get
it all working.  We don't have a Xenix machine, or any 286's, so its kind
of painful to test.


-- 
    Robert Bond 			nsc!nsc-pdc!rgb
    National Semiconductor		tektronix!reed!nsc-pdc!rgb

twb@hoqam.UUCP (BEATTIE) (05/31/85)

> > 
> > 	Has anyone else had trouble with Robert Bond's sunrise/sunset
> > calculation program? 
> I tried to understand the various arguments, like -t to change the time.
> What does the current time have to do with when the sun rises??
> 
> I got out my almanac and it says that on January 1,1981 the sun rose at
> 06:36 GMT and set at 17:32 GMT,
> so I tried sun -z 0 -a 51.5 -o 0 -d 01/01/1981
> it says the sun rises at 08:06 and sets at 16:02.
> What is the problem?
> Tom.

Apparently I misinterpreted my almanac. I pickup the times for 20 degrees north
of Greenwich (I think).
I tried again.
My newspaper claims that on Friday 5/31/85 the sun rises (rose) at 05:30
and sets (set) at 20:21.
I said:		sun -z 5 -a 40.733 -o 74.1667
It said:	Sunrise:  4:25    Sunset:  19:21        
Which I guess is correct!! (close enough) (since we are on daylight
savings time, add an hour)
Where did the 5 minutes for sunrise go??
How do I get the program to realize it's EDT and not EST?

Tom.

Petribar - n. Any sun-bleached prehistoric candy that has been
sitting in the window of a vending machine too long.

rgb@nsc-pdc.UUCP (Robert Bond) (06/08/85)

Here are the promised fixes for the Volks.. er.. 286 type machines.
Feed this to patch or try it by hand.

If any Microsoft/ IBM support types are interested in C compiler bugs
or broken #include files, please drop me a line.

						Bob Bond

*** sun.c.rel	Thu Jun  6 15:58:09 1985
--- sun.c	Thu Jun  6 15:56:51 1985
***************
*** 11,17
  *        
  *        All output is to standard io.  
  *
! *	 Compile with cc -O  -o sun -lm
  *	 Non 4.2 systems may have to change <sys/time.h> to <time.h> below.
  *
  *	 Note that the latitude, longitude, time zone correction and

--- 11,17 -----
  *        
  *        All output is to standard io.  
  *
! *	 Compile with cc -O -o sun sun.c -lm
  *	 Non 4.2 systems may have to change <sys/time.h> to <time.h> below.
  *
  *	 Note that the latitude, longitude, time zone correction and
***************
*** 51,56
  double cos_deg();
  double tan_deg();
  double gmst();
  
  int th;
  int tm;

--- 51,58 -----
  double cos_deg();
  double tan_deg();
  double gmst();
+ struct tm *localtime();
+ long time();
  
  int th;
  int tm;
***************
*** 77,83
      double lambda1, lambda2;
      double alt, az, gst, m1;
      double hsm, ratio;
!     time_t sec_1970;
      int h, m;
      struct tm *pt;
  

--- 79,85 -----
      double lambda1, lambda2;
      double alt, az, gst, m1;
      double hsm, ratio;
!     long sec_1970;
      int h, m;
      struct tm *pt;
  
***************
*** 139,145
      da = asin_deg(tan_deg(x)/tan_deg(tri));
      dt = 240.0 * y / cos_deg(delta) / 3600;
  
!     lst_to_hm(trise - dt, jd, &h, &m);
      printf("Sunrise: %2d:%02d    ", h, m);
  
      if (popt) {

--- 145,152 -----
      da = asin_deg(tan_deg(x)/tan_deg(tri));
      dt = 240.0 * y / cos_deg(delta) / 3600;
  
!     trise -= dt;
!     lst_to_hm(trise, jd, &h, &m);
      printf("Sunrise: %2d:%02d    ", h, m);
  
      if (popt) {
***************
*** 147,153
          printf("Azimuth: %2d deg %02d min \n", h, m);
      }
  
!     lst_to_hm(tset + dt, jd, &h, &m);
      printf("Sunset:  %2d:%02d    ", h, m);
  
      if (popt) {

--- 154,161 -----
          printf("Azimuth: %2d deg %02d min \n", h, m);
      }
  
!     tset += dt;
!     lst_to_hm(tset, jd, &h, &m);
      printf("Sunset:  %2d:%02d    ", h, m);
  
      if (popt) {
***************
*** 286,292
  double 
  julian_date(m, d, y)
  {
!     int a, b;
      double jd;
  
      if (m == 1 || m == 2) {

--- 294,300 -----
  double 
  julian_date(m, d, y)
  {
!     long a, b;
      double jd;
  
      if (m == 1 || m == 2) {
***************
*** 298,306
  	exit(1);
      }
      a = y/100;
!     b = 2 - a + a/4;
!     b += (int)((double)y * 365.25);
!     b += (int)(30.6001 * ((double)m + 1.0));
      jd = (double)d + (double)b + 1720994.5;
      return(jd);
  }

--- 306,314 -----
  	exit(1);
      }
      a = y/100;
!     b = 2 - a  + a/4;
!     b += (long)((double)y * 365.25);
!     b += (long)(30.6001 * ((double)m + 1.0));
      jd = (double)d + (double)b + 1720994.5;
  
      return(jd);
***************
*** 439,447
  	gst -= 24.0;
      jzjd = julian_date(1,0,yr);
      ed = jd-jzjd;
!     t = (jzjd -2415020.0)/36525.0;
!     r = 6.6460656+2400.05126*t+2.58E-05*t*t;
!     b = 24-(r-24*(yr-1900));
      t0 = ed * 0.0657098 - b;
      if (t0 < 0.0)
  	t0 += 24;

--- 449,457 -----
  	gst -= 24.0;
      jzjd = julian_date(1,0,yr);
      ed = jd-jzjd;
!     t = (jzjd -2415020.0) / 36525.0;
!     r = 6.6460656 + 2400.05126 * t + 2.58E-05 * t * t;
!     b = 24.0 - ( r - 24.0 * ( yr - 1900.0));
      t0 = ed * 0.0657098 - b;
      if (t0 < 0.0)
  	t0 += 24;
***************
*** 448,454
      gmt = gst-t0;
      if (gmt<0) 
  	gmt += 24.0;
!     gmt = gmt * 0.99727 - tz;;
      if (gmt < 0)
  	gmt +=24.0;
      dh_to_hm(gmt, h, m);

--- 458,464 -----
      gmt = gst-t0;
      if (gmt<0) 
  	gmt += 24.0;
!     gmt = gmt * 0.99727 - tz;
      if (gmt < 0)
  	gmt +=24.0;
      dh_to_hm(gmt, h, m);
-- 
    Robert Bond 			nsc!nsc-pdc!rgb
    National Semiconductor		tektronix!reed!nsc-pdc!rgb