     	SUBROUTINE WRWSAS
C
C  PROGRAMMER:  R. L. Snyder
C		ALFRED UNIVERSITY,  Jul-1988
C
C	THIS ROUTINE WRITES OUT A GSAS RAW DATA FILE
C	FROM THE COMMON BLOCKS
C
     	INCLUDE 'FILECONV.CBS'
     	CHARACTER*80 TBUF
     	INTEGER*2 ITIT(40)
     	EQUIVALENCE (ITIT,SLID)

     	CLOSE( UNIT=IOUT )
     	OPEN( UNIT=IOUT, FILE=FILOUT, STATUS='NEW', ACCESS='SEQUENTIAL',
     1 RECORDTYPE='FIXED',RECL=80,FORM='FORMATTED', ERR=888 )
C
C  WRITE THE FILE HEADER INFORMATION...
C
	NSTEPS = NPTS
	NREC = (NSTEPS-1)/10+1
c
c  GSAS requires all I's to be 5 digits maximum. - so we will scale them 
c  here. and if a scale factor is determined - a form breaking message will 
c  be output.
c
    	scaley = 1.0

c        DO J=1,100
c        TYPE*,'YOBS(',J,')=',YOBS(J)
c        ENDDO

     	DO J = 1, NPTS
     	if( YOBS(J) .gt. 99999. .and. YOBS(J) .gt. scaley) 
     1  scaley = YOBS(J)
     	ENDDO
    	if( scaley .gt. 1.0 ) then
    		scaley = 99999. / scaley 
    		write(6,1055) scaley
1055	format(' Intensities have been scaled by ',e14.7)
    	endif
C
C  Write out the header block
C
     	WRITE(IOUT, 1065) SLID
1065	FORMAT(20A4)

c        TYPE*,'BANG(1)=',BANG(1),'   BANG(3)=',BANG(3)
	WRITE(TBUF,1075) 'BANK 1',NSTEPS,NREC,'CONST',BANG(1)*100.,
     1 BANG(3)*100., BANG(10)
C1075	FORMAT(A,2I8,1X,A,2F10.0,f10.2,22X)
1075	FORMAT(A,2I8,1X,A,2F10.1,f10.2,22X)   !S.Z. SEP.20.93 
                                              ! for bang(3) < 0.01
        WRITE(IOUT,'(A)') TBUF
C
C  WRITE THE INTENSITY DATA...
C
     	DO I = 1, NPTS, 10
     	WRITE(IOUT, 1080) (YOBS(J)*scaley, J=I,I+9)
1080	FORMAT(10F8.0)
     	ENDDO
     	GOTO 999

888	IERR = 1
999	RETURN
     	END
