% check for good data

% ship buoy specified



ship='24';

if length(a)>=4;

  if a(5)~='/'&floor(hex2dec(a(14:15))/64)==1&hex2dec(a(16:17))<64&length(a)>37;



%   identify buoy

    disp(' ');

    if a(12)=='1';disp('200 Buoy');colval='g';

    elseif a(12)=='E';disp('6 Buoy');colval='m';

    elseif a(11:12)=='E2';disp('20 Buoy  ');colval='g';

    elseif a(12)=='A';disp('234 Buoy');colval='m';

    elseif a(11:12)=='24';disp('Deck Buoy 34');colval='y';

    elseif a(12)=='7';disp('PillBox Buoy  ');colval='c';

    elseif a(11:12)=='DF';  disp('Buoy 1');colval='b';

    end;



%   parse time, lat, lon, and temperature

    time=hex2dec(a(20:27));

    stevetime=((time-86400*floor(time/86400))/3600);

      minit=round((stevetime-fix(stevetime))*60);

      hour=fix(stevetime);

    latm1=(hex2dec(a(28:29))-192)*65535+hex2dec(a(30:31))*256+...

      hex2dec(a(32:33))-540001;

    latd=floor(latm1/6000);

    latm=(latm1-latd*6000)/100;

    lat=latd+latm/60;

    lonm=(hex2dec(a(34:35))-192)*65535+hex2dec(a(36:37))*256+...

        hex2dec(a(38:39))-1080001;

    lond=ceil(lonm/6000);

    lonm=(lonm-lond*6000)/100;

    lon=lond+lonm/60;

    if length(a)>=43;

     tmpc=(hex2dec(a(40:41))*256+hex2dec(a(42:43))-49152)/100;

    end;



%   calculate range & bearing to ship

    if a(11:12)==ship;

       rx=lon; ry=lat;

       if exist('hs')==1;set(hs,'visible','off');end;

       set(hs,'visible','off');

       hs=plot(rx,ry,'r.','markersize',40);

       plot(rx,ry,'r', 'markersize',20);      

    else;

       [rng,bear]=dist(ry,rx,lat,lon);

    end;





%   display results

%    if rng/1.85<15;

      disp(['  Lat:  ',num2str(latd),' ',num2str(latm)]);

      disp(['  Lon:  ',num2str(-1*lond),' ',num2str(-1*lonm)]);

      disp(['  Temp: ',num2str(tmpc)]);

      disp(['  Time   ',num2str(hour),':',num2str(minit),' GMT']);

      if a(11:12)~='24'|a(12)=='E';

      disp(['  Range:  ',num2str(rng/1.85),' nautical miles']);

      disp(['  Bearing:  ',num2str(bear),' true']);

      end;







%     plot

      plot(lon,lat,'.','color',colval,'markersize',20)

 

%     change axis if necessary

      if lat<mila&lat<40;mila=lat;end;

      if lat>mala&lat>42;mala=lat;end;

      if lon<milo&lon<-70;milo=lon;end;

      if lon>malo&lon>-66;malo=lon;end;

%      

%     axis([milo malo mila mala]);

     axis([-67.8 -67.65 40.93 41.1])

      hold on;

%    else;

%      disp('  poor fix ... probably too far away');

%    end;  

  end;

end;