Index: trunk/BNS/RTCM/clock_orbit_rtcm.c
===================================================================
--- trunk/BNS/RTCM/clock_orbit_rtcm.c	(revision 1841)
+++ trunk/BNS/RTCM/clock_orbit_rtcm.c	(revision 1843)
@@ -3,5 +3,5 @@
         Name:           clock_orbit_rtcm.c
         Project:        RTCM3
-        Version:        $Id: clock_orbit_rtcm.c,v 1.7 2009/05/12 13:19:03 stoecker Exp $
+        Version:        $Id: clock_orbit_rtcm.c,v 1.15 2009/05/14 13:24:13 stoecker Exp $
         Authors:        Dirk Stöcker
         Description:    state space approach for RTCM3
@@ -573,4 +573,8 @@
     return GCOBR_SHORTBUFFER;
 
+#ifdef DEBUG
+fprintf(stderr, "GetClockOrbitBias START: size %d, numbits %d\n",size, numbits);
+#endif
+
   G_HEADER(h)
   G_RESERVEDH(rs)
@@ -605,5 +609,6 @@
     co->OrbitDataSupplied |= 1;
 #ifdef DEBUG
-fprintf(stderr, "epochtime %d ui %d mmi %d sats %d\n",co->GPSEpochTime,co->UpdateInterval,mmi,co->NumberOfGPSSat);
+fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GPSEpochTime,
+co->UpdateInterval,mmi,co->NumberOfGPSSat,nums);
 #endif
     for(i = 0; i < nums; ++i)
@@ -653,4 +658,8 @@
     G_NO_OF_SATELLITES(nums)
     co->ClockDataSupplied |= 1;
+#ifdef DEBUG
+fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GPSEpochTime,
+co->UpdateInterval,mmi,co->NumberOfGPSSat,nums);
+#endif
     for(i = 0; i < nums; ++i)
     {
@@ -665,4 +674,9 @@
       G_DELTA_CLOCK_C1(co->Sat[pos].Clock.DeltaA1)
       G_DELTA_CLOCK_C2(co->Sat[pos].Clock.DeltaA2)
+#ifdef DEBUG
+fprintf(stderr, "id %2d c0 %8.3f c1 %8.3f c2 %8.3f\n",
+co->Sat[pos].ID, co->Sat[pos].Clock.DeltaA0, co->Sat[pos].Clock.DeltaA1,
+co->Sat[pos].Clock.DeltaA2);
+#endif
     }
     break;
@@ -755,14 +769,17 @@
     G_NO_OF_SATELLITES(nums)
     co->OrbitDataSupplied |= 2;
