Skip to content

Commit a232ebd

Browse files
authored
Merge pull request #108 from EXP-code/outdirTest
Check for valid output directory for FieldGenerator methods that write files
2 parents 6997a97 + 33179b7 commit a232ebd

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

expui/FieldGenerator.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <filesystem>
12
#include <algorithm>
23
#include <iomanip>
34
#include <sstream>
@@ -259,6 +260,14 @@ namespace Field
259260
const std::string prefix,
260261
const std::string outdir)
261262
{
263+
if (myid==0) {
264+
// Verify existence of directory
265+
bool filepathExists = std::filesystem::is_directory(outdir);
266+
if (not filepathExists)
267+
throw std::runtime_error("FieldGenerator::file_lines: directory <" +
268+
outdir + "> does not exist");
269+
}
270+
262271
auto db = lines(basis, coefs, beg, end, num);
263272

264273
if (myid==0) {
@@ -505,6 +514,14 @@ namespace Field
505514
const std::string prefix,
506515
const std::string outdir)
507516
{
517+
if (myid==0) {
518+
// Verify existence of directory
519+
bool filepathExists = std::filesystem::is_directory(outdir);
520+
if (not filepathExists)
521+
throw std::runtime_error("FieldGenerator::file_slices: directory <" +
522+
outdir + "> does not exist");
523+
}
524+
508525
auto db = slices(basis, coefs);
509526

510527
if (myid==0) {
@@ -710,6 +727,14 @@ namespace Field
710727
const std::string prefix,
711728
const std::string outdir)
712729
{
730+
if (myid==0) {
731+
// Verify existence of directory
732+
bool filepathExists = std::filesystem::is_directory(outdir);
733+
if (not filepathExists)
734+
throw std::runtime_error("FieldGenerator::file_volumes: directory <" +
735+
outdir + "> does not exist");
736+
}
737+
713738
auto db = volumes(basis, coefs);
714739

715740
int bunch = db.size()/numprocs;

exputil/VtkGrid.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ void VtkGrid::Add(const std::vector<double>& data, const std::string& name)
182182
//
183183
int I = 0;
184184

185-
for (int i=0; i<nx; i++) {
185+
for (int k=0; k<nz; k++) {
186186
for (int j=0; j<ny; j++) {
187-
for (int k=0; k<nz; k++) {
187+
for (int i=0; i<nx; i++) {
188188
dataSet[newName][I++] = static_cast<float>(data[(k*ny + j)*nx + i]);
189189
}
190190
}

pyEXP/FieldWrappers.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,7 @@ void FieldGeneratorClasses(py::module &m) {
399399
400400
See also
401401
--------
402-
<<<<<<< HEAD
403-
=======
404402
points : generate fields at an array of mesh points
405-
>>>>>>> pointMesh
406403
slices : generate fields in a surface slice given by the
407404
initializtion grid
408405
volumes : generate fields in volume given by the initializtion grid

0 commit comments

Comments
 (0)