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 have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29305 Discussions

How to output special characters by Fortran?

Zhanghong_T_
Novice
2,589 Views
Hi,
I am trying to output some special characters to a text file, such as 'a?d', can anyone tell me how to do?
Thanks,
Zhanghong Tang
PS: I have tried to write the following code, but it still can't output such characters.
Code:
integer i
open(1,file='test.txt')
do i=1,10000
write(1,*)char(i)
enddo
close(1)
end


0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
2,589 Views
The answer to this is anything but simple. Suggested reading:

http://www.cs.tut.fi/~jkorpela/chars.html

The bottom line is:

- If you don't use Unicode, you can see those characters only if all of them reside in the same code page (Greek?) and the font you're using to see them has these characters and the viewer application is set up for that code page. (Also, console code pages (SetConsoleIoCp) are pretty difficult to get right)

- If you use Unicode, you can output any combination of characters you want, but
1) Fortran support for Unicode is clumsy -- you have to use INTEGER(2) and APIs such as MultiByteToWideChar
2) The viewer applicaton must be such that it supports Unicode as well
3) The font you use must also contain these characters.

- A compromise solution could be to output the text to a HTML, where Unicode characters can be inserted in form &nnnn;. For example, α produces lowercase alpha (a ).

HTH
Jugoslav
0 Kudos
Intel_C_Intel
Employee
2,589 Views

I thought I'd point out that since the 9.0 release, Array Visualizer has supportted Unicode characters. I.e. object names, object comments, captions, andarrayscan be Unicode strings. You can look at the attachedscreen shot of Array Viewer to see what I mean.

Unfortunately, for the most part the Fortran API to AV (the AvFRT and AvObjMod modules) don't take Unicode arguments. (you can have Unicode string arrays, but not Uniocde object names, or captions). It should be easy enough to extend the API to support these arguments, but I'm wondering which approach developers would like to see:

1. Adding additional routines that take INTEGER(2) stringarguments

2. Keeping the same routines but converting UTF8 strings to Unicode internally

3. Keeping the same routines but convering HTML style entities of the form:"&#nnnn;" to unicode characters.

Any thought on which of these seems most natural for Fortran developers?
John
0 Kudos
Zhanghong_T_
Novice
2,589 Views

Hi,

Thank both of you very much!

To Jugoslay: Could you give me some example to show the usage of MultiByteToWideChar?

To John: I am wondering where does the object come from as shown in your figure? From Fortran application, or others such as VB application? In other words, the AV can be used in other language application?
Thanks,
Zhanghong Tang
0 Kudos
Intel_C_Intel
Employee
2,589 Views

Actually the screen shot was just the Intel Array Viewer application where I've opened a data file which uses Unicode characters.

But yes, you can use AV from Fortran, VB, C, or C#. AV comes with samples in all these languages, so could look through the VB samples on the kit to get an idea of how it worksWe've also had several recent questions in the Array Visualizer forum on using AV with VB.

If you have specific questions about AV & VB, let's take it up in the Array Visualizer forum.
John
0 Kudos
Reply