     	SUBROUTINE WRWMDI
C
C  PROGRAMMER:  R. L SNYDER
C		ALFRED UNIVERSITY   FEB-1987
C
C	THIS ROUTINE WRITES OUT AN MDI RAW DATA FILE
C	FROM THE COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
     	CHARACTER IQS*1, DAY*9, TIM*8
     	CHARACTER JJDAT*6

     	CALL COLORS(-1)
     	CALL PUTEXT('Writing the output file... Please wait...',41,24,1)

C        TYPE*,'NPTS=',NPTS
C        DO I=1,NPTS
C        TYPE*,'YOBS(',I,')=',YOBS(I)
C        ENDDO

C
C  WRITE OUT THE ASCII FILE...
C
     	CLOSE( UNIT=IOUT )
     	OPEN( UNIT=IOUT, FILE=FILOUT, STATUS='NEW', ERR=888,
     1 FORM='FORMATTED', CARRIAGECONTROL='LIST' )
     	IDATM = DATM
     	    ENCODE( 6, 1, JJDAT ) IDATM
1	FORMAT(I6)
     	WRITE(IOUT,1000,ERR=888) JJDAT(1:2), JJDAT(3:4), JJDAT(5:6), 
     1 (SLID(I),I=1,14)
1000	FORMAT(7X,A2,'-',A2,'-',A2,' DIF   ',14A4)
     	WRITE(IOUT,1002,ERR=888) DANG(1),DANG(3),DANG(10),
     1 ANODE(IELE), WAVE(1,IELE), DANG(2), NPTS
1002	FORMAT(F7.3,F6.3,F6.1,1X,A2,F10.6,F8.3,I7)
     	YOBS(NPTS+1) = -1
     	WRITE(IOUT,1003,ERR=888) (YOBS(I), I=1, NPTS+1)
1003	FORMAT(8F8.0)
     	GOTO 999

777	IERR = 3		!BAIL OUT
     	GOTO 999
888	IERR = 1
999	RETURN
     	END
