function ep_fullTimeSeries(id)
% ep_fullTimeSeries - Concatenate avg archive eqpac data with data from the current deployment
%
% This function reads <epid>.avg.nc and the data in the current deployment directory
% (using ep_cmpl) and writes the data out to a new netcdf file.
%
% Use as: ep_fullTimeSeries(id);
% Inputs: id = string, either 'EP1' or 'EP2'
% output: a new netcdf file named ep1_full.nc or ep2_full.nc in the current directory

id = upper(id);
ep_ini;                             % Load the header of each column of data (ColumnS) and the units (UnitS)
i  = strcmp(ColumnS,'Decimal_Year');
ep = ep_cmpl;                    % Read the data files in epX directories on tsunami

switch id
    case 'EP1'
        infile = netcdf(fullfile(getOasisPath, 'eqpac', 'netcdf', 'ep1.avg.nc'));
        ep = ep(1);
    case 'EP2'
        infile = netcdf(fullfile(getOasisPath, 'eqpac', 'netcdf', 'ep2.avg.nc'));
        ep = ep(2);
end

%=======================================
% Get the dates, Correct for Y2K issues
%=======================================
sdn = ep.dat(:,i) + 1900;
sdn = dy2date(sdn);      % Get Dates

%=========================================================
% Refine the approximate dates to make them more accurate
%=========================================================
[Year Month Day Hour Minute Second] = datevec(sdn);
i    = find(strcmp(ColumnS,'Time'));
Day  = round(Day + Hour./24);
Hour = ep.dat(:,i);
Hour(find(Hour == 1200)) = 12/24;
Hour(find(Hour == 1230)) = 12.5/24;
Day  = round(Day) + Hour;  % Correct the day to the local time
sdn  = datenum(Year, Month, Day) - gmtoffset(infile{'longitude'}(:)); % Convert local time to GMT

outfileName = [lower(id) '_specprr_full.nc'];
nccopyschema(infile, outfileName);
outfile = netcdf(outfileName, 'write');

c  = ep_iniNc;
tc = find(strcmp(c, 'time'));
ep.dat(:,tc) = sdn2utc(sdn);

% Assign time right off the bat
timeData = [infile{'time'}(:); ep.dat(:, tc)];
outfile{'time'}(1:length(timeData)) = timeData;


for i = 1:length(c)
    a = infile{c{i}}(:);
    b = ep.dat(:,i);
    dat = [a;b];
    if i == tc
        % Do nothing. We've already assigned time
    else

        if ~strcmp(c{i}, 'null')
            if length(dat) == length(timeData)
                try
                    outfile{c{i}}(:) = dat;
                catch
                    fprintf('ERROR!! Failed to write data for variable %s\n', c{i});
                end
            else
                fprintf(1, 'WARNING!! %s only had %i data points. It should have had %i\n', c{i}, length(dat), length(timeData));
            end

        end

    end

end;
oms_addqcflag(outfile);
ncquit(infile)
ncquit(outfile);




