      SUBROUTINE WADATA
      IMPLICIT NONE
*
* WADATA - Write Ascii data part of data file record from common block
*
* Local Variables...
*    ASCREC - Ascii record to be written to output file
*    ASCLEN - Length of Ascii record
*    I      - Loop counter
*    VALID  - Function to test whether values are legal reals
*                                         
      INCLUDE 'misc.inc'
      INCLUDE 'labl.inc'
      INCLUDE 'meta.inc'
      INCLUDE 'data.inc'

      CHARACTER ASCREC*2000
      INTEGER   ASCLEN, I
      LOGICAL   VALID

      RECLEN = INDEX(RECORD,'*DATA*') + 5    

      DO 20, I = 1, TNP
         IF (VALID(RDATA(I))) THEN
            WRITE (UNIT=RECORD(RECLEN+1:),FMT='(1PE17.10)') RDATA(I)
         ELSE
            RECORD(RECLEN+1:) = NULL
         ENDIF
         RECLEN = RECLEN + RWIDTH
   20 CONTINUE
*
* ...and then the Quality values...
*
      DO 30, I = 1, TNP
         IF (VALID(RQUAL(I))) THEN
            WRITE (UNIT=RECORD(RECLEN+1:),FMT='(1PE17.10)') RQUAL(I)
         ELSE
            RECORD(RECLEN+1:) = NULL
         ENDIF
         RECLEN = RECLEN + RWIDTH
   30 CONTINUE
*
* Attach any record key to the front of completed record and write out...
*
      IF (RECKEY .NE. ' ') THEN
         ASCREC = RECKEY(1:20)//RECORD(1:RECLEN)
         ASCLEN = 20 + RECLEN
      ELSE
         ASCREC = RECORD(1:RECLEN)
         ASCLEN = RECLEN
      ENDIF

      CALL WAWRIT (ASCREC,ASCLEN)

      RETURN
      END    
