Table of Contents Previous Chapter Chapter 9: compress - Compression

# Chapter 9: compress - Compression

## 1. Introduction

The VAL field of this record refers to an array of length NSAM. Unless INP is a database link, the compression algorithm is ignored. If, however, INP is a database link, then this record type supports several algorithms: CIRBUF, AVERAGE, NTO1LOW, NTO1HIGH, and NTO1AVE. Each will be discussed separately.

CIRBUF keeps a circular buffer of length NSAM. Each time the record is processed, it gets the data referenced by INP and puts it into the circular buffer referenced by VAL. Note that when INP refers to a scalar, VAL is just a time ordered circular buffer of values obtained from INP.

If AVERAGE is chosen, then VAL refers to an array of length NSAM that contains an element by element time average of values taken from the array referenced by INP. N successive samples of INP are averaged in order to compute VAL.

If NTO1LOW, NTO1HIGH, or NTO1AVE are chosen, then VAL is a circular buffer of length NSAM. The actual algorithm depends on whether INP references a scalar or an array. If INP refers to a scalar, then N successive time ordered samples of INP are taken. After the Nth sample is obtained a new value, determined by the algorithm (LOW, HIGH, or AVE), is written to the circular buffer referenced by VAL. If INP refers to an array, then each time the record is processed, the array referenced by INP is obtained, divided into sub-arrays each of length N, and the algorithm applied to each sub-array. The result obtained from each subarray is written to the circular buffer referenced by VAL.

## 2. Field Summary

```--------------------------------------------------------------
Field  Type       DCT  Initial  Access  Modify  Rec Proc   PP
Monitor
--------------------------------------------------------------
VAL    DOUBLE     No   0        Yes     Yes     Yes        Yes
INP    INLINK     Yes  0        No      No      N/A        No
RES    SHORT      No   0        Yes     Yes     No         No
ALG    RECCHOICE  Yes  0        Yes     No      No         No
NSAM   ULONG      Yes  1        Yes     No      No         No
N      ULONG      Yes  1        Yes     No      No         No
ILIL   FLOAT      Yes  0        Yes     Yes     No         No
IHIL   FLOAT      Yes  0        Yes     Yes     No         No
HOPR   FLOAT      Yes  0        Yes     Yes     No         No
LOPR   FLOAT      Yes  0        Yes     Yes     No         No
PREC   SHORT      Yes  0        Yes     Yes     No         No
EGU    STRING     Yes  null     Yes     Yes     No         No
OFF    ULONG      No   0        Yes     No      No         No
NUSE   ULONG      No   0        Yes     No      No         No
BPTR   NOACCESS   No   0        No      No                 No
SPTR   NOACCESS   No   0        No      No                 No
WPTR   NOACCESS   No   0        No      No                 No
CVB    DOUBLE     No   0        Yes     No      No         No
INX    ULONG      No   0        Yes     No      No         No
--------------------------------------------------------------
```

## 3. Field Descriptions

```--------------------------------------------------------------------------------------------
Name  Summary                 Description
--------------------------------------------------------------------------------------------
VAL   Value Field             This field is determined as a result of record processing. It
is a double precision array of length NSAM.
INP   Input Link              INP can be a constant, a database link, or a channel access
link. Unless it is a database link, ALG is meaningless.
RES   Reset                   Setting this field causes the algorithm to start over from
the beginning.
ALG   Algorithm               CIRBUF, AVERAGE, NTO1LOW, NTO1HIGH, or
NTO1AVE.
NSAM  Number in Sample        Number of elements in VAL.
N     Number                  Value of N for AVERAGE and NTO1xxx algorithms.
ILIL  Initial Low             Applies to NTO1xxx applied to INP arrays.
Interest Value
IHIL  Initial High Interest
Value
HOPR  High Operating          These fields determine the upper and lower display limits
Range                   for graphics displays and the upper and lower control
limits for control displays. The fields are used by record
support to honor calls to get_graphic_double or
get_control_double.
LOPR  Low Operating
Range
PREC  Display Precision       Precision with which to display VAL.  This field is used by
record support to supply a value when get_precision
is called.
EGU   Engineering Units       ASCII string describing Engineering units.  This field is
used by record support to supply a units description string
when get_units is called.
OFF   Current Offset
NUSE  Number Used             Number of elements currently stored.
BPTR  Buffer Pointer          Holds array referenced by VAL
SPTR  Summing Buffer          For array averages.
Pointer
WPTR  Work Buffer             For dbGetLinks.
Pointer
CVB   Compress Value
Buffer
INX   Current Index of
1,...,N
--------------------------------------------------------------------------------------------
```

## 4. Record Support Routines

### init_record

Space for all necessary arrays is allocated. The addresses are stored in the appropriate fields in the record.

### process

See next section.

### special

This routine is called when RSET is set. It performs a reset.

### get_value

Fills in the values of struct valueDes so that they refer to VAL.

### cvt_dbaddr

This is called by dbNameToAddr. It makes the dbAddr structure refer to the actual buffer holding the result.

### get_array_info

Obtains values from the circular buffer referenced by VAL.

### put_array_info

Writes values into the circular buffer referenced by VAL.

Retrieves EGU.

Retrieves PREC.

### get_graphic_double

Sets the upper display and lower display limits for a field. If the field is VAL, HIHI, HIGH, LOW, or LOLO, the limits are set to HOPR and LOPR, else if the field has upper and lower limits defined they will be used, else the upper and lower maximum values for the field type will be used.

### get_control_double

Sets the upper control and the lower control limits for a field. If the field is VAL, HIHI, HIGH, LOW, or LOLO, the limits are set to HOPR and LOPR, else if the field has upper and lower limits defined they will be used, else the upper and lower maximum values for the field type will be used.

## 5. Record Processing

Routine process implements the following algorithm:

1. If INP is not a database link, check monitors and the forward link and return.
2. Get the current data referenced by INP.
3. Perform the appropriate algorithm:
1. AVERAGE: Read N successive instances of INP and perform an element by element average. Until N instances have been obtained it just return without checking monitors or the forward link. When N instances have been obtained complete the algorithm, store the result in the VAL array, check monitors and the forward link, and return.
2. CIRBUF: Write the values obtained from INP into the VAL array as a circular buffer, check monitors and the forward link, and return.
3. NTO1xxx and INP refers to a scalar: Obtain N successive values from INP and apply the NTO1xxx algorithm to these values. Until N values are obtained monitors and forward links are not checked. When N successive values have been obtained, complete the algorithm, check monitors and the forward link, and return.
4. NTO1xxx and INP refers to an array: The ILIL and IHIL are honored if ILIL<IHIL. The input array is divided into subarrays of length N. The specified NTO1xxx compression algorithm is applied to each subarray and the result stored in the array referenced by VAL. The monitors and forward link are checked.
4. If success, set UDF to FALSE.
5. Check to see if monitors should be invoked:
• Alarm monitors are invoked if the alarm status or severity has changed.
• NSEV and NSTA are reset to 0.
6. Scan forward link if necessary, set PACT FALSE, and return.
` `
Table of Contents Next Chapter