LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fortran dll

Hello,

I am beating my head against the wall trying to get a fortran DLL to work in labview.
The DLL has multi-dimensional array inputs, and my guess is that my problem lies in correctly configuring the Call LibraryFunction.

The dll is very complex, but I know the dll works, because I have a visual basic program that calls the dll, and it works fine.

A simplified version of the DLL variable definition from the Fortran code is shown below:

      Subroutine MyFunction(Numx,V,dz,ep,nx,top,D)
c
c    ***    Set DLL Attributes   ***
c
!DEC$ ATTRIBUTES DLLEXPORT :: MyFunction
!DEC$ ATTRIBUTES ALIAS:'MyFunction' :: MyFunction
c
c      *** Declare Variables ***
      implicit real*8 (r-w)
      integer sizex,sizey,sizez
      parameter (sizex = 50,sizey = 50,sizez = 20)
c
c    *** Variables passed from the control routine ***
c
    integer D                                           
    integer Numx               
          real*8 V(0:sizex,0:sizey,0:3*sizez)       
    real*8 dz                           
    real*8 ep(2)                           
          real*8 nx(0:sizex,0:sizey,0:sizez)       
         integer top(0:sizex,0:sizey)                                                      
c
c    *** The rest of the program ***


As you can see the inputs consist of Integers, 2D integer arrays, 3D double arrays, a 1d double array, and double inputs.

When I configure the call library function I have tried both calling conventions (C and stdcall) I have defined the integers as I32 (signed integers), I have configured the arrays as Array Format=Array Data Pointer.  The input arrays have been pre-defined in labview as: V is 50x50x60, nx is 50x50x20, top is 50x50 and ep=2, which is the array size that they are defined in the fortran program.

I have tried all the different values for Array Format.  I have tried both calling conventions and both thread selections.  I'm working in LV 8.5

Everytime I try to run the program I get and error 1097 (An exception occured within external code).

I'm almost certain that the problem lies with how I'm configuring the DLL call.

I also have a dll called DFORMD.dll in the working directory (I'm pretty sure it's suppose to be there, but I don't know what to do with it).

The suggestion from my phone call to ni support was to wrap the fortran dll in a C dll, because labview cannot use fortran calling conventions.  However, the posts on this forum seem to suggest that I should be able to use the fortran DLL directly.

Any help would be appreciated.

Neil




0 Kudos
Message 1 of 8
(5,805 Views)
According to this page

http://blogs.msdn.com/oldnewthing/archive/2004/01/02/47184.aspx

Fortran calling convention is the same as Pascal calling convention and according to
this wikipedia article

http://en.wikipedia.org/wiki/X86_calling_conventions

Pascal and stcall conventions are both callee clean-up convention, but the parameters
are passed to stack in different order. This might be the problem.

You could try to make a Fortran function with only one parameter and try to call that with stdcall convention.
In case of parameter, it does not matter in which order the parameters are passed to stack.

Maybe you can change the calling convention in your Fortran code when creating the DLL.

Unfortunately I don't know anything about Fortran, but hopefully this helps and gives you some ideas for this.

0 Kudos
Message 2 of 8
(5,786 Views)
I too am beating my head on the wall over this.  I can pass 1 number, or 1 array, or 1 character back and forth between a fortran DLL no problem - but as soon as I try 2 values, error 1097.  Is what kaem saying that fortran can only pass 1 parameter?  That would be extremely inconvienient.  Did the ni support person have any suggestions on how to "wrap the fortran dll in a C dll" - because that doesn't mean much to me....
0 Kudos
Message 3 of 8
(5,750 Views)
>>Is what kaem saying that fortran can only pass 1 parameter?

No, I meant that if you can pass only one parameter then that would indicate a problem in the calling convention. With one parameter, it doesn't matter are the parameters passed to stack from left to right or vice versa.

This page gives some info on how to change the calling convention in Fortran. I don't know anything about Fortran, but it seems to give instructions on how to change to C calling convention.
0 Kudos
Message 4 of 8
(5,734 Views)

Hi all,

I too have fortran source code which I would like to use in LabVIEW.  I have the .for and the .obj files.  I'm not a fortran user.  I've seen that it is reasonable simple to interface directly with Fortran code in MatLab using the .mex functions.  Don't worry I hate MatLab too, although I do have a copy.  If it's so easy to do in MatLab then it has to be even easier in LabVIEW, surely.

Can anyone tell me what to do?

Thanks,

Jay.

0 Kudos
Message 5 of 8
(5,517 Views)

Hey Battler,

You could use the Call Library Function Node to do this.

For more information on this, refer to How Do I Call a Dynamic Link Library (DLL) from LabVIEW?

Hopefully this helps!!

Aashish M
CEO
TransferFi
www.transferfi.com
0 Kudos
Message 6 of 8
(5,489 Views)

Hi there,

The Call Library function requires that the fortran code be in the form of a .dll.  I am not new to LabVIEW (infact I am an ex-employee;-)) but I have no clue when it comes to Fortran or C.  I have uncompiled (.for) and compiled (.obj) fortran code.  How do I compile into a .dll?  Do I need to creat a c code header file (.h)?  How do I go about it?

Thanks again.

0 Kudos
Message 7 of 8
(5,469 Views)
Hey Battler,
 
You'd need to look up how you can convert Fortran to a DLL. Here's link I got from a quick Google search: How To Create a FORTRAN DLL and Call It from Visual Basic
 
Once you develop the DLL you'll have to create a C wrapper for LabVIEW to understand the Fortran DLL. A good reference for this would be Writing a Wrapper Function for an External Code Function.
 
Aashish M
CEO
TransferFi
www.transferfi.com
Message 8 of 8
(5,443 Views)