trans_end.F90 Source File


This file depends on

sourcefile~~trans_end.f90~~EfferentGraph sourcefile~trans_end.f90 trans_end.F90 sourcefile~abort_trans_mod.f90 abort_trans_mod.F90 sourcefile~trans_end.f90->sourcefile~abort_trans_mod.f90 sourcefile~backends_mod.f90 backends_mod.F90 sourcefile~trans_end.f90->sourcefile~backends_mod.f90 sourcefile~eq_regions_mod.f90 eq_regions_mod.F90 sourcefile~trans_end.f90->sourcefile~eq_regions_mod.f90 sourcefile~resols_mod.f90 resols_mod.F90 sourcefile~trans_end.f90->sourcefile~resols_mod.f90 sourcefile~tpm_ctl.f90 tpm_ctl.F90 sourcefile~trans_end.f90->sourcefile~tpm_ctl.f90 sourcefile~tpm_dim.f90 tpm_dim.F90 sourcefile~trans_end.f90->sourcefile~tpm_dim.f90 sourcefile~tpm_distr.f90 tpm_distr.F90 sourcefile~trans_end.f90->sourcefile~tpm_distr.f90 sourcefile~tpm_fields.f90 tpm_fields.F90 sourcefile~trans_end.f90->sourcefile~tpm_fields.f90 sourcefile~tpm_gen.f90 tpm_gen.F90 sourcefile~trans_end.f90->sourcefile~tpm_gen.f90 sourcefile~tpm_geometry.f90 tpm_geometry.F90 sourcefile~trans_end.f90->sourcefile~tpm_geometry.f90 sourcefile~abort_trans_mod.f90->sourcefile~tpm_gen.f90 sourcefile~resols_mod.f90->sourcefile~backends_mod.f90 sourcefile~sharedmem_mod.f90 sharedmem_mod.F90 sourcefile~tpm_ctl.f90->sourcefile~sharedmem_mod.f90

Source Code

! (C) Copyright 2000- ECMWF.
! (C) Copyright 2000- Meteo-France.
! 
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
! In applying this licence, ECMWF does not waive the privileges and immunities
! granted to it by virtue of its status as an intergovernmental organisation
! nor does it submit to any jurisdiction.
!

SUBROUTINE TRANS_END(CDMODE)

!**** *TRANS_END* - Terminate transform package

!     Purpose.
!     --------
!     Terminate transform package. Release all allocated arrays.

!**   Interface.
!     ----------
!     CALL TRANS_END

!     Explicit arguments : None
!     --------------------

!     Method.
!     -------

!     Externals.  None
!     ----------

!     Author.
!     -------
!        Mats Hamrud *ECMWF*

!     Modifications.
!     --------------
!        Original : 00-03-03
!          G. Radnoti: 19-03-2009: intermediate end of transf to allow to switch to mono-task transforms
!        R. El Khatib 09-Jul-2013 LENABLED

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

USE EC_PARKIND, ONLY: JPIM

!ifndef INTERFACE

USE TPM_GEN,         ONLY: MSETUP0, NCUR_RESOL, NMAX_RESOL, LENABLED,NDEF_RESOL
USE TPM_DIM,         ONLY: R, DIM_RESOL
USE TPM_DISTR,       ONLY: D, DISTR_RESOL, NPRCIDS
USE TPM_GEOMETRY,    ONLY: G, GEOM_RESOL
USE TPM_FIELDS,      ONLY: F, FIELDS_RESOL
USE TPM_CTL,         ONLY: C, CTL_RESOL
USE EQ_REGIONS_MOD,  ONLY: N_REGIONS
USE BACKENDS_MOD,    ONLY: Y_BACKENDS, JP_N_BACKENDS
USE RESOLS_MOD,      ONLY: Y_RESOLS
USE ABORT_TRANS_MOD, ONLY: ABORT_TRANS

IMPLICIT NONE

CHARACTER(LEN=5), OPTIONAL,  INTENT(IN) :: CDMODE
! Local variables
INTEGER(KIND=JPIM) :: JRES, JBACKEND
CHARACTER(LEN=5) :: CLMODE

! If SETUP_TRANS0 hasn't been called or TRANS_END has already been called, we just return
IF (MSETUP0 == 0) RETURN

!     ------------------------------------------------------------------
CLMODE='FINAL'
IF (PRESENT(CDMODE)) CLMODE=CDMODE
IF (CLMODE == 'FINAL') THEN
  ! Loop over all allocated resols, calling the deallocator for each one
  IF (ALLOCATED(LENABLED)) THEN
    DO JRES = 1, NMAX_RESOL
      IF (LENABLED(JRES)) THEN
        CALL Y_RESOLS(JRES)%DESTROY(JRES)
      ENDIF
    ENDDO
    DEALLOCATE(LENABLED)
  ENDIF
  DEALLOCATE(Y_RESOLS)

  ! For all enabled backends, call their backend teardown function
  DO JBACKEND = 1, JP_N_BACKENDS
    IF (Y_BACKENDS(JBACKEND)%ENABLED) THEN
      CALL Y_BACKENDS(JBACKEND)%TEARDOWN
    ENDIF
  ENDDO

  NULLIFY(R)
  IF( ALLOCATED(DIM_RESOL) ) DEALLOCATE(DIM_RESOL)

  NULLIFY(D)
  IF( ALLOCATED(DISTR_RESOL) ) DEALLOCATE(DISTR_RESOL)

  !TPM_CTL
  NULLIFY(C)
  IF( ALLOCATED(CTL_RESOL) ) DEALLOCATE(CTL_RESOL)

  !TPM_FIELDS
  NULLIFY(F)
  IF( ALLOCATED(FIELDS_RESOL) ) DEALLOCATE(FIELDS_RESOL)

  !TPM_GEOMETRY
  NULLIFY(G)
  IF( ALLOCATED(GEOM_RESOL) ) DEALLOCATE(GEOM_RESOL)

  MSETUP0 = 0
  NMAX_RESOL = 0
  NCUR_RESOL = 0
  NDEF_RESOL = 0
ENDIF
IF (CLMODE == 'FINAL' .OR. CLMODE == 'INTER') THEN
  !EQ_REGIONS
  IF( ASSOCIATED(N_REGIONS) ) DEALLOCATE(N_REGIONS)
  !TPM_DISTR
  IF( ALLOCATED(NPRCIDS) ) DEALLOCATE(NPRCIDS)
ENDIF

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

!endif INTERFACE

END SUBROUTINE TRANS_END