Difference between revisions of "Fortran3"
Jump to navigation
Jump to search
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:Pragmatic Programming]] | ||
+ | '''Fortran3: Object Oriented Fortran''' | ||
=Introduction= | =Introduction= | ||
− | Only a few | + | Only a few features of Fortran2003 are supported in gfortran version 4.3. gfortran-4.4 supports features such as the encapsulation of methods in user-derived types. |
=Encapsulation= | =Encapsulation= | ||
− | < | + | <source lang="Fortran"> |
module type_stuff | module type_stuff | ||
Line 68: | Line 70: | ||
− | </ | + | </source> |
Latest revision as of 11:58, 31 October 2011
Fortran3: Object Oriented Fortran
Introduction
Only a few features of Fortran2003 are supported in gfortran version 4.3. gfortran-4.4 supports features such as the encapsulation of methods in user-derived types.
Encapsulation
module type_stuff
implicit none
!! private?
integer, parameter :: maxstr = 50
type station
real :: frequency ! MHz
character(len=maxstr) :: name ! str
contains
procedure :: init => init_station
procedure :: str => str_station
end type station
contains
subroutine init_station(user_type, freq, stat_name)
implicit none
!! dummy args
type(station), intent(out :: user_type
real, intent(in) :: freq
character(len=maxstr), intent(in) :: stat_name
user_type%frequency = freq
user_type%name = stat_name
end subroutine init_station
subroutine str_station(user_type)
implicit none
!! dummy args
type station, intent(in) :: user_type
write(6,*) "station name: ", user_type%name
write(6,*) "frequency is: ", user_type%frequency
end subroutine str_station
end module type_stuff
! program encapsulation
! use type_suff
! implicit none
! type(station) :: radio2
! radio2%init(89.9,"radio 2")
! radio2%str
! end program encapsulation