- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Public
Declare Sub FCALL3 Lib "c: empIntel_FCALLDebugIntel_FCALL.dll" (ByRef xyz As Double)Visual Basic Call Statement
Call
FCALL3(xyz(1)) '<<--- Note the first position of the array as a single elementFortran Subroutine:
subroutine
FCALL3( xyz) !DEC$ ATTRIBUTES DLLEXPORT :: FCALL3 !DEC$ ATTRIBUTES ALIAS :'FCALL3' :: FCALL3 !DEC$ ATTRIBUTES REFERENCE :: XYZReal*8 :: xyz(512)
! Body of FCALLxyz(1) = 111.11d0
xyz(7) = 777.77d0
end subroutine
FCALL3'************************************The above works perfectly*****************************
However with a two dimensional array, I do not get the array values returned correctly
Visual Basic Declare Statement:
Public
Declare Sub FCALL4 Lib "c: empIntel_FCALLDebugIntel_FCALL.dll" (ByRef xyz2 As Double)Visual Basic Call Statement
Call
FCALL4(xyz2(1, 1))Fortran Subroutine:
subroutine
FCALL4( xyz2) !DEC$ ATTRIBUTES DLLEXPORT :: FCALL4 !DEC$ ATTRIBUTES ALIAS :'FCALL4' :: FCALL4 !DEC$ ATTRIBUTES REFERENCE :: XYZ2 ! Variables Real*8 :: xyz2(512,10) ! Body of FCALLxyz2(1,1) = 11.d0
xyz2(1,2) = 12.d0
end subroutine
FCALL4< FONT size=2>
The Array xyz2(512,10) does return back to Visual Basic.Net, but the array values are
received in Visual Basic as follows:
xyz2(1,1) = 11.d0
xyz2(1,2) = 0.d0
xyz2(47,7) = 12.d0
Why is the second value stored in row 47 column 7?
Any help would be greatly appreciated.
Thanks.
- Balises:
- Intel® Fortran Compiler
Lien copié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
How are you declaring the arrays in VB? I don't see a Dim statement to do that in your code.
AFAIK, both VB and Fortran store 2-d arrays in memory in row-major order: element(1,1), element(2,1), element(3,1),..., element(n,1), element(1,2), element(2,2), element(3,2),..., element(n,2), etc. How you declared the arrays in VB would help explain the results you are seeing.
Mike D.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
MsgBox("value = " & inx.ToString & "," & inx2.ToString)
End If Next Next ' Multi-dimensional Array Result Me.TextBox5.Text = xyz2(1, 1).ToString Me.TextBox6.Text = xyz2(47, 7).ToString ' ,<<<--- this is the xyz2(1,2) result End SubThe results from each call are placed in TextBoxes.
The VB.Net declarations are as follows
Public
Declare Sub FCALL3 Lib "c: empIntel_FCALLDebugIntel_FCALL.dll" (ByRef xyz As Double) Public Declare Sub FCALL4 Lib "c: empIntel_FCALLDebugIntel_FCALL.dll" (ByRef xyz2 As Double)Note: Each declaration is only using a single element reference as the starting point.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
VB.net arrays are 'zero-based' and store their array elements in the
opposite order from Fortran. Because you pass the array address to
Fortran using the (1,1) address, it lines up ok with (1,1) on the Fortran
end, but everything else would be off. Everything actually lines up in
memory like this:
VB.NET
(0,0)
(0,1)
(0,2)
(0,3)
(0,4)
(0,5)
(0,6)
(0,7)
(0,8)
(0,9)
(0,10)
(1,1)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
VB.net arrays are 'zero-based' and store their array elements in the
opposite order from Fortran. Because you pass the array address to
Fortran using the (1,1) address, it lines up ok with (1,1) on the Fortran
end, but everything else would be off. Everything actually lines up in
memory like this:
VB.NET
(0,0)
(0,1)
(0,2)
(0,3)
(0,4)
(0,5)
(0,6)
(0,7)
(0,8)
(0,9)
(0,10)
(1,1)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
VB.net arrays are 'zero-based' and store their array elements in the
opposite order from Fortran. Because you pass the array address to
Fortran using the (1,1) address, it lines up ok with (1,1) on the Fortran
end, but everything else would be off. Everything actually lines up in
memory like this:
VB.NET Fortran
(0,0)
(0,1)
(0,2)
(0,3)
(0,4)
(0,5)
(0,6)
(0,7)
(0,8)
(0,9)
(0,10)
(1,0)
(1,1) (1,1)
(1,2) (2,1)
(1,3) (3,1)
(1,4) (4,1)
(1,5) (5,1)
(1,6) (6,1)
(1,7) (7,1)
(1,8) (8,1)
(1,9) (9,1)
(1,10) (10,1)
(2,0) (11,1)
(2,1) (12,1)
.
.
.
(47,5) (511,1)
(47,6) (512,1)
(47,7) (1,2)
...and so on. So it works out just like you said. Since you can't change
the lower bound on arrays in VB.net you've got a couple of choices:
1. change the vb.net end to declare the array as (511,9) and pass
the starting adress as (0,0)
2. change the fortran end to explicitly declare the lower bounds
of the indices as 0.
In either case, you will need to swap the array indices on one end or
the other.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Thanks for the feedback. I see what you mean.
It is still not clean enough for me.
I do not want to be swapping array elements with non-square matrices (m by n).
Thanks again.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
You can make all the arrays in your VB program be one-based instead of the default zero-based by including an Option Base 1 statement at the top of your code before any procedure definitions.
You can override the zero-based default for any individual array by changing its declaration. For example, declaring an array Dim myarray(1 to 10, 1 to 10) will give you a 10x10 array with elements numbered 1 to 10 in each dimension instead of 0 to 9.
Steve was right above; I meant to say column-major order.
Mike D.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
I guess I didn't read all the posts carefully. According to jparsly VB.NET arrays are in row-major order. This may be a difference between VB6 and VB.NET.
Mike D.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Ciao,
Gerry T.
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable