MRTKLIB 0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_coords.c File Reference

MRTKLIB Coordinates Module — Coordinate transformations and geometry. More...

#include "mrtklib/mrtk_coords.h"
#include <math.h>
#include <string.h>
#include "mrtklib/mrtk_trace.h"
Include dependency graph for mrtk_coords.c:

Go to the source code of this file.

Macros

#define PI   3.1415926535897932 /* pi */
#define D2R   (PI / 180.0) /* deg to rad */
#define AS2R   (D2R / 3600.0) /* arc sec to radian */
#define RE_WGS84   6378137.0 /* earth semimajor axis (WGS84) (m) */
#define FE_WGS84   (1.0 / 298.257223563) /* earth flattening (WGS84) */
#define OMGE   7.2921151467E-5 /* earth angular velocity (IS-GPS) (rad/s) */
#define CLIGHT   299792458.0 /* speed of light (m/s) */
#define MAXSAT   256
#define Rx(t, X)
#define Ry(t, X)
#define Rz(t, X)
#define SQRT(x)

Functions

void deg2dms (double deg, double *dms, int ndec)
 Convert degree to degree-minute-second.
double dms2deg (const double *dms)
 Convert degree-minute-second to degree.
void ecef2pos (const double *r, double *pos)
 Transform ECEF position to geodetic position.
void pos2ecef (const double *pos, double *r)
 Transform geodetic position to ECEF position.
void xyz2enu (const double *pos, double *E)
 Compute ECEF to local coordinate transformation matrix.
void ecef2enu (const double *pos, const double *r, double *e)
 Transform ECEF vector to local tangential coordinate.
void enu2ecef (const double *pos, const double *e, double *r)
 Transform local tangential coordinate vector to ECEF.
void covenu (const double *pos, const double *P, double *Q)
 Transform ECEF covariance to local tangential coordinate.
void covecef (const double *pos, const double *Q, double *P)
 Transform local ENU covariance to ECEF coordinate.
static void ast_args (double t, double *f)
static void nut_iau1980 (double t, const double *f, double *dpsi, double *deps)
void eci2ecef (gtime_t tutc, const double *erpv, double *U, double *gmst)
 Compute ECI to ECEF transformation matrix.
double geodist (const double *rs, const double *rr, double *e)
 Compute geometric distance and receiver-to-satellite unit vector.
double satazel (const double *pos, const double *e, double *azel)
 Compute satellite azimuth/elevation angle.
void dops (int ns, const double *azel, double elmin, double *dop)
 Compute DOP (dilution of precision).

Detailed Description

MRTKLIB Coordinates Module — Coordinate transformations and geometry.

This file contains all coordinate transformation and positioning geometry functions extracted from rtkcmn.c with zero algorithmic changes (pure cut-and-paste).

Definition in file mrtk_coords.c.

Macro Definition Documentation

◆ AS2R

#define AS2R   (D2R / 3600.0) /* arc sec to radian */

Definition at line 37 of file mrtk_coords.c.

Referenced by ast_args(), ast_args(), eci2ecef(), nut_iau1980(), readerp(), and tide_pole().

◆ CLIGHT

◆ D2R

◆ FE_WGS84

#define FE_WGS84   (1.0 / 298.257223563) /* earth flattening (WGS84) */

Definition at line 39 of file mrtk_coords.c.

Referenced by ecef2pos(), and pos2ecef().

◆ MAXSAT

#define MAXSAT   256

Definition at line 45 of file mrtk_coords.c.

