Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with gfortran compiler.

Status
Not open for further replies.
Joined
Mar 21, 2012
Messages
1
Location
NO
I am new to fortran programming, and now I am strugling on how to compile a class using gfortran compiler. If I example try to compile the class class_circle.f90(see under, taken from I write: "gfortran -c class_circle.f90" in terminal window. When I do this I get the error given below.
I would really appreciate it if someone knows how to do this and can tell me!


Error message:
-----------------------------------------------------------

cyberclown@jern ~/GEO1331/testing_with_progs $ gfortran -c class_circle.f90
In file class_circle.f90:8

contains
1
Error: Unexpected CONTAINS statement at (1)
In file class_circle.f90:9

procedure :: area => circle_area
1
Error: Unclassifiable statement at (1)
In file class_circle.f90:10

procedure :: print => circle_print
1
Error: Unclassifiable statement at (1)
In file class_circle.f90:14

class(Circle), intent(in) :: this
1
Error: Unclassifiable statement at (1)
In file class_circle.f90:16

area = pi * this%radius**2
1
Error: Unclassifiable statement at (1)
In file class_circle.f90:20

class(Circle), intent(in) :: this
1
Error: Unclassifiable statement at (1)
In file class_circle.f90:22

area = this%area() ! Call the type-bound function
1
Error: Unclassifiable statement at (1)
In file class_circle.f90:23

print *, 'Circle: r = ', this%radius, ' area = ', area
1
Error: Syntax error in PRINT statement at (1)
In file class_circle.f90:19

subroutine circle_print(this)
1
Error: Symbol 'this' at (1) has no IMPLICIT type
In file class_circle.f90:13

function circle_area(this) result(area)
1
Error: Symbol 'this' at (1) has no IMPLICIT type





This is the class:

------------------------------------------------------

module class_Circle
implicit none
private
real :: pi = 3.1415926535897931d0 ! Class-wide private constant

type, public :: Circle
real :: radius
contains
procedure :: area => circle_area
procedure :: print => circle_print
end type Circle
contains
function circle_area(this) result(area)
class(Circle), intent(in) :: this
real :: area
area = pi * this%radius**2
end function circle_area

subroutine circle_print(this)
class(Circle), intent(in) :: this
real :: area
area = this%area() ! Call the type-bound function
print *, 'Circle: r = ', this%radius, ' area = ', area
end subroutine circle_print
end module class_Circle



Main program:
----------------------------------------
program circle_test
use class_Circle
implicit none

type(Circle) :: c ! Declare a variable of type Circle.
c = Circle(1.5) ! Use the implicit constructor, radius = 1.5.
call c%print ! Call the type-bound subroutine
end program circle_test
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top