LORENE
dim_tbl.C
1/*
2 * Methods of class Dim_tbl
3 *
4 * (see file dim_tbl.h for documentation)
5 *
6 */
7
8/*
9 * Copyright (c) 1999-2000 Jean-Alain Marck
10 * Copyright (c) 1999-2001 Eric Gourgoulhon
11 *
12 * This file is part of LORENE.
13 *
14 * LORENE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * LORENE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with LORENE; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30
31char dim_tbl[] = "$Header: /cvsroot/Lorene/C++/Source/Tbl/dim_tbl.C,v 1.7 2014/10/13 08:53:41 j_novak Exp $" ;
32
33/*
34 * $Id: dim_tbl.C,v 1.7 2014/10/13 08:53:41 j_novak Exp $
35 * $Log: dim_tbl.C,v $
36 * Revision 1.7 2014/10/13 08:53:41 j_novak
37 * Lorene classes and functions now belong to the namespace Lorene.
38 *
39 * Revision 1.6 2014/10/06 15:13:18 j_novak
40 * Modified #include directives to use c++ syntax.
41 *
42 * Revision 1.5 2006/09/26 07:21:07 p_grandclement
43 * Minor change in the indices
44 *
45 * Revision 1.4 2006/09/25 10:01:50 p_grandclement
46 * Addition of N-dimensional Tbl
47 *
48 * Revision 1.3 2002/10/16 14:37:13 j_novak
49 * Reorganization of #include instructions of standard C++, in order to
50 * use experimental version 3 of gcc.
51 *
52 * Revision 1.2 2001/12/04 21:27:54 e_gourgoulhon
53 *
54 * All writing/reading to a binary file are now performed according to
55 * the big endian convention, whatever the system is big endian or
56 * small endian, thanks to the functions fwrite_be and fread_be
57 *
58 * Revision 1.1 2001/11/23 09:37:51 e_gourgoulhon
59 * dim_tbl.C now in directory Tbl
60 *
61 * Revision 1.1.1.1 2001/11/20 15:19:30 e_gourgoulhon
62 * LORENE
63 *
64 * Revision 2.5 1999/11/23 12:16:49 eric
65 * Dimension 0 autorisee dans le constructeur 1D.
66 *
67 * Revision 2.4 1999/09/24 14:24:09 eric
68 * Declaration de methodes const.
69 *
70 * Revision 2.3 1999/09/22 11:24:53 eric
71 * Correction erreur ecriture/lecture fichier de taille (double->int).
72 * Initialisation de ndim.
73 *
74 * Revision 2.2 1999/09/16 16:24:08 eric
75 * *** empty log message ***
76 *
77 * Revision 2.1 1999/03/01 14:56:17 eric
78 * *** empty log message ***
79 *
80 * Revision 2.0 1999/02/15 10:42:45 hyc
81 * *** empty log message ***
82 *
83 * $Header: /cvsroot/Lorene/C++/Source/Tbl/dim_tbl.C,v 1.7 2014/10/13 08:53:41 j_novak Exp $
84 *
85 */
86
87// Headers C
88#include <cassert>
89
90// Headers Lorene
91#include "dim_tbl.h"
92#include "utilitaires.h"
93
94 //---------------//
95 // Constructeurs //
96 //---------------//
97
98// 1D constructor
99namespace Lorene {
100Dim_tbl::Dim_tbl(int i) : ndim(1) {
101 assert(i >= 0) ; // The dimension 0 is allowed
102 dim = new int[ndim] ;
103 dim[0] = i ;
104 taille = i ;
105}
106// 2D constructor
107Dim_tbl::Dim_tbl(int j, int i) : ndim(2) {
108 assert(j > 0) ;
109 assert(i > 0) ;
110 dim = new int[ndim] ;
111 dim[0] = i ; dim[1] = j ;
112 taille = i * j ;
113}
114// 3D constructor
115Dim_tbl::Dim_tbl(int k, int j, int i) : ndim(3) {
116 assert(k > 0) ;
117 assert(j > 0) ;
118 assert(i > 0) ;
119 dim = new int[ndim] ;
120 dim[0] = i ; dim[1] = j ; dim[2] = k ;
121 taille = i * j * k ;
122}
123
124// N-dimensional constructor
125Dim_tbl::Dim_tbl(int n, int* sizes) : ndim(n) {
126 for (int i=0 ; i<ndim ; i++)
127 assert(sizes[i] > 0) ;
128 dim = new int[ndim] ;
129 taille = 1 ;
130 for (int i=0 ; i<ndim ; i++) {
131 dim[i] = sizes[ndim-i-1] ;
132 taille *= sizes[i] ;
133 }
134}
135
136// Copy
137Dim_tbl::Dim_tbl(const Dim_tbl & titi) : ndim(titi.ndim) {
138 dim = new int[ndim] ;
139 for (int i=0 ; i<ndim ; i++) {
140 dim[i] = titi.dim[i] ;
141 }
142 taille = titi.taille ;
143}
144
145// From a file
147 fread_be(&ndim, sizeof(int), 1, fd) ; // ndim
148 dim = new int[ndim] ;
149 fread_be(dim, sizeof(int), ndim, fd) ; // dim[]
150 taille = dim[0] ;
151 for (int i=1; i<ndim; i++) {
152 taille *= dim[i] ;
153 }
154}
155
156 //--------------//
157 // Destructeurs //
158 //--------------//
159
160// Destructeur
162 delete [] dim ;
163}
164
165 //-------------//
166 // Affectation //
167 //-------------//
168
169// From Dim_tbl
171 ndim = titi.ndim ;
172 delete [] dim ;
173 dim = new int[ndim] ;
174 for (int i=0 ; i<ndim ; i++) {
175 dim[i] = titi.dim[i] ;
176 }
177 taille = titi.taille ;
178}
179
180 //------------//
181 // Sauvegarde //
182 //------------//
183
184// Save in a file
185void Dim_tbl::sauve(FILE* fd) const {
186 fwrite_be(&ndim, sizeof(int), 1, fd) ; // ndim
187 fwrite_be(dim, sizeof(int), ndim, fd) ; // dim[]
188}
189
190 //------------//
191 // Impression //
192 //------------//
193
194// Operateurs <<
196 o << titi.ndim << " dimension(s):" ;
197 for (int i=0 ; i<titi.ndim ; i++) {
198 o << " " << titi.dim[i] ;
199 }
200 return o ;
201}
202
203
204 //---------------------//
205 // Operateurs logiques //
206 //---------------------//
207
208bool Dim_tbl::operator==(const Dim_tbl & ti) const {
209
210 // Peut-etre faux ?
211 if (ndim != ti.ndim) return false ;
212 for (int i=0 ; i<ndim ; i++) {
213 if (dim[i] != ti.dim[i]) return false ;
214 }
215
216 // Non ! juste
217 return true ;
218}
219}
Storage of array dimensions.
Definition dim_tbl.h:99
int taille
Total size of the array Tbl::t.
Definition dim_tbl.h:112
~Dim_tbl()
Destructor.
Definition dim_tbl.C:161
bool operator==(const Dim_tbl &) const
Comparison operator.
Definition dim_tbl.C:208
Dim_tbl(int size0)
1D constructor
Definition dim_tbl.C:100
void sauve(FILE *) const
Save in a file.
Definition dim_tbl.C:185
int * dim
Array of dimensions (size: ndim).
Definition dim_tbl.h:102
int ndim
Number of dimensions of the Tbl: can be 1, 2 or 3.
Definition dim_tbl.h:101
void operator=(const Dim_tbl &)
Assignment.
Definition dim_tbl.C:170
Time evolution with partial storage (*** under development ***).
Definition evolution.h:371
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
Definition fread_be.C:69
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
Definition fwrite_be.C:70
Lorene prototypes.
Definition app_hor.h:64