!********************************************************************* ! Filename: struc_pointer.f ! Author: Eddie Baron ! Created at: Mon Jan 21 12:51:49 2008 ! Modified at: Thu Feb 14 13:41:24 2008 ! Modified by: Eddie Baron ! Version: 1.0 ! Description: variable length arrays in F95 !********************************************************************* c c c Here is an example of how to create variable length arrays c in fortran 90 c program struc_pointer c --------------------- implicit none c integer, parameter :: ndim=50,dp=kind(0.d0) type struc integer :: isize real (kind=dp), pointer :: p(:) => null() end type struc type(struc), allocatable :: array(:) c allocate(array(3)) c array(1)%isize = 2 array(2)%isize = 5 allocate(array(1)%p(array(1)%isize)) allocate(array(2)%p(array(2)%isize)) array(1)%p(:) = 1.d0 array(2)%p(:) = -1.d0 c c write(*,'(i5,2es11.3)')array(1)%isize,array(1)%p(:) write(*,'(i5,5es11.3)') array(2)%isize,array(2)%p(:) if(.not. associated(array(3)%p)) then write(*,*)'forgot to allocate array(3)' endif end