dynamic_string get_command_line()
    {
        dynamic_string cmd_line;

#ifdef VOGL_USE_WIN32_API
        cmd_line.set(GetCommandLineA());
#else
        dynamic_string_array params(get_command_line_params());

        for (uint32_t i = 0; i < params.size(); i++)
        {
            dynamic_string tmp(params[i]);

            // If the param is not already quoted, and it has any whitespace, then quote it. (The goal here is to ensure the split_command_line_params() method,
            // which was unfortunately written for Windows where it's trivial to get the full unparsed cmd line as a string, doesn't split up this parameter.)
            if ((tmp.front() != '\"') && (tmp.contains(' ') || tmp.contains('\t')))
                tmp = "\"" + tmp + "\"";

            if (cmd_line.get_len())
                cmd_line += " ";

            cmd_line += tmp;
        }
#endif
        return cmd_line;
    }
Beispiel #2
0
//----------------------------------------------------------------------------------------------------------------------
// init_command_line_params
//----------------------------------------------------------------------------------------------------------------------
static bool init_command_line_params(int argc, char *argv[])
{
    VOGL_FUNC_TRACER

    command_line_params::parse_config parse_cfg;
    parse_cfg.m_single_minus_params = true;
    parse_cfg.m_double_minus_params = true;

    if (!g_command_line_params().parse(get_command_line_params(argc, argv),
                                     VOGL_ARRAY_SIZE(g_command_line_param_descs),
                                     g_command_line_param_descs, parse_cfg))
    {
        vogl_error_printf("%s: Failed parsing command line parameters!\n", VOGL_FUNCTION_NAME);
        return false;
    }

    if (!init_logfile())
        return false;

    if (g_command_line_params().get_value_as_bool("help") || g_command_line_params().get_value_as_bool("?"))
    {
        tool_print_help();
        return false;
    }

    return true;
}
CLParams get_command_line_params(int argc,char *argv[]) {
    QStringList args;
    for (int i=1; i<argc; i++) {
        args << argv[i];
    }
    return get_command_line_params(args);
}
Beispiel #4
0
int main(int argc, char *argv[])
{
	QStringList required_params,optional_params;
	required_params << "tau" << "ftype";
	CLParams params=get_command_line_params(argc,argv,required_params,optional_params);

	if (!params.success) {
		qCritical() << params.error_message;
		usage(); return -1;
	}
	if (params.unnamed_parameters.count()!=2) {
		usage(); return -1;
	}

	QString inpath=params.unnamed_parameters[0];
	QString outpath=params.unnamed_parameters[1];

	int lowpass;
	if (params.named_parameters["ftype"]=="lowpass") lowpass=1;
	else if (params.named_parameters["ftype"]=="highpass") lowpass=0;
	else {usage(); return -1;}

	float tau=params.named_parameters["tau"].toFloat();

	FILE *inf=fopen(inpath.toLatin1().data(),"rb");
	if (!inf) {printf("Unable to open input file for reading.\n"); return -1;}
	FILE *outf=fopen(outpath.toLatin1().data(),"wb");
	if (!outf) {printf("Unable to open output file for writing.\n"); fclose(inf); return -1;}

	qDebug()  << "Running expfilter" << inpath << outpath << lowpass << tau;
	if (!expfilter(inf,outf,lowpass,tau)) {
		qCritical() << "Problem in expfilter.";
	}

	fclose(inf);
	fclose(outf);

	return 0;
}
Beispiel #5
0
int main(int argc, char *argv[])
{
	QStringList required_params,optional_params;
	required_params << "clipsize" << "labels";
	CLParams params=get_command_line_params(argc,argv,required_params,optional_params);

	if (!params.success) {
		qCritical() << params.error_message;
		usage(); return -1;
	}
	if (params.unnamed_parameters.count()!=6) {
		usage(); return -1;
	}

	QString inpath1=params.unnamed_parameters[0];
	QString inpath2=params.unnamed_parameters[1];
	QString inpath_TL1=params.unnamed_parameters[2];
	QString inpath_TL2=params.unnamed_parameters[3];
	QString outpath1=params.unnamed_parameters[4];
	QString outpath2=params.unnamed_parameters[5];

	QString outpath_TL=QFileInfo(outpath1).path()+"/"+QFileInfo(outpath1).completeBaseName()+".TL.mda";
	QString outpath_TM=QFileInfo(outpath1).path()+"/"+QFileInfo(outpath1).completeBaseName()+".TM.mda";

	QMap<QString,QVariant> runparams;

	int clipsize=params.named_parameters["clipsize"].toInt();
	if ((clipsize<=2)||(clipsize>=1000)) {
		qCritical() << "invalid clipsize" << clipsize;
		usage(); return -1;
	}
	runparams["clipsize"]=clipsize;

	QStringList labels=params.named_parameters["labels"].split(",");
	if (labels.count()!=2) {
		qCritical() << "invalid labels" << params.named_parameters["labels"];
		usage(); return -1;
	}
	runparams["labels"]=labels;

	FILE *inf1=fopen(inpath1.toLatin1().data(),"rb");
	if (!inf1) {printf("Unable to open input file1 for reading.\n"); return -1;}
	FILE *inf2=fopen(inpath2.toLatin1().data(),"rb");
	if (!inf2) {printf("Unable to open input file2 for reading.\n"); return -1;}
	FILE *inf_TL1=fopen(inpath_TL1.toLatin1().data(),"rb");
	if (!inf_TL1) {printf("Unable to open input_TL1 file for reading.\n"); return -1;}
	FILE *inf_TL2=fopen(inpath_TL2.toLatin1().data(),"rb");
	if (!inf_TL2) {printf("Unable to open input_TL2 file for reading.\n"); return -1;}
	FILE *outf1=fopen(outpath1.toLatin1().data(),"wb");
	if (!outf1) {printf("Unable to open output file1 for writing.\n"); return -1;}
	FILE *outf2=fopen(outpath2.toLatin1().data(),"wb");
	if (!outf2) {printf("Unable to open output file2 for writing.\n"); return -1;}
	FILE *outf_TL=fopen(outpath_TL.toLatin1().data(),"wb");
	if (!outf_TL) {printf("Unable to open output_TL file for writing.\n"); return -1;}
	FILE *outf_TM=fopen(outpath_TM.toLatin1().data(),"wb");
	if (!outf_TM) {printf("Unable to open output_TM file for writing.\n"); return -1;}

	qDebug() << "Running extractclips2" << inpath1 << inpath2 << inpath_TL1 << inpath_TL2 << outpath1 << outpath2 << outpath_TM << runparams["clipsize"].toInt();
	if (!extractclips2(inf1,inf2,inf_TL1,inf_TL2,outf1,outf2,outf_TL,outf_TM,runparams)) {
		qCritical() << "Problem in extractclips.";
	}

	fclose(inf1);
	fclose(inf2);
	fclose(inf_TL1);
	fclose(inf_TL2);
	fclose(outf1);
	fclose(outf2);
	fclose(outf_TL);
	fclose(outf_TM);

	return 0;
}
int main(int argc, char *argv[]) {
	QApplication a(argc, argv);
	//MainWindow w;
	//w.show();

//	{
//		test_histogramview();
//		return a.exec();
//	}


    QStringList required;
    QStringList optional;
    CLParams CLP=get_command_line_params(argc,argv,required);

	QStringList args;
	for (int i=1; i<argc; i++) {
		args << QString(argv[i]);
	}

	qsrand(QDateTime::currentDateTime().toMSecsSinceEpoch());

	QString working_path=CLP.named_parameters.value("working_path");
	QString output_path=CLP.named_parameters.value("output_path");

    QString templates_path=CLP.named_parameters.value("templates");
    QString locations_path=CLP.named_parameters.value("locations");
    QString raw_path=CLP.named_parameters.value("raw");
    QString times_path=CLP.named_parameters.value("times");
    QString labels_path=CLP.named_parameters.value("labels");
    QString cluster_path=CLP.named_parameters.value("cluster");
    QString primary_channels_path=CLP.named_parameters.value("primary-channels");
    QString cross_correlograms_path=CLP.named_parameters.value("cross-correlograms");
	QString clips_path=CLP.named_parameters.value("clips");
	QString clips_index_path=CLP.named_parameters.value("clips-index");

	//MountainViewWidget W;
	MVOverviewWidget W;
    W.show();
	W.move(QApplication::desktop()->screen()->rect().topLeft()+QPoint(200,200));
	W.resize(1800,1200);
    if (!templates_path.isEmpty()) {
        Mda X; X.read(templates_path);
        W.setTemplates(X);
    }
    if (!locations_path.isEmpty()) {
        Mda X; X.read(locations_path);
		W.setElectrodeLocations(X);
    }
    if (!raw_path.isEmpty()) {
        DiskArrayModel *X=new DiskArrayModel;
        X->setPath(raw_path);
		W.setRaw(X,true);
    }
	if (!clips_path.isEmpty()) {
		DiskArrayModel *X=new DiskArrayModel;
		X->setPath(clips_path);
		W.setClips(X,true);
	}
	if (!clips_index_path.isEmpty()) {
		Mda X; X.read(clips_index_path);
		W.setClipsIndex(X);
	}
    if (!times_path.isEmpty()) {
        Mda T; T.read(times_path);
        Mda L;
        if (!labels_path.isEmpty()) {
            L.read(labels_path);
        }
        else {
            L.allocate(T.N1(),T.N2());
            for (int ii=0; ii<L.totalSize(); ii++) L.setValue1(1,ii);
        }
        W.setTimesLabels(T,L);
    }
    if (!cluster_path.isEmpty()) {
        Mda CC; CC.read(cluster_path);
        int num_events=CC.N2();
        Mda T,L;
        T.allocate(1,num_events);
        L.allocate(1,num_events);
        for (int i=0; i<num_events; i++) {
            T.setValue(CC.value(1,i),0,i);
            L.setValue(CC.value(2,i),0,i);
        }
        W.setTimesLabels(T,L);
    }
	{
		Mda PC; PC.read(primary_channels_path);
		W.setPrimaryChannels(PC);
	}
    {
        W.setCrossCorrelogramsPath(cross_correlograms_path);
    }
	W.updateWidgets();


	int ret=a.exec();

	printf("Number of files open: %d, number of unfreed mallocs: %d, number of unfreed megabytes: %g\n",jnumfilesopen(),jmalloccount(),(int)jbytesallocated()*1.0/1000000);

	return ret;
}
int main(int argc,char *argv[]) {

	QCoreApplication app(argc,argv); //important for qApp->applicationDirPath() in processtracker

//	test_armadillo();
//	test_pca_2();
//	return 0;

	CLParams CLP;
	QStringList required;
	CLP=get_command_line_params(argc,argv,required);

	ProcessTracker PT;
	register_processors(PT);

	if (CLP.unnamed_parameters.count()>1) {
		printf("Only one command parameter may be specified.\n");
		return -1;
	}

	QString command=CLP.unnamed_parameters.value(0);

	if (command.isEmpty()) {
		printf("\nmountainsort processors:\n");
		for (int i=0; i<PT.processorCount(); i++) {
			QString cmd=PT.processor(i).command;
			printf("%s ",cmd.toLatin1().data());
		}
		printf("\n\n");
		return -1;
	}

	PTProcessor PP=PT.findProcessor(command);
	printf("%s version %s\n",PP.command.toLatin1().data(),PP.version.toLatin1().data());

	if (!CLP.named_parameters.value("force").toInt()) {
		if (PT.processAlreadyCompleted(CLP)) {
			printf("Process already completed.\n");
			return 0;
		}
	}
	CLP.named_parameters.remove("force");

	QTime timer; timer.start();

	if (command=="extract") {
		QString input_path=CLP.named_parameters["input"];
		QString output_path=CLP.named_parameters["output"];
		int num_channels=CLP.named_parameters["num_channels"].toInt();
		long t1=CLP.named_parameters["t1"].toLong();
		long t2=CLP.named_parameters["t2"].toLong();
		QStringList channels_str=CLP.named_parameters["channels"].split(",");
		int M=channels_str.count();
		int channels[M];
		for (int m=0; m<M; m++) channels[m]=channels_str[m].toInt();

		if ((input_path.isEmpty())||(output_path.isEmpty())) {extract_usage(); return -1;}
		if (M==0) {extract_usage(); return -1;}

		if (!extract(input_path.toLatin1().data(),output_path.toLatin1().data(),num_channels,M,channels,t1,t2)) {
			printf("Error in extract.\n");
			return -1;
		}
	}
	else if (command=="bandpass_filter") {
		QString input_path=CLP.named_parameters["input"];
		QString output_path=CLP.named_parameters["output"];
		double samplefreq=CLP.named_parameters["samplefreq"].toDouble();
		double freq_min=CLP.named_parameters["freq_min"].toDouble();
		double freq_max=CLP.named_parameters["freq_max"].toDouble();
		double outlier_threshold=CLP.named_parameters["outlier_threshold"].toDouble();

		if ((input_path.isEmpty())||(output_path.isEmpty())) {bandpass_filter_usage(); return -1;}
		if ((samplefreq==0)||(freq_min==0)||(freq_max==0)) {bandpass_filter_usage(); return -1;}

		if (!bandpass_filter(input_path.toLatin1().data(),output_path.toLatin1().data(),samplefreq,freq_min,freq_max,outlier_threshold)) {
			printf("Error in bandpass_filter.\n");
			return -1;
		}
	}
	else if (command=="normalize_channels") {
		QString input_path=CLP.named_parameters["input"];
		QString output_path=CLP.named_parameters["output"];

		if ((input_path.isEmpty())||(output_path.isEmpty())) {normalize_channels_usage(); return -1;}

		if (!normalize_channels(input_path.toLatin1().data(),output_path.toLatin1().data())) {
			printf("Error in normalize_channels.\n");
			return -1;
		}
	}
	else if (command=="whiten") {
		QString input_path=CLP.named_parameters["input"];
		QString output_path=CLP.named_parameters["output"];
		int ncomp=CLP.named_parameters["ncomp"].toInt();

		if ((input_path.isEmpty())||(output_path.isEmpty())) {whiten_usage(); return -1;}
		if (ncomp==0) {whiten_usage(); return -1;}

		if (!whiten(input_path.toLatin1().data(),output_path.toLatin1().data(),ncomp)) {
			printf("Error in whiten.\n");
			return -1;
		}
	}
	else if (command=="detect") {
		QString input_path=CLP.named_parameters["input"];
		QString output_path=CLP.named_parameters["output"];
		int inner_window_width=CLP.named_parameters["inner_window_width"].toInt();
		int outer_window_width=CLP.named_parameters["outer_window_width"].toInt();
		float threshold=CLP.named_parameters["threshold"].toFloat();

		if ((input_path.isEmpty())||(output_path.isEmpty())) {detect_usage(); return -1;}
		if (inner_window_width==0) {detect_usage(); return -1;}
		if (outer_window_width==0) {detect_usage(); return -1;}
		if (threshold==0) {detect_usage(); return -1;}

		if (!detect(input_path.toLatin1().data(),output_path.toLatin1().data(),inner_window_width,outer_window_width,threshold)) {
			printf("Error in detect.\n");
			return -1;
		}
	}
    else if (command=="features") {
        QString input_path=CLP.named_parameters["input"];
        QString detect_path=CLP.named_parameters["detect"];
        QString adjacency_path=CLP.named_parameters["adjacency"];
        QString output_path=CLP.named_parameters["output"];
        int num_features=CLP.named_parameters["num_features"].toInt();
        int clip_size=CLP.named_parameters["clip_size"].toInt();

        if ((input_path.isEmpty())||(detect_path.isEmpty())||(adjacency_path.isEmpty())||(output_path.isEmpty())) {features_usage(); return -1;}
        if (num_features==0) {features_usage(); return -1;}
        if (clip_size==0) {features_usage(); return -1;}

        if (!features(input_path.toLatin1().data(),detect_path.toLatin1().data(),adjacency_path.toLatin1().data(),output_path.toLatin1().data(),num_features,clip_size)) {
            printf("Error in features.\n");
            return -1;
        }
    }
    else if (command=="cluster") {
        QString input_path=CLP.named_parameters["input"];
        QString output_path=CLP.named_parameters["output"];

        if ((input_path.isEmpty())||(output_path.isEmpty())) {cluster_usage(); return -1;}

        if (!cluster(input_path.toLatin1().data(),output_path.toLatin1().data())) {
            printf("Error in cluster.\n");
            return -1;
        }
    }
	else if (command=="split_clusters") {
		QString input_path=CLP.named_parameters["input"];
		QString cluster_path=CLP.named_parameters["cluster"];
		QString output_path=CLP.named_parameters["output"];
		int num_features=CLP.named_parameters["num_features"].toInt();
		int clip_size=CLP.named_parameters["clip_size"].toInt();

		if ((input_path.isEmpty())||(cluster_path.isEmpty())||(output_path.isEmpty())) {cluster_usage(); return -1;}
		if (num_features==0) {cluster_usage(); return -1;}
		if (clip_size==0) {cluster_usage(); return -1;}

		if (!split_clusters(input_path.toLatin1().data(),cluster_path.toLatin1().data(),output_path.toLatin1().data(),num_features,clip_size)) {
			printf("Error in cluster.\n");
			return -1;
		}
	}
    else if (command=="templates") {
        QString input_path=CLP.named_parameters["input"];
        QString cluster_path=CLP.named_parameters["cluster"];
        QString output_path=CLP.named_parameters["output"];
        int clip_size=CLP.named_parameters["clip_size"].toInt();

        if ((input_path.isEmpty())||(output_path.isEmpty())) {templates_usage(); return -1;}
        if (clip_size==0) {templates_usage(); return -1;}

        if (!templates(input_path.toLatin1().data(),cluster_path.toLatin1().data(),output_path.toLatin1().data(),clip_size)) {
            printf("Error in templates.\n");
            return -1;
        }
    }
    else if (command=="consolidate") {
        QString cluster_path=CLP.named_parameters["cluster"];
        QString templates_path=CLP.named_parameters["templates"];
        QString cluster_out_path=CLP.named_parameters["cluster_out"];
        QString templates_out_path=CLP.named_parameters["templates_out"];
        QString load_channels_out_path=CLP.named_parameters["load_channels_out"];

        if ((cluster_path.isEmpty())||(templates_path.isEmpty())) {consolidate_usage(); return -1;}
        if ((cluster_out_path.isEmpty())||(templates_out_path.isEmpty())) {consolidate_usage(); return -1;}
        if (load_channels_out_path.isEmpty()) {consolidate_usage(); return -1;}

        if (!consolidate(cluster_path.toLatin1().data(),templates_path.toLatin1().data(),cluster_out_path.toLatin1().data(),templates_out_path.toLatin1().data(),load_channels_out_path.toLatin1().data())) {
            printf("Error in consolidate.\n");
            return -1;
        }
    }
    else if (command=="fit") {
        QString input_path=CLP.named_parameters["input"];
        QString cluster_path=CLP.named_parameters["cluster"];
        QString templates_path=CLP.named_parameters["templates"];
        QString cluster_out_path=CLP.named_parameters["cluster_out"];

        if ((input_path.isEmpty())||(cluster_path.isEmpty())||(templates_path.isEmpty())) {fit_usage(); return -1;}
        if ((cluster_out_path.isEmpty())) {fit_usage(); return -1;}

        if (!fit(input_path.toLatin1().data(),templates_path.toLatin1().data(),cluster_path.toLatin1().data(),cluster_out_path.toLatin1().data())) {
            printf("Error in fit.\n");
            return -1;
        }
    }
	else if (command=="extract_clips") {
		QString input_path=CLP.named_parameters["input"];
		QString cluster_path=CLP.named_parameters["cluster"];
		QString output_path=CLP.named_parameters["output"];
		QString index_out_path=CLP.named_parameters["index_out"];
		int clip_size=CLP.named_parameters["clip_size"].toInt();

		if ((input_path.isEmpty())||(cluster_path.isEmpty())) {extract_usage(); return -1;}
		if ((output_path.isEmpty())||(index_out_path.isEmpty())) {extract_usage(); return -1;}

		if (!extract_clips(input_path.toLatin1().data(),cluster_path.toLatin1().data(),output_path.toLatin1().data(),index_out_path.toLatin1().data(),clip_size)) {
			printf("Error in extract_clips.\n");
			return -1;
		}
	}
	else {
		printf("Unknown command: %s\n",command.toLatin1().data());
		return -1;
	}

	PT.reportProcessCompleted(CLP);

	printf("Elapsed time for %s: %.2f seconds\n",command.toLatin1().data(),timer.elapsed()*1.0/1000);

	return 0;
}