C======================================================================
	SUBROUTINE INITRET3 (STATUS)
C
C	Initializes stuff for the PDF-2 Database
C	   VERSION for both CDROM and DISK
C
C	   By: Mark Holomany     Date: 17-Oct-1985
C	   Modified by B. H. Toby for the Powder Suite
C======================================================================

	IMPLICIT INTEGER (A-Z)

!	CHARACTER*1  ESC
	CHARACTER*2  INPI
	CHARACTER*3  INCODE
	CHARACTER*5  MINVER
	CHARACTER*6  TMPCOD
	CHARACTER*10 INTEXT
	CHARACTER*64 FLSPEC
	CHARACTER*73 EXPBUF
	INTEGER*2    ININDX
	LOGICAL      WRTITL

	INCLUDE  'DSPCDS.CMN'

	CHARACTER*2  DSPFN(MAXFNC)
	DATA  DSPFN /'* ', 'DA', 'DD', 'SE', 'PG'/

     	INCLUDE  'CDROM.CMN'
	INCLUDE  'COUNTS.CMN'
	INCLUDE  'GRPIND.CMN'        
	INCLUDE  'IORET.CMN'
	INCLUDE  'PICDS.CMN'
	INCLUDE  'RET3.CMN'
	INCLUDE  'STDCDS.CMN'
CCCCC	INCLUDE  '($FORIOSDEF)/nolist'
                    
!	ESC = CHAR(27)
	DBSW = 'PDF2'
C
C      	...Initialize time, date, etc
	REVNO = '1.10 '
	RDATE = '28-Nov-90'
	CTIME = 'XXXXXXXX'
	CDATE = 'XXXXXXXXX'
	HOST  = 'VAX'
C
C	 ... Read the following in to initialize.
C
C	 ...   NUMMIN - Mineral names index
C	 ...   NUMCOD - CODENS file
C	 ...   NUMENT - Database (total possible entries in the bitmap)
C	 ...   INIT_SET - Current PDF Set number to which the init file
C	 ...              pertains
C
C!	FLSPEC = 'RET$DATA:DISP.INIT'
	FLSPEC = 'PS_PDF2_INDEX:DISP.INIT'
	OPEN (UNIT=NFTMP1, FILE=FLSPEC, ERR=901, 
	1     STATUS='OLD',READONLY, SHARED)
	READ (NFTMP1, 1101) INIT_SET, NUMMIN, NUMCOD, NUMENT, MINVER
1101	FORMAT(A2 / I6 / I6 / I6 / A5)
	CLOSE (UNIT=NFTMP1, DISP='KEEP')
C

C	... Display title screen
!	CALL BANNER
!	CALL TITLE (WRTITL)
!	IF(WRTITL) WRITE(NOUT,1659) ESC,ESC,ESC
!1659	FORMAT(' ',  A,'[24;1H',  A,'[7m',
!	1      29X,'Push RETURN to continue ',26X,A,'[m',$)
C
C	... Open all files
C!	FLSPEC = 'RET$DATA:MINERAL' // INIT_SET // '.DAT'
!	FLSPEC = 'PS_PDF2_INDEX:MINERAL' // INIT_SET // '.DAT'
!	OPEN (UNIT=NMINGP, 
!	1	FILE=FLSPEC, ERR=901, 
!	2     FORM='FORMATTED', ACCESS='DIRECT', RECL=29,
!	3     STATUS = 'OLD', SHARED, READONLY)
!
C!	FLSPEC = 'RET$DATA:MINNAM' // INIT_SET // '.IND'
!	FLSPEC = 'PS_PDF2_INDEX:MINNAM' // INIT_SET // '.IND'
!	OPEN (UNIT=NMINRL, 
!	1	FILE=FLSPEC, ERR=901, 
!	2     ACCESS='DIRECT', FORM='UNFORMATTED',
!	3     RECORDTYPE='FIXED', RECL=13,
!	4     STATUS='OLD', SHARED, READONLY)
!
C!	FLSPEC = 'RET$DATA:CODENS' // INIT_SET // '.DAT'
	FLSPEC = 'PS_PDF2_INDEX:CODENS' // INIT_SET // '.DAT'
	OPEN (UNIT=NCODEN, 
	1	FILE=FLSPEC, ERR=901, 
	2       ACCESS='DIRECT', FORM='FORMATTED',
	3       STATUS='OLD', SHARED, READONLY)


C!	FLSPEC = 'RET$DATA:RETHELP' // INIT_SET // '.HLP'
!	FLSPEC = 'PS_PDF2_INDEX:RETHELP' // INIT_SET // '.HLP'
!	OPEN (UNIT=HLPTXT, 
!	1	FILE=FLSPEC, ERR=901, 
!	1     ACCESS='DIRECT', FORM='FORMATTED', RECL=80,
!	2     STATUS='OLD', SHARED, READONLY)
!
C!	FLSPEC = 'RET$DATA:RETHELP' // INIT_SET // '.IND'
!	FLSPEC = 'PS_PDF2_INDEX:RETHELP' // INIT_SET // '.IND'
!	OPEN (UNIT=HLPIND, 
!	1	FILE=FLSPEC, ERR=901, 
!	1     ACCESS='DIRECT', FORM='UNFORMATTED', RECL=84,
!	2     STATUS='OLD', SHARED, READONLY)
!
!	OPEN (UNIT=PRINTR, FILE='PRINT.PDFCARD', STATUS='NEW')
!	OPEN (UNIT=PRINTR,
!	1     FILE='RET$SCRATCH:PRINT.PDFCARD',
!	2     STATUS='NEW')
!
C
C       ... Read binary file to fill commons
C!	FLSPEC = 'RET$DATA:VAXPDF' // INIT_SET // '.BIN'
	FLSPEC = 'PS_PDF2_INDEX:VAXPDF' // INIT_SET // '.BIN'
      OPEN (UNIT=NFTMP1, 
	1	FILE=FLSPEC, ERR=901, 
     1      FORM='UNFORMATTED',
     2      STATUS='OLD', READONLY, SHARED)
      READ (NFTMP1) GRPCDS, NUMCDS, CODIND
      READ (NFTMP1) NPICDS, LNTEXT, LNTEX2, PICDS, PICD2, PLTEXT, PLTEX2
      READ (NFTMP1) NCODES, LENEXP, BEGEXP, CODE, EXPAND

C
C	... Set default translation to non-ASCII
	ASCII = .FALSE.
C
C	... Define d-spacing footnote codes
	DO 4010 N=1,MAXFNC
	CALL PITRAN (DSPFN(N), INTEXT, LEN)
	IF(DSPFN(N) .EQ. '* ') THEN
	   DSPFNC(N) = '*'
	ELSE
	   DSPFNC(N) = INTEXT(1:1)
	   IF(LEN .GT. 1) CALL ERRTXT ('E',
	1    'Footnote code expansion > 1 char')
	ENDIF
4010	CONTINUE
C
C	... Establish line drawing character set
	CALL LINES
C
C	... Reset photocomp routine execution switches (init)
	CALL ONCE
C
C	... Turn off error checking for demo/production
C>>>	CALL ERRTXT ('*', 'D0')
!	CALL ERRTXT ('*', 'F1:ERR.TXT')
!	IF(WRTITL) READ (NIN, '(A)', ERR=9000, END=9000) REPLY

9000	STATUS = 0
	RETURN
901	STATUS = 1
	WRITE(*,'(2A)') ' PDF-2 ERROR: unable to open file: ',
	1	FLSPEC(:LENCH(FLSPEC))
	STOP

	END
