Passing arrays from VB5 to MS FORTRAN PwrStn 
Author Message
 Passing arrays from VB5 to MS FORTRAN PwrStn

Greetings:

I'm trying to build a Visual Basic 5.0 front-end for a MS fortran
PowerStation 4.0 program. My problem is that I need to pass an array from
VB to the FORTRAN DLL that varies in size; the user will specify the
matrix dimensions using the VB front-end, and the FORTRAN program will
return parameters in the array. I have it working for a matrix of fixed
dimensions - say, a 3x2 matrix, specified in both the VB and FORTRAN code
- but when I try to generalize it crashes and burns.

For example, I'd like to pass 3 arguments to the FORTRAN DLL - I, J and
X(I, J), where I and J are integers (e.g., 3 and 2) and X is a I x J
matrix (e.g., 3x2 matrix). I and J are specified by the user, however.

I dimensioned the variables in VB5 as follows:

        Dim I As Integer
        Dim J As Integer
        Dim X() As Single
        ReDim X(I,J) As Single

My subroutine declaration in VB looks like:


      (ByRef I As Integer, ByRef J As Integer, ByRef X As Single)

    Option Base 1       (by the way...)

And I call the FORTRAN DLL like this:

    Call PleaseWork (I, J, X(1,1))

On the FORTRAN side, I would like to say something like this:

    SUBROUTINE PLEASEWORK(I,J,X)
    DIMENSION X(I,J)                         (or, REAL X(I,J) )

and, of course, be able to enter values in the X matrix to be returned to
VB. If I try this:

    X(1,1) = 11

it's fine. But if I do this:

    X(1,2) = 12

it crashes and burns horribly. So, I can make it work with an
"Explicit-Shape Array", but it won't work with an "Assumed-Shape Array"
(i.e., DIMENSION X(:,:) ), I can't use an "Assumed-Size Array", and when I
try to set it up in FORTRAN as a "Deferred-Shape Array" (i.e.:

    REAL, ALLOCATABLE:: X(:,:)
    ALLOCATE (X(I,J))

the compiler complains that "X is a dummy argument - cannot be
ALLOCATABLE."

I've run out of ideas.  I hope this is enough information for somebody to
see what the problem might be ... assuming this is possible of course ...

Thanks much for any advice,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
David A. Robinson                 |
The Wharton School, Univ. of PA   |                  '''
2314 SH-DH, 3620 Locust Walk      |                 (o o)
Philadelphia, PA   19104          |-------------oOO--(_)--OOo--------------



Mon, 10 Jul 2000 03:00:00 GMT  
 Passing arrays from VB5 to MS FORTRAN PwrStn

Quote:

>Greetings:

>I'm trying to build a Visual Basic 5.0 front-end for a MS FORTRAN
>PowerStation 4.0 program. My problem is that I need to pass an array from
>VB to the FORTRAN DLL that varies in size; the user will specify the
>matrix dimensions using the VB front-end, and the FORTRAN program will
>return parameters in the array. I have it working for a matrix of fixed
>dimensions - say, a 3x2 matrix, specified in both the VB and FORTRAN code
>- but when I try to generalize it crashes and burns.

>For example, I'd like to pass 3 arguments to the FORTRAN DLL - I, J and
>X(I, J), where I and J are integers (e.g., 3 and 2) and X is a I x J
>matrix (e.g., 3x2 matrix). I and J are specified by the user, however.

<SNIP>
>And I call the FORTRAN DLL like this:

>    Call PleaseWork (I, J, X(1,1))

>On the FORTRAN side, I would like to say something like this:

>    SUBROUTINE PLEASEWORK(I,J,X)
>    DIMENSION X(I,J)                         (or, REAL X(I,J) )

>and, of course, be able to enter values in the X matrix to be returned to
>VB. If I try this:

>    X(1,1) = 11

>it's fine. But if I do this:

>    X(1,2) = 12

>it crashes and burns horribly. <SNIP>

First try using the pointer attribute in FORTRAN
    REAL, pointer :: x(:,:)
    DIMENSION X(I,J)

Second I found the following in my Digital Fortran help ( it is in MS
Powerstation also)
This would enable you to pass an array from VB and specify the shape of the
array at run time and FORTRAN would understand it.
You would have to create a user type in VB with all of this information and
pass that to FORTRAN.

FROM Digiatal Fortran Help File:
The components of the Visual Fortran array descriptor follow:
The first longword (bytes 0 to 3) contains the base address. The base
address plus the offset defines the first memory location (start) of the
array.
The second longword (bytes 4 to 7) contains the size of a single element of
the array.
The third longword (bytes 8 to 11) contains the offset. The offset is added
to the base address to define the start of the array.
The fourth longword (bytes 12 to 15) contains the low-order bit set if the
array has been defined (storage allocated).
The fifth longword (bytes 16 to 19) contain the number of dimensions (rank)
of the array.
The remaining longwords (bytes 20 up to 103) contain information about each
dimension (up to seven). Each dimension is described by three additional
longwords:
The number of elements (extent)
The distance between the starting address of two successive elements, in
bytes. This value is the stride of the array expression multiplied by the
size of one array element.
The lower bound
An array of rank one would require three additional longwords for a total of
in eight longwords (5 + 3*1) and end at byte 31. An array of rank seven
would be described in a total of 26 longwords (5 + 3*7) and end at byte 103.

Good luck
-Bruce Callen



Mon, 10 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing Arrays to Fortran DLL from VB

2. Passing string Arrays from Fortran DLL to Visual Basic

3. Passing arrays from FORTRAN dll from VB

4. MS Fortran Powerstation Arrays to VB4

5. Passing array to Word with VB5

6. Passing array to Word with VB5

7. Passing array's from vb5 to a DLL

8. vb5 Passing an array of type MENU to a Sub

9. VB5 - Passing Arrays To/From ActiveX

10. How to pass a big array from VB5 to VC5++ DLL

11. VB5: Passing Arrays to a DLL and back

12. VB5 passing arguements, user defined types and arrays

 

 
Powered by phpBB® Forum Software