Results 1 to 4 of 4

Thread: gfortran will not compile .f

  1. #1
    Join Date
    May 2009
    Beans
    9

    Red face gfortran will not compile .f

    hello everybody,

    i am trying to compile some fortran code using gfortran but i have unfortunately run into some issues.

    using:

    Code:
    program test
    write(*,*)'Hello world!'
    end program test
    i can compile and run the code if i end it with a .f90:

    gfortran -o test.exe test.f90
    ./test.exe


    the output i get is:

    Code:
    Hello world!
    however, when i try to end the file using .f:

    gfortran -o test.exe test.f

    the output i get is:

    Code:
    test.f:1.1:
    
    program test                                                            
     1
    Error: Non-numeric character in statement label at (1)
    test.f:1.1:
    
    program test                                                            
     1
    Error: Unclassifiable statement at (1)
    test.f:2.1:
    
    write(*,*)'Hello world!'                                                
     1
    Error: Non-numeric character in statement label at (1)
    test.f:2.1:
    
    write(*,*)'Hello world!'                                                
     1
    Error: Unclassifiable statement at (1)
    test.f:3.1:
    
    end program test
     1
    Error: Non-numeric character in statement label at (1)
    test.f:3.1:
    
    end program test
     1
    Error: Unclassifiable statement at (1)
    i get the aforementioned error message and gfortran will not compile the .f file. for some reason .f90 works but .f doesn't. i need both types to work (and do not see why it shouldn't as i have had this work on windows before but not on ubuntu).

    can anybody help me please?

    thank you.

  2. #2
    Join Date
    May 2009
    Beans
    9

    Re: gfortran will not compile .f

    update: when i indent my .f code 3 times (~6 spaces) then:

    Code:
    gfortran -o test.exe test.f
    ./test.exe
    works.



    does this mean i have to indent every single program 3 times before even beginning to write? what happens if i have a program which i would like to open that is already written and several hundred lines long?
    Last edited by nutu; May 20th, 2009 at 02:51 PM.

  3. #3
    Join Date
    Apr 2009
    Beans
    1,173

    Re: gfortran will not compile .f

    According to man gfortran:

    Code:
    -ffree-form
    -ffixed-form
    Specify the layout used by the source file.  The free form layout was introduced in Fortran 90.  Fixed form was traditionally used in older Fortran programs.  When neither option is specified, the source form is determined by the file extension.
    So I guess a .f90 extension allows free use of whitespace and .f requires strict use, but the gfortran -ffreeform option will permit free use in a .f source file.

  4. #4
    Join Date
    May 2009
    Beans
    9

    Re: gfortran will not compile .f

    Quote Originally Posted by StuartN View Post
    According to man gfortran:

    Code:
    -ffree-form
    -ffixed-form
    Specify the layout used by the source file.  The free form layout was introduced in Fortran 90.  Fixed form was traditionally used in older Fortran programs.  When neither option is specified, the source form is determined by the file extension.
    So I guess a .f90 extension allows free use of whitespace and .f requires strict use, but the gfortran -ffreeform option will permit free use in a .f source file.
    thank you so much. now when i write:

    Code:
    gfortran -ffree-form -o test.exe test.f
    it compiles!!!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •