File: rfigui.cpp

package info (click to toggle)
aoflagger 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,944 kB
  • sloc: cpp: 60,273; sh: 21; makefile: 8
file content (165 lines) | stat: -rw-r--r-- 4,855 bytes parent folder | download
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "version.h"

#include "gui/rfiguiwindow.h"

#include "gui/controllers/rfiguicontroller.h"

#include "util/aologger.h"

#include "strategy/imagesets/msimageset.h"

#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>

#include <gtkmm/application.h>

#include <glibmm/error.h>
#include <glibmm/wrap.h>

#include <string>
#include <vector>

#include <libgen.h>

struct SavedBaseline
{
	size_t a1Index, a2Index, bandIndex, sequenceIndex;
	std::string filename;
	bool operator<(const SavedBaseline& rhs) const
	{
		return boost::tie(a1Index, a2Index, bandIndex, sequenceIndex, filename) <
			boost::tie(rhs.a1Index, rhs.a2Index, rhs.bandIndex, rhs.sequenceIndex, rhs.filename);
	}
};

static void run(int argc, char *argv[])
{
	int argi = 1;
	
	std::vector<std::string> filenames;
	std::set<SavedBaseline> savedBaselines;
	bool interactive = true;
	std::string dataColumnName = "DATA";
	
	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 == "h" || p == "help" || p == "?")
			{
				AOLogger::Info
					<< "The RFIGui is a program to analyze the time-frequency information in radio astronomical observations.\n"
					<< "It is written by André Offringa (offringa@gmail.com) and published under the GPL 3.\n"
					<< "This program is part of AOFlagger " << AOFLAGGER_VERSION_STR << " (" << AOFLAGGER_VERSION_DATE_STR << ")\n\n"
					<< "Syntax:\n"
					<< "  rfigui [-option1 [-option2 ...]] [measurement set]\n\n"
					<< "The main window will be opened when no parameters are specified.\n"
					<< "Possible options:\n"
					<< " -help\n"
					<< "    Display this help message and exit.\n"
					<< " -version\n"
					<< "    Display AOFlagger version and exit.\n"
					<< " -save-baseline <filename> <antenna1> <antenna2> <band> <sequence index>\n"
					<< "    Save the selected baseline to the given filename. The parameter can be specified\n"
					<< "    multiple times to save multiple baselines in one run. When this parameter is specified,\n"
					<< "    the main window will not open and the program will exit after saving the requested baselines.\n"
					<< " -data-column <columnname>\n"
					<< "    Open the selected column name.\n";
				return;
			}
			else if(p == "version")
			{
				AOLogger::Info << "AOFlagger " << AOFLAGGER_VERSION_STR << " (" << AOFLAGGER_VERSION_DATE_STR << ")\n";
				return;
			}
			else if(p == "save-baseline")
			{
				SavedBaseline sb;
				sb.filename = argv[argi+1];
				sb.a1Index = atoi(argv[argi+2]);
				sb.a2Index = atoi(argv[argi+3]);
				sb.bandIndex = atoi(argv[argi+4]);
				sb.sequenceIndex = atoi(argv[argi+5]);
				savedBaselines.insert(sb);
				interactive = false;
				argi += 5;
			}
			else if(p == "data-column")
			{
				++argi;
				dataColumnName = argv[argi];
			}
			else {
				AOLogger::Error << "Unknown parameter " << argv[argi] << " specified on command line.\n";
				return;
			}
		}
		else {
			filenames.push_back(argv[argi]);
		}
		++argi;
	}
	
	// We have to 'lie' about argc to create(..), because of a bug in older gtkmms.
	int altArgc = 1;
	Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(altArgc, argv, "", Gio::APPLICATION_HANDLES_OPEN);
	RFIGuiWindow window;
	if(interactive)
		window.present();
	
	try {
		
		if(!filenames.empty())
		{
			if(filenames.size() > 1)
				throw std::runtime_error("Error: multiple input paths specified; RFIGui can only handle one path.\n");
			if(interactive)
				window.OpenPath(filenames[0]);
			else
				window.Controller().Open(filenames[0], DirectReadMode, true, dataColumnName, false, 4, false, true);
		}
		
		if(!savedBaselines.empty())
		{
			rfiStrategy::MSImageSet* imageSet =
				dynamic_cast<rfiStrategy::MSImageSet*>(&window.GetImageSet());
			if(imageSet == 0)
				throw std::runtime_error("Option -save-baseline can only be used for measurement sets.\n");
			window.GetTimeFrequencyWidget().SetShowXAxisDescription(true);
			window.GetTimeFrequencyWidget().SetShowYAxisDescription(true);
			window.GetTimeFrequencyWidget().SetShowZAxisDescription(true);
			for(std::set<SavedBaseline>::const_iterator i=savedBaselines.begin(); i!=savedBaselines.end(); ++i)
			{
				window.SetImageSetIndex(imageSet->Index(i->a1Index, i->a2Index, i->bandIndex, i->sequenceIndex));
				window.GetTimeFrequencyWidget().SaveByExtension(i->filename, 800, 480);
			}
		}
		
		if(interactive)
			app->run(window);
	} catch(const std::exception& e)
	{
		AOLogger::Error <<
			"\n"
			"==========\n"
			"An unhandled exception occured while executing RFIGui. The error is:\n" <<
			e.what() << '\n';
	}
}

int main(int argc, char *argv[])
{
	AOLogger::Init(basename(argv[0]), false, true);
	
	run(argc, argv);
	
	Glib::Error::register_cleanup();
	Glib::wrap_register_cleanup();
	
	return 0;
}