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

Problem directing Input/Output to Console

nitinshukla
Beginner
822 Views
I am porting an application from Unix to Windows NT. The complete
application consists of one executable built with FORTRAN source code and
Unix shell scripts. I have already built a console application with the
FORTRAN source code and the Unix shell scripts have been converted to Perl
scripts.

Problem : The original shell scripts is setting some environment variables,
which are looked for by the executable. One of the variables is set
to the value returned by a Unix utility 'tty'. This utility on Unix displays
the terminal name. The problem I am facing is that the Fortran
executable is opening with the filename specified as this terminal name. The
subsequent READ and WRITE statements using the Unit specifier,(
specified with the open statement while opening this terminal) are now
directed to this terminal. Since there is no such utility as 'tty' on
Windows, what I need to work out is same logic in which the open
statement should open a unit directed to CONSOLE. The following subsequent
READ and WRITE statements with the Unit specifier, as specified
in the open statement while opening file directed to
CONSOLE, should now read and write on the CONSOLE.

What I have tried : I have already tried the following.
Given open statements with File name specified as 'CON',
'USER', 'CONOUT$' and 'CONIN$'. While the
subsequent WRITE statements are successful for the first three and the READ
statements are failing, the READ statements are
successful for the last one and WRITE statements fail.

Please let me know how can I work out a solution for this. How can I achieve
the similar functionality for the application when ported to Windows NT.
0 Kudos
3 Replies
james1
Beginner
822 Views
Any reason you couldn't just use standard units 5 and 6?

James
0 Kudos
nitinshukla
Beginner
822 Views
It's like this. On run time, depending upon the option you choose the fortran application will open the terminal as file with unit specifier as say 13 or some other number. Now using this unit number you will read and write to the terminal with 'READ' and 'WRITE' statements. Doing this on Windows means opening Console as file with some unit number and then using this unit number you have to read and write using 'READ' and 'WRITE' statements. Any solution to this??
0 Kudos
james1
Beginner
822 Views
If you read from 5 and write to 6, you could just define the appropriate environment variable on each platform to redirect from a terminal to a file if desired.

Anyhow you cannot open CONIN$ or CONOUT$ on one unit and do reads and writes. You would have to read from one unit and write to another. This is because with a Windows console application CONIN$ is the keyboard (readonly) and CONOUT$ is the console screen buffer (writeonly).

Since unit 5 is CONIN$ and unit 6 in CONOUT$ under Windows, that would seem to provide a portable mechanism between your two platforms.

That said though CON should work I believe.

James
0 Kudos
Reply