      PROGRAM CLAIR
      INCLUDE 'com_avoir.f'
      CHARACTER*1 D
      LOGICAL NOPR,LA
      INTEGER IBC6,IBC7
      REAL*4  XBC6,XBC7
      EQUIVALENCE(IBC6,XBC6)
      EQUIVALENCE(IBC7,XBC7)
      DATA CQVSPI / 57.2957795130823  /
C
 1    CALL LIFICH('Prefix of the mesh file ?',0,FICH,LONG)
      NOK = 0
      INQUIRE(FILE=FICH(1:LONG)//'.avoir2D',EXIST=LA)
      IF (LA) NOK = NOK+2
      INQUIRE(FILE=FICH(1:LONG)//'.avoir3D',EXIST=LA)
      IF (LA) NOK = NOK+3
      IF (NOK.EQ.0) THEN
        PRINT*,'*** No .avoir2D or .avoir3D with this prefix'
        GOTO 1
      ELSEIF(NOK.EQ.2) THEN
        D = '2'
      ELSEIF(NOK.EQ.3) THEN
        D = '3'
      ELSEIF(NOK.EQ.5) THEN
        CALL LIENTIER('2d or 3d ? (2/3)',0,IDIM)
        IF (IDIM.EQ.2) THEN
          D = '2'
        ELSE
          D = '3'
        ENDIF
      ENDIF
      FICH = FICH(1:LONG)//'.avoir'//D//'D'
      LONG = LONG+8
      IF (NOK.LT.5) PRINT*,'--> File '//FICH(1:LONG)//' found'
C
      CALL LITAVOIR(FICH,LONG,HED,NUMNP,NELTOT,NGMAX,NMAX,NDSMAX,XYZ,IBC
     &             ,NODE,NPR,NFPR,PR,NGROUP,NTYP,NEL,NDS,NUMSD,2,IENDIAN
     &             ,IERR,0)
      IF (IERR.NE.0) GOTO 1
      IF (IENDIAN.NE.0) THEN
        PRINT*,'*** File from another architecture'//
     &       ' (big endian/little endian)'
      ENDIF
      CALL ENLEVE_TOUS_BLANCS(HED,LHED,80)
      IF (LHED.LT.80) THEN
        DO I=LHED+1,80
          HED(I:I) = ' '
        ENDDO
      ENDIF
C
      FICH = FICH(1:LONG-8)//'.clair'//D//'D'
      OPEN(1,FILE=FICH(1:LONG))
      WRITE(1,50) HED
      WRITE(1,100) NUMNP,8
      DO I=1,NUMNP
        IBC6 = IBC(6,I)
        IBC7 = IBC(7,I)
        XBC6 = XBC6*CQVSPI
        XBC7 = XBC7*CQVSPI
        II = NINT(XBC6)
        IF (ABS(XBC6-REAL(II)).LT.1.E-4) XBC6 = REAL(II)
        II = NINT(XBC7)
        IF (ABS(XBC7-REAL(II)).LT.1.E-4) XBC7 = REAL(II)
        IF (MAX(XYZ(1,I),XYZ(2,I),XYZ(3,I)).LT.100..AND.
     &      MIN(XYZ(1,I),XYZ(2,I),XYZ(3,I)).GT.-10.) THEN
          WRITE(1,208) I,(XYZ(L,I),L=1,3),(IBC(L,I),L=1,5),XBC6,XBC7
     &                  ,(IBC(L,I),L=8,9)
        ELSE
          WRITE(1,209) I,(XYZ(L,I),L=1,3),(IBC(L,I),L=1,5),XBC6,XBC7
     &                  ,(IBC(L,I),L=8,9)
        ENDIF
      ENDDO
C
      N = 0
      DO NS=1,NUMSD
        NOPR = NDS(NS).NE.3.AND.NDS(NS).NE.4.AND.NDS(NS).NE.8
        IF (NOPR.AND.NDS(NS).NE.6
     &          .AND.NDS(NS).NE.9.AND.NDS(NS).NE.27) THEN
          PRINT*,'*** Bizarre, group',NS,' with',NDS(NS),' nodes'
        ENDIF
        WRITE(1,300) NGROUP(NS),NTYP(NS),NEL(NS),NDS(NS)
        DO I=1,NEL(NS)
          N = N+1
          IF (NOPR) THEN
            WRITE(1,427) (NODE(J,N),J=0,NDS(NS))
          ELSEIF(NDS(NS).EQ.8) THEN
            IF (NPR(N).EQ.0) THEN
              WRITE(1,408) (NODE(J,N),J=0,NDS(NS)),NPR(N)
            ELSE
              WRITE(1,408) (NODE(J,N),J=0,NDS(NS)),NPR(N)
     &                    ,(NFPR(J,N),PR(J,N),J=1,NPR(N))
            ENDIF
          ELSEIF(NDS(NS).EQ.4) THEN
            IF (NPR(N).EQ.0) THEN
              WRITE(1,404) (NODE(J,N),J=0,NDS(NS)),NPR(N)
            ELSE
              WRITE(1,404) (NODE(J,N),J=0,NDS(NS)),NPR(N)
     &                    ,(NFPR(J,N),PR(J,N),J=1,NPR(N))
            ENDIF
          ELSEIF(NDS(NS).EQ.3) THEN
            IF (NPR(N).EQ.0) THEN
              WRITE(1,403) (NODE(J,N),J=0,NDS(NS)),NPR(N)
            ELSE
              WRITE(1,403) (NODE(J,N),J=0,NDS(NS)),NPR(N)
     &                    ,(NFPR(J,N),PR(J,N),J=1,NPR(N))
            ENDIF
          ENDIF
        ENDDO
      ENDDO
C
      CLOSE(1)
C
 50   FORMAT(A80)
 100  FORMAT(2I10)
cc 208  FORMAT(I7,3F13.9,3I4,4I2,2I5)
cc 209  FORMAT(I7,3F13.6,3I4,4I2,2I5)
 208  FORMAT(I7,3F13.9,3I4,2I2,2F10.5,2I5)
 209  FORMAT(I7,3F13.6,3I4,2I2,2F10.5,2I5)
 300  FORMAT(4I7)
 403  FORMAT(4I7,I2,3(I2,F15.9))
 404  FORMAT(5I7,I2,4(I2,F15.9))
 409  FORMAT(10I7)
 408  FORMAT(9I7,I2,6(I2,F15.9))
 427  FORMAT(10I7,5(/7X,9I7))
      END
