Changeset 2598
- Timestamp:
- 07/12/12 11:32:35 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/hpc34/external-alma/atnf/PKSIO/NRODataset.cc
r2596 r2598 357 357 // size of spectrum is not chmax_ but dataset_->getNCH() after binding 358 358 const int nchan = NUMCH ; 359 vector<double> bspec( nchan, 0.0 ) ; // spectrum "after" binding359 vector<double> spec( chmax_ ) ; // spectrum "before" binding 360 360 // DEBUG 361 361 //cout << "NRODataset::getSpectrum() nchan = " << nchan << " chmax_ = " << chmax_ << endl ; … … 375 375 if ( ( scale == 0.0 ) && ( offset == 0.0 ) ) { 376 376 //cerr << "NRODataset::getSpectrum() zero spectrum (" << i << ")" << endl ; 377 return bspec ; 377 LogIO os( LogOrigin("NRODataset","getSpectrum",WHERE) ) ; 378 os << LogIO::WARN << "zero spectrum for row " << i << LogIO::POST ; 379 if ( spec.size() != nchan ) 380 spec.resize( nchan ) ; 381 for ( vector<double>::iterator i = spec.begin() ; 382 i != spec.end() ; i++ ) 383 *i = 0.0 ; 384 return spec ; 378 385 } 379 386 unsigned char *cdata = (unsigned char *)record->LDATA ; … … 383 390 int chmin = CHMIN ; 384 391 385 // char -> int 386 int *ispec = new int[chmax_] ; 387 int *int_p = ispec ; 392 // char -> int -> double 393 vector<double>::iterator iter = spec.begin() ; 388 394 389 395 static const int shift_right[] = { … … 398 404 int j = 0 ; 399 405 for ( int i = 0 ; i < chmax_ ; i++ ) { 406 // char -> int 400 407 int ivalue = 0 ; 401 408 if ( bit == 12 ) { // 12 bit qunatization … … 410 417 //cerr << "NRODataset::getSpectrum() ispec[" << i << "] is out of range" << endl ; 411 418 LogIO os( LogOrigin( "NRODataset", "getSpectrum", WHERE ) ) ; 412 os << LogIO::SEVERE << "ispec[" << i << "] is out of range" << LogIO::EXCEPTION ; 413 delete ispec ; 414 return bspec ; 419 os << LogIO::SEVERE << "ivalue for row " << i << " is out of range" << LogIO::EXCEPTION ; 420 if ( spec.size() != nchan ) 421 spec.resize( nchan ) ; 422 for ( vector<double>::iterator i = spec.begin() ; 423 i != spec.end() ; i++ ) 424 *i = 0.0 ; 425 return spec ; 415 426 } 416 427 // DEBUG 417 428 //cout << "NRODataset::getSpectrum() ispec[" << i << "] = " << ispec[i] << endl ; 418 429 // 419 *int_p = ivalue ; 420 int_p++ ; 421 } 422 423 double *const spec = new double[ chmax_ ] ; // spectrum "before" binding 424 // int -> double 425 int_p = ispec ; 426 double *double_p = spec ; 427 for ( int i = 0 ; i < chmax_ ; i++ ) { 428 *double_p = (double)( (*int_p) * scale + offset ) * dscale ; 430 431 // int -> double 432 *iter = (double)( ivalue * scale + offset ) * dscale ; 429 433 // DEBUG 430 //cout << "NRODataset::getSpectrum() spec[" << i << "] = " << spec[i]<< endl ;434 //cout << "NRODataset::getSpectrum() spec[" << i << "] = " << *iter << endl ; 431 435 // 432 int_p++ ; 433 double_p++ ; 434 } 435 delete ispec ; 436 437 // channel binding 436 iter++ ; 437 } 438 439 // channel binding if necessary 438 440 if ( cbind != 1 ) { 439 double_p = &(spec[chmin]) ; 440 for ( vector<double>::iterator i = bspec.begin() ; 441 i != bspec.end() ; i++ ) { 441 iter = spec.begin() ; 442 advance( iter, chmin ) ; 443 vector<double>::iterator iter2 = spec.begin() ; 444 for ( int i = 0 ; i < nchan ; i++ ) { 442 445 double sum0 = 0 ; 443 446 double sum1 = 0 ; 444 447 for ( int j = 0 ; j < cbind ; j++ ) { 445 sum0 += * double_p;448 sum0 += *iter ; 446 449 sum1 += 1.0 ; 447 double_p++ ;450 iter++ ; 448 451 } 449 *i = sum0 / sum1 ;450 i ++ ;452 *iter2 = sum0 / sum1 ; 453 iter2++ ; 451 454 // DEBUG 452 455 //cout << "NRODataset::getSpectrum() bspec[" << i << "] = " << bspec[i] << endl ; 453 456 // 454 457 } 455 } 456 else { 457 double_p = spec ; 458 for ( vector<double>::iterator i = bspec.begin() ; 459 i != bspec.end() ; i++ ) { 460 *i = *double_p ; 461 double_p++ ; 462 } 463 } 464 delete[] spec; 458 spec.resize( nchan ) ; 459 } 465 460 466 461 // DEBUG … … 468 463 // 469 464 470 return bspec ;465 return spec ; 471 466 } 472 467
Note:
See TracChangeset
for help on using the changeset viewer.