function Scale2Levels, A, L @compile_opt.pro ; On error, return to caller ;+ ; NAME: ; Scale2Levels ; PURPOSE: ; Scale an array to byte array with value 0,..,n using n different levels ; CATEGORY: ; Number strangling ; CALLING SEQUENCE: ; B = Scale2Levels(A,L) ; INPUTS: ; A array numerical array of any type or dimension ; L array[n] used to scale input array A ; OPTIONAL INPUT PARAMETERS: ; OUTPUTS: ; B byte array contains only the n+1 values 0,..,n ; (not all need to be present) ; OPTIONAL OUTPUT PARAMETERS: ; CALLS: ; COMMON BLOCKS: ; SIDE EFFECTS: ; RESTRICTIONS: ; PROCEDURE: ; Values in A where A < L[0] are set to 0 ; Values in A where L[i-1] <= A < L[i] are set to i (i=1,n-1) ; Values in A where A >= L[n-1] are set to n ; MODIFICATION HISTORY: ; Paul Hick (UCSD/CASS, pphick@ucsd.edu) ;- AL = byte(0B*A) ; Initialize AL (byte array) N = n_elements(L) if N eq 0 then message, 'No levels specified for i=1,N-1 do begin d = where(L[i-1] le A and A lt L[i], m) if m gt 0 then AL[d] = i endfor d = where(L[N-1] le A, m) if m gt 0 then AL[d] = N return, AL & end