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
fbcb1570
Commit
fbcb1570
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
simplify determination of file type
parent
ad538ed2
No related branches found
No related tags found
1 merge request
!1629
IO further cleanup
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Device/IO/DataFormatUtil.cpp
+12
-13
12 additions, 13 deletions
Device/IO/DataFormatUtil.cpp
Device/IO/DataFormatUtil.h
+2
-0
2 additions, 0 deletions
Device/IO/DataFormatUtil.h
Device/IO/IOFactory.cpp
+27
-26
27 additions, 26 deletions
Device/IO/IOFactory.cpp
with
41 additions
and
39 deletions
Device/IO/DataFormatUtil.cpp
+
12
−
13
View file @
fbcb1570
...
...
@@ -40,15 +40,6 @@ std::istringstream getAxisStringRepresentation(std::istream& input_stream)
return
std
::
istringstream
(
line
);
}
std
::
string
uncompressedFilename
(
const
std
::
string
&
name
)
{
if
(
DataUtil
::
Format
::
isGZipped
(
name
))
return
name
.
substr
(
0
,
name
.
size
()
-
GzipExtension
.
size
());
if
(
DataUtil
::
Format
::
isBZipped
(
name
))
return
name
.
substr
(
0
,
name
.
size
()
-
BzipExtension
.
size
());
return
name
;
}
void
readLineOfDoubles
(
std
::
vector
<
double
>&
buffer
,
std
::
istringstream
&
iss
)
{
iss
.
imbue
(
std
::
locale
::
classic
());
...
...
@@ -58,6 +49,14 @@ void readLineOfDoubles(std::vector<double>& buffer, std::istringstream& iss)
}
// namespace
std
::
string
DataUtil
::
Format
::
uncompressedFilename
(
const
std
::
string
&
name
)
{
if
(
DataUtil
::
Format
::
isGZipped
(
name
))
return
name
.
substr
(
0
,
name
.
size
()
-
GzipExtension
.
size
());
if
(
DataUtil
::
Format
::
isBZipped
(
name
))
return
name
.
substr
(
0
,
name
.
size
()
-
BzipExtension
.
size
());
return
name
;
}
bool
DataUtil
::
Format
::
isCompressed
(
const
std
::
string
&
name
)
{
...
...
@@ -78,18 +77,18 @@ bool DataUtil::Format::isBZipped(const std::string& name)
bool
DataUtil
::
Format
::
isIntFile
(
const
std
::
string
&
file_name
)
{
return
BaseUtil
::
Filesystem
::
hasExtension
(
::
uncompressedFilename
(
file_name
),
IntExtension
);
return
BaseUtil
::
Filesystem
::
hasExtension
(
uncompressedFilename
(
file_name
),
IntExtension
);
}
bool
DataUtil
::
Format
::
isNicosFile
(
const
std
::
string
&
file_name
)
{
return
BaseUtil
::
Filesystem
::
hasExtension
(
::
uncompressedFilename
(
file_name
),
NicosExtension
);
return
BaseUtil
::
Filesystem
::
hasExtension
(
uncompressedFilename
(
file_name
),
NicosExtension
);
}
bool
DataUtil
::
Format
::
isTiffFile
(
const
std
::
string
&
file_name
)
{
return
BaseUtil
::
Filesystem
::
hasExtension
(
::
uncompressedFilename
(
file_name
),
TiffExtension
)
||
BaseUtil
::
Filesystem
::
hasExtension
(
::
uncompressedFilename
(
file_name
),
TiffExtension2
);
return
BaseUtil
::
Filesystem
::
hasExtension
(
uncompressedFilename
(
file_name
),
TiffExtension
)
||
BaseUtil
::
Filesystem
::
hasExtension
(
uncompressedFilename
(
file_name
),
TiffExtension2
);
}
//! Creates axis of certain type from input stream
...
...
This diff is collapsed.
Click to expand it.
Device/IO/DataFormatUtil.h
+
2
−
0
View file @
fbcb1570
...
...
@@ -28,6 +28,8 @@ class Datafield;
namespace
DataUtil
::
Format
{
std
::
string
uncompressedFilename
(
const
std
::
string
&
name
);
//! Returns true if name contains *.gz extension
bool
isCompressed
(
const
std
::
string
&
name
);
...
...
This diff is collapsed.
Click to expand it.
Device/IO/IOFactory.cpp
+
27
−
26
View file @
fbcb1570
...
...
@@ -15,6 +15,7 @@
#include
"Device/IO/IOFactory.h"
#include
"Base/Util/Assert.h"
#include
"Base/Util/FileSystemUtil.h"
#include
"Base/Util/StringUtil.h"
#include
"Device/Data/Datafield.h"
#include
"Device/Histo/DiffUtil.h"
#include
"Device/Histo/SimulationResult.h"
...
...
@@ -24,6 +25,8 @@
#include
"Device/IO/ReadWriteNicos.h"
#include
"Device/IO/ReadWriteNumpyTXT.h"
#include
"Device/IO/ReadWriteTiff.h"
#include
<algorithm>
#include
<cctype>
#include
<exception>
#include
<fstream>
#include
<iostream>
...
...
@@ -108,50 +111,48 @@ void stream2file(const std::string& file_name, std::stringstream& s)
fout
.
close
();
}
bool
f
ile
T
ype
MatchesFile
type
(
const
std
::
string
&
file
N
ame
,
IO
::
Filetype
selector
)
IO
::
F
ile
t
ype
filename2
type
(
const
std
::
string
&
file
n
ame
)
{
switch
(
selector
)
{
case
IO
::
bornagain
:
return
DataUtil
::
Format
::
isIntFile
(
fileName
);
case
IO
::
nicos
:
return
DataUtil
::
Format
::
isNicosFile
(
fileName
);
case
IO
::
tiff
:
return
DataUtil
::
Format
::
isTiffFile
(
fileName
);
default:
return
false
;
}
return
false
;
std
::
string
s
=
DataUtil
::
Format
::
uncompressedFilename
(
filename
);
s
=
BaseUtil
::
Filesystem
::
extension
(
s
);
s
=
BaseUtil
::
String
::
to_lower
(
s
);
if
(
s
==
".int"
)
return
IO
::
bornagain
;
if
(
s
==
".001"
)
return
IO
::
nicos
;
if
(
s
==
".tif"
||
s
==
".tiff"
)
return
IO
::
tiff
;
if
(
s
==
".mft"
)
return
IO
::
mft
;
return
IO
::
nil
;
}
}
// namespace
Datafield
*
IO
::
readData2D
(
const
std
::
string
&
file_name
,
Filetype
selector
)
Datafield
*
IO
::
readData2D
(
const
std
::
string
&
file_name
,
Filetype
ftype
)
{
const
auto
readAs
=
[
=
](
Filetype
testForSelector
)
{
return
(
selector
==
testForSelector
)
||
(
selector
==
nil
&&
::
fileTypeMatchesFiletype
(
file_name
,
testForSelector
));
};
if
(
ftype
==
nil
)
ftype
=
::
filename2type
(
file_name
);
auto
s
=
::
file2stream
(
file_name
);
if
(
readAs
(
bornagain
)
)
if
(
ftype
==
bornagain
)
return
Util
::
RW
::
readBAInt
(
s
);
else
if
(
readAs
(
nicos
)
)
if
(
ftype
==
nicos
)
return
Util
::
RW
::
readNicos
(
s
);
#ifdef BA_TIFF_SUPPORT
else
if
(
readAs
(
tiff
)
)
if
(
ftype
==
tiff
)
return
Util
::
RW
::
readTiff
(
s
);
#endif
else
// Try to read ASCII by default. Binary maps to ASCII.
// If the file is not actually a matrix of numbers,
// the error will be thrown during the reading.
return
Util
::
RW
::
readNumpyTxt
(
s
);
// Try to read ASCII by default. Binary maps to ASCII.
// If the file is not actually a matrix of numbers,
// the error will be thrown during the reading.
return
Util
::
RW
::
readNumpyTxt
(
s
);
}
Datafield
*
IO
::
readData1D
(
const
std
::
string
&
file_name
,
Filetype
/*selector*/
)
...
...
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