TSD rallying with a programmable calculator

All programmable calculators support the BASIC language (albeit in different flavours). It is trivial to implement TSD functionality in BASIC. Below is the listing of a rudimentary program that calculates ideal times for a given speed chart (test it here):

 010 CLEAR
 020 INPUT "Total speed zones: "; N
 030 DIM BE(N)
 040 DIM EN(N)
 050 DIM SP(N)
 060 BE(0) = 0
 070 FOR I = 0 TO N - 1
 080 PRINT (I + 1); " of "; N
 090 PRINT "Begin (KM): "; BE(I) / 1000
 100 INPUT "End (KM): "; EN(I)
 110 INPUT "Speed (KMPH): "; SP(I)
 120 SP(I) = SP(I) * 1000
 130 EN(I) = EN(I) * 1000
 140 IF I < N - 1 THEN BE(I + 1) = EN(I) 
 150 NEXT 
 160 INPUT "Start time at TC (HH): "; HH 
 170 INPUT "Start time at TC (MM): "; MM 
 180 INPUT "Start time at TC (SS): "; SS 
 190 INPUT "ODO reading at TC (KM): "; KM 
 200 KM = KM * 1000 
 210 INPUT "Distance (KM, 0 for TC): "; D 
 220 IF D = 0 THEN GOTO 160 
 230 D = D * 1000 
 240 SECS = 0 
 250 PRSD = 0 
 260 PART = 1 
 270 J = 0 
 280 GOTO 370 
 290 PART = 0 
 300 GOTO 440 
 310 DT = EN(I) - KM 
 320 PART = 1 
 330 GOTO 420 
 340 SECS = SECS + (DT / SP(I)) 
 350 PRSD = PRSD + DT 
 360 GOTO 440 
 370 FOR I = 0 TO N - 1 
 380 J = I 
 390 DT = EN(I) - BE(I) 
 400 IF KM >= EN(I) THEN GOTO 290
 410 IF PART = 0 THEN GOTO 310
 420 IF D > EN(I) THEN GOTO 340
 430 GOTO 450
 440 NEXT
 450 SECS = SECS + ((D - KM - PRSD) / SP(J))
 460 SECS = SECS * 3600 + HH * 3600 + MM * 60 + SS
 470 H = INT(SECS / 3600)
 480 M = INT((SECS - H * 3600) / 60)
 490 S = INT(SECS - H * 3600 - M * 60)
 500 IF H >= 24 THEN H = H - 24
 510 PRINT "Time: "; H; ":"; M; ":"; S
 520 GOTO 210
 530 END

It is left to the reader to do input validation, handle boundary conditions, optimize, make it more user friendly, port to target device etc.


One Response to TSD rallying with a programmable calculator

  1. It is very useful, thanks……….

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>