Ejemplo n.º 1
0
vector<vector<string>> GBCsv::parseCsv(const string& csvPath)
{
	Data data = FILE()->getDataFromFile(csvPath);
	vector<vector<string>> v = parseCsv(data.getBytes(), data.getSize());
	data.clear();

	return v;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: PierreGts/SDA
int main(int argc, char** argv)
{
    // Parse command line input
    if (argc  != 6)
    {
        fprintf(stderr, "%s is expecting exactly five parameters: "
                        "(1) a .csv file containing the cities and their coordinates, "
                        "(2) the first latitude, (3) the first longitude, "
                        "(4) the second latitude and (5) the second longitude\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    char* fileName = argv[1];
    double latitudeA = strtod(argv[2], NULL);
    double longitudeA = strtod(argv[3], NULL);
    double latitudeB = strtod(argv[4], NULL);
    double longitudeB = strtod(argv[5], NULL);

    // Compute min/max latitude/longitude
    double latitudeMin = (latitudeA < latitudeB)? latitudeA: latitudeB;
    double latitudeMax = (latitudeA < latitudeB)? latitudeB: latitudeA;
    double longitudeMin = (longitudeA < longitudeB)? longitudeA: longitudeB;
    double longitudeMax = (longitudeA < longitudeB)? longitudeB: longitudeA;

    // Parse csv file
    LinkedList* cities = parseCsv(fileName);
    size_t nbCities = sizeOfLinkedList(cities);
    printf("Number of cities: %lu\n", nbCities);

    // Compute the cities in the box
    LinkedList* citiesInBox = findCities(cities, latitudeMin, latitudeMax,
                                         longitudeMin, longitudeMax);
    if(!citiesInBox)
    {
        fprintf(stderr, "Allocation error while finding the cities. Exiting...\n");
        exit(EXIT_FAILURE);
    }

    // Print stuff
    nbCities = sizeOfLinkedList(citiesInBox);
    printf("Number of cities after filtering: %lu\n", nbCities);
    if(nbCities <= 50)
    {
        LLNode* node = citiesInBox->head;
        City* city;
        while(node != NULL)
        {
            city = (City*)node->value;
            printf("%s (%f, %f)\n", city->name, city->latitude, city->longitude);
            node = node->next;
        }
    }

    // Free the linked list: the name must be freed beforehand
    freeLinkedList(citiesInBox, false);
    LLNode* node = cities->head;
    City* city;
    while(node != NULL)
    {
        city = (City*)node->value;
        free(city->name);
        node = node->next;
    }
    freeLinkedList(cities, true);

    exit(EXIT_SUCCESS);
}