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

How to read a Unicode text file in FORTRAN

Lothar_Braun
Beginner
1,240 Views
I do have a unicode text file, written by VBScript on Windows with a leading BOM.
I do want to read this File line by line from FORTRAN.
The processing is done in C and C++ (line by line), but i would like to stick with FORTRAN I/O if that is possible.

Any ideas please?
0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,240 Views
At this time, the only suggestion I have is to open the file with ACCESS='STREAM' and read it byte by byte, figuring out for yourself where the line separators are. Adding support for alternate encodings is on our wish list, but is not something we expect to offer soon.

View solution in original post

0 Kudos
3 Replies
Steven_L_Intel1
Employee
1,240 Views
Module IFNLS contains routines for converting strings to and from Unicode. For a list, see the compiler documentation under Language Reference > A to Z Reference > Language Summary Tables > National Language Support Library Routines. You can read the lines as a string using A format and then convert as needed.
0 Kudos
Lothar_Braun
Beginner
1,240 Views
Thank you Steve,

but the problem is not the conversion, but the reading.

The file is split into records with cr lf, each as a wide character, meaning 0d00 0a00 in Hex.

The standard FORTRAN open has a RECTYPE of STREAM_LF, so the first READ Statement gets the first record starting with a BOM and up to, not including the LF.
The second READ gets the 0 Byte form the LF first and reads up to, not including the LF.

Is there a better way to READ the lines, or is there a chance of getting something like the support in MS C++?

Lothar
0 Kudos
Steven_L_Intel1
Employee
1,241 Views
At this time, the only suggestion I have is to open the file with ACCESS='STREAM' and read it byte by byte, figuring out for yourself where the line separators are. Adding support for alternate encodings is on our wish list, but is not something we expect to offer soon.
0 Kudos
Reply