% Example of how to use provided functions

% This bit is slow... comment out after first run in session
%Alice = import_data('./ClimateData/AliceSpringsDailyObs.csv', -23.7);
%Charleville = import_data('./ClimateData/CharlevilleDailyObs.csv', -26.4);
%Woomera = import_data('./ClimateData/WoomeraDailyObs.csv', -31.2);

for Data=[Alice CV WO] 
    % Find the first year which has full data for given fields
    fields = [Data.temp_min Data.temp_max Data.cloud_cover_9am Data.cloud_cover_3pm Data.humidity_9am Data.humidity_3pm];
    years = unique(Data.date_year)';
    ok = 0;
    minyear = min(years);
    for year = years    
        fieldNum = 1;
        ok(year-minyear+1,1)=year;
        for field = fields        
            fieldNum = fieldNum + 1;       
            field_year = field(Data.date_year == year);
            ok(year-minyear+1,fieldNum) = length(find(~isnan(field_year)));
        end
    end

    'Number of non-NaN elements in fields temp_min temp_max cloud_cover_9am cloud_cover_3pm humidity_9am humidity_3pm'
    ok

    [year avgtemp] = group(Alice.temp_max, Alice.date_year, @mean);
    plot(year, avgtemp)
    xlabel('year');
    ylabel('average max temperature');
end;

% From the above it looks as though the third year (1952) is pretty good.