Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
Power System Simulation and Optimization
DPsim
DPsim
Commits
a42e84b1
Commit
a42e84b1
authored
Jul 15, 2019
by
Steffen Vogel
🎅🏼
Browse files
datalogger: allow logger to be reopened for simulation reset
parent
a5281d31
Changes
2
Hide whitespace changes
Inline
Side-by-side
Include/dpsim/DataLogger.h
View file @
a42e84b1
...
...
@@ -24,6 +24,8 @@
#include
<map>
#include
<iostream>
#include
<fstream>
#include
<experimental/filesystem>
namespace
fs
=
std
::
experimental
::
filesystem
;
#include
<dpsim/Definitions.h>
#include
<dpsim/Scheduler.h>
...
...
@@ -41,6 +43,7 @@ namespace DPsim {
String
mName
;
Bool
mEnabled
;
UInt
mDownsampling
;
fs
::
path
mFilename
;
std
::
map
<
String
,
CPS
::
AttributeBase
::
Ptr
>
mAttributes
;
...
...
@@ -54,9 +57,13 @@ namespace DPsim {
DataLogger
(
Bool
enabled
=
true
);
DataLogger
(
String
name
,
Bool
enabled
=
true
,
UInt
downsampling
=
1
);
~
DataLogger
();
void
open
();
void
close
();
void
reopen
()
{
close
();
open
();
}
void
logPhasorNodeValues
(
Real
time
,
const
Matrix
&
data
);
void
logEMTNodeValues
(
Real
time
,
const
Matrix
&
data
);
...
...
Source/DataLogger.cpp
View file @
a42e84b1
...
...
@@ -19,8 +19,6 @@
*********************************************************************************/
#include
<iomanip>
#include
<experimental/filesystem>
namespace
fs
=
std
::
experimental
::
filesystem
;
#include
<dpsim/DataLogger.h>
#include
<cps/Logger.h>
...
...
@@ -41,26 +39,23 @@ DataLogger::DataLogger(String name, Bool enabled, UInt downsampling) :
if
(
!
mEnabled
)
return
;
String
f
ilename
=
CPS
::
Logger
::
logDir
()
+
"/"
+
name
+
".csv"
;
mF
ilename
=
CPS
::
Logger
::
logDir
()
+
"/"
+
name
+
".csv"
;
fs
::
path
p
=
filename
;
if
(
mFilename
.
has_parent_path
()
&&
!
fs
::
exists
(
mFilename
.
parent_path
()))
fs
::
create_directory
(
mFilename
.
parent_path
());
if
(
p
.
has_parent_path
()
&&
!
fs
::
exists
(
p
.
parent_path
()))
fs
::
create_directory
(
p
.
parent_path
());
open
();
}
mLogFile
=
std
::
ofstream
(
filename
);
void
DataLogger
::
open
()
{
mLogFile
=
std
::
ofstream
(
mFilename
,
std
::
ios_base
::
out
|
std
::
ios_base
::
trunc
);
if
(
!
mLogFile
.
is_open
())
{
// TODO: replace by exception
std
::
cerr
<<
"Cannot open log file "
<<
f
ilename
<<
std
::
endl
;
std
::
cerr
<<
"Cannot open log file "
<<
mF
ilename
<<
std
::
endl
;
mEnabled
=
false
;
}
}
DataLogger
::~
DataLogger
()
{
if
(
mLogFile
.
is_open
())
mLogFile
.
close
();
}
void
DataLogger
::
close
()
{
mLogFile
.
close
();
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment