% Make configuration file

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

%Input file - filenames (ionospheric map)
fiono = fopen('vstup/iono2019.txt');
tiono = textscan(fiono, '%s');
fclose(fiono);
iono= tiono{:,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};


%Configuration file settings

%MAIN 
pos1_posmode = 'ppp-static'; % Positioning mode(0:single,1:dgps,2:kinematic,3:static,4:movingbase,5:fixed,6:ppp_kine,7:ppp_static,8:ppp_fixed)
pos1_frequency = 'l1+l2';    %Frequency mode (1:l1,2:l1+l2,3:l1+l2+l5,4:l1+l5)
pos1_soltype       ='combined'; % Filtering mode  % (0:forward,1:backward,2:combined)
pos1_elmask        ='7';         % Elevation mask (deg)
pos1_snrmask_r     ='off';       % SNR mask  (0:off,1:on)
pos1_snrmask_b     ='off';       % SNR mask2 (0:off,1:on)
pos1_snrmask_L1    ='0,0,0,0,0,0,0,0,0'; %SNR mask L1
pos1_snrmask_L2    ='0,0,0,0,0,0,0,0,0'; %SNR mask L2
pos1_snrmask_L5    ='0,0,0,0,0,0,0,0,0'; %SNR mask L3
pos1_dynamics      ='off';        % Estimate receiver velocity and acceleration (0:off,1:on)
pos1_tidecorr      ='otl';        % Use tide corrections (0:off,1:on,2:otl) on = solid tides, otl = solid tydes + ocean tide loading
pos1_ionoopt       ='dual-freq';  % Ionospheric correction 
                                  %off  
                                  %brdc      - broadcast
                                  %sbas      - SBAS correction
                                  %dual_freq - ionosphere-free combination
                                  %est_stec  - estimate
                                  %ionex_tec - global ionospheric map
                                  %qzs_brdc  - QZSS broadcast
                                  %qzs_lex   - QZSS
                                  %stec      - input STEC
pos1_tropopt       ='est-ztdgrad';% Tropospheric correction 
                                  %off
                                  %saas        - Saastamoinen model
                                  %sbas        - SBAS correction
                                  %est_ztd     - estimate zenith total delay
                                  %est_ztdgrad - estimate zenith total delay + tropospheric gradients
                                  %ztd         - input zenith total delay
pos1_sateph        ='precise';    %Ephemeris type
                                  %brdc        - broadcast
                                  %precise     - precise (SP3 + CLK)
                                  %brdc+sbas   - SBAS correction
                                  %brdc+ssrapc - SSR (antenna phase center)
                                  %brdc+ssrcom - SSR (center of mass)
pos1_posopt1       ='on';         %using satellite antenna phase center variations (0:off,1:on)
pos1_posopt2       ='on';         %using receiver antenna phase center variations (0:off,1:on)
pos1_posopt3       ='on';         %wind-up correction (0:off,1:on,2:precise)
pos1_posopt4       ='on';         %exclude GPS Block IIA satellites in eclipse (0:off,1:on)
pos1_posopt5       ='on';         %receiver autonomous integrity - fault detection and exclusion(0:off,1:on)
pos1_posopt6       ='on';         %difference code bias (0:off,1:on)
pos1_exclsats      ='';           %exclude specific PRN (prn ...)
pos1_navsys        ='45';         %GNSS (1:gps+2:sbas+4:glo+8:gal+16:qzs+32:comp)
%AMBIGUITY RESOLUTION
pos2_armode        ='4';          %integer ambiguity resolution
                                  %0
                                  %1  - integer ambiguites are estimated and resolved continuously
                                  %2  - integer ambiguites are estimated epoch-by-epoch
                                  %3  - hold integer ambiguit if the validation is ok
                                  %4  - PPP integer ambiguity resolution (PPP-AR)
