-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrinex_ho.cpp
1274 lines (1035 loc) · 61.6 KB
/
rinex_ho.cpp
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
/*-------------------------------------------------------------------
Purpose: Program to read a RINEX file and apply the second and
third order ionospheric effects corrections
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP, Brazil
FAPESP PROCESS: 05/03522-1
Advisor: João Francisco Galera Monico
Departamento de Cartografia
FCT/UNESP - Presidente Prudente - SP, Brazil
Date: July of 2010
Reviewes and updates by Steve Hilla
-------------------------------------------------------------------
Observation: Use C++ classes to read and save RINEX file:
http://www.ngs.noaa.gov/gps-toolbox/rinex.htm
The authors would like to thanks CAPES, FAPESP by financial support
-------------------------------------------------------------------*/
//c::1304.13, SAH, change path, use one directory for all *.cpp/*.h files
//c::1304.13, SAH, comment out: printf("\033[20;4f") and system()
//c::1304.17, SAH, write cycle slip detection info to the log file.
//MHA, I've changed some system("pause") by getchar();
//insert a file to print cycle slip
//comment out: FilterObs[prn].Set_cont_epoch(0); near line 1023
#include "rinex_ho.h"
int main(int argc, char* argv[]) {
// #include "Include/Variable.inc"
#include "Variable.h"
string SatCode;
int Isat[NSAT]={0},NS,Ns_temp(0);
int count_sat_out(0),Pos_GPS_CurrObs[NSAT]={0};
bool wlslip, nlslip; //added by SH
double dx(0.0),dy(0.0),dz(0.0),dsv_sq(0.0),sv_range(0.0),omega_e(0.0),propagationDelay(0.0);
double dtom(0.0),usx(0.0),usy(0.0),svx(0.0),svy(0.0),svz(0.0);
double sh_az(0.0), sh_elv(0.0), sh_dist(0.0), sh_pplat(0.0), sh_pplon(0.0), sh_zp(0.0);
//lat. and long. of IPP in degrees
double lat_IPP_deg,lon_IPP_deg;
MEAN_PHASE_BIAS Phase_Bias[NSAT][max_arc]={0.0};
// memset(Phase_Bias,0,sizeof(Phase_Bias)); //set 0 to Phase_Bias struct
// system("clear"); //for linux
//clrscr(); //for windows
//check-out input parameters
if(argc == 1)
InpFileName = "rinex_ha.inp";
else
InpFileName = argv[1];
// InpFileName = "rinex_ha_brft_full.inp"; //TEST
// InpFileName = "rinex_ha_ASC1_full.inp";
//Imput parameters from rinex_ha.inp
//reading input parameters
ReadInput( InpFileName,filenameobs,filenamenav,newobsfile,
outfile,X0,Y0,Z0,Mask_Ele,read_tec,save_file,GIM_File,dcbr,
arqu_p1c1_sat,arqu_p1p2_sat,Geomag_Type,Name_IGRF_Model);
//Read data from rinex_ha_param.dat file
ReadParam(sigca,sigp2,sigph1,sigph2,h_ion,R_e,B_eq,Ne_max);
//object of class T_TEC
Class_TEC Calc_Tec(sigca,sigp2,sigph1,sigph2,dcbr,0.0);
double var_ca = pow(sigca,2),
var_p2 = pow(sigp2,2),
var_ph1 = pow(sigph1,2),
var_ph2 = pow(sigph2,2);
//Intial latitude and longitude for north pole
double latpn = 79.8,
lonpn = 288.1;
//object from Class_Iono class
Class_Iono calc_iono( latpn,lonpn,
h_ion, R_e, B_eq, Ne_max);
//-----------Opening Files--------------------------------------------------
fstream log; //log file
log.open("rinex.log",ios::out);
if( log.fail() )
{
cout << "It was not possible to open the file: rinex.log!" << endl;
getchar();
exit (-1);
}//if
string temp = outfile+"_tec.txt";
ofstream tecfile(temp.c_str(),ios::out);
if( tecfile.fail() )
{
cout << "It was not possible to open the file: tec.txt!" << endl;
getchar();
exit (-1);
}//if
else
{
tecfile.setf(ios::fixed);
tecfile.setf(ios::showpoint);
tecfile.setf(ios::right);
}
temp = outfile+"_I1L1.txt";
temp = outfile+"_I2L1.txt";
ofstream fstionoI2l1(temp.c_str());
if( fstionoI2l1.fail())
{
cout << "It was not possible to open the file: " << temp<< endl;
getchar();
exit (-1);
}//if
temp = outfile+"_I2L2.txt";
ofstream fstionoI2l2(temp.c_str());
if( fstionoI2l2.fail())
{
cout << "It was not possible to open the file: " << temp<< endl;
getchar();
exit (-1);
}//if
temp = outfile+"_I3L1.txt";
ofstream fstionoI3l1(temp.c_str());
if( fstionoI3l1.fail())
{
cout << "It was not possible to open the file: " << temp<< endl;
getchar();
exit (-1);
}//if
temp = outfile+"_I3L2.txt";
ofstream fstionoI3l2(temp.c_str());
if( fstionoI3l2.fail())
{
cout << "It was not possible to open the file: " << temp<< endl;
getchar();
exit (-1);
}//if
//Satellite elevation angle
temp = outfile+"_EleAngleSat.txt"; //MHA (may of 2013):File to print Satellite Elevation Angle
ofstream File_sateleangle(temp.c_str());
if( File_sateleangle.fail())
{
cout << "It was not possible to open the file: " << temp<< endl;
getchar();
exit (-1);
}//if
//MHA (may of 2013):File to print Cycle Slip
temp = outfile+"_CycleSlip.txt";
ofstream File_Cycleslip(temp.c_str());
if( File_Cycleslip.fail())
{
cout << "It was not possible to open the file: " << temp<< endl;
getchar();
exit (-1);
}//if
//---------------Configure output files-------------------------------------
fstionoI2l1.setf(ios::fixed); fstionoI2l2.setf(ios::fixed);
fstionoI2l1.setf(ios::showpoint); fstionoI2l2.setf(ios::showpoint);
fstionoI2l1.setf(ios::right); fstionoI2l2.setf(ios::right);
fstionoI3l1.setf(ios::fixed); fstionoI3l2.setf(ios::fixed);
fstionoI3l1.setf(ios::showpoint); fstionoI3l2.setf(ios::showpoint);
fstionoI3l1.setf(ios::right); fstionoI3l2.setf(ios::right);
File_sateleangle.setf(ios::fixed);
File_sateleangle.setf(ios::showpoint);
File_sateleangle.setf(ios::right);
File_Cycleslip.setf(ios::fixed);
File_Cycleslip.setf(ios::showpoint);
File_Cycleslip.setf(ios::right);
if(save_file) //MHA (may of 2013): Insert the print header file here
{
if(cont_epoch == 0)
{ //In the first epoch print the output file headers
string nome = filenameobs.substr(0,8);
tecfile<<setw(8)<<"h:m:s";
fstionoI2l1<<setw(8)<<"h:m:s";
fstionoI2l2<<setw(8)<<"h:m:s";
fstionoI3l1<<setw(8)<<"h:m:s";
fstionoI3l2<<setw(8)<<"h:m:s";
File_sateleangle<<setw(8)<<"h:m:s";
File_Cycleslip<<setw(8)<<"h:m:s";
for(int j=1;j<=32;j++)
{
if(j<10)
{ fstionoI2l1<<setw(12)<<"PRN0"<<j;
fstionoI2l2<<setw(12)<<"PRN0"<<j;
fstionoI3l1<<setw(12)<<"PRN0"<<j;
fstionoI3l2<<setw(12)<<"PRN0"<<j;
tecfile<<setw(12)<<"PRN0"<<j;
File_sateleangle<<setw(12)<<"PRN0"<<j;
File_Cycleslip<<setw(12)<<"PRN0"<<j;
}//if
else
{ fstionoI2l1<<setw(11)<<"PRN"<<j;
fstionoI2l2<<setw(11)<<"PRN"<<j;
fstionoI3l1<<setw(11)<<"PRN"<<j;
fstionoI3l2<<setw(11)<<"PRN"<<j;
tecfile<<setw(11)<<"PRN"<<j;
File_sateleangle<<setw(11)<<"PRN"<<j;
File_Cycleslip<<setw(11)<<"PRN"<<j;
}//else
}//for
tecfile<<endl;
fstionoI2l1<<endl;
fstionoI2l2<<endl;
fstionoI3l1<<endl;
fstionoI3l2<<endl;
File_sateleangle<<endl;
File_Cycleslip<<endl;
} //if(cont_epoch == 0)
}if(save_file)
cout <<"RINEX_HO - Program to read the RINEX, compute the TEC"<<endl
<<"and correct GPS data from 2nd and 3rd order ionospheric efffects" << endl<<endl
<<"Author: Haroldo Antonio Marques - 2009"<<endl
<<" Programa de Pos-Graduacao em Ciencias Cartograficas"<<endl
<<" Sao Paulo State University (Universidade Estadual Paulista) - FCT/UNESP"<<endl
<<" R. Roberto simonsen, 305 - Presidente Prudente - SP, Brazil"<<endl
<<" FAPESP Process: 05/03522-1"<<endl<<endl;
log <<"RINEX_HO - Program to read the RINEX, compute the TEC"<<endl
<<"and correct GPS data from 2nd and 3rd order ionospheric efffects" << endl<<endl
<<"Author: Haroldo Antonio Marques - 2009"<<endl
<<" Programa de Pos-Graduacao em Ciencias Cartograficas"<<endl
<<" Sao Paulo State University (Universidade Estadual Paulista) - FCT/UNESP"<<endl
<<" R. Roberto simonsen, 305 - Presidente Prudente - SP, Brazil"<<endl
<<" FAPESP Process: 05/03522-1"<<endl<<endl;
cout<<"*********************************************************************"<<endl<<endl;
log<<"**********************************************************************"<<endl<<endl;
cout<<"Navigation file: "<<filenamenav<<endl;
log<<"Navigation file: "<<filenamenav<<endl;
RinexFile *myFileNav = new RinexFile(); //class RinexFile
if( read_tec != 2) //if not to use GIM, read DCBs
{
Calc_Tec.Read_DCB_Sat(arqu_p1c1_sat,arqu_p1p2_sat);
log<<"DCBs read from "<<arqu_p1c1_sat<<" and "<<arqu_p1p2_sat<<": "<<endl;
log<<"PRN "<<setw(12)<<"P1C1(ns)"<<setw(12)<<"P1P2(ns)"<<endl;
for(int ik=0;ik<=32;ik++)
{
if(Calc_Tec.Get_P1C1(ik)!=0.0)
log<<setw(2)<< ik <<" "
<<setprecision(4)<<setw(12)<<Calc_Tec.Get_P1C1(ik)
<< " ";
if(Calc_Tec.Get_P1P2(ik)!=0.0)
log<<setprecision(4)<<setw(12)<<Calc_Tec.Get_P1P2(ik)<<endl;
}
}
//Reading broadcast ephemeris file
if(!ReadNavFile(currentPRNBlock,myFileNav,filenamenav,cont_efe_nav,log))
{ getchar();
exit(-1);
}//if
cout<<"Observation file: "<<filenameobs<<endl;
log<<"Observation file: "<<filenameobs<<endl;
if(read_tec==2)
{ cout<<"GIM File: "<<GIM_File<<endl;
log<<"GIM File: "<<GIM_File<<endl;
}
//------------------------------------------------------------------------------------------------------------
//Computing average phase bias for each stellite arc.
//The phase bias will be used to compute STEC from carrier levelled by code
if(read_tec==3)
Comp_Bias( filenameobs,Calc_Tec,Phase_Bias,File_Cycleslip);
//------------------------------------------------------------------------------------------------------------
RinexFile *myFile = new RinexFile(); //object from class RinexFile
try { //try to open rinex file
myFile->setPathFilenameMode( filenameobs, ios::in );
log<<" - Version "<<myFile->getFormatVersion()<<endl;
log<<"Satellite Sistem: "<<myFile->getSatSystem()<<endl;
log<<"Rinex Type: "<<myFile->getRinexFileType()<<endl;
log<<"Rinex Program: "<<myFile->getRinexProgram()<<endl;
log<<"Created by Agency: "<<myFile->getCreatedByAgency()<<endl;
//Type of file...
theObsFileType = myFile->getRinexFileType();
delete myFile;
myFile = 0;
}//try
catch( RinexFileException &openExcep )
{
cout << "Error opening file: " << filenameobs << endl
<< "Rinex File\"Exception:\" " << endl << openExcep.getMessage() << endl
<< "Exiting the program... " << endl << endl;
log << "Error opening file: " << filenameobs << endl
<< "Rinex File\"Exception:\" " << endl << openExcep.getMessage() << endl
<< "Exiting the program... " << endl << endl;
exit (-1);
}//catch
if( theObsFileType[0] == 'O' ) //check if it is observation file
{
RinexObsFile myobs; //RinexObsFile class
RinexObsFile mynewobs; //RinexObsFile class
ObsEpoch currentObsEpoch; //ObsEpoch class
try
{ //try to open observation file
myobs.setPathFilenameMode(filenameobs,ios_base::in);
}//try
catch( RinexFileException &openExcep )
{
cout << "Error opening file: " << filenameobs << endl
<< "Rinex File\"Exception:\" " << endl << openExcep.getMessage() << endl
<< "Exiting the program... " << endl << endl;
exit (-1);
}//catch
try
{ //try to open new observation file
mynewobs.setPathFilenameMode(newobsfile,ios_base::out);
}//try
catch( RinexFileException &openExcep )
{
cout<< "Error opening file: " << newobsfile << endl
<< "Rinex File\"Exception:\" " << endl << openExcep.getMessage() << endl
<< "Exiting the program... " << endl << endl;
log<< "Error opening file: " << newobsfile << endl
<< "Rinex File\"Exception:\" " << endl << openExcep.getMessage() << endl
<< "Exiting the program... " << endl << endl;
exit (-1);
}//catch
try
{ //Reading Header
myobs.readHeader();
if(X0!=0.0 && Y0!=0.0 && Z0!=0.0)
{
//Station Coordinates input by user
xest = X0;
yest = Y0;
zest = Z0;
}
else
{
//Station Coordinates from RINEX header
xest = myobs.getApproxX();
yest = myobs.getApproxY();
zest = myobs.getApproxZ();
}
//Cartesian to Geodetic Coordinates
calc_iono.Cart_Curv(xest,yest,zest,lat,lamb,h);
//Write out the header of new observations file
myobs.writeHeaderImage( mynewobs.outputStream );
}//try
catch( RequiredRecordMissingException &headerExcep )
{
cout << " RequiredRecordMissingException is: " << endl
<< headerExcep.getMessage() << endl;
log << " RequiredRecordMissingException is: " << endl
<< headerExcep.getMessage() << endl;
}//catch
// read the observation epochs
try
{
cout <<endl<< "Reading observation file and applying correction..." << endl;
cout << endl;
log <<endl<< "Reading observation file and applying correction..." << endl;
log << endl;
SatObsAtEpoch tempSatObsAtEpoch[NSAT];
int num = myobs.getNumObsTypes();
if(read_tec==2)
{
//Reading GIM file
Calc_Tec.ReadGIM(GIM_File);
if(Calc_Tec.Get_Gim_Flag() == 0)
{
cout<<"Problems Reading GIM File!"<<endl;
return 0;
}//if
else
cout<<"GIM File read succesfully!"<<endl;
}
//Decimal degrees
double lat_deg = lat*180.0/calc_iono.Get_PI();
double long_deg = lamb*180.0/calc_iono.Get_PI();
while( myobs.readEpoch( currentObsEpoch ) != 0 ) //read epochs
{
//print number of epochs in the screen
//For linux
// printf("\033[20;4f");
//for Windows
//gotoxy(10,20); //command not found in linux (#include <conio.h>)
cout<<"Epoch: "<<cont_epoch<<"..."<<endl;
if(cont_epoch==0)
epoca_ini_cs = true;
else
epoca_ini_cs = false;
num = myobs.getNumObsTypes();
calc_iono.Set_year(0);
calc_iono.Set_dayofyear(0);
calc_iono.Set_hour(0);
calc_iono.Set_min(0);
calc_iono.Set_sec(0.0);
calc_iono.Set_year(currentObsEpoch.getEpochTime().GetYMDHMS().year); //year
calc_iono.Set_month(currentObsEpoch.getEpochTime().GetYMDHMS().month); //month
calc_iono.Set_day(currentObsEpoch.getEpochTime().GetYMDHMS().day); //day
calc_iono.Set_dayofyear(currentObsEpoch.getEpochTime().GetYDOYHMS().dayOfYear); //day of year
calc_iono.Set_hour(currentObsEpoch.getEpochTime().GetYMDHMS().hour); //hours
calc_iono.Set_min(currentObsEpoch.getEpochTime().GetYMDHMS().min); //minutes
calc_iono.Set_sec(currentObsEpoch.getEpochTime().GetYMDHMS().sec); //seconds
segweek = currentObsEpoch.getEpochTime().GetGPSTime().secsOfWeek; //seconds of week
//GPS Reception time in MJD
double MJD = currentObsEpoch.getEpochTime().GetMJD().mjd,
fracOfDay = currentObsEpoch.getEpochTime().GetMJD().fracOfDay;
//Start some arrays
zera_vetor(TECM,NSAT);
zera_vetor(i2m_l1,NSAT);
zera_vetor(i2m_l2,NSAT);
zera_vetor(i3m_l1,NSAT);
zera_vetor(i3m_l2,NSAT);
zera_vetor(EleAngSat,NSAT);
zera_vetor(AzAngSat,NSAT);
if(read_tec==2)
{
//Check if GIM time match with Obs file
if(cont_epoch==0)
if( fabs( (MJD+fracOfDay) - Calc_Tec.Get_Epoch_First_MAP() ) > (2.0/24.0) ) //||
//fabs( (MJD+fracOfDay) - Calc_Tec.Get_Epoch_Last_Map()) > (2.0/24.0) )
{
cout<<"GIM file doesn't match with RINEX file!"<<endl;
return 0;
}//if
/* SH, move this to a loop over satellite (need one IPP, and VTEC, for each satellite!)
VTEC = 0.0;
//Interpolate TEC for MJD+fracOfDay
if(! Calc_Tec.CalcTecEpoch(MJD,fracOfDay,lat_deg,long_deg) )
{
log<<"Without TEC information from GIM "
<<"in the epoch: "<<calc_iono.Get_hour()<<" "
<<calc_iono.Get_min()<<" "
<<calc_iono.Get_sec()<<endl;
return 0;
}//if
else
{
VTEC = Calc_Tec.GetVTEC();
}//else
*/
}//if
//Reception time in seconds of week
tr = segweek;
//start obs arrays
zera_vetor(ca,NSAT);
zera_vetor(p1,NSAT);
zera_vetor(p2,NSAT);
zera_vetor(c2,NSAT);
zera_vetor(c5,NSAT);
zera_vetor(ph1,NSAT);
zera_vetor(ph2,NSAT);
zera_vetor(ph5,NSAT);
zera_vetor(Isat,NSAT);
zera_vetor(Pos_GPS_CurrObs,NSAT);
int numobstype = myobs.getNumObsTypes();
//number of satelites from file
NS = (unsigned short) currentObsEpoch.getNumSat();
Ns_temp = NS;
count_sat_out=0;
for (int i = 0; i < NS; i++ )
{
SatCode = "";
SatCode = currentObsEpoch.getSatListElement(i).satCode; //Satellite Code
int ptr = strcmp(SatCode.c_str(),"G"); //G for GPS satellites
int ptr1 = strcmp(SatCode.c_str()," ");
if( (ptr == 0 || ptr1 ==0) && currentObsEpoch.getSatListElement(i).satNum != 9999)//Only GPS satellites
{
int pos = i-count_sat_out;
Isat[pos] = currentObsEpoch.getSatListElement(i).satNum;
Pos_GPS_CurrObs[pos]=i;
//Store observations in arrays
StoreObsVector( numobstype,
currentObsEpoch,
ph1, //phase L1
ph2, //phase L2
ca, // C/A code
p1, //P1 code
p2, //P2 code
c2, //L2C code - not being used
c5, //C5 code - not being used
ph5, //phase L5 - not being used
pos);
}//if
else
{
Ns_temp--;
count_sat_out++;
//...
//if you want to store GLONASS for example insert your code here
}//else */
}//for
NS = Ns_temp; //number of GPS satelite
//-------DCB corrections for P1-----------------------------------
//Added by MHA (may of 2013)
//Applying DCB P1-C1 to compatibilize CA with P1
//DCBs p1c1 are not more applied inside the subroutine Calc_STEC_PR
for(int i=0;i<NS;i++){
int PRN = Isat[i];
if(PRN && p1[i]==0.0 && ca[i]!=0.0)
{
double p1c1 = Calc_Tec.Get_P1C1(PRN);
p1[i] = ca[i]+c*p1c1*1.0e-9;
}
}//for
/* We can do the same for L2C and P2, but p2c2 must be read from CODE files for example
for(int i=0;i<NS;i++){
int PRN = isat[i];
if(p2[i]==0.0 && c2[i]!=0.0)
p2[i] = c2[i]+c*p2c2[PRN]*1.0e-9;
}//for
*/
//---------//check-out for cycle slips-------------------
if(read_tec==1) //smothed pseudorange by phase
{
for (int i = 0; i < NS; i++ )
{ //int PRN = currentObsEpoch.getSatListElement(i).satNum;
int PRN = Isat[i];
if(p1[i] != 0.0 && p2[i] != 0.0 && ph1[i] !=0.0 && ph2[i] != 0.0)
{
wlslip = nlslip = FALSE;
//log << "------------------ " << PRN << " "
// << currentObsEpoch.getEpochTime().GetYMDHMS().hour << ":"
// << currentObsEpoch.getEpochTime().GetYMDHMS().min << ":"
// << (int) currentObsEpoch.getEpochTime().GetYMDHMS().sec << endl;
//log << "== step1: " << endl;
//log << "wlbias: " << CycleSlip[PRN].Get_wlbias() << endl;
//log << "sig_wlbias: " << CycleSlip[PRN].Get_sig_wlbias() << endl;
//log << "diff_wl: " << CycleSlip[PRN].Get_diff_wl() << endl;
//log << "flag: " << CycleSlip[PRN].Get_flag() << endl;
//log << "count: " << CycleSlip[PRN].Get_count() << endl;
CycleSlip[PRN].Wide_Cycle_Slip( ph1[i], //PHL1[PRN],
ph2[i], //PHL2[PRN],
p1[i], //p1[PRN],
p2[i], //P2[PRN],
epoca_ini_cs);
//log << "== step2: " << endl;
//log << "wlbias: " << CycleSlip[PRN].Get_wlbias() << endl;
//log << "sig_wlbias: " << CycleSlip[PRN].Get_sig_wlbias() << endl;
//log << "diff_wl: " << CycleSlip[PRN].Get_diff_wl() << endl;
//log << "flag: " << CycleSlip[PRN].Get_flag_wl() << endl;
//wlslip = CycleSlip[PRN].Get_flag_wl();
// log << "count: " << CycleSlip[PRN].Get_count() << endl;
/* if( CycleSlip[PRN].Get_flag_wl() )
{
log << "::: PRN:" << setw(2) << setfill('0') << PRN << " HMS: "
<< setw(2) << currentObsEpoch.getEpochTime().GetYMDHMS().hour << ":"
<< setw(2) << currentObsEpoch.getEpochTime().GetYMDHMS().min << ":"
<< setw(2) << (int) currentObsEpoch.getEpochTime().GetYMDHMS().sec << " difWL: "
<< setw(9) << setprecision(2) << setfill(' ') << CycleSlip[PRN].Get_diff_wl() << endl;
}//if
*/
CycleSlip[PRN].WN_Cycle_Slip(ph1[i], //PHL1[PRN],
ph2[i], //PHL2[PRN],
p1[i], //p1[PRN],
p2[i], //P2[PRN],
epoca_ini_cs);
/* log << "== step3: " << endl;
log << "wlbias: " << CycleSlip[PRN].Get_wlbias() << endl;
log << "sig_wlbias: " << CycleSlip[PRN].Get_sig_wlbias() << endl;
log << "diff_wl: " << CycleSlip[PRN].Get_diff_wl() << endl;
log << "flag: " << CycleSlip[PRN].Get_flag() << endl;
nlslip = CycleSlip[PRN].Get_flag();
log << "count: " << CycleSlip[PRN].Get_count() << endl;
if( wlslip == FALSE && nlslip == TRUE )
{
log << "::> PRN:" << setw(2) << setfill('0') << PRN << " HMS: "
<< setw(2) << currentObsEpoch.getEpochTime().GetYMDHMS().hour << ":"
<< setw(2) << currentObsEpoch.getEpochTime().GetYMDHMS().min << ":"
<< setw(2) << (int) currentObsEpoch.getEpochTime().GetYMDHMS().sec << " difWL: "
<< setw(9) << setprecision(2) << setfill(' ') << CycleSlip[PRN].Get_diff_wl()
<< " NL flag set!" << endl;
}//if
*/
}//if
}//for
File_Cycleslip<<setw(2)<<setfill('0')<<calc_iono.Get_hour()<<":"
<<setw(2)<<setfill('0')<<calc_iono.Get_min()<<":"
<<setw(4)<<setfill('0')<<setprecision(1)<<calc_iono.Get_sec();
File_Cycleslip<<setfill(' ');
for(int j=1;j<=32;j++)
{
int PRN = j;
wlslip = CycleSlip[PRN].Get_flag_wl(); //flag for wide lane
nlslip = CycleSlip[PRN].Get_flag_nl(); //flag for narrow lane
if(wlslip==true)
File_Cycleslip<<setw(13)<<setprecision(6)<<CycleSlip[PRN].Get_diff_wl();
else if(nlslip==true)
File_Cycleslip<<setw(13)<<setprecision(6)<<CycleSlip[PRN].Get_diff_nl();
else File_Cycleslip<<setw(13)<<setprecision(6)<<9999999;
}
File_Cycleslip<<endl;
}
//------------------------------------------------------------------------------
//----------//Tec from pseudorange smothed by phase----------------------------
if(read_tec==1)
{
for(int ij=0;ij<NSAT;ij++)
{ smoothed_code[ij][0] = 0.0;
smoothed_code[ij][1] = 0.0;
}
int iono = 1; // 1 to use smooth P1 and P2 and 2 for ionosphere free
double UTTAG = double(currentObsEpoch.getEpochTime().GetGPSTime().GPSWeek*604800.0 +
currentObsEpoch.getEpochTime().GetGPSTime().secsOfWeek);
for (int i = 0; i < NS; i++ )
{
int PRN = Isat[i];
//Start cycle slip
if(CycleSlip[PRN].Get_flag_wl()==true || CycleSlip[PRN].Get_flag_nl()==true)
{
CycleSlip[PRN].Start_CycleSlip();
if(PRN>0 && PRN <=32)
FilterObs[PRN].Set_cont_epoch(0); //it means that smoothing filter will be re-initialized in the next epoch
}//if
else if(p1[i] != 0.0 && p2[i] != 0.0 && ph1[i] !=0.0 && ph2[i] != 0.0)
{
if( epoca_ini_cs ||
(CycleSlip[PRN].Get_flag_wl()==true || CycleSlip[PRN].Get_flag_nl()==true) ||
FilterObs[PRN].Get_cont_epoch() == 0)
{
//Start Filter code
FilterObs[PRN].Start_Smooth_Code( UTTAG,
p1[i], //p1[PRN],
p2[i], //P2[PRN],
ph1[i], //PHL1[PRN],
ph2[i], //PHL2[PRN],
var_ca,
var_p2,
iono);
//Start cycle slip
if(CycleSlip[PRN].Get_flag_wl()==true || CycleSlip[PRN].Get_flag_nl()==true)
CycleSlip[PRN].Start_CycleSlip();
}//if
else
{
FilterObs[PRN].Filter_Obs( UTTAG,
p1[i], //p1[PRN],
p2[i], //P2[PRN],
ph1[i], //PHL1[PRN],
ph2[i], //PHL2[PRN],
var_ca,
var_p2,
var_ph1,
var_ph2,
iono );
}//else
if( FilterObs[PRN].Get_quality() )
{
if(iono==2) //ion-free
{
smoothed_code[PRN][0] = FilterObs[PRN].Get_p1_filt();
}
else
{ smoothed_code[PRN][0] = FilterObs[PRN].Get_p1_filt();
smoothed_code[PRN][1] = FilterObs[PRN].Get_p2_filt();
}//else
}//if
else
{
FilterObs[PRN].Start_Smooth_Code( UTTAG,
p1[i], //p1[PRN],
p2[i], //P2[PRN],
ph1[i], //PHL1[PRN],
ph2[i], //PHL2[PRN],
var_ca,
var_p2,
iono);
if(iono==2) //ion-free
{
smoothed_code[PRN][0] = FilterObs[PRN].Get_p1_filt();
}
else //CA and P2
{ smoothed_code[PRN][0] = FilterObs[PRN].Get_p1_filt();
smoothed_code[PRN][1] = FilterObs[PRN].Get_p2_filt();
}
}//else
}//if(p1[i] != 0.0 && p2[i] != 0.0 && ph1[i] !=0.0 && ph2[i] != 0.0)
else
{ //Enter here if there are no data available to smothing filter
if(PRN>0 && PRN <=32){
// FilterObs[PRN].Set_cont_epoch(0);
smoothed_code[PRN][0] = Old_smoothed_code[PRN][0];
smoothed_code[PRN][1] = Old_smoothed_code[PRN][1];
}
}//else
}//for
//Store current code smoothed by phase
for(int ij=0;ij<NSAT;ij++)
{
Old_smoothed_code[ij][0] = smoothed_code[ij][0];
Old_smoothed_code[ij][1] = smoothed_code[ij][1];
}//for
}// if(read_tec==1) //Tec from pseudorange smothed by phase
//----------------------------------------------------------------------------
for (int i = 0; i < NS; i++ )
{
calc_iono.Set_I1_L1(0.0);
calc_iono.Set_I1_L2(0.0);
//calc_iono.Set_I1_L5(0.0);
calc_iono.Set_I2_L1(0.0);
calc_iono.Set_I2_L2(0.0);
//calc_iono.Set_I2_L5(0.0);
calc_iono.Set_I3_L1(0.0);
calc_iono.Set_I3_L2(0.0);
//calc_iono.Set_I3_L5(0.0);
if(ca[i]!=0.0) //if there are data for CA
{
prn = Isat[i];
int k =0;
xs=0.0,ys=0.0,zs=0.0,dxs=0.0,dys=0.0,dzs=0.0;
while(k<cont_efe_nav)
{
if ( (prn == currentPRNBlock[k].getSatellitePRN()) &&
(fabs(tr - currentPRNBlock[k].getToe())< 7200.0) )
{
//store ephemeris to compute orbit
double toe = currentPRNBlock[k].getToe(), //TOE --> TIME ORIGIN EPHEMERIS:
ra = currentPRNBlock[k].getSqrtA(), //A --> SQUARE ROOT SEMI MAJOR AXIS AT TOE:
i0 = currentPRNBlock[k].getIo(), //RI0 --> INCLINATION AT TOE:
idot = currentPRNBlock[k].getIdot(), //DRI --> RATE OF INCLINATION:
dn = currentPRNBlock[k].getDeltan(), //DN --> CORRECTION OF MEAN MOTION:
m0 = currentPRNBlock[k].getMo(), //CM0 --> MEAN ANOMALY AT TOE:
e = currentPRNBlock[k].getEccen(), //E --> ECCENTRICITY:
omega = currentPRNBlock[k].getLilOmega(),//W --> ARGUMENT OF PERIGEE:
cus = currentPRNBlock[k].getCus(), //Cus --> AMPLITUDE OF THE SINE HARMONIC CORRECTION TERM TO THE ARGUMENT OF LATITUDE:
cuc = currentPRNBlock[k].getCuc(), //Cuc --> IBID COSINE:
crs = currentPRNBlock[k].getCrs(), //Crs --> AMPLITUDE OF THE SINE HARMONIC CORRECTION TERM TO THE ORBITS RADIUS:
crc = currentPRNBlock[k].getCrc(), //Crc --> IBID COSINE:
cis = currentPRNBlock[k].getCis(), //Cis --> AMPLITUDE OF THE SINE HARMONIC CORRECTION TERM TO THE INCLINATION ANGLE:
cic = currentPRNBlock[k].getCic(), //Cic --> IBID COSINE:
omega0 = currentPRNBlock[k].getBigOmega(), //W0 --> RIGHT ASCENSION AT REFERENCE TIME:
omegadot = currentPRNBlock[k].getBigOmegaDot(), //WD --> RATE OF RIGHT ASCENCION:
dt = 0.0;
/* ---- this method to compute tt may be affected by pseudorange multipath
---- and it does not include the Sagnac effect!
double tau = ca[i]/c;
double tt = tr - tau; //~ transmission time
//Satellite coordinates and velocities
sat_pos_vel(tt, toe,dt,ra,i0,idot,dn,m0, e,omega,cus,cuc,crs,crc,cis,
cic,omega0,omegadot,xs,ys,zs,dxs,dys,dzs);
*/
//------
//Get initial approx Satellite coordinates and velocities (at tr)
sat_pos_vel( tr, toe,dt,ra,i0,idot,dn,m0, e,omega,cus,cuc,crs,crc,cis,
cic,omega0,omegadot,xs,ys,zs,dxs,dys,dzs);
// Use Gerry's combined light loop and Sagnac code from Mergedb
//omega_e = 7.2921158553e-05;
//we is a const variable defined in the constant.h file
dx = xs - xest;
dy = ys - yest;
dz = zs - zest;
dsv_sq = ( (dx*dx) + (dy*dy) + (dz*dz) );
sv_range = sqrt( dsv_sq );
for( k = 0; k < 4; k++ )
{
propagationDelay = (-1.0 * sv_range)/c;
dtom = propagationDelay * we; //tau*we //we is a const variable defined in the constant.h file
usx = xs + dxs*propagationDelay;
usy = ys + dys*propagationDelay;
svx = usx*cos(dtom) - usy*sin(dtom);
svy = usy*cos(dtom) + usx*sin(dtom);
svz = zs + dzs*propagationDelay;
dx = svx - xest;
dy = svy - yest;
dz = svz - zest;
dsv_sq = ( (dx*dx) + (dy*dy) + (dz*dz) );
sv_range = sqrt( dsv_sq );
}
//double tt= tr + propagationDelay;
//coordinates at transmission time and corrected from sagnac effects
xs = svx;
ys = svy;
zs = svz;
/* cout << "PRN, LL_SVxyz: " << prn << endl
<< setw(30) << setprecision(5) << xs << endl
<< setw(30) << setprecision(5) << ys << endl
<< setw(30) << setprecision(5) << zs << endl;
getchar();
*/
//--------
//Elevation angle and azimuth of satellite
Sat_Angle( lat,lamb,xs,ys,zs,
xest,yest,zest,
EleAngSat[prn],AzAngSat[prn]);
double Ang_Dec = EleAngSat[prn]*180.0/PI;
if(Ang_Dec > Mask_Ele) //if elevation angle greater than elevation mask
{
//One possibility is to use TGD from broadcast ephemeris
//double TGD = currentPRNBlock[k].getTgd();
//double Bp1p2 = c*(TGD/(-1.0*calc_tec.Get_m2()));
switch(read_tec){
case 0: //TEC from raw pseudorange
//One possibility to correct from DCBs is to use TGD from broadcast ephemeris
//double TGD = currentPRNBlock[k].getTgd();
//double Bp1p2 = c*(TGD/(-1.0*calc_tec.Get_m2()));
STEC = 0.0;
if(p1[i]!=0.0 && p2[i]!=0.0)
{
//Compute slant TEC from Pseudorange
STEC = Calc_Tec.Calc_STEC_PR(p1[i],p2[i],prn);
}
if(STEC<0){
//Sometimes, mainly for low ionospheric activities period, we get negative TEC from pseudorange
//Then, warning user
log<<"Warning: "<<"Satellite "<<setw(3)<<prn<<" - Negative STEC ( "<<setprecision(4)<<setw(10)<<STEC<<" ) from Pseudorange in the epoch : "<<cont_epoch<<"..."<<endl;
log<<"Difference between CA and P2: "<<p1[i]-p2[i]<<endl;
}//if
if( STEC != 0.0) //Compute Second and third order ionospheric effects
calc_iono.Calc_Iono(STEC,read_tec,MJD,fracOfDay,xs,ys,zs,
xest,yest,zest,lat,lamb,h,
Geomag_Type,Name_IGRF_Model);
break;
case 1: //TEC from pseudorange smoothed by phase
STEC = 0.0;
if(smoothed_code[prn][0]!=0.0 && smoothed_code[prn][1]!=0.0){
//Wait almost 2 epochs until the smoothing filter get good values for smoothed pseudorange
//when there is cycle slip sometimes we will see gaps in the higher order iono time series due to STEC missig
if(FilterObs[prn].Get_cont_epoch() > 2){
//Compute slant TEC from Smoothed Pseudorange
STEC = (Calc_Tec.Calc_STEC_PR(smoothed_code[prn][0],smoothed_code[prn][1],prn));
}
if(STEC<0){
//Sometimes, mainly for low ionospheric activies periods, we got negative TEC from pseudorange
//warning user
log<<"Warning: "<<"Satellite "<<setw(3)<<prn<<" - Negative STEC ( "<<setprecision(4)<<setw(10)<<STEC<<" ) from Pseudorange in the epoch : "<<cont_epoch<<"..."<<endl;
log<<"Difference between CA and P2: "<<p1[i]-p2[i]<<endl;
}//if
if(STEC != 0.0) //Compute Second and third order ionospheric effects
calc_iono.Calc_Iono(STEC,read_tec,MJD,fracOfDay,xs,ys,zs,
xest,yest,zest,lat,lamb,h,
Geomag_Type,Name_IGRF_Model);
}//if
break;
case 2: //TEC from GIM (now get a VTEC for each IPP, each satellite)
VTEC = 0.0;
calc_iono.azelIPP( xest,yest,zest,xs,ys,zs,6371000.0,450000.0,
&sh_az,&sh_elv,&sh_dist,&sh_pplat,&sh_pplon,&sh_zp);
// calc_iono.Pierce_Point_Coord(xest,yest,zest,xs,ys,zs,lat,lamb,h);
//Marques, H. A.
//lat. and long. of IPP in degrees
lat_IPP_deg = sh_pplat*180.0/PI;
lon_IPP_deg = sh_pplon*180.0/PI;
//Interpolate TEC for MJD+fracOfDay
//**SH** if(! Calc_Tec.CalcTecEpoch(MJD,fracOfDay,lat_deg,long_deg) )