Question

I'm attempting to compile some old Fortran code used at my job with g77. I'm new at Fortran and programming generally, and I'm trying to work through the all of the errors. This is one that g77 is returning:

afsirs.for: In subroutine `sw':
afsirs.for:1209: 
     DATA BLANK /'    '/
                 ^
Type disagreement between expressions at (?) and (^)

If I understand correctly, this is related to the Hollerith constant used in the code snippets below:

1209  DATA BLANK /'    '/

...

2727  DIMENSION ARRAY(22,54),IAXIS(13),YAXIS(6),Y(52),X(52),YSC(12)
      CHARACTER CTYPE*12
      DATA EYE, BLANK, DASH, PLUS, SYMBOL/1HI,1H ,1H-,1H+,1H*/
      DATA YSC/1,2.5,5,10,20,40,50,60,75,100,150,200/
...

2753   C...... ZERO ARRAY
       DO 100 I = 1,22
       DO 100 J = 1,54
  100  ARRAY(I,J) = BLANK

I've tried a few things, replacing the Holleriths with Character statements, etc, but I think I'm missing something. I would appreciate any suggestions on how to proceed.

EDIT---

 1209  DATA BLANK /'    '/

is part of a subroutine called 'SW' which calculates soil water availability. BLANK is then initialized in a plotting subroutine 'plot'.

Was it helpful?

Solution

if it helps, this data staement is initializing each of eye,blank,dash,plus and symbol to a single character hollerith:

  DATA EYE, BLANK, DASH, PLUS, SYMBOL/1HI,1H ,1H-,1H+,1H*/

equivalently (and IMO preferred for readability),

  DATA EYE/1HI/, BLANK/1H /, DASH/1H-/, PLUS/1H+/, SYMBOL/1H*/

Even im not old enough to remember if holleriths need to be declared integer or if implicit typing works. (Indeed that may be your problem if they are not declared a type at all g77 may need them to be declared integers)

In any case that is exactly the cause of your error, if you want to change BLANK to a character you need to remove it from the holerith data statement. (Type issues aside a symbol cannot appear in two DATA statements in the same program unit). Really, if you want to go down that path you should change all of them, in which case you'll have something like:

  character*1 EYE/'I'/, BLANK/' '/, DASH/'-'/, PLUS/'+'/, SYMBOL/'*'/

I'm not sure what (if any) syntax change is required where they are used in the code, but my guess is you should be prepared to set about changing every hollerith in the whole code since mixing them is likely asking for trouble.

At the very least you'll need to declare ARRAY as character: character*1 array(22,54)

EDIT---

tested this --- g77 does not care if/how you type declare the holleriths. real,integer,double precision, character or implict work just the same. the newer gfortran also works with any type, but with warnings about type conversion. gfortran actually prefers you declare them as characters of the correct length... (that is you get fewer warnings witha char declaration)

This suggests that as a first pass you might declare all your constants as characters, ie.

  character*1 EYE, BLANK, DASH, PLUS, SYMBOL
  DATA EYE, BLANK, DASH, PLUS, SYMBOL/1HI,1H ,1H-,1H+,1H*/

then set about upgrading to mordern character syntax.

OTHER TIPS

You initialize BLANK twice (on line 1209 and just after line 2727), and this is of course not permitted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top