48 #include <sys/types.h> 76 filename = out_basename +
"." + varname +
".aa";
102 file.exceptions(ios::badbit | ios::failbit);
105 file.open(ename.c_str());
112 }
catch (
const std::exception& e) {
114 os <<
"Cannot open output file: " << ename <<
'\n' 115 <<
"Maybe you don't have write access " 116 <<
"to the directory or the file?";
117 throw runtime_error(os.
str());
129 if (file.is_open()) {
130 streampos fpos = file.tellp();
157 find_file(matching_files, ename, allpaths);
159 if (matching_files.
nelem()) ename = matching_files[0];
165 file.exceptions(ios::badbit);
168 file.open(ename.c_str());
175 os <<
"Cannot open input file: " << ename <<
'\n' 176 <<
"Maybe the file does not exist?";
177 throw runtime_error(os.
str());
197 while (is && is.good() && !is.eof()) {
199 getline(is, linebuffer);
202 text.push_back(linebuffer);
210 os <<
"Read Error. Last line read:\n" << linebuffer;
211 throw runtime_error(os.
str());
238 }
catch (
const std::runtime_error& x) {
240 os <<
"Error reading file: " << name <<
'\n' << x.what();
241 throw runtime_error(os.
str());
254 Index j = s.find(what);
255 while (j != s.
npos) {
256 s.replace(j, 1, with);
257 j = s.find(what, j + with.size());
280 const char* cp = d.c_str();
281 while ((*cp ==
'\n') && *cp) cp++;
283 if (!(*cp)) result = 1;
285 if (!result && d[d.length() - 1] !=
'\n')
287 else if (!result && d.length() > 2 && d[d.length() - 1] ==
'\n' &&
288 d[d.length() - 2] ==
'\n')
307 if (lstat(filename.c_str(), &st) >= 0 && !S_ISDIR(st.st_mode)) {
309 fin.open(filename.c_str(), ios::in);
330 fullrealpath = realpath(filename.c_str(), NULL);
332 String retpath(fullrealpath);
361 if (!paths.
nelem() || (efilename.
nelem() && efilename[0] ==
'/')) {
362 for (ArrayOfString::const_iterator ext = extensions.begin();
363 ext != extensions.end();
368 if (std::find(matches.begin(), matches.end(), fullpath) ==
370 matches.push_back(fullpath);
377 for (ArrayOfString::const_iterator path = paths.begin();
380 for (ArrayOfString::const_iterator ext = extensions.begin();
381 ext != extensions.end();
387 if (std::find(matches.begin(), matches.end(), fullpath) ==
389 matches.push_back(fullpath);
422 find_file(matching_files, filename, allpaths, {
"",
".xml",
".gz",
".xml.gz"});
424 if (matching_files.
nelem() > 1) {
427 <<
" WARNING: More than one file matching this name exists in the data path.\n" 428 <<
" Using the first file (1) found:\n";
430 out1 <<
" (" <<
i + 1 <<
") " << matching_files[
i] <<
"\n";
431 }
else if (!matching_files.
nelem()) {
433 os <<
"Cannot find input file: " << filename << endl;
434 os <<
"Search path: " << allpaths << endl;
435 throw runtime_error(os.
str());
438 filename = matching_files[0];
460 find_file(matching_files, filename, allpaths, {
"",
".xml",
".gz",
".xml.gz"});
462 if (matching_files.
nelem()) {
463 filename = matching_files[0];
481 if ((path.
nelem() == 1 && path[0] ==
'~') ||
482 (path.
nelem() > 1 && path[0] ==
'~' && path[1] ==
'/')) {
504 expanded_path = parameters.
outdir +
'/' + expanded_path;
507 return expanded_path;
521 if (!path.
nelem())
return;
524 path.
split(fileparts,
"/");
525 if (path[0] ==
'/') dirname =
"/";
526 if (fileparts.
nelem() > 1) {
528 dirname += fileparts[
i];
529 if (
i < fileparts.
nelem() - 2) dirname +=
"/";
546 if ((dp = opendir(dirname.c_str())) == NULL) {
548 os <<
"Error(" << errno <<
") opening " << dirname << endl;
549 throw runtime_error(os.
str());
552 while ((dirp = readdir(dp)) != NULL) {
553 files.push_back(
String(dirp->d_name));
572 String basename = filename;
576 if (extension.length()) {
577 size_t pos = filename.rfind(extension);
578 if (pos == filename.length() - extension.length()) {
579 basename = filename.substr(0, filename.length() - extension.length());
580 extensionname = extension;
584 Index filenumber = 0;
586 newfilename << basename << extensionname;
592 newfilename << basename <<
"." << filenumber << extensionname;
595 filename = newfilename.
str();
603 const char* exp[] = {
"",
"inf",
"Inf",
"nan",
"NaN"};
604 const char* e = exp[0];
606 char inf[4] =
"\0\0\0";
610 if (!(
in >> *c).good())
return *
this;
626 if ((e - exp[l]) == 2)
break;
628 if (!(
in >> *++c).good())
break;
630 if (
in.good() && *c == *e) {
634 x = std::numeric_limits<double>::infinity();
638 x = std::numeric_limits<double>::quiet_NaN();
643 }
else if (!
in.good()) {
644 if (!
in.fail())
return *
this;
650 }
while (c-- != inf);
651 in.setstate(std::ios_base::failbit);
INDEX Index
The type to use for all integer numbers and indices.
void cleanup_output_file(ofstream &, const String &)
Closes the file.
bool find_file(ArrayOfString &matches, const String &filename, const ArrayOfString &paths, const ArrayOfString &extensions)
Searches through paths for a file with a matching name.
Index nelem() const
Number of elements.
String expand_path(const String &path)
String out_basename
The basename for the report file and for all other output files.
void get_dirname(String &dirname, const String &path)
Return the parent directory of a path.
This file contains basic functions to handle ASCII files.
Structure to hold all command line Parameters.
void find_xml_file(String &filename, const Verbosity &verbosity)
Find an xml file.
ArrayOfString includepath
List of paths to search for include files.
This file contains the definition of Array.
ArrayOfString datapath
List of paths to search for data files.
String outdir
If this is specified (with the -o –outdir option), it is used as the base directory for the report f...
The global header file for ARTS.
void read_text_from_file(ArrayOfString &text, const String &name)
Reads an ASCII file and appends the contents to the String vector text.
Parameters parameters
Holds the command line parameters.
_CS_string_type str() const
void list_directory(ArrayOfString &files, String dirname)
Return list of files in directory.
Index nelem() const
Number of elements.
bool file_exists(const String &filename)
Checks if the given file exists.
String get_absolute_path(const String &filename)
Convert relative path to absolute path.
This can be used to make arrays out of anything.
void split(Array< my_basic_string< charT > > &aos, const my_basic_string< charT > &delim) const
Split string into substrings.
void open_input_file(ifstream &file, const String &name)
Open a file for reading.
void open_output_file(ofstream &file, const String &name)
Open a file for writing.
double_istream & operator>>(double &x)
bool find_xml_file_existence(String &filename)
As find_xml_file but does not throw in the main body.
void replace_all(String &s, const String &what, const String &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 read_text_from_stream(ArrayOfString &text, istream &is)
Read an ASCII stream and append the contents to the String array text.
String add_basedir(const String &path)
void make_filename_unique(String &filename, const String &extension)
Make filename unique.
int check_newline(const String &s)
Checks if there is exactly one newline character at the end of the string.
Input stream class for doubles that correctly handles nan and inf.
static const Index npos
Define npos:
This file contains header information for the dealing with command line parameters.
double_istream & parse_on_fail(double &x, bool neg)
Input manipulator class for doubles to enable nan and inf parsing.
my_basic_string< char > String
The String type for ARTS.