I am trying to sort node IDs by position. I created 2D REAL array where 1st column is node ID and second is position. Next I use mth_sort_column to sort by position column. However, it does not produce expected result. The first problem is that I cannot convert correctly INTEGER into REAL number:
example:
REAL a
INTEGER b
b=31100069
a=b
dump a, b
The result is:
$# REAL a = 31100068.
$# INTEGER b = 31100069
How to explain change of the value? How to make conversion correctly? Do I have to write my own sorting function?
You have a bit of a problem trying to use 8 digit integers as a real with PCL because PCL is pretty much single precision. The language dates from the early 80's and has some limitations. To quote from the internet: "All integers with 7 or fewer decimal digits, and any 2n for a whole number −149 ≤ n ≤ 127, can be converted exactly into an IEEE 754 single-precision floating-point value." 31100069 has one too many digits to work exactly.
If the model has less than 10 000 000 nodes then you can use a lookup reference to the node id to do the sort.
(Assuming you can't just renumber all the nodes.)
Easier to explain with an example:
note the example writes out the sorted nodes so you may not want to run this except on a small test model with big node ids. There may be better ways of doing it but this is what sprang to mind.
At the time I was thinking of transposing and using sys_move_raw and sys_reallocate_array to give space for the index but decided it would not gain anything. There are times when the underlying array row storage architecture(aka C) is not as convenient as column format (aka Fortran) when wanting to resize arrays, and of course times when it's great.