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

  • Fortran
  • Thread starter Triscas
  • Start date
  • Tags
    Fortran
In summary, the code snippet provided shows the use of the WRITE statement in FORTRAN to output data to a device with unit number 4. The first WRITE statement prints a single space using a default format, while the other two statements use format statements to print headers. The unit number determines which device the output is sent to, and in this case it appears to be a disk file. Additionally, the second header may indicate the units of the values in the first header.
  • #1
Triscas
9
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
  • #2
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.
 
  • #3
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
 
  • #4
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
 
  • #5
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.
 

1. What is the purpose of the "write" command in Fortran 77?

The "write" command in Fortran 77 is used to output data to a specified external file or to the standard output device, such as the console. It allows the programmer to display information to the user or save data for later use.

2. How is the "write" command used in Fortran 77?

The "write" command in Fortran 77 follows the format: WRITE (unit, format) list. The "unit" specifies the file or device to which the output will be directed, and the "format" specifies the appearance of the output. The "list" includes the variables or expressions to be outputted.

3. Can the "write" command be used to write to multiple files in Fortran 77?

Yes, the "write" command can be used to write to multiple files in Fortran 77. It is done by using different "unit" numbers for each file in the command. For example, WRITE (1, format) list1 will write to file "unit 1" and WRITE (2, format) list2 will write to file "unit 2".

4. How does the "write" command handle formatted and unformatted output in Fortran 77?

The "write" command in Fortran 77 can handle both formatted and unformatted output. Formatted output uses a specified format to display the data, while unformatted output writes the data in its raw, binary form. The programmer can specify the format to be used in the "format" parameter.

5. Is there a limit to the number of variables that can be outputted using the "write" command in Fortran 77?

The number of variables that can be outputted using the "write" command in Fortran 77 is limited by the maximum record length of the output device or file. This can vary depending on the system and compiler being used. It is recommended to check the system documentation for the maximum record length allowed.

Similar threads

  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
19K
Back
Top