1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Anyone know Fortran?

  1. May 7, 2004 #1
    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.
     
  2. jcsd
  3. May 8, 2004 #2

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    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.
     
  4. May 8, 2004 #3
    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.
     
  5. May 9, 2004 #4

    krab

    User Avatar
    Science Advisor

    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.
     
  6. May 9, 2004 #5
    Tried that and for some reason it wouldn't read the list of integers at all.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?