common_io.h 3.39 KB
Newer Older
1
2
/*******************************************************************************
 * This file is part of SWIFT.
3
 * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk),
4
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk).
5
 *
6
7
8
9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
10
 *
11
12
13
14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
15
 *
16
17
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 ******************************************************************************/
20
21
#ifndef SWIFT_COMMON_IO_H
#define SWIFT_COMMON_IO_H
22
23
24
25

/* Config parameters. */
#include "../config.h"

26
/* Local includes. */
27
28
#include "part.h"
#include "units.h"
29

30
31
32
#define FIELD_BUFFER_SIZE 200
#define PARTICLE_GROUP_BUFFER_SIZE 50
#define FILENAME_BUFFER_SIZE 150
33
#define IO_BUFFER_ALIGNMENT 1024
34

35
36
37
38
/* Avoid cyclic inclusion problems */
struct io_props;
struct engine;

39
40
#if defined(HAVE_HDF5)

41
42
43
44
45
/**
 * @brief The different types of data used in the GADGET IC files.
 *
 * (This is admittedly a poor substitute to C++ templates...)
 */
46
enum IO_DATA_TYPE {
47
48
49
50
51
52
53
54
55
56
  INT,
  LONG,
  LONGLONG,
  UINT,
  ULONG,
  ULONGLONG,
  FLOAT,
  DOUBLE,
  CHAR
};
57

58
59
60
hid_t io_hdf5_type(enum IO_DATA_TYPE type);
size_t io_sizeof_type(enum IO_DATA_TYPE type);
int io_is_double_precision(enum IO_DATA_TYPE type);
61

62
63
void io_read_attribute(hid_t grp, char* name, enum IO_DATA_TYPE type,
                       void* data);
64

65
66
void io_write_attribute(hid_t grp, const char* name, enum IO_DATA_TYPE type,
                        void* data, int num);
67

68
69
70
71
72
void io_write_attribute_d(hid_t grp, const char* name, double data);
void io_write_attribute_f(hid_t grp, const char* name, float data);
void io_write_attribute_i(hid_t grp, const char* name, int data);
void io_write_attribute_l(hid_t grp, const char* name, long data);
void io_write_attribute_s(hid_t grp, const char* name, const char* str);
73

74
void io_write_code_description(hid_t h_file);
75

76
void io_read_unit_system(hid_t h_file, struct unit_system* us, int mpi_rank);
77
78
void io_write_unit_system(hid_t h_grp, const struct unit_system* us,
                          const char* groupName);
79

80
81
82
83
84
void io_copy_temp_buffer(void* temp, const struct engine* e,
                         const struct io_props props, size_t N,
                         const struct unit_system* internal_units,
                         const struct unit_system* snapshot_units);

85
#endif /* defined HDF5 */
86

87
88
89
90
91
92
93
94
95
96
void io_collect_dm_gparts(const struct gpart* const gparts, size_t Ntot,
                          struct gpart* const dmparts, size_t Ndm);
void io_prepare_dm_gparts(struct gpart* const gparts, size_t Ndm);
void io_duplicate_hydro_gparts(struct part* const parts,
                               struct gpart* const gparts, size_t Ngas,
                               size_t Ndm);
void io_duplicate_star_gparts(struct spart* const sparts,
                              struct gpart* const gparts, size_t Nstars,
                              size_t Ndm);

97
#endif /* SWIFT_COMMON_IO_H */