Index: trunk/BNC/src/ephemeris.cpp
===================================================================
--- trunk/BNC/src/ephemeris.cpp	(revision 6400)
+++ trunk/BNC/src/ephemeris.cpp	(revision 6518)
@@ -21,7 +21,7 @@
 ////////////////////////////////////////////////////////////////////////////
 t_eph::t_eph() {
-  _ok      = false;
-  _orbCorr = 0;
-  _clkCorr = 0;
+  _checkState = unchecked;
+  _orbCorr    = 0;
+  _clkCorr    = 0;
 }
 
@@ -43,4 +43,9 @@
 ////////////////////////////////////////////////////////////////////////////
 t_irc t_eph::getCrd(const bncTime& tt, ColumnVector& xc, ColumnVector& vv, bool useCorr) const {
+
+  if (_checkState == bad) {
+    return failure;
+  }
+
   xc.ReSize(4);
   vv.ReSize(3);
@@ -88,5 +93,5 @@
   }
   else {
-    _ok = false;
+    _checkState = bad;
     return;
   }
@@ -134,6 +139,4 @@
   _TOT         = 0.9999e9;
   _fitInterval = 0.0;
-
-  _ok       = true;
 }
 
@@ -141,4 +144,8 @@
 ////////////////////////////////////////////////////////////////////////////
 t_irc t_ephGPS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
+
+  if (_checkState == bad) {
+    return failure;
+  }
 
   static const double omegaEarth = 7292115.1467e-11;
@@ -261,4 +268,8 @@
 t_irc t_ephGlo::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
 
+  if (_checkState == bad) {
+    return failure;
+  }
+
   static const double nominalStep = 10.0;
 
@@ -402,6 +413,4 @@
   _xv(5) = _y_velocity * 1.e3; 
   _xv(6) = _z_velocity * 1.e3; 
-
-  _ok = true;
 }
 
@@ -452,6 +461,4 @@
 
   _flags    = ee->flags;
-
-  _ok = true;
 }
 
@@ -459,4 +466,8 @@
 ////////////////////////////////////////////////////////////////////////////
 t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
+
+  if (_checkState == bad) {
+    return failure;
+  }
 
   static const double omegaEarth = 7292115.1467e-11;
@@ -545,7 +556,6 @@
   const int nLines = 8;
 
-  _ok = false;
-
   if (lines.size() != nLines) {
+    _checkState = bad;
     return;
   }
@@ -596,4 +606,5 @@
            readDbl(line, pos[2], fieldLen, _clock_drift    ) ||
            readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
+        _checkState = bad;
         return;
       }
@@ -605,4 +616,5 @@
            readDbl(line, pos[2], fieldLen, _Delta_n) ||
            readDbl(line, pos[3], fieldLen, _M0     ) ) {
+        _checkState = bad;
         return;
       }
@@ -614,4 +626,5 @@
            readDbl(line, pos[2], fieldLen, _Cus   ) ||
            readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
+        _checkState = bad;
         return;
       }
@@ -623,4 +636,5 @@
            readDbl(line, pos[2], fieldLen, _OMEGA0)  ||
            readDbl(line, pos[3], fieldLen, _Cis   ) ) {
+        _checkState = bad;
         return;
       }
@@ -632,4 +646,5 @@
            readDbl(line, pos[2], fieldLen, _omega   ) ||
            readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
+        _checkState = bad;
         return;
       }
@@ -641,4 +656,5 @@
            readDbl(line, pos[2], fieldLen, _TOEweek  ) ||
            readDbl(line, pos[3], fieldLen, _L2PFlag) ) {
+        _checkState = bad;
         return;
       }
@@ -650,4 +666,5 @@
            readDbl(line, pos[2], fieldLen, _TGD   ) ||
            readDbl(line, pos[3], fieldLen, _IODC  ) ) {
+        _checkState = bad;
         return;
       }
@@ -656,4 +673,5 @@
     else if ( iLine == 7 ) {
       if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
+        _checkState = bad;
         return;
       }
@@ -661,6 +679,4 @@
     }
   }
-
-  _ok = true;
 }
 
@@ -671,7 +687,6 @@
   const int nLines = 4;
 
-  _ok = false;
-
   if (lines.size() != nLines) {
+    _checkState = bad;
     return;
   }
@@ -722,4 +737,5 @@
            readDbl(line, pos[2], fieldLen, _gamma) ||
            readDbl(line, pos[3], fieldLen, _tki  ) ) {
+        _checkState = bad;
         return;
       }
@@ -733,4 +749,5 @@
            readDbl(line, pos[2], fieldLen, _x_acceleration) ||
            readDbl(line, pos[3], fieldLen, _health        ) ) {
+        _checkState = bad;
         return;
       }
@@ -742,4 +759,5 @@
            readDbl(line, pos[2], fieldLen, _y_acceleration  ) ||
            readDbl(line, pos[3], fieldLen, _frequency_number) ) {
+        _checkState = bad;
         return;
       }
@@ -751,4 +769,5 @@
            readDbl(line, pos[2], fieldLen, _z_acceleration)  ||
            readDbl(line, pos[3], fieldLen, _E             ) ) {
+        _checkState = bad;
         return;
       }
@@ -766,6 +785,4 @@
   _xv(5) = _y_velocity * 1.e3; 
   _xv(6) = _z_velocity * 1.e3; 
-
-  _ok = true;
 }
 
@@ -776,7 +793,6 @@
   const int nLines = 8;
 
-  _ok = false;
-
   if (lines.size() != nLines) {
+    _checkState = bad;
     return;
   }