Referenced by add_base_value_to_cbias(), add_base_value_to_pbias(), buff2sysopts(), check_same_fac(), clas_bank_get_close(), clas_osr_compensatedisp(), clas_osr_ctx_init(), clas_osr_zdres(), clas_restore_backup(), clas_ssr2osr(), clas_update_global(), combpclk(), combpeph(), convnav(), corr_iono_distwgt(), corr_iono_plane(), ddidx(), ddmat(), ddmat(), ddres(), ddres(), ddres(), decode_bnx_01_04(), decode_bnx_01_14(), decode_cssr_bias(), decode_cssr_cb(), decode_cssr_cc(), decode_cssr_combo(), decode_cssr_oc(), decode_cssr_pb(), decode_eph(), decode_galephemerisb(), decode_galinavephemerisb(), decode_galrawfnav(), decode_has_mask(), decode_lcliono(), decode_longcorr0(), decode_longcorr1(), decode_mcssr_mask(), decode_sbstype1(), decode_sbstype6(), decode_sbstype7(), decode_trkd5(), decode_trkmeas(), decode_type1045(), decoderaw(), detslp_dop(), dops(), dump_halfc(), encode_ssr1(), encode_ssr2(), encode_ssr3(), encode_ssr4(), encode_ssr5(), encode_ssr6(), encode_ssr7(), encode_type1045(), estpos(), exclsat(), flushobuf(), free_strfile(), freebiass(), gen_strfile(), get_iono_sta(), grid_intp_iono(), holdamb(), holdamb(), holdamb(), init_grid_index(), init_mdcl6d(), init_raw(), init_rnxctr(), init_rtcm(), input_rnxctr(), load_ppp_osr_cpc(), miono_get_corr(), nextsat(), outbsnxsol(), outnmea_gsa(), outnmea_gsv(), outsolstat(), peph2pos(), pntpos(), ppp_amb_ILS(), ppp_res(), ppp_rtk_pos(), pppos(), pppoutstat(), ppprtk_outstat(), raw2rtcm(), readbnxfp(), readdcb(), readionexdcb(), readrnxclk(), readrnxobs(), readsap(), readsp3(), readsp3b(), readsp3h(), readtec(), relpos(), relposvrs(), rescode(), residual_test(), residual_test(), restamb(), restamb(), restamb(), rtcm2rtcm(), rtkinit(), rtkoutstat(), rtksvrinit(), rtksvrstart(), satsys(), save_ppp_osr_cpc(), savenav(), search_amb_lambda(), seleph(), selsat(), set_cssr_bank_cbias(), set_cssr_bank_clock(), set_cssr_bank_orbit(), set_cssr_bank_pbias(), setpcv(), sta_sel_iono(), sysopts2buff(), test_hold_amb(), tracepclk(), tracepeph(), udbias(), udbias_ppp(), udbias_ppp(), udbias_ppp(), udfcb_sat(), udion(), udion(), udion(), udiono_ppp(), udosb_sat(), udosb_station(), udpos(), udsatcb(), udsatpb(), udstacb(), update_eph(), update_gal_has(), update_qzssl6d(), update_qzssl6e(), update_rtcm(), update_ssr(), update_stat(), update_stat(), update_stat(), and valid_zd_sig().

◆ OMGE

#define OMGE   7.2921151467E-5 /* earth angular velocity (IS-GPS) (rad/s) */

Definition at line 40 of file mrtk_coords.c.

Referenced by alm2pos(), eph2pos(), geodist(), pephpos(), resdop(), sat_yaw(), and windupcorr().

◆ PI

◆ RE_WGS84

#define RE_WGS84   6378137.0 /* earth semimajor axis (WGS84) (m) */

◆ Rx

#define Rx ( t,
X )
Value:
do { \
(X)[0] = 1.0; \
(X)[1] = (X)[2] = (X)[3] = (X)[6] = 0.0; \
(X)[4] = (X)[8] = cos(t); \
(X)[7] = sin(t); \
(X)[5] = -(X)[7]; \
} while (0)

Definition at line 215 of file mrtk_coords.c.

Referenced by eci2ecef().

◆ Ry

#define Ry ( t,
X )
Value:
do { \
(X)[4] = 1.0; \
(X)[1] = (X)[3] = (X)[5] = (X)[7] = 0.0; \
(X)[0] = (X)[8] = cos(t); \
(X)[2] = sin(t); \
(X)[6] = -(X)[2]; \
} while (0)

Definition at line 224 of file mrtk_coords.c.

Referenced by eci2ecef().

◆ Rz

#define Rz ( t,
X )
Value:
do { \
(X)[8] = 1.0; \
(X)[2] = (X)[5] = (X)[6] = (X)[7] = 0.0; \
(X)[0] = (X)[4] = cos(t); \
(X)[3] = sin(t); \
(X)[1] = -(X)[3]; \
} while (0)

Definition at line 233 of file mrtk_coords.c.

Referenced by eci2ecef().

◆ SQRT

#define SQRT ( x)
Value:
((x) < 0.0 || (x) != (x) ? 0.0 : sqrt(x))

Definition at line 543 of file mrtk_coords.c.

Referenced by dops(), outecef(), outenu(), outpos(), and ppprtk_outstat().

Function Documentation

◆ ast_args()

