Hi Nathaniel,
The binary output of dctimestep is just a dump of float (or double) values in
memory, and can be read into a float (or double) array using fread(), or the
Radiance equivalent, getbinary().
I don't know what System.Text.Encoding.ASCII.GetBytes() does, but it's probably
the wrong thing. You need to make sure you are reading the file in a binary
mode, otherwise Windows likes to convert "\r\n" sequences to "\n", which will
mess up your input.
I also don't know how the BitConverter class works, but you need to be sure it
isn't swapping bytes.
I would recommend instead calling:
_setmode(_fileno(fp),_O_BINARY);
while (fread(rgb, sizeof(double), 3, fp) == 3) {
process(rgb);
}
Cheers,
-Greg
> From: Nathaniel Jones <[email protected]>
> Date: April 16, 2018 5:42:06 PM PDT
>
> Hi all,
>
> I'm trying to read the binary output from dctimestep run with the -od
> argument. The idea is that the binary files appear to be a lot faster to save
> and load than text. However, I'm having a problem reading the binary values.
>
> Values less than 512 read in just fine. However, binary values greater than
> 512 are being converted to what look like random values between 31 and 32.
> Upon looking at the binary file, it looks like the first three bytes of each
> double are zero. Of course, I'm not even sure of the endianness of the data.
>
> I'm also not sure how to test whether the issue is in my reader or in the
> dctimestep output. Here's my C# code to read the values, in case anyone wants
> to do a deep dive here:
>
> byte[] bytes = System.Text.Encoding.ASCII.GetBytes(buffer, 0, ncols * ncomp *
> sizeof(double));
> for (int j = 0; j < ncols; j++)
> {
> double r = BitConverter.ToDouble(bytes, j * ncomp * sizeof(double));
> double g = BitConverter.ToDouble(bytes, (j * ncomp + 1) * sizeof(double));
> double b = BitConverter.ToDouble(bytes, (j * ncomp + 2) * sizeof(double));
> irradiance.Add(Bright(r, g, b), path);
> }
>
> Any help debugging this would be appreciated!
>
> Nathaniel
_______________________________________________
Radiance-dev mailing list
[email protected]
https://www.radiance-online.org/mailman/listinfo/radiance-dev