LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

parameter types in FORTRAN DLL's

Hi

I am a novice to fortran programing but want to use existing fortran code
within Labview. I have Digital Visual Fortran 5.0A and have suceeded in making
an elementary .DLL and calling it with the Labview call library function.


However, this only works if I set the parameter types to 'Adapt to Type'.
If I try to specify the types Labview crashes with an invalid page fault.
This particular example has only real parameters. I have tried with arrays
and have even less sucess as the 'Adapt to Type' option does not even work
in these cases.

Any help or explanation would be most appreciated.

Rory Stieger

PS : If it's any help here is the fortran code (the commented out bits for
the test with arrays)

ccccccccccccccccc
cccccccccccccccccccccccccc
c subroutine ftoc (n,f,c)
subroutine ftoc (f,c)
implicit none
!DEC$ ATTRIBUTES DLLEXPORT :: ftoc
!DEC$ ATTRIBUTES ALIAS :'ftoc'::ftoc
c integer n,i
c real*8 f,c(n)
real*8 f,c
c do i=1,n
c c(i) = (5.0/9.0) * (f*i-32.0)
c = (5.0/9.0) * (f-32.0)
c end do
return
end
ccccccccccccccccccccccccccccccccccccccccccc
0 Kudos
Message 1 of 5
(2,970 Views)
[posted and mailed]

rds28@eng.cam.ac.uk (Rory Stieger) wrote in <397d5bd0@newsgroups.ni.com>:

>
>Hi
>
>I am a novice to fortran programing but want to use existing fortran
>code within Labview. I have Digital Visual Fortran 5.0A and have
>suceeded in making an elementary .DLL and calling it with the Labview
>call library function.
>
>
>However, this only works if I set the parameter types to 'Adapt to
>Type'. If I try to specify the types Labview crashes with an invalid
>page fault. This particular example has only real parameters. I have
>tried with arrays and have even less sucess as the 'Adapt to Type'
>option does not even work in these cases.
>
>Any help or explanation would be most appreciated.
>
>Rory Stieger
>
>PS : If it's any help here is the fortran code (the commented out bits
>for the test with arrays)
>
>ccccccccccccccccccccccccccccccccccccccccccc
>c subroutine ftoc (n,f,c)
> subroutine ftoc (f,c)
> implicit none
> !DEC$ ATTRIBUTES DLLEXPORT :: ftoc
> !DEC$ ATTRIBUTES ALIAS :'ftoc'::ftoc
>c integer n,i
>c real*8 f,c(n)
> real*8 f,c
>c do i=1,n
>c c(i) = (5.0/9.0) * (f*i-32.0)
> c = (5.0/9.0) * (f-32.0)
>c end do
> return
> end
>ccccccccccccccccccccccccccccccccccccccccccc
>

First of all when passing arrays you need to define them before passing
them to the call library node. So use the init tool before hand to allocate
memory for the array before passing it (This causes a lot of crashes if not
done correctly).

Secondly, the type of call the dll uses is important. Usually you can set
the dll fucntions to have the standard call and you then configure the call
library node to take this into account.

Thirdly, you need to find out how fortran passes parameters. I cannot
remember enough of my fortran to help. But, for example if all values are
passed by reference then configure all your call library parameters as
(*varname). Otherewise by value they would be (varname). In the example
above if they are not passed by reference then you will not receive any
valid value in "c" on return from the subroutine.

Fourthly, some function calls in some languages return values by default
even though the standard way of accessing them might not use the return
value. Check out whether fortran is returning a void function, otherwise
you might need to set up a return in the call library node.

Lastly, make sure that the types match in the parameters. For example is
your int 32 or 16 bit by default?

cheers, Alex.

--

Alexander C. Le Dain, PhD
ICON Technologies Pty Ltd
http://www.icon-tech.com.au
0 Kudos
Message 2 of 5
(2,969 Views)
Rory Stieger wrote:

> Hi
>
> I am a novice to fortran programing but want to use existing fortran code
> within Labview. I have Digital Visual Fortran 5.0A and have suceeded in making
> an elementary .DLL and calling it with the Labview call library function.
>
> However, this only works if I set the parameter types to 'Adapt to Type'.
> If I try to specify the types Labview crashes with an invalid page fault.
> This particular example has only real parameters. I have tried with arrays
> and have even less sucess as the 'Adapt to Type' option does not even work
> in these cases.
>
> Any help or explanation would be most appreciated.
>
> Rory Stieger
>
> PS : If it's any help here is the fortran code (the commented out bits for
> the test with arrays)
>
> ccccccccccc
cccccccccccccccccccccccccccccccc
> c subroutine ftoc (n,f,c)
> subroutine ftoc (f,c)
> implicit none
> !DEC$ ATTRIBUTES DLLEXPORT :: ftoc
> !DEC$ ATTRIBUTES ALIAS :'ftoc'::ftoc
> c integer n,i
> c real*8 f,c(n)
> real*8 f,c
> c do i=1,n
> c c(i) = (5.0/9.0) * (f*i-32.0)
> c = (5.0/9.0) * (f-32.0)
> c end do
> return
> end
> ccccccccccccccccccccccccccccccccccccccccccc

I have some info online at:

http://copland.udel.edu/~rcflyer/dll.html

It's specific to MS Powerstation FORTRAN 4.0 (from a few years ago), but the
explanation of calling parameters, etc. should still be helpful.

Rod
--
Roderic Don
Research Associate II
University of Delaware
Center for Composite Materials
302-831-8701
302-831-8525 (FAX)
0 Kudos
Message 3 of 5
(2,969 Views)
Rory,

I am going down the same path as you are trying to link fortran code with labview. Have you had any success that you could share with me? Thanks, Chuck
0 Kudos
Message 4 of 5
(2,969 Views)
I know this is an old thread, but I just wanted to thank the original authors.  I too am building a labView interface to some old FORTRAN legacy code and was having a lot of problems with passing arrays.  Thanks to this thread, it now seems to work. 
 
The keys are;
 
Preallocate the arrays with the initialize array block (this is what I was missing)
Calling Conventions:   C
Parameter type:   Array
Array Format:   Array Data Pointer
Don't forget the CDEC$ directive in the source code (see below)
 
I am using COMPAQ Digital FORTRAN Version 6.6.
 
 
Thanks again,
Mark
 

 SUBROUTINE transArray(MYARRAY)
CDEC$ ATTRIBUTES DLLEXPORT:: transArray
 REAL MYARRAY(1000)
 INTEGER I
 
 DO I=1,999,2
   MYARRAY(I)=1.0
   MYARRAY(I+1)=2.0
 END DO
 

 RETURN
 END
 
0 Kudos
Message 5 of 5
(2,736 Views)