@@ -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 )
41524263extern int showmsg (const char * format ,...) {return 0 ;}
0 commit comments