@@ -89,17 +89,41 @@ void read_array_serial(hid_t grp, const struct io_props props, size_t N,
8989 long long N_total , long long offset ,
9090 const struct unit_system * internal_units ,
9191 const struct unit_system * ic_units , int cleanup_h ,
92- int cleanup_sqrt_a , double h , double a ) {
92+ int cleanup_sqrt_a , double h , double a ,
93+ const int accept_snapshot ) {
9394
9495 const size_t typeSize = io_sizeof_type (props .type );
9596 const size_t copySize = typeSize * props .dimension ;
9697 const size_t num_elements = N * props .dimension ;
9798
99+ const char * dataset_name = props .name ;
100+
98101 /* Check whether the dataspace exists or not */
99- const htri_t exist = H5Lexists (grp , props . name , 0 );
102+ htri_t exist = H5Lexists (grp , dataset_name , 0 );
100103 if (exist < 0 ) {
101- error ("Error while checking the existence of data set '%s'." , props .name );
102- } else if (exist == 0 ) {
104+ error ("Error while checking the existence of data set '%s'." , dataset_name );
105+ }
106+
107+ if (exist == 0 ) {
108+ const char * alias = io_get_input_field_alias (props .name );
109+ if (alias != NULL ) {
110+ const htri_t alias_exist = H5Lexists (grp , alias , 0 );
111+ if (alias_exist < 0 ) {
112+ error ("Error while checking the existence of data set '%s'." , alias );
113+ } else if (alias_exist > 0 && accept_snapshot ) {
114+ dataset_name = alias ;
115+ exist = alias_exist ;
116+ } else if (alias_exist > 0 && props .importance == COMPULSORY ) {
117+ error (
118+ "Compulsory data set '%s' not present in the file. Found snapshot "
119+ "field '%s' instead. Set InitialConditions:accept_snapshot to 1 "
120+ "to accept snapshot field names." ,
121+ props .name , alias );
122+ }
123+ }
124+ }
125+
126+ if (exist == 0 ) {
103127 if (props .importance == COMPULSORY ) {
104128 error ("Compulsory data set '%s' not present in the file." , props .name );
105129 } else {
@@ -122,8 +146,8 @@ void read_array_serial(hid_t grp, const struct io_props props, size_t N,
122146 /* fflush(stdout); */
123147
124148 /* Open data space */
125- const hid_t h_data = H5Dopen (grp , props . name , H5P_DEFAULT );
126- if (h_data < 0 ) error ("Error while opening data space '%s'." , props . name );
149+ const hid_t h_data = H5Dopen (grp , dataset_name , H5P_DEFAULT );
150+ if (h_data < 0 ) error ("Error while opening data space '%s'." , dataset_name );
127151
128152 /* Allocate temporary buffer */
129153 void * temp = malloc (num_elements * typeSize );
@@ -158,7 +182,7 @@ void read_array_serial(hid_t grp, const struct io_props props, size_t N,
158182 /* Using HDF5 dataspaces would be better */
159183 const hid_t h_err = H5Dread (h_data , io_hdf5_type (props .type ), h_memspace ,
160184 h_filespace , H5P_DEFAULT , temp );
161- if (h_err < 0 ) error ("Error while reading data array '%s'." , props . name );
185+ if (h_err < 0 ) error ("Error while reading data array '%s'." , dataset_name );
162186
163187 /* Unit conversion if necessary */
164188 const double factor =
@@ -569,7 +593,8 @@ void read_ic_serial(char *fileName, const struct unit_system *internal_units,
569593 const int cleanup_sqrt_a , double h , double a ,
570594 const int mpi_rank , int mpi_size , MPI_Comm comm ,
571595 MPI_Info info , const int n_threads , const int dry_run ,
572- const int remap_ids , struct ic_info * ics_metadata ) {
596+ const int remap_ids , const int accept_snapshot ,
597+ struct ic_info * ics_metadata ) {
573598
574599 hid_t h_file = 0 , h_grp = 0 ;
575600 /* GADGET has only cubic boxes (in cosmological mode) */
@@ -905,7 +930,8 @@ void read_ic_serial(char *fileName, const struct unit_system *internal_units,
905930 /* Read array. */
906931 read_array_serial (h_grp , list [i ], Nparticles , N_total [ptype ],
907932 offset [ptype ], internal_units , ic_units ,
908- cleanup_h , cleanup_sqrt_a , h , a );
933+ cleanup_h , cleanup_sqrt_a , h , a ,
934+ accept_snapshot );
909935 }
910936
911937 /* Close particle group */
0 commit comments