Пример #1
0
int main(int argc, char *argv[]){
	options opts;
	opts.n_arrows = 100;
	opts.kmeans_attempts = 1;
	opts.use_all_vectors = 0;
	
	int c, i;
	opterr = 0;
	while((c = getopt(argc, argv, "ak:n:")) != -1){
		switch(c){
		case 'a':
			opts.use_all_vectors = 1;
			break;
		case 'k':
			opts.kmeans_attempts = atoi(optarg);
			if(opts.kmeans_attempts < 1){
				opts.kmeans_attempts = 1;
			}
			break;
		case 'n':
			opts.n_arrows = atoi(optarg);
			if(opts.n_arrows < 1){
				opts.n_arrows = 1;
			}
			break;
		case '?':
			if('k' == optopt || 'n' == optopt){
				fprintf(stderr, "Option -%c requires an argument.\n", optopt);
			}else if(isprint(optopt)){
				fprintf(stderr, "Unknown option `-%c'.\n", optopt);
			}else{
				fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
			}
		default:
			usage();
			return EXIT_FAILURE;
		}
	}
	
	if(optind >= argc){ usage(); return EXIT_FAILURE; }
	for(i = optind; i < argc; i++){
		data d;
		data_init(&d);
		data_read(&d, argv[i]);
		
		if(opts.use_all_vectors || d.n <= opts.n_arrows || data_cull_zeros(&d, opts.n_arrows)){
			output_plot(&d);
		}else{
			data plot_data;
			data_init(&plot_data);
			gen_plot_kmeans(&d, opts.n_arrows, &plot_data, opts.kmeans_attempts);
			output_plot(&plot_data);
			data_destroy(&plot_data);
		}
		
		data_destroy(&d);
	}
	
	return EXIT_SUCCESS;
}
Пример #2
0
	std::basic_ostream<Elem, Traits>& output_plot(std::string const& filename, InputRange const& range) {
		std::ofstream os(filename);
		output_plot(os, range);
	}