Essentia  2.1-beta6-dev
tnt_fortran_array1d_utils.h
Go to the documentation of this file.
1 /*
2 *
3 * Template Numerical Toolkit (TNT)
4 *
5 * Mathematical and Computational Sciences Division
6 * National Institute of Technology,
7 * Gaithersburg, MD USA
8 *
9 *
10 * This software was developed at the National Institute of Standards and
11 * Technology (NIST) by employees of the Federal Government in the course
12 * of their official duties. Pursuant to title 17 Section 105 of the
13 * United States Code, this software is not subject to copyright protection
14 * and is in the public domain. NIST assumes no responsibility whatsoever for
15 * its use by other parties, and makes no guarantees, expressed or implied,
16 * about its quality, reliability, or any other characteristic.
17 *
18 */
19 
20 #ifndef TNT_FORTRAN_ARRAY1D_UTILS_H
21 #define TNT_FORTRAN_ARRAY1D_UTILS_H
22 
23 #include <iostream>
24 
25 namespace TNT
26 {
27 
28 
36 template <class T>
37 std::ostream& operator<<(std::ostream &s, const Fortran_Array1D<T> &A)
38 {
39  int N=A.dim1();
40 
41  s << N << "\n";
42  for (int j=1; j<=N; j++)
43  {
44  s << A(j) << "\n";
45  }
46  s << "\n";
47 
48  return s;
49 }
50 
65 template <class T>
66 std::istream& operator>>(std::istream &s, Fortran_Array1D<T> &A)
67 {
68  int N;
69  s >> N;
70 
71  Fortran_Array1D<T> B(N);
72  for (int i=1; i<=N; i++)
73  s >> B(i);
74  A = B;
75  return s;
76 }
77 
78 
79 template <class T>
81 {
82  int n = A.dim1();
83 
84  if (B.dim1() != n )
85  return Fortran_Array1D<T>();
86 
87  else
88  {
89  Fortran_Array1D<T> C(n);
90 
91  for (int i=1; i<=n; i++)
92  {
93  C(i) = A(i) + B(i);
94  }
95  return C;
96  }
97 }
98 
99 
100 
101 template <class T>
103 {
104  int n = A.dim1();
105 
106  if (B.dim1() != n )
107  return Fortran_Array1D<T>();
108 
109  else
110  {
111  Fortran_Array1D<T> C(n);
112 
113  for (int i=1; i<=n; i++)
114  {
115  C(i) = A(i) - B(i);
116  }
117  return C;
118  }
119 }
120 
121 
122 template <class T>
124 {
125  int n = A.dim1();
126 
127  if (B.dim1() != n )
128  return Fortran_Array1D<T>();
129 
130  else
131  {
132  Fortran_Array1D<T> C(n);
133 
134  for (int i=1; i<=n; i++)
135  {
136  C(i) = A(i) * B(i);
137  }
138  return C;
139  }
140 }
141 
142 
143 template <class T>
145 {
146  int n = A.dim1();
147 
148  if (B.dim1() != n )
149  return Fortran_Array1D<T>();
150 
151  else
152  {
153  Fortran_Array1D<T> C(n);
154 
155  for (int i=1; i<=n; i++)
156  {
157  C(i) = A(i) / B(i);
158  }
159  return C;
160  }
161 }
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 template <class T>
173 {
174  int n = A.dim1();
175 
176  if (B.dim1() == n)
177  {
178  for (int i=1; i<=n; i++)
179  {
180  A(i) += B(i);
181  }
182  }
183  return A;
184 }
185 
186 
187 
188 
189 template <class T>
191 {
192  int n = A.dim1();
193 
194  if (B.dim1() == n)
195  {
196  for (int i=1; i<=n; i++)
197  {
198  A(i) -= B(i);
199  }
200  }
201  return A;
202 }
203 
204 
205 
206 template <class T>
208 {
209  int n = A.dim1();
210 
211  if (B.dim1() == n)
212  {
213  for (int i=1; i<=n; i++)
214  {
215  A(i) *= B(i);
216  }
217  }
218  return A;
219 }
220 
221 
222 
223 
224 template <class T>
226 {
227  int n = A.dim1();
228 
229  if (B.dim1() == n)
230  {
231  for (int i=1; i<=n; i++)
232  {
233  A(i) /= B(i);
234  }
235  }
236  return A;
237 }
238 
239 
240 } // namespace TNT
241 
242 #endif
Definition: tnt_fortran_array1d.h:40
int dim1() const
Definition: tnt_fortran_array1d.h:201
Definition: tnt_array1d.h:36
Array1D< T > operator+(const Array1D< T > &A, const Array1D< T > &B)
Definition: tnt_array1d_utils.h:64
Array1D< T > & operator-=(Array1D< T > &A, const Array1D< T > &B)
Definition: tnt_array1d_utils.h:174
Array1D< T > & operator/=(Array1D< T > &A, const Array1D< T > &B)
Definition: tnt_array1d_utils.h:209
Array1D< T > operator*(const Array1D< T > &A, const Array1D< T > &B)
Definition: tnt_array1d_utils.h:107
Array1D< T > operator-(const Array1D< T > &A, const Array1D< T > &B)
Definition: tnt_array1d_utils.h:86
Array1D< T > & operator+=(Array1D< T > &A, const Array1D< T > &B)
Definition: tnt_array1d_utils.h:156
Array1D< T > & operator*=(Array1D< T > &A, const Array1D< T > &B)
Definition: tnt_array1d_utils.h:191
Array1D< T > operator/(const Array1D< T > &A, const Array1D< T > &B)
Definition: tnt_array1d_utils.h:128
std::ostream & operator<<(std::ostream &s, const Array1D< T > &A)
Definition: tnt_array1d_utils.h:31
std::istream & operator>>(std::istream &s, Array1D< T > &A)
Definition: tnt_array1d_utils.h:49