function output_M_MB_MBS()
%   Function: output_M_MB_MBS
%   Author: Daniel O'Hara
%   Date: 12/6/2015
%   Description: Fumction to output raw (M) and processed (background field
%   removed (MB) and background+ship's field removed (MBS)) data to .llm
%   (longitude, latitude, meter) files to use in GMT.

    load('codePaths.mat')
    load([path_data,'\Mag_Nav_Data.mat']) % Load data.
    load([path_data,'\Mag_Nav_Data_NoBackground.mat'])
    load([path_data,'\Mag_Nav_Data_NB_noShip.mat'])

    sM = size(magLLData);
    sMB = size(magLLData_noB);
    sMBS = size(magLLData_noB_noS);

    % Collect data to output.
    t = [magLLData(:,9),magLLData(:,8),magLLData(:,18)];
    tB = [magLLData_noB(:,9),magLLData_noB(:,8),magLLData_noB(:,19)];
    tBS = [magLLData_noB_noS(:,9),magLLData_noB_noS(:,8),magLLData_noB_noS(:,20)];

    % (Over)Write GMT data files.
    fidM = fopen([path_gmt_files,'\MagDD.llm'],'w+');
    fidMB = fopen([path_gmt_files,'\MagDD_noB.llm'],'w+');
    fidMBS = fopen([path_gmt_files,'\MagDD_noB_noS.llm'],'w+');
    fidC = fopen([path_gmt_files,'\MagDD_ShipCorrection.llm'],'w+');

    % If the three stages of data have the same save, output each stage to
    % its respective file all at once. Otherwise, output each stage
    % individually.
    if sM(1,1) == sMB(1,1) && sM(1,1) == sMBS(1,1)
        for i = 1:sM(1,1)
            fprintf(fidM,'%f\t%f\t%f\n',t(i,1),t(i,2),t(i,3));
            fprintf(fidMB,'%f\t%f\t%f\n',tB(i,1),tB(i,2),tB(i,3));
            fprintf(fidMBS,'%f\t%f\t%f\n',tBS(i,1),tBS(i,2),tBS(i,3));
            fprintf(fidC,'%f\t%f\t%f\n',tBS(i,1),tBS(i,2),magLLData_noB_noS(i,17));
        end
    else
        for i = 1:sM(1,1)
            fprintf(fidM,'%f\t%f\t%f\n',t(i,1),t(i,2),t(i,3));
        end

        for i = 1:sMB(1,1)
            fprintf(fidMB,'%f\t%f\t%f\n',tB(i,1),tB(i,2),tB(i,3));
        end

        for i = 1:sMBS(1,1)
            fprintf(fidMBS,'%f\t%f\t%f\n',tBS(i,1),tBS(i,2),tBS(i,3));
            fprintf(fidC,'%f\t%f\t%f\n',tBS(i,1),tBS(i,2),magLLData_noB_noS(i,17));
        end
    end

    % Close files.
    fclose(fidM);
    fclose(fidMB);
    fclose(fidMBS);
    fclose(fidC);
end