file.cc File Reference

This file contains basic functions to handle ASCII data files. More...

#include <stdexcept>
#include <math.h>
#include <cfloat>
#include "arts.h"
#include "matpackI.h"
#include "array.h"
#include "messages.h"
#include "file.h"

Go to the source code of this file.

Functions

void filename_ascii (String &filename, const String &varname)
 Gives the default file name for the ASCII formats.
void open_output_file (ofstream &file, const String &name)
 Open a file for writing.
void open_input_file (ifstream &file, const String &name)
 Open a file for reading.
void read_text_from_stream (ArrayOfString &text, istream &is)
 Read an ASCII stream and append the contents to the String array text.
void read_text_from_file (ArrayOfString &text, const String &name)
 Reads an ASCII file and appends the contents to the String vector text.
void replace_all (String &s, const String &what, const String &with)
 Replace all occurances of `what' in `s' with `with'.
void write_array_of_matrix_to_stream (ostream &os, const ArrayOfMatrix &am)
 A helper function that writes an array of matrix to a stream.
void write_array_of_matrix_to_file (const String &filename, const ArrayOfMatrix &am)
 A helper function that writes an array of matrix to a file.
void skip_comments (istream &is)
 A helper function that skips lines containing comments.
void read_array_of_matrix_from_stream (ArrayOfMatrix &am, istream &is)
 A helper function that reads an array of matrix from a stream.
void read_array_of_matrix_from_file (ArrayOfMatrix &am, const String &filename)
 A helper function that reads an array of matrix from a file.
void write_array_of_String_to_stream (ostream &os, const ArrayOfString &as)
 A helper function that writes an array of String to a stream.
void write_array_of_String_to_file (const String &filename, const ArrayOfString &as)
 A help function that writes an array of String to a file.
void read_array_of_String_from_stream (ArrayOfString &as, istream &is)
 A help function to read an array of String from a stream.
void read_array_of_String_from_file (ArrayOfString &as, const String &filename)
 A help function to read an array of String from a file.
void write_tag_groups_species_to_stream (ostream &os, const TagGroups &tgs)
 A helper function that writes an array of String to a stream.
void write_tag_groups_species_to_file (const String &filename, const TagGroups &tgs)
 A help function that writes an array of String to a file.


Detailed Description

This file contains basic functions to handle ASCII data files.

Author:
Patrick Eriksson
Date:
2000-10-28

Definition in file file.cc.


Function Documentation

void filename_ascii ( String filename,
const String varname 
)

Gives the default file name for the ASCII formats.

The default name is only used if the file name is empty.

Return values:
filename file name
Parameters:
varname variable name
Author:
Patrick Eriksson
Date:
2000-11-01

Definition at line 64 of file file.cc.

void open_input_file ( ifstream &  file,
const String name 
)

Open a file for reading.

If the file cannot be opened, the exception IOError is thrown.

Parameters:
file File pointer
name Name of the file to open
Author:
Stefan Buehler
Version:
1
Exceptions:
ios_base::failure Somehow the file cannot be opened.

Definition at line 130 of file file.cc.

void open_output_file ( ofstream &  file,
const String name 
)

Open a file for writing.

If the file cannot be opened, the exception IOError is thrown.

Parameters:
file File pointer
name Name of the file to open
Author:
Stefan Buehler
Version:
1
Exceptions:
ios_base::failure Could for example mean that the directory is read only.

Definition at line 91 of file file.cc.

void read_array_of_matrix_from_file ( ArrayOfMatrix am,
const String filename 
)

A helper function that reads an array of matrix from a file.

Uses read_array_of_matrix_from_stream.

Parameters:
am Output. The array of matrix to read.
filename The name of the file to read.
Author:
Stefan Buehler

Definition at line 425 of file file.cc.

void read_array_of_matrix_from_stream ( ArrayOfMatrix am,
istream &  is 
)

A helper function that reads an array of matrix from a stream.

