LightVoting
 All Classes Namespaces Files Functions Variables Pages
CDataWriter.java
Go to the documentation of this file.
1 
24 package org.lightvoting;
25 
26 import org.bytedeco.javacpp.IntPointer;
27 import org.bytedeco.javacpp.hdf5;
28 
32 public final class CDataWriter
33 {
34  // source: https://github.com/bytedeco/javacpp-presets/tree/master/hdf5#the-srcmainjavah5tutrcmprssjava-source-file
35 
36  private CDataWriter()
37  {
38 
39  }
40 
44  public static void createHDF5( final String p_filename )
45  {
46 
47  // Create a new file.
48  try
49  {
50  final hdf5.H5File l_h5file = new hdf5.H5File( p_filename, org.bytedeco.javacpp.hdf5.H5F_ACC_TRUNC );
51  l_h5file.close();
52  }
53  catch ( final Exception l_ex )
54  {
55  l_ex.printStackTrace();
56  }
57  }
58 
64  public static void test( final String p_name )
65  {
66  final hdf5.H5File l_file = new hdf5.H5File();
67  l_file.openFile( p_name, hdf5.H5F_ACC_RDWR );
68 
69  final String l_DATASETNAME = "Results";
70  final int l_DIM0 = 100;
71  final int l_DIM1 = 20;
72 
73  // dataset dimensions
74  final long[] l_dims = {l_DIM0, l_DIM1};
75  // chunk dimensions
76  final long[] l_chunkDims = {20, 20};
77  final int[] l_buf = new int[l_DIM0 * l_DIM1];
78 
79 
80 
81  // Create the data space for the dataset.
82  final hdf5.DataSpace l_dataSpace = new hdf5.DataSpace( 2, l_dims );
83 
84  // Modify dataset creation property to enable chunking
85  final hdf5.DSetCreatPropList l_plist = new hdf5.DSetCreatPropList();
86  l_plist.setChunk( 2, l_chunkDims );
87 
88  final hdf5.DataSet l_dataset = new hdf5.DataSet( l_file.asCommonFG().createDataSet( l_DATASETNAME,
89  new hdf5.DataType( hdf5.PredType.STD_I32BE() ), l_dataSpace, l_plist ) );
90 
91  for ( int i = 0; i < l_DIM0; i++ )
92  for ( int j = 0; j < l_DIM1; j++ )
93  l_buf[i * l_DIM1 + j] = i + j;
94 
95  // Write data to dataset.
96  l_dataset.write( new IntPointer( l_buf ), new hdf5.DataType( hdf5.PredType.NATIVE_INT() ) );
97 
98  l_dataSpace.close();
99  l_dataset.close();
100  l_plist.close();
101  l_file._close();
102  }
103 }
Created by sophie on 15.05.17.
static void test(final String p_name)
test for h5 file
static void createHDF5(final String p_filename)
create HDF5 file