ÿþv a r   r t i m e ,   r d a y ,   r m o n ,   r y e a r ,   r d w ,   r n t i m e ;  
 v a r   R P D   =   0 . 0 1 7 4 5 3 2 9 2 5 1 9 9 4 3 2 9 5 7 7 ;   / *   r a d i a n s   p e r   d e g r e e   ( p i / 1 8 0 )   * /  
 v a r   T I M Z   =   3 . 0 ;  
 v a r   M I N A G E   =   1 3 . 5 ;  
 v a r   S U N S E T   =   1 9 . 5 ;   / * a p p r o x i m a t e   * /  
 v a r   T I M D I F   =   ( S U N S E T - M I N A G E )   ;  
 v a r   N M O N T H S   =   ( 1 4 0 5 * 1 2 + 1 ) ;    
 h   =   { t i m e :   r t i m e ,   d a y :   r d a y   ,   m o n :   r m o n   ,   y e a r :   r y e a r   ,   d w :   r d w   ,   n m t i m e :   r n t i m e   }  
 d o w   =   [ " 'D#-/" ,   " 'D'+FJF" ,   " 'D+D'+'!" ,   " 'D#1(9'!" ,   " 'D.EJ3" ,   " 'D,E9)" ,   " 'D3(*"   ]  
 m n a m e   =   [ " J a n u a r y " ,   " F e b r u a r y " ,   " M a r c h " ,   " A p r i l " ,   " M a y " ,   " J u n e " ,   " J u l y " ,   " A u g u s t " ,   " S e p t e m b e r " ,   " O c t o b e r " ,   " N o v e m b e r " ,   " D e c e m b e r "   ]  
 h m n a m e   =   [   " E-1E" ,   " 5A1" ,   " 1(J9  'D#HD" ,   " 1(J9  'D+'FJ" ,   " ,E'/J  'D#HDI" ,   " ,E'/  'D+'FJ)" ,   " 1,(" ,   " 49('F" ,   " 1E6'F" ,   " 4H'D" ,   " 0H  'DB9/)" ,   " 0H  'D-,)" ]  
 e h m n a m e   =   [ " E-1E" ,   " 5A1" ,   " 1(J9  'D#HD" ,   " 1(J9  'D+'FJ" , " ,E'/  'D#HDI" ,   " ,'/  'D+'FJ)" ,   " 1,(" ,   " 49('F" ,   " 1E6'F" ,   " 4H'D" ,   " 0H  'DB9/)" ,   " 0H  'D-,)" ]  
 e d o w   =   [   " 'D#-/" ,   " 'D#+FJF" ,   " 'D+D'+'!" ,   " 'D#1(9'!" , " 'D.EJ3" ,   " 'D,E9)" ,   " 'D3(*" ]  
 t m n a m e =   [ " JF'J1" , " A(1'J1" , " E'13" , " #(1JD" , " E'JH" , " JHFJH" , " JHDJH" , " #:373" , " 3(*E(1" , " #C*H(1" , " FHAE(1" , " /J3E(1" ]  
 g   =   { t i m e :   r t i m e ,   d a y :   r d a y   ,   m o n :   r m o n   ,   y e a r :   r y e a r   ,   d w :   r d w   ,   n m t i m e :   r n t i m e   }   / /   n e w  
  
 v a r   r j d ;  
 v a r   y ,   m ,   d ;  
  
 f u n c t i o n   I n t ( x )  
 {  
   i f   (   x   <   0   )  
   {  
         	 x   =   - x ;  
 	 x   =   M a t h . f l o o r ( x + ( x   <   0   ?   1   :   0 ) )  
 	 x   =   - x ;  
   }  
   e l s e  
   {  
   	 x   =   M a t h . f l o o r ( x + ( x   <   0   ?   1   :   0 ) )  
   }    
   r e t u r n   x ;  
 }  
  
 f u n c t i o n   t m o o n p h a s e (   n ,   n p h )  
 {  
       n p h   =   I n t ( n p h ) ;  
 	 v a r   j d ,   t ,   t 2 ,   t 3 ,   k ,   m a ,   s a ,   t f ,   x t r a ;  
 	 k   =   n   +   n p h / 4 . 0 ;     t   =   k / 1 2 3 6 . 8 5 ;     t 2   =   t * t ;   t 3   =   t 2 * t ;  
 	 j d   =     2 4 1 5 0 2 0 . 7 5 9 3 3   +   2 9 . 5 3 0 5 8 8 6 8   *   k   -   1 . 1 7 8 e - 4   *   t 2   -   1 . 5 5 e - 7     *   t 3   +   3 . 3 e - 4   *   M a t h . s i n ( R P D   *   ( 1 6 6 . 5 6   + 1 3 2 . 8 7   *   t   -   0 . 0 0 9 1 7 3   *   t 2 ) ) ;    
  
 	 / *   S u n ' s   m e a n   a n o m a l y   * /  
 	 s a   =     R P D   *   ( 3 5 9 . 2 2 4 2   +   2 9 . 1 0 5 3 5 6 0 8 * k   -   3 . 3 3 e - 5   *   t 2   -   3 . 4 7 e - 6   *   t 3 ) ;  
  
 	 / *   M o o n ' s   m e a n   a n o m a l y   * /  
 	 m a   =     R P D   *   ( 3 0 6 . 0 2 5 3   +   3 8 5 . 8 1 6 9 1 8 0 6 * k   +   0 . 0 1 0 7 3 0 6 * t 2   + 1 . 2 3 6 e - 5   * t 3 ) ;  
  
 	 / *   M o o n ' s   a r g u m e n t   o f   l a t i t u d e   * /  
 	 t f   =   R P D   *   2 . 0   *   ( 2 1 . 2 9 6 4   +   3 9 0 . 6 7 0 5 0 6 4 6 * k   - 0 . 0 0 1 6 5 2 8 * t 2  
 	 	             - 2 . 3 9 e - 6   *   t 3 ) ;  
  
 	 / *   s h o u l d   r e d u c e   t o   i n t e r v a l   0 - 1 . 0   b e f o r e   c a l c u l a t i n g   f u r t h e r   * /  
 	 i f   ( n p h = = 0   | |   n p h = = 2 )  
 	 	 / *   C o r r e c t i o n s   f o r   N e w   a n d   F u l l   M o o n   * /  
 	 	 x t r a   =   ( 0 . 1 7 3 4   -   0 . 0 0 0 3 9 3 * t )   *   M a t h . s i n ( s a )  
 	 	             + 0 . 0 0 2 1 * M a t h . s i n ( s a * 2 )  
 	 	             - 0 . 4 0 6 8 * M a t h . s i n ( m a )   + 0 . 0 1 6 1 * M a t h . s i n ( 2 * m a )   - 0 . 0 0 0 4 * M a t h . s i n ( 3 * m a )  
 	 	             + 0 . 0 1 0 4 * M a t h . s i n ( t f )  
 	 	             - 0 . 0 0 5 1 * M a t h . s i n ( s a + m a )   - 0 . 0 0 7 4 * M a t h . s i n ( s a - m a )  
 	 	             + 0 . 0 0 0 4 * M a t h . s i n ( t f + s a )   - 0 . 0 0 0 4 * M a t h . s i n ( t f - s a )  
 	 	             - 0 . 0 0 0 6 * M a t h . s i n ( t f + m a )   + 0 . 0 0 1 0 * M a t h . s i n ( t f - m a )  
 	 	             + 0 . 0 0 0 5 * M a t h . s i n ( s a +   2 * m a ) ;  
 	 e l s e   i f   ( n p h = = 1   | |   n p h = = 3 )   {  
 	 	 x t r a   =   ( 0 . 1 7 2 1   -   0 . 0 0 0 4 * t )   *   M a t h . s i n ( s a )  
 	 	             + 0 . 0 0 2 1 * M a t h . s i n ( s a * 2 )  
 	 	             - 0 . 6 2 8 0 * M a t h . s i n ( m a )   + 0 . 0 0 8 9 * M a t h . s i n ( 2 * m a )   - 0 . 0 0 0 4 * M a t h . s i n ( 3 * m a )  
 	 	             + 0 . 0 0 7 9 * M a t h . s i n ( t f )  
 	 	             - 0 . 0 1 1 9 * M a t h . s i n ( s a + m a )   - 0 . 0 0 4 7 * M a t h . s i n ( s a - m a )  
 	 	             + 0 . 0 0 0 3 * M a t h . s i n ( t f + s a )   - 0 . 0 0 0 4 * M a t h . s i n ( t f - s a )  
 	 	             - 0 . 0 0 0 6 * M a t h . s i n ( t f + m a )   + 0 . 0 0 2 1 * M a t h . s i n ( t f - m a )  
 	 	             + 0 . 0 0 0 3 * M a t h . s i n ( s a +   2 * m a )   + 0 . 0 0 0 4 * M a t h . s i n ( s a - 2 * m a )  
 	 	             - 0 . 0 0 0 3 * M a t h . s i n ( 2 * s a + m a ) ;  
 	 	 i f   ( n p h = = 1 )  
 	 	 	 x t r a   =   x t r a   + 0 . 0 0 2 8   - 0 . 0 0 0 4 * M a t h . c o s ( s a )   + 0 . 0 0 0 3 * M a t h . c o s ( m a ) ;  
 	 	 e l s e  
 	 	 	 x t r a   =   x t r a   - 0 . 0 0 2 8   + 0 . 0 0 0 4 * M a t h . c o s ( s a )   - 0 . 0 0 0 3 * M a t h . c o s ( m a ) ;  
 	 }   e l s e   {  
 	 	 p r i n t f ( " t m o o n p h a s e :   i l l e g a l   p h a s e   n u m b e r \ n " ) ;  
 	 	 e x i t ( 1 ) ;  
 	 }  
 	 / *   c o n v e r t   f r o m   E p h e m e r i s   T i m e   ( E T )   t o   ( a p p r o x i m a t e )    
 	       U n i v e r s a l   T i m e   ( U T )   * /  
 	 j d   + =   x t r a   -   ( 0 . 4 1   + 1 . 2 0 5 3 * t   + 0 . 4 9 9 2 * t 2 ) / 1 4 4 0 ;  
 	 r e t u r n   ( j d ) ;  
 }  
  
 f u n c t i o n   j u l i a n d a y (   y e a r ,   m o n t h ,   d a y ,   t i m e )  
 {  
 	 v a r   j u l ;  
 	 v a r   m , y , j a ;  
 	 i f   ( y e a r < 0 )   y e a r + + ;  
 	 i f   ( m o n t h > 2 )   {  
 	 	 y   =   y e a r ;   m   = m o n t h ;  
 	 }   e l s e   {  
 	 	 y   =   y e a r - 1 ;   m   = m o n t h + 1 2 ;  
 	 }  
 	 j u l   =   y   *   3 6 5 . 2 5 ;  
 	  
 	 i f   ( y < 1 )   j u l   - =   0 . 7 5 ;  
 	  
 	 j u l   =   I n t ( j u l )   +   ( I n t ( 3 0 . 6 0 0 1 * ( m + 1 ) ) )   + d a y   + t i m e   + 1 7 2 0 9 9 4 . 5 ;    
        
 	 i f   ( y e a r   + m o n t h * 1 e - 2   + ( d a y + t i m e ) * 1 e - 4   > =   1 5 8 2 . 1 0 1 5 )   {  
 	 	 / *   c r o s s - o v e r   t o   G r e g o r i a n   c a l e n d a r   * /  
 	 	 j a   =   I n t ( 0 . 0 1 * y ) ;  
 	 	 j u l   =   j u l   + 2   - j a   +   ( I n t ( 0 . 2 5 * j a ) ) ;  
 	 }  
 	 r e t u r n   j u l ;  
 }  
  
  
 f u n c t i o n   v i s i b l e ( n ,   r i y )  
 {  
 	 v a r   j d ;  
 	 v a r   t f ;  
 	 v a r   d ;  
         	 n   =   I n t ( n ) ;  
 	 j d   =   t m o o n p h a s e ( n , 0 ) ;     r j d   =   j d ;  
 	 d   =   I n t ( j d ) ;  
  
 	 t f   =   ( j d   -   d ) ;  
 	 i f   ( t f < = 0 . 5 )     / * n e w   m o o n   s t a r t s   i n   t h e   a f t e r n o o n   * /  
 	 	 r e t u r n ( j d + 1 . 0 ) ;    
 	 / *   n e w   m o o n   s t a r t s   b e f o r e   n o o n   * /  
 	 t f   =   ( t f - 0 . 5 ) * 2 4   + T I M Z ;     / *   l o c a l   t i m e   * /    
 	 i f   ( t f > T I M D I F )   r e t u r n ( j d + 1 . 0 ) ;     / * a g e   a t   s u n s e t   <   m i n   f o r   v i s i b l i t y * /  
  
 	 r e t u r n ( j d ) ;  
 }  
  
 f u n c t i o n   h d a t e   ( y , m , d )  
 {  
 	 v a r   j d ,   m j d ;  
 	 v a r   k ,   h m ;  
      
 	 j d   =   j u l i a n d a y ( y , m , d , 0 . 0 0 ) ;    
 	 / *   o b t a i n   f i r s t   a p p r o x .   o f   h o w   m a n y   n e w   m o o n s   s i n c e   t h e   b e g i n n i n g  
 	       o f   t h e   y e a r   1 9 0 0   * /  
 	 k   =   I n t ( 0 . 6   +   ( y   +   ( I n t ( m - 0 . 5 ) )   / 1 2 . 0   +   d / 3 6 5 . 0   -   1 9 0 0 )   * 1 2 . 3 6 8 5 ) ;  
 	 d o     {  
 	 m j d   =   v i s i b l e ( k - - ,   r j d ) ;    
 	 }   w h i l e   ( m j d   >   j d ) ;      
 	 k + + ;  
 	 / * f i r s t   o f   t h e   m o n t h   i s   t h e   f o l l o w i n g   d a y * /  
 	 h m   =   I n t ( k   -   1 0 4 8 ) ;      
 	 h . y e a r   =   I n t ( 1 4 0 5   +   I n t ( h m   /   1 2 ) ) ;  
 	 h . m o n   =     I n t ( ( h m   %   1 2 )   + 1 ) ;    
 	 i f   ( h m   ! = 0   & &   h . m o n < = 0 )   { h . m o n   + = 1 2 ;   h . y e a r - - ;   }  
 	 i f   ( h . y e a r < = 0 )   h . y e a r - - ;  
 	 h . d a y   =   I n t ( j d   -   m j d   +   1 . 0 ) ;  
 	 h . t i m e   =   0 . 5 ;  
 	 h . d w   =   I n t ( I n t ( j d + 1 . 5 )   %   7 ) ;  
 	 r e t u r n ( h ) ;  
 }  
 f u n c t i o n   c a l d a t e (   j u l d a y   )  
 {  
 	 j u l d a y   + =   0 . 5 ;   z   =   I n t ( j u l d a y ) ;   f   =   j u l d a y - z ;  
 	 i f   (   z   <   2 2 9 9 1 6 1   )      
 	 {  
 	 	 a   =   z ;  
 	 }  
 	 e l s e   {  
 	 	 a l p h a   =   I n t ( ( z - 1 8 6 7 2 1 6 . 2 5 )   /   3 6 5 2 4 . 2 5 ) ;  
 	 	 a           =   I n t ( z   +   1   + a l p h a   -   I n t ( a l p h a   /   4 ) ) ;  
 	 	 }  
  
 	 b   =   I n t ( a   +   1 5 2 4 ) ;     c   =   I n t ( ( b   -   1 2 2 . 1 )   /   3 6 5 . 2 5 ) ;   d   =   I n t ( 3 6 5 . 2 5   *   c ) ;  
 	 e   =   I n t ( ( b - d )   /   3 0 . 6 0 0 1 ) ;  
 	 f   + =   b   - d   -   ( I n t ( 3 0 . 6 0 0 1 * e ) ) ;  
 	  
 	 g . d a y   =   I n t ( f ) ;  
 	 g . t i m e   =   f   -   g . d a y ;  
 	 g . m o n   =   ( e > 1 3 )   ?   e - 1 3   :   e - 1 ;  
 	 g . y e a r   =   ( g . m o n > 2 )   ?   c - 4 7 1 6   :   c - 4 7 1 5 ;  
 	 g . d w   =   I n t ( ( I n t ( j u l d a y   -   g . t i m e   +   1 . 1 ) )   %   7 ) ;  
 	 i f   (   g . y e a r < = 0 )   g . y e a r - - ;  
 	 r e t u r n ( g ) ;  
 }  
  
 f u n c t i o n   g d a t e (   y ,   m ,   d )  
 {  
 	 i f   ( y < 0 )   y + + ;  
 	 k   =   I n t ( m +   y * 1 2   -   N M O N T H S ) ;       / *   #   o f   m o n t h s   s i n c e   1 / 1 / 1 4 0 5   * /  
  
 	 j d   =   v i s i b l e ( k + 1 0 4 8 ,   r j d )   + d ;  
  
 	 g   =   c a l d a t e ( j d ) ;  
 	 g . n m t i m e   =   r j d ;  
 	 r e t u r n   ( g ) ;  
 	  
 }  
  
  
 f u n c t i o n   m a i n ( )  
 {  
 	 v a r   	 d ,   m ,   y ,   h f l a g = 0 ;  
  
 	 v a r   t i m e =   n e w   D a t e ( ) ;  
 	 v a r   m   =   t i m e . g e t M o n t h ( )   +   1 ;  
 	 v a r   d   =   t i m e . g e t D a t e ( ) ;  
 	 v a r   y   =   t i m e . g e t Y e a r ( ) ;  
 	  
 	 i f   ( y   <   2 0 0 0 ) {  
 	         y   =   y   +   1 9 0 0 ;  
 	 }  
        
 	 s d   =   h d a t e ( y ,   m ,   d ) ;  
       h i j r i   =     ' < f o n t   s i z e = " 2 " > < f o n t   s i z e = " 2 " > ' + d o w [ h . d w ]   +   ' < / f o n t >   '   +   h . d a y   +   ' < f o n t     s i z e = " 2 " >   '   +   h m n a m e [ h . m o n   -   1 ]   +   ' < / f o n t >   '   +   h . y e a r   +   '   < f o n t     > DDG,1)< / f o n t   s i z e = " 2 " > < / f o n t > '  
  
  
       r e t u r n   h i j r i ;  
 }  
  
 
