release: An example of how it works


The example beneath is designed to explain how release works.

Input

Input parameter: Input value(s): Description etc.:
mode 0 Always set this to '0' on first call, leave untouched thereafter
leading 1 No. of leading elements in 'idata()' that the users does not wish to compress
length 29 Dimension of (uncompressed) 'idata()'; left unchanged by release
idata
Element # 12*3* 4*5*6* 78
Value 988- 32767- 32767- 32768 - 327514- 3276828
Element # 9101112 13141516
Value - 3631308- 1123- 3261 - 16411- 3276732762- 32768
Element # 17181920 21222324
Value 82- 10915- 31852- 1851 - 553120820- 1821790
compressed array (leading entries, compressed field, trailing entries)
    1: leading entry
    2*: 'leading' - 32768
    3*: 'trailing' - 32768
    4*: int(# compressed entries/65536) - 32768
    5*: mod(# compressed entries, 65536) - 32768
    6*: compression algorithm no.
    7 - 23: compressed array
    24: trailing entry
maxsize 27 Dimension of the work array 'iwork()';
in the 2D case, this must be set >= nx*ny, etc.
nfactors 263 Dimension of 'factors()'; should be set >= 17
factors ... Factors used in the construction of the original set of values;
will be set on first call

Action

  1. Skip the leading entries; in this case, only consider elements from no. 2 and beyond

  2. Read and store the no. of trailing entries

  3. Read and check # leading entries
    (if not OK, print error message and return).

  4. Read the next two numbers n1, n2, and determine # compressed entries:
  5. Read the algorithm no. that was used during compression; here: no. 4
    (if this is a non-implemented algorithm, print error message and return)

    Start decompression (below, numbers in brackets are entries in the compressed field relative to #leading entries + 5):

  6. Read and decode next number:
    (1) -32768 -> single value specifier, read next value which is uncompressed

  7.   (2)  28
    'leading'+1:   28


  8. Read and decode next number:
    (3) -3631 -> under algorithm no. 4, negative values are two differences compressed as one:
    d1 = mod(3631-1, 181) = 10
    d2 = (3631-1 - d1)/181 = 20

  9. At this point, the signs of differences are unknown. Read the next value which contains these signs on bit-format; adjust to nonnegative number:
    (4) 308 -> bitsum = 308 + 32768 = 33076

  10. Decode the bit-formatted 'bitsum':
    bitsum >= 2**15 -> sign(16) = -1        bitsum = bitsum - 2**15 = 308
    bitsum < 2**14 -> sign(15) = 1
    bitsum < 2**13 -> sign(14) = 1
    bitsum < 2**12 -> sign(13) = 1
    bitsum < 2**11 -> sign(12) = 1
    bitsum < 2**10 -> sign(11) = 1
    bitsum < 2**9 -> sign(10) = 1
    bitsum >= 2**8 -> sign(9) = -1          bitsum = bitsum - 2**8 = 52
    bitsum < 2**7 -> sign(8) = 1
    bitsum < 2**6 -> sign(7) = 1
    bitsum >= 2**5 -> sign(6) = -1          bitsum = bitsum - 2**5 = 20
    bitsum >= 2**4 -> sign(5) = -1          bitsum = bitsum - 2**4 = 4
    bitsum < 2**3 -> sign(4) = 1
    bitsum >= 2**2 -> sign(3) = -1          bitsum = bitsum - 2**2 = 0
    bitsum < 2**1 -> sign(2) = 1
    bitsum < 2**0 -> sign(1) = 1

  11. Store d1 and d2:
    'leading'+2:   value('leading'+1) + sign(1)*d1 = 28 + 10 = 38
    'leading'+3:   value('leading'+2) + sign(2)*d2 = 38 + 20 = 58

  12. Read and decode next number:
    (5) -1123 -> negative values are two differences compressed as one:
    d1 = mod(1123-1, 181) = 36
    d2 = (1123-1 - d1)/181 = 6

  13. Store d1 and d2:
    'leading'+4:   value('leading'+3) + sign(3)*d1 = 58 - 36 = 22
    'leading'+5:   value('leading'+4) + sign(4)*d2 = 22 + 6 = 28

  14. Read and decode next number:
    (6) -3261 -> negative values are two differences compressed as one:
    d1 = mod(3261-1, 181) = 2
    d2 = (3261-1 - d1)/181 = 18

  15. Store d1 and d2:
    'leading'+6:   value('leading'+5) + sign(5)*d1 = 28 - 2 = 26
    'leading'+7:   value('leading'+6) + sign(6)*d2 = 26 - 18 = 8

  16. Read and decode next number:
    (7) -16411 -> negative values are two differences compressed as one:
    d1 = mod(16411-1, 181) = 120
    d2 = (16411-1 - d1)/181 = 90

  17. Store d1 and d2:
    'leading'+8:   value('leading'+7) + sign(7)*d1 = 8 + 120 = 128
    'leading'+9:   value('leading'+8) + sign(8)*d2 = 128 + 90 = 218

  18. Read and decode next number:
    (8) -32767 -> undefined values specifier; next value corresponds to # consequtive undefined values

  19. Read and decode next number:
    (9) 32762 -> # undefined values = 32768 - 32762 = 6

  20. Set to undefined values:
    'leading'+10:   -32767
    'leading'+11:   -32767
    'leading'+12:   -32767
    'leading'+13:   -32767
    'leading'+14:   -32767
    'leading'+15:   -32767

  21. Read and decode next number:
    (10) -32768 -> single value specifier, read next value which is uncompressed

  22.   (11)  82
    'leading'+16:   82

  23. Read and decode next number:
    (12) -10915 -> negative values are two differences compressed as one:
    d1 = mod(10915-1, 181) = 54
    d2 = (10915-1 - d1)/181 = 60

  24. Store d1:
    'leading'+17:   value('leading'+16) + sign(16)*d1 = 82 - 54 = 28

  25. 'sign()' has now been exhausted. Read the next value which contains signs of differences on bit-format; adjust to nonnegative number:
    (13) -31852 -> bitsum = -31852 + 32768 = 916

  26. Decode the bit-formatted 'bitsum':
    bitsum < 2**15 -> sign(16) = 1
    bitsum < 2**14 -> sign(15) = 1
    bitsum < 2**13 -> sign(14) = 1
    bitsum < 2**12 -> sign(13) = 1
    bitsum < 2**11 -> sign(12) = 1
    bitsum < 2**10 -> sign(11) = 1
    bitsum >= 2**9 -> sign(10) = -1        bitsum = bitsum - 2**9 = 404
    bitsum >= 2**8 -> sign(9) = -1          bitsum = bitsum - 2**8 = 148
    bitsum >= 2**7 -> sign(8) = -1          bitsum = bitsum - 2**7 = 20
    bitsum < 2**6 -> sign(7) = 1
    bitsum < 2**5 -> sign(6) = 1
    bitsum >= 2**4 -> sign(5) = -1          bitsum = bitsum - 2**4 = 4
    bitsum < 2**3 -> sign(4) = 1
    bitsum >= 2**2 -> sign(3) = -1          bitsum = bitsum - 2**2 = 0
    bitsum < 2**1 -> sign(2) = 1
    bitsum < 2**0 -> sign(1) = 1

  27. Store d2:
    'leading'+18:   value('leading'+17) + sign(1)*d2 = 28 + 60 = 88

  28. Read and decode next number:
    (14) -1851 -> negative values are two differences compressed as one:
    d1 = mod(1851-1, 181) = 40
    d2 = (1851-1 - d1)/181 = 10

  29. Store d1 and d2:
    'leading'+19:   value('leading'+18) + sign(2)*d1 = 88 + 40 = 128
    'leading'+20:   value('leading'+19) + sign(3)*d2 = 128 - 10 = 118

  30. Read and decode next number:
    (15) -5531 -> negative values are two differences compressed as one:
    d1 = mod(5531-1, 181) = 100
    d2 = (5531-1 - d1)/181 = 30

  31. Store d1 and d2:
    'leading'+21:   value('leading'+20) + sign(4)*d1 = 118 + 100 = 218
    'leading'+22:   value('leading'+21) + sign(5)*d2 = 218 - 30 = 188

  32. Read and decode next number:
    (16) 20820 -> nonnegative values are three differences compressed as one:
    d1 = mod(20820, 32) = 20
    d2 = mod( [20820 - d1] / 32, 32) = 10
    d3 = (20820 - 32*d2 - d1) / (32*32) = 20

  33. Store d1, d2 and d3:
    'leading'+23:   value('leading'+22) + sign(6)*d1 = 188 + 20 = 208
    'leading'+24:   value('leading'+23) + sign(7)*d2 = 208 + 10 = 218
    'leading'+25:   value('leading'+24) + sign(8)*d3 = 218 - 20 = 198

  34. Read and decode next number:
    (17) -16371 -> negative values are two differences compressed as one:
    d1 = mod(16371-1, 181) = 80
    d2 = (16371-1 - d1)/181 = 90

  35. Store d1 and d2:
    'leading'+26:   value('leading'+20) + sign(9)*d1 = 198 - 80 = 118
    'leading'+27:   value('leading'+21) + sign(10)*d2 = 118 - 90 = 28

  36. We have now stored all 17 compressed values.
    Finally, store the trailing entries:
    'leading'+28:   790

Output

Output parameter: Output value(s): Description etc.:
mode 1 see explanation above (item 16)
ldat 29 no. of elements in the original (decompessed) 'idata()', including leading and trailing elements
trailing 1 no. of trailing elements in 'idata()'
idata
Element # 12345 67
Value 98828385822 2826
Element # 12345 678910
Value 98828385822 28268128218
Element # 1112131415 1617181920
Value - 32767- 32767- 32767 - 32767- 32767 - 32767822888128
Element # 2122232425 26272829 
Value 118218188208218 198188178790 
original array; after decompression (leading entries, field, trailing entries)
factors
# Value
n = 1, 17 20, 21, ..., 216
factors used in the construction of the original (decompressed) set of values