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

# tnt_fortran_array3d_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_ARRAY3D_UTILS_H
    00022 #define TNT_FORTRAN_ARRAY3D_UTILS_H
    00023
    00024 #include <cstdlib>
    00025 #include <cassert>
    00026
    00027 namespace TNT
    00028 {
    00029
    00030
    00038 template <class T>
    00039 std::ostream& operator<<(std::ostream &s, const Fortran_Array3D<T> &A)
    00040 {
    00041     int M=A.dim1();
    00042     int N=A.dim2();
    00043     int K=A.dim3();
    00044
    00045     s << M << " " << N << " " << K << "\n";
    00046
    00047     for (int i=1; i<=M; i++)
    00048     {
    00049         for (int j=1; j<=N; j++)
    00050         {
    00051                         for (int k=1; k<=K; k++)
    00052                 s << A(i,j,k) << " ";
    00053                         s << "\n";
    00054         }
    00055         s << "\n";
    00056     }
    00057
    00058
    00059     return s;
    00060 }
    00061
    00078 template <class T>
    00079 std::istream& operator>>(std::istream &s, Fortran_Array3D<T> &A)
    00080 {
    00081
    00082     int M, N, K;
    00083
    00084     s >> M >> N >> K;
    00085
    00086         Fortran_Array3D<T> B(M,N,K);
    00087
    00088     for (int i=1; i<=M; i++)
    00089         for (int j=1; j<=N; j++)
    00090                         for (int k=1; k<=K; k++)
    00091                 s >>  B(i,j,k);
    00092
    00093         A = B;
    00094     return s;
    00095 }
    00096
    00097
    00098
    00099
    00100 } // namespace TNT
    00101
    00102 #endif