Commit 07869098 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Win64 fixes for vtkMultiBlockPLOT3DReader.

vtkMultiBlockPLOT3DReader now handles reading large files on Win64
machines. We need to use 64-bit API on Windows since sizeof(long) is 4
bytes on Windows.
parent 9c1667f6
......@@ -41,6 +41,16 @@
#include <exception>
#ifdef _WIN64
# define vtk_fseek _fseeki64
# define vtk_ftell _ftelli64
# define vtk_off_t __int64
#else
# define vtk_fseek fseek
# define vtk_ftell ftell
# define vtk_off_t long
#endif
vtkObjectFactoryNewMacro(vtkMultiBlockPLOT3DReader);
vtkCxxSetObjectMacro(vtkMultiBlockPLOT3DReader,
......@@ -65,10 +75,10 @@ public:
{
if (preskip > 0)
{
fseek(fp, preskip*sizeof(DataType), SEEK_CUR);
vtk_fseek(fp, preskip*sizeof(DataType), SEEK_CUR);
}
int retVal = static_cast<int>(fread(scalar, sizeof(DataType), n, fp));
fseek(fp, postskip*sizeof(DataType), SEEK_CUR);
vtk_fseek(fp, postskip*sizeof(DataType), SEEK_CUR);
if (this->ByteOrder == vtkMultiBlockPLOT3DReader::FILE_LITTLE_ENDIAN)
{
if (sizeof(DataType) == 4)
......@@ -514,7 +524,7 @@ int vtkMultiBlockPLOT3DReader::ReadIntScalar(
if (this->Internal->Settings.BinaryFile)
{
if (fseek(fp, offset, SEEK_SET) != 0)
if (vtk_fseek(fp, offset, SEEK_SET) != 0)
{
return 0;
}
......@@ -544,7 +554,7 @@ int vtkMultiBlockPLOT3DReader::ReadScalar(
if (this->Internal->Settings.BinaryFile)
{
if (fseek(fp, offset, SEEK_SET) != 0)
if (vtk_fseek(fp, offset, SEEK_SET) != 0)
{
return 0;
}
......@@ -623,7 +633,7 @@ int vtkMultiBlockPLOT3DReader::ReadVector(
if (this->Internal->Settings.BinaryFile)
{
if (fseek(fp, offset, SEEK_SET) != 0)
if (vtk_fseek(fp, offset, SEEK_SET) != 0)
{
return 0;
}
......@@ -692,31 +702,10 @@ int vtkMultiBlockPLOT3DReader::ReadVector(
// Read a block of floats (ascii or binary) and return number read.
void vtkMultiBlockPLOT3DReader::CalculateFileSize(FILE* fp)
{
long curPos = ftell(fp);
fseek(fp, 0, SEEK_END);
this->FileSize = ftell(fp);
fseek(fp, curPos, SEEK_SET);
}
// Estimate the size of a grid (binary file only)
long vtkMultiBlockPLOT3DReader::EstimateSize(int ni, int nj, int nk)
{
long size; // the header portion, 3 ints
size = this->Internal->Settings.NumberOfDimensions*4;
// x, y, z
size += ni*nj*nk*this->Internal->Settings.NumberOfDimensions*this->Internal->Settings.Precision;
if (this->Internal->Settings.HasByteCount)
{
size += 2*4; // the byte counts
}
if (this->Internal->Settings.IBlanking)
{
size += ni*nj*nk*4;
}
return size;
vtk_off_t curPos = vtk_ftell(fp);
vtk_fseek(fp, 0, SEEK_END);
this->FileSize = static_cast<size_t>(vtk_ftell(fp));
vtk_fseek(fp, curPos, SEEK_SET);
}
int vtkMultiBlockPLOT3DReader::CanReadBinaryFile(const char* fname)
......@@ -1241,7 +1230,7 @@ int vtkMultiBlockPLOT3DReader::RequestData(
if (this->Internal->Settings.BinaryFile)
{
offset = ftell(xyzFp);
offset = vtk_ftell(xyzFp);
fclose(xyzFp);
}
}
......@@ -1527,7 +1516,7 @@ int vtkMultiBlockPLOT3DReader::RequestData(
if (mp->GetLocalProcessId() == 0 &&
this->Internal->Settings.BinaryFile)
{
offset = ftell(qFp);
offset = vtk_ftell(qFp);
}
mp->Broadcast(&offset, 1, 0);
......@@ -1714,7 +1703,7 @@ int vtkMultiBlockPLOT3DReader::RequestData(
if (rank == 0 && this->Internal->Settings.BinaryFile)
{
fseek(qFp, offset, SEEK_SET);
vtk_fseek(qFp, offset, SEEK_SET);
}
if ( this->FunctionList->GetNumberOfTuples() > 0 )
......@@ -1760,7 +1749,7 @@ int vtkMultiBlockPLOT3DReader::RequestData(
fclose(fFp);
return 0;
}
offset = ftell(fFp);
offset = vtk_ftell(fFp);
fclose(fFp);
}
mp->Broadcast(&nFunctions[0], numBlocks, 0);
......
......@@ -288,7 +288,6 @@ protected:
int ReadFunctionHeader(FILE* fp, int* nFunctions);
void CalculateFileSize(FILE* fp);
long EstimateSize(int ni, int nj, int nk);
int AutoDetectionCheck(FILE* fp);
......@@ -337,7 +336,7 @@ protected:
int ExecutedGhostLevels;
long FileSize;
size_t FileSize;
//parameters used in computing derived functions
double R;
......
......@@ -29,7 +29,7 @@ int vtkMultiBlockPLOT3DReaderInternals::ReadInts(FILE* fp, int n, int* val)
return retVal;
}
void vtkMultiBlockPLOT3DReaderInternals::CheckBinaryFile(FILE *fp, long fileSize)
void vtkMultiBlockPLOT3DReaderInternals::CheckBinaryFile(FILE *fp, size_t fileSize)
{
rewind(fp);
this->Settings.BinaryFile = 0;
......@@ -259,7 +259,7 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckBlankingAndPrecision(FILE* fp)
// to check becaues it has no byte count markers. We need
// to do a bit more brute force checks based on reading
// data and estimating file size.
int vtkMultiBlockPLOT3DReaderInternals::CheckCFile(FILE* fp, long fileSize)
int vtkMultiBlockPLOT3DReaderInternals::CheckCFile(FILE* fp, size_t fileSize)
{
int precisions[2] = {4, 8};
int blankings[2] = {0, 1};
......@@ -349,7 +349,7 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckCFile(FILE* fp, long fileSize)
return 0;
}
long vtkMultiBlockPLOT3DReaderInternals::CalculateFileSize(int mgrid,
size_t vtkMultiBlockPLOT3DReaderInternals::CalculateFileSize(int mgrid,
int precision, // in bytes
int blanking,
int ndims,
......@@ -357,7 +357,7 @@ long vtkMultiBlockPLOT3DReaderInternals::CalculateFileSize(int mgrid,
int nGrids,
int* gridDims)
{
long size = 0; // the header portion, 3 ints
size_t size = 0; // the header portion, 3 ints
// N grids
if (mgrid)
......@@ -383,15 +383,15 @@ long vtkMultiBlockPLOT3DReaderInternals::CalculateFileSize(int mgrid,
return size;
}
long vtkMultiBlockPLOT3DReaderInternals::CalculateFileSizeForBlock(int precision, // in bytes
size_t vtkMultiBlockPLOT3DReaderInternals::CalculateFileSizeForBlock(int precision, // in bytes
int blanking,
int ndims,
int hasByteCount,
int* gridDims)
{
long size = 0;
size_t size = 0;
// x, y, (z)
long npts = 1;
size_t npts = 1;
for (int i=0; i<ndims; i++)
{
npts *= gridDims[i];
......
......@@ -68,21 +68,21 @@ struct vtkMultiBlockPLOT3DReaderInternals
}
int ReadInts(FILE* fp, int n, int* val);
void CheckBinaryFile(FILE *fp, long fileSize);
void CheckBinaryFile(FILE *fp, size_t fileSize);
int CheckByteOrder(FILE* fp);
int CheckByteCount(FILE* fp);
int CheckMultiGrid(FILE* fp);
int Check2DGeom(FILE* fp);
int CheckBlankingAndPrecision(FILE* fp);
int CheckCFile(FILE* fp, long fileSize);
long CalculateFileSize(int mgrid,
int CheckCFile(FILE* fp, size_t fileSize);
size_t CalculateFileSize(int mgrid,
int precision, // in bytes
int blanking,
int ndims,
int hasByteCount,
int nGrids,
int* gridDims);
long CalculateFileSizeForBlock(int precision, // in bytes
size_t CalculateFileSizeForBlock(int precision, // in bytes
int blanking,
int ndims,
int hasByteCount,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment