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

Fortran 90 loop output to file

  1. Feb 5, 2017 #1
    Hi, guys I am very new to programming in fortran90 and I am just experimenting with stuff. I have been trying to get my output of my loop program to a text file. But for some reason it will not work. Could someone please advise.

    Code displayed below:
    PROGRAM loop


    integer :: counter

    open(10, file='jason.txt')

    do counter= 1,10,1

    WRITE(*,*) 'Jason', counter
    end do


    end program loop
  2. jcsd
  3. Feb 5, 2017 #2


    User Avatar
    Gold Member

    This is not a helpful statement. Does it fail to compile? Does it compile but fail to output what you expect? Does it compile but fail to output anything at all? You see my point ?
  4. Feb 5, 2017 #3


    Staff: Mentor

    Your write statement needs to write to the unit you opened -- unit 10.
    Link to some documentation: http://www.math.hawaii.edu/~hile/fortran/fort7.htm
  5. Feb 5, 2017 #4


    User Avatar

    Change this to "write(10,*) 'Jason', counter".

    But like phinds says, "it doesn't work" isn't usually very helpful information.
  6. Feb 5, 2017 #5
    @Mark44 thank you I have just corrected my code.
  7. Feb 5, 2017 #6
    I have taken you comment on board. I will endeavour to improve my context when posting. Once again thank you for the quick responses.
  8. Feb 5, 2017 #7


    Staff: Mentor

    Good. Saying "for some reason it will not work" really doesn't tell us anything. Fortunately your program was very simple, so several of us were able to spot the problem right away.

    For future reference, the more information you give us about the problems you're having, the faster we can find the problem. Useful information is whether the program will compile or not. (If it won't compile, you have syntax errors, usually the easiest kinds of errors to find and fix.)

    If the program compiles, but doesn't produce correct output, or even any output at all, that is useful information. The time-honored technique of including extra write statements is useful, especially if you don't have or don't know how to use a debugger.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Threads - Fortran loop output Date
Fortran infinite loop Sep 9, 2015
Fortran : generating different output files in a loop Jun 30, 2015
Fortran DO loop sequence confusion Apr 25, 2014
Fortran Help (Do Loop) Feb 11, 2014
[FORTRAN] do-loop problem Mar 1, 2013