Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
35573d9b
Commit
35573d9b
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
fcts -> local ns
parent
00addba9
No related branches found
No related tags found
1 merge request
!1628
simplify and unify API and code for reading or writing data files
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Device/IO/ReadWriteNumpyTXT.cpp
+38
-38
38 additions, 38 deletions
Device/IO/ReadWriteNumpyTXT.cpp
Device/IO/ReadWriteNumpyTXT.h
+0
-5
0 additions, 5 deletions
Device/IO/ReadWriteNumpyTXT.h
with
38 additions
and
43 deletions
Device/IO/ReadWriteNumpyTXT.cpp
+
38
−
38
View file @
35573d9b
...
@@ -29,6 +29,44 @@ bool isDoubleStartChar(char c)
...
@@ -29,6 +29,44 @@ bool isDoubleStartChar(char c)
return
isdigit
(
c
)
||
c
==
'-'
||
c
==
'+'
;
return
isdigit
(
c
)
||
c
==
'-'
||
c
==
'+'
;
}
}
double
ignoreDenormalized
(
double
value
)
{
return
(
std
::
fpclassify
(
value
)
==
FP_SUBNORMAL
)
?
0.0
:
value
;
}
void
write1DRepresentation
(
const
Datafield
&
data
,
std
::
ostream
&
output_stream
)
{
output_stream
<<
"# coordinates intensities"
<<
std
::
endl
;
output_stream
.
imbue
(
std
::
locale
::
classic
());
output_stream
<<
std
::
scientific
<<
std
::
setprecision
(
12
);
const
std
::
vector
<
double
>
axis_values
=
data
.
axis
(
0
).
binCenters
();
// printing coordinate and associated intensity
for
(
size_t
i
=
0
,
nrows
=
axis_values
.
size
();
i
<
nrows
;
++
i
)
output_stream
<<
axis_values
[
i
]
<<
" "
<<
ignoreDenormalized
(
data
[
i
])
<<
std
::
endl
;
}
void
write2DRepresentation
(
const
Datafield
&
data
,
std
::
ostream
&
output_stream
)
{
const
size_t
nrows
=
data
.
axis
(
1
).
size
();
const
size_t
ncols
=
data
.
axis
(
0
).
size
();
output_stream
<<
"# [nrows="
<<
nrows
<<
", ncols="
<<
ncols
<<
"]"
<<
std
::
endl
;
std
::
vector
<
std
::
vector
<
double
>>
dataArray
=
DataUtil
::
Array
::
createVector2D
(
data
);
output_stream
.
imbue
(
std
::
locale
::
classic
());
output_stream
<<
std
::
scientific
<<
std
::
setprecision
(
12
);
for
(
size_t
i
=
0
;
i
<
nrows
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
ncols
;
j
++
)
{
double
z_value
=
dataArray
[
i
][
j
];
output_stream
<<
ignoreDenormalized
(
z_value
)
<<
" "
;
}
output_stream
<<
std
::
endl
;
}
}
}
// namespace
}
// namespace
Datafield
*
ReadWriteNumpyTXT
::
readDatafield
(
std
::
istream
&
input_stream
)
Datafield
*
ReadWriteNumpyTXT
::
readDatafield
(
std
::
istream
&
input_stream
)
...
@@ -98,41 +136,3 @@ void ReadWriteNumpyTXT::writeDatafield(const Datafield& data, std::ostream& outp
...
@@ -98,41 +136,3 @@ void ReadWriteNumpyTXT::writeDatafield(const Datafield& data, std::ostream& outp
"of unsupported dimensions"
);
"of unsupported dimensions"
);
}
}
}
}
void
ReadWriteNumpyTXT
::
write1DRepresentation
(
const
Datafield
&
data
,
std
::
ostream
&
output_stream
)
{
output_stream
<<
"# coordinates intensities"
<<
std
::
endl
;
output_stream
.
imbue
(
std
::
locale
::
classic
());
output_stream
<<
std
::
scientific
<<
std
::
setprecision
(
12
);
const
std
::
vector
<
double
>
axis_values
=
data
.
axis
(
0
).
binCenters
();
// printing coordinate and associated intensity
for
(
size_t
i
=
0
,
nrows
=
axis_values
.
size
();
i
<
nrows
;
++
i
)
output_stream
<<
axis_values
[
i
]
<<
" "
<<
ignoreDenormalized
(
data
[
i
])
<<
std
::
endl
;
}
void
ReadWriteNumpyTXT
::
write2DRepresentation
(
const
Datafield
&
data
,
std
::
ostream
&
output_stream
)
{
const
size_t
nrows
=
data
.
axis
(
1
).
size
();
const
size_t
ncols
=
data
.
axis
(
0
).
size
();
output_stream
<<
"# [nrows="
<<
nrows
<<
", ncols="
<<
ncols
<<
"]"
<<
std
::
endl
;
std
::
vector
<
std
::
vector
<
double
>>
dataArray
=
DataUtil
::
Array
::
createVector2D
(
data
);
output_stream
.
imbue
(
std
::
locale
::
classic
());
output_stream
<<
std
::
scientific
<<
std
::
setprecision
(
12
);
for
(
size_t
i
=
0
;
i
<
nrows
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
ncols
;
j
++
)
{
double
z_value
=
dataArray
[
i
][
j
];
output_stream
<<
ignoreDenormalized
(
z_value
)
<<
" "
;
}
output_stream
<<
std
::
endl
;
}
}
double
ReadWriteNumpyTXT
::
ignoreDenormalized
(
double
value
)
{
return
(
std
::
fpclassify
(
value
)
==
FP_SUBNORMAL
)
?
0.0
:
value
;
}
This diff is collapsed.
Click to expand it.
Device/IO/ReadWriteNumpyTXT.h
+
0
−
5
View file @
35573d9b
...
@@ -29,11 +29,6 @@ class ReadWriteNumpyTXT {
...
@@ -29,11 +29,6 @@ class ReadWriteNumpyTXT {
public:
public:
static
Datafield
*
readDatafield
(
std
::
istream
&
input_stream
);
static
Datafield
*
readDatafield
(
std
::
istream
&
input_stream
);
static
void
writeDatafield
(
const
Datafield
&
data
,
std
::
ostream
&
output_stream
);
static
void
writeDatafield
(
const
Datafield
&
data
,
std
::
ostream
&
output_stream
);
private:
static
void
write1DRepresentation
(
const
Datafield
&
data
,
std
::
ostream
&
output_stream
);
static
void
write2DRepresentation
(
const
Datafield
&
data
,
std
::
ostream
&
output_stream
);
static
double
ignoreDenormalized
(
double
value
);
};
};
#endif // BORNAGAIN_DEVICE_IO_READWRITENUMPYTXT_H
#endif // BORNAGAIN_DEVICE_IO_READWRITENUMPYTXT_H
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