Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read

Status
Not open for further replies.

bcbvi

Programmer
Sep 26, 2011
3
DE
I have a text file containing lines of input data:

T
1
300.00
C:\Documents and Settings\username\output\asdf.txt

which I am reading with some .f95 code:

character(len=1) ::var1
integer ::var2
double precision ::var3
character(len=150)::var4

open(12,file='input.txt')
read(12,*)var1
read(12,*)var2
read(12,*)var3
read(12,'(a)')var4

When I run the compiled .exe this works fine. However I need to call it from a larger VB.NET program. When I do that the debugger compains about the .f95 code: 'attempt to read past end of file at line xx'
where xx is the line number of the 1st read statement.

How can calling the code from some other script affect the way it runs?!

Help would be Hugely appreciated!
 
Apologies for the post title. That was a mistake.
 
What Fortran compiler are you using?
First of all I would explicitely close the file and code the IOSTAT to see what happened. For example something like this
Code:
[COLOR=#2e8b57][b]character[/b][/color]([COLOR=#2e8b57][b]len[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color])  ::var1
[COLOR=#2e8b57][b]integer[/b][/color]           ::var2, stat
[COLOR=#2e8b57][b]double precision[/b][/color]  ::var3
[COLOR=#2e8b57][b]character[/b][/color]([COLOR=#2e8b57][b]len[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]150[/color])::var4

[COLOR=#804040][b]open[/b][/color]([COLOR=#ff00ff]12[/color], [COLOR=#804040][b]file[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'input.txt'[/color], [COLOR=#804040][b]status[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'old'[/color], [COLOR=#804040][b]iostat[/b][/color][COLOR=#804040][b]=[/b][/color]stat)
[COLOR=#804040][b]if[/b][/color] (stat [COLOR=#804040][b].ne.[/b][/color] [COLOR=#ff00ff]0[/color]) [COLOR=#804040][b]then[/b][/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'File cannot be opened !, IOSTAT='[/color], stat
  [COLOR=#804040][b]go to[/b][/color] [COLOR=#ff00ff]99[/color]
[COLOR=#804040][b]end if[/b][/color]

[COLOR=#804040][b]read[/b][/color]([COLOR=#ff00ff]12[/color],[COLOR=#804040][b]*[/b][/color])var1
[COLOR=#804040][b]read[/b][/color]([COLOR=#ff00ff]12[/color],[COLOR=#804040][b]*[/b][/color])var2
[COLOR=#804040][b]read[/b][/color]([COLOR=#ff00ff]12[/color],[COLOR=#804040][b]*[/b][/color])var3
[COLOR=#804040][b]read[/b][/color]([COLOR=#ff00ff]12[/color],[COLOR=#ff00ff]'(a)'[/color]) var4

[COLOR=#0000ff]![/color]
[COLOR=#804040][b]99 continue[/b][/color] 
[COLOR=#804040][b]close[/b][/color]([COLOR=#ff00ff]12[/color])
[COLOR=#a020f0]end program[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top