function str2bytarr,str

   ss = size(str)
   if ss(ss(0)+1) NE 8 then message,'The input is not a structure ... use byte'

   array = 0b
   nbytes = [0,1,2,4,4,8,8,1,-1]  ; Number of bytes in the various data types

   for i=0L,n_tags(str)-1 do begin
      ss = size(str.(i))
      type = ss(ss(0)+1)

      CASE 1 OF
         type EQ 0: message,/info,'Structure tag '+strcompress(string(i))+ $
                            ' is undefined'
         type LE 6: array=[array,byte(str.(i),0,ss(ss(0)+2)*nbytes(type))]
         type EQ 7: for j=0L,ss(ss(0)+2)-1 do array=[array,byte((str.(i))(j))]
         type EQ 8: array=[array,str2bytarr(str.(i))]
         else: message,'Undefined type code'
      endcase
   endfor

   return,array(1:n_elements(array)-1L)

en