-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathClass_TEC.cpp
1504 lines (1237 loc) · 51.5 KB
/
Class_TEC.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: class to Read GIM interpolate TEC or compute TEC from Pseudorange
-------------------------------------------------------------------
Input:
Output:
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP - Brazil
Date: January of 2010
-------------------------------------------------------------------
Observation:
-------------------------------------------------------------------*/
#include "Class_TEC.h" // class's header file
namespace CTEC{
Class_TEC::Class_TEC()
{ // class constructor
//Default values
Re = 6371000.0;
hion = 450000.0;
Num_Value = 0; //Number of data read in the GIM file
for(int i =0;i<NSAT;i++)
{ p1p2[i][0] = 0.0;
p1c1[i][0] = 0.0;
p1p2[i][1] = 0.0;
p1c1[i][1] = 0.0;
s_tec[i] = 0.0;
}//for
br=0.0; //receiver hardware delay - DCB(P1-P2) (m)
sbr=0.0; //standard deviation of the reciever DCB(P1-P2)
}
//------------------------------------------------------------------------------------
Class_TEC::Class_TEC( double sigca = 0.6,double sigp2=0.8,
double sigph1=0.006,double sigph2=0.008,
double dcbr=0,double sdcbr=0)
{/*-------------------------------------------------------------------
Purpose: Class constructor
-------------------------------------------------------------------
Input:
Output:
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP
FAPESP PROCESS: 05/03522-1
Date: July of 2010
-------------------------------------------------------------------
Observation:
-------------------------------------------------------------------*/
//Default values
Re = 6371000.0;
hion = 450000.0;
Num_Value = 0; //Number of data read in the GIM file
var_ca = pow(sigca,2); //variance of CA - meter
var_p2 = pow(sigp2,2); //variance of P2 - meter
var_ph1 = pow(sigph1,2); //variance of Phase L1 - meter
var_ph2 = pow(sigph2,2); //variance of Phase L2 - meter
br = dcbr; //receiver hardware delay
sbr = sdcbr; //standard deviation of receiver hardware delay
for(int i =0;i<NSAT;i++)
{ p1p2[i][0] = 0.0;
p1c1[i][0] = 0.0;
p1p2[i][1] = 0.0;
p1c1[i][1] = 0.0;
s_tec[i] = 0.0;
}//for
}
//------------------------------------------------------------------------------------
Class_TEC::~Class_TEC()
{ // class destructor
// insert your code here
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_ZL()
{ //zenith angle at the pierce point
//unit: rad
return(zl);
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_LatIon()
{
return(lat_ion); //Latitude at pierce point
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_LambIon()
{
return(lamb_ion); //Longitude at pierce point
}
//------------------------------------------------------------------------------------
int Class_TEC::Get_Gim_Flag()
{
return(Gim_Flag);
}
//------------------------------------------------------------------------------------
double Class_TEC::GetVTEC()
{
return(VTEC); //Vertical TEC
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Epoch_First_MAP()
{
return (Epoch_First_MAP); //in MJD
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Epoch_Last_Map()
{
return (Epoch_Last_Map); //in MJD
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Interval()
{
return (Interval); //Seconds
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Ini_Lat()
{
return (Ini_Lat); //in Degrees
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_End_Lat()
{
return (End_Lat); //in Degrees
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Lat_Increment()
{
return (Lat_Increment); //in Degrees
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Ini_Lon()
{
return (Ini_Lon); //in Degrees
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_End_Lon()
{
return (End_Lon); //in Degrees
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Lon_Increment()
{
return (Lon_Increment); //in Degrees
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Elevation_Cuttof()
{
return (Elevation_Cuttof); //in Degrees
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Base_Radius()
{
return (Base_Radius); //in Km
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Ini_Height()
{
return (Ini_Height); //in Km
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_End_Height()
{
return (End_Height); //in Km
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_Height_Incremet()
{
return (Height_Incremet); //in km
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_P1P2(int prn)
{/*-------------------------------------------------------------------
Purpose: Return satellite P1-P2 hardware delay (ns)
-------------------------------------------------------------------
Input: prn - Satellite number
Output:
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP
FAPESP PROCESS: 05/03522-1
Date: July of 2010
-------------------------------------------------------------------
Observation:
-------------------------------------------------------------------*/
return(p1p2[prn][0]);
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_P1C1(int prn)
{/*-------------------------------------------------------------------
Purpose: Return satellite P1-C1 hardware delay (ns)
-------------------------------------------------------------------
Input: prn - Satellite number
Output:
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP
FAPESP PROCESS: 05/03522-1
Date: July of 2010
-------------------------------------------------------------------
Observation:
-------------------------------------------------------------------*/
return(p1c1[prn][0]);
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_S_TEC(int prn)
{/*-------------------------------------------------------------------
Purpose: Return standard deviation of STEC
-------------------------------------------------------------------
Input: prn - Satellite PRN
Output:
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP
FAPESP PROCESS: 05/03522-1
Date: July of 2010
-------------------------------------------------------------------
Observation:
-------------------------------------------------------------------*/
return (s_tec[prn]);
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_br() //receiver hardware delay
{
return(br);
}
//------------------------------------------------------------------------------------
double Class_TEC::Get_sbr()
{
return(sbr);
}
//------------------------------------------------------------------------------------
void Class_TEC::Set_var_ca(double value)
{
var_ca = value;
}
//------------------------------------------------------------------------------------
void Class_TEC::Set_var_p2(double value) //variances for CA and P2
{
var_p2 = value;
}
//------------------------------------------------------------------------------------
void Class_TEC::Set_var_ph1(double value)
{
var_ph1 = value;
}
//------------------------------------------------------------------------------------
void Class_TEC::Set_var_ph2(double value) //variances for phase L1 and phase L2
{
var_ph2 = value;
}
//------------------------------------------------------------------------------------
void Class_TEC::Set_br(double value) //receiver hardware delay
{
br = value;
}
//------------------------------------------------------------------------------------
void Class_TEC::Set_sbr(double value)
{
sbr = value;
}
//------------------------------------------------------------------------------------
double Class_TEC::Mean_Phase_Code(double ph1, double ph2, double p1, double p2,
double &Mean_Diff_Li_Pi,double &Last_Diff_Li_Pi,int &Count_Mean,
int &arc_number,int initial_epoch,bool Cycle_Slip_Flag,int prn )
{ double Li(0.0),Pi(0.0),Curr_Diff_Li_Pi(0.0),Curr_Last_Diff(0.0);
double f1_quad = pow(freq1,2),
f2_quad = pow(freq2,2),
alfa = 1.0/( 40.309*(1.0/f2_quad-1.0/f1_quad) ),
//values in meters
Bsm = c*(p1p2[prn][0]*1.0e-9), //satellite p1-p2 DCB
Brm = c*(br*1.0e-9); //receiver DCB
/* di2d1=f1_quad/(f1_quad-f2_quad),
di2d2=f2_quad/(f1_quad-f2_quad),
d1 = di2d1*(Brm+Bsm),
d2 = di2d2*(Brm+Bsm),
di = d2-d1;
*/
Li = wlf1*ph1 - wlf2*ph2; // Geomery free phase (meters)
Pi = (p2 - p1); // Geometry free pseudorange (meters)
Curr_Diff_Li_Pi = Li - Pi - (Brm+Bsm); //time-average phase - code - dcb
if(Cycle_Slip_Flag)
{ //it means that mean filter will be re-initialized in the next epoch
Count_Mean=0;
Mean_Diff_Li_Pi = Curr_Diff_Li_Pi = Last_Diff_Li_Pi = 0.0;
}
else if (initial_epoch==0 || Count_Mean==0) //first epoch or starting new computation
{
Mean_Diff_Li_Pi = Curr_Diff_Li_Pi;
Last_Diff_Li_Pi = Mean_Diff_Li_Pi; //Diff Phase and code to be used in the next epoch
Count_Mean=1;
arc_number++;
}//if
else
{
Count_Mean++; //current number of points in the data arc
Curr_Last_Diff = Curr_Diff_Li_Pi - Last_Diff_Li_Pi; //difference form current and last epoch
Mean_Diff_Li_Pi = Last_Diff_Li_Pi + (Curr_Last_Diff/Count_Mean); //Mean filter <Li - Pi>
Last_Diff_Li_Pi = Mean_Diff_Li_Pi; //Diff Phase and code to be used in the next epoch
}//else
return (Mean_Diff_Li_Pi);
}
//------------------------------------------------------------------------------------
long double Class_TEC::Calc_STEC_PH_PR(double ph1, double ph2,double p1,double p2,double Mean_Diff_Li_Pi,int prn )
{
double Li(0.0),Pi(0.0),Curr_Diff_Li_Pi(0.0),STEC(0.0);
double f1_quad = pow(freq1,2),
f2_quad = pow(freq2,2),
alfa = 1.0/( 40.309*(1.0/f2_quad-1.0/f1_quad) );
/* //values in meters
Bsm = c*(p1p2[prn][0]*1.0e-9), //satellite p1-p2 DCB
Brm = c*(br*1.0e-9), //receiver DCB
di2d1=f2_quad/(f1_quad-f2_quad),
di2d2=f1_quad/(f1_quad-f2_quad),
d1 = di2d1*(Brm+Bsm),
d2 = di2d2*(Brm+Bsm),
di = d2-d1;
*/
Li = wlf1*ph1 - wlf2*ph2; // Geomery free phase (meters)
//slant TEC in the first epoch from =pseudorange
// STEC = alfa*( Li - Mean_Diff_Li_Pi + Brm + Bsm );
STEC = alfa*( Li - Mean_Diff_Li_Pi );
// double teste = Calc_STEC_PR(p1,p2,prn);
return (STEC); //return STEC value
}
//------------------------------------------------------------------------------------
long double Class_TEC::Calc_STEC_PR(double P1,double P2,int prn)
{/*-------------------------------------------------------------------
Purpose: Compute slant TEC STEC from raw pseudorange CA and P1
-------------------------------------------------------------------
Input:
Output:
-------------------------------------------------------------------
Author: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP, Brazil
FAPESP PROCESS: 05/03522-1
Date: July of 2007
-------------------------------------------------------------------
Observation: DCB P1-C1 applied to CA to compatibilize CA with P1
-------------------------------------------------------------------*/
double c = 299792458.0;
double f1_quad = pow(freq1,2),
f2_quad = pow(freq2,2),
alfa = (f1_quad*f2_quad)/(40.309*(f2_quad-f1_quad)),
//values in meters
Bsm = c*(p1p2[prn][0]*1.0e-9), //satellite p1-p2 DCB
Brm = c*(br*1.0e-9); //receiver DCB
double var_bsm = pow(p1p2[prn][1],2), //P1-P2 rms
var_brm = pow(sbr,2); //DCBr rms
long double Stec=0.0,var_tec=0.0;
//slant TEC from pseudorange
Stec = alfa*( (P1 - P2) - Brm - Bsm );
//Computing Standard Deviation of TEC
var_tec = pow(alfa,2)*(var_ca + var_p2 + var_brm + var_bsm ); //(ele/m^2)
s_tec[prn] = sqrt(var_tec);
return (Stec); //return STEC value
}
//------------------------------------------------------------------------------------
void Class_TEC::Read_DCB_Sat(char arqu_p1c1[],char arqu_p1p2[])
{/*-------------------------------------------------------------------
Purpose: Read DCBs (P1-P2) and (P1-C1) from CODE files
-------------------------------------------------------------------
Input:
Output:
-------------------------------------------------------------------
Author: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP, Brazil
FAPESP PROCESS: 05/03522-1
Date: July of 2007
-------------------------------------------------------------------
Observation:
-------------------------------------------------------------------*/
char temp[500]={"\0"};
string linha;
int prn;
int Start_Col_DCB,Start_Col_RMS;
ifstream arqu1(arqu_p1c1);
ifstream arqu2(arqu_p1p2);
if(arqu1.fail())
{
cout<<"It was not possible to open DCB File: "<< arqu_p1c1<< " in Read_DCB_Sat subroutine."<<endl;
exit(-1);
}//if
if(arqu2.fail() )
{
cout<<"It was not possible to open DCB File: "<< arqu_p1p2<< " in Read_DCB_Sat subroutine."<<endl;
exit(-1);
}//if
while(!arqu1.eof())
{
//get line from P1-C1 file
arqu1.getline(temp,500);
linha = temp;
int j = linha.substr(0,3).compare("PRN");
if(j==0)
{ //Find the collun where are the DCBs!
Start_Col_DCB = linha.find("VALUE (NS)");
Start_Col_RMS = linha.find("RMS (NS)");
}//if
int i = linha.substr(0,1).compare("G");
if(i==0)
{
prn = atoi(linha.substr(1,2).c_str());
if(prn>=1&&prn<=32){ //only GPS
p1c1[prn][0]=atof(linha.substr(Start_Col_DCB,10).c_str()); //Read P1-C1
p1c1[prn][1]=atof(linha.substr(Start_Col_RMS,10).c_str()); //Read P1-C1 RMS
}//if
}
}//while
while(!arqu2.eof())
{
//get line from P1-P2 file
arqu2.getline(temp,500);
linha = temp;
int j = linha.substr(0,3).compare("PRN");
if(j==0)
{ //Find the collun where are the DCBs!
Start_Col_DCB = linha.find("VALUE (NS)");
Start_Col_RMS = linha.find("RMS (NS)");
}//if
int i = linha.substr(0,1).compare("G");
if(i==0)
{
prn = atoi(linha.substr(1,2).c_str());
if(prn>=1&&prn<=32){ //only GPS
p1p2[prn][0] = atof(linha.substr(Start_Col_DCB,10).c_str()); //Read P1-P2
p1p2[prn][1] = atof(linha.substr(Start_Col_RMS,10).c_str()); //Read P1-P2 RMS
}//if
}
}
}
//------------------------------------------------------------------------------------
double Class_TEC::DJUL(int Year,int Month, double t)
{/*-------------------------------------------------------------------
Purpose: To Compute Julian Date
-------------------------------------------------------------------
Input: Year
Month
t = DAY+HOUR/24.0+MIN/1440.0+SEC/86400.0
Output: Julian date
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP
Date: January of 2010
-------------------------------------------------------------------
Observation:
-------------------------------------------------------------------*/
int i, j, k, m;
double djul;
j = Year;
m = Month;
if( m <= 2 )
{
j -= 1;
m += 12;
}
i = j/100;
k = 2 - i + i/4;
djul = (365.25*j - fmod(365.25*j,1.0)) - 679006.0;
djul += int(30.6001*(m+1)) + t + k;
return( djul );
}
//------------------------------------------------------------------------------------
void Class_TEC::ReadMap(int numval,int iexp, double tecval[],int &irc,ifstream &f1)
{/*-------------------------------------------------------------------
Purpose: Read Ionex Data
-------------------------------------------------------------------
Input:
Output:
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP
Date: January of 2010
-------------------------------------------------------------------
Observation: The C++ subroutine ReadMap was developed based on the
original fortran subroutine RDIXDT from author (S.SCHAER, 1997)
-------------------------------------------------------------------*/
char LINE[82]={"\0"};
string line1;
int auxval[16]={0}, iaux, iaux_, ilin, ilin_, ival, ival1, ival2,
lfnerr, naux, nlin;
try{
// COMPUTE NUMBER OF DATA LINES TO BE READ
nlin = (numval - 1)/16 + 1;
// READ SINGLE DATA BLOCK
for( ilin=1; ilin <= nlin; ilin++ )
{
ival1 = 16*ilin - 15;
ival2 = 16*ilin;
if( ival2 > numval )
ival2 = numval;
for(int i=0;i<82;i++) LINE[i]='\0';
line1="";
f1.getline(LINE,82);
line1=LINE;
naux = ival2 - ival1 + 1;
int i=0;
for (int i=0;i<16;i++) auxval[i]=0.0;
for( iaux=1; iaux <= naux; iaux++ )
{
sscanf(line1.substr(i,i+5) .c_str(),"%d",&auxval[iaux-1]);
i+=5;
}//for
// CONVERT TEC/RMS VALUES FROM ACTIVE UNIT INTO TECU
for( iaux=1; iaux <= naux; iaux++ )
{
iaux_ = iaux - 1;
ival = ival1 + iaux - 1;
if( auxval[iaux_] != 9999 )
tecval[ival-1] = (pow(10.0,iexp)*auxval[iaux_]);
else
tecval[ival-1] = 999.9;
}//for
}//for
}catch(...){
irc = 0;
return;
}
irc = 1;
return;
}
//------------------------------------------------------------------------------------
void Class_TEC::ReadHeaderGim(ifstream &f1, int &Iexp, int &Header_Flag)
{/*-------------------------------------------------------------------
Purpose: Read Header of GIM file
-------------------------------------------------------------------
Input: f1 - ifstream file
Output: Iexp - Exponent
Header_Flag = 1 -> ok
Header_Flag = 0 -> Header Problem
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP
Date: January of 2010
-------------------------------------------------------------------
Observation: The C++ subroutine ReadHeaderGim was developed based on the
original fortran subroutine RDIXHD from author (S.SCHAER, 1997)
-------------------------------------------------------------------*/
char Line[83]="\0", AuxDataBlock0[60]="\0";
double GridFactor[4],G_Version0 = 1,G_Version = 0;
string line1,AuxDataBlock="\0", SatSystem="\0", Program="\0", Agency="\0", Date="\0",
MappFunction="\0", ObsUsed="\0";
const int NumReg = 22;
int RegFlag[NumReg]={0},iint,NMAP,idim;
int itemp;
try{
Iexp=-1;
Header_Flag=0;
f1.seekg(0);
//Read and check the first ionex record
f1.getline(Line,82);
line1=Line;
if(line1.substr(60,20).compare("IONEX VERSION / TYPE") != 0)
{
printf("Invalid First Ionex record");
Header_Flag=0;
return;
}//if
if(line1.substr(20,20).compare("IONOSPHERE MAPS ") != 0)
{
printf("Invalid ionex Label");
Header_Flag=0;
return;
}
//SATELLITE SYSTEM
SatSystem = line1.substr(40,20);
//IONEX VERSION NUMBER
sscanf(line1.c_str(),"%lf",&G_Version);
if(G_Version != G_Version0)
{
printf("Invalid Ionex Version. Greater than 1.0");
Header_Flag=0;
return;
}
RegFlag[0] = 1;
do
{
for(int i=0;i<83;i++) Line[i]='\0';
f1.getline(Line,83);
//cout<<Line<<endl;
line1=Line;
//cout<<line1.substr(60,21)<<endl;
// LOOK FOR CURRENT KEYWORD AND STORE CORRESPONDING INFORMATION
if(line1.substr(60,20).compare("PGM / RUN BY / DATE ") == 0) // PROGRAM, AGENCY, DATE
{
Program = line1.substr(0,20);
Agency = line1.substr(20,20);
Date = line1.substr(40,20);
RegFlag[1]=1;
}//else if
else if(line1.substr(60,20).compare("COMMENT ") == 0) //SKIP COMMENT LINES
{
RegFlag[2]=1;
}//else if
else if(line1.substr(60,20).compare("DESCRIPTION ") == 0) //SKIP DESCRIPTION LINES
{
RegFlag[3]=1;
}//else if
else if(line1.substr(60,20).compare("EPOCH OF FIRST MAP ") == 0) //EPOCH OF FIRST MAP
{
int IYEAR,IMONTH,IDAY,IHOUR,IMIN,ISEC;
sscanf(line1.c_str(),"%6d %6d %6d %6d %6d %6d",&IYEAR,&IMONTH,&IDAY,&IHOUR,&IMIN,&ISEC);
RegFlag[4]=1;
Epoch_First_MAP=DJUL(IYEAR,IMONTH,(IDAY+IHOUR/24.0+IMIN/1440.0+ISEC/86400.0) );
}//else if
else if(line1.substr(60,20).compare("EPOCH OF LAST MAP ") == 0) //EPOCH OF LAST MAP
{
int IYEAR,IMONTH,IDAY,IHOUR,IMIN,ISEC;
sscanf(line1.c_str(),"%6d %6d %6d %6d %6d %6d",&IYEAR,&IMONTH,&IDAY,&IHOUR,&IMIN,&ISEC);
RegFlag[5]=1;
Epoch_Last_Map=DJUL(IYEAR,IMONTH,(IDAY+IHOUR/24.0+IMIN/1440.0+ISEC/86400.0) );
}//else if
else if(line1.substr(60,20).compare("INTERVAL ") == 0)
{
sscanf(line1.c_str(),"%6d",&iint);
RegFlag[6]=1;
Interval=double(iint);
}//else if
else if(line1.substr(60,20).compare("# OF MAPS IN FILE ") == 0)
{
sscanf(line1.c_str(),"%6d",&NMAP);
RegFlag[7]=1;
}//else if
else if(line1.substr(60,20).compare("MAPPING FUNCTION ") == 0)
{
MappFunction = line1.substr(2,4);
//sscanf(line1.c_str(),"%s",MappFunction.c_str());
RegFlag[8]=1;
}//else if
else if(line1.substr(60,20).compare("ELEVATION CUTOFF ") == 0)
{
sscanf(line1.c_str(),"%lf",&Elevation_Cuttof);
RegFlag[9]=1;
}//else if
else if(line1.substr(60,20).compare("OBSERVABLES USED ") == 0)
{
ObsUsed = line1.substr(0,60);
RegFlag[10]=1;
}//else if
else if(line1.substr(60,20).compare("# OF STATIONS ") == 0)
{
sscanf(line1.c_str(),"%6d",&itemp);
RegFlag[11]=1;
}//else if
else if(line1.substr(60,20).compare("# OF SATELLITES ") == 0)
{
sscanf(line1.c_str(),"%6d",&itemp);
RegFlag[12]=1;
}//else if
else if(line1.substr(60,20).compare("BASE RADIUS ") == 0)
{
sscanf(line1.c_str(),"%lf",&Base_Radius);
RegFlag[13]=1;
}//else if
else if(line1.substr(60,20).compare("MAP DIMENSION ") == 0)
{
sscanf(line1.c_str(),"%6d",&idim);
RegFlag[14]=1;
}//else if
else if(line1.substr(60,20).compare("HGT1 / HGT2 / DHGT ") == 0)
{
sscanf(line1.c_str(),"%lf %lf %lf",&Ini_Height,&End_Height,&Height_Incremet);
RegFlag[15]=1;
}//else if
else if(line1.substr(60,20).compare("LAT1 / LAT2 / DLAT ") == 0)
{
sscanf(line1.c_str(),"%lf %lf %lf",&Ini_Lat,&End_Lat,&Lat_Increment);
RegFlag[16]=1;
}//else if
else if(line1.substr(60,20).compare("LON1 / LON2 / DLON ") == 0)
{
sscanf(line1.c_str(),"%lf %lf %lf",&Ini_Lon,&End_Lon,&Lon_Increment);
RegFlag[17]=1;
}//else if
else if(line1.substr(60,20).compare("EXPONENT ") == 0) // EXPONENT
{
sscanf(line1.c_str(),"%d",&Iexp);
RegFlag[18]=1;
} //else if
else if(line1.substr(60,20).compare("START OF AUX DATA ") == 0) // AUXILIARY DATA BLOCK FOUND
{
line1.copy(AuxDataBlock0,60,0);
RegFlag[19]=1;
int NADT=0;
do{
//read next AUX DATA line
for(int i=0;i<81;i++) Line[i]='\0';
f1.getline(Line,82);
line1=Line;
if (strcmp(AuxDataBlock.c_str(),AuxDataBlock0)==0)
{
NADT=NADT+1;
if (NADT > 16)
{
printf("So many Aux Data Lines");
Header_Flag=0;
return;
}//if
}//if
}while (line1.substr(60,20).compare("END OF AUX DATA ") != 0);
RegFlag[20] = 1;
}//else
}while( line1.substr(60,20).compare("END OF HEADER ") != 0 &&
line1.substr(60,20).compare("END OF FILE ") != 0);
if(line1.substr(60,20).compare("END OF FILE ") ==0)
{
printf("End of File reached");
Header_Flag = 0;
return;
}
RegFlag[21] = 1;
// Check ionex Header
for( int i=0; i < NumReg; i++ )
{
if( RegFlag[i] == 0 )
{
printf(" Record Missing in the GIM file header");
Header_Flag = 0;
return;
}//if
}//for
if( iint == 0 )
{
printf(" Interval 0 Not Supported" );
Header_Flag = 0;
return;
}//if
else
{
if( NMAP > 1 )
{
int iint0 = int((Epoch_Last_Map-Epoch_First_MAP)/(NMAP-1)*86400.0);
if( iint != iint0 )
{
printf("Incosistent Time Arguments");
Header_Flag = 0;
return;
}//if
}//if
}//else
// SATELLITE SYSTEM
if( SatSystem.compare(0,3,"BEN") != 0 &&
SatSystem.compare(0,3,"ENV") != 0 &&
SatSystem.compare(0,3,"ERS") != 0 &&
SatSystem.compare(0,3,"GEO") != 0 &&
SatSystem.compare(0,3,"GLO") != 0 &&
SatSystem.compare(0,3,"GNS") != 0 &&
SatSystem.compare(0,3,"GPS") != 0 &&
SatSystem.compare(0,3,"IRI") != 0 &&
SatSystem.compare(0,3,"MIX") != 0 &&
SatSystem.compare(0,3,"NNS") != 0 &&
SatSystem.compare(0,3,"TOP") != 0 )
{
printf("Satellite System Unknown");
Header_Flag = 0;
return;
}//if
// MAPPING FUNCTION
if( MappFunction.compare("NONE") != 0 &&
MappFunction.compare("COSZ") != 0 &&
MappFunction.compare("QFAC") != 0 )
{
printf("Mapping Function Unknown");
Header_Flag = 0;
return;
}//if
if( idim == 2 ) // MAP DIMENSION
{
if( (Ini_Height != End_Height) || (Height_Incremet != 0.0) )
{
printf("Ionosphere Height Unknown");
Header_Flag = 0;
return;
}//if
}//if
else
{
if( (Ini_Height == End_Height) || (End_Height == 0.0) )
{
printf(" Error related to Map Dimension");
Header_Flag = 0;
return;
}//if
}//else
// Check Latitude and Longitude
GridFactor[0] = Ini_Lat/Lat_Increment;
GridFactor[1] = End_Lat/Lat_Increment;
GridFactor[2] = Ini_Lon/Lon_Increment;
GridFactor[3] = End_Lon/Lon_Increment;
for( int i=0; i < 4; i++ )
{
double xdif = fabs(GridFactor[i]-int(GridFactor[i]));
if( xdif > 1.0E-4 )
{ Header_Flag = 0;
return;
}//if
}//for
}catch(...){
Header_Flag = 0;
return;
}
Header_Flag = 1;
return;
}
//---------------------------------------------------------------------------
int Class_TEC::ReadGIM(char *NameGIM)
{/*-------------------------------------------------------------------
Purpose: Read Ionex File
-------------------------------------------------------------------
Input:
Output:
-------------------------------------------------------------------
Authors: Haroldo Antonio Marques
Programa de Pos-Graduacao em Ciencias Cartograficas
FCT/UNESP - Presidente Prudente - SP
Date: January of 2010
-------------------------------------------------------------------
Observation: The C++ subroutine ReadGIM was developed based on the
original fortran subroutine RDIXFL from author (S.SCHAER, 1997)
-------------------------------------------------------------------*/
// 02/05/2013:MHA - Small changes in the source code
const int MaxMap = 67379;
int NHGT,IMAP,IVAL,iaux=0;
int NUMMAP[3]={0};
double XEPO=0.0;
char Line[83]="\0";
string line1;
ifstream f1;
int Iexp,Header_Flag=0;
Gim_Flag=0;
f1.open(NameGIM); //OPEN IONEX INPUT FILE
if(f1.fail())
{
printf("Error Opening GIM FILE");
return Gim_Flag;
}
//Read GIM Header
ReadHeaderGim( f1,Iexp,Gim_Flag);
Re = Base_Radius*1.0E3; //Equatorial Earth axis in m
hion = ((End_Height+Ini_Height)/2.0)*1.0E3; //Ionospheric layer height in m
if(Gim_Flag==0)
return Gim_Flag;
double XINT=Interval/86400.0;