function [messageId] = findMsgNSTB(fid);
%---------------------------------------------------------
% find sync in NSTB formatted data
% Ju-Yong Do,  Jan 15, 2009
%---------------------------------------------------------
% input  : NSTB file indicator
% output : msgID, put fid to the beginning of message (after framesync)
%=========================================================
%=========================================================
framesync   = uint8([250; 206; 222; 173]); %pattern of frame sync pulse (0xFACEDEAD)

%=========================================================
% find message location
while(1)    
    % find header of message (starts with sync)
    messageId=-1;    %default: no message found  
    while(1)
        if (feof(fid)), return; end; %exit if End of file
        [data, count] = fread(fid, 4, '*uint8'); %read 4 bytes and see if it's synch
        if (count < 4), return; end; %exit if insufficient data left. 

        % break if framesync and continue to search if not.
        if isequal(data, framesync), break; end; 
        fseek(fid, -3, 'cof');            
    end

    % check message ID and call corresponding message parsing routine
    fseek(fid, 6, 'cof');   %skip gpswk, tow
    messageId = fread(fid, 1, '*uint8');
    return;
end
%=========================================================
%=========================================================