9 #include <boost/filesystem.hpp>
23 std::vector<std::string> found_files;
25 for (t_int i = 0; i < names.size(); i++) {
26 const boost::filesystem::path file_path(names.at(i));
28 PURIFY_HIGH_LOG(
"Missing file will be removed from list: {}", names.at(i));
30 found_files.emplace_back(names.at(i));
33 std::size_t found = names.at(i).find_last_of(
".");
34 std::string format_string =
"." + names.at(i).substr(found + 1);
35 std::transform(format_string.begin(), format_string.end(), format_string.begin(), ::tolower);
36 if (format_string ==
".ms") {
39 throw std::runtime_error(names.at(i) +
40 " is not a directory, as expected for a measurement set.");
41 }
else if (format_string ==
".vis") {
44 throw std::runtime_error(names.at(i) +
" is not a regular file.");
45 }
else if (format_string ==
".h5") {
48 throw std::runtime_error(names.at(i) +
" is not a regular file.");
49 }
else if (format_string ==
".uvfits") {
52 throw std::runtime_error(names.at(i) +
" is not a regular file.");
54 throw std::runtime_error(
"File extension for " + names.at(i) +
55 " not recognised. Must be .vis, .h5, .uvfits, or .ms.");
56 if (i == 0) format_type = format_check;
57 if (i > 0 and (format_check != format_type))
58 throw std::runtime_error(
"File extension is not the same for " + names.at(i) +
" " +
63 if (found_files.size() == 0)
throw std::runtime_error(
"No files found.");
64 switch (format_type) {
67 throw std::runtime_error(
"Stokes I assumed for vis files, but a different type is chosen.");
69 measurements.units = units;
76 throw std::runtime_error(
"Stokes I assumed for HDF5 files, but a different type is chosen.");
78 measurements.units = units;
82 throw std::runtime_error(
"HDF5 interface required to read h5 files.");
90 #ifdef PURIFY_CASACORE
94 throw std::runtime_error(
"Casacore interface required to read a measurement set.");
98 throw std::runtime_error(
"Format not recognised.");
104 sopt::mpi::Communicator
const &comm,
110 sopt::mpi::Communicator
const &comm,
113 if (comm.size() == 1) {
116 }
catch (
const std::runtime_error &e) {
117 comm.abort(e.what());
120 if (comm.is_root()) {
121 utilities::vis_params result;
124 }
catch (
const std::runtime_error &e) {
125 comm.abort(e.what());
137 return (stat(path.c_str(), &buf) == 0);
142 return (stat(path.c_str(), &buf) == 0 && S_ISDIR(buf.st_mode));
146 std::vector<std::string>
split(
const std::string &s,
char delim) {
147 std::vector<std::string> elems;
148 split(s, delim, std::back_inserter(elems));
153 const auto folders =
split(path,
'/');
154 std::string current_path =
"";
155 for (
const auto f : folders) {
162 const t_int status = mkdir(current_path.c_str(), ACCESSPERMS);
164 throw std::runtime_error(
"Error making recursive directory: " + current_path);
#define PURIFY_HIGH_LOG(...)
High priority message.
utilities::vis_params read_measurementset(std::string const &filename, const stokes polarization, const std::vector< t_int > &channels_input, std::string const &filter)
Read measurement set into vis_params structure.
std::vector< t_int > distribute_measurements(Vector< t_real > const &u, Vector< t_real > const &v, Vector< t_real > const &w, t_int const number_of_nodes, distribute::plan const distribution_plan, t_int const &grid_size)
Distribute visiblities into groups.
utilities::vis_params read_uvfits(const std::vector< std::string > &names, const bool flag, const stokes pol)
Read uvfits files from name of vector.
utilities::vis_params read_measurements(const std::vector< std::string > &names, const bool w_term, const stokes pol, const utilities::vis_units units)
read in measurements from a vector of file names
bool dir_exists(const std::string &path)
check that directory path exists
bool file_exists(const std::string &path)
check that file path exists
utilities::vis_params read_measurements(const std::string &name, const bool w_term, const stokes pol, const utilities::vis_units units)
read in single measurement file
vis_params scatter_visibilities(vis_params const ¶ms, std::vector< t_int > const &sizes, sopt::mpi::Communicator const &comm)
vis_params regroup_and_scatter(vis_params const ¶ms, std::vector< t_int > const &groups, sopt::mpi::Communicator const &comm)
utilities::vis_params read_visibility(const std::vector< std::string > &names, const bool w_term)
Read visibility files from name of vector.
void mkdir_recursive(const std::string &path)
recursively create directories when they do not exist
std::vector< std::string > split(const std::string &s, char delim)
splits string into vector