;+NAME/ONE LINE DESCRIPTION OF ROUTINE:
;    RDBACKORBIT reads seawifs back-orbit state of health data in a byte
;    array.
;
;-----------------------------------------------------------------
; rdbackorbit - reads seawifs back-orbit SOH data into byte array
;
; Synopsis:
;     msgs = rdbackorbit( file, indx )
;
;     file	- input backorbit data filename
;     msgs	- SOH messages in S/C message format, stored as
;		  byte array 298 x n.
;     indx	- optional output list of messages source addresses
;
;
; Description:
;
;     The input file is assumed to be a stream of S/C messages.  
;     Back-orbit files of this type are generated by the seawifs
;     mission ops programs neb2raw or hdlc2raw.
;
; Written By:
;     B. A. Franz, General Sciences Corp., 7/97
;
;
;-----------------------------------------------------------------

function rdbackorbit,file,indx

    msglen = 298	; Max message size
    
    openr,/get_lun,lun,file
    f = fstat(lun)

    ;
    ; Create association
    ;
    a = assoc(lun, bytarr(f.size))
    r = a(0)
    
    ;
    ; Create fixed-length storage
    ;
    nmax = f.size/48 + 1
    msg  = bytarr(msglen, nmax)
    indx = intarr(nmax)

    ;
    ; Step through logger messages, save any SOH subsystem msgs
    ;
    p = 0L
    i = 0L
    while (p lt f.size) do begin

        flen = fix(r(p:p+1),0)
        addr = fix(r(p+14:p+15),0)
        indx(i) = addr
        msg(0:flen-1,i) = r(p:p+flen-1)
;        print,flen,fix(msg(0:1),0),addr
        i = i+1
        p = p+flen

    endwhile

    msg  = msg(*,0:i-1)
    indx = indx(0:i-1)

    return, msg

end

