- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm running a mixed language program under CENTOS using Composer on x64. It writes to stdout, stderr on the c side and 4,5,6, and a whole lot of other unit numbers from fortran. But I'm not getting the same consistent output on the linux side as I do under Windows. Is there some documentation about how these work on linux including redirecting the output of the command lines using > in script files?
Thanks,
Dave
Thanks,
Dave
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mixing language I/O is never a good idea. Each language has its own view of where it is in a file and what records look like.
On Linux, the Fortran I/O is done through the C library, but I'm not sure what problem you ae seeing. You should be able to redirect stdout in both languages, but I can't promise that both would be able to write to the file.
On Linux, the Fortran I/O is done through the C library, but I'm not sure what problem you ae seeing. You should be able to redirect stdout in both languages, but I can't promise that both would be able to write to the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In my experience under x86_64 RHEL 5, "unformatted" fortran IO with
ifort 11.x will write 4-byte integer record indicators at the beginning
and end of each record (each write statement). The beginning and end
record indicators appear to match, and appear to be 4 byte integers
containing the length of the record (in bytes if I remember correctly).
(I use the linux od utility to explore the contents of "unformatted"
binary files.) I suspect a more portable way to do mixed language
unformatted IO is to use a F2003 languagen feature implementing stream
IO. In the open statement you can add the access="stream" keyword pair.
This should do away with Fortran record indicators and on most systems give you a binary file you can read with C, matlab, etc. although as Steve noted there are some potential portability issues here. One possible solution might be to use the F2003 ISO_C_BINDING module and perfrom all the IO in one of the two languages.
In terms of portability and redirect standard in, out and error, I *HIGHLY* recomend using the F2003 ISO_FORTRAN_ENV module, which defines ERROR_UNIT, INPUT_UNIT, and OUTPUT_UNIT. This is by far the most portable way to deal with redirection. (On most systems these are 0 for stderr, and 5 and 6 for stdin and stdout respectively.)
Now keep in mind that stdin, stdout, and stderr are, in my experience, connected at the beginning of program execution as form="FORMATTED" files. I have run into problems in the past under ifort 11.x closing and reopening these with input redirection/pipes/herestrings etc. although I am having trouble finding the old threads on this forum.
-Z
In terms of portability and redirect standard in, out and error, I *HIGHLY* recomend using the F2003 ISO_FORTRAN_ENV module, which defines ERROR_UNIT, INPUT_UNIT, and OUTPUT_UNIT. This is by far the most portable way to deal with redirection. (On most systems these are 0 for stderr, and 5 and 6 for stdin and stdout respectively.)
Now keep in mind that stdin, stdout, and stderr are, in my experience, connected at the beginning of program execution as form="FORMATTED" files. I have run into problems in the past under ifort 11.x closing and reopening these with input redirection/pipes/herestrings etc. although I am having trouble finding the old threads on this forum.
-Z

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