Why Won't My Fortran 90 Loop Output to a File?

Click For Summary

Discussion Overview

The discussion revolves around a user's issue with outputting data from a Fortran 90 loop to a text file. Participants provide feedback on the user's code and suggest improvements, focusing on programming practices and debugging techniques.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant expresses confusion about the user's statement that the program "will not work," asking for clarification on whether it fails to compile, produces unexpected output, or outputs nothing at all.
  • Another participant points out that the user's WRITE statement should direct output to the file unit opened (unit 10) instead of using the default output unit.
  • A suggestion is made to change the WRITE statement to write to the correct unit: "write(10,*) 'Jason', counter."
  • Participants emphasize the importance of providing detailed context when reporting issues to facilitate quicker assistance.
  • Advice is given on debugging techniques, such as including additional WRITE statements to track program execution and output.

Areas of Agreement / Disagreement

Participants generally agree on the need for clearer communication regarding programming issues and the importance of directing output to the correct file unit. However, there is no consensus on the user's initial problem due to the lack of specific information provided.

Contextual Notes

Participants note that the user's code is simple, which allowed for quick identification of the issue. There are no unresolved mathematical steps or assumptions mentioned, but the discussion highlights the need for clearer problem descriptions.

Who May Find This Useful

New programmers in Fortran 90, individuals seeking help with debugging code, and those interested in best practices for providing context in programming forums may find this discussion useful.

Taylor_1989
Messages
400
Reaction score
14
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

IMPLICIT NONE

integer :: counter

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

do counter= 1,10,1

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

close(10)end program loop
 
Technology news on Phys.org
Taylor_1989 said:
... it will not work.
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 ?
 
Taylor_1989 said:
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:
Fortran:
PROGRAM loop

IMPLICIT NONE

integer :: counter

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

do counter= 1,10,1

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

close(10)end program loop
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
 
Taylor_1989 said:
WRITE(*,*) 'Jason', counter

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

But like phinds says, "it doesn't work" isn't usually very helpful information.
 
  • Like
Likes   Reactions: Taylor_1989
@Mark44 thank you I have just corrected my code.
 
I have taken you comment on board. I will endeavour to improve my context when posting. Once again thank you for the quick responses.
 
Taylor_1989 said:
I have taken you comment on board. I will endeavour to improve my context when posting.
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.
 
  • Like
Likes   Reactions: Taylor_1989

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K