Fortran3

From SourceWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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