Changeset 2768 for trunk/external-alma
- Timestamp:
- 02/12/13 12:04:54 (12 years ago)
- Location:
- trunk/external-alma/atnf/PKSIO
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc
r2766 r2768 61 61 // data initialization 62 62 readHeader( numField_, "TFIELDS", same_ ) ; 63 forms_.resize( numField_ ) ;64 63 names_.resize( numField_ ) ; 65 64 units_.resize( numField_ ) ; 65 sizes_.resize( numField_ ) ; 66 offsets_.resize( numField_ ) ; 66 67 getField() ; 67 68 … … 1478 1479 void NROFITSDataset::getField() 1479 1480 { 1481 long offset = 0; 1480 1482 for ( int i = 0 ; i < numField_ ; i++ ) { 1481 1483 char key1[9] ; … … 1507 1509 return ; 1508 1510 } 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( " " ) ; 1512 1513 if ( spos != string::npos ) 1513 form s_[i] = forms_[i].substr( 0, spos ) ;1514 form = form.substr( 0, spos ) ; 1514 1515 //strcpy( tmp, " " ) ; 1515 1516 if ( readHeader( tmp, key2 ) != 0 ) { … … 1523 1524 names_[i] = names_[i].substr( 0, spos ) ; 1524 1525 //strcpy( tmp, " " ) ; 1525 if ( form s_[i].find( "A" ) != string::npos ) {1526 //cout << "skip to get unit: name = " << form s_[i]<< endl ;1526 if ( form.find( "A" ) != string::npos ) { 1527 //cout << "skip to get unit: name = " << form << endl ; 1527 1528 //strcpy( tmp, "none " ) ; 1528 1529 tmp = "none" ; 1529 1530 } 1530 1531 else { 1531 //cout << "get unit: name = " << form s_[i]<< endl ;1532 //cout << "get unit: name = " << form << endl ; 1532 1533 if ( readHeader( tmp, key3 ) != 0 ) { 1533 1534 //strcpy( tmp, "none " ) ; … … 1540 1541 if ( spos != string::npos ) 1541 1542 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] ; 1543 1561 } 1544 1562 } … … 1679 1697 1680 1698 // get offset 1681 intoffset = getOffset( "ARRYT" ) ;1699 long offset = getOffset( "ARRYT" ) ; 1682 1700 if ( offset == -1 ) { 1683 1701 //cerr << "Error, ARRYT is not found in the name list." << endl ; … … 1720 1738 } 1721 1739 1722 intNROFITSDataset::getOffset( char *name )1723 { 1724 intoffset = 0 ;1740 long NROFITSDataset::getOffset( char *name ) 1741 { 1742 long offset = 0 ; 1725 1743 string sname( name ) ; 1726 bool found = false;1727 for ( inti = 0 ; i < numField_ ; i++ ) {1744 long j = -1 ; 1745 for ( long i = 0 ; i < numField_ ; i++ ) { 1728 1746 // escape if name is found 1729 1747 //cout << "names_[" << i << "] = " << names_[i] << " sname = " << sname << endl ; 1730 1748 if ( names_[i] == sname ) { 1731 found = true;1749 j = i ; 1732 1750 break ; 1733 1751 } 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 ; 1755 1755 1756 1756 return offset ; … … 1949 1949 } 1950 1950 } 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] ; 1954 1953 1955 1954 // read data … … 2037 2036 } 2038 2037 } 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] ; 2042 2040 2043 2041 for ( unsigned int i = 0 ; i < v.size() ; i++ ) { … … 2132 2130 } 2133 2131 } 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] ; 2137 2134 2138 2135 for ( unsigned int i = 0 ; i < v.size() ; i++ ) { … … 2274 2271 { 2275 2272 // find offset 2276 intoffset = getOffset( name ) ;2273 long offset = getOffset( name ) ; 2277 2274 if ( offset == -1 ) { 2278 2275 //cerr << "Error, " << name << " is not found in the name list." << endl ; … … 2280 2277 } 2281 2278 2282 offset += idx * scanLen_;2279 offset += (long)(idx * scanLen_) ; 2283 2280 2284 2281 //cout << "offset for " << name << " is " << offset << " bytes." << endl ; -
trunk/external-alma/atnf/PKSIO/NROFITSDataset.h
r2442 r2768 146 146 147 147 // get offset bytes for attributes 148 intgetOffset( char *name ) ;148 long getOffset( char *name ) ; 149 149 150 150 // move pointer to target position … … 167 167 168 168 // field names 169 vector<string> forms_ ;170 171 // field types172 169 vector<string> names_ ; 173 170 174 171 // field units 175 172 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_ ; 176 179 177 180 // spectral data
Note:
See TracChangeset
for help on using the changeset viewer.