//# ArrayIO.h: text output and binary IO for an array of any dimensionality. //# Copyright (C) 1993,1994,1995,1997,1999,2000,2001 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 of the License, or (at your //# option) any later version. //# //# This library is distributed in the hope that it will be useful, but WITHOUT //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# charlottesville, VA 22903-2475 USA //# //# $Id$ #ifndef CASA_ARRAYIO_2_H #define CASA_ARRAYIO_2_H //# Includes #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN class AipsIO; class LogIO; class IPosition; template class Block; class String; // // Input/output operators for Arrays. // // // // This header was reviewed and revised with the goal of making it an // example for those writing global function header files. // // //
  • Array //
  • ostream //
  • AipsIO // // // ArrayIO is simply the conventional shorthand for "array input/output". // // // These global functions provide easy input and output of (possibly) // large and (possibly) multi-dimensional arrays. Iteration through // entire arrays is done behind the scenes, with no effort required // of the client programmer. // These functions are global, rather than member functions of the // Array class, because of the well-known C++ requirement that the first // argument to an operator function (as it is declared) is the // left operand when the function is called. // // // // IPosition shape (3,10,10,3); // Array array (shape); // // ...initialize and manipulate the array... // cout << "result: " << array; // // // // Effortless input/output is clearly a big win. // // // // // // Array IO -- Input/output operators for Arrays. // // // // Write a formatted copy of the array to the LogIO output object. Merely calls // the ostream operator<< in turn. template LogIO &operator<<(LogIO &os, const Array &a); // Read or write a binary representation of an Array to a file. Very // useful for saving arrays and restoring them later. //
    The putArray function is put in for forwards compatibility // of images (so new images can be read with old release). // // template AipsIO &operator<< (AipsIO &, const Array &); template void putArray (AipsIO &, const Array &, const char* name); template AipsIO &operator>> (AipsIO &, Array &); // //
    // // Global functions to read/write binary arrays from/to a file. // // // // // // These global functions provide disk read/write functions for an Array of // binary numbers. The write operation is useful, for example, to dump an // image in binary form to disk so that it can be displayed with an external // utility such as SAOimage. // // // // Matrix picture(256, 256); picture = 0.0; // String fileName="picture.data"; // // // operations to populate picture // // ... // // write_array (picture, fileName); // // // //
  • These functions should eventually be replaced with something // more sophisticated. // // // Array binary IO -- Simple binary input/output for Arrays. // // // Write the values of an array in binary format into a file with // the given name. // The values are stored in local format, thus are not converted // to a canonical format as // AipsIO // does. // // This function is only suitable for built-in data types. // // template void write_array (const Array& the_array, const std::string& fileName); template inline void write_array (const Array& the_array, const char* fileName) { write_array (the_array, std::string(fileName)); } // // Read the values of an array in binary format from a file with // the given name. // The number of values read is the size of the Array, thus the file // should at least contain that number of values. // // This function is only suitable for built-in data types. // // template void read_array (Array& the_array, const std::string& fileName); template inline void read_array (Array& the_array, const char* fileName) { read_array (the_array, std::string(fileName)); } // // // These two functions read and write a Vector of data. The input // may be arranged in any format (i.e. It may be recorded as one value per // line or it may be recorded with all values on a single line). // Values must be separated by whitespace. // template void readAsciiVector (Vector& vec, const char* fileName); template void writeAsciiVector (const Vector& vec, const char* fileName); // // AipsIO& operator<< (AipsIO& aio, const IPosition& ip); AipsIO& operator>> (AipsIO& aio, IPosition& ip); LogIO& operator<< (LogIO& os, const IPosition& ip); template Block makeBlock(const Array& array); template Vector makeVector(const Block& block); Vector stringToVector (const String& string, char delim = ','); Vector stringToVector (const String& string, const std::regex& delim); } //# NAMESPACE CASACORE - END #include #endif