reading lines with trailing white spaces



I am having very basic problem with reading lines in a file with trailing
white spaces. Consider

program copy_a_file
! Fortran 90 program to copy a file
implicit none

integer :: ios
integer, parameter :: file_len=20, line_len=200
character(len=file_len) :: filename1, filename2
character(len=line_len) :: line

write(filename1, '(A)') 'copy_a_file.f90'
write(filename2, '(A)') 'temp.txt'
write(*,*) '******************************'
write(*,*) 'cp ', filename1, ' ', filename2
write(*,*) '******************************'

open(unit=101, file=filename1, action='read')
open(unit=102, file=filename2, action='write')
do
! read a line from file
read(101,'(A)', IOSTAT=ios) line
! negative IOSTAT indicates that an "end of file" or "end of record"
! condition occurred
if (ios < 0) then
exit
else
write(102,'(A)') trim(line)
end if
end do
close(unit=101)
close(unit=102)
end program copy_a_file


The strategy I am adopting is to read a line into chracter array of size 200
and then trim it and write it into a new file. Because of the trim function
I will loose all the trailing spaces in the original file. If I dont use
the trim function, I will end up with lines of length 200 (filled with
spaces at the end) even if the lines in the original file are shorter than
200 characters width. I want to have an exact copy of the original file and
I want to do this in Fortran (since the actual problem is somewhat
different)...

My questions are
1) Is there a clever way of copying a file into another file even if has
some trailing white space characters?
2) Is there a clever way of reading lines with trailing white spaces and
preserving them?

thanks
raju


--
Kamaraju S Kusumanchi
http://www.people.cornell.edu/pages/kk288/
http://malayamaarutham.blogspot.com/
.



Relevant Pages

  • RE: Trailing Whitespace
    ... I think the trailing white spaces are stripped off because they are the ... I used default pad characters ... That might preserve the white spaces. ... > suppress the stripping of trailing whitespaces. ...
    (microsoft.public.biztalk.general)
  • Re: Excel Formula Help
    ... White spaces are those spaces that you enter with the spacebar. ... Trailing just means located "after" as in after the visible ... of the visible characters, albeit these are not of issue here. ...
    (microsoft.public.excel)
  • RE: reading lines with trailing white spaces
    ... Kamaraju S Kusumanchi wrote: ... white spaces. ... Fortran 90 program to copy a file ... implicit none ...
    (comp.lang.fortran)