title: How do I store multiple data read from hdf5 files in one array?
body: <p>I'm trying to pre-load a bunch of matrices from HDF5 files and store them in one dynamic array. However, I'm not able to get it to work like I would like it to.
  For some reason that I can't figure out, the whole array is overwritten rather than the sub-array. Any ideas how to fix that?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>short ***data[line_count];
  short** dset_data;
  
  for (int file_index = 0; file_index &lt; line_count; ++file_index){
      dset_data = (short**) malloc(DIM_Y * sizeof(short*));
      dset_data[0] = (short*) malloc(DIM_Y * DIM_X * sizeof(short));
      for (int i=1; i &lt; DIM_Y; i++)
        dset_data[i] = dset_data[0] + i * DIM_X;
  
      for (int y = 0; y &lt; DIM_Y; y++) {
          for (int x = 0; x &lt; DIM_X; x++) {
                  dset_data[y][x] = 0;
          }
      }
      /* Open an existing file. */
      file_id = H5Fopen(input_files[file_index], H5F_ACC_RDONLY, H5P_DEFAULT);
  
      /* Open an existing dataset. */
      dataset_id = H5Dopen2(file_id, "data/data", H5P_DEFAULT);
  
      /* Read dataset */
      status = H5Dread(dataset_id, H5T_NATIVE_SHORT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &amp;dset_data[0][0]);
  
      /* Store two dimensional array at n-th position in data array */
      data[file_index] = &amp;dset_data;
  
      /* Close the dataset. */
      status = H5Dclose(dataset_id);
  
      /* Close the file. */
      status = H5Fclose(file_id);
  }
  </code></pre>