forked from rtklibexplorer/RTKLIB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtkpos.c
2382 lines (2155 loc) · 95.6 KB
/
rtkpos.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*------------------------------------------------------------------------------
* rtkpos.c : precise positioning
*
* Copyright (C) 2007-2020 by T.TAKASU, All rights reserved.
*
* version : $Revision: 1.1 $ $Date: 2008/07/17 21:48:06 $
* history : 2007/01/12 1.0 new
* 2007/03/13 1.1 add slip detection by LLI flag
* 2007/04/18 1.2 add antenna pcv correction
* change rtkpos argin
* 2008/07/18 1.3 refactored
* 2009/01/02 1.4 modify rtk positioning api
* 2009/03/09 1.5 support glonass, gallileo and qzs
* 2009/08/27 1.6 fix bug on numerical exception
* 2009/09/03 1.7 add check of valid satellite number
* add check time sync for moving-base
* 2009/11/23 1.8 add api rtkopenstat(),rtkclosestat()
* add receiver h/w bias estimation
* add solution status output
* 2010/04/04 1.9 support ppp-kinematic and ppp-static modes
* support earth tide correction
* changed api:
* rtkpos()
* 2010/09/07 1.10 add elevation mask to hold ambiguity
* 2012/02/01 1.11 add extended receiver error model
* add glonass interchannel bias correction
* add slip detection by L1-L5 gf jump
* output snr of rover receiver in residuals
* 2013/03/10 1.12 add otl and pole tides corrections
* 2014/05/26 1.13 support beidou and galileo
* add output of gal-gps and bds-gps time offset
* 2014/05/28 1.14 fix bug on memory exception with many sys and freq
* 2014/08/26 1.15 add function to swap sol-stat file with keywords
* 2014/10/21 1.16 fix bug on beidou amb-res with pos2-bdsarmode=0
* 2014/11/08 1.17 fix bug on ar-degradation by unhealthy satellites
* 2015/03/23 1.18 residuals referenced to reference satellite
* 2015/05/20 1.19 no output solution status file with Q=0
* 2015/07/22 1.20 fix bug on base station position setting
* 2016/07/30 1.21 suppress single solution if !prcopt.outsingle
* fix bug on slip detection of backward filter
* 2016/08/20 1.22 fix bug on ddres() function
* 2018/10/10 1.13 support api change of satexclude()
* 2018/12/15 1.14 disable ambiguity resolution for gps-qzss
* 2019/08/19 1.15 fix bug on return value of resamb_LAMBDA()
* 2020/11/30 1.16 support of NavIC/IRNSS in API rtkpos()
* add detecting cycle slips by L1-Lx GF phase jump
* delete GLONASS IFB correction in ddres()
* use integer types in stdint.h
*-----------------------------------------------------------------------------*/
#include <stdarg.h>
#include "rtklib.h"
/* algorithm configuration -------------------------------------------------- */
#define STD_PREC_VAR_THRESH 0 /* pos variance threshold to skip standard precision */
/* solution: 0 = run every epoch, */
/* 0.5 = skip except for first*/
/* constants/macros ----------------------------------------------------------*/
#define SQR(x) ((x)*(x))
#define SQRT(x) ((x)<=0.0||(x)!=(x)?0.0:sqrt(x))
#define MIN(x,y) ((x)<=(y)?(x):(y))
#define MAX(x,y) ((x)>=(y)?(x):(y))
#define ROUND(x) (int)floor((x)+0.5)
#define VAR_POS SQR(30.0) /* initial variance of receiver pos (m^2) */
#define VAR_POS_FIX SQR(1e-4) /* initial variance of fixed receiver pos (m^2) */
#define VAR_VEL SQR(10.0) /* initial variance of receiver vel ((m/s)^2) */
#define VAR_ACC SQR(10.0) /* initial variance of receiver acc ((m/ss)^2) */
#define VAR_GRA SQR(0.001) /* initial variance of gradient (m^2) */
#define INIT_ZWD 0.15 /* initial zwd (m) */
#define GAP_RESION 120 /* gap to reset ionosphere parameters (epochs) */
#define TTOL_MOVEB (1.0+2*DTTOL)
/* time sync tolerance for moving-baseline (s) */
/* number of parameters (pos,ionos,tropos,hw-bias,phase-bias,real,estimated) */
#define NF(opt) ((opt)->ionoopt==IONOOPT_IFLC?1:(opt)->nf)
#define NP(opt) ((opt)->dynamics==0?3:9)
#define NI(opt) ((opt)->ionoopt!=IONOOPT_EST?0:MAXSAT)
#define NT(opt) ((opt)->tropopt<TROPOPT_EST?0:((opt)->tropopt<TROPOPT_ESTG?2:6))
#define NL(opt) ((opt)->glomodear!=GLO_ARMODE_AUTOCAL?0:NFREQGLO)
#define NB(opt) ((opt)->mode<=PMODE_DGPS?0:MAXSAT*NF(opt))
#define NR(opt) (NP(opt)+NI(opt)+NT(opt)+NL(opt))
#define NX(opt) (NR(opt)+NB(opt))
/* state variable index */
#define II(s,opt) (NP(opt)+(s)-1) /* ionos (s:satellite no) */
#define IT(r,opt) (NP(opt)+NI(opt)+NT(opt)/2*(r)) /* tropos (r:0=rov,1:ref) */
#define IL(f,opt) (NP(opt)+NI(opt)+NT(opt)+(f)) /* receiver h/w bias */
#define IB(s,f,opt) (NR(opt)+MAXSAT*(f)+(s)-1) /* phase bias (s:satno,f:freq) */
/* poly coeffs used to adjust AR ratio by # of sats, derived by fitting to example from:
https://www.tudelft.nl/citg/over-faculteit/afdelingen/geoscience-remote-sensing/research/lambda/lambda */
static double ar_poly_coeffs[3][5] = {
{-1.94058448e-01, -7.79023476e+00, 1.24231120e+02, -4.03126050e+02, 3.50413202e+02},
{6.42237302e-01, -8.39813962e+00, 2.92107285e+01, -2.37577308e+01, -1.14307128e+00},
{-2.22600390e-02, 3.23169103e-01, -1.39837429e+00, 2.19282996e+00, -5.34583971e-02}};
/* global variables ----------------------------------------------------------*/
static int statlevel=0; /* rtk status output level (0:off) */
static FILE *fp_stat=NULL; /* rtk status file pointer */
static char file_stat[1024]=""; /* rtk status file original path */
static gtime_t time_stat={0}; /* rtk status file time */
/* open solution status file ---------------------------------------------------
* open solution status file and set output level
* args : char *file I rtk status file
* int level I rtk status level (0: off)
* return : status (1:ok,0:error)
* notes : file can constain time keywords (%Y,%y,%m...) defined in reppath().
* The time to replace keywords is based on UTC of CPU time.
* output : solution status file record format
*
* $POS,week,tow,stat,posx,posy,posz,posxf,posyf,poszf
* week/tow : gps week no/time of week (s)
* stat : solution status
* posx/posy/posz : position x/y/z ecef (m) float
* posxf/posyf/poszf : position x/y/z ecef (m) fixed
*
* $VELACC,week,tow,stat,vele,veln,velu,acce,accn,accu,velef,velnf,veluf,accef,accnf,accuf
* week/tow : gps week no/time of week (s)
* stat : solution status
* vele/veln/velu : velocity e/n/u (m/s) float
* acce/accn/accu : acceleration e/n/u (m/s^2) float
* velef/velnf/veluf : velocity e/n/u (m/s) fixed
* accef/accnf/accuf : acceleration e/n/u (m/s^2) fixed
*
* $CLK,week,tow,stat,clk1,clk2,clk3,clk4,clk5,clk6
* week/tow : gps week no/time of week (s)
* stat : solution status
* clk1 : receiver clock bias GPS (ns)
* clk2 : receiver clock bias GLO-GPS (ns)
* clk3 : receiver clock bias GAL-GPS (ns)
* clk4 : receiver clock bias BDS-GPS (ns)
* clk5 : receiver clock bias IRN-GPS (ns)
* clk6 : receiver clock bias QZS-GPS (ns)
*
* $ION,week,tow,stat,sat,az,el,ion,ion-fixed
* week/tow : gps week no/time of week (s)
* stat : solution status
* sat : satellite id
* az/el : azimuth/elevation angle(deg)
* ion : vertical ionospheric delay L1 (m) float
* ion-fixed: vertical ionospheric delay L1 (m) fixed
*
* $TROP,week,tow,stat,rcv,ztd,ztdf
* week/tow : gps week no/time of week (s)
* stat : solution status
* rcv : receiver (1:rover,2:base station)
* ztd : zenith total delay (m) float
* ztdf : zenith total delay (m) fixed
*
* $HWBIAS,week,tow,stat,frq,bias,biasf
* week/tow : gps week no/time of week (s)
* stat : solution status
* frq : frequency (1:L1,2:L2,...)
* bias : h/w bias coefficient (m/MHz) float
* biasf : h/w bias coefficient (m/MHz) fixed
*
* $SAT,week,tow,sat,frq,az,el,resp,resc,vsat,snr,fix,slip,lock,outc,slipc,rejc,icbias,bias,bias_var,lambda
* week/tow : gps week no/time of week (s)
* sat/frq : satellite id/frequency (1:L1,2:L2,...)
* az/el : azimuth/elevation angle (deg)
* resp : pseudorange residual (m)
* resc : carrier-phase residual (m)
* vsat : valid data flag (0:invalid,1:valid)
* snr : signal strength (dbHz)
* fix : ambiguity flag (0:no data,1:float,2:fixed,3:hold,4:ppp)
* slip : cycle-slip flag (bit1:slip,bit2:parity unknown)
* lock : carrier-lock count
* outc : data outage count
* slipc : cycle-slip count
* rejc : data reject (outlier) count
* icbias : interchannel bias (GLONASS)
* bias : phase bias
* bias_var : variance of phase bias
* lambda : wavelength
*
*-----------------------------------------------------------------------------*/
extern int rtkopenstat(const char *file, int level)
{
gtime_t time=utc2gpst(timeget());
char path[1024];
trace(3,"rtkopenstat: file=%s level=%d\n",file,level);
if (level<=0) return 0;
reppath(file,path,time,"","");
if (!(fp_stat=fopen(path,"w"))) {
trace(1,"rtkopenstat: file open error path=%s\n",path);
return 0;
}
strcpy(file_stat,file);
time_stat=time;
statlevel=level;
return 1;
}
/* close solution status file --------------------------------------------------
* close solution status file
* args : none
* return : none
*-----------------------------------------------------------------------------*/
extern void rtkclosestat(void)
{
trace(3,"rtkclosestat:\n");
if (fp_stat) fclose(fp_stat);
fp_stat=NULL;
file_stat[0]='\0';
statlevel=0;
}
/* Write solution status to buffer -------------------------------------------*/
extern int rtkoutstat(rtk_t *rtk, int level, char *buff)
{
if (level<=0||rtk->sol.stat==SOLQ_NONE) {
return 0;
}
ssat_t *ssat;
double pos[3],vel[3],acc[3],vela[3]={0},acca[3]={0},xa[3];
int week,nf=NF(&rtk->opt);
char id[8],*p=buff;
int est=rtk->opt.mode>=PMODE_DGPS;
int nfreq=est?nf:1;
double tow=time2gpst(rtk->sol.time,&week);
if (rtk->opt.mode>=PMODE_PPP_KINEMA) {
/* Write ppp solution status to buffer */
p+=pppoutstat(rtk,buff);
} else {
/* Receiver position */
if (est) {
for (int i=0;i<3;i++) xa[i]=i<rtk->na?rtk->xa[i]:0.0;
p+=sprintf(p,"$POS,%d,%.3f,%d,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f\n",week,tow,
rtk->sol.stat,rtk->x[0],rtk->x[1],rtk->x[2],xa[0],xa[1],
xa[2]);
}
else {
p+=sprintf(p,"$POS,%d,%.3f,%d,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f\n",week,tow,
rtk->sol.stat,rtk->sol.rr[0],rtk->sol.rr[1],rtk->sol.rr[2],
0.0,0.0,0.0);
}
/* Receiver velocity and acceleration */
if (est&&rtk->opt.dynamics) {
ecef2pos(rtk->sol.rr,pos);
ecef2enu(pos,rtk->x+3,vel);
ecef2enu(pos,rtk->x+6,acc);
if (rtk->na>=6) ecef2enu(pos,rtk->xa+3,vela);
if (rtk->na>=9) ecef2enu(pos,rtk->xa+6,acca);
p+=sprintf(p,"$VELACC,%d,%.3f,%d,%.4f,%.4f,%.4f,%.5f,%.5f,%.5f,%.4f,%.4f,%.4f,%.5f,%.5f,%.5f\n",
week,tow,rtk->sol.stat,vel[0],vel[1],vel[2],acc[0],acc[1],
acc[2],vela[0],vela[1],vela[2],acca[0],acca[1],acca[2]);
}
else {
ecef2pos(rtk->sol.rr,pos);
ecef2enu(pos,rtk->sol.rr+3,vel);
p+=sprintf(p,"$VELACC,%d,%.3f,%d,%.4f,%.4f,%.4f,%.5f,%.5f,%.5f,%.4f,%.4f,%.4f,%.5f,%.5f,%.5f\n",
week,tow,rtk->sol.stat,vel[0],vel[1],vel[2],
0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
}
/* Receiver clocks */
p+=sprintf(p,"$CLK,%d,%.3f,%d,%d,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\n",
week,tow,rtk->sol.stat,1,rtk->sol.dtr[0]*1E9,rtk->sol.dtr[1]*1E9,
rtk->sol.dtr[2]*1E9,rtk->sol.dtr[3]*1E9,
rtk->sol.dtr[4]*1E9,rtk->sol.dtr[5]*1E9);
/* Ionospheric parameters */
if (est&&rtk->opt.ionoopt==IONOOPT_EST) {
for (int i=0;i<MAXSAT;i++) {
ssat=rtk->ssat+i;
if (!ssat->vs) continue;
satno2id(i+1,id);
int j=II(i+1,&rtk->opt);
xa[0]=j<rtk->na?rtk->xa[j]:0.0;
p+=sprintf(p,"$ION,%d,%.3f,%d,%s,%.1f,%.1f,%.4f,%.4f\n",week,tow,
rtk->sol.stat,id,ssat->azel[0]*R2D,ssat->azel[1]*R2D,
rtk->x[j],xa[0]);
}
}
/* Tropospheric parameters */
if (est&&(rtk->opt.tropopt>=TROPOPT_EST)) {
for (int i=0;i<2;i++) {
int j=IT(i,&rtk->opt);
xa[0]=j<rtk->na?rtk->xa[j]:0.0;
p+=sprintf(p,"$TROP,%d,%.3f,%d,%d,%.4f,%.4f\n",week,tow,
rtk->sol.stat,i+1,rtk->x[j],xa[0]);
}
}
/* Receiver h/w bias */
if (est&&rtk->opt.glomodear==GLO_ARMODE_AUTOCAL) {
for (int i=0;i<nfreq;i++) {
int j=IL(i,&rtk->opt);
xa[0]=j<rtk->na?rtk->xa[j]:0.0;
p+=sprintf(p,"$HWBIAS,%d,%.3f,%d,%d,%.4f,%.4f\n",week,tow,
rtk->sol.stat,i+1,rtk->x[j],xa[0]);
}
}
}
if (level <= 1) return (int)(p-buff);
/* Write residuals and status */
for (int i=0;i<MAXSAT;i++) {
ssat=rtk->ssat+i;
if (!ssat->vs) continue;
satno2id(i+1,id);
for (int j=0;j<nfreq;j++) {
int k=IB(i+1,j,&rtk->opt);
p+=sprintf(p,"$SAT,%d,%.3f,%s,%d,%.1f,%.1f,%.4f,%.4f,%d,%.0f,%d,%d,%d,%u,%u,%u,%.2f,%.6f,%.5f\n",
week,tow,id,j+1,ssat->azel[0]*R2D,ssat->azel[1]*R2D,
ssat->resp[j],ssat->resc[j],ssat->vsat[j],ssat->snr_rover[j]*SNR_UNIT,
ssat->fix[j],ssat->slip[j]&3,ssat->lock[j],ssat->outc[j],
ssat->slipc[j],ssat->rejc[j],k<rtk->nx?rtk->x[k]:0,
k<rtk->nx?rtk->P[k+k*rtk->nx]:0,ssat->icbias[j]);
}
}
return (int)(p-buff);
}
/* swap solution status file -------------------------------------------------*/
static void swapsolstat(void)
{
gtime_t time=utc2gpst(timeget());
char path[1024];
if ((int)(time2gpst(time ,NULL)/INT_SWAP_STAT)==
(int)(time2gpst(time_stat,NULL)/INT_SWAP_STAT)) {
return;
}
time_stat=time;
if (!reppath(file_stat,path,time,"","")) {
return;
}
if (fp_stat) fclose(fp_stat);
if (!(fp_stat=fopen(path,"w"))) {
trace(2,"swapsolstat: file open error path=%s\n",path);
return;
}
trace(3,"swapsolstat: path=%s\n",path);
}
/* output solution status ----------------------------------------------------*/
static void outsolstat(rtk_t *rtk,const nav_t *nav)
{
if (statlevel<=0||!fp_stat||!rtk->sol.stat) return;
trace(3,"outsolstat:\n");
/* swap solution status file */
swapsolstat();
/* write solution status */
char buff[2*MAXSOLMSG+1];
int n=rtkoutstat(rtk,statlevel,buff);
buff[n]='\0';
fputs(buff,fp_stat);
}
/* save error message --------------------------------------------------------*/
static void errmsg(rtk_t *rtk, const char *format, ...)
{
char buff[256],tstr[32];
int n;
va_list ap;
time2str(rtk->sol.time,tstr,2);
n=sprintf(buff,"%s: ",tstr+11);
va_start(ap,format);
n+=vsprintf(buff+n,format,ap);
va_end(ap);
n=n<MAXERRMSG-rtk->neb?n:MAXERRMSG-rtk->neb;
memcpy(rtk->errbuf+rtk->neb,buff,n);
rtk->neb+=n;
trace(2,"%s",buff);
}
/* single-differenced observable ---------------------------------------------*/
static double sdobs(const obsd_t *obs, int i, int j, int k)
{
double pi=(k<NFREQ)?obs[i].L[k]:obs[i].P[k-NFREQ];
double pj=(k<NFREQ)?obs[j].L[k]:obs[j].P[k-NFREQ];
return pi==0.0||pj==0.0?0.0:pi-pj;
}
/* single-differenced geometry-free linear combination of phase --------------*/
static double gfobs(const obsd_t *obs, int i, int j, int k, const nav_t *nav)
{
double freq1,freq2,L1,L2;
freq1=sat2freq(obs[i].sat,obs[i].code[0],nav);
freq2=sat2freq(obs[i].sat,obs[i].code[k],nav);
L1=sdobs(obs,i,j,0);
L2=sdobs(obs,i,j,k);
if (freq1==0.0||freq2==0.0||L1==0.0||L2==0.0) return 0.0;
return L1*CLIGHT/freq1-L2*CLIGHT/freq2;
}
/* single-differenced measurement error variance -----------------------------*/
static double varerr(int sat, int sys, double el, double snr_rover, double snr_base,
double bl, double dt, int f, const prcopt_t *opt, const obsd_t *obs)
{
double a,b,c,d,e;
double snr_max=opt->err[5];
double fact;
double sinel=sin(el),var;
int nf=NF(opt),frq,code;
frq=f%nf;code=f<nf?0:1;
/* increase variance for pseudoranges */
if (code) fact=opt->eratio[frq];
/* else adjust variance between freqs */
else fact=opt->eratio[frq]/opt->eratio[0];
/* adjust variance for constellation */
switch (sys) {
case SYS_GPS: fact*=EFACT_GPS;break;
case SYS_GLO: fact*=EFACT_GLO;break;
case SYS_GAL: fact*=EFACT_GAL;break;
case SYS_SBS: fact*=EFACT_SBS;break;
case SYS_QZS: fact*=EFACT_QZS;break;
case SYS_CMP: fact*=EFACT_CMP;break;
case SYS_IRN: fact*=EFACT_IRN;break;
default: fact*=EFACT_GPS;break;
}
/* adjust variance for config parameters */
a=fact*opt->err[1]; /* base term */
b=fact*opt->err[2]; /* el term */
c=opt->err[3]*bl/1E4; /* baseline term */
d=CLIGHT*opt->sclkstab*dt; /* clock term */
/* calculate variance */
var=2.0*(a*a+b*b/sinel/sinel+c*c)+d*d;
if (opt->err[6]>0) { /* add SNR term */
e=fact*opt->err[6];
var+=e*e*(pow(10,0.1*MAX(snr_max-snr_rover,0))+
pow(10,0.1*MAX(snr_max-snr_base, 0)));
}
if (opt->err[7]>0.0) { /* add rcvr stdevs term */
if (code) var+=SQR(opt->err[7]*0.01*(1<<(obs->Pstd[frq]+5))); /* 0.01*2^(n+5) */
else var+=SQR(opt->err[7]*obs->Lstd[frq]*0.004*0.2); /* 0.004 cycles -> m) */
}
var*=(opt->ionoopt==IONOOPT_IFLC)?SQR(3.0):1.0;
return var;
}
/* baseline length -----------------------------------------------------------*/
static double baseline(const double *ru, const double *rb, double *dr)
{
int i;
for (i=0;i<3;i++) dr[i]=ru[i]-rb[i];
return norm(dr,3);
}
/* initialize state and covariance -------------------------------------------*/
static inline void initx(rtk_t *rtk, double xi, double var, int i)
{
int j;
rtk->x[i]=xi;
for (j=0;j<rtk->nx;j++) rtk->P[i+j*rtk->nx]=0.0;
for (j=0;j<rtk->nx;j++) rtk->P[j+i*rtk->nx]=0.0;
rtk->P[i+i*rtk->nx]=var;
}
/* select common satellites between rover and reference station --------------*/
static int selsat(const obsd_t *obs, double *azel, int nu, int nr,
const prcopt_t *opt, int *sat, int *iu, int *ir)
{
int i,j,k=0;
trace(3,"selsat : nu=%d nr=%d\n",nu,nr);
for (i=0,j=nu;i<nu&&j<nu+nr;i++,j++) {
if (obs[i].sat<obs[j].sat) j--;
else if (obs[i].sat>obs[j].sat) i--;
else if (azel[1+j*2]>=opt->elmin) { /* elevation at base station */
sat[k]=obs[i].sat; iu[k]=i; ir[k++]=j;
trace(4,"(%2d) sat=%3d iu=%2d ir=%2d\n",k-1,obs[i].sat,i,j);
}
}
return k;
}
/* temporal update of position/velocity/acceleration -------------------------*/
static void udpos(rtk_t *rtk, double tt)
{
double *F,*P,*FP,*x,*xp,pos[3],Q[9]={0},Qv[9],var=0.0;
int i,j,*ix,nx;
trace(3,"udpos : tt=%.3f\n",tt);
/* fixed mode */
if (rtk->opt.mode==PMODE_FIXED) {
for (i=0;i<3;i++) initx(rtk,rtk->opt.ru[i],VAR_POS_FIX,i);
return;
}
/* initialize position for first epoch */
if (norm(rtk->x,3)<=0.0) {
trace(3,"rr_init=");tracemat(3,rtk->sol.rr,1,6,15,6);
for (i=0;i<3;i++) initx(rtk,rtk->sol.rr[i],VAR_POS,i);
if (rtk->opt.dynamics) {
for (i=3;i<6;i++) initx(rtk,rtk->sol.rr[i],VAR_VEL,i);
for (i=6;i<9;i++) initx(rtk,1E-6,VAR_ACC,i);
}
}
/* static mode */
if (rtk->opt.mode==PMODE_STATIC||rtk->opt.mode==PMODE_STATIC_START) return;
/* kinmatic mode without dynamics */
if (!rtk->opt.dynamics) {
for (i=0;i<3;i++) initx(rtk,rtk->sol.rr[i],VAR_POS,i);
return;
}
/* check variance of estimated position */
for (i=0;i<3;i++) var+=rtk->P[i+i*rtk->nx];
var/=3.0;
if (var>VAR_POS) {
/* reset position with large variance */
for (i=0;i<3;i++) initx(rtk,rtk->sol.rr[i],VAR_POS,i);
for (i=3;i<6;i++) initx(rtk,rtk->sol.rr[i],VAR_VEL,i);
for (i=6;i<9;i++) initx(rtk,1E-6,VAR_ACC,i);
trace(2,"reset rtk position due to large variance: var=%.3f\n",var);
return;
}
/* generate valid state index */
ix=imat(rtk->nx,1);
for (i=nx=0;i<rtk->nx;i++) {
/* TODO: The b34 code causes issues so use b33 code for now */
if (i<9||(rtk->x[i]!=0.0&&rtk->P[i+i*rtk->nx]>0.0)) ix[nx++]=i;
}
/* state transition of position/velocity/acceleration */
F=eye(nx); P=mat(nx,nx); FP=mat(nx,nx); x=mat(nx,1); xp=mat(nx,1);
for (i=0;i<6;i++) {
F[i+(i+3)*nx]=tt;
}
/* include accel terms if filter is converged */
if (var<rtk->opt.thresar[1]) {
for (i=0;i<3;i++) {
F[i+(i+6)*nx]=(tt>=0?1:-1)*SQR(tt)/2.0;
}
}
else trace(3,"pos var too high for accel term: %.4f\n", var);
for (i=0;i<nx;i++) {
x[i]=rtk->x[ix[i]];
for (j=0;j<nx;j++) {
P[i+j*nx]=rtk->P[ix[i]+ix[j]*rtk->nx];
}
}
/* x=F*x, P=F*P*F' */
matmul("NN",nx,1,nx,F,x,xp);
matmul("NN",nx,nx,nx,F,P,FP);
matmul("NT",nx,nx,nx,FP,F,P);
for (i=0;i<nx;i++) {
rtk->x[ix[i]]=xp[i];
for (j=0;j<nx;j++) {
rtk->P[ix[i]+ix[j]*rtk->nx]=P[i+j*nx];
}
}
/* process noise added to only acceleration P=P+Q */
Q[0]=Q[4]=SQR(rtk->opt.prn[3])*fabs(tt);
Q[8]=SQR(rtk->opt.prn[4])*fabs(tt);
ecef2pos(rtk->x,pos);
covecef(pos,Q,Qv);
for (i=0;i<3;i++) for (j=0;j<3;j++) {
rtk->P[i+6+(j+6)*rtk->nx]+=Qv[i+j*3];
}
free(ix); free(F); free(P); free(FP); free(x); free(xp);
}
/* temporal update of ionospheric parameters ---------------------------------*/
static void udion(rtk_t *rtk, double tt, double bl, const int *sat, int ns)
{
double el,fact;
int i,j;
trace(3,"udion : tt=%.3f bl=%.0f ns=%d\n",tt,bl,ns);
/* reset ionospheric delays for sats with long outages */
for (i=1;i<=MAXSAT;i++) {
j=II(i,&rtk->opt);
if (rtk->x[j]!=0.0&&
rtk->ssat[i-1].outc[0]>GAP_RESION&&rtk->ssat[i-1].outc[1]>GAP_RESION)
rtk->x[j]=0.0;
}
for (i=0;i<ns;i++) {
j=II(sat[i],&rtk->opt);
if (rtk->x[j]==0.0) {
/* initialize ionospheric delay state */
initx(rtk,1E-6,SQR(rtk->opt.std[1]*bl/1E4),j);
}
else {
/* elevation dependent factor of process noise */
el=rtk->ssat[sat[i]-1].azel[1];
fact=cos(el);
rtk->P[j+j*rtk->nx]+=SQR(rtk->opt.prn[1]*bl/1E4*fact)*fabs(tt);
}
}
}
/* temporal update of tropospheric parameters --------------------------------*/
static void udtrop(rtk_t *rtk, double tt, double bl)
{
int i,j,k;
trace(3,"udtrop : tt=%.3f\n",tt);
for (i=0;i<2;i++) {
j=IT(i,&rtk->opt);
if (rtk->x[j]==0.0) {
initx(rtk,INIT_ZWD,SQR(rtk->opt.std[2]),j); /* initial zwd */
if (rtk->opt.tropopt>=TROPOPT_ESTG) {
for (k=0;k<2;k++) initx(rtk,1E-6,VAR_GRA,++j);
}
}
else {
rtk->P[j+j*rtk->nx]+=SQR(rtk->opt.prn[2])*fabs(tt);
if (rtk->opt.tropopt>=TROPOPT_ESTG) {
for (k=0;k<2;k++) {
rtk->P[++j*(1+rtk->nx)]+=SQR(rtk->opt.prn[2]*0.3)*fabs(tt);
}
}
}
}
}
/* temporal update of receiver h/w biases ------------------------------------*/
static void udrcvbias(rtk_t *rtk, double tt)
{
int i,j;
trace(3,"udrcvbias: tt=%.3f\n",tt);
for (i=0;i<NFREQGLO;i++) {
j=IL(i,&rtk->opt);
if (rtk->x[j]==0.0) {
/* add small offset to avoid initializing with zero */
initx(rtk,rtk->opt.thresar[2]+1e-6,rtk->opt.thresar[3],j);
}
/* hold to fixed solution */
else if (rtk->nfix>=rtk->opt.minfix) {
initx(rtk,rtk->xa[j],rtk->Pa[j+j*rtk->na],j);
}
else {
rtk->P[j+j*rtk->nx]+=SQR(rtk->opt.thresar[4])*fabs(tt);
}
}
}
/* detect cycle slip by LLI --------------------------------------------------*/
static void detslp_ll(rtk_t *rtk, const obsd_t *obs, int i, int rcv)
{
uint32_t slip,LLI;
int f,sat=obs[i].sat;
trace(4,"detslp_ll: i=%d rcv=%d\n",i,rcv);
for (f=0;f<rtk->opt.nf;f++) {
if ((obs[i].L[f]==0.0&&obs[i].LLI[f]==0)||
fabs(timediff(obs[i].time,rtk->ssat[sat-1].pt[rcv-1][f]))<DTTOL) {
continue;
}
/* restore previous LLI */
if (rcv==1) LLI=getbitu(&rtk->ssat[sat-1].slip[f],0,2); /* rover */
else LLI=getbitu(&rtk->ssat[sat-1].slip[f],2,2); /* base */
/* detect slip by cycle slip flag in LLI */
if (rtk->tt>=0.0) { /* forward */
if (obs[i].LLI[f]&1) {
errmsg(rtk,"slip detected forward (sat=%2d rcv=%d F=%d LLI=%x)\n",
sat,rcv,f+1,obs[i].LLI[f]);
}
slip=obs[i].LLI[f];
}
else { /* backward */
if (LLI&1) {
errmsg(rtk,"slip detected backward (sat=%2d rcv=%d F=%d LLI=%x)\n",
sat,rcv,f+1,LLI);
}
slip=LLI;
}
/* detect slip by parity unknown flag transition in LLI */
if (((LLI&2)&&!(obs[i].LLI[f]&2))||(!(LLI&2)&&(obs[i].LLI[f]&2))) {
errmsg(rtk,"slip detected half-cyc (sat=%2d rcv=%d F=%d LLI=%x->%x)\n",
sat,rcv,f+1,LLI,obs[i].LLI[f]);
slip|=1;
}
/* save current LLI */
if (rcv==1) setbitu(&rtk->ssat[sat-1].slip[f],0,2,obs[i].LLI[f]);
else setbitu(&rtk->ssat[sat-1].slip[f],2,2,obs[i].LLI[f]);
/* save slip and half-cycle valid flag */
rtk->ssat[sat-1].slip[f]|=(uint8_t)slip;
rtk->ssat[sat-1].half[f]=(obs[i].LLI[f]&2)?0:1;
}
}
/* detect cycle slip by geometry free phase jump -----------------------------*/
static void detslp_gf(rtk_t *rtk, const obsd_t *obs, int i, int j,
const nav_t *nav)
{
int k,sat=obs[i].sat;
double gf0,gf1;
trace(4,"detslp_gf: i=%d j=%d\n",i,j);
/* skip check if slip already detected or check disabled*/
if (rtk->opt.thresslip==0) return;
for (k=0;k<rtk->opt.nf;k++)
if (rtk->ssat[sat-1].slip[k]&1) return;
for (k=1;k<rtk->opt.nf;k++) {
/* calc SD geomotry free LC of phase between freq0 and freqk */
if ((gf1=gfobs(obs,i,j,k,nav))==0.0) continue;
gf0=rtk->ssat[sat-1].gf[k-1]; /* retrieve previous gf */
rtk->ssat[sat-1].gf[k-1]=gf1; /* save current gf for next epoch */
if (gf0!=0.0&&fabs(gf1-gf0)>rtk->opt.thresslip) {
rtk->ssat[sat-1].slip[0]|=1;
rtk->ssat[sat-1].slip[k]|=1;
errmsg(rtk,"slip detected GF jump (sat=%2d L1-L%d dGF=%.3f)\n",
sat,k+1,gf0-gf1);
}
}
}
/* detect cycle slip by doppler and phase difference -------------------------*/
static void detslp_dop(rtk_t *rtk, const obsd_t *obs, const int *ix, int ns,
int rcv, const nav_t *nav)
{
int i,ii,f,sat,ndop=0,nf=rtk->opt.nf;
double dph,dpt,mean_dop=0;
double dopdif[MAXSAT][NFREQ], tt[MAXSAT][NFREQ];
trace(4,"detslp_dop: rcv=%d\n", rcv);
if (rtk->opt.thresdop<=0) return; /* skip test if doppler thresh <= 0 */
/* calculate doppler differences for all sats and freqs */
for (i=0;i<ns;i++) {
ii = ix[i];
sat=obs[ii].sat;
for (f=0;f<nf;f++) {
dopdif[i][f]=0;tt[i][f]=0.00;
if (obs[ii].L[f]==0.0||obs[ii].D[f]==0.0||rtk->ssat[sat-1].ph[rcv-1][f]==0.0) continue;
if (fabs(tt[i][f]=timediff(obs[ii].time,rtk->ssat[sat-1].pt[rcv-1][f]))<DTTOL) continue;
/* calc phase difference and doppler x time (cycle) */
dph=(obs[ii].L[f]-rtk->ssat[sat-1].ph[rcv-1][f])/tt[i][f];
dpt=-obs[ii].D[f];
dopdif[i][f]=dph-dpt;
/* if not outlier, use this to calculate mean */
if (fabs(dopdif[i][f])<3*rtk->opt.thresdop) {
mean_dop+=dopdif[i][f];
ndop++;
}
}
}
/* calc mean doppler diff, most likely due to clock error */
if (ndop==0) return; /* unable to calc mean doppler, usually very large clock err */
mean_dop=mean_dop/ndop;
/* set slip if doppler difference with mean removed exceeds threshold */
for (i=0;i<ns;i++) {
sat=obs[ix[i]].sat;
for (f=0;f<nf;f++) {
if (dopdif[i][f]==0.00) continue;
if (fabs(dopdif[i][f]-mean_dop)>rtk->opt.thresdop) {
rtk->ssat[sat-1].slip[f]|=1;
errmsg(rtk,"slip detected doppler (sat=%2d rcv=%d dL%d=%.3f off=%.3f tt=%.2f)\n",
sat,rcv,f+1,dopdif[i][f]-mean_dop,mean_dop,tt[i][f]);
}
}
}
}
/* temporal update of phase biases -------------------------------------------*/
static void udbias(rtk_t *rtk, double tt, const obsd_t *obs, const int *sat,
const int *iu, const int *ir, int ns, const nav_t *nav)
{
double cp,pr,cp1,cp2,pr1,pr2,*bias,offset,freqi,freq1,freq2,C1,C2;
int i,j,k,slip,rejc,reset,nf=NF(&rtk->opt),f2;
trace(3,"udbias : tt=%.3f ns=%d\n",tt,ns);
/* clear cycle slips */
for (i=0;i<ns;i++) {
for (k=0;k<rtk->opt.nf;k++) rtk->ssat[sat[i]-1].slip[k]&=0xFC;
}
/* detect cycle slip by doppler and phase difference */
detslp_dop(rtk,obs,iu,ns,1,nav);
detslp_dop(rtk,obs,ir,ns,2,nav);
for (i=0;i<ns;i++) {
/* detect cycle slip by LLI */
detslp_ll(rtk,obs,iu[i],1);
detslp_ll(rtk,obs,ir[i],2);
/* detect cycle slip by geometry-free phase jump */
detslp_gf(rtk,obs,iu[i],ir[i],nav);
/* update half-cycle valid flag */
for (k=0;k<nf;k++) {
rtk->ssat[sat[i]-1].half[k]=
!((obs[iu[i]].LLI[k]&2)||(obs[ir[i]].LLI[k]&2));
}
}
for (k=0;k<nf;k++) {
/* reset phase-bias if instantaneous AR or expire obs outage counter */
for (i=1;i<=MAXSAT;i++) {
reset=++rtk->ssat[i-1].outc[k]>(uint32_t)rtk->opt.maxout;
if (rtk->opt.modear==ARMODE_INST&&rtk->x[IB(i,k,&rtk->opt)]!=0.0) {
initx(rtk,0.0,0.0,IB(i,k,&rtk->opt));
}
else if (reset&&rtk->x[IB(i,k,&rtk->opt)]!=0.0) {
initx(rtk,0.0,0.0,IB(i,k,&rtk->opt));
trace(3,"udbias : obs outage counter overflow (sat=%3d L%d n=%d)\n",
i,k+1,rtk->ssat[i-1].outc[k]);
rtk->ssat[i-1].outc[k]=0;
}
if (rtk->opt.modear!=ARMODE_INST&&reset) {
rtk->ssat[i-1].lock[k]=-rtk->opt.minlock;
}
}
/* update phase bias noise and check for cycle slips */
for (i=0;i<ns;i++) {
j=IB(sat[i],k,&rtk->opt);
rtk->P[j+j*rtk->nx]+=rtk->opt.prn[0]*rtk->opt.prn[0]*fabs(tt);
slip=rtk->ssat[sat[i]-1].slip[k];
rejc=rtk->ssat[sat[i]-1].rejc[k];
if (rtk->opt.ionoopt==IONOOPT_IFLC) {
f2=seliflc(rtk->opt.nf,rtk->ssat[sat[i]-1].sys);
slip|=rtk->ssat[sat[i]-1].slip[f2];
}
if (rtk->opt.modear==ARMODE_INST||(!(slip&1)&&rejc<2)) continue;
/* reset phase-bias state if detecting cycle slip or outlier */
rtk->x[j]=0.0;
rtk->ssat[sat[i]-1].rejc[k]=0;
rtk->ssat[sat[i]-1].lock[k]=-rtk->opt.minlock;
/* retain icbiases for GLONASS sats */
if (rtk->ssat[sat[i]-1].sys!=SYS_GLO) rtk->ssat[sat[i]-1].icbias[k]=0;
}
bias=zeros(ns,1);
/* estimate approximate phase-bias by delta phase - delta code */
for (i=j=0,offset=0.0;i<ns;i++) {
if (rtk->opt.ionoopt!=IONOOPT_IFLC) {
/* phase diff between rover and base in cycles */
cp=sdobs(obs,iu[i],ir[i],k); /* cycle */
/* pseudorange diff between rover and base in meters */
pr=sdobs(obs,iu[i],ir[i],k+NFREQ);
freqi=sat2freq(sat[i],obs[iu[i]].code[k],nav);
if (cp==0.0||pr==0.0||freqi==0.0) continue;
/* estimate bias in cycles */
bias[i]=cp-pr*freqi/CLIGHT;
}
else { /* use ionosphere free calc with 2 freqs */
f2=seliflc(rtk->opt.nf,rtk->ssat[sat[i]-1].sys);
cp1=sdobs(obs,iu[i],ir[i],0);
cp2=sdobs(obs,iu[i],ir[i],f2);
pr1=sdobs(obs,iu[i],ir[i],NFREQ);
pr2=sdobs(obs,iu[i],ir[i],NFREQ+f2);
freq1=sat2freq(sat[i],obs[iu[i]].code[0],nav);
freq2=sat2freq(sat[i],obs[iu[i]].code[f2],nav);
if (cp1==0.0||cp2==0.0||pr1==0.0||pr2==0.0||freq1<=0.0||freq2<=0.0) continue;
C1= SQR(freq1)/(SQR(freq1)-SQR(freq2));
C2=-SQR(freq2)/(SQR(freq1)-SQR(freq2));
/* estimate bias in meters */
bias[i]=(C1*cp1*CLIGHT/freq1+C2*cp2*CLIGHT/freq2)-(C1*pr1+C2*pr2);
}
if (rtk->x[IB(sat[i],k,&rtk->opt)]!=0.0) {
offset+=bias[i]-rtk->x[IB(sat[i],k,&rtk->opt)];
j++;
}
}
/* correct phase-bias offset to ensure phase-code coherency */
if (j>0) {
for (i=1;i<=MAXSAT;i++) {
if (rtk->x[IB(i,k,&rtk->opt)]!=0.0) rtk->x[IB(i,k,&rtk->opt)]+=offset/j;
}
}
/* set initial states of phase-bias */
for (i=0;i<ns;i++) {
if (bias[i]==0.0||rtk->x[IB(sat[i],k,&rtk->opt)]!=0.0) continue;
initx(rtk,bias[i],SQR(rtk->opt.std[0]),IB(sat[i],k,&rtk->opt));
trace(3," sat=%3d, F=%d: init phase=%.3f\n",sat[i],k+1,bias[i]);
if (rtk->opt.modear!=ARMODE_INST) {
rtk->ssat[sat[i]-1].lock[k]=-rtk->opt.minlock;
}
}
free(bias);
}
}
/* Temporal update of states --------------------------------------------------*/
static void udstate(rtk_t *rtk, const obsd_t *obs, const int *sat,
const int *iu, const int *ir, int ns, const nav_t *nav)
{
trace(3,"udstate : ns=%d\n",ns);
double tt=rtk->tt;
/* Temporal update of position/velocity/acceleration */
udpos(rtk,tt);
/* Temporal update of ionospheric parameters */
if (rtk->opt.ionoopt==IONOOPT_EST || rtk->opt.tropopt>=TROPOPT_EST) {
double dr[3], bl=baseline(rtk->x,rtk->rb,dr);
if (rtk->opt.ionoopt==IONOOPT_EST) {
udion(rtk,tt,bl,sat,ns);
}
/* Temporal update of tropospheric parameters */
if (rtk->opt.tropopt>=TROPOPT_EST) {
udtrop(rtk,tt,bl);
}
}
/* Temporal update of receiver h/w bias */
if (rtk->opt.glomodear==GLO_ARMODE_AUTOCAL&&(rtk->opt.navsys&SYS_GLO)) {
udrcvbias(rtk,tt);
}
/* Temporal update of phase-bias */
if (rtk->opt.mode>PMODE_DGPS) {
udbias(rtk,tt,obs,sat,iu,ir,ns,nav);
}
}
/* UD (undifferenced) phase/code residual for satellite ----------------------*/
static void zdres_sat(int base, double r, const obsd_t *obs, const nav_t *nav,
const double *azel, const double *dant,
const prcopt_t *opt, double *y, double *freq)
{
double freq1,freq2,C1,C2,dant_if;
int i,nf=NF(opt),f2;
if (opt->ionoopt==IONOOPT_IFLC) { /* iono-free linear combination */
freq1=sat2freq(obs->sat,obs->code[0],nav);
f2=seliflc(opt->nf,satsys(obs->sat,NULL));
freq2=sat2freq(obs->sat,obs->code[f2],nav);
if (freq1==0.0||freq2==0.0) return;
if (testsnr(base,0,azel[1],obs->SNR[0]*SNR_UNIT,&opt->snrmask)||
testsnr(base,f2,azel[1],obs->SNR[f2]*SNR_UNIT,&opt->snrmask)) return;
C1= SQR(freq1)/(SQR(freq1)-SQR(freq2));
C2=-SQR(freq2)/(SQR(freq1)-SQR(freq2));
dant_if=C1*dant[0]+C2*dant[f2];
if (obs->L[0]!=0.0&&obs->L[f2]!=0.0) {
y[0]=C1*obs->L[0]*CLIGHT/freq1+C2*obs->L[f2]*CLIGHT/freq2-r-dant_if;
}
if (obs->P[0]!=0.0&&obs->P[f2]!=0.0) {
y[nf]=C1*obs->P[0]+C2*obs->P[f2]-r-dant_if;
}
freq[0]=1.0;
}
else {
for (i=0;i<nf;i++) {
if ((freq[i]=sat2freq(obs->sat,obs->code[i],nav))==0.0) continue;
/* check SNR mask */
if (testsnr(base,i,azel[1],obs->SNR[i]*SNR_UNIT,&opt->snrmask)) {
continue;
}
/* residuals = observable - estimated range */
if (obs->L[i]!=0.0) y[i ]=obs->L[i]*CLIGHT/freq[i]-r-dant[i];
if (obs->P[i]!=0.0) y[i+nf]=obs->P[i] -r-dant[i];
trace(4,"zdres_sat: %d: L=%.6f P=%.6f r=%.6f f=%.0f\n",obs->sat,obs->L[i],
obs->P[i],r,freq[i]);
}
}
}
/* undifferenced phase/code residuals ----------------------------------------
calculate zero diff residuals [observed pseudorange - range]
output is in y[0:nu-1], only shared input with base is nav
args: I base: 1=base,0=rover
I obs = sat observations
I n = # of sats
I rs [(0:2)+i*6]= sat position {x,y,z} (m)
I dts[(0:1)+i*2]= sat clock {bias,drift} (s|s/s)
I var = variance of ephemeris
I svh = sat health flags
I nav = sat nav data
I rr = rcvr pos (x,y,z)
I opt = options
O y[(0:1)+i*2] = zero diff residuals {phase,code} (m)
O e = line of sight unit vectors to sats
O azel = [az, el] to sats */
static int zdres(int base, const obsd_t *obs, int n, const double *rs,
const double *dts, const double *var, const int *svh,
const nav_t *nav, const double *rr, const prcopt_t *opt,
double *y, double *e, double *azel, double *freq)
{
double r,rr_[3],pos[3],dant[NFREQ]={0},disp[3];
double mapfh,zhd,zazel[]={0.0,90.0*D2R};
int i,nf=NF(opt);