*-----------------------------------------------------------------------
*     LENC
*-----------------------------------------------------------------------
      INTEGER FUNCTION LENC(C)

      CHARACTER C*(*)

      LOGICAL   LCHAR
      CHARACTER CN*1,CS*1


      CN=CHAR(0)
      CS=' '

      N=LEN(C)

   15 LCHAR=N.GT.1 .AND. (C(N:N).EQ.CN .OR. C(N:N).EQ.CS)
      IF (.NOT.LCHAR) GO TO 10
        N=N-1
        GO TO 15
   10 CONTINUE

      LENC=N

      END
*-----------------------------------------------------------------------
*     MSGDMP
*                      from dcl-5.0.1, modified by S.Takehiro 96/08/31
*-----------------------------------------------------------------------
      SUBROUTINE MSGDMP(CLEV,CSUB,CMSG)

      CHARACTER CLEV*(*),CSUB*(*),CMSG*(*)

      LOGICAL   LCHREQ
      CHARACTER CLEVX*1,CSUBX*6,CMSGX*200

      EXTERNAL  LCHREQ,LENC

      SAVE

      DATA      IMSG/0/

      DATA      IUNIT / 6 /
      DATA      MSXMSG / 20 /
      DATA      MSGLEV / 0 /
      DATA      LNSIZE / 78 /
C      CALL GLIGET('MSGUNIT',IUNIT)
C      CALL GLIGET('MAXMSG',MAXMSG)
C      CALL GLIGET('MSGLEV',MSGLEV)
C      CALL GLIGET('NLNSIZE',LNSIZE)

      CLEVX=CLEV
      CSUBX=CSUB
      LMSG=LENC(CMSG)

      IF (LCHREQ(CLEVX,'E')) THEN
        CMSGX='***** ERROR ('//CSUBX//') ***  '//CMSG(1:LMSG)
        CALL MSZDMP(CMSGX,IUNIT,LNSIZE)
C        CALL OSABRT
        STOP
      END IF
      IF (IMSG.LT.MAXMSG) THEN
        IF (LCHREQ(CLEVX,'W') .AND. MSGLEV.LE.1) THEN
          IMSG=IMSG+1
          CMSGX='*** WARNING ('//CSUBX//') ***  '//CMSG(1:LMSG)
          CALL MSZDMP(CMSGX,IUNIT,LNSIZE)
        ELSE IF (LCHREQ(CLEVX,'M') .AND. MSGLEV.LE.0) THEN
          IMSG=IMSG+1
          CMSGX='*** MESSAGE ('//CSUBX//') ***  '//CMSG(1:LMSG)
          CALL MSZDMP(CMSGX,IUNIT,LNSIZE)
        END IF
        IF (IMSG.EQ.MAXMSG) THEN
          CMSGX='+++ THE FOLLOWING MESSAGES ARE SUPPRESSED.'
          CALL MSZDMP(CMSGX,IUNIT,LNSIZE)
        END IF
      END IF

      END
*-----------------------------------------------------------------------
      SUBROUTINE MSZDMP(CMSG,IUNIT,LNSIZE)

      CHARACTER CMSG*(*)

      PARAMETER (MMAX=200)

      CHARACTER CMSGX*(MMAX),CFM*12

      EXTERNAL  LENC


      CMSGX=CMSG
      NMSG=LENC(CMSGX)
      MMSG=(NMSG-1)/LNSIZE+1
      CFM='(TR1,A###)'
      WRITE(CFM(7:9),'(I3)') LNSIZE

      DO 10 M=1,MMSG
        WRITE(IUNIT,CFM) CMSGX(1+LNSIZE*(M-1):MIN(LNSIZE*M,MMAX))
   10 CONTINUE

      END
*-----------------------------------------------------------------------
*     LCHREQ FOR ASCII CHARACTER CODE
*-----------------------------------------------------------------------
      LOGICAL FUNCTION LCHREQ(CH1,CH2)

      CHARACTER CH1*(*),CH2*(*)


      LCHREQ=.TRUE.
      LCH1=LEN(CH1)
      LCH2=LEN(CH2)
      LCHMAX=MAX(LCH1,LCH2)
      LCHMIN=MIN(LCH1,LCH2)

      DO 10 I=1,LCHMIN
        IDX1=ICHAR(CH1(I:I))
        IDX2=ICHAR(CH2(I:I))
        IF (IDX1.NE.IDX2) THEN
          IF (65.LE.IDX1 .AND. IDX1.LE.90) THEN
            LCHREQ=(IDX2-IDX1).EQ.32
          ELSE IF (97.LE.IDX1 .AND. IDX1.LE.122) THEN
            LCHREQ=(IDX1-IDX2).EQ.32
          ELSE
            LCHREQ=.FALSE.
          END IF
          IF (.NOT.LCHREQ) RETURN
        END IF
   10 CONTINUE
      IF (LCH1.EQ.LCH2) RETURN

      IBLK=ICHAR(' ')
      IF (LCH1.GT.LCH2) THEN
        DO 20 I=LCHMIN+1,LCHMAX
          LCHREQ=ICHAR(CH1(I:I)).EQ.IBLK
          IF (.NOT.LCHREQ) RETURN
   20   CONTINUE
      ELSE
        DO 30 I=LCHMIN+1,LCHMAX
          LCHREQ=ICHAR(CH2(I:I)).EQ.IBLK
          IF (.NOT.LCHREQ) RETURN
   30   CONTINUE
      END IF

      END
