blob: f55da49dd8c98741ca3a8c618597b612cd55f9a3 (
plain)
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
|
.\" Copyright (c) 2025
.\" Manual page for cumsum(1)
.\"
.Dd $Mdocdate$
.Dt CUMSUM 1
.Os
.Sh NAME
.Nm cumsum
.Nd calculate cumulative sums from numeric data
.Sh SYNOPSIS
.Nm cumsum
.Op Fl f | u
.Op Fl r | w Ar window_size
.Op Fl h
.Op Ar file
.Sh DESCRIPTION
The
.Nm
utility computes cumulative sums from input data consisting of numeric values.
It reads data from
.Ar file
or standard input if no file is specified, and outputs cumulative sums
suitable for statistical analysis and plotting.
.Pp
Input data must consist of whitespace-separated numeric values. The utility
supports three modes of operation:
.Bl -bullet
.It
Default mode: outputs the total sum of all input values
.It
Running sum mode (with
.Fl r
): outputs the cumulative sum after each input value
.It
Windowed sum mode (with
.Fl w
): outputs the sum of the last N values in a sliding window
.El
.Pp
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl f
Read input values as floats.
.It Fl u
Read input values as unsigned integers
.It Fl r
Generate running cumulative sums, outputting the sum after each input value.
.It Fl w Ar window_size
Generate windowed sums using a sliding window of the specified size.
Each output line represents the sum of the last
.Ar window_size
values.
.It Fl h
Display usage information and exit.
.El
.Pp
If
.Fl f
or
.Fl u
is not specified, the input values will be read as signed integers by
default.
.Pp
The
.Fl r
and
.Fl w
options are mutually exclusive.
.Sh INPUT FORMAT
Input consists of whitespace-separated numeric values, one per line or
space-separated on the same line. Invalid tokens are skipped with a warning.
.Pp
Example input:
.Bd -literal -offset indent
1
2
3
4
5
.Ed
.Pp
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
Calculating the total sum of integer data in a file:
.Bd -literal -offset indent
$ cumsum data.txt
15
.Ed
.Pp
Calculating running cumulative sums:
.Bd -literal -offset indent
$ cumsum -r data.txt
1
3
6
10
15
.Ed
.Pp
Calculating windowed sums with a window size of 3:
.Bd -literal -offset indent
$ cumsum -w 3 data.txt
1
3
6
9
12
.Ed
.Pp
Processing float data:
.Bd -literal -offset indent
$ cumsum -f measurements.dat
123.456000
.Ed
.Sh SEE ALSO
.Xr awk 1 ,
.Xr paste 1 ,
.Xr seq 1 ,
.Xr gnuplot 1
.Sh AUTHORS
.An Douglas B. Rumbaugh
.Mt "dbrumbaugh@harrisburgu.edu"
|