C*	DSMUIC	- READ ALL UIC'S AND SAVE FILE-ID'S IN A SCRATCH FILE
C
	SUBROUTINE DSMUIC (NDEV)
C
C	NDEV	= NUMBER OF DEVICE IN IDEV TO SEARCH
C
	INCLUDE 'DSMCM.COM'
C
	DIMENSION IDB(8), NUSE(2)
	DIMENSION BUIC(2), BDEV(6)
	EQUIVALENCE (NUIC,BUIC)
C
	DIMENSION FIDSC (3), RBSC (128,10)
	DIMENSION FID00 (3), RB00 (128, 1)
	DIMENSION FIDDIR(3), RBDIR(128, 10)
	EQUIVALENCE (RB00,RBMAP), (RBDIR,RBMAP(1,2))
C
	DATA IRBSC /10/, ILSC /1/
	DATA IRB00 / 1/, IL00 /2/
	DATA IRBDIR/ 10/, ILDIR/3/
	DATA IRBMAP/16/, ILMAP/4/, IRSMAP/2/
C
	DATA NWPB/256/, NWPFN/8/, MAXHDR/0/
	DATA BDEV/6*0/
C
	ILNDX = 1		! INDEXF.SYS LUN
C
C	ASSIGN LUNS TO PROPER DEVICE
C	FOR [0,0]000000.DIR FILE AND INDIVIDUAL DIRECTORY FILES
C
	CALL ASNLUN (IL00, IDEV(1,NDEV), IDEV(2,NDEV))
	CALL ASNLUN (ILDIR, IDEV(1,NDEV), IDEV(2,NDEV))
C
C	OPEN SCRATCH FILE AND [0,0]000000.DIR MFD FILE
C	SCRATCH FILE (FIDSC) USES I*4 RECORD NUMBERS
C
	CALL X1LU (FIDSC, RBSC, IRBSC, 1, 1,
	1	ILSC, 'S', 'WK0:', -1, 'DSM1.TMP', NER)
	IF (NER .NE. 0) CALL DSMER (ILSC, NER)
C
	CALL X1LU (FID00, RB00, IRB00, NWPFN, 0,
	1	IL00, 'R', '[0,0]', -1, '000000.DIR', NER)
	IF (NER .NE. 0) CALL DSMER (IL00, NER)
C
C	INITIALIZE RECORD NUMBERS
C
	KRSC = 1
	NR00 = 1
	CALL X1LRN (FID00, IEF00)
C
C	GET NEXT .DIR ENTRY IN 000000.DIR MFD
C
 100	CONTINUE
	CALL DSMNDE (FID00, NR00, IEF00, IDB, .TRUE., LEOF)
	IF (LEOF) GO TO 400
C
C	CONVERT RAD-50 FILE NAME TO ASCII FOR X1LU LOOKUP
C
	CALL R50ASC (6, IDB(4), BDEV(1))
D	TYPE 1010, BDEV, IDB(1),IDB(2),IDB(3)
D1010	FORMAT (' ',6A1, 4X,3O8)
C
C	OPEN NEXT DIRECTORY FILE ON FILE-ID
C
	CALL X1LUID (FIDDIR, RBDIR, IRBDIR, NWPFN, 0,
	1	ILDIR, IDB, NER)
	IF (NER .NE. 0) CALL DSMER (ILDIR, NER)
	CALL X1LRN (FIDDIR, IEFDIR)
C
C	CONVERT ASCII UIC TO BINARY UIC
C
	CALL DSMCU (BDEV(1), BUIC(2))
	CALL DSMCU (BDEV(4), BUIC(1))
D	TYPE 1020,BUIC
D1020	FORMAT (' ',2O4)
C	TYPE 1022,ISC,BSC,KRSC,BUIC
C1022	FORMAT (' ',6I10/' ',12I5/' ',I5,2O4)
	CALL X1DW (FIDSC, KRSC, 2, NUIC)
	KRSCSV = KRSC - 1
	NENTRY = 0
	NRDIR = 1
