casacore
Loading...
Searching...
No Matches
ArrayIO.h
Go to the documentation of this file.
1//# ArrayIO.h: text output and binary IO for an array of any dimensionality.
2//# Copyright (C) 1993,1994,1995,1997,1999,2000,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_ARRAYIO_2_H
27#define CASA_ARRAYIO_2_H
28
29//# Includes
30#include <vector>
31#include <ostream>
32#include <regex>
33
34#include <casacore/casa/Arrays/ArrayFwd.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38class AipsIO;
39class LogIO;
40class IPosition;
41template<typename T> class Block;
42class String;
43
44// <summary>
45// Input/output operators for Arrays.
46// </summary>
47
48// <use visibility=export>
49
50// <reviewed reviewer="Paul Shannon" date="1995/02/21" tests="" demos="">
51// This header was reviewed and revised with the goal of making it an
52// example for those writing global function header files.
53// </reviewed>
54
55// <prerequisite>
56// <li> <linkto class=Array>Array</linkto>
57// <li> ostream
58// <li> <linkto class=AipsIO>AipsIO</linkto>
59// </prerequisite>
60
61// <etymology>
62// ArrayIO is simply the conventional shorthand for "array input/output".
63// </etymology>
64
65// <synopsis>
66// These global functions provide easy input and output of (possibly)
67// large and (possibly) multi-dimensional arrays. Iteration through
68// entire arrays is done behind the scenes, with no effort required
69// of the client programmer.
70// These functions are global, rather than member functions of the
71// Array class, because of the well-known C++ requirement that the first
72// argument to an operator function (as it is declared) is the
73// left operand when the function is called.
74// </synopsis>
75
76
77// <example>
78// <srcblock>
79// IPosition shape (3,10,10,3);
80// Array <float> array (shape);
81// // ...initialize and manipulate the array...
82// cout << "result: " << array;
83// </srcblock>
84//
85// <motivation>
86// Effortless input/output is clearly a big win.
87// </motivation>
88//
89// <todo asof="1997/01/15">
90// </todo>
91
92// <linkfrom anchor="Array IO" classes="Array Vector Matrix Cube">
93// <here>Array IO</here> -- Input/output operators for Arrays.
94// </linkfrom>
95//
96// <group name="Array IO">
98// Write a formatted copy of the array to the LogIO output object. Merely calls
99// the ostream operator<< in turn.
100template<typename T, typename Alloc>
102
103// Read or write a binary representation of an Array to a file. Very
104// useful for saving arrays and restoring them later.
105// <br>The putArray function is put in for forwards compatibility
106// of images (so new images can be read with old release).
107//
108// <group>
109
110template<typename T, typename Alloc>
112
113template<typename T, typename Alloc>
114void putArray (AipsIO &, const Array<T> &, const char* name);
115
116template<typename T, typename Alloc>
118
119// </group>
120
121// </group>
122
123// <summary>
124// Global functions to read/write binary arrays from/to a file.
125// </summary>
126
127// <use visibility=export>
128
129// <reviewed reviewer="Gareth Hunt" date="95Mar31" tests="" demos="">
130// </reviewed>
131
132// <synopsis>
133// These global functions provide disk read/write functions for an Array of
134// binary numbers. The write operation is useful, for example, to dump an
135// image in binary form to disk so that it can be displayed with an external
136// utility such as SAOimage.
137// </synopsis>
138
139// <example>
140// <srcblock>
141// Matrix<float> picture(256, 256); picture = 0.0;
142// String fileName="picture.data";
143//
144// // operations to populate picture
145// // ...
146//
147// write_array (picture, fileName);
148// </srcblock>
149// </example>
150
151// <todo asof="">
152// <li> These functions should eventually be replaced with something
153// more sophisticated.
154// </todo>
155
156// <linkfrom anchor="Array binary IO" classes="Array Vector Matrix Cube">
157// <here>Array binary IO</here> -- Simple binary input/output for Arrays.
158// </linkfrom>
159
160// <group name=Array binary IO>
162// Write the values of an array in binary format into a file with
163// the given name.
164// The values are stored in local format, thus are not converted
165// to a canonical format as
166// <linkto class="AipsIO:description">AipsIO</linkto>
167// does.
168// <note role=warning>
169// This function is only suitable for built-in data types.
170// </note>
171// <group>
172template <typename T, typename Alloc>
173void write_array (const Array<T>& the_array, const std::string& fileName);
174
175template <typename T, typename Alloc>
176inline void write_array (const Array<T>& the_array, const char* fileName)
177 { write_array (the_array, std::string(fileName)); }
178// </group>
179
180// Read the values of an array in binary format from a file with
181// the given name.
182// The number of values read is the size of the Array, thus the file
183// should at least contain that number of values.
184// <note role=warning>
185// This function is only suitable for built-in data types.
186// </note>
187// <group>
188template <typename T, typename Alloc>
189void read_array (Array<T>& the_array, const std::string& fileName);
190
191template <typename T, typename Alloc>
192inline void read_array (Array<T>& the_array, const char* fileName)
193 { read_array (the_array, std::string(fileName)); }
194// </group>
195
196// </group>
197
198// These two functions read and write a Vector of data. The input
199// may be arranged in any format (i.e. It may be recorded as one value per
200// line or it may be recorded with all values on a single line).
201// Values must be separated by whitespace.
202
203// <group>
204template <typename T, typename Alloc>
205void readAsciiVector (Vector<T>& vec, const char* fileName);
206
207template <typename T, typename Alloc>
208void writeAsciiVector (const Vector<T>& vec, const char* fileName);
209// </group>
210
211// </group>
212
213AipsIO& operator<< (AipsIO& aio, const IPosition& ip);
214AipsIO& operator>> (AipsIO& aio, IPosition& ip);
215LogIO& operator<< (LogIO& os, const IPosition& ip);
216
217template<typename T, typename Alloc>
218Block<T> makeBlock(const Array<T>& array);
219
220template<typename T>
221Vector<T> makeVector(const Block<T>& block);
222
223Vector<String> stringToVector (const String& string, char delim = ',');
224Vector<String> stringToVector (const String& string, const std::regex& delim);
225
226} //# NAMESPACE CASACORE - END
227
228#include <casacore/casa/IO/ArrayIO.tcc>
229
230#endif
AipsIO & operator<<(AipsIO &aio, const IPosition &ip)
AipsIO & operator>>(AipsIO &aio, IPosition &ip)
Vector< T > makeVector(const Block< T > &block)
Vector< String > stringToVector(const String &string, char delim=',')
Block< T > makeBlock(const Array< T > &array)
this file contains all the compiler specific defines
Definition mainpage.dox:28
void readAsciiVector(Vector< T > &vec, const char *fileName)
These two functions read and write a Vector of data.
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
void writeAsciiVector(const Vector< T > &vec, const char *fileName)
LogIO & operator<<(LogIO &os, const Array< T > &a)
Write a formatted copy of the array to the LogIO output object.
void putArray(AipsIO &, const Array< T > &, const char *name)
AipsIO & operator>>(AipsIO &, Array< T > &)
Global functions to read/write binary arrays from/to a file.
Definition ArrayIO.h:161
void write_array(const Array< T > &the_array, const char *fileName)
Definition ArrayIO.h:176
void write_array(const Array< T > &the_array, const std::string &fileName)
Write the values of an array in binary format into a file with the given name.
void read_array(Array< T > &the_array, const char *fileName)
Definition ArrayIO.h:192
void read_array(Array< T > &the_array, const std::string &fileName)
Read the values of an array in binary format from a file with the given name.