function resample_ship_data(n)
% RESAMPLE_SHIP_DATA Resamples ship sensor data to a regular time grid.
%   resample_ship_data(n) reads the ship sensor dataset and resamples
%   it to an n-minute interval using the mean. The output is written
%   to a .txt file.
%
%   INPUT:
%     n - resampling interval in minutes (e.g., 1 for 1-minute data)

    % Define full path to input file (resampled raw sensor data)
    fname = "\\atlas.shore.mbari.org\ProjectLibrary\" + ...
            "901805_Coastal_Biogeochemical_Sensing\Lochness\" + ...
            "7day-sensor-data_resampled.csv";

    % Define full path to save output resampled data
    fsave = "\\atlas.shore.mbari.org\ProjectLibrary\" + ...
            "901805_Coastal_Biogeochemical_Sensing\Lochness\" + ...
            "7day-sensor-data_" + n + "min.txt";

    % Read the data table from CSV file
    T = readtable(fname);

    % Convert timestamp column to datetime format, specify UTC timezone
    T.Time = datetime(T.timestamp, "TimeZone", "UTC");

    % Convert table to timetable for time-based operations
    TT = table2timetable(T, 'RowTimes', 'Time');

    % Resample the timetable to regular n-minute intervals using mean
    TT = retime(TT, 'regular', 'mean', 'TimeStep', minutes(n));

    % Write the resampled timetable to a .txt file
    writetimetable(TT, fsave);
end
