Commit 0eca9b5f authored by Amy Squillacote's avatar Amy Squillacote
Browse files

adding checks for running out of disk space

parent d5440e58
......@@ -30,6 +30,7 @@ static const char *vtkErrorCodeErrorStrings[] = {
"PrematureEndOfFileError",
"FileFormatError",
"NoFileNameError",
"OutOfDiskSpaceError",
"UnknownError",
"UserError",
NULL
......
......@@ -44,6 +44,7 @@ public:
PrematureEndOfFileError,
FileFormatError,
NoFileNameError,
OutOfDiskSpaceError,
UnknownError,
UserError = 1000
};
......
......@@ -20,8 +20,9 @@
#include "vtkObjectFactory.h"
#include "vtkOldStyleCallbackCommand.h"
#include "vtkDataObject.h"
#include "vtkErrorCode.h"
vtkCxxRevisionMacro(vtkProcessObject, "1.31");
vtkCxxRevisionMacro(vtkProcessObject, "1.32");
// Instantiate object with no start, end, or progress methods.
vtkProcessObject::vtkProcessObject()
......@@ -37,6 +38,7 @@ vtkProcessObject::vtkProcessObject()
this->Inputs = NULL;
this->SortedInputs = NULL;
this->SortedInputs2 = NULL;
this->ErrorCode = 0;
}
// Destructor for the vtkProcessObject class
......@@ -496,5 +498,5 @@ void vtkProcessObject::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Progress Text: (None)\n";
}
os << indent << "ErrorCode: " << vtkErrorCode::GetStringFromErrorCode(this->ErrorCode) << endl;
}
......@@ -126,6 +126,11 @@ public:
// Remove all the input data.
void RemoveAllInputs();
// Description:
// The error code contains a possible error that occured while
// reading or writing the file.
vtkGetMacro( ErrorCode, unsigned long );
protected:
vtkProcessObject();
~vtkProcessObject();
......@@ -160,6 +165,12 @@ protected:
virtual void AddInput(vtkDataObject *input);
virtual void RemoveInput(vtkDataObject *input);
// Description:
// The error code contains a possible error that occured while
// reading or writing the file.
vtkSetMacro( ErrorCode, unsigned long );
unsigned long ErrorCode;
private:
vtkProcessObject(const vtkProcessObject&); // Not implemented.
void operator=(const vtkProcessObject&); // Not implemented.
......
......@@ -23,7 +23,7 @@
#include "vtkFieldData.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkSource, "1.103");
vtkCxxRevisionMacro(vtkSource, "1.104");
#ifndef NULL
#define NULL 0
......@@ -35,7 +35,6 @@ vtkSource::vtkSource()
this->NumberOfOutputs = 0;
this->Outputs = NULL;
this->Updating = 0;
this->ErrorCode = 0;
}
//----------------------------------------------------------------------------
......@@ -721,8 +720,6 @@ void vtkSource::PrintSelf(ostream& os, vtkIndent indent)
{
os << indent <<"No Outputs\n";
}
os << indent << "ErrorCode: " << vtkErrorCode::GetStringFromErrorCode(this->ErrorCode) << endl;
}
int vtkSource::InRegisterLoop(vtkObject *o)
......
......@@ -48,7 +48,6 @@
#include "vtkProcessObject.h"
class vtkDataObject;
class vtkErrorCode;
class VTK_COMMON_EXPORT vtkSource : public vtkProcessObject
{
......@@ -119,12 +118,6 @@ public:
// does not match any of the outputs
int GetOutputIndex(vtkDataObject *out);
// Description:
// The reader should set this code at the end of the update.
// The error code contains a possible error that occured while
// reading the file.
vtkGetMacro( ErrorCode, unsigned long );
protected:
vtkSource();
~vtkSource();
......@@ -166,16 +159,9 @@ protected:
// Time when ExecuteInformation was last called.
vtkTimeStamp InformationTime;
// Description:
// The reader should set this code at the end of the update.
// The error code contains a possible error that occured while
// reading the file.
vtkSetMacro( ErrorCode, unsigned long );
private:
vtkSource(const vtkSource&); // Not implemented.
void operator=(const vtkSource&); // Not implemented.
unsigned long ErrorCode;
};
#endif
......
......@@ -18,11 +18,12 @@
#include "vtkBYUWriter.h"
#include "vtkCellArray.h"
#include "vtkErrorCode.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
vtkCxxRevisionMacro(vtkBYUWriter, "1.46");
vtkCxxRevisionMacro(vtkBYUWriter, "1.47");
vtkStandardNewMacro(vtkBYUWriter);
// Create object so that it writes displacement, scalar, and texture files
......@@ -86,11 +87,50 @@ void vtkBYUWriter::WriteData()
else
{
this->WriteGeometryFile(geomFp,numPts);
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
fclose(geomFp);
unlink(this->GeometryFileName);
return;
}
}
this->WriteDisplacementFile(numPts);
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
fclose(geomFp);
unlink(this->GeometryFileName);
unlink(this->DisplacementFileName);
return;
}
this->WriteScalarFile(numPts);
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
fclose(geomFp);
unlink(this->GeometryFileName);
if (this->DisplacementFileName)
{
unlink(this->DisplacementFileName);
}
unlink(this->ScalarFileName);
return;
}
this->WriteTextureFile(numPts);
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
fclose(geomFp);
unlink(this->GeometryFileName);
if (this->DisplacementFileName)
{
unlink(this->DisplacementFileName);
}
if (this->ScalarFileName)
{
unlink(this->ScalarFileName);
}
unlink(this->TextureFileName);
return;
}
// Close the file
fclose (geomFp);
......@@ -124,8 +164,17 @@ void vtkBYUWriter::WriteGeometryFile(FILE *geomFile, int numPts)
numEdges += npts;
}
fprintf (geomFile, "%d %d %d %d\n", 1, numPts, numPolys, numEdges);
fprintf (geomFile, "%d %d\n", 1, numPolys);
if (fprintf (geomFile, "%d %d %d %d\n", 1, numPts, numPolys, numEdges) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
if (fprintf (geomFile, "%d %d\n", 1, numPolys) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
//
// Write data
//
......@@ -133,15 +182,27 @@ void vtkBYUWriter::WriteGeometryFile(FILE *geomFile, int numPts)
for (i=0; i < numPts; i++)
{
x = inPts->GetPoint(i);
fprintf(geomFile, "%e %e %e ", x[0], x[1], x[2]);
if (fprintf(geomFile, "%e %e %e ", x[0], x[1], x[2]) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
if ( (i % 2) )
{
fprintf(geomFile, "\n");
if (fprintf(geomFile, "\n") < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
}
}
if ( (numPts % 2) )
{
fprintf(geomFile, "\n");
if (fprintf(geomFile, "\n") < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
}
// write poly data. Remember 1-offset.
......@@ -151,9 +212,17 @@ void vtkBYUWriter::WriteGeometryFile(FILE *geomFile, int numPts)
// treating vtkIdType as int
for (i=0; i < (npts-1); i++)
{
fprintf (geomFile, "%d ", (int)(pts[i]+1));
if (fprintf (geomFile, "%d ", (int)(pts[i]+1)) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
}
if (fprintf (geomFile, "%d\n", (int)(-(pts[npts-1]+1))) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
fprintf (geomFile, "%d\n", (int)(-(pts[npts-1]+1)));
}
vtkDebugMacro(<<"Wrote " << numPts << " points, " << numPolys << " polygons");
......@@ -186,10 +255,20 @@ void vtkBYUWriter::WriteDisplacementFile(int numPts)
for (i=0; i < numPts; i++)
{
v = inVectors->GetTuple(i);
fprintf(dispFp, "%e %e %e", v[0], v[1], v[2]);
if (fprintf(dispFp, "%e %e %e", v[0], v[1], v[2]) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
fclose(dispFp);
return;
}
if ( (i % 2) )
{
fprintf (dispFp, "\n");
if (fprintf (dispFp, "\n") < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
fclose(dispFp);
return;
}
}
}
......@@ -224,10 +303,20 @@ void vtkBYUWriter::WriteScalarFile(int numPts)
for (i=0; i < numPts; i++)
{
s = inScalars->GetComponent(i,0);
fprintf(scalarFp, "%e ", s);
if (fprintf(scalarFp, "%e ", s) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
fclose(scalarFp);
return;
}
if ( i != 0 && !(i % 6) )
{
fprintf (scalarFp, "\n");
if (fprintf (scalarFp, "\n") < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
fclose(scalarFp);
return;
}
}
}
......@@ -263,10 +352,20 @@ void vtkBYUWriter::WriteTextureFile(int numPts)
{
if ( i != 0 && !(i % 3) )
{
fprintf (textureFp, "\n");
if (fprintf (textureFp, "\n") < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
fclose(textureFp);
return;
}
}
t = inTCoords->GetTuple(i);
fprintf(textureFp, "%e %e", t[0], t[1]);
if (fprintf(textureFp, "%e %e", t[0], t[1]) < 0)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
fclose(textureFp);
return;
}
}
fclose (textureFp);
......
......@@ -17,6 +17,7 @@
=========================================================================*/
#include "vtkDataSet.h"
#include "vtkDataSetWriter.h"
#include "vtkErrorCode.h"
#include "vtkObjectFactory.h"
#include "vtkPolyDataWriter.h"
#include "vtkRectilinearGridWriter.h"
......@@ -24,7 +25,7 @@
#include "vtkStructuredPointsWriter.h"
#include "vtkUnstructuredGridWriter.h"
vtkCxxRevisionMacro(vtkDataSetWriter, "1.34");
vtkCxxRevisionMacro(vtkDataSetWriter, "1.35");
vtkStandardNewMacro(vtkDataSetWriter);
//----------------------------------------------------------------------------
......@@ -109,6 +110,10 @@ void vtkDataSetWriter::WriteData()
writer->SetDebug(this->Debug);
writer->SetWriteToOutputString(this->WriteToOutputString);
writer->Write();
if (writer->GetErrorCode() == vtkErrorCode::OutOfDiskSpaceError)
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
}
if (this->WriteToOutputString)
{
if (this->OutputString)
......
......@@ -24,6 +24,7 @@
#include "vtkCharArray.h"
#include "vtkDataSet.h"
#include "vtkDoubleArray.h"
#include "vtkErrorCode.h"
#include "vtkFieldData.h"
#include "vtkFloatArray.h"
#include "vtkIntArray.h"
......@@ -38,7 +39,7 @@
#include "vtkUnsignedLongArray.h"
#include "vtkUnsignedShortArray.h"
vtkCxxRevisionMacro(vtkDataWriter, "1.99");
vtkCxxRevisionMacro(vtkDataWriter, "1.100");
vtkStandardNewMacro(vtkDataWriter);
// this undef is required on the hp. vtkMutexLock ends up including
......@@ -206,6 +207,13 @@ int vtkDataWriter::WriteHeader(ostream *fp)
*fp << "BINARY\n";
}
fp->flush();
if (fp->fail())
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return 0;
}
return 1;
}
......@@ -596,6 +604,12 @@ int vtkDataWriter::WriteArray(ostream *fp, int dataType, vtkDataArray *data,
}
}
fp->flush();
if (fp->fail())
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return 0;
}
return 1;
}
......@@ -751,6 +765,13 @@ int vtkDataWriter::WriteScalarData(ostream *fp, vtkDataArray *scalars, int num)
*fp << "\n";
}
fp->flush();
if (fp->fail())
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return 0;
}
return 1;
}
......@@ -967,6 +988,11 @@ int vtkDataWriter::WriteFieldData(ostream *fp, vtkFieldData *f)
}
}
}
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
return 0;
}
return 1;
}
......@@ -1019,6 +1045,14 @@ int vtkDataWriter::WriteCells(ostream *fp, vtkCellArray *cells, const char *labe
}
*fp << "\n";
fp->flush();
if (fp->fail())
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return 0;
}
return 1;
}
......
......@@ -17,11 +17,12 @@
=========================================================================*/
#include "vtkImageWriter.h"
#include "vtkErrorCode.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
vtkCxxRevisionMacro(vtkImageWriter, "1.45");
vtkCxxRevisionMacro(vtkImageWriter, "1.46");
vtkStandardNewMacro(vtkImageWriter);
#ifdef write
......@@ -47,6 +48,9 @@ vtkImageWriter::vtkImageWriter()
strcpy(this->FilePattern, "%s.%d");
this->FileLowerLeft = 0;
this->MinimumFileNumber = this->MaximumFileNumber = 0;
this->FilesDeleted = 0;
}
......@@ -216,8 +220,14 @@ void vtkImageWriter::Write()
this->GetInput()->UpdateInformation();
this->GetInput()->SetUpdateExtent(this->GetInput()->GetWholeExtent());
this->FileNumber = this->GetInput()->GetWholeExtent()[4];
this->MinimumFileNumber = this->MaximumFileNumber = this->FileNumber;
this->FilesDeleted = 0;
this->UpdateProgress(0.0);
this->RecursiveWrite(2, this->GetInput(), NULL);
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
this->DeleteFiles();
}
delete [] this->InternalFileName;
this->InternalFileName = NULL;
}
......@@ -250,6 +260,14 @@ void vtkImageWriter::RecursiveWrite(int axis, vtkImageData *cache,
{
sprintf(this->InternalFileName, this->FilePattern,this->FileNumber);
}
if (this->FileNumber < this->MinimumFileNumber)
{
this->MinimumFileNumber = this->FileNumber;
}
else if (this->FileNumber > this->MaximumFileNumber)
{
this->MaximumFileNumber = this->FileNumber;
}
}
// Open the file
#ifdef _WIN32
......@@ -268,6 +286,14 @@ void vtkImageWriter::RecursiveWrite(int axis, vtkImageData *cache,
// Subclasses can write a header with this method call.
this->WriteFileHeader(file, cache);
file->flush();
if (file->fail())
{
file->close();
delete file;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
++this->FileNumber;
}
......@@ -282,9 +308,18 @@ void vtkImageWriter::RecursiveWrite(int axis, vtkImageData *cache,
cache->Update();
data = cache;
this->RecursiveWrite(axis,cache,data,file);
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
this->DeleteFiles();
}
if (file && fileOpenedHere)
{
this->WriteFileTrailer(file,cache);
file->flush();
if (file->fail())
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
}
file->close();
delete file;
file = NULL;
......@@ -304,6 +339,13 @@ void vtkImageWriter::RecursiveWrite(int axis, vtkImageData *cache,
if (file)
{
this->WriteFile(file,data,cache->GetUpdateExtent());
file->flush();
if (file->fail())
{
file->close();
delete file;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
}
return;
}
......@@ -326,6 +368,14 @@ void vtkImageWriter::RecursiveWrite(int axis, vtkImageData *cache,
{
sprintf(this->InternalFileName, this->FilePattern,this->FileNumber);
}
if (this->FileNumber < this->MinimumFileNumber)
{
this->MinimumFileNumber = this->FileNumber;
}
else if (this->FileNumber > this->MaximumFileNumber)
{
this->MaximumFileNumber = this->FileNumber;
}
}
// Open the file
#ifdef _WIN32
......@@ -343,9 +393,30 @@ void vtkImageWriter::RecursiveWrite(int axis, vtkImageData *cache,
// Subclasses can write a header with this method call.
this->WriteFileHeader(file, cache);
file->flush();
if (file->fail())
{
file->close();
delete file;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
this->WriteFile(file,data,cache->GetUpdateExtent());
file->flush();
if (file->fail())
{
file->close();
delete file;
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
return;
}
++this->FileNumber;
this->WriteFileTrailer(file,cache);
file->flush();
if (file->fail())
{
this->SetErrorCode(vtkErrorCode::OutOfDiskSpaceError);
}
file->close();
delete file;
return;
......@@ -361,7 +432,14 @@ void vtkImageWriter::RecursiveWrite(int axis, vtkImageData *cache,
for(idx = max; idx >= min; idx--)
{
cache->SetAxisUpdateExtent(axis, idx, idx);
this->RecursiveWrite(axis - 1, cache, data, file);
if (this->ErrorCode != vtkErrorCode::OutOfDiskSpaceError)
{
this->RecursiveWrite(axis - 1, cache, data, file);
}
else
{
this->DeleteFiles();
}
}
}
else
......@@ -369,7 +447,14 @@ void vtkImageWriter::RecursiveWrite(int axis, vtkImageData *cache,
for(idx = min; idx <= max; idx++)
{
cache->SetAxisUpdateExtent(axis, idx, idx);
this->RecursiveWrite(axis - 1, cache, data, file);
if (this->ErrorCode != vtkErrorCode::OutOfDiskSpaceError)
{
this->RecursiveWrite(axis - 1, cache, data, file);
}
else
{
this->DeleteFiles();
}
}
}
......@@ -477,9 +562,53 @@ void vtkImageWriter::WriteFile(ofstream *file, vtkImageData *data,
vtkErrorMacro("WriteFile: write failed");
file->close();
delete file;
this->DeleteFiles();
return;
}
}
}
}
void vtkImageWriter::DeleteFiles()