tnt_fortran_array2d_utils.h Source File

Main Page Namespace List Compound List File List Namespace Members Compound Members File Members

# tnt_fortran_array2d_utils.h

Go to the documentation of this file.

    00001 /*
    00002 *
    00003 * Template Numerical Toolkit (TNT)
    00004 *
    00005 * Mathematical and Computational Sciences Division
    00006 * National Institute of Technology,
    00007 * Gaithersburg, MD USA
    00008 *
    00009 *
    00010 * This software was developed at the National Institute of Standards and
    00011 * Technology (NIST) by employees of the Federal Government in the course
    00012 * of their official duties. Pursuant to title 17 Section 105 of the
    00013 * United States Code, this software is not subject to copyright protection
    00014 * and is in the public domain. NIST assumes no responsibility whatsoever for
    00015 * its use by other parties, and makes no guarantees, expressed or implied,
    00016 * about its quality, reliability, or any other characteristic.
    00017 *
    00018 */
    00019
    00020
    00021 #ifndef TNT_FORTRAN_ARRAY2D_UTILS_H
    00022 #define TNT_FORTRAN_ARRAY2D_UTILS_H
    00023
    00024 #include <iostream>
    00025
    00026 namespace TNT
    00027 {
    00028
    00029
    00037 template <class T>
    00038 std::ostream& operator<<(std::ostream &s, const Fortran_Array2D<T> &A)
    00039 {
    00040     int M=A.dim1();
    00041     int N=A.dim2();
    00042
    00043     s << M << " " << N << "\n";
    00044
    00045     for (int i=1; i<=M; i++)
    00046     {
    00047         for (int j=1; j<=N; j++)
    00048         {
    00049             s << A(i,j) << " ";
    00050         }
    00051         s << "\n";
    00052     }
    00053
    00054
    00055     return s;
    00056 }
    00057
    00074 template <class T>
    00075 std::istream& operator>>(std::istream &s, Fortran_Array2D<T> &A)
    00076 {
    00077
    00078     int M, N;
    00079
    00080     s >> M >> N;
    00081
    00082         Fortran_Array2D<T> B(M,N);
    00083
    00084     for (int i=1; i<=M; i++)
    00085         for (int j=1; j<=N; j++)
    00086         {
    00087             s >>  B(i,j);
    00088         }
    00089
    00090         A = B;
    00091     return s;
    00092 }
    00093
    00094
    00095
    00096
    00097 } // namespace TNT
    00098
    00099 #endif