Article ID: 112333
Article Last Modified on 10/17/2003
FL32 strip.for no_ctrlz.for
STRIP z-test.dat
C Compile options needed: None
open(10, file='z-test.dat',form='BINARY')
write(10) '1234', char(26)
end
C Compile options needed: None
open(10,file='z-test.dat')
do i=1,20
read(10,*,end=9) k
print *, k
enddo
9 end
C Compile options needed: None
C To build it use: "FL32 STRIP.FOR NO_CTRLZ.FOR"
include 'flib.fi'
include 'flib.fd'
character *40 filename
integer*2 i
if (NARGS() .gt. 1) then
call getarg(1, filename, i)
i = no_ctrlz(filename)
if (i .ne. 0) then
print *, 'Could not open the file: ', filename
end if
end if
end
C Compile options needed: None
c NO_CTRLZ removes the last character in a file if it is CTRL+Z
c
c Returns 1 if there are problems, otherwise 0.
c
integer function no_ctrlz(filename)
character c, filename*(*)
logical exist
inquire(file=filename(:len_trim(filename)),EXIST=exist)
if (.not. exist) then
no_ctrlz = 1
return
end if
open(10,file=filename(:len_trim(filename)),access='APPEND',
+ form='BINARY',recl=1)
c Check if the last character is CTRL+Z
backspace(10)
read(10) c
if (ichar(c) .ne. 26) then
no_ctrlz = 0 !No error, just don't need to do anything
return
end if
c Backup, and then rewrite the next to last character to reset
c the true end-of-file marker.
backspace(10)
backspace(10)
read(10) c
backspace(10)
write(10) c
close(10)
no_ctrlz = 0 !COMPLETED SUCCESSFULLY
end
Additional Reference Words: 1.00 ctrl-z
Keywords: kbbug kbfix kblangfortran KB112333