void ast_args ( double t,
double * f )
static

Definition at line 243 of file mrtk_coords.c.

References AS2R, and PI.

Referenced by eci2ecef().

Here is the caller graph for this function:

◆ covecef()

void covecef ( const double * pos,
const double * Q,
double * P )
extern

Transform local ENU covariance to ECEF coordinate.

Parameters
[in]posGeodetic position {lat, lon} (rad)
[in]QCovariance in local ENU coordinate
[out]PCovariance in ECEF coordinate

Definition at line 202 of file mrtk_coords.c.

References matmul(), and xyz2enu().

Referenced by decode_solllh(), udpos(), udpos(), udpos_ppp(), and udpos_ppp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ covenu()

void covenu ( const double * pos,
const double * P,
double * Q )
extern

Transform ECEF covariance to local tangential coordinate.

Parameters
[in]posGeodetic position {lat, lon} (rad)
[in]PCovariance in ECEF coordinate
[out]QCovariance in local tangential coordinate

Definition at line 188 of file mrtk_coords.c.

References matmul(), and xyz2enu().

Referenced by const_iono_corr(), outenu(), and outpos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deg2dms()

void deg2dms ( double deg,
double * dms,
int ndec )
extern

Convert degree to degree-minute-second.

Parameters
[in]degDegree
[out]dmsDegree-minute-second {deg, min, sec}
[in]ndecNumber of decimals of second

Definition at line 63 of file mrtk_coords.c.

Referenced by outnmea_gga(), outnmea_rmc(), outpos(), and outrpos().

Here is the caller graph for this function:

◆ dms2deg()

double dms2deg ( const double * dms)
extern

Convert degree-minute-second to degree.

Parameters
[in]dmsDegree-minute-second {deg, min, sec}
Returns
Degree

Definition at line 86 of file mrtk_coords.c.

Referenced by decode_refpos(), and decode_solllh().

Here is the caller graph for this function:

◆ dops()

void dops ( int ns,
const double * azel,
double elmin,
double * dop )
extern

Compute DOP (dilution of precision).

Parameters
[in]nsNumber of satellites
[in]azelSatellite azimuth/elevation angle (rad)
[in]elminElevation cutoff angle (rad)
[out]dopDOPs {GDOP, PDOP, HDOP, VDOP}
Note
dop[0]-[3] return 0 in case of DOP computation error.

Definition at line 545 of file mrtk_coords.c.

References matinv(), matmul(), MAXSAT, and SQRT.

Referenced by outnmea_gsa(), valsol(), zddop(), and zddop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecef2enu()

void ecef2enu ( const double * pos,
const double * r,
double * e )
extern

Transform ECEF vector to local tangential coordinate.

Parameters
[in]posGeodetic position {lat, lon} (rad)
[in]rVector in ECEF coordinate {x, y, z}
[out]eVector in local tangential coordinate {e, n, u}

Definition at line 162 of file mrtk_coords.c.

References matmul(), and xyz2enu().

Referenced by outenu(), outnmea_rmc(), outpos(), outrnxevent(), pppoutstat(), ppprtk_outstat(), rtkoutstat(), satazel(), setopt_sta(), and setpcv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ecef2pos()

void ecef2pos ( const double * r,
double * pos )
extern

Transform ECEF position to geodetic position.

Parameters
[in]rECEF position {x, y, z} (m)
[out]posGeodetic position {lat, lon, h} (rad, m)
Note
WGS84, ellipsoidal height.

Definition at line 102 of file mrtk_coords.c.

References dot(), FE_WGS84, PI, and RE_WGS84.

Referenced by antpos(), clas_osr_zdres(), clas_ssr2osr(), const_iono_corr(), corr_iono_plane(), corr_trop_plane(), ddres(), ddres(), ddres(), decode_type1005(), decode_type1006(), dump_stas(), get_site(), gettriangledd(), miono_get_corr(), model_phw(), outenu(), outnmea_gga(), outnmea_rmc(), outpos(), outrnxevent(), outrpos(), ppp_res(), ppp_rtk_pos(), pppoutstat(), ppprtk_outstat(), rescode(), resdop(), rtkoutstat(), rtksvrmark(), selpersta(), setopt_sta(), setpcv(), sta_sel_iono(), sta_sel_trop(), sysopts2buff(), udbias_ppp(), udiono_ppp(), udpos(), udpos(), udpos_ppp(), udpos_ppp(), udtrop_ppp(), update_antpos(), windupcorr(), zdres(), and zdres().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eci2ecef()

