C
C SUBROUTINE 'TASKQ'
C ==================
C
C Output a text prompt to the terminal (and log file if required) for a
C question with a yes/no answer. Return the answer as a logical flag.
C
C Logging as for TPROMP and TREAD
C
C If possible do not output a carriage return or linefeed after the prompt.
C
      SUBROUTINE TASKQ (STR, REPLY, EOF)
C
C Parameters:
C
C      STR (I)   Character string for the question 
C                (The string ' (y/n) [y]: ' or ' (y/n) [n]: ' will be appended)
C    REPLY (I/O) Logical flag: On input  .true.  if default reply is yes
C                                        .false. if default reply is no
C                              On output .true.  if reply was yes
C                                        .false. if reply was no
C      EOF (O)   Logical flag = .true. if end of file (or read error) 
C                encountered else .false.
C
C====== Specification statements
C
      CHARACTER*(*) STR
      LOGICAL REPLY, EOF
      CHARACTER*120 PROMPT
      CHARACTER*20 YESNO
      LOGICAL LOG
      COMMON /TTCOMN/ LUNR, LUNW, LUNLR, LUNLW, MODETT, LOG
      SAVE /TTCOMN/
C
C====== Get length less trailing blanks
C
      LL = LEN(STR)
      DO 100 L=LL,1,-1
         IF (STR(L:L).NE.' ') GO TO 120
100   CONTINUE
      L=1
C
C====== Form prompt string
C
120   IF (REPLY) THEN
         PROMPT = STR(1:L)//' (y/n) [y]: '
      ELSE
         PROMPT = STR(1:L)//' (y/n) [n]: '
      ENDIF
      L = L + 12
C
C====== Output prompt
C
200   CALL TPROMP (PROMPT(1:L))
C
C====== Get reply
C
      CALL TREAD (YESNO, EOF)
      IF (EOF) RETURN
      IF (YESNO.EQ.' ') RETURN
      DO 300 I=1,20
         IF (YESNO(I:I).NE.' ') THEN
            IF (YESNO(I:I).EQ.'y'.OR.YESNO(I:I).EQ.'Y') THEN
               REPLY = .TRUE.
               RETURN
            ELSE IF (YESNO(I:I).EQ.'n'.OR.YESNO(I:I).EQ.'N') THEN
               REPLY = .FALSE.
               RETURN
            ELSE
               GO TO 200
            ENDIF
         ENDIF
300   CONTINUE
      RETURN
      END
