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

Problem with accent mark

Zorrilla__David
Beginner
966 Views

 

Hi,

I have a problem with characters with accent mark (spanish) that I don't understand, because sometimes it works and sometimes it doesn't work.

I have written a simple program to check what is happening, and my surprise has been that it works correctly. The program is this:

 PROGRAM Console1
        IMPLICIT NONE
        CHARACTER(10)::ATOM
        LOGICAL(4)::RES,COMPARE
   
        ATOM="Hidrógeno"
        RES=COMPARE(TRIM(ATOM))
        PRINT *, RES
    END PROGRAM Console1

    LOGICAL(4) FUNCTION COMPARE(NB)
		IMPLICIT NONE
		CHARACTER(15)::LIST(6)
        CHARACTER(*)::NB
        INTEGER(4)::I
        
        DATA (LIST(I),I=1,6)/'Hidrógeno','Helio','Litio','Berilio','Boro','Carbono'/
        
        COMPARE=.FALSE.
        DO I=1,6
            IF(INDEX(TRIM(NB),TRIM(LIST(I)))>0) THEN
                COMPARE=.TRUE.
            ENDIF
        ENDDO
    END FUNCTION

 

But when I do it in a bigger program it saves the characters with accent mark wrong. I send you a capture.

What could be happend?

Thanks in advanced

0 Kudos
4 Replies
mecej4
Honored Contributor III
966 Views

When you use non-ANSI characters in literal strings or character variables, what you see for such characters depends on the encoding, the font used, locale, etc. When I cut and pasted 'Hidrógeno' in three different text editors, I saw three different representations for acute-o . One editor used Z'A2' for that character, another used Z'F3'. In one, I saw 'Hidrógeno'. I don't think that Intel Fortran provides full support for National Languages yet.

You will probably need to use the same text editor for creating the non-ANSI strings in your program text and for viewing the output from the program, whether that is the Visual Studio editor or another editor.

I have to admit that I do not use non-ANSI characters in my Fortran programs, so my knowledge of this topic is quite limited.

0 Kudos
Steve_Lionel
Honored Contributor III
966 Views

Intel Fortran does not currently support multinational characters, either in program source (including character literals) or in I/O. 

0 Kudos
GVautier
New Contributor II
966 Views

Hi

If you want to compare strings with non-ANSI characters, you must be aware of the strings encoding.

In your short example, all the strings are set in the same file so they are encoded using the same charset so it works.

I suspect that, when it does'nt work, the string to be compared among  "list" strings is input externally (keyboard, dialog control or file). So you must know it's encoding and convert it to to your source file encoding (dependant of the configuration of your text editor) in order to be able to compare them.

It's not very easy because, under Windows, console and dialog controls are not encoded with the same charset and files maybe encoded in multiple ways.

As Lionel said, there is no internal function in Fortran to deal with that. You must write your own functions using encoding related Windows API functions.

My advice will be to choose the most convenient internal charset and convert all external inputs to it.

Outputs maybe also a problem.

 

 

0 Kudos
Zorrilla__David
Beginner
966 Views

I have just sove the problem. The problem was that the file console.f90 was encoded as ANSI, and the other file was encoded as UTF-8.

I have changed the encoding from UTF-8 to ANSI, and that's all (for my purpose, that was to compare strings with non-ansi characters. because I know that, for example, I will not be able to print those characters correctly on screen).

Thanks to all

0 Kudos
Reply