VPTissue Reference Manual
Hdf5Format.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "Hdf5Format.h"
21 
22 #include "fileformats/Hdf5File.h"
23 #include "util/misc/Exception.h"
24 
25 using namespace std;
26 using namespace SimPT_Sim;
29 
30 namespace SimPT_Shell {
31 
32 void Hdf5Format::PreConvert(const string& target_path, shared_ptr<MergedPreferences>)
33 {
34  m_file.Open(target_path + '.' + GetExtension());
35  if (!m_file.IsOpen()) {
36  throw Exception("Couln't open or create HDF5 file " + target_path);
37  }
38 }
39 
40 void Hdf5Format::Convert(const SimState& s)
41 {
42  auto sim = make_shared<SimPT_Sim::Sim>();
43  sim->Initialize(s);
44  try {
45  m_file.Write(sim);
46  }
47  catch (runtime_error &e) {
48  throw Exception("Error writing step "
49  + to_string(s.GetTimeStep())
50  + " to " + m_file.GetFilePath() + ":\n" + e.what());
51  }
52 }
53 
54 void Hdf5Format::PostConvert()
55 {
56  m_file.Close();
57 }
58 
59 } // namespace
STL namespace.
Namespace for SimPT shell package.
Definition: Client.cpp:50
Wrapper around workspace to have read and write access to merged (workspace + project) preferences...
Extremely simple Exception root class.
Definition: Exception.h:28
Namespace for the core simulator.
Interface for VirtualLeaf::Hdf5File.
Contains the state of the whole Simulator at a given simulation step.
Definition: SimState.h:33
Header file for Exception class.
int GetTimeStep() const
Returns the index of the current time step.
Definition: SimState.cpp:35
Interface of File Converter Formats.