Site Map

Unpacking Out of Range Parameters

The parameters outofrange355, outofrange532, and outofrange064 are packed byte arrays which define the underflow and overflow elements in the Level 1 profiles.

Unpacking Directions:

  1. Create 3000 element byte arrays from the 375 element packed byte arrays (outofrange355, outofrange532, and outofrange064) by repeating each packed byte element 8 times.

    Example:

    Assume outofrange355 is a 3 element byte array: [228, 0, 126].
    Create a new byte array, new355:

    [228,228,228,228,228,228,228,228, 0, 0, 0, 0, 0, 0, 0, 0, 126,126,126,126,126,126,126,126]

  2. Create a byte array with 3000 (3 X 375) elements that repeat the following values 375 times:

    128, 64, 32, 16, 8, 4, 2, 1

    These values are defined as 2 to the power of 7, 6, 5, 4, 3, 2, 1, 0.

    Example:

    As above, outofrange355 is a 3 element byte array.

    Create a 24 (3 X 8) element byte array, andarray355:

    [128,64,32,16,8,4,2,1,128,64,32,16,8,4,2,1,128,64,32,16,8,4,2,1]

  3. Perform the Boolean "and" operation for each element of the two newly created byte arrays.

    unpacked355 = new355 "and" andarray355

    Each bit in x1 Each bit in x2 Corresponding bit in result of x1 and x2
    0 0 0
    0 1 0
    1 0 0
    1 1 1

    Example:

    Recall:

    new355 = [228,228,228,228,228,228,228,228,0,0,0,0,0,0,0,0,126,126,126,126,126,126,126,126]
    andarray355 = [128,64,32,16,8,4,2,1,128,64,32,16,8,4,2,1,128,64,32,16,8,4,2,1]

    228 in binary is 11100100
    128 in binary is 10000000
    228 and 128 = 10000000 = 128

    228 in binary is 11100100
    64 in binary is 01000000
    228 and 64 = 01000000 = 64

    228 in binary is 11100100
    32 in binary is 00100000
    228 and 32 = 00100000 = 32

    228 in binary is 11100100
    16 in binary is 00010000
    228 and 16 = 00000000 = 0

    228 in binary is 11100100
    8 in binary is 00001000
    228 and 8 = 00000000 = 0

    228 in binary is 11100100
    4 in binary is 00000100
    228 and 4 = 00000100 = 4

    228 in binary is 11100100
    2 in binary is 00000010
    228 and 2 = 00000000 = 0

    228 in binary is 11100100
    1 in binary is 00000001
    228 and 1 = 00000000 = 0

    The "and" operation for "0" and any value will be "0". The results of the "and" operation for the next 8 elements will result in 0.

    126 in binary is 01111110
    128 in binary is 10000000
    126 and 128 = 00000000 = 0

    228 in binary is 01111110
    64 in binary is 01000000
    126 and 64 = 01000000 = 64

    228 in binary is 01111110
    32 in binary is 00100000
    126 and 32 = 00100000 = 32

    228 in binary is 01111110
    16 in binary is 00010000
    126 and 16 = 00010000 = 16

    228 in binary is 01111110
    8 in binary is 00001000
    126 and 8 = 00001000 = 8

    228 in binary is 01111110
    4 in binary is 00000100
    126 and 4 = 00000100 = 4

    228 in binary is 01111110
    2 in binary is 00000010
    126 and 2 = 00000010 = 2

    228 in binary is 01111110
    1 in binary is 00000001
    126 and 1 = 00000000 = 0

    The result of the "and" operation is the array:

    unpackedarr355 = [128,64,32, 0,0,4,0,0, 0, 0, 0, 0,0,0,0,0, 0,64,32,16,8,4,2,0]

  4. Redefine any values greater than 1 to be 1 in the newly created unpacked array. If an element in the unpacked array is 1, then the corresponding element in the Level 1 profile array contained an out of range condition.

    Example:

    The final unpacked array is defined as follows:

    unpackedarr355 = [1,1,1,0,0,1,0,0, 0,0,0,0,0,0,0,0, 0,1,1,1,1,1,1,0]

An IDL procedure to unpack outofrange355, outofrange532, and outofrange064 follows:

pro init_p
common unpackcommon,andarr,outarr

; Initialize unpacking arrays, used to unpack outofrange355,
; outofrange532, nxs.outofrange064.

initunpack

end

function unpackbytes,thebytearr
common unpackcommon,andarr,outarr

;  This function takes an array of 375 bytes and unpacks 
;  it into an array of 3000 bytes.
;
;  Input: thebytearr is the packed byte array that will be unpacked.
;  Output: outarr is the unpacked array.
;
; andarr is defined and documented in pro initunpack

unpacksize = 3000

;  rebin will take the 375 element array, thebytearr, and 
;  and create a new 3000 element array by repeating each
;  thebytearr element 8 times.
;
;  example, want to create a 24 element array from a 3 
;           element array.
;
;   Let thebytearr be a 3 element array: [228, 0, 126]
;
;   rebin will create [228,228,228,228,228,228,228,228,           
;                        0,  0,  0,  0,  0,  0,  0,  0,           
;                      126,126,126,126,126,126,126,126]
;
;  The statement:  
;
;     (rebin(thebytearr,unpacksize,/sample) and andarr(0:unpacksize-1))
;
;  will "and" the rebinned array with andarr to determine which
;  bits in each packed word have been set to 1.
;
;  continue example:
; 
;   Let andarr be a 24 element array: 
;
;     [128,64,32,16,8,4,2,1,128,64,32,16,8,4,2,1,128,64,32,16,8,4,2,1]
;
;   The result of the "and" operation is the array:
;
;     [128,64,32,0,0,4,0,0,0,0,0,0,0,0,0,0,0,64,32,16,8,4,2,0]
;
;   The minimum operator (<) returns the smaller value, either 1b or
;   result value.
;
;   The final unpacked array is defined as follows:
;
;    unpackedarr = [1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0]
;
;   Therefore, out of range occurred at locations that equal 1.

unpackedarr = 1b < $
  (rebin(thebytearr,unpacksize,/sample) and andarr(0:unpacksize-1))

;355, 532, 1064
outarr(*) = unpackedarr(0:2999)

return,outarr
end

pro initunpack
common unpackcommon,andarr,outarr
  outarr = bytarr(3000)
  temparr = reverse(bindgen(3000))
  andarr = byte(2^(temparr mod 8))
end