Index: /trunk/rtcm3torinex/rtcm3torinex.c
===================================================================
--- /trunk/rtcm3torinex/rtcm3torinex.c	(revision 317)
+++ /trunk/rtcm3torinex/rtcm3torinex.c	(revision 318)
@@ -1,5 +1,5 @@
 /*
   Converter for RTCM3 data to RINEX.
-  $Id: rtcm3torinex.c,v 1.8 2006/11/03 11:50:11 stoecker Exp $
+  $Id: rtcm3torinex.c,v 1.9 2006/11/08 17:11:08 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.8 $";
+static char revisionstr[] = "$Revision: 1.9 $";
 
 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;
 
@@ -638,4 +639,23 @@
 }
 
+#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)
 {
@@ -643,5 +663,5 @@
   char thebuffer[MAXHEADERBUFFERSIZE];
   char *buffer = thebuffer;
-  int buffersize = sizeof(thebuffer);
+  size_t buffersize = sizeof(thebuffer);
   int i;
 
@@ -721,5 +741,5 @@
     }
 
-    int flags = 0;
+    int flags = Parser->startflags;
     int data[RINEXENTRY_NUMBER];
     char tbuffer[6*RINEXENTRY_NUMBER+1];
@@ -778,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)
@@ -785,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);
         }
@@ -792,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')
@@ -803,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
             {
@@ -819,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);
                 }
@@ -825,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
@@ -846,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);
       }
@@ -853,5 +872,5 @@
     else
     {
-      fprintf(stderr, "Could not open header datafile '%s'.\n",
+      RTCM3Error("Could not open header datafile '%s'.\n",
       Parser->headerfile);
     }
@@ -860,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
@@ -877,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;
@@ -891,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);
@@ -897,31 +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)
-            printf("S%02d", Parser->Data.satellites[i] - PRN_WAAS_START);
+            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;
@@ -935,5 +962,5 @@
           || isinf(Parser->Data.measdata[i][Parser->datapos[j]]))
           { /* no or illegal data */
-            printf("                ");
+            RTCM3Text("                ");
           }
           else
@@ -953,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");
         }
       }
@@ -965,5 +992,5 @@
 
 #ifndef NO_RTCM3_MAIN
-static char datestr[]     = "$Date: 2006/11/03 11:50:11 $";
+static char datestr[]     = "$Date: 2006/11/08 17:11:08 $";
 
 /* The string, which is send as agent in HTTP request */
@@ -1161,5 +1188,5 @@
         if((err = geturl(optarg, args)))
         {
-          fprintf(stderr, "%s\n\n", err);
+          RTCM3Error("%s\n\n", err);
           res = 0;
         }
@@ -1183,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"
@@ -1202,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;
@@ -1217,5 +1244,5 @@
 #endif /* __GNUC__ */
 {
-  fprintf(stderr, "Programm forcefully terminated.\n");
+  RTCM3Error("Programm forcefully terminated.\n");
   exit(1);
 }
@@ -1306,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);
       }
@@ -1312,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);
       }
@@ -1332,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);
           }
@@ -1346,5 +1373,5 @@
           int z;
           for(z = 0; z < numbytes && !stop; ++z)
-            HandleByte(&Parser, buf[z]);
+            HandleByte(&Parser, (unsigned int) buf[z]);
         }
       }
Index: /trunk/rtcm3torinex/rtcm3torinex.h
===================================================================
--- /trunk/rtcm3torinex/rtcm3torinex.h	(revision 317)
+++ /trunk/rtcm3torinex/rtcm3torinex.h	(revision 318)
@@ -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.2 2006/11/03 11:50:11 stoecker Exp $
   Copyright (C) 2005-2006 by Dirk Stoecker <stoecker@euronik.eu>
 
@@ -130,10 +130,21 @@
   int    validwarning;
   int    init;
+  int    startflags;
   const char * headerfile;
 };
