1 /*******************************************************************/
2 /* XDMF */
3 /* eXtensible Data Model and Format */
4 /* */
5 /* Id : Id */
6 /* Date : $Date$ */
7 /* Version : $Revision$ */
8 /* */
9 /* Author: */
10 /* Jerry A. Clarke */
11 /* clarke@arl.army.mil */
12 /* US Army Research Laboratory */
13 /* Aberdeen Proving Ground, MD */
14 /* */
15 /* Copyright @ 2002 US Army Research Laboratory */
16 /* All Rights Reserved */
17 /* See Copyright.txt or http://www.arl.hpc.mil/ice for details */
18 /* */
19 /* This software is distributed WITHOUT ANY WARRANTY; without */
20 /* even the implied warranty of MERCHANTABILITY or FITNESS */
21 /* FOR A PARTICULAR PURPOSE. See the above copyright notice */
22 /* for more information. */
23 /* */
24 /*******************************************************************/
25 #include "XdmfArray.h"
26 #include "XdmfArrayCopyMacro.h"
27
28 #include <cstring>
29
30 #ifndef _WIN32
31 #include <unistd.h>
32 #endif
33
34 namespace xdmf2
35 {
36
37 static XdmfLength GlobalTimeCntr = 0;
38 // static ostrstream *StringOutput = NULL;
39
40 class XdmfArrayListClass
41 {
42 public:
XdmfArrayListClass()43 XdmfArrayListClass()
44 {
45 this->ListLength = 0;
46 this->ListIndex = 0;
47 this->List = 0;
48 }
49 ~XdmfArrayListClass();
50
51 static XdmfArrayListClass *Instance();
52 XdmfArrayList* AddArray();
53 void RemoveArray(XdmfArray*);
54
GetNumberOfElements()55 XdmfLength GetNumberOfElements()
56 {
57 return this->ListIndex;
58 }
59
60 XdmfLength ListLength;
61 XdmfArrayList *List;
62
63 private:
64 XdmfLength ListIndex;
65 static XdmfArrayListClass *XdmfArrayListClassInstance;
66 };
67
68 XdmfArrayListClass *
Instance()69 XdmfArrayListClass::Instance(){
70 if(XdmfArrayListClassInstance == 0){
71 // cout << "Creating XdmfArrayListClassInstance" << endl;
72 XdmfArrayListClassInstance = new XdmfArrayListClass;
73 }
74 // cout << "Return Instance = " << XdmfArrayListClassInstance << endl;
75 return(XdmfArrayListClassInstance);
76 }
77
~XdmfArrayListClass()78 XdmfArrayListClass::~XdmfArrayListClass()
79 {
80
81
82 if ( this->List )
83 {
84 while( this->ListIndex > 0 )
85 {
86 // cout << "Before this->ListIndex = " << this->ListIndex << endl;
87 // cout << "Delete Array #" << i++ << endl;
88 delete this->List[this->ListIndex-1].Array;
89 // cout << "After this->ListIndex = " << this->ListIndex << endl;
90 }
91 delete [] this->List;
92 this->List = 0;
93 }
94 if ( XdmfArrayListClassInstance )
95 {
96 delete XdmfArrayListClassInstance;
97 }
98 }
99
AddArray()100 XdmfArrayList* XdmfArrayListClass::AddArray()
101 {
102 XdmfArrayList* res = 0;
103 if( this->ListIndex >= this->ListLength ){
104 XdmfArrayList *NewList = new XdmfArrayList[ this->ListLength + 32];
105 if( this->List != NULL ){
106 memcpy( NewList, this->List, this->ListLength * sizeof( XdmfArrayList ));
107 delete [] this->List;
108 }
109 this->List = NewList;
110 this->ListLength += 32;
111 }
112 res = this->List + this->ListIndex;
113 this->ListIndex++;
114 return res;
115 }
116
RemoveArray(XdmfArray * array)117 void XdmfArrayListClass::RemoveArray(XdmfArray* array)
118 {
119 XdmfLength i;
120 for( i = 0 ; i < this->ListLength ; i++ ){
121 if ( this->List[ i ].Array == array ){
122 memmove( &this->List[ i ],
123 &this->List[ i + 1 ],
124 MAX(0,(this->ListLength - i - 1)) * sizeof( XdmfArrayList ) );
125 this->ListIndex--;
126 break;
127 }
128 }
129 }
130
131 // static XdmfArrayListClass XDMFArrayList;
132 XdmfArrayListClass *XdmfArrayListClass::XdmfArrayListClassInstance;
133
134 XdmfArray *
TagNameToArray(XdmfString TagName)135 TagNameToArray( XdmfString TagName ) {
136
137 char c;
138 XdmfInt64 i, Id;
139 istrstream Tag(TagName, strlen(TagName));
140 XdmfArrayListClass *XDMFArrayList = XdmfArrayListClass::Instance();
141
142 Tag >> c;
143 if( c != '_' ) {
144 XdmfErrorMessage("Invalid Array Tag Name: " << TagName );
145 return( NULL );
146 }
147 #ifdef ICE_HAVE_64BIT_STREAMS
148 Tag >> Id;
149 #else
150 {
151 double d;
152 Tag >> d;
153 Id = (XdmfInt64)d;
154 }
155 #endif
156
157 for( i = 0 ; i < XDMFArrayList->ListLength ; i++ ){
158 if ( XDMFArrayList->List[ i ].timecntr == Id ){
159 return( XDMFArrayList->List[ i ].Array );
160 }
161 }
162 XdmfErrorMessage("No Array found with Tag Name: " << TagName );
163 return( NULL );
164 }
165
166 XdmfArray *
GetNextOlderArray(XdmfLength Age,XdmfLength * AgeOfArray)167 GetNextOlderArray( XdmfLength Age, XdmfLength *AgeOfArray ) {
168 XdmfLength i;
169 XdmfArrayListClass *XDMFArrayList = XdmfArrayListClass::Instance();
170
171 for( i = 0 ; i < XDMFArrayList->GetNumberOfElements(); i++ ){
172 if( XDMFArrayList->List[ i ].timecntr > Age ) {
173 if( AgeOfArray != NULL ){
174 *AgeOfArray = XDMFArrayList->List[ i ].timecntr;
175 }
176 return( XDMFArrayList->List[ i ].Array );
177 }
178 }
179 return( NULL );
180 }
181
182 XdmfLength
GetCurrentArrayTime(void)183 GetCurrentArrayTime( void ) {
184
185 return (GlobalTimeCntr);
186 }
187
188 extern void
PrintAllXdmfArrays()189 PrintAllXdmfArrays() {
190 XdmfLength i;
191 XdmfArrayListClass *XDMFArrayList = XdmfArrayListClass::Instance();
192
193 for( i = 0 ; i < XDMFArrayList->GetNumberOfElements(); i++ ){
194 cerr << "XdmfArray " << XDMF_64BIT_CAST i << '\n';
195 cerr << " NumberType " << XDMFArrayList->List[ i ].Array->GetNumberTypeAsString() << '\n';
196 cerr << " Time = " << XDMF_64BIT_CAST XDMFArrayList->List[ i ].timecntr << '\n';
197 cerr << " Size = " << XDMF_64BIT_CAST XDMFArrayList->List[ i ].Array->GetNumberOfElements() << '\n';
198 }
199 }
200
201 void
AddArrayToList(void)202 XdmfArray::AddArrayToList( void ) {
203 XdmfArrayListClass *XDMFArrayList = XdmfArrayListClass::Instance();
204
205 ostrstream Tag(this->TagName, XDMF_ARRAY_TAG_LENGTH);
206 GlobalTimeCntr++;
207 XdmfArrayList* array = XDMFArrayList->AddArray();
208 array->name = NULL;
209 array->timecntr = GlobalTimeCntr;
210 array->Array = this;
211 Tag << "_" << XDMF_64BIT_CAST GlobalTimeCntr << "_XdmfArray" << ends;
212 }
213
XdmfArray()214 XdmfArray::XdmfArray() {
215 XdmfDebug("XdmfArray Constructor");
216 this->AllowAllocate = 1;
217 this->DataPointer = NULL;
218 this->HeavyDataSetName = NULL;
219 this->DataIsMine = 1;
220 this->AddArrayToList();
221 }
222
XdmfArray(XdmfInt32 numberType)223 XdmfArray::XdmfArray( XdmfInt32 numberType ) {
224 XdmfDebug("XdmfArray Constructor");
225 this->AllowAllocate = 1;
226 this->DataPointer = NULL;
227 this->DataIsMine = 1;
228 this->SetNumberType( numberType );
229 this->AddArrayToList();
230 }
231
XdmfArray(XdmfInt32 numberType,XdmfLength Length)232 XdmfArray::XdmfArray( XdmfInt32 numberType, XdmfLength Length ) {
233 XdmfDebug("XdmfArray Constructor");
234 this->AllowAllocate = 1;
235 this->DataPointer = NULL;
236 this->DataIsMine = 1;
237 this->SetNumberType( numberType );
238 this->SetNumberOfElements( Length );
239 this->AddArrayToList();
240 }
241
~XdmfArray()242 XdmfArray::~XdmfArray() {
243 XdmfArrayListClass *XDMFArrayList = XdmfArrayListClass::Instance();
244 XdmfDebug("XdmfArray Destructor");
245 if( ( this->DataIsMine ) && ( this->DataPointer != NULL ) ) {
246 XdmfDebug(" Deleteing Data Array " << this->DataPointer );
247 // delete [] this->DataPointer;
248 free( this->DataPointer );
249 XdmfDebug(" Done Deleteing Data Array " << this->DataPointer );
250 this->DataPointer = NULL;
251 } else {
252 XdmfDebug("Can't Delete Array : Data Pointer is not mine");
253 }
254 XdmfDebug(" Remove From Array List " << this );
255 XDMFArrayList->RemoveArray(this);
256 XdmfDebug(" Done Remove From Array List " << this );
257 }
258
259 XdmfString
GetTagName(void)260 XdmfArray::GetTagName( void ){
261 return( this->TagName );
262 }
263
264
265 /*
266 XdmfPointer XdmfArray::MemCopy( XdmfLength StartOffset,
267 XdmfLength NumberOfElemnts,
268 XdmfPointer DataPointer,
269 XdmfLength Stride ) {
270 XdmfPointer RetVal;
271
272 if( Stride == 1 ) {
273 RetVal = memcpy( this->GetVoidPointer( StartOffset ),
274 DataPointer,
275 this->Precision * NumberOfElemnts );
276 } else {
277 XdmfLength i;
278 XdmfInt8 *ptr;
279
280 RetVal = this->GetVoidPointer( StartOffset );
281 ptr = ( XdmfInt8 *)DataPointer;
282 for( i = 0 ; i < NumberOfElemnts ; i++ ){
283 memcpy( this->GetVoidPointer( StartOffset ),
284 ptr,
285 this->Precision );
286 StartOffset += Stride;
287 ptr += this->Precision;
288 }
289 }
290
291 return( RetVal );
292 }
293 */
294
Allocate(void)295 XdmfInt32 XdmfArray::Allocate( void ){
296 XdmfDebug("Request Allocating " <<
297 XDMF_64BIT_CAST (this->GetNumberOfElements() * this->GetElementSize()) <<
298 " Bytes");
299 if(!this->AllowAllocate){
300 XdmfDebug("AllowAllocate is Off");
301 return(XDMF_SUCCESS);
302 }
303 if( this->DataIsMine ) {
304 XdmfDebug("Data " << XDMF_64BIT_CAST this->DataPointer << " is Mine");
305 if( this->DataPointer ) {
306 this->DataPointer = (XdmfInt8 *)realloc( this->DataPointer, this->GetNumberOfElements() * this->GetElementSize());
307 } else {
308 this->DataPointer = (XdmfInt8 *)malloc( this->GetNumberOfElements() * this->GetElementSize());
309 }
310 if( this->DataPointer == NULL ) {
311 XdmfDebug("Allocation Failed");
312 perror(" Alloc :" );
313 #ifndef _WIN32
314 XdmfDebug("End == " << sbrk(0) );
315 #endif
316 }
317 }
318 XdmfDebug("Data Pointer = " << this->DataPointer );
319 if( this->DataPointer == NULL ) {
320 XdmfDebug("Allocation Failed");
321 return( XDMF_FAIL );
322 }
323 XdmfDebug("Allocation Succeeded");
324 return( XDMF_SUCCESS );
325 }
326
Reform(XdmfInt32 rank,XdmfInt64 * Dimensions)327 XdmfInt32 XdmfArray::Reform( XdmfInt32 rank, XdmfInt64 *Dimensions ) {
328
329 XdmfDebug("Reform Shape");
330 XdmfDataDesc::SetShape( rank, Dimensions );
331 return( XDMF_SUCCESS );
332 }
333
ReformFromSelection(XdmfDataDesc * DataDesc)334 XdmfInt32 XdmfArray::ReformFromSelection( XdmfDataDesc *DataDesc) {
335
336 XdmfDebug("Reform from Selection");
337
338 if(DataDesc->GetSelectionType() == XDMF_SELECTALL){
339 return(this->Reform(DataDesc));
340 }
341 if( DataDesc->GetSelectionType() == XDMF_HYPERSLAB ){
342 XdmfInt32 rank;
343 XdmfInt64 start[ XDMF_MAX_DIMENSION ];
344 XdmfInt64 stride[ XDMF_MAX_DIMENSION ];
345 XdmfInt64 count[ XDMF_MAX_DIMENSION ];
346
347 // Select the HyperSlab from HDF5
348 XdmfDebug("Reform from Hyperslab");
349 rank = DataDesc->GetHyperSlab( start, stride, count );
350 this->Reform(rank, count);
351 this->SelectAll();
352 } else {
353 XdmfInt64 NumberOfCoordinates;
354 // XdmfInt64 *Coordinates;
355
356
357 // Select Parametric Coordinates from HDF5
358 XdmfDebug("Reform from Coordinates");
359 NumberOfCoordinates = DataDesc->GetSelectionSize();
360 XdmfDataDesc::SetNumberOfElements(NumberOfCoordinates);
361 this->SelectAll();
362 // delete Coordinates;
363 }
364 return( XDMF_SUCCESS );
365 }
366
SetShapeFromSelection(XdmfDataDesc * DataDesc)367 XdmfInt32 XdmfArray::SetShapeFromSelection( XdmfDataDesc *DataDesc) {
368 this->ReformFromSelection(DataDesc);
369 if(this->Allocate() != XDMF_SUCCESS){
370 return(XDMF_FAIL);
371 }
372 return( XDMF_SUCCESS );
373 }
374
SetShape(XdmfInt32 rank,XdmfInt64 * Dimensions)375 XdmfInt32 XdmfArray::SetShape( XdmfInt32 rank, XdmfInt64 *Dimensions ) {
376
377 XdmfDebug("Setting Shape and Allocating Memory");
378 XdmfDataDesc::SetShape( rank, Dimensions );
379 if(this->Allocate() != XDMF_SUCCESS){
380 return(XDMF_FAIL);
381 }
382 return( XDMF_SUCCESS );
383 }
384
385 XdmfInt32
CopyShape(hid_t dataSpace)386 XdmfArray::CopyShape( hid_t dataSpace ){
387 XdmfDebug("Setting Shape and Allocating Memory");
388 XdmfDataDesc::CopyShape( dataSpace );
389 if(this->Allocate() != XDMF_SUCCESS){
390 return(XDMF_FAIL);
391 }
392 return( XDMF_SUCCESS );
393 }
394
395 XdmfInt32
CopyShape(XdmfDataDesc * DataDesc)396 XdmfArray::CopyShape( XdmfDataDesc *DataDesc ){
397 XdmfDebug("Setting Shape and Allocating Memory");
398 XdmfDataDesc::CopyShape( DataDesc );
399 if(this->Allocate() != XDMF_SUCCESS){
400 return(XDMF_FAIL);
401 }
402 return( XDMF_SUCCESS );
403 }
404
405 XdmfInt32
Reform(XdmfDataDesc * DataDesc)406 XdmfArray::Reform( XdmfDataDesc *DataDesc ){
407 XdmfDebug("Setting Shape");
408 XdmfDataDesc::CopyShape( DataDesc );
409 return( XDMF_SUCCESS );
410 }
411
SetShapeFromString(XdmfConstString Dimensions)412 XdmfInt32 XdmfArray::SetShapeFromString( XdmfConstString Dimensions ) {
413
414 XdmfDebug("Setting Shape and Allocating Memory");
415 XdmfDataDesc::SetShapeFromString( Dimensions );
416 if(this->Allocate() != XDMF_SUCCESS){
417 return(XDMF_FAIL);
418 }
419 return( XDMF_SUCCESS );
420 }
421
ReformFromString(XdmfConstString Dimensions)422 XdmfInt32 XdmfArray::ReformFromString( XdmfConstString Dimensions ) {
423
424 XdmfDebug("Setting Shape and Allocating Memory");
425 XdmfDataDesc::SetShapeFromString( Dimensions );
426
427 return( XDMF_SUCCESS );
428 }
429
430
GetDataPointer(XdmfInt64 Index)431 XdmfPointer XdmfArray::GetDataPointer( XdmfInt64 Index ) {
432
433 XdmfByte *Pointer;
434 Pointer = ( XdmfByte *)this->DataPointer;
435 Pointer += (this->GetElementSize() * Index );
436 return( (XdmfPointer)Pointer );
437 }
438
SetValueFromInt64(XdmfInt64 Index,XdmfInt64 Value)439 XdmfInt32 XdmfArray::SetValueFromInt64( XdmfInt64 Index, XdmfInt64 Value ) {
440 return( this->SetValue( Index, Value ) );
441 }
442
SetValueFromFloat64(XdmfInt64 Index,XdmfFloat64 Value)443 XdmfInt32 XdmfArray::SetValueFromFloat64( XdmfInt64 Index, XdmfFloat64 Value ) {
444 return( this->SetValue( Index, Value ) );
445 }
446
CopyCompound(XdmfPointer ArrayPointer,XdmfInt32,XdmfInt64,XdmfPointer ValuePointer,XdmfInt32 ValueType,XdmfInt64 ValueStride,XdmfInt32 Direction,XdmfInt64 NumberOfValues)447 XdmfInt32 XdmfArray::CopyCompound( XdmfPointer ArrayPointer,
448 XdmfInt32 /*ArrayType*/,
449 XdmfInt64 /*ArrayStride*/,
450 XdmfPointer ValuePointer,
451 XdmfInt32 ValueType,
452 XdmfInt64 ValueStride,
453 XdmfInt32 Direction,
454 XdmfInt64 NumberOfValues ) {
455
456 XdmfFloat64 *TmpPtr, *TmpArray;
457 XdmfInt64 Length, NumberOfMembers, MemberIndex, MemberLength;
458 XdmfInt32 MemberType;
459 XdmfByte *Ptr;
460
461
462 XdmfDebug("Coping " << XDMF_64BIT_CAST NumberOfValues << " Direction = " << Direction );
463 if( Direction == XDMF_ARRAY_IN ){
464
465 TmpArray = new XdmfFloat64[ NumberOfValues ];
466
467 // Copy Values To TmpArray
468 TmpPtr = TmpArray;
469 Ptr = (XdmfByte *)ValuePointer;
470 XDMF_ARRAY_COPY( Ptr, ValueType, ValueStride,
471 TmpPtr, XDMF_FLOAT64_TYPE, 1,
472 XDMF_ARRAY_OUT, NumberOfValues );
473
474 // Copy TmpArray to Array
475 Ptr = (XdmfByte *)ArrayPointer;
476 TmpPtr = TmpArray;
477 MemberIndex = 0;
478 NumberOfMembers = this->GetNumberOfMembers();
479 while( NumberOfValues ){
480 MemberType = this->GetMemberType( MemberIndex );
481 MemberLength = this->GetMemberLength( MemberIndex );
482 XDMF_ARRAY_COPY( Ptr, MemberType, 1,
483 TmpPtr, XDMF_FLOAT64_TYPE, 1,
484 XDMF_ARRAY_IN, MemberLength);
485 Ptr += this->GetMemberSize( MemberIndex );
486 NumberOfValues -= MemberLength;
487 MemberIndex++;
488 if( MemberIndex >= NumberOfMembers ) {
489 MemberIndex = 0;
490 }
491 }
492 } else {
493 TmpArray = new XdmfFloat64[ NumberOfValues ];
494 // Copy Array to TmpArray
495 Ptr = (XdmfByte *)ArrayPointer;
496 TmpPtr = TmpArray;
497 MemberIndex = 0;
498 NumberOfMembers = this->GetNumberOfMembers();
499 Length = NumberOfValues;
500 XdmfDebug("Copying " << XDMF_64BIT_CAST NumberOfValues << " Out");
501 while( NumberOfValues ){
502 MemberType = this->GetMemberType( MemberIndex );
503 MemberLength = this->GetMemberLength( MemberIndex );
504 XDMF_ARRAY_COPY( Ptr, MemberType, 1,
505 TmpPtr, XDMF_FLOAT64_TYPE, 1,
506 XDMF_ARRAY_OUT, MemberLength);
507 Ptr += this->GetMemberSize( MemberIndex );
508 NumberOfValues -= MemberLength;
509 MemberIndex++;
510 if( MemberIndex >= NumberOfMembers ) {
511 MemberIndex = 0;
512 }
513 }
514 // Copy TmpArray to Values
515 TmpPtr = TmpArray;
516 Ptr = (XdmfByte *)ValuePointer;
517 XDMF_ARRAY_COPY( Ptr, ValueType, ValueStride,
518 TmpPtr, XDMF_FLOAT64_TYPE, 1,
519 XDMF_ARRAY_IN, Length);
520
521 }
522
523 delete TmpArray;
524 return( XDMF_SUCCESS );
525 }
526
SetValue(XdmfInt64 Index,XdmfInt64 Value)527 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfInt64 Value ) {
528
529 XdmfPointer ArrayPointer;
530 XdmfInt64 *vp;
531
532 ArrayPointer = this->GetDataPointer(Index);
533 vp = &Value;
534 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
535 vp, XDMF_INT64_TYPE, 1,
536 XDMF_ARRAY_IN, 1);
537 return( XDMF_SUCCESS );
538 }
539
SetValue(XdmfInt64 Index,XdmfFloat64 Value)540 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfFloat64 Value ) {
541
542 XdmfPointer ArrayPointer;
543 XdmfFloat64 *vp;
544
545 ArrayPointer = this->GetDataPointer(Index);
546 vp = &Value;
547 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
548 vp, XDMF_FLOAT64_TYPE, 1,
549 XDMF_ARRAY_IN, 1);
550 return( XDMF_SUCCESS );
551 }
552
SetValues(XdmfInt64 Index,XdmfArray * Values,XdmfInt64 NumberOfValues,XdmfInt64 ValuesStart,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)553 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfArray *Values,
554 XdmfInt64 NumberOfValues,
555 XdmfInt64 ValuesStart,
556 XdmfInt64 ArrayStride,
557 XdmfInt64 ValuesStride )
558 {
559 switch(Values->GetNumberType())
560 {
561 case(XDMF_INT8_TYPE):
562 return this->SetValues(Index, (XdmfInt8*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
563 case(XDMF_INT16_TYPE):
564 return this->SetValues(Index, (XdmfInt16*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
565 case(XDMF_INT32_TYPE):
566 return this->SetValues(Index, (XdmfInt32*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
567 case(XDMF_INT64_TYPE):
568 return this->SetValues(Index, (XdmfInt64*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
569 case(XDMF_FLOAT32_TYPE):
570 return this->SetValues(Index, (XdmfFloat32*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
571 case(XDMF_FLOAT64_TYPE):
572 return this->SetValues(Index, (XdmfFloat64*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
573 case(XDMF_UINT8_TYPE):
574 return this->SetValues(Index, (XdmfUInt8*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
575 case(XDMF_UINT16_TYPE):
576 return this->SetValues(Index, (XdmfUInt16*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
577 case(XDMF_UINT32_TYPE):
578 return this->SetValues(Index, (XdmfUInt32*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
579 default:
580 return this->SetValues(Index, (XdmfFloat64*)Values->GetDataPointer(ValuesStart), NumberOfValues, ArrayStride, ValuesStride);
581 }
582 return XDMF_FAIL;
583 }
584
SetValues(XdmfInt64 Index,XdmfConstString Values,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)585 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfConstString Values,
586 XdmfInt64 ArrayStride,
587 XdmfInt64 ValuesStride ) {
588 XdmfPointer ArrayPointer;
589 XdmfInt64 count = 0, i = 0, NumberOfValues;
590 char* NewValues = new char [ strlen(Values) + 1 ];
591 strcpy(NewValues, Values);
592 istrstream ist(NewValues, strlen( NewValues) );
593 istrstream counter(NewValues, strlen( NewValues) );
594 XdmfFloat64 dummy, *ValueArray, *vp;
595
596 while( counter >> dummy ) count++;
597 NumberOfValues = count;
598 vp = ValueArray = new XdmfFloat64[ count + 1 ];
599 while( ist >> dummy ) ValueArray[i++] = dummy;
600 ArrayPointer = this->GetDataPointer(Index);
601 delete [] NewValues;
602 if( ArrayPointer == NULL ){
603 this->SetNumberOfElements( NumberOfValues + Index );
604 ArrayPointer = this->GetDataPointer(Index);
605 }
606 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
607 vp, XDMF_FLOAT64_TYPE, ValuesStride,
608 XDMF_ARRAY_IN, NumberOfValues );
609 delete [] ValueArray;
610 return( XDMF_SUCCESS );
611 }
612
SetValues(XdmfInt64 Index,XdmfUInt8 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)613 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfUInt8 *Values,
614 XdmfInt64 NumberOfValues,
615 XdmfInt64 ArrayStride,
616 XdmfInt64 ValuesStride ) {
617 XdmfPointer ArrayPointer;
618
619 ArrayPointer = this->GetDataPointer(Index);
620 if( ArrayPointer == NULL ){
621 this->SetNumberOfElements( NumberOfValues + Index );
622 ArrayPointer = this->GetDataPointer(Index);
623 }
624 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
625 Values, XDMF_UINT8_TYPE, ValuesStride,
626 XDMF_ARRAY_IN, NumberOfValues );
627 return( XDMF_SUCCESS );
628 }
629
SetValues(XdmfInt64 Index,XdmfUInt16 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)630 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfUInt16 *Values,
631 XdmfInt64 NumberOfValues,
632 XdmfInt64 ArrayStride,
633 XdmfInt64 ValuesStride ) {
634 XdmfPointer ArrayPointer;
635
636 ArrayPointer = this->GetDataPointer(Index);
637 if( ArrayPointer == NULL ){
638 this->SetNumberOfElements( NumberOfValues + Index );
639 ArrayPointer = this->GetDataPointer(Index);
640 }
641 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
642 Values, XDMF_UINT16_TYPE, ValuesStride,
643 XDMF_ARRAY_IN, NumberOfValues );
644 return( XDMF_SUCCESS );
645 }
646
SetValues(XdmfInt64 Index,XdmfUInt32 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)647 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfUInt32 *Values,
648 XdmfInt64 NumberOfValues,
649 XdmfInt64 ArrayStride,
650 XdmfInt64 ValuesStride ) {
651 XdmfPointer ArrayPointer;
652
653 ArrayPointer = this->GetDataPointer(Index);
654 if( ArrayPointer == NULL ){
655 this->SetNumberOfElements( NumberOfValues + Index );
656 ArrayPointer = this->GetDataPointer(Index);
657 }
658 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
659 Values, XDMF_UINT32_TYPE, ValuesStride,
660 XDMF_ARRAY_IN, NumberOfValues );
661 return( XDMF_SUCCESS );
662 }
663
SetValues(XdmfInt64 Index,XdmfInt8 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)664 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfInt8 *Values,
665 XdmfInt64 NumberOfValues,
666 XdmfInt64 ArrayStride,
667 XdmfInt64 ValuesStride ) {
668 XdmfPointer ArrayPointer;
669
670 ArrayPointer = this->GetDataPointer(Index);
671 if( ArrayPointer == NULL ){
672 this->SetNumberOfElements( NumberOfValues + Index );
673 ArrayPointer = this->GetDataPointer(Index);
674 }
675 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
676 Values, XDMF_INT8_TYPE, ValuesStride,
677 XDMF_ARRAY_IN, NumberOfValues );
678 return( XDMF_SUCCESS );
679 }
680
SetValues(XdmfInt64 Index,XdmfInt16 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)681 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfInt16 *Values,
682 XdmfInt64 NumberOfValues,
683 XdmfInt64 ArrayStride,
684 XdmfInt64 ValuesStride ) {
685 XdmfPointer ArrayPointer;
686
687 ArrayPointer = this->GetDataPointer(Index);
688 if( ArrayPointer == NULL ){
689 this->SetNumberOfElements( NumberOfValues + Index );
690 ArrayPointer = this->GetDataPointer(Index);
691 }
692 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
693 Values, XDMF_INT16_TYPE, ValuesStride,
694 XDMF_ARRAY_IN, NumberOfValues );
695 return( XDMF_SUCCESS );
696 }
697
SetValues(XdmfInt64 Index,XdmfInt32 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)698 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfInt32 *Values,
699 XdmfInt64 NumberOfValues,
700 XdmfInt64 ArrayStride,
701 XdmfInt64 ValuesStride ) {
702 XdmfPointer ArrayPointer;
703
704 ArrayPointer = this->GetDataPointer(Index);
705 if( ArrayPointer == NULL ){
706 this->SetNumberOfElements( NumberOfValues + Index );
707 ArrayPointer = this->GetDataPointer(Index);
708 }
709 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
710 Values, XDMF_INT32_TYPE, ValuesStride,
711 XDMF_ARRAY_IN, NumberOfValues );
712 return( XDMF_SUCCESS );
713 }
714
SetValues(XdmfInt64 Index,XdmfInt64 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)715 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfInt64 *Values,
716 XdmfInt64 NumberOfValues,
717 XdmfInt64 ArrayStride,
718 XdmfInt64 ValuesStride ) {
719 XdmfPointer ArrayPointer;
720
721 ArrayPointer = this->GetDataPointer(Index);
722 if( ArrayPointer == NULL ){
723 this->SetNumberOfElements( NumberOfValues + Index );
724 ArrayPointer = this->GetDataPointer(Index);
725 }
726 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
727 Values, XDMF_INT64_TYPE, ValuesStride,
728 XDMF_ARRAY_IN, NumberOfValues );
729 return( XDMF_SUCCESS );
730 }
731
SetValues(XdmfInt64 Index,XdmfFloat32 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)732 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfFloat32 *Values,
733 XdmfInt64 NumberOfValues,
734 XdmfInt64 ArrayStride,
735 XdmfInt64 ValuesStride ) {
736 XdmfPointer ArrayPointer;
737
738 ArrayPointer = this->GetDataPointer(Index);
739 if( ArrayPointer == NULL ){
740 this->SetNumberOfElements( NumberOfValues + Index );
741 ArrayPointer = this->GetDataPointer(Index);
742 }
743 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
744 Values, XDMF_FLOAT32_TYPE, ValuesStride,
745 XDMF_ARRAY_IN, NumberOfValues );
746 return( XDMF_SUCCESS );
747 }
748
SetValues(XdmfInt64 Index,XdmfFloat64 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)749 XdmfInt32 XdmfArray::SetValues( XdmfInt64 Index, XdmfFloat64 *Values,
750 XdmfInt64 NumberOfValues,
751 XdmfInt64 ArrayStride,
752 XdmfInt64 ValuesStride ) {
753 XdmfPointer ArrayPointer;
754
755 ArrayPointer = this->GetDataPointer(Index);
756 if( ArrayPointer == NULL ){
757 this->SetNumberOfElements( NumberOfValues + Index );
758 ArrayPointer = this->GetDataPointer(Index);
759 }
760 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
761 Values, XDMF_FLOAT64_TYPE, ValuesStride,
762 XDMF_ARRAY_IN, NumberOfValues );
763 return( XDMF_SUCCESS );
764 }
765
766
GetValueAsFloat64(XdmfInt64 Index)767 XdmfFloat64 XdmfArray::GetValueAsFloat64( XdmfInt64 Index ) {
768
769 XdmfPointer ArrayPointer;
770 XdmfFloat64 Value, *vp = &Value;
771
772 ArrayPointer = this->GetDataPointer(Index);
773 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
774 vp, XDMF_FLOAT64_TYPE, 1,
775 XDMF_ARRAY_OUT, 1);
776 return( Value );
777 }
778
GetValueAsFloat32(XdmfInt64 Index)779 XdmfFloat32 XdmfArray::GetValueAsFloat32( XdmfInt64 Index ) {
780
781 XdmfPointer ArrayPointer;
782 XdmfFloat32 Value, *vp = &Value;
783
784 ArrayPointer = this->GetDataPointer(Index);
785 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
786 vp, XDMF_FLOAT32_TYPE, 1,
787 XDMF_ARRAY_OUT, 1);
788 return( Value );
789 }
790
GetValueAsInt64(XdmfInt64 Index)791 XdmfInt64 XdmfArray::GetValueAsInt64( XdmfInt64 Index ) {
792
793 XdmfPointer ArrayPointer;
794 XdmfInt64 Value, *vp = &Value;
795
796 ArrayPointer = this->GetDataPointer(Index);
797 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
798 vp, XDMF_INT64_TYPE, 1,
799 XDMF_ARRAY_OUT, 1);
800 return( Value );
801 }
802
GetValueAsInt32(XdmfInt64 Index)803 XdmfInt32 XdmfArray::GetValueAsInt32( XdmfInt64 Index ) {
804
805 XdmfPointer ArrayPointer;
806 XdmfInt32 Value, *vp = &Value;
807
808 ArrayPointer = this->GetDataPointer(Index);
809 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
810 vp, XDMF_INT32_TYPE, 1,
811 XDMF_ARRAY_OUT, 1);
812 return( Value );
813 }
814
GetValueAsInt16(XdmfInt64 Index)815 XdmfInt16 XdmfArray::GetValueAsInt16( XdmfInt64 Index ) {
816
817 XdmfPointer ArrayPointer;
818 XdmfInt16 Value, *vp = &Value;
819
820 ArrayPointer = this->GetDataPointer(Index);
821 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
822 vp, XDMF_INT16_TYPE, 1,
823 XDMF_ARRAY_OUT, 1);
824 return( Value );
825 }
826
GetValueAsInt8(XdmfInt64 Index)827 XdmfInt8 XdmfArray::GetValueAsInt8( XdmfInt64 Index ) {
828
829 XdmfPointer ArrayPointer;
830 XdmfInt8 Value, *vp = &Value;
831
832 ArrayPointer = this->GetDataPointer(Index);
833 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
834 vp, XDMF_INT8_TYPE, 1,
835 XDMF_ARRAY_OUT, 1);
836 return( Value );
837 }
838
839
GetValues(XdmfInt64 Index,XdmfUInt8 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)840 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfUInt8 *Values,
841 XdmfInt64 NumberOfValues,
842 XdmfInt64 ArrayStride,
843 XdmfInt64 ValuesStride ) {
844 XdmfPointer ArrayPointer;
845
846 ArrayPointer = this->GetDataPointer(Index);
847 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
848 Values, XDMF_UINT8_TYPE, ValuesStride,
849 XDMF_ARRAY_OUT, NumberOfValues );
850 return( XDMF_SUCCESS );
851 }
852
GetValues(XdmfInt64 Index,XdmfUInt16 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)853 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfUInt16 *Values,
854 XdmfInt64 NumberOfValues,
855 XdmfInt64 ArrayStride,
856 XdmfInt64 ValuesStride ) {
857 XdmfPointer ArrayPointer;
858
859 ArrayPointer = this->GetDataPointer(Index);
860 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
861 Values, XDMF_UINT16_TYPE, ValuesStride,
862 XDMF_ARRAY_OUT, NumberOfValues );
863 return( XDMF_SUCCESS );
864 }
865
GetValues(XdmfInt64 Index,XdmfUInt32 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)866 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfUInt32 *Values,
867 XdmfInt64 NumberOfValues,
868 XdmfInt64 ArrayStride,
869 XdmfInt64 ValuesStride ) {
870 XdmfPointer ArrayPointer;
871
872 ArrayPointer = this->GetDataPointer(Index);
873 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
874 Values, XDMF_UINT32_TYPE, ValuesStride,
875 XDMF_ARRAY_OUT, NumberOfValues );
876 return( XDMF_SUCCESS );
877 }
878
GetValues(XdmfInt64 Index,XdmfInt8 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)879 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfInt8 *Values,
880 XdmfInt64 NumberOfValues,
881 XdmfInt64 ArrayStride,
882 XdmfInt64 ValuesStride ) {
883 XdmfPointer ArrayPointer;
884
885 ArrayPointer = this->GetDataPointer(Index);
886 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
887 Values, XDMF_INT8_TYPE, ValuesStride,
888 XDMF_ARRAY_OUT, NumberOfValues );
889 return( XDMF_SUCCESS );
890 }
891
GetValues(XdmfInt64 Index,XdmfInt16 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)892 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfInt16 *Values,
893 XdmfInt64 NumberOfValues,
894 XdmfInt64 ArrayStride,
895 XdmfInt64 ValuesStride ) {
896 XdmfPointer ArrayPointer;
897
898 ArrayPointer = this->GetDataPointer(Index);
899 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
900 Values, XDMF_INT16_TYPE, ValuesStride,
901 XDMF_ARRAY_OUT, NumberOfValues );
902 return( XDMF_SUCCESS );
903 }
904
GetValues(XdmfInt64 Index,XdmfInt32 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)905 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfInt32 *Values,
906 XdmfInt64 NumberOfValues,
907 XdmfInt64 ArrayStride,
908 XdmfInt64 ValuesStride ) {
909 XdmfPointer ArrayPointer;
910
911 ArrayPointer = this->GetDataPointer(Index);
912 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
913 Values, XDMF_INT32_TYPE, ValuesStride,
914 XDMF_ARRAY_OUT, NumberOfValues );
915 return( XDMF_SUCCESS );
916 }
917
GetValues(XdmfInt64 Index,XdmfInt64 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)918 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfInt64 *Values,
919 XdmfInt64 NumberOfValues,
920 XdmfInt64 ArrayStride,
921 XdmfInt64 ValuesStride ) {
922 XdmfPointer ArrayPointer;
923
924 ArrayPointer = this->GetDataPointer(Index);
925 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
926 Values, XDMF_INT64_TYPE, ValuesStride,
927 XDMF_ARRAY_OUT, NumberOfValues );
928 return( XDMF_SUCCESS );
929 }
930
GetValues(XdmfInt64 Index,XdmfFloat32 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)931 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfFloat32 *Values,
932 XdmfInt64 NumberOfValues,
933 XdmfInt64 ArrayStride,
934 XdmfInt64 ValuesStride ) {
935 XdmfPointer ArrayPointer;
936
937 ArrayPointer = this->GetDataPointer(Index);
938 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
939 Values, XDMF_FLOAT32_TYPE, ValuesStride,
940 XDMF_ARRAY_OUT, NumberOfValues );
941 return( XDMF_SUCCESS );
942 }
943
GetValues(XdmfInt64 Index,XdmfFloat64 * Values,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride,XdmfInt64 ValuesStride)944 XdmfInt32 XdmfArray::GetValues( XdmfInt64 Index, XdmfFloat64 *Values,
945 XdmfInt64 NumberOfValues,
946 XdmfInt64 ArrayStride,
947 XdmfInt64 ValuesStride ) {
948 XdmfPointer ArrayPointer;
949
950 ArrayPointer = this->GetDataPointer(Index);
951 XdmfDebug("Getting " << XDMF_64BIT_CAST NumberOfValues << " From Pointer = " << ArrayPointer << " to " << Values );
952 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), ArrayStride,
953 Values, XDMF_FLOAT64_TYPE, ValuesStride,
954 XDMF_ARRAY_OUT, NumberOfValues );
955 return( XDMF_SUCCESS );
956 }
957
GetValues(XdmfInt64 Index,XdmfInt64 NumberOfValues,XdmfInt64 ArrayStride)958 XdmfString XdmfArray::GetValues( XdmfInt64 Index,
959 XdmfInt64 NumberOfValues,
960 XdmfInt64 ArrayStride ) {
961
962 XdmfInt64 i = 0, MemberLength;
963 XdmfInt64 *IntValues;
964 XdmfFloat64 * FloatValues;
965 ostrstream StringOutput;
966 XdmfString Ptr;
967 static XdmfString ReturnString = NULL;
968
969
970
971 if( NumberOfValues == 0 ){
972 NumberOfValues = this->GetNumberOfElements() - Index;
973 }
974 // NumberOfValues -= 1;
975 if( this->GetNumberType() == XDMF_COMPOUND_TYPE ){
976 XdmfDebug("Array is Compound, increasing value of NumberOfValues " << XDMF_64BIT_CAST NumberOfValues );
977 MemberLength = 0;
978 for( i = 0 ; i < this->GetNumberOfMembers() ; i++ ){
979 MemberLength += this->GetMemberLength(i);
980 }
981 NumberOfValues *= MemberLength;
982 XdmfDebug("New NumberOfValues = " << XDMF_64BIT_CAST NumberOfValues );
983 }
984
985 if( this->GetNumberType() == XDMF_INT8_TYPE || this->GetNumberType() == XDMF_INT16_TYPE || this->GetNumberType() == XDMF_INT32_TYPE || this->GetNumberType() == XDMF_INT64_TYPE || this->GetNumberType() == XDMF_UINT8_TYPE || this->GetNumberType() == XDMF_UINT16_TYPE || this->GetNumberType() == XDMF_UINT32_TYPE) {
986 IntValues = new XdmfInt64[ NumberOfValues + 10 ];
987 this->GetValues( Index, IntValues, NumberOfValues, ArrayStride, 1 );
988 i = 0;
989 while( NumberOfValues-- ) {
990 StringOutput << (long)IntValues[i++] << " ";
991 }
992 delete [] IntValues;
993 }
994 else {
995 FloatValues = new XdmfFloat64[ NumberOfValues + 10];
996 this->GetValues( Index, FloatValues, NumberOfValues, ArrayStride, 1 );
997 i=0;
998 while( NumberOfValues-- ) {
999 StringOutput << (double)FloatValues[i++] << " ";
1000 }
1001 delete [] FloatValues;
1002 }
1003
1004 StringOutput << ends;
1005 Ptr = StringOutput.str();
1006 if ( ReturnString != NULL ) delete [] ReturnString;
1007 ReturnString = new char[ strlen( Ptr ) + 2 ];
1008 strcpy( ReturnString, Ptr );
1009 delete [] Ptr;
1010 return( ReturnString );
1011 }
1012
Generate(XdmfFloat64 StartValue,XdmfFloat64 EndValue,XdmfInt64 StartIndex,XdmfInt64 EndIndex)1013 XdmfInt32 XdmfArray::Generate( XdmfFloat64 StartValue,
1014 XdmfFloat64 EndValue,
1015 XdmfInt64 StartIndex,
1016 XdmfInt64 EndIndex ){
1017
1018 XdmfFloat64 *Values, *vp, Current, Delta;
1019 XdmfInt64 i, Length;
1020
1021 if( EndIndex == StartIndex ) EndIndex = this->GetNumberOfElements() - 1;
1022 Length = EndIndex - StartIndex;
1023 vp = Values = new XdmfFloat64[ Length + 1];
1024 Current = StartValue;
1025 Delta = ( EndValue - StartValue ) / Length;
1026 Length++;
1027 for( i = 0 ; i < Length ; i++ ) {
1028 *vp++ = Current;
1029 Current += Delta;
1030 }
1031 this->SetValues( StartIndex, Values, Length, 1, 1);
1032 delete [] Values;
1033 return( XDMF_SUCCESS );
1034 }
1035
1036 XdmfArray &
operator =(XdmfArray & Array)1037 XdmfArray::operator=( XdmfArray &Array ){
1038
1039 XdmfInt64 Length;
1040 XdmfPointer ArrayPointer;
1041 XdmfFloat64 *Vp, *Values;
1042
1043 Length = MIN( this->GetNumberOfElements(), Array.GetNumberOfElements() );
1044 Vp = Values = new XdmfFloat64[ Length + 10 ];
1045 Array.GetValues( 0, Values, Length );
1046 ArrayPointer = this->GetDataPointer();
1047 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
1048 Vp, XDMF_FLOAT64_TYPE, 1,
1049 XDMF_ARRAY_IN, Length );
1050 delete [] Values;
1051 return( *this );
1052 }
1053
1054 XdmfArray &
operator =(XdmfFloat64 Value)1055 XdmfArray::operator=( XdmfFloat64 Value ){
1056
1057 XdmfPointer ArrayPointer;
1058 XdmfFloat64 *Vp = &Value;
1059
1060 ArrayPointer = this->GetDataPointer();
1061 XDMF_ARRAY_COPY( ArrayPointer, this->GetNumberType(), 1,
1062 Vp, XDMF_FLOAT64_TYPE, 0,
1063 XDMF_ARRAY_IN, this->GetNumberOfElements());
1064 return( *this );
1065 }
1066
1067 XdmfArray &
operator +(XdmfArray & Array)1068 XdmfArray::operator+( XdmfArray &Array ){
1069 XdmfInt64 Length;
1070 XdmfPointer ArrayPointer;
1071 XdmfFloat64 *Vp, *Values;
1072
1073 Length = MIN( this->GetNumberOfElements(), Array.GetNumberOfElements() );
1074 Vp = Values = new XdmfFloat64[ Length + 10 ];
1075 Array.GetValues( 0, Values, Length );
1076 ArrayPointer = this->GetDataPointer();
1077 XDMF_ARRAY_OPERATE( XdmfArrayAddTag, ArrayPointer, this->GetNumberType(), 1,
1078 Vp, XDMF_FLOAT64_TYPE, 1,
1079 XDMF_ARRAY_IN, Length );
1080 delete [] Values;
1081 return( *this );
1082 }
1083
1084 XdmfArray &
operator +(XdmfFloat64 Value)1085 XdmfArray::operator+( XdmfFloat64 Value ){
1086 XdmfPointer ArrayPointer;
1087 XdmfFloat64 *Vp = &Value;
1088
1089 ArrayPointer = this->GetDataPointer();
1090 XDMF_ARRAY_OPERATE( XdmfArrayAddTag, ArrayPointer, this->GetNumberType(), 1,
1091 Vp, XDMF_FLOAT64_TYPE, 0,
1092 XDMF_ARRAY_IN, this->GetNumberOfElements());
1093 return( *this );
1094 }
1095
1096 XdmfArray &
operator -(XdmfArray & Array)1097 XdmfArray::operator-( XdmfArray &Array ){
1098 XdmfInt64 Length;
1099 XdmfPointer ArrayPointer;
1100 XdmfFloat64 *Vp, *Values;
1101
1102 Length = MIN( this->GetNumberOfElements(), Array.GetNumberOfElements() );
1103 Vp = Values = new XdmfFloat64[ Length + 10 ];
1104 Array.GetValues( 0, Values, Length );
1105 ArrayPointer = this->GetDataPointer();
1106 XDMF_ARRAY_OPERATE( XdmfArraySubtractTag, ArrayPointer, this->GetNumberType(), 1,
1107 Vp, XDMF_FLOAT64_TYPE, 1,
1108 XDMF_ARRAY_IN, Length );
1109 delete [] Values;
1110 return( *this );
1111 }
1112
1113 XdmfArray &
operator -(XdmfFloat64 Value)1114 XdmfArray::operator-( XdmfFloat64 Value ){
1115 XdmfPointer ArrayPointer;
1116 XdmfFloat64 *Vp = &Value;
1117
1118 ArrayPointer = this->GetDataPointer();
1119 XDMF_ARRAY_OPERATE( XdmfArraySubtractTag, ArrayPointer, this->GetNumberType(), 1,
1120 Vp, XDMF_FLOAT64_TYPE, 0,
1121 XDMF_ARRAY_IN, this->GetNumberOfElements());
1122 return( *this );
1123 }
1124
1125 XdmfArray &
operator *(XdmfArray & Array)1126 XdmfArray::operator*( XdmfArray &Array ){
1127 XdmfInt64 Length;
1128 XdmfPointer ArrayPointer;
1129 XdmfFloat64 *Vp, *Values;
1130
1131 Length = MIN( this->GetNumberOfElements(), Array.GetNumberOfElements() );
1132 Vp = Values = new XdmfFloat64[ Length + 10 ];
1133 Array.GetValues( 0, Values, Length );
1134 ArrayPointer = this->GetDataPointer();
1135 XDMF_ARRAY_OPERATE( XdmfArrayMultiplyTag, ArrayPointer, this->GetNumberType(), 1,
1136 Vp, XDMF_FLOAT64_TYPE, 1,
1137 XDMF_ARRAY_IN, Length );
1138 delete [] Values;
1139 return( *this );
1140 }
1141
1142 XdmfArray &
operator *(XdmfFloat64 Value)1143 XdmfArray::operator*( XdmfFloat64 Value ){
1144 XdmfPointer ArrayPointer;
1145 XdmfFloat64 *Vp = &Value;
1146
1147 ArrayPointer = this->GetDataPointer();
1148 XDMF_ARRAY_OPERATE( XdmfArrayMultiplyTag, ArrayPointer, this->GetNumberType(), 1,
1149 Vp, XDMF_FLOAT64_TYPE, 0,
1150 XDMF_ARRAY_IN, this->GetNumberOfElements());
1151 return( *this );
1152 }
1153
1154 XdmfArray &
operator /(XdmfArray & Array)1155 XdmfArray::operator/( XdmfArray &Array ){
1156 XdmfInt64 Length;
1157 XdmfPointer ArrayPointer;
1158 XdmfFloat64 *Vp, *Values;
1159
1160 Length = MIN( this->GetNumberOfElements(), Array.GetNumberOfElements() );
1161 Vp = Values = new XdmfFloat64[ Length + 10 ];
1162 Array.GetValues( 0, Values, Length );
1163 ArrayPointer = this->GetDataPointer();
1164 XDMF_ARRAY_OPERATE( XdmfArrayDivideTag, ArrayPointer, this->GetNumberType(), 1,
1165 Vp, XDMF_FLOAT64_TYPE, 1,
1166 XDMF_ARRAY_IN, Length );
1167 delete [] Values;
1168 return( *this );
1169 }
1170
1171 XdmfArray &
operator /(XdmfFloat64 Value)1172 XdmfArray::operator/( XdmfFloat64 Value ){
1173 XdmfPointer ArrayPointer;
1174 XdmfFloat64 *Vp = &Value;
1175
1176 ArrayPointer = this->GetDataPointer();
1177 XDMF_ARRAY_OPERATE( XdmfArrayDivideTag, ArrayPointer, this->GetNumberType(), 1,
1178 Vp, XDMF_FLOAT64_TYPE, 0,
1179 XDMF_ARRAY_IN, this->GetNumberOfElements());
1180 return( *this );
1181 }
1182
1183 XdmfArray *
Clone(XdmfArray * Indexes)1184 XdmfArray::Clone( XdmfArray *Indexes ){
1185
1186 XdmfLength i, Length, Size;
1187 XdmfByte *Ptr, *Source, *Target;
1188 XdmfArray *NewArray = new XdmfArray();
1189 XdmfInt64 *IVals;
1190
1191
1192 Length = Indexes->GetNumberOfElements();
1193 IVals = new XdmfInt64[ Length + 10 ];
1194 Indexes->GetValues( 0, IVals, Length );
1195 NewArray->SetNumberType( this->GetNumberType() );
1196 NewArray->SetNumberOfElements( Length );
1197 Source = ( XdmfByte *)this->GetDataPointer();
1198 Target = ( XdmfByte *)NewArray->GetDataPointer(0);
1199 Size = this->GetElementSize();
1200 for( i = 0 ; i < Length ; i++ ){
1201 Ptr = Source + ( Size * IVals[ i ] );
1202 memcpy( Target, Ptr, Size );
1203 Target += Size;
1204 }
1205 delete [] IVals;
1206 return( NewArray );
1207 }
1208
1209 XdmfArray *
Clone(XdmfLength start,XdmfLength End)1210 XdmfArray::Clone( XdmfLength start, XdmfLength End ) {
1211
1212 XdmfLength Length;
1213 XdmfArray *NewArray = new XdmfArray();
1214
1215
1216 if( ( start == 0 ) && ( End == 0 )){
1217 NewArray->CopyType( this );
1218 NewArray->CopyShape( this );
1219 Length = this->GetNumberOfElements();
1220 End = Length - 1;
1221 } else {
1222 if( End <= start ) End = this->GetNumberOfElements() - start - 1;
1223 Length = End - start + 1;
1224 NewArray->SetNumberType( this->GetNumberType() );
1225 NewArray->SetNumberOfElements( Length );
1226 }
1227 memcpy( NewArray->GetDataPointer(0),
1228 this->GetDataPointer( start ),
1229 Length * this->GetElementSize() );
1230 return( NewArray );
1231 }
1232
1233 XdmfArray *
Reference(XdmfLength start,XdmfLength End)1234 XdmfArray::Reference( XdmfLength start, XdmfLength End ) {
1235
1236 XdmfLength Length;
1237 XdmfArray *NewArray = new XdmfArray();
1238
1239
1240 if( End <= start ) End = this->GetNumberOfElements() - start - 1;
1241 Length = End - start + 1;
1242 NewArray->SetNumberType( this->GetNumberType() );
1243 NewArray->SetDataPointer( this->GetDataPointer( start ) );
1244 NewArray->SetNumberOfElements( Length );
1245 return( NewArray );
1246 }
1247
1248
1249 XdmfFloat64
GetMean(void)1250 XdmfArray::GetMean( void ) {
1251 XdmfLength i, Length;
1252 XdmfFloat64 Value, *Data;
1253
1254 Length = this->GetNumberOfElements();
1255 Data = new XdmfFloat64[ Length + 10 ];
1256 this->GetValues( 0, Data, Length);
1257 Value = 0;
1258 for( i = 0 ; i < Length ; i++ ){
1259 Value += Data[i];
1260 }
1261 delete [] Data;
1262 Value /= Length;
1263 return( Value );
1264 }
1265
1266 XdmfFloat64
GetMaxAsFloat64(void)1267 XdmfArray::GetMaxAsFloat64( void ) {
1268 XdmfLength i, Length;
1269 XdmfFloat64 Value, *Data;
1270
1271 Length = this->GetNumberOfElements();
1272 Data = new XdmfFloat64[ Length ];
1273 this->GetValues( 0, Data, Length);
1274 Value = Data[0];
1275 for( i = 0 ; i < Length ; i++ ){
1276 if ( Data[i] > Value ) {
1277 Value = Data[i];
1278 }
1279 }
1280 delete [] Data;
1281 return( Value );
1282 }
1283
1284 XdmfFloat64
GetMinAsFloat64(void)1285 XdmfArray::GetMinAsFloat64( void ) {
1286 XdmfLength i, Length;
1287 XdmfFloat64 Value, *Data;
1288
1289 Length = this->GetNumberOfElements();
1290 Data = new XdmfFloat64[ Length ];
1291 this->GetValues( 0, Data, Length);
1292 Value = Data[0];
1293 for( i = 0 ; i < Length ; i++ ){
1294 if ( Data[i] < Value ) {
1295 Value = Data[i];
1296 }
1297 }
1298 delete [] Data;
1299 return( Value );
1300 }
1301
1302 XdmfInt64
GetMinAsInt64(void)1303 XdmfArray::GetMinAsInt64( void ) {
1304 XdmfLength i, Length;
1305 XdmfInt64 Value, *Data;
1306
1307 Length = this->GetNumberOfElements();
1308 Data = new XdmfInt64[ Length ];
1309 this->GetValues( 0, Data, Length);
1310 Value = Data[0];
1311 for( i = 0 ; i < Length ; i++ ){
1312 if ( Data[i] < Value ) {
1313 Value = Data[i];
1314 }
1315 }
1316 delete [] Data;
1317 return( Value );
1318 }
1319
1320 XdmfInt64
GetMaxAsInt64(void)1321 XdmfArray::GetMaxAsInt64( void ) {
1322 XdmfLength i, Length;
1323 XdmfInt64 Value, *Data;
1324
1325 Length = this->GetNumberOfElements();
1326 Data = new XdmfInt64[ Length ];
1327 this->GetValues( 0, Data, Length);
1328 Value = Data[0];
1329 for( i = 0 ; i < Length ; i++ ){
1330 if ( Data[i] > Value ) {
1331 Value = Data[i];
1332 }
1333 }
1334 delete [] Data;
1335 return( Value );
1336 }
1337
SetValue(XdmfInt64 Index,XdmfUInt8 Value)1338 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfUInt8 Value ) {
1339 return(this->SetValueFromInt64( Index, Value ));
1340 }
SetValue(XdmfInt64 Index,XdmfUInt16 Value)1341 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfUInt16 Value ) {
1342 return(this->SetValueFromInt64( Index, Value ));
1343 }
SetValue(XdmfInt64 Index,XdmfUInt32 Value)1344 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfUInt32 Value ) {
1345 return(this->SetValueFromInt64( Index, Value ));
1346 }
SetValue(XdmfInt64 Index,XdmfInt8 Value)1347 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfInt8 Value ) {
1348 return(this->SetValueFromInt64( Index, Value ));
1349 }
SetValue(XdmfInt64 Index,XdmfInt16 Value)1350 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfInt16 Value ) {
1351 return(this->SetValueFromInt64( Index, Value ));
1352 }
SetValue(XdmfInt64 Index,XdmfInt32 Value)1353 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfInt32 Value ) {
1354 return(this->SetValueFromInt64( Index, Value ));
1355 }
1356
SetValue(XdmfInt64 Index,XdmfFloat32 Value)1357 XdmfInt32 XdmfArray::SetValue( XdmfInt64 Index, XdmfFloat32 Value ) {
1358 return(this->SetValueFromFloat64( Index, Value ));
1359 }
1360
ICE_READ_STREAM64(istrstream & istr,XDMF_64_INT & i)1361 istrstream& ICE_READ_STREAM64(istrstream& istr, XDMF_64_INT& i)
1362 {
1363 #if defined( ICE_HAVE_64BIT_STREAMS )
1364 istr >>i;
1365 #else
1366 double d = 0;
1367 istr >> d;
1368 i = (XDMF_64_INT)d;
1369 #endif
1370 return istr;
1371 }
1372
1373 }
1374