C
C	GET EACH FILE SPEC FROM DIRECTORY AND WRITE TO SCRATCH FILE
C	WRITE OUT FILE NO. AND SEQUENCE NUMBER.
C
 150	CONTINUE
	CALL DSMNDE (FIDDIR, NRDIR, IEFDIR, IDB, .FALSE., LEOF)
	IF (LEOF) GO TO 200
	CALL X1DW (FIDSC, KRSC, 2, IDB(1))
	MAXHDR = MAX0(MAXHDR, IDB(1))
	NENTRY = NENTRY + 1
	GO TO 150
C
C	END OF CURRENT DIRECTORY FILE
C
 200	CONTINUE
	CALL X1DW (FIDSC, KRSCSV, 1, NENTRY)
	CALL X1EF (FIDDIR)
D	TYPE 1030,NENTRY,KRSCSV
D1030	FORMAT (' NENTRY,KRSCSV', 2I10)
	GO TO 100
C
C
C	ALL DIRECTORIES PROCESSED - BUILD UIC MAP
C
C
 400	CONTINUE
	CALL X1EF (FID00)
C
C	OPEN SCRATCH FILE FOR SEQUENCE NO./UIC MAP
C
	CALL X1LU (FIDMAP, RBMAP, IRBMAP, IRSMAP, 0,
	1	ILMAP, 'S', 'WK0:', -1, 'DSM2.TMP', NER)
	IF (NER .NE. 0) CALL DSMER (ILMAP, NER)
C
	NPASS = (MAXHDR-1)/(IRBMAP/IRSMAP*NWPB) + 1
C
C	SET MAP SCRATCH FILE TO -1'S
C
	NRMAP = 1
	CALL SIVFL (-1, RBMAP, IRBMAP*NWPB)
	DO 480 I=1, NPASS
	CALL X1DW (FIDMAP, NRMAP, IRBMAP*NWPB, RBMAP)
 480	CONTINUE
	CALL X1LRN (FIDSC, KEFSC)
C
	DO 490 I=1, NPASS
	ILO = (I-1)*(IRBMAP/IRSMAP*NWPB) + 1
	IHI = I*(IRBMAP/IRSMAP*NWPB)
	KRSC = 1
C
 410	CONTINUE
	IF (KRSC .GT. KEFSC) GO TO 490
	CALL X1DR (FIDSC, KRSC, 1, NUIC)
C
C	INSERT UIC INTO TABLE
C
	CALL DSMBS (1, NFO, IPOS, NERUIC)
C
	CALL X1DR (FIDSC, KRSC, 1, NENTRY)
D	TYPE 1040, BUIC(2),BUIC(1), NENTRY, I, NFO
D1040	FORMAT (' ',2O4, 2I6, 'NFO=',I5)
	IF (NENTRY .LE. 0) GO TO 410
C
	DO 420 J=1, NENTRY
	CALL X1DR (FIDSC, KRSC, 2, NUSE)
	NRMAP = NUSE(1)
	NUSE(1) = NUIC
D	TYPE 1035,NUSE
D1035	FORMAT (' NUSE= ',2O7)
	IF (NRMAP.GE.ILO .AND. NRMAP.LE.IHI)
	1	CALL X1DW (FIDMAP, NRMAP, 2, NUSE)
 420	CONTINUE
	GO TO 410
C
 490	CONTINUE
	CALL X1EF (FIDSC)
C
C	OPEN [1,1]INDEXF.SYS ON SPECIFIED DEVICE
C
	CALL ASNLUN (ILNDX, IDEV(1,NDEV), IDEV(2,NDEV))
	CALL DBKOF (ILNDX, 'R', '[0,0]', -1, 'INDEXF.SYS', NERR)
	IF (NERR .NE. 0) CALL DSMER (ILNDX, NERR)
C
	RETURN
	END
