;+ ; ; @file_comments ; Inverse function of the binary function => given a ; input array of 0/1, return its corresponding byte/integer/long ; representation ; ; @categories ; ; @param BINNUMB {in}{required} ; Must be a binary type array containing only 0 and 1. ; According to binary outputs, binnum array must have the ; following dimensions values: (8, t, d1, d2...) ; t gives the output type: t = 1 -> byte ; t = 2 -> integer ; t = 4 -> long ; ; (d1, d2...) are the output dimensions ; ; ; @returns ; A byte/integer/long array with (d1, d2...) dimensions ; ; @restrictions ; The binary number can represent only byte/integer/long ; ; @examples ; ; IDL> a=indgen(5) ; IDL> b=binary(a) ; IDL> help, b ; B BYTE = Array[8, 2, 5] ; IDL> print, b ; 0 0 0 0 0 0 0 0 ; 0 0 0 0 0 0 0 0 ; ; 0 0 0 0 0 0 0 0 ; 0 0 0 0 0 0 0 1 ; ; 0 0 0 0 0 0 0 0 ; 0 0 0 0 0 0 1 0 ; ; 0 0 0 0 0 0 0 0 ; 0 0 0 0 0 0 1 1 ; ; 0 0 0 0 0 0 0 0 ; 0 0 0 0 0 1 0 0 ; IDL> help, inverse_binary(b) ; INT = Array[5] ; IDL> print, inverse_binary(b) ; 0 1 2 3 4 ; ; @history ; Sebastien Masson (smasson\@jamstec.go.jp) ; July 2004 ; ; @version ; $Id$ ; ;- ; FUNCTION inverse_binary, binnumb ; compile_opt idl2, strictarrsubs ; s = size(binnumb, /dimensions) IF n_elements(s) EQ 1 THEN numbofbit = 8 ELSE numbofbit = 8*s[1] nvalues = n_elements(binnumb)/numbofbit bn = reform(long(binnumb), numbofbit, nvalues) ; CASE numbofbit OF 8:res = byte(total(temporary(bn)*2b^reverse(indgen(numbofbit)#replicate(1b, nvalues), 1), 1)) 16:res = fix(total(temporary(bn)*2^reverse(indgen(numbofbit)#replicate(1, nvalues), 1), 1, /double)) 32:res = long(total(temporary(bn)*2L^reverse(indgen(numbofbit)#replicate(1L, nvalues), 1), 1, /double)) ENDCASE ; CASE n_elements(s) OF 1:res = res[0] 2:res = res[0] 3: ELSE:res = reform(res, s[2:n_elements(s)-1], /over) ENDCASE ; return, res end