#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/* 250610
NO determination of gps_offset
NO determination of mean lat/long

*/

/* globale Arbeitsvariablen */

#define MXSMP 70000000


void main(argc,argv)
int argc;
char **argv;
{  
  char 			*filename;
  FILE			*fp;
  unsigned char         byte, upper;
  int			i,j,dhc,fileno;
  char			help[1000],dheader[100][1000],hh[1000];


	if (argc!=2) { fprintf(stderr,"%s ERROR: one input file name needed\n",argv[0]); exit(200);}

	if ((fp=fopen(argv[1], "r"))==NULL) { fprintf(stderr,"%s ERROR: opening input file: %s\n",argv[0],argv[1]); exit(200); }
/* read start header */  
	help[0]='\0';
	for (j=0; j<100; j++) dheader[j][0]='\0';  
	dhc=0;
        byte=0;
/*        while (( byte != 128 ) && ( byte != 207 ) && ( byte != 192 ))    */
        while (( byte < 128 ) || ( byte==240 ))  
  	{
		fread(&byte,1,1,fp);
                if ((byte != 240) && (byte != 128) && ( byte != 207 ) && ( byte != 192 ))
		{
			if ( byte == 32 ) {byte=95;} /* replaces spaces by _ in entry */
			if ( byte == 61 ) {byte = 32;}
			if ( byte == 59 ) {byte = 32;}
			strncat(help,&byte,1);
			if ( byte == 32 ) 
			{		
				dhc++;	
			} else
			{
				strncat(dheader[dhc],&byte,1);
			}
			if (feof(fp)) { fprintf(stderr,"%s ERROR: no header/data in file %s\n",argv[0],argv[1]); exit(200);}
		}
  	}
	fileno=-1;
	for (j=0; j<=dhc/2; j++) if (!strcmp(dheader[2*j], "DAT_NO")) {strcpy(hh, dheader[2*j+1]); fileno=atoi(hh);}
	fprintf(stdout,"%d\n",fileno);

	fclose(fp);

/*  	for (j=0; j<=dhc/2; j++) {fprintf(stdout,"%d %s %s\n",j,dheader[2*j+0],dheader[2*j+1]);}*/

 }



