i like this post (click again to cancel)
2
i dont like this post (click again to cancel) remove favorite mark from this question (click again to restore mark)

Hi Guys, I noticed that the Varian file format has a bit in the status code (a short value in the 32 byte header) which indicates wether spectra data are Float or Integer . However, I'm concerned this may not always be "set" .... i.e. I'm concerned that in some instances, this bit is ignored.

I'm wondering if there is any more reliable way to guess wether the numerical content in a spectrum is floating point or integer.......

Please let me know ! Thanks!

asked Mar 03 '10 at 12:40

j's gravatar image

j
131

updated Mar 04 '10 at 07:33

Evgeny%20Fadeev's gravatar image

Evgeny Fadeev
5771


3 Answers:
i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

Hello, I didn't know that Varian has that numeric mode bit, thanks for bringing it up. Floating point option offers greater "dynamic range" of storable numbers.

edit: Kirk is right - there is probably no way to guess whether a one given number is float or integer, since in the end both are represented by a bunch of bits (here is a Wikipedia page about Floating Point representation), however there may be a way to analyze a pattern within a set of numbers casted as integers and casted as floats. It's kind of like guessing in which language some text is written by looking at a sample. It does seem to be more complicated than I thought, anyway - below is the answer I've given originally:

With C programming language there seem to be two ways to guess (actually wrong - it's not a way to guess, but merely a way to extract a fractional and an integer part of a float) whether data is in the integer or floating point format:

  • using modf() and modff() functions (type man modf on your console) to extract integer and fractional parts
  • trying to cast a value into float first, then recast it into integer and calculate the difference. If the difference is always 0 - you have integer format, otherwise it's float.

Take a look here for more details.

So you could run through all the numbers with one of the methods and determine the format of entire set.

link

answered Mar 03 '10 at 13:31

Evgeny%20Fadeev's gravatar image

Evgeny Fadeev
5771

updated Mar 04 '10 at 12:43

what I'm thinking is that hopefully with the instrument data you don't have to be guessing if all the metadata is interpreted correctly. - Evgeny Fadeev (Mar 04 '10 at 12:41)

As far as I know, the bits in status word in block header thet specify whether the data are float, Int32 or Int16 are always correct. You are right, you should never have to guess. - Kirk Marat (Mar 08 '10 at 12:53)

i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

That value is used, and is most often used to specify 16 bit ints instead of 32 bit ints. I've never actually encountered a 32 bit float data set, although SpinWorks should handle it. I think I will try generating a floating point data set to see if it works :-)

Since digitizers are integer devices, there isn't much point in storing the fids as floats. Except: For a very large number of scans where you may overflow the 32 bit word; Real time digital signal processing may be done in floating point and it may make sense to save the result in floating point. All processing of the data should be done in floating point (typically 64 bit).

To decode the status word:

if ((bh.status & 0x8) != 0)    // 32 bit float  
{
.....
}

else if ((bh.status & 0x4) != 0     // most common, 32 bit ints
{
 .....
}

else if ((bh.status & 0x4) == 0     // 16 bit ints
{
 .....
}


etc...

You should probably check for float first because Varian states that the 16/32 bit bit (S32) is ignored if the float bit is set.

In a modern language (C#, probably Java and others) you could try something like:

byte[] b = new byte[4];
  • read the data point into a the 4 element byte array "b"
  • do something like:

    double fpnumber; try { fpnumber = BitConverter.ToSingle(b, 0); } catch (Exception){ // exception has been thrown, must not be 32 bit float (Single) }

  • Remember that the byte order of Varian data will be BIG ENDIAN, the byte order of the power PC processor.

link

answered Mar 04 '10 at 07:48

Kirk%20Marat's gravatar image

Kirk Marat
711

updated Mar 04 '10 at 12:13

Evgeny%20Fadeev's gravatar image

Evgeny Fadeev
5771

Hi Kirk, thanks for the insight. I've tried to format to code snippets. The third one seems to be particularly stubborn. I'll take a look into that. - Evgeny Fadeev (Mar 04 '10 at 10:31)

I was just thinking. All possible 32 bit combinations are valid integers. Many (most?) of those possible combinations are also valid 32 bit floating point numbers, so just trying to use a cast or conversion as a test is not likely to be very reliable. - Kirk Marat (Mar 04 '10 at 11:19)

The maximum value for an unsigned 32 bit int is 4,294,967,296 which is 11111111 11111111 11111111 11111111. In a 32 bit float, some of those bits are used for the exponent (is that what you ment by decimal?), so for many integers it would not be 0. - Kirk Marat (Mar 04 '10 at 11:50)

Floating point and integers are quite different formats. A float is not simply an int with an extra exponent added on. They use some of the 32bit for the exponent, giving fewer bits for the significand (mantissa). - Kirk Marat (Mar 04 '10 at 11:56)

yes, but I thought that the observation of decimal/fractional part (anything smaller than 1) being or not being always zero could be used as a hint that data is integer. of course this is subject to testing on the actual data. - Evgeny Fadeev (Mar 04 '10 at 12:27)

i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

Yes, The code is used.... but there are 16 bits in it. The real question is, which ones are commonly used ? It is known that Varian does not write values for some of their binary meta data flags, i.e. they just write zeros, and assume that you will use the procpar for all, or most, meta data.

1) So is the bit which signifies INT vs FLOAT always used when the varian folks write out spectra ?

and

2) Is there a way to find out (from the procpar) wether values are INT or FLOAT ?

and

3) What is more common in Varian spectra ? INT or FLOAT ?

link

answered Mar 04 '10 at 09:21

j's gravatar image

j
131

Hello J, just want to tell you that on this forum is slightly different from the others you might be used to. Here "discussion thread" mode is not supported by design. You can always just edit your original question and clearly mark significant edits. - Evgeny Fadeev (Mar 04 '10 at 10:35)

Thanks for the question, btw. Brings up some interesting issues. - Evgeny Fadeev (Mar 04 '10 at 10:36)

also, comments may be used for clarifications. Comments everywhere are accessible after you have 50 points, but are always accessible on your own questions and answers. - Evgeny Fadeev (Mar 04 '10 at 10:38)

this "reputation system" is another thing that helps keep this site in the better shape. You'll quickly surpass the 50 point barrier, so it's not really a problem. - Evgeny Fadeev (Mar 04 '10 at 10:40)

32 bit int is by far the most common. Do you have the Varian user programming manual? The status word is well described in there. I think the bits specifying int/short/float are quite relieble. - Kirk Marat (Mar 04 '10 at 12:00)

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a good answer, for discussions, please use comments and please do remember to vote (login to vote)
toggle preview

powered by CNPROG