File: aoqplot.cpp

package info (click to toggle)
aoflagger 2.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,232 kB
  • sloc: cpp: 61,805; python: 60; sh: 23; makefile: 8
file content (142 lines) | stat: -rw-r--r-- 3,953 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "aoqplot/aoqplotwindow.h"

#include "aoqplot/controllers/aoqplotcontroller.h"

#include <gtkmm/main.h>
#include <gtkmm/filechooserdialog.h>

#include "version.h"

#include "util/logger.h"

bool SelectFile(AOQPlotWindow& window, std::string& filename)
{
	Gtk::FileChooserDialog fileDialog(window, "Open observation set");
	
	fileDialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
	fileDialog.add_button("_Open", Gtk::RESPONSE_OK);
	
	Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
	filter->set_name("Observation sets (*.{vds,gds,ref,MS})");
	filter->add_pattern("*.vds");
	filter->add_pattern("*.gds");
	filter->add_pattern("*.gvds");
	filter->add_pattern("*.ref");
	filter->add_pattern("*.MS");
	fileDialog.add_filter(filter);
	
	if(fileDialog.run() == Gtk::RESPONSE_OK)
	{
		filename = fileDialog.get_filename();
		return true;
	}
	else return false;
}

int main(int argc, char *argv[])
{
	// We have to 'lie' about argc to create(..), because of a bug in older gtkmms.
	int altArgc = 1;
	AOQPlotController controller;
	std::unique_ptr<AOQPlotWindow> window;
	bool openGUI = true;
	int argi = 1;
	std::vector<AOQPlotController::PlotSavingData> savedPlots;
	std::vector<std::string> files;
	while(argi < argc)
	{
		if(argv[argi][0]=='-')
		{
			std::string p;
			if(argv[argi][1] == '-')
				p = &argv[argi][2];
			else
				p = &argv[argi][1];
			if(p=="help" || p=="h")
			{
				Logger::Info << "Syntax: aoqplot [<options>] [<observation>]\n\n"
					"<observation> can be a measurement set for opening a single observation.\n"
					"To get statistics for a (remote) observation consisting of multiple measurement\n"
					"sets, specify a measurement set specifier instead (generally a .ref, .vds\n"
					".gvds or .gds file).\n"
					"\n"
					"Options can be:\n"
					"-help\n"
					"  Show syntax help.\n"
					"-version\n"
					"  Print version info and exit.\n"
					"-v\n"
					"  Verbose logging.\n"
					"-save [filename prefix] [statistic name]\n"
					"  Save every plot for the given kind of statistic as a PDF file. This\n"
					"  will prevent the GUI from opening. You can repeat this parameter to save\n"
					"  multiple kinds at once. A list of allowed names can be retrieved with\n"
					"  'aoquality liststats'. Some common ones are: StandardDeviation, Variance, Mean,\n"
					"  RFIPercentage, RFIRatio, Count.\n"
					"\n"
					"AOQPlot is part of the AOFlagger software package, written by André Offringa\n"
					"  (offringa@gmail.com). This AOQPlot belongs to AOFlagger " << AOFLAGGER_VERSION_STR << " (" << AOFLAGGER_VERSION_DATE_STR << ")\n";
				return 0;
			}
			else if(p=="save")
			{
				AOQPlotController::PlotSavingData newPlot;
				newPlot.filenamePrefix = argv[argi+1];
				newPlot.statisticKind = QualityTablesFormatter::NameToKind(argv[argi+2]);
				argi += 2;
				openGUI = false;
				savedPlots.push_back(newPlot);
			}
			else if(p == "version")
			{
				Logger::Info << "AOQplot " << AOFLAGGER_VERSION_STR << " (" << AOFLAGGER_VERSION_DATE_STR << ")\n";
				return 0;
			}
			else if(p == "v")
			{
				Logger::SetVerbosity(Logger::VerboseVerbosity);
			}
			else {
				Logger::Error << "Bad parameter specified: " << argv[argi] << '\n';
				return 1;
			}
		}
		else {
			files.push_back(argv[argi]);
		}
		++argi;
	}
	
	if(openGUI)
	{
		Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(altArgc, argv, "", Gio::APPLICATION_HANDLES_OPEN);
		window.reset(new AOQPlotWindow(&controller));
		window->show_all();
		if(files.empty())
		{
			std::string filename;
			if(SelectFile(*window, filename))
				files.push_back(filename);
			else
				return 0;
		}
		window->Open(files);
		app->run(*window);
	}
	else {
		if(files.empty())
		{
			Logger::Error << "No observation specified.\n";
			return 1;
		}
		
		controller.ReadStatistics(files);
	
		for(const AOQPlotController::PlotSavingData& plot : savedPlots)
		{
			controller.Save(plot, 640, 480);
		}
	}
	
	return 0;
}