Index: trunk/BNC/RTCM3/RTCM3Decoder.cpp
===================================================================
--- trunk/BNC/RTCM3/RTCM3Decoder.cpp	(revision 319)
+++ trunk/BNC/RTCM3/RTCM3Decoder.cpp	(revision 320)
@@ -51,4 +51,10 @@
 #  define isinf(x) 0
 #endif
+
+// Error Handling
+////////////////////////////////////////////////////////////////////////////
+void RTCM3Error(const char *fmt, ...) {
+
+}
 
 // Constructor
Index: trunk/BNC/RTCM3/rtcm3torinex.cpp
===================================================================
--- trunk/BNC/RTCM3/rtcm3torinex.cpp	(revision 319)
+++ trunk/BNC/RTCM3/rtcm3torinex.cpp	(revision 320)
@@ -1,5 +1,5 @@
 /*
   Converter for RTCM3 data to RINEX.
-  $Id: rtcm3torinex.cpp,v 1.9 2006/11/08 16:08:32 mervart Exp $
+  $Id: rtcm3torinex.c,v 1.10 2006/11/15 12:31:31 stoecker Exp $
   Copyright (C) 2005-2006 by Dirk Stoecker <stoecker@euronik.eu>
 
@@ -29,4 +29,5 @@
 #include <math.h>
 #include <signal.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -50,5 +51,5 @@
 
 /* CVS revision and version */
-static char revisionstr[] = "$Revision: 1.9 $";
+static char revisionstr[] = "$Revision: 1.10 $";
 
 static uint32_t CRC24(long size, const unsigned char *buf)
@@ -109,5 +110,5 @@
   i = m - handle->Message;
   if(i && m < e)
-    memmove(handle->Message, m, handle->MessageSize-i);
+    memmove(handle->Message, m, (size_t)(handle->MessageSize-i));
   handle->MessageSize -= i;
 
@@ -145,4 +146,91 @@
 #define SKIPBITS(b) { LOADBITS(b) numbits -= (b); }
 
