      SUBROUTINE AD_MAIN ()
        IMPLICIT INTEGER (I-K), REAL (R-T), DOUBLE PRECISION (D-F), COMP
     *LEX (X-Z), CHARACTER (A-C), LOGICAL (L-N)
        
        INTEGER :: K_MA (0:15)
        
        LOGICAL, DIMENSION (0:35) :: L_A
        INTEGER, DIMENSION (0:1) :: K_PQ
        INTEGER :: I_J
        
        LOGICAL  N_FIRSTCALL
        DATA     N_FIRSTCALL /.TRUE./
        INTEGER  ::  K_Q, K_H0, K_H1, K_H2, K_H3, K_H4, K_H5, K_H6, K_H7
     *, K_P0, K_P1 (0:0), K_P2 (0:1), K_P3 (0:2), K_P4 (0:3), K_P5 (0:4)
     *, K_P6 (0:5), K_P7 (0:6)
        COMMON /Q_PROCS/ K_Q, K_H0, K_H1, K_H2, K_H3, K_H4, K_H5, K_H6, 
     *K_H7, K_P0, K_P1, K_P2, K_P3, K_P4, K_P5, K_P6, K_P7
        
        INTEGER           ::  K_PTR, K_Z, K_TMP (0 : 299999)
        REAL              ::  T_TMP (0 : 299999)
        DOUBLE PRECISION  ::  F_TMP (0 : 149999)
        COMPLEX           ::  Z_TMP (0 : 149999)
        LOGICAL           ::  N_TMP (0 : 299999)
        EQUIVALENCE (K_TMP, T_TMP, F_TMP, Z_TMP, N_TMP)
        COMMON /Q_STACK/ K_PTR, K_Z, K_TMP
        
        K_PTR = 0
        
        CALL AD_INIT_PROCS (K_H1, 1, (/1/))
        CALL AD_PROC_COORD (K_H1, K_P1)
        CALL AD_INIT_PROCS (K_H2, 2, (/1, 1/))
        CALL AD_PROC_COORD (K_H2, K_P2)
        CALL AD_INIT_PROCS (K_H3, 3, (/1, 1, 1/))
        CALL AD_PROC_COORD (K_H3, K_P3)
        CALL AD_INIT_PROCS (K_H4, 4, (/1, 1, 1, 1/))
        CALL AD_PROC_COORD (K_H4, K_P4)
        CALL AD_INIT_PROCS (K_H5, 5, (/1, 1, 1, 1, 1/))
        CALL AD_PROC_COORD (K_H5, K_P5)
        CALL AD_INIT_PROCS (K_H6, 6, (/1, 1, 1, 1, 1, 1/))
        CALL AD_PROC_COORD (K_H6, K_P6)
        CALL AD_INIT_PROCS (K_H7, 7, (/1, 1, 1, 1, 1, 1, 1/))
        CALL AD_PROC_COORD (K_H7, K_P7)
        CALL AD_INIT_PROCS (K_HQ, 2, (/2, 3/))
        CALL AD_PROC_COORD (K_HQ, K_PQ)
        
        K_MA = (/73, 0, K_HQ, 0, 80, 1, 36, 15, 80, 1, 100, 12, 4, 1, 0,
     * 0/)
        
        DO 10 I_I = 1, 80
          IF (K_PQ(0) == 0 .AND. K_PQ(1) == MOD((I_I+14)/12,3)) THEN
            K_V0 = MOD(I_I+14,12)+(I_I+14)/36*12
            L_A (K_V0) = .FALSE.
          ENDIF
          
   10   CONTINUE
        CALL AD_ANY (N_V0, L_A, K_MA)
        
        CALL AD_ALL (N_V1, L_A, K_MA)
        
        CALL AD_COUNT (K_V2, L_A, K_MA)
        
        IF (K_P0 == 0) THEN
          PRINT '(2l3,i4)', N_V0,N_V1,K_V2
        ENDIF
        IF (K_PQ(0) == 0 .AND. K_PQ(1) == 2) THEN
          L_A (2) = .TRUE.
        ENDIF
        
        IF (K_PQ(0) == 0 .AND. K_PQ(1) == 0) THEN
          L_A (15) = .TRUE.
        ENDIF
        
        IF (K_PQ(0) == 0 .AND. K_PQ(1) == 1) THEN
          L_A (4) = .TRUE.
        ENDIF
        
        IF (K_PQ(0) == 0 .AND. K_PQ(1) == 2) THEN
          L_A (7) = .TRUE.
        ENDIF
        
        CALL AD_ANY (N_V0, L_A, K_MA)
        
        CALL AD_ALL (N_V1, L_A, K_MA)
        
        CALL AD_COUNT (K_V2, L_A, K_MA)
        
        IF (K_P0 == 0) THEN
          PRINT '(2l3,i4)', N_V0,N_V1,K_V2
        ENDIF
        DO 20 I_I = 1, 80
          IF (K_PQ(0) == 0 .AND. K_PQ(1) == MOD((I_I+14)/12,3)) THEN
            K_V0 = MOD(I_I+14,12)+(I_I+14)/36*12
            L_A (K_V0) = .TRUE.
          ENDIF
          
   20   CONTINUE
        CALL AD_ANY (N_V0, L_A, K_MA)
        
        CALL AD_ALL (N_V1, L_A, K_MA)
        
        CALL AD_COUNT (K_V2, L_A, K_MA)
        
        IF (K_P0 == 0) THEN
          PRINT '(2l3,i4)', N_V0,N_V1,K_V2
        ENDIF
        CALL AD_DELETE_PROCS (K_HQ)
        
        CALL AD_DELETE_PROCS (K_H7)
        CALL AD_DELETE_PROCS (K_H6)
        CALL AD_DELETE_PROCS (K_H5)
        CALL AD_DELETE_PROCS (K_H4)
        CALL AD_DELETE_PROCS (K_H3)
        CALL AD_DELETE_PROCS (K_H2)
        CALL AD_DELETE_PROCS (K_H1)
        CALL AD_DELETE_PROCS (K_H0)
        
      END
