Line data Source code
1 : /*
2 : * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Torbjörn Klatt
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #include "matrix_io.h"
34 :
35 : namespace ug
36 : {
37 :
38 : // /////////////////////////////////////////////////////////////////////////////
39 : // Constructors / Destructor
40 14 : MatrixIO::MatrixIO() :
41 14 : m_pMatFileName( NULL ), m_matFileStream(), m_matFileType( 0 )
42 : // ,m_rows(0), m_cols(0), m_lines(0)
43 : {
44 14 : }
45 :
46 1 : MatrixIO::MatrixIO( std::string mFile, int openMode ) :
47 1 : m_matFileStream(), m_matFileType( 0 )//, m_rows(0), m_cols(0), m_lines(0)
48 : {
49 1 : set_mat_file_name( mFile, openMode );
50 1 : }
51 :
52 15 : MatrixIO::~MatrixIO()
53 : {
54 15 : close_file();
55 17 : delete m_pMatFileName;
56 15 : }
57 :
58 : // /////////////////////////////////////////////////////////////////////////////
59 : // Public Member Functions
60 2 : void MatrixIO::set_mat_file_name( std::string mFile, int openMode )
61 : {
62 2 : if ( !mFile.empty() ) {
63 2 : if ( openMode == EXISTING ) {
64 : UG_ASSERT( FileExists( mFile.c_str() ),
65 : "File " << mFile.c_str() << " could not be found." );
66 0 : } else if( openMode == NEW ) {
67 0 : std::ofstream createFile;
68 0 : createFile.open( mFile.c_str(), std::ios_base::out );
69 : UG_ASSERT( createFile.is_open(), "File could not be created." );
70 0 : createFile.close();
71 0 : } else {
72 0 : UG_THROW( "Invalid open mode specified: " << openMode );
73 : }
74 4 : m_pMatFileName = new std::string( mFile );
75 : }
76 2 : }
77 :
78 1 : std::string MatrixIO::get_mat_file_name() const
79 : {
80 1 : return std::string( *m_pMatFileName );
81 : }
82 :
83 : // /////////////////////////////////////////////////////////////////////////////
84 : // Private Member Functions
85 0 : void MatrixIO::open_file( std::ios_base::openmode mode )
86 : {
87 : UG_ASSERT( !m_pMatFileName->empty(), "Matrix File not set." );
88 :
89 0 : m_matFileStream.open( m_pMatFileName->c_str(), mode );
90 : UG_ASSERT( m_matFileStream.fail() || m_matFileStream.bad(),
91 : "Matrix File could not be opend for reading/writing.\n"
92 : << "iostate: " << m_matFileStream.rdstate() );
93 0 : }
94 :
95 15 : void MatrixIO::close_file()
96 : {
97 15 : if ( m_matFileStream.is_open() ) {
98 : // m_pMatFileStream->flush();
99 0 : m_matFileStream.close();
100 : }
101 15 : }
102 :
103 :
104 :
105 : } // namespace ug
106 :
107 : // EOF
|