pass string array from VB to Fortran by writing strings to file

  • Thread starter Thread starter Mike Kipling
  • Start date Start date
M

Mike Kipling

Guest
I am passing string arrays from Fortran to VB and vice-versa by writing them to a text file in one routine and then reading them from the text file in the other routine. The only time I have a problem is when reading the first line of the file inside the Fortran routine. The first three characters of the first line are garbage. I can ignore them, but I would like to eliminate the problem altogether.

Here is the VB code where I am writing the array to a file.

VB code:
Dim stringarray(2)

stringarray(0) = "string1"
stringarray(1) = "string2"
stringarray(2) = "string3"

My.Computer.FileSystem.DeleteFile("test.txt")

Dim file As System.IO.StreamWriter

file = My.Computer.FileSystem.OpenTextFileWriter("test.txt", False)

For i = 0 To 2
file.WriteLine(stringarray(i))
Next

file.Close()

I then call the Fortran routine which reads the text file.

FTN code:
CHARACTER(LEN=10), DIMENSION(3) :: stringarray

OPEN(10,FILE='test.txt',STATUS='OLD')

DO i = 1, 3
READ(10,'(A)') stringarray(i)
ENDDO


Here are the values of the array after they are read from the file.

stringarray(1) = 'string1'
stringarray(2) = 'string2'
stringarray(3) = 'string3'


If I look at the file in a text editor, the garbage values are not there.

Any Suggestions?

Thanks,

Mike

Continue reading...
 
Back
Top