public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Compile antiquated fortran?
@ 2023-07-27 17:36 Allin Cottrell
  2023-07-27 18:21 ` Steve Kargl
  2023-07-27 20:27 ` Jerry D
  0 siblings, 2 replies; 4+ messages in thread
From: Allin Cottrell @ 2023-07-27 17:36 UTC (permalink / raw)
  To: fortran

[-- Attachment #1: Type: text/plain, Size: 1312 bytes --]

I have old fortran source code (not my own work) for a specialized 
statistical program that I and others find quite useful.

A few years ago I was able to compile it on Linux using gfortran 
with std=legacy (and also cross-compile it for Windows an Mac). Now 
I'd like to rebuild it, but with recent gfortran (I've tried 12.2.1 
on Fedora and 13.1.1 on Arch) it's a no-go. I get lots of errors of 
the following sort:

ansub9.f:151:44:

   151 |    INTEGER ITYPE,INIT,LAM,IMEAN,IP,ID,Q,BP,BD,BQ,SQG,MQ,L,M,
       |                                       1
Error: Symbol ‘q’ at (1) already has basic type of REAL

I can understand this complaint. The code contains this sort of 
thing within a given subroutine:

        IMPLICIT  REAL*8 (A-H,O-Z)

then some lines later on:

        INTEGER ITYPE,INIT,LAM,IMEAN,P,D,Q,...

I guess the author was assuming that an explicit type-assignment 
just overrides an implicit one. Older gfortran apparently played 
along with that.

My question: Given that I'm already using -std=legacy, are there any 
other flags that I could add to get the code to compile?

(I know I could tackle this by renaming a bunch of variables, but in 
context that would be an extremely fiddly job.)

Thanks for any help.

-- 
Allin Cottrell
Department of Economics
Wake Forest University

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compile antiquated fortran?
  2023-07-27 17:36 Compile antiquated fortran? Allin Cottrell
@ 2023-07-27 18:21 ` Steve Kargl
  2023-07-27 20:27 ` Jerry D
  1 sibling, 0 replies; 4+ messages in thread
From: Steve Kargl @ 2023-07-27 18:21 UTC (permalink / raw)
  To: Allin Cottrell via Fortran

On Thu, Jul 27, 2023 at 01:36:46PM -0400, Allin Cottrell via Fortran wrote:
> I have old fortran source code (not my own work) for a specialized
> statistical program that I and others find quite useful.
> 
> A few years ago I was able to compile it on Linux using gfortran with
> std=legacy (and also cross-compile it for Windows an Mac). Now I'd like to
> rebuild it, but with recent gfortran (I've tried 12.2.1 on Fedora and 13.1.1
> on Arch) it's a no-go. I get lots of errors of the following sort:
> 
> ansub9.f:151:44:
> 
>   151 |    INTEGER ITYPE,INIT,LAM,IMEAN,IP,ID,Q,BP,BD,BQ,SQG,MQ,L,M,
>       |                                       1
> Error: Symbol ‘q’ at (1) already has basic type of REAL
> 
> I can understand this complaint. The code contains this sort of thing within
> a given subroutine:
> 
>        IMPLICIT  REAL*8 (A-H,O-Z)
> 
> then some lines later on:
> 
>        INTEGER ITYPE,INIT,LAM,IMEAN,P,D,Q,...
> 
> I guess the author was assuming that an explicit type-assignment just
> overrides an implicit one. Older gfortran apparently played along with that.
> 
> My question: Given that I'm already using -std=legacy, are there any other
> flags that I could add to get the code to compile?
> 
> (I know I could tackle this by renaming a bunch of variables, but in context
> that would be an extremely fiddly job.)
> 

I'm afraid we'll need to see some actual code.  The following compiles
without a problem.

       SUBROUTINE FOO(Q)
       IMPLICIT REAL*8 (A-H,O-Z)
       INTEGER Q
       Q = 1
       END

Hmmm, are DATA statements in the code?

       SUBROUTINE FOO
       IMPLICIT REAL*8 (A-H,O-Z)
       DATA Q/1/
       INTEGER Q
       Q = 1
       END

