Beispiel #1
0
/* ---------------- *
 * Public interface *
 * ---------------- */
TzDB *
tz_load_db (void)
{
	gchar *tz_data_file;
	TzDB *tz_db;
	FILE *tzfile;
	char buf[4096];

	tz_data_file = tz_data_file_get ();
	if (!tz_data_file) {
		g_warning ("Could not get the TimeZone data file name");
		return NULL;
	}
	tzfile = fopen (tz_data_file, "r");
	if (!tzfile) {
		g_warning ("Could not open *%s*\n", tz_data_file);
		g_free (tz_data_file);
		return NULL;
	}

	tz_db = g_new0 (TzDB, 1);
	tz_db->locations = g_ptr_array_new ();

	while (fgets (buf, sizeof(buf), tzfile))
	{
		gchar **tmpstrarr;
		gchar *latstr, *lngstr, *p;
		TzLocation *loc;

		if (*buf == '#') continue;

		g_strchomp(buf);
		tmpstrarr = g_strsplit(buf,"\t", 6);
		
		latstr = g_strdup (tmpstrarr[1]);
		p = latstr + 1;
		while (*p != '-' && *p != '+') p++;
		lngstr = g_strdup (p);
		*p = '\0';
		
		loc = g_new0 (TzLocation, 1);
		loc->country = g_strdup (tmpstrarr[0]);
		loc->zone = g_strdup (tmpstrarr[2]);
		loc->latitude  = convert_pos (latstr, 2);
		loc->longitude = convert_pos (lngstr, 3);
		
#ifdef __sun
		if (tmpstrarr[3] && *tmpstrarr[3] == '-' && tmpstrarr[4])
			loc->comment = g_strdup (tmpstrarr[4]);

		if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) {
			TzLocation *locgrp;

			/* duplicate entry */
			locgrp = g_new0 (TzLocation, 1);
			locgrp->country = g_strdup (tmpstrarr[0]);
			locgrp->zone = g_strdup (tmpstrarr[3]);
			locgrp->latitude  = convert_pos (latstr, 2);
			locgrp->longitude = convert_pos (lngstr, 3);
			locgrp->comment = (tmpstrarr[4]) ? g_strdup (tmpstrarr[4]) : NULL;

			g_ptr_array_add (tz_db->locations, (gpointer) locgrp);
		}
#else
		loc->comment = (tmpstrarr[3]) ? g_strdup(tmpstrarr[3]) : NULL;
#endif

		g_ptr_array_add (tz_db->locations, (gpointer) loc);

		g_free (latstr);
		g_free (lngstr);
		g_strfreev (tmpstrarr);
	}
	
	fclose (tzfile);
	
	/* now sort by country */
	sort_locations_by_country (tz_db->locations);
	
	g_free (tz_data_file);

	/* Load up the hashtable of backward links */
	load_backward_tz (tz_db);

	return tz_db;
}
Beispiel #2
0
int main()
{
  QFile in_file("Flugplätze.csv");

  QString line, name, short_name, description, temp, type_name, rwy_surface_name, icao, frequency;
  bool newobject = false;
  int type, elevation, country,
    rwy_landable, rwy_length, rwy_direc, rwy_surface, rwy_bidirectional, lat, lon;
  int points = 0;
  int ignore_c = 0;

  unsigned int count = 0;
  
  if(!in_file.open(IO_ReadOnly)) 
    {
      //      warning("KFLog: Can not open file %s", file);
      return false;
    }

  QTextStream in(&in_file);

  QList<QString> neu;

  while(!in.eof()) 
    {
      line = in.readLine();
      neu = split_string(line);

      // Felder
      name = *neu.at(0);
      short_name = *neu.at(1);
      description = *neu.at(2);

      lat  = convert_pos(*neu.at(3));
      lon = convert_pos(*neu.at(4));

      elevation = neu.at(5)->toInt();

      type = neu.at(6)->toInt();
      type_name = *neu.at(7);

      country = neu.at(8)->toInt();

      icao = *neu.at(9);

      frequency = *neu.at(10);

      rwy_landable = neu.at(11)->toInt();
      rwy_length = neu.at(12)->toInt();
      rwy_direc = neu.at(13)->toInt();
      rwy_surface = neu.at(14)->toInt();
      rwy_surface_name = *neu.at(15);
      rwy_bidirectional = neu.at(16)->toInt();

      // Ausgeben
      switch (type)
	{
	case 1024:
	  // Flughafen
	  type = 2;
	  break;
	case 1792:
	  // Segelfluggelände
	  type = 10;
	  break;
	case 256:
	  // Internationaler Flughafen
	  type = 1;
	  break;
	case 2816:
	  // Außenlandefeld
	  type = 15;
	  break;
	case 512:
	  // mil. Flugplatz
	  type = 3;
	  break;
	case 768:
	  // Sonderlandeplatz
	  type = 5;
	  break;
	}



      switch (country)
	{
	case 1060:
	  // Deutschland
	  break;
	}

      switch (rwy_surface)
	{
	case 0:
	  // Beton
	  break;
	case 1:
	  // Asphalt
	  break;
	case 3:
	  // Gras
	  break;
	case 4:
	  // sonstiger Belag
	  break;
	case 5:
	  // unbekannt
	  break;
	}


      // Ausgabe
      cout << "[NEW]"      << endl;
      cout << "TYPE="      << type       << endl;
      cout << "ALIAS="     << icao       << endl;
      cout << "ABBREV="    << short_name << endl;
      cout << "AT"         << " " << lat << " " << lon << endl;
      cout << "ELEVATION=" << elevation << endl;
      cout << "FREQUENCY=" << frequency << endl;
      cout << "NAME="      << name << endl;
      cout << "RUNWAY" << " " << rwy_direc
               	       << " " << rwy_length
	               << " " << rwy_surface << endl;
      cout << "[END]" << endl;


      
    }
      /*
	  x = 0;
	  int elev = -1;
	  int id = -1;

	  newobject = true;
	  
	  type = neu.at(1)->toInt();
	  points = neu.at(2)->toInt();
	  name = *neu.at(3);


	  switch(type)
	    {
	    case 1:
	      // Luftraum D + F (CTR und nicht)
	      type = 24;
	      break;
	    case 2:
	      // Flugbeschränkungsgebiet (R)
	      type = 32;
	      break;
	    case 3:
	      // Sperrgebiet (P)
	      type = 32;
	      break;
	    case 4:
	      // Gefahrengebiet (D)
	      type = 30;
	      break;
	    case 5:
	      // Tieffluggebiet
	      type = 31;
	      break;
	    case 6:
	      // Luftraum C
	      type = 23;
	      break;
	    case 9:
	      // Kontrollbezirk
	      // wird von uns nicht verwendet
	      type = 100;
	      break;
	    default:
	      break;
	    }


	  //Höhen
	  temp = *neu.at(8);
	  get_elevation(*neu.at(8),&id,&elev);
	  low = elev;
	  low_id = id;
	  get_elevation(*neu.at(9),&id,&elev);
	  high = elev;
	  high_id = id;

	  if(low_id == 2 && low == 0 && type == 22)
	    {
	      // Kontrolzone
	      type = 29;
	    }
	  

	  if(type == 31 && low != 0)
	    {
	      	      cerr << temp << endl;
	      // cerr << "Ey we've got a real low flying area!!\n";
	      ignore_c++;
	    }
	  if((low_id == 3 && low >= 100) || type == 100)
	    {
	      newobject = false;

	      ignore_c++;

	      //	      cerr << "High Level Airspace!! Ignoring...     " << temp << "   " << ignore_c << endl;

	    }
	  else {
	    cout << "[NEW]\n";
	    cout << "TYPE=" << type << endl;

	    cout << "LOWER=" << low << endl;
	    cout << "LTYPE=" << low_id << endl;
	    cout << "UPPER=" << high << endl;
	    cout << "UTYPE=" << high_id << endl;
	    
	    cout << "NAME=" << name << endl;
	  }
	}
      else if(newobject)
	{
	  // nun Punkte einlesen
	  

	  x = neu.at(1)->toFloat() * 600000.0;
	  y = neu.at(2)->toFloat() * 600000.0;
	  /* if(y < 0)
	     {
	     y = 0;
	     }
	     if(x < 0)
	     {
	     x = 0;
	     }

	  //	  cout << y << ".00'00\"N" << " " << x << ".00'00\"E" << endl;
	  cout << y << " " << x << endl;
	  count++;
	  if(count == points)
	    {
	      x = 0;
	      y = 0;

	      newobject = false;
	      cout << "[END]\n";

	      count = 0;
	    }
	}
    }
  cerr << ignore_c << endl;

*/
}