	Subroutine FTP$IMAGE_DISK
c
	Include 'FTP$DEVINFO.FOR'
C
	Character*255	File_Name
c
	Integer		Name_Len,	Buffer_Address
	Integer		Blk_Cnt,	Fil_Cnt
	Integer		CLI$PRESENT,	Log_Flag
c
	External	FTP$_WORKING
	External	FTP$_READIMG
c
	Call CLI$Get_Value('OUTPUT_FILE', File_Name, Name_Len )
	If (CLI$PRESENT('LOG')) Then
	    Log_Flag = .True.
	Else
	    Log_Flag = .False.
	End If
c
	Open	(	Unit		= 1
	1	,	Name		= File_Name(:Name_Len)
	1	,	Access		= 'SEQUENTIAL'
	1	,	CarriageControl	= 'NONE'
	1	,	Recl		= 65535
	1	,	Status		= 'NEW'
	1	)
c
c	*** Dynamically Allocate a Memory Buffer
c
	Call FTP$GET_MEMORY( Buffer_Address, 65535 )
c
	If ( Log_Flag )	Call Lib$Signal(FTP$_WORKING, %Val(1),
	1				File_Name(:Name_Len))
c
c	*** Read the tape
c
	Call FTP$WRITE_IMAGE( Blk_Cnt, Fil_Cnt, %Val(Buffer_Address) )
c
c	*** Release the Memory Buffer 
c
	Call FTP$RELEASE_MEMORY( Buffer_Address, 65535 )
c
c	*** Close the file
c
	Close(Unit=1)
c
c	*** Display statistics
c
	If ( Log_Flag )	Call Lib$Signal( FTP$_IMGREAD, %Val(2),
	1		 		 %Val(Blk_Cnt), %Val(Fil_Cnt))
c
	Return
	End



	Subroutine FTP$WRITE_IMAGE ( Block_Cnt, File_Cnt, Buffer )
c
	Integer		Block_Cnt,	File_Cnt
c
	Byte		Buffer( 65535 )
c
	Integer		EOF_Cnt,	Blk_Size,	Read_Stat
	Integer		FTP$READ_QIOW,	QIO_Status
c
	Include '($SSDEF)'
c
	EOF_Cnt = 0
	Block_Cnt = 0
	File_Cnt = 0
c
	QIO_Status = FTP$READ_QIOW( Buffer, 65535, Blk_Size, Read_Stat, )
c
	Do While ((EOF_Cnt .lt. 3) .and. (Read_Stat .ne. SS$_ENDOFTAPE))
c
	    Block_Cnt = Block_Cnt + 1
c
	    If (( Read_Stat .eq. SS$_ENDOFFILE ) .or.
	1	( Read_Stat .eq. SS$_ENDOFVOLUME )) Then
		EOF_Cnt = EOF_Cnt + 1
		File_Cnt = File_Cnt + 1
	    Else If ((EOF_Cnt .gt. 0) .and.
	1	     ( Read_Stat .eq. SS$_Parity )) Then
		EOF_Cnt = EOF_Cnt + 1
		File_Cnt = File_Cnt + 1
	    Else If ( .not. Read_Stat ) Then
		Call Lib$Signal( %Val(Read_Stat) )
c	1			 , FTP$_LOCATION, %VAL(2),
c	1			 %Val(File_Cnt), %Val(Block_Cnt))
	    Else
		EOF_Cnt = 0
	    End If
c
	    Call FTP$WRITE_IMAGE_FILE(%Descr(Buffer), Blk_Size, Read_Stat )
c
	    If ( EOF_Cnt .lt. 3 )
	1	QIO_Status = FTP$READ_QIOW( Buffer, 65535, Blk_Size,
	1				    Read_Stat, )
c
	End Do
c
	Return
	End



	Subroutine FTP$WRITE_IMAGE_FILE( Record, Rec_Size, Status )
c
	Character	Record*(*)
