function [sqminfo] = parseNSTBsqminfo(fid);
%---------------------------------------------------------
% parse NSTB message type 51 (SQMInfo)
% Ju-Yong Do,  Jan 22, 2009
%---------------------------------------------------------
% input  : NSTB file indicator
% output : sqminfo message in "sqminfo"
%=========================================================
%=========================================================
global rx option

%read header
receiverId      = fread(fid, 1, 'uint16');      
gpsweek         = fread(fid, 1, 'uint16');
sqminfo.tow     = fread(fid, 1, 'uint32')*1e-3; %time of validity in time of week (ms->sec)
sqminfo.rxconfig= fread(fid, 1, '*uint8');      %receiver configuration 0=narrow, 1=ultranarrow
sqminfo.numch   = fread(fid, 1, '*uint8');      %number of channels

%=========================================================
%read sqminfo message
bodyLen = 0;    %length of body text
for i=1:sqminfo.numch
    sqminfo.ch(i).id        = fread(fid, 1, '*uint8');      %channel number
    sqminfo.ch(i).accumtime = fread(fid, 1, 'uint32')*1e-3; %accumulation time (ms->sec)
    sqminfo.ch(i).numintch  = fread(fid, 1, '*uint8');      %number of internal channels for this channel (<=2) 
    
    for j=1:sqminfo.ch(i).numintch        
        sqminfo.ch(i).intch(j).a1xval   = fread(fid, 1, 'int8');    %correlator spacing in C/A chips from punctual for accumulation 1
        sqminfo.ch(i).intch(j).a2xval   = fread(fid, 1, 'int8');    %correlator spacing in C/A chips from punctual for accumulation 2
        sqminfo.ch(i).intch(j).a3xval   = fread(fid, 1, 'int8');    %correlator spacing in C/A chips from punctual for accumulation 3
        sqminfo.ch(i).intch(j).a4xval   = fread(fid, 1, 'int8');    %correlator spacing in C/A chips from punctual for accumulation 4
        sqminfo.ch(i).intch(j).a5xval   = fread(fid, 1, 'int8');    %correlator spacing in C/A chips from punctual for accumulation 5                
        sqminfo.ch(i).intch(j).statusa  = fread(fid, 1, '*uint8');  %status A
        sqminfo.ch(i).intch(j).statusb  = fread(fid, 1, '*uint8');  %status B
    end    
    bodyLen = bodyLen + (6 + double(sqminfo.ch(i).numintch)*7);
end

%stack up what's collected
rx.aiding.sqminfo        = [rx.aiding.sqminfo sqminfo];

%=========================================================
% CRC test for sanity check (done after parsing all because message size is unknown till now)
crcTestNSTB(fid, 11, bodyLen, 2); %(fid,headLen,bodyLen,tailLen)

if option.plot,             
    disp('=======MESSAGE 51 SQM INFO===============================');
    disp(['tow= ',num2str(sqminfo.tow),' sec']); 
end

return
%=========================================================
%=========================================================
