File: pointer_alloc.f90

package info (click to toggle)
ftnchek 3.3.1-7
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,684 kB
  • sloc: ansic: 21,908; fortran: 5,748; yacc: 4,071; sh: 3,035; makefile: 895; lisp: 322; f90: 118; perl: 76
file content (28 lines) | stat: -rw-r--r-- 676 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
! Example of allocating and using an array via a pointer

program pointer_alloc
  real, pointer, dimension(:, :) :: A
  integer :: M, N
  integer :: alloc_err, dealloc_err

  read *, M, N
  allocate ( A(M, N) , stat=alloc_err) 
  if( alloc_err /= 0 ) then
     print *, "Error allocating real array of size", &
          M, "x", N
  else
     read *, A
     print *, A
     deallocate (A, stat = dealloc_err)
     if( dealloc_err /= 0 ) then
        print *, "Error deallocating array"
     else
        print *, "Array deallocated"
     end if
  end if

  if( associated(A) ) then
     print *, "Pointer is still associated"
     nullify(A)
 end if
end program pointer_alloc