function [header,freq,data,grid_lon,grid_lat]=readSpec(filename);
% readSpec read WERA SPEC files created with wera16_grid  
 % open file 
%cd G:\Wave_experiment\WERA_data\SPEC
 for ihr = 00:23 
     for imin = 10:20:50
    if ihr== 0 
        if imin == 0
          filename = (['20080010000_nkl.SPEC']); 
        else 
          filename = (['200800100',int2str(imin),'_nkl.SPEC']); 
        end
    elseif ihr < 10
       if imin == 0
       filename = (['20080010',int2str(ihr),'00_nkl.SPEC']); 
       else
       filename = (['20080010',int2str(ihr),int2str(imin),'_nkl.SPEC']); 
       end
   else
       if imin == 0
           filename = (['2008001',int2str(ihr),'00_nkl.SPEC']);
       else
           filename = (['2008001',int2str(ihr),int2str(imin),'_nkl.SPEC']); 
       end
  end
 fid=fopen(filename,'rb');
 % read header (first 512 bytes)
 head=fread(fid,512,'char');  
 % this makes the header readable
 [header,grid_lon,grid_lat]=parseHeader(head);
 head=char(head');
 %frequency stuff
 fbragg=sqrt(9.81*num2str(header.freq)/300.0*pi);
 dt=str2num(header.delta_t);
 freq_start=-1/(2*dt); 
 freq_end=1/(2*dt)*255/256;
 freq_grad=-(freq_start-freq_end)/512;
 freq=(freq_start+freq_grad):freq_grad:freq_end;
 %output power
 nx=str2num(header.nx);
 ny=str2num(header.ny);
 
% for i=1:nx
%   for j=1:ny
%     dum=fread(fid,512,'float32');
%     data(i,j,1:512)=single(dum);
%   end
% end
% data=double(data)
% save freq freq
%  save nx nx
%  save ny ny
%  save fbragg fbragg
%  save dt dt
%  save head head
%  save config
 %output power
 for i=1:nx
   
   for j=1:ny
     dum=fread(fid,512,'float32');
     data(i,j,1:512)=single(dum);
   end
 end
data = double(data); 
fname = [filename(1:11),'_nkl_spec_t'];
eval(['save ',fname,' data']);
end
end
