Index: trunk/BNC/RTIGS/rtigs.cpp
===================================================================
--- trunk/BNC/RTIGS/rtigs.cpp	(revision 54)
+++ trunk/BNC/RTIGS/rtigs.cpp	(revision 55)
@@ -1,5 +1,15 @@
 #include "rtigs.h"
 
-#define MAXSTREAM 2048
+#define MAXSTREAM 10000
+
+////////////////////////////////////////////////////////////////////////////
+void SwitchBytes( char *Start, int Size ) {
+  char Tmp;
+  char *End = Start + Size - 1;
+  for( Tmp = *Start; Start < End; Tmp = *Start ){
+    *Start++ = *End;
+    *End-- = Tmp;
+  }
+}
 
 int main() {
@@ -20,25 +30,65 @@
 
   // use something like recvfrom 
-
-  messType = GPSTrans.GetRTIGSHdrRecType(data_stream);
-  numbytes = GPSTrans.GetRTIGSHdrRecBytes(data_stream);
-  statID   = GPSTrans.GetRTIGSHdrStaID(data_stream);
-
-  switch (messType) {
-  case 100:
-    GPSTrans.Decode_RTIGS_Sta(data_stream, numbytes , rtigs_sta);
-    break;
-  case 200:
-    retval = GPSTrans.Decode_RTIGS_Obs(data_stream, numbytes , rtigs_obs);
-    if (retval >= 1) {
-      GPSTrans.print_CMEAS();
-    }
-    break;
-  case 300:
-    retval = GPSTrans.Decode_RTIGS_Eph(data_stream, numbytes , rtigs_eph, PRN);
-    break;
-  case 400:
-    retval = GPSTrans.Decode_RTIGS_Met(data_stream, numbytes , &rtigs_met); 
-    break;
+  FILE* inpFile = fopen("RTIGS.txt", "rb");
+
+  while (true) {
+    size_t nr = 0;
+   if (inpFile) {
+     nr = fread(data_stream, sizeof(unsigned char), MAXSTREAM, inpFile);
+     if (nr == 0) exit(0);
+     cout << "Number of bytes read: " << nr << endl;
+   }
+   else {
+     exit(1);
+   }
+  
+   // Find the beginning of the message
+   // ---------------------------------
+   size_t sz = sizeof(unsigned short);
+   bool   found = false;
+   size_t ii;
+   for (ii = 0; ii < nr - sz; ii += sz) {
+     unsigned short xx;
+     memcpy( (void*) &xx, &data_stream[ii], sz);
+     SwitchBytes( (char*) &xx, sz);
+     if (xx == 200) {
+       found = true;
+       break;
+     }
+   }
+   if (! found) {
+     cout << "Message not found\n";
+     exit(0);
+   }
+   else {
+     cout << "Message found at " << ii << endl;
+   }
+
+
+   messType = GPSTrans.GetRTIGSHdrRecType(&data_stream[ii]);
+   numbytes = GPSTrans.GetRTIGSHdrRecBytes(&data_stream[ii]);
+   statID   = GPSTrans.GetRTIGSHdrStaID(&data_stream[ii]);
+
+   cout << "messType " << messType << endl;
+   cout << "numbytes " << numbytes << endl;
+   cout << "statID "   << statID   << endl;
+
+   switch (messType) {
+   case 100:
+     GPSTrans.Decode_RTIGS_Sta(&data_stream[ii], numbytes , rtigs_sta);
+     break;
+   case 200:
+     retval = GPSTrans.Decode_RTIGS_Obs(&data_stream[ii], numbytes , rtigs_obs);
+     if (retval >= 1) {
+       GPSTrans.print_CMEAS();
+     }
+     break;
+   case 300:
+     retval = GPSTrans.Decode_RTIGS_Eph(&data_stream[ii], numbytes , rtigs_eph, PRN);
+     break;
+   case 400:
+     retval = GPSTrans.Decode_RTIGS_Met(&data_stream[ii], numbytes , &rtigs_met); 
+     break;
+   }
   }
 
@@ -125,14 +175,4 @@
 }
 
-// 
-////////////////////////////////////////////////////////////////////////////
-void CGPS_Transform::SwitchBytes( char *Start, int Size ) {
-  char Tmp;
-  char *End = Start + Size - 1;
-  for( Tmp = *Start; Start < End; Tmp = *Start ){
-    *Start++ = *End;
-    *End-- = Tmp;
-  }
-}
 
 // 
@@ -556,4 +596,6 @@
   StrPos = IGSObsMinusPtr = sizeof(RTIGSO_T) - sizeof (rtigs_obs.data);
 
+  cout << "StrPos " << StrPos << endl;
+
   memcpy ((void *)&rtigs_obs.rec_id, RTIGSO_Str, IGSObsMinusPtr);
 
@@ -564,5 +606,6 @@
 
 
-//      printf("RecNumber : %hd Station ID %hd Num Obs %hd NumBytes %hd\n",rtigs_obs.rec_id, rtigs_obs.sta_id, rtigs_obs.num_obs, rtigs_obs.num_bytes);
+  printf("RecNumber : %hd Station ID %hd Num Obs %hd NumBytes %hd\n",rtigs_obs.rec_id, rtigs_obs.sta_id, rtigs_obs.num_obs, rtigs_obs.num_bytes);
+
   if((rtigs_obs.rec_id == 200) && (rtigs_obs.num_obs <= MAXCHANNELS_FOR_SOCKETS_TYPE1))
   {
Index: trunk/BNC/RTIGS/rtigs.h
===================================================================
--- trunk/BNC/RTIGS/rtigs.h	(revision 54)
+++ trunk/BNC/RTIGS/rtigs.h	(revision 55)
@@ -109,5 +109,4 @@
   short          P1_P2_Block_Extract(char * P1P2Str, double CA, double &Rng , double &Phase, double &RngF2Delta,short decode_F1orF2Flag );//done
   unsigned long  JPL_xtractLongVal (unsigned startBitNbr, unsigned xtractNbrBits, const char *msg);        //done
-  void           SwitchBytes( char *Start, int Size );
   inline void    SwitchIGS_Sta_HdrBytes( RTIGSS_T *StaHdr);
   inline void    SwitchIGS_Obs_HdrBytes( RTIGSO_T *ObsHdr);
