Index: /trunk/Mars/mcore/fits.h
===================================================================
--- /trunk/Mars/mcore/fits.h	(revision 12713)
+++ /trunk/Mars/mcore/fits.h	(revision 12714)
@@ -22,11 +22,11 @@
 #include <iostream>
 #define gLog cerr
-#define ___err___ ""
-#define ___all___ ""
+#define ___err___  ""
+#define ___all___  ""
 #else
 #include "MLog.h"
 #include "MLogManip.h"
-#define ___err___ err
-#define ___all___ all
+#define ___err___  err
+#define ___all___  all
 #endif
 
@@ -389,7 +389,7 @@
     size_t fRow;
 
-    vector<string> ReadBlock(vector<string> &vec)
-    {
-        bool endtag = false;
+    bool ReadBlock(vector<string> &vec)
+    {
+        int endtag = 0;
         for (int i=0; i<36; i++)
         {
@@ -400,6 +400,6 @@
                 break;
 
-            if (c[0]==0)
-                return vector<string>();
+//            if (c[0]==0)
+//                return vector<string>();
 
             string str(c);
@@ -408,40 +408,24 @@
 //                cout << setw(2) << i << "|" << str << "|" << (endtag?'-':'+') << endl;
 
-            if (str=="END                                                                             ")
-            {
-                endtag = true;
-
-                // Make sure that no empty vector is returned
-                if (vec.size()%36==0)
-                    vec.push_back(string("END     = '' / "));
-            }
-            else
-            {
-                char value = str[0];
-                int valuei = (int)(value);
-            }
-            //Would have liked to do it with a string comparison, but could not figure out the character for value 32...
-            bool isNULL = true;
-            for (int j=0;j<80;j++)
-                if (int(str[j]) != 32)
-                    isNULL = false;
-            if (isNULL)
-            {
-                if (!endtag)
-                    cout << "WARNING: END keyword missing. Loaded data may be corrupted" << endl;
-
-                endtag = true;
-
-                if (vec.size()%36==0)
-                    vec.push_back(string("END     = '' / "));
-            }
-
-            if (endtag)
+            if (endtag==2 || str=="END                                                                             ")
+            {
+                endtag = 2; // valid END tag found
                 continue;
+            }
+
+            if (endtag==1 || str=="                                                                                ")
+            {
+                endtag = 1; // end tag not found, but expected to be there
+                continue;
+            }
 
             vec.push_back(str);
         }
 
-        return vec;
+        // Make sure that no empty vector is returned
+        if (endtag && vec.size()%36==0)
+            vec.push_back(string("END     = '' / "));
+
+        return endtag==2;
     }
 
@@ -457,5 +441,5 @@
 
 public:
-    fits(const string &fname) : izstream(fname.c_str())
+    fits(const string &fname, bool force=false) : izstream(fname.c_str())
     {
         char simple[10];
@@ -483,5 +467,5 @@
             {
                 // FIXME: Set limit on memory consumption
-                ReadBlock(block);
+                const int rc = ReadBlock(block);
                 if (!good())
                 {
@@ -496,5 +480,17 @@
 
                 if (block.size()%36)
+                {
+                    if (!rc && !force)
+                    {
+                        clear(rdstate()|ios::badbit);
+#ifdef __EXCEPTIONS
+                        throw runtime_error("END keyword missing in FITS header.");
+#else
+                        gLog << ___err__ << "ERROR - END keyword missing in FITS file... file might be corrupted." << endl;
+                        return;
+#endif
+                    }
                     break;
+                }
             }
 
@@ -609,5 +605,5 @@
         {
             ostringstream str;
-            str <<"SetPtrAddress('" << name << "') - Column not found." << endl;
+            str << "SetPtrAddress('" << name << "') - Column not found." << endl;
 #ifdef __EXCEPTIONS
             throw runtime_error(str.str());
