function [hwd]=read_hwd_data(startyear,startmonth,startday,endyear,endmonth,endday)

% Read in file name and extract zonal, meridional and number of meteors
% (pts)
% Written by RJW, 2013. Questions: rosmarie.wit@ntnu.no

begindate=datenum(startyear,startmonth,startday);
enddate=datenum(endyear,endmonth,endday);

for day=1:(enddate-begindate+1) %loop through all files from begindate to enddate
    day_file=datevec(begindate+(day-1));
    
    if day_file(2)<10 & day_file(3)<10
        filename=['C:\Users\rosmariw\Documents\Data\skiymet\skiymet Trondheim raw\hw',num2str(day_file(1)),'0',num2str(day_file(2)),'0',num2str(day_file(3)),'.trondheim.hwd']
    elseif day_file(2)<10 & day_file(3)>9
        filename=['C:\Users\rosmariw\Documents\Data\skiymet\skiymet Trondheim raw\hw',num2str(day_file(1)),'0',num2str(day_file(2)),num2str(day_file(3)),'.trondheim.hwd']
    elseif day_file(2)>9 & day_file(3)<10
        filename=['C:\Users\rosmariw\Documents\Data\skiymet\skiymet Trondheim raw\hw',num2str(day_file(1)),num2str(day_file(2)),'0',num2str(day_file(3)),'.trondheim.hwd']
    else
        filename=['C:\Users\rosmariw\Documents\Data\skiymet\skiymet Trondheim raw\hw',num2str(day_file(1)),num2str(day_file(2)),num2str(day_file(3)),'.trondheim.hwd']
    end
    
    fid=fopen(filename);
    if fid==-1
        disp('Error opening file')
    else
 
        fgetl(fid);%skip line 1 (header)
        for i=1:6
            clear height1; clear time1; clear zonal1; clear meridional1; clear uu1; clear vv1; clear ww1; clear uv1; clear uw1; clear vw1; clear pts1;
            
            
            height1=textscan(fid,'%s %s %s %f %f %s %s %s',1);
            time1=textscan(fid,'%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f',1);
            zonal1=textscan(fid,'%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f',1);
            meridional1=textscan(fid,'%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f',1);
            pts1=textscan(fid,'%s %s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f',1);

            date(i,:)=day_file;
            height(i,:)=height1{5};
            for j=1:24
                time(i,j)=time1{(1+j)};
                zonal(i,j)=zonal1{(1+j)};
                if zonal(i,j)==999 || zonal(i,j)==9999
                    zonal(i,j)=NaN;
                end
                meridional(i,j)=meridional1{(1+j)};
                if meridional(i,j)==999 || meridional(i,j)==9999
                    meridional(i,j)=NaN;
                end
                pts(i,j)=pts1{(2+j)};
            end%for j
        end%for i
        
    end%if fid==1
    
    closeresult=fclose(fid);
    if closeresult == 0
        disp('File closed succesfully')
    else
        disp('File close not succesful')
    end%if closeresult
    
    
    hwd.date(:,:,day)=date;
    hwd.height(:,:,day)=height;
    hwd.time(:,:,day)=time;
    hwd.u(:,:,day)=zonal;
    hwd.v(:,:,day)=meridional;
    hwd.pts(:,:,day)=pts;
    
end%day
end%function