Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/output/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/output/vtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
9 changes: 7 additions & 2 deletions src/output/vtk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
};
Expand Down