- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm having a problem with some code I'm porting from AIX to Linux. Here's the deal:
OPEN(UNIT=6,FILE='OUTPUT')
WRITE(*,*) "TEST"
On AIX this creates a file called OUTPUT and writes TEST to it.
On Linux this creates an empty file called OUPUT and writes TEST to the console.
I've tried setting FORT6, but it doesn't work. I can explicity write to unit 6 (i.e. write(6,*) ) and it works, but the code has about2000 WRITE(*,*) statements.
Is there a way to redirect the * unit number to a file?
Thanks.
Message Edited by cjosefy on 01-27-2005 07:39 AM
Link Copied
11 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
On linux, unit=* normally is interpreted as stdout. The usual way to redirect is by the command line piping commands e.g.
./a.out > OUTPUT
20 years ago, it was common for unit=* to be the same as some numbered unit, but unit 6 was not the only common choice made by compilers.
Did you try
OPEN(unit=*,file='OUTPUT') ?
I don't think that is guaranteed, but it seems the most obvious way, if you want to build the file name into the program.
./a.out > OUTPUT
20 years ago, it was common for unit=* to be the same as some numbered unit, but unit 6 was not the only common choice made by compilers.
Did you try
OPEN(unit=*,file='OUTPUT') ?
I don't think that is guaranteed, but it seems the most obvious way, if you want to build the file name into the program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can't open unit *.
If you are going to open unit 6, do the writes to unit 6. As Tim says, unit * and unit 6 may well be different (and they are in Intel Fortran.)
If you are going to open unit 6, do the writes to unit 6. As Tim says, unit * and unit 6 may well be different (and they are in Intel Fortran.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran Compiler for Linux User's Guide Vol. 1 (Pg. 166) says that WRITE(*,f) iolist is associated with the environment variable FORT6 and stdout. However, setting FORT6 has no effect on this behavior.
If UNIT 6 and * are different then the wording should be changed.
Message Edited by cjosefy on 01-27-2005 10:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks - I see the table you are referring to. I will have it looked into.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot. For now, I think the temporary fix will be to call C's freopen() to redirect stdout. When you do that, WRITE(*,*) is redirected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would expect that defining FOR_PRINT would do it with or without -vms. The reference to -vms in the table puzzles me....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I compiled WITHOUT -vms and then set the FOR_PRINT environment variable. Now WRITE(*,*) outputs to the file specified in FOR_PRINT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That is what I would expect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a similar problem that I don't think has been answered here. I have a c++ main that calls some legacy fortran code. The fortran code performs writes to unit 6. The c++ code needs to parse whatever is written to stdout without it going to a file. The c++ code sets up a pipe with stdout going in one end and the other end being read and parsed. This works for printf's and cout's. Fortran writes to either unit 6 or unit * just hang in the write. Is there a way to intercept unit 6 and * without writing to a file and without changing the legacy fortran code?
The pipe is set up as follows in the c++ code:
enum {READ, WRITE};
int my_pipe[2];
pipe(my_pipe);
dup2(my_pipe[WRITE], fileno(stdout));
.
.
num_bytes = read(my_pipe[READ], buffer, sizeof(buffer));
.
.
The pipe is set up as follows in the c++ code:
enum {READ, WRITE};
int my_pipe[2];
pipe(my_pipe);
dup2(my_pipe[WRITE], fileno(stdout));
.
.
num_bytes = read(my_pipe[READ], buffer, sizeof(buffer));
.
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It should "just work". Fortran will honor the redirection and write to the pipe. If you are finding that it doesn't, please submit an example to Premier Support.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well, I wrote an example and, of course, it works ok. There must be something within the legacy code messing things up.
Thanks for the quick reply.
Thanks for the quick reply.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page