Changeset 2590


Ignore:
Timestamp:
07/09/12 14:41:03 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

In NROReader::getScanInfo, replaced a loop using casa::Vector<T>::iteratorSTL
with direct data access.

In NRODataset::getSpectrum, optimized operation and a few bug fixes.


Location:
branches/hpc34/external-alma/atnf/PKSIO
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/hpc34/external-alma/atnf/PKSIO/NRODataset.cc

    r2434 r2590  
    388388
    389389  // char -> int
    390   vector<int> ispec( chmax_, 0 ) ;
     390  int *ispec = new int[chmax_] ;
     391  int *int_p = ispec ;
    391392
    392393  static const int shift_right[] = {
     
    403404    int ivalue = 0 ;
    404405    if ( bit == 12 ) {  // 12 bit qunatization
    405       const int idx = j + start_pos[i & 1];
     406      const int ialt = i & 1 ;
     407      const int idx = j + start_pos[ialt];
    406408      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 ;
    412     if ( ( ispec[i] < 0 ) || ( ispec[i] > 4096 ) ) {
     409      ivalue = int((tmp >> shift_right[ialt]) & 0xFFF);
     410      j += incr[ialt];
     411    }
     412
     413    if ( ( ivalue < 0 ) || ( ivalue > 4096 ) ) {
    413414      //cerr << "NRODataset::getSpectrum()  ispec[" << i << "] is out of range" << endl ;
    414415      os << LogIO::SEVERE << "ispec[" << i << "] is out of range" << LogIO::EXCEPTION ;
     416      delete ispec ;
    415417      return bspec ;
    416418    }
     
    418420    //cout << "NRODataset::getSpectrum()  ispec[" << i << "] = " << ispec[i] << endl ;
    419421    //
     422    *int_p = ivalue ;
     423    int_p++ ;
    420424  }
    421425
    422426  double *const spec = new double[ chmax_ ] ;  // spectrum "before" binding
    423427  // int -> double
     428  int_p = ispec ;
     429  double *double_p = spec ;
    424430  for ( int i = 0 ; i < chmax_ ; i++ ) {
    425     spec[i] = (double)( ispec[i] * scale + offset ) * dscale ;
     431    *double_p = (double)( (*int_p) * scale + offset ) * dscale ;
    426432    // DEBUG
    427433    //cout << "NRODataset::getSpectrum()  spec[" << i << "] = " << spec[i] << endl ;
    428434    //
    429   }
     435    int_p++ ;
     436    double_p++ ;
     437  }
     438  delete ispec ;
    430439
    431440  // channel binding
    432441  if ( cbind != 1 ) {
    433     int k = chmin ;
    434     double sum0 = 0 ;
    435     double sum1 = 0 ;
    436     for ( int i = 0 ; i < nchan ; i++ ) {
    437       for ( int j = k ; j < k + cbind ; j++ ) {
    438         sum0 += spec[k] ;
    439         sum1++ ;
     442    double_p = &(spec[chmin]) ;
     443    for ( vector<double>::iterator i = bspec.begin() ;
     444          i != bspec.end() ; i++ ) {
     445      double sum0 = 0 ;
     446      double sum1 = 0 ;
     447      for ( int j = 0 ; j < cbind ; j++ ) {
     448        sum0 += *double_p ;
     449        sum1 += 1.0 ;
     450        double_p++ ;
    440451      }
    441       bspec[i] = sum0 / sum1 ;
    442       k += cbind ;
     452      *i = sum0 / sum1 ;
     453      i++ ;
    443454      // DEBUG
    444455      //cout << "NRODataset::getSpectrum()  bspec[" << i << "] = " << bspec[i] << endl ;
     
    447458  }
    448459  else {
    449     for ( int i = 0 ; i < nchan ; i++ )
    450       bspec[i] = spec[i] ;
     460    double_p = spec ;
     461    for ( vector<double>::iterator i = bspec.begin() ;
     462          i != bspec.end() ; i++ ) {
     463      *i = *double_p ;
     464      double_p++ ;
     465    }
    451466  }
    452467  delete[] spec;
  • branches/hpc34/external-alma/atnf/PKSIO/NROReader.cc

    r2588 r2590  
    613613  spectra.resize( spec.size() ) ;
    614614  int index = 0 ;
    615   for ( Vector<Float>::iterator itr = spectra.begin() ; itr != spectra.end() ; itr++ ) {
    616     *itr = spec[index++] ;
    617   }
     615  Bool b ;
     616  Float *fp = spectra.getStorage( b ) ;
     617  Float *wp = fp ;
     618  for ( vector<double>::iterator i = spec.begin() ;
     619        i != spec.end() ; i++ ) {
     620    *wp = *i ;
     621    wp++ ;
     622  }
     623  spectra.putStorage( fp, b ) ;
    618624  //cout << "spec.size() = " << spec.size() << endl ;
    619625 
    620626  // flagtra
    621627  bool setValue = !( flagtra.nelements() == spectra.nelements() ) ;
    622   flagtra.resize( spectra.nelements() ) ;
    623628  if ( setValue ) {
    624629    //cout << "flagtra resized. reset values..." << endl ;
     630    flagtra.resize( spectra.nelements() ) ;
    625631    flagtra.set( 0 ) ;
    626632  }
Note: See TracChangeset for help on using the changeset viewer.