diff --git a/CEP/DP3/DPPP/src/FlagCounter.cc b/CEP/DP3/DPPP/src/FlagCounter.cc index edd1e3661870b965025b5e31290a1acc231fcaa7..5b96edf8ee677fa42ce10854e6a305969d45b2ca 100644 --- a/CEP/DP3/DPPP/src/FlagCounter.cc +++ b/CEP/DP3/DPPP/src/FlagCounter.cc @@ -265,6 +265,10 @@ namespace LOFAR { os << endl; } int64 totalnpoints = npoints * itsChanCounts.size(); + // Prevent division by zero + if (totalnpoints == 0) { + totalnpoints = 1; + } os << "Total flagged: "; showPerc3 (os, nflagged, totalnpoints); os << " (" << nflagged << " out of " << totalnpoints @@ -287,6 +291,10 @@ namespace LOFAR { void FlagCounter::showCorrelation (ostream& os, int64 ntimes) const { int64 ntotal = ntimes * itsBLCounts.size() * itsChanCounts.size(); + // Prevent division by zero + if (ntotal == 0) { + ntotal = 1; + } os << endl << "Percentage of flagged visibilities detected per correlation:" << endl; diff --git a/CEP/DP3/DPPP/src/MSReader.cc b/CEP/DP3/DPPP/src/MSReader.cc index 35dd696864e6e0fe5161ea7bc3c79ac7dd9a81be..1b6f205db5ee85197fb6b5372d4edfebb10c31a3 100644 --- a/CEP/DP3/DPPP/src/MSReader.cc +++ b/CEP/DP3/DPPP/src/MSReader.cc @@ -131,7 +131,7 @@ namespace LOFAR { } } // Prepare the MS access and get time info. - double startTime, endTime; + double startTime=0., endTime=0.; prepare (startTime, endTime, itsTimeInterval); // Start and end time can be given in the parset in case leading // or trailing time slots are missing. @@ -258,8 +258,9 @@ namespace LOFAR { itsLastMSTime = mstime; itsIter.next(); } - // Stop if at the end. - if (itsNextTime > itsLastTime && !near(itsNextTime, itsLastTime)) { + // Stop if at the end, or if there is no data at all + if ((itsNextTime > itsLastTime && !near(itsNextTime, itsLastTime)) || + itsNextTime==0.) { return false; } // Fill the buffer. @@ -390,7 +391,7 @@ namespace LOFAR { os << " ncorrelations: " << getInfo().ncorr() << std::endl; uint nrbl = getInfo().nbaselines(); os << " nbaselines: " << nrbl << std::endl; - os << " ntimes: " << itsSelMS.nrow() / nrbl << std::endl; + os << " ntimes: " << (nrbl==0 ? 0 : itsSelMS.nrow() / nrbl) << std::endl; os << " time interval: " << getInfo().timeInterval() << std::endl; os << " DATA column: " << itsDataColName; if (itsMissingData) { @@ -421,7 +422,9 @@ namespace LOFAR { void MSReader::prepare (double& firstTime, double& lastTime, double& interval) { - ASSERT (itsSelMS.nrow() > 0); + if (itsSelMS.nrow() == 0) { + DPLOG_WARN_STR ("The selected input does not contain any data."); + } TableDesc tdesc = itsMS.tableDesc(); itsHasWeightSpectrum = false; @@ -495,9 +498,11 @@ namespace LOFAR { sortms = itsSelMS.sort(sortCols); } // Get first and last time and interval from MS. - firstTime = ROScalarColumn<double>(sortms, "TIME")(0); - lastTime = ROScalarColumn<double>(sortms, "TIME")(sortms.nrow()-1); - interval = ROScalarColumn<double>(sortms, "INTERVAL")(0); + if (itsSelMS.nrow() > 0) { + firstTime = ROScalarColumn<double>(sortms, "TIME")(0); + lastTime = ROScalarColumn<double>(sortms, "TIME")(sortms.nrow()-1); + interval = ROScalarColumn<double>(sortms, "INTERVAL")(0); + } // Create iterator over time. Do not sort again. itsIter = TableIterator (sortms, Block<String>(1, "TIME"), TableIterator::Ascending, diff --git a/CEP/DP3/DPPP/src/MSWriter.cc b/CEP/DP3/DPPP/src/MSWriter.cc index eb2884247f13169e8a2ce946e6068198ddcc43c3..a4cf6ee2fb1ac2782979350f521b1bb84ad711bb 100644 --- a/CEP/DP3/DPPP/src/MSWriter.cc +++ b/CEP/DP3/DPPP/src/MSWriter.cc @@ -508,6 +508,11 @@ namespace LOFAR { ArrayColumn<Complex> dataCol(out, itsDataColName); ArrayColumn<Bool> flagCol(out, "FLAG"); ScalarColumn<Bool> flagRowCol(out, "FLAG_ROW"); + + if (buf.getData().empty()) { + return; + } + dataCol.putColumn (buf.getData()); flagCol.putColumn (buf.getFlags()); // A row is flagged if no flags in the row are False.