+struct leapseconds { /* specify the day of leap second */
+  int day;        /* this is the day, where 23:59:59 exists 2 times */
+  int month;      /* not the next day! */
+  int year;
+  int taicount;
+}; 
+static const int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
+static const struct leapseconds leap[] = {
+/*{31, 12, 1971, 11},*/
+/*{31, 12, 1972, 12},*/
+/*{31, 12, 1973, 13},*/
+/*{31, 12, 1974, 14},*/
+/*{31, 12, 1975, 15},*/
+/*{31, 12, 1976, 16},*/
+/*{31, 12, 1977, 17},*/
+/*{31, 12, 1978, 18},*/
+/*{31, 12, 1979, 19},*/
+{30, 06, 1981,20},
+{30, 06, 1982,21},
+{30, 06, 1983,22},
+{30, 06, 1985,23},
+{31, 12, 1987,24},
+{31, 12, 1989,25},
+{31, 12, 1990,26},
+{30, 06, 1992,27},
+{30, 06, 1993,28},
+{30, 06, 1994,29},
+{31, 12, 1995,30},
+{30, 06, 1997,31},
+{31, 12, 1998,32},
+{31, 12, 2005,33},
+{0,0,0,0} /* end marker */
+};
+#define GPSLEAPSTART    19 /* 19 leap seconds existed at 6.1.1980 */
+
+static int longyear(int year, int month)
+{
+  if(!(year % 4) && (!(year % 400) || (year % 100)))
+  {
+    if(!month || month == 2)
+      return 1;
+  }
+  return 0;
+}
+
+static int gnumleap(int year, int month, int day)
+{
+  int ls = 0;
+  const struct leapseconds *l;
+
+  for(l = leap; l->taicount && year >= l->year; ++l)
+  {
+    if(year > l->year || month > l->month || day > l->day)
+       ls = l->taicount - GPSLEAPSTART;
+  }
+  return ls;
+}
+
+static void updatetime(int *week, int *tow, int tk)
+{
+  int y,m,d,k,l;
+  unsigned int j = *week*(7*24*60*60) + *tow + 5*24*60*60+3*60*60;
+  int glo_daynumber = 0, glo_timeofday;
+  for(y = 1980; j >= (unsigned int)(k = (l = (365+longyear(y,0)))*24*60*60)
+  + gnumleap(y+1,1,1); ++y)
+  {
+    j -= k; glo_daynumber += l;
+  }
+  for(m = 1; j >= (unsigned int)(k = (l = months[m]+longyear(y, m))*24*60*60)
+  + gnumleap(y, m+1, 1); ++m)
+  {
+    j -= k; glo_daynumber += l;
+  }
+  for(d = 1; j >= 24UL*60UL*60UL + gnumleap(y, m, d+1); ++d)
+    j -= 24*60*60;
+  glo_daynumber -= 16*365+4-d;
+  glo_timeofday = j-gnumleap(y, m, d);
+
+  if(tk < 5*60*1000 && glo_timeofday > 23*60*60)
+    *tow += 24*60*60;
+  else if(glo_timeofday < 5*60 && tk > 23*60*60*1000)
+    *tow -= 24*60*60;
+  *tow += tk/1000-glo_timeofday;
+  if(*tow < 0) {*tow += 24*60*60*7; --*week; }
+  if(*tow >= 24*60*60*7) {*tow -= 24*60*60*7; ++*week; }
+}
+
 int RTCM3Parser(struct RTCM3ParserData *handle)
 {
@@ -155,4 +243,5 @@
     uint64_t numbits = 0, bitfield = 0;
     int size = handle->size, type;
+    int syncf, old = 0;
     unsigned char *data = handle->Message+3;
 
@@ -171,6 +260,5 @@
           lastlockl1[i] = lastlockl2[i] = 0;
 
-        gnss = &handle->Data;
-        memset(gnss, 0, sizeof(*gnss));
+        gnss = &handle->DataNew;
 
         SKIPBITS(12) /* id */
@@ -179,8 +267,15 @@
           ++handle->GPSWeek;
         handle->GPSTOW = i/1000;
+        if(gnss->week && (gnss->timeofweek != i || gnss->week
+        != handle->GPSWeek))
+        {
+          handle->Data = *gnss;
+          memset(gnss, 0, sizeof(*gnss));
+          old = 1;
+        }
         gnss->timeofweek = i;
         gnss->week = handle->GPSWeek;
 
-        SKIPBITS(1) /* sync */
+        GETBITS(syncf,1) /* sync */
         GETBITS(i,5)
         gnss->numsats = i;
@@ -299,10 +394,188 @@
           handle->lastlockl2[i] = lastlockl2[i];
         }
-        if(wasamb) /* not RINEX compatible without */
-          ret = 1;
-        else
-          ret = 2;
+        if(!syncf && !old)
+        {
+          handle->Data = *gnss;
+          memset(gnss, 0, sizeof(*gnss));
+        }
+        if(!syncf || old)
+        {
+          if(wasamb) /* not RINEX compatible without */
+            ret = 1;
+          else
+            ret = 2;
+        }
       }
       break;
