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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
FTNCHEK Version 3.3 November 2004
File pointer_alloc.f90:
1 ! Example of allocating and using an array via a pointer
2
3 program pointer_alloc
4 real, pointer, dimension(:, :) :: A
5 integer :: M, N
6 integer :: alloc_err, dealloc_err
7
8 read *, M, N
9 allocate ( A(M, N) , stat=alloc_err)
10 if( alloc_err /= 0 ) then
11 print *, "Error allocating real array of size", &
12 M, "x", N
13 else
14 read *, A
15 print *, A
16 deallocate (A, stat = dealloc_err)
17 if( dealloc_err /= 0 ) then
18 print *, "Error deallocating array"
19 else
20 print *, "Array deallocated"
21 end if
22 end if
23
24 if( associated(A) ) then
25 print *, "Pointer is still associated"
26 nullify(A)
27 end if
28 end program pointer_alloc
Module POINTER_ALLOC: prog
External subprograms referenced:
ASSOCIATED: intrns
Variables:
Name Type Dims Name Type Dims Name Type Dims Name Type Dims
A real 2 ALLOC_ERR intg DEALLOC_ERR intg M intg
N intg
Warning in module POINTER_ALLOC: Variables used before set
ALLOC_ERR used at line 10; never set
DEALLOC_ERR used at line 17; never set
I/O Operations:
Unit ID Unit No. Access Form Operation Line
* SEQ FMTD PRINT 11 15 18 20 25
* SEQ FMTD READ 8 14
0 syntax errors detected in file pointer_alloc.f90
1 warning issued in file pointer_alloc.f90
|