Windows Required Reading |
Table of ContentsWindows Required Reading Abstract Introduction Basic Concepts The window data type References Window Routines Initialization Routines Unary Routines Binary Routines Complement Routines Comparison Routines Summary Appendix: Document Revision History Febuary 6, 2009 (EDW) Windows Required Reading
Abstract
Introduction
An interval is an ordered pair of numbers,
[ a(i), b(i) ]such that
a(i) < b(i) -The intervals within a window are both ordered and disjoint. That is, the beginning of each interval is greater than the end of the previous interval:
b(i) < a(i+1)This restriction is enforced primarily because it allows efficient window operations. The intervals stored in windows typically represent intervals of time (seconds, days, or centuries past a reference epoch). However, windows can represent any kinds of intervals. Basic Concepts
``cardinality - The number of elements stored in a cell. ``cardinality'' describes how much of ``size'' is used. ``cardinality'' satisfies the relationship:
cardinality < size -``measure'' - the measure of an interval is the length of the interval, that is the difference of its endpoints:
m(i) = b(i) - a(i)Note that the singleton interval
[ a(i), a(i) ]has measure zero. The window
[1,2], [4,9], [16,16]contains intervals of measure 1, 5, and 0 respectively. The concept of measure extends readily to the gaps between adjacent intervals. In the example above, the window contains gaps of measure 2 and 7. Intervals separated by gaps of measure zero or less are said to overlap. Overlapping intervals created by the window routines are merged as soon as they are created. Finally, the measure of a window is the sum of the measures of its intervals. In the example above, the measure of the window is 6. Note that a floating point window containing only singletons has measure zero. The window data type
The SPICELIB implementation of SPICE windows consists of Fortran double precision cells. Example:
C C Define our variable types. C INTEGER LBCELL PARAMETER (LBCELL = -5 ) INTEGER MAXSIZ PARAMETER (MAXSIZ = 8 ) C C Define a cell WIN to use as a window. C C The window can hold eight (MAXSIZ = 8) double precision values, C thus four intervals. C DOUBLE PRECISION WIN(LBCELL:MAXSIZ)The cell size, `MAXSIZ', must have an even value to use the cell as a window. Two values define a window interval, so a window of N intervals requires a cell of size 2*N. The size and cardinality of a window must be initialized (using the cell routines SSIZED and SCARDD) before the window may be used by any of the SPICELIB window routines. Any of the general cell routines in SPICELIB may be used with SPICE windows. For example, COPYD may be used to copy the contents of one window into another. The function CARDD may be used to determine the number of endpoints (that is, twice the number of intervals) in a window. All errors are reported via standard SPICELIB error handling. With the exception of the initialization routines, all window routines assume that input cells do contain valid windows---that is, ordered and distinct sets of endpoints. The windows subsystem may not signal errors resulting from attempts to operate on invalid windows. References
Window Routines
Initialization Routines
WNVALD ( SIZE, N, WINDOW )On input, WINDOW is a cell of size SIZE containing N endpoints. During validation, the intervals are ordered, and overlapping intervals are merged. On output, the cardinality of WINDOW is the number of endpoints remaining, and the window is ready for use with any of the window routines. Because validation is done in place, there is no chance of overflow. However, other errors may be detected. For example, if the left endpoint of any interval is greater than the corresponding right endpoint, WNVALD signals an error. Validation is primarily useful for ordering and merging intervals added to a cell by APPNDD, or directly assigned to the cell. Building a large window is done most efficiently by assigning the window elements and then calling WNVALD. Building up the window by repeated insertion requires repeated ordering operations; WNVALD does a single ordering operation. Unary Routines
WNCOND ( LEFT, RIGHT, WINDOW ) { Contract } WNEXPD ( LEFT, RIGHT, WINDOW ) { Expand } WNEXTD ( SIDE, WINDOW ) { Extract } WNFILD ( SMALL, WINDOW ) { Fill } WNFLTD ( SMALL, WINDOW ) { Filter } WNINSD ( LEFT, RIGHT, WINDOW ) { Insert }Each of the unary window routines works in place. That is, only one window, WINDOW, appears in each calling sequence, serving as both input and output. Windows whose original contents need to be preserved should be copied prior to calling any of the unary routines. WNINSD inserts the interval whose endpoints are LEFT and RIGHT into WINDOW. If the input interval overlaps any of the intervals in the window, the intervals are merged. Thus, the cardinality of WINDOW can actually decrease as the result of an insertion. WNEXPD and WNCOND expand (lengthen) and contract (shorten) each of the intervals in WINDOW. The adjustments are not necessarily symmetric. That is, WNEXPD works by subtracting LEFT units from the left endpoint of each interval and adding RIGHT units to the right endpoint of each interval. WNCOND is the same as EXP with the signs of the arguments reversed, and is primarily provided for clarity in coding. (Expansion by negative increments is a messy concept.) Intervals are merged when expansion causes them to overlap. Intervals are dropped when they are contracted by amounts greater than their measures. WNFLTD and WNFILD remove small intervals and small gaps between adjacent intervals. Both routines take as input a minimum measure, SMALL. WNFLTD filters out (drops) intervals with measures less than or equal to SMALL, while WNFILD merges adjacent intervals separated by gaps with measures less than or equal to SMALL. Depending on the value of SIDE, WNEXTD extracts the left or right endpoints of each interval in WINDOW. The resulting window contains only the singleton intervals
[ a(1), a(1) ], ..., [ a(n), a(n) ]or
[ b(1), b(1) ], ..., [ b(n), b(n) ] Binary Routines
WNUNID ( A, B, C ) { Union } WNINTD ( A, B, C ) { Intersection } WNDIFD ( A, B, C ) { Difference }In contrast with the unary routines, none of the binary routines work in place. The output window, C, must be distinct from both of the input windows, A and B. We will have more to say about this later on. WNUNID places the union of A and B into C. The union of two windows contains every point that is contained in the first window, or in the second window, or in both windows. WNINTD places the intersection of A and B into C. The intersection of two windows contains every point that is contained in the first window AND in the second. WNDIFD places the difference of A and B into C. The difference of two windows contains every point that is contained in the first window, but NOT in the second. In each case, if the output window, C, is not large enough to hold the result of the operation, as many intervals as will fit are inserted into the window, and a SPICE error is signaled. (You can control the effect of this error on your program; refer to Error Required Reading.) In each of the binary routines, the output window must be distinct from both of the input windows. All three of the binary operations can, in principle, be performed in place, but not all can be performed efficiently. Consequently, for the sake of consistency, none of the routines work in place. For example, the following calls are invalid.
WNINTD ( A, B, A ) WNINTD ( A, B, B )In each of the examples above, whether or not the subroutine signals an error, the results will almost certainly be wrong. Nearly the same effect can be achieved, however, by placing the result into a temporary window, which can be immediately copied back into one of the input windows, as shown below.
WNINTD ( A, B, TEMP ) COPYD ( TEMP, A ) Complement Routines
WNCOMD ( LEFT, RIGHT, A, C ) { Complement }As with the binary routines, the output window, C, must be distinct from the input window, A. Mathematically, the complement of a window contains those points that are not contained in the window. That is, the complement of the set of closed intervals
[ a(1), b(1) ], [ a(2), b(2) ], ..., [ a(n), b(n) ]is the set of open intervals
( -inf, a(1) ), ( b(1), a(2) ), ..., ( b(n), +inf )Not all computer languages offer a satisfactory way to represent infinity, so WNCOMD must take the complement with respect to a finite interval. Since the results of a window routine must be another window, WNCOMD returns the closure of the set theoretical complement. In short, the double precision complement of the window
[ a(1), b(1) ], [ a(2), b(2) ], ..., [ a(n), b(n) ]with respect to the interval from LEFT to RIGHT is the intersection of the windows
( -inf, a(1) ], [ b(1), a(2) ], ..., [ b(n), +inf )and [ LEFT, RIGHT ]. Intervals of measure zero (singleton intervals) in the original window are replaced by gaps of measure zero, which are filled. Thus, complementing a window twice does not necessarily yield the original window. Comparison Routines
WNELMD ( POINT, WINDOW ) { Element } WNINCD ( LEFT, RIGHT, WINDOW ) { Inclusion } WNRELD ( A, OP, B ) { Relation } WNSUMD ( WINDOW, MEAS, AVG, STDDEV, SHORT, LONG) { Summary }WNELMD returns true if the input point, POINT, is an element of the input window, WINDOW---that is, whenever the point lies within one of the intervals of the window. Similarly, WNINCD is true whenever the input interval, from LEFT to RIGHT, is included in the input window, WINDOW---that is, whenever the interval lies entirely within one of the intervals of the window. WNRELD is true whenever a specified relationship between the input windows, A and B, is satisfied. Each relationship corresponds to a comparison operator, OP. The complete set of operators recognized by WNRELD is shown below.
'=' is equal to (contains the same intervals as) '<>' is not equal to '<=' is a subset of '<' is a proper subset of '>=' is a superset of '>' is a proper superset ofFor example, the expression
WNRELD ( NEEDED, '<=', AVAIL )is true whenever the window NEEDED is a subset of the window AVAIL. One window is a subset of another window if each of the intervals in the first window is included in one of the intervals in the second window. In addition, the first window is a proper subset of the second if the second window contains at least one point not contained in the first window. The following pairs of expressions are equivalent.
WNRELD ( A, '>', B ) WNRELD ( B, '<', A ) WNRELD ( A, '>=', B ) WNRELD ( B, '<=', A )WNSUMD provides a summary of the input window, WINDOW. It computes the measure of the window, MEAS, and the average, AVG, and standard deviation, STDDEV, of the measures of the individual intervals in the window. It also returns the indices of the left endpoints of the shortest and longest intervals in the window. All of these quantities and indices are zero if the window contains no intervals. The following describes the relation of SHORT and LONG to the window data: The left endpoint of the shortest interval has value:
WINDOW(SHORT)The right endpoint of the shortest interval has value:
WINDOW(SHORT+1)The left endpoint of the longest interval has value:
WINDOW(LONG)The right endpoint of the longest interval has value:
WINDOW(LONG+1) Summary
Appendix: Document Revision HistoryFebuary 6, 2009 (EDW)
|