summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Lundborg <lundborg.magnus@gmail.com>2014-01-08 08:03:28 (GMT)
committerMagnus Lundborg <lundborg.magnus@gmail.com>2014-01-08 08:03:28 (GMT)
commitc3617738c8183748a2128126e612e74ea660bf87 (patch)
tree910cce144af2ce98975caf58e0eed39c2644f445
parent87d2272197b6c9cfd27aec0da5af627001d9b95e (diff)
Do forward declarations in separate header file.
Also fixed some cmake warnings.
-rw-r--r--include/tng_io.h26
-rw-r--r--include/tng_io_fwd.h41
-rw-r--r--src/lib/tng_io.c89
3 files changed, 128 insertions, 28 deletions
diff --git a/include/tng_io.h b/include/tng_io.h
index 58b9235..3a5aa37 100644
--- a/include/tng_io.h
+++ b/include/tng_io.h
@@ -275,7 +275,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
-
+#include "tng_io_fwd.h"
#ifdef USE_STD_INTTYPES_H
#include <inttypes.h>
@@ -503,30 +503,6 @@ struct tng_trajectory_frame_set;
struct tng_particle_data;
struct tng_non_particle_data;
-/** A pointer to the main trajectory data storage. */
-typedef struct tng_trajectory *tng_trajectory_t;
-/** A pointer to a molecule description. */
-typedef struct tng_molecule *tng_molecule_t;
-/** A pointer to a molecular chain description. */
-typedef struct tng_chain *tng_chain_t;
-/** A pointer to a molecular residue description. */
-typedef struct tng_residue *tng_residue_t;
-/** A pointer to a molecular atom description. */
-typedef struct tng_atom *tng_atom_t;
-/** A pointer to a bond between two atoms. */
-typedef struct tng_bond *tng_bond_t;
-/** A pointer to a structure containing data common to all trajectory blocks,
- * such as header and contents. */
-typedef struct tng_gen_block *tng_gen_block_t;
-/** A pointer to particle mapping information. */
-typedef struct tng_particle_mapping *tng_particle_mapping_t;
-/** A pointer to a structure containing frame set information. */
-typedef struct tng_trajectory_frame_set *tng_trajectory_frame_set_t;
-/** A pointer to a particle data container. */
-typedef struct tng_particle_data *tng_particle_data_t;
-/** A pointer to a non-particle data container. */
-typedef struct tng_non_particle_data *tng_non_particle_data_t;
-
/** Data can be either double, float, int or a string */
union data_values {
double d;
diff --git a/include/tng_io_fwd.h b/include/tng_io_fwd.h
new file mode 100644
index 0000000..e7abac4
--- /dev/null
+++ b/include/tng_io_fwd.h
@@ -0,0 +1,41 @@
+/* This code is part of the tng binary trajectory format.
+ *
+ * VERSION 1.4
+ *
+ * Written by Magnus Lundborg
+ * Copyright (c) 2012-2013, The GROMACS development team.
+ * Check out http://www.gromacs.org for more information.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the Revised BSD License.
+ */
+
+#ifndef TNG_IO_FWD_H
+#define TNG_IO_FWD_H 1
+
+/** A pointer to the main trajectory data storage. */
+typedef struct tng_trajectory *tng_trajectory_t;
+/** A pointer to a molecule description. */
+typedef struct tng_molecule *tng_molecule_t;
+/** A pointer to a molecular chain description. */
+typedef struct tng_chain *tng_chain_t;
+/** A pointer to a molecular residue description. */
+typedef struct tng_residue *tng_residue_t;
+/** A pointer to a molecular atom description. */
+typedef struct tng_atom *tng_atom_t;
+/** A pointer to a bond between two atoms. */
+typedef struct tng_bond *tng_bond_t;
+/** A pointer to a structure containing data common to all trajectory blocks,
+ * such as header and contents. */
+typedef struct tng_gen_block *tng_gen_block_t;
+/** A pointer to particle mapping information. */
+typedef struct tng_particle_mapping *tng_particle_mapping_t;
+/** A pointer to a structure containing frame set information. */
+typedef struct tng_trajectory_frame_set *tng_trajectory_frame_set_t;
+/** A pointer to a particle data container. */
+typedef struct tng_particle_data *tng_particle_data_t;
+/** A pointer to a non-particle data container. */
+typedef struct tng_non_particle_data *tng_non_particle_data_t;
+
+#endif \ No newline at end of file
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index f016ca9..07e8a28 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -835,6 +835,8 @@ static tng_function_status tng_block_header_read
{
int len, offset = 0;
+ TNG_ASSERT(block != 0, "TNG library: Trying to read to uninitialized block (NULL pointer).");
+
if(tng_input_file_init(tng_data) != TNG_SUCCESS)
{
return(TNG_CRITICAL);
@@ -853,7 +855,7 @@ static tng_function_status tng_block_header_read
if(ftell(tng_data->input_file) < 9)
{
/* File is little endian */
- if ( *(const char*)&block->header_contents_size != 0x00 &&
+ if ( *((const char*)&block->header_contents_size) != 0x00 &&
*((const char*)(&block->header_contents_size) + 7) == 0x00)
{
/* If the architecture endianness is little endian no byte swap
@@ -8430,6 +8432,11 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_name_of_particle_nr_get
TNG_ASSERT(name, "TNG library: name must not be a NULL pointer.");
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
for(i = 0; i < tng_data->n_molecules; i++)
{
@@ -8471,6 +8478,11 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_id_of_particle_nr_get
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
for(i = 0; i < tng_data->n_molecules; i++)
{
mol = &tng_data->molecules[i];
@@ -8510,6 +8522,11 @@ tng_function_status DECLSPECDLLEXPORT tng_molsystem_bonds_get
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
*n_bonds = 0;
/* First count the total number of bonds to allocate memory */
for(i = 0; i < tng_data->n_molecules; i++)
@@ -8518,6 +8535,11 @@ tng_function_status DECLSPECDLLEXPORT tng_molsystem_bonds_get
mol_cnt = molecule_cnt_list[i];
*n_bonds += mol_cnt * mol->n_bonds;
}
+ if(*n_bonds == 0)
+ {
+ return(TNG_SUCCESS);
+ }
+
*from_atoms = malloc(sizeof(int64_t) * (*n_bonds));
if(!*from_atoms)
{
@@ -8573,6 +8595,11 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_name_of_particle_nr_get
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
for(i = 0; i < tng_data->n_molecules; i++)
{
mol = &tng_data->molecules[i];
@@ -8620,6 +8647,11 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_name_of_particle_nr_get
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
for(i = 0; i < tng_data->n_molecules; i++)
{
mol = &tng_data->molecules[i];
@@ -8666,6 +8698,11 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_id_of_particle_nr_get
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
for(i = 0; i < tng_data->n_molecules; i++)
{
mol = &tng_data->molecules[i];
@@ -8707,6 +8744,11 @@ tng_function_status DECLSPECDLLEXPORT tng_global_residue_id_of_particle_nr_get
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
for(i = 0; i < tng_data->n_molecules; i++)
{
mol = &tng_data->molecules[i];
@@ -8752,6 +8794,11 @@ tng_function_status DECLSPECDLLEXPORT tng_atom_name_of_particle_nr_get
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
for(i = 0; i < tng_data->n_molecules; i++)
{
mol = &tng_data->molecules[i];
@@ -8795,6 +8842,11 @@ tng_function_status tng_atom_type_of_particle_nr_get
tng_molecule_cnt_list_get(tng_data, &molecule_cnt_list);
+ if(!molecule_cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
for(i = 0; i < tng_data->n_molecules; i++)
{
mol = &tng_data->molecules[i];
@@ -10610,6 +10662,11 @@ tng_function_status DECLSPECDLLEXPORT tng_num_molecules_get
tng_molecule_cnt_list_get(tng_data, &cnt_list);
+ if(!cnt_list)
+ {
+ return(TNG_FAILURE);
+ }
+
for(i = tng_data->n_molecules; i --;)
{
cnt += cnt_list[i];
@@ -14767,6 +14824,13 @@ tng_function_status DECLSPECDLLEXPORT tng_data_vector_interval_get
(long)tng_data->current_trajectory_frame_set_input_file_pos,
SEEK_SET);
stat = tng_block_header_read(tng_data, block);
+ if(stat != TNG_SUCCESS)
+ {
+ fprintf(stderr, "TNG library: Cannot read block header. %s: %d\n",
+ __FILE__, __LINE__);
+ return(stat);
+ }
+
fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
}
file_pos = ftell(tng_data->input_file);
@@ -15604,6 +15668,13 @@ tng_function_status DECLSPECDLLEXPORT tng_particle_data_vector_interval_get
(long)tng_data->current_trajectory_frame_set_input_file_pos,
SEEK_SET);
stat = tng_block_header_read(tng_data, block);
+ if(stat != TNG_SUCCESS)
+ {
+ fprintf(stderr, "TNG library: Cannot read block header. %s: %d\n",
+ __FILE__, __LINE__);
+ return(stat);
+ }
+
fseek(tng_data->input_file, (long)block->block_contents_size, SEEK_CUR);
}
file_pos = ftell(tng_data->input_file);
@@ -16382,7 +16453,13 @@ tng_function_status DECLSPECDLLEXPORT tng_util_particle_data_next_frame_read
}
if(frame_set->prev_frame_set_file_pos != frame_set_file_pos)
{
- tng_num_frames_get(tng_data, &n_frames);
+ stat = tng_num_frames_get(tng_data, &n_frames);
+ if(stat != TNG_SUCCESS)
+ {
+ fprintf(stderr, "TNG library: Cannot get number of frames. %s: %d\n",
+ __FILE__, __LINE__);
+ return(stat);
+ }
if(i < n_frames)
{
fprintf(stderr, "TNG library: Cannot find frame set of frame %"PRId64". %s: %d\n",
@@ -16551,6 +16628,12 @@ tng_function_status DECLSPECDLLEXPORT tng_util_non_particle_data_next_frame_read
if(frame_set->prev_frame_set_file_pos != frame_set_file_pos)
{
tng_num_frames_get(tng_data, &n_frames);
+ if(stat != TNG_SUCCESS)
+ {
+ fprintf(stderr, "TNG library: Cannot get number of frames. %s: %d\n",
+ __FILE__, __LINE__);
+ return(stat);
+ }
if(i < n_frames)
{
fprintf(stderr, "TNG library: Cannot find frame set of frame %"PRId64". %s: %d\n",
@@ -16893,7 +16976,7 @@ tng_function_status DECLSPECDLLEXPORT tng_util_generic_write_interval_double_set
tng_trajectory_frame_set_t frame_set;
tng_particle_data_t p_data;
tng_non_particle_data_t np_data;
- int64_t n_particles, n_frames = 100*i;
+ int64_t n_particles, n_frames;
tng_function_status stat;
TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup.");
contact: Jan Huwald // Impressum