Using if endif statement checking odd or even number of data in wave.
eesyliu
I am doing some FFT repetitively for some data file and I want the script to check if the number of data points is even (a must for FFT) or not. If it is odd, then delete one data points from all wave to make it even.
Variable NOD=DimSize(wave0,0)
Variable REMAIN=mod(NOD,2)
if (REMAIN 1==0)
DeletePoints NOD-1,1, wave0,wave1,wave2,wave3,wave4,wave5,wave6,wave7
endif
Variable REMAIN=mod(NOD,2)
if (REMAIN 1==0)
DeletePoints NOD-1,1, wave0,wave1,wave2,wave3,wave4,wave5,wave6,wave7
endif
I used the above code to detect the modulus. If the number of data is odd, modulus equals to 1 then one data point will be deleted from all waves.
However, when I run this in front of all other codes, Igor prompts me "expected wave, variable name...." when it comes to the "if" code.
So, I want to ask if it is not allowed to run "if endif" directly in command line without putting them into a function?
Or, what is the simplest way to achieve that? (make all waves to even number of data points for FFT. Thanks.
May 7, 2013 at 01:35 am - Permalink
If you really wanted to do something like this from the command line, you could execute the following (from the command line)
DeletePoints NOD-1,REMAIN, wave0,wave1,wave2,wave3,wave4,wave5,wave6,wave7
One point will be deleted for mod = 1; none for mod = 0.
This assumes that your waves and variables exist in the current directory.
May 7, 2013 at 05:38 am - Permalink
May 7, 2013 at 07:34 am - Permalink
wave ww
variable npts, sx, dx
npts = DimSize(ww,0)
sx = DimOffset(ww,0)
dx = DimDelta(ww,0)
duplicate/O/FREE ww dww
dww = ww[npts-p-1]
Concatenate/NP/O {ww,dww}, ww
SetScale/P x, sx, dx, ww // you may want to use either 2*dx or dx/2 as the step size
return 0
end
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
May 8, 2013 at 02:36 pm - Permalink
And then there's the Reverse operation...
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 7, 2013 at 12:15 pm - Permalink
dww = ww[npts-p-1]
It would be slightly more efficient to use:
WaveTransform flip ww
May 7, 2013 at 03:38 pm - Permalink
Reverse fww
Concatenate/NP/O {ww,fww} ww
versus
Concatenate/NP/O {ww,W_flipped} ww
killwaves W_flipped
Edit: Fixed syntax to Concatenate operation ... thanks AG!
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
May 8, 2013 at 02:35 pm - Permalink