Nate,
I believe I have solved the problem. I was getting odd output
because I was storing data as a float which means it get interpreted
in two's complement. When I made data an int so that the memory
isn't interpreted as two's complement and printed the value as a
float with printf("%f", data); I get a version number of 0.5 after
dividing the numerical constant. Does this sound right?
Btw. I don't think it matters if I read in 4 chunks of 1 byte data
or 1 chunk of 4 bytes does it? So I believe the fread() call is
correct either way. Should I be getting a version number of 0.5 in
the gzb file? I really don't have anything to compare my output to
so It is hard to know if my code is correct. But I think 0.5 for a
version number makes more sense then 397497394 or whatever giberish i
was getting.
I went ahead and wrote a class to extract vertex info and everything
from the file. I'd appreciate some experienced eyes to look it over.
http://rafb.net/paste/results/sbfbX431.html GZBfile.cc
http://rafb.net/paste/results/34aRo482.html GZBfile.h
Please be gentle when criticizing the code. I whipped it up pretty
fast and I don't claim to be a super duper awesome coder. I am aware
there may be some inefficiencies. Constructive criticism is very
welcome however. Thanks.
-Dustin-
On Jul 26, 2006, at 12:23 PM, Nate Koenig wrote:
> Hello,
>
> Your fread statement is incorrect. To read in the version number use
> fread(&data,4,1,input).
> Check the manpage for fread.
>
> -nate
>
> On 7/19/06, Dustin Cannon <[EMAIL PROTECTED]> wrote:
>>
>> Hi all,
>>
>> In the previous email I sent. The line
>> printf("version number:%s\n", data);
>>
>>
>> should be
>> printf("version number:%f\n", data);
>>
>> the %s was a type-o, so my problem isn't that I accidentally tried
>> to print
>> it as a string ;)
>>
>> -Dustin-
>>
>> previous message:
>>
>> Hi,
>>
>> I need to extract info from a .gzb file. I have read the
>> description of
>> gzbuilder's output file format. I tried doing a simple extraction
>> of the
>> version number, which to my understanding should be the first 4
>> bytes in the
>> file. I used code like this:
>>
>> gzb_extract(const char *filename) {
>>
>> FILE *input;
>> size_t n;
>> float data;
>>
>> input = fopen(filename, "rb");
>> if (input == NULL) {
>> perror("gzb_extract(): couldn't open input file");
>> return -1;
>> }
>>
>> n = fread(&data, 1, 4, input);
>> if (n != 0) {
>> data = (float) ntohl((uint32_t) data); // convert to host
>> byte order
>> data /= 1000; // take out numerical constant
>> printf("version number: %s\n", data);
>> }
>>
>> fclose(input);
>> }
>>
>> However, the printed results don't seem to make sense. And a hex
>> dump of
>> the gzb file doesn't seem to match what my program is showing when
>> I print
>> out those first 4 bytes in hexadecimal.
>>
>> If anyone can offer some insight or perhaps tell me if there is a
>> flaw in
>> the way I am trying to extract the info it would be much appreciated.
>> Thanks!
>>
>> -Dustin-
>>
>>
>>
>> ---------------------------------------------------------------------
>> ----
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to
>> share your
>> opinions on IT & business topics through brief surveys -- and earn
>> cash
>> http://www.techsay.com/default.php?
>> page=join.php&p=sourceforge&CID=DEVDEV
>>
>>
>> _______________________________________________
>> Playerstage-gazebo mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
>>
>>
>>
>
> ----------------------------------------------------------------------
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to
> share your
> opinions on IT & business topics through brief surveys -- and earn
> cash
> http://www.techsay.com/default.php?
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Playerstage-gazebo mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Playerstage-gazebo mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-gazebo