pos2_gloarmode     ='on';         %GLONASS integer ambiguity (0:off,1:on,2:autocal)
pos2_bdsarmode     ='on';         %BeiDou integer ambiguity (0:off,1:on)
pos2_arthres       ='3';          %minimum ratio to fix ambiguity
pos2_arthres1      ='0.9999';     %minimum confidence level to fix ambiguity in PPP?AR mode
pos2_arthres2      ='0.25';       %maximum fractional code bias in PPP-AR
pos2_arthres3      ='0.1';        
pos2_arthres4      ='0.05';
pos2_arlockcnt     ='0';          %minimum elevation to fix ambiguity
pos2_arelmask      ='0';          % (deg)
pos2_arminfix      ='10';         %minimum count of fix to hold ambiguity
pos2_armaxiter     ='1';          %
pos2_elmaskhold    ='0';          %minimum satellites to hold ambiguity (deg)
pos2_aroutcnt      ='5';          %reset ambiguity value
pos2_maxage        ='30';         %max age of differential corrections (s)
pos2_syncsol       ='off';        %set time synchronization mode of solutions (0:off,1:on)
pos2_slipthres     ='0.05';       %cycle slip treshold (m)
pos2_rejionno      ='30';         %maximum GDOP (m)
pos2_rejgdop       ='30';
pos2_niter         ='1';          %number of iterations in estimation update
pos2_baselen       ='0';          %baseline length in Moving-Base mode (m)
pos2_basesig       ='0';          % (m)
%OUTPUT
out_solformat      ='xyz';        %solution format
                                  %llh  - latitude longtitude
                                  %height(ellipsoidal)
                                  %xyz  - ECEF coordinates (e.g. ITRF2014)
                                  %enu  - baseline vector (ENU)
                                  %nmea - NMEA message
out_outhead        ='on';         %write header (0:off,1:on)
out_outopt         ='on';         %write processing options (0:off,1:on)
out_outvel         ='off';        % (0:off,1:on)
out_timesys        ='gpst';       %time type (0:gpst,1:utc,2:jst)
out_timeform       ='hms';        %tiem format (0:tow,1:hms)
out_timendec       ='3';          %number of decimal places
out_degform        ='deg';        %angle type (0:deg,1:dms)
out_fieldsep       ='';           %field separator
out_outsingle      ='on';         % (0:off,1:on)
out_maxsolstd      ='0';          % (m)
out_height         ='ellipsoidal';%height type (0:ellipsoidal,1:geodetic)
out_geoid          ='egm08_1';    %geoid type (0:internal,1:egm96,2:egm08_2.5,3:egm08_1,4:gsi2000)
out_solstatic      ='single';     %output type ? all epoch, average of all epoch (0:all,1:single)
out_nmeaintv1      ='0';          % (s)
out_nmeaintv2      ='0';          % (s)
out_outstat        ='off';      % (0:off,1:state,2:residual)
%STATISTICS
stats_eratio1      ='1000';       %pseudorange/carrier-phase ratio
stats_eratio2      ='1000';       %
stats_errphase     ='0.005';      %carrier-phase standard deviation (m)
stats_errphaseel   ='0.005';      %carrier-phase standard deviation (m/sin(El)) (m)
stats_errphasebl   ='0';          %baseline standard deviation (m/10km)
stats_errdoppler   ='10';         %Doppler errors (Hz)
stats_stdbias      ='30';         %BIASES (m)
stats_stdiono      ='0.03';       % (m)
stats_stdtrop      ='0.3';        % (m)
stats_prnaccelh    ='10';         % (m/s^2)
stats_prnaccelv    ='10';         % (m/s^2)
stats_prnbias      ='0.0001';     % (m)
stats_prniono      ='0.001';      % (m)
stats_prntrop      ='0.0001';     % (m)
stats_prnpos       ='0';          % (m)
stats_clkstab      ='5e-12';      % (s/s)
%ANTENNAS AND POSITIONS
%rover
ant1_postype       ='llh';        %input coordinates
                                  %llh       - latitude longtitude height
                                  %xyz       - ECEF coordinates
                                  %single    - from SPP solution
                                  %posfile   - read positions from position file
                                  %rinexhead - read from RINEX header
                                  %rtcm      - read from RTCM stream
                                  %raw       - raw data
