disp('read P3navdata');
% vkonsa=[];%ones(10,36000);
P3nav=[];

% 0903332 IWG1_NAMES,TIME,LATref,LONref,ALTref,GPS_GeoidHt.1,ALTPAft.d,AltRaft.1,GS.d,TAS.d,IAS.d,MACH.d,GSZref,THDGref,TRK.d,DA.d,PITCHref,ROLLref,SA.d,AA.d,TA.d,TD.c,TTMref,PS.c,PQ.c,PCAB.1,WS.d,WD.d,UWZ.d,SolarZenith,SunElevAc,SunAzGnd,SunAzAc,FLID,MISSIONID,STORMID,MDSHOUR.1,MDSMINUTE.1,MDSSECOND.1,AccZfilterI-GPS.1,AccZfilterI-GPS.2,ACCZref,AccZI-GPS.1,AccZI-GPS.2,ALTGA.d,AltGPS.1,AltGPS.2,AltGPS.3,AltI-GPS.1,AltI-GPS.2,ALTPA.d,AltRa.1,AltRa.2,AltRa1.c,AltRa2.c,AXBT.1,AXBT.2,AXBT.3,COURSEcorr.d,DV.d,GPS_AltErr.1,GPS_Quality.1,GSXref,GSYref,HT.d,HUM_ABS.d,HUM_REL.d,IASkt.d,LicHum_Abs.1,LicCO2D.1,LicTDM.1,LicTTMi.1,LicTTMo.1,LicPT.1,LatGPS.1,LatGPS.2,LatGPS.3,LatI-GPS.1,LatI-GPS.2,LonGPS.1,LonGPS.2,LonGPS.3,LonI-GPS.1,LonI-GPS.2,LWC.1,MR.d,PDALPHA.1,PDALPHA.2,PDBETA.1,PDBETA.2,PitchI.1,PitchI.2,PitchI-GPS.1,PitchI-GPS.2,PitchI-GPS.3,PitchI-GPS.4,PitchRate.1,PQALPHA.1,PQBETA.1,PQM.2,PQM.3,PQM.4,PQM.1,PSM.2,PSM.1,PSURF.d,PTM.1,RollI.1,RollI.2,RollI-GPS.1,RollI-GPS.2,RollI-GPS.3,RollI-GPS.4,SfmrRainRate.R,SfmrWS.R,SST.1,TASkt.d,TDM.1,TDM.2,TDM.3,THdgI-GPS.1,THdgI-GPS.2,THdgI-GPS.3,THdgI-GPS.4,THETA.d,THETAE.d,TRadD.1,TRadS.1,TRadU.1,TRKdesired.d,TTM.1,TTM.2,TTM.3,TVIRT.d
% str2reject={'IWG1_NAMES','TIME','LATref','LONref','ALTref','GPS_GeoidHt.1','ALTPAft.d','AltRaft.1','GS.d','TAS.d','IAS.d','MACH.d','GSZref','THDGref','TRK.d','DA.d','PITCHref','ROLLref','SA.d','AA.d','TA.d','TD.c','TTMref','PS.c','PQ.c','PCAB.1','WS.d','WD.d','UWZ.d','SolarZenith','SunElevAc','SunAzGnd','SunAzAc','FLID','MISSIONID','STORMID','MDSHOUR.1','MDSMINUTE.1','MDSSECOND.1','AccZfilterI-GPS.1','AccZfilterI-GPS.2','ACCZref','AccZI-GPS.1','AccZI-GPS.2','ALTGA.d','AltGPS.1','AltGPS.2','AltGPS.3','AltI-GPS.1','AltI-GPS.2','ALTPA.d','AltRa.1','AltRa.2','AltRa1.c','AltRa2.c','AXBT.1','AXBT.2','AXBT.3','COURSEcorr.d','DV.d','GPS_AltErr.1','GPS_Quality.1','GSXref','GSYref','HT.d','HUM_ABS.d','HUM_REL.d','IASkt.d','LicHum_Abs.1','LicCO2D.1','LicTDM.1','LicTTMi.1','LicTTMo.1','LicPT.1','LatGPS.1','LatGPS.2','LatGPS.3','LatI-GPS.1','LatI-GPS.2','LonGPS.1','LonGPS.2','LonGPS.3','LonI-GPS.1','LonI-GPS.2','LWC.1','MR.d','PDALPHA.1','PDALPHA.2','PDBETA.1','PDBETA.2','PitchI.1','PitchI.2','PitchI-GPS.1','PitchI-GPS.2','PitchI-GPS.3','PitchI-GPS.4','PitchRate.1','PQALPHA.1','PQBETA.1','PQM.2','PQM.3','PQM.4','PQM.1','PSM.2','PSM.1','PSURF.d','PTM.1','RollI.1','RollI.2','RollI-GPS.1','RollI-GPS.2','RollI-GPS.3','RollI-GPS.4','SfmrRainRate.R','SfmrWS.R','SST.1','TASkt.d','TDM.1','TDM.2','TDM.3','THdgI-GPS.1','THdgI-GPS.2','THdgI-GPS.3','THdgI-GPS.4','THETA.d','THETAE.d','TRadD.1','TRadS.1','TRadU.1','TRKdesired.d','TTM.1','TTM.2','TTM.3','TVIRT.d'};
%                            10                                  15                             20                                25                            30                          35                                     40                                      45
% 
str2reject='_NAMES,TIME,LATref,LONref,ALTref,GPS_GeoidHt.1,ALTPAft.d,AltRaft.1,GS.d,TAS.d,IAS.d,MACH.d,GSZref,THDGref,TRK.d,DA.d,PITCHref,ROLLref,SA.d,AA.d,TA.d,TD.c,TTMref,PS.c,PQ.c,PCAB.1,WS.d,WD.d,UWZ.d,SolarZenith,SunElevAc,SunAzGnd,SunAzAc,FLID,MISSIONID,STORMID,MDSHOUR.1,MDSMINUTE.1,MDSSECOND.1,AccZfilterI-GPS.1,AccZfilterI-GPS.2,ACCZref,AccZI-GPS.1,AccZI-GPS.2,ALTGA.d,AltGPS.1,AltGPS.2,AltGPS.3,AltI-GPS.1,AltI-GPS.2,ALTPA.d,AltRa.1,AltRa.2,AltRa1.c,AltRa2.c,AXBT.1,AXBT.2,AXBT.3,COURSEcorr.d,DV.d,GPS_AltErr.1,GPS_Quality.1,GSXref,GSYref,HT.d,HUM_ABS.d,HUM_REL.d,IASkt.d,LicHum_Abs.1,LicCO2D.1,LicTDM.1,LicTTMi.1,LicTTMo.1,LicPT.1,LatGPS.1,LatGPS.2,LatGPS.3,LatI-GPS.1,LatI-GPS.2,LonGPS.1,LonGPS.2,LonGPS.3,LonI-GPS.1,LonI-GPS.2,LWC.1,MR.d,PDALPHA.1,PDALPHA.2,PDBETA.1,PDBETA.2,PitchI.1,PitchI.2,PitchI-GPS.1,PitchI-GPS.2,PitchI-GPS.3,PitchI-GPS.4,PitchRate.1,PQALPHA.1,PQBETA.1,PQM.2,PQM.3,PQM.4,PQM.1,PSM.2,PSM.1,PSURF.d,PTM.1,RollI.1,RollI.2,RollI-GPS.1,RollI-GPS.2,RollI-GPS.3,RollI-GPS.4,SfmrRainRate.R,SfmrWS.R,SST.1,TASkt.d,TDM.1,TDM.2,TDM.3,THdgI-GPS.1,THdgI-GPS.2,THdgI-GPS.3,THdgI-GPS.4,THETA.d,THETAE.d,TRadD.1,TRadS.1,TRadU.1,TRKdesired.d,TTM.1,TTM.2,TTM.3,TVIRT.d';
dr=dir([way_raw_motion_wband 'p3' yyyy(2:end) ddds hr '_raw.txt']);
filnx=dr.name
FID = fopen([way_raw_motion_wband filnx]','r');
if FID>0
    while ~feof(FID)
        try
            temp=textscan(FID,'%2f%2f%3f %*4c %4f%2f%2f%*c%2f%2f%2f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %*8f%*c%*f %*11c %*4c %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %*[^\n]','delimiter', ',', 'headerlines', 1,'treatAsEmpty',str2reject, 'emptyvalue', NaN);
            P3nav=[P3nav cell2mat(temp)'];
        catch
            [l,c]=size(temp{1,end});
            for ll=1:length(temp)
                 if length(temp{1,ll})~=l
                     temp{1,ll}(l+1)=[];
                 end;
            end;
            if isempty(temp{1,1}); continue; end
            P3nav=[P3nav cell2mat(temp)'];
        end; %end try    
    end     %end while 
else
    P3nav=ones(1,1)*NaN;
end %end if IFD>0  
clear FID;

%fix some weird points
ii=find(P3nav(4,:)~=str2num(yyyy));  P3nav(:,ii)=[];



P3_doy=datenum(P3nav(4,:),P3nav(5,:),P3nav(6,:),P3nav(7,:),P3nav(8,:),P3nav(9,:))-datenum(P3nav(4,:)-1,12,31);
P3_hh=P3nav(7,:)+P3nav(8,:)/60+P3nav(9,:)/3600;
P3_lat=P3nav(10,:);
P3_lon=P3nav(11,:);
P3_altref=P3nav(12,:);
P3_pitchref=P3nav(24,:);
P3_rollref=P3nav(25,:);
P3_head=P3nav(22,:);
P3_Windspeed=P3nav(34,:);
P3_WindDir=P3nav(35,:);



%clear P3nav
%################## Track map limits #########################################################
Lonmin=-85;
Lonmax=-80; 
Latmin=25;
Latmax=30;

figure(3);clf;
subplot(2,2,1:2)
%     plot(P3_lon,P3_lat);xlabel('Lat');ylabel('Lon');
%     grid
    eval(['map_P3','(P3_lon,P3_lat,cruise,[Lonmin Lonmax Latmin Latmax])'])
    title(sprintf('%s (%04i-%02i-%02i, DOY%03i).  P3 navigation data',cruise,Vdate(1),Vdate(2),Vdate(3),ddd),'FontWeight','Bold','Interpreter','none')

subplot(2,2,3:4)
     plot(P3_doy,P3_altref,'.');
     xlabel('Hour (UTC)');ylabel('Altitude ref'); xlim([P3_doy(1) P3_doy(end)]); 
     datetick('x','HH:MM','keepticks');
     grid
     orient tall
     annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
if prtit_hr; print(graphdevice,[way_raw_images_wband cruise '_P3nav_' sprintf('%04i_%02i_%02i_%03i_%02i',Vdate(1),Vdate(2),Vdate(3),ddd,jam) graphformat]);end

