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

Last change on this file since 221 was 221, 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#include <math.h>
21
22#include <QRegExp>
23#include <QStringList>
24
25#include "bncutils.h"
26
27using namespace std;
28
29void 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}
43
44QDateTime 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}
57
58double 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}
69
70void 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}
75
76void currentGPSWeeks(int& week, double& sec) {
77
78 time_t ltime;
79 struct tm *gmt;
80
81 time(&ltime);
82 gmt = gmtime(&ltime);
83
84 double dayFrac = (( gmt->tm_sec / 60.0
85 + gmt->tm_min ) / 60.0
86 + gmt->tm_hour ) / 24.0;
87
88 double mjd = MJD(1900+gmt->tm_year, gmt->tm_mon+1, gmt->tm_mday+dayFrac);
89
90 MJD_GPSWeeks(mjd, week, sec);
91}
Note: See TracBrowser for help on using the repository browser.