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