Rain
Rain

Reputation: 375

Difference between write(*,*) and write(6,*) in Fortran

I know this may sound like a stupid question: is there any difference between

write(*,*)

and

write(6,*)

? I am running a complicated code on the supercomputer in my institute which outputs a data file via a unit number different than 6, and apparently the Fortran code compiled with the ONLY difference being the above code gives me a different data file (i.e., data do not match).

I know the (*,*) format goes to standard output, while the (6,*) renders on screen, however I am really confused by why this has any effect on my actual data. Any ideas about how this works would be appreciated!

Upvotes: 3

Views: 8037

Answers (1)

The unit denoted by * is the "standard output" (not a true Fortran standard term). It is usually pre-connected as unit number 6, but it can be connected to a different one - compiler options control that. You can check this using the constant OUTPUT_UNIT in the module iso_fortran_env

OUTPUT_UNIT:
    Identifies the preconnected unit identified by the asterisk (*) in WRITE statement. 

(from gfortran documentation)

Most often the results can be expected to be the same for both. If it is not your case, you have to show as what the differences look like.

If you use some other unit number and you opened it yourself in your own code, anything can happen. You must check the options you used when opening the file, i.e. the open statement and the compiler options in place.

Upvotes: 5

Related Questions