program idpick2 c Program reads in two files, the first a single-column file of c object ID numbers (idFile) and the second a multi-column file c of object data (objFile). One of the columns of objFile (column c idCol) contains object ID numbers which are used to sort through c the object list. Only those objects with IDs in the ID input file c are written to output (outFile); the rest are discarded. c c ** Program assumes both input files are sorted into ascending order c on the basis of ID number. ** c c Name of the summary input file is 'idpick2.in'. c c DHJ c c 30/11/98 c Max number of columns in objFile and outFile = 30 c Max number of objects in outFile = 10000 implicit none character*50 idFile, objFile, outFile integer col, row, idRow, objRow, numID, outRow integer idCol, numCol real currID, input(30), output(10000,30) open(unit=1, file='idpick2.in', status='old') read(1,*,end=10,err=10) idFile c read(1,*,end=10,err=10) numID read(1,*,end=10,err=10) objFile c read(1,*,end=10,err=10) numObj read(1,*,end=10,err=10) numCol read(1,*,end=10,err=10) idCol read(1,*,end=10,err=10) outFile write (6,*) ' ' write (6,*) 'File of ID numbers (input): ',idFile c write (6,*) 'Number of IDs: ',numID write (6,*) 'File of catalogue data (input): ',objFile c write (6,*) 'Number of objects: ',numObj write (6,*) 'Number of catalogue columns: ',numCol write (6,*) 'Object column (in catalogue) containing IDs: ',idCol write (6,*) 'Trimmed object file (output): ',outFile 10 continue c -------------------------------------------------------------------- c Main Loop: reading input files and checking entries: c -------------------------------------------------------------------- write (6,*) 'Reading/sorting data...' write (6,*) ' ' open(unit=11, file=idFile, status='old') open(unit=14, file=objFile, status='old') idRow = 1 objRow = 1 outRow = 1 c do while ((idRow.le.numID).and.(objRow.le.numObj)) 15 read(11,*,end=20,err=20) currID 25 read(14,*,end=30,err=30) (input(col),col=1,numCol) do while (currID.ne.(input(idCol))) 35 read(14,*,end=40,err=40) (input(col),col=1,numCol) objRow = objRow+1 enddo c --- once program makes it to this point, an ID match c --- must have been made; hence copy input to output do col=1,numCol output(outRow,col) = input(col) enddo outRow = outRow+1 objRow = objRow+1 idRow=idRow+1 c enddo goto 15 c --- end of main loop. 20 continue 30 continue 40 continue outRow = outRow-1 write (6,*) 'Number of IDs tried: ',numID write (6,*) 'Number found: ',outRow c -------------------------------------------------------------------- c Writing output file: c -------------------------------------------------------------------- write (6,*) ' ' write (6,*) 'Writing to output...' open(unit=13, file=outFile, status='unknown') do row=1,outRow write (13,220) (output(row,col),col=1,numCol) enddo c --- proper catalogue (full version, all columns) 220 format (f5.0, f8.2, f8.2, f6.1, f9.2, f7.3, f7.2, f6.2, f14.0, $ f5.1, f5.0, f12.2, f8.2, f8.2, f8.2, f8.3, f5.1, f5.0) c --- this is the format of the elgRed files. write (6,*) 'Done.' write (6,*) ' ' stop end c ===========================================================================