c
	Integer		Rec_Size,	Status
c
10	Format( A4, A )
c
	Write( 1, 10 ) Status, Record( : Rec_Size )
c
	Return
	End



	Subroutine FTP$IMAGE_TAPE
c
	Include 'FTP$DEVINFO.FOR'
C
	Character*255	File_Name
c
	Integer		Name_Len,	Buffer_Address
	Integer		Blk_Cnt,	Fil_Cnt
	Integer		CLI$PRESENT,	Log_Flag
c
	External	FTP$_WRITEIMG
	External	FTP$_WORKING
c
	Call CLI$Get_Value('INPUT_FILE', File_Name, Name_Len )
c
	If (CLI$PRESENT('LOG')) Then
	    Log_Flag = .True.
	Else
	    Log_Flag = .False.
	End If
c
	Open	(	Unit		= 1
	1	,	Name		= File_Name(:Name_Len)
	1	,	Access		= 'SEQUENTIAL'
	1	,	Status		= 'OLD'
	1	)
c
c	*** Dynamically Allocate a Memory Buffer
c
	Call FTP$GET_MEMORY( Buffer_Address, 65535 )
c
	If ( Log_Flag ) Call Lib$Signal(FTP$_WORKING, %VAL(1),
	1				File_Name(:Name_Len))
c
c	*** Read the tape
c
	Call FTP$READ_IMAGE( Blk_Cnt, Fil_Cnt, %Val(Buffer_Address) )
c
c	*** Release the Memory Buffer 
c
	Call FTP$RELEASE_MEMORY( Buffer_Address, 65535 )
c
c	*** Close the file
c
	Close(Unit=1)
c
c	*** Display statistics
c
	If ( Log_Flag ) Call Lib$Signal( FTP$_WRITEIMG,%Val(2),
	1				 %Val(Blk_Cnt),%Val(Fil_Cnt))
c
	Return
	End



	Subroutine FTP$READ_IMAGE ( Block_Cnt, File_Cnt, Buffer )
c
	Integer		Block_Cnt,	File_Cnt
c
	Byte		Buffer( 65535 )
c
	Integer		EOF_Cnt,	Blk_Size,	Write_Stat
	Integer		Read_Stat,	FTP$WRITE_QIOW,	IOSB( 2 )
c
	Include '($SSDEF)'
c
	EOF_Cnt = 0
	Block_Cnt = 0
	File_Cnt = 0
	Write_Stat = .True.
c
	Call FTP$READ_IMAGE_FILE(%Descr(Buffer),Blk_Size,Read_Stat)
c
	Do While ((Read_Stat .ne. 0) .and. ( Write_Stat ))
c
	    Block_Cnt = Block_Cnt + 1
c
	    If ( Read_Stat .eq. SS$_ENDOFFILE ) Then
		Call FTP$WRITE_EOF( IOSB )
		File_Cnt = File_Cnt + 1
	    Else
	1	QIO_Status = FTP$READ_QIOW( Buffer, 65535, Blk_Size,
	1						   Write_Stat, )
		If (.not. Write_Stat) Call Lib$Signal( %VAL(Write_Stat) )
	    End If
c
	    Call FTP$READ_IMAGE_FILE(%Descr(Buffer),Blk_Size,Read_Stat)
c
	End Do
c
	Return
	End



	Subroutine FTP$READ_IMAGE_FILE( Record, Rec_Size, Status )
c
	Character	Record*(*)
c
	Integer		Rec_Size,	Status
c
10	Format( Q, A4, A )
c
	Read( 1, 10, End=100 ) Rec_Size, Status, Record( : Rec_Size - 8 )
c
c	*** Remove the 8 bytes for the status code
c
	Rec_Size = Rec_Size - 4
c
	Return
c
100	Continue
c
c	*** Make STATUS show we have hit the end of the input file.
c
	Rec_Size = 0
	Status = 0
	Return
c
	End

