- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Currently we can do this: open a text file and write degree symbol(°F) in FORTRAN, then read this file in C++ with ANSI mode.
But now if we read the same file in C++ with UTF-8 mode, we have trouble with degree symbol. Please refer to the attached screenshots.
We tried to add "encoding = 'UTF-8'" option when we open the file before writing the degree symbol in FOTRAN, it doesn't help.
So we have 2 questions:
1. Does Intel FORTRAN support encoding UTF-8 for text file, exp. for special characters -- degree symbol, square, cube etc.?
2. If yes, how should we write the degree symbol to text file in FORTRAN to let FORTRAN compiler knows this is UTF-8 mode, not ANSI mode?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I would suggest is creating a series of named (PARAMETER) character constants for the symbols you want. You could then write them in formatted I/O using an A format.
character(2), parameter :: utf_degree = char(int(Z'C2'))//char(int(Z'B0'))
character(2), parameter :: utf_squared = char(int(Z'C2'))//char(int(Z'B2'))
character(2), parameter :: utf_cubed = char(int(Z'C2'))//char(int(Z'B3'))
open (unit=1,file='E:\new2.txt', form='formatted', status='unknown')
write (1,'(A,A)') "Degree: ", utf_degree
write (1,'(A,A)') "Squared: ", utf_squared
write (1,'(A,A)') "Cubed: ", utf_cubed
close (1)
end
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Intel Fortran does not currently support UTF-8 in files. But if you can figure out the UTF-8 encoding, you can write it as a series of bytes. For example:
open (unit=1,file='E:\new 2.txt', form='unformatted',access='stream',status='new')
write (1) '37',int(Z'B0C2',2)
close (1)
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I would suggest is creating a series of named (PARAMETER) character constants for the symbols you want. You could then write them in formatted I/O using an A format.
character(2), parameter :: utf_degree = char(int(Z'C2'))//char(int(Z'B0'))
character(2), parameter :: utf_squared = char(int(Z'C2'))//char(int(Z'B2'))
character(2), parameter :: utf_cubed = char(int(Z'C2'))//char(int(Z'B3'))
open (unit=1,file='E:\new2.txt', form='formatted', status='unknown')
write (1,'(A,A)') "Degree: ", utf_degree
write (1,'(A,A)') "Squared: ", utf_squared
write (1,'(A,A)') "Cubed: ", utf_cubed
close (1)
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
We are having trouble to use the same way to write these characters(fourth power, ≤, ≥) in FORTRAN to text file, because these characters' UNICODE(UTF-8) value has 3 bytes.
Here is our test code:
character(3), parameter :: utf_fourth = char( int( Z'E2' )) // char(int( Z'81' )) // char(int( Z'B4' )) ! fourth power
open (unit=1,file='E:\new2.txt', form='formatted', status='unknown')
write (1,'(A,A)') "Fourth: ", utf_fourth
close (1)
end
But the test result is:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your test result doesn't match the program you show. When I compile and run the program, I get the proper "fourth" character.
character(3), parameter :: utf_fourth = char( int( Z'E2' )) // char(int( Z'81' )) // char(int( Z'B4' )) ! fourth power
character(3), parameter :: utf_lessequal = char(int(Z'E2')) // char(int(Z'89')) // char(int(Z'A4')) ! Less than or equal
character(3), parameter :: utf_greaterequal = char(int(Z'E2')) // char(int(Z'89')) // char(int(Z'A5')) ! Greaterthan or equal
open (unit=1,file='E:\new2.txt', form='formatted', status='unknown')
write (1,'(A,A)') "Fourth: ", utf_fourth
write (1,'(A,A)') "Less or equal: ", utf_lessequal
write (1,'(A,A)') "Greater or equal: ", utf_greaterequal
close (1)
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for quick response, Steve.
Sorry for the confusion, I uploaded the wrong screen shot.
I copied your test code and ran it, why did I get this for fourth power? Any idea or guess?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would guess because the font being used in your text editor does not have a definition for that code. I note that Steve opened in Notepad and you have some other program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah, that's Notepad++ which I also have. It defaults to Courier New font which doesn't have that character. Indeed, if I copy that character from Character Map and paste it into Notepad++, I get the block symbol.
Do this. Settings > Style Configurator...
Language: Global Style, Style: Default Style. Change Font from Courier New to Consolas. While you're at it, you may want to change the font size from 10 to something larger (at least I did.) Save and Close.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page