Пример #1
0
        static void test_h5s_basic()
        {
            try
            {
                int rank;		// Logical rank of dataspace
                hsize_t[] dims1 = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
                hsize_t[] dims2 = {SPACE2_DIM1, SPACE2_DIM2, SPACE2_DIM3, SPACE2_DIM4};
                hsize_t[] max2 = {SPACE2_MAX1, SPACE2_MAX2, SPACE2_MAX3, SPACE2_MAX4};
                hsize_t[] tmax = new hsize_t[4];

                // Output message about test being performed.
                Console.Write("Testing Dataspace Manipulation");

                // Create a simple dataspace and check its rank.
                H5DataSpaceId sid1 = H5S.create_simple(SPACE1_RANK, dims1);
                rank = H5S.getSimpleExtentNDims(sid1);
                if (rank != SPACE1_RANK)
                {
                    Console.WriteLine("\ntest_h5s_basic: Incorrect rank {0}, should be SPACE1_RANK({1})",
                                        rank, SPACE1_RANK);
                    nerrors++;
                }

                // Check its dims.
                hsize_t[] tdims1 = new hsize_t[3];
                tdims1 = H5S.getSimpleExtentDims(sid1);
                int i;
                for (i = 0; i < rank; i++)
                {
                    if (tdims1[i] != dims1[i])
                    {
                        Console.WriteLine("\ntest_h5s_basic: read tdims1[{0}] = {1} differs from dims1[{0}] = {2}", i, tdims1[i], dims1[i]);
                        nerrors++;
                    }
                }

                // Create another simple dataspace and check its rank, dims, and maxdims.
                H5DataSpaceId sid2 = H5S.create_simple(SPACE2_RANK, dims2, max2);

                rank = H5S.getSimpleExtentNDims(sid2);
                if (rank != SPACE2_RANK)
                {
                    Console.WriteLine("\ntest_h5s_basic: Incorrect rank {0}, should be SPACE1_RANK({1})",
                                        rank, SPACE1_RANK);
                    nerrors++;
                }

                hsize_t[] tdims2 = new hsize_t[3];
                tdims2 = H5S.getSimpleExtentDims(sid2);
                tmax = H5S.getSimpleExtentMaxDims(sid2);

                for (i = 0; i < rank; i++)
                {
                    if (tdims2[i] != dims2[i])
                    {
                        Console.WriteLine("\ntest_h5s_basic: read tdims2[{0}] = {1} differs from dims2[{0}] = {2}", i, tdims2[i], dims2[i]);
                        nerrors++;
                    }
                }

                for (i = 0; i < rank; i++)
                {
                    if (tmax[i] != max2[i])
                    {
                        Console.WriteLine("\ntest_h5s_basic: read tmax[{0}] = {1} differs from max2[{0}] = {2}", i, tmax[i], max2[i]);
                        nerrors++;
                    }
                }

                // Close all dataspaces.
                H5S.close(sid1);
                H5S.close(sid2);

                /*
                 * Try writing simple dataspaces without setting their extents.
                 */
                // Create the file
                H5FileId fid1 = H5F.create(BASICFILE, H5F.CreateMode.ACC_TRUNC);

                // Create dataspaces for testing.
                dims1[0]=SPACE1_DIM1;
                sid1 = H5S.create(H5S.H5SClass.SIMPLE);
                sid2 = H5S.create_simple(1, dims1, dims1);

                // This dataset's space has no extent; it should not be created
                try
                {
                    H5DataSetId dset1 = H5D.create(fid1, BASICDATASET, H5T.H5Type.NATIVE_INT, sid1);

                    // should fail, but didn't, print an error message.
                    Console.WriteLine("\ntest_h5s_basic: Attempting to create a dataset whose space has no extent.");
                    nerrors++;
                }
                catch (H5DcreateException) {} // does nothing, it should fail

                // Create dataset with good dataspace.
                H5DataSetId dataset = H5D.create(fid1, BASICDATASET2, H5T.H5Type.NATIVE_INT, sid2);

                // Try some writes with the bad dataspace (sid1)
                try
                {
                    hssize_t nelems=10; // Number of dataspace elements
                    H5D.writeScalar(dataset, new H5DataTypeId(H5T.H5Type.NATIVE_INT), sid1, sid2, new H5PropertyListId(H5P.Template.DEFAULT), ref nelems);

                    // should fail, but didn't, print an error message.
                    Console.WriteLine("\ntest_h5s_basic: Attempting to write to a dataset with space that has no extent.");
                    nerrors++;
                }
                catch (H5DwriteException) {} // does nothing, it should fail

                // Make sure that dataspace reads using the bad dataspace fail
                try
                {
                    hssize_t n = 10; // Number of dataspace elements
                    H5D.readScalar(dataset, new H5DataTypeId(H5T.H5Type.NATIVE_INT), sid1, sid2, 
                        new H5PropertyListId(H5P.Template.DEFAULT), ref n);

                    // should fail, but didn't, print an error message.
                    Console.WriteLine("\ntest_h5s_basic: Attempting to read a dataset with space that has no extent.");
                    nerrors++;
                }
                catch (H5DreadException) {} // does nothing, it should fail

                // Close objects and file.
                H5D.close(dataset);
                H5S.close(sid1);
                H5S.close(sid2);
                H5F.close(fid1);

                Console.WriteLine("\t\tPASSED");
            } // end of try
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
        } // test_h5s_basic
