# How can I encode pressure with higher precision - ecCodes BUFR FAQ

## Step-by-step guide

First of all let's see how data is encoded and decoded. The relevant formulae are:

```value = (intValue + ref) / (10^scale)
min = ref / 10^scale
max = (2^width - 2 + ref) / (10^scale)
intValue = (10^scale) * value - ref
precision = 10^-scale```

Where scale=scale factor, ref=reference value (or bias) and width=bit width of the descriptor.
And "intValue" is an integer of "width" bits from the Data Section.

Example:
For "pressure" we have:
code=007004,  type=long (integer), scale=-1, reference=0, bitwidth=14

And the formula used is: value = (intValue + ref) * 10-scale
So when we encode a value of 213.61 we do the above formula in reverse i.e.

intValue = value*10scale - ref

intValue = value*10-1 - 0 = round(213.61/10) = 21
So we store the integer 21 in the BUFR message using 14 bits.
When we come to decode it, we use the first formula i.e. value = (21 + 0) / 10-1 = 21 * 10 = 210
So when you put in 213.61, you will get out 210. The precision of this element is 10-scale i.e. 10 so it will not store intermediate values. It will be 210 or 220 or 230 etc..

To encode this descriptor with higher precision we can add an operator around the 007004 as follows:

encode.filter
```set unexpandedDescriptors = { 207003, 7004, 207000 };
set pressure = 12.34;
set pack = 1;
write;```

We have added a 207003 operator that changes the scale factor, the reference and the width of the following key. Then disable the behaviour with operator 207000. Quoting the WMO BUFR table C for reference:

Operator 207YYY means "Increase scale, reference value and data width"
Description: For Table B elements that are not CCITT IA5 (character data), code or flag tables:
1. Add YYY bits to the existing scale factor
2. Multiply the existing reference value by 10**YYY
3. Calculate ((10 * YYY) + 2) / 3, disregard any fractional remainder and add the result to the existing bit width.

Now we can encode pressure with 2 decimal digits:

"key" : "pressure",
"value" : 12.34,
"index" : 1,
"code" : "007004",
"units" : "Pa",
"scale" : 2,
"reference" : 0,
"width" : 24

Note the difference with the original 007004 descriptor:

"key" : "pressure",
"value" : 10,
"index" : 1,
"code" : "007004",
"units" : "Pa",
"scale" : -1,
"reference" : 0,
"width" : 14

so we increased the width by 10 bits and changed the scale to 2.

• Page:
• Page:
• Page:
• Page:
• Page: