Not able to see the data in the created .h5 file

Hi,

I tried writing some data to .h5 file and I used the same code as provided in the example.cs file:

HDFqlCursor myCursor;
int[,] values;
int x;
int y;

		// display HDFql version in use
		System.Console.WriteLine("HDFql version: {0}", HDFql.Version);

		// create an HDF5 file named "example.h5"
		HDFql.Execute("CREATE FILE Example.h5");

		// use (i.e. open) HDF5 file "example.h5"
		HDFql.Execute("USE FILE Example.h5");

		// show (i.e. get) HDF5 file currently in use and populate HDFql default cursor with it
		HDFql.Execute("SHOW USE FILE");

		// display HDF5 file currently in use
		HDFql.CursorFirst();
		System.Console.WriteLine("File in use: {0}", HDFql.CursorGetChar());

		// create an attribute named "example_attribute" of data type float with an initial value of 12.4
		HDFql.Execute("CREATE ATTRIBUTE example_attribute AS FLOAT VALUES(12.4)");

		// select (i.e. read) data from attribute "example_attribute" and populate HDFql default cursor with it
		HDFql.Execute("SELECT FROM example_attribute");

		// display value of attribute "example_attribute"
		HDFql.CursorFirst();
		System.Console.WriteLine("Attribute value: {0}", HDFql.CursorGetFloat());

		// create a dataset named "example_dataset" of data type int of two dimensions (size 3x2)
		HDFql.Execute("CREATE DATASET example_dataset AS INT(3, 2)");

		// create variable "values" and populate it with certain values
		values = new int[3, 2];
		for (x = 0; x < 3; x++)
		{
			for (y = 0; y < 2; y++)
			{
				values[x, y] = x * 2 + y + 1;
			}
		}

		// register variable "values" for subsequent use (by HDFql)
		HDFql.VariableRegister(values);

		// insert (i.e. write) values from variable "values" into dataset "example_dataset"
		HDFql.Execute("INSERT INTO example_dataset VALUES FROM MEMORY " + HDFql.VariableGetNumber(values));

		// populate variable "values" with zeros (i.e. reset variable)
		for (x = 0; x < 3; x++)
		{
			for (y = 0; y < 2; y++)
			{
				values[x, y] = 0;
			}
		}

		// select (i.e. read) data from dataset "example_dataset" and populate variable "values" with it
		HDFql.Execute("SELECT FROM example_dataset INTO MEMORY " + HDFql.VariableGetNumber(values));

		// unregister variable "values" as it is no longer used/needed (by HDFql)
		HDFql.VariableUnregister(values);

		// display content of variable "values"
		System.Console.WriteLine("Dataset value (through variable):");
		for (x = 0; x < 3; x++)
		{
			for (y = 0; y < 2; y++)
			{
				System.Console.WriteLine(values[x, y]);
			}
		}

		// select (i.e. read) data from dataset "example_dataset" again and populate HDFql default cursor with it
		HDFql.Execute("SELECT FROM example_dataset");

		// display content of HDFql default cursor
		System.Console.WriteLine("Dataset value (through cursor):");
		while (HDFql.CursorNext() == HDFql.Success)
		{
			System.Console.WriteLine(HDFql.CursorGetInt());
		}

		// create cursor "myCursor"
		myCursor = new HDFqlCursor();

		// use cursor "myCursor"
		HDFql.CursorUse(myCursor);

		// show (i.e. get) size (in bytes) of dataset "example_dataset" and populate cursor "myCursor" with it
		HDFql.Execute("SHOW SIZE example_dataset");

		// display content of cursor "myCursor"
		HDFql.CursorFirst();
		System.Console.WriteLine("Dataset size (in bytes): {0}", HDFql.CursorGetBigint());

I’m not getting any error, but after running my code if I open the created .h5 file, it doesn’t show any data. The size of the file shows as 3 KB though.

Please let me know if I’m missing anything.

Thanks in advance.

Hi @leelakrishna.k,

Good news there are no errors and that the HDF5 file was successfully created. In addition, it seems that the dataset was successfully created too (based on the size of the file you have posted).

Could it be that after running the code snippet, your IDE immediately closes the terminal containing the output of the execution (giving the impression that nothing is shown)?

Hope it helps!

Hi Team,

I attached a screenshot of output what we are getting in the Console and HDFView. we can’t able to see any data in the HDFView.

Please kindly let us know the solution for this.

Thanks in advance
Leelakrishna

Hi @leelakrishna.k,

It seems that you are viewing another (empty) HDF5 file instead of the HDF5 file with a size ~3 KB (the one you made reference to in the beginning of this thread).

Would you mind to attach to this thread the HDF5 file with a size ~3 KB, as well as the output of running the C# code snippet you have posted?

Thanks!

Or, even better, go to https://myhdf5.hdfgroup.org/, open it in a browser, and send us a screenshot! G.

1 Like

From the screenshot, maybe you are looking at the wrong file. According to the code it’s going to be Example.h5, not example.h5. Your file system is probably case-sensitive.

