conn = connect_penguin();
% Get new files to be uploaded
dirPath = 'C:\Users\bwerb\Documents\MATLAB\WetLabk0\CAL';
files = dir(dirPath);
fnames = cell2table({files.name}',"VariableNames",{'names'});
files = files(~[files.isdir]);
% Process files into structured table matching database format
n = length(files(:));
% Initialize empty composite table
CAL_composite = table();
for i = 1:n
    folder = files(i).folder;
    name = files(i).name;
    filename = fullfile(folder,name);
    CAL = readtable(filename);
    CAL.Properties.VariableNames = {...
        'com_port', 'datetime',...
        'temperature','salinity','vbiaspos',...
        'vrse','vrse_std','vk','vk_std',...
        'ik','ib','gliderfet_id'};
    % Convert from local to UTC
    CAL.datetime.TimeZone = "America/Los_Angeles";
    CAL.datetime.TimeZone = "UTC";
    CAL.datetime.Format = 'yyyy-MM-dd HH:mm:ss.SSS';
    CAL.datetime = string(CAL.datetime);
    CAL.com_port = string(CAL.com_port);
    CAL.gliderfet_id = string(CAL.gliderfet_id);
    % sqlwrite(conn, 'k0_seawater_lab', CAL); % Push to database
    CAL_composite = [CAL_composite; CAL];
end

sqlwrite(conn, 'k0_seawater_lab', CAL_composite); % Push to database