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,
63 const IPosition *ip=0, bool it=false);
64// </group>
65
66// General read support function for matrices.
67// In principle these functions will not be
68// used by general user, but could be. They can be used by Array type
69// classes (like Slice, Lattice) to do the work of comparable input
70// functions as the one for Arrays.
71// In these functions p is the shape
72// of the returned Block x. This shape is either deduced from the user
73// specification; made equal to (1, nelements) if no user shape is
74// given; is set to ip if specified. The function will return false (and
75// p = (0)) in the case of an invalid input element; a number of elements
76// input not equal to ip (if specified); the shape given by user as input
77// does not conform to ip (if given) or the number of elements input.<br>
78// trans will be true if transpose asked by user; or if forced by it.
79template<typename T> bool readArrayBlock(std::istream &s, bool &trans,
80 IPosition &p,
81 std::vector<T> &x,
82 const IPosition *ip=0, bool it=false);
83
84// <summary>
85// Global functions for Matrix/Vector input/output using ASCII format.
86// </summary>
87
88// <use visibility=export>
89
90// <prerequisite>
91// <li> <linkto class=Matrix>Matrix</linkto>
92// <li> <linkto class=Vector>Vector</linkto>
93// </prerequisite>
94
95// <synopsis>
96// These global functions support file I/O between ASCII files and
97// Matrices or Vectors.
98// </synopsis>
99
100// <example>
101// <srcblock>
102// Matrix<float> picture(256, 256); picture = 0.0;
103// String fileName="picture.data";
104//
105// // operations to populate picture
106// // ...
107//
108// writeAsciiMatrix (picture, fileName);
109// </srcblock>
110// </example>
111
112// <linkfrom anchor="Array Ascii IO" classes="Vector Matrix">
113// <here>Array Ascii IO</here> -- Simple Ascii input/output for Arrays.
114// </linkfrom>
115
116// <group name=Array Ascii IO>
117
118// These routines read and write a Matrix of data. The first line of
119// input will be examined to determine the number of columns in the matrix.
120// The maximum number of columns provided for is 100. Each item may be up
121// to 50 characters long.
122//
123// Each item must be separated from others by one (or more) blank column.
124// The "line" may be up to 1024 characters long. Each subsequent line must
125// contain the SAME number of items as the first line but may be any length
126// (up to 1024 characters).
127//
128// The matrix need NOT be square.
129//
130// The matrix should be declared but NOT dimensioned in the calling program.
131
132// <group>
133template <typename T>
134void readAsciiMatrix (Matrix<T>& mat, const char* fileName);
135
136template <typename T>
137void writeAsciiMatrix (const Matrix<T>& mat, const char* fileName);
138// </group>
139
140template<typename T>
141std::string to_string(const Array<T> array);
142
143}
144
145#include "ArrayStr.tcc"
146
147#endif
this file contains all the compiler specific defines
Definition mainpage.dox:28
AipsIO & operator>>(AipsIO &os, Record &rec)
Definition Record.h:462
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition ExprNode.h:1933
std::string to_string(const IPosition &ip)