How to use a variable in format statement in Fortran?

In summary, the conversation discusses the use of variable format specifiers in a programming language called Fortran. The person is having trouble using these specifiers and is seeking help from others who may have experience with them. The conversation also mentions that the gcc-3.4.6 compiler does not support variable format specifiers.
  • #1
manugv
2
0
hello everyone!
I was do programming in fortran and i wanted to print my answer in the format below. I was not able to do it. I have written a part of my program also.
i.e,
#####
greeting = 'Good Morning!'
do 110 I = 1, 12
write (*,115) (greeting)
115 format (A<I>)
110 continue
end
#####
here i want to use a variable 'I' in the format statement i tried it doing but i failed. so please if anyone knows to use a variable in format statement tell me.
I use gcc-3.4.6 compiler.

output of the program
G
Go
Goo
Good
Good
Good M
Good Mo
Good Mor
Good Morn
Good Morni
Good Mornin
Good Morning
 
Last edited by a moderator:
Technology news on Phys.org

1. What is a problem in a Fortran program?

A problem in a Fortran program refers to an error or issue that occurs during the execution of the program. This can be caused by a variety of factors, such as incorrect syntax, logic errors, or compatibility issues with the compiler or operating system.

2. How can I identify and troubleshoot problems in my Fortran program?

To identify and troubleshoot problems in a Fortran program, you can use debugging tools, such as a debugger or profiler, to track the execution of the program and identify any errors or issues. You can also review the code and compare it with the expected behavior to identify any logic errors.

3. What are some common types of problems in Fortran programs?

Some common types of problems in Fortran programs include syntax errors, logic errors, runtime errors, and compatibility issues. Syntax errors occur when the code does not follow the correct format and cannot be compiled. Logic errors refer to mistakes in the program's logic that result in incorrect output. Runtime errors occur during program execution and can be caused by issues such as division by zero or array out of bounds. Compatibility issues may arise when the program is run on different versions of Fortran or on different operating systems.

4. How can I prevent problems in my Fortran program?

To prevent problems in a Fortran program, it is important to carefully review and test your code before running it. Use proper coding practices and follow the Fortran syntax rules to avoid syntax errors. Use debugging tools to identify and fix any logic errors. It is also important to regularly check for compatibility issues when running the program on different systems or after making any updates to the code.

5. What resources are available for troubleshooting Fortran program problems?

There are various resources available for troubleshooting Fortran program problems, such as online forums and communities where you can ask for help from experienced Fortran programmers. There are also online tutorials and documentation provided by the Fortran compiler or development environment you are using. Additionally, there are debugging tools and profilers that can assist in identifying and fixing errors in your code.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
Back
Top