diff --git a/src/output/dump.cpp b/src/output/dump.cpp index 5a27ecc2..73b0df99 100644 --- a/src/output/dump.cpp +++ b/src/output/dump.cpp @@ -248,7 +248,9 @@ void Dump::WriteString(IdfxFileHandler fileHdl, char *str, int size) { } offset=offset+size; #else - fwrite (str, sizeof(char), size, fileHdl); + if(fwrite (str, sizeof(char), size, fileHdl) != size) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } #endif } @@ -312,15 +314,23 @@ void Dump::WriteSerial(IdfxFileHandler fileHdl, int ndim, int *dim, #else // Write type of data - fwrite(&type, 1, sizeof(int), fileHdl); + if(fwrite(&type, sizeof(int), 1, fileHdl) != 1) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } // Write dimensions of array - fwrite(&ndim, 1, sizeof(int), fileHdl); + if(fwrite(&ndim, sizeof(int), 1, fileHdl) != 1) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } for(int n = 0 ; n < ndim ; n++) { - fwrite(dim+n, 1, sizeof(int), fileHdl); + if(fwrite(dim+n, sizeof(int), 1, fileHdl) != 1) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } ntot = ntot * dim[n]; } // Write raw data - fwrite(data, ntot, size, fileHdl); + if(fwrite(data, size, ntot, fileHdl) != ntot) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } #endif } @@ -384,18 +394,26 @@ void Dump::WriteDistributed(IdfxFileHandler fileHdl, int ndim, int *dim, int *gd #else // Write type of data - fwrite(&type, 1, sizeof(int), fileHdl); + if(fwrite(&type, sizeof(int), 1, fileHdl) != 1) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } // Write dimensions of array // (in serial, dim and gdim are identical, so no need to differentiate) - fwrite(&ndim, 1, sizeof(int), fileHdl); + if(fwrite(&ndim, sizeof(int), 1, fileHdl) != 1) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } for(int n = 0 ; n < ndim ; n++) { - fwrite(dim+n, 1, sizeof(int), fileHdl); + if(fwrite(dim+n, sizeof(int), 1, fileHdl) != 1) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } ntot = ntot * dim[n]; } // Write raw data - fwrite(data, ntot, sizeof(real), fileHdl); + if(fwrite(data, sizeof(real), ntot, fileHdl) != ntot) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } #endif } @@ -836,6 +854,12 @@ int Dump::Write(Output& output) { this->offset = 0; #else fileHdl = fopen(filename.c_str(),"wb"); + if(fileHdl == NULL) { + std::stringstream msg; + msg << "Unable to open file " << filename << std::endl; + msg << "Check that you have write access and that you don't exceed your quota." << std::endl; + IDEFIX_ERROR(msg); + } #endif // File is open // First thing we need are coordinates: init a host mirror and sync it diff --git a/src/output/vtk.cpp b/src/output/vtk.cpp index 13b47d30..0f52f37c 100644 --- a/src/output/vtk.cpp +++ b/src/output/vtk.cpp @@ -53,7 +53,9 @@ void Vtk::WriteHeaderNodes(IdfxFileHandler fvtk) { MPI_FLOAT, MPI_STATUS_IGNORE)); this->offset += sizeof(float)*(nx1+ioffset)*(nx2+joffset)*(nx3+koffset)*3; #else - fwrite(node_coord.data(),sizeof(float),size,fvtk); + if(fwrite(node_coord.data(),sizeof(float),size,fvtk) != size) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } #endif } @@ -290,6 +292,13 @@ int Vtk::Write() { this->offset = 0; #else fileHdl = fopen(filename.c_str(),"wb"); + + if(fileHdl == NULL) { + std::stringstream msg; + msg << "Unable to open file " << filename << std::endl; + msg << "Check that you have write access and that you don't exceed your quota." << std::endl; + IDEFIX_ERROR(msg); + } #endif WriteHeader(fileHdl, this->data->t); @@ -502,6 +511,8 @@ void Vtk::WriteScalar(IdfxFileHandler fvtk, float* Vin, const std::string &var_ this->offset = this->offset + sizeof(float)*nx1*nx2*nx3; #else - fwrite(Vin,sizeof(float),nx1loc*nx2loc*nx3loc,fvtk); + if(fwrite(Vin,sizeof(float),nx1loc*nx2loc*nx3loc,fvtk) != nx1loc*nx2loc*nx3loc) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } #endif } diff --git a/src/output/vtk.hpp b/src/output/vtk.hpp index c33e0d05..dcda3618 100644 --- a/src/output/vtk.hpp +++ b/src/output/vtk.hpp @@ -75,7 +75,10 @@ class BaseVtk { } offset=offset+strlen(header); #else - fprintf (fvtk, "%s", header); + int rc = fprintf (fvtk, "%s", header); + if(rc<0) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } #endif } @@ -90,7 +93,9 @@ class BaseVtk { } offset=offset+nelem*sizeof(T); #else - fwrite(buffer, sizeof(T), nelem, fvtk); + if(fwrite(buffer, sizeof(T), nelem, fvtk) != nelem) { + IDEFIX_ERROR("Unable to write to file. Check your filesystem permissions and disk quota."); + } #endif } };