89 file.exceptions(ios::badbit | ios::failbit);
91 file.open(ename.c_str());
98 }
catch (
const std::exception& e) {
100 "Cannot open output file: ",
102 "\nMaybe you don't have write access to the directory or the file?");
113 if (file.is_open()) {
114 streampos fpos = file.tellp();
116 if (!fpos) std::filesystem::remove(
expand_path(name).c_str());
138 find_file(matching_files, ename, allpaths);
140 if (matching_files.
nelem()) ename = matching_files[0];
146 file.exceptions(ios::badbit);
149 file.open(ename.c_str());
155 "Cannot open input file: ",
157 "\nMaybe the file does not exist?");
177 while (is && is.good() && !is.eof()) {
179 getline(is, linebuffer);
182 text.push_back(linebuffer);
217 }
catch (
const std::runtime_error& x) {
233 Index j = s.find(what);
234 while (j != s.
npos) {
235 s.replace(j, 1, with);
236 j = s.find(what, j + with.size());
259 const char* cp =
d.c_str();
260 while (*cp ==
'\n') cp++;
262 if (!(*cp)) result = 1;
264 if (!result &&
d[
d.length() - 1] !=
'\n')
266 else if (!result &&
d.length() > 2 &&
d[
d.length() - 1] ==
'\n' &&
267 d[
d.length() - 2] ==
'\n')
283 return std::filesystem::exists(filename) &&
284 !std::filesystem::is_directory(filename);
302 const std::string_view filename,
309 if (!paths.
nelem() || std::filesystem::path(efilename).is_absolute()) {
310 for (
const auto& ext : extensions) {
311 const String fullpath{efilename + ext};
314 if (std::find(matches.begin(), matches.end(), fullpath) ==
316 matches.push_back(fullpath);
323 for (
const auto& path : paths) {
324 for (
const auto& ext : extensions) {
328 if (std::find(matches.begin(), matches.end(), fullpath) ==
330 matches.push_back(fullpath);
363 find_file(matching_files, filename, allpaths, {
"",
".xml",
".gz",
".xml.gz"});
366 "Cannot find input file: ",
371 if (matching_files.
nelem() > 1) {
374 <<
" WARNING: More than one file matching this name exists in the data path.\n"
375 <<
" Using the first file (1) found:\n";
376 for (
Index i = 0; i < matching_files.
nelem(); i++)
377 out1 <<
" (" << i + 1 <<
") " << matching_files[i] <<
"\n";
380 filename = matching_files[0];
402 find_file(matching_files, filename, allpaths, {
"",
".xml",
".gz",
".xml.gz"});
404 if (matching_files.
nelem()) {
405 filename = matching_files[0];
423 if ((path.length() == 1 && path[0] ==
'~') ||
424 (path.length() > 1 && path[0] ==
'~' && path[1] ==
'/')) {
449 return expanded_path;
463 if (!path.length())
return dirname;
467 if (path[0] ==
'/') dirname =
"/";
468 if (fileparts.
nelem() > 1) {
469 for (
Index i = 0; i < fileparts.
nelem() - 1; i++) {
470 dirname += fileparts[i];
471 if (i < fileparts.
nelem() - 2) dirname +=
"/";
489 "Error accessing directory: ",
493 for (
const auto& filename :
494 std::filesystem::directory_iterator{dirname}) {
495 files.push_back(filename.path().string());
514 String basename = filename;
518 if (extension.length()) {
519 size_t pos = filename.rfind(extension);
520 if (pos == filename.length() - extension.length()) {
521 basename = filename.substr(0, filename.length() - extension.length());
522 extensionname = extension;
526 Index filenumber = 0;
527 ostringstream newfilename;
528 newfilename << basename << extensionname;
534 newfilename << basename <<
"." << filenumber << extensionname;
537 return newfilename.str();
This file contains the definition of Array.
The global header file for ARTS.
Index nelem() const ARTS_NOEXCEPT
Structure to hold all command line Parameters.
ArrayOfString includepath
List of paths to search for include files.
String outdir
If this is specified (with the -o –outdir option), it is used as the base directory for the report fi...
ArrayOfString datapath
List of paths to search for data files.
void split(Array< my_basic_string< charT > > &aos, const my_basic_string< charT > &delim) const
static const Index npos
Define npos:
#define ARTS_USER_ERROR(...)
#define ARTS_USER_ERROR_IF(condition,...)
ArrayOfString read_text_from_stream(istream &is)
Read an ASCII stream and append the contents to the String array text.
ArrayOfString list_directory(const std::string_view dirname)
Return list of files in directory.
ArrayOfString read_text_from_file(const std::string_view name)
Reads an ASCII file and appends the contents to the String vector text.
String add_basedir(const std::string_view path)
void find_xml_file(String &filename, const Verbosity &verbosity)
Find an xml file.
bool find_xml_file_existence(String &filename)
As find_xml_file but does not throw in the main body.
String expand_path(String path)
void replace_all(String &s, const std::string_view what, const std::string_view with)
Replace all occurances of ‘what’ in ‘s’ with ‘with’.
void filename_ascii(String &filename, const String &varname)
Gives the default file name for the ASCII formats.
void open_input_file(ifstream &file, const std::string_view name)
Open a file for reading.
int check_newline(const std::string_view s)
Checks if there is exactly one newline character at the end of the string.
String make_filename_unique(const std::string_view filename, const String &extension)
Make filename unique.
bool file_exists(const std::string_view filename)
Checks if the given file exists.
void open_output_file(ofstream &file, const std::string_view name)
Open a file for writing.
bool find_file(ArrayOfString &matches, const std::string_view filename, const ArrayOfString &paths, const ArrayOfString &extensions)
Searches through paths for a file with a matching name.
String get_dirname(const std::string_view path)
Return the parent directory of a path.
void cleanup_output_file(ofstream &file, const std::string_view name)
Closes the file.
This file contains basic functions to handle ASCII files.
INDEX Index
The type to use for all integer numbers and indices.
String out_basename
The basename for the report file and for all other output files.
my_basic_string< char > String
The String type for ARTS.
Parameters parameters
Holds the command line parameters.
This file contains header information for the dealing with command line parameters.