Path: utzoo!attcan!uunet!husc6!bbn!uwmcsd1!ig!agate!ucbvax!NUACC.ACNS.NWU.EDU!MCGEE From: MCGEE@NUACC.ACNS.NWU.EDU (Randy McGee) Newsgroups: comp.os.vms Subject: RE: anyone have any clues why this doesn't work Message-ID: <8205201128.aa01478@accuvax.NWU.Edu> Date: 19 May 88 16:29:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 78 > I am trying to whip up a quick and dirty program which will > emulate the Unix tail program, ie, read the last n lines of > a file. I wrote up the following code, which seems like it > should work, but it doesn't seem to position the file at EOF. > any clues what i'm doing wrong? Your program is attempting to use BACKSPACE illegaly. The following was extracted from the "Programming in VAX FORTRAN" reference manual (V4.0, order number AA-D034D-TE) page 13-27: "You must no issue a BACKSPACE statement for a file that is open for direct, keyed, or append access. Backspacing from record n is done by rewinding to the start of the file and then performin n-1 successive reads to reach the previous record. For direct, keyed, and append access, the current record count (n) is not available to the FORTRAN I/O system." The same thing is true when you use the USEROPEN option to position the file. The following modified version of your program will work. V(AX/VMS W)izard Randy McGee (MAGOO) Phone: (312) 491 4079 Academic Computing and Network Services USPost: 2129 Sheridan Road Northwestern University Evanston, IL 60208 ---[ TAIL.FOR ]--------------------------------------------------------------- program tail implicit none integer*4 max_lines parameter (max_lines = 100) character*80 inline(max_lines) integer*4 lines, nback, P, I open( 1, name='SYS$MANAGER:LPR_SERVER.LOG', type='OLD', READONLY - , SHARED ) print 100, max_lines 100 format('$Number of records from end (<', I3, ')? ') accept*,nback if ( nback .gt. max_lines ) then type 101, max_lines nback = max_lines end if 101 format( ' Number greater than maximum allowed. Using ', I3 ) lines = 0 do while( .true. ) read(1,'(a)', end=5) inline( mod( lines, nback ) + 1 ) lines = lines + 1 end do 5 continue lines = lines - 1 P = mod( lines, nback ) + 1 if ( lines .eq. 0 ) then print *, 'File is empty' else if ( lines .gt. nback ) then if ( nback .ne. P ) then do I = P + 1, nback print *, inline( I ) end do end if end if do I = 1, P print *, inline( I ) end do end if close(unit=1) call exit end