Also includes a check that the user name can be retrieved
before trying to set it.
Change-Id: I51d4ab2e590752980953d1926d4bea56fe1beffa
if(n_frames == 1 && tng_data->frame_set_n_frames > 1)
{
nalgo = tng_compress_nalgo();
if(n_frames == 1 && tng_data->frame_set_n_frames > 1)
{
nalgo = tng_compress_nalgo();
- alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_pos);
+ alt_algo=malloc(nalgo * sizeof *tng_data->compress_algo_vel);
if(type == TNG_FLOAT_DATA)
{
dest = tng_compress_vel_float_find_algo((float *)temp_data_contents, (int)n_particles,
if(type == TNG_FLOAT_DATA)
{
dest = tng_compress_vel_float_find_algo((float *)temp_data_contents, (int)n_particles,
TNG_ASSERT(offset != 0, "TNG library: offset must not be a NULL pointer.");
TNG_ASSERT(offset != 0, "TNG library: offset must not be a NULL pointer.");
+ /* This must be caught early to avoid creating a data block if not necessary. */
+#ifndef USE_ZLIB
+ if(codec_id == TNG_GZIP_COMPRESSION)
+ {
+ fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__,
+ __LINE__);
+ return(TNG_FAILURE);
+ }
+#endif
+
switch(datatype)
{
case TNG_CHAR_DATA:
switch(datatype)
{
case TNG_CHAR_DATA:
/* fprintf(stderr, "TNG library: %s\n", block->name);*/
/* fprintf(stderr, "TNG library: %s\n", block->name);*/
+ /* This must be caught early to avoid creating a data block if not necessary. */
+#ifndef USE_ZLIB
+ if(codec_id == TNG_GZIP_COMPRESSION)
+ {
+ fprintf(stderr, "TNG library: Cannot uncompress data block. %s: %d\n", __FILE__,
+ __LINE__);
+ return(TNG_FAILURE);
+ }
+#endif
+
switch(datatype)
{
case TNG_CHAR_DATA:
switch(datatype)
{
case TNG_CHAR_DATA:
#ifdef HAVE_UNISTD_H
char username[256];
#ifdef HAVE_UNISTD_H
char username[256];
- getlogin_r(username, 256);
- if (mode == 'w')
+ if (!getlogin_r(username, 256))
- tng_first_user_name_set(*tng, username);
+ if (mode == 'w')
+ {
+ tng_first_user_name_set(*tng, username);
+ }
}
/* TODO: This should be implemented when the above fixme is done (adding data to
* the header). */
}
/* TODO: This should be implemented when the above fixme is done (adding data to
* the header). */
+ typedef tng_function_status (*set_writing_interval_func_pointer)(tng_trajectory_t,
+ const gmx_int64_t,
+ const gmx_int64_t,
+ const gmx_int64_t,
+ const char*,
+ const char,
+ const char);
+#ifdef GMX_DOUBLE
+ set_writing_interval_func_pointer set_writing_interval = tng_util_generic_write_interval_double_set;
+#else
+ set_writing_interval_func_pointer set_writing_interval = tng_util_generic_write_interval_set;
+#endif
gmx_tng_open(filename, mode, output);
gmx_tng_open(filename, mode, output);
{
case TNG_TRAJ_POSITIONS:
case TNG_TRAJ_VELOCITIES:
{
case TNG_TRAJ_POSITIONS:
case TNG_TRAJ_VELOCITIES:
- tng_util_generic_write_interval_set(*output, interval, 3, fallbackIds[i],
- fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
- compression_type);
+ set_writing_interval(*output, interval, 3, fallbackIds[i],
+ fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
+ compression_type);
break;
case TNG_TRAJ_FORCES:
break;
case TNG_TRAJ_FORCES:
- tng_util_generic_write_interval_set(*output, interval, 3, fallbackIds[i],
- fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
- TNG_GZIP_COMPRESSION);
+ set_writing_interval(*output, interval, 3, fallbackIds[i],
+ fallbackNames[i], TNG_PARTICLE_BLOCK_DATA,
+ TNG_GZIP_COMPRESSION);
break;
case TNG_TRAJ_BOX_SHAPE:
break;
case TNG_TRAJ_BOX_SHAPE:
- tng_util_generic_write_interval_set(*output, interval, 9, fallbackIds[i],
- fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
- TNG_GZIP_COMPRESSION);
+ set_writing_interval(*output, interval, 9, fallbackIds[i],
+ fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
+ TNG_GZIP_COMPRESSION);
break;
case TNG_GMX_LAMBDA:
break;
case TNG_GMX_LAMBDA:
- tng_util_generic_write_interval_set(*output, interval, 1, fallbackIds[i],
- fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
- TNG_GZIP_COMPRESSION);
+ set_writing_interval(*output, interval, 1, fallbackIds[i],
+ fallbackNames[i], TNG_NON_PARTICLE_BLOCK_DATA,
+ TNG_GZIP_COMPRESSION);