Fortran Why is my Gfortran Code Not Compiling?

  • Thread starter Thread starter RissaR
  • Start date Start date
  • Tags Tags
    Error Gfortran
AI Thread Summary
The discussion focuses on a Fortran programming issue where the user is trying to compile a code that includes subroutines for linear interpolation and mean wind calculation. The user encounters multiple compilation errors, primarily due to incorrect placement of subroutines within the main program and conflicting attributes for dummy arguments. Suggestions include moving the subroutines outside of the main program block and ensuring the main program performs meaningful operations, such as calling these subroutines. The user reports progress in resolving other errors but identifies this structural issue as the most significant hurdle.
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! :)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
4
Views
2K
Replies
1
Views
3K
Replies
2
Views
3K
Replies
16
Views
2K
Back
Top