Commit 449d1cef authored by Dave DeMarle's avatar Dave DeMarle
Browse files

Merge branch 'RInterface-fread-warning-rel' into release

Change-Id: I6e8656a2322fd64d4d66a232aa8b11c2e6864762
parents 82dc57c3 51fb84f0
......@@ -194,15 +194,16 @@ SEXP vtkRAdapter::VTKDataArrayToR(vtkDataArray* da)
vtkArray* vtkRAdapter::RToVTKArray(SEXP variable)
{
int i;
int ndim;
vtkArray::SizeT i;
vtkArray::DimensionT j;
vtkArray::DimensionT ndim;
SEXP dims;
vtkArrayExtents extents;
vtkTypedArray<double>* da;
da = vtkTypedArray<double>::SafeDownCast(vtkArray::CreateArray(vtkArray::DENSE, VTK_DOUBLE));
dims = getAttrib(variable, R_DimSymbol);
ndim = length(dims);
dims = getAttrib(variable, R_DimSymbol);
ndim = static_cast<vtkArray::DimensionT>(length(dims));
if (!isMatrix(variable)&&!isArray(variable)&&isVector(variable))
{
......@@ -213,9 +214,9 @@ vtkArray* vtkRAdapter::RToVTKArray(SEXP variable)
if (isMatrix(variable)||isArray(variable))
{
for(i=0;i< ndim;i++)
for(j=0;j<ndim;j++)
{
extents[i] = vtkArrayRange(0,INTEGER(dims)[i]);
extents[j] = vtkArrayRange(0,INTEGER(dims)[j]);
}
}
else
......@@ -257,15 +258,16 @@ SEXP vtkRAdapter::VTKArrayToR(vtkArray* da)
SEXP a;
SEXP dim;
int i;
vtkArray::SizeT i;
vtkArray::DimensionT j;
vtkArrayCoordinates coords;
PROTECT(dim = Rf_allocVector(INTSXP, da->GetDimensions()));
assert(da->GetExtents().ZeroBased());
for(i=0;i<da->GetDimensions();i++)
for(j=0;j<da->GetDimensions();j++)
{
INTEGER(dim)[i] = da->GetExtents()[i].GetSize();
INTEGER(dim)[j] = da->GetExtents()[j].GetSize();
}
PROTECT(a = Rf_allocArray(REALSXP, dim));
......
/*=========================================================================
Program: Visualization Toolkit
......@@ -823,6 +822,7 @@ int vtkRCalculatorFilter::SetRscriptFromFile(const char* fname)
FILE *fp;
long len;
long rlen;
if(fname && (strlen(fname) > 0) )
{
......@@ -845,10 +845,18 @@ int vtkRCalculatorFilter::SetRscriptFromFile(const char* fname)
}
this->RfileScript = new char[len+1];
fread(this->RfileScript,len,1,fp);
rlen = static_cast<long>(fread(this->RfileScript,1,len,fp));
this->RfileScript[len] = '\0';
fclose(fp);
if (rlen != len)
{
delete [] this->RfileScript;
this->RfileScript = 0;
vtkErrorMacro(<<"Error reading R script");
return(0);
}
this->Modified();
return(1);
......
......@@ -77,7 +77,6 @@ public:
newPath=newPath+VTK_R_HOME;
vtksys::SystemTools::PutEnv(newPath.c_str());
}
const char* path2 = vtksys::SystemTools::GetEnv("R_HOME");
const char *R_argv[]= {"vtkRInterface", "--gui=none", "--no-save", "--no-readline", "--silent"};
Rf_initialize_R(sizeof(R_argv)/sizeof(R_argv[0]), const_cast<char **>(R_argv));
......@@ -376,6 +375,8 @@ int vtkRInterface::FillOutputBuffer()
FILE *fp;
long len;
long rlen;
long tlen;
if(this->buffer && (this->buffer_size > 0) )
{
......@@ -394,22 +395,19 @@ int vtkRInterface::FillOutputBuffer()
{
return(1);
}
if(len >= this->buffer_size)
{
fseek(fp,len-this->buffer_size+1,SEEK_SET);
fread(this->buffer,1,this->buffer_size-1,fp);
this->buffer[this->buffer_size-1] = '\0';
}
else
tlen = ((len >= this->buffer_size) ? this->buffer_size-1 : len);
fseek(fp,len-tlen,SEEK_SET);
rlen = static_cast<long>(fread(this->buffer,1,tlen,fp));
this->buffer[tlen] = '\0';
fclose(fp);
if (rlen != tlen)
{
fseek(fp,0,SEEK_SET);
fread(this->buffer,1,len,fp);
this->buffer[len] = '\0';
vtkErrorMacro(<<"Error while reading file " << this->rs->GetROutputFilePath());
return(0);
}
fclose(fp);
return(1);
......
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