MODULE TRCOM1
  USE TRCOM0, ONLY : NRMAX, NRUM, NTUM, NEQMAXM
  IMPLICIT NONE

! TMSLC
  INTEGER(4)              :: NTAMAX, NTXMAX, NTXMAX1
  REAL(8)                 :: PNBI
  REAL(8), DIMENSION(NTUM):: TMU, TMU1

! TRERU
  REAL(8), DIMENSION(:,:),POINTER :: RTEXU, RTIXU, RNEXU, RTEXEU, RTIXEU, RNEXEU   ! (NTUM,NRUM)

! TRINS
  INTEGER(4):: INS

! TRLCL
  REAL(8), DIMENSION(:,:,:),POINTER :: A, B, C                ! (NVM,NVM,NRM)
  REAL(8), DIMENSION(:,:)  ,POINTER :: D                      ! (NVM,NRM)
  REAL(8), DIMENSION(:,:)  ,POINTER :: RD, PPA, PPB, PPC      ! (NEQM,NRM)

! TRUFC
  INTEGER(4)              :: NMCHK
  INTEGER(4),DIMENSION(2) :: NREMAX
  REAL(4),DIMENSION(:,:),POINTER :: GRE   ! (NRUM,2)
  CHARACTER(LEN=80)       :: KDIRX


  CONTAINS

  SUBROUTINE ALLOCATE_TRCOM1(IERR)

    INTEGER(4), INTENT(OUT):: IERR
    IERR = 0
    IF(ASSOCIATED(RTEXU)) CALL DEALLOCATE_TRCOM1
    ALLOCATE(RTEXU(NTUM,NRUM), RTIXU(NTUM,NRUM), RNEXU(NTUM,NRUM),STAT=IERR)
      IF(IERR.NE.0) GOTO 900
    ALLOCATE(RTEXEU(NTUM,NRUM), RTIXEU(NTUM,NRUM), RNEXEU(NTUM,NRUM),STAT=IERR)
      IF(IERR.NE.0) GOTO 900
    ALLOCATE(A(NEQMAXM,NEQMAXM,NRMAX), B(NEQMAXM,NEQMAXM,NRMAX),STAT=IERR)
      IF(IERR.NE.0) GOTO 900
    ALLOCATE(C(NEQMAXM,NEQMAXM,NRMAX), D(NEQMAXM,NRMAX),STAT=IERR)
      IF(IERR.NE.0) GOTO 900
    ALLOCATE(RD(NEQMAXM,NRMAX), PPA(NEQMAXM,NRMAX), PPB(NEQMAXM,NRMAX),STAT=IERR)
      IF(IERR.NE.0) GOTO 900
    ALLOCATE(PPC(NEQMAXM,NRMAX), GRE(NRUM,2),STAT=IERR)
      IF(IERR.NE.0) GOTO 900
    RETURN
 900 CONTINUE
    WRITE(6,*) "XX TRCOM1 ALLOCATION ERROR IERR=",IERR
    CALL DEALLOCATE_ERR_TRCOM1
    RETURN
  END SUBROUTINE ALLOCATE_TRCOM1

  SUBROUTINE DEALLOCATE_TRCOM1
    DEALLOCATE(RTEXU, RTIXU, RNEXU, RTEXEU, RTIXEU, RNEXEU)
    DEALLOCATE(A, B, C, D, RD, PPA, PPB, PPC, GRE)
    RETURN
  END SUBROUTINE DEALLOCATE_TRCOM1

  SUBROUTINE DEALLOCATE_ERR_TRCOM1
    IF(ASSOCIATED(RTEXU ))     DEALLOCATE(RTEXU )
    IF(ASSOCIATED(RTIXU ))     DEALLOCATE(RTIXU )
    IF(ASSOCIATED(RNEXU ))     DEALLOCATE(RNEXU )
    IF(ASSOCIATED(RTEXEU))     DEALLOCATE(RTEXEU)
    IF(ASSOCIATED(RTIXEU))     DEALLOCATE(RTIXEU)
    IF(ASSOCIATED(RNEXEU))     DEALLOCATE(RNEXEU)
    IF(ASSOCIATED(A     ))     DEALLOCATE(A     )
    IF(ASSOCIATED(B     ))     DEALLOCATE(B     )
    IF(ASSOCIATED(C     ))     DEALLOCATE(C     )
    IF(ASSOCIATED(D     ))     DEALLOCATE(D     )
    IF(ASSOCIATED(RD    ))     DEALLOCATE(RD    )
    IF(ASSOCIATED(PPA   ))     DEALLOCATE(PPA   )
    IF(ASSOCIATED(PPB   ))     DEALLOCATE(PPB   )
    IF(ASSOCIATED(PPC   ))     DEALLOCATE(PPC   )
    IF(ASSOCIATED(GRE   ))     DEALLOCATE(GRE   )
    RETURN
  END SUBROUTINE DEALLOCATE_ERR_TRCOM1


END MODULE TRCOM1