ant1_pos1          ='';           % (deg|m)
ant1_pos2          ='';           % (deg|m)
ant1_pos3          ='';           % (m|m)
ant1_anttype       ='';           %antenna type from ANTEX file (e.g. TRM57971.00)
ant1_antdele       ='0';          %antenna offset E (m)
ant1_antdeln       ='0';          %antenna offset N (m)
ant1_antdelu       ='0';          %antenna offset U (m)
%base station - same as rover
ant2_postype       ='llh';        % (0:llh,1:xyz,2:single,3:posfile,4:rinexhead,5:rtcm,6:raw)
ant2_pos1          ='90';         % (deg|m)
ant2_pos2          ='0';          % (deg|m)
ant2_pos3          =''; % (m|m)
ant2_anttype       ='';
ant2_antdele       ='0';          % (m)
ant2_antdeln       ='0';          % (m)
ant2_antdelu       ='0';          % (m)
ant2_maxaveep      ='0';
ant2_initrst       ='off';        % (0:off,1:on)
%RTKNAVI settings
misc_timeinterp    ='off';        % (0:off,1:on)
misc_sbasatsel     ='0';          % (0:all)
misc_rnxopt1       ='';
misc_rnxopt2       ='';
misc_pppopt        ='';
% FILES
file_satantfile    =''; %satellite antenna phase variations (e.g. igs14.atx)
file_rcvantfile    =''; %receiver antenna phase variations (e.g. igs14.atx)
file_staposfile    =''; %station positions
file_geoidfile     =''; %geoid
file_ionofile      =''; %ionex
file_dcbfile       =''; %difference code bias
file_eopfile       =''; %earth rotation and orientation parameters
file_blqfile       ='E:\CADM_PPP\PPP\CADM.BLQ'; %ocean tide loadin BLQ file
file_tempdir       =''; 
file_geexefile     ='';
file_solstatfile   ='';
file_tracefile     ='';


