ARTS  1.0.222
Functions
file.h File Reference

This file contains basic functions to handle ASCII and binary (HDF) data files. More...

#include <fstream>
#include "matpackI.h"
#include "mystring.h"
#include "absorption.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. More...
 
void filename_bin (String &filename, const String &varname)
 
void open_output_file (ofstream &file, const String &name)
 Open a file for writing. More...
 
void open_input_file (ifstream &file, const String &name)
 Open a file for reading. More...
 
void read_text_from_stream (ArrayOfString &text, 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...
 
void write_array_of_matrix_to_stream (ostream &os, const ArrayOfMatrix &am)
 A helper function that writes an array of matrix to a stream. More...
 
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. More...
 
void read_array_of_matrix_from_stream (ArrayOfMatrix &am, istream &is)
 A helper function that reads an array of matrix from a stream. More...
 
void read_array_of_matrix_from_file (ArrayOfMatrix &am, const String &filename)
 A helper function that reads an array of matrix from a file. More...
 
void write_array_of_String_to_stream (ostream &os, const ArrayOfString &as)
 A helper function that writes an array of String to a stream. More...
 
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. More...
 
void read_array_of_String_from_stream (ArrayOfString &as, istream &is)
 A help function to read an array of String from a stream. More...
 
void read_array_of_String_from_file (ArrayOfString &as, const String &filename)
 A help function to read an array of String from a file. More...
 
void write_tag_groups_species_to_stream (ostream &os, const TagGroups &tgs)
 A helper function that writes an array of String to a stream. More...
 
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. More...
 
void binfile_open_out (int &fid, const String &filename)
 
void binfile_open_in (int &fid, const String &filename)
 
void binfile_close (int &fid, const String &filename)
 
void binfile_write_index (const String &filename, const int &fid, const Index &x, const String &dataname)
 
void binfile_read_index (Index &x, const String &filename, const int &fid, const String &dataname)
 
void binfile_write_numeric (const String &filename, const int &fid, const Numeric &x, const String &dataname)
 
void binfile_read_numeric (Numeric &x, const String &filename, const int &fid, const String &dataname)
 
void binfile_write_vector (const String &filename, const int &fid, const Vector &x, const String &dataname)
 
void binfile_read_vector (Vector &x, const String &filename, const int &fid, const String &dataname)
 
void binfile_write_matrix (const String &filename, const int &fid, const Matrix &x, const String &dataname)
 
void binfile_read_matrix (Matrix &x, const String &filename, const int &fid, const String &dataname)
 
void binfile_write_indexarray (const String &filename, const int &fid, const ArrayOfIndex &x, const String &dataname)
 
void binfile_read_indexarray (ArrayOfIndex &x, const String &filename, const int &fid, const String &dataname)
 
void binfile_write_vectorarray (const String &filename, const int &fid, const ArrayOfVector &x, const String &dataname)
 
void binfile_read_vectorarray (ArrayOfVector &x, const String &filename, const int &fid, const String &dataname)
 
void binfile_write_matrixarray (const String &filename, const int &fid, const ArrayOfMatrix &x, const String &dataname)
 
void binfile_read_matrixarray (ArrayOfMatrix &x, const String &filename, const int &fid, const String &dataname)
 
void binfile_write_String (const String &filename, const int &fid, const String &s, const String &dataname)
 
void binfile_read_String (String &x, const String &filename, const int &fid, const String &dataname)
 
void binfile_write_Stringarray (const String &filename, const int &fid, const ArrayOfString &x, const String &dataname)
 
void binfile_read_Stringarray (ArrayOfString &x, const String &filename, const int &fid, const String &dataname)
 

Detailed Description

This file contains basic functions to handle ASCII and binary (HDF) data files.

Author
Patrick Eriksson
Date
2000-10-28

Definition in file file.h.

Function Documentation

◆ binfile_close()

void binfile_close ( int &  fid,
const String filename 
)

◆ binfile_open_in()

void binfile_open_in ( int &  fid,
const String filename 
)

◆ binfile_open_out()

void binfile_open_out ( int &  fid,
const String filename 
)

◆ binfile_read_index()

void binfile_read_index ( Index x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_read_indexarray()

void binfile_read_indexarray ( ArrayOfIndex x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_read_matrix()

void binfile_read_matrix ( Matrix x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_read_matrixarray()

void binfile_read_matrixarray ( ArrayOfMatrix x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_read_numeric()

void binfile_read_numeric ( Numeric x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_read_String()

void binfile_read_String ( String x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_read_Stringarray()

void binfile_read_Stringarray ( ArrayOfString x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_read_vector()

void binfile_read_vector ( Vector x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_read_vectorarray()

void binfile_read_vectorarray ( ArrayOfVector x,
const String filename,
const int &  fid,
const String dataname 
)

◆ binfile_write_index()

void binfile_write_index ( const String filename,
const int &  fid,
const Index x,
const String dataname 
)

◆ binfile_write_indexarray()

void binfile_write_indexarray ( const String filename,
const int &  fid,
const ArrayOfIndex x,
const String dataname 
)

◆ binfile_write_matrix()

void binfile_write_matrix ( const String filename,
const int &  fid,
const Matrix x,
const String dataname 
)

◆ binfile_write_matrixarray()

void binfile_write_matrixarray ( const String filename,
const int &  fid,
const ArrayOfMatrix x,
const String dataname 
)

◆ binfile_write_numeric()

void binfile_write_numeric ( const String filename,
const int &  fid,
const Numeric x,
const String dataname 
)

◆ binfile_write_String()

void binfile_write_String ( const String filename,
const int &  fid,
const String s,
const String dataname 
)

◆ binfile_write_Stringarray()

void binfile_write_Stringarray ( const String filename,
const int &  fid,
const ArrayOfString x,
const String dataname 
)

◆ binfile_write_vector()

void binfile_write_vector ( const String filename,
const int &  fid,
const Vector x,
const String dataname 
)

◆ binfile_write_vectorarray()

void binfile_write_vectorarray ( const String filename,
const int &  fid,
const ArrayOfVector x,
const String dataname 
)

◆ filename_ascii()

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
filenamefile name
Parameters
varnamevariable name
Author
Patrick Eriksson
Date
2000-11-01

Definition at line 64 of file file.cc.

◆ filename_bin()

void filename_bin ( String filename,
const String varname 
)

◆ open_input_file()

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
fileFile pointer
nameName of the file to open
Author
Stefan Buehler
Version
1
Exceptions
ios_base::failureSomehow the file cannot be opened.

Definition at line 130 of file file.cc.

◆ open_output_file()

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
fileFile pointer
nameName of the file to open
Author
Stefan Buehler
Version
1
Exceptions
ios_base::failureCould for example mean that the directory is read only.

Definition at line 91 of file file.cc.

◆ read_array_of_matrix_from_file()

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
amOutput. The array of matrix to read.
filenameThe name of the file to read.
Author
Stefan Buehler

Definition at line 425 of file file.cc.

◆ read_array_of_matrix_from_stream()

void read_array_of_matrix_from_stream ( ArrayOfMatrix am,
istream &  is 
)

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

Parameters
amOutput. The array of matrix to read.
isOutput. The input stream.
Author
Stefan Buehler

Definition at line 371 of file file.cc.

◆ read_array_of_String_from_file()

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
asThe array of String to read
Parameters
filenameThe name of the file to read
Author
Patrick Eriksson
Date
2000-11-04

Definition at line 582 of file file.cc.

◆ read_array_of_String_from_stream()

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
asThe array of String to read
Parameters
isThe input stream
Author
Patrick Eriksson
Date
2000-11-04

Definition at line 522 of file file.cc.

◆ read_text_from_file()

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
textOutput. The contents fo the file
filenameName of file to read
Exceptions
IOError
Version
1
Author
Stefan Buehler

Definition at line 206 of file file.cc.

◆ read_text_from_stream()

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
textOutput. The contents fo the file
isStream from which to read
Exceptions
IOErrorSome error occured during the read
Version
1
Author
Stefan Buehler

Definition at line 165 of file file.cc.

◆ replace_all()

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

Replace all occurances of ‘what’ in ‘s’ with ‘with’.

Parameters
sOutput. The String to act on.
whatThe String to replace.
withThe replacement.
Author
Stefan Buehler

Definition at line 242 of file file.cc.

◆ write_array_of_matrix_to_file()

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
filenameThe name of the file.
amThe array of matrix to write.
Author
Stefan Buehler

Definition at line 322 of file file.cc.

◆ write_array_of_matrix_to_stream()

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
osOutput. The stream to write to.
amThe matrix to write.
Author
Stefan Buehler

Definition at line 268 of file file.cc.

◆ write_array_of_String_to_file()

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
filenameThe name of the file.
Parameters
asThe array of String to write.
Author
Patrick Eriksson
Date
2000-11-04

Definition at line 497 of file file.cc.

◆ write_array_of_String_to_stream()

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
osthe stream to write to
Parameters
asthe String array to write
Author
Patrick Eriksson
Date
2000-11-04

Definition at line 469 of file file.cc.

◆ write_tag_groups_species_to_file()

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
filenameThe name of the file.
Parameters
tgsThe tag groups to write.
Author
Viju + Oliver
Date
2005-05-02

Definition at line 656 of file file.cc.

◆ write_tag_groups_species_to_stream()

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
osthe stream to write to
Parameters
tgsthe tag groups to write
Author
Viju + Oliver
Date
2005-05-02

Definition at line 621 of file file.cc.