HP Forums
Loops in Prime - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: Loops in Prime (/thread-251956.html)



Loops in Prime - Geoff Quickfall - 10-02-2013

hello,

As a newbie here a couple of questions. I am developing a program to create corrected altitudes for barometric altimeters when the out side air temperature is less then 0'C.

EXPORT Corr_Temp(a_tmp, a_alt, f_alt)

BEGIN

HFormat:=1;
HDigits:=0;
HAngle:=1;

T:=a_tmp+.00198*a_alt;
C:=f_alt*(15-T)/(273+T-.5*.00198*(f_alt-a_alt));
F:=f_alt+C;
F:=10*ROUND(F/10);

MSGBOX("Corr Fix Alt = " +F);

END;

above is the code, rather simple and without a loop. You will notice the variables:

a_tmp
a_alt
f_alt

As you can see the program prompts for 3 variables. At the moment the program will only solve for a single f_alt at a time. What I would like to do is actually prompt for a total of five variables, the last three listed below will replace the f_alt single variable:

FAF
MDA
MAP

I can easily prompt for these variables by adding them to the Export section as follows:

EXPORT Corr_Temp(a_tmp,a_alt,FAF,MDA,MAP)

I would now like the routine to loop three times calling the old FAF and displaying the new FAF then calling the old MDA and then displaying the new MDA and finally calling the old MAP and then displaying the new MDA.

The output to be formatted like after the three loops are done:

Corrected FAF: xxxx
Corrected MDA: yyyy
Corrected MAP: zzzz

I know I need a 'for' loop command and have an idea for a local variable in the 'for' loop and a local variable for the new FAF,MDA,MAP.

So I would call FAF and store it in a local variable 'f' then run the routine, display the new FAF as above then at the end store the MDA in f and rerun the routine, displaying the new MDA then call and store MAP in f and run again.

Hope I have explained the problem. Any takers, as I am going to run this through my brain and try to solve it. Maybe someone can beat me to it!

oh yes, the other question. I have read that you can create your own apps based on your programs, and as Joe just posted, move apps to the front of the list. Can you change the icon for the app? I know how to create the app but not how to change the icon.

Cheers, Geoff


Edited: 2 Oct 2013, 11:37 a.m. after one or more responses were posted


Re: Loops in Prime - Joe Horn - 10-02-2013

> Can you change the icon for the app?

For now, you have to use one of the already-existing icons. Whether a future firmware version will allow custom icons, or whether external development tools will be created for such things, remains to be seen. I'm keeping my fingers crossed!


Re: Loops in Prime - Geoff Quickfall - 10-02-2013

Joe, You are still up!!

That's what I read but I was hoping my manual was an older version!

Cheers


Re: Loops in Prime - Dieter - 10-02-2013

What you want to do can be easily accomplished with an array. Since I do not have a Prime at hand, here's a solution in Visual Basic:

Function Corr_Temp(a_tmp, a_alt, FAF, MDA, MAP)
 
Dim ff(3), Message(3)
 
ff(1) = FAF
ff(2) = MDA
ff(3) = MAP
 
Message(1) = "Corrected FAF = "
Message(2) = "Corrected MDA = "
Message(3) = "Corrected MAP = "
 
For i = 1 To 3
f_alt = ff(i)
T = a_tmp + 0.00198 * a_alt
C = f_alt * (15 - T) / (273 + T - 0.5 * 0.00198 * (f_alt - a_alt))
f = f_alt + C
f = 10 * Round(f / 10, 0)
MsgBox Message(i) + Str$(f)
Next
 
End Function

Another (IMHO more elegant) option is a separate calculation function that is called three times:

Function Corr_Temp(a_tmp, a_alt, FAF, MDA, MAP)
x = Calculation(a_tmp, a_alt, FAF)
MsgBox "Corrected FAF = " + x
x = Calculation(a_tmp, a_alt, MDA)
MsgBox "Corrected MDA = " + x
x = Calculation(a_tmp, a_alt, MAP)
MsgBox "Corrected MAP " + x
End Function
 
Function Calculation(a_tmp, a_alt, f_alt)
T = a_tmp + 0.00198 * a_alt
C = f_alt * (15 - T) / (273 + T - 0.5 * 0.00198 * (f_alt - a_alt))
F = f_alt + C
F = 10 * Round(F / 10, 0)
Calculation = Str$(F)
End Function
Quote:
Hope I have explained the problem. Any takers, as I am going to run this through my brain and try to solve it. Maybe someone can beat me to it!

I hope so. ;-)

Dieter


Re: Loops in Prime - Geoff Quickfall - 10-02-2013

Thanks Dieter!

That's looks similar to tsolution on my 71b and completely forgot to check it!

I will convert the first one into equivalent Prime code as soon as I read up on matrices.

Cheers, Geoff

Edited: 2 Oct 2013, 10:47 a.m.