Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29283 Discussions

WRITE statement for Unix compatible output, from a Windows executable.

OP1
New Contributor III
719 Views
Hi,

My Windows IVF application is creating text files, which in turn are used as input to my customers' applications. Now, these customer codes either run on Windows or Unix machines. The problem is of course the difference in CR/LF characters at the end of each line of these files.
Is there a way to turn a flag in my code that would help these WRITE statements be interpreted eitheras a *Windows* WRITE, or a *UNIX* WRITE? Or maybe an easy workaround?

Short of this I have to postprocess my output file to remove the extra ^M charactersthat Unix applications are not expecting.

Thanks,

Olivier
0 Kudos
5 Replies
Steven_L_Intel1
Employee
719 Views
OPEN the file with RECORDTYPE="STREAM_LF".
0 Kudos
OP1
New Contributor III
719 Views

Thanks Steve,

I am sure you pointed me in the right direction - but I don't see any difference yet between the STREAM_LF and STREAM_CR options. When Iexecut a 'cat -v my_file.txt' on a Unix machine I still see the ^M characters for both.

Here is how I open my file, and perform write operations:

[fortran]OPEN(UNIT=MY_UNIT,FILE=MY_FILE,STATUS='REPLACE',IOSTAT=IO_ERROR,RECORDTYPE='STREAM_LF')
WRITE(MY_UNIT,'(A)',IOSTAT=IO_ERROR,ERR=100) 'TEST 1'
WRITE(MY_UNIT,'(A)',IOSTAT=IO_ERROR,ERR=100) 'TEST 2'
[/fortran]
0 Kudos
Steven_L_Intel1
Employee
719 Views
I don't know everything you did - you may be looking at an old file. But when I try it, I get only LF delimiters. It is also possible you are using a very old version of the compiler - this feature did not work correctly for a while, but it has been fixed for a couple of years now.
0 Kudos
OP1
New Contributor III
719 Views
Steve,

Thanks to your pointer I was able to sort things out. I am using IVF 10.1 (which probably qualifies as old). The documentation of RECORDTYPE is a bit all over the place (depending on whether you look at the page "Record Types" in "Building Applications", or "OPEN: RECORTYPE Specifier" in "Language Reference" you might not come to the same interpretation of STREAM_LF, for instance).

Anyway, the answer to produce a text file where each line only ends with the LF character (the UNIX/LINUX standard) is:

[fortran]OPEN(UNIT=MY_UNIT,FILE=MY_FILE,STATUS='REPLACE',IOSTAT=IO_ERROR,RECORDTYPE='STREAM',CARRIAGECONTROL='LIST')[/fortran]

STREAM_LF writes CR+LF. STREAM_CR writes CR only. STREAM (with CARRIAGECONTROL = 'LIST', which is the default I think) writes LF only. STREAM (with CARRIAGECONTROL = 'NONE') writes nothing.

Maybe this has been clarified in the documentation of newer compiler versions (I couldn't check). If not, may I suggest a slight rewrite to better explain?

Anyway - problem solved; thanks Steve for your help and forbeing always so available to answers this forum users' questions.

Olivier
0 Kudos
Steven_L_Intel1
Employee
719 Views
Yes, that's a buggy version with the interdependence on CARRIAGECONTROL. It is fixed in newer versions.

The current documentation says:

'STREAM'

Indicates stream-type variable length data with no record terminators.

'STREAM_LF'

Indicates stream-type variable length records, terminated with a line feed.

'STREAM_CR'

Indicates stream-type variable length records, terminated with a carriage return.

'STREAM_CRLF'

Indicates stream-type variable length records, terminated with a carriage return/line feed pair.


STREAM_CRLF is the default on Windows, STREAM_LF is the default on Linux and Mac OS. CARRIAGECONTROL has no effect on this.

You will probably find that the behavior changes if you update the compiler.
0 Kudos
Reply