Index: trunk/BNC/RTCM3/rtcm3torinex.c
===================================================================
--- trunk/BNC/RTCM3/rtcm3torinex.c	(revision 1277)
+++ trunk/BNC/RTCM3/rtcm3torinex.c	(revision 1278)
@@ -1,5 +1,5 @@
 /*
   Converter for RTCM3 data to RINEX.
-  $Id: rtcm3torinex.c,v 1.34 2008/11/26 10:14:46 stoecker Exp $
+  $Id: rtcm3torinex.c,v 1.36 2008/12/03 08:33:16 stoecker Exp $
   Copyright (C) 2005-2008 by Dirk Stöcker <stoecker@alberding.eu>
 
@@ -51,5 +51,5 @@
 
 /* CVS revision and version */
-static char revisionstr[] = "$Revision: 1.34 $";
+static char revisionstr[] = "$Revision: 1.36 $";
 
 #ifndef COMPILEDATE
@@ -459,5 +459,5 @@
         int lastlockl2[64];
         struct gnssdata *gnss;
-        int i, num, wasamb=0;
+        int i, numsats, wasamb=0;
 
         for(i = 0; i < 64; ++i)
@@ -482,14 +482,21 @@
 
         GETBITS(syncf,1) /* sync */
-        GETBITS(i,5)
-        gnss->numsats += i;
+        GETBITS(numsats,5)
         SKIPBITS(4) /* smind, smint */
 
-        for(num = gnss->numsats-i; num < gnss->numsats; ++num)
+        while(numsats--)
         {
           int sv, code, l1range, c,l,s,ce,le,se,amb=0;
-
-          GETBITS(sv, 6);
-          gnss->satellites[num] = (sv < 40 ? sv : sv+80);
+          int fullsat, num;
+
+          GETBITS(sv, 6)
+          fullsat = sv < 40 ? sv : sv+80;
+          for(num = 0; num < gnss->numsats
+          && fullsat != gnss->satellites[num]; ++num)
+            ;
+
+          if(num == gnss->numsats)
+            gnss->satellites[gnss->numsats++] = fullsat;
+
           /* L1 */
           GETBITS(code, 1);
@@ -606,4 +613,8 @@
             ret = 2;
         }
+#ifdef NO_RTCM3_MAIN
+        else
+          ret = type;
+#endif /* NO_RTCM3_MAIN */
       }
       break;
@@ -613,5 +624,5 @@
         int lastlockl2[64];
         struct gnssdata *gnss;
-        int i, num;
+        int i, numsats;
         int wasamb=0;
 
@@ -638,16 +649,23 @@
 
         GETBITS(syncf,1) /* sync */
-        GETBITS(i,5)
-        gnss->numsats += i;
+        GETBITS(numsats,5)
 
         SKIPBITS(4) /* smind, smint */
 
-        for(num = gnss->numsats-i; num < gnss->numsats; ++num)
+        while(numsats--)
         {
           int sv, code, l1range, c,l,s,ce,le,se,amb=0;
           int freq;
+          int fullsat, num;
 
           GETBITS(sv, 6)
-          gnss->satellites[num] = sv-1 + PRN_GLONASS_START;
+          fullsat = sv-1 + PRN_GLONASS_START;
+          for(num = 0; num < gnss->numsats
+          && fullsat != gnss->satellites[num]; ++num)
+            ;
+
+          if(num == gnss->numsats)
+            gnss->satellites[gnss->numsats++] = fullsat;
+
           /* L1 */
           GETBITS(code, 1)
@@ -750,8 +768,6 @@
             gnss->measdata[num][le] /= GLO_WAVELENGTH_L2(freq-7);
           }
-          if(!sv || sv > 24)
-          {
-            --num; --gnss->numsats;
-          }
+          if(!sv || sv > 24) /* illegal, remove it again */
+            --gnss->numsats;
         }
         for(i = 0; i < 64; ++i)
@@ -772,4 +788,8 @@
             ret = 2;
         }
+#ifdef NO_RTCM3_MAIN
+        else
+          ret = type;
+#endif /* NO_RTCM3_MAIN */
       }
       break;
@@ -1665,5 +1685,5 @@
 
 #ifndef NO_RTCM3_MAIN
-static char datestr[]     = "$Date: 2008/11/26 10:14:46 $";
+static char datestr[]     = "$Date: 2008/12/03 08:33:16 $";
 
 /* The string, which is send as agent in HTTP request */
