	PROGRAM IPNS
!Program to take IPNS data files and convert them to GSAS raw powder files
	REAL*4		START		!Start 2-theta
	REAL*4		FINISH		!End 2-theta (no point here)
	REAL*4		STEP		!2-theta steps
	REAL*4		YO(10)		!One line of output
	INTEGER*4	IUIN,IUOUT	!Input and output unit nos.
	CHARACTER*80	INNAME,OUTNAME	!Input & output file names
	CHARACTER*1	IX		!Dummy character
	CHARACTER*80	TITLE		!Data string

	DATA	IUIN,IUOUT/10,11/

!Open files

	TYPE *,' Enter IPNS data file name'
	ACCEPT '(A)',INNAME
	OPEN(IUIN,FILE=INNAME,STATUS='OLD',ACCESS='SEQUENTIAL')
	TYPE *,' Enter GSAS output data file name'
	ACCEPT '(A)',OUTNAME
	OPEN(IUOUT,FILE=OUTNAME,STATUS='UNKNOWN',ACCESS='SEQUENTIAL',
	1	RECORDTYPE='FIXED',RECL=80,FORM='FORMATTED')

!Read header

	IERR = 0
	IBANK = 1
	DO WHILE ( IERR.EQ.0 )
	  TITLE = ' '
          READ(IUIN,'(A)',IOSTAT=IERR) TITLE
	  IF ( IERR.NE.0 ) THEN
	    CLOSE(IUIN)
	    CLOSE(IUOUT)
	    STOP 'All done'
	  END IF
	  READ(TITLE,'(55X,I4,3X,I2,5X,I4)') NSTEPS,ISTEP,ISTART
	  TITLE = TITLE(1:52)//TITLE(74:80)
          IF ( IBANK.EQ.1 ) THEN
	    WRITE(IUOUT,'(A)') TITLE
            TYPE 1,TITLE(1:66)
1	    FORMAT(' Title: ',A)
	  END IF

	  START = ISTART
	  STEP = ISTEP
	  FINISH = ISTART+(NSTEPS-1)*ISTEP
	  TYPE 2,START,FINISH,STEP
2	  FORMAT(' Starting TOF = ',F10.2,' ending TOF = ',F10.2,
	1	' step = ',F6.2)
	  NREC = (NSTEPS-1)/10+1
	  TYPE 3,NSTEPS,NREC
3	  FORMAT(' Number of data = ',I6,' number of output records = ',I5)
	  TITLE = ' '
	  WRITE(TITLE,4) 'BANK',IBANK,NSTEPS,NREC,'CONST',START,STEP
4	  FORMAT(A,I2,2I8,1X,A,2F10.0)
          WRITE(IUOUT,'(A)') TITLE

!Process data

	  DO IREC = 1,NREC
	    READ(IUIN,'(A)') TITLE
	    WRITE(IUOUT,'(A)') TITLE
	  END DO
	  IBANK = IBANK+1
	END DO

	END
