<STAT= Example Program>
Program stat_example
Real,Allocatable :: a(:)
Call newmem(100)
Print 1,Size(a)
1 Format(1X,'Got memory: ',I0,' elements')
Call newmem(1000)
Print 1,Size(a)
Print *,'Finished'
Contains
Subroutine newmem(n)
Integer,Intent(In) :: n
Integer stat
Character(100) error
Deallocate(a,Stat=stat,Errmsg=error)
If (stat/=0) Then
Print *,'Deallocation error: ',Trim(error),'; continuing'
End If
If (Allocated(a)) Stop 'Cannot continue - still allocated'
Allocate(a(n),Stat=stat,Errmsg=error)
If (stat/=0) Then
Print *,Trim(error)
Stop 'Cannot continue - allocation failed'
End If
End Subroutine
End Program
■ Execution Results
Deallocation error: Allocatable variable is not allocated; continuing
Got memory: 100 elements
Got memory: 1000 elements
Finished