Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran77 statement - character assignment

  1. Nov 21, 2011 #1

    nds

    User Avatar

    fortran77 statement -- character assignment

    Hi, I am porting an application written in fortran 77 to linux. The following code compiles well with IBM xlf compiler on AIX. However, when I use g77, it fails with the following error:


    foo.f:6:
    + var /ZFF/
    ^
    Invalid declaration of or reference to symbol `zff' at (^) [initially seen at (^)]

    I am not sure how ZFF is internally interpreted. I also tried using DATA var /ZFF/ (not that there are no singl quotes around ZFF.) but it doesn't work with g77

    Can someone please help? Thank you.

    Code (Text):

    program  test

          CHARACTER * 1
         +             var /ZFF/
         
         
           write(*,*) "printing var=", var
           return
    end
     
    Last edited: Nov 21, 2011
  2. jcsd
  3. Nov 21, 2011 #2
    Re: fortran77 statement -- character assignment

    Your program is trying to initialize a one-byte character variable "var" using hexidecimal format. The 'Z' in the data assigment (/ZFF/) is the format deliminator for hexidecimal that lets the program know that the following should be interpretated as HEX.

    I can't remmeber if g77 supports this or not. If not, your going to have to resort to some work-arounds.
     
  4. Nov 21, 2011 #3

    jtbell

    User Avatar

    Staff: Mentor

    Re: fortran77 statement -- character assignment

    These two lines look like they're intended to be a single statement, split (for some unknown reason) into two lines. In traditional fixed-format FORTRAN, the '+' in position 6 indicates that the second line is a "continuation" of the preceding line.

    In fixed-format, the compiler discards the '+' after interpreting it as a continuation character. I suspect that you're compiling the program in free-format, in which the '+' would not be treated as a continuation character but instead as an arithmetic '+'.

    Try collapsing the two lines together:

    Code (Text):

          CHARACTER * 1 var /ZFF/
     
     
  5. Nov 21, 2011 #4

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    Re: fortran77 statement -- character assignment

    I'm pretty sure using Z to mean hexadecimal data is non-standard fortran. I used to use IBM hardware quite a lot, but and I don't remember that feature.

    Another possibility is that ZFF is a pre-processor constant that is defined somewhere else (maybe in the makefile, not in the source code). In that case, its value could be anything.

    My next move would be to read the code and see what "var" is used for. It seems a fairly "anonymous" sort of variable name...

    FWIW you can assign var to hexadecimal FF in standard fortran with
    CHARACTER*1 var
    var = char(255)
     
  6. Nov 22, 2011 #5

    nds

    User Avatar

    Re: fortran77 statement -- character assignment

    AlephZero , TheoMcCloskey -- thank you very much! Now I understand that Z is the format delimiter and I think var = char(255) is exactly what I need. Thank you again!
     
  7. Oct 4, 2012 #6
    Re: fortran77 statement -- character assignment

    i need a fortran tutorial for begginers, kindly help
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran77 statement - character assignment
Loading...