Help with formatted output in fortran

  • Context: Fortran 
  • Thread starter Thread starter nikhillaghave
  • Start date Start date
  • Tags Tags
    Fortran Output
Click For Summary
SUMMARY

The discussion focuses on formatting output in Fortran, specifically when printing an array of 11 real numbers, an additional real number, and an integer. The user encountered a runtime error due to incorrect format specification when including the integer in the output statement. The correct format should be adjusted to format(2(2X,5D15.6),1PD18.10,I6) to resolve the issue, as the original format misinterpreted the intended structure of the output.

PREREQUISITES
  • Understanding of Fortran syntax and structure
  • Familiarity with Fortran format specifiers
  • Knowledge of data types in Fortran, particularly REAL and INTEGER
  • Experience with Fortran I/O operations
NEXT STEPS
  • Review Fortran format specifiers in the Fortran 90 standard
  • Learn about Fortran I/O error handling techniques
  • Explore advanced formatting options in Fortran for complex data types
  • Practice writing Fortran programs that utilize formatted output
USEFUL FOR

This discussion is beneficial for Fortran developers, students learning Fortran programming, and anyone involved in scientific computing requiring formatted output in their applications.

nikhillaghave
Messages
2
Reaction score
0
Hello,

I am trying to print in formatted output using the format specifiers but I am not able to get the correct output.
I am trying to print an array with 11 reals, followed by one more real number and finally an integer.

When I skip the integer, the format statement works and but when I add the integer I get an error.
Code:
C  Works with array of 11 reals followed by another real
write(9,326,REC=NF),(X(I),I=1,N),F
format((2X,5D15.6),1PD18.10)

Code:
write(9,326,REC=NF),(X(I),I=1,N),F,NF
format((2X,5D15.6),1PD18.10,I6)

I get this error:
Code:
Fortran runtime error: Expected INTEGER for item 8 in formatted transfer, got REAL
((2X,5D15.6),1PD18.10,I6)

Can someone please guide me the correct way to print this output and explain what I am doing wrong in the above format ? Thanks

Nikhil
 
Technology news on Phys.org
(2X,5D15.6) is two blank spaces followed by 5 floats, not "2 times 5 floats." The format should be changed to something like
Fortran:
format(2(2X,5D15.6),1PD18.10,I6)
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 17 ·
Replies
17
Views
7K
Replies
11
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 29 ·
Replies
29
Views
6K