Skip to content

Commit 1c2fbff

Browse files
Merge pull request #695 from ourairquality/getstapos-sinex
getstapos: add sinex suport, and export
2 parents 4865e8b + 69bbfa5 commit 1c2fbff

3 files changed

Lines changed: 114 additions & 35 deletions

File tree

src/postpos.c

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -847,47 +847,14 @@ static int avepos(double *ra, int rcv, const obs_t *obs, const nav_t *nav,
847847
for (i=0;i<3;i++) ra[i]/=n;
848848
return 1;
849849
}
850-
/* station position from file ------------------------------------------------*/
851-
static int getstapos(const char *file, const char *name, double *r)
852-
{
853-
FILE *fp;
854-
char buff[256],sname[256],*p;
855-
const char *q;
856-
double pos[3];
857-
858-
trace(3,"getstapos: file=%s name=%s\n",file,name);
859850

860-
if (!(fp=fopen(file,"r"))) {
861-
trace(1,"station position file open error: %s\n",file);
862-
return 0;
863-
}
864-
while (fgets(buff,sizeof(buff),fp)) {
865-
if ((p=strchr(buff,'%'))) *p='\0';
866-
867-
if (sscanf(buff,"%lf %lf %lf %255s",pos,pos+1,pos+2,sname)<4) continue;
868-
869-
for (p=sname,q=name;*p&&*q;p++,q++) {
870-
if (toupper((int)*p)!=toupper((int)*q)) break;
871-
}
872-
if (!*p) {
873-
pos[0]*=D2R;
874-
pos[1]*=D2R;
875-
pos2ecef(pos,r);
876-
fclose(fp);
877-
return 1;
878-
}
879-
}
880-
fclose(fp);
881-
trace(1,"no station position: %s %s\n",name,file);
882-
return 0;
883-
}
884851
/* antenna phase center position ---------------------------------------------*/
885852
static int antpos(prcopt_t *opt, int rcvno, const obs_t *obs, const nav_t *nav,
886-
const sta_t *sta, const char *posfile)
853+
const sta_t *stas, const char *posfile)
887854
{
888855
double *rr=rcvno==1?opt->ru:opt->rb,del[3],pos[3],dr[3]={0};
889856
int i,postype=rcvno==1?opt->rovpos:opt->refpos;
890-
char *name;
857+
const char *name;
891858

892859
trace(3,"antpos : rcvno=%d\n",rcvno);
893860

src/rtkcmn.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,6 +4147,117 @@ extern int rtk_uncompress(const char *file, char *uncfile)
41474147
trace(3,"rtk_uncompress: stat=%d\n",stat);
41484148
return stat;
41494149
}
4150+
/* station position from file ------------------------------------------------*/
4151+
extern int getstapos(const char *file, const char *name, double *r)
4152+
{
4153+
trace(3, "getstapos: file=%s name=%s\n", file, name);
4154+
4155+
FILE *fp = fopen(file, "r");
4156+
if (!fp) {
4157+
trace(1,"station position file open error: %s\n",file);
4158+
return 0;
4159+
}
4160+
4161+
char buff[256];
4162+
int state = 0; // 0 pos file, 1 sinex misc, 2 sinex pos estimates.
4163+
int n = 0, posp = 0;
4164+
double poss[3];
4165+
while (fgets(buff, sizeof(buff), fp)) {
4166+
size_t len = strlen(buff);
4167+
if (state == 0) {
4168+
if (len >= 4 && strncmp(buff, "%=SNX", 4) == 0) {
4169+
state = 1;
4170+
continue;
4171+
}
4172+
// RTKLIB Position file
4173+
char *p = strchr(buff,'%');
4174+
if (p) *p='\0';
4175+
4176+
// Match either the full extended name or the 4 character
4177+
// prefix, giving priority to a full match.
4178+
char sname[256];
4179+
double pos[3];
4180+
if (sscanf(buff, "%lf %lf %lf %255s", pos, pos+1, pos+2, sname) < 4) continue;
4181+
4182+
int i = 0;
4183+
for (; sname[i] && name[i]; i++) {
4184+
if (toupper(sname[i]) != toupper(name[i])) break;
4185+
}
4186+
4187+
if (sname[i] == '\0' && name[i] == '\0') {
4188+
// Exact match.
4189+
pos[0] *= D2R;
4190+
pos[1] *= D2R;
4191+
pos2ecef(pos, r);
4192+
fclose(fp);
4193+
return 1;
4194+
}
4195+
4196+
if (i > 3 && (sname[i] == '\0' || name[i] == '\0') && i > posp) {
4197+
// Prefix match, save position.
4198+
posp = i;
4199+
for (int i = 0; i < 3; i++) poss[i] = pos[i];
4200+
}
4201+
}
4202+
4203+
// Sinex position file.
4204+
if (buff[0] == '*') continue; // Comment
4205+
if (strncmp(buff, "+SOLUTION/ESTIMATE", 18) == 0) {
4206+
state = 2;
4207+
continue;
4208+
}
4209+
if (state != 2) continue;
4210+
4211+
if (strncmp(buff, "-SOLUTION/ESTIMATE", 18) == 0) {
4212+
state = 1;
4213+
continue;
4214+
}
4215+
if (len < 68) {
4216+
trace(2, "getstapos: unexpected sinex line '%s'\n", buff);
4217+
continue;
4218+
}
4219+
4220+
// The solution sinex site codes are limited to 4 characters
4221+
// and only the 4 character prefix of the 'name' is matched.
4222+
char sname[5];
4223+
setstr(sname, buff + 14, 4);
4224+
int i = 0;
4225+
for (; i < 4 && sname[i] && name[i]; i++) {
4226+
if (toupper(sname[i]) != toupper(name[i])) break;
4227+
}
4228+
if (sname[i]) continue;
4229+
if (i < 4 && name[i]) continue;
4230+
4231+
if (strncmp(buff + 7, "STAX", 4) == 0) {
4232+
r[0] = str2num(buff, 47, 21);
4233+
n |= 1;
4234+
}
4235+
if (strncmp(buff + 7, "STAY", 4) == 0) {
4236+
r[1] = str2num(buff, 47, 21);
4237+
n |= 2;
4238+
}
4239+
if (strncmp(buff + 7, "STAZ", 4) == 0) {
4240+
r[2] = str2num(buff, 47, 21);
4241+
n |= 4;
4242+
}
4243+
if (n == 7) {
4244+
fclose(fp);
4245+
return 1;
4246+
}
4247+
}
4248+
fclose(fp);
4249+
4250+
if (state == 0 && posp > 0) {
4251+
// Return the longest prefix match.
4252+
poss[0] *= D2R;
4253+
poss[1] *= D2R;
4254+
pos2ecef(poss, r);
4255+
return 1;
4256+
}
4257+
4258+
trace(1, "no station position: %s %s\n", name, file);
4259+
return 0;
4260+
}
41504261
/* dummy application functions for shared library ----------------------------*/
41514262
#if defined(WIN_DLL) || defined(DLL)
41524263
extern int showmsg(const char *format,...) {return 0;}

src/rtklib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,7 @@ EXPORT int postpos(gtime_t ts, gtime_t te, double ti, double tu,
18621862
const prcopt_t *popt, const solopt_t *sopt,
18631863
const filopt_t *fopt, const char **infile, int n, const char *outfile,
18641864
const char *rov, const char *base);
1865+
EXPORT int getstapos(const char *file, const char *name, double *r);
18651866

18661867
/* stream server functions ---------------------------------------------------*/
18671868
EXPORT void strsvrinit (strsvr_t *svr, int nout);

0 commit comments

Comments
 (0)