% This pulls out the date, hisg, wave direction, and wave height, from the
% WWIII grid files.
Fileshs = dir('*hs.2006*.grb') % all of them
Filesdp = dir('*dp.2006*') % all of them
Filestp = dir('*tp.2006*') % all of them

time=[];
height=[];
per=[];
DIR=[];

for i=1:12
   
    tmp=read_grib(Fileshs(i).name,-1);
    for j=1:length(tmp)
        tmp2=tmp(j).stime;
        t(j,:)=datevec(datenum(tmp2));
    end
    time=[time;t];
    range(t)
  %  pause
        clear t
                
    for j=1:length(tmp)
        hs=tmp(j).fltarray;
        hs=reshape(hs,[288 157]);
        HS(j)=hs(144,117);
    end
    height=[height;HS'];
    range(HS)
   % pause
        clear HS hs
    
    
    tmp=read_grib(Filesdp(i).name,-1);
    for j=1:length(tmp)
        d=tmp(j).fltarray;
        d=reshape(d,[288 157]);
        D(j)=d(144,117);
    end
    DIR=[DIR;D'];
    range(D)
    %pause
        clear D d
        
    tmp=read_grib(Filestp(i).name,-1);
    for j=1:length(tmp)
        t=tmp(j).fltarray;
        t=reshape(t,[288 157]);
        T(j)=t(144,117);
    end
    per=[per;T'];
    range(T)
        clear T t
%        pause
end

for i=1:length(time)
    T1(i)=time(i,1)*10000+time(i,2)*100+time(i,3);
    T2(i)=time(i,4)/100+time(i,5)/10000+time(i,6)/1000000;
end
    T1=T1';
    T2=T2';
    
data=[T1 T2 height per DIR];
data(:,6)=20;

save swan_ww3.wav data -ASCII


    