コード例 #1
0
ファイル: copilot.c プロジェクト: alexbirkett/GPSBabel
static waypoint*
read_version0(void *data)
{
  char *vdata;
  waypoint *wpt_tmp;
  struct record0* rec = (struct record0*)data;

  wpt_tmp = waypt_new();

  wpt_tmp->longitude =
	DEG(-pdb_read_double(&rec->longitude));
  wpt_tmp->latitude =
	DEG(pdb_read_double(&rec->latitude));
  wpt_tmp->altitude = FEET_TO_METERS(be_read32(&rec->elevation));

  vdata = (char *) data + sizeof(*rec);

  wpt_tmp->shortname = xstrdup(vdata);
  vdata = vdata + strlen(vdata) + 1;

  wpt_tmp->description = xstrdup(vdata);
  vdata = vdata + strlen(vdata) + 1;

  wpt_tmp->notes = NULL;

  return wpt_tmp;
}
コード例 #2
0
ファイル: unicsv.c プロジェクト: alexbirkett/GPSBabel
static void
unicsv_fondle_header(char *ibuf)
{
	char *s;
	char *buf = NULL;
	int i, column;
	const cet_cs_vec_t *ascii = &cet_cs_vec_ansi_x3_4_1968;	/* us-ascii */

	/* Convert the entire header to lower case for convenience.
	 * If we see a tab in that header, we decree it to be tabsep.
	 */
	unicsv_fieldsep = ",";
	for (s = ibuf; *s; s++) {
		if (*s == '\t') {
			unicsv_fieldsep = "\t";
		}
		else if (*s == ';') {
			unicsv_fieldsep = ";";
		}
		else if (*s == '|') {
			unicsv_fieldsep = "|";
		}
		else {
			continue;
		}
		break;
	}
	for (s = ibuf; *s; s++) {
		*s = tolower(*s);
	}

	/* convert the header line into native ascii */
	if (global_opts.charset != ascii) {
		buf = cet_str_any_to_any(ibuf, global_opts.charset, ascii);
		ibuf = buf;
	}

	column = -1;
	while ((s = csv_lineparse(ibuf, unicsv_fieldsep, "\"", 0))) {

		field_t *f = &fields_def[0];

		ibuf = NULL;
		column++;
		unicsv_fields_tab_ct++;
		s = lrtrim(s);

		if (column % 4 == 0) {
			int sz = (column + 4) * sizeof(*unicsv_fields_tab);
			if (column == 0) unicsv_fields_tab = (field_e*) xmalloc(sz);
			else unicsv_fields_tab = (field_e*) xrealloc(unicsv_fields_tab, sz);
			for (i = 0; i < 4; i++) unicsv_fields_tab[column + i] = fld_terminator;
		}

		while (f->name) {
			if (unicsv_compare_fields(s, f)) {
				unicsv_fields_tab[column] = f->type;
				break;
			}
			f++;
		}
		if ((! f->name) && global_opts.debug_level)
				warning(MYNAME ": Unhandled column \"%s\".\n", s);

		/* handle some special items */
		if (f->type == fld_altitude) {
			if (UNICSV_CONTAINS("ft") || UNICSV_CONTAINS("feet")) {
				unicsv_altscale = FEET_TO_METERS(1);
			}
		}
		if (f->type == fld_depth) {
			if (UNICSV_CONTAINS("ft") || UNICSV_CONTAINS("feet")) {
				unicsv_depthscale = FEET_TO_METERS(1);
			}
		}
		if (f->type == fld_proximity) {
			if (UNICSV_CONTAINS("ft") || UNICSV_CONTAINS("feet")) {
				unicsv_proximityscale = FEET_TO_METERS(1);
			}
		}
		if ((f->type == fld_time) || (f->type == fld_date)) {
			if (UNICSV_CONTAINS("iso"))
				f->type = fld_iso_time;
		}
	}
	if (buf) xfree(buf);
}
コード例 #3
0
ファイル: pathaway.c プロジェクト: alexbirkett/GPSBabel
static 
int ppdb_read_wpt(route_head *head, int isRoute)
{
	char *data, *str;
	double altfeet;
	struct tm tm;
	
	while (pdb_read_rec(file_in, NULL, NULL, NULL, (void *)&data) >= 0) {
		waypoint *wpt_tmp = waypt_new();
		int line = 0;
		char *tmp = data;

/* Print the whole input record. All input records are printed before processing. */
               if (global_opts.debug_level >= 5)
               {
                       DBG(("\n\
--- BEGIN Input data record -----------------------------------------------\n\
%s\n\
--- END Input data record -------------------------------------------------\n",data));
               }

		while ((str = csv_lineparse(tmp, ",", "\"", line++))) { 
		    tmp = NULL;
		    switch(line)
		    {
			case 1:		/* latitude */
			    wpt_tmp->latitude = ppdb_decode_coord(str);
			    break;
			case 2:		/* longitude */
			    wpt_tmp->longitude = ppdb_decode_coord(str);
			    break;
			case 3:		/* altitude */
			    if (*str != '\0')
			    {
				CHECK_INP(1, sscanf(str, "%lf", &altfeet), "altitude", str);
				if (altfeet != -9999) 
				    wpt_tmp->altitude = FEET_TO_METERS(altfeet);
			    }
			    break;
			case 4:		/* time and date (optional) */ 
			    memset(&tm, 0, sizeof(tm));
			    if (ppdb_decode_tm(str, &tm))
			    {
				tm.tm_year -= 1900;
				tm.tm_mon--;
				wpt_tmp->creation_time = mkgmtime(&tm);
			    }
			    break;
			case 5:		/* name */
			    if (*str != '\0')
				wpt_tmp->shortname = xstrdup(str);
			    break;
			case 6:		/* icon */
			    if (*str != '\0')
				wpt_tmp->icon_descr = xstrdup(str); 
	    			wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1;
			    break;
			case 7:		/* notes */
			    if (*str != '\0')
				wpt_tmp->notes = xstrdup(str);
			    break;
			    
		    }
		}
		
/* Print the whole input record, should a warning be triggered.
 * Use warning() here instead of DBG() to print the data record
 * right after the warning is issued.
 */
               if (warn_ && (global_opts.debug_level > 1) && (global_opts.debug_level < 5))
               {
                       warning("Faulty input data record : %s\n",data);
                       warn_ = 0;
               }

		if (head && isRoute )
		    route_add_wpt(head, wpt_tmp);
		else if (head)
                    track_add_wpt(head, wpt_tmp);
		else
		    waypt_add(wpt_tmp);

	} 
コード例 #4
0
static void
lowranceusr_parse_waypt(waypoint *wpt_tmp)
{
	char buff[MAXUSRSTRINGSIZE + 1];
	int text_len;
	time_t waypt_time;
	short waypt_type;

	wpt_tmp->latitude = lat_mm_to_deg(gbfgetint32(file_in));
	wpt_tmp->longitude = lon_mm_to_deg(gbfgetint32(file_in));
	wpt_tmp->altitude = FEET_TO_METERS(gbfgetint32(file_in));
	if (wpt_tmp->altitude <= UNKNOWN_USR_ALTITUDE) {
		wpt_tmp->altitude = unknown_alt;
	}

	text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
	if (text_len) {
		buff[text_len] = '\0';
		wpt_tmp->shortname = xstrdup(buff);
	}

	if (global_opts.debug_level >= 1)
		printf(MYNAME " parse_waypt: Waypt name = %s Lat = %f Lon = %f alt = %f\n",wpt_tmp->shortname, wpt_tmp->latitude,
			wpt_tmp->longitude, wpt_tmp->altitude);

	text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
	if (text_len) {
		buff[text_len] = '\0';
		wpt_tmp->description = xstrdup(buff);
	}
	/* Time is number of seconds since Jan. 1, 2000 */
	waypt_time = gbfgetint32(file_in);
	if (waypt_time)
		wpt_tmp->creation_time = base_time_secs + waypt_time;

	if (global_opts.debug_level >= 2)
	{
		printf(MYNAME " parse_waypt: creation time %d\n", 
			(int)wpt_tmp->creation_time);
		printf(MYNAME " parse_waypt: base_time %d\n", (int)base_time_secs);
		printf(MYNAME " parse_waypt: waypt time %d\n", (int)waypt_time);
	}

	/* Symbol ID */
	wpt_tmp->icon_descr = lowranceusr_find_desc_from_icon_number(gbfgetint32(file_in));
	if (!wpt_tmp->icon_descr[0]) {
		char nbuf[10];
		snprintf(nbuf, sizeof(nbuf), "%d", le_read32(buff));
		wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1;
		wpt_tmp->icon_descr = xstrdup(nbuf);
	}

	/* Waypoint Type (USER, TEMPORARY, POINT_OF_INTEREST) */
	waypt_type = gbfgetint16(file_in);
	if (global_opts.debug_level >= 1)
		printf(MYNAME " parse_waypt: waypt_type = %d\n",waypt_type);

        // Version 3 has a depth field here.
        if (reading_version >= 3) {
          float depth_feet = gbfgetflt(file_in);
          if (abs(depth_feet - 99999.0)  > .1)
            WAYPT_SET(wpt_tmp, depth, FEET_TO_METERS(depth_feet));
        }

}