Skip to content

Commit 69bbfa5

Browse files
committed
getstapos: add sinex suport, and export
Also improve the heuristics for working with both 4 character names and longer extended names. The first four characters need to match, including terminations. Extended names, longer than four characters, can match a shorter name and preference is given to a longer match.
1 parent 23a860f commit 69bbfa5

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
@@ -841,47 +841,14 @@ static int avepos(double *ra, int rcv, const obs_t *obs, const nav_t *nav,
841841
for (i=0;i<3;i++) ra[i]/=n;
842842
return 1;
843843
}
844-
/* station position from file ------------------------------------------------*/
845-
static int getstapos(const char *file, const char *name, double *r)
846-
{
847-
FILE *fp;
848-
char buff[256],sname[256],*p;
849-
const char *q;
850-
double pos[3];
851-
852-
trace(3,"getstapos: file=%s name=%s\n",file,name);
853844

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

886853
trace(3,"antpos : rcvno=%d\n",rcvno);
887854

src/rtkcmn.c

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