Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The end of a binary file being cut 1

Status
Not open for further replies.

jeansberg

Programmer
Oct 5, 2006
7
FI
I have been trying to make a program that copies binary files. I have used autocad .dwg files.

When I open the binary files in a text editor and compare them to the originals they are identical, EXCEPT for a few symbols on the last line. Could this be because the last record is not getting copied?

I have tried changing the record length and have determined that '32' works best. Here is the entire program:
------------------------------------------------------------
Program quad

character a*32
integer i
i=1

open (4,file='3GZF243131-5.dwg', form='unformatted',
1access='direct', status='old', recl=32)
open (8, file='test.dwg', form='unformatted',
1access='direct', status='old', recl=32)

do while(.true.)
read(4, rec=i) a
write(8, rec=i) a

i=i+1
enddo

close (4)
close (8)

stop
end
------------------------------------------------------------

Any help would be appreciated.
 
At a guess your program is crashing and not managing to write the last record. If you look at the loop, it never terminates. Try this
Code:
      Program quad

      character a*32
      integer i
      i=1
         
      open (4,file='3GZF243131-5.dwg', form='unformatted',
     1access='direct', status='old', recl=32)  
      open (8, file='test.dwg', form='unformatted',    
     1access='direct', status='old', recl=32)
                           
          do while(.true.)                  
            read(4, rec=i, end = 200) a
            write(8, rec=i) a
        
            i=i+1
          enddo
200       continue
          close (4)
          close (8)
      
      stop
      end
 
Hi xwb. I have tried using the 'end = ...' before, but when I try compiling the program I get this error message:

Code:
read(4, rec=i, end = 200) a
            1
Error: REC tag at (1) is incompatible with END tag

I am using the G95 compiler on Windows 2000.
 
The rec specifier is required for direct access data transfer, which is required for reading and writing a binary file correctly. Unfortunately an END tag is not allowed with a rec specifier.
 
Use err= instead of end=. When it reaches end of file, it will generate an error so it will go to 200.
 
That got rid of the error message. Unfortunately the problem with the missing part at the end of the file is still there.
 
You should only read and write ONE character but not 32 characters. That is why your files are different. You should also specify the new file (test.dwg) as 'new' but not 'old'. Note that the input file is not specified with access='direct', but as a binary sequencial file, which is enough. Try this:

program quad

byte a

open(unit=4,file='3GZF243131-5.dwg',form='binary')
open(unit=8,file='test.dwg',form='binary',status='new')

do while(.true.)
read(4,end=99) a
write(8) a
enddo

99 continue
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top