@@ -824,4 +840,5 @@
            readDbl(line, pos[2], fieldLen, _clock_drift    ) ||
            readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
+        _checkState = bad;
         return;
       }
@@ -833,4 +850,5 @@
            readDbl(line, pos[2], fieldLen, _Delta_n) ||
            readDbl(line, pos[3], fieldLen, _M0     ) ) {
+        _checkState = bad;
         return;
       }
@@ -842,4 +860,5 @@
            readDbl(line, pos[2], fieldLen, _Cus   ) ||
            readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
+        _checkState = bad;
         return;
       }
@@ -851,4 +870,5 @@
            readDbl(line, pos[2], fieldLen, _OMEGA0)  ||
            readDbl(line, pos[3], fieldLen, _Cis   ) ) {
+        _checkState = bad;
         return;
       }
@@ -860,4 +880,5 @@
            readDbl(line, pos[2], fieldLen, _omega   ) ||
            readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
+        _checkState = bad;
         return;
       }
@@ -867,4 +888,5 @@
       if ( readDbl(line, pos[0], fieldLen, _IDOT    ) ||
            readDbl(line, pos[2], fieldLen, _TOEweek) ) {
+        _checkState = bad;
         return;
       }
@@ -876,4 +898,5 @@
            readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
            readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
+        _checkState = bad;
         return;
       }
@@ -882,10 +905,9 @@
     else if ( iLine == 7 ) {
       if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
-        return;
-      }
-    }
-  }
-
-  _ok = true;
+        _checkState = bad;
+        return;
+      }
+    }
+  }
 }
 
@@ -1107,7 +1129,6 @@
   const int nLines = 4;
 
-  _ok = false;
-
   if (lines.size() != nLines) {
+    _checkState = bad;
     return;
   }
@@ -1155,4 +1176,5 @@
            readDbl(line, pos[2], fieldLen, _agf1 ) ||
            readDbl(line, pos[3], fieldLen, _TOW  ) ) {
+        _checkState = bad;
         return;
       }
@@ -1164,4 +1186,5 @@
            readDbl(line, pos[2], fieldLen, _x_acceleration) ||
            readDbl(line, pos[3], fieldLen, _health        ) ) {
+        _checkState = bad;
         return;
       }
@@ -1173,4 +1196,5 @@
            readDbl(line, pos[2], fieldLen, _y_acceleration  ) ||
            readDbl(line, pos[3], fieldLen, _ura             ) ) {
+        _checkState = bad;
         return;
       }
@@ -1182,4 +1206,5 @@
            readDbl(line, pos[2], fieldLen, _z_acceleration)  ||
            readDbl(line, pos[3], fieldLen, _IODN          ) ) {
+        _checkState = bad;
         return;
       }
@@ -1196,6 +1221,4 @@
   _y_acceleration *= 1.e3; 
   _z_acceleration *= 1.e3; 
-
-  _ok = true;
 }
 
@@ -1227,5 +1250,4 @@
   _ura            = ee->URA;
 
-  _ok     = true;
   _health = 0;
 }
@@ -1234,4 +1256,8 @@
 ////////////////////////////////////////////////////////////////////////////
 t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
+
+  if (_checkState == bad) {
+    return failure;
+  }
 
   bncTime tt(GPSweek, GPSweeks);
@@ -1293,7 +1319,6 @@
   const int nLines = 8;
 
-  _ok = false;
-
   if (lines.size() != nLines) {
+    _checkState = bad;
     return;
   }
@@ -1345,4 +1370,5 @@
            readDbl(line, pos[2], fieldLen, _clock_drift    ) ||
            readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
+        _checkState = bad;
         return;
       }
@@ -1355,4 +1381,5 @@
            readDbl(line, pos[2], fieldLen, _Delta_n) ||
            readDbl(line, pos[3], fieldLen, _M0     ) ) {
+        _checkState = bad;
         return;
       }
@@ -1365,4 +1392,5 @@
            readDbl(line, pos[2], fieldLen, _Cus   ) ||
            readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
+        _checkState = bad;
         return;
       }
@@ -1374,4 +1402,5 @@
            readDbl(line, pos[2], fieldLen, _OMEGA0)  ||
            readDbl(line, pos[3], fieldLen, _Cis   ) ) {
+        _checkState = bad;
         return;
       }
@@ -1383,4 +1412,5 @@
            readDbl(line, pos[2], fieldLen, _omega   ) ||
            readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
+        _checkState = bad;
         return;
       }
@@ -1390,4 +1420,5 @@
       if ( readDbl(line, pos[0], fieldLen, _IDOT    ) ||
            readDbl(line, pos[2], fieldLen, TOEw)    ) {
+        _checkState = bad;
         return;
       }
@@ -1399,4 +1430,5 @@
            readDbl(line, pos[2], fieldLen, _TGD1) ||
            readDbl(line, pos[3], fieldLen, _TGD2) ) {
+        _checkState = bad;
         return;
       }
@@ -1408,4 +1440,5 @@
       if ( readDbl(line, pos[0], fieldLen, TOTs) ||
            readDbl(line, pos[1], fieldLen, aodc) ) {
+        _checkState = bad;
         return;
       }
@@ -1428,6 +1461,4 @@
   //         but it seems to be unreliable in RINEX files
   _TOT = _TOC;
-
-  _ok = true;
 }
 
@@ -1435,4 +1466,8 @@
 //////////////////////////////////////////////////////////////////////////////
 t_irc t_ephCompass::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
+
+  if (_checkState == bad) {
+    return failure;
+  }
 
   static const double gmCompass    = 398.6004418e12;
