04.01.2015 Views

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Section 7. Installation<br />

CRBasic Example 19.<br />

Public Pressure(3), Mult(3), Offset(3)<br />

DataTable(AvgPress,1,-1)<br />

DataInterval(0,60,Min,10)<br />

Average(3,Pressure(),IEEE4,0)<br />

EndTable<br />

BeginProg<br />

'Calibration Factors:<br />

Mult(1)=0.123 : Offset(1)=0.23<br />

Mult(2)=0.115 : Offset(2)=0.234<br />

Mult(3)=0.114 : Offset(3)=0.224<br />

Use of Arrays as Multipliers and Offsets<br />

Scan(1,Sec,10,0)<br />

'VoltSe instruction using array of multipliers and offsets:<br />

VoltSe(Pressure(),3,mV5000,1,True,0,_60Hz,Mult(),Offset())<br />

CallTable AvgPress<br />

NextScan<br />

EndProg<br />

7.7.3.9 Expressions<br />

An expression is a series of words, operators, or numbers that produce a value or<br />

result. Expressions are evaluated from left to right, with deference to precedence<br />

rules. The result of each stage of the evaluation is of type Long (integer, 32 bits) if<br />

the variables are of type Long (constants are integers) and the functions give<br />

integer results, such as occurs with INTDV(). If part of the equation has a<br />

floating point variable or constant (24 bits), or a function that results in a floating<br />

point, the rest of the expression is evaluated using floating-point, 24-bit math,<br />

even if the final function is to convert the result to an integer, so precision can be<br />

lost; for example, INT((rtYear-1993)*.25). This is a critical feature to consider<br />

when, 1) trying to use integer math to retain numerical resolution beyond the limit<br />

of floating point variables, or 2) if the result is to be tested for equivalence against<br />

another value. See section Floating-Point Arithmetic (p. 142) for limits.<br />

Two types of expressions, mathematical and programming, are used in CRBasic.<br />

A useful property of expressions in CRBasic is that they are equivalent to and<br />

often interchangeable with their results.<br />

Consider the expressions:<br />

x = (z * 1.8) + 32 '(mathematical expression)<br />

If x = 23 then y = 5 '(programming expression)<br />

The variable x can be omitted and the expressions combined and written as:<br />

If (z * 1.8 + 32 = 23) then y = 5<br />

Replacing the result with the expression should be done judiciously and with the<br />

realization that doing so may make program code more difficult to decipher.<br />

7.7.3.9.1 Floating-Point Arithmetic<br />

Variables and calculations are performed internally in single precision IEEE fourbyte<br />

floating point with some operations calculated in double precision.<br />

142

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!