3.4 Modules in Fortran 89
proton_particle_descript
INTEGER, DIMENSION(:), POINTER, PUBLIC :: itzp
END TYPE proton_sp_orbit
To initialize the proton_sp_orbit TYPE, we could now define anew function
SUBROUTINE allocate_proton_array(this_array,n)
TYPE (single_particle_descript), INTENT(INOUT) :: this_array
INTEGER , INTENT(IN) :: n
IF (ASSOCIATED (this_array%itzp) ) &
DEALLOCATE(this_array%itzp)
CALL allocate_sp_array(this_array,n)
this_array%itzp(i)=0
END SUBROUTINE allocate_proton_array
and
SUBROUTINE dellocate_proton_array(this_array)
TYPE (single_particle_descript), INTENT(INOUT) :: this_array
DEALLOCATE(this_array%itzp)
CALL deallocate_sp_array(this_array)
END SUBROUTINE deallocate_proton_array
and we could define a MODULE
MODULE proton_class
USE single_particle_orbits
TYPE proton_sp_orbit
TYPE (single_particle_orbits), PUBLIC :: &
proton_particle_descript
INTEGER, DIMENSION(:), POINTER, PUBLIC :: itzp
END TYPE proton_sp_orbit
INTERFACE allocate_proton
MODULE PROCEDURE allocate_proton_array, read_proton_array
END INTERFACE
INTERFACE deallocate_proton
MODULE PROCEDURE deallocate_proton_array
END INTERFACE
.....
CONTAINS
....
! various procedure
END MODULE proton_class
PROGRAM with_just_protons
USE proton_class
....
TYPE (proton_sp_orbit ) :: proton_data
CALL allocate_proton(proton_data)
....
CALL deallocate_proton_array(prton_data)
We have a written a new class which contains the data of the base class and all the pro-
cedures of the base class have been extended to work with the new derived class. Interface
statements have to be used to give the procedure uniform names.
We can now derive further classes for other particle types such as neutrons, hyperons etc
etc.