What does the Fortran 77 command 'write' do and how is it used?

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

The Fortran 77 command 'write' is used to output data to a specified unit, in this case, unit 4. The command 'write (4,*)' outputs a single space using default formatting, while 'write (4,310)' and 'write (4,311)' utilize specific format statements defined in lines 310 and 311, respectively. These format statements dictate how the data is presented, with line 310 serving as a header for the output and line 311 providing units for the data. The unit number indicates the output destination, likely a disk file assigned via an OPEN statement.

PREREQUISITES
  • Understanding of Fortran 77 syntax
  • Familiarity with format statements in Fortran
  • Knowledge of file handling in Fortran, particularly the OPEN statement
  • Basic concepts of output units in programming
NEXT STEPS
  • Study Fortran 77 file I/O operations, focusing on the OPEN and CLOSE statements
  • Learn about Fortran 77 format specifications and how to create custom format statements
  • Explore examples of using the WRITE statement with different output units
  • Investigate debugging techniques for Fortran programs to understand output behavior
USEFUL FOR

This discussion is beneficial for new Fortran programmers, educators teaching Fortran 77, and developers working on legacy Fortran code who need to understand output formatting and file handling.

Triscas
Messages
9
Reaction score
0
Hello,

I'm new using fortran and I don't know what does it mean:

write (4,*) ' '
write (4,310)
write (4,311)

this lines go consecutive in the programm I have to understand.

- might say that 4 is not a reference to a line of the code.
- 310,311 are references about how the format should be

i.e:
310 format('Distance C Elec C Sol Surf Liq Pot Solid Pot ',
&'Liq Cur j main j side 1 j side 2 j side 3')
311 format('(microns) (mol/m3) x or y (V) (V) ',
1' (A/m2) (A/m2) (A/m2) (A/m2) (A/m2)')



I hope someone can help. Thanks
 
Technology news on Phys.org
Triscas said:
Hello,

I'm new using fortran and I don't know what does it mean:

write (4,*) ' '
write (4,310)
write (4,311)

this lines go consecutive in the programm I have to understand.

- might say that 4 is not a reference to a line of the code.
- 310,311 are references about how the format should be

i.e:
310 format('Distance C Elec C Sol Surf Liq Pot Solid Pot ',
&'Liq Cur j main j side 1 j side 2 j side 3')
311 format('(microns) (mol/m3) x or y (V) (V) ',
1' (A/m2) (A/m2) (A/m2) (A/m2) (A/m2)')
All of your write statements send output to unit 4, the first number in the parentheses.
write (4,*) ' ' -- prints a single space (' ') on unit 4, using a default format.
write (4,310) -- prints the string in the format statement in line 310, on unit 4. This string appears to be a header of some sort.
write (4,311) -- prints the string in the format statement in line 311, on unit 4. This string also appears to be some sort of header.
 
Mark44 said:
All of your write statements send output to unit 4, the first number in the parentheses.
write (4,*) ' ' -- prints a single space (' ') on unit 4, using a default format.
write (4,310) -- prints the string in the format statement in line 310, on unit 4. This string appears to be a header of some sort.
write (4,311) -- prints the string in the format statement in line 311, on unit 4. This string also appears to be some sort of header.
what does unit 4 mean? The values will have a length of 4 characters?

yes, i also understood they're a header the other outputs. The second might be the units of the first
 
Triscas said:
what does unit 4 mean?
The unit number indicates which device you want to write to. In this case it would probably be a disk file that was assigned a unit number with an OPEN statement.
Triscas said:
The values will have a length of 4 characters?

yes, i also understood they're a header the other outputs. The second might be the units of the first
 
Mark44 said:
The unit number indicates which device you want to write to. In this case it would probably be a disk file that was assigned a unit number with an OPEN statement.

Thanks for the answer, Mark.
 

Similar threads

Replies
6
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
19K