The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

Loops in Prime
Message #1 Posted by Geoff Quickfall on 2 Oct 2013, 3:16 a.m.

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
Message #2 Posted by Joe Horn on 2 Oct 2013, 3:41 a.m.,
in response to message #1 by Geoff Quickfall

> 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
Message #3 Posted by Geoff Quickfall on 2 Oct 2013, 3:50 a.m.,
in response to message #2 by Joe Horn

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
Message #4 Posted by Dieter on 2 Oct 2013, 7:26 a.m.,
in response to message #1 by Geoff Quickfall

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
Message #5 Posted by Geoff Quickfall on 2 Oct 2013, 10:45 a.m.,
in response to message #4 by Dieter

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.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall