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

%read header
receiverId      = fread(fid, 1, 'uint16');
gpsweek         = fread(fid, 1, 'uint16');
almanac.tow     = fread(fid, 1, 'uint32')*1e-3; %time of validity in time of week (ms->sec)
almanac.dwn     = fread(fid, 1, 'uint8');       %difference b.t. GPS week and week of almanac (weeks)
almanac.toa     = fread(fid, 1, 'uint8')*2^12;  %time of almanac (sec)
almanac.numtx   = fread(fid, 1, '*uint8');      %number of satellites in the record

%=========================================================
%read almanac message
for i=1:almanac.numtx    
    almanac.prn(i)     = fread(fid, 1, '*uint8');          %prn number
    almanac.e(i)       = fread(fid, 1, 'uint16')*2^-21;    %eccentricity
    almanac.di(i)      = fread(fid, 1, 'int16')*pi*2^-19;  %delta inclination from 0.3 (rad)
    almanac.odot(i)    = fread(fid, 1, 'int16')*pi*2^-38;  %rate of right ascension (rad/s)
    almanac.sqrta(i)   = fread(fid, 1, 'uint32')*2^-11;    %sqrt(semi-major axis)
    almanac.omg0(i)    = fread(fid, 1, 'int32')*pi*2^-23;  %longitude of ascending node (rad)
    almanac.w(i)       = fread(fid, 1, 'int32')*pi*2^-23;  %argument of perigee (rad)
    almanac.m0(i)      = fread(fid, 1, 'int32')*pi*2^-23;  %mean anomaly at ref time (rad)
    almanac.af0(i)     = fread(fid, 1, 'int16')*2^-20;     %clk correction coef (sec)
    almanac.af1(i)     = fread(fid, 1, 'int16')*2^-38;     %clk correction coef (s/s)
    almanac.health(i)  = fread(fid, 1, '*uint8');          %satellite health    
end

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

%=========================================================
% CRC test for sanity check
crcTestNSTB(fid, 12, 28*double(almanac.numtx), 2); %(fid,headLen,bodyLen,tailLen)

if option.plot,         
    disp('=======MESSAGE 30 ALMANAC====================================');
    disp(['tow= ',num2str(almanac.tow),' sec']); 
end

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