Re: [Hdf-forum] c# read different datatypes

2013-04-12 Thread coolshashi
Here is a C# class that i created for my application to read / write some 2D
and 3D arrays and basic data types. It has functions to read / write
strings. I have not used compound data. Hope this helps a bit.

Shashi

class HDFFileHandler
{
public enum DataTypes
{
STRING,
INTEGER,
DOUBLE,
BYTE,
USHORT,
FLOAT
}

public H5FileId CreateFile(string filename)
{
return H5F.create(filename, H5F.CreateMode.ACC_TRUNC);
}
public H5GroupId CreateGroup(string groupName, H5LocId parentGroup)
{
return H5G.create(parentGroup, groupName);
}
public H5DataSetId Create1DDataSet(string datasetName,
H5FileOrGroupId parentGroup, DataTypes datatype, int size)
{
long[] dims = new long[1];
dims[0] = size;

H5DataSpaceId spaceId = H5S.create_simple(1, dims);
H5DataTypeId typeId = null;
switch (datatype)
{
case DataTypes.BYTE:
typeId = H5T.copy(H5T.H5Type.NATIVE_UCHAR);
break;
case DataTypes.DOUBLE:
typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
break;
case DataTypes.INTEGER:
typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
break;
case DataTypes.STRING:
typeId = H5T.copy(H5T.H5Type.C_S1);
break;
case DataTypes.FLOAT:
typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
break;
case DataTypes.USHORT:
typeId = H5T.copy(H5T.H5Type.NATIVE_USHORT);
break;
default:
break;
}
return H5D.create(parentGroup, datasetName, typeId, spaceId);
}
public H5DataSetId Create2DDataSet(string datasetName,
H5FileOrGroupId parentGroup, DataTypes datatype, int sizeX, int sizeY)
{
long[] dims = new long[2];
dims[0] = sizeX;
dims[1] = sizeY;

H5DataSpaceId spaceId = H5S.create_simple(2, dims);
H5DataTypeId typeId = null;
switch (datatype)
{
case DataTypes.BYTE:
typeId = H5T.copy(H5T.H5Type.NATIVE_UCHAR);
break;
case DataTypes.DOUBLE:
typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
break;
case DataTypes.INTEGER:
typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
break;
case DataTypes.STRING:
typeId = H5T.copy(H5T.H5Type.C_S1);
break;
case DataTypes.FLOAT:
typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
break;
case DataTypes.USHORT:
typeId = H5T.copy(H5T.H5Type.NATIVE_USHORT);
break;
default:
break;
}
return H5D.create(parentGroup, datasetName, typeId, spaceId);
}
public H5DataSetId Create3DDataSet(string datasetName,
H5FileOrGroupId parentGroup, DataTypes datatype, int sizeX, int sizeY, int
nSizeZ)
{
long[] dims = new long[3];
dims[0] = sizeX;
dims[1] = sizeY;
dims[2] = nSizeZ;

H5DataSpaceId spaceId = H5S.create_simple(3, dims);
H5DataTypeId typeId = null;
switch (datatype)
{
case DataTypes.BYTE:
typeId = H5T.copy(H5T.H5Type.NATIVE_UCHAR);
break;
case DataTypes.DOUBLE:
typeId = H5T.copy(H5T.H5Type.NATIVE_DOUBLE);
break;
case DataTypes.INTEGER:
typeId = H5T.copy(H5T.H5Type.NATIVE_INT);
break;
case DataTypes.STRING:
typeId = H5T.copy(H5T.H5Type.C_S1);
break;
case DataTypes.FLOAT:
typeId = H5T.copy(H5T.H5Type.NATIVE_FLOAT);
break;
case DataTypes.USHORT:
typeId = H5T.copy(H5T.H5Type.NATIVE_USHORT);
break;
default:
break;
}
return H5D.create(parentGroup, datasetName, typeId, spaceId);
}
public void CloseFile(H5FileId fileId)
{
H5F.close(fileId);
}
public void CloseGroup(H5GroupId grpId)
{
H5G.close(grpId);
}
public void CloseDataset(H5DataSetId datasetId)
{
H5D.close(datasetId);
}
public H5FileId OpenFile(string filename, 

Re: [Hdf-forum] c# read different datatypes

2013-04-12 Thread coolshashi
I use that class in my project to read and write strings..And it works
perfectly.

If you had written the string using the write method i have in my class the
read should work..May be the way you have written is different than mine.



--
View this message in context: 
http://hdf-forum.184993.n3.nabble.com/c-read-different-datatypes-tp4026057p4026089.html
Sent from the hdf-forum mailing list archive at Nabble.com.

___
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org