The conversion of raw UDF data into physical units is done through a UDF algorithm. A UDF algorithm is the successive application of tables defined in the UDF VIDF. The actual application of the algorithm is accomplished through a call to the UDF kernel routine convert_to_units.
UDF data is accessed through a call to read_drec. This call takes data from a specified sensor or sensor matrix column and places that data into an output structure. In addition the output structure has a number of other quantities loaded into it including: the scan index array, all associated ancillary data, the current mode data, the current timing information, the data quality flag, the current spin rate, the phase angles associated with the retrieved data, and if set in the VIDF, the pitch angles associated with the retrieved data. Any information which is contained in the output structure is available to be used within a UDF algorithm. The fact that data from only a single UDF sensor is acquired in a read is the reason that data from multiple sensors cannot be used together.
The first step taken by the convert_to_units routine when called is to locate a base set of data from within the UDF output structure and to preload it into the UDF algorithm output buffer. The data set chosen depends on the value of the DataField input field and can include: the sensor data, the scan index array, data from any one ancillary data set, any one mode byte, the data quality flag, the computed pitch angles, the starting or stopping phase angles. For vector or matrix sensors the output buffer is an array of values and it a single element for scalar sensors.
After the initial loading of the output buffer, the algorithm steps are parsed. The algorithm is an input parameter and is specified through the NAS, Tbls, and Ops inputs. NAS specifies how many steps are defined in the algorithm and Tbls and Ops are arrays of length NAS which provide the VIDF table numbers and the operations to apply at each step in the algorithm.
Once an algorithm has been developed it is usually stored in a Units definition field in the UDF PIDF which is used by most interactive UDF based programs to determine what set of data are contained in a UDF definition and what units are available for each data set. Once a data set and an appropriate set of units has been selected, the needed conversion algorithm can be obtained from the PIDF Unit definition block and directly input into the convert_to_units routine.
A VIDF defined table may be either sensor or mode based. The major difference is that in sensor based tables the lookup table or the set of polynomial coefficients returned may depend upon the value of one of the VIDF status bytes. In addition, sensor based tables can have any data source found in the UDF output structure (with the exception of mode data) or any intermediate step data currently being held in one of the UDF algorithm buffers assigned as input to them.
If a VIDF table returns a look up table and if V is the defined table input buffer then the value OV output from the application of the table is generally:
for (i = 0; i < input_array_length; ++i) OV[i] = T[(int)V[i]];where T is the array of look up table values and the loop processes all of the defined UDF input data. This is not true when the table is used in conjunction with the Table Inverse operator. In this case the table returns the index of the lookup location which most closely matches the input value V.
If the table returns a set of N polynomial coefficients C then the polynomial expansion of the input data is given by:
for (i = 0; i < input_array_length; ++i) { X = 1.0; OV[i] = C[0]; for (j = 1; j < N; ++j) { X *= V[i]; OV[i] += X * C[j]; } }The output value(s) from a table operation are placed back into one of the VIDF Algorithm Buffers according according to the algorithm operation defined for that algorithm step.
Once the Table Operation has been completed for a given algorithm step, the returned values are placed back into one of the 4 VIDF Algorithm Buffers in accordance with the algorithm operation defined for that step in the algorithm. Each operator is defined by a maximum 5 digit digit number which may be signed. Generically an operator can be represented as a integer of the form BBEEO. The least significant digit O coupled with the operator sign specifies the base operation. The digits EE specify any extended operations which occur after the base operation has been completed. Finally the most significant two digits BB are used to indicate the algorithm buffers being manipulated in the operation.
Each step in a UDF algorithm has the generic form:
In the above BufB is the input buffer to be acted on, and BufA is
the output buffer in which the result of the algorithm step is stored.
Both are determined from the BB in the algorithm operator and
may be the same buffer.
The Basic Operation operator codes are shown in the table below. The symbols in parenthesis can be used in the PIDF in place of the numerical value when listing the operators used in a defined UDF algorithm. The symbol can only be used only when there is no extended operation and the primary buffer is both the buffer being operated on and the destination buffer. This is equivalent to saying that the most significant four digits in the operator are 0. The Basic Operators can be both positive and negative. A negative Basic Operator makes the entire operation code negative.
| BASIC OPERATOR DEFINITIONS | |
|---|---|
| VALUE | BASE OPERATION |
| 0 | EQUALS (=) |
| 1 | ADDITION (+) |
| 2 | SUBTRACTION (-) |
| 3 | MULTIPLICATION (*) |
| 4 | DIVISION (/) |
| 5 | LOGICAL BITWISE AND (&) |
| 6 | LOGICAL BITWISE OR (|) |
| 7 | SHIFT RIGHT (>) |
| 8 | SHIFT LEFT (<) |
| 9 | POWER (^) |
| -1 | MODULUS (%) |
| -2 | BITWISE EXCLUSIVE OR |
| -3 | TABLE INVERSE |
With the possibly the exception of the equals, the power and the Table Inverse operators, it is reasonably clear how the base operations work in the generic algorithm step equation defined above. The equals operator simply transfers the contents of OV to BufB. The power operator performs the operation BufBOV. The table inverse operator is really a table operation in the guise of an operator. It only operates on lookup tables and returns the index of the table value which most closely matches the input value. The table must be in ascending or descending order. If the first three values are not ascending or descending then the input value is returned unchanged and the operator works as a pass through operator, handy when the operator is used in conjunction with a mode dependency.
The tens and hundreds place in the UDF operator defines the extended operations. An extended operation occurs after the base operation with its input being the output of the base operation. The defined extended operations are shown in the following table. V in the operation definitions is the output of the base operation. The X in the ones place in the operator can be any of the base operations defined above.
| BASIC OPERATOR DEFINITIONS | |
|---|---|
| VALUE | BASE OPERATION |
| 1X | eV |
| 2XK | logeV |
| 3X | 10V |
| 4X | log10V |
| 5X | 2V |
| 6X | sqrt(V) |
| 7X | cos(V) (V in degrees) |
| 8X | sin(V) (V in degrees) |
| 9X | tan(V) (V in degrees) |
| 10X | acos(V) |
| 11X | asin(V) |
| 12X | atan(V) |
| 13X | 1.0/V |
| 14X | V * UDF Header Data Accumulation Field (in seconds) |
| 15X | V */UDF Header Data Accumulation Field (in seconds) |
| 16X | -V |
| 17X | V2 |
| 18X | V - (Stop Spin Phase - Start Spin Phase)/2 |
| 19X | abs(V) |
| 20X | V + Start Azimuthal Angle |
| 21X | (int)V |
| 22X | (signed)V (8 bit 2's complement) |
| 23X | (signed)V (16 bit 2's complement) |
| 24X | (signed)V (12 bit 2's complement) |
| 30 | erf(V) |
The most significant two places in the UDF operator are used to indicate the input (BufA) and output buffer (BufB) in any algorithm step. The definitions of the buffer digits in the UDF operator are given in the following table. The XXX in place of the lower three operator digits represents the base and extended operations. The various buffers are listed by the numbers 0 through 6, where 0 is the algorithm output buffer, 1 through 3 the general buffers, and 4 through 6 the storage only buffers. Note that leading zeros in the UDF operator are always omitted but shown here for clarity.
| BASIC OPERATOR DEFINITIONS | ||
|---|---|---|
| OPERATOR | INPUT (BufA) | OUTPUT (BufB) |
| 00XXX | 0 | 0 |
| 01XXX | 1 | 1 |
| 02XXX | 1 | 0 |
| 03XXX | 0 | 1 |
| 04XXX | 1 | 2 |
| 05XXX | 0 | 3 |
| 06XXX | 2 | 0 |
| 07XXX | 2 | 1 |
| 08XXX | 3 | 2 |
| 09XXX | 1 | 3 |
| 10XXX | 3 | 0 |
| 11XXX | 3 | 1 |
| 12XXX | 0 | 2 |
| 13XXX | 2 | 3 |
| 14XXX | 0 | 4 |
| 15XXX | 0 | 5 |
| 16XXX | 0 | 6 |
| 17XXX | 1 | 4 |
| 18XXX | 2 | 5 |
| 19XXX | 3 | 6 |
| 20XXX | 2 | 2 |
| 21XXX | 3 | 3 |
| 22XXX | 4 | 4 |
| 23XXX | 5 | 5 |
| 24XXX | 6 | 6 |
Show below are several examples of UDF algorithms.
The following is an example algorithm which is used to convert raw UDF particle data into units of velocity distribution function. The raw UDF data to be converted is acquired from a vector sensor which is measuring counts as a function of energy. For convenience in notation below the raw sensor data will be denoted by V and the associated raw scan index data by I.
The basic equation to use is given by
where A is a constant, R is the sensor data in counts per accumulation period, Eff is the energy dependent detector efficiency, GF is the sensor geometry factor, dT is the accumulation period, and dE/E is the energy band resolution.
The following tables have been set up in the VIDF:
| VIDF TABLES | ||
|---|---|---|
| TABLE | INPUT | DESCRIPTION |
| 0 | Raw Sensor Data | Look Up Decompression Table, Taking Raw Sensor Data to Counts Per Accumulation Period |
| 1 | Raw Scan Index | Loop Up Table Giving Eff |
| 2 | Raw Scan Index | Holds Constant Value GF |
| 3 | Raw Scan Index | Holds Constant Value dE/E |
| 4 | Raw Scan Index | Holds Constant Value C |
| 4 | Raw Scan Index | Loop Up Table Giving Ev |
A comment. A table which returns a constant value is a polynomial expansion with just a single coefficient defined, that being the constant value to be returned. As such, it doesn't really matter what the input to the table is since it is never used in the expansion.
The UDF algorithm is given in the following table.
| OPERATOR DEFINITIONS | |||
|---|---|---|---|
| STEP | TABLE | OPERATION | ACCUMULATIVE RESULT |
| 1 | 0 | 150 | R / dT |
| 2 | 4 | * | (C * R)/dT |
| 3 | 1 | / | (C * R)/[Eff * dT] |
| 4 | 5 | / | (C * R)/[Eff * dT * Ev] |
| 5 | 5 | / | (C * R)/[Eff * dT * Ev |
| 6 | 3 | / | (C * R)/[Eff * dT * Ev |
The second and third columns in the table provide the necessary input to the UDF kernel routine convert_to_units, to define the algorithm. The values in the second column provide the input to the Tbls input array and the values in the third column the input to the Ops input array. The number of algorithm steps (NAS) is 6.
The following is an example algorithm which is used to unpack a packed UDF sensor. The sensor is 8 bits in length and is built of a 5 bit data word in bits 0-4 and a 3 bit data word in bits 5-7.
The following tables have been set up in the VIDF:
| VIDF TABLES | ||
|---|---|---|
| TABLE | INPUT | DESCRIPTION |
| 0 | Processed Data | Holds Constant Value 5 |
| 1 | Processed Data | Holds Constant Value 7 |
| 2 | Processed Data | Holds Constant Value 31 |
The tables all have processed data as input since the call to convert_to_units is made asking for the sensor data to be loaded into the output buffer. At this point it becomes processed data and the contents and it is this data which will be used as input to the tables.
The UDF algorithm is given in the following table.
| OPERATOR DEFINITIONS (BREAK OUT LOWER 5 BITS) |
|||
|---|---|---|---|
| STEP | TABLE | OPERATION | ACCUMULATIVE RESULT |
| 1 | 2 | & | Lower 5 Bits |
| OPERATOR DEFINITIONS (BREAK OUT UPPER 3 BITS) |
|||
|---|---|---|---|
| STEP | TABLE | OPERATION | ACCUMULATIVE RESULT |
| 1 | 0 | > | Shift Bit 5 To Bit 0 |
| 2 | 1 | & | Lower 3 Bits |
In both tables the second and third columns provide the necessary input to the UDF kernel routine convert_to_units, to split out the two bit fields. The values in the second column provide the input to the Tbls input array and the values in the third column the input to the Ops input array. The number of algorithm steps (NAS) is 6.