+ /* Set atom masses. */
+ masses = malloc(sizeof(float) * n_particles);
+ for(i = 0; i < n_particles; i++)
+ {
+ stat = tng_atom_type_of_particle_nr_get(*traj, i, atom_type,
+ sizeof(atom_type));
+ if(stat == TNG_CRITICAL)
+ {
+ break;
+ }
+ /* We only have water in the system. If the atom is oxygen set its
+ * mass to 16.00000, if it's a hydrogen set its mass to
+ * 1.00800. */
+ switch(atom_type[0])
+ {
+ case 'O':
+ masses[i] = 16.00000;
+ break;
+ case 'H':
+ masses[i] = 1.00800;
+ break;
+ default:
+ printf("Failed setting atom masses. %s: %d\n",
+ __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }
+ }
+ if(stat == TNG_CRITICAL)
+ {
+ free(masses);
+ printf("Failed setting atom masses. %s: %d\n",
+ __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }
+
+ stat = tng_particle_data_block_add(*traj, TNG_TRAJ_MASSES, "ATOM MASSES",
+ TNG_FLOAT_DATA, TNG_NON_TRAJECTORY_BLOCK,
+ 1, 1, 1, 0, n_particles,
+ TNG_GZIP_COMPRESSION, masses);
+ free(masses);
+ masses = 0;
+ if(stat != TNG_SUCCESS)
+ {
+ printf("Failed adding atom masses. %s: %d\n",
+ __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }