G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsCsv.h
Go to the documentation of this file.
1
15
16#include <fstream>
17
18#pragma once
19
20
21namespace gismo {
22
30template<class T>
31void gsWriteCsv(std::string const & filename, const gsMatrix<T> & matrix, const std::vector<std::string> & headers = std::vector<std::string>() )
32{
33 // Define format of .csv file.
34 const static gsEigen::IOFormat CSVFormat(gsEigen::FullPrecision, gsEigen::Aligned, ", ", "\n");
35
36 std::ofstream csv_file;
37 csv_file.open(filename);
38 GISMO_ASSERT( (headers.empty() || headers.size() == (size_t)matrix.cols()), "The column headers should be as many as the columns of the matrix provided." );
39
40 // If column headers are provided, write to file
41 if (! headers.empty())
42 {
43 for ( size_t j=0 ; j < headers.size() ; j++)
44 {
45 csv_file << headers[j];
46 if (headers.size()-1 == j)
47 csv_file << CSVFormat.rowSeparator;
48 else
49 csv_file << CSVFormat.coeffSeparator ;
50 }
51 }
52 // write matrix entries to file
53 csv_file << matrix.format(CSVFormat);
54 csv_file.close();
55}
56
57
58} // namespace gismo
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
void gsWriteCsv(std::string const &filename, const gsMatrix< T > &matrix, const std::vector< std::string > &headers=std::vector< std::string >())
Export a gsMatrix to a .csv (comma separated values) file.
Definition gsCsv.h:31
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides forward declarations of types and structs.
The G+Smo namespace, containing all definitions for the library.