-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathazelplot.cpp
executable file
·2108 lines (1766 loc) · 65.7 KB
/
azelplot.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
#pragma hdrstop
#include <fstream> // this includes iostream.h
#include <string>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#ifdef __linux__
#include <sys/stat.h>
#endif
#include "datetime.h"
#include "rinex.h"
#include "intrpSP3.h"
#include "consts.h"
#include "physcon.h"
using std::string;
using namespace NGSdatetime;
using namespace NGSrinex;
void llh2xyz(double a, double finverse, double lat, double lon,
double h, double *x, double *y, double *z);
void xyz2llh(double a, double finverse, double x, double y, double z,
double *lat, double *lon, double *h);
double dot( int n, double a[], double b[]);
int bccalc( double tsubr, int isv, double recf[3], double vecf[3]);
int bcorb( double tc, int isv, double recf[4], double vecf[3] );
int bcread(RinexNavFile &navFile, ofstream &out );
string padZeros( int a );
const int MAXSVS = 36;
const int MAXUNK = 28;
const int MAXEPOCH = 50; // PRN blocks per file, was 160
double scaleBar = 0.06; // was 0.04 for full page
bool gmt5 = false;
bool lite = false;
const double strayLineThreshold = 0.50; // don't connect setTime with riseTime
double xco[MAXSVS][MAXUNK][MAXEPOCH];
int nxco[MAXSVS];
int jxco;
long cuml_bad_blocks[MAXSVS];
double bcpos[4], bcvel[3];
double t_r;
int BRprns[ MAXSVS ];
#pragma argsused
int main(int args, char* argv[] )
{
istringstream inString;
istringstream prnList;
int i, j, ierr, prnNum, itemp, currNumPrns;
int currPRNs[ MAXSVS ] = { 0 };
double jpi = 4.0*atan(1.0);
SP3File mysp3;
double tt;
double lat, lon , h;
double pvVec[10];
double svpos[10];
double n[3], e[3], u[3], rho[3], len, zenithAng, tmpe, tmpn, azim, elvAng;
double xsta[3] = { 0.0 };
string orbfile, outfile, stemp, rinfile, teqcPltFile, rinexObsFile, psFile("azelplot.ps"), batchFile("azelplot.bat"), cleanbatchFile("azelplot_cleanup.bat");
string elevRingFile("elevRings.dat"), cutoffRingFile("cutoffRing.dat"),
titleFile("title.txt"), mpFile("mp.xy"), mpHighlightFile("mp_highlight.xy"), satFileExt(".sat.xy"),
timeXYFile("hr.xy"), timeTagFile("hr.txt"), crossFile("cross.txt"), neswFile("nesw.txt"), arrowsFile("arrows.xy"),
ringTxtFile("ring.txt");
string stationName("no_sta"), doy("000"), from_to("YYYYMMDD-HMS_YYYYMMDD-HMS");
char title[256];
YMDHMS ymdhms;
double tmp1, tmp2,sz;
double xmap,ymap;
double r[20];
// YMDHMS prevYmdhms;
MJD tempMJD;
int year1, mon1, day1, hr1, min1, sec1;
int year2, mon2, day2, hr2, min2, sec2;
int h_year1, h_mon1, h_day1, h_hr1, h_min1, h_sec1;
int h_year2, h_mon2, h_day2, h_hr2, h_min2, h_sec2;
string color("175/175/175"), highlightColor("200/0/0");
DateTime startTime;
DateTime endTime;
DateTime startHighlightTime;
DateTime endHighlightTime;
DateTime currEpoch;
DateTime teqcStartTime;
bool broadcastExist(false);
bool highlight(false);
double cutoffAngle;
double arrowsx[40][2];
double arrowsy[40][2];
double currData[MAXSVS];
double prevXMAP[MAXSVS] = { 0.0 };
double prevYMAP[MAXSVS] = { 0.0 };
string tString, buf, temp, temp2;
long index;
GPSTime gpsTime;
double htt, sampleRate, dtemp;
int fileNumPrns, prnIDs[ MAXSVS ];
double dist3d, teqcStartFrac;
bool LLHsupplied;
double xtmp, ytmp, ztmp;
// double currMJD, currHour,
double epochNum(0.0);
double dx,dy,az;
long teqcStartMJD, lineNum;
string infile("azelplot.inp");
string font_delim(" ");
string pen_delim("/");
string gmt("");
string vector_desc("0.0/0.0/0.0");
string pstext_F("");
string multi_seg(" -M ");
if (args == 1 ){
cout << "Program AZELPLOT (forking cf2sky Version 17 December 2003, edits R. Grapenthin, July 2011)"<<endl;
cout << "Version 2016-08-25"<<endl<<endl;
cout << "USAGE: azelplot input-file [scale-factor [GMT5 [lite]]]"<<endl<<endl;
cout << " input-file: Is a file that drives the execution of "<<endl;
cout << " this program. Its syntax is as follows: "<<endl<<endl;
cout << " Line 1: Title of plot"<<endl;
cout << " Line 2: Plot start time (YYYY MM DD HH mm SS) "<<endl;
cout << " Line 3: Plot end time (YYYY MM DD HH mm SS) "<<endl;
cout << " Line 4: Orbit file (SP3 format) "<<endl;
cout << " Line 5: Cutoff elevation angle "<<endl;
cout << " Line 6: uncompressed Rinex file (paths possible) "<<endl;
cout << " Line 7: teqc COMPACT formatted data file "<<endl;
cout << " Line 8: color (GMT COLOR STRING) "<<endl;
cout << " [ Line 9: Highlight start time (YYYY MM DD HH mm SS) "<<endl;
cout << " Line 10: Highlight end time (YYYY MM DD HH mm SS) "<<endl<<endl;
cout << " Line 11: Highlight color (GMT COLOR STRING) ]"<<endl<<endl;
cout << " scale-factor: increase / decrease data plot line length (default: 0.06) "<<endl<<endl;
cout << " GMT5: Use this exact string (GMT5) to generate GMT5 compatible "<<endl;
cout << " plotting commands."<<endl<<endl;
cout << " lite: bare bones version will be plotted"<<endl<<endl;
return -1;
}
if (args > 1 ){ infile = argv[1]; }
if (args == 3 ){ scaleBar = atof(argv[2]);}
if (args == 4 ){
scaleBar = atof(argv[2]);
if (string(argv[3]) == "GMT5"){
gmt5 = true;
}
}
if (args == 5 ){
scaleBar = atof(argv[2]);
if (string(argv[3]) == "GMT5"){
gmt5 = true;
}
if (string(argv[4]) == "lite"){
lite = true;
}
}
if (gmt5 == true){
font_delim = string(",");
pen_delim = string(",");
vector_desc= string("0");
gmt = string("gmt ");
pstext_F = string(" -F+f+a+j ");
multi_seg = string("");
}
for (i=0; i < 40; ++i ) {
arrowsx[i][0] = -9999.0;
arrowsx[i][1] = -9999.0;
arrowsy[i][0] = -9999.0;
arrowsy[i][1] = -9999.0;
}
for (i=1; i < MAXSVS; ++i ) {
BRprns[i] = i;
}
ofstream out("azelplot.log");
if ( !out )
{
cerr << "Error opening azelplot.log ! " << endl;
return -1;
}
out << endl << "Program AZELPLOT (forking cf2sky Version 17 December 2003, edits R. Grapenthin, since July 2011)" << endl;
out << endl << "Version 2015-10-02"<<endl<<endl;
out.setf( ios::fixed, ios::floatfield );
ifstream inp(infile.c_str());
if ( !inp )
{
cerr << "Error opening azelplot.inp! " << endl;
out << endl << "Error opening azelplot.inp! " << endl << endl;
return -1;
}
//RG: Title had to go to the top and grabbed with .get, otherwise wouldn't work. '>>' doesn't consume newlines
inp.get( title, 256 );
inp >> year1 >> mon1 >> day1 >> hr1 >> min1 >> sec1;
inp >> year2 >> mon2 >> day2 >> hr2 >> min2 >> sec2;
inp >> orbfile;
inp >> cutoffAngle;
inp >> rinexObsFile;
inp >> teqcPltFile;
inp >> color;
if(!inp.eof( )){
inp >> h_year1 >> h_mon1 >> h_day1 >> h_hr1 >> h_min1 >> h_sec1;
startHighlightTime = DateTime( h_year1, h_mon1, h_day1, h_hr1, h_min1, h_sec1 );
if(!inp.eof( )){
inp >> h_year2 >> h_mon2 >> h_day2 >> h_hr2 >> h_min2 >> h_sec2;
endHighlightTime = DateTime( h_year2, h_mon2, h_day2, h_hr2, h_min2, h_sec2 );
if(!inp.eof( )){
inp >> highlightColor;
}
}
}
inp.close();
startTime = DateTime( year1, mon1, day1, hr1, min1, sec1 );
endTime = DateTime( year2, mon2, day2, hr2, min2, sec2 );
if(startHighlightTime >= startTime) //if endhighlight isn't set, highlight it all!
highlight = true;
stemp.assign(title);
//get station name, DOY from rinex filename:
stationName = rinexObsFile.substr(rinexObsFile.length()-12, 4);
doy = rinexObsFile.substr(rinexObsFile.length()- 8, 3);
char buffer[32];
sprintf(buffer, "%.4d%.2d%.2d-%.2d%.2d%.2d_%.4d%.2d%.2d-%.2d%.2d%.2d", year1, mon1, day1, hr1, min1, sec1, year2, mon2, day2, hr2, min2, sec2);
from_to = buffer;
//create a whole lot of Station/DOY/time specific filenames
#ifdef __linux__
psFile = stationName + "_" + from_to + ".ps";
batchFile = stationName + "_" + from_to + ".bat";
cleanbatchFile = "cleanup_" + stationName + "_" + from_to + ".bat";
elevRingFile = "elevRings_" + stationName + "_" + from_to + ".dat";
cutoffRingFile = "cutoffRing_" + stationName + "_" + from_to + ".dat";
titleFile = "title_" + stationName + "_" + from_to + ".txt";
mpFile = "mp_" + stationName + "_" + from_to + ".xy";
mpHighlightFile= "mp_highlight_" + stationName + "_" + from_to + ".xy";
satFileExt = stationName + "_" + from_to + ".sat.xy";
timeXYFile = "hr_" + stationName + "_" + from_to + ".xy";
timeTagFile = "hr_" + stationName + "_" + from_to + ".txt";
crossFile = "cross_" + stationName + "_" + from_to + ".txt";
neswFile = "nesw_" + stationName + "_" + from_to + ".txt";
arrowsFile = "arrows_" + stationName + "_" + from_to + ".xy";
ringTxtFile = "ring_" + stationName + "_" + from_to + ".txt";
#endif
// create a cleanup file
ofstream cleanbat(cleanbatchFile.c_str());
if ( !cleanbat )
{
cerr << "Error opening << " << cleanbatchFile <<" ! " << endl;
return -1;
}
#ifdef __linux__
chmod(cleanbatchFile.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH);
#endif
cleanbat << "echo cleanup ..." << endl;
if (highlight) cleanbat << "rm "<< mpHighlightFile << endl;
cleanbat << "rm "<< psFile << " " << elevRingFile << " " << cutoffRingFile << " " << titleFile << " " << mpFile << " " <<
"*"<<satFileExt << " " << timeXYFile << " " << timeTagFile << " " << crossFile << " " << neswFile << " " <<
arrowsFile << " " << ringTxtFile << " " << batchFile << " " << cleanbatchFile << " azelplot.AzEl" << endl;
cleanbat.close();
// Open the RINEX OBS file to get the Approx. X,Y,Z coordinates
ifstream obs(rinexObsFile.c_str());
if ( !obs )
{
cerr << "Error opening obsfile " << rinexObsFile << endl;
return -1;
}
while( getline( obs, buf ) ) // **** loop to read thru OBS file
{
cout << buf << endl;
temp = buf.substr( 60, 15 );
if( temp == "APPROX POSITION" )
{
temp2 = buf.substr( 0, 14);
xsta[0] = atof(temp2.c_str());
temp2 = buf.substr( 14, 14);
xsta[1] = atof(temp2.c_str());
temp2 = buf.substr( 28, 14);
xsta[2] = atof(temp2.c_str());
cout.setf( ios::fixed);
cout.setf( ios::showpoint);
cout << endl << "Approx XYZ: " << setw(16) << setprecision(4) << xsta[0]
<< " " << setw(16) << setprecision(4) <<xsta[1] << " "
<< setw(16) << setprecision(4) << xsta[2] << endl << endl;
break;
}
} // end of while loop
obs.close();
if( fabs(xsta[0] + xsta[1] + xsta[2]) < 0.0001 )
{
cerr << "Error reading X,Y,Z coordinates from " << rinexObsFile << endl;
return -1;
}
out << "Use GMT5? " << gmt5 << endl;
out << "Input file: " << infile << endl;
out.precision(0);
out << year1 << " " << mon1 << " " << day1 << " " << hr1 << " " <<
min1 << " " << sec1 << endl;
out << year2 << " " << mon2 << " " << day2 << " " << hr2 <<
" " << min2 << " " << sec2 << endl;
out << orbfile << endl;
out.precision(3);
out << "Title: " << stemp << endl;
// out << xsta[0] << " " << xsta[1] << " " << xsta[2] << " " << endl;
out << "Cutoff Angle: " << cutoffAngle << endl;
out << "Rinex Obs File: " << rinexObsFile << endl;
out << "TEQC File: " << teqcPltFile << endl;
out.setf( ios::fixed);
out.setf( ios::showpoint);
out << endl << "Approx XYZ: " << setw(16) << setprecision(4) << xsta[0]
<< " " << setw(16) << setprecision(4) <<xsta[1] << " "
<< setw(16) << setprecision(4) << xsta[2] << endl << endl;
dist3d = sqrt( xsta[0]*xsta[0] + xsta[1]*xsta[1] + xsta[2]*xsta[2] );
if ( dist3d >= 6300000.0 ) {
// xyz given as input
xyz2llh(6378137.0, 298.257223563, xsta[0], xsta[1], xsta[2],
&lat, &lon, &htt);
// out << "\n\nuser supplied XYZ, rather than LLH" << endl;
LLHsupplied = false;
} else {
// llh given as input
lat = xsta[0] * jpi/180.0;
lon = xsta[1] * jpi/180.0;
htt = xsta[2];
LLHsupplied = true;
}
out.precision( 7 );
ofstream outtt(titleFile.c_str());
if ( !outtt ) {
cerr << "Error opening " << titleFile <<" ! " << endl;
return -1;
}
outtt.setf( ios::fixed, ios::floatfield);
outtt << setw(2) << setprecision(0);
outtt << "0 2.3 12" << font_delim << "0 0 CM " << stemp << endl;
outtt << "0 2.1 8" << font_delim << "0 0 CM Lat: "
<< setw(10) << setprecision(4) << lat * 180.0 /jpi << "\xB0 Lon: "
<< setw(10) << setprecision(4) << lon * 180.0 /jpi << "\xB0 Ell Ht: "
<< setw(10) << setprecision(1) << htt << " m " <<
endl;
outtt << "0 1.95 8" << font_delim << "0 0 CM GPS Time: "
<< setw(2) << setprecision(0)
<< year1 << "/" << padZeros(mon1) << "/" <<
padZeros(day1) << " " << padZeros(hr1) << ":"
<< padZeros(min1) << ":" << padZeros(sec1) << " - "
<< year2 << "/" << padZeros(mon2) << "/" << padZeros(day2)
<< " " << padZeros(hr2) << ":"
<< padZeros(min2) << ":" << padZeros(sec2) << endl;
outtt.close();
// open the batch file
ofstream outbat(batchFile.c_str());
if ( !outbat )
{
cerr << "Error opening << " << batchFile <<" ! " << endl;
return -1;
}
#ifdef __linux__
chmod(batchFile.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH);
outbat << "#!/bin/tcsh" << endl;
#endif
if (lite==true){
outbat << gmt << "gmtset PS_MEDIA Custom_200x200" << endl;
outbat << gmt << "psxy " << elevRingFile << " -R-1.6/1.6/-1.6/1.6 -JX7.0 -W1.0p" << pen_delim << "0/0/0 -G230 -V " << multi_seg << " -K -P -Xc -Yc > " << psFile << endl;
}else{
outbat << gmt << "gmtset PS_MEDIA Custom_250x280" << endl;
outbat << gmt << "psxy " << elevRingFile << " -R-1.6/1.6/-1.6/1.6 -JX7.0 -W1.0p" << pen_delim << "0/0/0 -G230 -V " << multi_seg << " -K -P -X0.75 -Y1.0 > " << psFile << endl;
}
if(gmt5==true){
outbat << gmt << "psxy " << cutoffRingFile << " -R -JX -W0.2,0,4_8:0p -G255 -V " << multi_seg << " -O -K -P >> " << psFile << endl;
}else{
outbat << gmt << "psxy " << cutoffRingFile << " -R -JX -W0.2t4_8:0p -G255 -V " << multi_seg << " -O -K -P >> " << psFile << endl;
}
outbat << gmt << "psxy " << elevRingFile << " -R -JX -W1.0p" << pen_delim << "0/0/0 -V " << multi_seg << " -O -K -P >> " << psFile << endl;
outbat << gmt << "psxy " << elevRingFile << " -R -JX -W0.5p" << pen_delim << "255/255/255 -V " << multi_seg << " -O -K -P >> " << psFile << endl;
if (lite==false){
outbat << gmt << "pstext " << titleFile << pstext_F <<" -R -JX -N -V -O -K -P >> " << psFile << endl;
}
outbat << gmt << "psvelo " << mpFile << " -R -JX -L -W0.5p" << pen_delim << color << " -Se1/0.95/0 -A"<< vector_desc <<
" -N -O -K -P -V >> " << psFile << endl;
if(highlight)
{
outbat << gmt << "psvelo " << mpHighlightFile << " -R -JX -L -W0.5p" << pen_delim << highlightColor << " -Se1/0.95/0 -A"<< vector_desc <<
" -N -O -K -P -V >> " << psFile << endl;
}
// broadcast or precise?
ifstream inp2( orbfile.c_str() );
if ( !inp2 ) {
cerr << "Warning: " << orbfile << " does not exist " << endl;
inp2.close();
exit(0);
} else {
getline( inp2, tString );
index = tString.find( "NAVIGATION" );
if ( 0 < index && index < 80 ) {
out << "\n\nUsing broadcast file " << orbfile << endl;
broadcastExist = true;
RinexNavFile mynav;
try{ mynav.setPathFilenameMode( orbfile, ios_base::in); }
catch( RinexFileException &openExcep )
{
cerr << "Error opening file: " << orbfile << endl;
cerr << "Rinex File Exception is: " << endl << openExcep.getMessage() << endl;
cerr << endl << "Error Messages for " << orbfile << " :" << endl
<< mynav.getErrorMessages() << endl << endl;
cerr << endl << "Format Warnings for " << orbfile << " :" << endl
<< mynav.getWarningMessages() << endl << endl << endl;
cerr << "Terminating program POINT due to an error." << endl;
}
//cout << endl << "NV::Header for RINEX NAV file: " << orbfile << endl;
try{ bcread(mynav, out); }
catch( RequiredRecordMissingException &headerExcep )
{
cerr << "RequiredRecordMissingException is: " << endl
<< headerExcep.getMessage() << endl;
cerr << endl << "Error Messages for " << orbfile << " :" << endl
<< mynav.getErrorMessages() << endl << endl;
cerr << endl << "Format Warnings for " << orbfile << " :" << endl
<< mynav.getWarningMessages() << endl << endl << endl;
cerr << "Terminating program POINT due to an error." << endl;
}
} else {
cout << "\n\nUsing sp3 file " << orbfile << endl;
mysp3.setPathFilenameMode(orbfile.c_str(),ios_base::in);
mysp3.readHeader();
}
}
inp2.close();
if ( ! LLHsupplied ) {
xyz2llh(AE84, FLATINV84, xsta[0], xsta[1], xsta[2], &lat, &lon, &h);
} else {
llh2xyz(AE84, FLATINV84, lat, lon, htt, &xtmp, &ytmp, &ztmp);
xsta[0] = xtmp;
xsta[1] = ytmp;
xsta[2] = ztmp;
}
n[0] = -sin(lat) * cos(lon);
n[1] = -sin(lat) * sin(lon);
n[2] = cos(lat);
e[0] = -sin(lon);
e[1] = cos(lon);
e[2] = 0.0;
u[0] = cos(lat) * cos(lon);
u[1] = cos(lat) * sin(lon);
u[2] = sin(lat);
cout.setf(ios::fixed, ios::floatfield);
string removeSats("rm ");
removeSats.append("*").append(satFileExt);
system(removeSats.c_str());
ofstream satcoords;
ofstream hourstamps( timeTagFile.c_str() );
if ( ! hourstamps ) {
cout << "ERROR: cant open " << timeTagFile << " ! " << endl;
exit(0);
}
ofstream hourdots( timeXYFile.c_str() );
if ( ! hourdots ) {
cout << "ERROR: cant open " << timeXYFile << " ! " << endl;
exit(0);
}
ofstream azelOut( "azelplot.AzEl" );
if ( ! azelOut ) {
cout << "ERROR: cant open azelplot.AzEl " << endl;
exit(0);
}
azelOut.setf( ios::fixed, ios::floatfield );
// Open the TEQC plot file
ifstream cfplt( teqcPltFile.c_str() );
if( !cfplt )
{
out << "Error! Cannot open file: " << teqcPltFile.c_str() << endl
<< "Now terminating Program AZELPLOT." << endl << endl;
cerr << "Error! Cannot open file: " << teqcPltFile.c_str() << endl
<< "Now terminating Program AZELPLOT." << endl << endl;
return -1;
}
getline( cfplt, buf ); // **** read the first line
temp = buf.substr( 0, 7 );
if( temp != "COMPACT" )
{
cerr << "WARNING! First Line in teqc plot file is not the word COMPACT!" << endl;
out << "WARNING! First Line in teqc plot file is not the word COMPACT!" << endl;
}
getline( cfplt, buf ); // **** read the second line
temp = buf.substr( 0, 3 );
if( temp != "SVS" )
{
out << "WARNING! Second Line in teqc plot file does not start with SVS!" << endl;
cerr << "WARNING! Second Line in teqc plot file does not start with SVS!"<< endl;
}
fileNumPrns = (buf.length() - 5 )/6;
for( i = 0; i < fileNumPrns; ++i)
{
temp = buf.substr( 6+(6*i), 2 );
prnIDs[i] = atoi(temp.c_str());
temp = buf.substr( 6+(6*i)+3, 2 );
itemp = atoi(temp.c_str());
if( itemp != prnIDs[i] )
{
out << "Warning! unequal satellite IDs found in header for file: " << teqcPltFile.c_str() << endl << endl;
cerr << "Warning! unequal satellite IDs found in header for file: " << teqcPltFile.c_str() << endl << endl;
}
}
getline( cfplt, buf ); // **** read the third line
temp = buf.substr( 0, 6 );
if( temp != "T_SAMP" )
{
out << "WARNING! Third Line in teqc plot file does not start with T_SAMP!" << endl;
cerr << "WARNING! Third Line in teqc plot file does not start with T_SAMP!" << endl;
}
temp = buf.substr( 6, 10);
sampleRate = atof(temp.c_str());
getline( cfplt, buf ); // **** read the fourth line
temp = buf.substr( 0, 14 );
if( temp != "START_TIME_MJL" )
{
out << "WARNING! 4th Line in teqc plot file does not start with START_TIME_MJL!" << endl
<< "Terminating program." << endl << endl;
cerr << "WARNING! 4th Line in teqc plot file does not start with START_TIME_MJL!" << endl
<< "Terminating program." << endl << endl;
out.close();
cfplt.close();
exit(1);
}
temp = buf.substr( 14, 7);
teqcStartMJD = atol(temp.c_str());
temp = buf.substr( 21, 7);
teqcStartFrac = atof(temp.c_str());
tempMJD.mjd = teqcStartMJD;
tempMJD.fracOfDay = teqcStartFrac;
teqcStartTime.SetMJD( tempMJD );
if( endTime < teqcStartTime )
{
out << "Error. User's Stop Time is before the TEQC file starts ! " << endl
<< "User Stop Time (MJD): " << endTime << " File Start Time (YMDHMS): " << teqcStartTime << endl
<< "Terminating program." << endl << endl;
cerr << "Error. User's Stop Time is before the TEQC file starts ! " << endl
<< "User Stop Time (MJD): " << endTime << " File Start Time (YMDHMS): " << teqcStartTime << endl
<< "Terminating program." << endl << endl;
cfplt.close();
out.close();
exit(1);
}
ofstream mp( mpFile.c_str() );
if ( ! mp ) {
cerr << "ERROR: cannot open " << mpFile << " ! " << endl;
exit(0);
}
ofstream mpHighlight( mpHighlightFile.c_str() );
if ( ! mpHighlight ) {
cerr << "ERROR: cannot open " << mpHighlightFile << " ! " << endl;
exit(0);
}
// create the legend for the size of the multipath bars (1,5,10 meters)
if (lite==false){
mp << " 1.35 -1.59 " << -10.0*scaleBar << " 0.0 0 0 0" << endl;
mp << " 1.35 -1.49 " << -5.0*scaleBar << " 0.0 0 0 0" << endl;
mp << " 1.35 -1.39 " << -1.0*scaleBar << " 0.0 0 0 0" << endl;
}
//ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cout << endl << "Now reading the TEQC plot file..." << endl << endl;
out << endl << "Now reading the TEQC plot file..." << endl << endl;
lineNum = 4;
while( getline( cfplt, buf ) ) // **** loop to read two lines for each epoch
{
++lineNum;
epochNum = epochNum + 1.0;
currEpoch = teqcStartTime + (((epochNum - 1.0) * sampleRate)/86400.0);
//forward to user start time
if( currEpoch < startTime ){
getline( cfplt, buf ); ++lineNum; continue;
}
//stop if we're past endTime
if( currEpoch > endTime ) break;
temp = buf.substr( 0, 2); // The first integer is the # of PRNs
itemp = atoi( temp.c_str() );
gpsTime = currEpoch.GetGPSTime();
t_r = gpsTime.secsOfWeek; // this is the given receipt time (dt)
ymdhms = currEpoch.GetYMDHMS();
for( i = 0; i < MAXSVS; ++i )
currData[i] = 0.0;
if( itemp == 0 )
{
// zero means there is data for zero satellites at this epoch
cout << "No data at all at time " << currEpoch << endl;
}
else if( itemp == -1 ) // when itemp == -1, use previous list of PRNs
{
getline( cfplt, buf );
++lineNum;
inString.clear();
inString.str( buf );
for( i = 0; i < currNumPrns; ++i ) // loop over satellites
{
inString >> dtemp;
prnNum = currPRNs[i];
currData[prnNum] = dtemp;
}
}
else if( itemp >= 1 ) // when itemp >= 1, read in new list of PRNs
{
currNumPrns = itemp;
prnList.clear();
temp = buf.substr(2, buf.length());
prnList.str( temp );
for( i = 0; i < currNumPrns; ++i )
prnList >> currPRNs[i];
getline( cfplt, buf );
lineNum++;
inString.clear();
inString.str( buf );
for( i = 0; i < currNumPrns; ++i ) // loop over all satellites
{
inString >> dtemp;
prnNum = currPRNs[i];
currData[prnNum] = dtemp;
}
}
else
{
out << "Number of satellites incorrect on line number: " << lineNum << endl
<< buf << endl << endl;
out << "Now terminating Program CF2SKY." << endl << endl;
cerr << "Number of satellites incorrect on line number: " << lineNum << endl
<< buf << endl << endl;
cerr << "Now terminating Program CF2SKY." << endl << endl;
return -1;
}
// Now compute the azimuth and elevation of ALL satellites
if( currEpoch >= (startTime + ( -0.0000001/86400.0)) &&
currEpoch <= (endTime + (0.0000001/86400.0)) )
{
for( i = 1; i < MAXSVS; ++i )
{
prnNum = i;
if ( broadcastExist )
{
ierr = bcorb( t_r, i, bcpos, bcvel); //BR
if ( fabs( bcpos[0] ) < 1.0e-8 )
{
ierr = 1;
}
else
{
svpos[0] = bcpos[0];
svpos[1] = bcpos[1];
svpos[2] = bcpos[2];
//cout << i << " " << svpos[0] << " " << svpos[1] << " "
// << svpos[2] << endl;
}
}
else
{
ierr = (int) mysp3.getSVPosVel( currEpoch, (unsigned short) prnNum, pvVec);
svpos[0] = pvVec[0] * 1000.0;
svpos[1] = pvVec[1] * 1000.0;
svpos[2] = pvVec[2] * 1000.0;
}
if ( ierr == 0 )
{
// pg 148 hoffman-wellenhoff
for (j=0; j < 3; ++j ) {
rho[j] = svpos[j] - xsta[j];
}
len = 0.0;
for (j=0; j < 3; ++j ) {
len += ( rho[j] * rho[j] );
}
len = sqrt(len);
for (j=0; j < 3; ++j ) {
rho[j] /= len;
}
zenithAng = acos( dot( 3, rho, u) );
tmp1 = dot( 3, rho, e);
sz = sin(zenithAng);
tmpe = tmp1 / sz ;
tmp2 = dot( 3, rho, n);
tmpn = tmp2 / sz ;
azim = atan2( tmpe, tmpn);
if ( azim < 0.0 ) azim += (2.0*jpi);
elvAng = jpi/2.0 - zenithAng;
if ( elvAng * 180.0/jpi > cutoffAngle ) {
// compute map coords for satellite
xmap = ( jpi / 2.0 - elvAng) * sin( azim );
ymap = ( jpi / 2.0 - elvAng) * cos( azim );
tt = (ymdhms.hour + ymdhms.min / 60.0 + ymdhms.sec/ 3600.0);
azelOut <<
setw(10) << setprecision(6) << tt <<
setw(4) << setprecision(0) << prnNum <<
setw(9) << setprecision(3) << (azim * 180.0/jpi) <<
setw(9) << setprecision(3) << (elvAng * 180.0/jpi) <<
//setw(18) << setprecision(13) << xmap <<
//setw(18) << setprecision(13) << ymap <<
endl ;
ostringstream fname;
fname << prnNum << satFileExt;
satcoords.open( fname.str().c_str() , ios::app);
if( fabs(prevXMAP[prnNum]) > 0.0000001 &&
fabs(prevYMAP[prnNum]) > 0.0000001 &&
sqrt( (prevXMAP[prnNum] - xmap)*(prevXMAP[prnNum] - xmap) +
(prevYMAP[prnNum] - ymap)*(prevYMAP[prnNum] - ymap) )
> strayLineThreshold ) satcoords << "> " << endl;
satcoords << xmap << " " << ymap << endl;
// << " " << prnNum << " " << dtemp << " " << currEpoch << endl;
satcoords.close();
prevXMAP[prnNum] = xmap;
prevYMAP[prnNum] = ymap;
// if ( tt - (double)( (int) tt ) < 1.0e-6 &&
// ymdhms.min != 59 && ymdhms.sec != 60.000 ) {
// 0.00027 = 1 second in units of decimal hours
if( fabs(tt - roundoff(tt)) < 0.0002 ) {
/* cout << "hourstamp " << tt << " " << currEpoch <<
" " << ymdhms.hour << endl; */
// hourstamps << (xmap+0.02) << " " << ymap << " 6 0 0 ML " <<
// (int) ymdhms.hour << "h" << endl;
if ((int) roundoff(tt) > hr1 && (int) roundoff(tt) < hr2)
hourstamps << (xmap+0.02) << " " << ymap << " 6" <<font_delim << "0 0 ML " << (int) roundoff(tt) << endl;
hourdots << xmap << " " << ymap << endl;
}
// save arrow info
arrowsx[ prnNum ][0] = arrowsx[ prnNum ][1];
arrowsx[ prnNum ][1] = xmap ;
arrowsy[ prnNum ][0] = arrowsy[ prnNum ][1];
arrowsy[ prnNum ][1] = ymap ;
if ( arrowsx[prnNum][0] != -9999.0 && arrowsx[prnNum][1] != -9999.0 &&
arrowsy[prnNum][0] != -9999.0 && arrowsy[prnNum][1] != -9999.0
&& fabs( currData[prnNum] ) > 0.00000001 )
{
dx = arrowsx[prnNum][1] - arrowsx[prnNum][0];
dy = arrowsy[prnNum][1] - arrowsy[prnNum][0];
az = atan2( dx,dy);
dx = (fabs(currData[prnNum]) * scaleBar) * sin( az );
dy = (fabs(currData[prnNum]) * scaleBar) * cos( az );
if (highlight && startHighlightTime <= currEpoch && ( endHighlightTime >= currEpoch || endHighlightTime.GetMJD().mjd <= 0))
{
if( currData[prnNum] > 0.0 )
{
mpHighlight << arrowsx[prnNum][1] << " " << arrowsy[prnNum][1]
<< " " << -dy
<< " " << dx << " 0 0 0 " << prnNum << endl;
}
else
{
mpHighlight << arrowsx[prnNum][1] << " " << arrowsy[prnNum][1]
<< " " << dy
<< " " << -dx << " 0 0 0 " << prnNum << endl;
}
}
else
{
if( currData[prnNum] > 0.0 )
{
mp << arrowsx[prnNum][1] << " " << arrowsy[prnNum][1]
<< " " << -dy
<< " " << dx << " 0 0 0 " << prnNum << endl;
}
else
{
mp << arrowsx[prnNum][1] << " " << arrowsy[prnNum][1]
<< " " << dy
<< " " << -dx << " 0 0 0 " << prnNum << endl;
}
}
}
} // end if
} // if ierr == 0
} // end of for loop over all MAXSVS
} // do if currEpoch is between user's start and end times
} // end of while-loop over all epochs
cfplt.close();
mp.close();
mpHighlight.close();
// check that the file stop time agrees with the user's start time
if( currEpoch < startTime )
{
out << "Error. File Stop Time is before the User's Start Time! " << endl
<< "File Stop Time (YMDHMS): " << currEpoch << " User Start Time (YMDHMS): "
<< startTime << endl << "Terminating program." << endl << endl;
cerr << "Error. File Stop Time is before the User's Start Time! " << endl
<< "File Stop Time (YMDHMS): " << currEpoch << " User Start Time (YMDHMS): "
<< startTime << endl << "Terminating program." << endl << endl;
out.close();
exit(1);
}
hourstamps.close();
hourdots.close();
azelOut.close();
out << "\n\nFinished writing azimuth/elevation " << endl;
// arrow data
ofstream arrowsf( arrowsFile.c_str() );
if ( ! arrowsf ) {
cout << "ERROR: cant open " << arrowsFile <<" ! " << endl;
exit(0);
}
double rad = 0.1;
int acount = 0;
for (i=0; i < 40 ; ++i ) {
if ( arrowsx[i][0] != -9999.0 && arrowsx[i][1] != -9999.0 &&
arrowsy[i][0] != -9999.0 && arrowsy[i][1] != -9999.0 ) {
acount++;
dx = arrowsx[i][1] - arrowsx[i][0];
dy = arrowsy[i][1] - arrowsy[i][0];
az = atan2( dx,dy);
dx = rad * sin( az );
dy = rad * cos( az );
arrowsf << arrowsx[i][1] << " " << arrowsy[i][1] << " " << dx << " " <<
dy << " 0 0 0 " << i << endl;
outbat << gmt << "psxy " << i << satFileExt << " -R -JX -W0.15p" << pen_delim << "0 -V -P " << multi_seg << " -O -K >> " << psFile << endl;
}
}
arrowsf.close();
// compute elevation angle rings
ofstream outf(elevRingFile.c_str());
if ( !outf )
{
cerr << "Error opening "<< elevRingFile <<" ! " << endl;
return -1;
}
ofstream outCut(cutoffRingFile.c_str());
if ( !outCut )
{
cerr << "Error opening " << cutoffRingFile << " ! " << endl;
return -1;
}
outf.setf( ios::fixed, ios::floatfield );
outCut.setf( ios::fixed, ios::floatfield );
r[0] = jpi/2.0 - 0. *jpi / 180.0;
r[1] = jpi/2.0 - 30. *jpi / 180.0;
r[2] = jpi/2.0 - 60. *jpi / 180.0;
r[3] = jpi/2.0 - cutoffAngle *jpi / 180.0;
// nominal rings
for ( j=0; j<3; ++j ) {
outf << ">" << endl;
for ( i=0; i <= 360; ++i ) {
xmap = r[j] * cos( i * jpi/ 180.0 );
ymap = r[j] * sin( i * jpi/ 180.0 );
outf <<
setw(18) << setprecision(8) << xmap <<
setw(18) << setprecision(8) << ymap << endl;
}
}
// cutoff rings
j = 3;
outf << ">" << endl;
for ( i=0; i <= 360; ++i ) {
xmap = r[j] * cos( i * jpi/ 180.0 );
ymap = r[j] * sin( i * jpi/ 180.0 );
outCut <<
setw(18) << setprecision(8) << xmap <<
setw(18) << setprecision(8) << ymap << endl;
}
outf.close();
outCut.close();
ofstream outcross(crossFile.c_str());
if ( !outcross )
{
cerr << "Error opening " << crossFile <<" ! " << endl;
return -1;
}
// nesw cross
outcross << ">" << endl;
outcross <<
setw(18) << setprecision(8) << ( 120 * jpi/180.0) <<
setw(18) << setprecision(8) << 0 << endl;