Add TNG writing and reading support
[alexxy/gromacs.git] / src / external / tng_io / src / tests / tng_io_testing.c
1 /* This code is part of the tng binary trajectory format.
2  *
3  *                      VERSION 1.0
4  *
5  * Written by Magnus Lundborg
6  * Copyright (c) 2012-2013, The GROMACS development team.
7  * Check out http://www.gromacs.org for more information.
8  *
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the Revised BSD License.
12  */
13
14 #ifdef USE_STD_INTTYPES_H
15 #include <inttypes.h>
16 #endif
17
18 #include <stdlib.h>
19 #include <string.h>
20 #include "../../include/tng_io.h"
21
22 static tng_function_status tng_test_setup_molecules(tng_trajectory_t traj)
23 {
24     tng_molecule_t molecule;
25     tng_chain_t chain;
26     tng_residue_t residue;
27     tng_atom_t atom;
28     int64_t cnt;
29
30     tng_molecule_add(traj, "water", &molecule);
31     tng_molecule_chain_add(traj, molecule, "W", &chain);
32     tng_chain_residue_add(traj, chain, "WAT", &residue);
33     if(tng_residue_atom_add(traj, residue, "O", "O", &atom) == TNG_CRITICAL)
34     {
35         return(TNG_CRITICAL);
36     }
37     if(tng_residue_atom_add(traj, residue, "HO1", "H", &atom) == TNG_CRITICAL)
38     {
39         return(TNG_CRITICAL);
40     }
41     if(tng_residue_atom_add(traj, residue, "HO2", "H", &atom) == TNG_CRITICAL)
42     {
43         return(TNG_CRITICAL);
44     }
45     tng_molecule_cnt_set(traj, molecule, 200);
46     tng_molecule_cnt_get(traj, molecule, &cnt);
47 /*     printf("Created %"PRId64" %s molecules.\n", cnt, molecule->name); */
48
49 /*     traj->molecule_cnt_list[traj->n_molecules-1] = 5;
50 //     tng_molecule_name_set(traj, &traj->molecules[1], "ligand");
51 //     tng_molecule_name_set(traj, &traj->molecules[2], "water");
52 //     tng_molecule_name_set(traj, &traj->molecules[3], "dummy");
53 //     traj->molecules[0].id = 0;
54 //     traj->molecules[1].id = 1;
55 //     traj->molecules[2].id = 2;
56 //     traj->molecules[3].id = 3;
57
58 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[0], "atom1", "type1") == TNG_CRITICAL)
59 //     {
60 //         return(TNG_CRITICAL);
61 //     }
62 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[0], "atom2", "type1") == TNG_CRITICAL)
63 //     {
64 //         return(TNG_CRITICAL);
65 //     }
66 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[0], "atom3", "type1") == TNG_CRITICAL)
67 //     {
68 //         return(TNG_CRITICAL);
69 //     }
70 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[0], "atom4", "type2") == TNG_CRITICAL)
71 //     {
72 //         return(TNG_CRITICAL);
73 //     }
74 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[0], "atom5", "type2") == TNG_CRITICAL)
75 //     {
76 //         return(TNG_CRITICAL);
77 //     }
78 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[0], "atom6", "type2") == TNG_CRITICAL)
79 //     {
80 //         return(TNG_CRITICAL);
81 //     }
82 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[0], "atom7", "type3") == TNG_CRITICAL)
83 //     {
84 //         return(TNG_CRITICAL);
85 //     }
86 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[1], "C1", "C") == TNG_CRITICAL)
87 //     {
88 //         return(TNG_CRITICAL);
89 //     }
90 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[1], "O1", "O") == TNG_CRITICAL)
91 //     {
92 //         return(TNG_CRITICAL);
93 //     }
94 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[1], "H11", "H") == TNG_CRITICAL)
95 //     {
96 //         return(TNG_CRITICAL);
97 //     }
98 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[1], "H12", "H") == TNG_CRITICAL)
99 //     {
100 //         return(TNG_CRITICAL);
101 //     }
102 //     if(tng_add_atom_to_molecule(traj, &traj->molecules[1], "H13", "H") == TNG_CRITICAL)
103 //     {
104 //         return(TNG_CRITICAL);
105 //     }
106 */
107     return(TNG_SUCCESS);
108 }
109
110 static tng_function_status tng_test_read_and_write_file
111                 (tng_trajectory_t traj)
112 {
113     tng_function_status stat;
114
115     stat = tng_file_headers_read(traj, TNG_USE_HASH);
116     if(stat == TNG_CRITICAL)
117     {
118         return(stat);
119     }
120     stat = tng_file_headers_write(traj, TNG_USE_HASH);
121     if(stat == TNG_CRITICAL)
122     {
123         return(stat);
124     }
125
126     while(stat == TNG_SUCCESS)
127     {
128         stat = tng_frame_set_read_next(traj, TNG_USE_HASH);
129         if(stat != TNG_SUCCESS)
130         {
131             return(stat);
132         }
133         stat = tng_frame_set_write(traj, TNG_USE_HASH);
134     }
135
136     return(stat);
137 }
138
139 static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t *traj)
140 {
141     int i, j, k, nr, cnt;
142     float *data, *molpos, *charges;
143     int64_t mapping[300], n_particles, n_frames_per_frame_set, tot_n_mols;
144 //     int64_t frame_nr;
145     double box_shape[9];
146     char atom_type[16], annotation[128];
147     tng_function_status stat = TNG_SUCCESS;
148
149     tng_medium_stride_length_set(*traj, 10);
150     tng_long_stride_length_set(*traj, 100);
151
152     /* Create molecules */
153     if(tng_test_setup_molecules(*traj) == TNG_CRITICAL)
154     {
155         return(TNG_CRITICAL);
156     }
157
158     /* Set the box shape */
159     box_shape[1] = box_shape[2] = box_shape[3] = box_shape[5] = box_shape[6] =
160     box_shape[7] = 0;
161     box_shape[0] = 150.0;
162     box_shape[4] = 145.5;
163     box_shape[8] = 155.5;
164     if(tng_data_block_add(*traj, TNG_TRAJ_BOX_SHAPE, "BOX SHAPE", TNG_DOUBLE_DATA,
165                        TNG_NON_TRAJECTORY_BLOCK, 1, 9, 1, TNG_UNCOMPRESSED,
166                        box_shape) == TNG_CRITICAL)
167     {
168         tng_trajectory_destroy(traj);
169         printf("Cannot write trajectory box shape.\n");
170         exit(1);
171     }
172
173     /* Set partial charges (treat the water as TIP3P. */
174     tng_num_particles_get(*traj, &n_particles);
175     charges = malloc(sizeof(float) * n_particles);
176     for(i = 0; i < n_particles; i++)
177     {
178         stat = tng_atom_type_of_particle_nr_get(*traj, i, atom_type,
179                                                 sizeof(atom_type));
180         if(stat == TNG_CRITICAL)
181         {
182             break;
183         }
184         if(atom_type[0] == 'O')
185         {
186             charges[i] = -0.834;
187         }
188         else if(atom_type[0] == 'H')
189         {
190             charges[i] = 0.417;
191         }
192     }
193     if(stat == TNG_CRITICAL)
194     {
195         free(charges);
196         printf("Failed setting partial charges.\n");
197         return(TNG_CRITICAL);
198     }
199
200     stat = tng_particle_data_block_add(*traj, TNG_TRAJ_PARTIAL_CHARGES, "PARTIAL CHARGES",
201                                        TNG_FLOAT_DATA, TNG_NON_TRAJECTORY_BLOCK,
202                                        1, 1, 1, 0, n_particles,
203                                        TNG_UNCOMPRESSED, charges);
204     free(charges);
205     if(stat != TNG_SUCCESS)
206     {
207         printf("Failed adding partial charges\n");
208         return(TNG_CRITICAL);
209     }
210
211
212     /* Generate a custom annotation data block */
213     strcpy(annotation, "This trajectory was generated from tng_io_testing. "
214                        "It is not a real MD trajectory.");
215     if(tng_data_block_add(*traj, 10100, "DETAILS", TNG_CHAR_DATA,
216                           TNG_NON_TRAJECTORY_BLOCK, 1, 1, 1, TNG_UNCOMPRESSED,
217                           annotation) != TNG_SUCCESS)
218     {
219         printf("Failed adding details annotation data block.\n");
220         return(TNG_CRITICAL);
221     }
222
223     /* Write file headers (includes non trajectory data blocks */
224     if(tng_file_headers_write(*traj, TNG_SKIP_HASH) == TNG_CRITICAL)
225     {
226         printf("Cannot write file headers.\n");
227     }
228
229
230     tng_num_frames_per_frame_set_get(*traj, &n_frames_per_frame_set);
231
232     data = malloc(sizeof(float) * n_particles *
233                   n_frames_per_frame_set * 3);
234     if(!data)
235     {
236         printf("Cannot allocate memory. %s: %d\n", __FILE__, __LINE__);
237         return(TNG_CRITICAL);
238     }
239
240     tng_num_molecules_get(*traj, &tot_n_mols);
241     molpos = malloc(sizeof(float) * tot_n_mols * 3);
242
243     /* Set initial coordinates */
244     for(i = 0; i < tot_n_mols; i++)
245     {
246         nr = i * 3;
247         /* Somewhat random coordinates (between 0 and 100),
248          * but not specifying a random seed */
249         molpos[nr] = 100.0 * rand() / (RAND_MAX + 1.0);
250         molpos[nr+1] = 100.0 * rand() / (RAND_MAX + 1.0);
251         molpos[nr+2] = 100.0 * rand() / (RAND_MAX + 1.0);
252     }
253
254     /* Generate 200 frame sets - each with 100 frames (by default) */
255     for(i = 0; i < 200; i++)
256     {
257         cnt = 0;
258         for(j = 0; j < n_frames_per_frame_set; j++)
259         {
260             for(k = 0; k < tot_n_mols; k++)
261             {
262                 nr = k * 3;
263                 /* Move -1 to 1 */
264                 molpos[nr] += 2 * (rand() / (RAND_MAX + 1.0)) - 1;
265                 molpos[nr+1] += 2 * (rand() / (RAND_MAX + 1.0)) - 1;
266                 molpos[nr+2] += 2 * (rand() / (RAND_MAX + 1.0)) - 1;
267
268                 data[cnt++] = molpos[nr];
269                 data[cnt++] = molpos[nr + 1];
270                 data[cnt++] = molpos[nr + 2];
271                 data[cnt++] = molpos[nr] + 1;
272                 data[cnt++] = molpos[nr + 1] + 1;
273                 data[cnt++] = molpos[nr + 2] + 1;
274                 data[cnt++] = molpos[nr] - 1;
275                 data[cnt++] = molpos[nr + 1] - 1;
276                 data[cnt++] = molpos[nr + 2] - 1;
277             }
278         }
279         if(tng_frame_set_new(*traj, i * n_frames_per_frame_set,
280             n_frames_per_frame_set) != TNG_SUCCESS)
281         {
282             printf("Error creating frame set %d. %s: %d\n",
283                    i, __FILE__, __LINE__);
284             free(molpos);
285             free(data);
286             return(TNG_CRITICAL);
287         }
288
289         tng_frame_set_particle_mapping_free(*traj);
290
291         /* Setup particle mapping. Use 4 different mapping blocks with arbitrary
292          * mappings. */
293         for(k=0; k<150; k++)
294         {
295             mapping[k]=k;
296         }
297         if(tng_particle_mapping_add(*traj, 0, 150, mapping) != TNG_SUCCESS)
298         {
299             printf("Error creating particle mapping. %s: %d\n",
300                    __FILE__, __LINE__);
301             free(molpos);
302             free(data);
303             return(TNG_CRITICAL);
304         }
305         for(k=0; k<150; k++)
306         {
307             mapping[k]=599-k;
308         }
309         if(tng_particle_mapping_add(*traj, 150, 150, mapping) != TNG_SUCCESS)
310         {
311             printf("Error creating particle mapping. %s: %d\n",
312                    __FILE__, __LINE__);
313             free(molpos);
314             free(data);
315             return(TNG_CRITICAL);
316         }
317         for(k=0; k<150; k++)
318         {
319             mapping[k]=k+150;
320         }
321         if(tng_particle_mapping_add(*traj, 300, 150, mapping) != TNG_SUCCESS)
322         {
323             printf("Error creating particle mapping. %s: %d\n",
324                    __FILE__, __LINE__);
325             free(molpos);
326             free(data);
327             return(TNG_CRITICAL);
328         }
329         for(k=0; k<150; k++)
330         {
331             mapping[k]=449-k;
332         }
333         if(tng_particle_mapping_add(*traj, 450, 150, mapping) != TNG_SUCCESS)
334         {
335             printf("Error creating particle mapping. %s: %d\n",
336                    __FILE__, __LINE__);
337             free(molpos);
338             free(data);
339             return(TNG_CRITICAL);
340         }
341
342         /* Add the positions in a data block */
343         if(tng_particle_data_block_add(*traj, TNG_TRAJ_POSITIONS,
344                                        "POSITIONS",
345                                        TNG_FLOAT_DATA,
346                                        TNG_TRAJECTORY_BLOCK,
347                                        n_frames_per_frame_set, 3,
348                                        1, 0, n_particles,
349 /*                                        TNG_UNCOMPRESSED, */
350                                        TNG_GZIP_COMPRESSION,
351                                        data) != TNG_SUCCESS)
352         {
353             printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
354             free(molpos);
355             free(data);
356             return(TNG_CRITICAL);
357         }
358         /* Write the frame set */
359         if(tng_frame_set_write(*traj, TNG_SKIP_HASH) != TNG_SUCCESS)
360         {
361             printf("Error writing frame set. %s: %d\n", __FILE__, __LINE__);
362             free(molpos);
363             free(data);
364             return(TNG_CRITICAL);
365         }
366     }
367
368     /* Write two more frame sets one frame at a time */
369
370     /* Make a new frame set - if always using the same mapping blocks
371      * it is not necessary to explicitly add a new frame set - it will
372      * be added automatically when adding data for a frame */
373 /*    if(tng_frame_set_new(*traj, i * n_frames_per_frame_set,
374         n_frames_per_frame_set) != TNG_SUCCESS)
375     {
376         printf("Error creating frame set %d. %s: %d\n",
377                 i, __FILE__, __LINE__);
378         free(molpos);
379         free(data);
380         return(TNG_CRITICAL);
381     }
382
383     frame_nr = i * n_frames_per_frame_set;
384
385     for(k=0; k<300; k++)
386     {
387         mapping[k]=k;
388     }
389     *//* Just use two particle mapping blocks in this frame set *//*
390     if(tng_particle_mapping_add(*traj, 0, 300, mapping) != TNG_SUCCESS)
391     {
392         printf("Error creating particle mapping. %s: %d\n",
393                 __FILE__, __LINE__);
394         free(molpos);
395         free(data);
396         return(TNG_CRITICAL);
397     }
398     for(k=0; k<300; k++)
399     {
400         mapping[k]=599-k;
401     }
402     if(tng_particle_mapping_add(*traj, 300, 300, mapping) != TNG_SUCCESS)
403     {
404         printf("Error creating particle mapping. %s: %d\n",
405                 __FILE__, __LINE__);
406         free(molpos);
407         free(data);
408         return(TNG_CRITICAL);
409     }
410
411     *//* Add the data block to the current frame set *//*
412     if(tng_particle_data_block_add(*traj, TNG_TRAJ_POSITIONS,
413                                     "POSITIONS",
414                                     TNG_FLOAT_DATA,
415                                     TNG_TRAJECTORY_BLOCK,
416                                     n_frames_per_frame_set, 3,
417                                     1, 0, n_particles,
418                                     TNG_UNCOMPRESSED,
419                                     0) != TNG_SUCCESS)
420     {
421         printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
422         free(molpos);
423         free(data);
424         return(TNG_CRITICAL);
425     }
426
427     *//* Write the frame set to disk *//*
428     if(tng_frame_set_write(*traj, TNG_SKIP_HASH) != TNG_SUCCESS)
429     {
430         printf("Error writing frame set. %s: %d\n", __FILE__, __LINE__);
431         free(molpos);
432         free(data);
433         return(TNG_CRITICAL);
434     }
435
436     *//* Write particle data to disk - one frame at a time *//*
437     for(i = 0; i < n_frames_per_frame_set * 2; i++)
438     {
439         for(j = 0; j < 2; j++)
440         {
441             cnt = 0;
442             for(k = 0; k < tot_n_mols/2; k++)
443             {
444                 nr = k * 3;
445                 *//* Move -1 to 1 *//*
446                 molpos[nr] += 2 * (rand() / (RAND_MAX + 1.0)) - 1;
447                 molpos[nr+1] += 2 * (rand() / (RAND_MAX + 1.0)) - 1;
448                 molpos[nr+2] += 2 * (rand() / (RAND_MAX + 1.0)) - 1;
449
450                 data[cnt++] = molpos[nr];
451                 data[cnt++] = molpos[nr + 1];
452                 data[cnt++] = molpos[nr + 2];
453                 data[cnt++] = molpos[nr] + 1;
454                 data[cnt++] = molpos[nr + 1] + 1;
455                 data[cnt++] = molpos[nr + 2] + 1;
456                 data[cnt++] = molpos[nr] - 1;
457                 data[cnt++] = molpos[nr + 1] - 1;
458                 data[cnt++] = molpos[nr + 2] - 1;
459             }
460             if(tng_frame_particle_data_write(*traj, frame_nr + i,
461                                           TNG_TRAJ_POSITIONS, j * 300, 300,
462                                           data, TNG_SKIP_HASH) != TNG_SUCCESS)
463             {
464                 printf("Error adding data. %s: %d\n", __FILE__, __LINE__);
465                 free(molpos);
466                 free(data);
467                 return(TNG_CRITICAL);
468             }
469         }
470     }
471 */
472     free(molpos);
473     free(data);
474
475     tng_trajectory_destroy(traj);
476     tng_trajectory_init(traj);
477 #ifdef TNG_EXAMPLE_FILES_DIR
478     tng_input_file_set(*traj, TNG_EXAMPLE_FILES_DIR "tng_test.tng");
479 #else
480     tng_input_file_set(*traj, "/tmp/tng_test.tng");
481 #endif
482
483     stat = tng_file_headers_read(*traj, TNG_SKIP_HASH);
484
485     while(stat == TNG_SUCCESS)
486     {
487         stat = tng_frame_set_read_next(*traj, TNG_SKIP_HASH);
488     }
489
490     return(stat);
491 }
492
493 /* This test relies on knowing that the box shape is stored as double */
494 tng_function_status tng_test_get_box_data(tng_trajectory_t traj)
495 {
496     int64_t n_frames, n_values_per_frame;
497     union data_values **values = 0;
498     char type;
499
500     if(tng_data_get(traj, TNG_TRAJ_BOX_SHAPE, &values, &n_frames,
501                     &n_values_per_frame, &type) != TNG_SUCCESS)
502     {
503         printf("Failed getting box shape. %s: %d\n", __FILE__, __LINE__);
504         return(TNG_CRITICAL);
505     }
506
507 /*
508 //     int64_t i, j;
509 //     printf("Box shape:");
510 //     for(i=0; i<n_frames; i++)
511 //     {
512 //         for(j=0; j<n_values_per_frame; j++)
513 //         {
514 //             printf("\t%f", (values[i][j]).d);
515 //         }
516 //         printf("\n");
517 //     }
518 */
519     tng_data_values_free(traj, values, n_frames, n_values_per_frame, type);
520
521     return(TNG_SUCCESS);
522 }
523
524 /* This test relies on knowing that the positions are stored as float
525  * and that the data is not sparse (i.e. as many frames in the data
526  * as in the frame set */
527 tng_function_status tng_test_get_positions_data(tng_trajectory_t traj)
528 {
529     int64_t n_frames, n_particles, n_values_per_frame;
530     union data_values ***values = 0;
531     char type;
532
533     if(tng_particle_data_get(traj, TNG_TRAJ_POSITIONS, &values, &n_frames,
534                              &n_particles, &n_values_per_frame, &type) !=
535        TNG_SUCCESS)
536     {
537         printf("Failed getting particle positions. %s: %d\n", __FILE__, __LINE__);
538         return(TNG_CRITICAL);
539     }
540
541 /*
542 //     int64_t i, j, k;
543 //     struct tng_trajectory_frame_set *frame_set =
544 //     &traj->current_trajectory_frame_set;
545 //     for(i = 0; i<n_frames; i++)
546 //     {
547 //         printf("Frame %"PRId64"\n", frame_set->first_frame + i);
548 //         for(j = 0; j<n_particles; j++)
549 //         {
550 //             printf("Particle %"PRId64":", j);
551 //             for(k=0; k<n_values_per_frame; k++)
552 //             {
553 //                 printf("\t%f", (values[i][j][k]).f);
554 //             }
555 //             printf("\n");
556 //         }
557 //     }
558 */
559     tng_particle_data_values_free(traj, values, n_frames, n_particles,
560                                   n_values_per_frame, type);
561
562     values = 0;
563
564     tng_particle_data_interval_get(traj, TNG_TRAJ_POSITIONS, 11000, 11499,
565                                    TNG_SKIP_HASH, &values, &n_particles,
566                                    &n_values_per_frame, &type);
567
568     /* Here the particle positions can be printed */
569
570     tng_particle_data_values_free(traj, values, 500, n_particles,
571                                   n_values_per_frame, type);
572
573     return(TNG_SUCCESS);
574 }
575
576 int main()
577 {
578     tng_trajectory_t traj;
579     tng_function_status stat;
580     char time_str[TNG_MAX_DATE_STR_LEN];
581
582     if(tng_trajectory_init(&traj) != TNG_SUCCESS)
583     {
584         tng_trajectory_destroy(&traj);
585         printf("Test Init trajectory:\t\t\t\tFailed. %s: %d.\n",
586                __FILE__, __LINE__);
587         exit(1);
588     }
589     printf("Test Init trajectory:\t\t\t\tSucceeded.\n");
590
591     tng_time_get_str(traj, time_str);
592
593     printf("Creation time: %s\n", time_str);
594
595 #ifdef TNG_EXAMPLE_FILES_DIR
596     tng_input_file_set(traj, TNG_EXAMPLE_FILES_DIR "tng_example.tng");
597     tng_output_file_set(traj, TNG_EXAMPLE_FILES_DIR "tng_example_out.tng");
598 #else
599     tng_input_file_set(traj, "tng_example.tng");
600     tng_output_file_set(traj, "/tmp/tng_example_out.tng");
601 #endif
602
603
604     if(tng_test_read_and_write_file(traj) == TNG_CRITICAL)
605     {
606         printf("Test Read and write file:\t\t\tFailed. %s: %d\n",
607                __FILE__, __LINE__);
608     }
609     else
610     {
611         printf("Test Read and write file:\t\t\tSucceeded.\n");
612     }
613
614     if(tng_test_get_box_data(traj) != TNG_SUCCESS)
615     {
616         printf("Test Get data:\t\t\t\t\tFailed. %s: %d\n",
617                __FILE__, __LINE__);
618     }
619     else
620     {
621         printf("Test Get data:\t\t\t\t\tSucceeded.\n");
622     }
623
624     if(tng_trajectory_destroy(&traj) == TNG_CRITICAL ||
625        tng_trajectory_init(&traj) == TNG_CRITICAL)
626     {
627         printf("Test Destroy and init trajectory:\t\tFailed. %s: %d\n",
628                __FILE__, __LINE__);
629     }
630     else
631     {
632         printf("Test Destroy and init trajectory:\t\tSucceeded.\n");
633     }
634
635
636 #ifdef TNG_EXAMPLE_FILES_DIR
637     tng_output_file_set(traj, TNG_EXAMPLE_FILES_DIR "tng_test.tng");
638 #else
639     tng_output_file_set(traj, "/tmp/tng_test.tng");
640 #endif
641
642     if(tng_test_write_and_read_traj(&traj) == TNG_CRITICAL)
643     {
644         printf("Test Write and read file:\t\t\tFailed. %s: %d\n",
645                __FILE__, __LINE__);
646     }
647     else
648     {
649         printf("Test Write and read file:\t\t\tSucceeded.\n");
650     }
651
652     if(tng_test_get_positions_data(traj) != TNG_SUCCESS)
653     {
654         printf("Test Get particle data:\t\t\t\tFailed. %s: %d\n",
655                __FILE__, __LINE__);
656     }
657     else
658     {
659         printf("Test Get particle data:\t\t\t\tSucceeded.\n");
660     }
661
662     if(tng_trajectory_destroy(&traj) == TNG_CRITICAL)
663     {
664         printf("Test Destroy trajectory:\t\t\tFailed. %s: %d.\n",
665                __FILE__, __LINE__);
666         exit(1);
667     }
668     else
669     {
670         printf("Test Destroy trajectory:\t\t\tSucceeded.\n");
671     }
672
673
674 #ifdef TNG_EXAMPLE_FILES_DIR
675     stat = tng_util_trajectory_open(TNG_EXAMPLE_FILES_DIR "tng_test.tng", 'r', &traj);
676 #else
677     stat = tng_util_trajectory_open("/tmp/tng_test.tng", 'r', &traj);
678 #endif
679     if(stat != TNG_SUCCESS)
680     {
681         printf("Test Utility function open:\t\t\tFailed. %s: %d.\n",
682                __FILE__, __LINE__);
683         exit(1);
684     }
685     else
686     {
687         printf("Test Utility function open:\t\t\tSucceeded.\n");
688     }
689
690     stat = tng_util_trajectory_close(&traj);
691     if(stat != TNG_SUCCESS)
692     {
693         printf("Test Utility function close:\t\t\tFailed. %s: %d.\n",
694                __FILE__, __LINE__);
695         exit(1);
696     }
697     else
698     {
699         printf("Test Utility function close:\t\t\tSucceeded.\n");
700     }
701
702     printf("Tests finished\n");
703
704     exit(0);
705 }