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
abf1cd54
Commit
abf1cd54
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
more uses of filename2type; extract common fct for binary openmode
parent
0b01d06e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1629
IO further cleanup
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Device/IO/IOFactory.cpp
+15
-6
15 additions, 6 deletions
Device/IO/IOFactory.cpp
GUI/View/Import/ImportDataUtil.cpp
+2
-7
2 additions, 7 deletions
GUI/View/Import/ImportDataUtil.cpp
with
17 additions
and
13 deletions
Device/IO/IOFactory.cpp
+
15
−
6
View file @
abf1cd54
...
@@ -44,6 +44,12 @@
...
@@ -44,6 +44,12 @@
namespace
{
namespace
{
bool
is_binary
(
const
std
::
string
&
file_name
)
{
const
IO
::
Filetype
ftype
=
IO
::
filename2type
(
file_name
);
return
ftype
==
IO
::
tiff
||
DataUtil
::
Format
::
isCompressed
(
file_name
);
}
std
::
stringstream
file2stream
(
const
std
::
string
&
file_name
)
std
::
stringstream
file2stream
(
const
std
::
string
&
file_name
)
{
{
if
(
!
BaseUtil
::
Filesystem
::
IsFileExists
(
file_name
))
if
(
!
BaseUtil
::
Filesystem
::
IsFileExists
(
file_name
))
...
@@ -52,8 +58,8 @@ std::stringstream file2stream(const std::string& file_name)
...
@@ -52,8 +58,8 @@ std::stringstream file2stream(const std::string& file_name)
using
namespace
DataUtil
::
Format
;
using
namespace
DataUtil
::
Format
;
std
::
ifstream
input_stream
;
std
::
ifstream
input_stream
;
std
::
ios_base
::
openmode
openmode
=
std
::
ios
::
in
;
std
::
ios_base
::
openmode
openmode
=
std
::
ios
::
in
;
if
(
is
TiffFile
(
file_name
)
||
isCompressed
(
file_name
))
if
(
is
_binary
(
file_name
))
openmode
=
std
::
ios
::
in
|
std
::
ios_base
::
binary
;
openmode
|
=
std
::
ios_base
::
binary
;
#ifdef _WIN32
#ifdef _WIN32
input_stream
.
open
(
BaseUtil
::
Filesystem
::
convert_utf8_to_utf16
(
file_name
),
openmode
);
input_stream
.
open
(
BaseUtil
::
Filesystem
::
convert_utf8_to_utf16
(
file_name
),
openmode
);
...
@@ -85,8 +91,8 @@ void stream2file(const std::string& file_name, std::stringstream& s)
...
@@ -85,8 +91,8 @@ void stream2file(const std::string& file_name, std::stringstream& s)
std
::
ofstream
fout
;
std
::
ofstream
fout
;
std
::
ios_base
::
openmode
openmode
=
std
::
ios
::
out
;
std
::
ios_base
::
openmode
openmode
=
std
::
ios
::
out
;
if
(
is
TiffFile
(
file_name
)
||
isCompressed
(
file_name
))
if
(
is
_binary
(
file_name
))
openmode
=
std
::
ios
::
out
|
std
::
ios_base
::
binary
;
openmode
|
=
std
::
ios_base
::
binary
;
#ifdef _WIN32
#ifdef _WIN32
fout
.
open
(
BaseUtil
::
Filesystem
::
convert_utf8_to_utf16
(
file_name
),
openmode
);
fout
.
open
(
BaseUtil
::
Filesystem
::
convert_utf8_to_utf16
(
file_name
),
openmode
);
...
@@ -162,15 +168,18 @@ Datafield* IO::readData1D(const std::string& file_name, Filetype /*selector*/)
...
@@ -162,15 +168,18 @@ Datafield* IO::readData1D(const std::string& file_name, Filetype /*selector*/)
void
IO
::
writeDatafield
(
const
Datafield
&
data
,
const
std
::
string
&
file_name
)
void
IO
::
writeDatafield
(
const
Datafield
&
data
,
const
std
::
string
&
file_name
)
{
{
const
Filetype
ftype
=
filename2type
(
file_name
);
try
{
try
{
std
::
stringstream
s
;
std
::
stringstream
s
;
if
(
DataUtil
::
Format
::
isIntFile
(
file_name
)
)
if
(
ftype
==
bornagain
)
Util
::
RW
::
writeBAInt
(
data
,
s
);
Util
::
RW
::
writeBAInt
(
data
,
s
);
#ifdef BA_TIFF_SUPPORT
#ifdef BA_TIFF_SUPPORT
else
if
(
DataUtil
::
Format
::
isTiffFile
(
file_name
)
)
else
if
(
ftype
==
tiff
)
Util
::
RW
::
writeTiff
(
data
,
s
);
Util
::
RW
::
writeTiff
(
data
,
s
);
#endif
#endif
else
else
Util
::
RW
::
writeNumpyTxt
(
data
,
s
);
Util
::
RW
::
writeNumpyTxt
(
data
,
s
);
...
...
This diff is collapsed.
Click to expand it.
GUI/View/Import/ImportDataUtil.cpp
+
2
−
7
View file @
abf1cd54
...
@@ -73,13 +73,8 @@ QString GUI::View::ImportDataUtil::Import1dData(RealItem* realItem,
...
@@ -73,13 +73,8 @@ QString GUI::View::ImportDataUtil::Import1dData(RealItem* realItem,
return
QString
();
return
QString
();
}
}
}
catch
(
std
::
exception
&
ex
)
{
}
catch
(
std
::
exception
&
ex
)
{
// If it is not tiff but e.g. dat.gz, it could be tried with CSV import
// Try with CSV import ? TODO check the logic, simplify
const
bool
tryWithLoaders
=
if
(
filetype
!=
IO
::
bornagain
||
DataUtil
::
Format
::
isCompressed
(
fileNameStdString
))
(
DataUtil
::
Format
::
isIntFile
(
fileNameStdString
)
&&
!
DataUtil
::
Format
::
isCompressed
(
fileNameStdString
));
// #baimport support compressed
if
(
!
tryWithLoaders
)
// import is not possible
// import is not possible
return
QString
::
fromLatin1
(
ex
.
what
());
return
QString
::
fromLatin1
(
ex
.
what
());
}
}
...
...
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