ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/doc/man/man1/rcalc.1
Revision: 1.8
Committed: Tue Sep 4 17:36:41 2007 UTC (16 years, 8 months ago) by greg
Branch: MAIN
CVS Tags: rad4R1, rad4R0, rad3R9
Changes since 1.7: +3 -3 lines
Log Message:
Added backslashes in front of hyphens (thanks to Bernd Zeimetz for his effort)

File Contents

# Content
1 .\" RCSid "$Id: rcalc.1,v 1.7 2006/12/23 17:27:45 greg Exp $"
2 .TH RCALC 1 4/6/99 RADIANCE
3 .SH NAME
4 rcalc - record calculator
5 .SH SYNOPSIS
6 .B rcalc
7 [
8 .B \-b
9 ][
10 .B \-l
11 ][
12 .B \-p
13 ][
14 .B \-n
15 ][
16 .B \-w
17 ][
18 .B \-u
19 ][
20 .B \-tS
21 ][
22 .B "\-i format"
23 ][
24 .B "\-o format"
25 ][
26 .B "\-f source"
27 ][
28 .B "\-e expr"
29 ][
30 .B "\-s svar=sval"
31 ]
32 file ..
33 .SH DESCRIPTION
34 .I Rcalc
35 transforms ``records'' from each
36 .I file
37 according to the given set of literal and relational information.
38 By default, records are separated by newlines, and contain
39 numeric fields separated by tabs.
40 The
41 .I \-tS
42 option is used to specify an alternate tab character.
43 .PP
44 A
45 .I \-i format
46 option specifies a template for an alternate
47 input record format.
48 .I Format
49 is interpreted as a specification string if it contains a dollar sign '$'.
50 Otherwise, it is interpreted as the name of the file containing
51 the format specification.
52 In either case, if the format does not end with a newline, one will be added
53 automatically.
54 A special form of the
55 .I \-i
56 option may be followed immediately by a 'd' or an 'f' and an optional
57 count, which defaults to 1, indicating the number of double or float
58 binary values to read per record on the input file.
59 If the input is byte-swapped, the
60 .I \-iD
61 or
62 .I \-iF
63 options may be substituted.
64 If binary input is specified, no format string or file is needed.
65 .PP
66 A
67 .I \-o format
68 option specifies an alternate output record format.
69 It is interpreted the same as an input specification, except that
70 the special
71 .I \-od
72 or
73 .I \-of
74 options do not require a count, as this will be determined by the
75 number of output channels in the given expressions.
76 If byte-swapped output is desired, the
77 .I \-oD
78 or
79 .I \-oF
80 options may be substituted.
81 .PP
82 The
83 .I \-p
84 option specifies "passive mode," where characters that do not
85 match the input format are passed unaltered to the output.
86 This option has no effect unless
87 .I \-i
88 is also specified, and does not make much sense unless
89 .I \-o
90 is also given.
91 With both input and output formats, the passive mode can
92 effectively substitute information in the middle of a file
93 or stream without affecting the rest of the data.
94 .PP
95 The variable and function definitions in each
96 .I \-f source
97 file are read and compiled.
98 The
99 .I \-e expr
100 option can be used to define variables on the command line.
101 Since many of the characters in an expression have special meaning
102 to the shell, it should usually be enclosed in single quotes.
103 The
104 .I \-s svar=sval
105 option can be used to assign a string variable a string value.
106 If this string variable appears in an input format, only records
107 with the specified value will be processed.
108 .PP
109 The
110 .I \-b
111 option instructs the program to accept only exact matches.
112 By default, tabs and spaces are ignored except
113 as field separators.
114 The
115 .I \-l
116 option instructs the program to ignore newlines in the input,
117 basically treating them the same as tabs and spaces.
118 Normally, the beginning of the input format matches the beginning of
119 a line, and the end of the format matches the end of a line.
120 With the
121 .I \-l
122 option, the input format can match anywhere on a line.
123 .PP
124 The
125 .I \-w
126 option causes non-fatal error messages (such as division by zero) to
127 be supressed.
128 The
129 .I \-u
130 option causes output to be flushed after each record.
131 The
132 .I \-n
133 option tells the program not to get any input, but to produce a
134 single output record.
135 Otherwise, if no files are given, the standard input is read.
136 .PP
137 Format files associate names with string and numeric fields
138 separated by literal information in a record.
139 A numeric field is given in a format file as a dollar sign, followed
140 by curly braces enclosing a variable name:
141 .PP
142 This is a numeric field: ${vname}
143 .PP
144 A string variable is enclosed in parentheses:
145 .PP
146 This is a string field: $(sname)
147 .PP
148 The program attempts to match literal information in
149 the input format to its input and assign string and numeric
150 fields accordingly.
151 If a string or numeric field variable appears more than once in
152 the input format, input values for the corresponding fields must
153 match (ie. have the same value) for the whole record to match.
154 Numeric values are allowed some deviation, on the order of 0.1%, but
155 string variables must match exactly.
156 Thus, dummy variables for "don't care" fields should be given unique
157 names so that they are not all required to take on the same value.
158 .PP
159 For each valid input record, an output record is produced
160 in its corresponding format.
161 Output field widths are given implicitly by the space occupied
162 in the format file, including the dollar sign and braces.
163 This makes it impossible to produce fields with fewer than four
164 characters.
165 If the
166 .I \-b
167 option is specified, input records must exactly match the
168 template.
169 By default, the character following each input field is used as
170 a delimiter.
171 This implies that string fields that are followed by white space
172 cannot contain strings with white space.
173 Also, numeric fields followed but not preceded by white space
174 will not accept numbers preceded by white space.
175 Adjacent input fields are advisable only with the
176 .I \-b
177 option.
178 Numeric output fields may contain expressions as well as variables.
179 A dollar sign may appear in a literal as two dollar signs ($$).
180 .PP
181 The definitions specified in
182 .I \-e
183 and
184 .I \-f
185 options relate numeric output fields to numeric input fields.
186 For the default record format, a field is a variable of the form
187 $N, where N is the column number, beginning with 1.
188 Output columns appear on the left-hand side of assignments, input
189 columns appear on the right-hand side.
190 .PP
191 A variable definition has the form:
192 .PP
193
194 var = expression ;
195
196 .PP
197 Any instance of the variable in an expression will be replaced
198 with its definition.
199 .PP
200 An expression contains real numbers, variable names, function calls,
201 and the following operators:
202 .PP
203 + - * / ^
204 .PP
205 Operators are evaluated left to right.
206 Powers have the highest precedence; multiplication and
207 division are evaluated before addition and subtraction.
208 Expressions can be grouped with parentheses.
209 All values are double precision real.
210 .PP
211 A function definition has the form:
212 .PP
213
214 func(a1, a2, ..) = expression ;
215
216 .PP
217 The expression can contain instances of the function arguments
218 as well as other variables and functions.
219 Function names can be passed as arguments.
220 Recursive functions can be defined using calls to the defined
221 function or other functions calling the defined function.
222 .PP
223 The variable
224 .I cond,
225 if defined, will determine whether the current input record produces
226 an output record.
227 If
228 .I cond
229 is positive, output is produced.
230 If
231 .I cond
232 is less than or equal to zero, the record is skipped and no other expressions
233 are evaluated.
234 This provides a convenient method for avoiding inappropriate calculations.
235 The following library of pre-defined functions and variables is provided:
236 .TP 10n
237 .BR "in(n)"
238 Return the value for input column
239 .I n,
240 or the number of columns available in this record if
241 .I n
242 is 0.
243 This is an alternate way to get a column value instead of using
244 the $N notation, and is more flexible since it is programmable.
245 This function is disabled if an input format is used.
246 .TP
247 .BR "if(cond, then, else)"
248 if cond is greater than zero,
249 then is evaluated, otherwise else is evaluated.
250 This function is necessary for recursive definitions.
251 .TP
252 .BR "select(N, a1, a2, ..)"
253 return aN (N is rounded to the nearest integer).
254 This function provides array capabilities.
255 If
256 .I N
257 is zero, the number of available arguments is returned.
258 .TP
259 .BR "rand(x)"
260 compute a random number between 0 and 1 based on x.
261 .TP
262 .BR "floor(x)"
263 return largest integer not greater than x.
264 .TP
265 .BR "ceil(x)"
266 return smallest integer not less than x.
267 .TP
268 .BR "sqrt(x)"
269 return square root of x.
270 .TP
271 .BR "exp(x)"
272 compute e to the power of x (e approx = 2.718281828).
273 .TP
274 .BR "log(x)"
275 compute the logarithm of x to the base e.
276 .TP
277 .BR "log10(x)"
278 compute the logarithm of x to the base 10.
279 .TP
280 .BR PI
281 the ratio of a circle's circumference to its diameter.
282 .TP
283 .BR recno
284 the number of records recognized thus far.
285 .TP
286 .BR outno
287 the number or records output thus far (including this one).
288 .TP
289 .BR "sin(x), cos(x), tan(x)"
290 trigonometric functions.
291 .TP
292 .BR "asin(x), acos(x), atan(x)"
293 inverse trigonometric functions.
294 .TP
295 .BR "atan2(y, x)"
296 inverse tangent of y/x (range \-pi to pi).
297 .SH EXAMPLE
298 To print the square root of column two in column one,
299 and column one times column three in column two:
300 .IP "" .2i
301 rcalc \-e '$1=sqrt($2);$2=$1*$3' inputfile > outputfile
302 .SH AUTHOR
303 Greg Ward
304 .SH BUGS
305 String variables can only be used in input and output formats and
306 .I \-s
307 options, not in definitions.
308 .PP
309 Tabs count as single spaces inside fields.
310 .SH "SEE ALSO"
311 cnt(1), ev(1), getinfo(1), icalc(1), rlam(1), tabfunc(1), total(1)