disp('read_sonic') 
fclose('all');
%ICEALOT 2009. Running at 10Hz
%
clear

st1=[];
st2=[];
st3=[];
jds = '88';
%if 0 % DEW 5/15/2007
for jam=0:0     %6:6,						%cycle thru 24 hourly stats files
    clear sonraw jade sonraw_dep st1 st2 st3 stxt np ict
    e= 'Y:\day088\son00808800_raw.txt'
    %03/20/2008 00:00 Gill-Sonic Anemometer  (SN: 070514)
    %0000039 B,+001.16,+000.02,-000.09,M,+014.66,00,2D
    flist=fopen(e,'r');
        disp(['Reading Sonic file in rdson  ',e])
        dmp=fgets(flist);			%read 1st header line
        YY = str2num(dmp(7:10));
        MM = str2num(dmp(1:2));
        DD = str2num(dmp(4:5));
        hh = str2num(dmp(12:13));
        ict = 0;
        while feof(flist)==0,
            % for p = 1:100
            dtmp=fgetl(flist);
            if length(dtmp) == 51
            ict = ict + 1;
            tim = dtmp(1:8);
            mm = str2num(tim(:,1:2));
            ss = str2num(tim(:,3:8))/1000;
            %calculate year day
            yd=datenum(YY,MM,DD,hh,0,0)-datenum(YY-1,12,31);
            jdn(ict,1) = yd + (((mm+(ss/60))/60))/24;
            st1(1,ict) = jdn(ict,1);
            % despike data  DEW 5/6/2007 fm CWK
            st1(2,ict) = str2num(dtmp(12:18));  %  U
            st1(3,ict) = str2num(dtmp(20:26));  %  V
            st1(4,ict) = str2num(dtmp(28:34));  %  W
            st1(5,ict) = str2num(dtmp(38:44));  %  T
            end %test for good data
        ss = size(st1);
    end  %while
    ss = size(st1)
    fclose(flist);
end;         %end of hour loop jam
    u=st1(2,:);%   /100;
    v=st1(3,:);%    /100;
    w=st1(4,:);%    /100;
    %% DEW 5/18/2007
    if 1
        plot(jdn,u,'k')
        hold
        plot(jdn,v,'b')
        plot(jdn,w,'r')
        title('Sonic raw components')
        legend('u','v','w')
    end  %skip
    sonraw = st1;   % load sonic array into temp array
    sonfix  % run despiking routine
    son_spc  % calculate sonic spectra was rdson2_08.m