+    case 1009: case 1010: case 1011: case 1012:
+      {
+        int lastlockl1[64];
+        int lastlockl2[64];
+        struct gnssdata *gnss;
+        int i, num;
+        int wasamb=0;
+
+        for(i = 0; i < 64; ++i)
+          lastlockl1[i] = lastlockl2[i] = 0;
+
+        gnss = &handle->DataNew;
+
+        SKIPBITS(12) /* id */;
+        GETBITS(i,27) /* tk */
+
+        updatetime(&handle->GPSWeek, &handle->GPSTOW, i);
+        i = handle->GPSTOW*1000;
+        if(gnss->week && (gnss->timeofweek != i || gnss->week
+        != handle->GPSWeek))
+        {
+          handle->Data = *gnss;
+          memset(gnss, 0, sizeof(*gnss));
+          old = 1;
+        }
+
+        gnss->timeofweek = i;
+        gnss->week = handle->GPSWeek;
+
+        GETBITS(syncf,1) /* sync */
+        GETBITS(i,5)
+        gnss->numsats += i;
+
+        SKIPBITS(4) /* smind, smint */
+
+        for(num = gnss->numsats-i; num < gnss->numsats; ++num)
+        {
+          int sv, code, l1range, c,l,s,ce,le,se,amb=0;
+
+          GETBITS(sv, 6)
+          if(!sv || sv > 24)
+          {
+            --num; --gnss->numsats;
+          }
+          else
+          {
+            int freq;
+            gnss->satellites[num] = sv-1 + PRN_GLONASS_START;
+            /* L1 */
+            GETBITS(code, 1)
+            GETBITS(freq, 5)
+            if(code)
+            {
+              c = GNSSDF_P1DATA;  ce = GNSSENTRY_P1DATA;
+              l = GNSSDF_L1PDATA; le = GNSSENTRY_L1PDATA;
+              s = GNSSDF_S1PDATA; se = GNSSENTRY_S1PDATA;
+            }
+            else
+            {
+              c = GNSSDF_C1DATA;  ce = GNSSENTRY_C1DATA;
+              l = GNSSDF_L1CDATA; le = GNSSENTRY_L1CDATA;
+              s = GNSSDF_S1CDATA; se = GNSSENTRY_S1CDATA;
+            }
+            GETBITS(l1range, 25)
+            if(l1range != 0x80000)
+            {
+              gnss->dataflags[num] |= c;
+              gnss->measdata[num][ce] = l1range*0.02;
+            }
+            GETBITSSIGN(i, 20)
+            if(i != 0x80000)
+            {
+              gnss->dataflags[num] |= l;
+              gnss->measdata[num][le] = l1range*0.02+i*0.0005;
+            }
+            GETBITS(i, 7)
+            lastlockl1[sv] = i;
+            if(handle->lastlockl1[sv] > i)
+              gnss->dataflags[num] |= GNSSDF_LOCKLOSSL1;
+            if(type == 1010 || type == 1012)
+            {
+              GETBITS(amb,7)
+              if(amb && (gnss->dataflags[num] & c))
+              {
+                gnss->measdata[num][ce] += amb*599584.916;
+                gnss->measdata[num][le] += amb*599584.916;
+                ++wasamb;
+              }
+              GETBITS(i, 8)
+              if(i)
+              {
+                gnss->dataflags[num] |= s;
+                gnss->measdata[num][se] = i*0.25;
+                i /= 4*4;
+                if(i > 9) i = 9;
+                else if(i < 1) i = 1;
+                gnss->snrL1[num] = i;
+              }
+            }
+            gnss->measdata[num][le] /= GLO_WAVELENGTH_L1(freq-7);
+            if(type == 1011 || type == 1012)
+            {
+              /* L2 */
+              GETBITS(code,2)
+              if(code)
+              {
+                c = GNSSDF_P2DATA;  ce = GNSSENTRY_P2DATA;
+                l = GNSSDF_L2PDATA; le = GNSSENTRY_L2PDATA;
+                s = GNSSDF_S2PDATA; se = GNSSENTRY_S2PDATA;
+              }
+              else
+              {
+                c = GNSSDF_C2DATA;  ce = GNSSENTRY_C2DATA;
+                l = GNSSDF_L2CDATA; le = GNSSENTRY_L2CDATA;
+                s = GNSSDF_S2CDATA; se = GNSSENTRY_S2CDATA;
+              }
+              GETBITSSIGN(i,14)
+              if(i != 0x2000)
+              {
+                gnss->dataflags[num] |= c;
+                gnss->measdata[num][ce] = l1range*0.02+i*0.02
+                +amb*599584.916;
+              }
+              GETBITSSIGN(i,20)
+              if(i != 0x80000)
+              {
+                gnss->dataflags[num] |= l;
+                gnss->measdata[num][le] = l1range*0.02+i*0.0005
+                +amb*599584.915;
+              }
+              GETBITS(i,7)
+              lastlockl2[sv] = i;
+              if(handle->lastlockl2[sv] > i)
+                gnss->dataflags[num] |= GNSSDF_LOCKLOSSL2;
+              if(type == 1012)
+              {
+                GETBITS(i, 8)
+                if(i)
+                {
+                  gnss->dataflags[num] |= s;
+                  gnss->measdata[num][se] = i*0.25;
+                  i /= 4*4;
+                  if(i > 9) i = 9;
+                  else if(i < 1) i = 1;
+                  gnss->snrL2[num] = i;
+                }
+              }
+              gnss->measdata[num][le] /= GLO_WAVELENGTH_L2(freq-7);
+            }
+          }
+        }
+        for(i = 0; i < 64; ++i)
+        {
+          handle->lastlockl1[i] = lastlockl1[i];
+          handle->lastlockl2[i] = lastlockl2[i];
+        }
+        if(!syncf && !old)
+        {
+          handle->Data = *gnss;
+          memset(gnss, 0, sizeof(*gnss));
+        }
+        if(!syncf || old)
+        {
+          if(wasamb) /* not RINEX compatible without */
+            ret = 1;
+          else
+            ret = 2;
+        }
+      }
+      break;
     }
   }
