Fortran 90

7.2 Derived Types
  • User defines a new type from intrinsic and previously defined types

    Fortran has a number of intrinsic data types, such as integer, real, complex, logical, and character, for which operators and functions are defined in the language. An important new feature of Fortran90 is user defined data types. A user defined type, called a derived type, is built up from intrinsic types and previously defined user types. One simple use of this new capability is to bundle together various scalars that normally get passed together as arguments to procedures. For example, consider the following interface from a particle pushing subroutine written in FORTRAN77:

     SUBROUTINE push1(part,fx,qbm,dt,ek,np,idimp,nop,nx)
     INTEGER np, idimp, nop, nx
     REAL qbm, dt, ek, part(idimp,nop), fx(nx)
     ! rest of procedure
     RETURN
     END
    
  • Various components can be unified by a derived type...
     TYPE species_descriptor
       INTEGER :: number_of_particles
       REAL :: charge, charge_to_mass, kinetic_energy
     END TYPE species_descriptor
     TYPE (species_descriptor) electrons
    
    Notice that in this derived type, there are components of both integer and real type, so that this could not have been implemented with just an array in FORTRAN77.
  • Structure components are accessed using ``%'' notation
     electrons%charge = 1.6022e-19