Blender  V2.59
tnt_fortran_array1d_utils.h
Go to the documentation of this file.
00001 
00004 /*
00005 *
00006 * Template Numerical Toolkit (TNT)
00007 *
00008 * Mathematical and Computational Sciences Division
00009 * National Institute of Technology,
00010 * Gaithersburg, MD USA
00011 *
00012 *
00013 * This software was developed at the National Institute of Standards and
00014 * Technology (NIST) by employees of the Federal Government in the course
00015 * of their official duties. Pursuant to title 17 Section 105 of the
00016 * United States Code, this software is not subject to copyright protection
00017 * and is in the public domain. NIST assumes no responsibility whatsoever for
00018 * its use by other parties, and makes no guarantees, expressed or implied,
00019 * about its quality, reliability, or any other characteristic.
00020 *
00021 */
00022 
00023 #ifndef TNT_FORTRAN_ARRAY1D_UTILS_H
00024 #define TNT_FORTRAN_ARRAY1D_UTILS_H
00025 
00026 #include <iostream>
00027 
00028 namespace TNT
00029 {
00030 
00031 
00039 template <class T>
00040 std::ostream& operator<<(std::ostream &s, const Fortran_Array1D<T> &A)
00041 {
00042     int N=A.dim1();
00043 
00044     s << N << "\n";
00045     for (int j=1; j<=N; j++)
00046     {
00047        s << A(j) << "\n";
00048     }
00049     s << "\n";
00050 
00051     return s;
00052 }
00053 
00068 template <class T>
00069 std::istream& operator>>(std::istream &s, Fortran_Array1D<T> &A)
00070 {
00071         int N;
00072         s >> N;
00073 
00074         Fortran_Array1D<T> B(N);
00075         for (int i=1; i<=N; i++)
00076                 s >> B(i);
00077         A = B;
00078         return s;
00079 }
00080 
00081 
00082 template <class T>
00083 Fortran_Array1D<T> operator+(const Fortran_Array1D<T> &A, const Fortran_Array1D<T> &B)
00084 {
00085         int n = A.dim1();
00086 
00087         if (B.dim1() != n )
00088                 return Fortran_Array1D<T>();
00089 
00090         else
00091         {
00092                 Fortran_Array1D<T> C(n);
00093 
00094                 for (int i=1; i<=n; i++)
00095                 {
00096                         C(i) = A(i) + B(i);
00097                 }
00098                 return C;
00099         }
00100 }
00101 
00102 
00103 
00104 template <class T>
00105 Fortran_Array1D<T> operator-(const Fortran_Array1D<T> &A, const Fortran_Array1D<T> &B)
00106 {
00107         int n = A.dim1();
00108 
00109         if (B.dim1() != n )
00110                 return Fortran_Array1D<T>();
00111 
00112         else
00113         {
00114                 Fortran_Array1D<T> C(n);
00115 
00116                 for (int i=1; i<=n; i++)
00117                 {
00118                         C(i) = A(i) - B(i);
00119                 }
00120                 return C;
00121         }
00122 }
00123 
00124 
00125 template <class T>
00126 Fortran_Array1D<T> operator*(const Fortran_Array1D<T> &A, const Fortran_Array1D<T> &B)
00127 {
00128         int n = A.dim1();
00129 
00130         if (B.dim1() != n )
00131                 return Fortran_Array1D<T>();
00132 
00133         else
00134         {
00135                 Fortran_Array1D<T> C(n);
00136 
00137                 for (int i=1; i<=n; i++)
00138                 {
00139                         C(i) = A(i) * B(i);
00140                 }
00141                 return C;
00142         }
00143 }
00144 
00145 
00146 template <class T>
00147 Fortran_Array1D<T> operator/(const Fortran_Array1D<T> &A, const Fortran_Array1D<T> &B)
00148 {
00149         int n = A.dim1();
00150 
00151         if (B.dim1() != n )
00152                 return Fortran_Array1D<T>();
00153 
00154         else
00155         {
00156                 Fortran_Array1D<T> C(n);
00157 
00158                 for (int i=1; i<=n; i++)
00159                 {
00160                         C(i) = A(i) / B(i);
00161                 }
00162                 return C;
00163         }
00164 }
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 template <class T>
00175 Fortran_Array1D<T>&  operator+=(Fortran_Array1D<T> &A, const Fortran_Array1D<T> &B)
00176 {
00177         int n = A.dim1();
00178 
00179         if (B.dim1() == n)
00180         {
00181                 for (int i=1; i<=n; i++)
00182                 {
00183                                 A(i) += B(i);
00184                 }
00185         }
00186         return A;
00187 }
00188 
00189 
00190 
00191 
00192 template <class T>
00193 Fortran_Array1D<T>&  operator-=(Fortran_Array1D<T> &A, const Fortran_Array1D<T> &B)
00194 {
00195         int n = A.dim1();
00196 
00197         if (B.dim1() == n)
00198         {
00199                 for (int i=1; i<=n; i++)
00200                 {
00201                                 A(i) -= B(i);
00202                 }
00203         }
00204         return A;
00205 }
00206 
00207 
00208 
00209 template <class T>
00210 Fortran_Array1D<T>&  operator*=(Fortran_Array1D<T> &A, const Fortran_Array1D<T> &B)
00211 {
00212         int n = A.dim1();
00213 
00214         if (B.dim1() == n)
00215         {
00216                 for (int i=1; i<=n; i++)
00217                 {
00218                                 A(i) *= B(i);
00219                 }
00220         }
00221         return A;
00222 }
00223 
00224 
00225 
00226 
00227 template <class T>
00228 Fortran_Array1D<T>&  operator/=(Fortran_Array1D<T> &A, const Fortran_Array1D<T> &B)
00229 {
00230         int n = A.dim1();
00231 
00232         if (B.dim1() == n)
00233         {
00234                 for (int i=1; i<=n; i++)
00235                 {
00236                                 A(i) /= B(i);
00237                 }
00238         }
00239         return A;
00240 }
00241 
00242 
00243 } // namespace TNT
00244 
00245 #endif