Index: trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc
===================================================================
--- trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc	(revision 2940)
+++ trunk/external-alma/atnf/PKSIO/NROFITSDataset.cc	(revision 3066)
@@ -1684,4 +1684,7 @@
     char ctmp[5] ;
     std::size_t retval = fread( ctmp, 1, 4, fp_ ) ;
+    if (retval < 4) {
+      os << LogIO::SEVERE << "Failed to read array configuration." << LogIO::EXCEPTION;
+    }
     ctmp[4] = '\0' ;
     //cout << "ctmp = " << ctmp << endl ;
@@ -1768,4 +1771,8 @@
   while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
     std::size_t retval = fread( buf, 1, 80, fp_ ) ;
+    if (retval < 80) {
+      LogIO os(LogOrigin("NROFITSDataset", "readHeader(string)", WHERE));
+      os << LogIO::SEVERE << "Failed to read header" << LogIO::EXCEPTION;
+    }
     buf[80] = '\0' ;
     count++ ;
@@ -1802,4 +1809,8 @@
   while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
     std::size_t retval = fread( buf, 1, 80, fp_ ) ;
+    if (retval < 80) {
+      LogIO os(LogOrigin("NROFITSDataset", "readHeader(int)", WHERE));
+      os << LogIO::SEVERE << "Failed to read header" << LogIO::EXCEPTION;
+    }
     buf[80] = '\0' ;
     //char bufo[9] ;
@@ -1838,4 +1849,8 @@
   while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
     std::size_t retval = fread( buf, 1, 80, fp_ ) ;
+    if (retval < 80) {
+      LogIO os(LogOrigin("NROFITSDataset", "readHeader(float)", WHERE));
+      os << LogIO::SEVERE << "Failed to read header" << LogIO::EXCEPTION;
+    }
     buf[80] = '\0' ;
     //char bufo[9] ;
@@ -1872,4 +1887,8 @@
   while ( strncmp( buf, name, strlen(name) ) != 0 && strncmp( buf, "END", 3 ) != 0 ) {
     std::size_t retval = fread( buf, 1, 80, fp_ ) ;
+    if (retval < 80) {
+      LogIO os(LogOrigin("NROFITSDataset", "readHeader(double)", WHERE));
+      os << LogIO::SEVERE << "Failed to read header" << LogIO::EXCEPTION;
+    }
     buf[80] = '\0' ;
     char bufo[9] ;
@@ -1895,5 +1914,5 @@
 }
 
