disp(['read_hed_day_', cruise, '_', year]);
% Inputs data from ASCII data files
%  Note:  hhh=hour

st2=[];jax1=1;jd_hed=[];jd1=[];

for jam=hhh:hhh
    if jam<10,
       hr=['0',num2str(jam)];
    else
       hr=num2str(jam);
    end;

    if ddd<10,
       jd=['00',num2str(ddd)];
    elseif ddd<100,
       jd=['0',num2str(ddd)];
    else
       jd=num2str(ddd);
    end;
    nmang='picth';
    dfl=[way_raw_data_flux, 'day',jd,'\hed0' year(3:4) jd hr '_raw.txt'];
    disp(dfl)
    flist=fopen(dfl);
    if flist>0
        
    %     temp =textscan(flist,'%f %6c %6c %c %f %c %f %c %f %f %f %f %4c %*[^\n]','delimiter', ',', 'headerlines', 1,  'emptyvalue', NaN);
        temp =textscan(flist,'%2f%2f%3f %5c %3c %f %f %f %f %4c %*[^\n]','delimiter', ', ', 'headerlines', 1,  'emptyvalue', NaN);
         %%%%  check for pitch or roll
         xy=temp{1,8};
        if ~isnan(xy(1));
            stx=[temp{1,1}';temp{1,2}';temp{1,3}';(temp{1,6}');(temp{1,7}');(temp{1,8}')];
        else
              stx=[temp{1,1}';temp{1,2}';temp{1,3}';(temp{1,6}');(temp{1,7}');(temp{1,9}')];
              nmang='roll';
        end;
        stx(2:8,any(isnan(stx),1))=NaN;      %put NaN into any rows containing NaNs (to remove bad lines, gap...), except JD

        [nr1,nl1]=size(stx);
        st2(:,jax1:jax1+nl1-1)=stx;
        jd1=ddd + (jam+(st2(1,jax1:jax1+nl1-1)+(st2(2,jax1:jax1+nl1-1)+st2(3,jax1:jax1+nl1-1)/1000)/60)/60)/24;
        jd_hed = [jd_hed jd1];
        jax1=jax1+nl1;
    
    else
        disp('file not found')
    end;
end;
time_hed=st2(1,:);
headx=st2(5,:); 
pitchx=st2(6,:); 

jdx=jd_hed(:);jd_hed=[];jd_hed=jdx;
% jd_gps=ddd+((st2(1,:)-st2(1,1))/1000/60/60)/24;
figure;plot(jd_hed,headx,'.');title(['JD',jd,' Hr',hr,' UTC  Heading from PSD GPS. ', cruise, year]);xlabel('Julian Day ');ylabel('Heading (deg)');  

ii=find(isnan(pitchx));pitchx(ii)=nanmean(pitchx);
%lowpass filter time series at 2 Hz for signal sampled at 10 Hz

wp=[.01 3]/5;ws= [.003 4]/5;rp=2;rs=8;
wp=[.02/5 2/5];ws= [.01/5 3/5];rp=3;rs=15;
[n,wmn]=cheb1ord(wp,ws,rp,rs);
[b,a]=cheby1(n,rp,wmn);
yxp=filter(b,a,pitchx-mean(pitchx));%roll rate rad/sec
figure;plot(jd_hed,pitchx,'.',jd_hed,yxp);title(['JD',jd,' Hr',hr,' UTC ' nmang ' from PSD GPS. ', cruise, year]);xlabel('Julian Day');ylabel([nmang ' (deg)']);  
