LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone know how to pass a character array into Fortran from Labview?

Hi, I don't think this is covered in the forums and am sorry if it is.

 

I have a FORTRAN dll with a parameter of type CHARACTER(99) which I'd like to assign from Labview.  When I set up the parameter in the configure menu, the closest option I find is string, but this hasn't been acceptable and I get an error when I try it.

 

Thanks very much!

 

0 Kudos
Message 1 of 15
(4,348 Views)
Have you tried using an array of bytes (U8)? Haven't a clue if it will actually work, since I don't know what the "CHARACTER" datatype is in Fortran. In other words, are characters 8-bit or 16-bit?
0 Kudos
Message 2 of 15
(4,326 Views)
I know 0% Fortran either, but when you tried a LabVIEW string configured as C string pointer did you make sure that this string was allocated with 100 characters in the diagram, before passing it to the Call Library Node. In C (and I assume in Fortran too) the caller is always responsible to allocate the memory buffers that get passed to functions as parameters.
Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 15
(4,283 Views)
Thanks for the responses, I'm going to try converting the string into an array of U8 and passing it to the dll that way.  I will write back if this was successful.  Thanks again!
0 Kudos
Message 4 of 15
(4,274 Views)
As mentioned by Rolf, if the Fortran code is expecting an array of 99 bytes (or 100 bytes - don't know if Fortran starts counting at 0 or 1), then you must make sure you create an array of that size before passing it to the DLL. Otherwise, the DLL may try to access memory it's not supposed to. The same holds for a string if you pass it in as a string.
0 Kudos
Message 5 of 15
(4,271 Views)

If I'm not mistaken is a fortran string the same as a LabVIEW string, preceded by an INT containing the number of characters.

A c-string is null-terminated.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 6 of 15
(4,258 Views)

I'm not aware of such a Fortran convention. Generally in Fortran strings seem to be always fixed size allocated, like C fixed size character arrays and while they are indeed 0 terminated those 0 termination characters are considered part of the string when the string contents is used in a comparison. Same about the len() operator which seems to return the length of the allocated fixed size buffer, not the number of characters until the 0 character. All in all without using explicit string functions, string operations are quite a pain in Fortran.

 

Pascal has the notion of a prepended character to note the length of the string, but that is again not the same as LabVIEW which uses a 32 bit integer but also stores the strings inside a handle too, not a pointer.

Message Edited by rolfk on 12-22-2009 07:47 PM
Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 15
(4,245 Views)

Hi Paul. You might want to start here: http://www.math.utah.edu/software/c-with-fortran.html, although it may be tricky:

 

Fortran and C/C++ common data types

For mixed-language programming in C/C++ and Fortran, only the minimal intersection of their many data types can be relied on:

  • int == INTEGER,
  • float == REAL,
  • double == DOUBLE PRECISION.

No other data types can be expected to be exchanged without serious compromise of portability.

 

 

Also, with respect to other comments Fortran CHARACTER variables are 8-bit per character and not preceded by an integer relating to length and counting, like MATLAB, starts at 1 for amusing confusion with LabVIEW and C users.

0 Kudos
Message 8 of 15
(4,215 Views)

Hi Everyone,

 

  Thanks for your responses.  In the end I was able to make the solution work in which I:

1)  Converted a labview string to an array of U8

2)  Passed the array and the length of the string to my FORTRAN DLL

3)  In the FORTRAN code, copied the passed in array, to a local one which is mapped to an array of CHARACTERS using the EQUIVALENCE statement

 

  I'm not sure it's the most elegant, but it works.  Thanks again everyone,

 

Paul 

0 Kudos
Message 9 of 15
(4,040 Views)

Can everyone tell me how to write the fortran code?

Thanks!

 

0 Kudos
Message 10 of 15
(3,575 Views)