void eci2ecef ( gtime_t tutc,
const double * erpv,
double * U,
double * gmst )
extern

Compute ECI to ECEF transformation matrix.

Parameters
[in]tutcTime in UTC
[in]erpvERP values {xp, yp, ut1_utc, lod} (rad, rad, s, s/d)
[out]UECI to ECEF transformation matrix (3x3)
[in,out]gmstGreenwich mean sidereal time (rad) (NULL: no output)
Note
Not thread-safe (uses static cache).

Definition at line 399 of file mrtk_coords.c.

References AS2R, ast_args(), epoch2time(), matmul(), NP, nut_iau1980(), Rx, Ry, Rz, time_str(), timediff(), trace(), tracemat(), utc2gmst(), and utc2gpst().

Referenced by sunmoonpos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enu2ecef()

void enu2ecef ( const double * pos,
const double * e,
double * r )
extern

Transform local tangential coordinate vector to ECEF.

Parameters
[in]posGeodetic position {lat, lon} (rad)
[in]eVector in local tangential coordinate {e, n, u}
[out]rVector in ECEF coordinate {x, y, z}

Definition at line 175 of file mrtk_coords.c.

References matmul(), and xyz2enu().

Referenced by antpos(), decode_solllh(), and update_antpos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ geodist()

double geodist ( const double * rs,
const double * rr,
double * e )
extern

Compute geometric distance and receiver-to-satellite unit vector.

Parameters
[in]rsSatellite position (ECEF at transmission) (m)
[in]rrReceiver position (ECEF at reception) (m)
[out]eLine-of-sight vector (ECEF)
Returns
Geometric distance (m) (<0: error/no satellite position)
Note
Distance includes Sagnac effect correction.

Definition at line 493 of file mrtk_coords.c.

References CLIGHT, norm(), OMGE, and RE_WGS84.

Referenced by clas_osr_adjust_r_dts(), clas_osr_zdres(), ppp_res(), rescode(), zdres(), and zdres().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nut_iau1980()

void nut_iau1980 ( double t,
const double * f,
double * dpsi,
double * deps )
static

Definition at line 265 of file mrtk_coords.c.

References AS2R.

Referenced by eci2ecef().

Here is the caller graph for this function:

◆ pos2ecef()

void pos2ecef ( const double * pos,
double * r )
extern

Transform geodetic position to ECEF position.

Parameters
[in]posGeodetic position {lat, lon, h} (rad, m)
[out]rECEF position {x, y, z} (m)
Note
WGS84, ellipsoidal height.

Definition at line 122 of file mrtk_coords.c.

References FE_WGS84, and RE_WGS84.

Referenced by buff2sysopts(), decode_bnx_00(), decode_lcliono(), decode_lcltrop(), decode_nmeagga(), decode_nmearmc(), decode_pvtgeodetic(), decode_refpos(), decode_solllh(), get_site(), getstapos(), miono_sel_area(), and selpersta().

Here is the caller graph for this function:

◆ satazel()

double satazel ( const double * pos,
const double * e,
double * azel )
extern

Compute satellite azimuth/elevation angle.

Parameters
[in]posGeodetic position {lat, lon, h} (rad, m)
[in]eReceiver-to-satellite unit vector (ECEF)
[in,out]azelAzimuth/elevation {az, el} (rad) (NULL: no output) (0.0<=azel[0]<2*pi, -pi/2<=azel[1]<=pi/2)
Returns
Elevation angle (rad)

Definition at line 517 of file mrtk_coords.c.

References dot(), ecef2enu(), PI, and RE_WGS84.

Referenced by clas_osr_zdres(), ppp_res(), rescode(), zdres(), and zdres().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xyz2enu()

void xyz2enu ( const double * pos,
double * E )
extern

Compute ECEF to local coordinate transformation matrix.

Parameters
[in]posGeodetic position {lat, lon} (rad)
[out]EECEF to local coord transformation matrix (3x3)
Note
Matrix stored by column-major order (Fortran convention).

Definition at line 142 of file mrtk_coords.c.

Referenced by clas_osr_zdres(), covecef(), covenu(), ecef2enu(), enu2ecef(), model_phw(), resdop(), tidedisp(), and windupcorr().

Here is the caller graph for this function: