Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

Please, help to translate program with language basic..


Please, help to translate program with language basic..

Postby Poooh » Jun 29, 2004 @ 8:40pm

...on language ppl
Thank you! The text on Qbasic following:
(explain Problem: it is necessary to find azimuth a sun in given point in given time that is to say transform PDA in compass, Quite well also draw on screen certain resemblance compass)


'*********************************************************
' This program will calculate the position of the Sun
' using a low precision method found on page C24 of the
' 1996 Astronomical Almanac.
'
' The method is good to 0.01 degrees in the sky over the
' period 1950 to 2050.
'
' QBASIC program by Keith Burnett (kburnett@geocity.com)
'
'
' Work in double precision and define some constants
'
DEFDBL A-Z
pr1$ = "\ \#####.##"
pr2$ = "\ \#####.#####"
pr3$ = "\ \#####.###"
pi = 4 * ATN(1)
tpi = 2 * pi
twopi = tpi
degs = 180 / pi
rads = pi / 180
'
' Get the days to J2000
' h is UT in decimal hours
' FNday only works between 1901 to 2099 - see Meeus chapter 7
'
DEF FNday (y, m, d, h) = 367 * y - 7 * (y + (m + 9) \ 12) \ 4 + 275 * m\ 9 + d - 730531.5 + h / 24
'
' define some arc cos and arc sin functions and a modified inverse
' tangent function
'
DEF FNacos (x)
s = SQR(1 - x * x)
FNacos = ATN(s / x)
END DEF
DEF FNasin (x)
c = SQR(1 - x * x)
FNasin = ATN(x / c)
END DEF
'
' the atn2 function below returns an angle in the range 0 to two pi
' depending on the signs of x and y.
'
DEF FNatn2 (y, x)
a = ATN(y / x)
IF x < 0 THEN a = a + pi
IF (y < 0) AND (x > 0) THEN a = a + tpi
FNatn2 = a
END DEF
'
' the function below returns the true integer part,
' even for negative numbers
'
DEF FNipart (x) = SGN(x) * INT(ABS(x))
'
' the function below returns an angle in the range
' 0 to two pi
'
DEF FNrange (x)
b = x / tpi
a = tpi * (b - FNipart(b))
IF a < 0 THEN a = tpi + a
FNrange = a
END DEF
'
' Find the ecliptic longitude of the Sun
'
DEF FNsun (d)
'
' mean longitude of the Sun
'
L = FNrange(280.461 * rads + .9856474# * rads * d)
'
' mean anomaly of the Sun
'
g = FNrange(357.528 * rads + .9856003# * rads * d)
'
' Ecliptic longitude of the Sun
'
FNsun = FNrange(L + 1.915 * rads * SIN(g) + .02 * rads * SIN(2 * g))
'
' Ecliptic latitude is assumed to be zero by definition
'
END DEF
'
'
'
CLS
'
' get the date and time from the user
'
INPUT " year : ", y
INPUT " month : ", m
INPUT " day : ", day
INPUT "hour UT : ", h
INPUT " minute : ", mins
INPUT " lat : ", glat
INPUT " long : ", glong
glat = glat * rads
glong = glong * rads
h = h + mins / 60
d = FNday(y, m, day, h)
'
' Use FNsun to find the ecliptic longitude of the
' Sun
'
lambda = FNsun(d)
'
' Obliquity of the ecliptic
'
obliq = 23.439 * rads - .0000004# * rads * d
'
' Find the RA and DEC of the Sun
'
alpha = FNatn2(COS(obliq) * SIN(lambda), COS(lambda))
delta = FNasin(SIN(obliq) * SIN(lambda))
'
' Find the Earth - Sun distance
'
r = 1.00014 - .01671 * COS(g) - .00014 * COS(2 * g)
'
' Find the Equation of Time
'
equation = (L - alpha) * degs * 4
'
' find the Alt and Az of the Sun for a given position
' on Earth
'
' hour angle of Sun
LMST = FNrange((280.46061837# + 360.98564736629# * d) * rads + glong)
hasun = FNrange(LMST - alpha)
'
' conversion from hour angle and dec to Alt Az
sinalt = SIN(delta) * SIN(glat) + COS(delta) * COS(glat) * COS(hasun)
altsun = FNasin(sinalt)
y = -COS(delta) * COS(glat) * SIN(hasun)
x = SIN(delta) - SIN(glat) * sinalt
azsun = FNatn2(y, x)
'
' print results in decimal form
'
PRINT
PRINT "Position of Sun"
PRINT "==============="
PRINT
PRINT USING pr2$; " days : "; d
PRINT USING pr1$; "longitude : "; lambda * degs
PRINT USING pr3$; " RA : "; alpha * degs / 15
PRINT USING pr1$; " DEC : "; delta * degs
PRINT USING pr2$; " distance : "; r
PRINT USING pr1$; " eq time : "; equation
PRINT USING pr1$; " LST : "; FNrange(LMST) * degs
PRINT USING pr1$; " azimuth : "; azsun * degs
PRINT USING pr1$; " altitude : "; altsun * degs
END
'*********************************************************
Poooh
pm Member
 
Posts: 4
Joined: Jun 29, 2004 @ 8:28pm
Location: Russia


Postby redshift » Jun 29, 2004 @ 9:45pm

Not tested because i'm not fan of console mode in PPL.
But basically translated in ppl language, you have to create a visual form to handle the value in a more user friendly way.

//*********************************************************
// This program will calculate the position of the Sun
// using a low precision method found on page C24 of the
// 1996 Astronomical Almanac.
//
// The method is good to 0.01 degrees in the sky over the
// period 1950 to 2050.
//
// QBASIC program by Keith Burnett (kburnett@geocity.com)
// PPL code level Translated by Vasanne Eric :-)
//
// Work in double precision and define some constants
//


DEF DBL A-Z <-- Is that the main function name ???

pr1$ = "\ \#####.##";
pr2$ = "\ \#####.#####";
pr3$ = "\ \#####.###";
pi$ = 4 * ATAN(1);
tpi$ = 2 * pi$;
twopi$ = tpi$;
degs$ = (180 / pi$);
rads$ = (pi$ / 180);

// Get the days to J2000
// h$ is UT in decimal hours
// FNday only works between 1901 to 2099 - see Meeus chapter 7


Func FNday (y$, m$, d$, h$)
FNday$ = 367 * y$ - 7 * (y$ + (m$ + 9) \ 12) \ 4 + 275 * m$\ 9 + d$ - 730531.5 + h$ / 24;
Return(FNday$);
END;

// define some arc cos and arc sin functions and a modified inverse
// tangent function

// ACOS already exist in PPL so you could simplify the program
func FNacos (x$)
s$ = SQRT(1 - x$ * x$);
FNacos$ = ATAN(s$ / x$);
Return(FNacos$);
END;


// ASIN already exist in PPL so you could simplify the program
func FNasin (x$)
c$ = SQRT(1 - x$ * x$);
FNasin$ = ATAN(x$ / c$);
Return(FNasin$);
END;

// the atn2 function below returns an angle in the range 0 to two pi
// depending on the signs of x and y.
//

// ATN2 already exist in PPL so you could simplify the program
func FNatn2 (y$, x$)
a$ = ATAN(y$ / x$);
IF (x$ < 0)
a$ = a$ + pi$;
end;
IF (y$ < 0) AND (x$ > 0)
a$ = a$ + tpi$;
end;
FNatn2$ = a$
Return(FNatn2$);
END;

// the function below returns the true integer part,
// even for negative numbers

// Any help there what SGN does it mean ??

Func FNipart (x$)
x$ = SGN(x) * INT(ABS(x$));
Return(x$);
end;


// the function below returns an angle in the range
// 0 to two pi

Func FNrange (x$)
b$ = x$ / tpi$;
a$ = tpi$ * (b$ - FNipart(b$));
IF a$ < 0 THEN a$ = tpi$ + a$;
FNrange$ = a$;
Return(FNrange$);
END;

//
// Find the ecliptic longitude of the Sun
//

Func FNsun (d$)
// mean longitude of the Sun
L$ = FNrange(280.461 * rads$ + .9856474# * rads$ * d$);
// mean anomaly of the Sun
g$ = FNrange(357.528 * rads$ + .9856003# * rads$ * d$)
// Ecliptic longitude of the Sun
FNsun$ = FNrange(L$ + 1.915 * rads * SIN(g$) + .02 * rads$ * SIN(2 * g$));
// Ecliptic latitude is assumed to be zero by definition
Return(FNsun$);
END;

CLS

// get the date and time from the user
// For this i suggest you to create a visual form, it's easier so you can use text$ = GetText(editbox);
//eg: y$ = GetText(EDIT10$);
//Don't forget you can rename the controlvariable name in the visual form builder

INPUT " year : ", y$;
INPUT " month : ", m$;
INPUT " day : ", day$;
INPUT "hour UT : ", h$;
INPUT " minute : ", mins$;
INPUT " lat : ", glat$;
INPUT " long : ", glong$;


glat$ = glat$ * rads$;
glong$ = glong$ * rads$;
h$ = h$ + mins$ / 60;
d$ = FNday(y$, m$, day$, h$);

// Use FNsun to find the ecliptic longitude of the
// Sun

lambda$ = FNsun(d$);

// Obliquity of the ecliptic

obliq$ = 23.439 * rads$ - .0000004# * rads$ * d$;

// Find the RA and DEC of the Sun

alpha$ = FNatn2(COS(obliq$) * SIN(lambda$), COS(lambda$));
delta$ = FNasin(SIN(obliq$) * SIN(lambda$));

// Find the Earth - Sun distance

r$ = 1.00014 - .01671 * COS(g$) - .00014 * COS(2 * g$);

// Find the Equation of Time

equation$ = (L$ - alpha$) * degs$ * 4;

// find the Alt and Az of the Sun for a given position
// on Earth

// hour angle of Sun
LMST$ = FNrange((280.46061837# + 360.98564736629# * d$) * rads$ + glong$);
hasun$ = FNrange(LMST$ - alpha$);

// conversion from hour angle and dec to Alt Az
sinalt$ = SIN(delta$) * SIN(glat$) + COS(delta$) * COS(glat$) * COS(hasun$);
altsun$ = FNasin(sinalt$);
y$ = -COS(delta$) * COS(glat$) * SIN(hasun$);
x$ = SIN(delta$) - SIN(glat$) * sinalt$;
azsun$ = FNatn2(y$, x$);


// print results in decimal form
// Here also i suggest you to use the visual form builder so ou can easely manage the screen
// eg: SetText(MEMO10$,textoset$);
sunpos$ = "\n Position of Sun \n";
SetText(MEMO10$,sunpos$);

PRINT USING pr2$; " days : "; d
PRINT USING pr1$; "longitude : "; lambda$ * degs$
PRINT USING pr3$; " RA : "; alpha$ * degs$ / 15
PRINT USING pr1$; " DEC : "; delta$ * degs$
PRINT USING pr2$; " distance : "; r$
PRINT USING pr1$; " eq time : "; equation$
PRINT USING pr1$; " LST : "; FNrange(LMST$) * degs$
PRINT USING pr1$; " azimuth : "; azsun$ * degs$
PRINT USING pr1$; " altitude : "; altsun$ * degs$


END;

This is a basic code and function translation, the code won't work like that even build, you have to use the modified part of the code in a new application that you create in the visual builder, but at least this will help you !
For the compass, i suggest you to use the Game API or the visual builder and bitmaps.
redshift
pm Member
 
Posts: 52
Joined: Jun 9, 2004 @ 9:52pm


Help, please, me to create the visual form

Postby Poooh » Jun 29, 2004 @ 9:58pm

Help, please, me to create the visual form to handle the value in more friend ways. Excuse me for my bad english - I from Russia...
Poooh
pm Member
 
Posts: 4
Joined: Jun 29, 2004 @ 8:28pm
Location: Russia


Postby redshift » Jun 29, 2004 @ 10:31pm

I can give you the keys, the method, the car, the licence, the road, but you have to fill it with fuel , start the engine, and press the accelerator at least :-)

http://ppl.arwen.com/Tutorials/

For the latest tutorial Visual PPL for Dummies, take this one, updated from the one on the website.

http://etxredshift.cjb.net/testing/PPLF ... PPL0.6.pdf

Best regards,

Kornalius, can you update your plone with this one if you read this thread ;-)
redshift
pm Member
 
Posts: 52
Joined: Jun 9, 2004 @ 9:52pm


Postby kornalius » Jun 30, 2004 @ 12:47am

I too, suggest that you read through the PPL help file that is provided with the PIDE. Read through the PPL syntax section first then go down the list.

PPL is very similar to C and is not far from BASIC or PASCAL.

Regards,
Kornalius
User avatar
kornalius
pm Member
 
Posts: 1704
Joined: Dec 9, 2003 @ 6:04pm
Location: Montreal, Québec, Canada


Return to Pocket Programming Language (PPL)


Sort


Forum Description

Discuss this new development tool.

Moderator:

kornalius

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron