Incompatible size of common block - pgf77

I am compiling a Fortran 77 code in Linux that uses the Cray pointer extension. The compilation does not complete properly, giving me the following error message:

PGFTN-S-0168-Incompatible size of common block ptrcom (default.F)

As I understand from another thread, Cray pointers in 32-bit are INTEGER4 and in 64-bit, they are INTEGER8. I am trying to compile on a 64-bit machine, so I get the impression this code (not written by me) was written for a 32-bit machine. From another thread, it seems I can use the -i8 option to set the default to INTEGER*8 or compile the program in 32 bits. I don’t believe it’s possible to do the latter without switching to the 32-bit PGI Workstation (which I had trouble getting to work on my machine), and the former seems to be a “quick fix” that can cause problems later.

I’m quite new to Fortran, C, and Linux, so while I kind of understand what’s happening on a conceptual level, the code is essential convulted gibberish to me. So if I say something blatantly obvious or incorrect, I apologize.

The file ‘default.F’ has a line stating to include ‘ptrcom.h’, which is a header file that consists entirely of lines like the following:

Code removed

How do I translate “Incompatible size of common block” into an error in the source code that I can fix? Please be patient with my responses and try to use layman’s terms where possible.

Note: I have tried using -i8, and this specific part of the compilation completes, but it creates additional errors later in the same compilation and the final executable doesn’t work.

There are no signs of any Cray pointers in the lines of code that you showed, so there is not much that can be said about their role.

Secondly, for a message to be issued about incompatible common block sizes, the compiler would have to have seen at least two instances of the same block (named or blank common blocks). You showed only a portion of the declaration of ONE common block.

If possible, please post the complete code (or, if that is too long, a link to some place where it is available), or construct a “reproducer” – a short piece of code which is enough to demonstrate the problem(s) described.

To cause the error to occur, I make an executable with the (abbreviated) makefile below.

Code removed

The compiler runs through a long list of .F files, getting stuck on default.F after executing
Code removed
which returns the aforementioned error,
Code removed
I took out the comments in the above makefile, so if you want me to include those or other code, like default.F or ptrcom.h please let me know. Thanks again for your patience.

Please provide the source code default.F and any files INCLUDEd in it.

Here is default.F in its entirety:

Code removed

Here is ptrcom.h:

Code removed

Here are the other include files referenced in default.F: Link removed

I have the files from “includefiles.zip – Dropbox”, but default.F contains INCLUDE statements for the following files that have not been provided:

bccommon.h globcom.h histcom.h intrcom.h magdgn.h mgcom.h mgpltcom.h modtcom.h paramcom.h pcommon.h remapcom.h rstcom.h

Offhand, I can make the following observation. In your program you have relied on implicit typing based on variable names. If any real variable is given implicit typing in one subprogram and explicit typing as DOUBLE PRECISION in another, that can cause the length of the common block containing that variable to be inconsistent. The same thing can happen if you have variables in a common block that are declared to be of character type in one program unit and given implicit type in another.

If you provide the missing .h files, I can take another look.

Sorry about that, I’ve added the rest of the header files. Same link.

There is still one more include file missing (celcptrs.h), but there is enough information that I can see to diagnose the problem.

Common block PTRCOM contains a number of variables with names of the form “kpnnn”. If ‘ptrcom.h’ is included but not ‘mgcom.h’ and ‘pcommon.h’, those variables are seen by the compiler as default integers, whereas if the latter two files have been included, those variables are seen as Cray pointers. When you compile for 64 bits, pointers are 8 bytes and integers are 4 bytes, causing a mismatch in common block length.

After adding “include ‘mgcom.h’” and “include ‘pcommon.h’” before “include ‘ptrcom.h’” in your block data subprogram, I found that the compiler no longer reports a common block size mismatch. More generally, if any common block contains variables that are Cray pointers, make sure that those variables have been declared as Cray pointers.

I urge you to consider adding “IMPLICIT NONE” and explicit type declarations in order to reveal any remaining inconsistencies, although I understand that it will take substantial effort. It is better to declare the types of variables before their names are used in common block declarations.

Didn’t receive the error like you said, thanks so much!

Everything after ‘default.F’ compiled fine, and since this was the last thing I needed to compile, hopefully I won’t need to modify any more source code. I will take your advice and make sure the Cray pointers are explicitly declared if I run into any more trouble.