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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem reading binary file

Status
Not open for further replies.

BowlofPetunias

Programmer
Jul 16, 2009
2
AU
I am a novice, and am using turbo delphi.

I would like to read some data from a binary file. I have found where in the file the information is, and can extract most of it, however there are three numbers that i can not read correctly.

I know what I should be reading from the file.

I have tried reading them as real, single, double with no success.

I have written the numbers to another file as reals and read them succesfully. I have examined the data i wrote to the file and the data from the file I am trying to read with a hex editor and they appear identical.

I have been trying to figure this out for days and am at my wits end trying to figure it out.

I appreciate any help you can give.



Code:
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

Type

	ccadtype = record
              dummy_1	        : array[1..4] of byte;

 				    	point_number    : array[1..16] of char;     { 1234567890123456 }
				    	point_code      : array[1..16] of char;     { 1234567890123456 }

				    	point_east      : array[1..8] of byte;      { 123456.789 }
				    	point_north     : array[1..8] of byte;      { 987654.321 }
				    	point_level     : array[1..8] of byte;      { 999999.999 }

				    	dummy_2				  : array[1..44] of byte;     

				    	x_scale				  :	single;                   { 555.555  }
				    	y_scale				  :	single;                   { 666.666  }
				    	rotation			  :	single;                   { 333.5592 }

              dummy_3         : array[1..4] of byte;

			    	end;

Var
	point : ccadtype;

	inf : file;
	outf : text;

  initial_offset, counter : longint;

  num_read, rec_size, fp_ccf, fp_inf, fs_inf : integer;

  xx : byte;

begin

	initial_offset := $21204; (* 21204h 135684d*)

	counter := 0;

  rec_size := SizeOf(point);

	Assign(inf, 'd:\tp5\cc6\test.cc6');
	Reset(inf, 1);

  fs_inf :=  FileSize(inf);
  fp_inf := FilePos(inf);

  WriteLn('*** File Size is ... ', fs_inf );
  WriteLn('*** File Ptr  is ... ', fp_inf );

  WriteLn('*** size point east ... ', sizeof(point.point_east) );
  WriteLn('*** size x scale    ... ', sizeof(point.x_scale) );

	Writeln('Record Size is ...', Rec_Size);
	WriteLn('File Size is   ...', Sizeof(inf));

	Seek(inf, initial_offset);

	Repeat
    fp_inf := FilePos(inf);
    WriteLn('*** File Ptr  is ... ', fp_inf );
		Blockread(inf, point, rec_size, num_read);

		Inc(counter);
		WriteLn(counter:20, '      ', point.point_number);

	Until Eof(inf);

	close(inf);

end.

 
You would do well to try to make yourself clearer so it can be understood what you are looking for.

For example:

however there are three numbers that i can not read correctly.

What "three numbers"?

In addition, you might do well to describe where this file came from, so we might have a clue as to what your mystery data type is.

Measurement is not management.
 
Sorry ... yes I was not clear

The file is from Surveying and Civil Engineering software package called Civilcad (ver 6.9) The file I am trying to read from is hopefully attached to the original post ... TEST.CC6

The three values i cannot read correctly are
point_east, point_north and point_level, they are all floating point numbers, I have tried reading them as real, single double etc with no luck.

In the record definition (ccadtype) beside the variables are the values that I should be reading, ie 123456.789, 987654.321 and 9999.999

I know these are the correct values as I created the file using civilcad with the values stated.

the values for x_scale, y_scale and rotation are read correctly as single


Thanks again for your help
 
If it's 8 bytes (and I think you got that right since you say the other values read right), then it would be Double, Currency, or Int64. Probably one of the first two. Hope that helps.

Measurement is not management.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top