Why is my Gfortran Code Not Compiling?

  • Context: Fortran 
  • Thread starter Thread starter RissaR
  • Start date Start date
  • Tags Tags
    Error Gfortran
Click For Summary

Discussion Overview

The discussion revolves around a user's issue with compiling a Fortran code, specifically related to the placement of subroutines and the structure of the program. The scope includes programming practices and error resolution in Fortran.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • The user reports that their Fortran code does not compile and provides specific error messages encountered during compilation.
  • Some participants suggest that subroutines should not be placed inside the main program section.
  • Others emphasize that the main program should perform useful tasks, such as calling the subroutines.
  • A participant indicates that they have resolved most errors but identifies the placement of subroutines as a significant issue.

Areas of Agreement / Disagreement

There is a general agreement among participants that the placement of subroutines is problematic, but the discussion does not reach a consensus on all aspects of the code structure.

Contextual Notes

Participants have not fully explored all error messages, and some assumptions about the intended functionality of the program remain unaddressed.

RissaR
Messages
5
Reaction score
0
I'm new to programming in Fortran, but have programmed for quite a while in C, Matlab, and Python.

This is my code. It's incomplete at the moment (the subroutines are unreferenced), though it should still compile, but won't.
Code:
PROGRAM bunkers
      IMPLICIT NONE

      SUBROUTINE lininterp(ulist,vlist,hlist,targetlvl,u,v)
            IMPLICIT NONE

            !Dummy argument declarations
            REAL, INTENT(IN) :: ulist,vlist,hlist,targetlvl
            REAL, INTENT(OUT) :: u,v

            !Local variable declaration 
            REAL :: spacing

            spacing = hlist(2) - hlist(1)
            DO i=1,SIZE(hlist)
                  IF (targetlvl>hlist(i) .and. targetlvl < hlist(i+1)):
                        u=(ulist(i+1)-ulist(i))/spacing*(targetlvl-hlist(i))+ulist(i)
                        v=(vlist(i+1)-vlist(i))/spacing*(targetlvl-hlist(i))+vlist(i)
                  END IF
            END DO
            RETURN
      END SUBROUTINE lininterp

      SUBROUTINE meanwind(ulist,vlist,hlist,blayer,tlayer,meanwind)
            IMPLICIT NONE

            !Dummy argument declarations
            REAL, INTENT(IN) :: ulist,vlist,hlist,blayer,tlayer
            REAL, INTENT(OUT) :: meanwind

            !Local variable declaration
            REAL :: vmod, i, j, umodmean, vmodmean
            REAL, ALLOCATABLE, DIMENSION(:) :: tailvect,headvect
            REAL, DIMENSION(2) ::   vector,modheadvect,vect,modmean, meanwind
            REAL, DIMENSION (2,2) :: rotation,counter

            !Find head and tail wind vectors
            DO i=1,SIZE(hlist)
                  IF (hlist(i) .eq. blayer) THEN
                        ALLOCATE(tailvect(2))
                        tailvect = (/ ulist(i),vlist(i) /)
                  ELSE IF (hlist(i) .eq. tlayer) THEN
                        ALLOCATE(headvect(2))
                        headvect = (/ ulist(i), vlist(i) /)
                  ELSE IF (hlist(i) >= tlayer) THEN
                        EXIT
                  ELSE
                        EXIT
                  END IF
            END DO

            IF (.not. allocated(tailvect)) 
                  CALL lininterp(ulist,vlist,hlist,blayer,u,v)
                  tailvect = (/ u,v /)
            END IF

            IF (.not. allocated(headvect))
                  CALL lininterp(ulist,vlist,hlist,tlayer,u,v)
                  headvect = (/ u,v /)
            END IF
            RETURN 
      END SUBROUTINE meanwind     
      STOP
END PROGRAM bunkers

Output:
Code:
Larissas-MacBook-Pro:Sounding_Codes Larissa$ gfortran -o idmethod idmethod.f90
idmethod.f90:4.6:

      SUBROUTINE lininterp(ulist,vlist,hlist,targetlvl,u,v)
     1
Error: Unclassifiable statement at (1)
idmethod.f90:5.25:

            IMPLICIT NONE
                        1
Error: Duplicate IMPLICIT NONE statement at (1)
idmethod.f90:14.27:

            spacing = hlist(2) - hlist(1)
                          1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'hlist' at (1)
idmethod.f90:16.37:

                  IF (targetlvl>hlist(i) .and. targetlvl < hlist(i+1)):
                                    1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'hlist' at (1)
