PDA

View Full Version : Anyone know Fortran?


falcon0311
May7-04, 01:43 PM
I know this isn't really physics related, but I was wondering if anyone here knows Fortran.

I'm trying to read a list of integers from a file and sort them. Well, I'm reading them and sorting them, but my problem is the list looks something like:

23
253
23
45
75
4
856
45
234
54
34
12
21

It's printing the total number of items as being 10, then it's printing this list:

0
165584
1633955692
1668244013
1697591601
1702047597
0
1731162226
0
925854305

Then it won't even write to the new file.
Here's my open statement,

open( unit = unitnum, file = infile, status = "old", action = "read", &
form = "binary", iostat = status )

I don't feel right about it, and if I try to change the form=, the program doesn't read the file altogether. Any help is much appreciated, and if you need to see anything else, by all means, let me know. Thank you.

Dr Transport
May8-04, 06:23 PM
try
open( unit = unitnum, file = infile, form = "binary" )
do i = 1,13
read(unit, 10 ) A(i)
enddo
10 format (F10.4)

is the file binary???? I would suspect that your trying to read a file incorrectly. Try rewriting the file and saving in a *.dat naming convention. it has been a while since I wrote fortran, so my skills are rusty.

falcon0311
May8-04, 11:16 PM
The binary aspect was my main question I guess. I figured binary meant one character at a time, I want the whole number, but my teacher isn't a very understanding guy and doesn't like to explain stuff. My book doesn't even mention binary, it says formatted or unformatted, and these two make the program not work at all. Binary is the only thing I can even get a read for so far, so I'm using it.

krab
May9-04, 01:15 AM
Binary refers to the file format. I don't think your file is in binary. Just drop the 'form="binary",' part and you should be OK.

falcon0311
May9-04, 04:00 AM
Tried that and for some reason it wouldn't read the list of integers at all.