% This pulls out the date, hisg, wave direction, and wave height, from the
% WWIII grid files.
Fileshs = dir('*hs.2006*') % 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)=julian(datevec(tmp2))-2440000;
    end
    time=[time;t'];
        clear t
        
    for j=1:length(tmp)
        hs=tmp(j).fltarray;
        hs=reshape(hs,[288 157]);
        HS(j)=hs(119,143);
    end
    height=[height;HS'];
        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(119,143);
    end
    DIR=[DIR;D'];
        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(119,143);
    end
    per=[per;T'];
        clear T t
end

cmd=['! ncgen -o ' 'ww3_20064swan.nc' ' wave_swan.cdl '];
eval(cmd);

nc=netcdf('ww3_2006.nc','w')
m=length(time);
nc{'wave_time'}(1:m)=time;
nc{'hisg'}(1:m)=height;
nc{'dir'}(1:m)=DIR;
nc{'period'}(1:m)=per;

close(nc);


    