function out = aggregateDischargeTable(tbl, qCol, area_km2)
% AGGREGATEDISCHARGETABLE Portata 10 min -> oraria per ora di calendario -> mm/h.
%
% tbl    tabella con colonne 'date' e qCol (Q o Q_obs in m3/s)
% out    table con date (inizio ora) e Q_mm_h

    dt = datetime(tbl.date, 'InputFormat', 'preserve');
    hourId = dateshift(dt, 'start', 'hour');
    [hours, ~, gid] = unique(hourId, 'stable');
    q_m3s = splitapply(@(x) mean(x, 'omitnan'), tbl.(qCol)(:), gid);
    q_mm_h = q_m3s * 3600 * 1000 / (area_km2 * 1e6);
    out = table(hours, q_mm_h, 'VariableNames', {'date', 'Q_mm_h'});
    % fprintf('Portata: ora di calendario -> mm/h (%d passi)\n', height(out));
end
