1 /*
2 * Copyright (c) 2013-2021, The OSKAR Developers.
3 * See the LICENSE file at the top-level directory of this distribution.
4 */
5
6 #include "telescope/private_TelescopeLoaderLayout.h"
7 #include "utility/oskar_dir.h"
8
9 using std::map;
10 using std::string;
11
12 static const char* layout_file = "layout.txt";
13 static const char* layout_enu_file = "layout_enu.txt";
14 static const char* layout_x_file = "layout_x.txt";
15 static const char* layout_enu_x_file = "layout_enu_x.txt";
16 static const char* layout_y_file = "layout_y.txt";
17 static const char* layout_enu_y_file = "layout_enu_y.txt";
18 static const char* layout_ecef_file = "layout_ecef.txt";
19 static const char* layout_wgs84_file = "layout_wgs84.txt";
20
21
load(oskar_Telescope * telescope,const string & cwd,int num_subdirs,map<string,string> &,int * status)22 void TelescopeLoaderLayout::load(oskar_Telescope* telescope,
23 const string& cwd, int num_subdirs,
24 map<string, string>& /*filemap*/, int* status)
25 {
26 // Check for presence of top-level layout files.
27 if (oskar_dir_file_exists(cwd.c_str(), layout_file))
28 {
29 // Load the interferometer layout (horizon plane).
30 oskar_telescope_load_station_coords_enu(telescope,
31 get_path(cwd, layout_file).c_str(),
32 oskar_telescope_lon_rad(telescope),
33 oskar_telescope_lat_rad(telescope),
34 oskar_telescope_alt_metres(telescope), status);
35 }
36 else if (oskar_dir_file_exists(cwd.c_str(), layout_enu_file))
37 {
38 // Load the interferometer layout (horizon plane).
39 oskar_telescope_load_station_coords_enu(telescope,
40 get_path(cwd, layout_enu_file).c_str(),
41 oskar_telescope_lon_rad(telescope),
42 oskar_telescope_lat_rad(telescope),
43 oskar_telescope_alt_metres(telescope), status);
44 }
45 else if (oskar_dir_file_exists(cwd.c_str(), layout_ecef_file))
46 {
47 // Load the interferometer layout (ECEF system).
48 oskar_telescope_load_station_coords_ecef(telescope,
49 get_path(cwd, layout_ecef_file).c_str(),
50 oskar_telescope_lon_rad(telescope),
51 oskar_telescope_lat_rad(telescope),
52 oskar_telescope_alt_metres(telescope), status);
53 }
54 else if (oskar_dir_file_exists(cwd.c_str(), layout_wgs84_file))
55 {
56 // Load the interferometer layout (WGS84 system).
57 oskar_telescope_load_station_coords_wgs84(telescope,
58 get_path(cwd, layout_wgs84_file).c_str(),
59 oskar_telescope_lon_rad(telescope),
60 oskar_telescope_lat_rad(telescope),
61 oskar_telescope_alt_metres(telescope), status);
62 }
63 else
64 {
65 // If telescope hasn't already been sized, return an error.
66 if (oskar_telescope_num_stations(telescope) == 0)
67 {
68 *status = OSKAR_ERR_SETUP_FAIL_TELESCOPE_CONFIG_FILE_MISSING;
69 }
70 return;
71 }
72
73 // If no subdirectories, set all "stations" to be a single dipole.
74 if (num_subdirs == 0)
75 {
76 int num_stations = oskar_telescope_num_station_models(telescope);
77 for (int i = 0; i < num_stations; ++i)
78 {
79 oskar_Station* station = oskar_telescope_station(telescope, i);
80 oskar_station_resize(station, 1, status);
81 oskar_station_resize_element_types(station, 1, status);
82 }
83 }
84 }
85
load(oskar_Station * station,const string & cwd,int num_subdirs,int,map<string,string> &,int * status)86 void TelescopeLoaderLayout::load(oskar_Station* station,
87 const string& cwd, int num_subdirs, int /*depth*/,
88 map<string, string>& /*filemap*/, int* status)
89 {
90 // Check for presence of station layout file.
91 if (oskar_dir_file_exists(cwd.c_str(), layout_file))
92 {
93 oskar_station_load_layout(station, 0,
94 get_path(cwd, layout_file).c_str(), status);
95 }
96 else if (oskar_dir_file_exists(cwd.c_str(), layout_enu_file))
97 {
98 oskar_station_load_layout(station, 0,
99 get_path(cwd, layout_enu_file).c_str(), status);
100 }
101
102 if (oskar_dir_file_exists(cwd.c_str(), layout_x_file))
103 {
104 oskar_station_load_layout(station, 0,
105 get_path(cwd, layout_x_file).c_str(), status);
106 }
107 else if (oskar_dir_file_exists(cwd.c_str(), layout_enu_x_file))
108 {
109 oskar_station_load_layout(station, 0,
110 get_path(cwd, layout_enu_x_file).c_str(), status);
111 }
112
113 if (oskar_dir_file_exists(cwd.c_str(), layout_y_file))
114 {
115 oskar_station_load_layout(station, 1,
116 get_path(cwd, layout_y_file).c_str(), status);
117 }
118 else if (oskar_dir_file_exists(cwd.c_str(), layout_enu_y_file))
119 {
120 oskar_station_load_layout(station, 1,
121 get_path(cwd, layout_enu_y_file).c_str(), status);
122 }
123
124 // If station hasn't already been sized, return an error.
125 if (oskar_station_num_elements(station) == 0)
126 {
127 *status = OSKAR_ERR_SETUP_FAIL_TELESCOPE_CONFIG_FILE_MISSING;
128 }
129
130 // Check if this is the last level.
131 if (num_subdirs > 0)
132 {
133 // Allocate storage for child stations.
134 oskar_station_create_child_stations(station, status);
135 }
136 else if (num_subdirs == 0)
137 {
138 // Allocate storage for element model data if no children.
139 oskar_station_resize_element_types(station, 1, status);
140 }
141 }
142
name() const143 string TelescopeLoaderLayout::name() const
144 {
145 return string("layout file loader");
146 }
147