C       SUBROUTINE ADRIN( DUNK, THUNK, INUNK, NUMDI, TITLE,
C     1 AHI, ALO, TIME, STEP)
C
C  THIS IS A GENERAL SUBROUTINE READ TO THE d-I INFORMATION
C  FROM AN ADR FILE. THE ADR INPUT FORMAT FOR SIEMENS FILES IS:
C  RECORD  1: BLANK
C  RECORD  2: BLANK
C  RECORD  3: BLANK
C  RECORD  4: ADR HEADER RECORD
C  RECORD  5: ALFRED UNIVERSITY HEADER RECORD
C  RECORD  6: DATE AND TIME OF PROCESSESING WITH ADR
C	(1X,'DATE:',1X,9A1,5X,'TIME: ',1X,8A1)
C	FOR INPUT: (7X,9A1,12X,8A1)
C  RECORD  7: OUTPUT FILE NAME
C	(' OUTPUT FILE NAME:'40A1) - (18X,10A1)
C  RECORD  8: TITLE OF RUN
C	('TITLE OF RUN:',80A1) - (13X,80A1)
C  RECORD  9: DATE OF RUN
C	(' DATE OF RUN: ',9A1) - (14X,9A1)
C  RECORD 10: BLANK
C  RECORD 11: STARTING ANGLE AND COUNT TIME (17X,F9.4,4X,F7.2)
C  RECORD 12: ENDING ANGLE AND X SIGMA (17X,F9.4,4X,F7.2)
C  RECORD 13: ANGLE INCREMENT AND Y SIGMA (17X,F9.4,4X,F7.2)
C  RECORD 14: POINTS FOR SMOOTH AND MAXIMUM FWHM
C  RECORDS 15-?: EXTRA RUN PARAMETERS
C  RECORD 16: d-I HEADER
C	(' PEAK',....)
C  RECORD 17: PK. #, 2-THETA, *, d, RELI, DELTA d, ABS I, FWHM
C	(1XI3,1XF9.4,A1,F8.3,F8.2,10X,F6.4,F9.1,F9.4)
C  OPTIONAL INFO ON d-I RECORD: IN PLACE OF 10X - hkl's in 3I3,1X
C
	CHARACTER*40 NFILE
	CHARACTER*1 IDOT, IBL, NAST, IAST
	CHARACTER*80 TITLE
	DIMENSION DUNK(200), THUNK(200), INUNK(200), IT(2), IPE(2)
	DATA IO5,IO6,IO7,IO10,IO20,IO30/5,6,6,10,20,30/
	DATA IDOT, IBL, IAST, IPE/'.', ' ', '*','PE','AK'/
C
C   INITIALIZE NUMDI - ZERO MEANS NO DATA ON FILE OR NO SUCH FILE
C
	NUMDI = 0
C
C  ALFRED OR SIEMENS FORMAT?
C
	WRITE(IO7,530)
530	FORMAT(/' Input must be from a d-I file.  If your d''s and',
     1' I''s are not',/' on a file you must exit this program and ',
     2'run POWD:[POWDER.GENRAL]FILMOD to create'/
     1' the required file from typed',
     1' input.  The normal format is Siemens'//
     1 '$ENTER your d-I file type: <0>=Siemens (Default), <1>=',
     1 'Alfred, <2>=EXIT: ')
	READ(IO5,535) IFMT
535	FORMAT(I)
	IF(IFMT .GE. 2)STOP 'TYPE RUN POWD:[POWDER.GENRAL]FILMOD'
	IF(IFMT .EQ. 1) IFMT = 2
	IF(IFMT .LE. 0) IFMT = 1
C
C  GET NAME OF THE FILE
C
	WRITE(IO7,540)
540	FORMAT(/'$Enter the name of the ADR d-I file :')
	READ(IO5,550)NFILE
550	FORMAT(A40)
C
C  OPEN THE ADR FILE
C
	OPEN(UNIT=IO30, NAME=NFILE, TYPE='OLD',FORM='FORMATTED',
     1 READONLY)	
C
C  SKIP OFF THE FIRST SEVEN BLANK RECORDS
C
	DO 556 I=1,7
556	READ(IO30,555)
555	FORMAT(1X)
C
C  READ HEADER RECORDS AND GET THE TITLE
C
	GO TO (560,580), IFMT
560	READ(IO30,570,END=710) TITLE
570	FORMAT(11X,A80)
	GO TO 600
580	READ(IO30,590,END=710) TITLE
590	FORMAT(12X,A80)
C
C  SKIP THE NEXT TWO RECORDS
C
600	READ(IO30,555)
	READ(IO30,555)
