	PROGRAM FRAGMENT

C	LINK THIS PROGRAM WITH /NOTRACEBACK
C	David Deley  GRC/SB MAY-1988  Created

	IMPLICIT NONE
	INCLUDE '($RMSDEF)'
	integer*4	findstatus,
	2		context,
	3		lib$find_file,
	4		msglen,
	5		file_number,
	6		inputfile_len,
	7		K
	character*32256	outline
	character*255 	inputfile, outputfile, infilespec, errmsg
	character*5	ctrstr /'.!3ZL'/
	character*4	ftype

20	FORMAT (
	1' '/
	2' This program searches for files of the form filename.001,'/
	3' filename.002, filename.003, etc. and appends them all together'/
	4' recreating the original file.'/
	5' ')
21	format (' INPUT FILE (minus type and version): ',$)
23	format (' OUTPUT FILE: ',$)

31	format (a)
32	format (I)
C------------------------------------------------------------------------------
	write (6,20)
	write (6,21)
	read  (5,31) infilespec
	write (6,23)
	read  (5,31) outputfile

        open(unit=2,
	1	file=outputfile,
	2	status='NEW',
	3	recl=32256,
	4	carriagecontrol='NONE',
	5	recordtype='FIXED')

	k = 1

	DO FILE_NUMBER = 1, 999
		call sys$fao(ctrstr,,ftype,%VAL(file_number))
		Findstatus = LIB$FIND_FILE( ftype,
	1	                            inputfile,
	2	                            context,
	3	                            infilespec)
		Call Lib$find_file_end( context )
		IF (findstatus.NE.rms$_normal) THEN
			IF (findstatus.NE.rms$_fnf) THEN
				Call Sys$getmsg( %val(Findstatus), msglen, Errmsg, , )
				Write(6,31) Errmsg(1:msglen)
				Call Lib$find_file_end( context )
				call exit
			ELSE
				GOTO 1000
			ENDIF
		ENDIF

                Call Str$trim( Inputfile, Inputfile, Inputfile_len)
		Print*, 'WORKING ON FILE ', Inputfile(1:Inputfile_len)
		open(unit=1,
	1		file=inputfile,
	2		status='OLD',
	3		recl=512,
	4		carriagecontrol='NONE',
	5		recordtype='FIXED',
	6		readonly)

100		read (1,31,end=101) outline(k:k+511)
		k = k + 512
		if (k .gt. 32256) then
			write (2,31) outline(1:32256)
			k = 1
		endif
		goto 100
101		close(unit=1)
	ENDDO

1000	close(unit=2)
	close(unit=1)
	PRINT*, 'FINISHED'
	Call Str$trim (outputfile, outputfile, inputfile_len)
	PRINT*, 'OUTPUT FILE IS ', outputfile(1:inputfile_len)
	call exit
	end
