%   Script: combineMag2
%   Author: Daniel O'Hara
%   Date: 12/6/2015
%   Description: Script to combine raw magnetic data from local directory.

load('codePaths.mat')
folderPath = path_mag; %local directory.
magForm = 'Mag_*2015*_Data.mat'; %File name header.

magFiles = ls([folderPath,'\',magForm]);
magDataTitles = {'Year','Day','Hour','Minute','Second','Serial Date','Time Diff (s)','Field Strength (nT)'};
    % Formatted data fields.

sMF = size(magFiles);
newMag = [];

for i = 2:sMF(1,1) %Combine local directory raw magnetic data. 
                    %   Ignore day 320 (11/16) - Outside cruise.
    load([folderPath,'\',magFiles(i,:)])
    newMag = [newMag;magData];
end

% Create serial date data.
allMagData = newMag(:,1:5);
seri = datenum([newMag(:,1),convertYD2MD(newMag(1,1),newMag(:,2)),newMag(:,3:5)]);
dif = [0;diff(seri,1,1)].*24;
allMagData = [allMagData,seri,dif,newMag(:,6:end)];
    
% Save results.
save([folderPath,'\Mag_All_Data.mat'],'allMagData','magDataTitles','-v7')