+#ifdef DEBUG
+fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GLONASSEpochTime,
+co->UpdateInterval,mmi,co->NumberOfGLONASSSat,nums);
+#endif
     for(i = 0; i < nums; ++i)
     {
       G_GLONASS_SATELLITE_ID(id)
-      for(pos = CLOCKORBIT_NUMGPS; pos < co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
+      for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
         ;
       if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
-      else if(pos == co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
+      else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
       co->Sat[pos].ID = id;
 
-      G_GLONASS_SATELLITE_ID(co->Sat[pos].ID)
       G_GLONASS_IOD(co->Sat[pos].IOD)
       G_DELTA_RADIAL(co->Sat[pos].Orbit.DeltaRadial)
@@ -777,4 +794,17 @@
       G_SATELLITE_REFERENCE_POINT(co->SatRefPoint)
       G_SATELLITE_REFERENCE_DATUM(co->SatRefDatum)
+#ifdef DEBUG
+fprintf(stderr, "id %2d iod %3d dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f dr %8.3f da %8.3f dc %8.3f rp %d rd %d\n",
+co->Sat[pos].ID,co->Sat[pos].IOD,co->Sat[pos].Orbit.DeltaRadial,
+co->Sat[pos].Orbit.DeltaAlongTrack,co->Sat[pos].Orbit.DeltaCrossTrack,
+co->Sat[pos].Orbit.DotDeltaRadial,
+co->Sat[pos].Orbit.DotDeltaAlongTrack,
+co->Sat[pos].Orbit.DotDeltaCrossTrack,
+co->Sat[pos].Orbit.DotDotDeltaRadial,
+co->Sat[pos].Orbit.DotDotDeltaAlongTrack,
+co->Sat[pos].Orbit.DotDotDeltaCrossTrack,
+co->SatRefPoint,
+co->SatRefDatum);
+#endif
     }
     break;
@@ -787,11 +817,15 @@
     G_NO_OF_SATELLITES(nums)
     co->ClockDataSupplied |= 2;
+#ifdef DEBUG
+fprintf(stderr, "epochtime %d ui %d mmi %d sats %d/%d\n",co->GLONASSEpochTime,
+co->UpdateInterval,mmi,co->NumberOfGLONASSSat,nums);
+#endif
     for(i = 0; i < nums; ++i)
     {
       G_GLONASS_SATELLITE_ID(id)
-      for(pos = CLOCKORBIT_NUMGPS; pos < co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
+      for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
         ;
       if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
-      else if(pos == co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
+      else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
       co->Sat[pos].ID = id;
 
@@ -799,4 +833,9 @@
       G_DELTA_CLOCK_C1(co->Sat[pos].Clock.DeltaA1)
       G_DELTA_CLOCK_C2(co->Sat[pos].Clock.DeltaA2)
+#ifdef DEBUG
+fprintf(stderr, "id %2d c0 %8.3f c1 %8.3f c2 %8.3f\n",
+co->Sat[pos].ID, co->Sat[pos].Clock.DeltaA0, co->Sat[pos].Clock.DeltaA1,
+co->Sat[pos].Clock.DeltaA2);
+#endif
     }
     break;
@@ -813,8 +852,8 @@
     {
       G_GLONASS_SATELLITE_ID(id)
-      for(pos = CLOCKORBIT_NUMGPS; pos < co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
+      for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
         ;
       if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
-      else if(pos == co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
+      else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
       co->Sat[pos].ID = id;
 
@@ -846,8 +885,8 @@
     {
       G_GLONASS_SATELLITE_ID(id)
-      for(pos = CLOCKORBIT_NUMGPS; pos < co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
+      for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
         ;
       if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
-      else if(pos == co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
+      else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
       co->Sat[pos].ID = id;
 
@@ -866,8 +905,8 @@
     {
       G_GLONASS_SATELLITE_ID(id)
-      for(pos = CLOCKORBIT_NUMGPS; pos < co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
+      for(pos = CLOCKORBIT_NUMGPS; pos < CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
         ;
       if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
-      else if(pos == co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
+      else if(pos == CLOCKORBIT_NUMGPS+co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
       co->Sat[pos].ID = id;
 
@@ -877,6 +916,6 @@
   case BTYPE_GPS:
     if(!b) return GCOBR_NOBIASPARAMETER;
-    G_GPS_EPOCH_TIME(b->GPSEpochTime, co->NumberOfGPSSat)
-    G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
+    G_GPS_EPOCH_TIME(b->GPSEpochTime, b->NumberOfGPSSat)
+    G_SSR_UPDATE_INTERVAL(b->UpdateInterval)
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
     G_RESERVED5
@@ -885,9 +924,9 @@
     {
       G_GPS_SATELLITE_ID(id)
-      for(pos = 0; pos < co->NumberOfGPSSat && co->Sat[pos].ID != id; ++pos)
+      for(pos = 0; pos < b->NumberOfGPSSat && b->Sat[pos].ID != id; ++pos)
         ;
       if(pos >= CLOCKORBIT_NUMGPS) return GCOBR_DATAMISMATCH;
-      else if(pos == co->NumberOfGPSSat) ++co->NumberOfGPSSat;
-      co->Sat[pos].ID = id;
+      else if(pos == b->NumberOfGPSSat) ++b->NumberOfGPSSat;
+      b->Sat[pos].ID = id;
 
       G_NO_OF_CODE_BIASES(b->Sat[pos].NumberOfCodeBiases)
@@ -901,6 +940,6 @@
   case BTYPE_GLONASS:
     if(!b) return GCOBR_NOBIASPARAMETER;
-    G_GPS_EPOCH_TIME(b->GLONASSEpochTime, co->NumberOfGLONASSSat)
-    G_SSR_UPDATE_INTERVAL(co->UpdateInterval)
+    G_GLONASS_EPOCH_TIME(b->GLONASSEpochTime, b->NumberOfGLONASSSat)
+    G_SSR_UPDATE_INTERVAL(b->UpdateInterval)
     G_MULTIPLE_MESSAGE_INDICATOR(mmi)
     G_RESERVED5
@@ -909,9 +948,9 @@
     {
       G_GLONASS_SATELLITE_ID(id)
-      for(pos = CLOCKORBIT_NUMGPS; pos < co->NumberOfGLONASSSat && co->Sat[pos].ID != id; ++pos)
+      for(pos = CLOCKORBIT_NUMGPS; pos < b->NumberOfGLONASSSat && b->Sat[pos].ID != id; ++pos)
         ;
       if(pos >= CLOCKORBIT_NUMGPS+CLOCKORBIT_NUMGLONASS) return GCOBR_DATAMISMATCH;
-      else if(pos == co->NumberOfGLONASSSat) ++co->NumberOfGLONASSSat;
-      co->Sat[pos].ID = id;
+      else if(pos == b->NumberOfGLONASSSat) ++b->NumberOfGLONASSSat;
+      b->Sat[pos].ID = id;
 
       G_NO_OF_CODE_BIASES(b->Sat[pos].NumberOfCodeBiases)
@@ -924,8 +963,10 @@
     break;
   default:
+    if(bytesused)
+      *bytesused = sizeofrtcmblock+6;
     return GCOBR_UNKNOWNTYPE;
   }
 #ifdef DEBUG
-for(type = 0; type < size && (unsigned char)buffer[type] != 0xD3; ++type)
+for(type = 0; type < (int)size && (unsigned char)buffer[type] != 0xD3; ++type)
   numbits += 8;
 fprintf(stderr, "numbits left %d\n",numbits);
