How to use a variable in format statement in Fortran?

  • Context: Fortran 
  • Thread starter Thread starter manugv
  • Start date Start date
  • Tags Tags
    Fortran Program
Click For Summary
SUMMARY

The discussion centers on using a variable in a FORMAT statement in Fortran, specifically with the gcc-3.4.6 compiler. The user attempts to print a greeting with a dynamic length determined by the variable 'I' but encounters limitations due to the lack of support for variable format specifiers in the compiler. The output demonstrates the incremental display of the greeting, but the desired functionality cannot be achieved as variable format specifiers are not part of the Fortran standard supported by gcc.

PREREQUISITES
  • Understanding of Fortran programming language syntax
  • Familiarity with FORMAT statements in Fortran
  • Basic knowledge of the gcc compiler and its versions
  • Awareness of Fortran standards and limitations
NEXT STEPS
  • Research alternative methods for dynamic string manipulation in Fortran
  • Explore the use of character arrays and substring functions in Fortran
  • Learn about the capabilities of newer Fortran compilers that support variable format specifiers
  • Investigate the differences between Fortran standards regarding FORMAT statements
USEFUL FOR

Fortran developers, programmers working with gcc compilers, and anyone looking to understand the limitations of FORMAT statements in Fortran.

manugv
Messages
2
Reaction score
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

Similar threads

  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K