Changeset 2768 for trunk/external-alma


Ignore:
Timestamp:
02/12/13 12:04:54 (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: test_sdsave

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Speedup NRO filler for NEWSTAR data.

Location:
trunk/external-alma/atnf/PKSIO
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc

    r2766 r2768  
    6161  // data initialization
    6262  readHeader( numField_, "TFIELDS", same_ ) ;
    63   forms_.resize( numField_ ) ;
    6463  names_.resize( numField_ ) ;
    6564  units_.resize( numField_ ) ;
     65  sizes_.resize( numField_ ) ;
     66  offsets_.resize( numField_ ) ;
    6667  getField() ;
    6768
     
    14781479void NROFITSDataset::getField()
    14791480{
     1481  long offset = 0;
    14801482  for ( int i = 0 ; i < numField_ ; i++ ) {
    14811483    char key1[9] ;
     
    15071509      return ;
    15081510    }
    1509     //forms_[i] = string( tmp ) ;
    1510     forms_[i] = tmp ;
    1511     string::size_type spos = forms_[i].find( " " ) ;
     1511    string form = tmp ;
     1512    string::size_type spos = form.find( " " ) ;
    15121513    if ( spos != string::npos )
    1513       forms_[i] = forms_[i].substr( 0, spos ) ;
     1514      form = form.substr( 0, spos ) ;
    15141515    //strcpy( tmp, "         " ) ;
    15151516    if ( readHeader( tmp, key2 ) != 0 ) {
     
    15231524      names_[i] = names_[i].substr( 0, spos ) ;
    15241525    //strcpy( tmp, "         " ) ;
    1525     if ( forms_[i].find( "A" ) != string::npos ) {
    1526       //cout << "skip to get unit: name = " << forms_[i] << endl ;
     1526    if ( form.find( "A" ) != string::npos ) {
     1527      //cout << "skip to get unit: name = " << form << endl ;
    15271528      //strcpy( tmp, "none    " ) ;
    15281529      tmp = "none" ;
    15291530    }
    15301531    else {
    1531       //cout << "get unit: name = " << forms_[i] << endl ;
     1532      //cout << "get unit: name = " << form << endl ;
    15321533      if ( readHeader( tmp, key3 ) != 0 ) {
    15331534        //strcpy( tmp, "none    " ) ;
     
    15401541    if ( spos != string::npos )
    15411542      units_[i] = units_[i].substr( 0, spos ) ;
    1542     //cout << "i = " << i << ": name=" << forms_[i] << " type=" << names_[i] << " unit=" << units_[i] << endl ;
     1543    //cout << "i = " << i << ": name=" << form << " type=" << names_[i] << " unit=" << units_[i] << endl ;
     1544
     1545    offsets_[i] = offset ;
     1546    string substr1 = form.substr( 0, form.size()-1 ) ;
     1547    string substr2 = form.substr( form.size()-1, 1 ) ;
     1548    //cout << "substr1 = " << substr1 << ", substr2 = " << substr2 << endl ;
     1549    int o1 = atoi( substr1.c_str() ) ;
     1550    int o2 = 0 ;
     1551    if ( substr2 == "A" )
     1552      o2 = sizeof(char) ;
     1553    else if ( substr2 == "J" )
     1554      o2 = sizeof(int) ;
     1555    else if ( substr2 == "F" )
     1556      o2 = sizeof(float) ;
     1557    else if ( substr2 == "D" )
     1558      o2 = sizeof(double) ;
     1559    sizes_[i] = o1 * o2 ;
     1560    offset += sizes_[i] ;
    15431561  } 
    15441562}
     
    16791697
    16801698  // get offset
    1681   int offset = getOffset( "ARRYT" ) ;
     1699  long offset = getOffset( "ARRYT" ) ;
    16821700  if ( offset == -1 ) {
    16831701    //cerr << "Error, ARRYT is not found in the name list." << endl ;
     
    17201738  }
    17211739
    1722 int NROFITSDataset::getOffset( char *name )
    1723 {
    1724   int offset = 0 ;
     1740long NROFITSDataset::getOffset( char *name )
     1741{
     1742  long offset = 0 ;
    17251743  string sname( name ) ;
    1726   bool found = false ;
    1727   for ( int i = 0 ; i < numField_ ; i++ ) {
     1744  long j = -1 ;
     1745  for ( long i = 0 ; i < numField_ ; i++ ) {
    17281746    // escape if name is found
    17291747    //cout << "names_[" << i << "] = " << names_[i] << "  sname = " << sname << endl ;
    17301748    if ( names_[i] == sname ) {
    1731       found = true ;
     1749      j = i ;
    17321750      break ;
    17331751    }
    1734 
    1735     // form analysis
    1736     string substr1 = forms_[i].substr( 0, forms_[i].size()-1 ) ;
    1737     string substr2 = forms_[i].substr( forms_[i].size()-1, 1 ) ;
    1738     //cout << "substr1 = " << substr1 << ", substr2 = " << substr2 << endl ;
    1739     int o1 = atoi( substr1.c_str() ) ;
    1740     int o2 = 0 ;
    1741     if ( substr2 == "A" )
    1742       o2 = sizeof(char) ;
    1743     else if ( substr2 == "J" )
    1744       o2 = sizeof(int) ;
    1745     else if ( substr2 == "F" )
    1746       o2 = sizeof(float) ;
    1747     else if ( substr2 == "D" )
    1748       o2 = sizeof(double) ;
    1749     //cout << "o1 = " << o1 << ", o2 = " << o2 << endl ;
    1750     offset += o1 * o2 ;
    1751   }
    1752 
    1753   if ( !found )
    1754     offset = -1 ;
     1752  }
     1753
     1754  offset = (j >= 0) ? offsets_[j] : j ;
    17551755
    17561756  return offset ;
     
    19491949    }
    19501950  }
    1951   string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
    1952   int xsize = atoi( substr.c_str() ) ;
    1953   //cout << "xsize = " << xsize << endl ;
     1951
     1952  int xsize = sizes_[index] ;
    19541953
    19551954  // read data
     
    20372036    }
    20382037  }
    2039   string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
    2040   int xsize = atoi( substr.c_str() ) ;
    2041   //cout << "xsize = " << xsize << endl ;
     2038
     2039  int xsize = sizes_[index] ;
    20422040
    20432041  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
     
    21322130    }
    21332131  }
    2134   string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
    2135   int xsize = atoi( substr.c_str() ) ;
    2136   //cout << "xsize = " << xsize << endl ;
     2132
     2133  int xsize = sizes_[index] ;
    21372134
    21382135  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
     
    22742271{
    22752272  // find offset
    2276   int offset = getOffset( name ) ;
     2273  long offset = getOffset( name ) ;
    22772274  if ( offset == -1 ) {
    22782275    //cerr << "Error, " << name << " is not found in the name list." << endl ;
     
    22802277  }
    22812278
    2282   offset += idx * scanLen_ ;
     2279  offset += (long)(idx * scanLen_) ;
    22832280
    22842281  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
  • trunk/external-alma/atnf/PKSIO/NROFITSDataset.h

    r2442 r2768  
    146146
    147147  // get offset bytes for attributes
    148   int getOffset( char *name ) ;
     148  long getOffset( char *name ) ;
    149149
    150150  // move pointer to target position
     
    167167
    168168  // field names
    169   vector<string> forms_ ;
    170  
    171   // field types
    172169  vector<string> names_ ;
    173170
    174171  // field units
    175172  vector<string> units_ ;
     173
     174  // sizes of each field
     175  vector<int> sizes_ ; 
     176
     177  // offsets from the beginning of the file
     178  vector<long> offsets_ ;
    176179
    177180  // spectral data
Note: See TracChangeset for help on using the changeset viewer.