casacore
Loading...
Searching...
No Matches
ArrayStr.h
Go to the documentation of this file.
1#ifndef CASACORE_ARRAYSTR_H
2#define CASACORE_ARRAYSTR_H
3
4#include "Array.h"
5
6#include <istream>
7#include <ostream>
8
9namespace casacore {
10
11// Write out an ascii representation of an array of any dimensionality.
12// Arrays of dimensionality 3 or greater are written out vector by vector,
13// preceeded by the position of the start of the vector. If the origin of
14// the array isn't zero it is printed. The shape of the array is always
15// printed.
16template <typename T>
17std::ostream &operator<<(std::ostream &, const Array<T> &);
18
19// Read an ascii representation of an array. All types with an <src><<</src>
20// operator can be handled. The basic format of the input should be:
21// <srcblock>
22// [element element element ....]
23// </srcblock>
24// Elements are separated by whitespace, or a comma, optionally surrounded
25// by white space. <br>
26// <note role=warning> Some input routines read fields between blank spaces. This
27// is (at the moment) especially true for Quantities and Strings.
28// In those cases
29// the separator should be blank (or a comma following a blank), and the
30// end ']' should have a blank in front.
31// A crude fix for String arrays having separators <src>,</src> and <src>]</src>
32// without blanks preceding has been made; but slows routines down </note>
33// The default input is a vector of unspecified length. The input shape
34// can be changed by pre-pending the input with:
35// <srcblock>
36// {[shape]}
37// </srcblock>
38// where shape is an unsigned integer vector. The shape will be used to check
39// the input length; and, depending on the possibility, to resize/reshape the
40// result. However, reshaping of e.g. a Vector to a Matrix cannot be done, and
41// the result will stay in the form asked.<br>
42// Input order is row major, however by preceding the input with:
43// <srcblock>
44// {T[shape]}
45// </srcblock>
46// the order will be reversed.<br>
47// Reshaping of the Array provided will depend on the type of Array and its
48// state. If a general Array, the shape will be
49// as defined by user. If fixed Array (e.g. Matrix, Vector, Cube) the number
50// of dimesnsions will be kept. If the user specified more dimensions
51// then supported (e.g. 3 for Matrix), the last dimesions will be collapsed.
52// If less dimensions are specified, the missing ones will be set to 1.
53// will be kept.<br>
54// The read() version can be used to force a shape (ip), or an input
55// transpose (it) (which can be undone by the user specifying transpose).
56//
57// <group>
58template <typename T>
59std::istream &operator>>(std::istream &s, Array<T> &x);
60
61template <typename T>
62bool read(std::istream &s, Array<T> &x, const IPosition *ip = 0, bool it = false);
63// </group>
64
65// General read support function for matrices.
66// In principle these functions will not be
67// used by general user, but could be. They can be used by Array type
68// classes (like Slice, Lattice) to do the work of comparable input
69// functions as the one for Arrays.
70// In these functions p is the shape
71// of the returned Block x. This shape is either deduced from the user
72// specification; made equal to (1, nelements) if no user shape is
73// given; is set to ip if specified. The function will return false (and
74// p = (0)) in the case of an invalid input element; a number of elements
75// input not equal to ip (if specified); the shape given by user as input
76// does not conform to ip (if given) or the number of elements input.<br>
77// trans will be true if transpose asked by user; or if forced by it.
78template <typename T>
79bool readArrayBlock(std::istream &s, bool &trans, IPosition &p, std::vector<T> &x,
80 const IPosition *ip = 0, bool it = false);
81
82// <summary>
83// Global functions for Matrix/Vector input/output using ASCII format.
84// </summary>
85
86// <use visibility=export>
87
88// <prerequisite>
89// <li> <linkto class=Matrix>Matrix</linkto>
90// <li> <linkto class=Vector>Vector</linkto>
91// </prerequisite>
92
93// <synopsis>
94// These global functions support file I/O between ASCII files and
95// Matrices or Vectors.
96// </synopsis>
97
98// <example>
99// <srcblock>
100// Matrix<float> picture(256, 256); picture = 0.0;
101// String fileName="picture.data";
102//
103// // operations to populate picture
104// // ...
105//
106// writeAsciiMatrix (picture, fileName);
107// </srcblock>
108// </example>
109
110// <linkfrom anchor="Array Ascii IO" classes="Vector Matrix">
111// <here>Array Ascii IO</here> -- Simple Ascii input/output for Arrays.
112// </linkfrom>
113
114// <group name=Array Ascii IO>
115
116// These routines read and write a Matrix of data. The first line of
117// input will be examined to determine the number of columns in the matrix.
118// The maximum number of columns provided for is 100. Each item may be up
119// to 50 characters long.
120//
121// Each item must be separated from others by one (or more) blank column.
122// The "line" may be up to 1024 characters long. Each subsequent line must
123// contain the SAME number of items as the first line but may be any length
124// (up to 1024 characters).
125//
126// The matrix need NOT be square.
127//
128// The matrix should be declared but NOT dimensioned in the calling program.
129
130// <group>
131template <typename T>
132void readAsciiMatrix(Matrix<T> &mat, const char *fileName);
133
134template <typename T>
135void writeAsciiMatrix(const Matrix<T> &mat, const char *fileName);
136// </group>
137
138template <typename T>
139std::string to_string(const Array<T> array);
140
141} // namespace casacore
142
143#include "ArrayStr.tcc"
144
145#endif
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
friend AipsIO & operator>>(AipsIO &os, Record &rec)
Read the Record from an input stream.
Definition Record.h:431
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
virtual int read()
The read()' and write()' functions control reading and writing data from the external FITS I/O medium...
T * array
The actual storage.
Definition Block.h:689
std::string to_string(const IPosition &ip)