INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

gfortran: loading hex into DATA statement CHARACTER variables

gfortran: loading hex into DATA statement CHARACTER variables

gfortran: loading hex into DATA statement CHARACTER variables

(OP)
I need to move existing code from the INTEL FORTAN ifort compiler to GNU gfortran.

The gfortran compiler does not like this coding:

CHARACTER Comma*1
C
DATA Comma/Z'2C'/

Anyway to fix this besides an ASCII implementation.

DATA Comma/','/

I have a large number of these which were fine using the Intel fortran compiler.

RE: gfortran: loading hex into DATA statement CHARACTER variables

Well, it sounds like you already found a solution to your problem. What else are you looking for here?

Sources do require maintenance and yours requires at least modernization from f77 to f90/95...so, the way I see it, this is just one of the changes you need to make among many others. Most changes can be handled with a f77-to-f90 converter; others, you may have to take advantage of macros or search-and-replace in your editor.

Anyway, getting back to the issue presented in your post, do you see the problem? The code is effectively attempting to assign an integer (with default length surely greater than 1 byte) to a character variable, thus, the incompatibility.

Heck, I think "data" blocks are falling out of fashion, too. I would replace that "data" with an assignment statement:

comma = ','

or, if you want to preserve the hex expression/conversion:

comma = achar(Z'2C')

gsal






RE: gfortran: loading hex into DATA statement CHARACTER variables

(OP)
So I take it I will have to use the hex expression/conversion for non-ASCII characters such as

Trial=achar(Z'B6')

Thanks,
Clark

RE: gfortran: loading hex into DATA statement CHARACTER variables

Yes - you do know that you can output in unicode on the console as well on Linux.

CODE

program uniq
    use iso_fortran_env
    implicit none
    integer, parameter :: unicode  = selected_char_kind ('ISO_10646')
          
    character(kind=unicode,  len=30) :: chinese

    ! create a unicode string
    chinese = unicode_'Ni Hao ' &
              // char (int (z'4F60'), unicode) &
              // char (int (z'597D'), unicode) &
              // unicode_'3/4 ' & char(int(z'BE', unicode)

    ! Output in unicode          
    open (output_unit, encoding='UTF-8')
    write (*,*) trim(chinese)
end program uniq 

RE: gfortran: loading hex into DATA statement CHARACTER variables

Following from the previous snippet, you can also use

unicode_'\u00be'

instead of char(int(z'be'), unicode) for the 3/4 but the program must be compiled with -fbackslash otherwise it doesn't work.

RE: gfortran: loading hex into DATA statement CHARACTER variables

Hey, thanks for the unicode lesson.

By the way, I did not have to use the -fbadkslash flag (gfortran 4.8 or 6.3); but, noticed the "open(output_unit, enconding='UTF-8')" line is a must.

RE: gfortran: loading hex into DATA statement CHARACTER variables

If I compile a program with the following

print *, '\u00be'

without -fbackslash, I get

\u00be

With -fbackslash, I get

¾

RE: gfortran: loading hex into DATA statement CHARACTER variables

Oh, I understand now; like that much better.

CODE

program uni
    use iso_fortran_env
    implicit none
    integer, parameter :: u=selected_char_kind('ISO_10646')
    character(kind=u, len=30) :: chinese

    ! create a unicode string
    chinese = u_'Ni Hao: \u4F60 \u597D ; 3/4: \u00BE'

    ! Output in unicode
    open (output_unit, encoding='UTF-8')
    write (*,*) trim(chinese)
end program uni 

RE: gfortran: loading hex into DATA statement CHARACTER variables

You can also run this on windows but it is quite painful - you need to install the east asian fonts and change the code page (chcp 65001). It only works on the cmd prompt from Vista onwards. I spent about 3 hours trying to get it to work on XP but it just wasn't having it.

You can change it to the Chinese code page (chcp 54936 - not 936 as many articles/forums say) there is a spurious ? that appears after each character.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close