1 / 15

Support for OOP in Fortran (90 and some 95)

Support for OOP in Fortran (90 and some 95). By Samuel Robinson. Support for OOP in Fortran(90). ~General Characteristics -Backwards compatible with Fortran 77 -Classes are supported (keyword: module) -Supports static and dynamic binding (bdstatic, bdynamic) and heap dynamic

Télécharger la présentation

Support for OOP in Fortran (90 and some 95)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Support for OOP in Fortran (90 and some 95) By Samuel Robinson

  2. Support for OOP in Fortran(90) ~General Characteristics -Backwards compatible with Fortran 77 -Classes are supported (keyword: module) -Supports static and dynamic binding (bdstatic, bdynamic) and heap dynamic variables -Supports polymorphism /dynamic binding (Fortran 95)

  3. Support for OOP in Fortran (90) Inheritance -Single – only one member inherits -Selective Single – specifies what to inherit -Single with Local Renaming -Multiple Selective

  4. Single Inheritance Module new_class_name Use base_class_name !make new attribute declarations Contains !declare new member definitions End module new_class_name

  5. Selective Single Inheritance Module new_class_name Use base_class_name; only: list_of_entities !declare new attributes Contains !declare new member definitions End module new_class_name

  6. Single Inheritance with Local Renaming Module new_class_name Use base_class name; local_name=> base_entity_name !new attribute declarations Contains !new member declarations End module new_class_name

  7. Multiple Selective Inheritance with Renaming Module new_class_name Use base1_class_name Use base2_class_name Use base3_class_name; list of entities Use base4_class_name, local_name => base entity name !new member definitions Contains !new member definitions End module new_class_name

  8. Examples module student !declares student class INTEGER idnumber end module student module class !declares student class INTEGER classnumber CHARACTER description end module class module student_information !new class use student use class, only: classnumber end module student_information

  9. Examples module student INTEGER idnumber contains subroutine grade grade = average*4 end subroutine grade end module student module class use student, classnumber =>idnumber end module class

  10. Public and Private Source: IncyWincy.com module Room_class implicit none public type Room private integer :: roomNumber logical, dimension(4) :: walls end type Room integer, parameter :: NORTH =1, SOUTH = 2.. contains

  11. This Source: IncyWincy.com To make sure that a type is given the correct procedure, an object of that type needs to be passed. To do this, give the object the name “this” and make it first argument Ex: Subroutine new_Room (this, roomNumber, N,S, E, W) type(Room) :: this ...

  12. Support for OOP in Fortran(95) Dynamic Binding – lets a single object refer to any member of an inheritance hierarchy and allows a procedure to resolve at run time whch object is being referred to Necessary : id mechanism to keep track of the class of the object and method lookup to select the right procedure to execute

  13. Polymorphic Type Source: rsimplifiedRT.cwk type poly_stopwatch private type(stopwatch), pointer :: s Type (parallel_stopwatch), pointer :: p end type poly_stopwatch

  14. Use poly_stopwatch_class type(stopwatch) s type(parallel_stopwatch) p type(poly_stopwatch) sw call new_stopwatch(s) call new_parallel_stopwatch(p) sw = poly(s) call split(sw, 'bar') call bar() call split(sw, 'bar') call report(sw, 6) sw = poly(p) call split(sw, 'foo') call foo() call split(sw, 'foo') call report(sw, 6)

  15. Evaluation ~Fortran is object based, but not object oriented. -Inheritance and run time polymorphism are not directly supported, rather they are emulated. -Different, yet the similar.

More Related