;parsebytes by Eli Rotenberg

;Modifications:
; (14nov00 cgz) Replaced call of CHR function by explicit STRING(BYTE())
; (15nov00 cgz) Replaced call of DIMEN function by explicit (SIZE(var))(index+1)

function parsebytes, btarr, num
;parses byte array --> array of floating point numbers
;assumes tab or space delimited numbers
  on_error,2
;  nmax=dimen(btarr,0)
  nmax=(size(btarr))(1)
  btarr2=[btarr,32B]
  pos=long(0)
  ;help,nmax
  fa=fltarr(num)
  for i=0,num-1 do begin
    ;skip initial white space
    while ((btarr(pos) eq 32B) or (btarr(pos) eq 9B)) and (pos le nmax) do pos=pos+1
    
    ;accumulate characters to string
    s=''
    while (btarr2(pos) ne 32B ) and (btarr2(pos) ne 09B) and (pos lt nmax)  do begin
;      s=s+chr(btarr2(pos)) 
      s=s+string(byte(btarr2(pos))) 
      pos=pos+1
    endwhile
    fa(i)=float(s)
    ;print,i,fa(i),pos
  endfor
  return,fa
end
    
    