Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28440 Discussions

deallocate type variable only one field

diedro
Beginner
312 Views

Dear all,

I have the following type variable:

  TYPE::tMACROCELLNODE
   INTEGER                                        :: nElem
   INTEGER                                        :: AA
   INTEGER                                        :: IDnode
   INTEGER                                        :: IDmCell
   REAL(KIND=8),ALLOCATABLE,DIMENSION(:)          :: WFX
   REAL(KIND=8),ALLOCATABLE,DIMENSION(:)          :: WFY
   !
   REAL(KIND=8),ALLOCATABLE,DIMENSION(:)          :: WFtime
   REAL(KIND=8),ALLOCATABLE,DIMENSION(:)          :: WFpdf
   !
   REAL                                           :: qs
  ENDTYPE

During my program, I allocate it as:

first of all:

ALLOCATE(MACROCELLNODE(npairs))

and then

DO i.....

       ALLOCATE(MACROCELLNODE(i)%WFX(n))
...
...

My question is:

Is it possible deallocate only one field of it?

for example:

i=10
DEALLOCATE(MACRCELLNODE(i)%WFX(:))

Thank to all of you

Diego

0 Kudos
3 Replies
Steven_L_Intel1
Employee
312 Views

Yes, you can do that. You can also deallocate the entire array and each of the components will be deallocated as necessary.

You have the syntax a bit wrong in the DEALLOCATE, though - no (:) at the end.

0 Kudos
diedro
Beginner
312 Views

Dear all, Dear Steve,

Thanks a lot, but what is the difference between

VECTOR(:) or VECTOR?

Just to better understand

Thanks again

0 Kudos
mecej4
Honored Contributor III
312 Views

When you allocate an array, you have to specify the extent of the array. When you deallocate, however, you do not specify a range of indices. You may deallocate only the entire array, and not chosen portions of it. Therefore, writing (:) in the deallocation statement would be superfluous, and the language rules do not let you write that qualifier.

0 Kudos
Reply