1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
//! # Windows Required Reading
//!
//! Last revised on 2010 MAY 18 by B. V. Semenov.
//!
//!
//!
//!
//!
//! ## Abstract
//!
//! SPICE Toolkits define the SPICE data type "window" for use in the
//! manipulation of continuous intervals on the real line. Corresponding
//! window routines in SPICELIB are designed to simplify the use of this
//! data type.
//!
//!
//!
//!
//!
//! ## Introduction
//!
//! By definition, a window is a double precision SPICE cell that contains
//! zero or more intervals.
//!
//! An interval is an ordered pair of numbers,
//!
//!
//!
//! ```text
//! [ a(i), b(i) ]
//! ```
//!
//! such that
//!
//!
//!
//! ```text
//! 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:
//!
//!
//!
//! ```text
//! 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
//!
//! "size" - The maximum number of elements storable in a SPICE cell.
//! Cells are created with a constant size.
//!
//! "cardinality - The number of elements stored in a cell. "cardinality"
//! describes how much of "size" is used. "cardinality" satisfies the
//! relationship:
//!
//!
//!
//! ```text
//! cardinality < size
//! -
//! ```
//!
//! "measure" - the measure of an interval is the length of the interval,
//! that is the difference of its endpoints:
//!
//!
//!
//! ```text
//! m(i) = b(i) - a(i)
//! ```
//!
//! Note that the singleton interval
//!
//!
//!
//! ```text
//! [ a(i), a(i) ]
//! ```
//!
//! has measure zero. The window
//!
//!
//!
//! ```text
//! [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
//!
//! SPICE windows are a form of the SPICE cell data type \[1], so any
//! restriction that applies to the use of cells applies to the use of
//! windows as well. The implementation of a SPICE window differs according
//! to the Toolkit language.
//!
//! The SPICELIB implementation of SPICE windows consists of Fortran double
//! precision cells.
//!
//! Example:
//!
//!
//!
//! ```text
//! 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](crate::raw::ssized) and [SCARDD](crate::raw::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](crate::raw::copyd) may be used to copy the contents of one
//! window into another. The function [CARDD](crate::raw::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
//!
//!
//!
//! * \[1]
//!
//!
//! CELLS Required Reading ([cells.req](crate::required_reading::cells)).
//!
//!
//! # Window Routines
//!
//! The window routines in SPICELIB fall into the following categories.
//!
//!
//!
//! * Initialization
//!
//! * Unary
//!
//! * Binary
//!
//! * Complement
//!
//! * Comparison
//!
//!
//! ## Initialization Routines
//!
//! [WNVALD](crate::raw::wnvald) takes as input a double precision SPICE cell containing pairs of
//! endpoints and validates it to form a window. The calling sequence is
//! shown below.
//!
//!
//!
//! ```text
//! 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](crate::raw::wnvald)
//! signals an error.
//!
//! Validation is primarily useful for ordering and merging intervals added
//! to a cell by [APPNDD](crate::raw::appndd), or directly assigned to the cell.
//!
//! Building a large window is done most efficiently by assigning the window
//! elements and then calling [WNVALD](crate::raw::wnvald). Building up the window by repeated
//! insertion requires repeated ordering operations; [WNVALD](crate::raw::wnvald) does a single
//! ordering operation.
//!
//!
//!
//!
//!
//! ## Unary Routines
//!
//! Each unary routine operates on a single window. Six unary operations are
//! supported, each of which alters the contents of the input window. The
//! calling sequences are shown below.
//!
//!
//!
//! ```text
//! 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](crate::raw::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](crate::raw::wnexpd) and [WNCOND](crate::raw::wncond) expand (lengthen) and contract (shorten) each of the
//! intervals in WINDOW. The adjustments are not necessarily symmetric. That
//! is, [WNEXPD](crate::raw::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](crate::raw::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](crate::raw::wnfltd) and [WNFILD](crate::raw::wnfild) remove small intervals and small gaps between adjacent
//! intervals. Both routines take as input a minimum measure, SMALL. [WNFLTD](crate::raw::wnfltd)
//! filters out (drops) intervals with measures less than or equal to SMALL,
//! while [WNFILD](crate::raw::wnfild) merges adjacent intervals separated by gaps with measures
//! less than or equal to SMALL.
//!
//! Depending on the value of SIDE, [WNEXTD](crate::raw::wnextd) extracts the left or right
//! endpoints of each interval in WINDOW. The resulting window contains only
//! the singleton intervals
//!
//!
//!
//! ```text
//! [ a(1), a(1) ], ..., [ a(n), a(n) ]
//! ```
//!
//! or
//!
//!
//!
//! ```text
//! [ b(1), b(1) ], ..., [ b(n), b(n) ]
//! ```
//!
//!
//! ## Binary Routines
//!
//! Binary routines operate on two input windows to produce a third
//! (distinct) output window. Three major binary operations are supported.
//! The calling sequences are shown below.
//!
//!
//!
//! ```text
//! 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](crate::raw::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](crate::raw::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](crate::raw::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.
//!
//!
//!
//! ```text
//! 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.
//!
//!
//!
//! ```text
//! WNINTD ( A, B, TEMP )
//!
//! COPYD ( TEMP, A )
//! ```
//!
//!
//! ## Complement Routines
//!
//! [WNCOMD](crate::raw::wncomd) determines the complement of a window with respect to an
//! interval. The calling sequence is
//!
//!
//!
//! ```text
//! 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
//!
//!
//!
//! ```text
//! [ a(1), b(1) ], [ a(2), b(2) ], ..., [ a(n), b(n) ]
//! ```
//!
//! is the set of open intervals
//!
//!
//!
//! ```text
//! ( -inf, a(1) ), ( b(1), a(2) ), ..., ( b(n), +inf )
//! ```
//!
//! Not all computer languages offer a satisfactory way to represent
//! infinity, so [WNCOMD](crate::raw::wncomd) must take the complement with respect to a finite
//! interval.
//!
//! Since the results of a window routine must be another window, [WNCOMD](crate::raw::wncomd)
//! returns the closure of the set theoretical complement. In short, the
//! double precision complement of the window
//!
//!
//!
//! ```text
//! [ 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
//!
//!
//!
//! ```text
//! ( -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
//!
//! Comparison routines allow the contents of windows to be compared against
//! the contents of other windows. There are four comparison routines: three
//! logical functions and one subroutine. The calling sequences are shown
//! below.
//!
//!
//!
//! ```text
//! WNELMD ( POINT, WINDOW ) { Element }
//!
//! WNINCD ( LEFT, RIGHT, WINDOW ) { Inclusion }
//!
//! WNRELD ( A, OP, B ) { Relation }
//!
//! WNSUMD ( WINDOW, MEAS, AVG, STDDEV, SHORT, LONG) { Summary }
//! ```
//!
//! [WNELMD](crate::raw::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](crate::raw::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](crate::raw::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](crate::raw::wnreld) is shown below.
//!
//!
//!
//! ```text
//! '=' 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 of
//! ```
//!
//! For example, the expression
//!
//!
//!
//! ```text
//! 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.
//!
//!
//!
//! ```text
//! WNRELD ( A, '>', B )
//! WNRELD ( B, '<', A )
//!
//! WNRELD ( A, '>=', B )
//! WNRELD ( B, '<=', A )
//! ```
//!
//! [WNSUMD](crate::raw::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:
//!
//!
//!
//! ```text
//! WINDOW(SHORT)
//! ```
//!
//! The right endpoint of the shortest interval has value:
//!
//!
//!
//! ```text
//! WINDOW(SHORT+1)
//! ```
//!
//! The left endpoint of the longest interval has value:
//!
//!
//!
//! ```text
//! WINDOW(LONG)
//! ```
//!
//! The right endpoint of the longest interval has value:
//!
//!
//!
//! ```text
//! WINDOW(LONG+1)
//! ```
//!
//!
//! # Summary
//!
//! The following is a summary of the window routines in SPICELIB. (DP =
//! double precision)
//!
//!
//!
//! * [WNCARD](crate::raw::wncard) - Cardinality of a DP window
//!
//! * [WNCOMD](crate::raw::wncomd) - Complement a DP window
//!
//! * [WNCOND](crate::raw::wncond) - Contract the intervals of a DP window
//!
//! * [WNDIFD](crate::raw::wndifd) - Difference two DP windows
//!
//! * [WNELMD](crate::raw::wnelmd) - Element of a DP window
//!
//! * [WNEXPD](crate::raw::wnexpd) - Expand the intervals of a DP window
//!
//! * [WNEXTD](crate::raw::wnextd) - Extract the endpoints from a DP window
//!
//! * [WNFETD](crate::raw::wnfetd) - Fetch an interval from a DP window
//!
//! * [WNFILD](crate::raw::wnfild) - Fill small gaps in a DP window
//!
//! * [WNFLTD](crate::raw::wnfltd) - Filter small intervals from a DP window
//!
//! * [WNINCD](crate::raw::wnincd) - Included in a DP window
//!
//! * [WNINSD](crate::raw::wninsd) - Insert an interval into a DP window
//!
//! * [WNINTD](crate::raw::wnintd) - Intersect two DP windows
//!
//! * [WNRELD](crate::raw::wnreld) - Compare two DP windows
//!
//! * [WNSUMD](crate::raw::wnsumd) - Summary of a DP window
//!
//! * [WNUNID](crate::raw::wnunid) - Union two DP windows
//!
//! * [WNVALD](crate::raw::wnvald) - Validate a DP window
//!
//!
//! # Appendix: Document Revision History
//!
//!
//!
//!
//!
//! ### Febuary 6, 2009 (EDW)
//!
//! Document edited to conform to current NAIF format for Required Reading
//! Documents.
//!
//!
//!
//!
//!