+
+#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 PRINTFARG(1,2) RTCM3Error(const char *fmt, ...);
+void PRINTFARG(1,2) RTCM3Text(const char *fmt, ...);
 
 #endif /* RTCM3TORINEX_H */
Index: /trunk/rtcm3torinex/rtcm3torinex.txt
===================================================================
--- /trunk/rtcm3torinex/rtcm3torinex.txt	(revision 317)
+++ /trunk/rtcm3torinex/rtcm3torinex.txt	(revision 318)
@@ -2,6 +2,35 @@
 
 The program rtcm3torinex is an real-time converter from NTRIP streamed RTCM3
-data into the RINEX format. The generated RINEX is somewhat limited due to
-the streaming character of the conversion:
+data into the RINEX format.
+
+RTCM3 defines a number of message types. Among them are the following:
+
+Message
+Type  Contains information about
+--------------------------------------------------------------------------
+1001  GPS L1 code and phase
+1002  GPS L1 code and phase and ambiguities and carrier to noise ratio
+1003  GPS L1 and L1 code and phase
+1004  GPS L1 and L2 code and phase and ambiguities and carrier to noise ratio
+1005  Station coordinates XZY for antenna reference point
+1006  Station coordinates XYZ for antenna reference point and antenna height
+1007  Antenna descriptor and ID
+1008  Antenna serial number
+1009  GLONASS L1 code and phase
+1010  GLONASS L1 code and phase and ambiguities and carrier to noise ratio
+1011  GLONASS L1 and L1 code and phase
+1012  GLONASS L1 and L2 code and phase and ambiguities and carrier to noise ratio
+1013  Modified julian date, leep second, configured message types and intervall
+1014-1017 Network RTK (MAK) messages (under development)
+1019  GPS Ephemeris (under development)
+1020  GLONASS Ephemeris (under development)
+4088-4095 Proprietary messages (under development)
+
+Note that this version of rtcm3torinex only handles RTCM3 message types 1001,
+1002, 1003, 1004, 1009, 1010, 1011 and 1012.
+
+The generated RINEX is somewhat limited due to the streaming character of the
+conversion:
+
  - Header records can only represent data, which is known after receiving the
    very first epoch. Data rate, position, number of observations and any such
@@ -10,5 +39,5 @@
    the observables, which exist in the first epoch are outputted. If there
    are new observables later on, these are ignored.
- - Only known data types are interpreted. This means only GPS data at the
+ - Only known message types are interpreted. This means only GPS data at the
    moment. Send me new RTCM3 data files and data support can be improved.
    See contact address at the end of this document.
@@ -32,4 +61,8 @@
 must be used to specify the RTCM3 input data stream. If it is not given, you
 will be shown the source table of the selected NTRIP caster.
+
+Alternatively a single text of the form
+"ntrip:mountpoint[/username[:password]][@server[:port]]"
+can be used. Everything in brackets is optional.
 
 Additionally the argument --headerfile can be used to provide additional header
@@ -56,9 +89,26 @@
 You will not get corrupted RINEX files.
 
-Contact me with your comments, suggestions, improvements, patches, ...
+When compiling the program with older gcc versions running the `make'
+command, you may receive an informative error message saying
 
-Dirk Stöcker
-EuroNav Service GmbH
-http://www.euronav.de/
-stoecker@euronav.de
-2006-01-12
+rtcm3torinex.c: In function `signalhandler_alarm':
+rtcm3torinex.c:1240: warning: `noreturn' function does return
+
+This is most likely a compiler problem which only concerns the optimization
+and is thus not critical. New compilers will not show this problem.
+
+Program written by
+
+Dirk Stoecker
+Euronik GmbH
+http://www.euronik.eu/
+
+for
+
+Federal Agency for Cartography and Geodesy (BKG)
+Richard-Strauss-Allee 11
+D-60598 Frankfurt
+http://igs.bkg.bund.de/index_ntrip.htm
+
+Contact Dirk Stoecker [stoecker@euronik.eu] or [euref-ip@bkg.bund.de]
+with your comments, suggestions, improvements, patches, ...
