%% combineFiles.m
% Combine the input files specified in gieTestSetup.mat into a single
% data file that can be analyzed. 
% 
% Vivek Nadkarni
% Trimble
% June 10, 2004

function combineFiles

loadCfg; 
disp('Please Wait ...'); 

% Description of data format columns. 
% 
% Data in Columns:
%%%%%%%%%%%%%%%%%%%%%%%
% 424817.000	  0.432449	29	 272	 48	    22474982.039	    21701095.211	
%          0.000	 52.00	1	0	    17502108.793	    21701091.480	 42.75	1	1
% 
% Meaning of the Data:
%%%%%%%%%%%%%%%%%%%%%%%
% TYPE 17:  SV # 29     Elv :  48                               Time : 424817.000
%                       Az  : 272   Clock bias (ms) :  0.432449      22:00:17 UTC
%                     ------L1------             ------L2------
%   Phase (cycles)     22474982.039 SLIP        17502108.793 X CORR SLIP
%   Range (meters)     21701095.211 C/A CODE     21701091.480 X CORR
%   L1 Doppler (Hz)           0.000
%   Residuals  (cycles)       0.000                    -3.730 meters
%   SNR                       52.00                     42.75
%   Flags (L2ldd L1slp L2slp lockp L1val L2rng L1ldd npos) (L1p L2p L2x L1f Dplr)
%            1     1     1     0     1     1     1     1     0   0   1   0   0
% 
%
% The indexing into these data files is defined in the struct dkey. 

%% Save Base Data
load([directoryname fileNames{BASE}]);
% Select common time epochs for all three data sets
seg = find((data(:,dkey.TIME) >= startTime) & (data(:,dkey.TIME) <= endTime)); 
baseData = data(seg,:); 
save([directoryname testFileName], 'baseData'); 
clear seg data baseData;
disp('Base Data Saved');

%% Save Rover Data
load([directoryname fileNames{ROVER}]);
% Select common time epochs for all three data sets
seg = find((data(:,dkey.TIME) >= startTime) & (data(:,dkey.TIME) <= endTime)); 
roverData = data(seg,:); 
save([directoryname testFileName], 'roverData', '-append'); 
clear seg data roverData;
disp('Rover Data Saved');


%% Save GIE data
load([directoryname fileNames{GIE}]);
% Select common time epochs for all three data sets
seg = find((data(:,dkey.TIME) >= startTime) & (data(:,dkey.TIME) <= endTime)); 
gieData = data(seg,:); 
save([directoryname testFileName], 'gieData', '-append'); 
clear seg data gieData;
disp('GIE Data Saved');


%% Save column descriptions
% Set a flag to say that GIE data has been combined
combinedDataFlag = 1; 
save([directoryname testFileName], '-append'); 

%% Clean up
% clear all; 

return; 
