diff options
Diffstat (limited to 'src/lib/tng_io.c')
-rw-r--r-- | src/lib/tng_io.c | 75 |
1 files changed, 25 insertions, 50 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 82568e9..66e7780 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -57,7 +57,7 @@ struct tng_residue { /** The number of atoms in the residue */ int64_t n_atoms; /** A list of atoms in the residue */ - tng_atom_t atoms; + int64_t atoms_offset; }; struct tng_chain { @@ -2277,7 +2277,7 @@ static tng_function_status tng_molecules_block_read tng_residue_data_read(tng_data, block, residue, &offset); - residue->atoms = atom; + residue->atoms_offset = atom - molecule->atoms; /* Read the atoms of the residue */ for(l=residue->n_atoms; l--;) { @@ -2302,7 +2302,7 @@ static tng_function_status tng_molecules_block_read tng_residue_data_read(tng_data, block, residue, &offset); - residue->atoms = atom; + residue->atoms_offset = atom - molecule->atoms; /* Read the atoms of the residue */ for(l=residue->n_atoms; l--;) { @@ -2681,7 +2681,7 @@ static tng_function_status tng_molecules_block_write { tng_residue_data_write(tng_data, block, residue, &offset); - atom = residue->atoms; + atom = molecule->atoms + residue->atoms_offset; for(l = residue->n_atoms; l--;) { tng_atom_data_write(tng_data, block, atom, &offset); @@ -2701,7 +2701,7 @@ static tng_function_status tng_molecules_block_write { tng_residue_data_write(tng_data, block, residue, &offset); - atom = residue->atoms; + atom = molecule->atoms + residue->atoms_offset; for(l = residue->n_atoms; l--;) { tng_atom_data_write(tng_data, block, atom, &offset); @@ -6624,8 +6624,7 @@ tng_function_status tng_chain_residue_add(tng_trajectory_t tng_data, if(chain->n_residues) { - curr_index = (chain->residues - molecule->residues) / - sizeof(struct tng_residue); + curr_index = chain->residues - molecule->residues; } else { @@ -6649,10 +6648,10 @@ tng_function_status tng_chain_residue_add(tng_trajectory_t tng_data, if(curr_index != -1) { - chain->residues = new_residues + curr_index * sizeof(struct tng_residue); + chain->residues = new_residues + curr_index; if(molecule->n_residues) { - last_residue = &new_residues[molecule->n_atoms-1]; + last_residue = &new_residues[molecule->n_residues - 1]; temp_residue = chain->residues + (chain->n_residues - 1); /* Make space in list of residues to add the new residues together with the other @@ -6682,7 +6681,7 @@ tng_function_status tng_chain_residue_add(tng_trajectory_t tng_data, (*residue)->chain = chain; (*residue)->n_atoms = 0; - (*residue)->atoms = 0; + (*residue)->atoms_offset = 0; chain->n_residues++; molecule->n_residues++; @@ -6730,18 +6729,12 @@ tng_function_status tng_residue_atom_add(tng_trajectory_t tng_data, const char *atom_type, tng_atom_t *atom) { - int curr_index; - tng_atom_t new_atoms, temp_atom, last_atom; + tng_atom_t new_atoms; tng_molecule_t molecule = residue->chain->molecule; - if(residue->n_atoms) - { - curr_index = (residue->atoms - molecule->atoms) / - sizeof(struct tng_atom); - } - else + if(!residue->n_atoms) { - curr_index = -1; + residue->atoms_offset = molecule->n_atoms; } new_atoms = realloc(molecule->atoms, @@ -6759,35 +6752,7 @@ tng_function_status tng_residue_atom_add(tng_trajectory_t tng_data, molecule->atoms = new_atoms; - if(curr_index != -1) - { - residue->atoms = new_atoms + curr_index * sizeof(struct tng_atom); - if(molecule->n_atoms) - { - last_atom = &new_atoms[molecule->n_atoms-1]; - - temp_atom = residue->atoms + (residue->n_atoms - 1); - /* Make space in list of atoms to add the new atoms together with the other - * atoms of this residue */ - if(temp_atom != last_atom) - { - temp_atom++; - memmove(temp_atom + 1, temp_atom, - last_atom - temp_atom); - } - } - } - else - { - curr_index = molecule->n_atoms; - } - - *atom = &new_atoms[curr_index + residue->n_atoms]; - - if(!residue->n_atoms) - { - residue->atoms = *atom; - } + *atom = &new_atoms[molecule->n_atoms]; tng_atom_init(*atom); tng_atom_name_set(tng_data, *atom, atom_name); @@ -9791,7 +9756,7 @@ tng_function_status tng_data_block_add(tng_trajectory_t tng_data, const tng_block_type block_type_flag, int64_t n_frames, const int64_t n_values_per_frame, - const int64_t stride_length, + int64_t stride_length, const int64_t codec_id, void *new_data) { @@ -9803,6 +9768,11 @@ tng_function_status tng_data_block_add(tng_trajectory_t tng_data, frame_set = &tng_data->current_trajectory_frame_set; + if(stride_length <= 0) + { + stride_length = 1; + } + block_index = -1; /* See if there is already a data block of this ID */ if(block_type_flag == TNG_TRAJECTORY_BLOCK) @@ -9998,7 +9968,7 @@ tng_function_status tng_particle_data_block_add(tng_trajectory_t tng_data, const tng_block_type block_type_flag, int64_t n_frames, const int64_t n_values_per_frame, - const int64_t stride_length, + int64_t stride_length, const int64_t num_first_particle, const int64_t n_particles, const int64_t codec_id, @@ -10013,6 +9983,11 @@ tng_function_status tng_particle_data_block_add(tng_trajectory_t tng_data, frame_set = &tng_data->current_trajectory_frame_set; + if(stride_length <= 0) + { + stride_length = 1; + } + block_index = -1; /* See if there is already a data block of this ID */ if(block_type_flag == TNG_TRAJECTORY_BLOCK) |