ARTS
2.2.66
|
This file contains basic functions to handle ASCII files. More...
#include <fstream>
#include "matpackI.h"
#include "mystring.h"
#include "messages.h"
#include "make_array.h"
Go to the source code of this file.
Classes | |
class | double_istream |
Input stream class for doubles that correctly handles nan and inf. More... | |
class | double_imanip |
Input manipulator class for doubles to enable nan and inf parsing. More... | |
Functions | |
void | filename_ascii (String &filename, const String &varname) |
Gives the default file name for the ASCII formats. More... | |
void | filename_bin (String &filename, const String &varname) |
void | open_output_file (std::ofstream &file, const String &name) |
void | cleanup_output_file (std::ofstream &file, const String &name) |
void | open_input_file (std::ifstream &file, const String &name) |
void | read_text_from_stream (ArrayOfString &text, std::istream &is) |
Read an ASCII stream and append the contents to the String array text. More... | |
void | read_text_from_file (ArrayOfString &text, const String &name) |
Reads an ASCII file and appends the contents to the String vector text. More... | |
void | replace_all (String &s, const String &what, const String &with) |
Replace all occurances of ‘what’ in ‘s’ with ‘with’. More... | |
int | check_newline (const String &s) |
Checks if there is exactly one newline character at the end of the string. More... | |
bool | file_exists (const String &filename) |
Checks if the given file exists. More... | |
bool | find_file (ArrayOfString &matches, const String &filename, const ArrayOfString &paths, const ArrayOfString &extensions=MakeArray< String >("")) |
Searches through paths for a file with a matching name. More... | |
void | find_xml_file (String &filename, const Verbosity &verbosity) |
Find an xml file. More... | |
String | expand_path (const String &path) |
String | add_basedir (const String &path) |
void | get_dirname (String &dirname, const String &path) |
Return the parent directory of a path. More... | |
void | list_directory (ArrayOfString &files, String dirname) |
Return list of files in directory. More... | |
void | make_filename_unique (String &filename, const String &extension="") |
Make filename unique. More... | |
const double_imanip & | operator>> (std::istream &in, const double_imanip &dm) |
Adds base directory to the given path if it is a relative path.
[in] | path | String with path |
Definition at line 530 of file file.cc.
References expand_path(), my_basic_string< charT >::nelem(), Parameters::outdir, and parameters.
Referenced by arts_exit(), nca_write_to_file(), open_output_file(), and xml_write_to_file().
int check_newline | ( | const String & | s | ) |
Checks if there is exactly one newline character at the end of the string.
s | The String to check. |
Definition at line 307 of file file.cc.
References replace_all().
Referenced by md_sanity_checks().
void cleanup_output_file | ( | std::ofstream & | file, |
const String & | name | ||
) |
Expands the ~ to home directory location in given path.
[in] | path | String with path |
Definition at line 506 of file file.cc.
References my_basic_string< charT >::nelem().
Referenced by add_basedir(), find_file(), nca_read_from_file(), open_input_file(), and operator>>().
bool file_exists | ( | const String & | filename | ) |
Checks if the given file exists.
filename | File to check. |
Definition at line 343 of file file.cc.
Referenced by find_file(), and make_filename_unique().
Gives the default file name for the ASCII formats.
The default name is only used if the file name is empty.
filename | Output: file name |
varname | variable name |
Definition at line 78 of file file.cc.
References out_basename.
bool find_file | ( | ArrayOfString & | matches, |
const String & | filename, | ||
const ArrayOfString & | paths, | ||
const ArrayOfString & | extensions | ||
) |
Searches through paths for a file with a matching name.
If the filename starts with '/', the search path is ignored.
[in,out] | matches | Matching files are appended to this list. |
[in] | filename | File to find. |
[in] | paths | List of paths to look in for the file. |
[in] | extensions | List of extensions to add to base filename. |
Definition at line 402 of file file.cc.
References expand_path(), file_exists(), get_absolute_path(), Array< base >::nelem(), and my_basic_string< charT >::nelem().
Referenced by find_xml_file(), open_input_file(), and ArtsParser::parse_agenda().
Find an xml file.
If it doesn't exist in the current directory, also search the include and data path. Also tests if a compressed version exists.
The filename will be modified to contain the full path to the found match.
[in,out] | filename | File to check. |
[in] | verbosity | Verbosity |
runtime_error | if file is not found. |
Definition at line 464 of file file.cc.
References CREATE_OUT1, Parameters::datapath, find_file(), Parameters::includepath, Array< base >::nelem(), and parameters.
Referenced by abs_speciesDefineAllInScenario(), xml_read_arts_catalogue_from_file(), and xml_read_from_file().
Return the parent directory of a path.
Extracts the parent directory part of the given path.
[out] | dirname | Parent directory of path |
[in] | path | Path |
Definition at line 553 of file file.cc.
References Array< base >::nelem(), my_basic_string< charT >::nelem(), and my_basic_string< charT >::split().
Referenced by get_parameters(), and ArtsParser::parse_agenda().
void list_directory | ( | ArrayOfString & | files, |
String | dirname | ||
) |
Return list of files in directory.
Returns list of all files in the given path.
[out] | files | List of files |
[in] | dirname | Parent directory of path |
Definition at line 581 of file file.cc.
Referenced by abs_cia_dataReadFromCIA().
Make filename unique.
Checks if a file (or a gzipped version of it) with the given name already exists und appends a unique number to the filename if necessary
[in,out] | filename | Filename |
[in] | extension | Optional, number is inserted before the extension |
Definition at line 612 of file file.cc.
References file_exists().
Referenced by xml_write_to_file().
void open_input_file | ( | std::ifstream & | file, |
const String & | name | ||
) |
void open_output_file | ( | std::ofstream & | file, |
const String & | name | ||
) |
const double_imanip& operator>> | ( | std::istream & | in, |
const double_imanip & | dm | ||
) |
Definition at line 135 of file file.cc.
References expand_path(), and double_imanip::in.
void read_text_from_file | ( | ArrayOfString & | text, |
const String & | name | ||
) |
Reads an ASCII file and appends the contents to the String vector text.
This uses the function
text | Output. The contents fo the file |
name | Name of file to read |
IOError |
Definition at line 252 of file file.cc.
References open_input_file(), and read_text_from_stream().
Referenced by SourceText::AppendFile().
void read_text_from_stream | ( | ArrayOfString & | text, |
istream & | is | ||
) |
Read an ASCII stream and append the contents to the String array text.
TEXT IS NOT OVERWRITTEN, BUT APPENDED!
text | Output. The contents fo the file |
is | Stream from which to read |
IOError | Some error occured during the read |
Definition at line 213 of file file.cc.
Referenced by read_text_from_file().
Replace all occurances of ‘what’ in ‘s’ with ‘with’.
s | Output. The String to act on. |
what | The String to replace. |
with | The replacement. |
Definition at line 286 of file file.cc.
References my_basic_string< charT >::npos.
Referenced by check_newline().