%GENERATE CONFIGURATION FILE
for i = 1:length(code)
 %filepaths
 configuration = fopen(['C:\CONF2019\conf' dates{i} '.conf'], 'w');%otevření souboru pro zápis   
 file_ionofile = ['C:\PPP\' iono{i}];   
 file_dcbfile = ['C:\PPP\' code{i} '.dcb'];   
 file_eopfile = ['C:\PPP\' code{i} '.erp'];   
 




%save configuration file

fprintf(configuration,'pos1-posmode       =%s\r\npos1-frequency     =%s\r\npos1-soltype       =%s\r\npos1-elmask        =%s\r\npos1-snrmask-r     =%s\r\npos1-snrmask-b     =%s\r\npos1-snrmask-L1    =%s\r\npos1-snrmask-L2    =%s\r\npos1-snrmask-L5    =%s\r\npos1-dynamics      =%s\r\npos1-tidecorr      =%s\r\npos1-ionoopt       =%s\r\npos1-tropopt       =%s\r\npos1-sateph        =%s\r\npos1-posopt1       =%s\r\npos1-posopt2       =%s\r\npos1-posopt3       =%s\r\npos1-posopt4       =%s\r\npos1-posopt5       =%s\r\npos1-posopt6       =%s\r\npos1-exclsats      =%s\r\npos1-navsys        =%s\r\npos2-armode        =%s\r\npos2-gloarmode     =%s\r\npos2-bdsarmode     =%s\r\npos2-arthres       =%s\r\npos2-arthres1      =%s\r\npos2-arthres2      =%s\r\npos2-arthres3      =%s\r\npos2-arthres4      =%s\r\npos2-arlockcnt     =%s\r\npos2-arelmask      =%s\r\npos2-arminfix      =%s\r\npos2-armaxiter     =%s\r\npos2-elmaskhold    =%s\r\npos2-aroutcnt      =%s\r\npos2-maxage        =%s\r\npos2-syncsol       =%s\r\npos2-slipthres     =%s\r\npos2-rejionno      =%s\r\npos2-rejgdop       =%s\r\npos2-niter         =%s\r\npos2-baselen       =%s\r\npos2-basesig       =%s\r\nout-solformat      =%s\r\nout-outhead        =%s\r\nout-outopt         =%s\r\nout-outvel         =%s\r\nout-timesys        =%s\r\nout-timeform       =%s\r\nout-timendec       =%s\r\nout-degform        =%s\r\nout-fieldsep       =%s\r\nout-outsingle      =%s\r\nout-maxsolstd      =%s\r\nout-height         =%s\r\nout-geoid          =%s\r\nout-solstatic      =%s\r\nout-nmeaintv1      =%s\r\nout-nmeaintv2      =%s\r\nout-outstat        =%s\r\nstats-eratio1      =%s\r\nstats-eratio2      =%s\r\nstats-errphase     =%s\r\nstats-errphaseel   =%s\r\nstats-errphasebl   =%s\r\nstats-errdoppler   =%s\r\nstats-stdbias      =%s\r\nstats-stdiono      =%s\r\nstats-stdtrop      =%s\r\nstats-prnaccelh    =%s\r\nstats-prnaccelv    =%s\r\nstats-prnbias      =%s\r\nstats-prniono      =%s\r\nstats-prntrop      =%s\r\nstats-prnpos       =%s\r\nstats-clkstab      =%s\r\nant1-postype       =%s\r\nant1-pos1          =%s\r\nant1-pos2          =%s\r\nant1-pos3          =%s\r\nant1-anttype       =%s\r\nant1-antdele       =%s\r\nant1-antdeln       =%s\r\nant1-antdelu       =%s\r\nant2-postype       =%s\r\nant2-pos1          =%s\r\nant2-pos2          =%s\r\nant2-pos3          =%s\r\nant2-anttype       =%s\r\nant2-antdele       =%s\r\nant2-antdeln       =%s\r\nant2-antdelu       =%s\r\nant2-maxaveep      =%s\r\nant2-initrst       =%s\r\nmisc-timeinterp    =%s\r\nmisc-sbasatsel     =%s\r\nmisc-rnxopt1       =%s\r\nmisc-rnxopt2       =%s\r\nmisc-pppopt        =%s\r\nfile-satantfile    =%s\r\nfile-rcvantfile    =%s\r\nfile-staposfile    =%s\r\nfile-geoidfile     =%s\r\nfile-ionofile      =%s\r\nfile-dcbfile       =%s\r\nfile-eopfile       =%s\r\nfile-blqfile       =%s\r\nfile-tempdir       =%s\r\nfile-geexefile     =%s\r\nfile-solstatfile   =%s\r\nfile-tracefile     =%s',...
pos1_posmode,...
pos1_frequency,...
pos1_soltype,...
pos1_elmask,...
pos1_snrmask_r,...
pos1_snrmask_b,... 
pos1_snrmask_L1,...
pos1_snrmask_L2,...
pos1_snrmask_L5,...
pos1_dynamics,...
pos1_tidecorr,...
pos1_ionoopt,...
pos1_tropopt,...
pos1_sateph,...
pos1_posopt1,...
pos1_posopt2,...
pos1_posopt3,...
pos1_posopt4,...
pos1_posopt5,...
pos1_posopt6,...
pos1_exclsats,...
pos1_navsys,...
pos2_armode,...
pos2_gloarmode,...
pos2_bdsarmode,...
pos2_arthres,...
pos2_arthres1,...
pos2_arthres2,...
pos2_arthres3,...
pos2_arthres4,...
pos2_arlockcnt,...
pos2_arelmask,...
pos2_arminfix,...
pos2_armaxiter,...
pos2_elmaskhold,...
pos2_aroutcnt,...
pos2_maxage,...
pos2_syncsol,...
pos2_slipthres,...
pos2_rejionno,...
pos2_rejgdop,...
pos2_niter,...
pos2_baselen,...
pos2_basesig,...
out_solformat,...
out_outhead,...
out_outopt,...
out_outvel,...
out_timesys,...
out_timeform,...
out_timendec,...
out_degform,...
out_fieldsep,...
out_outsingle,...
out_maxsolstd,...
out_height,...
out_geoid,...
out_solstatic,...
out_nmeaintv1,...
out_nmeaintv2,...
out_outstat,...
stats_eratio1,...
stats_eratio2,...
stats_errphase,...
stats_errphaseel,...
stats_errphasebl,...
stats_errdoppler,...
stats_stdbias,...
stats_stdiono,...
stats_stdtrop,...
stats_prnaccelh,...
stats_prnaccelv,...
stats_prnbias,...
stats_prniono,...
stats_prntrop,...
stats_prnpos,...
stats_clkstab,...
ant1_postype,...
ant1_pos1,...
ant1_pos2,...
ant1_pos3,...
ant1_anttype,...
ant1_antdele,...
ant1_antdeln,...
ant1_antdelu,...
ant2_postype,...
ant2_pos1,...
ant2_pos2,...
ant2_pos3,...
ant2_anttype,...
ant2_antdele,...
ant2_antdeln,...
ant2_antdelu,...
ant2_maxaveep,...
ant2_initrst,...
misc_timeinterp,...
misc_sbasatsel,...
misc_rnxopt1,...
misc_rnxopt2,...
misc_pppopt,...
file_satantfile,...
file_rcvantfile,...
file_staposfile,...
file_geoidfile,...
file_ionofile,...
file_dcbfile,...
file_eopfile,...
file_blqfile,...
file_tempdir,...
file_geexefile,...
file_solstatfile,...
file_tracefile);
 fclose(configuration);
end

disp('Done');
