12#include "gadgetconfig.h"
14#ifdef SUBFIND_ORPHAN_TREATMENT
25#include "../cooling_sfr/cooling.h"
26#include "../data/allvars.h"
27#include "../data/dtypes.h"
28#include "../data/mymalloc.h"
29#include "../data/particle_data.h"
30#include "../fof/fof.h"
31#include "../io/hdf5_util.h"
33#include "../logs/timer.h"
34#include "../main/main.h"
35#include "../main/simulation.h"
36#include "../mergertree/io_readsnap.h"
37#include "../mergertree/mergertree.h"
38#include "../mpi_utils/mpi_utils.h"
39#include "../subfind/subfind_readid_io.h"
40#include "../system/system.h"
42subreadid_io::subreadid_io(idstoredata *IdStore_ptr, MPI_Comm comm,
int format) :
IO_Def(comm, format)
44 IdStore = IdStore_ptr;
46 this->N_IO_Fields = 0;
47 this->N_DataGroups =
NTYPES;
48 this->header_size =
sizeof(header);
49 this->header_buf = &header;
51 sprintf(this->info,
"MERGERTREE: reading snapshot IDs");
53 init_field(
"ID ",
"ParticleIDs",
MEM_MY_ID_TYPE,
FILE_MY_ID_TYPE,
READ_IF_PRESENT, 1,
A_IDS, IdStore->ID, NULL,
ALL_TYPES, 0, 0, 0,
78void subreadid_io::previously_bound_read_snap_ids(
int num)
89 int num_files = find_files(fname, fname_multiple);
92 strcpy(fname, fname_multiple);
98 for(
int rep = 0; rep < 2; rep++)
100 IdStore->NumPart = 0;
102 read_files_driver(fname, rep, num_files);
107 IdStore->ID = (
MyIDType *)
Mem.mymalloc_movable_clear(&IdStore->ID,
"IdStore->ID", IdStore->NumPart *
sizeof(
MyIDType));
111 MPI_Barrier(Communicator);
113 mpi_printf(
"READSNAPID: reading done.\n");
118void subreadid_io::fill_file_header(
int writeTask,
int lastTask,
long long *n_type,
long long *ntot_type)
122void subreadid_io::read_file_header(
const char *fname,
int filenr,
int readTask,
int lastTask,
long long *n_type,
long long *ntot_type,
125 if(ThisTask == readTask)
127 if(filenr == 0 && nstart == NULL)
130 "\nREADSNAPID: filenr=%d, '%s' contains:\n"
131 "READSNAPID: Type 0 (gas): %8lld (tot=%15lld) masstab= %g\n",
132 filenr, fname, (
long long)header.npart[0], (
long long)header.npartTotal[0],
All.
MassTable[0]);
134 for(
int type = 1; type <
NTYPES; type++)
136 mpi_printf(
"READSNAPID: Type %d: %8lld (tot=%15lld) masstab= %g\n", type, (
long long)header.npart[type],
137 (
long long)header.npartTotal[type],
All.
MassTable[type]);
148 for(
int type = 0; type <
NTYPES; type++)
150 ntot_type[type] = header.npart[type];
152 long long n_in_file = header.npart[type];
153 int ntask = lastTask - readTask + 1;
154 int n_for_this_task = n_in_file / ntask;
155 if((ThisTask - readTask) < (n_in_file % ntask))
158 n_type[type] = n_for_this_task;
160 nall += n_for_this_task;
165 memmove(&IdStore->ID[nall], &IdStore->ID[0], IdStore->NumPart *
sizeof(
MyIDType));
171void subreadid_io::write_header_fields(hid_t handle)
179void subreadid_io::read_header_fields(
const char *fname)
181 for(
int i = 0; i <
NTYPES; i++)
184 header.npartTotal[i] = 0;
190 hid_t hdf5_file =
my_H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
191 hid_t handle =
my_H5Gopen(hdf5_file,
"/Header");
195 hid_t space = H5Aget_space(hdf5_attribute);
197 H5Sget_simple_extent_dims(space, &dims, &len);
200 Terminate(
"Length of NumPart_ThisFile attribute (%d) does not match NTYPES(ICS) (%d)", (
int)len, (
int)ntypes);
231int subreadid_io::get_filenr_from_header(
void) {
return header.num_files; }
233void subreadid_io::set_filenr_in_header(
int numfiles) { header.num_files = numfiles; }
235void subreadid_io::read_increase_numbers(
int type,
int n_for_this_task) { IdStore->NumPart += n_for_this_task; }
237void subreadid_io::get_datagroup_name(
int type,
char *buf) { sprintf(buf,
"/PartType%d", type); }
239int subreadid_io::get_type_of_element(
int index) {
return 0; }
241void subreadid_io::set_type_of_element(
int index,
int type)
245void *subreadid_io::get_base_address_of_structure(
enum arrays array,
int index)
250 return (
void *)(IdStore->ID + index);
252 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]