From 643a0305911d4564f970eef59511c8773fdbacef Mon Sep 17 00:00:00 2001 From: chenfeiyang <309905109@qq.com> Date: Thu, 11 Jun 2020 23:30:09 +0800 Subject: [PATCH 1/3] add obs_t --- CMakeLists.txt | 3 +++ src/gpstime.h | 11 +++++++++ src/obs_t.cpp | 10 ++++++++ src/obs_t.h | 33 +++++++++++++++++++++++++++ src/rtklib.h | 62 +++++++++++++++----------------------------------- 5 files changed, 75 insertions(+), 44 deletions(-) create mode 100644 src/gpstime.h create mode 100644 src/obs_t.cpp create mode 100644 src/obs_t.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b51df18..c882f8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,9 @@ ${CMAKE_SOURCE_DIR}/src/sbas.cpp ${CMAKE_SOURCE_DIR}/src/solution.cpp ${CMAKE_SOURCE_DIR}/src/tides.cpp ${CMAKE_SOURCE_DIR}/src/rtklib.h +${CMAKE_SOURCE_DIR}/src/gpstime.h +${CMAKE_SOURCE_DIR}/src/obs_t.h +${CMAKE_SOURCE_DIR}/src/obs_t.cpp ) set(COMMIT_HASH "") diff --git a/src/gpstime.h b/src/gpstime.h new file mode 100644 index 0000000..e1f9ef9 --- /dev/null +++ b/src/gpstime.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +#ifndef _GPS_TIME_ +#define _GPS_TIME_ +typedef struct { /* time struct */ + time_t time = 0; /* time (s) expressed by standard time_t */ + double sec = 0.0; /* fraction of second under 1 s */ +} gtime_t; +#endif diff --git a/src/obs_t.cpp b/src/obs_t.cpp new file mode 100644 index 0000000..432c97c --- /dev/null +++ b/src/obs_t.cpp @@ -0,0 +1,10 @@ +#include "obs_t.h" +#include + +int obs_t::addobsdata(const obsd_t* d) +{ + _data.push_back(*d); + data = &_data[0]; + n++; + return 1; +} diff --git a/src/obs_t.h b/src/obs_t.h new file mode 100644 index 0000000..e4064b9 --- /dev/null +++ b/src/obs_t.h @@ -0,0 +1,33 @@ +#pragma once +#include +#include "gpstime.h" + +#ifndef NFREQ +#define NFREQ 3 /* number of carrier frequencies */ +#endif +#define NFREQGLO 2 /* number of carrier frequencies of GLONASS */ + +#ifndef NEXOBS +#define NEXOBS 0 /* number of extended obs codes */ +#endif + +typedef struct { /* observation data record */ + gtime_t time; /* receiver sampling time (GPST) */ + unsigned char sat, rcv; /* satellite/receiver number */ + unsigned char SNR[NFREQ + NEXOBS]; /* signal strength (0.25 dBHz) */ + unsigned char LLI[NFREQ + NEXOBS]; /* loss of lock indicator */ + unsigned char code[NFREQ + NEXOBS]; /* code indicator (CODE_???) */ + double L[NFREQ + NEXOBS]; /* observation data carrier-phase (cycle) */ + double P[NFREQ + NEXOBS]; /* observation data pseudorange (m) */ + float D[NFREQ + NEXOBS]; /* observation data doppler frequency (Hz) */ +} obsd_t; + +class obs_t { +public: + int addobsdata(const obsd_t* data); + + int n = 0; /* number of obervation data */ + int nmax = 0; /* number of obervation data/allocated */ + obsd_t* data = 0; /* observation data records */ + std::vector _data; +}; diff --git a/src/rtklib.h b/src/rtklib.h index 984bf9a..8d98421 100644 --- a/src/rtklib.h +++ b/src/rtklib.h @@ -44,6 +44,9 @@ #else #include #endif + +#include "gpstime.h" +#include "obs_t.h" //#ifdef __cplusplus //extern "C" { //#endif @@ -80,21 +83,21 @@ #define MAXFREQ 7 /* max NFREQ */ -#define FREQ1 1.57542E9 /* L1/E1 frequency (Hz) */ -#define FREQ2 1.22760E9 /* L2 frequency (Hz) */ -#define FREQ5 1.17645E9 /* L5/E5a frequency (Hz) */ -#define FREQ6 1.27875E9 /* E6/LEX frequency (Hz) */ -#define FREQ7 1.20714E9 /* E5b frequency (Hz) */ -#define FREQ8 1.191795E9 /* E5a+b frequency (Hz) */ -#define FREQ9 2.492028E9 /* S frequency (Hz) */ -#define FREQ1_GLO 1.60200E9 /* GLONASS G1 base frequency (Hz) */ -#define DFRQ1_GLO 0.56250E6 /* GLONASS G1 bias frequency (Hz/n) */ -#define FREQ2_GLO 1.24600E9 /* GLONASS G2 base frequency (Hz) */ -#define DFRQ2_GLO 0.43750E6 /* GLONASS G2 bias frequency (Hz/n) */ -#define FREQ3_GLO 1.202025E9 /* GLONASS G3 frequency (Hz) */ -#define FREQ1_CMP 1.561098E9 /* BeiDou B1 frequency (Hz) */ -#define FREQ2_CMP 1.20714E9 /* BeiDou B2 frequency (Hz) */ -#define FREQ3_CMP 1.26852E9 /* BeiDou B3 frequency (Hz) */ +constexpr double FREQ1 = 1.57542E9; /* L1/E1 frequency (Hz) */ +constexpr double FREQ2 = 1.22760E9 ; /* L2 frequency (Hz) */ +constexpr double FREQ5 = 1.17645E9 ; /* L5/E5a frequency (Hz) */ +constexpr double FREQ6 = 1.27875E9 ; /* E6/LEX frequency (Hz) */ +constexpr double FREQ7 = 1.20714E9 ; /* E5b frequency (Hz) */ +constexpr double FREQ8 = 1.191795E9; /* E5a+b frequency (Hz) */ +constexpr double FREQ9 = 2.492028E9; /* S frequency (Hz) */ +constexpr double FREQ1_GLO = 1.60200E9 ; /* GLONASS G1 base frequency (Hz) */ +constexpr double DFRQ1_GLO = 0.56250E6 ; /* GLONASS G1 bias frequency (Hz/n) */ +constexpr double FREQ2_GLO = 1.24600E9 ; /* GLONASS G2 base frequency (Hz) */ +constexpr double DFRQ2_GLO = 0.43750E6 ; /* GLONASS G2 bias frequency (Hz/n) */ +constexpr double FREQ3_GLO = 1.202025E9; /* GLONASS G3 frequency (Hz) */ +constexpr double FREQ1_CMP = 1.561098E9; /* BeiDou B1 frequency (Hz) */ +constexpr double FREQ2_CMP = 1.20714E9 ; /* BeiDou B2 frequency (Hz) */ +constexpr double FREQ3_CMP = 1.26852E9 ; /* BeiDou B3 frequency (Hz) */ #define EFACT_GPS 1.0 /* error factor: GPS */ #define EFACT_GLO 1.5 /* error factor: GLONASS */ @@ -123,14 +126,7 @@ #define TSYS_CMP 5 /* time system: BeiDou time */ #define TSYS_IRN 6 /* time system: IRNSS time */ -#ifndef NFREQ -#define NFREQ 3 /* number of carrier frequencies */ -#endif -#define NFREQGLO 2 /* number of carrier frequencies of GLONASS */ -#ifndef NEXOBS -#define NEXOBS 0 /* number of extended obs codes */ -#endif #define MINPRNGPS 1 /* min satellite PRN number of GPS */ #define MAXPRNGPS 32 /* max satellite PRN number of GPS */ @@ -524,28 +520,6 @@ #endif /* type definitions ----------------------------------------------------------*/ - -typedef struct { /* time struct */ - time_t time; /* time (s) expressed by standard time_t */ - double sec; /* fraction of second under 1 s */ -} gtime_t; - -typedef struct { /* observation data record */ - gtime_t time; /* receiver sampling time (GPST) */ - unsigned char sat,rcv; /* satellite/receiver number */ - unsigned char SNR [NFREQ+NEXOBS]; /* signal strength (0.25 dBHz) */ - unsigned char LLI [NFREQ+NEXOBS]; /* loss of lock indicator */ - unsigned char code[NFREQ+NEXOBS]; /* code indicator (CODE_???) */ - double L[NFREQ+NEXOBS]; /* observation data carrier-phase (cycle) */ - double P[NFREQ+NEXOBS]; /* observation data pseudorange (m) */ - float D[NFREQ+NEXOBS]; /* observation data doppler frequency (Hz) */ -} obsd_t; - -typedef struct { /* observation data */ - int n,nmax; /* number of obervation data/allocated */ - obsd_t *data; /* observation data records */ -} obs_t; - typedef struct { /* earth rotation parameter data type */ double mjd; /* mjd (days) */ double xp,yp; /* pole offset (rad) */ From 5c6fdce39a9c660b0b6382f68680489c37ca436d Mon Sep 17 00:00:00 2001 From: H179378 Date: Fri, 12 Jun 2020 12:40:57 +0800 Subject: [PATCH 2/3] obs_t class --- src/gpstime.h | 6 ++++++ src/obs_t.cpp | 5 ++--- src/obs_t.h | 21 ++++++++++++++++----- src/postpos.cpp | 4 ++-- src/rcv/cmr.cpp | 2 +- src/rcv/javad.cpp | 28 ++++++++++++++-------------- src/rcv/rt17.cpp | 2 +- src/rcvraw.cpp | 16 ++++++++++------ src/rinex.cpp | 22 +++++----------------- src/rtcm.cpp | 7 +++---- src/rtcm3e.cpp | 20 ++++++++++---------- src/rtkcmn.cpp | 18 ++++++++++-------- src/rtklib.h | 12 ++---------- 13 files changed, 82 insertions(+), 81 deletions(-) diff --git a/src/gpstime.h b/src/gpstime.h index e1f9ef9..2dea8e9 100644 --- a/src/gpstime.h +++ b/src/gpstime.h @@ -8,4 +8,10 @@ typedef struct { /* time struct */ time_t time = 0; /* time (s) expressed by standard time_t */ double sec = 0.0; /* fraction of second under 1 s */ } gtime_t; + +gtime_t timeadd(gtime_t t, double sec); +gtime_t operator+(const gtime_t& t, double sec); +gtime_t operator+(double sec, const gtime_t& t); +double timediff(gtime_t t1, gtime_t t2); +double operator-(const gtime_t& t1, const gtime_t& t2); #endif diff --git a/src/obs_t.cpp b/src/obs_t.cpp index 432c97c..5464f42 100644 --- a/src/obs_t.cpp +++ b/src/obs_t.cpp @@ -3,8 +3,7 @@ int obs_t::addobsdata(const obsd_t* d) { - _data.push_back(*d); - data = &_data[0]; - n++; + data.push_back(*d); + ++n; return 1; } diff --git a/src/obs_t.h b/src/obs_t.h index e4064b9..e3a0138 100644 --- a/src/obs_t.h +++ b/src/obs_t.h @@ -11,7 +11,14 @@ #define NEXOBS 0 /* number of extended obs codes */ #endif -typedef struct { /* observation data record */ +#ifdef OBS_100HZ +#define DTTOL 0.005 /* tolerance of time difference (s) */ +#else +#define DTTOL 0.025 /* tolerance of time difference (s) */ +#endif + +class obsd_t { /* observation data record */ +public: gtime_t time; /* receiver sampling time (GPST) */ unsigned char sat, rcv; /* satellite/receiver number */ unsigned char SNR[NFREQ + NEXOBS]; /* signal strength (0.25 dBHz) */ @@ -20,14 +27,18 @@ typedef struct { /* observation data record */ double L[NFREQ + NEXOBS]; /* observation data carrier-phase (cycle) */ double P[NFREQ + NEXOBS]; /* observation data pseudorange (m) */ float D[NFREQ + NEXOBS]; /* observation data doppler frequency (Hz) */ -} obsd_t; + bool operator<(const obsd_t& r) const { + double tt = time-r.time; + if (fabs(tt) > DTTOL) return tt < 0 ? -1 : 1; + if (rcv != r.rcv) return (int)rcv - (int)r.rcv; + return (int)sat - (int)r.sat; + } +} ; class obs_t { public: int addobsdata(const obsd_t* data); int n = 0; /* number of obervation data */ - int nmax = 0; /* number of obervation data/allocated */ - obsd_t* data = 0; /* observation data records */ - std::vector _data; + std::vector data; }; diff --git a/src/postpos.cpp b/src/postpos.cpp index 4e36ce7..6c011d0 100644 --- a/src/postpos.cpp +++ b/src/postpos.cpp @@ -663,7 +663,7 @@ static int readobsnav(gtime_t ts, gtime_t te, double ti, char **infile, trace(3,"readobsnav: ts=%s n=%d\n",time_str(ts,0),n); - obs->data=NULL; obs->n =obs->nmax =0; + obs->data.clear(); nav->eph =NULL; nav->n =nav->nmax =0; nav->geph=NULL; nav->ng=nav->ngmax=0; nav->seph=NULL; nav->ns=nav->nsmax=0; @@ -717,7 +717,7 @@ static void freeobsnav(obs_t *obs, nav_t *nav) { trace(3,"freeobsnav:\n"); - free(obs->data); obs->data=NULL; obs->n =obs->nmax =0; + obs->data.clear(); free(nav->eph ); nav->eph =NULL; nav->n =nav->nmax =0; free(nav->geph); nav->geph=NULL; nav->ng=nav->ngmax=0; free(nav->seph); nav->seph=NULL; nav->ns=nav->nsmax=0; diff --git a/src/rcv/cmr.cpp b/src/rcv/cmr.cpp index 67eb0ef..7961929 100644 --- a/src/rcv/cmr.cpp +++ b/src/rcv/cmr.cpp @@ -2485,7 +2485,7 @@ static int OutputCmrObs(raw_t *Raw, obsb_t *Obs) if (Raw->obs.n > 0) { tracet(2, "CMR: Base observations referenced and output:\n"); - traceobs(2, Raw->obs.data, Raw->obs.n); + traceobs(2, &Raw->obs.data[0], Raw->obs.n); } return (Ret < 0) ? Ret : (Raw->obs.n > 0); diff --git a/src/rcv/javad.cpp b/src/rcv/javad.cpp index 141a4a2..6f02f56 100644 --- a/src/rcv/javad.cpp +++ b/src/rcv/javad.cpp @@ -1203,7 +1203,7 @@ static int decode_Rx(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].P[j]=prm; raw->obuf.data[i].code[j]=type; } @@ -1249,7 +1249,7 @@ static int decode_rx(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].P[j]=prm; raw->obuf.data[i].code[j]=type; } @@ -1282,7 +1282,7 @@ static int decode_xR(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].P[j]=pr*CLIGHT+raw->prCA[sat-1]; raw->obuf.data[i].code[j]=type; } @@ -1318,7 +1318,7 @@ static int decode_xr(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].P[j]=prm; raw->obuf.data[i].code[j]=type; } @@ -1350,7 +1350,7 @@ static int decode_Px(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].L[j]=cp; raw->obuf.data[i].code[j]=type; } @@ -1382,7 +1382,7 @@ static int decode_px(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].L[j]=cp/1024.0; raw->obuf.data[i].code[j]=type; } @@ -1415,7 +1415,7 @@ static int decode_xP(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; fn=freq_sys(sys,freq,raw->freqn[i]); cp=(rcp+raw->prCA[sat-1]/CLIGHT)*fn; @@ -1452,7 +1452,7 @@ static int decode_xp(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; fn=freq_sys(sys,freq,raw->freqn[i]); cp=(rcp*P2_40+raw->prCA[sat-1]/CLIGHT)*fn; @@ -1493,7 +1493,7 @@ static int decode_Dx(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].D[j]=(float)dop; } } @@ -1526,7 +1526,7 @@ static int decode_xd(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; f1=freq_sys(sys,0 ,raw->freqn[i]); fn=freq_sys(sys,freq,raw->freqn[i]); dop=(-rdp+raw->dpCA[sat-1]*1E4)*fn/f1*1E-4; @@ -1561,7 +1561,7 @@ static int decode_Ex(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].SNR[j]=(unsigned char)(cnr*4.0+0.5); } } @@ -1592,7 +1592,7 @@ static int decode_xE(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; raw->obuf.data[i].SNR[j]=cnr; } } @@ -1624,7 +1624,7 @@ static int decode_Fx(raw_t *raw, char code) if ((freq=tofreq(code,sys,&type))<0) continue; if ((j=checkpri(raw->opt,sys,type,freq))>=0) { - if (!settag(raw->obuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; #if 0 if (flags&0x20) { /* loss-of-lock potential */ raw->obuf.data[i].LLI[j]|=1; @@ -1657,7 +1657,7 @@ static int decode_TC(raw_t *raw) for (i=0;iobuf.n&&iobuf.data+i,raw->time)) continue; + if (!settag(&(raw->obuf.data[i]),raw->time)) continue; sat=raw->obuf.data[i].sat; tt_p=(unsigned short)raw->lockt[sat-1][0]; diff --git a/src/rcv/rt17.cpp b/src/rcv/rt17.cpp index 50ebe0b..99260c1 100644 --- a/src/rcv/rt17.cpp +++ b/src/rcv/rt17.cpp @@ -1868,7 +1868,7 @@ static int DecodeType17(raw_t *Raw, unsigned int rif) if (n > 0) { tracet(2, "RT17: Observations output:\n"); - traceobs(2, Raw->obs.data, Raw->obs.n); + traceobs(2, &Raw->obs.data[0], Raw->obs.n); } return (n > 0); diff --git a/src/rcvraw.cpp b/src/rcvraw.cpp index 91fe8b2..bc6251b 100644 --- a/src/rcvraw.cpp +++ b/src/rcvraw.cpp @@ -894,8 +894,10 @@ extern int init_raw(raw_t *raw, int format) raw->opt[0]='\0'; raw->format=-1; - raw->obs.data =NULL; - raw->obuf.data=NULL; + //raw->obs.data =NULL; + //raw->obuf.data=NULL; + raw->obs.data.clear(); + raw->obuf.data.clear(); raw->nav.eph =NULL; raw->nav.alm =NULL; raw->nav.geph =NULL; @@ -903,8 +905,8 @@ extern int init_raw(raw_t *raw, int format) raw->half_cyc =NULL; raw->rcv_data =NULL; - if (!(raw->obs.data =(obsd_t *)malloc(sizeof(obsd_t)*MAXOBS))|| - !(raw->obuf.data=(obsd_t *)malloc(sizeof(obsd_t)*MAXOBS))|| + if (/*!(raw->obs.data =(obsd_t *)malloc(sizeof(obsd_t)*MAXOBS))|| + !(raw->obuf.data=(obsd_t *)malloc(sizeof(obsd_t)*MAXOBS))||*/ !(raw->nav.eph =(eph_t *)malloc(sizeof(eph_t )*MAXSAT))|| !(raw->nav.alm =(alm_t *)malloc(sizeof(alm_t )*MAXSAT))|| !(raw->nav.geph =(geph_t *)malloc(sizeof(geph_t)*NSATGLO))|| @@ -960,8 +962,10 @@ extern void free_raw(raw_t *raw) trace(3,"free_raw:\n"); - free(raw->obs.data ); raw->obs.data =NULL; raw->obs.n =0; - free(raw->obuf.data); raw->obuf.data=NULL; raw->obuf.n=0; + //free(raw->obs.data ); raw->obs.data =NULL; raw->obs.n =0; + //free(raw->obuf.data); raw->obuf.data=NULL; raw->obuf.n=0; + raw->obs.data.clear(); + raw->obuf.data.clear(); free(raw->nav.eph ); raw->nav.eph =NULL; raw->nav.n =0; free(raw->nav.alm ); raw->nav.alm =NULL; raw->nav.na=0; free(raw->nav.geph ); raw->nav.geph =NULL; raw->nav.ng=0; diff --git a/src/rinex.cpp b/src/rinex.cpp index d70766f..7997263 100644 --- a/src/rinex.cpp +++ b/src/rinex.cpp @@ -855,18 +855,7 @@ static void restslips(unsigned char slips[][NFREQ], obsd_t *data) /* add obs data --------------------------------------------------------------*/ static int addobsdata(obs_t *obs, const obsd_t *data) { - obsd_t *obs_data; - - if (obs->nmax<=obs->n) { - if (obs->nmax<=0) obs->nmax=NINCOBS; else obs->nmax*=2; - if (!(obs_data=(obsd_t *)realloc(obs->data,sizeof(obsd_t)*obs->nmax))) { - trace(1,"addobsdata: memalloc error n=%dx%d\n",sizeof(obsd_t),obs->nmax); - free(obs->data); obs->data=NULL; obs->n=obs->nmax=0; - return -1; - } - obs->data=obs_data; - } - obs->data[obs->n++]=*data; + obs->addobsdata(data); return 1; } /* set system mask -----------------------------------------------------------*/ @@ -1705,13 +1694,12 @@ extern int init_rnxctr(rnxctr_t *rnx) trace(3,"init_rnxctr:\n"); - rnx->obs.data=NULL; + rnx->obs.data.clear(); rnx->nav.eph =NULL; rnx->nav.geph=NULL; rnx->nav.seph=NULL; - if (!(rnx->obs.data=(obsd_t *)malloc(sizeof(obsd_t)*MAXOBS ))|| - !(rnx->nav.eph =(eph_t *)malloc(sizeof(eph_t )*MAXSAT ))|| + if (!(rnx->nav.eph =(eph_t *)malloc(sizeof(eph_t )*MAXSAT ))|| !(rnx->nav.geph=(geph_t *)malloc(sizeof(geph_t)*NSATGLO))|| !(rnx->nav.seph=(seph_t *)malloc(sizeof(seph_t)*NSATSBS))) { free_rnxctr(rnx); @@ -1743,7 +1731,7 @@ extern void free_rnxctr(rnxctr_t *rnx) { trace(3,"free_rnxctr:\n"); - free(rnx->obs.data); rnx->obs.data=NULL; rnx->obs.n =0; + rnx->obs.data.clear(); free(rnx->nav.eph ); rnx->nav.eph =NULL; rnx->nav.n =0; free(rnx->nav.geph); rnx->nav.geph=NULL; rnx->nav.ng=0; free(rnx->nav.seph); rnx->nav.seph=NULL; rnx->nav.ns=0; @@ -1802,7 +1790,7 @@ extern int input_rnxctr(rnxctr_t *rnx, FILE *fp) /* read rinex obs data */ if (rnx->type=='O') { if ((n=readrnxobsb(fp,rnx->opt,rnx->ver,&rnx->tsys,rnx->tobs,&flag, - rnx->obs.data,&rnx->sta))<=0) { + &rnx->obs.data[0],&rnx->sta))<=0) { rnx->obs.n=0; return n<0?-2:0; } diff --git a/src/rtcm.cpp b/src/rtcm.cpp index 7642eed..56f934d 100644 --- a/src/rtcm.cpp +++ b/src/rtcm.cpp @@ -106,13 +106,12 @@ extern int init_rtcm(rtcm_t *rtcm) for (i=0;i<100;i++) rtcm->nmsg2[i]=0; for (i=0;i<400;i++) rtcm->nmsg3[i]=0; - rtcm->obs.data=NULL; + rtcm->obs.data.clear(); rtcm->nav.eph =NULL; rtcm->nav.geph=NULL; /* reallocate memory for observation and ephemris buffer */ - if (!(rtcm->obs.data=(obsd_t *)malloc(sizeof(obsd_t)*MAXOBS))|| - !(rtcm->nav.eph =(eph_t *)malloc(sizeof(eph_t )*MAXSAT))|| + if (!(rtcm->nav.eph =(eph_t *)malloc(sizeof(eph_t )*MAXSAT))|| !(rtcm->nav.geph=(geph_t *)malloc(sizeof(geph_t)*MAXPRNGLO))) { free_rtcm(rtcm); return 0; @@ -135,7 +134,7 @@ extern void free_rtcm(rtcm_t *rtcm) trace(3,"free_rtcm:\n"); /* free memory for observation and ephemeris buffer */ - free(rtcm->obs.data); rtcm->obs.data=NULL; rtcm->obs.n=0; + rtcm->obs.data.clear(); free(rtcm->nav.eph ); rtcm->nav.eph =NULL; rtcm->nav.n=0; free(rtcm->nav.geph); rtcm->nav.geph=NULL; rtcm->nav.ng=0; } diff --git a/src/rtcm3e.cpp b/src/rtcm3e.cpp index cd8019a..4210f51 100644 --- a/src/rtcm3e.cpp +++ b/src/rtcm3e.cpp @@ -355,7 +355,7 @@ static int encode_type1001(rtcm_t *rtcm, int sync) if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */ /* generate obs field data gps */ - gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb,NULL, + gen_obs_gps(rtcm,&rtcm->obs.data[j],&code1,&pr1,&ppr1,&lock1,&amb,NULL, NULL,NULL,NULL,NULL,NULL); setbitu(rtcm->buff,i, 6,prn ); i+= 6; @@ -390,7 +390,7 @@ static int encode_type1002(rtcm_t *rtcm, int sync) if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */ /* generate obs field data gps */ - gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb,&cnr1, + gen_obs_gps(rtcm,&rtcm->obs.data[j],&code1,&pr1,&ppr1,&lock1,&amb,&cnr1, NULL,NULL,NULL,NULL,NULL); setbitu(rtcm->buff,i, 6,prn ); i+= 6; @@ -427,7 +427,7 @@ static int encode_type1003(rtcm_t *rtcm, int sync) if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */ /* generate obs field data gps */ - gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb, + gen_obs_gps(rtcm,&rtcm->obs.data[j],&code1,&pr1,&ppr1,&lock1,&amb, NULL,&code2,&pr21,&ppr2,&lock2,NULL); setbitu(rtcm->buff,i, 6,prn ); i+= 6; @@ -466,7 +466,7 @@ static int encode_type1004(rtcm_t *rtcm, int sync) if (sys==SYS_SBS) prn-=80; /* 40-58: sbas 120-138 */ /* generate obs field data gps */ - gen_obs_gps(rtcm,rtcm->obs.data+j,&code1,&pr1,&ppr1,&lock1,&amb, + gen_obs_gps(rtcm,&rtcm->obs.data[j],&code1,&pr1,&ppr1,&lock1,&amb, &cnr1,&code2,&pr21,&ppr2,&lock2,&cnr2); setbitu(rtcm->buff,i, 6,prn ); i+= 6; @@ -607,7 +607,7 @@ static int encode_type1009(rtcm_t *rtcm, int sync) fcn=fcn_glo(sat,rtcm); /* generate obs field data glonass */ - gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb, + gen_obs_glo(rtcm,&rtcm->obs.data[j],fcn,&code1,&pr1,&ppr1,&lock1,&amb, NULL,NULL,NULL,NULL,NULL,NULL); if (fcn<0) fcn=0; @@ -643,7 +643,7 @@ static int encode_type1010(rtcm_t *rtcm, int sync) fcn=fcn_glo(sat,rtcm); /* generate obs field data glonass */ - gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb, + gen_obs_glo(rtcm,&rtcm->obs.data[j],fcn,&code1,&pr1,&ppr1,&lock1,&amb, &cnr1,NULL,NULL,NULL,NULL,NULL); if (fcn<0) fcn=0; @@ -681,7 +681,7 @@ static int encode_type1011(rtcm_t *rtcm, int sync) fcn=fcn_glo(sat,rtcm); /* generate obs field data glonass */ - gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb, + gen_obs_glo(rtcm,&rtcm->obs.data[j],fcn,&code1,&pr1,&ppr1,&lock1,&amb, NULL,&code2,&pr21,&ppr2,&lock2,NULL); if (fcn<0) fcn=0; @@ -721,7 +721,7 @@ static int encode_type1012(rtcm_t *rtcm, int sync) fcn=fcn_glo(sat,rtcm); /* generate obs field data glonass */ - gen_obs_glo(rtcm,rtcm->obs.data+j,fcn,&code1,&pr1,&ppr1,&lock1,&amb, + gen_obs_glo(rtcm,&rtcm->obs.data[j],fcn,&code1,&pr1,&ppr1,&lock1,&amb, &cnr1,&code2,&pr21,&ppr2,&lock2,&cnr2); if (fcn<0) fcn=0; @@ -1807,7 +1807,7 @@ static void gen_msm_sat(rtcm_t *rtcm, int sys, int nsat, for (i=0;i<64;i++) rrng[i]=rrate[i]=0.0; for (i=0;iobs.n;i++) { - data=rtcm->obs.data+i; + data=&rtcm->obs.data[i]; if (!(sat=to_satid(sys,data->sat))) continue; fcn=fcn_glo(data->sat,rtcm); @@ -1846,7 +1846,7 @@ static void gen_msm_sig(rtcm_t *rtcm, int sys, int nsat, int nsig, int ncell, if (rate ) rate [i]=0.0; } for (i=0;iobs.n;i++) { - data=rtcm->obs.data+i; + data=&rtcm->obs.data[i]; if (!(sat=to_satid(sys,data->sat))) continue; diff --git a/src/rtkcmn.cpp b/src/rtkcmn.cpp index 3fd7319..1538936 100644 --- a/src/rtkcmn.cpp +++ b/src/rtkcmn.cpp @@ -137,6 +137,7 @@ #include #endif #include "rtklib.h" +#include /* constants -----------------------------------------------------------------*/ @@ -2652,13 +2653,13 @@ extern void uniqnav(nav_t *nav) } } /* compare observation data -------------------------------------------------*/ -static int cmpobs(const void *p1, const void *p2) +static int cmpobs(const obsd_t& q1, const obsd_t& q2) { - obsd_t *q1=(obsd_t *)p1,*q2=(obsd_t *)p2; - double tt=timediff(q1->time,q2->time); - if (fabs(tt)>DTTOL) return tt<0?-1:1; - if (q1->rcv!=q2->rcv) return (int)q1->rcv-(int)q2->rcv; - return (int)q1->sat-(int)q2->sat; + // obsd_t *q1 = (obsd_t *)p1, *q2 = (obsd_t *)p2; + double tt = timediff(q1.time, q2.time); + if (fabs(tt) > DTTOL) return tt < 0 ? -1 : 1; + if (q1.rcv != q2.rcv) return (int)q1.rcv - (int)q2.rcv; + return (int)q1.sat - (int)q2.sat; } /* sort and unique observation data -------------------------------------------- * sort and unique observation data by time, rcv, sat @@ -2673,7 +2674,8 @@ extern int sortobs(obs_t *obs) if (obs->n<=0) return 0; - qsort(obs->data,obs->n,sizeof(obsd_t),cmpobs); + // qsort(&obs->data[0],obs->n,sizeof(obsd_t),cmpobs); + std::sort(obs->data.begin(), obs->data.end(), cmpobs); /* delete duplicated data */ for (i=j=0;in;i++) { @@ -2836,7 +2838,7 @@ extern int savenav(const char *file, const nav_t *nav) *-----------------------------------------------------------------------------*/ extern void freeobs(obs_t *obs) { - free(obs->data); obs->data=NULL; obs->n=obs->nmax=0; + obs->data.clear(); } /* free navigation data --------------------------------------------------------- * free memory for navigation data diff --git a/src/rtklib.h b/src/rtklib.h index 8d98421..a70500d 100644 --- a/src/rtklib.h +++ b/src/rtklib.h @@ -218,11 +218,7 @@ constexpr double FREQ3_CMP = 1.26852E9 ; /* BeiDou B3 frequency (Hz) */ #endif #define MAXRCV 64 /* max receiver number (1 to MAXRCV) */ #define MAXOBSTYPE 64 /* max number of obs type in RINEX */ -#ifdef OBS_100HZ -#define DTTOL 0.005 /* tolerance of time difference (s) */ -#else -#define DTTOL 0.025 /* tolerance of time difference (s) */ -#endif + #define MAXDTOE 7200.0 /* max time difference to GPS Toe (s) */ #define MAXDTOE_QZS 7200.0 /* max time difference to QZSS Toe (s) */ #define MAXDTOE_GAL 14400.0 /* max time difference to Galileo Toe (s) */ @@ -1430,11 +1426,7 @@ EXPORT gtime_t bdt2time(int week, double sec); EXPORT double time2bdt(gtime_t t, int *week); EXPORT char *time_str(gtime_t t, int n); -EXPORT gtime_t timeadd (gtime_t t, double sec); -gtime_t operator+(const gtime_t& t, double sec); -gtime_t operator+(double sec, const gtime_t& t); -EXPORT double timediff (gtime_t t1, gtime_t t2); -double operator-(const gtime_t& t1, const gtime_t& t2); + EXPORT gtime_t gpst2utc (gtime_t t); EXPORT gtime_t utc2gpst (gtime_t t); EXPORT gtime_t gpst2bdt (gtime_t t); From b1da14d151d79c2a82e8eb9de56c412bf4c95610 Mon Sep 17 00:00:00 2001 From: chenfeiyang <309905109@qq.com> Date: Sun, 14 Jun 2020 15:09:53 +0800 Subject: [PATCH 3/3] obs_t .n --- src/obs_t.cpp | 32 +++++++++++++++++++++++++++++++- src/obs_t.h | 12 +++++++++++- src/postpos.cpp | 24 ++++++++++++------------ src/rcv/javad.cpp | 10 +++++----- src/rcv/novatel.cpp | 19 ++----------------- src/rcv/tersus.cpp | 18 ++---------------- src/rcvraw.cpp | 4 ++-- src/rinex.cpp | 6 +++--- src/rtcm.cpp | 2 +- src/rtcm2.cpp | 21 +++------------------ src/rtcm3.cpp | 19 ++----------------- src/rtklib.h | 4 +--- 12 files changed, 75 insertions(+), 96 deletions(-) diff --git a/src/obs_t.cpp b/src/obs_t.cpp index 5464f42..ca11b60 100644 --- a/src/obs_t.cpp +++ b/src/obs_t.cpp @@ -1,9 +1,39 @@ #include "obs_t.h" #include +obsd_t::obsd_t() +{ + for (int j = 0; j < NFREQ+ NEXOBS; j++) { + L[j] = P[j] = 0.0; + D[j] = 0.0; + SNR[j] = LLI[j] = code[j] = 0; + } +} int obs_t::addobsdata(const obsd_t* d) { data.push_back(*d); - ++n; return 1; } + +int obs_t::count() const +{ + return data.size(); +} + +int obs_t::obsindex(const gtime_t& time, int sat) +{ + int i, j; + + for (i = 0; i < count(); i++) { + if (data[i].sat == sat) return i; /* field already exists */ + } + if (i >= MAXOBS) return -1; /* overflow */ + + /* add new field */ + obsd_t obs_tmp; + obs_tmp.time = time; + obs_tmp.sat = sat; + data.push_back(obs_tmp); + + return i; +} diff --git a/src/obs_t.h b/src/obs_t.h index e3a0138..4e5cc51 100644 --- a/src/obs_t.h +++ b/src/obs_t.h @@ -17,8 +17,13 @@ #define DTTOL 0.025 /* tolerance of time difference (s) */ #endif +#ifndef MAXOBS +#define MAXOBS 64 /* max number of obs in an epoch */ +#endif + class obsd_t { /* observation data record */ public: + obsd_t(); gtime_t time; /* receiver sampling time (GPST) */ unsigned char sat, rcv; /* satellite/receiver number */ unsigned char SNR[NFREQ + NEXOBS]; /* signal strength (0.25 dBHz) */ @@ -38,7 +43,12 @@ class obsd_t { /* observation data record */ class obs_t { public: int addobsdata(const obsd_t* data); + int count() const; + /* add new field */ + void add_new_field(const gtime_t& time, int sat); + /* get observation data index ------------------------------------------------*/ + int obsindex(const gtime_t& time, int sat); - int n = 0; /* number of obervation data */ + //int n = 0; /* number of obervation data */ std::vector data; }; diff --git a/src/postpos.cpp b/src/postpos.cpp index 6c011d0..6e0907d 100644 --- a/src/postpos.cpp +++ b/src/postpos.cpp @@ -142,8 +142,8 @@ static void outheader(FILE *fp, char **file, int n, const prcopt_t *popt, for (i=0;i=0;j--) if (obss.data[j].rcv==1) break; + for (i=0;i=0;j--) if (obss.data[j].rcv==1) break; if (jn;(*i)++) if (obs->data[*i].rcv==rcv) break; - for (n=0;*i+nn;n++) { + for (;*icount();(*i)++) if (obs->data[*i].rcv==rcv) break; + for (n=0;*i+ncount();n++) { tt=timediff(obs->data[*i+n].time,obs->data[*i].time); if (obs->data[*i+n].rcv!=rcv||tt>DTTOL) break; } @@ -239,7 +239,7 @@ static int inputobs(obsd_t *obs, int solq, const prcopt_t *popt) trace(3,"infunc : revs=%d iobsu=%d iobsr=%d isbs=%d\n",revs,iobsu,iobsr,isbs); - if (0<=iobsu&&iobsun<=0) { + if (obs->count()<=0) { checkbrk("error : no obs data"); trace(1,"\n"); return 0; @@ -702,8 +702,8 @@ static int readobsnav(gtime_t ts, gtime_t te, double ti, char **infile, /* set time span for progress display */ if (ts.time==0||te.time==0) { - for (i=0; in;i++) if (obs->data[i].rcv==1) break; - for (j=obs->n-1;j>=0;j--) if (obs->data[j].rcv==1) break; + for (i=0; icount();i++) if (obs->data[i].rcv==1) break; + for (j=obs->count()-1;j>=0;j--) if (obs->data[j].rcv==1) break; if (idata[i].time; if (te.time==0) te=obs->data[j].time; @@ -732,7 +732,7 @@ static int avepos(double *ra, int rcv, const obs_t *obs, const nav_t *nav, int i,j,n=0,m,iobs; char msg[128]; - trace(3,"avepos: rcv=%d obs.n=%d\n",rcv,obs->n); + trace(3,"avepos: rcv=%d obs.n=%d\n",rcv,obs->count()); for (i=0;i<3;i++) ra[i]=0.0; @@ -1023,7 +1023,7 @@ static int execses(gtime_t ts, gtime_t te, double ti, const prcopt_t *popt, } /* set antenna paramters */ if (popt_.mode!=PMODE_SINGLE) { - setpcv(obss.n>0?obss.data[0].time:timeget(),&popt_,&navs,&pcvss,&pcvsr, + setpcv(obss.count()>0?obss.data[0].time:timeget(),&popt_,&navs,&pcvss,&pcvsr, stas); } /* read ocean tide loading parameters */ @@ -1065,7 +1065,7 @@ static int execses(gtime_t ts, gtime_t te, double ti, const prcopt_t *popt, } else if (popt_.soltype==1) { if ((fp=openfile(outfile))) { - revs=1; iobsu=iobsr=obss.n-1; isbs=sbss.n-1; ilex=lexs.n-1; + revs=1; iobsu=iobsr=obss.count()-1; isbs=sbss.n-1; ilex=lexs.n-1; procpos(fp,&popt_,sopt,0); /* backward */ fclose(fp); } @@ -1079,7 +1079,7 @@ static int execses(gtime_t ts, gtime_t te, double ti, const prcopt_t *popt, if (solf&&solb) { isolf=isolb=0; procpos(NULL,&popt_,sopt,1); /* forward */ - revs=1; iobsu=iobsr=obss.n-1; isbs=sbss.n-1; ilex=lexs.n-1; + revs=1; iobsu=iobsr=obss.count()-1; isbs=sbss.n-1; ilex=lexs.n-1; procpos(NULL,&popt_,sopt,1); /* backward */ /* combine forward/backward solutions */ diff --git a/src/rcv/javad.cpp b/src/rcv/javad.cpp index 6f02f56..471faff 100644 --- a/src/rcv/javad.cpp +++ b/src/rcv/javad.cpp @@ -1650,11 +1650,11 @@ static int decode_TC(raw_t *raw) trace(2,"javad TC checksum error: len=%d\n",raw->len); return -1; } - if (raw->len!=raw->obuf.n*2+6) { - trace(2,"javad TC length error: n=%d len=%d\n",raw->obuf.n,raw->len); + if (raw->len!=raw->obuf.count()*2+6) { + trace(2,"javad TC length error: n=%d len=%d\n",raw->obuf.count(),raw->len); return -1; } - for (i=0;iobuf.n&&iobuf.count()&&iobuf.data[i]),raw->time)) continue; @@ -1820,7 +1820,7 @@ extern int input_javad(raw_t *raw, unsigned char data) static void startfile(raw_t *raw) { raw->tod=-1; - raw->obuf.n=0; + raw->obuf.data.clear(); raw->buff[4]='\n'; } /* end input file ------------------------------------------------------------*/ @@ -1828,7 +1828,7 @@ static int endfile(raw_t *raw) { /* flush observation data buffer */ if (!flushobuf(raw)) return -2; - raw->obuf.n=0; + raw->obuf.data.clear(); return 1; } /* input javad raw message from file ------------------------------------------- diff --git a/src/rcv/novatel.cpp b/src/rcv/novatel.cpp index 4ecd3e5..6c4df00 100644 --- a/src/rcv/novatel.cpp +++ b/src/rcv/novatel.cpp @@ -142,22 +142,7 @@ static gtime_t adjweek(gtime_t time, double tow) /* get observation data index ------------------------------------------------*/ static int obsindex(obs_t *obs, gtime_t time, int sat) { - int i,j; - - if (obs->n>=MAXOBS) return -1; - for (i=0;in;i++) { - if (obs->data[i].sat==sat) return i; - } - obs->data[i].time=time; - obs->data[i].sat=sat; - for (j=0;jdata[i].L[j]=obs->data[i].P[j]=0.0; - obs->data[i].D[j]=0.0; - obs->data[i].SNR[j]=obs->data[i].LLI[j]=0; - obs->data[i].code[j]=CODE_NONE; - } - obs->n++; - return i; + return obs->obsindex(time,sat); } /* ura value (m) to ura index ------------------------------------------------*/ static int uraindex(double value) @@ -1124,7 +1109,7 @@ static int decode_rgeb(raw_t *raw) raw->halfc[sat-1][freq]=parity; if (fabs(timediff(raw->obs.data[0].time,raw->time))>1E-9) { - raw->obs.n=0; + raw->obs.data.clear(); } if ((index=obsindex(&raw->obs,raw->time,sat))>=0) { raw->obs.data[index].L [freq]=-adr; /* flip sign */ diff --git a/src/rcv/tersus.cpp b/src/rcv/tersus.cpp index 6f6f08e..07d6abc 100644 --- a/src/rcv/tersus.cpp +++ b/src/rcv/tersus.cpp @@ -57,22 +57,8 @@ static gtime_t adjweek(gtime_t time, double tow) /* get observation data index ------------------------------------------------*/ static int obsindex(obs_t *obs, gtime_t time, int sat) { - int i,j; - - if (obs->n>=MAXOBS) return -1; - for (i=0;in;i++) { - if (obs->data[i].sat==sat) return i; - } - obs->data[i].time=time; - obs->data[i].sat=sat; - for (j=0;jdata[i].L[j]=obs->data[i].P[j]=0.0; - obs->data[i].D[j]=0.0; - obs->data[i].SNR[j]=obs->data[i].LLI[j]=0; - obs->data[i].code[j]=CODE_NONE; - } - obs->n++; - return i; + return obs->obsindex(time, sat); + } /* ura value (m) to ura index ------------------------------------------------*/ static int uraindex(double value) diff --git a/src/rcvraw.cpp b/src/rcvraw.cpp index bc6251b..9e40c7b 100644 --- a/src/rcvraw.cpp +++ b/src/rcvraw.cpp @@ -914,8 +914,8 @@ extern int init_raw(raw_t *raw, int format) free_raw(raw); return 0; } - raw->obs.n =0; - raw->obuf.n=0; + raw->obs.data.clear(); + raw->obuf.data.clear(); raw->nav.n =MAXSAT; raw->nav.na=MAXSAT; raw->nav.ng=NSATGLO; diff --git a/src/rinex.cpp b/src/rinex.cpp index 7997263..84c79c1 100644 --- a/src/rinex.cpp +++ b/src/rinex.cpp @@ -1045,7 +1045,7 @@ static int readrnxobs(FILE *fp, gtime_t ts, gtime_t te, double tint, if ((stat=addobsdata(obs,data+i))<0) break; } } - trace(4,"readrnxobs: nobs=%d stat=%d\n",obs->n,stat); + trace(4,"readrnxobs: nobs=%d stat=%d\n",obs->count(),stat); free(data); @@ -1709,7 +1709,7 @@ extern int init_rnxctr(rnxctr_t *rnx) rnx->ver=0.0; rnx->sys=rnx->tsys=0; for (i=0;i<6;i++) for (j=0;jtobs[i][j][0]='\0'; - rnx->obs.n=0; + rnx->obs.data.clear(); rnx->nav.n=MAXSAT; rnx->nav.ng=NSATGLO; rnx->nav.ns=NSATSBS; @@ -1791,7 +1791,7 @@ extern int input_rnxctr(rnxctr_t *rnx, FILE *fp) if (rnx->type=='O') { if ((n=readrnxobsb(fp,rnx->opt,rnx->ver,&rnx->tsys,rnx->tobs,&flag, &rnx->obs.data[0],&rnx->sta))<=0) { - rnx->obs.n=0; + rnx->obs.data.clear(); return n<0?-2:0; } rnx->time=rnx->obs.data[0].time; diff --git a/src/rtcm.cpp b/src/rtcm.cpp index 56f934d..3d60bb1 100644 --- a/src/rtcm.cpp +++ b/src/rtcm.cpp @@ -116,7 +116,7 @@ extern int init_rtcm(rtcm_t *rtcm) free_rtcm(rtcm); return 0; } - rtcm->obs.n=0; + rtcm->obs.data.clear(); rtcm->nav.n=MAXSAT; rtcm->nav.ng=MAXPRNGLO; for (i=0;iobs.data[i]=data0; diff --git a/src/rtcm2.cpp b/src/rtcm2.cpp index 0676591..4dc87b1 100644 --- a/src/rtcm2.cpp +++ b/src/rtcm2.cpp @@ -30,23 +30,8 @@ static void adjhour(rtcm_t *rtcm, double zcnt) /* get observation data index ------------------------------------------------*/ static int obsindex(obs_t *obs, gtime_t time, int sat) { - int i,j; - - for (i=0;in;i++) { - if (obs->data[i].sat==sat) return i; /* field already exists */ - } - if (i>=MAXOBS) return -1; /* overflow */ - - /* add new field */ - obs->data[i].time=time; - obs->data[i].sat=sat; - for (j=0;jdata[i].L[j]=obs->data[i].P[j]=0.0; - obs->data[i].D[j]=0.0; - obs->data[i].SNR[j]=obs->data[i].LLI[j]=obs->data[i].code[j]=0; - } - obs->n++; - return i; + return obs->obsindex(time, sat); + } /* decode type 1/9: differential gps correction/partial correction set -------*/ static int decode_type1(rtcm_t *rtcm) @@ -267,7 +252,7 @@ static int decode_type19(rtcm_t *rtcm) } freq>>=1; - while (i+48<=rtcm->len*8&&rtcm->obs.nlen*8&&rtcm->obs.count()buff,i, 1); i+= 1; code=getbitu(rtcm->buff,i, 1); i+= 1; sys =getbitu(rtcm->buff,i, 1); i+= 1; diff --git a/src/rtcm3.cpp b/src/rtcm3.cpp index 55370b1..6b0c8e3 100644 --- a/src/rtcm3.cpp +++ b/src/rtcm3.cpp @@ -176,23 +176,8 @@ static unsigned char snratio(double snr) /* get observation data index ------------------------------------------------*/ static int obsindex(obs_t *obs, gtime_t time, int sat) { - int i,j; - - for (i=0;in;i++) { - if (obs->data[i].sat==sat) return i; /* field already exists */ - } - if (i>=MAXOBS) return -1; /* overflow */ - - /* add new field */ - obs->data[i].time=time; - obs->data[i].sat=sat; - for (j=0;jdata[i].L[j]=obs->data[i].P[j]=0.0; - obs->data[i].D[j]=0.0; - obs->data[i].SNR[j]=obs->data[i].LLI[j]=obs->data[i].code[j]=0; - } - obs->n++; - return i; + return obs->obsindex(time, sat); + } /* test station id consistency -----------------------------------------------*/ static int test_staid(rtcm_t *rtcm, int staid) diff --git a/src/rtklib.h b/src/rtklib.h index a70500d..ddc1566 100644 --- a/src/rtklib.h +++ b/src/rtklib.h @@ -213,9 +213,7 @@ constexpr double FREQ3_CMP = 1.26852E9 ; /* BeiDou B3 frequency (Hz) */ /* max satellite number (1 to MAXSAT) */ #define MAXSTA 255 -#ifndef MAXOBS -#define MAXOBS 64 /* max number of obs in an epoch */ -#endif + #define MAXRCV 64 /* max receiver number (1 to MAXRCV) */ #define MAXOBSTYPE 64 /* max number of obs type in RINEX */