/* Sunrise/Sunset Program */ /* Astronomy, April 1984, pp. 75-77. */ /* Halachic Z'manim added by Andrew M. Shooman, 26 January 1992 */ #include /* Global Definitions */ float a,b,c,d,e,f,g,j,k,p,q,r,v,x,z; float sr,ss,sh; int h,i,m,y; float pi=3.14159265358979; /* Prototype Definitions */ void main(void); float sexdec(float z); void solarpos(float j); float coordconv(int i, float r); float decsex(float v); void normalize(float *z); void main(void) { /* Constant Definitions */ a=pi/2.0; b=pi; c=a+pi; d=pi*2.0; /* Inputs */ printf("Sunrise/Sunset Program\n"); printf("----------------------\n"); printf("LAT ----> "); scanf("%f",&z); e=sexdec(z)*pi/180.0; printf("LON ----> "); scanf("%f",&z); f=sexdec(z)*pi/180.0; printf("ZONE ---> "); scanf("%f",&z); g=sexdec(z)*pi/12.0; printf("YEAR ---> "); scanf("%d",&h); printf("MONTH --> "); scanf("%d",&i); printf("DAY ----> "); scanf("%f",&j); /* Day of Year */ k=(int)((i+9)/12); x=h/4.0; y=(int)x; z=x-y; if(z!=0) k*=2; h=(int)(275*i/9); h+=j-k-30; /* Rising Phenomena */ printf("\n"); solarpos(a); r= -.309017; v=coordconv(0,r); printf("Astronomical Dawn %5.2f\n",v); r= -.207912; v=coordconv(0,r); printf("Nautical Dawn %5.2f\n",v); r= -.104528; v=coordconv(0,r); printf("Civil Dawn %5.2f\n",v); r= -.0145439; v=coordconv(0,r); printf("SUNRISE %5.2f\n",v); sr=v; /* Setting Phenomena */ solarpos(c); r= -.0145439; v=coordconv(1,r); if(v>=24.0) v-=24.0; printf("SUNSET %5.2f\n",v); ss=v; sh=v; r= -.104528; v=coordconv(1,r); printf("Civil Dusk %5.2f\n",v); r= -.207912; v=coordconv(1,r); printf("Nautical Dusk %5.2f\n",v); r= -.309017; v=coordconv(1,r); printf("Astronomical Dusk %5.2f\n",v); sr=sexdec(sr); ss=sexdec(ss); v=decsex((ss-sr)*pi/12.0); printf("Length %5.2f\n",v); solarpos(a); r= -.258819; v=coordconv(0,r); printf("\nAlot ha-Shachar %5.2f\n",v); r= -.219279; v=coordconv(0,r); printf("Talit v'T'filin %5.2f\n",v); r= -.0145439; v=coordconv(0,r); printf("SUNRISE %5.2f\n",v); if(ss>sr) m=0; else m=24; v=decsex((sr+(ss-sr+m)/4.0)*pi/12.0); printf("Z'man T'fila %5.2f\n",v); v=decsex((sr+(ss-sr+m)/2.0)*pi/12.0); printf("Midday %5.2f\n",v); v=decsex((sr+(ss-sr+m)*13.0/24.0)*pi/12.0); printf("Mincha G'dola %5.2f\n",v); v=decsex((sr+(ss-sr+m)*19.0/24.0)*pi/12.0); printf("Mincha K'tana %5.2f\n",v); if(sh<0.18) sh+=24.0; if((sh-(int)sh)<0.18) v=sh-0.58; else v=sh-0.18; if(v<0) v=0; if(sh>=24.0) sh-=24.0; printf("Candles %5.2f\n",v); printf("SUNSET %5.2f\n",sh); solarpos(c); r= -.156434; v=coordconv(1,r); printf("3 Stars %5.2f\n",v); } /* Sexagesimal to Decimal */ float sexdec(float z) { float w,y; w=1; if(z<0) { w= -1; z=fabs(z); } x=(int)z; z=(z-x)*100.0; y=(int)z; z=(z-y)*100.0; return((x+y/60.0+z/3600.0)*w); } /* Approximate Time */ void solarpos(float j) { float l,m,x,z; int n,y; k=h+((j+f)/d); /* Solar Mean Anomaly */ l=k*.017202; l=l-.0574039; /* Solar True Longitude */ z=sin(l); m=l+.0334405*z; z=sin(2.0*l); m=m+3.49066e-04*z; m=m+4.93289; /* Quadrant Determination */ normalize(&m); x=m/a; y=(int)x; z=x-y; if(z==0) m=m+4.84814e-06; if(m>c) n=2; else if(m>a) n=1; else n=0; /* Solar Right Ascension */ p=tan(m); p=atan(.91746*p); /* Quadrant Adjustment */ if(n==1) p+=b; else if(n==2) p+=d; /* Solar Declination */ q=.39782*sin(m); q=asin(q); } /* Coordinate Conversion */ float coordconv(int i, float r) { float s,t,u,z; s=r-(sin(q)*sin(e)); s=s/(cos(q)*cos(e)); /* Null Phenomenon */ z=fabs(s); if(z>1.0) return(0); /* Adjustment */ s= -asin(s)+a; if(i!=1) s=d-s; /* Local Apparent Time */ z=.0172028*k; t=s+p-z-1.73364; /* Universal Time */ u=t+f; /* Wall Clock Time */ return(decsex(u-g)); } /* Decimal to Sexagesimal */ float decsex(float v) { float w,x,y,z; normalize(&v); z=v*3.81972; v=(int)z; w=(z-v)*60.0; x=(int)w; y=w-x; if(y>=0.5) x++; if(x>=60) { v++; x=0; } return(v+x/100.0); } /* Normalization */ void normalize(float *z) { if(*z>=0) (*z)=fmod(*z,d); else (*z)=fmod(*z,d)+d; } -------------------------CUT HERE----------------------------------- Documentation and instructions: Sunrise/Sunset Program ---------------------- LAT ----> 42.21 LON ----> 71.07 ZONE ---> 5 YEAR ---> 1992 MONTH --> 2 DAY ----> 4 Astronomical Dawn 5.19 Nautical Dawn 5.52 Civil Dawn 6.26 SUNRISE 6.55 SUNSET 17.02 Civil Dusk 17.32 Nautical Dusk 18.05 Astronomical Dusk 18.38 Length 10.07 Alot ha-Shachar 5.36 Talit v'T'filin 5.49 SUNRISE 6.55 Z'man T'fila 9.27 Midday 11.59 Mincha G'dola 12.24 Mincha K'tana 14.56 Candles 16.44 SUNSET 17.02 3 Stars 17.49 Explanation: ----------- The LATITUDE and LONGITUDE for this example are for Brookline, Massachusetts. ZONE 5 means EST (Eastern Standard Time), 5 hours behind GMT (Greenwich Mean Time) or UT (Universal Time), the reference point for all time zones in Greenwich, England. (Use 5 for EST and 4 for EDT). For DAWN and DUSK, A=astronomical, N=nautical, C=civil. ALOT HA-SHACHAR is the time when the sun is 15 degrees below the horizon before sunrise, the earliest time to begin Shacharit. TALIT V'T'FILIN is the time when the sun is 12+2/3 degrees below the horizon before sunrise. Z'MAN T'FILA is Sof Z'man Kriat Sh'ma, 3 daylight hours after sunrise. MIDDAY is the midpoint between sunrise and sunset. MINCHA G'DOLA is the earliest time to begin Mincha, 1/2 daylight hour after midday. MINCHA K'TANA is the preferred earliest time to begin Mincha, 3+1/2 daylight hours after midday. CANDLES is Z'man Hadlakat Nerot, 18 minutes before Shkiya or sunset. 3 STARS is the end of Shabbat or Yom Tov, the time when the sun goes 9 degrees below the horizon, derived from Rav Yehuda's Tzeit ha-Kochavim from Shabbat 34b,35a. (All times are given according to the 24 hour clock: 1.00 = 1 AM, 13.00 = 1 PM). The program uses (+) as north and (-) as south for latitude and (+) as west and (-) as east for longitude. You can compile the sunrise program on a Unix machine with the standard C compiler or on a PC using Turbo C. For Unix, remember to link with the math library as follows: cc sunrise.c -o sunrise -lm Happy computing!.. p.s. Here are some sample US lats/longs (courtesy of Andy Shooman): Location Latitude Longitude -------- -------- --------- Bethesda, MD 38.59 N 77.07 W Bronx, NY (Einstein) 40.51 N 73.51 W Brookline, MA 42.21 N 71.07 W Brooklyn, NY (Brighton Beach) 40.34 N 73.57 W Brooklyn, NY (Polytechnic U.) 40.42 N 73.59 W Cambridge, MA 42.22 N 71.06 W Canton, MA 42.09 N 71.07 W Desert Hot Springs, CA 33.57 N 116.30 W Glen Cove, NY 40.52 N 73.37 W Hawthorne, NY 41.06 N 73.49 W Hinsdale, MA 42.27 N 73.05 W Indian Orchard, PA 41.33 N 75.13 W Las Vegas, NV 36.10 N 115.09 W Monsey, NY 41.07 N 74.04 W New York, NY (NYU) 40.44 N 74.00 W New York, NY (Wash. Heights) 40.51 N 73.57 W Newton, MA 42.18 N 71.11 W Ocean, NJ 40.15 N 74.02 W Orlando, FL 28.32 N 81.22 W Phoenix, AZ 33.27 N 112.04 W Port Jervis, NY 41.23 N 74.41 W Tannersville, NY 42.12 N 74.08 W