Пример #2
0
        static void test_h5s_scalar()
        {
            try
            {
                hsize_t[] tdims = new hsize_t[3];
                
                // Output message about test being performed.
                Console.Write("Testing Dataspace during Writing");

                // Create the file.
                H5FileId fid1 = H5F.create(DATAFILE, H5F.CreateMode.ACC_TRUNC); 

                // Create scalar dataspace.
                H5DataSpaceId sid1 = H5S.create_simple(SPACE3_RANK, null);

                // Get the logical rank of dataspace and verify it.
                int rank = H5S.getSimpleExtentNDims(sid1);
                if (rank != SPACE3_RANK)
                {
                    Console.WriteLine("\ntest_h5s_scalar: incorrect rank {0}, should be SPACE3_RANK({1})", rank, SPACE3_RANK);
                    nerrors++;
                }

                // Create and write the dataset.
                uint space3_data = 65;
                H5DataSetId dataset = H5D.create(fid1, "Dataset1", H5T.H5Type.NATIVE_UINT, sid1);
                H5D.writeScalar(dataset, new H5DataTypeId(H5T.H5Type.NATIVE_UINT), ref space3_data);

                // Close objects and file.
                H5D.close(dataset);
                H5S.close(sid1);
                H5F.close(fid1);

                /* Open the file and verify the dataspace. */

                // Open the file.
                fid1 = H5F.open(DATAFILE, H5F.OpenMode.ACC_RDWR);

                // Create a dataset.
                dataset = H5D.open(fid1, "Dataset1");

                // Get dataset's dataspace.
                sid1 = H5D.getSpace(dataset);

                rank = H5S.getSimpleExtentNDims(sid1);
                if (rank != SPACE3_RANK)
                    Console.WriteLine("\ntest_h5s_scalar: incorrect rank {0}", rank);

                tdims = H5S.getSimpleExtentDims(sid1);
                //Console.WriteLine("tdims[0] = {0}, tdims[1] = {1}", tdims[0], tdims[1]);
                if (rank != 0)
                    Console.WriteLine("\ntest_h5s_scalar: incorrect rank {0}", rank);

                // Read the dataset.
                uint rdata=0;
                H5D.readScalar(dataset, new H5DataTypeId(H5T.H5Type.NATIVE_UINT), ref rdata);
                if (rdata != space3_data)
                    Console.WriteLine("\ntest_h5s_scalar: incorrect data {0}, should be {1}", rdata, space3_data);

                // Close objects.
                H5D.close(dataset);
                H5S.close(sid1);
                H5F.close(fid1);

                Console.WriteLine("\tPASSED");
            } // end of try
            catch (HDFException anyHDF5E)
            {
                Console.WriteLine(anyHDF5E.Message);
                nerrors++;
            }
            catch (System.Exception sysE)
            {
                Console.WriteLine(sysE.TargetSite);
                Console.WriteLine(sysE.Message);
                nerrors++;
            }
        }	// test_h5s_scalar_write