88 3 Numerical differentiation and interpolation
CASE ('proton&neutron')
CALL read_nuclear_sp_data
END SELECT
END SUBROUTINE single_particle_data
END MODULE single_particle_orbits
The module ends with theEND MODULE single_particle_orbitsstatement. We have defined
a public variable TYPE, PUBLIC :: single_particle_descriptwhich plays the same role
as thestructtype in C++. In addition we have defined several member functions which
operate on various arrays and variables.
An example of a function which uses this module is given belowand the module is accessed
via theUSE single_particle_orbitsstatement.
!
PROGRAM main
....
USE single_particle_orbits
IMPLICIT NONE
INTEGER :: i
READ(5,) all_orbit%total_orbits
IF( all_orbit%total_orbits <= 0 ) THEN
WRITE(6,)'WARNING, NO ELECTRON ORBITALS'; STOP
ENDIF
! Setup all possible orbit information
! Allocate space in heapforall single-particle data
CALL allocate_sp_array(all_orbit,all_orbit%total_orbits)
! Read electron single-particle data
DO i=1, all_orbit%total_orbits
READ(5,*) all_orbit%nn(i),all_orbit%ll, &
all_orbit%jj(i),all_orbit%spin(i), &
all_orbit%orbit_status(i), &
all_orbit%model_space(i), all_orbit%e(i)
ENDDO
! further instructions
.......
! deallocate all arrays
CALL deallocate_sp_array(all_orbit)
END PROGRAM main
Inheritance allows one to create a hierarchy of classes in which the base class contains the
common properties of the hierarchy and the derived classes can modify and specialize these
properties. Specifically, a derived class contains all the class member functions of the base
class and can add new ones. Further, a derived class containsall the class member functions
of the base class and can modify them or add new ones. The valuein using inheritance is to
avoid duplicating code when creating classes which are similar to one another. Fortran does
not support inheritance, but several features can be faked in Fortran! Consider the following
declarations:
TYPE proton_sp_orbit
TYPE (single_particle_orbits), PUBLIC :: &