Hello,
I am trying to create an array of Objects in FORTRAN but I cannot seem to find a way of doing this. I just want to know if this is possible as google did not really encouraged me. I have seen some older posts in this forum but they were old so I thought I should bring this into your attention again.
Below there is an example of my code:
module substance_init implicit none type substance real :: property1 ! diffusion coefficient logical :: filled ! variable to tell if cell is filled with substance or not real :: length real :: width contains procedure :: initialize => initSubstance procedure, public :: print ! allow access to print type-bound procedure end type substance type, EXTENDS (substance) :: cyto contains procedure :: initialize => initcyto end type cyto type, EXTENDS (cyto) :: leaks end type leaks CONTAINS Subroutine initSubstance (this,property1,filled,length,width) !initialise shape objects class(substance) :: this !polymorphic dummy argument real :: property1 logical :: filled real, optional :: length ! ignored for substance real, optional :: width ! ignored for substance end subroutine initSubstance Subroutine initcyto (this,property1,filled,length,width) !initialise cyto objects class(cyto) :: this real :: property1 logical :: filled real, optional :: length real, optional :: width end subroutine initcyto subroutine print(this) class (substance) :: this print *, '' ,this%property1, this%filled,this%length,this%width end subroutine end module substance_init Program SC_2D use substance_init use array integer, parameter :: gridsize = 10 ! cyto layers integer :: i, j, generation=0 type(substance) :: sub type(cyto) :: cor1 type(cyto) :: cor2 type(cyto) :: cor3 type(cyto) :: cor4 type(leaks) :: lip sub = substance (0.0012345567, .false.,0,0) cor1 = cyto ( 0.00000002, .true. ,0.001,0.001) cor2 = cyto ( 0.00000005, .true. ,0.001,0.001) cor3 = cyto ( 0.00000009, .true. ,0.001,0.001) cor4 = cyto ( 0.0000001, .true. ,0.001,0.001) lip = leaks( 0.0000001, .true. ,0.00001,0.000001) call sub%print() call cor1%print() call cor2%print() call cor3%print() call cor4%print() call lip%print() write(*,'(" Enter to exit")') read (*,*) END PROGRAM SC_2D
So as you can see I created some objects like sub, cor1, cor2, cor3, cor4 and lip , initialized them and now I wish to arrange them in a 2D array and be able to acces them efficiently. Is there a way of doing this in fortran ? ( A small example would be perfect)