G.

Hi,

Please find the Screenshot attached.

Thanks

Yes, that’s example.h5, but what about Example.h5? G.

Hi Team,

I’m using the following code to create a dataset dn write it to the .h5 file (painters.h5)

int[,] values = new int[200, 150];
string script;
int x;
int y;
HDFql.Execute(“CREATE FILE painters.h5”);
HDFql.Execute(“USE FILE painters.h5”);
HDFql.Execute(“CREATE GROUP picasso ORDER TRACKED”);
HDFql.Execute(“CREATE CHUNKED(40, 30) DATASET picasso / guernica AS INT(200, 150) ENABLE FLETCHER32”);
for (x = 0; x < 200; x++)
{
for (y = 0; y < 150; y++)
{
values[x, y] = x * 150 + y;
}
}
script = string.Format(“INSERT INTO picasso / guernica VALUES FROM MEMORY % d”, values);
//sprintf(script, “INSERT INTO picasso / guernica VALUES FROM MEMORY % d”, hdfql_variable_transient_register(values));
HDFql.Execute(script);
HDFql.Execute(“CREATE ATTRIBUTE picasso / guernica / subject AS UTF8 VARCHAR VALUES("guerra civil española")”);
HDFql.Execute(“CLOSE FILE”);

The file size is displayed as 2 KB
image

However, when I open the file in HDFView, I don’t see any data in it.

Please let me know if I’m missing anything here

Thanks,
Leelakrishna

Hi @leelakrishna.k,

Looking at the last code snippet you have posted, it seems that you have copied it from HDFql website examples. Unfortunately, the posted code snippet has been modified, which has now several issues. Probably the best is to just copy it again (from the website) or from here:

using AS.HDFql;

public class Example
{
    public static void Main(string[] args)
    {
        int[,] values = new int[200, 150];
        int x;
        int y;
        HDFql.Execute("CREATE FILE painters.h5");
        HDFql.Execute("USE FILE painters.h5");
        HDFql.Execute("CREATE GROUP picasso ORDER TRACKED");
        HDFql.Execute("CREATE CHUNKED(40, 30) DATASET picasso/guernica AS INT(200, 150) ENABLE FLETCHER32"));
        for(x = 0; x < 200; x++)
        {
            for(y = 0; y < 150; y++)
            {
                values[x, y] = x * 150 + y;
            }
        }
        HDFql.Execute("INSERT INTO picasso/guernica VALUES FROM MEMORY " + HDFql.VariableTransientRegister(values));
        HDFql.Execute("CREATE ATTRIBUTE picasso/guernica/subject AS UTF8 VARCHAR VALUES(\"guerra civil española\")");
        HDFql.Execute("CLOSE FILE");
    }
}

Hope it helps!

1 Like

Thank you much team for the solution it helps !

And please kindly let us know how to read the same data from the HDF5 file.

1 Like

Hi @leelakrishna.k,

Great to know that it works now!

Please use HDFql SELECT operation if you wish to read the same data from the HDF5 file. To read dataset guernica do the following (this will populate HDFql cursor - see section 4 of the reference manual to get additional details on how to work with cursors):

HDFql.Execute("SELECT FROM picasso/guernica");

// implement code that traverses cursor and processes its data

That said, in case you wish to populate a (user-defined) variable (instead of a cursor) with the values of the dataset, just do the following instead:

int[,] read = new int[200, 150];

HDFql.Execute("SELECT FROM picasso/guernica INTO MEMORY " + HDFql.VariableTransientRegister(read));

// implement code that processes data stored in variable 'read'

Hope it helps!

Hi team,

Thanks for the response.

i tried in the way u explained and while implementing it in our sample we got strucked and I’m using the following code to read the data from HDF5 file.

		// Reading the data from HDF5 file.

        HDFql.Execute("USE FILE painters1.h5");
        HDFql.Execute("SELECT FROM picasso/guernica");
        HDFql.CursorFirst();

        int[,] read = new int[200, 150];

        HDFql.Execute("SELECT FROM picasso/guernica INTO MEMORY " + HDFql.VariableTransientRegister(values));

	}

I’m attaching the HDF5 file below which we are trying to read.

painters1.h5 (125.4 KB)

Please kindly help us to get the exact solution for this.

Thanks in advance.

Hi again @leelakrishna.k,

The last code snippet you posted reads twice dataset guernica: the first read will populate HDFql cursor, while the second will populate (user-defined) variable read.

Concerning the first read, do the following after executing the SELECT operation:

while(HDFql.CursorNext() == HDFql.Success)
{
    System.Console.WriteLine("Value from cursor=" + HDFql.CursorGetInt());
}

Concerning the second read, do the following after executing the SELECT operation:

for(int x = 0; x < 200; x++)
{
    for(int y = 0; y < 150; y++)
    {
        System.Console.WriteLine("Value from variable=" + read[x, y]);
    }
}

Hope it helps!

Thank you so much it helped us and working fine.

1 Like