Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sbalzarini Lab
S
Software
P
Parallel Computing
OpenFPM
openfpm_io
Commits
69308d7f
Commit
69308d7f
authored
Jun 26, 2015
by
incardon
Browse files
Added missing files
parent
f6a17078
Changes
3
Hide whitespace changes
Inline
Side-by-side
Makefile.am
0 → 100755
View file @
69308d7f
SUBDIRS
=
src
bin_PROGRAMS
=
\ No newline at end of file
src/csv_multiarray.hpp
0 → 100644
View file @
69308d7f
/*
* csv_multiarray_copy.hpp
*
* Created on: Jun 20, 2015
* Author: i-bird
*/
#ifndef CSV_MULTIARRAY_COPY_HPP_
#define CSV_MULTIARRAY_COPY_HPP_
/*! \brief This class is an helper to produce csv headers from multi-array
*
* Usage:
*
* \code{.cpp}
*
* float src[3];
*
* std::stringstream str;
* csv_col_str<float[3]> cp(std::string("test"),str);
*
* std::cout << str.str() << "\n";
*
* \endcode
*
* Will produce ",test[0],test[1],test[2]"
*
*/
template
<
typename
T
>
struct
csv_col_str
{
inline
csv_col_str
(
std
::
string
prp
,
std
::
stringstream
&
str
)
{
str
<<
","
<<
prp
;
}
};
//! Partial specialization for N=1 1D-Array
template
<
typename
T
,
size_t
N1
>
struct
csv_col_str
<
T
[
N1
]
>
{
inline
csv_col_str
(
std
::
string
prp
,
std
::
stringstream
&
str
)
{
for
(
size_t
i
=
0
;
i
<
N1
;
i
++
)
str
<<
","
<<
prp
<<
"_"
<<
"["
<<
i
<<
"]"
;
}
};
//! Partial specialization for N=2 2D-Array
template
<
typename
T
,
size_t
N1
,
size_t
N2
>
struct
csv_col_str
<
T
[
N1
][
N2
]
>
{
inline
csv_col_str
(
std
::
string
prp
,
std
::
stringstream
&
str
)
{
for
(
size_t
i1
=
0
;
i1
<
N1
;
i1
++
)
{
for
(
size_t
i2
=
0
;
i2
<
N2
;
i2
++
)
{
str
<<
","
<<
prp
<<
"_"
<<
"["
<<
i1
<<
"]"
<<
"["
<<
i2
<<
"]"
;
}
}
}
};
//! Partial specialization for N=3
template
<
typename
T
,
size_t
N1
,
size_t
N2
,
size_t
N3
>
struct
csv_col_str
<
T
[
N1
][
N2
][
N3
]
>
{
inline
csv_col_str
(
std
::
string
prp
,
std
::
stringstream
&
str
)
{
for
(
size_t
i1
=
0
;
i1
<
N1
;
i1
++
)
{
for
(
size_t
i2
=
0
;
i2
<
N2
;
i2
++
)
{
for
(
size_t
i3
=
0
;
i3
<
N3
;
i3
++
)
{
str
<<
","
<<
prp
<<
"_"
<<
"["
<<
i1
<<
"]"
<<
"["
<<
i2
<<
"]"
<<
"["
<<
i3
<<
"]"
;
}
}
}
}
};
//! Partial specialization for N=4
template
<
typename
T
,
size_t
N1
,
size_t
N2
,
size_t
N3
,
size_t
N4
>
struct
csv_col_str
<
T
[
N1
][
N2
][
N3
][
N4
]
>
{
inline
csv_col_str
(
std
::
string
prp
,
std
::
stringstream
&
str
)
{
for
(
size_t
i1
=
0
;
i1
<
N1
;
i1
++
)
{
for
(
size_t
i2
=
0
;
i2
<
N2
;
i2
++
)
{
for
(
size_t
i3
=
0
;
i3
<
N3
;
i3
++
)
{
for
(
size_t
i4
=
0
;
i4
<
N4
;
i4
++
)
{
str
<<
","
<<
prp
<<
"_"
<<
"["
<<
i1
<<
"]"
<<
"["
<<
i2
<<
"]"
<<
"["
<<
i3
<<
"]"
<<
"["
<<
i4
<<
"]"
;
}
}
}
}
}
};
/*! \brief This class is an helper to produce csv data from multi-array
*
* Usage:
*
* \code{.cpp}
*
* float src[3] = {1.0,2.0,3.0};
*
* std::stringstream str;
* csv_value_str<float[3]> cp(src,str);
*
* std::cout << str.str() << "\n";
*
* \endcode
*
* Will produce ",1.0,2.0,3.0"
*
*/
template
<
typename
T
>
struct
csv_value_str
{
inline
csv_value_str
(
T
&
v
,
std
::
stringstream
&
str
)
{
str
<<
","
<<
v
;
}
};
//! Partial specialization for N=1 1D-Array
template
<
typename
T
,
size_t
N1
>
struct
csv_value_str
<
T
[
N1
]
>
{
inline
csv_value_str
(
const
T
v
[
N1
],
std
::
stringstream
&
str
)
{
for
(
size_t
i
=
0
;
i
<
N1
;
i
++
)
str
<<
","
<<
v
[
i
];
}
};
//! Partial specialization for N=2 2D-Array
template
<
typename
T
,
size_t
N1
,
size_t
N2
>
struct
csv_value_str
<
T
[
N1
][
N2
]
>
{
inline
csv_value_str
(
const
T
v
[
N1
][
N2
],
std
::
stringstream
&
str
)
{
for
(
size_t
i1
=
0
;
i1
<
N1
;
i1
++
)
{
for
(
size_t
i2
=
0
;
i2
<
N2
;
i2
++
)
{
str
<<
","
<<
v
[
i1
][
i2
];
}
}
}
};
//! Partial specialization for N=3
template
<
typename
T
,
size_t
N1
,
size_t
N2
,
size_t
N3
>
struct
csv_value_str
<
T
[
N1
][
N2
][
N3
]
>
{
inline
csv_value_str
(
const
T
v
[
N1
][
N2
][
N3
],
std
::
stringstream
&
str
)
{
for
(
size_t
i1
=
0
;
i1
<
N1
;
i1
++
)
{
for
(
size_t
i2
=
0
;
i2
<
N2
;
i2
++
)
{
for
(
size_t
i3
=
0
;
i3
<
N3
;
i3
++
)
{
str
<<
","
<<
v
[
i1
][
i2
][
i3
];
}
}
}
}
};
//! Partial specialization for N=4
template
<
typename
T
,
size_t
N1
,
size_t
N2
,
size_t
N3
,
size_t
N4
>
struct
csv_value_str
<
T
[
N1
][
N2
][
N3
][
N4
]
>
{
inline
csv_value_str
(
const
T
v
[
N1
][
N2
][
N3
][
N4
],
std
::
stringstream
&
str
)
{
for
(
size_t
i1
=
0
;
i1
<
N1
;
i1
++
)
{
for
(
size_t
i2
=
0
;
i2
<
N2
;
i2
++
)
{
for
(
size_t
i3
=
0
;
i3
<
N3
;
i3
++
)
{
for
(
size_t
i4
=
0
;
i4
<
N4
;
i4
++
)
{
str
<<
","
<<
v
[
i1
][
i2
][
i3
][
i4
];
}
}
}
}
}
};
#endif
/* CSV_MULTIARRAY_COPY_HPP_ */
src/util.hpp
0 → 100644
View file @
69308d7f
/*
* util.hpp
*
* Created on: May 7, 2015
* Author: Pietro Incardona
*/
#ifndef UTIL_HPP_
#define UTIL_HPP_
#include <boost/iostreams/device/mapped_file.hpp>
/*! \brief Compare two files, return true if they match
*
* \param file1 path1
* \param file2 path2
*
* \return true if they match
*
*/
bool
compare
(
std
::
string
file1
,
std
::
string
file2
)
{
boost
::
iostreams
::
mapped_file_source
f1
(
file1
);
boost
::
iostreams
::
mapped_file_source
f2
(
file2
);
if
(
f1
.
size
()
==
f2
.
size
()
&&
std
::
equal
(
f1
.
data
(),
f1
.
data
()
+
f1
.
size
(),
f2
.
data
())
)
return
true
;
else
return
false
;
}
struct
RGB
{
float
R
;
float
G
;
float
B
;
std
::
string
toString
()
{
return
std
::
to_string
(
R
)
+
" "
+
std
::
to_string
(
G
)
+
" "
+
std
::
to_string
(
B
);
}
};
/*! \brief Return the color sampled from one group
*
* groups:
*
* 0: Red
* 1: Green
* 2: Blue
* 3: Yellow
* 4: Cyan
* 5: Magenta
* 6: Orange
* 7: Chartreuse-Green
* 8: Spring Green
* 9: Azure
* 10: Violet
* 11: Rose
*
* \param group
*
*/
struct
RGB
getColor
(
int
group
,
std
::
uniform_real_distribution
<
float
>
&
d
,
std
::
default_random_engine
&
g
)
{
struct
RGB
col
;
if
(
group
==
0
)
{
float
s
=
d
(
g
);
col
.
R
=
s
/
2
+
0.5
;
col
.
G
=
0.0
;
col
.
B
=
0.0
;
}
else
if
(
group
==
1
)
{
float
s
=
d
(
g
);
col
.
R
=
0.0
;
col
.
G
=
s
/
2
+
0.5
;
col
.
B
=
0.0
;
}
else
if
(
group
==
2
)
{
float
s
=
d
(
g
);
col
.
R
=
0.0
;
col
.
G
=
0.0
;
col
.
B
=
s
;
}
else
if
(
group
==
3
)
{
float
s
=
d
(
g
);
col
.
R
=
s
/
2
+
0.5
;
col
.
G
=
s
/
2
+
0.5
;
col
.
B
=
0.0
;
}
else
if
(
group
==
4
)
{
float
s
=
d
(
g
);
col
.
R
=
s
/
2
+
0.5
;
col
.
G
=
0.0
;
col
.
B
=
s
/
2
+
0.5
;
}
else
if
(
group
==
5
)
{
float
s
=
d
(
g
);
col
.
R
=
0.0
;
col
.
G
=
s
/
2
+
0.5
;
col
.
B
=
s
/
2
+
0.5
;
}
else
if
(
group
==
6
)
{
float
s
=
d
(
g
);
col
.
R
=
s
/
2
+
0.5
;
col
.
G
=
s
/
4
+
0.5
;
col
.
B
=
0.0
;
}
else
if
(
group
==
7
)
{
float
s
=
d
(
g
);
col
.
R
=
s
/
4
+
0.5
;
col
.
G
=
s
/
2
+
0.5
;
col
.
B
=
0.0
;
}
else
if
(
group
==
8
)
{
float
s
=
d
(
g
);
col
.
R
=
0.0
;
col
.
G
=
s
/
2
+
0.5
;
col
.
B
=
s
/
4
+
0.5
;
}
else
if
(
group
==
9
)
{
float
s
=
d
(
g
);
col
.
R
=
0.0
;
col
.
G
=
s
/
4
+
0.5
;
col
.
B
=
s
/
2
+
0.5
;
}
else
if
(
group
==
10
)
{
float
s
=
d
(
g
);
col
.
R
=
s
/
4
+
0.5
;
col
.
G
=
0.0
;
col
.
B
=
s
/
2
+
0.5
;
}
else
if
(
group
==
11
)
{
float
s
=
d
(
g
);
col
.
R
=
s
/
2
+
0.5
;
col
.
G
=
0.0
;
col
.
B
=
s
/
4
+
0.5
;
}
return
col
;
}
/*! \brief Check if one string end with a particular string
*
* \param fullString string to check
* \param ending ending string to check
*
*/
bool
hasEnding
(
std
::
string
const
&
fullString
,
std
::
string
const
&
ending
)
{
if
(
fullString
.
length
()
>=
ending
.
length
())
{
return
(
0
==
fullString
.
compare
(
fullString
.
length
()
-
ending
.
length
(),
ending
.
length
(),
ending
));}
else
{
return
false
;}
}
#endif
/* UTIL_HPP_ */
Write
Preview
Markdown
is supported
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