Changeset 2812 for trunk/external-alma


Ignore:
Timestamp:
04/15/13 12:12:26 (11 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...

Refactoring NRO NEWSTAR filler. Introduced map and internal structure
to represent names and associated properties for each fields in
scan header.


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

Legend:

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

    r2784 r2812  
    6767  // field names, units, and sizes
    6868  readHeader( numField_, "TFIELDS" ) ;
    69   names_.resize( numField_ ) ;
    70   units_.resize( numField_ ) ;
    71   sizes_.resize( numField_ ) ;
    72   offsets_.resize( numField_ ) ;
    7369  getField() ;
    7470
     
    14941490      return ;
    14951491    }
    1496     //names_[i] = string( tmp ) ;
    1497     names_[i] = tmp ;
    1498     spos = names_[i].find( " " ) ;
     1492    string name = tmp ;
     1493    spos = tmp.find( " " ) ;
    14991494    if ( spos != string::npos )
    1500       names_[i] = names_[i].substr( 0, spos ) ;
     1495      name = tmp.substr( 0, spos ) ;
    15011496    //strcpy( tmp, "         " ) ;
    15021497    if ( form.find( "A" ) != string::npos ) {
     
    15121507      }
    15131508    }
    1514     //units_[i] = string( tmp ) ;
    1515     units_[i] = tmp ;
    1516     spos = units_[i].find( " " ) ;
    1517     if ( spos != string::npos )
    1518       units_[i] = units_[i].substr( 0, spos ) ;
    1519     //cout << "i = " << i << ": name=" << form << " type=" << names_[i] << " unit=" << units_[i] << endl ;
    1520 
    1521     offsets_[i] = offset ;
     1509    //string unit = string( tmp ) ;
     1510    //unit = tmp ;
     1511    //spos = tmp.find( " " ) ;
     1512    //if ( spos != string::npos )
     1513    //  unit = unit.substr( 0, spos ) ;
     1514    //cout << "i = " << i << ": name=" << form << " type=" << name << " unit=" << unit << endl ;
     1515
    15221516    string substr1 = form.substr( 0, form.size()-1 ) ;
    15231517    string substr2 = form.substr( form.size()-1, 1 ) ;
     
    15331527    else if ( substr2 == "D" )
    15341528      o2 = sizeof(double) ;
    1535     sizes_[i] = o1 * o2 ;
    1536     offset += sizes_[i] ;
     1529
     1530    FieldProperty property;
     1531    property.offset = offset;
     1532    property.size = o1 * o2;
     1533    properties_[name] = property;
     1534
     1535    offset += property.size ;
    15371536  } 
    15381537}
     
    17141713  }
    17151714
    1716 long NROFITSDataset::getOffset( char *name )
    1717 {
    1718   long offset = 0 ;
    1719   string sname( name ) ;
    1720   long j = -1 ;
    1721   for ( long i = 0 ; i < numField_ ; i++ ) {
    1722     // escape if name is found
    1723     //cout << "names_[" << i << "] = " << names_[i] << "  sname = " << sname << endl ;
    1724     if ( names_[i] == sname ) {
    1725       j = i ;
    1726       break ;
    1727     }
    1728   }
    1729 
    1730   offset = (j >= 0) ? offsets_[j] : j ;
     1715long NROFITSDataset::getOffset( const char *name )
     1716{
     1717  map<string, FieldProperty>::iterator iter = properties_.find(string(name));
     1718  long offset = (iter != properties_.end()) ? iter->second.offset : -1;
    17311719
    17321720  return offset ;
     
    17671755}
    17681756
    1769 int NROFITSDataset::readHeader( string &v, char *name )
     1757int NROFITSDataset::readHeader( string &v, const char *name )
    17701758{
    17711759  //
     
    18021790}
    18031791
    1804 int NROFITSDataset::readHeader( int &v, char *name )
     1792int NROFITSDataset::readHeader( int &v, const char *name )
    18051793{
    18061794  //
     
    18381826
    18391827
    1840 int NROFITSDataset::readHeader( float &v, char *name )
     1828int NROFITSDataset::readHeader( float &v, const char *name )
    18411829{
    18421830  //
     
    18721860}
    18731861
    1874 int NROFITSDataset::readHeader( double &v, char *name )
     1862int NROFITSDataset::readHeader( double &v, const char *name )
    18751863{
    18761864  //
     
    19071895}
    19081896
    1909 int NROFITSDataset::readTable( char *v, char *name, int clen, int idx )
     1897int NROFITSDataset::readTable( char *v, const char *name, int clen, int idx )
    19101898{
    19111899  //
     
    19171905    return status ;
    19181906
    1919   // get length of char
    1920   int index = -1 ;
    1921   for ( int i = 0 ; i < numField_ ; i++ ) {
    1922     if ( names_[i] == name ) {
    1923       index = i ;
    1924       break ;
    1925     }
    1926   }
    1927 
    1928   int xsize = sizes_[index] ;
     1907  map<string, FieldProperty>::iterator iter = properties_.find(string(name));
     1908  if (iter == properties_.end())
     1909    return -1;
     1910
     1911  int xsize = iter->second.size;
    19291912
    19301913  // read data
     
    19411924}
    19421925
    1943 int NROFITSDataset::readTable( int &v, char *name, int b, int idx )
     1926int NROFITSDataset::readTable( int &v, const char *name, int b, int idx )
    19441927{
    19451928  //
     
    19591942}
    19601943
    1961 int NROFITSDataset::readTable( float &v, char *name, int b, int idx )
     1944int NROFITSDataset::readTable( float &v, const char *name, int b, int idx )
    19621945{
    19631946  //
     
    19771960}
    19781961
    1979 int NROFITSDataset::readTable( double &v, char *name, int b, int idx )
     1962int NROFITSDataset::readTable( double &v, const char *name, int b, int idx )
    19801963{
    19811964  //
     
    19951978}
    19961979
    1997 int NROFITSDataset::readTable( vector<char *> &v, char *name, int idx )
     1980int NROFITSDataset::readTable( vector<char *> &v, const char *name, int idx )
    19981981{
    19991982  //
     
    20041987    return status ;
    20051988
    2006   // get length of char
    2007   int index = -1 ;
    2008   for ( int i = 0 ; i < numField_ ; i++ ) {
    2009     if ( names_[i] == name ) {
    2010       index = i ;
    2011       break ;
    2012     }
    2013   }
    2014 
    2015   int xsize = sizes_[index] ;
     1989  map<string, FieldProperty>::iterator iter = properties_.find(string(name));
     1990  if (iter == properties_.end())
     1991    return -1;
     1992
     1993  int xsize = iter->second.size;
    20161994
    20171995  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
     
    20312009}
    20322010
    2033 int NROFITSDataset::readTable( vector<int> &v, char *name, int b, int idx )
     2011int NROFITSDataset::readTable( vector<int> &v, const char *name, int b, int idx )
    20342012{
    20352013  //
     
    20502028}
    20512029
    2052 int NROFITSDataset::readTable( vector<float> &v, char *name, int b, int idx )
     2030int NROFITSDataset::readTable( vector<float> &v, const char *name, int b, int idx )
    20532031{
    20542032  //
     
    20692047}
    20702048
    2071 int NROFITSDataset::readTable( vector<double> &v, char *name, int b, int idx )
     2049int NROFITSDataset::readTable( vector<double> &v, const char *name, int b, int idx )
    20722050{
    20732051  //
     
    20882066}
    20892067
    2090 int NROFITSDataset::readColumn( vector<string> &v, char *name, int idx )
     2068int NROFITSDataset::readColumn( vector<string> &v, const char *name, int idx )
    20912069{
    20922070  //
     
    20982076    return status ;
    20992077
    2100   // get length of char
    2101   int index = -1 ;
    2102   for ( int i = 0 ; i < numField_ ; i++ ) {
    2103     if ( names_[i] == name ) {
    2104       index = i ;
    2105       break ;
    2106     }
    2107   }
    2108 
    2109   int xsize = sizes_[index] ;
     2078  map<string, FieldProperty>::iterator iter = properties_.find(string(name));
     2079  if (iter == properties_.end())
     2080    return -1;
     2081
     2082  int xsize = iter->second.size;
    21102083
    21112084  for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
     
    21322105}
    21332106
    2134 int NROFITSDataset::readColumn( vector<int> &v, char *name, int b, int idx )
     2107int NROFITSDataset::readColumn( vector<int> &v, const char *name, int b, int idx )
    21352108{
    21362109  //
     
    21552128}
    21562129
    2157 int NROFITSDataset::readColumn( vector<float> &v, char *name, int b, int idx )
     2130int NROFITSDataset::readColumn( vector<float> &v, const char *name, int b, int idx )
    21582131{
    21592132  //
     
    21782151}
    21792152
    2180 int NROFITSDataset::readColumn( vector<double> &v, char *name, int b, int idx )
     2153int NROFITSDataset::readColumn( vector<double> &v, const char *name, int b, int idx )
    21812154{
    21822155  //
     
    22442217}
    22452218
    2246 int NROFITSDataset::movePointer( char *name, int idx )
     2219int NROFITSDataset::movePointer( const char *name, int idx )
    22472220{
    22482221  // find offset
     
    22602233  return 0 ;
    22612234}
    2262 
    2263 // double NROFITSDataset::toLSR( double v, double t, double x, double y )
    2264 // {
    2265 //   return v ;
    2266 // }
  • trunk/external-alma/atnf/PKSIO/NROFITSDataset.h

    r2784 r2812  
    3939
    4040#include <string>
     41#include <map>
    4142
    4243using namespace std ;
     
    9798
    9899 protected:
     100  // stracture representing property of fields
     101  struct FieldProperty {
     102    //string name;    // field name
     103    int size;         // data size [byte]
     104    //string unit;    // unit of the field
     105    long offset;      // offset from the head of scan record [byte]
     106  };
     107
    99108  // fill header information
    100109  int fillHeader( int sameEndian ) ;
    101110
    102111  // Read char data
    103   int readHeader( string &v, char *name ) ;
    104   int readTable( char *v, char *name, int clen, int idx=0 ) ;
    105   int readTable( vector<char *> &v, char *name, int idx=0 ) ;
    106   int readColumn( vector<string> &v, char *name, int idx=0 ) ;
     112  int readHeader( string &v, const char *name ) ;
     113  int readTable( char *v, const char *name, int clen, int idx=0 ) ;
     114  int readTable( vector<char *> &v, const char *name, int idx=0 ) ;
     115  int readColumn( vector<string> &v, const char *name, int idx=0 ) ;
    107116
    108117  // Read int data
    109   int readHeader( int &v, char *name) ;
    110   int readTable( int &v, char *name, int b, int idx=0 ) ;
    111   int readTable( vector<int> &v, char *name, int b, int idx=0 ) ;
    112   int readColumn( vector<int> &v, char *name, int b, int idx=0 ) ;
     118  int readHeader( int &v, const char *name) ;
     119  int readTable( int &v, const char *name, int b, int idx=0 ) ;
     120  int readTable( vector<int> &v, const char *name, int b, int idx=0 ) ;
     121  int readColumn( vector<int> &v, const char *name, int b, int idx=0 ) ;
    113122
    114123  // Read float data
    115   int readHeader( float &v, char *name) ;
    116   int readTable( float &v, char *name, int b, int idx=0 ) ;
    117   int readTable( vector<float> &v, char *name, int b, int idx=0 ) ;
    118   int readColumn( vector<float> &v, char *name, int b, int idx=0 ) ;
     124  int readHeader( float &v, const char *name) ;
     125  int readTable( float &v, const char *name, int b, int idx=0 ) ;
     126  int readTable( vector<float> &v, const char *name, int b, int idx=0 ) ;
     127  int readColumn( vector<float> &v, const char *name, int b, int idx=0 ) ;
    119128
    120129  // Read double data
    121   int readHeader( double &v, char *name) ;
    122   int readTable( double &v, char *name, int b, int idx=0 ) ;
    123   int readTable( vector<double> &v, char *name, int b, int idx=0 ) ;
    124   int readColumn( vector<double> &v, char *name, int b, int idx=0 ) ;
     130  int readHeader( double &v, const char *name) ;
     131  int readTable( double &v, const char *name, int b, int idx=0 ) ;
     132  int readTable( vector<double> &v, const char *name, int b, int idx=0 ) ;
     133  int readColumn( vector<double> &v, const char *name, int b, int idx=0 ) ;
    125134
    126135  // read ARRY
     
    143152
    144153  // get offset bytes for attributes
    145   long getOffset( char *name ) ;
     154  long getOffset( const char *name ) ;
    146155
    147156  // move pointer to target position
    148   int movePointer( char *name, int idx=0 ) ;
    149 
    150   // convert frequency frame
    151 //   virtual double toLSR( double v, double t, double x, double y ) ;
     157  int movePointer( const char *name, int idx=0 ) ;
    152158
    153159  // number of column for scan header
     
    163169  vector<int> arrayid_ ;
    164170
    165   // field names
    166   vector<string> names_ ;
    167 
    168   // field units
    169   vector<string> units_ ;
    170 
    171   // sizes of each field
    172   vector<int> sizes_ ; 
    173 
    174   // offsets from the beginning of the file
    175   vector<long> offsets_ ;
     171  // field properties
     172  // Key   = field name
     173  // Value = field properties
     174  map<string, FieldProperty> properties_ ;
    176175
    177176  // spectral data
Note: See TracChangeset for help on using the changeset viewer.