-int NROFITSDataset::readTable( char *v, const char *name, int clen, int idx ) 
+int NROFITSDataset::readTable( char *v, const char *name, size_t clen, int idx )
 {
   //
@@ -1909,14 +1928,25 @@
     return -1;
 
-  int xsize = iter->second.size;
+  size_t xsize = iter->second.size;
 
   // read data
   if ( xsize < clen ) {
     std::size_t retval = fread( v, 1, xsize, fp_ ) ;
+    if (retval < xsize) {
+      LogIO os(LogOrigin("NROFITSDataset", "readTable(char *)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
     //v[xsize] = '\0' ;
   }
+  else if (clen > 0) {
+    std::size_t retval = fread( v, 1, clen - 1, fp_ ) ;
+    if (retval < clen - 1) {
+      LogIO os(LogOrigin("NROFITSDataset", "readTable(char *)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
+    //v[clen-1] = '\0' ;
+  }
   else {
-    std::size_t retval = fread( v, 1, clen-1, fp_ ) ;
-    //v[clen-1] = '\0' ;
+    status = -1;
   }
 
@@ -1936,4 +1966,8 @@
   // read data
   std::size_t retval = fread( &v, sizeof(int), 1, fp_ ) ;
+  if (retval < 1) {
+    LogIO os(LogOrigin("NROFITSDataset", "readTable(int)", WHERE));
+    os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+  }
   if ( b == 0 ) 
     convertEndian( v ) ;
@@ -1954,4 +1988,8 @@
   // read data
   std::size_t retval = fread( &v, sizeof(float), 1, fp_ ) ;
+  if (retval < 1) {
+    LogIO os(LogOrigin("NROFITSDataset", "readTable(float)", WHERE));
+    os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+  }
   if ( b == 0 ) 
     convertEndian( v ) ;
@@ -1972,4 +2010,8 @@
   // read data
   std::size_t retval = fread( &v, sizeof(double), 1, fp_ ) ;
+  if (retval < 1) {
+    LogIO os(LogOrigin("NROFITSDataset", "readTable(double)", WHERE));
+    os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+  }
   if ( b == 0 ) 
     convertEndian( v ) ;  
@@ -1991,14 +2033,22 @@
     return -1;
 
-  int xsize = iter->second.size;
+  size_t xsize = iter->second.size;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
-    int clen = strlen( v[i] ) ;
+    size_t clen = strlen( v[i] ) ;
     if ( clen > xsize ) {
       std::size_t retval = fread( v[i], 1, xsize, fp_ ) ;
+      if (retval < xsize) {
+        LogIO os(LogOrigin("NROFITSDataset", "readTable(vector<char *>)", WHERE));
+        os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+      }
       //v[i][xsize] = '\0' ;
     }
     else {
       std::size_t retval = fread( v[i], 1, clen, fp_ ) ;
+      if (retval < clen) {
+        LogIO os(LogOrigin("NROFITSDataset", "readTable(vector<char *>)", WHERE));
+        os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+      }
       //v[i][clen-1] = '\0' ;
     }
@@ -2019,5 +2069,9 @@
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
-    std::size_t retval = fread( &v[i], 1, sizeof(int), fp_ ) ;
+    std::size_t retval = fread( &v[i], sizeof(int), 1, fp_ ) ;
+    if (retval < 1) {
+      LogIO os(LogOrigin("NROFITSDataset", "readTable(vector<int>)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
     if ( b == 0 ) 
       convertEndian( v[i] ) ;
@@ -2038,5 +2092,9 @@
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
-    std::size_t retval = fread( &v[i], 1, sizeof(float), fp_ ) ;
+    std::size_t retval = fread( &v[i], sizeof(float), 1, fp_ ) ;
+    if (retval < 1) {
+      LogIO os(LogOrigin("NROFITSDataset", "readTable(vector<float>)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
     if ( b == 0 ) 
       convertEndian( v[i] ) ;
@@ -2057,5 +2115,9 @@
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
-    std::size_t retval = fread( &v[i], 1, sizeof(double), fp_ ) ;
+    std::size_t retval = fread( &v[i], sizeof(double), 1, fp_ ) ;
+    if (retval < 1) {
+      LogIO os(LogOrigin("NROFITSDataset", "readTable(vector<double>)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
     if ( b == 0 ) 
       convertEndian( v[i] ) ;
@@ -2080,5 +2142,5 @@
     return -1;
 
-  int xsize = iter->second.size;
+  size_t xsize = iter->second.size;
 
   for ( unsigned int i = 0 ; i < v.size() ; i++ ) {
@@ -2096,4 +2158,8 @@
     char c[xsize+1] ;
     std::size_t retval = fread( c, 1, xsize, fp_ ) ;
+    if (retval < xsize) {
+      LogIO os(LogOrigin("NROFITSDataset", "readColumn(string)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
     c[xsize] = '\0' ;
     v[i] = string( c ) ;
@@ -2118,5 +2184,9 @@
     int offset = scanLen_ * arrayid_[i] + sizeof(int) * idx ;
     fseek( fp_, offset, SEEK_CUR ) ;
-    std::size_t retval = fread( &v[i], 1, sizeof(int), fp_ ) ;
+    std::size_t retval = fread( &v[i], sizeof(int), 1, fp_ ) ;
+    if (retval < 1) {
+      LogIO os(LogOrigin("NROFITSDataset", "readColumn(int)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
     if ( b == 0 ) 
       convertEndian( v[i] ) ;
@@ -2142,4 +2212,8 @@
     fseek( fp_, offset, SEEK_CUR ) ;
     std::size_t retval = fread( &v[i], 1, sizeof(float), fp_ ) ;
+    if (retval < 1) {
+      LogIO os(LogOrigin("NROFITSDataset", "readColumn(float)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
     if ( b == 0 ) 
       convertEndian( v[i] ) ;
@@ -2165,4 +2239,8 @@
     fseek( fp_, offset, SEEK_CUR ) ;
     std::size_t retval = fread( &v[i], 1, sizeof(double), fp_ ) ;
+    if (retval < 1) {
+      LogIO os(LogOrigin("NROFITSDataset", "readColumn(double)", WHERE));
+      os << LogIO::SEVERE << "Failed to read binary table" << LogIO::EXCEPTION;
+    }
     if ( b == 0 ) 
       convertEndian( v[i] ) ;
