summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMagnus Lundborg <magnus.lundborg@scilifelab.se>2013-01-14 12:30:59 (GMT)
committerMagnus Lundborg <magnus.lundborg@scilifelab.se>2013-01-14 12:30:59 (GMT)
commit04d1b62313b529a521f2a961b61fc21210d0c406 (patch)
tree16d7ce9fd9ecc939d53b718e12b808f0acff606c /src/tests
parent1582d40b4b3d6b1be49da3a2b31f9019cbb0393c (diff)
Added functions to get atom names and molecule names from atom number. Fixed minor bugs. Fixed compiler warnings.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/tng_io_read_pos.c52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/tests/tng_io_read_pos.c b/src/tests/tng_io_read_pos.c
index 753f475..5d3be64 100644
--- a/src/tests/tng_io_read_pos.c
+++ b/src/tests/tng_io_read_pos.c
@@ -12,6 +12,7 @@ int main(int argc, char **argv)
int64_t particle = 0;
// Set a default frame range
int first_frame = 0, last_frame = 50;
+ char name[64];
if(argc <= 1)
{
@@ -49,6 +50,16 @@ int main(int argc, char **argv)
n_frames = last_frame - first_frame + 1;
+ if(tng_atom_name_of_particle_nr_get(traj, particle, name, sizeof(name)) ==
+ TNG_SUCCESS)
+ {
+ printf("Particle: %s\n", name);
+ }
+ else
+ {
+ printf("Particle name not found\n");
+ }
+
// Get the positions of all particles in the requested frame range.
// The positions are stored in the positions array.
// N.B. No proper error checks.
@@ -56,27 +67,34 @@ int main(int argc, char **argv)
last_frame, TNG_USE_HASH, &positions, &n_particles, &n_values_per_frame,
&data_type) == TNG_SUCCESS)
{
- // Print the positions of the wanted particle (zero based)
- for(i=0; i<n_frames; i++)
+ if(particle >= n_particles)
+ {
+ printf("Chosen particle out of range. Only %"PRId64" particles in trajectory.\n", n_particles);
+ }
+ else
{
- printf("%d", first_frame + i);
- for(j=0; j<n_values_per_frame; j++)
+ // Print the positions of the wanted particle (zero based)
+ for(i=0; i<n_frames; i++)
{
- switch(data_type)
+ printf("%d", first_frame + i);
+ for(j=0; j<n_values_per_frame; j++)
{
- case TNG_INT_DATA:
- printf("\t%"PRId64"", positions[i][particle][j].i);
- break;
- case TNG_FLOAT_DATA:
- printf("\t%f", positions[i][particle][j].f);
- break;
- case TNG_DOUBLE_DATA:
- printf("\t%f", positions[i][particle][j].d);
- break;
- default:
- break;
+ switch(data_type)
+ {
+ case TNG_INT_DATA:
+ printf("\t%"PRId64"", positions[i][particle][j].i);
+ break;
+ case TNG_FLOAT_DATA:
+ printf("\t%f", positions[i][particle][j].f);
+ break;
+ case TNG_DOUBLE_DATA:
+ printf("\t%f", positions[i][particle][j].d);
+ break;
+ default:
+ break;
+ }
+ printf("\n");
}
- printf("\n");
}
}
}
contact: Jan Huwald // Impressum