Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help me in fortran90

  1. Aug 3, 2011 #1
    Hi All
    I have a problem in the work with Fortran90. I have a file that don't have any idea for read it. It consiste of number and character.For example it includes as below
    1 15193r 8 9r 4 6 74r,...
    I want to write these numbers in 2 columns. For example
    1 15193
    8 9
    4 0
    6 74
    terms with r show the number of iteratin and number ( that after it dosen't exist term with r) shows that this number has no iteration. Please help me.

    Thanks a lot.
  2. jcsd
  3. Aug 3, 2011 #2


    User Avatar
    Science Advisor

    Honestly Fortran is one of the worst languages for that type of problem. It would probably be quicker to do it in Python, even if you had to teach yourself the basics of Python first.

    Do you have any other languages available?
  4. Aug 3, 2011 #3
    Thanks Uart.But I had to solve this problem with Fortran90.
  5. Aug 3, 2011 #4
    I have a problem in write arrays also.How I do write rows and columns in file as matrix.
    For example I use this program:
    do i=1,10
    end do
    but in file only 4columns are showed and 20columns are breaked.Can anyone help me?
    Thanks a lot.
    Last edited: Aug 3, 2011
  6. Aug 4, 2011 #5


    User Avatar
    Science Advisor

    Hi ne 237

    If the matrix only has 20 columns then try using to following

    write(12,*) x(i,:)

    If it's got more than 20 (but you only want to output the first 20) try

    write(12,*) x(i,1:20)
  7. Aug 4, 2011 #6
    Thanks a lot Uart for reply
    But I want to the output will be as below:
    1 2 2 3 2 3 4 3 5 3 5 3 6 4 5 8 9 45 65 14
    that is 20columns (or more in other program)write in different rows.
  8. Aug 4, 2011 #7


    User Avatar
    Science Advisor

    Yeah that's how it works for me (you still need the outer for loop of course).

    do i=1,10
    write(12,*) x(i,:)
    end do

    I'm using the freeware gnu fortran compiler "g95" and the above code correctly writes the matrix, whole row per line, to an output text file.
  9. Aug 5, 2011 #8
    Thank you very much.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Help me in fortran90
  1. Fortran90 help (Replies: 4)

  2. Can you help me ? (Replies: 2)

  3. Fortran90 help (Replies: 5)