Example #1
0
static void
garmin_txt_read(void)
{
    char *buff;

    current_line = 0;

    while ((buff = gbfgetstr(fin))) {
        char *cin;

        if ((current_line++ == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1);

        cin = lrtrim(buff);
        if (*cin == '\0') continue;

        cin = csv_lineparse(cin, "\t", "", 0);

        if (cin == NULL) continue;

        if (case_ignore_strcmp(cin, "Header") == 0) parse_header();
        else if (case_ignore_strcmp(cin, "Grid") == 0) parse_grid();
        else if (case_ignore_strcmp(cin, "Datum") == 0) parse_datum();
        else if (case_ignore_strcmp(cin, "Waypoint") == 0) parse_waypoint();
        else if (case_ignore_strcmp(cin, "Route Waypoint") == 0) parse_route_waypoint();
        else if (case_ignore_strcmp(cin, "Trackpoint") == 0) parse_track_waypoint();
        else if (case_ignore_strcmp(cin, "Route") == 0) parse_route_header();
        else if (case_ignore_strcmp(cin, "Track") == 0) parse_track_header();
        else if (case_ignore_strcmp(cin, "Map") == 0) /* do nothing */ ;
        else
            fatal(MYNAME ": Unknwon identifier (%s) at line %d!\n", cin, current_line);

        /* flush pending data */
        while (csv_lineparse(NULL, "\t", "", 0));
    }
}
Example #2
0
static void
unicsv_rd_init(const char *fname)
{
	char *c;
	unicsv_altscale = 1.0;
	unicsv_depthscale = 1.0;
	unicsv_proximityscale = 1.0;

	unicsv_fields_tab = NULL;
	unicsv_fields_tab_ct = 0;
	unicsv_data_type = global_opts.objective;
	unicsv_detect = (! (global_opts.masked_objective & (WPTDATAMASK | TRKDATAMASK | RTEDATAMASK | POSNDATAMASK)));

	unicsv_track = unicsv_route = NULL;
	unicsv_datum_idx = gt_lookup_datum_index(opt_datum, MYNAME);

	fin = gbfopen(fname, "rb", MYNAME);

	if ((c = gbfgetstr(fin)))
		unicsv_fondle_header(c);
	else
		unicsv_fieldsep = NULL;
	if (fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1);
}
Example #3
0
static void
nmn4_read_data(void)
{
	char *buff;
	char *str, *c;
	int column;
	int line = 0;

	char *zip1, *zip2, *city, *street, *number;	
	route_head *route;
	waypoint *wpt;
	
	route = route_head_alloc();
	route_add_head(route);
	
	while ((buff = gbfgetstr(fin)))
	{
		if ((line++ == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1);
		str = buff = lrtrim(buff);
		if (*buff == '\0') continue;
		
		nmn4_check_line(buff);

		/* for a quiet compiler */
		zip1 = zip2 = city = street = number = NULL;
	    
	    	wpt = waypt_new();
	    
	    	column = -1;
	    	c = csv_lineparse(str, "|", "", column++);
	    	while (c != NULL)
	    	{
			switch(column)
			{
		    		case  0: /* "-" */	/* unknown fields for the moment */
		    		case  1: /* "-" */
		    		case  2: /* "-" */
		    		case  3: /* "-" */
		    		case  9: /* "-" */
		    		case 10: /* "-" */
		    		case 13: /* "-" */
		    		case 14: /* "-" */
				case 15: /* "" */
					break;
		    
		    		case  4: 				/* ZIP Code */
					if (*c != '-') 
						zip1 = xstrdup(c);
					else
						zip1 = xstrdup("");
					break;
			
		    		case  5: 				/* City */
					if (*c != '-')
						city = xstrdup(c); 
					else
						city = xstrdup("");
					break;
			
		    		case  6: 				/* ZIP Code -2- */
					if (*c != '-') 
						zip2 = xstrdup(c); 
					else
						zip2 = xstrdup("");	
					break;
					
				case  7: 				/* Street */
					if (*c != '-')
						street = xstrdup(c); 
					else
						street = xstrdup("");
					break;
					
				case  8: 				/* Number */
					if (*c != '-')
						number = xstrdup(c); 
					else
						number = xstrdup("");

				/* 
			    	   This is our final index
				   All stuff for generating names or comments
				   is hold locally.
				   
				   We don't have fields for street, city or zip-code.
				   Instead we construct a description from that.
				*/
			
					if (strcmp(zip1, zip2) == 0) *zip2 = '\0';
					if (*city != '\0')
					{
			    			/* 
						   if any field following city has a value, add a comma to city 
						*/
			    			if ((*street != '\0') || (*number != '\0') || (*zip2 != '\0'))
							city = xstrappend(city, ",");
					}
										
					/* concats all fields to one string and release */
					wpt->description = nmn4_concat(zip1, city, street, number, zip2, NULL);
					break;
			
		    		case 11: 				/* longitude */
					sscanf(c, "%lf", &wpt->longitude);
					break;
			
				case 12: 				/* latitude */
					sscanf(c, "%lf", &wpt->latitude);
					break;
			
			}
			c = csv_lineparse(NULL, "|", "", column++);
		}
		route_add_wpt(route, wpt);
	}
}
Example #4
0
static void
compegps_data_read(void)
{
	char *buff;
	int line = 0;
	int input_datum;
	waypoint *wpt = NULL;
	route_head *route = NULL;
	route_head *track = NULL;
	
	while ((buff = gbfgetstr(fin)))
	{
		char *cin = buff;
		char *ctail;
		
		if ((line++ == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1);
		cin = lrtrim(buff);
		if (strlen(cin) == 0) continue;
		
		ctail = strchr(cin, ' ');
		if (ctail == NULL) continue;
		ctail = lrtrim(ctail);
		
		switch(*cin)
		{
			case 'G':
				input_datum = GPS_Lookup_Datum_Index(ctail);
				if (input_datum < 0) {
					fatal( MYNAME ": Unsupported datum \"%s\"!", ctail);
				}
				break;
			case 'U':
				switch(*ctail)
				{
					case '1': /* lat/lon, that's we want to see */ 
						break;
					case '0': /* UTM not supported yet */
						fatal(MYNAME "Sorry, UTM is not supported yet!\n");
					default:
						fatal(MYNAME "Invalid system of coordinates (%s)!\n", cin);
				}
				break;
			case 'R':
				route = route_head_alloc();
				route_add_head(route);
				parse_rte_info(ctail, route);
				break;
			case 'M':
				break;
			case 'W':
				wpt = parse_wpt(ctail);
				if (wpt != NULL)
				{
					if (route != NULL)
						route_add_wpt(route, wpt);
					else
						waypt_add(wpt);
				}
				break;
			case 'w':
				is_fatal((wpt == NULL), MYNAME ": No waypoint data before \"%s\"!", cin);
				parse_wpt_info(ctail, wpt);
				break;
			case 'T': 
				wpt = parse_trkpt(ctail);
				if (wpt != NULL)
				{
					if (track == NULL)
					{
						track = route_head_alloc();
						track_add_head(track);
					}
					track_add_wpt(track, wpt);
				}
				break;
			case 't':
				if (track != NULL)
					parse_track_info(ctail, track);
				break;
		}
	}
}
Example #5
0
static void 
data_read(void)
{
    char *buff;
    char *s;
    char *holder;
    waypoint *wpt_tmp;
    int i;
    int linecount = 0;
    
    while ((buff = gbfgetstr(file_in))) {
        if ((linecount++ == 0) && file_in->unicode) cet_convert_init(CET_CHARSET_UTF8, 1);

	/* skip the line if it contains "sHyperLink" as it is a header (I hope :) */
	if ((strlen(buff)) && (strstr(buff, "sHyperLink") == NULL)) {

	    wpt_tmp = waypt_new();

	    /* data delimited by tabs, not enclosed in quotes.  */
	    s = buff;
	    s = csv_lineparse(s, "\t", "", linecount);
	    
	    i = 0;
	    while (s) {
		switch (i) {
		
		/* Group sID sDescription fLat fLong fEasting fNorthing fAlt iColour iSymbol sHyperLink */
		/*   0    1       2         3    4      5         6       7    8       9       10       */
		
		case 0:
			 /* ignore: group  */
			 break;
		case 1:
		    wpt_tmp->shortname = csv_stringtrim(s, "", 0);
		    break;
		case 2:
			/* Description is not a TopoMapPro format requirement.
			   If we assign "" then .loc/.gpx will generate empty XML tags :(
			*/
			holder = csv_stringtrim(s, "", 0);
			if (strlen(holder))
				wpt_tmp->description = holder;
			else 
				xfree(holder);
		    break;
		case 3:
		    wpt_tmp->latitude = atof(s);
		    break;
		case 4:
		    wpt_tmp->longitude = atof(s);
		    break;
		case 5:
			/* ignore: NZMapGrid Easting  */
			 break;
		case 6:
			/* ignore: NZMapGrid Northing  */
			 break;
		case 7:
			wpt_tmp->altitude = atof(s);
		    break;
		case 8:
		    /* ignore: color  */
		    break;
		case 9:
		    /* ignore: symbol (non standard) */
		    break;
		case 10:
			/* URL is not a TopoMapPro format requirement.
			   You can store file links etc, we will discard anything that is not http
			   (as URLs in TMPro must start "http:") as other GPS formats probably can't 
			   use the TopoMapLinks links.
			   (plus discards length 0 strings (so no empty XML tags))
			*/
			holder = csv_stringtrim(s, "", 0);
			if (strstr(holder, "http:") != NULL)
				wpt_tmp->url = holder;
			else 
				xfree(holder);
			break;
		default:
		    /* whoa! nelly */
		    warning(MYNAME ": Warning: data fields on line %d exceed specification.\n", 
		        linecount);
		    break;
		}
		i++;

		s = csv_lineparse(NULL, "\t", "\"", linecount);
	    }
	    
	    if (i != 11) {
   	        xfree(wpt_tmp);
	        warning(MYNAME ": WARNING - extracted %d fields from line %d. \nData on line ignored.\n", 
	            i, linecount);
	    } else {
   	        waypt_add(wpt_tmp);
   	    }

	} else {
            /* empty line */
	}

    }
}
Example #6
0
static void
gopal_read(void)
{

	char *buff;
	char *str, *c;
	int column;
	long line;
	double hmsd,speed;
	int fix, hms;
	route_head *route;
	waypoint *wpt, *lastwpt=NULL;
	double long_old,lat_old;
	char tbuffer[64];
	long_old=0;lat_old=0;
	strftime(routename,sizeof(routename),"Tracklog %c",localtime(&tx));
	
	route = route_head_alloc();
	route->rte_name=xstrdup(routename);
	route_add_head(route);

	line=0;
	while ((buff = gbfgetstr(fin)))
	{
		if ((line == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1);

		str = buff = lrtrim(buff);
		if (*buff == '\0') continue;	
		if (gopal_check_line(buff)!=8)continue;
		wpt = waypt_new();
		
		column = -1;
		// the format of gopal is quite simple. Unfortunately the developers forgot the date as the first element...
		//TICK;    TIME;   LONG;     LAT;       HEIGHT; SPEED;  Fix; HDOP;    SAT
		//3801444, 080558, 2.944362, 43.262117, 295.28, 0.12964, 2, 2.900000, 3 
		c = csv_lineparse(str, ",", "", column++);
		while (c != NULL)
		{
			switch(column)
			{
			case  0: /* "-" */	/* unknown fields for the moment */
				//sscanf(c, "%llu", &wpt->microseconds);
				break;
			case  1:				/* Time UTC */	
				sscanf(c,"%lf",&hmsd);
				hms = (int) hmsd;
				tm.tm_sec = hms % 100;
				hms = hms / 100;
				tm.tm_min = hms % 100;
				hms = hms / 100;
				tm.tm_hour = hms % 100;  
				tm.tm_year=trackdate.tm_year;
				tm.tm_mon=trackdate.tm_mon;
				tm.tm_mday=trackdate.tm_mday;
				wpt->creation_time = tx+((((time_t)tm.tm_hour * 60) + tm.tm_min) * 60) + tm.tm_sec;
				if (global_opts.debug_level > 1){
					strftime(tbuffer, sizeof(tbuffer), "%c", gmtime(&wpt->creation_time));
					printf("parsed timestamp: %s\n",tbuffer);	
				}				
				break;
				
			case  2: 				/* longitude */
				sscanf(c, "%lf", &wpt->longitude);
				break;
				
			case  3: 				/* latitude */
				sscanf(c, "%lf", &wpt->latitude);
				break;
			case  4: 				/* altitude */
				sscanf(c, "%lf", &wpt->altitude);
				break;
			case  5: 				/* speed */
				//sscanf(c, "%lf", &wpt->speed);
				wpt->speed=atof(c);
				if (global_opts.debug_level > 1){
					printf("parsed speed: %8.5f\n",wpt->speed);	
				}
				break;
			case  6: 				/* type of fix */
				sscanf(c, "%d", &fix);
				//my device shows only 0 or 2
				//should i guess from no of sats if 2d or 3d?
				switch (fix) {
				case 0: wpt->fix = fix_none;break;
				case 2: wpt->fix = fix_2d;break;
					//case 3: wpt->fix = fix_3d;break;
					//case 4: wpt->fix = fix_dgps;break; /* 2D_diff */
					//case 5: wpt->fix = fix_dgps;break; /* 3D_diff */
				default:
					wpt->fix = fix_unknown;
					break;
				}
				break;
			case  7: 				/* hdop */
				wpt->hdop = atof(c);
				//sscanf(c, "%lf", &wpt->hdop); does not work ???
				//wpt->vdop=0;wpt->hdop=0;
				break;
			case  8: 				/* number of sats */
				sscanf(c, "%d", &wpt->sat);
				break;
				
			}
			c = csv_lineparse(NULL, ",", "", column++);
		}
		line++;
		
		if ((wpt->fix != fix_none)&&(lat_old==0)){ //first-time init
			lat_old=wpt->latitude;
			long_old=wpt->longitude;
			//route_add_wpt(route, wpt);
			lastwpt=wpt;
		}
		//calculate the speed to reach this waypoint from the last. This way I try to sort out invalid waypoints
		speed=0;	
		if (lastwpt !=NULL)
		{
			speed=3.6*radtometers(gcdist(RAD(lastwpt->latitude), RAD(lastwpt->longitude), RAD(wpt->latitude), RAD(wpt->longitude))) / abs(wpt->creation_time - lastwpt->creation_time);	
			//printf("speed line %d %lf \n",line,speed);			
		}
		/* Error handling: in the tracklog of my device sometimes "jump" waypoints ;-) */
		if	((optclean) && 
		(((wpt->longitude==0.0)|| (wpt->latitude==0.0)||(abs(wpt->latitude)>90)||(abs(wpt->longitude)>180))||
		((speed>maxspeed)||(speed<minspeed)))
		)
		{
			if (global_opts.debug_level > 1) fprintf(stderr,"Problem in or around line %5lu: \"%s\" %lf km/h\n",line,buff,speed);
		}
		else
		{
			if (global_opts.debug_level > 1) fprintf(stderr,"valid                line %5lu: \"%s\" %lf km/h\n",line,buff,speed);
			lastwpt=wpt;
			long_old=wpt->longitude;
			lat_old=wpt->latitude;
			route_add_wpt(route,wpt);
			waypt_add(waypt_dupe( wpt));
		}
	}
}