*DECK FLDADI
      SUBROUTINE FLDADI (NAMP,IPTRK,IPSYS,LL4,ITY,F1,NADI)
*
*-----------------------------------------------------------------------
*
*Purpose:
* perform NADI inner iterations with the ADI preconditionning method.
*
*Copyright:
* Copyright (C) 2002 Ecole Polytechnique de Montreal
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version
*
*Author(s): A. Hebert
*
*Parameters: input
* NAMP    name of the ADI-splitted matrix.
* IPTRK   L_TRACK pointer to the tracking information.
* IPSYS   L_SYSTEM pointer to system matrices.
* LL4     order of the matrix.
* ITY     type of coefficient matrix (1: Bivac; 2: classical Trivac;
*         3: Thomas-Raviart; 11: SPN/Bivac; 13: SPN/Thomas-Raviart).
* F1      source term of the linear system.
* NADI    number of inner ADI iterations.
*
*Parameters: output
* F1      approached solution of the linear system.
*
*-----------------------------------------------------------------------
*
      USE GANLIB
*----
*  SUBROUTINE ARGUMENTS
*----
      TYPE(C_PTR) IPTRK,IPSYS
      CHARACTER NAMP*12
      INTEGER LL4,ITY,NADI
      REAL F1(LL4)
*----
*  LOCAL VARIABLES
*----
      PARAMETER (NSTATE=40)
      INTEGER ITP(NSTATE)
      REAL, DIMENSION(:), ALLOCATABLE :: GAR,GAF
*----
*  THOMAS-RAVIART SPECIAL TREATMENT
*----
      IF(ITY.EQ.3) THEN
*        THOMAS-RAVIART/DIFFUSION TRIVAC TRACKING.
         CALL FLDTRS(NAMP,IPTRK,IPSYS,LL4,F1,NADI)
         RETURN
      ELSE IF(ITY.EQ.13) THEN
*        THOMAS-RAVIART/SIMPLIFIED PN TRIVAC TRACKING.
         CALL LCMGET(IPSYS,'STATE-VECTOR',ITP)
         NBMIX=ITP(7)
         NAN=ITP(8)
         IF(NAN.EQ.0) CALL XABORT('FLDADI: SPN-ONLY ALGORITHM.')
         CALL FLDSPN(NAMP,IPTRK,IPSYS,LL4,NBMIX,NAN,F1,NADI)
         RETURN
      ENDIF
*----
*  CLASSICAL TREATMENT
*----
      CALL MTLDLS(NAMP,IPTRK,IPSYS,LL4,ITY,F1)
      IF(NADI.EQ.1) RETURN
      ALLOCATE(GAF(LL4))
      DO 10 I=1,LL4
   10 GAF(I)=F1(I)
      M=1
   20 M=M+1
      ALLOCATE(GAR(LL4))
         CALL MTLDLM(NAMP,IPTRK,IPSYS,LL4,ITY,F1,GAR)
         CALL MTLDLS(NAMP,IPTRK,IPSYS,LL4,ITY,GAR)
         DO 30 I=1,LL4
   30    F1(I)=GAF(I)+(F1(I)-GAR(I))
      DEALLOCATE(GAR)
      IF(M.EQ.NADI) GO TO 40
      GO TO 20
   40 DEALLOCATE(GAF)
      RETURN
      END
