source: ntrip/trunk/BNC/src/bncutils.cpp@ 6168

Last change on this file since 6168 was 6168, checked in by mervart, 10 years ago
File size: 19.0 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncutils
30 *
31 * Purpose: Auxiliary Functions
32 *
33 * Author: L. Mervart
34 *
35 * Created: 30-Aug-2006
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include <ctime>
43#include <math.h>
44
45#include <QRegExp>
46#include <QStringList>
47#include <QDateTime>
48
49#include <newmatap.h>
50
51#include "bncutils.h"
52#include "bnccore.h"
53
54using namespace std;
55
56//
57////////////////////////////////////////////////////////////////////////////
58void expandEnvVar(QString& str) {
59
60 QRegExp rx("(\\$\\{.+\\})");
61
62 if (rx.indexIn(str) != -1) {
63 QStringListIterator it(rx.capturedTexts());
64 if (it.hasNext()) {
65 QString rxStr = it.next();
66 QString envVar = rxStr.mid(2,rxStr.length()-3);
67 str.replace(rxStr, qgetenv(envVar.toAscii()));
68 }
69 }
70
71}
72
73// Strip White Space
74////////////////////////////////////////////////////////////////////////////
75void stripWhiteSpace(string& str) {
76 if (!str.empty()) {
77 string::size_type beg = str.find_first_not_of(" \t\f\n\r\v");
78 string::size_type end = str.find_last_not_of(" \t\f\n\r\v");
79 if (beg > str.max_size())
80 str.erase();
81 else
82 str = str.substr(beg, end-beg+1);
83 }
84}
85
86//
87////////////////////////////////////////////////////////////////////////////
88QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
89
90 static const QDate zeroEpoch(1980, 1, 6);
91
92 QDate date(zeroEpoch);
93 QTime time(0,0,0,0);
94
95 int weekDays = int(GPSWeeks) / 86400;
96 date = date.addDays( GPSWeek * 7 + weekDays );
97 time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
98
99 return QDateTime(date,time);
100}
101
102//
103////////////////////////////////////////////////////////////////////////////
104void currentGPSWeeks(int& week, double& sec) {
105
106 QDateTime currDateTimeGPS;
107
108 if ( BNC_CORE->dateAndTimeGPSSet() ) {
109 currDateTimeGPS = BNC_CORE->dateAndTimeGPS();
110 }
111 else {
112 currDateTimeGPS = QDateTime::currentDateTime().toUTC();
113 QDate hlp = currDateTimeGPS.date();
114 currDateTimeGPS = currDateTimeGPS.addSecs(gnumleap(hlp.year(),
115 hlp.month(), hlp.day()));
116 }
117
118 QDate currDateGPS = currDateTimeGPS.date();
119 QTime currTimeGPS = currDateTimeGPS.time();
120
121 week = int( (double(currDateGPS.toJulianDay()) - 2444244.5) / 7 );
122
123 sec = (currDateGPS.dayOfWeek() % 7) * 24.0 * 3600.0 +
124 currTimeGPS.hour() * 3600.0 +
125 currTimeGPS.minute() * 60.0 +
126 currTimeGPS.second() +
127 currTimeGPS.msec() / 1000.0;
128}
129
130//
131////////////////////////////////////////////////////////////////////////////
132QDateTime currentDateAndTimeGPS() {
133 if ( BNC_CORE->dateAndTimeGPSSet() ) {
134 return BNC_CORE->dateAndTimeGPS();
135 }
136 else {
137 int GPSWeek;
138 double GPSWeeks;
139 currentGPSWeeks(GPSWeek, GPSWeeks);
140 return dateAndTimeFromGPSweek(GPSWeek, GPSWeeks);
141 }
142}
143
144//
145////////////////////////////////////////////////////////////////////////////
146QByteArray ggaString(const QByteArray& latitude,
147 const QByteArray& longitude,
148 const QByteArray& height) {
149
150 double lat = strtod(latitude,NULL);
151 double lon = strtod(longitude,NULL);
152 double hei = strtod(height,NULL);
153
154 const char* flagN="N";
155 const char* flagE="E";
156 if (lon >180.) {lon=(lon-360.)*(-1.); flagE="W";}
157 if ((lon < 0.) && (lon >= -180.)) {lon=lon*(-1.); flagE="W";}
158 if (lon < -180.) {lon=(lon+360.); flagE="E";}
159 if (lat < 0.) {lat=lat*(-1.); flagN="S";}
160 QTime ttime(QDateTime::currentDateTime().toUTC().time());
161 int lat_deg = (int)lat;
162 double lat_min=(lat-lat_deg)*60.;
163 int lon_deg = (int)lon;
164 double lon_min=(lon-lon_deg)*60.;
165 int hh = 0 , mm = 0;
166 double ss = 0.0;
167 hh=ttime.hour();
168 mm=ttime.minute();
169 ss=(double)ttime.second()+0.001*ttime.msec();
170 QString gga;
171 gga += "GPGGA,";
172 gga += QString("%1%2%3,").arg((int)hh, 2, 10, QLatin1Char('0')).arg((int)mm, 2, 10, QLatin1Char('0')).arg((int)ss, 2, 10, QLatin1Char('0'));
173 gga += QString("%1%2,").arg((int)lat_deg,2, 10, QLatin1Char('0')).arg(lat_min, 7, 'f', 4, QLatin1Char('0'));
174 gga += flagN;
175 gga += QString(",%1%2,").arg((int)lon_deg,3, 10, QLatin1Char('0')).arg(lon_min, 7, 'f', 4, QLatin1Char('0'));
176 gga += flagE + QString(",1,05,1.00");
177 gga += QString(",%1,").arg(hei, 2, 'f', 1);
178 gga += QString("M,10.000,M,,");
179 int xori;
180 char XOR = 0;
181 char *Buff =gga.toAscii().data();
182 int iLen = strlen(Buff);
183 for (xori = 0; xori < iLen; xori++) {
184 XOR ^= (char)Buff[xori];
185 }
186 gga = "$" + gga + QString("*%1").arg(XOR, 2, 16, QLatin1Char('0'));
187
188 return gga.toAscii();
189}
190
191//
192////////////////////////////////////////////////////////////////////////////
193void RSW_to_XYZ(const ColumnVector& rr, const ColumnVector& vv,
194 const ColumnVector& rsw, ColumnVector& xyz) {
195
196 ColumnVector along = vv / vv.norm_Frobenius();
197 ColumnVector cross = crossproduct(rr, vv); cross /= cross.norm_Frobenius();
198 ColumnVector radial = crossproduct(along, cross);
199
200 Matrix RR(3,3);
201 RR.Column(1) = radial;
202 RR.Column(2) = along;
203 RR.Column(3) = cross;
204
205 xyz = RR * rsw;
206}
207
208// Transformation xyz --> radial, along track, out-of-plane
209////////////////////////////////////////////////////////////////////////////
210void XYZ_to_RSW(const ColumnVector& rr, const ColumnVector& vv,
211 const ColumnVector& xyz, ColumnVector& rsw) {
212
213 ColumnVector along = vv / vv.norm_Frobenius();
214 ColumnVector cross = crossproduct(rr, vv); cross /= cross.norm_Frobenius();
215 ColumnVector radial = crossproduct(along, cross);
216
217 rsw.ReSize(3);
218 rsw(1) = DotProduct(xyz, radial);
219 rsw(2) = DotProduct(xyz, along);
220 rsw(3) = DotProduct(xyz, cross);
221}
222
223// Rectangular Coordinates -> Ellipsoidal Coordinates
224////////////////////////////////////////////////////////////////////////////
225t_irc xyz2ell(const double* XYZ, double* Ell) {
226
227 const double bell = t_CST::aell*(1.0-1.0/t_CST::fInv) ;
228 const double e2 = (t_CST::aell*t_CST::aell-bell*bell)/(t_CST::aell*t_CST::aell) ;
229 const double e2c = (t_CST::aell*t_CST::aell-bell*bell)/(bell*bell) ;
230
231 double nn, ss, zps, hOld, phiOld, theta, sin3, cos3;
232
233 ss = sqrt(XYZ[0]*XYZ[0]+XYZ[1]*XYZ[1]) ;
234 zps = XYZ[2]/ss ;
235 theta = atan( (XYZ[2]*t_CST::aell) / (ss*bell) );
236 sin3 = sin(theta) * sin(theta) * sin(theta);
237 cos3 = cos(theta) * cos(theta) * cos(theta);
238
239 // Closed formula
240 Ell[0] = atan( (XYZ[2] + e2c * bell * sin3) / (ss - e2 * t_CST::aell * cos3) );
241 Ell[1] = atan2(XYZ[1],XYZ[0]) ;
242 nn = t_CST::aell/sqrt(1.0-e2*sin(Ell[0])*sin(Ell[0])) ;
243 Ell[2] = ss / cos(Ell[0]) - nn;
244
245 const int MAXITER = 100;
246 for (int ii = 1; ii <= MAXITER; ii++) {
247 nn = t_CST::aell/sqrt(1.0-e2*sin(Ell[0])*sin(Ell[0])) ;
248 hOld = Ell[2] ;
249 phiOld = Ell[0] ;
250 Ell[2] = ss/cos(Ell[0])-nn ;
251 Ell[0] = atan(zps/(1.0-e2*nn/(nn+Ell[2]))) ;
252 if ( fabs(phiOld-Ell[0]) <= 1.0e-11 && fabs(hOld-Ell[2]) <= 1.0e-5 ) {
253 return success;
254 }
255 }
256
257 return failure;
258}
259
260// Rectangular Coordinates -> North, East, Up Components
261////////////////////////////////////////////////////////////////////////////
262void xyz2neu(const double* Ell, const double* xyz, double* neu) {
263
264 double sinPhi = sin(Ell[0]);
265 double cosPhi = cos(Ell[0]);
266 double sinLam = sin(Ell[1]);
267 double cosLam = cos(Ell[1]);
268
269 neu[0] = - sinPhi*cosLam * xyz[0]
270 - sinPhi*sinLam * xyz[1]
271 + cosPhi * xyz[2];
272
273 neu[1] = - sinLam * xyz[0]
274 + cosLam * xyz[1];
275
276 neu[2] = + cosPhi*cosLam * xyz[0]
277 + cosPhi*sinLam * xyz[1]
278 + sinPhi * xyz[2];
279}
280
281// North, East, Up Components -> Rectangular Coordinates
282////////////////////////////////////////////////////////////////////////////
283void neu2xyz(const double* Ell, const double* neu, double* xyz) {
284
285 double sinPhi = sin(Ell[0]);
286 double cosPhi = cos(Ell[0]);
287 double sinLam = sin(Ell[1]);
288 double cosLam = cos(Ell[1]);
289
290 xyz[0] = - sinPhi*cosLam * neu[0]
291 - sinLam * neu[1]
292 + cosPhi*cosLam * neu[2];
293
294 xyz[1] = - sinPhi*sinLam * neu[0]
295 + cosLam * neu[1]
296 + cosPhi*sinLam * neu[2];
297
298 xyz[2] = + cosPhi * neu[0]
299 + sinPhi * neu[2];
300}
301
302//
303////////////////////////////////////////////////////////////////////////////
304double Frac (double x) {
305 return x-floor(x);
306}
307
308//
309////////////////////////////////////////////////////////////////////////////
310double Modulo (double x, double y) {
311 return y*Frac(x/y);
312}
313
314// Round to nearest integer
315////////////////////////////////////////////////////////////////////////////
316double nint(double val) {
317 return ((val < 0.0) ? -floor(fabs(val)+0.5) : floor(val+0.5));
318}
319
320// Jacobian XYZ --> NEU
321////////////////////////////////////////////////////////////////////////////
322void jacobiXYZ_NEU(const double* Ell, Matrix& jacobi) {
323
324 Tracer tracer("jacobiXYZ_NEU");
325
326 double sinPhi = sin(Ell[0]);
327 double cosPhi = cos(Ell[0]);
328 double sinLam = sin(Ell[1]);
329 double cosLam = cos(Ell[1]);
330
331 jacobi(1,1) = - sinPhi * cosLam;
332 jacobi(1,2) = - sinPhi * sinLam;
333 jacobi(1,3) = cosPhi;
334
335 jacobi(2,1) = - sinLam;
336 jacobi(2,2) = cosLam;
337 jacobi(2,3) = 0.0;
338
339 jacobi(3,1) = cosPhi * cosLam;
340 jacobi(3,2) = cosPhi * sinLam;
341 jacobi(3,3) = sinPhi;
342}
343
344// Jacobian Ell --> XYZ
345////////////////////////////////////////////////////////////////////////////
346void jacobiEll_XYZ(const double* Ell, Matrix& jacobi) {
347
348 Tracer tracer("jacobiEll_XYZ");
349
350 double sinPhi = sin(Ell[0]);
351 double cosPhi = cos(Ell[0]);
352 double sinLam = sin(Ell[1]);
353 double cosLam = cos(Ell[1]);
354 double hh = Ell[2];
355
356 double bell = t_CST::aell*(1.0-1.0/t_CST::fInv);
357 double e2 = (t_CST::aell*t_CST::aell-bell*bell)/(t_CST::aell*t_CST::aell) ;
358 double nn = t_CST::aell/sqrt(1.0-e2*sinPhi*sinPhi) ;
359
360 jacobi(1,1) = -(nn+hh) * sinPhi * cosLam;
361 jacobi(1,2) = -(nn+hh) * cosPhi * sinLam;
362 jacobi(1,3) = cosPhi * cosLam;
363
364 jacobi(2,1) = -(nn+hh) * sinPhi * sinLam;
365 jacobi(2,2) = (nn+hh) * cosPhi * cosLam;
366 jacobi(2,3) = cosPhi * sinLam;
367
368 jacobi(3,1) = (nn*(1.0-e2)+hh) * cosPhi;
369 jacobi(3,2) = 0.0;
370 jacobi(3,3) = sinPhi;
371}
372
373// Covariance Matrix in NEU
374////////////////////////////////////////////////////////////////////////////
375void covariXYZ_NEU(const SymmetricMatrix& QQxyz, const double* Ell,
376 SymmetricMatrix& Qneu) {
377
378 Tracer tracer("covariXYZ_NEU");
379
380 Matrix CC(3,3);
381 jacobiXYZ_NEU(Ell, CC);
382 Qneu << CC * QQxyz * CC.t();
383}
384
385// Covariance Matrix in XYZ
386////////////////////////////////////////////////////////////////////////////
387void covariNEU_XYZ(const SymmetricMatrix& QQneu, const double* Ell,
388 SymmetricMatrix& Qxyz) {
389
390 Tracer tracer("covariNEU_XYZ");
391
392 Matrix CC(3,3);
393 jacobiXYZ_NEU(Ell, CC);
394 Qxyz << CC.t() * QQneu * CC;
395}
396
397// Fourth order Runge-Kutta numerical integrator for ODEs
398////////////////////////////////////////////////////////////////////////////
399ColumnVector rungeKutta4(
400 double xi, // the initial x-value
401 const ColumnVector& yi, // vector of the initial y-values
402 double dx, // the step size for the integration
403 double* acc, // aditional acceleration
404 ColumnVector (*der)(double x, const ColumnVector& y, double* acc)
405 // A pointer to a function that computes the
406 // derivative of a function at a point (x,y)
407 ) {
408
409 ColumnVector k1 = der(xi , yi , acc) * dx;
410 ColumnVector k2 = der(xi+dx/2.0, yi+k1/2.0, acc) * dx;
411 ColumnVector k3 = der(xi+dx/2.0, yi+k2/2.0, acc) * dx;
412 ColumnVector k4 = der(xi+dx , yi+k3 , acc) * dx;
413
414 ColumnVector yf = yi + k1/6.0 + k2/3.0 + k3/3.0 + k4/6.0;
415
416 return yf;
417}
418//
419////////////////////////////////////////////////////////////////////////////
420double djul(long jj, long mm, double tt) {
421 long ii, kk;
422 double djul ;
423 if( mm <= 2 ) {
424 jj = jj - 1;
425 mm = mm + 12;
426 }
427 ii = jj/100;
428 kk = 2 - ii + ii/4;
429 djul = (365.25*jj - fmod( 365.25*jj, 1.0 )) - 679006.0;
430 djul = djul + floor( 30.6001*(mm + 1) ) + tt + kk;
431 return djul;
432}
433
434//
435////////////////////////////////////////////////////////////////////////////
436double gpjd(double second, int nweek) {
437 double deltat;
438 deltat = nweek*7.0 + second/86400.0 ;
439 return( 44244.0 + deltat) ;
440}
441
442//
443////////////////////////////////////////////////////////////////////////////
444void jdgp(double tjul, double & second, long & nweek) {
445 double deltat;
446 deltat = tjul - 44244.0 ;
447 nweek = (long) floor(deltat/7.0);
448 second = (deltat - (nweek)*7.0)*86400.0;
449}
450
451//
452////////////////////////////////////////////////////////////////////////////
453void jmt(double djul, long& jj, long& mm, double& dd) {
454 long ih, ih1, ih2 ;
455 double t1, t2, t3, t4;
456 t1 = 1.0 + djul - fmod( djul, 1.0 ) + 2400000.0;
457 t4 = fmod( djul, 1.0 );
458 ih = long( (t1 - 1867216.25)/36524.25 );
459 t2 = t1 + 1 + ih - ih/4;
460 t3 = t2 - 1720995.0;
461 ih1 = long( (t3 - 122.1)/365.25 );
462 t1 = 365.25*ih1 - fmod( 365.25*ih1, 1.0 );
463 ih2 = long( (t3 - t1)/30.6001 );
464 dd = t3 - t1 - (int)( 30.6001*ih2 ) + t4;
465 mm = ih2 - 1;
466 if ( ih2 > 13 ) mm = ih2 - 13;
467 jj = ih1;
468 if ( mm <= 2 ) jj = jj + 1;
469}
470
471//
472////////////////////////////////////////////////////////////////////////////
473void GPSweekFromDateAndTime(const QDateTime& dateTime,
474 int& GPSWeek, double& GPSWeeks) {
475
476 static const QDateTime zeroEpoch(QDate(1980, 1, 6),QTime(),Qt::UTC);
477
478 GPSWeek = zeroEpoch.daysTo(dateTime) / 7;
479
480 int weekDay = dateTime.date().dayOfWeek() + 1; // Qt: Monday = 1
481 if (weekDay > 7) weekDay = 1;
482
483 GPSWeeks = (weekDay - 1) * 86400.0
484 - dateTime.time().msecsTo(QTime()) / 1e3;
485}
486
487//
488////////////////////////////////////////////////////////////////////////////
489void GPSweekFromYMDhms(int year, int month, int day, int hour, int min,
490 double sec, int& GPSWeek, double& GPSWeeks) {
491
492 double mjd = djul(year, month, day);
493
494 long GPSWeek_long;
495 jdgp(mjd, GPSWeeks, GPSWeek_long);
496 GPSWeek = GPSWeek_long;
497 GPSWeeks += hour * 3600.0 + min * 60.0 + sec;
498}
499
500//
501////////////////////////////////////////////////////////////////////////////
502void mjdFromDateAndTime(const QDateTime& dateTime, int& mjd, double& dayfrac) {
503
504 static const QDate zeroDate(1858, 11, 17);
505
506 mjd = zeroDate.daysTo(dateTime.date());
507
508 dayfrac = (dateTime.time().hour() +
509 (dateTime.time().minute() +
510 (dateTime.time().second() +
511 dateTime.time().msec() / 1000.0) / 60.0) / 60.0) / 24.0;
512}
513
514//
515////////////////////////////////////////////////////////////////////////////
516bool findInVector(const vector<QString>& vv, const QString& str) {
517 std::vector<QString>::const_iterator it;
518 for (it = vv.begin(); it != vv.end(); ++it) {
519 if ( (*it) == str) {
520 return true;
521 }
522 }
523 return false;
524}
525
526//
527////////////////////////////////////////////////////////////////////////////
528int readInt(const QString& str, int pos, int len, int& value) {
529 bool ok;
530 value = str.mid(pos, len).toInt(&ok);
531 return ok ? 0 : 1;
532}
533
534//
535////////////////////////////////////////////////////////////////////////////
536int readDbl(const QString& str, int pos, int len, double& value) {
537 QString hlp = str.mid(pos, len);
538 for (int ii = 0; ii < hlp.length(); ii++) {
539 if (hlp[ii]=='D' || hlp[ii]=='d' || hlp[ii] == 'E') {
540 hlp[ii]='e';
541 }
542 }
543 bool ok;
544 value = hlp.toDouble(&ok);
545 return ok ? 0 : 1;
546}
547
548// Topocentrical Distance and Elevation
549////////////////////////////////////////////////////////////////////////////
550void topos(double xRec, double yRec, double zRec,
551 double xSat, double ySat, double zSat,
552 double& rho, double& eleSat, double& azSat) {
553
554 double dx[3];
555 dx[0] = xSat-xRec;
556 dx[1] = ySat-yRec;
557 dx[2] = zSat-zRec;
558
559 rho = sqrt( dx[0]*dx[0] + dx[1]*dx[1] + dx[2]*dx[2] );
560
561 double xyzRec[3];
562 xyzRec[0] = xRec;
563 xyzRec[1] = yRec;
564 xyzRec[2] = zRec;
565
566 double Ell[3];
567 double neu[3];
568 xyz2ell(xyzRec, Ell);
569 xyz2neu(Ell, dx, neu);
570
571 eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
572 if (neu[2] < 0) {
573 eleSat *= -1.0;
574 }
575
576 azSat = atan2(neu[1], neu[0]);
577}
578
579// Degrees -> degrees, minutes, seconds
580////////////////////////////////////////////////////////////////////////////
581void deg2DMS(double decDeg, int& deg, int& min, double& sec) {
582 int sgn = (decDeg < 0.0 ? -1 : 1);
583 deg = sgn * static_cast<int>(decDeg);
584 min = static_cast<int>((decDeg - deg)*60);
585 sec = (decDeg - deg - min/60.0) * 3600.0;
586}
587
588//
589////////////////////////////////////////////////////////////////////////////
590QString fortranFormat(double value, int width, int prec) {
591 int expo = value == 0.0 ? 0 : log10(fabs(value));
592 double mant = value == 0.0 ? 0 : value / pow(10, expo);
593 if (fabs(mant) >= 1.0) {
594 mant /= 10.0;
595 expo += 1;
596 }
597 if (expo >= 0) {
598 return QString("%1e+%2").arg(mant, width-4, 'f', prec).arg(expo, 2, 10, QChar('0'));
599 }
600 else {
601 return QString("%1e-%2").arg(mant, width-4, 'f', prec).arg(-expo, 2, 10, QChar('0'));
602 }
603}
604
605//
606//////////////////////////////////////////////////////////////////////////////
607void kalman(const Matrix& AA, const ColumnVector& ll, const DiagonalMatrix& PP,
608 SymmetricMatrix& QQ, ColumnVector& xx) {
609
610 Tracer tracer("kalman");
611
612 int nPar = AA.Ncols();
613 int nObs = AA.Nrows();
614 UpperTriangularMatrix SS = Cholesky(QQ).t();
615
616 Matrix SA = SS*AA.t();
617 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
618 for (int ii = 1; ii <= nObs; ++ii) {
619 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
620 }
621
622 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
623 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
624
625 UpperTriangularMatrix UU;
626 QRZ(SRF, UU);
627
628 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
629 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
630 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
631
632 UpperTriangularMatrix SHi = SH_rt.i();
633
634 Matrix KT = SHi * YY;
635 SymmetricMatrix Hi; Hi << SHi * SHi.t();
636
637 xx += KT.t() * (ll - AA * xx);
638 QQ << (SS.t() * SS);
639}
640
Note: See TracBrowser for help on using the repository browser.