QPTR

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
jfb9301
Posts: 21
Joined: Mon Dec 11, 2017 12:33 am

QPTR

Post by jfb9301 »

I'm currently writing a program to allow me to quickly determine a tilt ratio for a (let's just call it a heat exchanger".

The detectors output current in micro amps. To compensate for detector differences, each detector is multiplied by a correction factor to normalize the channel. The sum is calculated and then averaged. Each quadrant is then divided by the average to normalize it to the average power of each sector. This way a sector that is generating more heat can be determined. The detectors for the quadrants are N41, N42, N43 and N44. and all numbers are to be calculated to 4 decimal places.

I have not written code for a HP calculator in years, even though I'm a longtime HP user. I am rather OCD about code optimization, probably due to the memory constraints of the calculators I initially learned to code on. The program I have written is rather brute force rather than elegant, and just sequentially solves my problem. Maybe one of you will be willing to take a look and see where I can trim code. Most especially I think there might be a way to use increment/decrement with the repetitive variables.

Code: Select all

00 { 299-Byte Prgm }
01▸LBL "QPTR"
02 FIX 04
03 INPUT "N41" @ 03-06 Input N41 to N44 Detector Current
04 INPUT "N42"
05 INPUT "N43"
06 INPUT "N44"
07 INPUT "C41" @ 07-10 Input N41 to N44 Correction Factors
08 INPUT "C42"
09 INPUT "C43"
10 INPUT "C44"
11 RCL "N41" @ 11-22 Calculate Current x Correction Factor
12 RCL× "C41"
13 STO "N41C"
14 RCL "N42"
15 RCL× "C42"
16 STO "N42C"
17 RCL "N43"
18 RCL× "C43"
19 STO "N43C"
20 RCL "N44"
21 RCL× "C44"
22 STO "N44C"
23 RCL "N41C" @ 23-30 Sum and Ave Corrected Detector currents
24 RCL+ "N42C"
25 RCL+ "N43C"
26 RCL+ "N44C"
27 STO "Total"
28 4
29 ÷
30 STO "Ave"
31 CLLCD
32 RCL "N41C" @ 32-47 Divide Corrected Detector Current by Ave Det Cur
33 RCL÷ "Ave" @ Round to 4 decimal places due to earlier FIX 4
34 RND
35 STO "Q41"
36 RCL "N42C"
37 RCL÷ "Ave"
38 RND
39 STO "Q42"
40 RCL "N43C"
41 RCL÷ "Ave"
42 RND
43 STO "Q43"
44 RCL "N44C"
45 RCL÷ "Ave"
46 RND
47 STO "Q44"
48 VIEW "N41C" @ 48-67 Display results using GETKEY to pause the
49 GETKEY @ program to allow a chance to record results
50 VIEW "N42C"
51 GETKEY
52 VIEW "N43C"
53 GETKEY
54 VIEW "N44C"
55 GETKEY
56 VIEW "Total"
57 GETKEY
58 VIEW "Ave"
59 GETKEY
60 VIEW "Q41"
61 GETKEY
62 VIEW "Q42"
63 GETKEY
64 VIEW "Q43"
65 GETKEY
66 VIEW "Q44"
67 GETKEY
68 END
Attachments
qptr.zip
(279 Bytes) Downloaded 219 times
jfb9301
Posts: 21
Joined: Mon Dec 11, 2017 12:33 am

Re: QPTR

Post by jfb9301 »

I already spotted an error, there is no RND after line 29,

I played with the code and found a way to make it more elegant, but I don't think I saved anything.

Code: Select all

00 { 294-Byte Prgm }
01▸LBL "QPTR"
02 FIX 04
03 INPUT "N41" @ 03-06 Input N41 to N44 Detector Current
04 INPUT "N42"
05 INPUT "N43"
06 INPUT "N44"
07 INPUT "C41" @ 07-10 Input N41 to N44 Correction Factors
08 INPUT "C42"
09 INPUT "C43"
10 INPUT "C44"
11 RCL "N41" @ 11-22 Calculate Current x Correction Factor
12 RCL× "C41"
13 STO "N41C"
14 RCL "N42"
15 RCL× "C42"
16 STO "N42C"
17 RCL "N43"
18 RCL× "C43"
19 STO "N43C"
20 RCL "N44"
21 RCL× "C44"
22 STO "N44C"
23 RCL+ "N41C" @ 23-30 Sum and Ave Corrected Detector currents
24 RCL+ "N42C"
25 RCL+ "N43C"
26 STO "Total"
27 4
28 ÷
29 RND
30 STO "Ave"
31 CLLCD
32 RCL "N41C" @ 32-47 Divide Corrected Detector Current by Ave Det Cur
33 RCL÷ "Ave" @ Round to 4 decimal places due to earlier FIX 4
34 RND
35 STO "Q41"
36 RCL "N42C"
37 RCL÷ "Ave"
38 RND
39 STO "Q42"
40 RCL "N43C"
41 RCL÷ "Ave"
42 RND
43 STO "Q43"
44 RCL "N44C"
45 RCL÷ "Ave"
46 RND
47 STO "Q44"
48 VIEW "N41C" @ 48-67 Display results using GETKEY to pause the
49 GETKEY @ program to allow a chance to record results
50 VIEW "N42C"
51 GETKEY
52 VIEW "N43C"
53 GETKEY
54 VIEW "N44C"
55 GETKEY
56 VIEW "Total"
57 GETKEY
58 VIEW "Ave"
59 GETKEY
60 VIEW "Q41"
61 GETKEY
62 VIEW "Q42"
63 GETKEY
64 VIEW "Q43"
65 GETKEY
66 VIEW "Q44"
67 GETKEY
68 END
5 bytes is hardly optimization
Post Reply