Skip to content

Commit

Permalink
Return null ptrs from cleanup routines in hco_arr_mod, hco_tidx_mod
Browse files Browse the repository at this point in the history
src/Core/hco_arr_mod.F90
- Set Arr and ArrVec to null before exiting cleanup routines


src/Core/hco_tidx_mod.F90
- Set individual fields of AlltIDx to NULL after deallocating
- Update comments

Signed-off-by: Bob Yantosca <[email protected]>
  • Loading branch information
yantosca committed Jan 5, 2024
1 parent f0dc3db commit ca9b187
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Core/hco_arr_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,9 @@ SUBROUTINE HCO_ArrCleanup_2D_Hp( Arr, DeepClean )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_2D_Hp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1685,6 +1688,9 @@ SUBROUTINE HCO_ArrCleanup_2D_Sp( Arr, DeepClean )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_2D_Sp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1732,6 +1738,9 @@ SUBROUTINE HCO_ArrCleanup_2D_I( Arr, DeepClean )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_2D_I
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1778,6 +1787,10 @@ SUBROUTINE HCO_ArrCleanup_3D_Hp( Arr, DeepClean )
CALL HCO_ValCleanup( Arr%Val, Arr%Alloc, DeepClean=DC )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_3D_Hp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1825,6 +1838,9 @@ SUBROUTINE HCO_ArrCleanup_3D_Sp( Arr, DeepClean )
DEALLOCATE( Arr )
ENDIF

! Make sure we return a null pointer
Arr => NULL()

END SUBROUTINE HCO_ArrCleanup_3D_Sp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1876,6 +1892,9 @@ SUBROUTINE HCO_ArrVecCleanup_2D_Hp( ArrVec, DeepClean )

ENDIF

! Make sure we return a null pointer
ArrVec => NULL()

END SUBROUTINE HCO_ArrVecCleanup_2D_Hp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1927,6 +1946,9 @@ SUBROUTINE HCO_ArrVecCleanup_2D_Sp( ArrVec, DeepClean )

ENDIF

! Make sure we return a null pointer
ArrVec => NULL()

END SUBROUTINE HCO_ArrVecCleanup_2D_Sp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -1978,6 +2000,9 @@ SUBROUTINE HCO_ArrVecCleanup_3D_Hp( ArrVec, DeepClean )

ENDIF

! Make sure we return a null pointer
ArrVec => NULL()

END SUBROUTINE HCO_ArrVecCleanup_3D_Hp
!EOC
!------------------------------------------------------------------------------
Expand Down Expand Up @@ -2029,6 +2054,9 @@ SUBROUTINE HCO_ArrVecCleanup_3D_Sp( ArrVec, DeepClean )

ENDIF

! Make sure we return a null pointer
ArrVec => NULL()

END SUBROUTINE HCO_ArrVecCleanup_3D_Sp
!EOC
!------------------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion src/Core/hco_tidx_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ SUBROUTINE tIDx_Cleanup( AlltIDx )
! tIDx_Cleanup begins here!
!======================================================================

! Deallocate fields
IF ( ASSOCIATED( AlltIDx ) ) THEN

IF ( ASSOCIATED(AlltIDx%CONSTANT) ) THEN
Expand All @@ -307,9 +308,18 @@ SUBROUTINE tIDx_Cleanup( AlltIDx )
DEALLOCATE(AlltIDx%MONTHLY)
ENDIF

! Also deallocate AlltIDx pointer
! Nullify fields
AlltIDx%CONSTANT => NULL()
AlltIDx%HOURLY => NULL()
AlltIDx%HOURLY_GRID => NULL()
AlltIDx%WEEKDAY => NULL()
AlltIDx%MONTHLY => NULL()

! Deallocate container
DEALLOCATE( AlltIDx )
ENDIF

! Make sure we return a null pointer
AlltIDx => NULL()

END SUBROUTINE tIDx_Cleanup
Expand Down

0 comments on commit ca9b187

Please sign in to comment.