Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Eisgenerator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Klemm, Carl Philipp
Eisgenerator
Commits
9f680191
Commit
9f680191
authored
2 years ago
by
Carl Philipp Klemm
Browse files
Options
Downloads
Patches
Plain Diff
eistype: add exceptions, add function to load eis spectrum from disk
parent
4e2c2fef
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
eisgenerator/eistype.h
+27
-0
27 additions, 0 deletions
eisgenerator/eistype.h
eistype.cpp
+30
-2
30 additions, 2 deletions
eistype.cpp
with
57 additions
and
2 deletions
eisgenerator/eistype.h
+
27
−
0
View file @
9f680191
...
@@ -8,6 +8,7 @@ typedef double fvalue;
...
@@ -8,6 +8,7 @@ typedef double fvalue;
namespace
eis
namespace
eis
{
{
class
DataPoint
class
DataPoint
{
{
public:
public:
...
@@ -109,8 +110,34 @@ public:
...
@@ -109,8 +110,34 @@ public:
static
std
::
vector
<
Range
>
rangesFromParamString
(
const
std
::
string
&
paramStr
,
size_t
count
);
static
std
::
vector
<
Range
>
rangesFromParamString
(
const
std
::
string
&
paramStr
,
size_t
count
);
};
};
class
parse_errror
:
public
std
::
exception
{
std
::
string
whatStr
;
public:
parse_errror
(
const
std
::
string
&
whatIn
)
:
whatStr
(
whatIn
)
{}
virtual
const
char
*
what
()
const
noexcept
override
{
return
whatStr
.
c_str
();
}
};
class
file_error
:
public
std
::
exception
{
std
::
string
whatStr
;
public:
file_error
(
const
std
::
string
&
whatIn
)
:
whatStr
(
whatIn
)
{}
virtual
const
char
*
what
()
const
noexcept
override
{
return
whatStr
.
c_str
();
}
};
bool
saveToDisk
(
const
std
::
vector
<
DataPoint
>&
data
,
const
std
::
string
&
fileName
,
std
::
string
headStr
=
""
);
bool
saveToDisk
(
const
std
::
vector
<
DataPoint
>&
data
,
const
std
::
string
&
fileName
,
std
::
string
headStr
=
""
);
std
::
pair
<
std
::
vector
<
DataPoint
>
,
std
::
string
>
loadFromDisk
(
const
std
::
string
&
fileName
);
fvalue
eisDistance
(
const
std
::
vector
<
eis
::
DataPoint
>&
a
,
const
std
::
vector
<
eis
::
DataPoint
>&
b
);
fvalue
eisDistance
(
const
std
::
vector
<
eis
::
DataPoint
>&
a
,
const
std
::
vector
<
eis
::
DataPoint
>&
b
);
fvalue
eisNyquistDistance
(
const
std
::
vector
<
eis
::
DataPoint
>&
a
,
const
std
::
vector
<
eis
::
DataPoint
>&
b
);
fvalue
eisNyquistDistance
(
const
std
::
vector
<
eis
::
DataPoint
>&
a
,
const
std
::
vector
<
eis
::
DataPoint
>&
b
);
...
...
This diff is collapsed.
Click to expand it.
eistype.cpp
+
30
−
2
View file @
9f680191
...
@@ -19,8 +19,8 @@ bool eis::saveToDisk(const std::vector<DataPoint>& data, const std::string& file
...
@@ -19,8 +19,8 @@ bool eis::saveToDisk(const std::vector<DataPoint>& data, const std::string& file
}
}
if
(
!
headStr
.
empty
())
if
(
!
headStr
.
empty
())
file
<<
headStr
<<
'\n'
;
file
<<
headStr
;
file
<<
"omega,real,im
\n
"
;
file
<<
"
\n
omega,real,im
\n
"
;
for
(
const
eis
::
DataPoint
&
point
:
data
)
for
(
const
eis
::
DataPoint
&
point
:
data
)
file
<<
point
.
omega
<<
','
<<
point
.
im
.
real
()
<<
','
<<
point
.
im
.
imag
()
<<
'\n'
;
file
<<
point
.
omega
<<
','
<<
point
.
im
.
real
()
<<
','
<<
point
.
im
.
imag
()
<<
'\n'
;
...
@@ -28,6 +28,34 @@ bool eis::saveToDisk(const std::vector<DataPoint>& data, const std::string& file
...
@@ -28,6 +28,34 @@ bool eis::saveToDisk(const std::vector<DataPoint>& data, const std::string& file
return
true
;
return
true
;
}
}
std
::
pair
<
std
::
vector
<
DataPoint
>
,
std
::
string
>
eis
::
loadFromDisk
(
const
std
::
string
&
fileName
)
{
std
::
fstream
file
;
file
.
open
(
fileName
,
std
::
ios_base
::
in
);
if
(
!
file
.
is_open
())
throw
file_error
(
"can not open "
+
fileName
+
" for reading
\n
"
);
std
::
pair
<
std
::
vector
<
DataPoint
>
,
std
::
string
>
out
;
std
::
getline
(
file
,
out
.
second
);
std
::
string
line
;
std
::
getline
(
file
,
line
);
while
(
file
.
good
())
{
std
::
getline
(
file
,
line
);
if
(
line
.
empty
()
||
line
[
0
]
==
'#'
)
continue
;
std
::
vector
<
std
::
string
>
tokens
=
tokenize
(
line
,
','
);
if
(
tokens
.
size
()
!=
3
)
throw
file_error
(
"invalid line in "
+
fileName
+
": "
+
line
);
out
.
first
.
push_back
(
DataPoint
({
std
::
stod
(
tokens
[
1
]),
std
::
stod
(
tokens
[
2
])},
std
::
stod
(
tokens
[
0
])));
}
file
.
close
();
return
out
;
}
void
eis
::
Range
::
print
(
int
level
)
const
void
eis
::
Range
::
print
(
int
level
)
const
{
{
Log
(
static_cast
<
Log
::
Level
>
(
level
))
<<
"Range "
<<
start
<<
'-'
<<
end
<<
' '
<<
count
<<
" steps"
<<
(
log
?
" Log"
:
""
);
Log
(
static_cast
<
Log
::
Level
>
(
level
))
<<
"Range "
<<
start
<<
'-'
<<
end
<<
' '
<<
count
<<
" steps"
<<
(
log
?
" Log"
:
""
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment