	SUBROUTINE INPUT( NFILE, TITLE, ALO, AHI, STEP, TIME, WAVEL,
     & THETA1, DSP1, RELINT, INTCPS, FWHM1, NPEAKS, IOUT)
C
C	READ A DIFFRAC-11 D & I FILE FOR PROGRAM INTCAL.
C	JIM WALKER     25-MAR-85
C
	REAL*4 THETA1(200), DSP1(200), RELINT(200), INTCPS(200), FWHM1(200)
	REAL*4 TITLE4(12), F4
	BYTE  TITLE(80)
	INTEGER*2 JPEAKS
	CHARACTER NFILE*40, IOUT*1
	COMMON /IO/ IO5,IO6,IO7,IO10,IO11,IO20
        DATA F4/0.0/
	OPEN ( UNIT=IO10, NAME=NFILE, TYPE='OLD', SHARED,
     +	  READONLY, FORM='UNFORMATTED', ACCESS='DIRECT', 
     &    RECORDSIZE=1, ASSOCIATEVARIABLE=NEXT)

C
C Get run title
	DO 7,I=1,12
	J=I
	READ(IO10'J) TITLE4(I)
       IF(IOUT .EQ. 'D') WRITE(IO20'J) TITLE4(I)
7	CONTINUE
	ENCODE(80,4,TITLE) (TITLE4(I),I=1,12)
4	FORMAT(' SAMPLE ID: ',4A4,'  MEASURED: ',5A4,'  BY ',3A4)
	TITLE(56) = ' '
C
C Get the run parameters
	READ(IO10'13) ALO
	READ(IO10'14) AHI
	READ(IO10'15) STEP
	READ(IO10'16) TIME
	READ(IO10'19) WAVEL
       IF(IOUT .EQ. 'D') THEN
		WRITE(IO20'13) ALO
		WRITE(IO20'14) AHI
		WRITE(IO20'15) STEP
		WRITE(IO20'16) TIME
       		DO 2 II=17,38
       		READ(IO10'II) F4
2		WRITE(IO20'II) F4
       ENDIF
C
C Get the peaks
	READ(IO10'21) JPEAKS
	NPEAKS = JPEAKS
	BIGINT= 0.
	NEXT = 41
C
	DO 30, I=1,NPEAKS
	READ(IO10'NEXT) DSP1(I)
	READ(IO10'NEXT) INTCPS(I)
	READ(IO10'NEXT) FWHM1(I)
	NEXT = NEXT + 3
	THETA1(I) = D2TH(DSP1(I),WAVEL)
	IF (INTCPS(I).GT.BIGINT) BIGINT = INTCPS(I)
30	CONTINUE
C
	DO 40, I=1,NPEAKS
	RELINT(I) = 100.0 * INTCPS(I) / BIGINT
40	CONTINUE
C
	RETURN
	END
C
	FUNCTION D2TH(D,W)
C	W = 2*D*SIN(TH)
	D2TH = 360.0/3.1415926 * ASIN( W / 2.0 / D)
	RETURN
	END

	SUBROUTINE STDFIL(DINT,NUM,ISTD,IOUT,IUNIT,MAX)
C   Look for a file containing the standard in powd:[public.exe.intcal.standards]
C   The standard file has one number to a line.  Negative numbers indicate
C   comments.  0.0 indicates that the comment should be echoed on the
C   terminal.
C
	CHARACTER ISTD*40, NOTES*80
	REAL*8 DINT(200)
C
C   open the file
	OPEN(UNIT=IUNIT,NAME=ISTD, READONLY,STATUS='OLD',ERR=910,
     &   DEFAULTFILE='POWD:[PUBLIC.EXE.INTCAL.STANDARDS]SAMPLE.ICS')
C
C   read the lines
	NUM = 1
10	READ(IUNIT,20,END=999) DINT(NUM),NOTES
20	FORMAT(F10.5,A80)
	IF (DINT(NUM).EQ.0.0) WRITE(IOUT,30) NOTES
30	FORMAT(X,A80)
	IF (DINT(NUM).GT.0.0) NUM = NUM + 1
	IF (NUM.LT.MAX) GOTO 10
C
	WRITE(IOUT,40) NUM-1
40	FORMAT(' Only the first',I4,
     &	  ' lines for the standard will be used.')
C
999	NUM = NUM - 1
	CLOSE(UNIT=IUNIT)
    	RETURN
C
910	NUM = 0
	RETURN
     	END
