@@ -48,11 +48,11 @@ namespace libmpdataxx
4848 // HDF types of host data
4949 const H5::FloatType
5050 flttype_solver =
51- sizeof (typename solver_t ::real_t ) == sizeof (long double )
52- ? H5::PredType::NATIVE_LDOUBLE
53- : sizeof (typename solver_t ::real_t ) == sizeof (double )
54- ? H5::PredType::NATIVE_DOUBLE :
55- H5::PredType::NATIVE_FLOAT,
51+ sizeof (typename solver_t ::real_t ) == sizeof (long double )
52+ ? H5::PredType::NATIVE_LDOUBLE
53+ : sizeof (typename solver_t ::real_t ) == sizeof (double )
54+ ? H5::PredType::NATIVE_DOUBLE :
55+ H5::PredType::NATIVE_FLOAT,
5656 flttype_output = H5::PredType::NATIVE_FLOAT; // using floats not to waste disk space
5757
5858 blitz::TinyVector<hsize_t , parent_t ::n_dims> cshape, shape, chunk, srfcshape, srfcchunk, offst;
@@ -98,7 +98,7 @@ namespace libmpdataxx
9898 offst = 0 ;
9999
100100 for (int d = 0 ; d < parent_t ::n_dims; ++d)
101- shape[d] = this ->mem ->distmem .grid_size [d];
101+ shape[d] = this ->mem ->distmem .grid_size [d];
102102
103103 chunk = shape;
104104
@@ -114,10 +114,10 @@ namespace libmpdataxx
114114#if defined(USE_MPI)
115115 if (this ->mem ->distmem .size () > 1 )
116116 {
117- shape[0 ] = this ->mem ->grid_size [0 ].length ();
118- cshape[0 ] = this ->mem ->grid_size [0 ].length ();
117+ shape[0 ] = this ->mem ->grid_size [0 ].length ();
118+ cshape[0 ] = this ->mem ->grid_size [0 ].length ();
119119
120- if (this ->mem ->distmem .rank () == this ->mem ->distmem .size () - 1 )
120+ if (this ->mem ->distmem .rank () == this ->mem ->distmem .size () - 1 )
121121 cshape[0 ] += 1 ;
122122
123123 offst[0 ] = this ->mem ->grid_size [0 ].first ();
@@ -134,9 +134,9 @@ namespace libmpdataxx
134134 srfcchunk = chunk;
135135 *(srfcchunk.end ()-1 ) = 1 ;
136136
137- params.setChunk (parent_t ::n_dims, chunk.data ());
137+ params.setChunk (parent_t ::n_dims, chunk.data ());
138138#if !defined(USE_MPI)
139- params.setDeflate (5 ); // TODO: move such constant to the header
139+ params.setDeflate (5 ); // TODO: move such constant to the header
140140#endif
141141
142142 // creating variables
@@ -222,26 +222,26 @@ namespace libmpdataxx
222222 assert (this ->rank == 0 );
223223 // count[1] = 1; TODO
224224
225- // creating the timestep file
226- hdfp.reset (new H5::H5File (this ->outdir + " /" + hdf_name (), H5F_ACC_TRUNC
225+ // creating the timestep file
226+ hdfp.reset (new H5::H5File (this ->outdir + " /" + hdf_name (), H5F_ACC_TRUNC
227227#if defined(USE_MPI)
228228 , H5P_DEFAULT, fapl_id
229229#endif
230- ));
230+ ));
231231
232232 {
233233 std::map<int , H5::DataSet> vars;
234234
235- for (const auto &v : this ->outvars )
236- {
237- // creating the user-requested variables
238- vars[v.first ] = (*hdfp).createDataSet (
239- v.second .name ,
240- flttype_output,
241- sspace,
242- params
243- );
244- // TODO: units attribute
235+ for (const auto &v : this ->outvars )
236+ {
237+ // creating the user-requested variables
238+ vars[v.first ] = (*hdfp).createDataSet (
239+ v.second .name ,
240+ flttype_output,
241+ sspace,
242+ params
243+ );
244+ // TODO: units attribute
245245
246246 record_dsc_helper (vars[v.first ], this ->out_data (v.first ));
247247 }
@@ -313,11 +313,11 @@ namespace libmpdataxx
313313 }
314314
315315 // data is assumed to be contiguous and in the same layout as hdf variable
316- void record_aux (const std::string &name, typename solver_t ::real_t *data)
316+ void record_aux_hlpr (const std::string &name, typename solver_t ::real_t *data, H5::H5File hdf )
317317 {
318318 assert (this ->rank == 0 );
319319
320- auto aux = (*hdfp) .createDataSet (
320+ auto aux = hdf .createDataSet (
321321 name,
322322 flttype_output,
323323 sspace,
@@ -328,16 +328,21 @@ namespace libmpdataxx
328328 space.selectHyperslab (H5S_SELECT_SET, shape.data (), offst.data ());
329329 aux.write (data, flttype_solver, H5::DataSpace (parent_t ::n_dims, shape.data ()), space, dxpl_id);
330330 }
331+
332+ void record_aux (const std::string &name, typename solver_t ::real_t *data)
333+ {
334+ record_aux_hlpr (name, data, *hdfp);
335+ }
331336
332337 // for discontiguous array with halos
333- void record_aux_dsc (const std::string &name, const typename solver_t ::arr_t &arr, bool srfc = false )
338+ void record_aux_dsc_hlpr (const std::string &name, const typename solver_t ::arr_t &arr, H5::H5File hdf , bool srfc = false )
334339 {
335340 assert (this ->rank == 0 );
336341
337342 if (srfc)
338- params.setChunk (parent_t ::n_dims, srfcchunk.data ());
343+ params.setChunk (parent_t ::n_dims, srfcchunk.data ());
339344
340- auto aux = (*hdfp) .createDataSet (
345+ auto aux = hdf .createDataSet (
341346 name,
342347 flttype_output,
343348 srfc ? srfcspace : sspace,
@@ -347,13 +352,19 @@ namespace libmpdataxx
347352 if (srfc)
348353 {
349354 // revert to default chunk
350- params.setChunk (parent_t ::n_dims, chunk.data ());
355+ params.setChunk (parent_t ::n_dims, chunk.data ());
351356 record_dsc_srfc_helper (aux, arr);
352357 }
353358 else
354359 record_dsc_helper (aux, arr);
355360 }
356361
362+ void record_aux_dsc (const std::string &name, const typename solver_t ::arr_t &arr, bool srfc = false )
363+ {
364+ record_aux_dsc_hlpr (name, arr, *hdfp, srfc);
365+ }
366+
367+
357368 void record_scalar_hlpr (const std::string &name, const std::string &group_name, typename solver_t ::real_t data, H5::H5File hdf)
358369 {
359370 assert (this ->rank == 0 );
@@ -373,6 +384,19 @@ namespace libmpdataxx
373384 }
374385
375386 // has to be called after const file was created (i.e. after start())
387+ void record_aux_const (const std::string &name, typename solver_t ::real_t *data)
388+ {
389+ H5::H5File hdfcp (const_file, H5F_ACC_RDWR); // reopen the const file
390+ record_aux_hlpr (name, data, hdfcp);
391+ }
392+
393+ // has to be called after const file was created (i.e. after start())
394+ void record_aux_dsc_const (const std::string &name, const typename solver_t ::arr_t &arr)
395+ {
396+ H5::H5File hdfcp (const_file, H5F_ACC_RDWR); // reopen the const file
397+ record_aux_dsc_hlpr (name, arr, hdfcp);
398+ }
399+
376400 void record_aux_const (const std::string &name, const std::string &group_name, typename solver_t ::real_t data)
377401 {
378402 H5::H5File hdfcp (const_file, H5F_ACC_RDWR
@@ -593,8 +617,8 @@ namespace libmpdataxx
593617
594618 // ctor
595619 hdf5 (
596- typename parent_t ::ctor_args_t args,
597- const typename parent_t ::rt_params_t &p
620+ typename parent_t ::ctor_args_t args,
621+ const typename parent_t ::rt_params_t &p
598622 ) : parent_t(args, p)
599623 {
600624#if defined(USE_MPI)
0 commit comments