Index: trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc
===================================================================
--- trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc	(revision 2436)
+++ trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc	(revision 2440)
@@ -1947,18 +1947,7 @@
   // of the FITS Scan Record
   //
-  int status = 0 ;
-
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  offset += idx * scanLen_ ;
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name, idx ) ;
+  if ( status < 0 )
+    return status ;
 
   // get length of char
@@ -2004,17 +1993,7 @@
   // of the FITS Scan Record
   //
-  int status = 0 ;
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  offset += idx * scanLen_ ;
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name, idx ) ;
+  if ( status < 0 )
+    return status ;
 
   // read data
@@ -2043,18 +2022,7 @@
   // of the FITS Scan Record
   //
-  int status = 0 ;
-
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  offset += idx * scanLen_ ;
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name, idx ) ;
+  if ( status < 0 )
+    return status ;
 
   // read data
@@ -2083,18 +2051,7 @@
   // of the FITS Scan Record
   //
-  int status = 0 ;
-
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  offset += idx * scanLen_ ;
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name, idx ) ;
+  if ( status < 0 )
+    return status ;
 
   // read data
@@ -2111,18 +2068,7 @@
   // Read 'name' attribute defined as char array from the FITS Scan Record
   //
-  int status = 0 ;
-  
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  offset += idx * scanLen_ ;
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name, idx ) ;
+  if ( status < 0 )
+    return status ;
 
   // get length of char
@@ -2159,18 +2105,7 @@
   // Read 'name' attribute defined as int array from the FITS Scan Record
   //
-  int status = 0 ;
-  
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  offset += idx * scanLen_ ;
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name, idx ) ;
+  if ( status < 0 )
+    return status ;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
@@ -2189,18 +2124,7 @@
   // Read 'name' attribute defined as float array from the FITS Scan Record
   //
-  int status = 0 ;
-  
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  offset += idx * scanLen_ ;
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name, idx ) ;
+  if ( status < 0 )
+    return status ;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
@@ -2219,18 +2143,7 @@
   // Read 'name' attribute defined as double array from the FITS Scan Record
   //
-  int status = 0 ;
-  
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  offset += idx * scanLen_ ;
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name, idx ) ;
+  if ( status < 0 )
+    return status ;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
@@ -2261,17 +2174,7 @@
   // defined as char array from the FITS Scan Record 
   //
-  int status = 0 ;
-
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name ) ;
+  if ( status < 0 )
+    return status ;
 
   // get length of char
@@ -2288,5 +2191,5 @@
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
-    offset = scanLen_ * arrayid_[i] + xsize * idx ;
+    int offset = scanLen_ * arrayid_[i] + xsize * idx ;
     fseek( fp_, offset, SEEK_CUR ) ;
 //     int clen = (int)strlen( v[i] ) ;
@@ -2327,20 +2230,10 @@
   // defined as int array from the FITS Scan Record 
   //
-  int status = 0 ;
-
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name ) ;
+  if ( status < 0 )
+    return status ;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
-    offset = scanLen_ * arrayid_[i] + sizeof(int) * idx ;
+    int offset = scanLen_ * arrayid_[i] + sizeof(int) * idx ;
     fseek( fp_, offset, SEEK_CUR ) ;
     fread( &v[i], 1, sizeof(int), fp_ ) ;
@@ -2371,20 +2264,10 @@
   // defined as float array from the FITS Scan Record 
   //
-  int status = 0 ;
-
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name ) ;
+  if ( status < 0 )
+    return status ;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
-    offset = scanLen_ * arrayid_[i] + sizeof(float) * idx ;
+    int offset = scanLen_ * arrayid_[i] + sizeof(float) * idx ;
     fseek( fp_, offset, SEEK_CUR ) ;
     fread( &v[i], 1, sizeof(float), fp_ ) ;
@@ -2415,20 +2298,10 @@
   // defined as double array from the FITS Scan Record 
   //
-  int status = 0 ;
-
-  // skip header 
-  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
-
-  // find offset
-  int offset = getOffset( name ) ;
-  if ( offset == -1 ) {
-    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
-    return -1 ;
-  }
-  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
-  fseek( fp_, offset, SEEK_CUR ) ;
+  int status = movePointer( name ) ;
+  if ( status < 0 )
+    return status ;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
-    offset = scanLen_ * arrayid_[i] + sizeof(double) * idx ;
+    int offset = scanLen_ * arrayid_[i] + sizeof(double) * idx ;
     fseek( fp_, offset, SEEK_CUR ) ;
     fread( &v[i], 1, sizeof(double), fp_ ) ;
@@ -2484,4 +2357,24 @@
 }
 
+int NROFITSDataset::movePointer( char *name, int idx ) 
+{
+  // skip header 
+  fseek( fp_, FITS_HEADER_SIZE, SEEK_SET ) ;
+
+  // find offset
+  int offset = getOffset( name ) ;
+  if ( offset == -1 ) {
+    //cerr << "Error, " << name << " is not found in the name list." << endl ; 
+    return -1 ;
+  }
+
+  offset += idx * scanLen_ ;
+
+  //cout << "offset for " << name << " is " << offset << " bytes." << endl ;
+  fseek( fp_, offset, SEEK_CUR ) ;
+
+  return 0 ;
+}
+
 // double NROFITSDataset::toLSR( double v, double t, double x, double y ) 
 // {
