function diff_gmd_files(file_a, file_b, diff_out, rec_type)

    % Receive two GMD files and write a new file containing the difference
    % (B-A) of the measurement time tags and measurements.
    pause(1)
    fid_a   = fopen(file_a, 'r');
    fid_b   = fopen(file_b, 'r');
    fid_out = fopen(diff_out, 'w');

    % Get the GMD record format and output record format
    
    itai = 1;
    iobs = 6;    
    out_fmt = '%e %e\n';
    
    switch rec_type
        
        case {'Range', 'Range_Skin', 'Angles'}
            
            rec_format = '%f%s%d%s%s%f';    
            
        case 'DSN_SeqRange'
            
            rec_format = '%f%s%d%s%s%f%d%f%f';

        case 'DSN_TCP'
            
            rec_format = '%f%s%d%s%s%f%f%f';
            iobs = 8;

        case 'RangeRate'
            
            rec_format = '%f%s%d%s%s%d%d%f';
            iobs = 8;

        case 'GPS_PosVec'
            
            rec_format = '%f%s%d%d%f%f%f';
            iobs = 5:7;
            out_fmt = '%e %e %e %e\n';

        case 'SN_Doppler'
            
            rec_format = '%f%s%d%s%s%s%s%s%s%s%f%d%s%s%s%f%f';
            iobs = 17;

        otherwise
            
            fprintf('diff_gmd_files: Format %s not implemented', rec_type);
            return;
            
    end
    
    % Read in the GMD files
    pause(1)
    gmd_a = textscan(fid_a, rec_format, 'CommentStyle', {'%'});
    gmd_b = textscan(fid_b, rec_format, 'CommentStyle', {'%'});

    % Difference the measurement times and values
    
    tai_mjd_a = gmd_a{itai};
    obs_a     = cell2mat(gmd_a(iobs));

    tai_mjd_b = gmd_b{itai};
    obs_b     = cell2mat(gmd_b(iobs));
    
    tai_mjd_diff = tai_mjd_b - tai_mjd_a;
    obs_diff     = obs_b - obs_a;
    
    % Write out the difference file
    
    fprintf(fid_out, out_fmt, [tai_mjd_diff, obs_diff]');
    
    % Done-zo
    
    fclose(fid_a);
    fclose(fid_b);
    fclose(fid_out);
    pause(2)
end
