% Make autobatch file - PPP processing in RTKLib (GNSS combination variant)

%Type of GNSS 
sol = 'rc' % g = GPS, r = GLONASS, e = Galileo, c = BeiDou 
 sTyp = {'G' 'R' 'E' 'GR' 'GE' 'GC' 'RE' 'RC' 'GRE' 'GRC' 'REC' 'GREC'};
 switch sol
      case 'g'
      type = sTyp{1};
     case 'r'
      type = sTyp{2};
     case 'e'
      type = sTyp{3};
     case 'gr'
      type = sTyp{4};
      case 'ge'
      type = sTyp{5};
      case 'gc'
      type = sTyp{6};
      case 're'
      type = sTyp{7};
      case 'rc'
      type = sTyp{8};
      case 'gre'
      type = sTyp{9};
      case 'grc'
      type = sTyp{10};
      case 'rec'
      type = sTyp{11};
      case 'grec'
      type = sTyp{12};   
    end
     
 
%Input file - dates in year
fdates = fopen('vstup/dates2019.txt');
tdates = textscan(fdates, '%s');
fclose(fdates);
dates= tdates{:,1};

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

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

% Setting - processing filepath
batfile = fopen(['2019_24_' type '.bat'], 'w');%otevření souboru pro zápis  


for i = 1:length(dates)  
 
    switch sol
     case 'g'
     fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sG.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19n %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},code{i},code{i});
     case 'r'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sR.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19g %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},code{i},code{i});
     case 'e'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sE.pos 5423R48793%s0000D.19o %s.19l %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},numbers{i},code{i},code{i});
     case 'gr'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sGR.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19n 5423R48793%s0000D.19g %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},dates{i},code{i},code{i});
     case 'ge'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sGE.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19n %s.19l %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},numbers{i},code{i},code{i});
     case 'gc'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sGC.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19n 5423R48793%s0000D.19c %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},dates{i},code{i},code{i});
     case 're'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sRE.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19g %s.19l %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},numbers{i},code{i},code{i});
     case 'rc'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sRC.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19g 5423R48793%s0000D.19c %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},dates{i},code{i},code{i});
     case 'gre'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sGRE.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19n 5423R48793%s0000D.19g %s.19l %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},dates{i},numbers{i},code{i},code{i});
     case 'grc'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sGRC.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19n 5423R48793%s0000D.19g 5423R48793%s0000D.19c %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},dates{i},dates{i},code{i},code{i});
     case 'rec'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sREC.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19g %s.19l 5423R48793%s0000D.19c %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},numbers{i},dates{i},code{i},code{i});        
     case 'grec'
      fprintf(batfile,'rnx2rtkp -k conf%s.conf -o %sGREC.pos 5423R48793%s0000D.19o 5423R48793%s0000D.19n 5423R48793%s0000D.19g %s.19l 5423R48793%s0000D.19c %s.eph %s.clk\r\n' ,dates{i}, dates{i},dates{i},dates{i},dates{i},numbers{i},dates{i},code{i},code{i});       
    end
end

fclose(batfile);
disp('Done');