      SUBROUTINE DIRTST(ARG,LDIR,LENDIR,DIRNAM)
C
C     * JUN 28/02 - S.KHARIN
C     *
C     * TEST WHETHER ARG IS A FILE, OR A DIRECTORY (OR POINTS TO A DIRECTORY).
C     *
C     * IF ARG IS A DIRECTORY THEN ON RETURN:
C     *  LDIR   =.TRUE.
C     *  DIRNAM = THE NAME OF THE DIRECTORY
C     *  LENDIR = THE LENGTH OF THE DIRECTORY NAME
C     * OTHERWISE, 
C     *  LDIR   =.FALSE.
C     *
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      LOGICAL LDIR
      CHARACTER*128 ARG,DIRNAM

      LDIR=.FALSE.
      LENDIR=LEN_TRIM(ARG)
C
C     * RUN THE TEST TO FIND OUT WHETHER ARG IS A FILE OR A DIRECTORY
C
      CALL SYSTEM(' chkfldr '//ARG(1:LENDIR)//' .tmp_dirtst')

      OPEN(98,FILE='.tmp_dirtst',STATUS='OLD',ERR=120)
      REWIND 98
      READ(98,'(A)') DIRNAM
      CLOSE(98)
      CALL SYSTEM('\rm -f .tmp_dirtst')
      LENDIR=LEN_TRIM(DIRNAM)
      LDIR=.TRUE.
 120  RETURN
      END
