setting up subroutines that are called many times...



#6

HPPL PRIME:

Hello all, still working on the programming which when I get the code right is fantastic.

I must admit that I have very crude programming abilities at the moment but here goes:

I have the following dilema, I need to create a subroutine, easy in Basic and RPN with label, xeq and gto commands but I am having problems with the HPPL.

In essence I am creating a break schedule program that takes the following variables:

EXPORT OFF,ONA,ONB,IN,OUT,NUM,EQL;

OFF the GMT takeoff (wheels up time) of the aircraft.
ONA the GMT landing (wheels down time).
ONB the scratch pad for a corrected wheels landing time;
actually the landing time if the landing time is less
then the OFF time, ie the flight goes through midnight.
IN the time returning to the flight deck before landing.
OUT the time leaving the flight deck after takeoff.
NUM number of breaks.
EQL the time if all breaks are equal.

So the break schedule follows:

the input functions prompt for OFF, ON, IN, OUT, NUM.


// the next line tests for takeoff time greater then landing time
// and corrects that by adding 24 hours to ONB. This is so total
// time for breaks can be calculated.
// the reason for ONA versus ONB as ONA must remain untouched for
// display purposes at the end of the program.

IF OFF>ONA THEN ONB:=ONA+24 ELSE ONB:=ONA

Now that little routine is used every time a time period is added to a time period making it a perfect subroutine. This is because any additional time period may traverse 24 hours.

My problem is how do I set up a subroutine which is called multiple times. As I am typing I see that it could be a program that is called for each calculation but how is a subroutine within a created APP done.

Still reading and trying but lazy me, any help would be appreciated.

Looking for SYNTAX something like:

ROUTINE X
IF OFF>ONA THEN ONB:=ONA + 24 ELSE ONB:=ONA
RETURN

Cheers, Geoff


#7

How about declaring a function with OFF and ONA as arguments, returning a value which is assigned to ONB? Something like

ONB := FIXUP(OFF, ONA),

with your "if..." code line making up the body of the function?

Disclaimer: I don't actually have a Prime!

Nigel (UK)


#8

Quote:
How about declaring a function with OFF and ONA as arguments, returning a value which is assigned to ONB? Something like

ONB := FIXUP(OFF, ONA),

with your "if..." code line making up the body of the function?

Disclaimer: I don't actually have a Prime!

Nigel (UK)


You would still need to create either a program or subroutine called FIXUP and also ensure that OFF and ONA are properly declared (local vs global).

Let's say that our program is called SCHEDULE. Now, SCHEDULE may actually consist of a bunch of subroutines: SUBR1, SUBR2, SUBR3, etc. Your SCHEDULE source file should look something like:

// subprogram declarations
SUBR1(); // add EXPORT in front if you want to use these programs as standalone
SUBR2(); // or use the subprograms within other programs residing in a different
SUBR3(); // program source file
... more subprogram declarations ...

// global vars. declarations
EXPORT OFF; // leave off EXPORT if you want them "hidden" from the user
EXPORT ONA;
... more gobal variable declarations

EXPORT SCHEDULE()
BEGIN
... source code for schedule here ...
END;

SUBR1() // add EXPORT in front to make this visible to users and/or other programs
BEGIN
... source code for subroutine 1 here...
END;

SUBR2()
BEGIN
... source code for subroutine 2 here...
END

... and so on...

Hope that helps. In a sense, it is very similar to C. Normally we have a .h file in C where we store all the function declarations (as well as global variable declarations) and use an include blah.h in the actual C source file at the top. The difference is the the HP Prime does not use include files so we just declare them at the top of the source file. Then, the actual source code of the main program and its subroutines are placed below.

Edited: 17 Oct 2013, 7:30 a.m.


#9

Han,

Yes, I see many similarities to basic BASIC! Thanks for the syntax on the subroutines. I will give them a try. Exporting the >24 hour subroutine makes sense as I have this as a global on all my machines..

It's just getting a working handle in the language and that comes with practice.

Nigel,

Thanks for the input, get a prime!!!

In RPN for the 42S the subroutine is labelled LBL '24H":

LBL 24H
HMS+
24
X>Y?
CLX
HMS-
RTN

In basic the intitial test for the second time having past through 24hr GMT is as follows:

10  .......
20 IF OFF>ONA THEN ON‌B=ONA+24 ELSE ON‌B=ONA
30 .......

very similar.

Now as a subroutine I would want to test for any additional additive for passing through 24hr GMT with the following and in Basic this would be:

!    PREVIOUS LINES PART OF CALCULATION RESULTING IN THE NEXT LINE
! WHICH ADDS A PREVIOUS TIME TO A NEW TIME INTERVAL

110 TI=T1+T2
120 IF T1>24 THEN GOSUB 700 ELSE !LOOP BACK AND DO THE NEXT ADDITION

690 .......
700 IF T1>24 THEN TI=TI-24 ELSE TI RETURN
710 .......

these two examples are called upwards of 6 times depending on the break schedule subroutine run under the program Schedule:

The actual program notes on the prime are:

Break schedules: 
-calculates break periods.

*Initialize:
- prompts for "off and on" times.
these are the airborne and landing times.
- break "out and in" times.
these are the delay and early return
times in minutes after takeoff and
before landing.
- number of breaks.

*equal breaks:
- 2, 4, 6 typically.

*weighted breaks:
- front or back.
allows the front half or rear half of the
breaks to be longer by choice.
- 4 or 6 typically.

*2 short followed by 3 long and short:
- places the sleep period outside the dinner
service.

cheers and thanks for the help.

geoff


Edited: 17 Oct 2013, 2:01 p.m.


#10

Ha! It works, thanks Han!

Still messing with the loops but the subroutines gets called perfectly.

Now for the finite loops.

Geoff


Possibly Related Threads...
Thread Author Replies Views Last Post
  Tutorials #5 (STARTAPP, RGB) and #6 (Subroutines) Are Up Eddie W. Shore 0 115 11-17-2013, 04:23 PM
Last Post: Eddie W. Shore
  HP Prime - Revision Suggestion - Setting the Clock Bill Triplett 5 317 11-15-2013, 12:36 AM
Last Post: Joe Horn
  HP Prime Tip: Setting Up User Keys Eddie W. Shore 2 216 09-27-2013, 09:53 PM
Last Post: Eddie W. Shore
  Los Angeles Times on the HP-12C Peter Murphy (Livermore) 6 280 08-29-2013, 02:18 PM
Last Post: Matt Agajanian
  WP-34S: Subroutines, local registers and hotkeys Marcel Samek 7 348 08-23-2013, 12:08 PM
Last Post: David Hayden
  Little curiosity: why the fourth stack register is called "T"? Antlab 34 1,122 07-03-2013, 04:49 PM
Last Post: Walter B
  Meg Whitman's Toughest Campaign (New York Times) Eric Smith 1 126 09-30-2012, 08:38 AM
Last Post: Jim Johnson
  HP41 barcodes: this one called my attention Luiz C. Vieira (Brazil) 6 285 04-08-2012, 04:04 AM
Last Post: Raymond Wiker
  NY Times article - a school without "technology" Don Shepherd 26 732 10-26-2011, 01:33 PM
Last Post: Dominic Richens
  HP12C Article in the Financial Times Charles 4 202 09-24-2011, 06:54 PM
Last Post: Mark Harman

Forum Jump: