*DECK MOCIK3
      SUBROUTINE MOCIK3(NDIM,NL,ISIGNR,KEYANI)
*
*-----------------------------------------------------------------------
*
*Purpose:
* generate all signs ISIGNR(L,M,K) for spherical harmonics R(L,M) for
* 0 <= L <= NL (and for -L <= M <= L) on the 8 octant angular modes
* for 1 <= K <= 8. Definition of these signs:
* ISIGNR(L,M,1)= +1
* ISIGNR(L,M,2)= SIGN(M)*(-1)**M
* ISIGNR(L,M,3)= SIGN(M)
* ISIGNR(L,M,4)= (-1)**M
* ISIGNR(L,M,5)= (-1)**(L+M)
* ISIGNR(L,M,6)= SIGN(M)*(-1)**L
* ISIGNR(L,M,7)= SIGN(M)*(-1)**(L+M)
* ISIGNR(L,M,8)= (-1)**L
* where SIGN(M)= +1 for 0 <= M
*                -1 for M <  0
* All these ISIGNR values are compressed to be used according to the
* rectangular dimension 'NDIM'. The remaining place is filled up with
* zeros to ensure that no problem arise if one overrides the dimensions.
*
*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): R. Roy
*
*-----------------------------------------------------------------------
*
      IMPLICIT NONE
*----
*  SUBROUTINE ARGUMENTS
*----
      INTEGER  NDIM,NL,ISIGNR(8*(NL+1)*(NL+1)),KEYANI((NL+1)*(NL+1))
*----
*  LOCAL VARIABLES
*----
      INTEGER  NEWMOD(8,3),K,L,M,IND1,IND2,IND3,KNEW,INDNEW,NSELEC
      LOGICAL  LROK
      DATA NEWMOD    / 1,0,0,0, 0,0,2,0,
     >                 1,2,3,4, 0,0,0,0,
     >                 1,2,3,4, 5,6,7,8 /
*
*     INDEX FOR SIGN 'ISIGNR' DEPENDING ON THE DIMENSION
      IND1(NSELEC,K)=      NSELEC + 1 + (K-1)* (NL+1)
      IND2(NSELEC,K)=      NSELEC + 1 + (K-1)*((NL+1)*(NL+2)/2)
      IND3(L,M,K)=    L*(L+1) + M + 1 + (K-1)*((NL+1)*(NL+1))
*
      DO 30 L= 0, NL
         DO 20 M= -L, L
            ISIGNR(IND3(L,M,1))= +1
            ISIGNR(IND3(L,M,2))= ISIGN(1,M)*(-1)**M
            ISIGNR(IND3(L,M,3))= ISIGN(1,M)
            ISIGNR(IND3(L,M,4))= (-1)**M
            ISIGNR(IND3(L,M,5))= (-1)**(L+M)
            ISIGNR(IND3(L,M,6))= ISIGN(1,M)*(-1)**L
            ISIGNR(IND3(L,M,7))= ISIGN(1,M)*(-1)**(L+M)
            ISIGNR(IND3(L,M,8))= (-1)**L
   20    CONTINUE
   30 CONTINUE
*
***** SELECTS THE GOOD SIGN ISIGNR(L,M) FUNCTIONS
*             FOR NDIM=1(SLAB),2(TWO-D RECT),3(THREE-D).
*
*     COMPRESSES 'ISIGNR' IN PLACE.
*
      DO 80 K= 1, 8
         NSELEC= 0
         KNEW= NEWMOD(K,NDIM)
         IF( KNEW.NE.0 )THEN
            DO 50 L= 0, NL
               DO 40 M= -L, L
                  LROK=.FALSE.
                  INDNEW=0
                  IF( NDIM.EQ.1 )THEN
                     LROK= M.EQ.0
                     INDNEW= IND1(NSELEC,KNEW)
                  ELSEIF( NDIM.EQ.2 )THEN
                     LROK= MOD(L+M,2).EQ.0
                     INDNEW= IND2(NSELEC,KNEW)
                  ELSEIF( NDIM.EQ.3 )THEN
                     LROK= .TRUE.
                     INDNEW= IND3(L,M,KNEW)
                  ENDIF
                  IF( LROK )THEN
                     NSELEC= NSELEC+1
                     IF(INDNEW.NE.IND3(L,M,K))THEN
                        ISIGNR(INDNEW)= ISIGNR(IND3(L,M,K))
                     ENDIF
                     KEYANI(NSELEC) = L
                  ELSE
                     ISIGNR(IND3(L,M,K))= 0
                  ENDIF
   40          CONTINUE
   50       CONTINUE
         ELSE
            DO 70 L= 0, NL
               DO 60 M= -L, L
                  ISIGNR(IND3(L,M,K))= 0
   60          CONTINUE
   70       CONTINUE
         ENDIF
   80 CONTINUE
*
      RETURN
      END
