Fortran Fortran77 statement - character assignment

AI Thread Summary
The discussion centers on porting a Fortran 77 application to Linux, specifically addressing an error encountered when using the g77 compiler. The issue arises from the initialization of a one-byte character variable "var" with the hexadecimal format specifier /ZFF/, which is not recognized by g77. The 'Z' is identified as a format delimiter for hexadecimal values, a feature that may not be supported in g77. Participants suggest that the original code may be misinterpreted due to the use of a continuation character ('+') in fixed-format Fortran, which could lead to compilation errors if the code is treated as free-format. It is recommended to combine the two lines into a single statement. Additionally, there is a possibility that "ZFF" could be a pre-processor constant defined elsewhere, which would require further investigation into the codebase. For standard Fortran compatibility, an alternative approach is proposed: using `var = char(255)` to assign the hexadecimal value directly.
nds
Messages
2
Reaction score
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


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.
 


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/
 


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)
 


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!
 


i need a fortran tutorial for begginers, kindly help
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

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