source: ntrip/trunk/BNC/bncutils.cpp@ 219

Last change on this file since 219 was 219, checked in by mervart, 18 years ago

* empty log message *

File size: 2.0 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Client
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
18#include <iostream>
19#include <ctime>
20
21#include <QRegExp>
22#include <QStringList>
23
24#include "bncutils.h"
25
26using namespace std;
27
28void expandEnvVar(QString& str) {
29
30 QRegExp rx("(\\$\\{.+\\})");
31
32 if (rx.indexIn(str) != -1) {
33 QStringListIterator it(rx.capturedTexts());
34 if (it.hasNext()) {
35 QString rxStr = it.next();
36 QString envVar = rxStr.mid(2,rxStr.length()-3);
37 str.replace(rxStr, qgetenv(envVar.toAscii()));
38 }
39 }
40
41}
42
43QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
44
45 static const QDate zeroEpoch(1980, 1, 6);
46
47 QDate date(zeroEpoch);
48 QTime time(0,0,0,0);
49
50 int weekDays = int(GPSWeeks) / 86400;
51 date = date.addDays( GPSWeek * 7 + weekDays );
52 time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
53
54 return QDateTime(date,time);
55}
56
57double MJD(int year, int month, double day) {
58 if( month <= 2 ) {
59 year = year - 1;
60 month = month + 12;
61 }
62 int ii = year/100;
63 int kk = 2 - ii + ii/4;
64 double mjd = (365.25*year - fmod( 365.25*year, 1.0 )) - 679006.0
65 + floor( 30.6001*(month + 1) ) + day + kk;
66 return mjd;
67}
68
69void MJD_GPSWeeks(double mjd, int& week, double& sec) {
70 double deltat = mjd - 44244.0 ;
71 week = (long) floor(deltat/7.0);
72 sec = (deltat - (week)*7.0)*86400.0;
73}
74
75void currentGPSWeeks(int& week, double& sec) {
76
77 time_t ltime;
78 struct tm *gmt;
79
80 time(&ltime);
81 gmt = gmtime(&ltime);
82
83 double dayFrac = (( gmt->tm_sec / 60.0
84 + gmt->tm_min ) / 60.0
85 + gmt->tm_hour ) / 24.0;
86
87 double mjd = MJD(1900+gmt->tm_year, gmt->tm_mon+1, gmt->tm_mday+dayFrac);
88
89 MJD_GPSWeeks(mjd, week, sec);
90}
Note: See TracBrowser for help on using the repository browser.