[XOP] Set complete wave to NaN

The following two functions can be used to set a complete wave with size entries to Nan. This is especially useful for images.
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 />
Dr. Jamie Boyd, Ph.D.
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.
@jamie:

Yes you have a point here. One alternative to write would be:
<br />
long i;<br />
for (i = 0; i < size; i++){<br />
    data[i] = DOUBLE_NAN;<br />
}<br />

or maybe even
<br />
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.
I believe this:
void waveClearNaN64(double *data, long size){
 
      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.

Forum

Support

Gallery

Igor Pro 10

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More