LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to pass 2d arrays when linking LabVIEW to Intel FORTRAN DLL

Hello,

 

I am trying to link legacy FORTRAN code to LabVIEW 2012 SP1. I am able to pass and retrieve 1D arrays (see TestArrrays FORTRAN code below) using the Call Library Function. I pass N using a Pointer to Value, and the arrays using Array Data Pointer for the format with the minimum size set to N. Works great.

 

If I try a 2D example such as TestArrays2. I enter 2 for the Y dimension which causes the minimum size option to vanish (as designed). However, when I run the calling VI LabVIEW crashes. I believe the issue is that the array size information is no longer passed correctly.

 

thanks for any help,

- Troy

    

      SUBROUTINE TestArrays(lun_log, N, X, Y)

!DEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE :: TestArrays          

      IMPLICIT NONE

      INTEGER*4 I, N, lun_log

      REAL*8 X(N), Y(N)

      DO I = 1, N

               Y(I) = X(I)*2.0

      ENDDO

      END  !  SUBROUTINE TestArrays

 

 

     

      SUBROUTINE TestArrays2(lun_log, M, N, X, Y)

!DEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE :: TestArrays2          

            IMPLICIT NONE

            INTEGER*4 I, J, M, N, lun_log

            REAL*8 X(N), Y(N,M)

      DO I = 1, N

        DO J = 1,M

                   Y(I,J) = X(I) * J

        ENDDO

      ENDOD

      END  !  SUBROUTINE TestArrays2

 

0 Kudos
Message 1 of 2
(2,384 Views)

You cannot pass variable-sized 2D arrays to a DLL like this, because C (which is the model for passing data to a DLL) doesn't have any way to specify the array dimensions. A 2D array is passed as a large block of memory the same way as a 1D array. Search this forum for "pass 2D array to DLL" for more posts on this topic (you might need to use Google and add site:forums.ni.com since the forum search is unreliable). Consider defining Y in your function as a 1D N*M array, and index it with Y(I*N+M).

0 Kudos
Message 2 of 2
(2,367 Views)