Index: trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc
===================================================================
--- trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc	(revision 2766)
+++ trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc	(revision 2768)
@@ -61,7 +61,8 @@
   // data initialization
   readHeader( numField_, "TFIELDS", same_ ) ;
-  forms_.resize( numField_ ) ;
   names_.resize( numField_ ) ;
   units_.resize( numField_ ) ;
+  sizes_.resize( numField_ ) ;
+  offsets_.resize( numField_ ) ;
   getField() ;
 
@@ -1478,4 +1479,5 @@
 void NROFITSDataset::getField() 
 {
+  long offset = 0;
   for ( int i = 0 ; i < numField_ ; i++ ) {
     char key1[9] ;
@@ -1507,9 +1509,8 @@
       return ;
     }
-    //forms_[i] = string( tmp ) ;
-    forms_[i] = tmp ;
-    string::size_type spos = forms_[i].find( " " ) ;
+    string form = tmp ;
+    string::size_type spos = form.find( " " ) ;
     if ( spos != string::npos )
-      forms_[i] = forms_[i].substr( 0, spos ) ;
+      form = form.substr( 0, spos ) ;
     //strcpy( tmp, "         " ) ;
     if ( readHeader( tmp, key2 ) != 0 ) {
@@ -1523,11 +1524,11 @@
       names_[i] = names_[i].substr( 0, spos ) ;
     //strcpy( tmp, "         " ) ;
-    if ( forms_[i].find( "A" ) != string::npos ) {
-      //cout << "skip to get unit: name = " << forms_[i] << endl ;
+    if ( form.find( "A" ) != string::npos ) {
+      //cout << "skip to get unit: name = " << form << endl ;
       //strcpy( tmp, "none    " ) ;
       tmp = "none" ;
     }
     else {
-      //cout << "get unit: name = " << forms_[i] << endl ;
+      //cout << "get unit: name = " << form << endl ;
       if ( readHeader( tmp, key3 ) != 0 ) {
         //strcpy( tmp, "none    " ) ;
@@ -1540,5 +1541,22 @@
     if ( spos != string::npos )
       units_[i] = units_[i].substr( 0, spos ) ;
-    //cout << "i = " << i << ": name=" << forms_[i] << " type=" << names_[i] << " unit=" << units_[i] << endl ;
+    //cout << "i = " << i << ": name=" << form << " type=" << names_[i] << " unit=" << units_[i] << endl ;
+
+    offsets_[i] = offset ;
+    string substr1 = form.substr( 0, form.size()-1 ) ;
+    string substr2 = form.substr( form.size()-1, 1 ) ;
+    //cout << "substr1 = " << substr1 << ", substr2 = " << substr2 << endl ;
+    int o1 = atoi( substr1.c_str() ) ;
+    int o2 = 0 ;
+    if ( substr2 == "A" )
+      o2 = sizeof(char) ;
+    else if ( substr2 == "J" ) 
+      o2 = sizeof(int) ;
+    else if ( substr2 == "F" )
+      o2 = sizeof(float) ;
+    else if ( substr2 == "D" )
+      o2 = sizeof(double) ;
+    sizes_[i] = o1 * o2 ;
+    offset += sizes_[i] ;
   }  
 }
@@ -1679,5 +1697,5 @@
 
   // get offset
-  int offset = getOffset( "ARRYT" ) ;
+  long offset = getOffset( "ARRYT" ) ;
   if ( offset == -1 ) {
     //cerr << "Error, ARRYT is not found in the name list." << endl ; 
@@ -1720,37 +1738,19 @@
   }
 
-int NROFITSDataset::getOffset( char *name ) 
-{
-  int offset = 0 ;
+long NROFITSDataset::getOffset( char *name ) 
+{
+  long offset = 0 ;
   string sname( name ) ;
-  bool found = false ;
-  for ( int i = 0 ; i < numField_ ; i++ ) {
+  long j = -1 ;
+  for ( long i = 0 ; i < numField_ ; i++ ) {
     // escape if name is found
     //cout << "names_[" << i << "] = " << names_[i] << "  sname = " << sname << endl ;
     if ( names_[i] == sname ) {
-      found = true ;
+      j = i ;
       break ;
     }
-
-    // form analysis
-    string substr1 = forms_[i].substr( 0, forms_[i].size()-1 ) ;
-    string substr2 = forms_[i].substr( forms_[i].size()-1, 1 ) ;
-    //cout << "substr1 = " << substr1 << ", substr2 = " << substr2 << endl ;
-    int o1 = atoi( substr1.c_str() ) ;
-    int o2 = 0 ;
-    if ( substr2 == "A" )
-      o2 = sizeof(char) ;
-    else if ( substr2 == "J" ) 
-      o2 = sizeof(int) ;
-    else if ( substr2 == "F" )
-      o2 = sizeof(float) ;
-    else if ( substr2 == "D" )
-      o2 = sizeof(double) ;
-    //cout << "o1 = " << o1 << ", o2 = " << o2 << endl ;
-    offset += o1 * o2 ;
-  }
-
-  if ( !found )
-    offset = -1 ;
+  }
+
+  offset = (j >= 0) ? offsets_[j] : j ;
 
   return offset ;
@@ -1949,7 +1949,6 @@
     }
   }
-  string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
-  int xsize = atoi( substr.c_str() ) ;
-  //cout << "xsize = " << xsize << endl ;
+
+  int xsize = sizes_[index] ;
 
   // read data
@@ -2037,7 +2036,6 @@
     }
   }
-  string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
-  int xsize = atoi( substr.c_str() ) ;
-  //cout << "xsize = " << xsize << endl ;
+
+  int xsize = sizes_[index] ;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
@@ -2132,7 +2130,6 @@
     }
   }
-  string substr = forms_[index].substr( 0, forms_[index].size()-1 ) ;
-  int xsize = atoi( substr.c_str() ) ;
-  //cout << "xsize = " << xsize << endl ;
+
+  int xsize = sizes_[index] ;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
@@ -2274,5 +2271,5 @@
 {
   // find offset
-  int offset = getOffset( name ) ;
+  long offset = getOffset( name ) ;
   if ( offset == -1 ) {
     //cerr << "Error, " << name << " is not found in the name list." << endl ; 
@@ -2280,5 +2277,5 @@
   }
 
-  offset += idx * scanLen_ ;
+  offset += (long)(idx * scanLen_) ;
 
   //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
