Go to the documentation of this file.
48 #include <sys/types.h>
114 file.exceptions(ios::badbit |
118 file.open(ename.c_str() );
129 os <<
"Cannot open output file: " << ename <<
'\n'
130 <<
"Maybe you don't have write access "
131 <<
"to the directory or the file?";
132 throw runtime_error(os.str());
148 streampos fpos = file.tellp();
173 allpaths.insert(allpaths.end(),
178 find_file(matching_files, ename, allpaths);
180 if (matching_files.
nelem()) ename = matching_files[0];
186 file.exceptions(ios::badbit);
189 file.open(ename.c_str() );
197 os <<
"Cannot open input file: " << ename <<
'\n'
198 <<
"Maybe the file does not exist?";
199 throw runtime_error(os.str());
221 while (is && is.good() && !is.eof())
224 getline(is,linebuffer);
227 text.push_back(linebuffer);
235 os <<
"Read Error. Last line read:\n" << linebuffer;
236 throw runtime_error(os.str());
268 catch (runtime_error x)
271 os <<
"Error reading file: " << name <<
'\n'
273 throw runtime_error(os.str());
288 Index j = s.find(what);
289 while ( j != s.
npos )
292 j = s.find(what,j+with.size());
317 const char *cp = d.c_str ();
318 while ((*cp ==
'\n') && *cp) cp++;
323 if (!result && d[d.length () - 1] !=
'\n')
325 else if (!result && d.length () > 2
326 && d[d.length () - 1] ==
'\n' && d[d.length () - 2] ==
'\n')
348 if (lstat(filename.c_str(), &st) >= 0
349 && !S_ISDIR(st.st_mode))
352 fin.open(filename.c_str(), ios::in);
376 fullrealpath = realpath(filename.c_str(), NULL);
379 String retpath(fullrealpath);
410 || (efilename.
nelem() && efilename[0] ==
'/'))
412 for (ArrayOfString::const_iterator ext = extensions.begin();
413 ext != extensions.end(); ext++)
419 if (std::find(matches.begin(), matches.end(), fullpath) == matches.end())
420 matches.push_back(fullpath);
428 for (ArrayOfString::const_iterator path = paths.begin(); path != paths.end(); path++)
430 for (ArrayOfString::const_iterator ext = extensions.begin();
431 ext != extensions.end(); ext++)
437 if (std::find(matches.begin(), matches.end(), fullpath) == matches.end())
438 matches.push_back(fullpath);
469 allpaths.insert(allpaths.end(),
476 if (matching_files.
nelem() > 1)
479 out1 <<
" WARNING: More than one file matching this name exists in the data path.\n"
480 <<
" Using the first file (1) found:\n";
481 for (
Index i = 0; i < matching_files.
nelem(); i++)
482 out1 <<
" (" << i+1 <<
") " << matching_files[i] <<
"\n";
484 else if (!matching_files.
nelem())
487 os <<
"Cannot find input file: " << filename << endl;
488 os <<
"Search path: " << allpaths << endl;
489 throw runtime_error(os.str());
492 filename = matching_files[0];
508 if ((path.
nelem() == 1 && path[0] ==
'~')
509 || (path.
nelem() > 1 && path[0] ==
'~' && path[1] ==
'/'))
540 return expanded_path;
556 if (!path.
nelem())
return;
559 path.
split(fileparts,
"/");
560 if (path[0] ==
'/') dirname =
"/";
561 if (fileparts.
nelem() > 1)
563 for(
Index i = 0; i < fileparts.
nelem()-1; i++)
565 dirname += fileparts[i];
566 if (i < fileparts.
nelem()-2) dirname +=
"/";
585 if((dp = opendir(dirname.c_str())) == NULL)
588 os <<
"Error(" << errno <<
") opening " << dirname << endl;
589 throw runtime_error(os.str());
592 while ((dirp = readdir(dp)) != NULL)
594 files.push_back(
String(dirp->d_name));
614 String basename = filename;
618 if (extension.length())
620 size_t pos = filename.rfind(extension);
621 if (pos == filename.length() - extension.length())
623 basename = filename.substr(0, filename.length() - extension.length());
624 extensionname = extension;
628 Index filenumber = 0;
629 ostringstream newfilename;
630 newfilename << basename << extensionname;
637 newfilename << basename <<
"." << filenumber << extensionname;
640 filename = newfilename.str();
650 const char *exp[] = {
"",
"inf",
"Inf",
"nan",
"NaN" };
651 const char *e = exp[0];
657 if (!(
in >> *c).good())
return *
this;
659 case 'i': e = exp[l=1];
break;
660 case 'I': e = exp[l=2];
break;
661 case 'n': e = exp[l=3];
break;
662 case 'N': e = exp[l=4];
break;
665 if ((e-exp[l]) == 2)
break;
666 ++e;
if (!(
in >> *++c).good())
break;
668 if (
in.good() && *c == *e) {
671 case 2: x = std::numeric_limits<double>::infinity();
break;
673 case 4: x = std::numeric_limits<double>::quiet_NaN();
break;
677 }
else if (!
in.good()) {
678 if (!
in.fail())
return *
this;
681 do {
in.putback(*c); }
while (c-- != inf);
682 in.setstate(std::ios_base::failbit);
String outdir
If this is specified (with the -o –outdir option), it is used as the base directory for the report fi...
Structure to hold all command line Parameters.
void cleanup_output_file(ofstream &, const String &)
Closes the file.
void open_input_file(ifstream &file, const String &name)
Open a file for reading.
void get_dirname(String &dirname, const String &path)
Return the parent directory of a path.
This file contains the definition of Array.
const double_imanip & operator>>(std::istream &in, const double_imanip &dm)
This can be used to make arrays out of anything.
void read_text_from_stream(ArrayOfString &text, istream &is)
Read an ASCII stream and append the contents to the String array text.
The implementation for String, the ARTS string class.
String get_absolute_path(const String &filename)
Convert relative path to absolute path.
Input manipulator class for doubles to enable nan and inf parsing.
void find_xml_file(String &filename, const Verbosity &verbosity)
Find an xml file.
void make_filename_unique(String &filename, const String &extension)
Make filename unique.
bool file_exists(const String &filename)
Checks if the given file exists.
This file contains header information for the dealing with command line parameters.
String out_basename
The basename for the report file and for all other output files.
void open_output_file(ofstream &file, const String &name)
Open a file for writing.
Index nelem() const
Number of elements.
void list_directory(ArrayOfString &files, String dirname)
Return list of files in directory.
void split(Array< my_basic_string< charT > > &aos, const my_basic_string< charT > &delim) const
Split string into substrings.
void read_text_from_file(ArrayOfString &text, const String &name)
Reads an ASCII file and appends the contents to the String vector text.
String expand_path(const String &path)
Parameters parameters
Holds the command line parameters.
my_basic_string< char > String
The String type for ARTS.
int check_newline(const String &s)
Checks if there is exactly one newline character at the end of the string.
void filename_ascii(String &filename, const String &varname)
Gives the default file name for the ASCII formats.
Input stream class for doubles that correctly handles nan and inf.
String add_basedir(const String &path)
This file contains basic functions to handle ASCII files.
double_istream & parse_on_fail(double &x, bool neg)
Explicit construction of Arrays.
INDEX Index
The type to use for all integer numbers and indices.
static const Index npos
Define npos:
ArrayOfString includepath
List of paths to search for include files.
ArrayOfString datapath
List of paths to search for data files.
Index nelem() const
Number of elements.
The global header file for ARTS.
bool find_file(ArrayOfString &matches, const String &filename, const ArrayOfString &paths, const ArrayOfString &extensions)
Searches through paths for a file with a matching name.
void replace_all(String &s, const String &what, const String &with)
Replace all occurances of ‘what’ in ‘s’ with ‘with’.