diff options
author | Robb Matzke <matzke@llnl.gov> | 1998-08-31 19:21:23 (GMT) |
---|---|---|
committer | Robb Matzke <matzke@llnl.gov> | 1998-08-31 19:21:23 (GMT) |
commit | 2ab2e14bb59d6ae7013bba9458e9f5a3b5cc2d1a (patch) | |
tree | c23cdadb45857e5e8549bb14fd057db63cce7c26 /examples/h5_read.c | |
parent | 473452205dcc08055486d29b6dc5f36670c3ceb5 (diff) | |
download | hdf5-2ab2e14bb59d6ae7013bba9458e9f5a3b5cc2d1a.zip hdf5-2ab2e14bb59d6ae7013bba9458e9f5a3b5cc2d1a.tar.gz hdf5-2ab2e14bb59d6ae7013bba9458e9f5a3b5cc2d1a.tar.bz2 |
[svn-r635] Changes since 19980831
----------------------
./Makefile.in
Running `make distclean' will not fail if one of the
subdirectories has already been cleaned.
./config/BlankForm
./config/irix5.3
Cleaned it up more. Added better support/documentation for
systems that have more than one compiler.
./config/alpha-dec-osf4.0 [NEW]
Added a new config file as a result of testing on Jim Reus's
machine.
./test/chunk.c
Scaled down the testing range so we can actually run it
interactively.
./tools/h5import.c
Included <unistd.h> to get rid of warning for close().
./src/H5detect.c
Seg-faults on Linux for some reason when NDEBUG is defined, so
I just undef it at the top of the source.
./test/big.c
Added a fflush().
./tools/h5ls.c
The `-d' flag now works even when `-v' isn't specified.
./examples/h5_chunk_read.c
./examples/h5_compound.c
./examples/h5_extend_write.c
./examples/h5_group.c
./examples/h5_read.c
./examples/h5_write.c
Indented according to hdf5 standards.
Fixed compiler warnings
Diffstat (limited to 'examples/h5_read.c')
-rw-r--r-- | examples/h5_read.c | 198 |
1 files changed, 102 insertions, 96 deletions
diff --git a/examples/h5_read.c b/examples/h5_read.c index 51bf381..599ba59 100644 --- a/examples/h5_read.c +++ b/examples/h5_read.c @@ -17,114 +17,120 @@ #define RANK 2 #define RANK_OUT 3 -main () +int +main (void) { - hid_t file, dataset; /* handles */ - hid_t datatype, dataspace; - hid_t memspace; - H5T_class_t class; /* data type class */ - H5T_order_t order; /* data order */ - size_t size; /* size of the data element - stored in file */ - hsize_t dimsm[3]; /* memory space dimensions */ - hsize_t dims_out[2]; /* dataset dimensions */ - herr_t status; + hid_t file, dataset; /* handles */ + hid_t datatype, dataspace; + hid_t memspace; + H5T_class_t class; /* data type class */ + H5T_order_t order; /* data order */ + size_t size; /* + * size of the data element + * stored in file + */ + hsize_t dimsm[3]; /* memory space dimensions */ + hsize_t dims_out[2]; /* dataset dimensions */ + herr_t status; - int data_out[NX][NY][NZ ]; /* output buffer */ + int data_out[NX][NY][NZ ]; /* output buffer */ - hsize_t count[2]; /* size of the hyperslab in the file */ - hsize_t offset[2]; /* hyperslab offset in the file */ - hsize_t count_out[3]; /* size of the hyperslab in memory */ - hsize_t offset_out[3]; /* hyperslab offset in memory */ - int i, j, k, status_n, rank; + hsize_t count[2]; /* size of the hyperslab in the file */ + hsize_t offset[2]; /* hyperslab offset in the file */ + hsize_t count_out[3]; /* size of the hyperslab in memory */ + hsize_t offset_out[3]; /* hyperslab offset in memory */ + int i, j, k, status_n, rank; -for (j = 0; j < NX; j++) { - for (i = 0; i < NY; i++) { - for (k = 0; k < NZ ; k++) - data_out[j][i][k] = 0; - } -} + for (j = 0; j < NX; j++) { + for (i = 0; i < NY; i++) { + for (k = 0; k < NZ ; k++) + data_out[j][i][k] = 0; + } + } -/* - * Open the file and the dataset. - */ -file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT); -dataset = H5Dopen(file, DATASETNAME); + /* + * Open the file and the dataset. + */ + file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT); + dataset = H5Dopen(file, DATASETNAME); -/* - * Get datatype and dataspace handles and then query - * dataset class, order, size, rank and dimensions. - */ + /* + * Get datatype and dataspace handles and then query + * dataset class, order, size, rank and dimensions. + */ + datatype = H5Dget_type(dataset); /* datatype handle */ + class = H5Tget_class(datatype); + if (class == H5T_INTEGER) printf("Data set has INTEGER type \n"); + order = H5Tget_order(datatype); + if (order == H5T_ORDER_LE) printf("Little endian order \n"); -datatype = H5Dget_type(dataset); /* datatype handle */ -class = H5Tget_class(datatype); -if (class == H5T_INTEGER) printf("Data set has INTEGER type \n"); -order = H5Tget_order(datatype); -if (order == H5T_ORDER_LE) printf("Little endian order \n"); + size = H5Tget_size(datatype); + printf(" Data size is %d \n", size); -size = H5Tget_size(datatype); -printf(" Data size is %d \n", size); + dataspace = H5Dget_space(dataset); /* dataspace handle */ + rank = H5Sextent_ndims(dataspace); + status_n = H5Sextent_dims(dataspace, dims_out, NULL); + printf("rank %d, dimensions %lu x %lu \n", rank, + (unsigned long)(dims_out[0]), (unsigned long)(dims_out[1])); -dataspace = H5Dget_space(dataset); /* dataspace handle */ -rank = H5Sextent_ndims(dataspace); -status_n = H5Sextent_dims(dataspace, dims_out, NULL); -printf("rank %d, dimensions %d x %d \n", rank, dims_out[0], dims_out[1]); - -/* - * Define hyperslab in the datatset. - */ -offset[0] = 1; -offset[1] = 2; -count[0] = NX_SUB; -count[1] = NY_SUB; -status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL, - count, NULL); + /* + * Define hyperslab in the datatset. + */ + offset[0] = 1; + offset[1] = 2; + count[0] = NX_SUB; + count[1] = NY_SUB; + status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL, + count, NULL); -/* - * Define the memory dataspace. - */ -dimsm[0] = NX; -dimsm[1] = NY; -dimsm[2] = NZ ; -memspace = H5Screate_simple(RANK_OUT,dimsm,NULL); + /* + * Define the memory dataspace. + */ + dimsm[0] = NX; + dimsm[1] = NY; + dimsm[2] = NZ ; + memspace = H5Screate_simple(RANK_OUT,dimsm,NULL); -/* - * Define memory hyperslab. - */ -offset_out[0] = 3; -offset_out[1] = 0; -offset_out[2] = 0; -count_out[0] = NX_SUB; -count_out[1] = NY_SUB; -count_out[2] = 1; -status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL, - count_out, NULL); + /* + * Define memory hyperslab. + */ + offset_out[0] = 3; + offset_out[1] = 0; + offset_out[2] = 0; + count_out[0] = NX_SUB; + count_out[1] = NY_SUB; + count_out[2] = 1; + status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL, + count_out, NULL); -/* - * Read data from hyperslab in the file into the hyperslab in - * memory and display. - */ -status = H5Dread(dataset, H5T_NATIVE_INT, memspace, dataspace, - H5P_DEFAULT, data_out); -for (j = 0; j < NX; j++) { - for (i = 0; i < NY; i++) printf("%d ", data_out[j][i][0]); - printf("\n"); -} - /* 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 - 3 4 5 6 0 0 0 - 4 5 6 7 0 0 0 - 5 6 7 8 0 0 0 - 0 0 0 0 0 0 0 */ + /* + * Read data from hyperslab in the file into the hyperslab in + * memory and display. + */ + status = H5Dread(dataset, H5T_NATIVE_INT, memspace, dataspace, + H5P_DEFAULT, data_out); + for (j = 0; j < NX; j++) { + for (i = 0; i < NY; i++) printf("%d ", data_out[j][i][0]); + printf("\n"); + } + /* + * 0 0 0 0 0 0 0 + * 0 0 0 0 0 0 0 + * 0 0 0 0 0 0 0 + * 3 4 5 6 0 0 0 + * 4 5 6 7 0 0 0 + * 5 6 7 8 0 0 0 + * 0 0 0 0 0 0 0 + */ -/* - * Close/release resources. - */ -H5Tclose(datatype); -H5Dclose(dataset); -H5Sclose(dataspace); -H5Sclose(memspace); -H5Fclose(file); + /* + * Close/release resources. + */ + H5Tclose(datatype); + H5Dclose(dataset); + H5Sclose(dataspace); + H5Sclose(memspace); + H5Fclose(file); + return 0; } |