"platforms/cuda/vscode:/vscode.git/clone" did not exist on "036c3ff4eaffc5be586ae158b566f0ffd2d01604"
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
177
178
//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 );

179
180
   delete[] _data;

Mark Friedrichs's avatar
Mark Friedrichs committed
181
182
183
184
185
186
187
}

/** 
 * Get dangle value
 * 
 * @return  dangle value
 */
188

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

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
194
 * Load data from input array
195
196
197
198
199
200
 * 
 * @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
201
202
 * @throw exception if baseType not recognized
 *
203
204
 */

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

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

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
213
   return loadFromArray( array, getBaseDataType() );
214

Mark Friedrichs's avatar
Mark Friedrichs committed
215
216
}

217
/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
218
 * Load data from input array
219
220
221
222
223
224
 * 
 * @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.
 *
225
 * @throw exception if baseType not float, double, or integer
226
227
 *
 */
Mark Friedrichs's avatar
Mark Friedrichs committed
228

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

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

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

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
240
241
242
243
244
245
246
   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
247
      }
Mark Friedrichs's avatar
Mark Friedrichs committed
248
*/
Mark Friedrichs's avatar
Mark Friedrichs committed
249

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

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

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

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
270
271
272
273
274
275
   }

   // set dangling values

   _loadDanglingValues();

276
   // write to GPU
Mark Friedrichs's avatar
Mark Friedrichs committed
277

278
   _aStream.read( _data );
Mark Friedrichs's avatar
Mark Friedrichs committed
279
280
}

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

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

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

287
288
// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
289
   // get _data from GPU
290

Mark Friedrichs's avatar
Mark Friedrichs committed
291
   _aStream.write( _data );
Mark Friedrichs's avatar
Mark Friedrichs committed
292

Mark Friedrichs's avatar
Mark Friedrichs committed
293
   // load into array
Mark Friedrichs's avatar
Mark Friedrichs committed
294

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

Mark Friedrichs's avatar
Mark Friedrichs committed
298
   if( baseType == BrookStreamInternal::Float ){
299

300
301
//printf( "%s Basetype is float\n", methodName.c_str() );
//fflush( stdout );
Mark Friedrichs's avatar
Mark Friedrichs committed
302
303
304
305
306
307
308
309
310
      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 ){
311

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

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

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
325
326
327
328
329
330
331
332
333
334
      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
335
336
337
   }
}

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

Mark Friedrichs's avatar
Mark Friedrichs committed
345
void BrookFloatStreamInternal::fillWithValue( void* value ){
Mark Friedrichs's avatar
Mark Friedrichs committed
346

347
348
// ---------------------------------------------------------------------------------------

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

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

   BrookOpenMMFloat valueData;
Mark Friedrichs's avatar
Mark Friedrichs committed
355
   if( _baseType == BrookStreamInternal::Float) {
356
      valueData = (BrookOpenMMFloat) *((float*) value);
Mark Friedrichs's avatar
Mark Friedrichs committed
357
   } else {
358
359
      valueData = (BrookOpenMMFloat) *((double*) value);
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
360
361
362
363
364
   //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
365
   }
366

Mark Friedrichs's avatar
Mark Friedrichs committed
367
   _loadDanglingValues();
368
   _aStream.read( _data );
Mark Friedrichs's avatar
Mark Friedrichs committed
369

Mark Friedrichs's avatar
Mark Friedrichs committed
370
371
}

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
383
// ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
384

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

Mark Friedrichs's avatar
Mark Friedrichs committed
387
// ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
388

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

   return (void*) _data;
Mark Friedrichs's avatar
Mark Friedrichs committed
394
395
}

396
397
398
399
400
401
402
/** 
 * Get data
 * 
 * @return data array
 *
 */

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

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

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

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

Mark Friedrichs's avatar
Mark Friedrichs committed
411
   return getData( 0 );
Mark Friedrichs's avatar
Mark Friedrichs committed
412
413
}

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

Mark Friedrichs's avatar
Mark Friedrichs committed
421
void BrookFloatStreamInternal::_loadDanglingValues( float danglingValue ){
Mark Friedrichs's avatar
Mark Friedrichs committed
422

423
424
// ---------------------------------------------------------------------------------------

425
    static const std::string methodName      = "BrookFloatStreamInternal::_loadDanglingValues";
426
427
428

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

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

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

434
435
436
//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
437
438
439
   if( arraySize < streamSize ){
      for( int ii = arraySize; ii < streamSize; ii++ ){
          _data[ii] = danglingValue;
Mark Friedrichs's avatar
Mark Friedrichs committed
440
441
442
443
       }
    }
}

444
445
446
447
448
/** 
 * Load default dangling value into stream
 * 
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
449
void BrookFloatStreamInternal::_loadDanglingValues( void ){
450
   _loadDanglingValues( _defaultDangleValue );
Mark Friedrichs's avatar
Mark Friedrichs committed
451
}
Mark Friedrichs's avatar
Mark Friedrichs committed
452
453
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

/* 
 * 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();
}

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
/* 
 * 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";

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

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
523
   assert( log );
524

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
525
526
527
528
529
530
531
532
   void* dataArrayV = getData( 1 );
   //void* dataArrayV = getDataArray( );
   //saveToArray( dataArrayV );

   int streamSize         = getStreamSize();
   int width              = getWidth();
   int index              = 0;
   const float* dataArray = (float*) dataArrayV;
533
534
535
   for( int ii = 0; ii < streamSize; ii++ ){
      std::stringstream message;
      message.width( 15 );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
536
      message.precision( 8 );
537
538
539
540
541
542
543
544
      message << ii << " [ ";
      for( int jj = 0; jj < width; jj++ ){
         message << dataArray[index++] << " ";
      }
      message << "]\n";
      (void) fprintf( log, "%s", message.str().c_str() );    
   }

Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
545
   //delete[] dataArrayV;
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
573

   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];
}