Why is my Gfortran Code Not Compiling?

In summary: It's important to structure your code properly so that it is easily readable and understandable. Keep up the good work!
  • #1
RissaR
5
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
  • #2
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
 
  • #3
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! :)
 
  • #5


I would recommend carefully reviewing and debugging your code to address the compilation errors. Some possible things to check include:

1. Make sure all variables are properly declared with their correct data types and intent attributes. The error messages indicate conflicts with intent attributes, so double check that they are consistent.

2. Check for any duplicate statements, such as the duplicate IMPLICIT NONE statement in line 5.

3. Make sure all loops have the correct syntax, including proper use of END DO statements.

4. Check for any syntax errors, such as missing commas or parentheses.

5. Make sure all subroutines are properly referenced and called within the main program.

6. Consider using a debugger or printing out intermediate values to help identify where the errors are occurring.

7. If you are still having trouble, consider seeking help from a more experienced Fortran programmer or consulting online resources for troubleshooting common Fortran errors.
 

Related to Why is my Gfortran Code Not Compiling?

1. What is a Gfortran compiling error?

A Gfortran compiling error is a type of error that occurs when attempting to compile code written in the Fortran programming language using the Gfortran compiler. This error can occur due to syntax errors, missing libraries, or incompatible code.

2. How can I fix a Gfortran compiling error?

To fix a Gfortran compiling error, you can try to identify the specific error message and address the issue accordingly. This may involve correcting syntax errors, installing missing libraries, or updating your code to be compatible with the Gfortran compiler.

3. Why am I getting a Gfortran compiling error?

There are several reasons why you may be getting a Gfortran compiling error. Some common causes include typos or syntax errors in your code, missing libraries or dependencies, and incompatible code with the Gfortran compiler.

4. Can I prevent Gfortran compiling errors?

While it may not be possible to prevent all Gfortran compiling errors, there are steps you can take to reduce the likelihood of encountering them. This includes writing clean and error-free code, regularly updating your compiler and libraries, and testing your code frequently.

5. Where can I find more resources for troubleshooting Gfortran compiling errors?

If you are encountering Gfortran compiling errors, you can find more resources for troubleshooting by checking the documentation for the Gfortran compiler, searching online forums and communities, or consulting with other Fortran programmers for assistance.

Similar threads

  • Programming and Computer Science
Replies
5
Views
5K
  • Programming and Computer Science
Replies
4
Views
951
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
9
Views
8K
  • Programming and Computer Science
Replies
4
Views
13K
  • Programming and Computer Science
Replies
10
Views
5K
  • Programming and Computer Science
Replies
3
Views
2K
Back
Top