Skip to content

Commit

Permalink
IO/VTK: add a function to create the handler for a collection
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-iob committed Nov 21, 2023
1 parent b58b195 commit d8c4312
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
15 changes: 15 additions & 0 deletions src/IO/VTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,21 @@ void VTK::writeCollection( const std::string &outputName ) const {
writeCollection(outputName, outputName) ;
}

/*!
* Creates a handler for the collection.
*
* \param collectionName collection filename to be set for this output only
*/
FileHandler VTK::createCollectionHandler( const std::string &collectionName ) const {
FileHandler handler(m_fh) ;
handler.setSeries(false) ;
handler.setParallel(false) ;
handler.setName(collectionName) ;
handler.setAppendix(getCollectionExtension()) ;

return handler;
}

/*!
* Writes data only in VTK file
*/
Expand Down
2 changes: 2 additions & 0 deletions src/IO/VTK.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ class VTK{
void writeDataArray( std::fstream &, const VTKField &) const ;
void writePDataArray( std::fstream &, const VTKField &) const ;

FileHandler createCollectionHandler( const std::string &collectionName) const ;

//For Reading
void readDataHeader( std::fstream &) ;
bool readDataArray( std::fstream &, VTKField &) const ;
Expand Down
12 changes: 4 additions & 8 deletions src/IO/VTKRectilinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,11 @@ void VTKRectilinearGrid::writeCollection( const std::string &outputName, const s
return;
}

// Initialize file handler
std::fstream str ;

FileHandler fhp(m_fh) ;
fhp.setSeries(false) ;
fhp.setParallel(false) ;
fhp.setName(collectionName) ;
fhp.setAppendix(getCollectionExtension()) ;
// Create file handler
FileHandler fhp = createCollectionHandler(collectionName) ;

// Initialize outout stream
std::fstream str ;
str.open( fhp.getPath( ), std::ios::out ) ;
if (!str.is_open()) {
throw std::runtime_error("Cannot create file \"" + fhp.getName() + "\"" + " inside the directory \"" + fhp.getDirectory() + "\"");
Expand Down
12 changes: 4 additions & 8 deletions src/IO/VTKUnstructured.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,11 @@ void VTKUnstructuredGrid::writeCollection( const std::string &outputName, const
return;
}

// Initialize file handler
std::fstream str ;

FileHandler fhp(m_fh) ;
fhp.setSeries(false) ;
fhp.setParallel(false) ;
fhp.setName(collectionName) ;
fhp.setAppendix(getCollectionExtension()) ;
// Create file handler
FileHandler fhp = createCollectionHandler(collectionName) ;

// Initialize outout stream
std::fstream str ;
str.open( fhp.getPath( ), std::ios::out ) ;
if (!str.is_open()) {
throw std::runtime_error("Cannot create file \"" + fhp.getName() + "\"" + " inside the directory \"" + fhp.getDirectory() + "\"");
Expand Down

0 comments on commit d8c4312

Please sign in to comment.