[83] | 1 |
|
---|
| 2 | /* -------------------------------------------------------------------------
|
---|
[93] | 3 | * BKG NTRIP Client
|
---|
[83] | 4 | * -------------------------------------------------------------------------
|
---|
| 5 | *
|
---|
| 6 | * Class: bncutils
|
---|
| 7 | *
|
---|
| 8 | * Purpose: Auxiliary Functions
|
---|
| 9 | *
|
---|
| 10 | * Author: L. Mervart
|
---|
| 11 | *
|
---|
| 12 | * Created: 30-Aug-2006
|
---|
| 13 | *
|
---|
| 14 | * Changes:
|
---|
| 15 | *
|
---|
| 16 | * -----------------------------------------------------------------------*/
|
---|
| 17 |
|
---|
[124] | 18 | #include <iostream>
|
---|
[218] | 19 | #include <ctime>
|
---|
[221] | 20 | #include <math.h>
|
---|
[124] | 21 |
|
---|
[83] | 22 | #include <QRegExp>
|
---|
| 23 | #include <QStringList>
|
---|
| 24 |
|
---|
| 25 | #include "bncutils.h"
|
---|
| 26 |
|
---|
[124] | 27 | using namespace std;
|
---|
| 28 |
|
---|
[83] | 29 | void expandEnvVar(QString& str) {
|
---|
| 30 |
|
---|
| 31 | QRegExp rx("(\\$\\{.+\\})");
|
---|
| 32 |
|
---|
| 33 | if (rx.indexIn(str) != -1) {
|
---|
| 34 | QStringListIterator it(rx.capturedTexts());
|
---|
| 35 | if (it.hasNext()) {
|
---|
| 36 | QString rxStr = it.next();
|
---|
| 37 | QString envVar = rxStr.mid(2,rxStr.length()-3);
|
---|
| 38 | str.replace(rxStr, qgetenv(envVar.toAscii()));
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | }
|
---|
[124] | 43 |
|
---|
| 44 | QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
|
---|
| 45 |
|
---|
| 46 | static const QDate zeroEpoch(1980, 1, 6);
|
---|
| 47 |
|
---|
| 48 | QDate date(zeroEpoch);
|
---|
| 49 | QTime time(0,0,0,0);
|
---|
| 50 |
|
---|
| 51 | int weekDays = int(GPSWeeks) / 86400;
|
---|
| 52 | date = date.addDays( GPSWeek * 7 + weekDays );
|
---|
| 53 | time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
|
---|
| 54 |
|
---|
| 55 | return QDateTime(date,time);
|
---|
| 56 | }
|
---|
[210] | 57 |
|
---|
[218] | 58 | double MJD(int year, int month, double day) {
|
---|
| 59 | if( month <= 2 ) {
|
---|
| 60 | year = year - 1;
|
---|
| 61 | month = month + 12;
|
---|
| 62 | }
|
---|
| 63 | int ii = year/100;
|
---|
| 64 | int kk = 2 - ii + ii/4;
|
---|
| 65 | double mjd = (365.25*year - fmod( 365.25*year, 1.0 )) - 679006.0
|
---|
| 66 | + floor( 30.6001*(month + 1) ) + day + kk;
|
---|
| 67 | return mjd;
|
---|
| 68 | }
|
---|
[210] | 69 |
|
---|
[218] | 70 | void MJD_GPSWeeks(double mjd, int& week, double& sec) {
|
---|
| 71 | double deltat = mjd - 44244.0 ;
|
---|
| 72 | week = (long) floor(deltat/7.0);
|
---|
| 73 | sec = (deltat - (week)*7.0)*86400.0;
|
---|
| 74 | }
|
---|
[210] | 75 |
|
---|
[218] | 76 | void currentGPSWeeks(int& week, double& sec) {
|
---|
[210] | 77 |
|
---|
[218] | 78 | time_t ltime;
|
---|
| 79 | struct tm *gmt;
|
---|
[210] | 80 |
|
---|
[218] | 81 | time(<ime);
|
---|
| 82 | gmt = gmtime(<ime);
|
---|
| 83 |
|
---|
| 84 | double dayFrac = (( gmt->tm_sec / 60.0
|
---|
| 85 | + gmt->tm_min ) / 60.0
|
---|
| 86 | + gmt->tm_hour ) / 24.0;
|
---|
| 87 |
|
---|
[219] | 88 | double mjd = MJD(1900+gmt->tm_year, gmt->tm_mon+1, gmt->tm_mday+dayFrac);
|
---|
[218] | 89 |
|
---|
| 90 | MJD_GPSWeeks(mjd, week, sec);
|
---|
[210] | 91 | }
|
---|