Changeset 2812 for trunk/external-alma/atnf
- Timestamp:
- 04/15/13 12:12:26 (12 years ago)
- Location:
- trunk/external-alma/atnf/PKSIO
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc
r2784 r2812 67 67 // field names, units, and sizes 68 68 readHeader( numField_, "TFIELDS" ) ; 69 names_.resize( numField_ ) ;70 units_.resize( numField_ ) ;71 sizes_.resize( numField_ ) ;72 offsets_.resize( numField_ ) ;73 69 getField() ; 74 70 … … 1494 1490 return ; 1495 1491 } 1496 //names_[i] = string( tmp ) ; 1497 names_[i] = tmp ; 1498 spos = names_[i].find( " " ) ; 1492 string name = tmp ; 1493 spos = tmp.find( " " ) ; 1499 1494 if ( spos != string::npos ) 1500 name s_[i] = names_[i].substr( 0, spos ) ;1495 name = tmp.substr( 0, spos ) ; 1501 1496 //strcpy( tmp, " " ) ; 1502 1497 if ( form.find( "A" ) != string::npos ) { … … 1512 1507 } 1513 1508 } 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 1522 1516 string substr1 = form.substr( 0, form.size()-1 ) ; 1523 1517 string substr2 = form.substr( form.size()-1, 1 ) ; … … 1533 1527 else if ( substr2 == "D" ) 1534 1528 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 ; 1537 1536 } 1538 1537 } … … 1714 1713 } 1715 1714 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 ; 1715 long 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; 1731 1719 1732 1720 return offset ; … … 1767 1755 } 1768 1756 1769 int NROFITSDataset::readHeader( string &v, c har *name )1757 int NROFITSDataset::readHeader( string &v, const char *name ) 1770 1758 { 1771 1759 // … … 1802 1790 } 1803 1791 1804 int NROFITSDataset::readHeader( int &v, c har *name )1792 int NROFITSDataset::readHeader( int &v, const char *name ) 1805 1793 { 1806 1794 // … … 1838 1826 1839 1827 1840 int NROFITSDataset::readHeader( float &v, c har *name )1828 int NROFITSDataset::readHeader( float &v, const char *name ) 1841 1829 { 1842 1830 // … … 1872 1860 } 1873 1861 1874 int NROFITSDataset::readHeader( double &v, c har *name )1862 int NROFITSDataset::readHeader( double &v, const char *name ) 1875 1863 { 1876 1864 // … … 1907 1895 } 1908 1896 1909 int NROFITSDataset::readTable( char *v, c har *name, int clen, int idx )1897 int NROFITSDataset::readTable( char *v, const char *name, int clen, int idx ) 1910 1898 { 1911 1899 // … … 1917 1905 return status ; 1918 1906 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; 1929 1912 1930 1913 // read data … … 1941 1924 } 1942 1925 1943 int NROFITSDataset::readTable( int &v, c har *name, int b, int idx )1926 int NROFITSDataset::readTable( int &v, const char *name, int b, int idx ) 1944 1927 { 1945 1928 // … … 1959 1942 } 1960 1943 1961 int NROFITSDataset::readTable( float &v, c har *name, int b, int idx )1944 int NROFITSDataset::readTable( float &v, const char *name, int b, int idx ) 1962 1945 { 1963 1946 // … … 1977 1960 } 1978 1961 1979 int NROFITSDataset::readTable( double &v, c har *name, int b, int idx )1962 int NROFITSDataset::readTable( double &v, const char *name, int b, int idx ) 1980 1963 { 1981 1964 // … … 1995 1978 } 1996 1979 1997 int NROFITSDataset::readTable( vector<char *> &v, c har *name, int idx )1980 int NROFITSDataset::readTable( vector<char *> &v, const char *name, int idx ) 1998 1981 { 1999 1982 // … … 2004 1987 return status ; 2005 1988 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; 2016 1994 2017 1995 for ( unsigned int i = 0 ; i < v.size() ; i++ ) { … … 2031 2009 } 2032 2010 2033 int NROFITSDataset::readTable( vector<int> &v, c har *name, int b, int idx )2011 int NROFITSDataset::readTable( vector<int> &v, const char *name, int b, int idx ) 2034 2012 { 2035 2013 // … … 2050 2028 } 2051 2029 2052 int NROFITSDataset::readTable( vector<float> &v, c har *name, int b, int idx )2030 int NROFITSDataset::readTable( vector<float> &v, const char *name, int b, int idx ) 2053 2031 { 2054 2032 // … … 2069 2047 } 2070 2048 2071 int NROFITSDataset::readTable( vector<double> &v, c har *name, int b, int idx )2049 int NROFITSDataset::readTable( vector<double> &v, const char *name, int b, int idx ) 2072 2050 { 2073 2051 // … … 2088 2066 } 2089 2067 2090 int NROFITSDataset::readColumn( vector<string> &v, c har *name, int idx )2068 int NROFITSDataset::readColumn( vector<string> &v, const char *name, int idx ) 2091 2069 { 2092 2070 // … … 2098 2076 return status ; 2099 2077 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; 2110 2083 2111 2084 for ( unsigned int i = 0 ; i < v.size() ; i++ ) { … … 2132 2105 } 2133 2106 2134 int NROFITSDataset::readColumn( vector<int> &v, c har *name, int b, int idx )2107 int NROFITSDataset::readColumn( vector<int> &v, const char *name, int b, int idx ) 2135 2108 { 2136 2109 // … … 2155 2128 } 2156 2129 2157 int NROFITSDataset::readColumn( vector<float> &v, c har *name, int b, int idx )2130 int NROFITSDataset::readColumn( vector<float> &v, const char *name, int b, int idx ) 2158 2131 { 2159 2132 // … … 2178 2151 } 2179 2152 2180 int NROFITSDataset::readColumn( vector<double> &v, c har *name, int b, int idx )2153 int NROFITSDataset::readColumn( vector<double> &v, const char *name, int b, int idx ) 2181 2154 { 2182 2155 // … … 2244 2217 } 2245 2218 2246 int NROFITSDataset::movePointer( c har *name, int idx )2219 int NROFITSDataset::movePointer( const char *name, int idx ) 2247 2220 { 2248 2221 // find offset … … 2260 2233 return 0 ; 2261 2234 } 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 39 39 40 40 #include <string> 41 #include <map> 41 42 42 43 using namespace std ; … … 97 98 98 99 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 99 108 // fill header information 100 109 int fillHeader( int sameEndian ) ; 101 110 102 111 // Read char data 103 int readHeader( string &v, c har *name ) ;104 int readTable( char *v, c har *name, int clen, int idx=0 ) ;105 int readTable( vector<char *> &v, c har *name, int idx=0 ) ;106 int readColumn( vector<string> &v, c har *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 ) ; 107 116 108 117 // Read int data 109 int readHeader( int &v, c har *name) ;110 int readTable( int &v, c har *name, int b, int idx=0 ) ;111 int readTable( vector<int> &v, c har *name, int b, int idx=0 ) ;112 int readColumn( vector<int> &v, c har *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 ) ; 113 122 114 123 // Read float data 115 int readHeader( float &v, c har *name) ;116 int readTable( float &v, c har *name, int b, int idx=0 ) ;117 int readTable( vector<float> &v, c har *name, int b, int idx=0 ) ;118 int readColumn( vector<float> &v, c har *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 ) ; 119 128 120 129 // Read double data 121 int readHeader( double &v, c har *name) ;122 int readTable( double &v, c har *name, int b, int idx=0 ) ;123 int readTable( vector<double> &v, c har *name, int b, int idx=0 ) ;124 int readColumn( vector<double> &v, c har *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 ) ; 125 134 126 135 // read ARRY … … 143 152 144 153 // get offset bytes for attributes 145 long getOffset( c har *name ) ;154 long getOffset( const char *name ) ; 146 155 147 156 // 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 ) ; 152 158 153 159 // number of column for scan header … … 163 169 vector<int> arrayid_ ; 164 170 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_ ; 176 175 177 176 // spectral data
Note:
See TracChangeset
for help on using the changeset viewer.