BrookFloatStreamInternal.cpp 17.3 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * Authors: Peter Eastman, Mark Friedrichs                                    *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

32
#include <sstream>
Mark Friedrichs's avatar
Mark Friedrichs committed
33
34
#include "BrookFloatStreamInternal.h"
#include "BrookPlatform.h"
35
#include "OpenMMException.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
36
37
38

using namespace OpenMM;

39
/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
40
 * BrookFloatStreamInternal constructor
41
42
43
44
45
46
47
48
49
50
 * 
 * @param name                      stream name
 * @param size                      stream size
 * @param type                      stream type (float, float2, ...)
 * @param platform                  platform
 * @param inputStreamWidth          stream width
 * @param inputDefaultDangleValue   default dangle value
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
51
52
BrookFloatStreamInternal::BrookFloatStreamInternal( const std::string& name, int size, int streamWidth, BrookStreamInternal::DataType type,
                                                    double inputDefaultDangleValue ) : BrookStreamInternal( name, size, streamWidth, type ){
53
54
55

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
56
   static const std::string methodName      = "BrookFloatStreamInternal::BrookFloatStreamInternal";
57
58
59
60
61
62
63

// ---------------------------------------------------------------------------------------

   // set base type (currently only FLOAT supported)

   switch( type ){

Mark Friedrichs's avatar
Mark Friedrichs committed
64
65
66
67
      case BrookStreamInternal::Float:
      case BrookStreamInternal::Float2:
      case BrookStreamInternal::Float3:
      case BrookStreamInternal::Float4:
68
   
Mark Friedrichs's avatar
Mark Friedrichs committed
69
          _baseType = BrookStreamInternal::Float;
70
71
          break;
   
Mark Friedrichs's avatar
Mark Friedrichs committed
72
73
74
75
      case BrookStreamInternal::Double:
      case BrookStreamInternal::Double2:
      case BrookStreamInternal::Double3:
      case BrookStreamInternal::Double4:
76

Mark Friedrichs's avatar
Mark Friedrichs committed
77
          _baseType = BrookStreamInternal::Double;
78
79
80
81
82
83
84
          break;

      default:
         std::stringstream message;
         message << methodName << " stream=" << name << " input type=" << type << " not recognized.";
         throw OpenMMException( message.str() );
         break;
Mark Friedrichs's avatar
Mark Friedrichs committed
85
86
   }

87
   // set _width (FLOAT, FLOAT2, ... )
Mark Friedrichs's avatar
Mark Friedrichs committed
88

89
   switch( type ){
Mark Friedrichs's avatar
Mark Friedrichs committed
90

Mark Friedrichs's avatar
Mark Friedrichs committed
91
92
      case BrookStreamInternal::Float:
      case BrookStreamInternal::Double:
Mark Friedrichs's avatar
Mark Friedrichs committed
93

94
95
96
          _width = 1;
          break;

Mark Friedrichs's avatar
Mark Friedrichs committed
97
98
      case BrookStreamInternal::Float2:
      case BrookStreamInternal::Double2:
99
100
101
102

          _width = 2;
          break;

Mark Friedrichs's avatar
Mark Friedrichs committed
103
104
      case BrookStreamInternal::Float3:
      case BrookStreamInternal::Double3:
Mark Friedrichs's avatar
Mark Friedrichs committed
105

106
107
          _width = 3;
          break;
Mark Friedrichs's avatar
Mark Friedrichs committed
108

Mark Friedrichs's avatar
Mark Friedrichs committed
109
110
      case BrookStreamInternal::Float4:
      case BrookStreamInternal::Double4:
Mark Friedrichs's avatar
Mark Friedrichs committed
111

112
113
114
115
          _width = 4;
          break;
   }

Mark Friedrichs's avatar
Mark Friedrichs committed
116
   _defaultDangleValue = (float) inputDefaultDangleValue;
117
118
119

   // set stream height based on specified stream _width

Mark Friedrichs's avatar
Mark Friedrichs committed
120
   if( streamWidth < 1 ){
121

122
      std::stringstream message;
Mark Friedrichs's avatar
Mark Friedrichs committed
123
      message << methodName << " stream=" << name << " input stream width=" << streamWidth << " is less than 1.";
124
125
126
127
      throw OpenMMException( message.str() );
   }

   // create Brook stream handle
Mark Friedrichs's avatar
Mark Friedrichs committed
128

129
   switch( _width ){
Mark Friedrichs's avatar
Mark Friedrichs committed
130

131
      case 1:
Mark Friedrichs's avatar
Mark Friedrichs committed
132

133
134
135
136
         _aStream      = brook::stream::create<float>(  _streamHeight, _streamWidth );
         break;
   
      case 2:
Mark Friedrichs's avatar
Mark Friedrichs committed
137

138
139
140
141
         _aStream      = brook::stream::create<float2>( _streamHeight, _streamWidth );
         break;
   
      case 3:
Mark Friedrichs's avatar
Mark Friedrichs committed
142

143
144
145
146
         _aStream      = brook::stream::create<float3>( _streamHeight, _streamWidth );
         break;
   
      case 4:
Mark Friedrichs's avatar
Mark Friedrichs committed
147

148
149
         _aStream      = brook::stream::create<float4>( _streamHeight, _streamWidth );
         break;
Mark Friedrichs's avatar
Mark Friedrichs committed
150
151
   }

Mark Friedrichs's avatar
Mark Friedrichs committed
152
   int streamSize = getStreamSize();
Mark Friedrichs's avatar
Mark Friedrichs committed
153

Mark Friedrichs's avatar
Mark Friedrichs committed
154
   // allocate memory for data buffer
Mark Friedrichs's avatar
Mark Friedrichs committed
155

Mark Friedrichs's avatar
Mark Friedrichs committed
156
   _data = new float[streamSize*_width];
157

158
159
160
//printf( "%s %s data=%u stream=%d [%d %d] width=%d\n", methodName.c_str(), getName().c_str(), (unsigned int) _data, streamSize, _streamHeight, _streamWidth, _width );
//fflush( stdout );

161
162
163
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
164
 * BrookFloatStreamInternal destructor
165
166
167
 * 
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
168
BrookFloatStreamInternal::~BrookFloatStreamInternal( ){
169
170
171

// ---------------------------------------------------------------------------------------

172
   static const std::string methodName      = "BrookFloatStreamInternal::~BrookFloatStreamInternal";
173
174
175
176

// ---------------------------------------------------------------------------------------

   //delete _aStream;
177
178
179
180

//printf( "%s %s data=%u stream=%d [%d %d] width=%d\n", methodName.c_str(), getName().c_str(), (unsigned int) _data, getStreamSize(), _streamHeight, _streamWidth, _width );
//fflush( stdout );

181
182
   delete[] _data;

Mark Friedrichs's avatar
Mark Friedrichs committed
183
184
185
186
187
188
189
}

/** 
 * Get dangle value
 * 
 * @return  dangle value
 */
190

Mark Friedrichs's avatar
Mark Friedrichs committed
191
192
double BrookFloatStreamInternal::getDangleValue( void ) const {
   return _defaultDangleValue;
193
194
195
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
196
 * Load data from input array
197
198
199
200
201
202
 * 
 * @param  array a pointer to the start of the array.  The array is assumed to have the same length as this stream,
 * and to contain elements of the correct _data type for this stream.  If the stream has a compound _data type, all
 * the values should be packed into a single array: all the values for the first element, followed by all the values
 * for the next element, etc.
 *
Mark Friedrichs's avatar
Mark Friedrichs committed
203
204
 * @throw exception if baseType not recognized
 *
205
206
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
207
void BrookFloatStreamInternal::loadFromArray( const void* array ){
208
209
210

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
211
   //static const std::string methodName      = "BrookFloatStreamInternal::loadFromArray";
212
213
214

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
215
   return loadFromArray( array, getBaseDataType() );
216

Mark Friedrichs's avatar
Mark Friedrichs committed
217
218
}

219
/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
220
 * Load data from input array
221
222
223
224
225
226
 * 
 * @param  array a pointer to the start of the array.  The array is assumed to have the same length as this stream,
 * and to contain elements of the correct _data type for this stream.  If the stream has a compound _data type, all
 * the values should be packed into a single array: all the values for the first element, followed by all the values
 * for the next element, etc.
 *
227
 * @throw exception if baseType not float, double, or integer
228
229
 *
 */
Mark Friedrichs's avatar
Mark Friedrichs committed
230

Mark Friedrichs's avatar
Mark Friedrichs committed
231
void BrookFloatStreamInternal::loadFromArray( const void* array, BrookStreamInternal::DataType baseType ){
232
233
234

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
235
   static const std::string methodName      = "BrookFloatStreamInternal::loadFromArray";
236
237
238

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
239
   int totalSize                           = getSize()*getWidth();
240
   //int totalSize                           = getSize();
241

Mark Friedrichs's avatar
Mark Friedrichs committed
242
243
244
245
246
247
248
   if( baseType == BrookStreamInternal::Float ){

      memcpy( _data, array, sizeof( float )*totalSize );
/*
      float* arrayData = (float*) array;
      for( int ii = 0; ii < totalSize; ii++ ){
         _data[ii] = (BrookOpenMMFloat) arrayData[ii];
Mark Friedrichs's avatar
Mark Friedrichs committed
249
      }
Mark Friedrichs's avatar
Mark Friedrichs committed
250
*/
Mark Friedrichs's avatar
Mark Friedrichs committed
251

Mark Friedrichs's avatar
Mark Friedrichs committed
252
   } else if( baseType == BrookStreamInternal::Double ){
Mark Friedrichs's avatar
Mark Friedrichs committed
253
254

      double* arrayData = (double*) array;
Mark Friedrichs's avatar
Mark Friedrichs committed
255
256
      for( int ii = 0; ii < totalSize; ii++ ){
         _data[ii] = (BrookOpenMMFloat) arrayData[ii];
257
258
      }

Mark Friedrichs's avatar
Mark Friedrichs committed
259
   } else if( baseType == BrookStreamInternal::Integer ){
260
261

      int* arrayData = (int*) array;
Mark Friedrichs's avatar
Mark Friedrichs committed
262
263
      for( int ii = 0; ii < totalSize; ii++ ){
         _data[ii] = (BrookOpenMMFloat) arrayData[ii];
Mark Friedrichs's avatar
Mark Friedrichs committed
264
      }
265
266
267
268

   } else {
      
      std::stringstream message;
Mark Friedrichs's avatar
Mark Friedrichs committed
269
      message << methodName << " stream=" << getName() << " base type=" << getTypeString( baseType ) << " not recognized.";
270
271
      throw OpenMMException( message.str() );

Mark Friedrichs's avatar
Mark Friedrichs committed
272
273
274
275
276
277
   }

   // set dangling values

   _loadDanglingValues();

278
   // write to GPU
Mark Friedrichs's avatar
Mark Friedrichs committed
279

280
   _aStream.read( _data );
Mark Friedrichs's avatar
Mark Friedrichs committed
281
282
}

Mark Friedrichs's avatar
Mark Friedrichs committed
283
void BrookFloatStreamInternal::saveToArray( void* array ){
284
285

// ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
286

Mark Friedrichs's avatar
Mark Friedrichs committed
287
   static const std::string methodName      = "BrookFloatStreamInternal::saveToArray";
Mark Friedrichs's avatar
Mark Friedrichs committed
288

289
290
// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
291
   // get _data from GPU
292

Mark Friedrichs's avatar
Mark Friedrichs committed
293
   _aStream.write( _data );
Mark Friedrichs's avatar
Mark Friedrichs committed
294

Mark Friedrichs's avatar
Mark Friedrichs committed
295
   // load into array
Mark Friedrichs's avatar
Mark Friedrichs committed
296

Mark Friedrichs's avatar
Mark Friedrichs committed
297
298
   int totalSize                             = getSize()*getWidth();
   BrookStreamInternal::DataType  baseType   = getBaseDataType();
299

Mark Friedrichs's avatar
Mark Friedrichs committed
300
   if( baseType == BrookStreamInternal::Float ){
301

302
303
//printf( "%s Basetype is float\n", methodName.c_str() );
//fflush( stdout );
Mark Friedrichs's avatar
Mark Friedrichs committed
304
305
306
307
308
309
310
311
312
      memcpy( array, _data, sizeof( float )*totalSize );
/*
      float* arrayData = (float*) array;
      for( int ii = 0; ii < totalSize; ii++ ){
         arrayData[ii] = (float) _data[ii];
      }
*/

   } else if( baseType == BrookStreamInternal::Double ){
313

314
315
316
//printf( "%s Basetype is double\n", methodName.c_str() );
//fflush( stdout );

Mark Friedrichs's avatar
Mark Friedrichs committed
317
      double* arrayData = (double*) array;
Mark Friedrichs's avatar
Mark Friedrichs committed
318
319
      for( int ii = 0; ii < totalSize; ii++ ){
         arrayData[ii] = (double) _data[ii];
Mark Friedrichs's avatar
Mark Friedrichs committed
320
      }
321

Mark Friedrichs's avatar
Mark Friedrichs committed
322
323
   } else if( baseType == BrookStreamInternal::Integer ){

324
325
326
//printf( "%s Basetype is int\n", methodName.c_str() );
//fflush( stdout );

Mark Friedrichs's avatar
Mark Friedrichs committed
327
328
329
330
331
332
333
334
335
336
      int* arrayData = (int*) array;
      for( int ii = 0; ii < totalSize; ii++ ){
         arrayData[ii] = (int) _data[ii];
      }
   } else {
      
      std::stringstream message;
      message << methodName << " stream=" << getName() << " base type=" << getTypeString( baseType ) << " not recognized.";
      throw OpenMMException( message.str() );

Mark Friedrichs's avatar
Mark Friedrichs committed
337
338
339
   }
}

340
341
342
343
344
345
346
/** 
 * Fill stream w/ specified value
 * 
 * @param value                     value to fill stream w/
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
347
void BrookFloatStreamInternal::fillWithValue( void* value ){
Mark Friedrichs's avatar
Mark Friedrichs committed
348

349
350
// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
351
   // static const std::string methodName      = "BrookFloatStreamInternal::fillWithValue";
352
353
354
355
356
   // static const int debug                   = 1;

// ---------------------------------------------------------------------------------------

   BrookOpenMMFloat valueData;
Mark Friedrichs's avatar
Mark Friedrichs committed
357
   if( _baseType == BrookStreamInternal::Float) {
358
      valueData = (BrookOpenMMFloat) *((float*) value);
Mark Friedrichs's avatar
Mark Friedrichs committed
359
   } else {
360
361
      valueData = (BrookOpenMMFloat) *((double*) value);
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
362
363
364
365
366
   //memset( _data, valueData, sizeof( float )*getSize()*getWidth() );

   int totalSize = getSize()*getWidth();
   for( int ii = 0; ii < totalSize; ii++ ){
      _data[ii] = valueData;
Mark Friedrichs's avatar
Mark Friedrichs committed
367
   }
368

Mark Friedrichs's avatar
Mark Friedrichs committed
369
   _loadDanglingValues();
370
   _aStream.read( _data );
Mark Friedrichs's avatar
Mark Friedrichs committed
371

Mark Friedrichs's avatar
Mark Friedrichs committed
372
373
}

Mark Friedrichs's avatar
Mark Friedrichs committed
374
375
376
377
378
379
380
381
/** 
 * Get data
 * 
 * @param readFromBoard if set, read values on board 
 *
 * @return data array
 *
 */
382

Mark Friedrichs's avatar
Mark Friedrichs committed
383
void* BrookFloatStreamInternal::getData( int readFromBoard ){
Mark Friedrichs's avatar
Mark Friedrichs committed
384

Mark Friedrichs's avatar
Mark Friedrichs committed
385
// ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
386

Mark Friedrichs's avatar
Mark Friedrichs committed
387
   // static const std::string methodName      = "BrookFloatStreamInternal::getData";
Mark Friedrichs's avatar
Mark Friedrichs committed
388

Mark Friedrichs's avatar
Mark Friedrichs committed
389
// ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
390

Mark Friedrichs's avatar
Mark Friedrichs committed
391
392
   if( readFromBoard ){
      _aStream.write( _data );
Mark Friedrichs's avatar
Mark Friedrichs committed
393
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
394
395

   return (void*) _data;
Mark Friedrichs's avatar
Mark Friedrichs committed
396
397
}

398
399
400
401
402
403
404
/** 
 * Get data
 * 
 * @return data array
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
405
void* BrookFloatStreamInternal::getData( void ){
406
407
408

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
409
   // static const std::string methodName      = "BrookFloatStreamInternal::getData";
410
411
412

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
413
   return getData( 0 );
Mark Friedrichs's avatar
Mark Friedrichs committed
414
415
}

416
417
418
419
420
421
422
/** 
 * Load dangling value into stream
 * 
 * @param danglingValue   dangling value to load
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
423
void BrookFloatStreamInternal::_loadDanglingValues( float danglingValue ){
Mark Friedrichs's avatar
Mark Friedrichs committed
424

425
426
// ---------------------------------------------------------------------------------------

427
    static const std::string methodName      = "BrookFloatStreamInternal::_loadDanglingValues";
428
429
430

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
431
432
433
434
435
   int width      = getWidth();

   int arraySize  = getSize()*width;
   int streamSize = getStreamSize()*width;

436
437
438
//printf( "%s array=%d stream=%d width=%d %s\n", methodName.c_str(), arraySize, streamSize, width, getName().c_str() );
//fflush( stdout );

Mark Friedrichs's avatar
Mark Friedrichs committed
439
440
441
   if( arraySize < streamSize ){
      for( int ii = arraySize; ii < streamSize; ii++ ){
          _data[ii] = danglingValue;
Mark Friedrichs's avatar
Mark Friedrichs committed
442
443
444
445
       }
    }
}

446
447
448
449
450
/** 
 * Load default dangling value into stream
 * 
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
451
void BrookFloatStreamInternal::_loadDanglingValues( void ){
452
   _loadDanglingValues( _defaultDangleValue );
Mark Friedrichs's avatar
Mark Friedrichs committed
453
}
Mark Friedrichs's avatar
Mark Friedrichs committed
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507

/* 
 * Get contents of object
 *
 * @param level   level of dump
 *
 * @return string containing contents
 *
 * */

const std::string BrookFloatStreamInternal::getContentsString( int level ) const {

// ---------------------------------------------------------------------------------------

   // static const std::string methodName      = "BrookFloatStreamInternal::getContentsString";

   static const unsigned int MAX_LINE_CHARS = 256; 
   char value[MAX_LINE_CHARS];
   //static const char* Set                   = "Set";
   //static const char* NotSet                = "Not set";


// ---------------------------------------------------------------------------------------

   std::stringstream message;
   std::string tab   = "   ";
 
#ifdef WIN32
#define LOCAL_SPRINTF(a,b,c) sprintf_s( (a), MAX_LINE_CHARS, (b), (c) );   
#else
#define LOCAL_SPRINTF(a,b,c) sprintf( (a), (b), (c) );   
#endif

   (void) LOCAL_SPRINTF( value, "%s", getName().c_str() );
   message << _getLine( tab, "Name:", value ); 

   (void) LOCAL_SPRINTF( value, "%d", getWidth() );
   message << _getLine( tab, "Width:", value ); 

   (void) LOCAL_SPRINTF( value, "%d", getStreamSize() );
   message << _getLine( tab, "Stream size:", value ); 

   (void) LOCAL_SPRINTF( value, "%d", getStreamWidth() );
   message << _getLine( tab, "Stream width:", value ); 

   (void) LOCAL_SPRINTF( value, "%d", getStreamHeight() );
   message << _getLine( tab, "Stream height:", value ); 

   (void) LOCAL_SPRINTF( value, "%3e", getDangleValue() );
   message << _getLine( tab, "Dangle value:", value ); 

   return message.str();
}

508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
/* 
 * Print array contents of object to file
 *
 * @param log         file to print to
 *
 * @return DefaultReturnValue
 *
 * */

int BrookFloatStreamInternal::_bodyPrintToFile( FILE* log ){

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookStreamInternal::_bodyPrintToFile";

// ---------------------------------------------------------------------------------------

   void* dataArrayV = getDataArray( );
   saveToArray( dataArrayV );

   int streamSize   = getStreamSize();
   int width        = getWidth();
   int index        = 0;
    float* dataArray = (float*) dataArrayV;
   for( int ii = 0; ii < streamSize; ii++ ){
      std::stringstream message;
      message.width( 15 );
      message.precision( 5 );
      message << ii << " [ ";
      for( int jj = 0; jj < width; jj++ ){
         message << dataArray[index++] << " ";
      }
      message << "]\n";
      (void) fprintf( log, "%s", message.str().c_str() );    
   }

   delete[] dataArrayV;

   return DefaultReturnValue;

}

/** 
 * Get array of appropritate size for loading data
 *
 * @return data array -- user's responsibility to free
 */

void* BrookFloatStreamInternal::getDataArray( void ){

// ---------------------------------------------------------------------------------------

   //static const std::string methodName      = "BrookStreamInternal::getDataArray";

// ---------------------------------------------------------------------------------------

   int totalSize                          = getStreamSize()*getWidth();
   BrookStreamInternal::DataType baseType = getBaseDataType();
   
   if( baseType == Double || baseType == Double2 ||  baseType == Double3 ||  baseType == Double4 ){
      totalSize *= 2;
   }
   return new float[totalSize];
}