View Raw SPL
/*****************************************************************************
* *
* EXTRACTWIN.SPL Copyright (C) 2012 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Extract a series from a number of windows *
* *
* Revisions: 20 Jan 2012 RRR Creation *
* *
*****************************************************************************/
#if @HELP_EXTRACTWIN
EXTRACTWIN
Purpose: Extracts a portion of a series from multiple windows.
Syntax: EXTRACTWIN(W1, W2, ..., Wn, start, length, offset)
Wn - Optional, zero or more Windows. If not specified,
all windows are processed.
start - An integer, the starting index.
length - An integer. The number of points to extract. A
value of -1 implies extract to the end of the series.
offset - Optional, a real. The x-offset value of the resulting
series. Defaults to the X value of the starting point.
Returns: Nothing, the result of each extraction is placed into the
target windows.
Example:
W1: integ(gnorm(1000, 1))
W2: integ(gnorm(1000, 1))
W3: integ(gnorm(1000, 1))
W4: integ(gnorm(1000, 1))
extractwin(100, 400)
W1 through W4 originally contain 1000 point random series.
EXTRACTWIN extracts 400 points from each window starting at
the 100th point.
Example:
W1: integ(gnorm(1000, 1))
W2: integ(gnorm(1000, 1))
W3: integ(gnorm(1000, 1))
W4: integ(gnorm(1000, 1))
extractwin(W1, W2, 100, 400)
Same as above except only W1 and W2 are processed.
Example:
W1: integ(gnorm(1000, 1))
W2: integ(gnorm(1000, 1))
W3: integ(gnorm(1000, 1))
W4: integ(gnorm(1000, 1))
extractwin(W2..W4, 100, 400, 0.0)
W1 through W4 originally contain 1000 point random series.
EXTRACTWIN extracts 400 points from W2, W3 and W4 starting at
the 100th point. The X offset for each window is set to 0.0.
Remarks:
If no windows are specifed, all windows are processed.
If START is negative, zeros are prepended to the result. If the
number of points to extract exceeds the original series length,
zeros are appended.
See XEXTRACTWIN to extract from multiple windows using X values.
See Also:
Cut
Extract
Remove
Xextract
Xextractwin
#endif
/* extract data from multiple windows */
extractwin(argv, start, len)
{
local i, w, cnt, xoff, tmp, isxoff = 0;
/* check input for user specified offset */
cnt = argc;
if (cnt > 2)
{
xoff = getargv(argc - 2);
if (isscalar(xoff))
{
/* modify argv count */
cnt--;
/* shift args */
tmp = len;
len = start;
start = xoff;
xoff = tmp;
/* indicates user specified offset */
isxoff = 1;
}
}
if (cnt <= 2)
{
if (isscalar(start) && isscalar(len))
{
/* extract all windows */
loop (i = 1..numwindows)
{
w = castwindow(sprintf("w%d", i));
if (not(isempty(w)))
{
if (isxoff)
{
setwform(w, sprintf("extract(curr, %d, %d, %g)", start, len, xoff));
}
else
{
setwform(w, sprintf("extract(curr, %d, %d)", start, len));
}
}
}
}
}
else
{
/* use input windows */
loop (i = 1..(cnt - 2))
{
w = getargv(i);
if (iswindow(w))
{
if (not(isempty(w)))
{
if (isxoff)
{
setwform(w, sprintf("extract(curr, %d, %d, %g)", start, len, xoff));
}
else
{
setwform(w, sprintf("extract(curr, %d, %d)", start, len));
}
}
}
}
}
}