C
C  GET SCAN LIMITS AND MEAS. CONDITIONS.
C
	GO TO (610,630), IFMT
610	READ(IO30,620,END=710) ALO,TIME,AHI,STEP
620	FORMAT(17X,F8.4,19X,F6.1/16X,F9.4/17X,F8.4)
	GO TO 650
630	READ(IO30,640,END=710) ALO,TIME,AHI,STEP
640	FORMAT(18X,F8.4,19X,F6.1/17X,F9.4/18X,F8.4)
C
C  SEARCH FOR THE RECORD WITH "PEAK" STARTING IN COLUMN 1 OR 2
C
650	DO 700 I=1,50
	GO TO (660,680), IFMT
660	READ(IO30,670,END=710)(IT(J),J=1,2)
670	FORMAT(2A2)
	GO TO 695
680	READ(IO30,690,END=710) (IT(J),J=1,2)
690	FORMAT(1X,2A2)
695	IF( IT(1).EQ.IPE(1) .AND. IT(2).EQ.IPE(2) )GO TO 750
700     CONTINUE
C
C **	FILE IN WRONG FORMAT
C
710	STOP ' ????? FILE IN WRONG FORMAT'
C
C  FILE IS IN CORRECT FORMAT
C
C  READ THE TWO-THETA AND INTENSITIES
C
750	GO TO (760,780),IFMT
760	READ(IO30,770,END=830) THETA,NAST,TEMP0,TEMP1
770	FORMAT(3X,1XF9.5,A1,1XF7.4,1XF7.2,16X,F9.1,F9.4)
	GO TO 800
780	READ(IO30,790,END=830) THETA,NAST,TEMP0,TEMP1
790	FORMAT(4X,1XF9.5,A1,1XF7.4,1XF7.2,16X,F9.1,F9.4)
800	IF( TEMP0 .EQ. 0 )GO TO 830
C
C  ELIMINATE ALPHA 2 PEAK FROM INPUT LIST
C
        IF(IAST.EQ.NAST)GO TO 750
	NUMDI = NUMDI + 1
	THUNK(NUMDI) = THETA
	DUNK(NUMDI) = TEMP0
	INUNK(NUMDI) = TEMP1 + 0.5
	IF( NUMDI .LT. 200 )GO TO 750
        WRITE(IO7,810)
810    FORMAT(/1X,'INPUT D-I LIST TRUNCATED TO 200 VALUES')
C
C  TEST OUTPUT ROUTINE
C
830	CALL OUTPUT( DUNK, THUNK, INUNK, NUMDI, TITLE,
     1 AHI, ALO, TIME, STEP)
C	RETURN
	CALL EXIT
        END

	SUBROUTINE OUTPUT( DUNK, THUNK, INUNK, NUMDI, TITLE,
     1 AHI, ALO, TIME, STEP)
C
C  THIS SUBROUTINE ALLOWS THE WRITING OF A SEARCHABLE PATTERN WITH A
C  NEW FILE NAME OR WRITING AN EDITED FILE WITH THE ORIGINAL NAME
C
	CHARACTER*80 TITLE
	BYTE NAMEN(16), NAME(16), IBL
	LOGICAL*1 DAT(9)
	DIMENSION INUNK(200),DUNK(200),THUNK(200)
	DATA IO5, IO6, IO7, IO20/5,6,6,6/
	DATA IBL/' '/
400	CALL DATE(DAT)
	WRITE(IO20,2000)DAT,TITLE
2000	FORMAT(//' XRAY POWDER DATA ANALYSIS',/4X,
     1	'MODIFIED PATTERN',/1X,'DATE: ',9A1,//1X,'SAMPLE ID: ',
     2	A80,64X,/1X)
	WRITE(IO20,2001)ALO,TIME,AHI,STEP
2001	FORMAT(1X,'STARTING ANGLE : ',F8.4,5X,'COUNT TIME  : ',
     1	F6.1/1X,'ENDING ANGLE  : ',F9.4,/1X,'ANGLE INCREMENT: ',F8.4)
	WRITE(IO20,2002)
2002	FORMAT(//1X,'PEAK  2-THETA      D     RELINT')
	DO 700 I=1,NUMDI
	WRITE(IO20,1060)I,THUNK(I),DUNK(I),INUNK(I)
1060	FORMAT(1X,I3,2X,F9.5,2X,F7.4,F6.2,I6)
700	CONTINUE
999	RETURN
	END

