~~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.