Parameters:
am Output. The array of matrix to read.
is Output. The input stream.
Author:
Stefan Buehler

Definition at line 371 of file file.cc.

void read_array_of_String_from_file ( ArrayOfString as,
const String filename 
)

A help function to read an array of String from a file.

Return values:
as The array of String to read
Parameters:
filename The name of the file to read
Author:
Patrick Eriksson
Date:
2000-11-04

Definition at line 582 of file file.cc.

void read_array_of_String_from_stream ( ArrayOfString as,
istream &  is 
)

A help function to read an array of String from a stream.

Return values:
as The array of String to read
Parameters:
is The input stream
Author:
Patrick Eriksson
Date:
2000-11-04

Definition at line 522 of file file.cc.

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

See also:
read_text_from_stream. TEXT IS NOT OVERWRITTEN, BUT APPENDED!
Parameters:
text Output. The contents fo the file
filename Name of file to read
Exceptions:
IOError 
Version:
1
Author:
Stefan Buehler

Definition at line 206 of file file.cc.

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!

Parameters:
text Output. The contents fo the file
is Stream from which to read
Exceptions:
IOError Some error occured during the read
Version:
1
Author:
Stefan Buehler

Definition at line 165 of file file.cc.

void replace_all ( String s,
const String what,
const String with 
)

Replace all occurances of `what' in `s' with `with'.

Parameters:
s Output. The String to act on.
what The String to replace.
with The replacement.
Author:
Stefan Buehler

Definition at line 242 of file file.cc.

void skip_comments ( istream &  is  ) 

A helper function that skips lines containing comments.

Comments are all lines that have a # at the beginning. (Maybe preceded by whitespace.

Parameters:
is The input stream.
Author:
Stefan Buehler
Date:
2001-11-09

Definition at line 343 of file file.cc.

void write_array_of_matrix_to_file ( const String filename,
const ArrayOfMatrix am 
)

A helper function that writes an array of matrix to a file.

Uses write_array_of_matrix_to_stream.

Parameters:
filename The name of the file.
am The array of matrix to write.
Author:
Stefan Buehler

Definition at line 322 of file file.cc.

void write_array_of_matrix_to_stream ( ostream &  os,
const ArrayOfMatrix am 
)

A helper function that writes an array of matrix to a stream.

This is the generic output function for Vectors, Matrixs, and ArrayOf both. All these are converted first to ArrayOfMatrix, and then written by this function.

Parameters:
os Output. The stream to write to.
am The matrix to write.
Author:
Stefan Buehler

Definition at line 268 of file file.cc.

void write_array_of_String_to_file ( const String filename,
const ArrayOfString as 
)

A help function that writes an array of String to a file.

Return values:
filename The name of the file.
Parameters:
as The array of String to write.
Author:
Patrick Eriksson
Date:
2000-11-04

Definition at line 497 of file file.cc.

void write_array_of_String_to_stream ( ostream &  os,
const ArrayOfString as 
)

A helper function that writes an array of String to a stream.

Return values:
os the stream to write to
Parameters:
as the String array to write
Author:
Patrick Eriksson
Date:
2000-11-04

Definition at line 469 of file file.cc.

void write_tag_groups_species_to_file ( const String filename,
const TagGroups tgs 
)

A help function that writes an array of String to a file.

Return values:
filename The name of the file.
Parameters:
tgs The tag groups to write.
Author:
Viju + Oliver
Date:
2005-05-02

Definition at line 656 of file file.cc.

void write_tag_groups_species_to_stream ( ostream &  os,
const TagGroups tgs 
)

A helper function that writes an array of String to a stream.

Return values:
os the stream to write to
Parameters:
tgs the tag groups to write
Author:
Viju + Oliver
Date:
2005-05-02

Definition at line 621 of file file.cc.


Generated on Wed Feb 4 08:17:23 2009 for ARTS by  doxygen 1.5.6