12#include "gadgetconfig.h"
25#include "../cooling_sfr/cooling.h"
26#include "../data/allvars.h"
27#include "../data/dtypes.h"
28#include "../data/mymalloc.h"
29#include "../fof/fof.h"
30#include "../io/hdf5_util.h"
32#include "../logs/timer.h"
33#include "../main/main.h"
34#include "../main/simulation.h"
35#include "../mergertree/io_readsnap.h"
36#include "../mergertree/mergertree.h"
37#include "../mpi_utils/mpi_utils.h"
38#include "../system/system.h"
40readsnap_io::readsnap_io(mergertree *MergerTree_ptr, MPI_Comm comm,
int format) :
IO_Def(comm, format)
42 MergerTree = MergerTree_ptr;
44 this->N_IO_Fields = 0;
45 this->N_DataGroups =
NTYPES;
46 this->header_size =
sizeof(header);
47 this->header_buf = &header;
49 sprintf(this->info,
"MERGERTREE: reading snapshot IDs");
79void readsnap_io::mergertree_read_snap_ids(
int num)
90 int num_files = find_files(fname, fname_multiple);
93 strcpy(fname, fname_multiple);
99 for(
int rep = 0; rep < 2; rep++)
101 MergerTree->MtrP_NumPart = 0;
103 read_files_driver(fname, rep, num_files);
108 MergerTree->MtrP = (mergertree::mergertree_particle_data *)
Mem.mymalloc_movable_clear(
109 &MergerTree->MtrP,
"MtrP", (MergerTree->MtrP_NumPart + 1) *
sizeof(mergertree::mergertree_particle_data));
113 MPI_Barrier(Communicator);
115 mpi_printf(
"READSNAPID: reading done.\n");
120void readsnap_io::fill_file_header(
int writeTask,
int lastTask,
long long *n_type,
long long *ntot_type)
124void readsnap_io::read_file_header(
const char *fname,
int filenr,
int readTask,
int lastTask,
long long *n_type,
long long *ntot_type,
127 if(ThisTask == readTask)
129 if(filenr == 0 && nstart == NULL)
132 "\nREADSNAPID: filenr=%d, '%s' contains:\n"
133 "READSNAPID: Type 0 (gas): %8lld (tot=%15lld) masstab= %g\n",
134 filenr, fname, (
long long)header.npart[0], (
long long)header.npartTotal[0],
All.
MassTable[0]);
136 for(
int type = 1; type <
NTYPES; type++)
138 mpi_printf(
"READSNAPID: Type %d: %8lld (tot=%15lld) masstab= %g\n", type, (
long long)header.npart[type],
139 (
long long)header.npartTotal[type],
All.
MassTable[type]);
150 for(
int type = 0; type <
NTYPES; type++)
152 ntot_type[type] = header.npart[type];
154 long long n_in_file = header.npart[type];
155 int ntask = lastTask - readTask + 1;
156 int n_for_this_task = n_in_file / ntask;
157 if((ThisTask - readTask) < (n_in_file % ntask))
160 n_type[type] = n_for_this_task;
162 nall += n_for_this_task;
167 memmove(&MergerTree->MtrP[nall], &MergerTree->MtrP[0], MergerTree->MtrP_NumPart *
sizeof(mergertree::mergertree_particle_data));
172void readsnap_io::write_header_fields(hid_t handle)
180void readsnap_io::read_header_fields(
const char *fname)
182 for(
int i = 0; i <
NTYPES; i++)
185 header.npartTotal[i] = 0;
191 hid_t hdf5_file =
my_H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
192 hid_t handle =
my_H5Gopen(hdf5_file,
"/Header");
196 hid_t space = H5Aget_space(hdf5_attribute);
198 H5Sget_simple_extent_dims(space, &dims, &len);
201 Terminate(
"Length of NumPart_ThisFile attribute (%d) does not match NTYPES(ICS) (%d)", (
int)len, (
int)ntypes);
224int readsnap_io::get_filenr_from_header(
void) {
return header.num_files; }
226void readsnap_io::set_filenr_in_header(
int numfiles) { header.num_files = numfiles; }
228void readsnap_io::read_increase_numbers(
int type,
int n_for_this_task) { MergerTree->MtrP_NumPart += n_for_this_task; }
230void readsnap_io::get_datagroup_name(
int type,
char *buf) { sprintf(buf,
"/PartType%d", type); }
232int readsnap_io::get_type_of_element(
int index) {
return MergerTree->MtrP[index].Type; }
234void readsnap_io::set_type_of_element(
int index,
int type) { MergerTree->MtrP[index].Type = type; }
236void *readsnap_io::get_base_address_of_structure(
enum arrays array,
int index)
241 return (
void *)(MergerTree->MtrP + index);
243 Terminate(
"we don't expect to get here");
global_data_all_processes All
#define MAXLEN_PATH_EXTRA
hid_t my_H5Gopen(hid_t loc_id, const char *groupname)
hid_t my_H5Fopen(const char *fname, unsigned int flags, hid_t fapl_id)
herr_t my_H5Gclose(hid_t group_id, const char *groupname)
void read_vector_attribute(hid_t handle, const char *attr_name, void *buf, hid_t mem_type_id, int length)
herr_t my_H5Fclose(hid_t file_id, const char *fname)
hid_t my_H5Aopen_name(hid_t loc_id, const char *attr_name)
herr_t my_H5Aclose(hid_t attr_id, const char *attr_name)
void read_scalar_attribute(hid_t handle, const char *attr_name, void *buf, hid_t mem_type_id)
#define TIMER_START(counter)
Starts the timer counter.
#define TIMER_STOP(counter)
Stops the timer counter.
char OutputDir[MAXLEN_PATH]
char SnapshotFileBase[MAXLEN_PATH]