Changeset 2266 for branches/parallel/external-alma/atnf/PKSIO
- Timestamp:
- 08/08/11 16:41:40 (13 years ago)
- Location:
- branches/parallel/external-alma/atnf/PKSIO
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/parallel/external-alma/atnf/PKSIO/NRODataset.cc
r2262 r2266 71 71 dataid_ = -1 ; 72 72 73 // OS endian 74 int i = 1 ; 75 endian_ = -1 ; 76 if ( *reinterpret_cast<char *>(&i) == 1 ) { 77 endian_ = LITTLE_ENDIAN ; 78 os << LogIO::NORMAL << "LITTLE_ENDIAN " << LogIO::POST ; 79 } 80 else { 81 endian_ = BIG_ENDIAN ; 82 os << LogIO::NORMAL << "BIG_ENDIAN " << LogIO::POST ; 83 } 73 // endian matches 84 74 same_ = -1 ; 85 75 … … 353 343 vector< vector<double> > NRODataset::getSpectrum() 354 344 { 355 vector< vector<double> > spec ;345 vector< vector<double> > spec(rowNum_); 356 346 357 347 for ( int i = 0 ; i < rowNum_ ; i++ ) { 358 spec .push_back( getSpectrum( i )) ;348 spec[i] = getSpectrum( i ) ; 359 349 } 360 350 … … 370 360 // 371 361 // size of spectrum is not chmax_ but dataset_->getNCH() after binding 372 int nchan = NUMCH ; 373 vector<double> spec( chmax_, 0.0 ) ; // spectrum "before" binding 362 const int nchan = NUMCH ; 374 363 vector<double> bspec( nchan, 0.0 ) ; // spectrum "after" binding 375 364 // DEBUG … … 379 368 NRODataRecord *record = getRecord( i ) ; 380 369 381 int bit = IBIT ; // fixed to 12 bit370 const int bit = IBIT ; // fixed to 12 bit 382 371 double scale = record->SFCTR ; 383 372 // DEBUG … … 392 381 return bspec ; 393 382 } 394 char *cdata =record->LDATA ;383 unsigned char *cdata = (unsigned char *)record->LDATA ; 395 384 vector<double> mscale = MLTSCF ; 396 385 double dscale = mscale[getIndex( i )] ; … … 400 389 // char -> int 401 390 vector<int> ispec( chmax_, 0 ) ; 402 union SharedMemory { 403 int ivalue ; 404 unsigned char cbuf[4] ; 405 } ; 406 SharedMemory u ; 391 392 static const int shift_right[] = { 393 4, 0 394 }; 395 static const int start_pos[] = { 396 0, 1 397 }; 398 static const int incr[] = { 399 0, 3 400 }; 407 401 int j = 0 ; 408 char ctmp = 0x00 ;409 int sw = 0 ;410 402 for ( int i = 0 ; i < chmax_ ; i++ ) { 403 int ivalue = 0 ; 411 404 if ( bit == 12 ) { // 12 bit qunatization 412 u.ivalue = 0 ; 413 414 if ( endian_ == BIG_ENDIAN ) { 415 // big endian 416 if ( sw == 0 ) { 417 char c0 = (cdata[j] >> 4) & 0x0f ; 418 char c1 = ((cdata[j] << 4) & 0xf0) | ((cdata[j+1] >> 4) & 0x0f) ; 419 ctmp = cdata[j+1] & 0x0f ; 420 u.cbuf[2] = c0 ; 421 u.cbuf[3] = c1 ; 422 j += 2 ; 423 sw = 1 ; 424 } 425 else if ( sw == 1 ) { 426 u.cbuf[2] = ctmp ; 427 u.cbuf[3] = cdata[j] ; 428 j++ ; 429 sw = 0 ; 430 } 431 } 432 else if ( endian_ == LITTLE_ENDIAN ) { 433 // little endian 434 if ( sw == 0 ) { 435 char c0 = (cdata[j] >> 4) & 0x0f ; 436 char c1 = ((cdata[j] << 4) & 0xf0) | ((cdata[j+1] >> 4) & 0x0f) ; 437 ctmp = cdata[j+1] & 0x0f ; 438 u.cbuf[1] = c0 ; 439 u.cbuf[0] = c1 ; 440 j += 2 ; 441 sw = 1 ; 442 } 443 else if ( sw == 1 ) { 444 u.cbuf[1] = ctmp ; 445 u.cbuf[0] = cdata[j] ; 446 j++ ; 447 sw = 0 ; 448 } 449 } 450 } 451 452 ispec[i] = u.ivalue ; 405 const int idx = j + start_pos[i & 1]; 406 const unsigned tmp = unsigned(cdata[idx]) << 8 | cdata[idx + 1]; 407 ivalue = int((tmp >> shift_right[i & 1]) & 0xFFF); 408 j += incr[i & 1]; 409 } 410 411 ispec[i] = ivalue ; 453 412 if ( ( ispec[i] < 0 ) || ( ispec[i] > 4096 ) ) { 454 413 //cerr << "NRODataset::getSpectrum() ispec[" << i << "] is out of range" << endl ; … … 461 420 } 462 421 422 double *const spec = new double[ chmax_ ] ; // spectrum "before" binding 463 423 // int -> double 464 424 for ( int i = 0 ; i < chmax_ ; i++ ) { … … 490 450 bspec[i] = spec[i] ; 491 451 } 452 delete[] spec; 492 453 493 454 // DEBUG -
branches/parallel/external-alma/atnf/PKSIO/NRODataset.h
r2262 r2266 506 506 507 507 // OS endian 508 int endian_ ;509 508 int same_ ; 510 509
Note:
See TracChangeset
for help on using the changeset viewer.