Put, Get, Data Matrix

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
wilnav
Posts: 3
Joined: Wed Mar 27, 2019 1:47 am

Put, Get, Data Matrix

Post by wilnav »

Pica and Thomas Okken in two discussions show the ideas below
are common knowledge to many. The discussions are:

Constants
viewtopic.php?f=19&t=271

Converting 3D vector to Cartesian triplet x,y,z
viewtopic.php?f=15&t=1966

NOTE: EXITing or EXITALL from the INDEX function does not clear IJ.
When accessing any of the ← functions, values of the matrix appear.
I noticed that Pica used EDIT and INDEXEd the matrix in one of his
programs. Perhaps he is aware of this feature.

To experience this, INDEX a matrix. EXIT then access the MATRIX
menu and RCLIJ. The last values are still there. EXITALL has no
effect. If the Matrix is EDITed and EXITed RCLIJ returns NONEXISTANT.

In general this may not ever be a problem. Still caution maybe
advised when using the INDEX function.

From the HP 42s Users Manual:

Because matrices can be used to hold large amounts of
data, it's recommended that you store copies of matrices
(and other important data) into variables and then recall
the data as it's needed. This saves you the trouble of
keying the data in again if you inadvertently lose the matrix off
the top of the stack during other calculations or
while editing another matrix

Program "put"

This program gets m1 a [1x4] vector. Puts new coordinate values
in the vector [N E eL Note] and stores them in Matrix "M 1"

The program uses ← rather than STOEL

To use this program create a [1x4] matrix named "m1". Create a [4x4]
matrix "M 1". Any number of points N can be specified by [Nx4], to
the limit of DM 42 memory.

Input program and run.


01▶LBL "put"
02 CLST
03 × @Clears Stack and Lastx

04 "E^N^L R/S"
05 PROMPT @Asks for East Coord ENT North Coord ENT eLevation RUN

06 "Note?"
07 AON
08 STOP @Asks for point description
09 ASTO ST L @Stores in Lastx

10 RCL "m1"
11 EDIT @Edit 1x4 matrix m1
12 ← @Positions index at 1,4 (column 4)

13 R↓ @ROLL DOWN to Position E^N^L values on stack

14 LASTX @Puts description at column 4 (1,4)

15 ←
16 R↓ @Puts eLevation at column 3 (1,3)

17 ←
18 R↓ @Puts North Coord at column 2 (1,2)

19 ←
20 R↓ @Puts East Coord at colunm 1 (1,1)

21 EXITALL @m1 is complete with E,N,L and Description

22 "Pt#" @Index to PUTM submatrix m1 in "M 1"
23 PROMPT
24 1
25 INDEX "M 1"
26 STOIJ @Index of "M 1" is a (5,1) for this example

27 RCL ST Z @RCLs m1
28 PUTM @STOs m1 as a sub matrix in Matrix "M 1"
@at location Pt# (I) and 1 (J)
29 CLST
30 END @Clears stack display

Contents of "M 1" Matrix

M 1= [ 5x4 Matrix ]
1:1= 480.3448 @EASTING
1:2= 516.5265 @NORTHING
1:3= 1,558.9512 @eLevation
1:4= "a=40" @NOTE
2:1= 480.3779
2:2= 485.9857
2:3= 1,558.6645
2:4= "b=41"
3:1= 506.1492
3:2= 485.9040
3:3= 1,558.6544
3:4= "c=42"
4:1= 506.1211
4:2= 516.6897
4:3= 1,558.9460
4:4= "d=43"
5:1= 300.0000
5:2= 100.0000
5:3= 5.0000
5:4= "Test"

________________________________________________________________________

The get prgrm takes two points stored by put in matrix "M 1" and
computes the distance and direction (a→b). Because points are
accessed randomly, the pointer IJ is used. GETM is used to extract
the submatrix. I hope this maybe useful.

01▶LBL "get"

02 "a→b"
03 PROMPT @From "Point a" → (to) "Point b"

04 INDEX "M 1"
05 X<>Y @Exchanges b for a. Pt a now Stack X
06 4
07 STOIJ @Sets Index at Pt a and 4 (a,4)

