View Raw SPL
/*****************************************************************************
* *
* XEXTRACTWIN.SPL Copyright (C) 2012 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Extract a series from a number of windows based on X values *
* *
* Revisions: 8 May 2012 RRR Creation *
* *
*****************************************************************************/
#if @HELP_XEXTRACTWIN
XEXTRACTWIN
Purpose: Extracts a series segment from multiple windows based on X values.
Syntax: XEXTRACTWIN(W1, W2, ..., Wn, xstart, xend, offset)
Wn - Optional, zero or more Windows. If not specified,
all windows are processed.
xstart - A real, the starting X value.
xend - A real, the ending X value.
offset - Optional, a real. The x-offset value of the resulting
series. Defaults to XSTART, the starting X value.
Returns: Nothing, the result of each extraction is placed into the
target windows.
Example:
W1: integ(gnorm(1000, 1/1000))
W2: integ(gnorm(1000, 1/1000))
W3: integ(gnorm(1000, 1/1000))
W4: integ(gnorm(1000, 1/1000))
xextractwin(0.1, 0.4)
W1 through W4 originally contain 1000 point random series.
XEXTRACTWIN extracts 301 points from each window starting at
the X value 0.1 and ending at the X value 0.4.
Example:
W1: integ(gnorm(1000, 1/1000))
W2: integ(gnorm(1000, 1/1000))
W3: integ(gnorm(1000, 1/1000))
W4: integ(gnorm(1000, 1/1000))
xextractwin(W1, W2, 0.1, 0.4)
Same as above except only W1 and W2 are processed.
Example:
W1: integ(gnorm(1000, 1/1000))
W2: integ(gnorm(1000, 1/1000))
W3: integ(gnorm(1000, 1/1000))
W4: integ(gnorm(1000, 1/1000))
xextractwin(W2..W4, 0.1, 0.4, 0.0)
W1 through W4 originally contain 1000 point random series.
XEXTRACTWIN extracts 301 points from W2, W3 and W4 starting at
the X value 0.1. The X offset for each window is set to 0.0.
Remarks:
If no windows are specifed, all windows are processed.
If XSTART is negative, zeros are prepended to the result. If
XEND exceeds the original series duration, zeros are appended.
See EXTRACTWIN to extract from multiple windows using series
indices.
See Also:
Cut
Extract
Extractwin
Remove
Xextract
#endif
/* extract data from multiple windows using X values */
xextractwin(argv, xstart, xend)
{
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 = xend;
xend = xstart;
xstart = xoff;
xoff = tmp;
/* indicates user specified offset */
isxoff = 1;
}
}
if (cnt <= 2)
{
if (isscalar(xstart) && isscalar(xend))
{
/* extract all windows */
loop (i = 1..numwindows)
{
w = castwindow(sprintf("w%d", i));
if (not(isempty(w)))
{
if (isxoff)
{
setwform(w, sprintf("xextract(curr, %1.16g, %1.16g, 1.16%g)", xstart, xend, xoff));
}
else
{
setwform(w, sprintf("xextract(curr, %1.16g, %1.16g)", xstart, xend));
}
}
}
}
}
else
{
/* use input windows */
loop (i = 1..(cnt - 2))
{
w = getargv(i);
if (iswindow(w))
{
if (not(isempty(w)))
{
if (isxoff)
{
setwform(w, sprintf("xextract(curr, %1.16g, %1.16g, %1.16g)", xstart, xend, xoff));
}
else
{
setwform(w, sprintf("xextract(curr, %1.16g, %1.16g)", xstart, xend));
}
}
}
}
}
}