C  COMPUTER: VAX SERIES			OPERATING ENVIRONMENT: VMS
C  LANGUAGE: FORTRAN IV, WITHOUT WATFOR/WATFIV ADDITIONS AND IF/ELSE
C            STATEMENTS
C
C    WRITTEN BY BENJAMIN J. TAYLOR ON MAY 3, 1995
C
C  This program accepts a list of star ID numbers and outputs readings from
C   the [Fe/H] catalog and a composite list of original literature sources.
C
C -1- INSTRUCTIONS FOR USE
C
C   The program has the following I/O files:
C
C	File 8--READ (8,	Input	[Fe/H] catalog ("fehd.dat", 
C					 "comment.dat', and "refs.dat")
C	File 9--READ (9,	Input	User input file, specifying star IDs
C	File 10-WRITE (10,	Output	Values of [Fe/H], rms error, and number
C					 of degrees of freedom for each input-
C					 star ID, plus composite list of 
C					 original literature sources for the 
C					 data
C
C   Each line of the input file has the following structure:
C
C	A2	Catalog designation.  "vB" (Hyades), "Tr" (Coma), "BD", "DM", 
C   		 "HD", "W" (Woolley), and "HR" (all without quotation marks) 
C		 are acceptable designations.  The designations are not case 
C		 sensitive, and " W" and "W " are both acceptable.
C	A1	"+" or "-" sign for "BD" and "DM" designations, otherwise blank.
C	I6	Catalog number.  The figures for BD numbers are run together
C		 (example: the number for "+41 3306" appears as "413306".
C	A1	"A" or "B" for components of binaries, otherwise blank.  
C		 (Warning: binaries must be cited by their HD designations.)
C		 "a" or "b" may also be used.
C
C    No special line is needed to end the input file; the program senses 
C    end-of-file during the readin process.  An example of an acceptable file
C    is as follows:
C
C	hD   6582
C	bd+413306
C	Vb     13
C	[End-of-file]
C
C -2- GLOSSARY OF PROGRAM VARIABLES
C
C*I,J,K,L,M,N			DO-loop indices, array addresses, and auxiliary 
C				 variables.
C
C*AB(2,2)	CHARACTER*1	AB contains the alphanumeric characters "A",
C				 "a", "B", and "b", and is used to normalize
C				 USERAB to caps.  (See USERAB.)
C				
C*ABVC(1000)	CHARACTER*1	ABVC is read in from file "fehd.dat".  For star
C				 "n", ABVC(n) contains "A" or "B" for binary
C				 designations, "V" for VSL or possible SMR 
C				 stars, and "C" for a comment.  (The comments
C				 are found in "comment.dat".  See also 
C				 CNO.)
C
C*BDSIGN(1000)	 CHARACTER*1	BDSIGN is read in from file "fehd.dat".  For
C				 star "n", BDSIGN(n) is "+" or "-" for BD/DM
C				 numbers and is blank otherwise.
C
C*BLANK		 CHARACTER*1	The alphanumeric character " ".
C
C*CAYNO(10,1000) INTEGER*4	CAYNO is read in from file "fehd.dat".
C				 CAYNO contains "Cayrel de Strobel" numbers 
C				 which identify literature sources in 
C				 "refs.dat".  CAYNO(i,n) contains the "i"th 
C				 "Cayrel de Strobel" number for star "n".
C
C*CNO(1000)	 INTEGER*4	If a comment for star "n" of file "fehd.dat" 
C				 appears in the file "comment.dat", CNO(n)
C				 contains the comment number used in 
C				 "comment.dat".  (See also ABVC and COMMENT.)
C
C*COMMENT(10)	 CHARACTER*78	COMMENT is read in from file "comment.dat".
C				 COMMENT(i) is the "i"th comment in the file.
C				 (See also CNO.)
C
C*DASH		 CHARACTER*1	The alphanumeric character "-".
C 
C*DM		 CHARACTER*2	The alphanumeric characters "DM".  For a BD
C				 designation, "DM" appears instead of "BD" in
C				 the output file.
C
C*FEH(3,1000)			FEH is read in from file "fehd.dat".  For star
C				 "n", FEH(1,n) contains the catalog value of
C				 [Fe/H].  FEH(2,n) contains the rms error, while
C				 FEH(3,n) contains the number of degrees of
C				 freedom for the rms error.
C
C*FLAGFEH(1000)	 INTEGER*4	If the data line for star "n" in "fehd.dat" is 
C				 to be printed out, FLAGFEH(n) = 1.  Otherwise,
C				 FLAGFEH(n) = 0.
C
C*FLAGREF(200)	 INTEGER*$	If the "k"th reference in "refs.dat" is to be
C				 printed out, FLAGREF(k) = 1.  Otherwise,
C				 FLAGREF(k) = 0.
C
C*HD(1000)	 INTEGER*4	HD is read in from "fehd.dat".  HD(n) is usually
C				 the HD number for star "n".  HD also contains
C				 "vB" numbers (for the Hyades), "Tr" numbers 
C				 (for Coma), and BD/DM numbers.  BD/DM numbers
C				 are compressed; for instance, the number in 
C				 HD(1000) for "+41 3306" is "413306".
C
C*HDALPHA(2)	 CHARACTER*2	HDALPHA(1) and HDALPHA(2) contain the character
C				 strings "HD" and "  ", respectively.
C
C*HR(1000)	 INTEGER*4	HR is read in from "fehd.dat".  HR(n) is usually
C				 the HR number for star "n".  Alternatively,
C				 HR(n) may contain the Woolley-catalog number.
C
C*HRW(1000)	 INTEGER*4	For star "n" in "fehd.dat", HRW(n) is assigned
C				 one of the following values: 
C
C					0	No HR or Woolley number
C					1	Woolley number
C					2	HR number
C					
C*HRWTEST(2)	 CHARACTER*2	HRWTEST(1) and HRWTEST(2) contain the character 
C				 strings " W" and "HR", respectively.
C
C*I,J,K,L,M,N			DO-loop indices, array addresses, and auxiliary 
C				 variables.
C
C*LINE(200)			LINE is read in from "refs.dat".  For the "k"th
C				 literature reference read in, LINE(k) = 0
C				 (which is read in from a blank space) if the
C				 reference occupies only one line.  If the 
C				 reference requires 2 or 3 lines, LINE(k) = 2
C				 or 3, respectively.
C
C*NA(5)		 CHARACTER*1	NA(1-5) is read from each line of the text
C				 which precedes "fehd.dat".  If all entries
C				 in NA are found to be numbers, the program
C				 assumes that it has found the first line of
C				 "fehd.dat" and backspaces one logical record.
C				 (See NALPHA, just below.)
C
C*NALPHA(10)	 CHARACTER*1	NALPHA(1-10) contains the alphanumberic
C				 characters "0" through "9".
C
C*NCAY(1000)			NCAY is read in from "fehd.dat".  For star
C				 "n", NCAY(n) is the number of "Cayrel de
C				Strobel" numbers (for literature references)
C				given as primary sources of the quoted value
C				of [Fe/H].  If there are no such sources for
C				star "n", NCAY(n) = 1 and a "Cayrel de Strobel"
C				number of 0 is given.
C
C*NCOM				The number of comments in "comment.dat" 
C				 (currently 4).
C
C*NORMALIZE(4,8) CHARACTER*2  	NORMALIZE(1,k) is the preferred version of a 
C				 catalog designation.  NORMALIZE(2-4,k) are
C				 alternative catalog designations.  This array
C				 is used to normalize user-input IDs to "caps"
C				 style.
C
C*NREF				The number of references in "refs.dat".  NREF
C				 is initially set to 136 (the number of data
C				 lines in "refs.dat") and is then reset to
C				 the correct number of references by the
C				 program.
C
C*NSTAR				The number of stars with data lines in 
C				 "fehd.dat" (currently 497).
C
C*REF(3,200)	 CHARACTER*75	REF is read in from "refs.dat".  For the
C				 "k"th literature reference read in, REF(1,k)
C				 contains the first line of the reference.  If
C				 there is more than one line, those lines are
C				 stored in REF(2,k) and REF(3,k) as necessary.
C
C*REFNO(200)	 INTEGER*4	REFNO is read in from "refs.dat".  For the
C				 "k"th literature reference read in, REFNO(k)
C				 is the "Cayrel de Strobel" number.
C
C*VBTR(1000)	 CHARACTER*2	VBTR is read in from "fehd.dat".  For star
C				 "n", VBTR(n) is "vB" for van Beuren (Hyades)
C				 stars, "Tr" for Trumpler (Coma) stars, and
C				 "  " otherwise.
C
C*USERAB	 CHARACTER*1	USERAB is specified in the user input file.
C				 USERAB = "A", "a", "B", or "b" to designate
C				 members of binaries, and is not specified
C				 (blank) otherwise.
C
C*USERHD	 CHARACTER*2	USERHD is specified in the user input file, and
C				 contains "HD" and other entries as specified
C				 above (see Sec. -1-).
C
C*USERHDNO	 INTEGER*4	USERHDNO is specified in the user input file,
C				 contains catalog numbers as specified above
C				 (see Sec. -1-).
C
C*USERSIGN	 CHARACTER*1	USERSIGN is specified in the user input file,
C				 contains "+" or "-" for BD/DM stars and blanks
C				 for other stars.
C
C*W		 CHARACTER*1	W is read in from "fehd.dat", and is "W" for
C				 Woolley catalog numbers and blank for HR 
C				 numbers.
C
C*WTEST		 CHARACTER*1	The alphanumeric character "W".
C
C -3- DIMENSION AND DATA STATEMENTS
C
	DIMENSION FEH(3,1000),LINE(200),NCAY(1000)
C
	INTEGER*4 CAYNO(10,1000),CNO(1000),FLAGFEH(1000)
	INTEGER*4 FLAGREF(200),HD(1000),HR(1000),HRW(1000)
	INTEGER*4 REFNO(200),USERHDNO
C
	CHARACTER*1 AB(2,2),ABVC(1000),BDSIGN(1000),BLANK,DASH
	CHARACTER*1 NA(8),NALPHA(10),USERAB,USERSIGN,W,WTEST
	CHARACTER*2 DM,HDALPHA(2),USERHD,HRWTEST(2)
	CHARACTER*2 NORMALIZE(4,8),VBTR(1000)
	CHARACTER*75 REF(3,200)
	CHARACTER*78 COMMENT(10)
C
	DATA CAYNO/10000*0/,FLAGFEH/1000*0/,FLAGREF/200*0/
	DATA HRW/1000*0/,NCOM/4/,NREF/136/,NSTAR/497/
C
	DATA AB/'A','a','B','b'/,BLANK/' '/,DASH/'-'/,DM/'DM'/
	DATA NALPHA/'0','1','2','3','4','5','6','7','8','9'/
	DATA HDALPHA/'HD','  '/,HRWTEST/' W','HR'/
	DATA NORMALIZE/' W','W ','w ',' w','HD','hD','Hd','hd','HR',
	1 'Hr','hR','hr','vB','Vb','VB','vb','Tr','TR','tR','tr',
	2 'HD','BD','bD','bd','HD','Bd','DM','Dm','HD','dM','dm','dm'/
	DATA WTEST/'W'/
C
C -4- READ IN CDS FILE
C
	   DO 30 N=1,200
	   READ (8,1) (NA(K),K=1,8)
1	   FORMAT (18X,A1,1X,3A1,1X,A1,1X,3A1)
C
	      DO 20 I=1,8
C
	         DO 10 J=1,10
	         IF (NA(I) .EQ. NALPHA(J)) GO TO 20
10	         CONTINUE
C
	      GO TO 30
C
20	      CONTINUE
C
	   GO TO 40
C
30	   CONTINUE
C
	WRITE (10,35) 
35	FORMAT (1X,'HEADING OF CDS FILE IS MORE THAN 200 LINES LONG')
	STOP666
C
40	BACKSPACE(UNIT=8)
C
	   DO 60 N=1,NSTAR
	   READ (8,50) VBTR(N),BDSIGN(N),HD(N),ABVC(N),CNO(N),W,HR(N),
	1   (FEH(M,N),M=1,3),L,(CAYNO(J,N),J=1,L)
50	   FORMAT (A2,A1,I6,A1,I1,A1,I4,F7.3,F6.3,F5.3,11I4)
	   NCAY(N)=L
C
	   IF (VBTR(N) .EQ. HDALPHA(2)) VBTR(N)=HDALPHA(1)
	   IF (HR(N) .LT. 1) GO TO 60
	   HRW(N)=2
	   IF (W .EQ. WTEST) HRW(N)=1
C
60	   CONTINUE
C
	READ (8,70) (COMMENT(N),N=1,NCOM)
70	FORMAT (2X,A78)
C
	   DO 100 N=1,NREF
	   READ (8,80,END=110,ERR=110) (REFNO(N),LINE(N),REF(1,N))
80	   FORMAT (I3,1X,I1,A75)
C
	   LINE(N)=JMAX0(LINE(N),1)
	   IF (LINE(N) .LT. 2) GO TO 100
	   L=LINE(N)
	   READ (8,90) (REF(J,N),J=2,L)
90	   FORMAT (5X,A75)
C
100	   CONTINUE
C
110	NREF=N-1
C
C -5- READ IN USER FILE OF STAR NUMBERS; FLAG DESIGNATED STAR NUMBERS
C      AND "CAYREL DE STROBEL" NUMBERS
C
120	USERAB=BLANK
	READ (9,130,END=240) USERHD,USERSIGN,USERHDNO,USERAB
130	FORMAT (A2,A1,I6,A1)
C
	IF (USERAB .EQ. AB(2,1)) USERAB=AB(1,1)
	IF (USERAB .EQ. AB(2,2)) USERAB=AB(1,2)
C
	   DO 140 I=1,8
C
	      DO 135 J=2,4
	      IF (USERHD .NE. NORMALIZE(J,I)) GO TO 135
	      USERHD=NORMALIZE(1,I)
	      GO TO 145
135	      CONTINUE
C
140	   CONTINUE
C
145	   DO 150 L=1,2
	   IF (USERHD .EQ. HRWTEST(L)) GO TO 165
150	   CONTINUE
C
	   DO 160 N=1,NSTAR
	   IF (USERHDNO .NE. HD(N)) GO TO 160
	   IF (USERSIGN .NE. BDSIGN(N)) GO TO 160
	   IF (ABVC(N) .NE. AB(1,1) .AND. ABVC(N) .NE. AB(1,2))
	1   GO TO 155
	   IF (USERAB .NE. ABVC(N)) GO TO 160
155	   IF (USERHD .EQ. VBTR(N)) GO TO 200
160	   CONTINUE
C
	GO TO 180
C
165	   DO 170 N=1,NSTAR
	   IF (USERHDNO .NE. HR(N)) GO TO 170
	   IF (L .EQ. HRW(N)) GO TO 200
170	   CONTINUE
C
180	WRITE (10,190) USERHD,USERSIGN,USERHDNO
190	FORMAT (1X,'NO CATALOG ENTRY IS FOUND FOR ' A2,A1,I6)
	GO TO 120
C
200	FLAGFEH(N)=1
	L=NCAY(N)
	IF (L .LT. 1) GO TO 120
C
	   DO 230 J=1,L
	   IF (CAYNO(J,N) .LT. 1) GO TO 230
C
	      DO 210 K=1,NREF
	      IF (CAYNO(J,N) .NE. REFNO(K)) GO TO 210
	      FLAGREF(K)=1
	      GO TO 230
210	      CONTINUE
C
	   WRITE (10,220) CAYNO(J,N)
220	   FORMAT (1X,'*** NO CATALOG ENTRY IS FOUND FOR CdS'
	1   ' NUMBER ' I3)
C
230	   CONTINUE
C
	GO TO 120
C
C -6- WRITE OUT DATA FOR EACH DESIGNATED STAR AND CdS NUMBER; STOP
C
240	L=0
C
	WRITE (10,250)
250	FORMAT (2X,'HD/vB/Tr' 5X,'HR/W' 2X,'[Fe/H]  Sigma   Nu')
	WRITE (10,255) (DASH,J=1,39)
255	FORMAT (1X,39A1)
C
	   DO 280 N=1,NSTAR
	   IF (FLAGFEH(N) .LT. 1) GO TO 280
C
	   L=1
	   IF (BDSIGN(N) .NE. BLANK) VBTR(N)=DM
	   IF (HRW(N) .GT. 0) WRITE (10,260) VBTR(N),BDSIGN(N),
	1   HD(N),ABVC(N),HRWTEST(HRW(N)),HR(N),(FEH(M,N),M=1,3)
260	   FORMAT (1X,A2,A1,I6,A1,1X,A2,1X,I4,1X,2F7.3,F6.1)
	   IF (HRW(N) .LT. 1) WRITE (10,265) VBTR(N),BDSIGN(N),
	1   HD(N),ABVC(N),(FEH(M,N),M=1,3)
265	   FORMAT (1X,A2,A1,I6,A1,9X,2F7.3,F6.1)
C
	   IF (CNO(N) .GT. 0) WRITE (10,270) COMMENT(CNO(N))
270	   FORMAT (2X,A78)
C
280	   CONTINUE
C
	IF (L .GT. 0) GO TO 300
	WRITE (10,290) 
290	FORMAT (1X,'*** NO STARS FOUND ***' )
	STOP666
C
300	WRITE (10,255) (DASH,J=1,39)
	WRITE (10,310) (DASH,J=1,79)
310	FORMAT (/1X,79A1/' CdS'/2X,'#' 2X,'REFERENCE')
C
	   DO 350 N=1,NREF
	   IF (FLAGREF(N) .LT. 1) GO TO 350
	   WRITE (10,320) REFNO(N),REF(1,N)
320	   FORMAT (1X,I3,1X,A75)
C
	   IF (LINE(N) .LT. 2) GO TO 350
	   L=LINE(N)
C
	      DO 330 K=2,L
330	      WRITE (10,340) REF(K,N)
340	      FORMAT (5X,A75)
C
350	   CONTINUE
C
	STOP
	END