08 R↓
09 R↓ @a in X and b in Y

10 RCLEL @Gets description of First point
11 CLA @Clears Alpha reg
12 ARCL ST X @Put description in Alpha reg
13 ├" → " @Appends → ( to point b)

14 R↓
15 RCLIJ @RCL pointer values
16 R↓
17 1 @Positons Index at (pt a,2)
18 STOIJ

19 2
20 GETM @gets 1x2 submatrix. Pt a [Easting Northing]

21 R^ @point b to Stack X
22 4 @Positions index
23 STOIJ @to (pt b,4). Description for point B

24 R↓
25 R↓ @Puts matrix b in Stack X

26 RCLEL @Gets Description
27 ├"" @Appends
28 ARCL ST X @Description
29 ├" " @Appends a space

30 R↓ @Drops Description
31 RCLIJ @Recalls index M 1 matrix
32 R↓
33 1
34 STOIJ @Sets index to beginning of row

35 2 @Defines [1x2] matrix/vector Pt b
36 GETM

37 R^ @Puts Pt a [1x2] Matrix Stack X
38 - @Diff Matrix in Stack Y and X

39 EDIT @Puts diff in Easting and Northing
40 ENTER @In Stack Y and X
41 →
42 ENTER
43 EXITALL
@The rest computes North Azimuth and Bearings for
direction and formats data for display in Alpha
register. The are severe limits as to what can be
shown at one time in the Alpha reg.

Here is an example.
a = point 1 and b = point 2
a→b PROMPT
1 ENTER 2 R/S yields:

a=40 → b=41 Az179.5616
SE 0.0344 HD30.5408



44 R↓
45 →POL
46 RCL ST Y
47 360
48 MOD
49 →HMS
50 ├"Az"
51 ARCL ST X
52 ├"␊"
53 R^
54 X≥0?
55 GTO 02
56 +/-
57 90
58 X≥Y?
59 GTO 04
60 RCL+ ST X
61 X<>Y
62 -
63 ├"SW"
64 GTO 05
65▶LBL 04
66 ├"NW"
67 R↓
68 GTO 05
69▶LBL 02
70 90
71 X≥Y?
72 GTO 01
73 STO+ ST X
74 X<>Y
75 -
76 ├"SE"
77 GTO 05
78▶LBL 01
79 "NE"
80 R↓
81▶LBL 05
82 →HMS
83 ├" "
84 ARCL ST X
85 ├" HD"
86 ARCL ST Z
87 AVIEW
88 END
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: Put, Get, Data Matrix

Post by Thomas Okken »

wilnav wrote:
Sun Apr 21, 2019 6:47 am
NOTE: EXITing or EXITALL from the INDEX function does not clear IJ.
When accessing any of the ← functions, values of the matrix appear.
I noticed that Pica used EDIT and INDEXEd the matrix in one of his
programs. Perhaps he is aware of this feature.

To experience this, INDEX a matrix. EXIT then access the MATRIX
menu and RCLIJ. The last values are still there. EXITALL has no
effect. If the Matrix is EDITed and EXITed RCLIJ returns NONEXISTANT.

In general this may not ever be a problem. Still caution maybe
advised when using the INDEX function.
The matrix element pointers, IJ, are used by EDIT, EDITN, and INDEX, and they are valid while any of those three modes are active. When not valid, RCLIJ returns Nonexistent.

The behavior you observed is due to the fact that unlike EDIT and EDITN, INDEX is just a function, and does not correspond to a mode within the menu hierarchy. When you use EXIT while in EDIT or EDITN mode, the Matrix Editor exits, and EDIT or EDITN mode ends. On INDEX, on the other hand, EXIT has no effect. There is no "un-index" command, although you can achieve pretty much the same effect by creating a matrix, indexing it, and then deleting it.
wilnav
Posts: 3
Joined: Wed Mar 27, 2019 1:47 am

Re: Put, Get, Data Matrix

Post by wilnav »

Thank you. That explains it very well.
Post Reply