PDA

View Full Version : Oxygen - help on passing multidimensional array to sub...



Oscar Ugolini
15-03-2023, 05:00
Hi all, It's been a while since my last post, I hope you're all doing well.
I have a problem passing a multidimensional array to an oxygen sub... like this

'Oxygen source ( I have last one Version Oxygen and Thinbasic )
''''''''''''''''''''''''''''''''
src="
Sub CalcPoint(addre as long, byref RetV as Single) link #p3

indexbase 1
Dim as Single Pws(4,4,4) at addre ' seem dont work

''''' i make some math on points and return some values '''''
RetV=(my values calculated)
End Sub
"

'Thinbasic source
'''''''''''''''''''''''''''''''''
Dim Pw(4,4,4) as Single
Dim RetV as Single

''''' i put data in this array

ptrv=varptr(Pw(1,1,1))
CalcPoint (ptrv,retV)

----------------------------

With array single-dimensional oxygen sub work, but with multidimensional i can't get it to work...

I hope someone can help me.
Thank you!

Oscar

Charles Pegge
15-03-2023, 09:10
Hi Oscar,
Oxygen fully supports multidimensional arrays, as of December 2022.

I don't know whether the current thinBasic includes this version, so I attach it below.

Oxygen.dll goes into your thinBasic\lib folder.

thinBasic uses indexbase 1 in Column-Major order, in other words the minor steps come first.

#minormajor 'thinBasic and Powerbasic mode
indexbase 1
overlay single v(4,4,4)
@v=#v 'link to host variable v




uses "oxygen"


'SHARED VARIABLES
'================


dim as string src
dim as single v(4,4,4)
'
'OXYGENBASIC SECTION
'===================
src="
#minormajor 'thinBasic and Powerbasic mode
indexbase 1
overlay single v(4,4,4)
@v=#v 'link to host variable v
dim as long c,x,y,z
for z=1 to 4
for y=1 to 4
for x=1 to 4
c++
v(x,y,z)=c 'fill 1 to 64
next
next
next
"


'COMPILE
'=======


o2_basic src
if o2_errno then
msgbox 0,o2_error
stop
else
o2_exec
'msgbox 0,"ok"
end if




'MAIN THINBASIC SECTION
'======================


'array Order: 17 18 19 20
msgbox 0,"Order: "+v(1,1,2)+", "+v(2,1,2)+", "+v(3,1,2)+", "+v(4,1,2)

Oscar Ugolini
15-03-2023, 13:28
Hi Charles,
and thanks for the reply... Your work is amazing ;)

I had already seen the example in your other posts...
I only wanted to know if it is possible to pass a multidimensional array or a pointer to this array as an argument, and "dim" a new multidimensional array inside the oxygen sub that points to array in the argument ...
If it is not possible, in thinbasic using peek and poke I succeed, I will do as you wrote.
Thank you

Oscar

Charles Pegge
16-03-2023, 16:42
Thanks Oscar,

I've developed this example a bit more, and given O2 all the responsibility for creating and managing the array-space. The array-space is only freed when finish() is executed.

You have to be careful about when variables are created on the thinBasic side.





uses "oxygen"


'SHARED VARIABLES
'================


dim as string src
dim as long pCreateArray3d
dim as long pFinish
'
'OXYGENBASIC SECTION
'===================
src="
#minormajor 'thinBasic and Powerbasic mode
indexbase 1
redim single v(0,0,0)


sub CreateArray3d(sys *pv, long x,y,z) link #pCreateArray3d
redim single v(x,y,z)
pv=@v 'link to host variable v
dim as long c,x,y,z
for z=1 to 4
for y=1 to 4
for x=1 to 4
c++
v(x,y,z)=c 'fill 1 to 64
next
next
next
end sub


sub finish() link #pFinish
freememory @v
terminate
end sub


"


'COMPILE
'=======


o2_basic src
if o2_errno then
msgbox 0,o2_error
stop
else
o2_exec
'msgbox 0,"ok"
end if




'MAIN THINBASIC SECTION
'======================
declare sub CreateArray3d(byref pv as long, byval x as long, byval y as long, byval z as long ) at pCreateArray3d
declare sub Finish() at pFinish
dim as long pv
dim as long x,y,z
x=4
y=4
z=4
CreateArray3d(pv,x,y,z)
'msgbox 0,pv
dim as single v(x,y,z) at pv
'array Order: 17 18 19 20
msgbox 0,"Order: "+v(1,1,2)+", "+v(2,1,2)+", "+v(3,1,2)+", "+v(4,1,2)
finish()

Oscar Ugolini
16-03-2023, 18:28
Thanks Charles!
And sorry for the same questions every time! :D

I will try it.
Bye,
Oscar