19 Fev 2014 13:43
19 Fev 2014 19:43
20 Fev 2014 04:17
*-------------------------------------------------------------------------------
*
* Astro.Prg
*
* Compilar com hbmk2 astro hbct.hbc
*
* Alexandre Santos - 20/02/2014
*-------------------------------------------------------------------------------
#include "box.ch"
#include "set.ch"
#include "setcurs.ch"
#include "inkey.ch"
#include "hbcompat.ch"
#define PI 3.1415926535897932385
//------------------------------------------------------------------------------
REQUEST HB_CODEPAGE_PTISO
INIT PROCEDURE AppInit()
RELEASE GetList
Set( _SET_DATEFORMAT, "dd/mm/yyyy" )
Set( _SET_DELETED, .T. )
Set( _SET_SCOREBOARD, .F. )
Set( _SET_EVENTMASK, 255 )
SetMode(25,80)
SetBlink( .F. )
SetCursor( SC_NONE )
SetColor( "N/W, W+/N" )
DispOutAt( 0,0, PadC("Compute moon position and phase",80), "W+/N*" )
DispBox(1,0,MaxRow() - 1, MaxCol(), B_SINGLE + " ")
DispOutAt( MaxRow(),0, PadR( " Enter date or <ESC> to exit...", 80), "W+/N*" )
RETURN
//------------------------------------------------------------------------------
Function AppMain()
LOCAL dDate As Date := Date()
LOCAL GetList As Array := {}
@ 06, 05 Say "Moon on " ;
Get dDate
READ SAVE
WHILE LastKey() != K_ESC
DispBox(08,05,16,75, Space(9))
moon_posit( Year(dDate ), Month(dDate ),Day(dDate ) )
READ SAVE
ENDDO
RETURN NIL
//------------------------------------------------------------------------------
EXIT PROCEDURE AppExit()
CLS
RETURN
//------------------------------------------------------------------------------
// compute moon position and phase
PROCEDURE moon_posit( Y, M, D )
LOCAL AG As Numeric // Moon's age
LOCAL DI As Numeric // Moon's distance in earth radii
LOCAL LA As Numeric // Moon's ecliptic latitude
LOCAL LO As Numeric // Moon's ecliptic longitude
LOCAL Phase As Character
LOCAL Zodiac As Character
LOCAL YY, MM, K1, K2, K3, JD As Numeric
LOCAL IP, DP, NP, RP As Numeric
// calculate the Julian date at 12h UT
YY := Y - floor( ( 12 - M ) / 10 )
MM := M + 9
if (MM >= 12)
MM := MM - 12
end if
K1 := Floor( 365.25 * ( YY + 4712 ) )
K2 := Floor( 30.6 * MM + 0.5 )
K3 := Floor( Floor( ( YY / 100 ) + 49 ) * 0.75 ) - 38
JD := K1 + K2 + D + 59 // for dates in Julian calendar
if (JD > 2299160)
JD := JD - K3 // for Gregorian calendar
endif
// calculate moon's age in days
IP := normalize( ( JD - 2451550.1 ) / 29.530588853 )
AG := IP*29.53
if AG < 1.84566
Phase := "NEW"
ElseIf AG < 5.53699
Phase := "Waxing crescent"
ElseIf AG < 9.22831
Phase := "First quarter"
ElseIf AG < 12.91963
Phase := "Waxing gibbous"
ElseIf AG < 16.61096
Phase := "FULL"
ElseIf AG < 20.30228
Phase := "Waning gibbous"
ElseIf AG < 23.99361
Phase := "Last quarter"
ElseIf AG < 27.68493
Phase := "Waning crescent"
Else
Phase := "NEW"
Endif
IP := IP*2*PI // Convert phase to radians
// calculate moon's distance
DP := 2*PI*normalize( ( JD - 2451562.2 ) / 27.55454988 )
DI := 60.4 - 3.3*cos( DP ) - 0.6*cos( 2*IP - DP ) - 0.5*cos( 2*IP )
// calculate moon's ecliptic latitude
NP := 2*PI*normalize( ( JD - 2451565.2 ) / 27.212220817 )
LA := 5.1*sin( NP )
// calculate moon's ecliptic longitude
RP := normalize( ( JD - 2451555.8 ) / 27.321582241 )
LO := 360*RP + 6.3*sin( DP ) + 1.3*sin( 2*IP - DP ) + 0.7*sin( 2*IP )
if LO < 33.18
Zodiac := "Pisces"
ElseIf LO < 51.16
Zodiac := "Aries"
ElseIf LO < 93.44
Zodiac := "Taurus"
ElseIf LO < 119.48
Zodiac := "Gemini"
ElseIf LO < 135.30
Zodiac := "Cancer"
ElseIf LO < 173.34
Zodiac := "Leo"
ElseIf LO < 224.17
Zodiac := "Virgo"
ElseIf LO < 242.57
Zodiac := "Libra"
ElseIf LO < 271.26
Zodiac := "Scorpio"
ElseIf LO < 302.49
Zodiac := "Sagittarius"
ElseIf LO < 311.72
Zodiac := "Capricorn"
ElseIf LO < 348.58
Zodiac := "Aquarius"
else
Zodiac := "Pisces"
endif
// display results
DispOutAt(08, 05, "Phase = " + Phase)
DispOutAt(09, 05, "Age = " + Ltrim(Str(round2( AG ))) + " days")
DispOutAt(10, 05, "Distance = " + LTrim(Str(round2( DI ))) + " earth radii")
DispOutAt(12, 05, "Ecliptic ")
DispOutAt(13, 05, " Latitude = " + LTrim(Str(round2( LA ))) + Chr(167))
DispOutAt(14, 05, " Longitude = " + LTrim(Str(round2( LO ))) + Chr(167))
DispOutAt(16, 05, "Constellation = " + Zodiac )
RETURN
//--------------------------------------------------------------------------------
STATIC FUNCTION round2( x )
RETURN ( round( 100*x, 1 )/100.0 )
//--------------------------------------------------------------------------------
STATIC FUNCTION Normalize(v)
v := v - floor( v )
if v < 0
v++
end if
RETURN v
//--------------------------------------------------------------------------------
20 Fev 2014 11:18
20 Fev 2014 18:31