reading structures

Hi, I have a problem in reading the following structure.


structure spe_calib
	double offset // +0 offset
	double factor
	char current_unit
	char reserved1
	char strings[40]
	char reserved2[40]
	char calib_valid
	char input_unit
	char polynom_unit
	char polynom_order
	char calib_count
	double pixel_position[10]  // +103 offset
	double calib_value[10]
	double polynom_coeff[6]
	double laser_position
	char reserved3
	uchar new_calib_flag
	char calib_label[81]
	char expansion[87]
endstructure



By reading the structure from a file the following way

	struct spe_calib x_calib
	Fbinread/B=3 file, x_calib

I get wrong values for "pixel_position", "calib_value", and "polynom_coeff" although the char before them (calib_count) is read correctly.
"pixel_position", "calib_value", and "polynom_coeff" are off by one byte (offset +1). I dont know why.
If I delete a char from the struct (shifting "pixel_position", "calib_value", and "polynom_coeff" by one byte) they are offset-1 off, which is correct because I am reading one char less.

Jumping directly to the offset of "pixel_position", "calib_value", and "polynom_coeff" by fsetpos gives the proper values and deviding the struct into two parts (one before "pixel_position" and the second with the rest) produces also the correct values.

I also had a similar problem when a char like

	char calib_label[80]

was read for less then 80 bytes.

Is this a bug in Igor?
This may be an issue of structure alignment. You should determine the structure alignment of the file from the file format documentation if possible. If not I would use Data->Load General Binary to load the structure into an unsigned byte wave for inspection in a table.

Igor structures are 2-byte aligned. This means that any field larger than a single byte will always be at an even offset even if this requires leaving an unused padding byte. Depending on compiler settings a structure may be 1-byte, 2-byte, 4-byte or 8-byte aligned.

If your file is 4-byte or 8-byte aligned then you will need to adjust the Igor structure by adding padding fields. If it is 1-byte aligned then it will be tricky to implement. The details depend on the precise layout of the file structure.