dbcsr_data_release Subroutine

public subroutine dbcsr_data_release(area)

Removes a reference and/or clears the data area.

Arguments

Type IntentOptional Attributes Name
type(dbcsr_data_obj), intent(inout) :: area

data area


Source Code

   SUBROUTINE dbcsr_data_release(area)
      !! Removes a reference and/or clears the data area.

      TYPE(dbcsr_data_obj), INTENT(INOUT)                :: area
         !! data area

      CHARACTER(len=*), PARAMETER :: routineN = 'dbcsr_data_release'

      INTEGER                                            :: handle

!   ---------------------------------------------------------------------------

      CALL timeset(routineN, handle)

      IF (.NOT. ASSOCIATED(area%d)) &
         DBCSR_WARN("Data seems to be unreferenced.")
      IF (ASSOCIATED(area%d)) THEN
         !
         IF (careful_mod) THEN
            IF (area%d%refcount .LE. 0) &
               DBCSR_WARN("Data seems to be unreferenced.")
         END IF
         !
         area%d%refcount = area%d%refcount - 1
         ! If we're releasing the last reference, then free the memory.
         IF (area%d%refcount .EQ. 0) THEN
            IF (.NOT. dbcsr_data_exists(area)) THEN
               DEALLOCATE (area%d)
            ELSE IF (dbcsr_data_get_size(area) > 1 .AND. ASSOCIATED(area%d%memory_type%pool)) THEN
               area%d%ref_size = 0
               CALL dbcsr_mempool_add(area)
            ELSE
               CALL internal_data_deallocate(area%d)
               DEALLOCATE (area%d)
            END IF
            NULLIFY (area%d)
         END IF
      END IF

      CALL timestop(handle)

   END SUBROUTINE dbcsr_data_release