diff options
| author | Magnus Lundborg <magnus.lundborg@scilifelab.se> | 2012-12-07 16:55:55 (GMT) | 
|---|---|---|
| committer | Magnus Lundborg <magnus.lundborg@scilifelab.se> | 2012-12-07 16:55:55 (GMT) | 
| commit | e09e982c52d3d92a1008b01190ab27073f1d490a (patch) | |
| tree | 7be05a9193efbf70eacbb072ee13a9c1cdd95b31 | |
| parent | b036d0550ccbdb7281094f7eaf39b2dd80016d8e (diff) | |
Fixes to make get particle data work and added code to test it.
| -rw-r--r-- | src/lib/tng_io.c | 21 | ||||
| -rw-r--r-- | src/tests/tng_io_testing.c | 49 | 
2 files changed, 60 insertions, 10 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index e626e66..d07861a 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -954,7 +954,6 @@ static tng_function_status tng_write_general_info_block      return(TNG_SUCCESS);  } -/* FIXME: Update this according to the new specs */  static tng_function_status tng_read_molecules_block                  (tng_trajectory_t tng_data,                   struct tng_gen_block *block, @@ -6995,7 +6994,7 @@ tng_function_status tng_particle_data_get(tng_trajectory_t tng_data,          }      } -    if(block_index <= 0) +    if(block_index < 0)      {          /* If the data block was not found in the frame set           * look for it in the non-trajectory data (in tng_data). */ @@ -7009,8 +7008,10 @@ tng_function_status tng_particle_data_get(tng_trajectory_t tng_data,                  break;              }          } -        if(block_index <= 0) +        if(block_index < 0)          { +            printf("Could not find particle data block with id %"PRId64". %s: %d\n", +                   block_id, __FILE__, __LINE__);              return(TNG_FAILURE);          }      } @@ -7028,8 +7029,16 @@ tng_function_status tng_particle_data_get(tng_trajectory_t tng_data,      /* A bit hackish to create a new data struct before returning the data */      new_data = malloc(sizeof(struct tng_particle_data)); -    tng_allocate_particle_data_mem(tng_data, new_data, data->n_frames, -                                   n_particles, data->n_values_per_frame); +     +    new_data->n_values_per_frame = 0; +    new_data->n_frames = 0; +    new_data->values = 0; +    if(tng_allocate_particle_data_mem(tng_data, new_data, data->n_frames, +                                   n_particles, data->n_values_per_frame) != +       TNG_SUCCESS) +    { +        return(TNG_CRITICAL); +    }      switch(data->datatype)      { @@ -7050,7 +7059,7 @@ tng_function_status tng_particle_data_get(tng_trajectory_t tng_data,      memcpy(new_data->values, data->values, size * data->n_frames *             n_particles * data->n_values_per_frame); -    values = &new_data->values; +    *values = new_data->values;      return(TNG_SUCCESS);  } diff --git a/src/tests/tng_io_testing.c b/src/tests/tng_io_testing.c index e9881bc..e10e829 100644 --- a/src/tests/tng_io_testing.c +++ b/src/tests/tng_io_testing.c @@ -6,7 +6,7 @@ -static tng_function_status tng_setup_test_molecules(tng_trajectory_t traj) +static tng_function_status tng_test_setup_molecules(tng_trajectory_t traj)  {      struct tng_molecule *molecule;      struct tng_chain *chain; @@ -131,7 +131,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)      tng_function_status stat;      /* Create molecules */ -    if(tng_setup_test_molecules(traj) == TNG_CRITICAL) +    if(tng_test_setup_molecules(traj) == TNG_CRITICAL)      {          return(TNG_CRITICAL);      } @@ -251,7 +251,7 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)      stat = tng_file_headers_read(traj, TNG_SKIP_HASH);      while(stat != TNG_CRITICAL && traj->input_file_pos < traj->input_file_len && -          traj->current_trajectory_frame_set.next_frame_set_file_pos != -1ULL) +          traj->current_trajectory_frame_set.next_frame_set_file_pos != -1)      {          stat = tng_frame_set_read_next(traj, TNG_SKIP_HASH);          if(stat == TNG_CRITICAL) @@ -263,6 +263,37 @@ static tng_function_status tng_test_write_and_read_traj(tng_trajectory_t traj)      return(stat);  } +/* This test relies on knowing that the positions are stored as float + * and that the data is not sparse (i.e. as many frames in the data + * as in the frame set */ +tng_function_status tng_test_get_particle_data(tng_trajectory_t traj) +{ +    union data_values ***values = 0; + +    if(tng_particle_data_get(traj, TNG_TRAJ_POSITIONS, &values) != +       TNG_SUCCESS) +    { +        printf("Failed getting particle data. %s: %d\n", __FILE__, __LINE__); +        return(TNG_CRITICAL); +    } + +/* +    int64_t i, j; +    struct tng_trajectory_frame_set *frame_set = +    &traj->current_trajectory_frame_set; +    for(i = 0; i<frame_set->n_frames; i++) +    { +        printf("Frame %"PRId64"\n", frame_set->first_frame + i); +        for(j = 0; j<traj->n_particles; j++) +        { +            printf("Particle %"PRId64": %f\t%f\t%f\n", j, (values[i][j][0]).f, +                   (values[i][j][1]).f, (values[i][j][2]).f); +        } +    } +*/     +    return(TNG_SUCCESS); +} +  int main()  {      struct tng_trajectory traj; @@ -312,7 +343,7 @@ int main()      tng_output_file_set(&traj, "/tmp/tng_test.tng"); -     +      if(tng_test_write_and_read_traj(&traj) == TNG_CRITICAL)      {          printf("Test Write and read file:\t\t\tFailed. %s: %d\n", @@ -323,6 +354,16 @@ int main()          printf("Test Write and read file:\t\t\tSucceeded.\n");      } +    if(tng_test_get_particle_data(&traj) != TNG_SUCCESS) +    { +        printf("Test Get particle data:\t\t\tFailed. %s: %d\n", +               __FILE__, __LINE__); +    } +    else +    { +        printf("Test Get particle data:\t\t\tSucceeded.\n"); +    } +      if(tng_trajectory_destroy(&traj) == TNG_CRITICAL)      {          printf("Test Destroy trajectory:\t\t\tFailed. %s: %d.\n",  | 
