source: XMLIO_V2/external/include/blitz/tinymatio.cc @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

File size: 1.7 KB
Line 
1/*
2 * Copyright (C) 1997 Todd Veldhuizen <tveldhui@oonumerics.org>
3 * All rights reserved.  Please see <blitz/blitz.h> for terms and
4 * conditions of use.
5 *
6 */
7
8#ifndef BZ_TINYMATIO_CC
9#define BZ_TINYMATIO_CC
10
11#ifndef BZ_TINYMAT_H
12 #include <blitz/tinymat.h>
13#endif
14
15BZ_NAMESPACE(blitz)
16
17template <typename P_numtype, int N_rows, int N_columns>
18ostream& operator<<(ostream& os,
19    const TinyMatrix<P_numtype, N_rows, N_columns>& x)
20{
21    os << "(" << N_rows << "," << N_columns << "): " << endl;
22    for (int i=0; i < N_rows; ++i)
23    {
24        os << " [ ";
25        for (int j=0; j < N_columns; ++j)
26        {
27            os << setw(10) << x(i,j);
28            if (!((j+1)%7))
29                os << endl << "  ";
30        }
31        os << " ]" << endl;
32    }
33    return os;
34}
35
36template <typename P_numtype, int N_rows, int N_columns>
37istream& operator>>(istream& is, 
38    TinyMatrix<P_numtype, N_rows, N_columns>& x)
39{
40    int rows, columns;
41    char sep;
42             
43    is >> rows >> columns;
44
45    BZPRECHECK(rows == N_rows, "Size mismatch in number of rows");
46    BZPRECHECK(columns == N_columns, "Size mismatch in number of columns");
47
48    for (int i=0; i < N_rows; ++i) 
49    {
50        is >> sep;
51        BZPRECHECK(sep == '[', "Format error while scanning input matrix"
52            << endl << " (expected '[' before beginning of row data)");
53        for (int j = 0; j < N_columns; ++j)
54        {
55            BZPRECHECK(!is.bad(), "Premature end of input while scanning matrix");
56            is >> x(i,j);
57        }
58        is >> sep;
59        BZPRECHECK(sep == ']', "Format error while scanning input matrix"
60            << endl << " (expected ']' after end of row data)");
61    }
62
63    return is;
64}
65
66BZ_NAMESPACE_END
67
68#endif // BZ_TINYMATIO_CC
69
Note: See TracBrowser for help on using the repository browser.