      SUBROUTINE ECR_ELM2D(IFIL,NEL,NCOPNP,M,NUMSD,NBTRI,NBQUA)
C
      INTEGER M(*),NODE(50),NELSD(1000),IORDRESD(1000),NDSSD(1000)
C
      IA = 1
      IF (NUMSD.LE.1) THEN
        DO I=1,NEL
          NMAE = M(IA+1)
          NNO  = M(IA+3)
          IF (NCOPNP.EQ.0) THEN
            NPO = M(IA+4+NNO)
            DO K=1,NPO
              NODE(K) = M(IA+4+NNO+K)
            ENDDO
            print*,i,':',(m(ia+3+k),k=1,nno)
            IA = IA + 5 + NNO + NMAE + NPO
            NNO = NPO
          ELSE
            DO K=1,NNO
              NODE(K) = M(IA+3+K)
            ENDDO
            IA = IA + 4 + NNO + NMAE
          ENDIF
          IF (I.EQ.1) THEN
            IF (NBQUA.NE.0) THEN
              NNO1 = MAX(4,NNO)
            ELSE
              NNO1 = NNO
            ENDIF
            WRITE(IFIL) 1,1,NEL,NNO1
          ENDIF
          IF (NNO.EQ.4) THEN
            WRITE(IFIL) I,(NODE(K),K=1,NNO),0
          ELSE
            IF (NNO.EQ.3.AND.NNO1.EQ.4) THEN
              WRITE(IFIL) I,(NODE(K),K=1,NNO),NODE(3),0
            ELSE
              WRITE(IFIL) I,(NODE(K),K=1,NNO),0
            ENDIF
          ENDIF
        ENDDO
      ELSE
        PRINT*,NUMSD,' subdomains'
        DO I=1,NUMSD
          NELSD(I) = 0
          NDSSD(I) = 0
        ENDDO
Cfj        NSD0 = 0
Cfj        IBADSD = 0
Cfj        NNSD = 0
        DO I=1,NEL
          NMAE = M(IA+1)
          NSD  = M(IA+2)
          NNO  = M(IA+3)
          NELSD(NSD) = NELSD(NSD)+1
          IF (NCOPNP.EQ.0) THEN
            NPO = M(IA+4+NNO)
            IA = IA + 5 + NNO + NMAE + NPO
            NDSSD(NSD) = MAX(NDSSD(NSD),NPO)
          ELSE
            IA = IA + 4 + NNO + NMAE
            NDSSD(NSD) = MAX(NDSSD(NSD),NNO)
          ENDIF
Cfj          IF (NSD.NE.NSD0) THEN
Cfj            IF (NSD.LT.NSD0) THEN
Cfj              PRINT*,'*** Warning, sd',NSD0,' before sd',NSD
Cfj              IBADSD = 1
Cfj            ENDIF
Cfj            NNSD = NNSD+1
Cfj            IORDRESD(NNSD) = NSD
Cfj          ENDIF
Cfj          NSD0 = NSD
        ENDDO
Cfj        IF (IBADSD.NE.0)
Cfj     &PRINT*,'*** Les  numeros de sous-domaines seront faux dans xd3d'
        DO NNN=1,NUMSD
cc          NN = IORDRESD(NNN)
          NN = NNN
          PRINT*,'Subdomain',NNN,':',NELSD(NN),' elements'
          IF (NNN.NE.NN) PRINT*,'*** (sd',NN,' in the nopo file)'
          NDS = NDSSD(NN)
          IA = 1
          II = 0
          WRITE(IFIL) NN,1,NELSD(NN),NDSSD(NSD)
          DO I=1,NEL
            NMAE = M(IA+1)
            NSD  = M(IA+2)
            NNO  = M(IA+3)
            IF (NCOPNP.EQ.0) THEN
              NPO = M(IA+4+NNO)
              IF (NSD.EQ.NN) THEN
                DO K=1,NPO
                  NODE(K) = M(IA+4+NNO+K)
                ENDDO
                II = II+1
                IF (NPO.LT.NDS) THEN
                  DO K=NPO+1,NDS
                    NODE(K) = NODE(NPO)
                  ENDDO
                ENDIF
                WRITE(IFIL) I,(NODE(K),K=1,NDS)
              ENDIF
              IA = IA + 5 + NNO + NMAE + NPO
            ELSE
              IF (NSD.EQ.NN) THEN
                DO K=1,NNO
                  NODE(K) = M(IA+3+K)
                ENDDO
                II = II+1
                IF (NNO.LT.NDS) THEN
                  DO K=NNO+1,NDS
                    NODE(K) = NODE(NNO)
                  ENDDO
                ENDIF
                IF (NDS.EQ.4) THEN
                  WRITE(IFIL) I,(NODE(K),K=1,NDS),0
                ELSE
                  WRITE(IFIL) I,(NODE(K),K=1,NDS)
                ENDIF
              ENDIF
              IA = IA + 4 + NNO + NMAE
            ENDIF
          ENDDO
cc          PRINT*,II,NELSD(NN),NCOPNP,nds
        ENDDO
      ENDIF
      END
