Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Using unit 6 for writing to file

Lars_Jakobsen
Beginner
2,575 Views
Hi all,

I have a console application compiled using Intel Visual Fortran Compiler XE 12.0.5.221 [IA-32].

I have attached unit 6 to a file through an open command. When I do

write(6,*) 'This should go to the file'
write(*,*) 'This should go the screen'

both messages are written to the file. This only happens in release mode and only when I compile using IVF not when I compile the same code using CVF (compaq visual fortran).

It was my understanding that even though unit 6 per default represents the screen and can be changed, then * should always represent the screen (when written to).

I have made a simple test program to reproduce the behaviour, but I cannot reproduce the error suggesting that it may be my application that changes the default behaviour of write(*,*). My applicationitselfis to large to append to this thread.

I have spent hours trying to figure out why my program behaves as it does - so I thought I would seek your help. Does anybody have any idea asto what I should be looking for?

Regards

Lars
0 Kudos
6 Replies
Les_Neilson
Valued Contributor II
2,575 Views
The help (see Logical Devices) seems to imply that * and 6 are treatedas distinct but your experience wouldindicate that this is not so. * always to the screen and 6 to the screen unless attached to a file.

Having said that though,the general advice (e.g. the concensus on comp.lang.fortran)for unit numbers for file output is to use numbers > 9

Les
0 Kudos
mecej4
Honored Contributor III
2,575 Views
Is is possible that in your large application you mix I/O operations between Fortran, C and OS calls?

Units * and 6 are initially the same -- an unspecified standard output device. Whether that device is the screen, card punch, printer, plotter, etc. is up to the operating system to select in conjunction with, possibly, environmental variables. Some operating systems allow redirection of output to a different device than the default device.

Unit 6 may be associated with a non-default device using an OPEN statement. Unit * cannot be treated this way. From the Fortran point of view, Unit * guarantees output to the standard output device. However, the output can be diverted at the OS level. Similarly, a C program or a utility program could run your Fortran program with the standard devices reassigned/reconnected to other devices.
0 Kudos
Lars_Jakobsen
Beginner
2,575 Views
Thanks the input.

I found the cause to be the F2003 semantics compiler setting (properties -> fortran -> Language).

When turned off it works as I intended.

Somehow I got itenabled in the release version and not in the debug version.

The behaviour can be seen by this small test program

[bash]program WriteToUnit6

open(unit=6,file='MyOutPut.txt')
  write(6,*) ' This should go in the file '
  write(*,*) ' This should go to the screen'
close(6)

end program WriteToUnit6[/bash]
If F2003 semantics is turned on it will write both lines to the file.

Regards

Lars
0 Kudos
Steven_L_Intel1
Employee
2,575 Views
The option that changes this behavior is /assume:[no]old_unit_star. The default is noold_unit_star which specifies that unit * and unit 6 are distinct. If /assume:old_unit_star is in effect, then writes to unit * and 6 are treated the same. So I would guess that the release configuration of your project changes this option. As there is no project property for it, look on the Command Line property page under Additional Options.

If you can't figure it out, attach the .vfproj file only and I'll take a look.
0 Kudos
Lars_Jakobsen
Beginner
2,575 Views
Hi Steve,

I do not have any Additional Options set (please see attached .vfproj) file.

As I wrote earlier,if I enable F2003 semmanticsthe outcomebecomes identical to your description of /assume:old_unit_starand if I disable F2003 semmantics I get /assume:[no]old_unit_star - is that to be expected?

Regards

Lars

0 Kudos
Steven_L_Intel1
Employee
2,575 Views
Ok - you have the F2003 semantics option different in the debug and release configurations.

If /assume:old_unit_star is in effect, unit * and units 5/6 are distinct.
If /assume:noold_unit_star is in effect, unit * is the same as 5/6

/standard-semantics implies /assume:noold_unit_star

The F2003 standard requires that unit * be the same as INPUT_UNIT and OUTPUT_UNIT from ISO_FORTRAN_ENV.

The default, if you say nothing, is old_unit_star - the documentation is incorrect in saying that it is noold_unit_star and I will have that corrected.
0 Kudos
Reply