Fortran77 statement - character assignment

In summary, the programmer is trying to compile a program that was written in fortran 77, but when they use the IBM xlf compiler, it fails with a error that says "var=". They are not sure how ZFF is interpreted in the program or how to assign it a value. They ask for someone to help them and the person responds with a tutorial on how to start coding in fortran.
  • #1
nds
2
0
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:
program  test

      CHARACTER * 1
     +             var /ZFF/
	 
	 
	   write(*,*) "printing var=", var
	   return
end
 
Last edited:
Technology news on Phys.org
  • #2


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 let's 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.
 
  • #3


nds said:
Code:
      CHARACTER * 1
     +             var /ZFF/

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:
      CHARACTER * 1 var /ZFF/
 
  • #4


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)
 
  • #5


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!
 
  • #6


i need a fortran tutorial for begginers, kindly help
 

FAQ: Fortran77 statement - character assignment

What is a character assignment in Fortran77?

A character assignment in Fortran77 is a statement that allows you to assign a character value to a variable. This is useful for storing and manipulating text data in your program.

How do you assign a character value to a variable in Fortran77?

To assign a character value to a variable in Fortran77, you use the equals sign (=) followed by the character value enclosed in single quotes. For example, if you wanted to assign the character 'A' to a variable named letter, you would use the statement "letter = 'A'".

Can you assign multiple characters to a variable in Fortran77?

Yes, you can assign multiple characters to a variable in Fortran77 using a character array. This allows you to store and manipulate strings of text in your program. You can declare a character array by using the DIMENSION keyword followed by the name of the array and the number of elements in parentheses.

What happens if you try to assign a character value to a numeric variable in Fortran77?

If you try to assign a character value to a numeric variable in Fortran77, the compiler will generate an error. This is because Fortran77 is a strongly-typed language, meaning that variables must be declared with a specific data type and cannot be changed during execution.

Can you use mathematical operators in character assignments in Fortran77?

No, mathematical operators cannot be used in character assignments in Fortran77. These statements are used for assigning character values to variables, and arithmetic operations are not applicable to characters. If you need to perform calculations on character data, you will need to convert it to a numeric data type first.

Similar threads

Replies
27
Views
6K
Replies
2
Views
2K
Replies
2
Views
5K
Replies
4
Views
12K
Replies
16
Views
3K
Replies
4
Views
4K
Replies
2
Views
3K
Replies
9
Views
7K
Replies
11
Views
3K
Back
Top