Вопрос

~~SOLVED, See Edit4)

I am creating an input file with Java on OSX, when I try to run the FORTRAN program that reads the input file, I encounter EOF on the first line:

At line 37 of file ../fortran.f (unit = 5, file = 'input2.txt')
Fortran runtime error: End of file

where line 37 starts:

  open (5,file='input2.txt')
  read(5,*) INDEX

I read that this could be a problem with the OS's EOL character, and I've run into it before but can't remember how I fixed it. I am using "\n" in the Java code.
I also tried writing a simple file from the FORTRAN code, in TextWrangler I opened it and saw some leading character (diamond shaped) so I copied that to my Java code but to no avail.

Also, if I edit a text in Eclipse and run it with the FORTRAN program, it works.
Please help, Thanks in advance

Edit1) Here is the Hexdump of input2.txt, I don't see anything strange, however my eye is untrained.

00000000  31 0a 32 0a 4e 69 74 72  6f 67 65 6e 0a 30 2e 30  |1.2.Nitrogen.0.0|
00000010  09 30 2e 30 09 30 2e 30  09 30 2e 30 09 30 2e 30  |.0.0.0.0.0.0.0.0|
*
00000030  09 0a 48 79 64 72 6f 67  65 6e 0a 30 2e 30 09 30  |..Hydrogen.0.0.0|
00000040  2e 30 09 30 2e 30 09 30  2e 30 09 30 2e 30 09 30  |.0.0.0.0.0.0.0.0|
00000050  2e 30 09 30 2e 30 09 30  2e 30 09 30 2e 30 0a 30  |.0.0.0.0.0.0.0.0|
00000060  20 35 39 34 2e 30 20 20  31 2e 30 0a 30 2e 35 20  | 594.0  1.0.0.5 |
00000070  30 2e 35 20 0a 30 0a 0a                           |0.5 .0..|
00000078

those zeros are okay for now, little bug in the java code but FORTRAN should still give me NaN in the calculation.

Edit2) Hex dump from test file:

00000000  20 62 6c 61 68 0a 20 62  6c 61 68 0a 20 62 6c 61  | blah. blah. bla|
00000010  68 0a 0a                                          |h..|
00000013

I've had this problem before, a guy successfully tested the file by explicitly setting EOL to ^M (instead of Unix's ^J), however, I don't know how to do this with java, shouldn't the EOL convention be the same if the program.f is compiled on the same machine?

Edit3) Ok, it seems the file was being written to my "/Users/Tricknology/" directory instead of the location from where I ran the program. However, this led me to a problem.

file='/Users/Tricknology/Desktop/Programming/FORTRAN/input2.txt'

is too long, and

file='/Users/Tricknology/Desktop/Programming'
 &/FORTRAN/input2.txt'

produces:

At line 32 of file ../fortran.f (unit = 4, file = '')
Fortran runtime error: File '/Users/Tricknology/Desktop/Programming                       /Thermo/OUTPUT2' does not exist

(spaces included)

Anyone know of a way to make this work? I think that is the root of the problem.

Edit4) Found the solution:

I changed the read line to

open (4,file=fileplace//"OUTPUT2", action='write')

where

CHARACTER(*), PARAMETER :: fileplace = 
 &"/Users/Tricknology/Desktop/Programming/FORTRAN/"

and it works. Thank you everyone, I hope this helps someone else save a lot of time in the future.

Это было полезно?

Решение 2

I changed the read lines to:

open (4,file=fileplace//"OUTPUT2", action='write')

open (5,file=fileplace//"input2.txt", action='read')

where

CHARACTER(*), PARAMETER :: fileplace = 
 &"/Users/Tricknology/Desktop/Programming/FORTRAN/"

Другие советы

If it turns out that end of line issues are your problem, then you should use methods named

println

in your Java code, the file you write out will have the proper line endings for your operating system. You might have better luck with files produced this way, than by using "\n".

I'm not sure it is a line ending problem, though.

The "diamond-shaped" character you are seeing are very likely REPLACEMENT CHARACTERS which show up whenever you assuming the wrong character encoding in your viewer. For example, if you have a file that was created by a program writing out UTF-8, and you open it in an editor that assumes an encoding of Windows-1252 or Latin-1 or MacRoman, say, you will see replacement characters. There are other cases where those things pop up, too.

Make sure your Java program, your Fortran program, and your operating system's default encoding, and the encoding you are assuming in TextWrangler are all the same, preferably UTF-8.

Also, take a look at the file input2.txt with a binary editor, or simply enter

hexdump -C input2.txt

on your command line (I'm guessing you have a Mac since you mentioned TextWrangler). Maybe the first few bytes represent an end of file, or maybe you have a BOM in there that your Fortran compiler does not understand.

TL;DR: Look at the binary encoding of your txt file and check for BOMs or other weirdness. Regardless of what you find, make everything in your world UTF-8.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top