I'm trying to read the PTH files using Java. My program works kind off, but it shows some weird output.
What I am doing is read all the center values, output them to a file, open it in Excel, and let excel draw points. The result of Blackwood is as on the attached picture.
Obviously, some points are read incorrectly. Every time I run the program, I get exactly the same output, there is no random-ness in that. I suspect it has something to do with converting the 4 bytes to an integer value. This is the code I use
This is the output, with a 'wrong' point in bold.
18 2423615 41647638 2 123 382 22
19 2622119 41855926 2 126 171 182
20 2835197 50159278 2 65533 94 174
21 3059961 43167675 2 402 175 187
22 3293969 36053532 2 8230 8226 8220
23 3534078 35719702 2 8225 10 22
24 3776569 46532716 2 710 8 108
25 4019415 46539360 2 710 8226 96
The 3'rd byte seems to be the problem, but I can't really find out why I am really puzzled here.
What I am doing is read all the center values, output them to a file, open it in Excel, and let excel draw points. The result of Blackwood is as on the attached picture.
Obviously, some points are read incorrectly. Every time I run the program, I get exactly the same output, there is no random-ness in that. I suspect it has something to do with converting the 4 bytes to an integer value. This is the code I use
<?php
BufferedReader readPTH = new BufferedReader (new FileReader("as5.pth"));
char[] p = new char[40];
char[] header = new char[16];
readPTH.read(header, 0, 16);
int numNodes = ((header[11]&0xff) << 24) | ((header[10]&0xff) << 16) | ((header[9]&0xff) << 8) | (header[8]&0xff);
for (int i=0; i < numNodes; i++)
{
readPTH.read(p, 0, 40);
int x = ((p[3]&0xff) << 24) + (((p[2]&0xff) << 16) + (((p[1]&0xff) << 8) + (p[0]&0xff)));
int y = ((p[7]&0xff) << 24) + (((p[6]&0xff) << 16) + (((p[5]&0xff) << 8) + (p[4]&0xff)));
System.out.println (i + "\t" + x + "\t" + y + "\t" + (int)p[7] + "\t" + (int)p[6] + "\t" + (int)p[5] + "\t" + (int)p[4]);
}
readPTH.close();
?>
18 2423615 41647638 2 123 382 22
19 2622119 41855926 2 126 171 182
20 2835197 50159278 2 65533 94 174
21 3059961 43167675 2 402 175 187
22 3293969 36053532 2 8230 8226 8220
23 3534078 35719702 2 8225 10 22
24 3776569 46532716 2 710 8 108
25 4019415 46539360 2 710 8226 96
The 3'rd byte seems to be the problem, but I can't really find out why I am really puzzled here.