% Read csv file into a table class variable, tt
function[dates,levelheights,snr,stationNum,alldatesmdy,timeDifs,cloud_fracs,latitude,longitude,altitude,avgtime]=readerloader(stationNum, year)
%[dates,levelheights,snr,stationNum,clrdatesmdy,pcldydatesmdy,cldydatesmdy,month1,day1,hours1,day_utc,hours_utc]=readerloader(stationNum, year)

    tt = readtable(fileFinder(stationNum,year));
    
    %To remove RASS entries
    if stationNum==8221
        toDelete = tt.Avg_time_period < 4;
        tt(toDelete,:)=[];
    end
    if stationNum==10135
        toDelete = tt.Avg_time_period < 17;
        tt(toDelete,:)=[];
    end
    if stationNum==10678
        toDelete = tt.Avg_time_period < 17;
        tt(toDelete,:)=[];
    end  
    
    %sort by time
    tt = sortrows(tt,1); 
    
    
    filename=fileFinder(stationNum,year);
    filename = split(filename,"_");
    latitude=str2double(filename(6));
    longitude=str2double(filename(7));
    altitude=str2double(filename(8));
    
    
    
    %A few stations had the coordinates written incorrectly for the first 
    %few years or moved a fraction of a degree after the first few years. 
    %This is to record the latitude and longitude correctly even
    %though the file name had it written incorrectly.
    if stationNum>3018 && stationNum<3023
        latitude=57.35;
        longitude=-7.37;
    end
    if stationNum==6348
        longitude=4.95;
    end
    
    % unpack table into arrays
    %each of the following arrays should have a size of the number of rows in
    %the file

    %dates1 - an array of the 19th column in the file (local date/timestamp)
    dates=table2array(tt(:,19));
    [~, month1, day1] = ymd(dates);
    [hours1, ~, ~] = hms(dates);
    
    utc_dates=table2array(tt(:,1));
    [~, ~, day_utc] = ymd(utc_dates);
    [hours_utc,~, ~] = hms(utc_dates);
    %levelheights - array of 8th column of the file (height of each data point)
    
    levelheights=table2array(tt(:,8));
    %snr - array of the 18th column of the file (SNR of each data point)
    snr=table2array(tt(:,18));
    
    avgtime=table2array(tt(:,2));
    
    %Get list of dates, time differences, and cloud fractions
    [alldatesmdy,timeDifs,cloud_fracs]=getcleardates(year,month1,day1,hours1,day_utc,hours_utc,latitude,longitude);

    
    
end
        
        