@@ -310,19 +583,42 @@
 }
 
-static int longyear(int year, int month)
-{
-  if(!(year % 4) && (!(year % 400) || (year % 100)))
-  {
-    if(!month || month == 2)
-      return 1;
-  }
-  return 0;
-}
-
-void converttime(struct converttimeinfo *c, int week, int tow)
-{
-  /* static variables */
-  static const int months[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
-
+struct Header
+{
+  const char *version;
+  const char *pgm;
+  const char *marker;
+  const char *observer;
+  const char *receiver;
+  const char *antenna;
+  const char *position;
+  const char *antennaposition;
+  const char *wavelength;
+  const char *typesofobs; /* should not be modified outside */
+  const char *timeoffirstobs; /* should not be modified outside */
+};
+
+#define MAXHEADERLINES 50
+#define MAXHEADERBUFFERSIZE 4096
+struct HeaderData
+{
+  union
+  {
+    struct Header named;
+    const char *unnamed[MAXHEADERLINES];
+  } data;
+  int  numheaders;
+};
+
+struct converttimeinfo {
+  int second;    /* seconds of GPS time [0..59] */
+  int minute;    /* minutes of GPS time [0..59] */
+  int hour;      /* hour of GPS time [0..24] */
+  int day;       /* day of GPS time [1..28..30(31)*/
+  int month;     /* month of GPS time [1..12]*/
+  int year;      /* year of GPS time [1980..] */
+};
+
+static void converttime(struct converttimeinfo *c, int week, int tow)
+{
   int i, k, doy, j; /* temporary variables */
   j = week*(7*24*60*60) + tow + 5*24*60*60;
@@ -343,31 +639,23 @@
 }
 
-struct Header
-{
-  const char *version;
-  const char *pgm;
-  const char *marker;
-  const char *observer;
-  const char *receiver;
-  const char *antenna;
-  const char *position;
-  const char *antennaposition;
-  const char *wavelength;
-  const char *typesofobs; /* should not be modified outside */
-  const char *timeoffirstobs; /* should not be modified outside */
-};
-
-#define MAXHEADERLINES 50
-#define MAXHEADERBUFFERSIZE 4096
-struct HeaderData
-{
-  union
-  {
-    struct Header named;
-    const char *unnamed[MAXHEADERLINES];
-  } data;
-  int  numheaders;
-};
-
+#ifndef NO_RTCM3_MAIN
+void RTCM3Error(const char *fmt, ...)
+{
+  va_list v;
+  va_start(v, fmt);
+  vfprintf(stderr, fmt, v);
+  va_end(v);
+}
+#endif
+
+void RTCM3Text(const char *fmt, ...)
+{
+  va_list v;
+  va_start(v, fmt);
+  vprintf(fmt, v);
+  va_end(v);
+}
+
+#define NUMSTARTSKIP 3
 void HandleHeader(struct RTCM3ParserData *Parser)
 {
@@ -375,5 +663,5 @@
   char thebuffer[MAXHEADERBUFFERSIZE];
   char *buffer = thebuffer;
-  int buffersize = sizeof(thebuffer);
+  size_t buffersize = sizeof(thebuffer);
   int i;
 
@@ -453,5 +741,5 @@
     }
 
-    int flags = 0;
+    int flags = Parser->startflags;
     int data[RINEXENTRY_NUMBER];
     char tbuffer[6*RINEXENTRY_NUMBER+1];
@@ -510,5 +798,5 @@
     if((fh = fopen(Parser->headerfile, "r")))
     {
-      int siz;
+      size_t siz;
       char *lastblockstart;
       if((siz = fread(buffer, 1, buffersize-1, fh)) > 0)
@@ -517,5 +805,5 @@
         if(siz == buffersize)
         {
-          fprintf(stderr, "Header file is too large. Only %d bytes read.",
+          RTCM3Error("Header file is too large. Only %d bytes read.",
           siz);
         }
@@ -524,5 +812,5 @@
         /* overwrites entries, except for comments */
         lastblockstart = buffer;
-        for(i = 0; i < siz; ++i)
+        for(i = 0; i < (int)siz; ++i)
         {
           if(buffer[i] == '\n')
@@ -535,5 +823,5 @@
               *(end--) = 0;
             if(end-lastblockstart < 60+5) /* short line */
-              fprintf(stderr, "Short Header line '%s' ignored.\n", lastblockstart);
+              RTCM3Error("Short Header line '%s' ignored.\n", lastblockstart);
             else
             {
@@ -551,5 +839,5 @@
                 || !strcmp("TIME OF FIRST OBS", lastblockstart+60))
                 {
-                  fprintf(stderr, "Overwriting header '%s' is dangerous.\n",
+                  RTCM3Error("Overwriting header '%s' is dangerous.\n",
                   lastblockstart+60);
                 }
@@ -557,11 +845,10 @@
               if(pos >= MAXHEADERLINES)
               {
-                fprintf(stderr,
-                "Maximum number of header lines of %d reached.\n",
+                RTCM3Error("Maximum number of header lines of %d reached.\n",
                 MAXHEADERLINES);
               }
               else if(!strcmp("END OF HEADER", lastblockstart+60))
               {
-                fprintf(stderr, "End of header ignored.\n");
+                RTCM3Error("End of header ignored.\n");
               }
               else
@@ -578,5 +865,5 @@
       else
       {
-        fprintf(stderr, "Could not read data from headerfile '%s'.\n",
+        RTCM3Error("Could not read data from headerfile '%s'.\n",
         Parser->headerfile);
       }
@@ -585,5 +872,5 @@
     else
     {
-      fprintf(stderr, "Could not open header datafile '%s'.\n",
+      RTCM3Error("Could not open header datafile '%s'.\n",
       Parser->headerfile);
     }
@@ -592,6 +879,6 @@
 #ifndef NO_RTCM3_MAIN
   for(i = 0; i < hdata.numheaders; ++i)
-    printf("%s\n", hdata.data.unnamed[i]);
-  printf("                                                            "
+    RTCM3Text("%s\n", hdata.data.unnamed[i]);
+  RTCM3Text("                                                            "
   "END OF HEADER\n");
 #endif
@@ -609,12 +896,20 @@
       struct converttimeinfo cti;
 
-      if(!Parser->init)
-      {
-        HandleHeader(Parser);
-        Parser->init = 1;
+      if(Parser->init < NUMSTARTSKIP) /* skip first epochs to detect correct data types */
+      {
+        ++Parser->init;
+
+        if(Parser->init == NUMSTARTSKIP)
+          HandleHeader(Parser);
+        else
+        {
+          for(i = 0; i < Parser->Data.numsats; ++i)
+            Parser->startflags |= Parser->Data.dataflags[i];
+          continue;
+        }
       }
       if(r == 2 && !Parser->validwarning)
       {
-        printf("No valid RINEX! All values are modulo 299792.458!"
+        RTCM3Text("No valid RINEX! All values are modulo 299792.458!"
         "           COMMENT\n");
         Parser->validwarning = 1;
@@ -623,5 +918,5 @@
       converttime(&cti, Parser->Data.week,
       (int)floor(Parser->Data.timeofweek/1000.0));
-      printf(" %02d %2d %2d %2d %2d %10.7f  0%3d",
+      RTCM3Text(" %02d %2d %2d %2d %2d %10.7f  0%3d",
       cti.year%100, cti.month, cti.day, cti.hour, cti.minute, cti.second
       + fmod(Parser->Data.timeofweek/1000.0,1.0), Parser->Data.numsats);
@@ -629,28 +924,31 @@
       {
         if(Parser->Data.satellites[i] <= PRN_GPS_END)
-          printf("G%02d", Parser->Data.satellites[i]);
+          RTCM3Text("G%02d", Parser->Data.satellites[i]);
         else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
         && Parser->Data.satellites[i] <= PRN_GLONASS_END)
-          printf("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
+          RTCM3Text("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
         else
-          printf("%3d", Parser->Data.satellites[i]);
-      }
-      printf("\n");
+          RTCM3Text("%3d", Parser->Data.satellites[i]);
+      }
+      RTCM3Text("\n");
       o = 12;
       j = Parser->Data.numsats - 12;
       while(j > 0)
       {
-        printf("                                ");
+        RTCM3Text("                                ");
         for(i = o; i < o+12 && i < Parser->Data.numsats; ++i)
         {
           if(Parser->Data.satellites[i] <= PRN_GPS_END)
-            printf("G%02d", Parser->Data.satellites[i]);
+            RTCM3Text("G%02d", Parser->Data.satellites[i]);
           else if(Parser->Data.satellites[i] >= PRN_GLONASS_START
           && Parser->Data.satellites[i] <= PRN_GLONASS_END)
-            printf("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
+            RTCM3Text("R%02d", Parser->Data.satellites[i] - (PRN_GLONASS_START-1));
+          else if(Parser->Data.satellites[i] >= PRN_WAAS_START
+          && Parser->Data.satellites[i] <= PRN_WAAS_END)
+            RTCM3Text("S%02d", Parser->Data.satellites[i] - PRN_WAAS_START);
           else
-            printf("%3d", Parser->Data.satellites[i]);
-        }
-        printf("\n");
+            RTCM3Text("%3d", Parser->Data.satellites[i]);
+        }
+        RTCM3Text("\n");
         j -= 12;
         o += 12;
@@ -664,5 +962,5 @@
           || isinf(Parser->Data.measdata[i][Parser->datapos[j]]))
           { /* no or illegal data */
-            printf("                ");
+            RTCM3Text("                ");
           }
           else
@@ -682,9 +980,9 @@
               snr = '0'+Parser->Data.snrL2[i];
             }
-            printf("%14.3f%c%c",
+            RTCM3Text("%14.3f%c%c",
             Parser->Data.measdata[i][Parser->datapos[j]],lli,snr);
           }
           if(j%5 == 4 || j == Parser->numdatatypes-1)
-            printf("\n");
+            RTCM3Text("\n");
         }
       }
@@ -694,5 +992,5 @@
 
 #ifndef NO_RTCM3_MAIN
-static char datestr[]     = "$Date: 2006/11/08 16:08:32 $";
+static char datestr[]     = "$Date: 2006/11/15 12:31:31 $";
 
 /* The string, which is send as agent in HTTP request */
@@ -777,5 +1075,77 @@
 {0,0,0,0}};
 #endif
-#define ARGOPT "d:hp:r:s:u:f:"
+#define ARGOPT "-d:hp:r:s:u:f:"
+
+static const char *geturl(const char *url, struct Args *args)
+{
+  static char buf[1000];
+  static char *Buffer = buf;
+  static char *Bufend = buf+sizeof(buf);
+
+  if(strncmp("ntrip:", url, 6))
+    return "URL must start with 'ntrip:'.";
+  url += 6; /* skip ntrip: */
+
+  if(*url != '@' && *url != '/')
+  {
+    /* scan for mountpoint */
+    args->data = Buffer;
+    while(*url && *url != '@' && *url != '/' && Buffer != Bufend)
+      *(Buffer++) = *(url++);
+    if(Buffer == args->data)
+      return "Mountpoint required.";
+    else if(Buffer >= Bufend-1)
+      return "Parsing buffer too short.";
+    *(Buffer++) = 0;
+  }
+
+  if(*url == '/') /* username and password */
+  {
+    ++url;
+    args->user = Buffer;
+    while(*url && *url != '@' && *url != ':' && Buffer != Bufend)
+      *(Buffer++) = *(url++);
+    if(Buffer == args->user)
+      return "Username cannot be empty.";
+    else if(Buffer >= Bufend-1)
+      return "Parsing buffer too short.";
+    *(Buffer++) = 0;
+
+    if(*url == ':') ++url;
+
+    args->password = Buffer;
+    while(*url && *url != '@' && Buffer != Bufend)
+      *(Buffer++) = *(url++);
+    if(Buffer == args->password)
+      return "Password cannot be empty.";
+    else if(Buffer >= Bufend-1)
+      return "Parsing buffer too short.";
+    *(Buffer++) = 0;
+  }
+
+  if(*url == '@') /* server */
+  {
+    ++url;
+    args->server = Buffer;
+    while(*url && *url != ':' && Buffer != Bufend)
+      *(Buffer++) = *(url++);
+    if(Buffer == args->server)
+      return "Servername cannot be empty.";
+    else if(Buffer >= Bufend-1)
+      return "Parsing buffer too short.";
+    *(Buffer++) = 0;
+
+    if(*url == ':')
+    {
+      char *s2 = 0;
+      args->port = strtol(++url, &s2, 10);
+      if(*s2 || args->port <= 0 || args->port > 0xFFFF)
+        return "Illegal port number.";
+      url = s2;
+    }
+  }
+
+  return *url ? "Garbage at end of server string." : 0;
+}
 
 static int getargs(int argc, char **argv, struct Args *args)
@@ -813,4 +1183,14 @@
         res = 0;
       break;
+    case 1:
+      {
+        const char *err;
+        if((err = geturl(optarg, args)))
+        {
+          RTCM3Error("%s\n\n", err);
+          res = 0;
+        }
+      }
+      break;
     case -1: break;
     }
@@ -830,5 +1210,5 @@
   if(!res || help)
   {
-    fprintf(stderr, "Version %s (%s) GPL\nUsage: %s -s server -u user ...\n"
+    RTCM3Error("Version %s (%s) GPL\nUsage: %s -s server -u user ...\n"
     " -d " LONG_OPT("--data       ") "the requested data set\n"
     " -f " LONG_OPT("--headerfile ") "file for RINEX header information\n"
@@ -837,5 +1217,6 @@
     " -r " LONG_OPT("--port       ") "the server port number (default 80)\n"
     " -u " LONG_OPT("--user       ") "the user name\n"
-    , revisionstr, datestr, argv[0]);
+    "or using an URL:\n%s ntrip:mountpoint[/username[:password]][@server[:port]]\n"
+    , revisionstr, datestr, argv[0], argv[0]);
     exit(1);
   }
@@ -848,5 +1229,5 @@
   if(!stop)
   {
-    fprintf(stderr, "Stop signal number %d received. "
+    RTCM3Error("Stop signal number %d received. "
     "Trying to terminate gentle.\n", sig);
     stop = 1;
@@ -863,5 +1244,5 @@
 #endif /* __GNUC__ */
 {
-  fprintf(stderr, "Programm forcefully terminated.\n");
+  RTCM3Error("Programm forcefully terminated.\n");
   exit(1);
 }
@@ -952,5 +1333,5 @@
       if(i > MAXDATASIZE-40 && i < 0) /* second check for old glibc */
       {
-        fprintf(stderr, "Requested data too long\n");
+        RTCM3Error("Requested data too long\n");
         exit(1);
       }
@@ -958,5 +1339,5 @@
       if(i > MAXDATASIZE-5)
       {
-        fprintf(stderr, "Username and/or password too long\n");
+        RTCM3Error("Username and/or password too long\n");
         exit(1);
       }
@@ -978,10 +1359,10 @@
           if(numbytes < 12 || strncmp("ICY 200 OK\r\n", buf, 12))
           {
-            fprintf(stderr, "Could not get the requested data: ");
+            RTCM3Error("Could not get the requested data: ");
             for(k = 0; k < numbytes && buf[k] != '\n' && buf[k] != '\r'; ++k)
             {
-              fprintf(stderr, "%c", isprint(buf[k]) ? buf[k] : '.');
-            }
-            fprintf(stderr, "\n");
+              RTCM3Error("%c", isprint(buf[k]) ? buf[k] : '.');
+            }
+            RTCM3Error("\n");
             exit(1);
           }
@@ -992,5 +1373,5 @@
           int z;
           for(z = 0; z < numbytes && !stop; ++z)
-            HandleByte(&Parser, buf[z]);
+            HandleByte(&Parser, (unsigned int) buf[z]);
         }
       }
Index: trunk/BNC/RTCM3/rtcm3torinex.h
===================================================================
--- trunk/BNC/RTCM3/rtcm3torinex.h	(revision 319)
+++ trunk/BNC/RTCM3/rtcm3torinex.h	(revision 320)
@@ -4,5 +4,5 @@
 /*
   Converter for RTCM3 data to RINEX.
-  $Id: rtcm3torinex.h,v 1.1 2006/11/02 13:34:00 stoecker Exp $
+  $Id: rtcm3torinex.h,v 1.3 2006/11/15 12:31:31 stoecker Exp $
   Copyright (C) 2005-2006 by Dirk Stoecker <stoecker@euronik.eu>
 
@@ -27,4 +27,6 @@
 #define PRN_GLONASS_START         38
 #define PRN_GLONASS_END           61
+#define PRN_WAAS_START            120
+#define PRN_WAAS_END              138
 
 #define GNSSENTRY_C1DATA     0
@@ -77,9 +79,18 @@
 #define RINEXENTRY_NUMBER     10
 
-#define LIGHTSPEED         2.99792458e8    /* m/sec                                           */
+#define LIGHTSPEED         2.99792458e8    /* m/sec */
 #define GPS_FREQU_L1       1575420000.0  /* Hz */
 #define GPS_FREQU_L2       1227600000.0  /* Hz */
 #define GPS_WAVELENGTH_L1  (LIGHTSPEED / GPS_FREQU_L1) /* m */
 #define GPS_WAVELENGTH_L2  (LIGHTSPEED / GPS_FREQU_L2) /* m */
+
+#define GLO_FREQU_L1_BASE  1602000000.0  /* Hz */
+#define GLO_FREQU_L2_BASE  1246000000.0  /* Hz */
+#define GLO_FREQU_L1_STEP      562500.0  /* Hz */
+#define GLO_FREQU_L2_STEP      437500.0  /* Hz */
+#define GLO_FREQU_L1(a)      (GLO_FREQU_L1_BASE+(a)*GLO_FREQU_L1_STEP)
+#define GLO_FREQU_L2(a)      (GLO_FREQU_L2_BASE+(a)*GLO_FREQU_L2_STEP)
+#define GLO_WAVELENGTH_L1(a) (LIGHTSPEED / GLO_FREQU_L1(a)) /* m */
+#define GLO_WAVELENGTH_L2(a) (LIGHTSPEED / GLO_FREQU_L2(a)) /* m */
 
 /* unimportant, only for approx. time needed */
@@ -110,4 +121,5 @@
   int    GPSTOW;        /* in seconds */
   struct gnssdata Data;
+  struct gnssdata DataNew;
   int    size;
   int    lastlockl1[64];
@@ -118,20 +130,21 @@
   int    validwarning;
   int    init;
+  int    startflags;
   const char * headerfile;
 };
 
-struct converttimeinfo {
-  int second;    /* seconds of GPS time [0..59] */
-  int minute;    /* minutes of GPS time [0..59] */
-  int hour;      /* hour of GPS time [0..24] */
-  int day;       /* day of GPS time [1..28..30(31)*/
-  int month;     /* month of GPS time [1..12]*/
-  int year;      /* year of GPS time [1980..] */
-};
+#ifndef PRINTFARG
+#ifdef __GNUC__
+#define PRINTFARG(a,b) __attribute__ ((format(printf, a, b)))
+#else /* __GNUC__ */
+#define PRINTFARG(a,b)
+#endif /* __GNUC__ */
+#endif /* PRINTFARG */
 
 void HandleHeader(struct RTCM3ParserData *Parser);
 int RTCM3Parser(struct RTCM3ParserData *handle);
 void HandleByte(struct RTCM3ParserData *Parser, unsigned int byte);
-void converttime(struct converttimeinfo *c, int week, int tow);
+void PRINTFARG(1,2) RTCM3Error(const char *fmt, ...);
+void PRINTFARG(1,2) RTCM3Text(const char *fmt, ...);
 
 #endif /* RTCM3TORINEX_H */