idmethod.f90:17.32:

                        u=(ulist(i+1)-ulist(i))/spacing*(targetlvl-hlist(i))+ul
                               1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'ulist' at (1)
idmethod.f90:18.32:

                        v=(vlist(i+1)-vlist(i))/spacing*(targetlvl-hlist(i))+vl
                               1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'vlist' at (1)
idmethod.f90:19.21:

                  END IF
                    1
Error: Expecting END DO statement at (1)
idmethod.f90:22.7:

    END SUBROUTINE lininterp
      1
Error: Expecting END PROGRAM statement at (1)
idmethod.f90:24.6:

      SUBROUTINE meanwind(ulist,vlist,hlist,blayer,tlayer,meanwind)
     1
Error: Unclassifiable statement at (1)
idmethod.f90:25.25:

            IMPLICIT NONE
                        1
Error: Unexpected IMPLICIT NONE statement at (1)
idmethod.f90:28.37:

            REAL, INTENT(IN) :: ulist,vlist,hlist,blayer,tlayer
                                    1
Error: Symbol 'ulist' at (1) already has basic type of REAL
idmethod.f90:29.41:

            REAL, INTENT(OUT) :: meanwind
                                        1
Error: Unexpected data declaration statement at (1)
idmethod.f90:32.50:

            REAL :: vmod, i, j, umodmean, vmodmean
                                                 1
Error: Unexpected data declaration statement at (1)
idmethod.f90:33.64:

            REAL, ALLOCATABLE, DIMENSION(:) :: tailvect,headvect
                                                               1
Error: Unexpected data declaration statement at (1)
idmethod.f90:34.77:

          REAL, DIMENSION(2) ::   vector,modheadvect,vect,modmean, meanwind
                                                                          1  
Error: Unexpected data declaration statement at (1)
idmethod.f90:35.53:

            REAL, DIMENSION (2,2) :: rotation,counter
                                                    1
Error: Unexpected data declaration statement at (1)
idmethod.f90:39.27:

                  IF (hlist(i) .eq. blayer) THEN
                          1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'hlist' at (1)
idmethod.f90:40.41:

                        ALLOCATE(tailvect(2))
                                        1
Error: Syntax error in ALLOCATE statement at (1)
idmethod.f90:41.43:

                        tailvect = (/ ulist(i),vlist(i) /)
                                          1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'ulist' at (1)
idmethod.f90:42.32:

                  ELSE IF (hlist(i) .eq. tlayer) THEN
                               1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'hlist' at (1)
idmethod.f90:43.41:

                        ALLOCATE(headvect(2))
                                        1
Error: Syntax error in ALLOCATE statement at (1)
idmethod.f90:44.43:

                        headvect = (/ ulist(i), vlist(i) /)
                                          1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'ulist' at (1)
idmethod.f90:45.32:

                  ELSE IF (hlist(i) >= tlayer) THEN
                               1
Error: PROCEDURE attribute conflicts with INTENT attribute in 'hlist' at (1)
idmethod.f90:47.22:

                  ELSE
                     1
Error: Unexpected ELSE statement at (1)
idmethod.f90:49.21:

                  END IF
                    1
Error: Expecting END DO statement at (1)
Fatal Error: Error count reached limit of 25.

Any ideas?
 
Technology news on Phys.org
Don't put the subroutines inside the program section.

Also, you main program should actually do something useful, like call the subroutines.

Your code should look something like this:
Code:
PROGRAM bunkers
  ! declarations 
  ! statements
END PROGRAM bunkers

SUBROUTINE lininterp( ... )
  ! declarations 
  ! statements
END SUBROUTINE lininterp

SUBROUTINE meanwind( ... )
  ! declarations 
  ! statements
END SUBROUTINE meanwind
 
Mark44 said:
Don't put the subroutines inside the program section.

Also, you main program should actually do something useful, like call the subroutines.

Your code should look something like this:
Code:
PROGRAM bunkers
  ! declarations 
  ! statements
END PROGRAM bunkers

SUBROUTINE lininterp( ... )
  ! declarations 
  ! statements
END SUBROUTINE lininterp

SUBROUTINE meanwind( ... )
  ! declarations 
  ! statements
END SUBROUTINE meanwind

I have successfully fixed most of the other errors, but this was the biggest problem I was running in to. Thanks so much! :)
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 10 ·
Replies
10
Views
6K
  • · Replies 16 ·
Replies
16
Views
2K