% gfortran12 -c -Wall a.f
a.f:4:16:

    4 |        INTEGER Q
      |                1
Error: Symbol 'q' at (1) already has basic type of REAL

gfortran is correct to complain here.  The DATA statement give
Q a REAL type due to the implicit statement.  Q can only appear
in a later declaration statement that re-affirms that type.

-- 
Steve

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compile antiquated fortran?
  2023-07-27 17:36 Compile antiquated fortran? Allin Cottrell
  2023-07-27 18:21 ` Steve Kargl
@ 2023-07-27 20:27 ` Jerry D
  2023-07-27 23:09   ` Allin Cottrell
  1 sibling, 1 reply; 4+ messages in thread
From: Jerry D @ 2023-07-27 20:27 UTC (permalink / raw)
  To: Allin Cottrell; +Cc: gfortran

On 7/27/23 1:36 PM, Allin Cottrell via Fortran wrote:
> I have old fortran source code (not my own work) for a specialized 
> statistical program that I and others find quite useful.
> 
> A few years ago I was able to compile it on Linux using gfortran with 
> std=legacy (and also cross-compile it for Windows an Mac). Now I'd like 
> to rebuild it, but with recent gfortran (I've tried 12.2.1 on Fedora and 
> 13.1.1 on Arch) it's a no-go. I get lots of errors of the following sort:
> 
> ansub9.f:151:44:
> 
>    151 |    INTEGER ITYPE,INIT,LAM,IMEAN,IP,ID,Q,BP,BD,BQ,SQG,MQ,L,M,
>        |                                       1
> Error: Symbol ‘q’ at (1) already has basic type of REAL
> 
> I can understand this complaint. The code contains this sort of thing 
> within a given subroutine:
> 
>         IMPLICIT  REAL*8 (A-H,O-Z)

Have you considered replacing the above line with IMPLICIT NONE and add 
explicit declarations as needed? The code will be safer in the long run.


Regards,

Jerry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compile antiquated fortran?
  2023-07-27 20:27 ` Jerry D
@ 2023-07-27 23:09   ` Allin Cottrell
  0 siblings, 0 replies; 4+ messages in thread
From: Allin Cottrell @ 2023-07-27 23:09 UTC (permalink / raw)
  To: Jerry D; +Cc: gfortran

[-- Attachment #1: Type: text/plain, Size: 1360 bytes --]

On Thu, 27 Jul 2023, Jerry D wrote:

> On 7/27/23 1:36 PM, Allin Cottrell via Fortran wrote:
>> I have old fortran source code (not my own work) for a specialized 
>> statistical program that I and others find quite useful.
>> 
>> A few years ago I was able to compile it on Linux using gfortran with 
>> std=legacy (and also cross-compile it for Windows an Mac). Now I'd like to 
>> rebuild it, but with recent gfortran (I've tried 12.2.1 on Fedora and 
>> 13.1.1 on Arch) it's a no-go. I get lots of errors of the following sort:
>> 
>> ansub9.f:151:44:
>>
>>    151 |    INTEGER ITYPE,INIT,LAM,IMEAN,IP,ID,Q,BP,BD,BQ,SQG,MQ,L,M,
>>        |                                       1
>> Error: Symbol ‘q’ at (1) already has basic type of REAL
>> 
>> I can understand this complaint. The code contains this sort of thing 
>> within a given subroutine:
>>
>>         IMPLICIT  REAL*8 (A-H,O-Z)
>
> Have you considered replacing the above line with IMPLICIT NONE and add 
> explicit declarations as needed? The code will be safer in the long run.

That would be a good solution, for sure, but I don't think I 
understand the original code well enough to make the required 
changes.

Meanwhile, though, Steve Kargl has suggested a nice fix which just 
involved moving one block of the code.

Allin Cottrell

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-27 23:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27 17:36 Compile antiquated fortran? Allin Cottrell
2023-07-27 18:21 ` Steve Kargl
2023-07-27 20:27 ` Jerry D
2023-07-27 23:09   ` Allin Cottrell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).