% Make autobatch file - PPP processing in RTKLib (time comparison variant)

solution = 1 %1=GPS 4=GLONASS 8=GALILEO;


%Input file - dates in year
fdates = fopen('dates2019.txt');
tdates = textscan(fdates, '%s');
fclose(fdates);
dates= tdates{:,1};
dates2 = dates(1);

%Input file - GPS Weeks/Days in year (with prefix, e.g. CODE, COM, ...)
fcode = fopen('code2019.txt');
tcode = textscan(fcode, '%s');
fclose(fcode);
code= tcode{:,1};

%Input file - DOY
fnumbers = fopen('dayNumbers.txt');
tnumbers = textscan(fnumbers, '%s');
fclose(fnumbers);
numbers= tnumbers{:,1};

%Input file - variants (1h, 3h, 6h, ...)
ftime = fopen('time_1h.txt');
ttime = textscan(ftime, '%s');
fclose(ftime);
time= ttime{:,1};

years = cellfun (@(x) x(1:4),dates,'un',0);
days  = cellfun (@(x) x(7:8),dates,'un',0);
months =  cellfun (@(x) x(5:6),dates,'un',0);

% Setting - processing filepath
batfile = fopen('bat_1h\2018_01_GREC.bat', 'w');%otevření souboru pro zápis  
sprintf('%.0f',str2double(dates(1)))
k=1;
rr=1;
for i = 1:length(dates)  
 
    for k = 1:length(time)-1
   
        %GPS + GLONASS + Galileo
        fprintf(batfile,'rnx2rtkp -k conf%s.conf -ts %s/%s/%s %s -te %s/%s/%s %s  -o %0.0f.pos 5423R48793%s0000D.18o 5423R48793%s0000D.18n 5423R48793%s0000D.18g %s.18l 5423R48793%s0000D.18c %s.eph %s.clk\r\n' ,dates{i}, years{i},months{i}, days{i}, time{k}, years{i},  months{i}, days{i}, time{k+1},  rr,dates{i},dates{i},dates{i}, numbers{i}, dates{i},code{i},code{i});
    rr=rr+1;
    end    
    
end

fprintf(batfile,'%s',endRtklib);

fclose(batfile);
disp('Done')
