function [header,freq,data,grid_lon,grid_lat]=readSpec(filename);
% readSpec read WERA SPEC files created with wera16_grid  
 % open file 
 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
   i
   for j=1:ny
     dum=fread(fid,512,'float32');
     data(i,j,1:512)=single(dum);
   end
 end
data = double(data); 
fname = [filename(1:57),'_spec'];
save fname data grid_lat grid_lon freq
