I am trying to find out how classes and modules work and am getting
the compile error as indicated. Could you please help me?
program main
!use animal_mod
implicit none
integer::age
age=18
animal_print_age(18)!statement not recognised
end program main
module animal_mod
implicit none
private
type,public::animal_class
integer,public::age
real,public::size
contains
procedure,public::print_age=>animal_print_age
end type animal_class
contains
subroutine animal_print_age(this)
class(animal_class),intent(inout)::this
print '("I am ",i0,"year(s)old")',this%age
end subroutine animal_print_age
end module animal_mod
I am etting this response to your suggestion
Call to missing routine - ANIMAL_PRINT_AGE at address 1a009550
Can you provide more details? See a working illustration below of what I posted.
Click here
C:\temp>type p.f
module animal_mod
implicit none
private
type,public::animal_class
integer,public::age
real,public::size
contains
procedure,public::print_age=>animal_print_age
end type animal_class
contains
subroutine animal_print_age(this)
class(animal_class),intent(inout)::this
print '("I am ",i0,"year(s)old")',this%age
end subroutine animal_print_age
end module animal_mod
program main
use animal_mod, only : animal_class
implicit none
type(animal_class) :: animal
animal%age=18
call animal%print_age()
end program main
C:\temp>gfortran -ffree-form p.f -o p.exe
C:\temp>p.exe
I am 18year(s)old
C:\temp>
Thank you for your help. Your code works well. Thank you also for your additional remarks.
As to your final remark: Allow me to inform you that I have read extensively on the subject of Fortran, but realise that there is still plenty to be learned. In doing so I am going meet with situations I cannot yet cope with and hope I will be helped by people as helpful, and well informed, as you. Thank you again.