[XOP] Set complete wave to NaN
thomas_braun
As I could not find anything in XOPSupport I created them myself. The *data pointers are returned from WaveData(waveHandle).
Tested on Windows XP 32bit.
<br />
void waveClearNaN64(double *data, long size){<br />
<br />
long i;<br />
for (i = 0; i < size; i++){<br />
data[i] = DOUBLE_NAN;<br />
}<br />
}<br />
<br />
void waveClearNaN32(float *data, long size){<br />
<br />
long i;<br />
for (i = 0; i < size; i++){<br />
data[i] = SINGLE_NAN;<br />
}<br />
}<br />
void waveClearNaN64(double *data, long size){<br />
<br />
long i;<br />
for (i = 0; i < size; i++){<br />
data[i] = DOUBLE_NAN;<br />
}<br />
}<br />
<br />
void waveClearNaN32(float *data, long size){<br />
<br />
long i;<br />
for (i = 0; i < size; i++){<br />
data[i] = SINGLE_NAN;<br />
}<br />
}<br />
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
September 17, 2010 at 04:44 am - Permalink
UBC In Vivo Imaging Core
If you already have a pointer to increment, why do you need i?
Incrementing two variables through a loop when one will do seems wasteful.
Maybe some c++ guru can tell us whether the compiler will optimize your code to be equivalent to the pointer arithmetic version.
September 17, 2010 at 12:48 pm - Permalink
Yes you have a point here. One alternative to write would be:
long i;<br />
for (i = 0; i < size; i++){<br />
data[i] = DOUBLE_NAN;<br />
}<br />
or maybe even
void waveClearNaN64(double *data, long size){<br />
<br />
double *lastEntry = &data[size-1];<br />
while(data != lastEntry){<br />
*data++ = DOUBLE_NAN;<br />
}<br />
}<br />
I'll guess I will change it to the first version. From a speed POV I have not evaluated my solution properly I must admit.
September 20, 2010 at 12:16 pm - Permalink
double *lastEntry = &data[size-1];
while(data != lastEntry){
*data++ = DOUBLE_NAN;
}
}
has an off-by-one error. It does not set the last point. Change != to <=.
I think your original version was fine and probably as fast as the others. It was also straightforward and clear.
September 20, 2010 at 02:13 pm - Permalink
September 21, 2010 at 12:22 pm - Permalink