Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
1aaf8f0d
Commit
1aaf8f0d
authored
Feb 20, 2017
by
Matthieu Schaller
Browse files
Merge branch 'master' into timestep_order
parents
351fa6bf
7bd06f71
Changes
31
Hide whitespace changes
Inline
Side-by-side
examples/MultiTypes/makeIC.py
View file @
1aaf8f0d
...
...
@@ -39,143 +39,151 @@ Ldm = int(sys.argv[2]) # Number of particles along one axis
massStars
=
0.1
Lstars
=
int
(
sys
.
argv
[
3
])
# Number of particles along one axis
fileName
=
"multiTypes.hdf5"
fileBaseName
=
"multiTypes"
num_files
=
int
(
sys
.
argv
[
4
])
#---------------------------------------------------
numGas
=
Lgas
**
3
massGas
=
boxSize
**
3
*
rhoGas
/
numGas
numGas
_tot
=
Lgas
**
3
massGas
=
boxSize
**
3
*
rhoGas
/
numGas
_tot
internalEnergy
=
P
/
((
gamma
-
1.
)
*
rhoGas
)
numDM
=
Ldm
**
3
massDM
=
boxSize
**
3
*
rhoDM
/
numDM
numDM
_tot
=
Ldm
**
3
massDM
=
boxSize
**
3
*
rhoDM
/
numDM
_tot
numStars
=
Lstars
**
3
numStars
_tot
=
Lstars
**
3
massStars
=
massDM
*
massStars
#--------------------------------------------------
#File
file
=
h5py
.
File
(
fileName
,
'w'
)
# Header
grp
=
file
.
create_group
(
"/Header"
)
grp
.
attrs
[
"BoxSize"
]
=
boxSize
grp
.
attrs
[
"NumPart_Total"
]
=
[
numGas
,
numDM
,
0
,
0
,
numStars
,
0
]
grp
.
attrs
[
"NumPart_Total_HighWord"
]
=
[
0
,
0
,
0
,
0
,
0
,
0
]
grp
.
attrs
[
"NumPart_ThisFile"
]
=
[
numGas
,
numDM
,
0
,
0
,
numStars
,
0
]
grp
.
attrs
[
"Time"
]
=
0.0
grp
.
attrs
[
"NumFilesPerSnapshot"
]
=
1
grp
.
attrs
[
"MassTable"
]
=
[
0.0
,
massDM
,
0.0
,
0.0
,
0.0
,
0.0
]
grp
.
attrs
[
"Flag_Entropy_ICs"
]
=
0
grp
.
attrs
[
"Dimension"
]
=
3
#Runtime parameters
grp
=
file
.
create_group
(
"/RuntimePars"
)
grp
.
attrs
[
"PeriodicBoundariesOn"
]
=
periodic
#Units
grp
=
file
.
create_group
(
"/Units"
)
grp
.
attrs
[
"Unit length in cgs (U_L)"
]
=
1.
grp
.
attrs
[
"Unit mass in cgs (U_M)"
]
=
1.
grp
.
attrs
[
"Unit time in cgs (U_t)"
]
=
1.
grp
.
attrs
[
"Unit current in cgs (U_I)"
]
=
1.
grp
.
attrs
[
"Unit temperature in cgs (U_T)"
]
=
1.
# Gas Particle group
grp
=
file
.
create_group
(
"/PartType0"
)
v
=
zeros
((
numGas
,
3
))
ds
=
grp
.
create_dataset
(
'Velocities'
,
(
numGas
,
3
),
'f'
)
ds
[()]
=
v
v
=
zeros
(
1
)
m
=
full
((
numGas
,
1
),
massGas
)
ds
=
grp
.
create_dataset
(
'Masses'
,
(
numGas
,
1
),
'f'
)
ds
[()]
=
m
m
=
zeros
(
1
)
h
=
full
((
numGas
,
1
),
eta
*
boxSize
/
Lgas
)
ds
=
grp
.
create_dataset
(
'SmoothingLength'
,
(
numGas
,
1
),
'f'
)
ds
[()]
=
h
h
=
zeros
(
1
)
u
=
full
((
numGas
,
1
),
internalEnergy
)
ds
=
grp
.
create_dataset
(
'InternalEnergy'
,
(
numGas
,
1
),
'f'
)
ds
[()]
=
u
u
=
zeros
(
1
)
ids
=
linspace
(
0
,
numGas
,
numGas
,
endpoint
=
False
).
reshape
((
numGas
,
1
))
ds
=
grp
.
create_dataset
(
'ParticleIDs'
,
(
numGas
,
1
),
'L'
)
ds
[()]
=
ids
+
1
x
=
ids
%
Lgas
;
y
=
((
ids
-
x
)
/
Lgas
)
%
Lgas
;
z
=
(
ids
-
x
-
Lgas
*
y
)
/
Lgas
**
2
;
coords
=
zeros
((
numGas
,
3
))
coords
[:,
0
]
=
z
[:,
0
]
*
boxSize
/
Lgas
+
boxSize
/
(
2
*
Lgas
)
coords
[:,
1
]
=
y
[:,
0
]
*
boxSize
/
Lgas
+
boxSize
/
(
2
*
Lgas
)
coords
[:,
2
]
=
x
[:,
0
]
*
boxSize
/
Lgas
+
boxSize
/
(
2
*
Lgas
)
ds
=
grp
.
create_dataset
(
'Coordinates'
,
(
numGas
,
3
),
'd'
)
ds
[()]
=
coords
# DM Particle group
grp
=
file
.
create_group
(
"/PartType1"
)
v
=
zeros
((
numDM
,
3
))
ds
=
grp
.
create_dataset
(
'Velocities'
,
(
numDM
,
3
),
'f'
)
ds
[()]
=
v
v
=
zeros
(
1
)
m
=
full
((
numDM
,
1
),
massDM
)
ds
=
grp
.
create_dataset
(
'Masses'
,
(
numDM
,
1
),
'f'
)
ds
[()]
=
m
m
=
zeros
(
1
)
ids
=
linspace
(
0
,
numDM
,
numDM
,
endpoint
=
False
).
reshape
((
numDM
,
1
))
ds
=
grp
.
create_dataset
(
'ParticleIDs'
,
(
numDM
,
1
),
'L'
)
ds
[()]
=
ids
+
Lgas
**
3
+
1
x
=
ids
%
Ldm
;
y
=
((
ids
-
x
)
/
Ldm
)
%
Ldm
;
z
=
(
ids
-
x
-
Ldm
*
y
)
/
Ldm
**
2
;
coords
=
zeros
((
numDM
,
3
))
coords
[:,
0
]
=
z
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
1
]
=
y
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
2
]
=
x
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
ds
=
grp
.
create_dataset
(
'Coordinates'
,
(
numDM
,
3
),
'd'
)
ds
[()]
=
coords
# Star Particle group
grp
=
file
.
create_group
(
"/PartType4"
)
v
=
zeros
((
numStars
,
3
))
ds
=
grp
.
create_dataset
(
'Velocities'
,
(
numStars
,
3
),
'f'
)
ds
[()]
=
v
v
=
zeros
(
1
)
m
=
full
((
numStars
,
1
),
massStars
)
ds
=
grp
.
create_dataset
(
'Masses'
,
(
numStars
,
1
),
'f'
)
ds
[()]
=
m
m
=
zeros
(
1
)
ids
=
linspace
(
0
,
numStars
,
numStars
,
endpoint
=
False
).
reshape
((
numStars
,
1
))
ds
=
grp
.
create_dataset
(
'ParticleIDs'
,
(
numStars
,
1
),
'L'
)
ds
[()]
=
ids
+
Lgas
**
3
+
1
x
=
ids
%
Ldm
;
y
=
((
ids
-
x
)
/
Ldm
)
%
Ldm
;
z
=
(
ids
-
x
-
Ldm
*
y
)
/
Ldm
**
2
;
coords
=
zeros
((
numStars
,
3
))
coords
[:,
0
]
=
z
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
1
]
=
y
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
2
]
=
x
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
ds
=
grp
.
create_dataset
(
'Coordinates'
,
(
numStars
,
3
),
'd'
)
ds
[()]
=
coords
file
.
close
()
offsetGas
=
0
offsetDM
=
0
offsetStars
=
0
for
n
in
range
(
num_files
):
# File name
if
num_files
==
1
:
fileName
=
fileBaseName
+
".hdf5"
else
:
fileName
=
fileBaseName
+
".%d.hdf5"
%
n
# File
file
=
h5py
.
File
(
fileName
,
'w'
)
# Number of particles
numGas
=
numGas_tot
/
num_files
numDM
=
numDM_tot
/
num_files
numStars
=
numStars_tot
/
num_files
if
n
==
num_files
-
1
:
numGas
+=
numGas_tot
%
num_files
numDM
+=
numDM_tot
%
num_files
numStars
+=
numStars_tot
%
num_files
# Header
grp
=
file
.
create_group
(
"/Header"
)
grp
.
attrs
[
"BoxSize"
]
=
boxSize
grp
.
attrs
[
"NumPart_Total"
]
=
[
numGas_tot
,
numDM_tot
,
0
,
0
,
numStars_tot
,
0
]
grp
.
attrs
[
"NumPart_Total_HighWord"
]
=
[
0
,
0
,
0
,
0
,
0
,
0
]
grp
.
attrs
[
"NumPart_ThisFile"
]
=
[
numGas
,
numDM
,
0
,
0
,
numStars
,
0
]
grp
.
attrs
[
"Time"
]
=
0.0
grp
.
attrs
[
"NumFilesPerSnapshot"
]
=
num_files
grp
.
attrs
[
"MassTable"
]
=
[
0.0
,
massDM
,
0.0
,
0.0
,
0.0
,
0.0
]
grp
.
attrs
[
"Flag_Entropy_ICs"
]
=
0
grp
.
attrs
[
"Dimension"
]
=
3
#Runtime parameters
grp
=
file
.
create_group
(
"/RuntimePars"
)
grp
.
attrs
[
"PeriodicBoundariesOn"
]
=
periodic
#Units
grp
=
file
.
create_group
(
"/Units"
)
grp
.
attrs
[
"Unit length in cgs (U_L)"
]
=
1.
grp
.
attrs
[
"Unit mass in cgs (U_M)"
]
=
1.
grp
.
attrs
[
"Unit time in cgs (U_t)"
]
=
1.
grp
.
attrs
[
"Unit current in cgs (U_I)"
]
=
1.
grp
.
attrs
[
"Unit temperature in cgs (U_T)"
]
=
1.
# Gas Particle group
grp
=
file
.
create_group
(
"/PartType0"
)
v
=
zeros
((
numGas
,
3
))
ds
=
grp
.
create_dataset
(
'Velocities'
,
(
numGas
,
3
),
'f'
,
data
=
v
)
m
=
full
((
numGas
,
1
),
massGas
)
ds
=
grp
.
create_dataset
(
'Masses'
,
(
numGas
,
1
),
'f'
,
data
=
m
)
h
=
full
((
numGas
,
1
),
eta
*
boxSize
/
Lgas
)
ds
=
grp
.
create_dataset
(
'SmoothingLength'
,
(
numGas
,
1
),
'f'
,
data
=
h
)
u
=
full
((
numGas
,
1
),
internalEnergy
)
ds
=
grp
.
create_dataset
(
'InternalEnergy'
,
(
numGas
,
1
),
'f'
,
data
=
u
)
ids
=
linspace
(
offsetGas
,
offsetGas
+
numGas
,
numGas
,
endpoint
=
False
).
reshape
((
numGas
,
1
))
ds
=
grp
.
create_dataset
(
'ParticleIDs'
,
(
numGas
,
1
),
'L'
,
data
=
ids
+
1
)
x
=
ids
%
Lgas
;
y
=
((
ids
-
x
)
/
Lgas
)
%
Lgas
;
z
=
(
ids
-
x
-
Lgas
*
y
)
/
Lgas
**
2
;
coords
=
zeros
((
numGas
,
3
))
coords
[:,
0
]
=
z
[:,
0
]
*
boxSize
/
Lgas
+
boxSize
/
(
2
*
Lgas
)
coords
[:,
1
]
=
y
[:,
0
]
*
boxSize
/
Lgas
+
boxSize
/
(
2
*
Lgas
)
coords
[:,
2
]
=
x
[:,
0
]
*
boxSize
/
Lgas
+
boxSize
/
(
2
*
Lgas
)
ds
=
grp
.
create_dataset
(
'Coordinates'
,
(
numGas
,
3
),
'd'
,
data
=
coords
)
# DM Particle group
grp
=
file
.
create_group
(
"/PartType1"
)
v
=
zeros
((
numDM
,
3
))
ds
=
grp
.
create_dataset
(
'Velocities'
,
(
numDM
,
3
),
'f'
,
data
=
v
)
m
=
full
((
numDM
,
1
),
massDM
)
ds
=
grp
.
create_dataset
(
'Masses'
,
(
numDM
,
1
),
'f'
,
data
=
m
)
ids
=
linspace
(
offsetDM
,
offsetDM
+
numDM
,
numDM
,
endpoint
=
False
).
reshape
((
numDM
,
1
))
ds
=
grp
.
create_dataset
(
'ParticleIDs'
,
(
numDM
,
1
),
'L'
,
data
=
ids
+
numGas_tot
+
1
)
ds
[()]
=
ids
+
Lgas
**
3
+
1
x
=
ids
%
Ldm
;
y
=
((
ids
-
x
)
/
Ldm
)
%
Ldm
;
z
=
(
ids
-
x
-
Ldm
*
y
)
/
Ldm
**
2
;
coords
=
zeros
((
numDM
,
3
))
coords
[:,
0
]
=
z
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
1
]
=
y
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
2
]
=
x
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
ds
=
grp
.
create_dataset
(
'Coordinates'
,
(
numDM
,
3
),
'd'
,
data
=
coords
)
# Star Particle group
grp
=
file
.
create_group
(
"/PartType4"
)
v
=
zeros
((
numStars
,
3
))
ds
=
grp
.
create_dataset
(
'Velocities'
,
(
numStars
,
3
),
'f'
,
data
=
v
)
m
=
full
((
numStars
,
1
),
massStars
)
ds
=
grp
.
create_dataset
(
'Masses'
,
(
numStars
,
1
),
'f'
,
data
=
m
)
ids
=
linspace
(
0
,
numStars
,
numStars
,
endpoint
=
False
).
reshape
((
numStars
,
1
))
ds
=
grp
.
create_dataset
(
'ParticleIDs'
,
(
numStars
,
1
),
'L'
,
data
=
ids
+
numGas_tot
+
numDM_tot
+
1
)
x
=
ids
%
Ldm
;
y
=
((
ids
-
x
)
/
Ldm
)
%
Ldm
;
z
=
(
ids
-
x
-
Ldm
*
y
)
/
Ldm
**
2
;
coords
=
zeros
((
numStars
,
3
))
coords
[:,
0
]
=
z
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
1
]
=
y
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
coords
[:,
2
]
=
x
[:,
0
]
*
boxSize
/
Ldm
+
boxSize
/
(
2
*
Ldm
)
ds
=
grp
.
create_dataset
(
'Coordinates'
,
(
numStars
,
3
),
'd'
,
data
=
coords
)
# Shift stuff
offsetGas
+=
numGas
offsetDM
+=
numDM
offsetStars
+=
numStars
file
.
close
()
examples/MultiTypes/multiTypes.yml
View file @
1aaf8f0d
...
...
@@ -32,6 +32,7 @@ SPH:
# Parameters related to the initial conditions
InitialConditions
:
file_name
:
./multiTypes.hdf5
# The file to read
replicate
:
2
# Replicate all particles twice along each axis
# External potential parameters
PointMassPotential
:
...
...
examples/MultiTypes/run.sh
View file @
1aaf8f0d
...
...
@@ -4,7 +4,7 @@
if
[
!
-e
multiTypes.hdf5
]
then
echo
"Generating initial conditions for the multitype box example..."
python makeIC.py
17 24
1
2
python makeIC.py
9 13 7
1
fi
../swift
-s
-g
-S
-t
1 multiTypes.yml 2>&1 |
tee
output.log
examples/main.c
View file @
1aaf8f0d
...
...
@@ -54,7 +54,7 @@ struct profiler prof;
void
print_help_message
()
{
printf
(
"
\n
Usage: swift [OPTION]... PARAMFILE
\n
"
);
printf
(
" swift_mpi [OPTION]... PARAMFILE
\n
"
);
printf
(
" swift_mpi [OPTION]... PARAMFILE
\n
\n
"
);
printf
(
"Valid options are:
\n
"
);
printf
(
" %2s %8s %s
\n
"
,
"-a"
,
""
,
"Pin runners using processor affinity"
);
...
...
@@ -371,6 +371,8 @@ int main(int argc, char *argv[]) {
/* Read particles and space information from (GADGET) ICs */
char
ICfileName
[
200
]
=
""
;
parser_get_param_string
(
params
,
"InitialConditions:file_name"
,
ICfileName
);
const
int
replicate
=
parser_get_opt_param_int
(
params
,
"InitialConditions:replicate"
,
1
);
if
(
myrank
==
0
)
message
(
"Reading ICs from file '%s'"
,
ICfileName
);
fflush
(
stdout
);
...
...
@@ -441,7 +443,7 @@ int main(int argc, char *argv[]) {
if
(
myrank
==
0
)
clocks_gettime
(
&
tic
);
struct
space
s
;
space_init
(
&
s
,
params
,
dim
,
parts
,
gparts
,
sparts
,
Ngas
,
Ngpart
,
Nspart
,
periodic
,
with_self_gravity
,
talking
,
dry_run
);
periodic
,
replicate
,
with_self_gravity
,
talking
,
dry_run
);
if
(
myrank
==
0
)
{
clocks_gettime
(
&
toc
);
message
(
"space_init took %.3f %s."
,
clocks_diff
(
&
tic
,
&
toc
),
...
...
@@ -458,6 +460,7 @@ int main(int argc, char *argv[]) {
s
.
cdim
[
1
],
s
.
cdim
[
2
]);
message
(
"%zi parts in %i cells."
,
s
.
nr_parts
,
s
.
tot_cells
);
message
(
"%zi gparts in %i cells."
,
s
.
nr_gparts
,
s
.
tot_cells
);
message
(
"%zi sparts in %i cells."
,
s
.
nr_sparts
,
s
.
tot_cells
);
message
(
"maximum depth is %d."
,
s
.
maxdepth
);
fflush
(
stdout
);
}
...
...
@@ -521,6 +524,18 @@ int main(int argc, char *argv[]) {
for
(
k
=
0
;
k
<
runner_hist_N
;
k
++
)
runner_hist_bins
[
k
]
=
0
;
#endif
#if defined(WITH_MPI)
N_long
[
0
]
=
s
.
nr_parts
;
N_long
[
1
]
=
s
.
nr_gparts
;
N_long
[
2
]
=
s
.
nr_sparts
;
MPI_Reduce
(
&
N_long
,
&
N_total
,
3
,
MPI_LONG_LONG_INT
,
MPI_SUM
,
0
,
MPI_COMM_WORLD
);
#else
N_total
[
0
]
=
s
.
nr_parts
;
N_total
[
1
]
=
s
.
nr_gparts
;
N_total
[
2
]
=
s
.
nr_sparts
;
#endif
/* Get some info to the user. */
if
(
myrank
==
0
)
{
long
long
N_DM
=
N_total
[
1
]
-
N_total
[
2
]
-
N_total
[
0
];
...
...
examples/parameter_example.yml
View file @
1aaf8f0d
...
...
@@ -55,6 +55,7 @@ InitialConditions:
shift_x
:
0.
# (Optional) A shift to apply to all particles read from the ICs (in internal units).
shift_y
:
0.
shift_z
:
0.
replicate
:
2
# (Optional) Replicate all particles along each axis a given number of times. Default 1.
# Parameters governing domain decomposition
DomainDecomposition
:
...
...
src/Makefile.am
View file @
1aaf8f0d
...
...
@@ -45,7 +45,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
physical_constants.h physical_constants_cgs.h potential.h version.h
\
hydro_properties.h riemann.h threadpool.h cooling.h cooling_struct.h sourceterms.h
\
sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h
\
dump.h logger.h active.h timeline.h
dump.h logger.h active.h timeline.h
xmf.h
# Common source files
AM_SOURCES
=
space.c runner.c queue.c task.c cell.c engine.c
\
...
...
@@ -54,7 +54,8 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
kernel_hydro.c tools.c part.c partition.c clocks.c parser.c
\
physical_constants.c potential.c hydro_properties.c
\
runner_doiact_fft.c threadpool.c cooling.c sourceterms.c
\
statistics.c runner_doiact_vec.c profiler.c dump.c logger.c
statistics.c runner_doiact_vec.c profiler.c dump.c logger.c
\
part_type.c xmf.c
# Include files for distribution, not installation.
nobase_noinst_HEADERS
=
align.h approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h
\
...
...
@@ -109,15 +110,18 @@ version_string.h: version_string.h.in $(AM_SOURCES) $(include_HEADERS) $(noinst_
if
test
"X
$(GIT_CMD)
"
!=
"X"
;
then
\
GIT_REVISION
=
`
$(GIT_CMD)
describe
--abbrev
=
8
--always
--tags
--dirty
`
;
\
GIT_BRANCH
=
`
$(GIT_CMD)
branch |
sed
-n
's/^\* \(.*\)/\1/p'
`
;
\
GIT_DATE
=
`
$(GIT_CMD)
log
-1
--format
=
%ci
`
;
\
sed
-e
"s,@PACKAGE_VERSION
\@
,
$(PACKAGE_VERSION)
,"
\
-e
"s,@GIT_REVISION
\@
,
$
${GIT_REVISION}
,"
\
-e
"s|@GIT_BRANCH
\@
|
$
${GIT_BRANCH}
|"
\
-e
"s|@GIT_DATE
\@
|
$
${GIT_DATE}
|"
\
-e
"s|@SWIFT_CFLAGS
\@
|
$(CFLAGS)
|"
$<
>
version_string.h
;
\
else
\
if
test
!
-f
version_string.h
;
then
\
sed
-e
"s,@PACKAGE_VERSION
\@
,
$(PACKAGE_VERSION)
,"
\
-e
"s,@GIT_REVISION
\@
,unknown,"
\
-e
"s,@GIT_BRANCH
\@
,unknown,"
\
-e
"s,@GIT_DATE
\@
,unknown,"
\
-e
"s|@SWIFT_CFLAGS
\@
|
$(CFLAGS)
|"
$<
>
version_string.h
;
\
fi
;
\
fi
...
...
src/common_io.c
View file @
1aaf8f0d
...
...
@@ -47,9 +47,6 @@
#include
"units.h"
#include
"version.h"
const
char
*
particle_type_names
[
NUM_PARTICLE_TYPES
]
=
{
"Gas"
,
"DM"
,
"Boundary"
,
"Dummy"
,
"Star"
,
"BH"
};
/**
* @brief Converts a C data type to the HDF5 equivalent.
*
...
...
@@ -57,7 +54,7 @@ const char* particle_type_names[NUM_PARTICLE_TYPES] = {
* to change the exact storage types matching the code types in a transparent
*way.
*/
hid_t
hdf5
T
ype
(
enum
DATA_TYPE
type
)
{
hid_t
io_
hdf5
_t
ype
(
enum
IO_
DATA_TYPE
type
)
{
switch
(
type
)
{
case
INT
:
...
...
@@ -87,7 +84,7 @@ hid_t hdf5Type(enum DATA_TYPE type) {
/**
* @brief Returns the memory size of the data type
*/
size_t
size
OfT
ype
(
enum
DATA_TYPE
type
)
{
size_t
io_
size
of_t
ype
(
enum
IO_
DATA_TYPE
type
)
{
switch
(
type
)
{
case
INT
:
...
...
@@ -119,7 +116,7 @@ size_t sizeOfType(enum DATA_TYPE type) {
*
* Returns an error if the type is not FLOAT or DOUBLE
*/
int
i
sD
ouble
P
recision
(
enum
DATA_TYPE
type
)
{
int
i
o_is_d
ouble
_p
recision
(
enum
IO_
DATA_TYPE
type
)
{
switch
(
type
)
{
case
FLOAT
:
...
...
@@ -142,7 +139,8 @@ int isDoublePrecision(enum DATA_TYPE type) {
*
* Calls #error() if an error occurs.
*/
void
readAttribute
(
hid_t
grp
,
char
*
name
,
enum
DATA_TYPE
type
,
void
*
data
)
{
void
io_read_attribute
(
hid_t
grp
,
char
*
name
,
enum
IO_DATA_TYPE
type
,
void
*
data
)
{
hid_t
h_attr
=
0
,
h_err
=
0
;
h_attr
=
H5Aopen
(
grp
,
name
,
H5P_DEFAULT
);
...
...
@@ -150,7 +148,7 @@ void readAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data) {
error
(
"Error while opening attribute '%s'"
,
name
);
}
h_err
=
H5Aread
(
h_attr
,
hdf5
T
ype
(
type
),
data
);
h_err
=
H5Aread
(
h_attr
,
io_
hdf5
_t
ype
(
type
),
data
);
if
(
h_err
<
0
)
{
error
(
"Error while reading attribute '%s'"
,
name
);
}
...
...
@@ -169,8 +167,8 @@ void readAttribute(hid_t grp, char* name, enum DATA_TYPE type, void* data) {
*
* Calls #error() if an error occurs.
*/
void
write
A
ttribute
(
hid_t
grp
,
const
char
*
name
,
enum
DATA_TYPE
type
,
void
*
data
,
int
num
)
{
void
io_
write
_a
ttribute
(
hid_t
grp
,
const
char
*
name
,
enum
IO_
DATA_TYPE
type
,
void
*
data
,
int
num
)
{
hid_t
h_space
=
0
,
h_attr
=
0
,
h_err
=
0
;
hsize_t
dim
[
1
]
=
{
num
};
...
...
@@ -184,12 +182,12 @@ void writeAttribute(hid_t grp, const char* name, enum DATA_TYPE type,
error
(
"Error while changing dataspace shape for attribute '%s'."
,
name
);
}
h_attr
=
H5Acreate1
(
grp
,
name
,
hdf5
T
ype
(
type
),
h_space
,
H5P_DEFAULT
);
h_attr
=
H5Acreate1
(
grp
,
name
,
io_
hdf5
_t
ype
(
type
),
h_space
,
H5P_DEFAULT
);
if
(
h_attr
<
0
)
{
error
(
"Error while creating attribute '%s'."
,
name
);
}
h_err
=
H5Awrite
(
h_attr
,
hdf5
T
ype
(
type
),
data
);
h_err
=
H5Awrite
(
h_attr
,
io_
hdf5
_t
ype
(
type
),
data
);
if
(
h_err
<
0
)
{
error
(
"Error while reading attribute '%s'."
,
name
);
}
...
...
@@ -208,8 +206,8 @@ void writeAttribute(hid_t grp, const char* name, enum DATA_TYPE type,
*
* Calls #error() if an error occurs.
*/
void
writeStringAttribute
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
,
int
length
)
{
void
io_
writeStringAttribute
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
,
int
length
)
{
hid_t
h_space
=
0
,
h_attr
=
0
,
h_err
=
0
,
h_type
=
0
;
h_space
=
H5Screate
(
H5S_SCALAR
);
...
...
@@ -248,8 +246,8 @@ void writeStringAttribute(hid_t grp, const char* name, const char* str,
* @param name The name of the attribute
* @param data The value to write
*/
void
write
A
ttribute_d
(
hid_t
grp
,
const
char
*
name
,
double
data
)
{
write
A
ttribute
(
grp
,
name
,
DOUBLE
,
&
data
,
1
);
void
io_
write
_a
ttribute_d
(
hid_t
grp
,
const
char
*
name
,
double
data
)
{
io_
write
_a
ttribute
(
grp
,
name
,
DOUBLE
,
&
data
,
1
);
}
/**
...
...
@@ -258,8 +256,8 @@ void writeAttribute_d(hid_t grp, const char* name, double data) {
* @param name The name of the attribute
* @param data The value to write
*/
void
write
A
ttribute_f
(
hid_t
grp
,
const
char
*
name
,
float
data
)
{
write
A
ttribute
(
grp
,
name
,
FLOAT
,
&
data
,
1
);
void
io_
write
_a
ttribute_f
(
hid_t
grp
,
const
char
*
name
,
float
data
)
{
io_
write
_a
ttribute
(
grp
,
name
,
FLOAT
,
&
data
,
1
);
}
/**
...
...
@@ -269,8 +267,8 @@ void writeAttribute_f(hid_t grp, const char* name, float data) {
* @param data The value to write
*/
void
write
A
ttribute_i
(
hid_t
grp
,
const
char
*
name
,
int
data
)
{
write
A
ttribute
(
grp
,
name
,
INT
,
&
data
,
1
);
void
io_
write
_a
ttribute_i
(
hid_t
grp
,
const
char
*
name
,
int
data
)
{
io_
write
_a
ttribute
(
grp
,
name
,
INT
,
&
data
,
1
);
}
/**
...
...
@@ -279,8 +277,8 @@ void writeAttribute_i(hid_t grp, const char* name, int data) {
* @param name The name of the attribute
* @param data The value to write
*/
void
write
A
ttribute_l
(
hid_t
grp
,
const
char
*
name
,
long
data
)
{
write
A
ttribute
(
grp
,
name
,
LONG
,
&
data
,
1
);
void
io_
write
_a
ttribute_l
(
hid_t
grp
,
const
char
*
name
,
long
data
)
{
io_
write
_a
ttribute
(
grp
,
name
,
LONG
,
&
data
,
1
);
}
/**
...
...
@@ -289,8 +287,8 @@ void writeAttribute_l(hid_t grp, const char* name, long data) {
* @param name The name of the attribute
* @param str The string to write
*/
void
write
A
ttribute_s
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
)
{
writeStringAttribute
(
grp
,
name
,
str
,
strlen
(
str
));
void
io_
write
_a
ttribute_s
(
hid_t
grp
,
const
char
*
name
,
const
char
*
str
)
{
io_
writeStringAttribute
(
grp
,
name
,
str
,
strlen
(
str
));
}
/**
...
...
@@ -300,7 +298,7 @@ void writeAttribute_s(hid_t grp, const char* name, const char* str) {
*
* If the 'Units' group does not exist in the ICs, cgs units will be assumed
*/
void
readUnitSystem
(
hid_t
h_file
,
struct
UnitSystem
*
us
)
{
void
io_
read
_
UnitSystem
(
hid_t
h_file
,
struct
UnitSystem
*
us
)
{
hid_t
h_grp
=
H5Gopen
(
h_file
,
"/Units"
,
H5P_DEFAULT
);
...
...
@@ -318,14 +316,16 @@ void readUnitSystem(hid_t h_file, struct UnitSystem* us) {
}
/* Ok, Read the damn thing */
readAttribute
(
h_grp
,
"Unit length in cgs (U_L)"
,
DOUBLE
,
&
us
->
UnitLength_in_cgs
);
readAttribute
(
h_grp
,
"Unit mass in cgs (U_M)"
,
DOUBLE
,
&
us
->
UnitMass_in_cgs
);
readAttribute
(
h_grp
,
"Unit time in cgs (U_t)"
,
DOUBLE
,
&
us
->
UnitTime_in_cgs
);
readAttribute
(
h_grp
,
"Unit current in cgs (U_I)"
,
DOUBLE
,
&
us
->
UnitCurrent_in_cgs
);
readAttribute
(
h_grp
,
"Unit temperature in cgs (U_T)"
,
DOUBLE
,
&
us
->
UnitTemperature_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit length in cgs (U_L)"
,
DOUBLE
,
&
us
->
UnitLength_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit mass in cgs (U_M)"
,
DOUBLE
,
&
us
->
UnitMass_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit time in cgs (U_t)"
,
DOUBLE
,
&
us
->
UnitTime_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit current in cgs (U_I)"
,
DOUBLE
,
&
us
->
UnitCurrent_in_cgs
);
io_read_attribute
(
h_grp
,
"Unit temperature in cgs (U_T)"
,
DOUBLE
,
&
us
->
UnitTemperature_in_cgs
);
/* Clean up */
H5Gclose
(
h_grp
);
...
...
@@ -337,23 +337,23 @@ void readUnitSystem(hid_t h_file, struct UnitSystem* us) {
* @param us The UnitSystem to dump
* @param groupName The name of the HDF5 group to write to
*/
void
writeUnitSystem
(
hid_t
h_file
,
const
struct
UnitSystem
*
us
,
const
char
*
groupName
)
{
void
io_
write
_
UnitSystem
(
hid_t
h_file
,
const
struct
UnitSystem
*
us
,
const
char
*
groupName
)
{
hid_t
h_grpunit
=
0
;
h_grpunit
=
H5Gcreate1
(
h_file
,
groupName
,
0
);
if
(
h_grpunit
<
0
)
error
(
"Error while creating Unit System group"
);
write
A
ttribute_d
(
h_grpunit
,
"Unit mass in cgs (U_M)"
,
units_get_base_unit
(
us
,
UNIT_MASS
));
write
A
ttribute_d
(
h_grpunit
,
"Unit length in cgs (U_L)"
,
units_get_base_unit
(
us
,
UNIT_LENGTH
));
write
A
ttribute_d
(
h_grpunit
,
"Unit time in cgs (U_t)"
,
units_get_base_unit
(
us
,
UNIT_TIME
));
write
A
ttribute_d
(
h_grpunit
,
"Unit current in cgs (U_I)"
,
units_get_base_unit
(
us
,
UNIT_CURRENT
));
write
A
ttribute_d
(
h_grpunit
,
"Unit temperature in cgs (U_T)"
,
units_get_base_unit
(
us
,
UNIT_TEMPERATURE
));
io_
write
_a
ttribute_d
(
h_grpunit
,
"Unit mass in cgs (U_M)"
,
units_get_base_unit
(
us
,
UNIT_MASS
));
io_
write
_a
ttribute_d
(
h_grpunit
,
"Unit length in cgs (U_L)"
,