function [t1, t2] = append_db(station)
% Determine time period to append available data to existing SQL table
% t1   year after newest year in existing SQL table
% t2   year of latest available definitive data

% Read config file db_cong.pc
f = fopen('db_config.pc','r');
    serv = fgetl(f);
    log = fgetl(f);
    pass = fgetl(f);
    dbname  = fgetl(f);
    table = fgetl(f);    
fclose(f);

% Get latest year from db
mysql('open', serv,log,pass);
mysql(['use ' dbname]);
t1 = mysql(['select time from ' table ' where id=(select max(id) from ' table ');']);
mysql('close');
% Year after newest year in existing SQL table
t1 = str2num(datestr(t1, 'yyyy'))+1;

% Available data
station_dir = ['/nfs/r14/magobs/PC-index/Definitive_PC/data/' station '_archive/'];
year_folders = dir(station_dir);
for i = 1:length(year_folders)
    t2 = str2num(year_folders(end-(i)).name);
    nfiles = dir(fullfile(station_dir, num2str(t2), '*.min'));
    if(t2 >= t1 && length(nfiles) >= 365)
      break
    elseif(t2 < t1)
      error(['No new data available. Newest data: ' num2str(t2)])
    end%if
end%for i