diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2009-04-09 20:04:03 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2009-04-09 20:04:03 (GMT) |
commit | 1dffdaa262aae487df0e9103466c14eafd882559 (patch) | |
tree | e1a11928dfe140d4b6f72da481b09164f3a3c52f | |
parent | 3fb6b6d6faee14846100214e6d4ac62efb0441f0 (diff) | |
download | hdf5-1dffdaa262aae487df0e9103466c14eafd882559.zip hdf5-1dffdaa262aae487df0e9103466c14eafd882559.tar.gz hdf5-1dffdaa262aae487df0e9103466c14eafd882559.tar.bz2 |
[svn-r16720] merge 16719
clean warnings linux
tested linux
-rw-r--r-- | hl/src/H5DS.c | 12 | ||||
-rw-r--r-- | hl/src/H5IM.c | 1817 | ||||
-rw-r--r-- | hl/src/H5LT.c | 3328 | ||||
-rw-r--r-- | hl/src/H5TB.c | 2346 | ||||
-rw-r--r-- | hl/test/test_ds.c | 13 | ||||
-rw-r--r-- | hl/test/test_image.c | 463 | ||||
-rw-r--r-- | hl/test/test_lite.c | 1483 | ||||
-rw-r--r-- | hl/test/test_table.c | 646 |
8 files changed, 5052 insertions, 5056 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index c3b444c..9efa95e 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -482,7 +482,7 @@ herr_t H5DSattach_scale(hid_t did, nelmts++; - dsbuf = malloc((size_t)nelmts * sizeof(ds_list_t)); + dsbuf = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t)); if (dsbuf == NULL) goto out; @@ -831,7 +831,7 @@ herr_t H5DSdetach_scale(hid_t did, if((nelmts = H5Sget_simple_extent_npoints(sid)) < 0) goto out; - dsbuf = malloc((size_t)nelmts * sizeof(ds_list_t)); + dsbuf = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t)); if(dsbuf == NULL) goto out; @@ -907,7 +907,7 @@ herr_t H5DSdetach_scale(hid_t did, goto out; dims[0] = nelmts; - dsbufn = malloc((size_t)nelmts * sizeof(ds_list_t)); + dsbufn = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t)); if(dsbufn == NULL) goto out; @@ -1195,7 +1195,7 @@ htri_t H5DSis_attached(hid_t did, if((nelmts = H5Sget_simple_extent_npoints(sid)) < 0) goto out; - dsbuf = malloc((size_t)nelmts * sizeof(ds_list_t)); + dsbuf = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t)); if (dsbuf == NULL) goto out; @@ -1596,7 +1596,7 @@ herr_t H5DSset_label(hid_t did, unsigned int idx, const char *label) goto out; if (buf) { - free((void *) buf); + free(buf); buf = NULL; } } @@ -1652,7 +1652,7 @@ herr_t H5DSset_label(hid_t did, unsigned int idx, const char *label) goto out; if (buf) { - free((void *) buf); + free(buf); buf = NULL; } } diff --git a/hl/src/H5IM.c b/hl/src/H5IM.c index 479b572..361a65b 100644 --- a/hl/src/H5IM.c +++ b/hl/src/H5IM.c @@ -1,17 +1,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +* Copyright by The HDF Group. * +* Copyright by the Board of Trustees of the University of Illinois. * +* All rights reserved. * +* * +* This file is part of HDF5. The full HDF5 copyright notice, including * +* terms governing use, modification, and redistribution, is contained in * +* the files COPYING and Copyright.html. COPYING can be found at the root * +* of the source code distribution tree; Copyright.html can be found at the * +* root level of an installed copy of the electronic HDF5 document set and * +* is linked from the top-level documents page. It can also be found at * +* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * +* access to either file, you may request a copy from help@hdfgroup.org. * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "H5IMprivate.h" #include "H5LTprivate.h" @@ -19,155 +19,156 @@ #include <stdlib.h> /*------------------------------------------------------------------------- - * Function: H5IMmake_image_8bit - * - * Purpose: Creates and writes an image an 8 bit image - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: June 13, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMmake_image_8bit +* +* Purpose: Creates and writes an image an 8 bit image +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: June 13, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMmake_image_8bit( hid_t loc_id, - const char *dset_name, - hsize_t width, - hsize_t height, - const unsigned char *buffer ) + const char *dset_name, + hsize_t width, + hsize_t height, + const unsigned char *buf ) { - hsize_t dims[IMAGE8_RANK]; + hsize_t dims[IMAGE8_RANK]; - /* Initialize the image dimensions */ - dims[0] = height; - dims[1] = width; + /* Initialize the image dimensions */ + dims[0] = height; + dims[1] = width; - /* Make the dataset */ - if ( H5LTmake_dataset( loc_id, dset_name, IMAGE8_RANK, dims, H5T_NATIVE_UCHAR, buffer ) < 0) - return -1; + /* Make the dataset */ + if ( H5LTmake_dataset( loc_id, dset_name, IMAGE8_RANK, dims, H5T_NATIVE_UCHAR, buf ) < 0) + return -1; - /* Attach the CLASS attribute */ - if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0) - return -1; + /* Attach the CLASS attribute */ + if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0) + return -1; - /* Attach the VERSION attribute */ - if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0) - return -1; + /* Attach the VERSION attribute */ + if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0) + return -1; - /* Attach the IMAGE_SUBCLASS attribute */ - if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_INDEXED" ) < 0) - return -1; + /* Attach the IMAGE_SUBCLASS attribute */ + if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_INDEXED" ) < 0) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5IMmake_image_24bit - * - * Purpose: - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: June 13, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Interlace Mode Dimensions in the Dataspace - * INTERLACE_PIXEL [height][width][pixel components] - * INTERLACE_PLANE [pixel components][height][width] - * - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMmake_image_24bit +* +* Purpose: +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: June 13, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Interlace Mode Dimensions in the Dataspace +* INTERLACE_PIXEL [height][width][pixel components] +* INTERLACE_PLANE [pixel components][height][width] +* +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMmake_image_24bit( hid_t loc_id, - const char *dset_name, - hsize_t width, - hsize_t height, - const char *interlace, - const unsigned char *buffer ) + const char *dset_name, + hsize_t width, + hsize_t height, + const char *interlace, + const unsigned char *buf ) { - hsize_t dims[IMAGE24_RANK]; - - /* Initialize the image dimensions */ - - if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 ) - { - /* Number of color planes is defined as the third dimension */ - dims[0] = height; - dims[1] = width; - dims[2] = IMAGE24_RANK; - } - else - if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 ) - { - /* Number of color planes is defined as the first dimension */ - dims[0] = IMAGE24_RANK; - dims[1] = height; - dims[2] = width; - } - else return -1; - - /* Make the dataset */ - if ( H5LTmake_dataset( loc_id, dset_name, IMAGE24_RANK, dims, H5T_NATIVE_UCHAR, buffer ) < 0) - return -1; - - /* Attach the CLASS attribute */ - if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0) - return -1; - - /* Attach the VERSION attribute */ - if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0) - return -1; - - /* Attach the IMAGE_SUBCLASS attribute */ - if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_TRUECOLOR" ) < 0) - return -1; - - /* Attach the INTERLACE_MODE attribute. This attributes is only for true color images */ - if ( H5LTset_attribute_string( loc_id, dset_name, "INTERLACE_MODE", interlace ) < 0) - return -1; - - return 0; + hsize_t dims[IMAGE24_RANK]; + + /* Initialize the image dimensions */ + + if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 ) + { + /* Number of color planes is defined as the third dimension */ + dims[0] = height; + dims[1] = width; + dims[2] = IMAGE24_RANK; + } + else + if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 ) + { + /* Number of color planes is defined as the first dimension */ + dims[0] = IMAGE24_RANK; + dims[1] = height; + dims[2] = width; + } + else return -1; + + /* Make the dataset */ + if ( H5LTmake_dataset( loc_id, dset_name, IMAGE24_RANK, dims, H5T_NATIVE_UCHAR, buf ) < 0) + return -1; + + /* Attach the CLASS attribute */ + if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0) + return -1; + + /* Attach the VERSION attribute */ + if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_VERSION", IMAGE_VERSION ) < 0) + return -1; + + /* Attach the IMAGE_SUBCLASS attribute */ + if ( H5LTset_attribute_string( loc_id, dset_name, "IMAGE_SUBCLASS", "IMAGE_TRUECOLOR" ) < 0) + return -1; + + /* Attach the INTERLACE_MODE attribute. This attributes is only for true color images */ + if ( H5LTset_attribute_string( loc_id, dset_name, "INTERLACE_MODE", interlace ) < 0) + return -1; + + return 0; } /*------------------------------------------------------------------------- - * Function: find_palette - * - * Purpose: operator function used by H5LT_find_palette - * - * Return: - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: May 28, 2001 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static herr_t -find_palette(hid_t loc_id, const char *name, const H5A_info_t *ainfo, - void *op_data) +* Function: find_palette +* +* Purpose: operator function used by H5LT_find_palette +* +* Return: +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: May 28, 2001 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ +static herr_t find_palette(hid_t loc_id, + const char *name, + const H5A_info_t *ainfo, + void *op_data) { int ret = H5_ITER_CONT; @@ -175,9 +176,9 @@ find_palette(hid_t loc_id, const char *name, const H5A_info_t *ainfo, loc_id = loc_id; ainfo = ainfo; op_data = op_data; /* Define a positive value for return value if the attribute was found. This will - * cause the iterator to immediately return that positive value, - * indicating short-circuit success - */ + * cause the iterator to immediately return that positive value, + * indicating short-circuit success + */ if(strcmp(name, "PALETTE") == 0) ret = H5_ITER_STOP; @@ -186,23 +187,23 @@ find_palette(hid_t loc_id, const char *name, const H5A_info_t *ainfo, /*------------------------------------------------------------------------- - * Function: H5IM_find_palette - * - * Purpose: Private function. Find the attribute "PALETTE" in the image dataset - * - * Return: Success: 1, Failure: 0 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: May 11, 2001 - * - * Comments: - * The function uses H5Aiterate2 with the operator function find_palette - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IM_find_palette +* +* Purpose: Private function. Find the attribute "PALETTE" in the image dataset +* +* Return: Success: 1, Failure: 0 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: May 11, 2001 +* +* Comments: +* The function uses H5Aiterate2 with the operator function find_palette +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IM_find_palette( hid_t loc_id ) { @@ -211,1007 +212,1011 @@ herr_t H5IM_find_palette( hid_t loc_id ) /*------------------------------------------------------------------------- - * Function: H5IMget_image_info - * - * Purpose: Gets information about an image dataset (dimensions, interlace mode - * and number of associated palettes). - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: July 25, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMget_image_info +* +* Purpose: Gets information about an image dataset (dimensions, interlace mode +* and number of associated palettes). +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: July 25, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMget_image_info( hid_t loc_id, - const char *dset_name, - hsize_t *width, - hsize_t *height, - hsize_t *planes, - char *interlace, - hssize_t *npals ) + const char *dset_name, + hsize_t *width, + hsize_t *height, + hsize_t *planes, + char *interlace, + hssize_t *npals ) { - hid_t did, sid; - hsize_t dims[IMAGE24_RANK]; - hid_t attr_id; - hid_t attr_type; - int has_attr; - hid_t attr_space_id; - hid_t attr_class; - int has_pal; + hid_t did; + hid_t sid; + hsize_t dims[IMAGE24_RANK]; + hid_t aid; + hid_t asid; + hid_t atid; + H5T_class_t aclass; + int has_pal; + int has_attr; - /*assume initially we have no palettes attached*/ - *npals = 0; + /*assume initially we have no palettes attached*/ + *npals = 0; - /* Open the dataset. */ - if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the dataset. */ + if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) + return -1; - /* Try to find the attribute "INTERLACE_MODE" on the >>image<< dataset */ - has_attr = H5LT_find_attribute(did, "INTERLACE_MODE"); + /* Try to find the attribute "INTERLACE_MODE" on the >>image<< dataset */ + has_attr = H5LT_find_attribute(did, "INTERLACE_MODE"); - /* It exists, get it */ - if(has_attr == 1) - { + /* It exists, get it */ + if(has_attr == 1) + { - if((attr_id = H5Aopen(did, "INTERLACE_MODE", H5P_DEFAULT)) < 0) - goto out; + if((aid = H5Aopen(did, "INTERLACE_MODE", H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((atid = H5Aget_type(aid)) < 0) + goto out; - if(H5Aread(attr_id, attr_type, interlace) < 0) - goto out; + if(H5Aread(aid, atid, interlace) < 0) + goto out; - if(H5Tclose(attr_type) < 0) - goto out; + if(H5Tclose(atid) < 0) + goto out; - if(H5Aclose(attr_id) < 0) - goto out; - } + if(H5Aclose(aid) < 0) + goto out; + } - /* Get the dataspace handle */ - if ( (sid = H5Dget_space( did )) < 0) - goto out; + /* Get the dataspace handle */ + if ( (sid = H5Dget_space( did )) < 0) + goto out; - /* Get dimensions */ - if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0) - goto out; + /* Get dimensions */ + if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0) + goto out; - /* Initialize the image dimensions */ + /* Initialize the image dimensions */ - if ( has_attr == 1 ) - /* This is a 24 bit image */ - { + if ( has_attr == 1 ) + /* This is a 24 bit image */ + { - if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 ) - { - /* Number of color planes is defined as the third dimension */ - *height = dims[0]; - *width = dims[1]; - *planes = dims[2]; - } - else - if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 ) - { - /* Number of color planes is defined as the first dimension */ - *planes = dims[0]; - *height = dims[1]; - *width = dims[2]; - } - else return -1; - } - else - /* This is a 8 bit image */ - { - *height = dims[0]; - *width = dims[1]; - *planes = 1; - } + if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 ) + { + /* Number of color planes is defined as the third dimension */ + *height = dims[0]; + *width = dims[1]; + *planes = dims[2]; + } + else + if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 ) + { + /* Number of color planes is defined as the first dimension */ + *planes = dims[0]; + *height = dims[1]; + *width = dims[2]; + } + else return -1; + } + else + /* This is a 8 bit image */ + { + *height = dims[0]; + *width = dims[1]; + *planes = 1; + } - /* Close */ - if ( H5Sclose( sid ) < 0) - goto out; + /* Close */ + if ( H5Sclose( sid ) < 0) + goto out; - /* Get number of palettes */ + /* Get number of palettes */ - /* Try to find the attribute "PALETTE" on the >>image<< dataset */ - has_pal = H5IM_find_palette(did); + /* Try to find the attribute "PALETTE" on the >>image<< dataset */ + has_pal = H5IM_find_palette(did); - if(has_pal == 1) - { + if(has_pal == 1) + { - if((attr_id = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) - goto out; + if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((atid = H5Aget_type(aid)) < 0) + goto out; - if((attr_class = H5Tget_class(attr_type)) < 0) - goto out; + if((aclass = H5Tget_class(atid)) < 0) + goto out; - /* Check if it is really a reference */ + /* Check if it is really a reference */ - if(attr_class == H5T_REFERENCE) - { + if(aclass == H5T_REFERENCE) + { - /* Get the reference(s) */ + /* Get the reference(s) */ - if ( (attr_space_id = H5Aget_space( attr_id )) < 0) - goto out; + if ( (asid = H5Aget_space( aid )) < 0) + goto out; - *npals = H5Sget_simple_extent_npoints( attr_space_id ); + *npals = H5Sget_simple_extent_npoints( asid ); - if ( H5Sclose( attr_space_id ) < 0) - goto out; + if ( H5Sclose( asid ) < 0) + goto out; - } /* H5T_REFERENCE */ + } /* H5T_REFERENCE */ - if ( H5Tclose( attr_type ) < 0) - goto out; + if ( H5Tclose( atid ) < 0) + goto out; - /* Close the attribute. */ - if ( H5Aclose( attr_id ) < 0) - goto out; + /* Close the attribute. */ + if ( H5Aclose( aid ) < 0) + goto out; - } + } - /* End access to the dataset and release resources used by it. */ - if ( H5Dclose( did ) < 0) - goto out; + /* End access to the dataset and release resources used by it. */ + if ( H5Dclose( did ) < 0) + goto out; - return 0; + return 0; out: - H5Dclose( did ); - return -1; + H5Dclose( did ); + H5Aclose( aid ); + H5Sclose( asid ); + H5Tclose( atid ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5IMread_image - * - * Purpose: Reads image data from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: June 13, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMread_image +* +* Purpose: Reads image data from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: June 13, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMread_image( hid_t loc_id, const char *dset_name, - unsigned char *buffer ) + unsigned char *buf ) { - hid_t did; + hid_t did; - /* Open the dataset. */ - if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the dataset. */ + if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) + return -1; - /* Read */ - if ( H5Dread( did, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, buffer ) < 0) - goto out; + /* Read */ + if ( H5Dread( did, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf ) < 0) + goto out; - /* End access to the dataset and release resources used by it. */ - if ( H5Dclose( did ) ) - return -1; + /* End access to the dataset and release resources used by it. */ + if ( H5Dclose( did ) ) + return -1; - return 0; + return 0; out: - H5Dclose( did ); - return -1; + H5Dclose( did ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5IMmake_palette - * - * Purpose: Creates and writes a palette. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: May 01, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMmake_palette +* +* Purpose: Creates and writes a palette. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: May 01, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMmake_palette( hid_t loc_id, - const char *pal_name, - const hsize_t *pal_dims, - const unsigned char *pal_data ) + const char *pal_name, + const hsize_t *pal_dims, + const unsigned char *pal_data ) { - int has_pal; + int has_pal; - /* Check if the dataset already exists */ - has_pal = H5LTfind_dataset( loc_id, pal_name ); + /* Check if the dataset already exists */ + has_pal = H5LTfind_dataset( loc_id, pal_name ); - /* It exists. Return */ - if ( has_pal == 1 ) - return 0; + /* It exists. Return */ + if ( has_pal == 1 ) + return 0; - /* Make the palette dataset. */ - if ( H5LTmake_dataset( loc_id, pal_name, 2, pal_dims, H5T_NATIVE_UCHAR, pal_data ) < 0 ) - return -1; + /* Make the palette dataset. */ + if ( H5LTmake_dataset( loc_id, pal_name, 2, pal_dims, H5T_NATIVE_UCHAR, pal_data ) < 0 ) + return -1; - /* Attach the attribute "CLASS" to the >>palette<< dataset*/ - if ( H5LTset_attribute_string( loc_id, pal_name, "CLASS", PALETTE_CLASS ) < 0) - return -1; + /* Attach the attribute "CLASS" to the >>palette<< dataset*/ + if ( H5LTset_attribute_string( loc_id, pal_name, "CLASS", PALETTE_CLASS ) < 0) + return -1; - /* Attach the attribute "PAL_VERSION" to the >>palette<< dataset*/ - if ( H5LTset_attribute_string( loc_id, pal_name, "PAL_VERSION", "1.2" ) < 0) - return -1; + /* Attach the attribute "PAL_VERSION" to the >>palette<< dataset*/ + if ( H5LTset_attribute_string( loc_id, pal_name, "PAL_VERSION", "1.2" ) < 0) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5IMlink_palette - * - * Purpose: This function attaches a palette to an existing image dataset - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: May 01, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * An image (dataset) within an HDF5 file may optionally specify an array of - * palettes to be viewed with. The dataset will have an attribute - * which contains an array of object reference pointers which refer to palettes in the file. - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMlink_palette +* +* Purpose: This function attaches a palette to an existing image dataset +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: May 01, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* An image (dataset) within an HDF5 file may optionally specify an array of +* palettes to be viewed with. The dataset will have an attribute +* which contains an array of object reference pointers which refer to palettes in the file. +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMlink_palette( hid_t loc_id, - const char *image_name, - const char *pal_name ) + const char *image_name, + const char *pal_name ) { - hid_t image_id; - hid_t attr_type=-1; - hid_t attr_id=-1; - hid_t attr_space_id=-1; - hobj_ref_t ref; /* write a new reference */ - hobj_ref_t *refbuf; /* buffer to read references */ - hssize_t n_refs; - hsize_t dim_ref; - int ok_pal; - - /* The image dataset may or may not have the attribute "PALETTE" - * First we try to open to see if it is already there; if not, it is created. - * If it exists, the array of references is extended to hold the reference - * to the new palette - */ - - /* First we get the image id */ - if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) - return -1; - - /* Try to find the attribute "PALETTE" on the >>image<< dataset */ - ok_pal = H5LT_find_attribute( image_id, "PALETTE" ); + hid_t did; + hid_t atid=-1; + hid_t aid=-1; + hid_t asid=-1; + hobj_ref_t ref; /* write a new reference */ + hobj_ref_t *refbuf; /* buffer to read references */ + hssize_t n_refs; + hsize_t dim_ref; + int ok_pal; + + /* The image dataset may or may not have the attribute "PALETTE" + * First we try to open to see if it is already there; if not, it is created. + * If it exists, the array of references is extended to hold the reference + * to the new palette + */ + + /* First we get the image id */ + if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) + return -1; + + /* Try to find the attribute "PALETTE" on the >>image<< dataset */ + ok_pal = H5LT_find_attribute( did, "PALETTE" ); + + /*------------------------------------------------------------------------- + * It does not exist. We create the attribute and one reference + *------------------------------------------------------------------------- + */ + if(ok_pal == 0 ) + { + if((asid = H5Screate(H5S_SCALAR)) < 0) + goto out; -/*------------------------------------------------------------------------- - * It does not exist. We create the attribute and one reference - *------------------------------------------------------------------------- - */ - if(ok_pal == 0 ) - { - if((attr_space_id = H5Screate(H5S_SCALAR)) < 0) - goto out; - - /* Create the attribute type for the reference */ - if((attr_type = H5Tcopy(H5T_STD_REF_OBJ)) < 0) - goto out; - - /* Create the attribute "PALETTE" to be attached to the image*/ - if((attr_id = H5Acreate2(image_id, "PALETTE", attr_type, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto out; - - /* Create a reference. The reference is created on the local id. */ - if(H5Rcreate(&ref, loc_id, pal_name, H5R_OBJECT, -1) < 0) - goto out; - - /* Write the attribute with the reference */ - if(H5Awrite(attr_id, attr_type, &ref) < 0) - goto out; - - /* close */ - if(H5Sclose(attr_space_id) < 0) - goto out; - if ( H5Tclose( attr_type ) < 0) - goto out; - if(H5Aclose(attr_id) < 0) - goto out; - - } + /* Create the attribute type for the reference */ + if((atid = H5Tcopy(H5T_STD_REF_OBJ)) < 0) + goto out; -/*------------------------------------------------------------------------- - * The attribute already exists, open it - *------------------------------------------------------------------------- - */ - else if(ok_pal == 1) - { - if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0) - goto out; + /* Create the attribute "PALETTE" to be attached to the image*/ + if((aid = H5Acreate2(did, "PALETTE", atid, asid, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + /* Create a reference. The reference is created on the local id. */ + if(H5Rcreate(&ref, loc_id, pal_name, H5R_OBJECT, -1) < 0) + goto out; - if(H5Tget_class(attr_type) < 0) - goto out; + /* Write the attribute with the reference */ + if(H5Awrite(aid, atid, &ref) < 0) + goto out; - /* Get and save the old reference(s) */ - if((attr_space_id = H5Aget_space(attr_id)) < 0) - goto out; + /* close */ + if(H5Sclose(asid) < 0) + goto out; + if ( H5Tclose( atid ) < 0) + goto out; + if(H5Aclose(aid) < 0) + goto out; - n_refs = H5Sget_simple_extent_npoints(attr_space_id); + } - dim_ref = n_refs + 1; + /*------------------------------------------------------------------------- + * The attribute already exists, open it + *------------------------------------------------------------------------- + */ + else if(ok_pal == 1) + { + if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) + goto out; - refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref ); + if((atid = H5Aget_type(aid)) < 0) + goto out; - if ( H5Aread( attr_id, attr_type, refbuf ) < 0) - goto out; + if(H5Tget_class(atid) < 0) + goto out; - /* The attribute must be deleted, in order to the new one can reflect the changes*/ - if(H5Adelete(image_id, "PALETTE") < 0) - goto out; + /* Get and save the old reference(s) */ + if((asid = H5Aget_space(aid)) < 0) + goto out; - /* Create a new reference for this palette. */ - if ( H5Rcreate( &ref, loc_id, pal_name, H5R_OBJECT, -1 ) < 0) - goto out; + n_refs = H5Sget_simple_extent_npoints(asid); - refbuf[n_refs] = ref; + dim_ref = n_refs + 1; - /* Create the data space for the new references */ - if(H5Sclose(attr_space_id) < 0) - goto out; + refbuf = (hobj_ref_t*)malloc( sizeof(hobj_ref_t) * (int)dim_ref ); - if((attr_space_id = H5Screate_simple(1, &dim_ref, NULL)) < 0) - goto out; + if ( H5Aread( aid, atid, refbuf ) < 0) + goto out; - /* Create the attribute again with the changes of space */ - if(H5Aclose(attr_id) < 0) - goto out; + /* The attribute must be deleted, in order to the new one can reflect the changes*/ + if(H5Adelete(did, "PALETTE") < 0) + goto out; - if((attr_id = H5Acreate2(image_id, "PALETTE", attr_type, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto out; + /* Create a new reference for this palette. */ + if ( H5Rcreate( &ref, loc_id, pal_name, H5R_OBJECT, -1 ) < 0) + goto out; - /* Write the attribute with the new references */ - if(H5Awrite(attr_id, attr_type, refbuf) < 0) - goto out; + refbuf[n_refs] = ref; - /* close */ - if(H5Sclose(attr_space_id) < 0) - goto out; - if(H5Aclose(attr_id) < 0) - goto out; + /* Create the data space for the new references */ + if(H5Sclose(asid) < 0) + goto out; - free( refbuf ); + if((asid = H5Screate_simple(1, &dim_ref, NULL)) < 0) + goto out; - } /* ok_pal == 1 */ + /* Create the attribute again with the changes of space */ + if(H5Aclose(aid) < 0) + goto out; - /* Close the image dataset. */ - if ( H5Dclose( image_id ) < 0) - return -1; + if((aid = H5Acreate2(did, "PALETTE", atid, asid, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto out; - return 0; + /* Write the attribute with the new references */ + if(H5Awrite(aid, atid, refbuf) < 0) + goto out; + + /* close */ + if(H5Sclose(asid) < 0) + goto out; + if(H5Aclose(aid) < 0) + goto out; + + free( refbuf ); + + } /* ok_pal == 1 */ + + /* Close the image dataset. */ + if ( H5Dclose( did ) < 0) + return -1; + + return 0; out: - H5Dclose( image_id ); - H5Sclose( attr_space_id ); - H5Tclose( attr_type ); - H5Aclose( attr_id ); - return -1; + H5Dclose( did ); + H5Sclose( asid ); + H5Tclose( atid ); + H5Aclose( aid ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5IMunlink_palette - * - * Purpose: This function dettaches a palette from an existing image dataset - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: September 10, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMunlink_palette +* +* Purpose: This function dettaches a palette from an existing image dataset +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: September 10, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMunlink_palette( hid_t loc_id, - const char *image_name, - const char *pal_name ) + const char *image_name, + const char *pal_name ) { - hid_t image_id; - hid_t attr_type; - hid_t attr_id; - hid_t attr_class; - int ok_pal, has_pal; + hid_t did; + hid_t atid; + hid_t aid; + H5T_class_t aclass; + int ok_pal, has_pal; - /* Try to find the palette dataset */ - has_pal = H5LTfind_dataset( loc_id, pal_name ); + /* Try to find the palette dataset */ + has_pal = H5LTfind_dataset( loc_id, pal_name ); - /* It does not exist. Return */ - if ( has_pal == 0 ) - return -1; + /* It does not exist. Return */ + if ( has_pal == 0 ) + return -1; - /* The image dataset may or not have the attribute "PALETTE" - * First we try to open to see if it is already there; if not, it is created. - * If it exists, the array of references is extended to hold the reference - * to the new palette - */ + /* The image dataset may or not have the attribute "PALETTE" + * First we try to open to see if it is already there; if not, it is created. + * If it exists, the array of references is extended to hold the reference + * to the new palette + */ - /* First we get the image id */ - if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) - return -1; + /* First we get the image id */ + if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) + return -1; - /* Try to find the attribute "PALETTE" on the >>image<< dataset */ - ok_pal = H5LT_find_attribute(image_id, "PALETTE"); + /* Try to find the attribute "PALETTE" on the >>image<< dataset */ + ok_pal = H5LT_find_attribute(did, "PALETTE"); - /* It does not exist. Nothing to do */ - if(ok_pal == 0) - return -1; + /* It does not exist. Nothing to do */ + if(ok_pal == 0) + return -1; - /* The attribute exists, open it */ - else if(ok_pal == 1) - { - if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0) - goto out; + /* The attribute exists, open it */ + else if(ok_pal == 1) + { + if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((atid = H5Aget_type(aid)) < 0) + goto out; - if((attr_class = H5Tget_class(attr_type)) < 0) - goto out; + if((aclass = H5Tget_class(atid)) < 0) + goto out; - /* Check if it is really a reference */ - if(attr_class == H5T_REFERENCE) - { - /* Delete the attribute */ - if(H5Adelete(image_id, "PALETTE") < 0) - goto out; + /* Check if it is really a reference */ + if(aclass == H5T_REFERENCE) + { + /* Delete the attribute */ + if(H5Adelete(did, "PALETTE") < 0) + goto out; - } /* H5T_REFERENCE */ + } /* H5T_REFERENCE */ - if(H5Tclose(attr_type) < 0) - goto out; + if(H5Tclose(atid) < 0) + goto out; - /* Close the attribute. */ - if(H5Aclose(attr_id) < 0) - goto out; + /* Close the attribute. */ + if(H5Aclose(aid) < 0) + goto out; - } /* ok_pal */ + } /* ok_pal */ - /* Close the image dataset. */ - if(H5Dclose(image_id) < 0) - return -1; + /* Close the image dataset. */ + if(H5Dclose(did) < 0) + return -1; - return 0; + return 0; out: - H5Dclose( image_id ); - return -1; + H5Dclose( did ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5IMget_npalettes - * - * Purpose: Gets the number of palettes associated to an image - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: July 22, 2001 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMget_npalettes +* +* Purpose: Gets the number of palettes associated to an image +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: July 22, 2001 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMget_npalettes( hid_t loc_id, - const char *image_name, - hssize_t *npals ) + const char *image_name, + hssize_t *npals ) { - hid_t image_id; - hid_t attr_type; - hid_t attr_id; - hid_t attr_space_id; - hid_t attr_class; - int has_pal; + hid_t did; + hid_t atid; + hid_t aid; + hid_t asid; + H5T_class_t aclass; + int has_pal; - /*assume initially we have no palettes attached*/ - *npals = 0; + /*assume initially we have no palettes attached*/ + *npals = 0; - /* Open the dataset. */ - if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the dataset. */ + if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) + return -1; - /* Try to find the attribute "PALETTE" on the >>image<< dataset */ - has_pal = H5IM_find_palette(image_id); + /* Try to find the attribute "PALETTE" on the >>image<< dataset */ + has_pal = H5IM_find_palette(did); - if(has_pal == 1 ) - { + if(has_pal == 1 ) + { - if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0) - goto out; + if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((atid = H5Aget_type(aid)) < 0) + goto out; - if((attr_class = H5Tget_class(attr_type)) < 0) - goto out; + if((aclass = H5Tget_class(atid)) < 0) + goto out; - /* Check if it is really a reference */ + /* Check if it is really a reference */ - if(attr_class == H5T_REFERENCE) - { - if((attr_space_id = H5Aget_space(attr_id)) < 0) - goto out; + if(aclass == H5T_REFERENCE) + { + if((asid = H5Aget_space(aid)) < 0) + goto out; - *npals = H5Sget_simple_extent_npoints( attr_space_id ); + *npals = H5Sget_simple_extent_npoints( asid ); - if ( H5Sclose( attr_space_id ) < 0) - goto out; + if ( H5Sclose( asid ) < 0) + goto out; - } /* H5T_REFERENCE */ + } /* H5T_REFERENCE */ - if ( H5Tclose( attr_type ) < 0) - goto out; + if ( H5Tclose( atid ) < 0) + goto out; - /* Close the attribute. */ - if ( H5Aclose( attr_id ) < 0) - goto out; + /* Close the attribute. */ + if ( H5Aclose( aid ) < 0) + goto out; - } + } - /* Close the image dataset. */ - if ( H5Dclose( image_id ) < 0) - return -1; + /* Close the image dataset. */ + if ( H5Dclose( did ) < 0) + return -1; - return 0; + return 0; out: - H5Dclose( image_id ); - return -1; + H5Dclose( did ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5IMget_palette_info - * - * Purpose: Get palette information - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: July 22, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMget_palette_info +* +* Purpose: Get palette information +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: July 22, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMget_palette_info( hid_t loc_id, - const char *image_name, - int pal_number, - hsize_t *pal_dims ) + const char *image_name, + int pal_number, + hsize_t *pal_dims ) { - hid_t image_id; - int has_pal; - hid_t attr_type=-1; - hid_t attr_id; - hid_t attr_space_id=-1; - hssize_t n_refs; - hsize_t dim_ref; - hobj_ref_t *refbuf; /* buffer to read references */ - hid_t pal_id; - hid_t pal_space_id; - hsize_t pal_maxdims[2]; + hid_t did; + int has_pal; + hid_t atid=-1; + hid_t aid; + hid_t asid=-1; + hssize_t n_refs; + hsize_t dim_ref; + hobj_ref_t *refbuf; /* buffer to read references */ + hid_t pal_id; + hid_t pal_space_id; + hsize_t pal_maxdims[2]; - /* Open the dataset. */ - if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the dataset. */ + if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) + return -1; - /* Try to find the attribute "PALETTE" on the >>image<< dataset */ - has_pal = H5IM_find_palette(image_id); + /* Try to find the attribute "PALETTE" on the >>image<< dataset */ + has_pal = H5IM_find_palette(did); - if(has_pal == 1) - { - if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0) - goto out; + if(has_pal == 1) + { + if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((atid = H5Aget_type(aid)) < 0) + goto out; - if(H5Tget_class(attr_type) < 0) - goto out; + if(H5Tget_class(atid) < 0) + goto out; - /* Get the reference(s) */ - if((attr_space_id = H5Aget_space(attr_id)) < 0) - goto out; + /* Get the reference(s) */ + if((asid = H5Aget_space(aid)) < 0) + goto out; - n_refs = H5Sget_simple_extent_npoints(attr_space_id); + n_refs = H5Sget_simple_extent_npoints(asid); - dim_ref = n_refs; + dim_ref = n_refs; - refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref ); + refbuf = (hobj_ref_t*)malloc( sizeof(hobj_ref_t) * (int)dim_ref ); - if ( H5Aread( attr_id, attr_type, refbuf ) < 0) - goto out; + if ( H5Aread( aid, atid, refbuf ) < 0) + goto out; - /* Get the actual palette */ - if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0) - goto out; + /* Get the actual palette */ + if ( (pal_id = H5Rdereference( did, H5R_OBJECT, &refbuf[pal_number] )) < 0) + goto out; - if ( (pal_space_id = H5Dget_space( pal_id )) < 0) - goto out; + if ( (pal_space_id = H5Dget_space( pal_id )) < 0) + goto out; - if ( H5Sget_simple_extent_ndims( pal_space_id ) < 0) - goto out; + if ( H5Sget_simple_extent_ndims( pal_space_id ) < 0) + goto out; - if ( H5Sget_simple_extent_dims( pal_space_id, pal_dims, pal_maxdims ) < 0) - goto out; + if ( H5Sget_simple_extent_dims( pal_space_id, pal_dims, pal_maxdims ) < 0) + goto out; - /* close */ - if (H5Dclose(pal_id)<0) - goto out; - if ( H5Sclose( pal_space_id ) < 0) - goto out; - if ( H5Sclose( attr_space_id ) < 0) - goto out; - if ( H5Tclose( attr_type ) < 0) - goto out; - if ( H5Aclose( attr_id ) < 0) - goto out; - free( refbuf ); + /* close */ + if (H5Dclose(pal_id)<0) + goto out; + if ( H5Sclose( pal_space_id ) < 0) + goto out; + if ( H5Sclose( asid ) < 0) + goto out; + if ( H5Tclose( atid ) < 0) + goto out; + if ( H5Aclose( aid ) < 0) + goto out; + free( refbuf ); - } + } - /* Close the image dataset. */ - if ( H5Dclose( image_id ) < 0) - return -1; + /* Close the image dataset. */ + if ( H5Dclose( did ) < 0) + return -1; - return 0; + return 0; out: - H5Dclose( image_id ); - H5Sclose( attr_space_id ); - H5Tclose( attr_type ); - H5Aclose( attr_id ); - return -1; + H5Dclose( did ); + H5Sclose( asid ); + H5Tclose( atid ); + H5Aclose( aid ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5IMget_palette - * - * Purpose: Read palette - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: August 30, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMget_palette +* +* Purpose: Read palette +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: August 30, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMget_palette( hid_t loc_id, - const char *image_name, - int pal_number, - unsigned char *pal_data ) + const char *image_name, + int pal_number, + unsigned char *pal_data ) { - hid_t image_id; - int has_pal; - hid_t attr_type=-1; - hid_t attr_id; - hid_t attr_space_id=-1; - hssize_t n_refs; - hsize_t dim_ref; - hobj_ref_t *refbuf; /* buffer to read references */ - hid_t pal_id; + hid_t did; + int has_pal; + hid_t atid=-1; + hid_t aid; + hid_t asid=-1; + hssize_t n_refs; + hsize_t dim_ref; + hobj_ref_t *refbuf; /* buffer to read references */ + hid_t pal_id; - /* Open the dataset. */ - if((image_id = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the dataset. */ + if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0) + return -1; - /* Try to find the attribute "PALETTE" on the >>image<< dataset */ - has_pal = H5IM_find_palette(image_id); + /* Try to find the attribute "PALETTE" on the >>image<< dataset */ + has_pal = H5IM_find_palette(did); - if(has_pal == 1 ) - { - if((attr_id = H5Aopen(image_id, "PALETTE", H5P_DEFAULT)) < 0) - goto out; + if(has_pal == 1 ) + { + if((aid = H5Aopen(did, "PALETTE", H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((atid = H5Aget_type(aid)) < 0) + goto out; - if(H5Tget_class(attr_type) < 0) - goto out; + if(H5Tget_class(atid) < 0) + goto out; - /* Get the reference(s) */ - if((attr_space_id = H5Aget_space(attr_id)) < 0) - goto out; + /* Get the reference(s) */ + if((asid = H5Aget_space(aid)) < 0) + goto out; - n_refs = H5Sget_simple_extent_npoints(attr_space_id); + n_refs = H5Sget_simple_extent_npoints(asid); - dim_ref = n_refs; + dim_ref = n_refs; - refbuf = malloc( sizeof(hobj_ref_t) * (int)dim_ref ); + refbuf = (hobj_ref_t*)malloc( sizeof(hobj_ref_t) * (int)dim_ref ); - if ( H5Aread( attr_id, attr_type, refbuf ) < 0) - goto out; + if ( H5Aread( aid, atid, refbuf ) < 0) + goto out; - /* Get the palette id */ - if ( (pal_id = H5Rdereference( image_id, H5R_OBJECT, &refbuf[pal_number] )) < 0) - goto out; + /* Get the palette id */ + if ( (pal_id = H5Rdereference( did, H5R_OBJECT, &refbuf[pal_number] )) < 0) + goto out; - /* Read the palette dataset */ - if ( H5Dread( pal_id, H5Dget_type(pal_id), H5S_ALL, H5S_ALL, H5P_DEFAULT, pal_data ) < 0) - goto out; + /* Read the palette dataset */ + if ( H5Dread( pal_id, H5Dget_type(pal_id), H5S_ALL, H5S_ALL, H5P_DEFAULT, pal_data ) < 0) + goto out; - /* close */ - if (H5Dclose(pal_id)<0) - goto out; - if ( H5Sclose( attr_space_id ) < 0) - goto out; - if ( H5Tclose( attr_type ) < 0) - goto out; - if ( H5Aclose( attr_id ) < 0) - goto out; - free( refbuf ); - } + /* close */ + if (H5Dclose(pal_id)<0) + goto out; + if ( H5Sclose( asid ) < 0) + goto out; + if ( H5Tclose( atid ) < 0) + goto out; + if ( H5Aclose( aid ) < 0) + goto out; + free( refbuf ); + } - /* Close the image dataset. */ - if ( H5Dclose( image_id ) < 0) - return -1; + /* Close the image dataset. */ + if ( H5Dclose( did ) < 0) + return -1; - return 0; + return 0; out: - H5Dclose( image_id ); - H5Sclose( attr_space_id ); - H5Tclose( attr_type ); - H5Aclose( attr_id ); - return -1; + H5Dclose( did ); + H5Sclose( asid ); + H5Tclose( atid ); + H5Aclose( aid ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5IMis_image - * - * Purpose: - * - * Return: true, false, fail - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: August 30, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMis_image +* +* Purpose: +* +* Return: true, false, fail +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: August 30, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMis_image( hid_t loc_id, - const char *dset_name ) + const char *dset_name ) { - hid_t did; - int has_class; - hid_t attr_type; - hid_t attr_id; - char attr_data[20]; - herr_t ret; + hid_t did; + int has_class; + hid_t atid; + hid_t aid; + char attr_data[20]; + herr_t ret; - /* Assume initially fail condition */ - ret = -1; + /* Assume initially fail condition */ + ret = -1; - /* Open the dataset. */ - if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the dataset. */ + if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) + return -1; - /* Try to find the attribute "CLASS" on the dataset */ - has_class = H5LT_find_attribute(did, "CLASS"); + /* Try to find the attribute "CLASS" on the dataset */ + has_class = H5LT_find_attribute(did, "CLASS"); - if(has_class == 0) - { - H5Dclose(did); - return 0; - } - else if(has_class == 1) - { + if(has_class == 0) + { + H5Dclose(did); + return 0; + } + else if(has_class == 1) + { - if((attr_id = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0) - goto out; + if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((atid = H5Aget_type(aid)) < 0) + goto out; - if(H5Tget_class(attr_type) < 0) - goto out; + if(H5Tget_class(atid) < 0) + goto out; - if(H5Aread(attr_id, attr_type, attr_data) < 0) - goto out; + if(H5Aread(aid, atid, attr_data) < 0) + goto out; - if(strcmp(attr_data, IMAGE_CLASS) == 0) - ret = 1; - else - ret = 0; + if(strcmp(attr_data, IMAGE_CLASS) == 0) + ret = 1; + else + ret = 0; - if ( H5Tclose( attr_type ) < 0) - goto out; + if ( H5Tclose( atid ) < 0) + goto out; - if ( H5Aclose( attr_id ) < 0) - goto out; + if ( H5Aclose( aid ) < 0) + goto out; - } + } - /* Close the dataset. */ - if ( H5Dclose( did ) < 0) - return -1; + /* Close the dataset. */ + if ( H5Dclose( did ) < 0) + return -1; - return ret; + return ret; out: - H5Dclose( did ); - return -1; + H5Dclose( did ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5IMis_palette - * - * Purpose: - * - * Return: true, false, fail - * - * Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu - * - * Date: August 30, 2001 - * - * Comments: - * based on HDF5 Image and Palette Specification - * http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5IMis_palette +* +* Purpose: +* +* Return: true, false, fail +* +* Programmer: Pedro Vicente Nunes, pvn@ncsa.uiuc.edu +* +* Date: August 30, 2001 +* +* Comments: +* based on HDF5 Image and Palette Specification +* http://hdf.ncsa.uiuc.edu/HDF5/H5Image/ImageSpec.html +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5IMis_palette( hid_t loc_id, - const char *dset_name ) + const char *dset_name ) { - hid_t did; - int has_class; - hid_t attr_type; - hid_t attr_id; - char attr_data[20]; - herr_t ret; + hid_t did; + int has_class; + hid_t atid; + hid_t aid; + char attr_data[20]; + herr_t ret; - /* Assume initially fail condition */ - ret = -1; + /* Assume initially fail condition */ + ret = -1; - /* Open the dataset. */ - if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the dataset. */ + if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) + return -1; - /* Try to find the attribute "CLASS" on the dataset */ - has_class = H5LT_find_attribute(did, "CLASS"); + /* Try to find the attribute "CLASS" on the dataset */ + has_class = H5LT_find_attribute(did, "CLASS"); - if(has_class == 0) - { - H5Dclose( did ); - return 0; - } - else if(has_class == 1) - { + if(has_class == 0) + { + H5Dclose( did ); + return 0; + } + else if(has_class == 1) + { - if((attr_id = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0) - goto out; + if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0) + goto out; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((atid = H5Aget_type(aid)) < 0) + goto out; - if(H5Tget_class(attr_type) < 0) - goto out; + if(H5Tget_class(atid) < 0) + goto out; - if(H5Aread(attr_id, attr_type, attr_data) < 0) - goto out; + if(H5Aread(aid, atid, attr_data) < 0) + goto out; - if(strcmp(attr_data, PALETTE_CLASS) == 0) - ret = 1; - else - ret = 0; + if(strcmp(attr_data, PALETTE_CLASS) == 0) + ret = 1; + else + ret = 0; - if ( H5Tclose( attr_type ) < 0) - goto out; + if ( H5Tclose( atid ) < 0) + goto out; - if ( H5Aclose( attr_id ) < 0) - goto out; + if ( H5Aclose( aid ) < 0) + goto out; - } + } - /* Close the dataset. */ - if ( H5Dclose( did ) < 0) - return -1; + /* Close the dataset. */ + if ( H5Dclose( did ) < 0) + return -1; - return ret; + return ret; out: - H5Dclose( did ); - return -1; + H5Dclose( did ); + return -1; } diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c index 92965fd..7c073d6 100644 --- a/hl/src/H5LT.c +++ b/hl/src/H5LT.c @@ -1,17 +1,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +* Copyright by The HDF Group. * +* Copyright by the Board of Trustees of the University of Illinois. * +* All rights reserved. * +* * +* This file is part of HDF5. The full HDF5 copyright notice, including * +* terms governing use, modification, and redistribution, is contained in * +* the files COPYING and Copyright.html. COPYING can be found at the root * +* of the source code distribution tree; Copyright.html can be found at the * +* root level of an installed copy of the electronic HDF5 document set and * +* is linked from the top-level documents page. It can also be found at * +* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * +* access to either file, you may request a copy from help@hdfgroup.org. * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <string.h> #include <stdlib.h> @@ -33,38 +33,38 @@ int indent = 0; /*------------------------------------------------------------------------- - * - * internal functions - * - *------------------------------------------------------------------------- - */ +* +* internal functions +* +*------------------------------------------------------------------------- +*/ static herr_t H5LT_get_attribute_mem(hid_t loc_id, - const char *obj_name, - const char *attr_name, - hid_t mem_type_id, - void *data); - -/*------------------------------------------------------------------------- - * Function: H5LT_make_dataset - * - * Purpose: Creates and writes a dataset of a type tid - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Quincey Koziol, koziol@hdfgroup.org - * - * Date: October 10, 2007 - * - *------------------------------------------------------------------------- - */ + const char *obj_name, + const char *attr_name, + hid_t mem_type_id, + void *data); + +/*------------------------------------------------------------------------- +* Function: H5LT_make_dataset +* +* Purpose: Creates and writes a dataset of a type tid +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Quincey Koziol, koziol@hdfgroup.org +* +* Date: October 10, 2007 +* +*------------------------------------------------------------------------- +*/ static herr_t H5LT_make_dataset_numerical( hid_t loc_id, - const char *dset_name, - int rank, - const hsize_t *dims, - hid_t tid, - const void *data ) + const char *dset_name, + int rank, + const hsize_t *dims, + hid_t tid, + const void *data ) { hid_t did = -1, sid = -1; @@ -100,124 +100,124 @@ out: } /*------------------------------------------------------------------------- - * - * Public functions - * - *------------------------------------------------------------------------- - */ - -/*------------------------------------------------------------------------- - * Function: H5LTmake_dataset - * - * Purpose: Creates and writes a dataset of a type tid - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 19, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* +* Public functions +* +*------------------------------------------------------------------------- +*/ + +/*------------------------------------------------------------------------- +* Function: H5LTmake_dataset +* +* Purpose: Creates and writes a dataset of a type tid +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 19, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5LTmake_dataset( hid_t loc_id, - const char *dset_name, - int rank, - const hsize_t *dims, - hid_t tid, - const void *data ) + const char *dset_name, + int rank, + const hsize_t *dims, + hid_t tid, + const void *data ) { return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, tid, data)); } /*------------------------------------------------------------------------- - * Function: H5LTmake_dataset_char - * - * Purpose: Creates and writes a dataset of H5T_NATIVE_CHAR type - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 14, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5LTmake_dataset_char +* +* Purpose: Creates and writes a dataset of H5T_NATIVE_CHAR type +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 14, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5LTmake_dataset_char( hid_t loc_id, - const char *dset_name, - int rank, - const hsize_t *dims, - const char *data ) + const char *dset_name, + int rank, + const hsize_t *dims, + const char *data ) { return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_CHAR, data)); } /*------------------------------------------------------------------------- - * Function: H5LTmake_dataset_short - * - * Purpose: Creates and writes a dataset of H5T_NATIVE_SHORT type - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 14, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5LTmake_dataset_short +* +* Purpose: Creates and writes a dataset of H5T_NATIVE_SHORT type +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 14, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5LTmake_dataset_short( hid_t loc_id, - const char *dset_name, - int rank, - const hsize_t *dims, - const short *data ) + const char *dset_name, + int rank, + const hsize_t *dims, + const short *data ) { return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_SHORT, data)); } /*------------------------------------------------------------------------- - * Function: H5LTmake_dataset_int - * - * Purpose: Creates and writes a dataset of H5T_NATIVE_INT type - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 14, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5LTmake_dataset_int +* +* Purpose: Creates and writes a dataset of H5T_NATIVE_INT type +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 14, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5LTmake_dataset_int( hid_t loc_id, - const char *dset_name, - int rank, - const hsize_t *dims, - const int *data ) + const char *dset_name, + int rank, + const hsize_t *dims, + const int *data ) { return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_INT, data)); } @@ -225,59 +225,59 @@ herr_t H5LTmake_dataset_int( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTmake_dataset_long - * - * Purpose: Creates and writes a dataset of H5T_NATIVE_LONG type - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 14, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5LTmake_dataset_long +* +* Purpose: Creates and writes a dataset of H5T_NATIVE_LONG type +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 14, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5LTmake_dataset_long( hid_t loc_id, - const char *dset_name, - int rank, - const hsize_t *dims, - const long *data ) + const char *dset_name, + int rank, + const hsize_t *dims, + const long *data ) { return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_LONG, data)); } /*------------------------------------------------------------------------- - * Function: H5LTmake_dataset_float - * - * Purpose: Creates and writes a dataset of H5T_NATIVE_FLOAT type - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 14, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5LTmake_dataset_float +* +* Purpose: Creates and writes a dataset of H5T_NATIVE_FLOAT type +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 14, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5LTmake_dataset_float( hid_t loc_id, - const char *dset_name, - int rank, - const hsize_t *dims, - const float *data ) + const char *dset_name, + int rank, + const hsize_t *dims, + const float *data ) { return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_FLOAT, data)); } @@ -285,53 +285,53 @@ herr_t H5LTmake_dataset_float( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTmake_dataset_double - * - * Purpose: Creates and writes a dataset of H5T_NATIVE_DOUBLE type - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 14, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5LTmake_dataset_double +* +* Purpose: Creates and writes a dataset of H5T_NATIVE_DOUBLE type +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 14, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5LTmake_dataset_double( hid_t loc_id, - const char *dset_name, - int rank, - const hsize_t *dims, - const double *data ) + const char *dset_name, + int rank, + const hsize_t *dims, + const double *data ) { return(H5LT_make_dataset_numerical(loc_id, dset_name, rank, dims, H5T_NATIVE_DOUBLE, data)); } /*------------------------------------------------------------------------- - * Function: H5LTmake_dataset_string - * - * Purpose: Creates and writes a dataset of H5T_C_S1 type - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 05, 2004 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5LTmake_dataset_string +* +* Purpose: Creates and writes a dataset of H5T_C_S1 type +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: October 05, 2004 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5LTmake_dataset_string(hid_t loc_id, @@ -389,18 +389,18 @@ out: /*------------------------------------------------------------------------- - * Function: H5LT_read_dataset - * - * Purpose: Reads a dataset from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Quincey Koziol, koziol@hdfgroup.org - * - * Date: October 8, 2007 - * - *------------------------------------------------------------------------- - */ +* Function: H5LT_read_dataset +* +* Purpose: Reads a dataset from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Quincey Koziol, koziol@hdfgroup.org +* +* Date: October 8, 2007 +* +*------------------------------------------------------------------------- +*/ static herr_t H5LT_read_dataset_numerical(hid_t loc_id, const char *dset_name, hid_t tid, void *data) @@ -427,18 +427,18 @@ out: } /*------------------------------------------------------------------------- - * Function: H5LTread_dataset - * - * Purpose: Reads a dataset from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: June 13, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTread_dataset +* +* Purpose: Reads a dataset from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: June 13, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTread_dataset(hid_t loc_id, const char *dset_name, @@ -450,150 +450,150 @@ herr_t H5LTread_dataset(hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTread_dataset_char - * - * Purpose: Reads a dataset from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 5, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTread_dataset_char +* +* Purpose: Reads a dataset from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 5, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTread_dataset_char( hid_t loc_id, - const char *dset_name, - char *data ) + const char *dset_name, + char *data ) { return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_CHAR, data)); } /*------------------------------------------------------------------------- - * Function: H5LTread_dataset_short - * - * Purpose: Reads a dataset from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 5, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTread_dataset_short +* +* Purpose: Reads a dataset from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 5, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTread_dataset_short( hid_t loc_id, - const char *dset_name, - short *data ) + const char *dset_name, + short *data ) { return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_SHORT, data)); } /*------------------------------------------------------------------------- - * Function: H5LTread_dataset_int - * - * Purpose: Reads a dataset from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 5, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTread_dataset_int +* +* Purpose: Reads a dataset from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 5, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTread_dataset_int( hid_t loc_id, - const char *dset_name, - int *data ) + const char *dset_name, + int *data ) { return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_INT, data)); } /*------------------------------------------------------------------------- - * Function: H5LTread_dataset_long - * - * Purpose: Reads a dataset from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 5, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTread_dataset_long +* +* Purpose: Reads a dataset from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 5, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTread_dataset_long( hid_t loc_id, - const char *dset_name, - long *data ) + const char *dset_name, + long *data ) { return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_LONG, data)); } /*------------------------------------------------------------------------- - * Function: H5LTread_dataset_float - * - * Purpose: Reads a dataset from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 5, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTread_dataset_float +* +* Purpose: Reads a dataset from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 5, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTread_dataset_float( hid_t loc_id, - const char *dset_name, - float *data ) + const char *dset_name, + float *data ) { return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_FLOAT, data)); } /*------------------------------------------------------------------------- - * Function: H5LTread_dataset_double - * - * Purpose: Reads a dataset from disk. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 5, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTread_dataset_double +* +* Purpose: Reads a dataset from disk. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 5, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTread_dataset_double( hid_t loc_id, - const char *dset_name, - double *data ) + const char *dset_name, + double *data ) { return(H5LT_read_dataset_numerical(loc_id, dset_name, H5T_NATIVE_DOUBLE, data)); } /*------------------------------------------------------------------------- - * Function: H5LTread_dataset_string - * - * Purpose: Reads a dataset - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: October 05, 2004 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTread_dataset_string +* +* Purpose: Reads a dataset +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: October 05, 2004 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTread_dataset_string( hid_t loc_id, - const char *dset_name, - char *buf ) + const char *dset_name, + char *buf ) { hid_t did = -1; hid_t tid = -1; @@ -627,22 +627,22 @@ out: /*------------------------------------------------------------------------- - * Function: H5LTget_dataset_ndims - * - * Purpose: Gets the dimensionality of a dataset. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 4, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_dataset_ndims +* +* Purpose: Gets the dimensionality of a dataset. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 4, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_dataset_ndims( hid_t loc_id, - const char *dset_name, - int *rank ) + const char *dset_name, + int *rank ) { hid_t did = -1; hid_t sid = -1; @@ -679,25 +679,25 @@ out: /*------------------------------------------------------------------------- - * Function: H5LTget_dataset_info - * - * Purpose: Gets information about a dataset. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 4, 2001 - * Modified: February 28, 2006: checked for NULL parameters - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_dataset_info +* +* Purpose: Gets information about a dataset. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 4, 2001 +* Modified: February 28, 2006: checked for NULL parameters +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_dataset_info( hid_t loc_id, - const char *dset_name, - hsize_t *dims, - H5T_class_t *type_class, - size_t *type_size ) + const char *dset_name, + hsize_t *dims, + H5T_class_t *type_class, + size_t *type_size ) { hid_t did = -1; hid_t tid = -1; @@ -753,27 +753,27 @@ out: } /*------------------------------------------------------------------------- - * Function: find_dataset - * - * Purpose: operator function used by H5LTfind_dataset - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: June 21, 2001 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: find_dataset +* +* Purpose: operator function used by H5LTfind_dataset +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: June 21, 2001 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ static herr_t find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_data) { /* Define a default zero value for return. This will cause the iterator to continue if - * the dataset is not found yet. - */ + * the dataset is not found yet. + */ int ret = 0; /* Shut the compiler up */ @@ -781,9 +781,9 @@ find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_d linfo = linfo; /* Define a positive value for return value if the dataset was found. This will - * cause the iterator to immediately return that positive value, - * indicating short-circuit success - */ + * cause the iterator to immediately return that positive value, + * indicating short-circuit success + */ if(strcmp(name, (char *)op_data) == 0) ret = 1; @@ -792,26 +792,26 @@ find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_d /*------------------------------------------------------------------------- - * Function: H5LTfind_dataset - * - * Purpose: Inquires if a dataset named dset_name exists attached - * to the object loc_id. - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: July 15, 2001 - * - * Return: - * Success: The return value of the first operator that - * returns non-zero, or zero if all members were - * processed with no operator returning non-zero. - * - * Failure: Negative if something goes wrong within the - * library, or the negative value returned by one - * of the operators. - * - *------------------------------------------------------------------------- - */ +* Function: H5LTfind_dataset +* +* Purpose: Inquires if a dataset named dset_name exists attached +* to the object loc_id. +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: July 15, 2001 +* +* Return: +* Success: The return value of the first operator that +* returns non-zero, or zero if all members were +* processed with no operator returning non-zero. +* +* Failure: Negative if something goes wrong within the +* library, or the negative value returned by one +* of the operators. +* +*------------------------------------------------------------------------- +*/ herr_t H5LTfind_dataset( hid_t loc_id, const char *dset_name ) @@ -821,98 +821,98 @@ H5LTfind_dataset( hid_t loc_id, const char *dset_name ) /*------------------------------------------------------------------------- - * - * Set attribute functions - * - *------------------------------------------------------------------------- - */ +* +* Set attribute functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_string - * - * Purpose: Creates and writes a string attribute named attr_name and attaches - * it to the object specified by the name obj_name. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: July 23, 2001 - * - * Comments: If the attribute already exists, it is overwritten - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_string +* +* Purpose: Creates and writes a string attribute named attr_name and attaches +* it to the object specified by the name obj_name. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: July 23, 2001 +* +* Comments: If the attribute already exists, it is overwritten +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_string( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const char *attr_data ) + const char *obj_name, + const char *attr_name, + const char *attr_data ) { - hid_t attr_type; - hid_t attr_space_id; - hid_t attr_id; - hid_t obj_id; - int has_attr; - size_t attr_size; + hid_t attr_type; + hid_t attr_space_id; + hid_t attr_id; + hid_t obj_id; + int has_attr; + size_t attr_size; - /* Open the object */ - if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the object */ + if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0) + return -1; - /* Create the attribute */ - if ( (attr_type = H5Tcopy( H5T_C_S1 )) < 0 ) - goto out; + /* Create the attribute */ + if ( (attr_type = H5Tcopy( H5T_C_S1 )) < 0 ) + goto out; - attr_size = strlen( attr_data ) + 1; /* extra null term */ + attr_size = strlen( attr_data ) + 1; /* extra null term */ - if ( H5Tset_size( attr_type, (size_t)attr_size) < 0 ) - goto out; + if ( H5Tset_size( attr_type, (size_t)attr_size) < 0 ) + goto out; - if ( H5Tset_strpad( attr_type, H5T_STR_NULLTERM ) < 0 ) - goto out; + if ( H5Tset_strpad( attr_type, H5T_STR_NULLTERM ) < 0 ) + goto out; - if ( (attr_space_id = H5Screate( H5S_SCALAR )) < 0 ) - goto out; + if ( (attr_space_id = H5Screate( H5S_SCALAR )) < 0 ) + goto out; - /* Verify if the attribute already exists */ - has_attr = H5LT_find_attribute(obj_id, attr_name); + /* Verify if the attribute already exists */ + has_attr = H5LT_find_attribute(obj_id, attr_name); - /* The attribute already exists, delete it */ - if(has_attr == 1) - if(H5Adelete(obj_id, attr_name) < 0) - goto out; + /* The attribute already exists, delete it */ + if(has_attr == 1) + if(H5Adelete(obj_id, attr_name) < 0) + goto out; - /* Create and write the attribute */ + /* Create and write the attribute */ - if((attr_id = H5Acreate2(obj_id, attr_name, attr_type, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto out; + if((attr_id = H5Acreate2(obj_id, attr_name, attr_type, attr_space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto out; - if(H5Awrite(attr_id, attr_type, attr_data) < 0) - goto out; + if(H5Awrite(attr_id, attr_type, attr_data) < 0) + goto out; - if(H5Aclose(attr_id) < 0) - goto out; + if(H5Aclose(attr_id) < 0) + goto out; - if(H5Sclose(attr_space_id) < 0) - goto out; + if(H5Sclose(attr_space_id) < 0) + goto out; - if(H5Tclose(attr_type) < 0) - goto out; + if(H5Tclose(attr_type) < 0) + goto out; - /* Close the object */ - if(H5Oclose(obj_id) < 0) - return -1; + /* Close the object */ + if(H5Oclose(obj_id) < 0) + return -1; - return 0; + return 0; out: - H5Oclose(obj_id); - return -1; + H5Oclose(obj_id); + return -1; } @@ -920,185 +920,185 @@ out: /*------------------------------------------------------------------------- - * Function: H5LT_set_attribute_numerical - * - * Purpose: Private function used by H5LTset_attribute_int and H5LTset_attribute_float - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: July 25, 2001 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LT_set_attribute_numerical +* +* Purpose: Private function used by H5LTset_attribute_int and H5LTset_attribute_float +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: July 25, 2001 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LT_set_attribute_numerical( hid_t loc_id, - const char *obj_name, - const char *attr_name, - size_t size, - hid_t tid, - const void *data ) + const char *obj_name, + const char *attr_name, + size_t size, + hid_t tid, + const void *data ) { - hid_t obj_id, sid, attr_id; - hsize_t dim_size=size; - int has_attr; + hid_t obj_id, sid, attr_id; + hsize_t dim_size=size; + int has_attr; - /* Open the object */ - if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the object */ + if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0) + return -1; - /* Create the data space for the attribute. */ - if ( (sid = H5Screate_simple( 1, &dim_size, NULL )) < 0 ) - goto out; + /* Create the data space for the attribute. */ + if ( (sid = H5Screate_simple( 1, &dim_size, NULL )) < 0 ) + goto out; - /* Verify if the attribute already exists */ - has_attr = H5LT_find_attribute(obj_id, attr_name); + /* Verify if the attribute already exists */ + has_attr = H5LT_find_attribute(obj_id, attr_name); - /* The attribute already exists, delete it */ - if(has_attr == 1) - if(H5Adelete(obj_id, attr_name) < 0) - goto out; + /* The attribute already exists, delete it */ + if(has_attr == 1) + if(H5Adelete(obj_id, attr_name) < 0) + goto out; - /* Create the attribute. */ - if((attr_id = H5Acreate2(obj_id, attr_name, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto out; + /* Create the attribute. */ + if((attr_id = H5Acreate2(obj_id, attr_name, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto out; - /* Write the attribute data. */ - if(H5Awrite(attr_id, tid, data) < 0) - goto out; + /* Write the attribute data. */ + if(H5Awrite(attr_id, tid, data) < 0) + goto out; - /* Close the attribute. */ - if(H5Aclose(attr_id) < 0) - goto out; + /* Close the attribute. */ + if(H5Aclose(attr_id) < 0) + goto out; - /* Close the dataspace. */ - if(H5Sclose(sid) < 0) - goto out; + /* Close the dataspace. */ + if(H5Sclose(sid) < 0) + goto out; - /* Close the object */ - if(H5Oclose(obj_id) < 0) - return -1; + /* Close the object */ + if(H5Oclose(obj_id) < 0) + return -1; - return 0; + return 0; out: - H5Oclose(obj_id); - return -1; + H5Oclose(obj_id); + return -1; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_char - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 7, 2001 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_char +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 7, 2001 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_char( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const char *data, - size_t size ) + const char *obj_name, + const char *attr_name, + const char *data, + size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_CHAR, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_CHAR, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_uchar - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_uchar +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_uchar( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const unsigned char *data, - size_t size ) + const char *obj_name, + const char *attr_name, + const unsigned char *data, + size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_UCHAR, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_UCHAR, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_short - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 7, 2001 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_short +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 7, 2001 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_short( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const short *data, - size_t size ) + const char *obj_name, + const char *attr_name, + const short *data, + size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_SHORT, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_SHORT, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_ushort - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_ushort +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_ushort( hid_t loc_id, const char *obj_name, @@ -1107,60 +1107,60 @@ herr_t H5LTset_attribute_ushort( hid_t loc_id, size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_USHORT, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_USHORT, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_int - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 7, 2001 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_int +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 7, 2001 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_int( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const int *data, - size_t size ) + const char *obj_name, + const char *attr_name, + const int *data, + size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_INT, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_INT, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_uint - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_uint +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_uint( hid_t loc_id, const char *obj_name, @@ -1169,92 +1169,92 @@ herr_t H5LTset_attribute_uint( hid_t loc_id, size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_UINT, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_UINT, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_long - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 7, 2001 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_long +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 7, 2001 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_long( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const long *data, - size_t size ) + const char *obj_name, + const char *attr_name, + const long *data, + size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_LONG, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_LONG, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_long_long - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Elena Pourmal, epourmal@ncsa.uiuc.edu - * - * Date: June 17, 2005 - * - * Comments: This function was added to support attributes of type long long - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_long_long +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Elena Pourmal, epourmal@ncsa.uiuc.edu +* +* Date: June 17, 2005 +* +* Comments: This function was added to support attributes of type long long +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_long_long( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const long long *data, - size_t size ) + const char *obj_name, + const char *attr_name, + const long long *data, + size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_LLONG, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_LLONG, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_ulong - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_ulong +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_ulong( hid_t loc_id, const char *obj_name, @@ -1263,99 +1263,99 @@ herr_t H5LTset_attribute_ulong( hid_t loc_id, size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_ULONG, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_ULONG, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_float - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: July 25, 2001 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_float +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: July 25, 2001 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_float( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const float *data, - size_t size ) + const char *obj_name, + const char *attr_name, + const float *data, + size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_FLOAT, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_FLOAT, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTset_attribute_double - * - * Purpose: Create and write an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 7, 2001 - * - * Comments: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTset_attribute_double +* +* Purpose: Create and write an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 7, 2001 +* +* Comments: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTset_attribute_double( hid_t loc_id, - const char *obj_name, - const char *attr_name, - const double *data, - size_t size ) + const char *obj_name, + const char *attr_name, + const double *data, + size_t size ) { - if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, - H5T_NATIVE_DOUBLE, data ) < 0 ) - return -1; + if ( H5LT_set_attribute_numerical( loc_id, obj_name, attr_name, size, + H5T_NATIVE_DOUBLE, data ) < 0 ) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: find_attr - * - * Purpose: operator function used by H5LT_find_attribute - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: June 21, 2001 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: find_attr +* +* Purpose: operator function used by H5LT_find_attribute +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: June 21, 2001 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ static herr_t find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo, - void *op_data) + void *op_data) { int ret = H5_ITER_CONT; @@ -1363,9 +1363,9 @@ find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo, loc_id = loc_id; ainfo = ainfo; /* Define a positive value for return value if the attribute was found. This will - * cause the iterator to immediately return that positive value, - * indicating short-circuit success - */ + * cause the iterator to immediately return that positive value, + * indicating short-circuit success + */ if(strcmp(name, (char *)op_data) == 0) ret = H5_ITER_STOP; @@ -1374,51 +1374,51 @@ find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo, /*------------------------------------------------------------------------- - * Function: H5LTfind_attribute - * - * Purpose: Inquires if an attribute named attr_name exists attached to - * the object loc_id. - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: May 17, 2006 - * - * Comments: - * Calls the private version of the function - * - *------------------------------------------------------------------------- - */ +* Function: H5LTfind_attribute +* +* Purpose: Inquires if an attribute named attr_name exists attached to +* the object loc_id. +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: May 17, 2006 +* +* Comments: +* Calls the private version of the function +* +*------------------------------------------------------------------------- +*/ herr_t H5LTfind_attribute( hid_t loc_id, const char* attr_name ) { - return H5LT_find_attribute(loc_id,attr_name); + return H5LT_find_attribute(loc_id,attr_name); } /*------------------------------------------------------------------------- - * Function: H5LT_find_attribute - * - * Purpose: Inquires if an attribute named attr_name exists attached to the object loc_id. - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: June 21, 2001 - * - * Comments: - * The function uses H5Aiterate2 with the operator function find_attr - * - * Return: - * Success: The return value of the first operator that - * returns non-zero, or zero if all members were - * processed with no operator returning non-zero. - * - * Failure: Negative if something goes wrong within the - * library, or the negative value returned by one - * of the operators. - * - *------------------------------------------------------------------------- - */ +* Function: H5LT_find_attribute +* +* Purpose: Inquires if an attribute named attr_name exists attached to the object loc_id. +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: June 21, 2001 +* +* Comments: +* The function uses H5Aiterate2 with the operator function find_attr +* +* Return: +* Success: The return value of the first operator that +* returns non-zero, or zero if all members were +* processed with no operator returning non-zero. +* +* Failure: Negative if something goes wrong within the +* library, or the negative value returned by one +* of the operators. +* +*------------------------------------------------------------------------- +*/ herr_t H5LT_find_attribute( hid_t loc_id, const char* attr_name ) @@ -1429,146 +1429,146 @@ H5LT_find_attribute( hid_t loc_id, const char* attr_name ) /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_ndims - * - * Purpose: Gets the dimensionality of an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 4, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_ndims +* +* Purpose: Gets the dimensionality of an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 4, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_ndims( hid_t loc_id, - const char *obj_name, - const char *attr_name, - int *rank ) + const char *obj_name, + const char *attr_name, + int *rank ) { - hid_t attr_id; - hid_t sid; - hid_t obj_id; + hid_t attr_id; + hid_t sid; + hid_t obj_id; - /* Open the object */ - if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the object */ + if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0) + return -1; - /* Open the attribute. */ - if((attr_id = H5Aopen(obj_id, attr_name, H5P_DEFAULT)) < 0) - { - H5Oclose(obj_id); - return -1; - } + /* Open the attribute. */ + if((attr_id = H5Aopen(obj_id, attr_name, H5P_DEFAULT)) < 0) + { + H5Oclose(obj_id); + return -1; + } - /* Get the dataspace handle */ - if((sid = H5Aget_space(attr_id)) < 0) - goto out; + /* Get the dataspace handle */ + if((sid = H5Aget_space(attr_id)) < 0) + goto out; - /* Get rank */ - if((*rank = H5Sget_simple_extent_ndims(sid)) < 0) - goto out; + /* Get rank */ + if((*rank = H5Sget_simple_extent_ndims(sid)) < 0) + goto out; - /* Terminate access to the attribute */ - if ( H5Sclose( sid ) < 0 ) - goto out; + /* Terminate access to the attribute */ + if ( H5Sclose( sid ) < 0 ) + goto out; - /* End access to the attribute */ - if ( H5Aclose( attr_id ) ) - goto out;; + /* End access to the attribute */ + if ( H5Aclose( attr_id ) ) + goto out;; - /* Close the object */ - if(H5Oclose(obj_id) < 0 ) - return -1; + /* Close the object */ + if(H5Oclose(obj_id) < 0 ) + return -1; - return 0; + return 0; out: - H5Aclose( attr_id ); - H5Oclose(obj_id); - return -1; + H5Aclose( attr_id ); + H5Oclose(obj_id); + return -1; } /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_info - * - * Purpose: Gets information about an attribute. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 4, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_info +* +* Purpose: Gets information about an attribute. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 4, 2001 +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_info( hid_t loc_id, - const char *obj_name, - const char *attr_name, - hsize_t *dims, - H5T_class_t *type_class, - size_t *type_size ) + const char *obj_name, + const char *attr_name, + hsize_t *dims, + H5T_class_t *type_class, + size_t *type_size ) { - hid_t attr_id; - hid_t tid; - hid_t sid; - hid_t obj_id; + hid_t attr_id; + hid_t tid; + hid_t sid; + hid_t obj_id; - /* Open the object */ - if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the object */ + if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0) + return -1; - /* Open the attribute. */ - if((attr_id = H5Aopen(obj_id, attr_name, H5P_DEFAULT)) < 0) - { - H5Oclose(obj_id); - return -1; - } + /* Open the attribute. */ + if((attr_id = H5Aopen(obj_id, attr_name, H5P_DEFAULT)) < 0) + { + H5Oclose(obj_id); + return -1; + } - /* Get an identifier for the datatype. */ - tid = H5Aget_type(attr_id); + /* Get an identifier for the datatype. */ + tid = H5Aget_type(attr_id); - /* Get the class. */ - *type_class = H5Tget_class(tid); + /* Get the class. */ + *type_class = H5Tget_class(tid); - /* Get the size. */ - *type_size = H5Tget_size( tid ); + /* Get the size. */ + *type_size = H5Tget_size( tid ); - /* Get the dataspace handle */ - if ( (sid = H5Aget_space( attr_id )) < 0 ) - goto out; + /* Get the dataspace handle */ + if ( (sid = H5Aget_space( attr_id )) < 0 ) + goto out; - /* Get dimensions */ - if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 ) - goto out; + /* Get dimensions */ + if ( H5Sget_simple_extent_dims( sid, dims, NULL) < 0 ) + goto out; - /* Terminate access to the dataspace */ - if ( H5Sclose( sid ) < 0 ) - goto out; + /* Terminate access to the dataspace */ + if ( H5Sclose( sid ) < 0 ) + goto out; - /* Release the datatype. */ - if ( H5Tclose( tid ) ) - goto out; + /* Release the datatype. */ + if ( H5Tclose( tid ) ) + goto out; - /* End access to the attribute */ - if ( H5Aclose( attr_id ) ) - goto out; + /* End access to the attribute */ + if ( H5Aclose( attr_id ) ) + goto out; - /* Close the object */ - if(H5Oclose(obj_id) < 0 ) - return -1; + /* Close the object */ + if(H5Oclose(obj_id) < 0 ) + return -1; - return 0; + return 0; out: - H5Tclose(tid); - H5Aclose(attr_id); - H5Oclose(obj_id); - return -1; + H5Tclose(tid); + H5Aclose(attr_id); + H5Oclose(obj_id); + return -1; } @@ -1576,65 +1576,65 @@ out: /*------------------------------------------------------------------------- - * Function: H5LTtext_to_dtype - * - * Purpose: Convert DDL description to HDF5 data type. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Raymond Lu, slu@ncsa.uiuc.edu - * - * Date: October 6, 2004 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTtext_to_dtype +* +* Purpose: Convert DDL description to HDF5 data type. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Raymond Lu, slu@ncsa.uiuc.edu +* +* Date: October 6, 2004 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ hid_t H5LTtext_to_dtype(const char *text, H5LT_lang_t lang_type) { - extern int H5LTyyparse(void); - hid_t type_id; + extern int H5LTyyparse(void); + hid_t type_id; - if(lang_type <= H5LT_LANG_ERR || lang_type >= H5LT_NO_LANG) - goto out; + if(lang_type <= H5LT_LANG_ERR || lang_type >= H5LT_NO_LANG) + goto out; - if(lang_type != H5LT_DDL) { - fprintf(stderr, "only DDL is supported for now.\n"); - goto out; - } + if(lang_type != H5LT_DDL) { + fprintf(stderr, "only DDL is supported for now.\n"); + goto out; + } - input_len = strlen(text); - myinput = strdup(text); + input_len = strlen(text); + myinput = strdup(text); - if((type_id = H5LTyyparse()) < 0) - goto out; + if((type_id = H5LTyyparse()) < 0) + goto out; - free(myinput); - input_len = 0; + free(myinput); + input_len = 0; - return type_id; + return type_id; out: - return -1; + return -1; } /*------------------------------------------------------------------------- - * Function: indentation - * - * Purpose: Print spaces for indentation - * - * Return: void - * - * Programmer: Raymond Lu, slu@ncsa.uiuc.edu - * - * Date: December 6, 2005 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: indentation +* +* Purpose: Print spaces for indentation +* +* Return: void +* +* Programmer: Raymond Lu, slu@ncsa.uiuc.edu +* +* Date: December 6, 2005 +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ static void indentation(int x, char* str) { @@ -1648,17 +1648,17 @@ indentation(int x, char* str) } /*------------------------------------------------------------------------- - * Function: print_enum - * - * Purpose: prints the enum data - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Raymond Lu - * - * Modifications: - * - *-----------------------------------------------------------------------*/ +* Function: print_enum +* +* Purpose: prints the enum data +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Raymond Lu +* +* Modifications: +* +*-----------------------------------------------------------------------*/ static herr_t print_enum(hid_t type, char* str, int indt) { @@ -1682,9 +1682,9 @@ print_enum(hid_t type, char* str, int indt) goto out; /* Use buffer of INT or UNSIGNED INT to print enum values because - * we don't expect these values to be so big that INT or UNSIGNED - * INT can't hold. - */ + * we don't expect these values to be so big that INT or UNSIGNED + * INT can't hold. + */ if (H5T_SGN_NONE == H5Tget_sign(super)) { native = H5T_NATIVE_UINT; } else { @@ -1699,9 +1699,9 @@ print_enum(hid_t type, char* str, int indt) value = (unsigned char*)calloc((size_t)nmembs, MAX(dst_size, super_size)); for (i = 0; i < nmembs; i++) { - if((name[i] = H5Tget_member_name(type, (unsigned)i))==NULL) + if((name[i] = H5Tget_member_name(type, (unsigned)i))==NULL) goto out; - if(H5Tget_member_value(type, (unsigned)i, value + i * super_size) < 0) + if(H5Tget_member_value(type, (unsigned)i, value + i * super_size) < 0) goto out; } @@ -1712,45 +1712,45 @@ print_enum(hid_t type, char* str, int indt) } /* - * Sort members by increasing value - * ***not implemented yet*** - */ + * Sort members by increasing value + * ***not implemented yet*** + */ /* Print members */ for (i = 0; i < nmembs; i++) { - indentation(indt + COL, str); - nchars = sprintf(tmp_str, "\"%s\"", name[i]); + indentation(indt + COL, str); + nchars = sprintf(tmp_str, "\"%s\"", name[i]); strcat(str, tmp_str); - sprintf(tmp_str, "%*s ", MAX(0, 16 - nchars), ""); + sprintf(tmp_str, "%*s ", MAX(0, 16 - nchars), ""); strcat(str, tmp_str); - if (H5T_SGN_NONE == H5Tget_sign(native)) { - /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" - *strangely, unless use another pointer "copy".*/ - copy = value+i*dst_size; - sprintf(tmp_str,"%u", *((unsigned int*)((void *)copy))); + if (H5T_SGN_NONE == H5Tget_sign(native)) { + /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" + *strangely, unless use another pointer "copy".*/ + copy = value+i*dst_size; + sprintf(tmp_str,"%u", *((unsigned int*)((void *)copy))); strcat(str, tmp_str); - } else { - /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" - *strangely, unless use another pointer "copy".*/ - copy = value+i*dst_size; - sprintf(tmp_str,"%d", *((int*)((void *)copy))); + } else { + /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" + *strangely, unless use another pointer "copy".*/ + copy = value+i*dst_size; + sprintf(tmp_str,"%d", *((int*)((void *)copy))); strcat(str, tmp_str); - } + } - strcat(str, ";\n"); + strcat(str, ";\n"); } /* Release resources */ for (i = 0; i < nmembs; i++) - free(name[i]); + free(name[i]); free(name); free(value); H5Tclose(super); if (0 == nmembs) { - sprintf(tmp_str, "\n%*s <empty>", indt + 4, ""); + sprintf(tmp_str, "\n%*s <empty>", indt + 4, ""); strcat(str, tmp_str); } @@ -1761,22 +1761,22 @@ out: } /*------------------------------------------------------------------------- - * Function: H5LTdtype_to_text - * - * Purpose: Convert HDF5 data type to DDL description. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Raymond Lu, slu@ncsa.uiuc.edu - * - * Date: December 6, 2005 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTdtype_to_text +* +* Purpose: Convert HDF5 data type to DDL description. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Raymond Lu, slu@ncsa.uiuc.edu +* +* Date: December 6, 2005 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTdtype_to_text(hid_t dtype, char *str, H5LT_lang_t lang_type, size_t *len) { size_t str_len = INCREMENT; @@ -1805,24 +1805,24 @@ out: } /*------------------------------------------------------------------------- - * Function: H5LT_dtype_to_text - * - * Purpose: Private function to convert HDF5 data type to DDL description. - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Raymond Lu, slu@ncsa.uiuc.edu - * - * Date: December 20, 2005 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LT_dtype_to_text +* +* Purpose: Private function to convert HDF5 data type to DDL description. +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Raymond Lu, slu@ncsa.uiuc.edu +* +* Date: December 20, 2005 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LT_dtype_to_text(hid_t dtype, char **dt_str, H5LT_lang_t lang, size_t *slen, - hbool_t no_user_buf) + hbool_t no_user_buf) { H5T_class_t tcls; char tmp_str[256]; @@ -1834,8 +1834,8 @@ herr_t H5LT_dtype_to_text(hid_t dtype, char **dt_str, H5LT_lang_t lang, size_t * *slen += INCREMENT; tmp = (char*)realloc(*dt_str, *slen); if(tmp != *dt_str) { - free(*dt_str); - *dt_str = tmp; + free(*dt_str); + *dt_str = tmp; } } @@ -1930,150 +1930,150 @@ herr_t H5LT_dtype_to_text(hid_t dtype, char **dt_str, H5LT_lang_t lang, size_t * break; case H5T_STRING: { - /* Make a copy of type in memory in case when DTYPE is on disk, the size - * will be bigger than in memory. This makes it easier to compare - * types in memory. */ - hid_t str_type; - H5T_order_t order; - hid_t tmp_type; - size_t size; - H5T_str_t str_pad; - H5T_cset_t cset; - htri_t is_vlstr; - - if((tmp_type = H5Tcopy(dtype)) < 0) - goto out; - if((size = H5Tget_size(tmp_type))==0) - goto out; - if((str_pad = H5Tget_strpad(tmp_type)) < 0) - goto out; - if((cset = H5Tget_cset(tmp_type)) < 0) - goto out; - if((is_vlstr = H5Tis_variable_str(tmp_type)) < 0) - goto out; + /* Make a copy of type in memory in case when DTYPE is on disk, the size + * will be bigger than in memory. This makes it easier to compare + * types in memory. */ + hid_t str_type; + H5T_order_t order; + hid_t tmp_type; + size_t size; + H5T_str_t str_pad; + H5T_cset_t cset; + htri_t is_vlstr; + + if((tmp_type = H5Tcopy(dtype)) < 0) + goto out; + if((size = H5Tget_size(tmp_type))==0) + goto out; + if((str_pad = H5Tget_strpad(tmp_type)) < 0) + goto out; + if((cset = H5Tget_cset(tmp_type)) < 0) + goto out; + if((is_vlstr = H5Tis_variable_str(tmp_type)) < 0) + goto out; - /* Print lead-in */ - sprintf(*dt_str, "H5T_STRING {\n"); - indent += COL; + /* Print lead-in */ + sprintf(*dt_str, "H5T_STRING {\n"); + indent += COL; - indentation(indent + COL, *dt_str); + indentation(indent + COL, *dt_str); - if(is_vlstr) - strcat(*dt_str, "STRSIZE H5T_VARIABLE;\n"); - else { - sprintf(tmp_str, "STRSIZE %d;\n", (int)size); - strcat(*dt_str, tmp_str); - } + if(is_vlstr) + strcat(*dt_str, "STRSIZE H5T_VARIABLE;\n"); + else { + sprintf(tmp_str, "STRSIZE %d;\n", (int)size); + strcat(*dt_str, tmp_str); + } - indentation(indent + COL, *dt_str); + indentation(indent + COL, *dt_str); - if (str_pad == H5T_STR_NULLTERM) - strcat(*dt_str, "STRPAD H5T_STR_NULLTERM;\n"); - else if (str_pad == H5T_STR_NULLPAD) - strcat(*dt_str, "STRPAD H5T_STR_NULLPAD;\n"); - else if (str_pad == H5T_STR_SPACEPAD) - strcat(*dt_str, "STRPAD H5T_STR_SPACEPAD;\n"); - else - strcat(*dt_str, "STRPAD H5T_STR_ERROR;\n"); + if (str_pad == H5T_STR_NULLTERM) + strcat(*dt_str, "STRPAD H5T_STR_NULLTERM;\n"); + else if (str_pad == H5T_STR_NULLPAD) + strcat(*dt_str, "STRPAD H5T_STR_NULLPAD;\n"); + else if (str_pad == H5T_STR_SPACEPAD) + strcat(*dt_str, "STRPAD H5T_STR_SPACEPAD;\n"); + else + strcat(*dt_str, "STRPAD H5T_STR_ERROR;\n"); - indentation(indent + COL, *dt_str); + indentation(indent + COL, *dt_str); - if (cset == H5T_CSET_ASCII) - strcat(*dt_str, "CSET H5T_CSET_ASCII;\n"); - else if (cset == H5T_CSET_UTF8) - strcat(*dt_str, "CSET H5T_CSET_UTF8;\n"); - else - strcat(*dt_str, "CSET unknown;\n"); + if (cset == H5T_CSET_ASCII) + strcat(*dt_str, "CSET H5T_CSET_ASCII;\n"); + else if (cset == H5T_CSET_UTF8) + strcat(*dt_str, "CSET H5T_CSET_UTF8;\n"); + else + strcat(*dt_str, "CSET unknown;\n"); - /* Reproduce a C type string */ - if((str_type = H5Tcopy(H5T_C_S1)) < 0) - goto out; - if(is_vlstr) { - if(H5Tset_size(str_type, H5T_VARIABLE) < 0) + /* Reproduce a C type string */ + if((str_type = H5Tcopy(H5T_C_S1)) < 0) goto out; - } else { - if(H5Tset_size(str_type, size) < 0) + if(is_vlstr) { + if(H5Tset_size(str_type, H5T_VARIABLE) < 0) + goto out; + } else { + if(H5Tset_size(str_type, size) < 0) + goto out; + } + if(H5Tset_cset(str_type, cset) < 0) + goto out; + if(H5Tset_strpad(str_type, str_pad) < 0) goto out; - } - if(H5Tset_cset(str_type, cset) < 0) - goto out; - if(H5Tset_strpad(str_type, str_pad) < 0) - goto out; - indentation(indent + COL, *dt_str); + indentation(indent + COL, *dt_str); - /* Check C variable-length string first. Are the two types equal? */ - if (H5Tequal(tmp_type, str_type)) { - strcat(*dt_str, "CTYPE H5T_C_S1;\n"); - goto next; - } + /* Check C variable-length string first. Are the two types equal? */ + if (H5Tequal(tmp_type, str_type)) { + strcat(*dt_str, "CTYPE H5T_C_S1;\n"); + goto next; + } - /* Change the endianness and see if they're equal. */ - if((order = H5Tget_order(tmp_type)) < 0) - goto out; - if(order==H5T_ORDER_LE) { - if(H5Tset_order(str_type, H5T_ORDER_LE) < 0) + /* Change the endianness and see if they're equal. */ + if((order = H5Tget_order(tmp_type)) < 0) goto out; - } else if(order==H5T_ORDER_BE) { - if(H5Tset_order(str_type, H5T_ORDER_BE) < 0) + if(order==H5T_ORDER_LE) { + if(H5Tset_order(str_type, H5T_ORDER_LE) < 0) + goto out; + } else if(order==H5T_ORDER_BE) { + if(H5Tset_order(str_type, H5T_ORDER_BE) < 0) + goto out; + } + + if (H5Tequal(tmp_type, str_type)) { + strcat(*dt_str, "H5T_C_S1;\n"); + goto next; + } + + /* If not equal to C variable-length string, check Fortran type. + * Actually H5Tequal can't tell difference between H5T_C_S1 and H5T_FORTRAN_S1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + if(H5Tclose(str_type) < 0) goto out; - } - - if (H5Tequal(tmp_type, str_type)) { - strcat(*dt_str, "H5T_C_S1;\n"); - goto next; - } - - /* If not equal to C variable-length string, check Fortran type. - * Actually H5Tequal can't tell difference between H5T_C_S1 and H5T_FORTRAN_S1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ - if(H5Tclose(str_type) < 0) - goto out; - if((str_type = H5Tcopy(H5T_FORTRAN_S1)) < 0) - goto out; - if(H5Tset_cset(str_type, cset) < 0) - goto out; - if(H5Tset_size(str_type, size) < 0) - goto out; - if(H5Tset_strpad(str_type, str_pad) < 0) - goto out; - - /* Are the two types equal? */ - if (H5Tequal(tmp_type, str_type)) { - strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n"); - goto next; - } - - /* Change the endianness and see if they're equal. */ - if((order = H5Tget_order(tmp_type)) < 0) - goto out; - if(order==H5T_ORDER_LE) { - if(H5Tset_order(str_type, H5T_ORDER_LE) < 0) + if((str_type = H5Tcopy(H5T_FORTRAN_S1)) < 0) goto out; - } else if(order==H5T_ORDER_BE) { - if(H5Tset_order(str_type, H5T_ORDER_BE) < 0) + if(H5Tset_cset(str_type, cset) < 0) + goto out; + if(H5Tset_size(str_type, size) < 0) + goto out; + if(H5Tset_strpad(str_type, str_pad) < 0) goto out; - } - /* Are the two types equal? */ - if (H5Tequal(tmp_type, str_type)) { - strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n"); - goto next; - } + /* Are the two types equal? */ + if (H5Tequal(tmp_type, str_type)) { + strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n"); + goto next; + } - /* Type doesn't match any of above. */ - strcat(*dt_str, "CTYPE unknown_one_character_type;\n "); + /* Change the endianness and see if they're equal. */ + if((order = H5Tget_order(tmp_type)) < 0) + goto out; + if(order==H5T_ORDER_LE) { + if(H5Tset_order(str_type, H5T_ORDER_LE) < 0) + goto out; + } else if(order==H5T_ORDER_BE) { + if(H5Tset_order(str_type, H5T_ORDER_BE) < 0) + goto out; + } + + /* Are the two types equal? */ + if (H5Tequal(tmp_type, str_type)) { + strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n"); + goto next; + } + + /* Type doesn't match any of above. */ + strcat(*dt_str, "CTYPE unknown_one_character_type;\n "); next: - H5Tclose(str_type); - H5Tclose(tmp_type); + H5Tclose(str_type); + H5Tclose(tmp_type); - /* Print closing */ - indent -= COL; - indentation(indent + COL, *dt_str); - strcat(*dt_str, "}"); + /* Print closing */ + indent -= COL; + indentation(indent + COL, *dt_str); + strcat(*dt_str, "}"); - break; + break; } case H5T_OPAQUE: /* Print lead-in */ @@ -2096,166 +2096,166 @@ next: break; case H5T_ENUM: { - hid_t super; - size_t super_len; - char* stmp; + hid_t super; + size_t super_len; + char* stmp; - /* Print lead-in */ - sprintf(*dt_str, "H5T_ENUM {\n"); - indent += COL; - indentation(indent + COL, *dt_str); + /* Print lead-in */ + sprintf(*dt_str, "H5T_ENUM {\n"); + indent += COL; + indentation(indent + COL, *dt_str); - if((super = H5Tget_super(dtype)) < 0) - goto out; - if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0) - goto out; - stmp = (char*)calloc(super_len, sizeof(char)); - if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) - goto out; - strcat(*dt_str, stmp); - free(stmp); - strcat(*dt_str, ";\n"); - H5Tclose(super); - - if(print_enum(dtype, *dt_str, indent) < 0) - goto out; + if((super = H5Tget_super(dtype)) < 0) + goto out; + if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0) + goto out; + stmp = (char*)calloc(super_len, sizeof(char)); + if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) + goto out; + strcat(*dt_str, stmp); + free(stmp); + strcat(*dt_str, ";\n"); + H5Tclose(super); - /* Print closing */ - indent -= COL; - indentation(indent + COL, *dt_str); - strcat(*dt_str, "}"); + if(print_enum(dtype, *dt_str, indent) < 0) + goto out; - break; + /* Print closing */ + indent -= COL; + indentation(indent + COL, *dt_str); + strcat(*dt_str, "}"); + + break; } case H5T_VLEN: { - hid_t super; - size_t super_len; - char* stmp; + hid_t super; + size_t super_len; + char* stmp; - /* Print lead-in */ - sprintf(*dt_str, "H5T_VLEN {\n"); - indent += COL; - indentation(indent + COL, *dt_str); + /* Print lead-in */ + sprintf(*dt_str, "H5T_VLEN {\n"); + indent += COL; + indentation(indent + COL, *dt_str); - if((super = H5Tget_super(dtype)) < 0) - goto out; - if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0) - goto out; - stmp = (char*)calloc(super_len, sizeof(char)); - if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) - goto out; - strcat(*dt_str, stmp); - free(stmp); - strcat(*dt_str, "\n"); - H5Tclose(super); + if((super = H5Tget_super(dtype)) < 0) + goto out; + if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0) + goto out; + stmp = (char*)calloc(super_len, sizeof(char)); + if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) + goto out; + strcat(*dt_str, stmp); + free(stmp); + strcat(*dt_str, "\n"); + H5Tclose(super); - /* Print closing */ - indent -= COL; - indentation(indent + COL, *dt_str); - strcat(*dt_str, "}"); + /* Print closing */ + indent -= COL; + indentation(indent + COL, *dt_str); + strcat(*dt_str, "}"); - break; + break; } case H5T_ARRAY: { - hid_t super; - size_t super_len; - char* stmp; - hsize_t dims[H5S_MAX_RANK]; - int ndims; - - /* Print lead-in */ - sprintf(*dt_str, "H5T_ARRAY {\n"); - indent += COL; - indentation(indent + COL, *dt_str); - - /* Get array information */ - if((ndims = H5Tget_array_ndims(dtype)) < 0) - goto out; - if(H5Tget_array_dims2(dtype, dims) < 0) - goto out; - - /* Print array dimensions */ - for (i = 0; i < ndims; i++) { - sprintf(tmp_str, "[%d]", (int) dims[i]); - strcat(*dt_str, tmp_str); - } - strcat(*dt_str, " "); - - if((super = H5Tget_super(dtype)) < 0) - goto out; - if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0) - goto out; - stmp = (char*)calloc(super_len, sizeof(char)); - if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) - goto out; - strcat(*dt_str, stmp); - free(stmp); - strcat(*dt_str, "\n"); - H5Tclose(super); - - /* Print closing */ - indent -= COL; - indentation(indent + COL, *dt_str); - strcat(*dt_str, "}"); - - break; - } - case H5T_COMPOUND: - { - char *mname; - hid_t mtype; - size_t moffset; - H5T_class_t mclass; - size_t mlen; - char* mtmp; - int nmembs; - - if((nmembs = H5Tget_nmembers(dtype)) < 0) - goto out; - - sprintf(*dt_str, "H5T_COMPOUND {\n"); - indent += COL; + hid_t super; + size_t super_len; + char* stmp; + hsize_t dims[H5S_MAX_RANK]; + int ndims; + + /* Print lead-in */ + sprintf(*dt_str, "H5T_ARRAY {\n"); + indent += COL; + indentation(indent + COL, *dt_str); - for (i = 0; i < nmembs; i++) { - if((mname = H5Tget_member_name(dtype, (unsigned)i))==NULL) + /* Get array information */ + if((ndims = H5Tget_array_ndims(dtype)) < 0) goto out; - if((mtype = H5Tget_member_type(dtype, (unsigned)i)) < 0) + if(H5Tget_array_dims2(dtype, dims) < 0) goto out; - moffset = H5Tget_member_offset(dtype, (unsigned)i); - indentation(indent + COL, *dt_str); - if((mclass = H5Tget_class(mtype)) < 0) - goto out; - if (H5T_COMPOUND == mclass) - indent += COL; + /* Print array dimensions */ + for (i = 0; i < ndims; i++) { + sprintf(tmp_str, "[%d]", (int) dims[i]); + strcat(*dt_str, tmp_str); + } + strcat(*dt_str, " "); - if(H5LTdtype_to_text(mtype, NULL, lang, &mlen) < 0) + if((super = H5Tget_super(dtype)) < 0) goto out; - mtmp = (char*)calloc(mlen, sizeof(char)); - if(H5LTdtype_to_text(mtype, mtmp, lang, &mlen) < 0) + if(H5LTdtype_to_text(super, NULL, lang, &super_len) < 0) goto out; - strcat(*dt_str, mtmp); - free(mtmp); - - if (H5T_COMPOUND == mclass) - indent -= COL; + stmp = (char*)calloc(super_len, sizeof(char)); + if(H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) + goto out; + strcat(*dt_str, stmp); + free(stmp); + strcat(*dt_str, "\n"); + H5Tclose(super); - sprintf(tmp_str, " \"%s\"", mname); - strcat(*dt_str, tmp_str); - free(mname); + /* Print closing */ + indent -= COL; + indentation(indent + COL, *dt_str); + strcat(*dt_str, "}"); - sprintf(tmp_str, " : %lu;\n", (unsigned long)moffset); - strcat(*dt_str, tmp_str); + break; } + case H5T_COMPOUND: + { + char *mname; + hid_t mtype; + size_t moffset; + H5T_class_t mclass; + size_t mlen; + char* mtmp; + int nmembs; + + if((nmembs = H5Tget_nmembers(dtype)) < 0) + goto out; - /* Print closing */ - indent -= COL; - indentation(indent + COL, *dt_str); - strcat(*dt_str, "}"); + sprintf(*dt_str, "H5T_COMPOUND {\n"); + indent += COL; + + for (i = 0; i < nmembs; i++) { + if((mname = H5Tget_member_name(dtype, (unsigned)i))==NULL) + goto out; + if((mtype = H5Tget_member_type(dtype, (unsigned)i)) < 0) + goto out; + moffset = H5Tget_member_offset(dtype, (unsigned)i); + indentation(indent + COL, *dt_str); + + if((mclass = H5Tget_class(mtype)) < 0) + goto out; + if (H5T_COMPOUND == mclass) + indent += COL; + + if(H5LTdtype_to_text(mtype, NULL, lang, &mlen) < 0) + goto out; + mtmp = (char*)calloc(mlen, sizeof(char)); + if(H5LTdtype_to_text(mtype, mtmp, lang, &mlen) < 0) + goto out; + strcat(*dt_str, mtmp); + free(mtmp); + + if (H5T_COMPOUND == mclass) + indent -= COL; + + sprintf(tmp_str, " \"%s\"", mname); + strcat(*dt_str, tmp_str); + free(mname); + + sprintf(tmp_str, " : %lu;\n", (unsigned long)moffset); + strcat(*dt_str, tmp_str); + } + + /* Print closing */ + indent -= COL; + indentation(indent + COL, *dt_str); + strcat(*dt_str, "}"); - break; + break; } case H5T_TIME: sprintf(*dt_str, "H5T_TIME: not yet implemented"); @@ -2278,77 +2278,77 @@ out: /*------------------------------------------------------------------------- - * - * Get attribute functions - * - *------------------------------------------------------------------------- - */ +* +* Get attribute functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_string - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_string +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_string( hid_t loc_id, - const char *obj_name, - const char *attr_name, - char *data ) + const char *obj_name, + const char *attr_name, + char *data ) { - /* identifiers */ - hid_t obj_id; + /* identifiers */ + hid_t obj_id; - /* Open the object */ - if ((obj_id = H5Oopen( loc_id, obj_name, H5P_DEFAULT)) < 0) - return -1; + /* Open the object */ + if ((obj_id = H5Oopen( loc_id, obj_name, H5P_DEFAULT)) < 0) + return -1; - /* Get the attribute */ - if ( H5LT_get_attribute_disk( obj_id, attr_name, data ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LT_get_attribute_disk( obj_id, attr_name, data ) < 0 ) + return -1; - /* Close the object */ - if(H5Oclose(obj_id) < 0) - return -1; + /* Close the object */ + if(H5Oclose(obj_id) < 0) + return -1; - return 0; + return 0; } /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_char - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_char +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_char( hid_t loc_id, - const char *obj_name, - const char *attr_name, - char *data ) + const char *obj_name, + const char *attr_name, + char *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_CHAR, data) < 0) @@ -2358,26 +2358,26 @@ herr_t H5LTget_attribute_char( hid_t loc_id, } /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_uchar - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_uchar +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_uchar( hid_t loc_id, - const char *obj_name, - const char *attr_name, - unsigned char *data ) + const char *obj_name, + const char *attr_name, + unsigned char *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_UCHAR, data) < 0) @@ -2389,26 +2389,26 @@ herr_t H5LTget_attribute_uchar( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_short - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_short +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_short( hid_t loc_id, - const char *obj_name, - const char *attr_name, - short *data ) + const char *obj_name, + const char *attr_name, + short *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_SHORT, data) < 0) @@ -2418,22 +2418,22 @@ herr_t H5LTget_attribute_short( hid_t loc_id, } /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_ushort - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_ushort +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_ushort( hid_t loc_id, const char *obj_name, const char *attr_name, @@ -2449,26 +2449,26 @@ herr_t H5LTget_attribute_ushort( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_int - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_int +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_int( hid_t loc_id, - const char *obj_name, - const char *attr_name, - int *data ) + const char *obj_name, + const char *attr_name, + int *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_INT, data) < 0) @@ -2478,22 +2478,22 @@ herr_t H5LTget_attribute_int( hid_t loc_id, } /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_uint - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_uint +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_uint( hid_t loc_id, const char *obj_name, const char *attr_name, @@ -2509,22 +2509,22 @@ herr_t H5LTget_attribute_uint( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_long - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_long +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_long( hid_t loc_id, const char *obj_name, const char *attr_name, @@ -2538,26 +2538,26 @@ herr_t H5LTget_attribute_long( hid_t loc_id, } /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_long_long - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Elena Pourmal, epourmal@ncsa.uiuc.edu - * - * Date: June 17, 2005 - * - * Comments: This funstion was added to suuport INTEGER*8 Fortran types - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_long_long +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Elena Pourmal, epourmal@ncsa.uiuc.edu +* +* Date: June 17, 2005 +* +* Comments: This funstion was added to suuport INTEGER*8 Fortran types +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_long_long( hid_t loc_id, - const char *obj_name, - const char *attr_name, - long long *data ) + const char *obj_name, + const char *attr_name, + long long *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_LLONG, data) < 0) @@ -2568,26 +2568,26 @@ herr_t H5LTget_attribute_long_long( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_ulong - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_ulong +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_ulong( hid_t loc_id, - const char *obj_name, - const char *attr_name, - unsigned long *data ) + const char *obj_name, + const char *attr_name, + unsigned long *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_ULONG, data) < 0) @@ -2598,28 +2598,28 @@ herr_t H5LTget_attribute_ulong( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_float - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_float +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_float( hid_t loc_id, - const char *obj_name, - const char *attr_name, - float *data ) + const char *obj_name, + const char *attr_name, + float *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_FLOAT, data) < 0) @@ -2630,28 +2630,28 @@ herr_t H5LTget_attribute_float( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTget_attribute_double - * - * Purpose: Reads an attribute named attr_name - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute_double +* +* Purpose: Reads an attribute named attr_name +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute_double( hid_t loc_id, - const char *obj_name, - const char *attr_name, - double *data ) + const char *obj_name, + const char *attr_name, + double *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, H5T_NATIVE_DOUBLE, data) < 0) @@ -2662,29 +2662,29 @@ herr_t H5LTget_attribute_double( hid_t loc_id, /*------------------------------------------------------------------------- - * Function: H5LTget_attribute - * - * Purpose: Reads an attribute named attr_name with the memory type mem_type_id - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: Private function - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LTget_attribute +* +* Purpose: Reads an attribute named attr_name with the memory type mem_type_id +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: Private function +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LTget_attribute( hid_t loc_id, - const char *obj_name, - const char *attr_name, - hid_t mem_type_id, - void *data ) + const char *obj_name, + const char *attr_name, + hid_t mem_type_id, + void *data ) { /* Get the attribute */ if(H5LT_get_attribute_mem(loc_id, obj_name, attr_name, mem_type_id, data) < 0) @@ -2695,35 +2695,35 @@ herr_t H5LTget_attribute( hid_t loc_id, /*------------------------------------------------------------------------- - * private functions - *------------------------------------------------------------------------- - */ +* private functions +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5LT_get_attribute_mem - * - * Purpose: Reads an attribute named attr_name with the memory type mem_type_id - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: Private function - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LT_get_attribute_mem +* +* Purpose: Reads an attribute named attr_name with the memory type mem_type_id +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: Private function +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ static herr_t H5LT_get_attribute_mem(hid_t loc_id, - const char *obj_name, - const char *attr_name, - hid_t mem_type_id, - void *data) + const char *obj_name, + const char *attr_name, + hid_t mem_type_id, + void *data) { /* identifiers */ hid_t obj_id = -1; @@ -2745,7 +2745,7 @@ static herr_t H5LT_get_attribute_mem(hid_t loc_id, /* Close the object */ if(H5Oclose(obj_id) < 0) - goto out; + goto out; obj_id = -1; return 0; @@ -2757,138 +2757,138 @@ out: } /*------------------------------------------------------------------------- - * Function: H5LT_get_attribute_disk - * - * Purpose: Reads an attribute named attr_name with the datatype stored on disk - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September 19, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LT_get_attribute_disk +* +* Purpose: Reads an attribute named attr_name with the datatype stored on disk +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: September 19, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LT_get_attribute_disk( hid_t loc_id, - const char *attr_name, - void *attr_out ) + const char *attr_name, + void *attr_out ) { - /* identifiers */ - hid_t attr_id; - hid_t attr_type; + /* identifiers */ + hid_t attr_id; + hid_t attr_type; - if(( attr_id = H5Aopen(loc_id, attr_name, H5P_DEFAULT)) < 0) - return -1; + if(( attr_id = H5Aopen(loc_id, attr_name, H5P_DEFAULT)) < 0) + return -1; - if((attr_type = H5Aget_type(attr_id)) < 0) - goto out; + if((attr_type = H5Aget_type(attr_id)) < 0) + goto out; - if(H5Aread(attr_id, attr_type, attr_out) < 0) - goto out; + if(H5Aread(attr_id, attr_type, attr_out) < 0) + goto out; - if(H5Tclose(attr_type) < 0) - goto out; + if(H5Tclose(attr_type) < 0) + goto out; - if ( H5Aclose( attr_id ) < 0 ) - return -1;; + if ( H5Aclose( attr_id ) < 0 ) + return -1;; - return 0; + return 0; out: - H5Tclose( attr_type ); - H5Aclose( attr_id ); - return -1; + H5Tclose( attr_type ); + H5Aclose( attr_id ); + return -1; } /*------------------------------------------------------------------------- - * Function: H5LT_set_attribute_string - * - * Purpose: creates and writes an attribute named NAME to the dataset DSET_ID - * - * Return: FAIL on error, SUCCESS on success - * - * Programmer: pvn@ncsa.uiuc.edu - * - * Date: January 04, 2005 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5LT_set_attribute_string +* +* Purpose: creates and writes an attribute named NAME to the dataset DSET_ID +* +* Return: FAIL on error, SUCCESS on success +* +* Programmer: pvn@ncsa.uiuc.edu +* +* Date: January 04, 2005 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5LT_set_attribute_string(hid_t dset_id, const char *name, const char *buf ) { - hid_t tid; - hid_t sid = -1; - hid_t aid = -1; - int has_attr; - size_t size; - - /* verify if the attribute already exists */ - has_attr = H5LT_find_attribute(dset_id,name); - - /* the attribute already exists, delete it */ - if(has_attr == 1) - if(H5Adelete(dset_id, name) < 0) - return FAIL; + hid_t tid; + hid_t sid = -1; + hid_t aid = -1; + int has_attr; + size_t size; -/*------------------------------------------------------------------------- - * create the attribute type - *------------------------------------------------------------------------- - */ - if((tid = H5Tcopy(H5T_C_S1)) < 0) - return FAIL; + /* verify if the attribute already exists */ + has_attr = H5LT_find_attribute(dset_id,name); - size = strlen(buf) + 1; /* extra null term */ + /* the attribute already exists, delete it */ + if(has_attr == 1) + if(H5Adelete(dset_id, name) < 0) + return FAIL; - if(H5Tset_size(tid,(size_t)size) < 0) - goto out; + /*------------------------------------------------------------------------- + * create the attribute type + *------------------------------------------------------------------------- + */ + if((tid = H5Tcopy(H5T_C_S1)) < 0) + return FAIL; - if(H5Tset_strpad(tid, H5T_STR_NULLTERM) < 0) - goto out; + size = strlen(buf) + 1; /* extra null term */ - if((sid = H5Screate(H5S_SCALAR)) < 0) - goto out; + if(H5Tset_size(tid,(size_t)size) < 0) + goto out; + if(H5Tset_strpad(tid, H5T_STR_NULLTERM) < 0) + goto out; -/*------------------------------------------------------------------------- - * create and write the attribute - *------------------------------------------------------------------------- - */ - if((aid = H5Acreate2(dset_id, name, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto out; + if((sid = H5Screate(H5S_SCALAR)) < 0) + goto out; - if(H5Awrite(aid, tid, buf) < 0) - goto out; - if(H5Aclose(aid) < 0) - goto out; + /*------------------------------------------------------------------------- + * create and write the attribute + *------------------------------------------------------------------------- + */ + if((aid = H5Acreate2(dset_id, name, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto out; - if(H5Sclose(sid) < 0) - goto out; + if(H5Awrite(aid, tid, buf) < 0) + goto out; - if(H5Tclose(tid) < 0) - goto out; + if(H5Aclose(aid) < 0) + goto out; - return SUCCEED; + if(H5Sclose(sid) < 0) + goto out; + + if(H5Tclose(tid) < 0) + goto out; + + return SUCCEED; - /* error zone, gracefully close */ + /* error zone */ out: - H5E_BEGIN_TRY { - H5Aclose(aid); - H5Tclose(tid); - H5Sclose(sid); - } H5E_END_TRY; - return FAIL; + H5E_BEGIN_TRY { + H5Aclose(aid); + H5Tclose(tid); + H5Sclose(sid); + } H5E_END_TRY; + return FAIL; } diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c index 30a8490..a035319 100644 --- a/hl/src/H5TB.c +++ b/hl/src/H5TB.c @@ -1,17 +1,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +* Copyright by The HDF Group. * +* Copyright by the Board of Trustees of the University of Illinois. * +* All rights reserved. * +* * +* This file is part of HDF5. The full HDF5 copyright notice, including * +* terms governing use, modification, and redistribution, is contained in * +* the files COPYING and Copyright.html. COPYING can be found at the root * +* of the source code distribution tree; Copyright.html can be found at the * +* root level of an installed copy of the electronic HDF5 document set and * +* is linked from the top-level documents page. It can also be found at * +* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * +* access to either file, you may request a copy from help@hdfgroup.org. * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdlib.h> #include <string.h> @@ -20,11 +20,11 @@ /*------------------------------------------------------------------------- - * - * internal functions - * - *------------------------------------------------------------------------- - */ +* +* internal functions +* +*------------------------------------------------------------------------- +*/ static int H5TB_find_field(const char *field, const char *field_list); @@ -43,47 +43,47 @@ static hid_t H5TB_create_type(hid_t loc_id, hid_t ftype_id); /*------------------------------------------------------------------------- - * - * Create functions - * - *------------------------------------------------------------------------- - */ +* +* Create functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5TBmake_table - * - * Purpose: Make a table - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * Quincey Koziol - * - * Date: January 17, 2001 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5TBmake_table +* +* Purpose: Make a table +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* Quincey Koziol +* +* Date: January 17, 2001 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5TBmake_table( const char *table_title, - hid_t loc_id, - const char *dset_name, - hsize_t nfields, - hsize_t nrecords, - size_t type_size, - const char *field_names[], - const size_t *field_offset, - const hid_t *field_types, - hsize_t chunk_size, - void *fill_data, - int compress, - const void *buf ) + hid_t loc_id, + const char *dset_name, + hsize_t nfields, + hsize_t nrecords, + size_t type_size, + const char *field_names[], + const size_t *field_offset, + const hid_t *field_types, + hsize_t chunk_size, + void *fill_data, + int compress, + const void *buf ) { - + hid_t did; hid_t sid; hid_t mem_type_id; @@ -97,37 +97,37 @@ herr_t H5TBmake_table( const char *table_title, char aux[255]; hsize_t i; unsigned char *tmp_buf; - + dims[0] = nrecords; dims_chunk[0] = chunk_size; - + /* create the memory data type. */ if ((mem_type_id = H5Tcreate (H5T_COMPOUND, type_size )) < 0) return -1; - + /* insert fields. */ for ( i = 0; i < nfields; i++) { if(H5Tinsert(mem_type_id, field_names[i], field_offset[i], field_types[i] ) < 0) return -1; } - + /* create a simple data space with unlimited size */ if ((sid = H5Screate_simple( 1, dims, maxdims )) < 0) return -1; - + /* modify dataset creation properties, i.e. enable chunking */ plist_id = H5Pcreate(H5P_DATASET_CREATE); if (H5Pset_chunk(plist_id, 1, dims_chunk) < 0) return -1; - + /* set the fill value using a struct as the data type. */ if (fill_data) { if(H5Pset_fill_value(plist_id, mem_type_id, fill_data) < 0) return -1; } - + /* dataset creation property list is modified to use GZIP compression with the compression effort set to 6. @@ -137,11 +137,11 @@ herr_t H5TBmake_table( const char *table_title, if(H5Pset_deflate(plist_id, 6) < 0) return -1; } - + /* create the dataset. */ if ((did = H5Dcreate2(loc_id, dset_name, mem_type_id, sid, H5P_DEFAULT, plist_id, H5P_DEFAULT)) < 0) goto out; - + /* only write if there is something to write */ if (buf) { @@ -149,108 +149,108 @@ herr_t H5TBmake_table( const char *table_title, if (H5Dwrite( did, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf ) < 0) goto out; } - + /* terminate access to the data space. */ if (H5Sclose(sid) < 0) goto out; - + /* end access to the dataset */ if (H5Dclose(did) < 0) goto out; - + /* end access to the property list */ if (H5Pclose(plist_id) < 0) goto out; - + /*------------------------------------------------------------------------- * set the conforming table attributes *------------------------------------------------------------------------- */ - + /* attach the CLASS attribute */ if (H5LTset_attribute_string( loc_id, dset_name, "CLASS", TABLE_CLASS ) < 0) goto out; - + /* attach the VERSION attribute */ if (H5LTset_attribute_string( loc_id, dset_name, "VERSION", TABLE_VERSION ) < 0) goto out; - + /* attach the TITLE attribute */ if (H5LTset_attribute_string( loc_id, dset_name, "TITLE", table_title ) < 0) goto out; - + /* attach the FIELD_ name attribute */ for ( i = 0; i < nfields; i++) { /* get the member name */ member_name = H5Tget_member_name( mem_type_id,(unsigned) i ); - + strcpy( attr_name, "FIELD_" ); sprintf( aux, "%d", (int)i ); strcat( attr_name, aux ); sprintf( aux, "%s", "_NAME" ); strcat( attr_name, aux ); - + /* attach the attribute */ if (H5LTset_attribute_string( loc_id, dset_name, attr_name, member_name ) < 0) goto out; - + free( member_name ); - + } - + /* attach the FIELD_ fill value attribute */ if (fill_data ) { - - tmp_buf = fill_data; - + + tmp_buf = (unsigned char *) fill_data; + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + if (( sid = H5Screate(H5S_SCALAR)) < 0) goto out; - + for ( i = 0; i < nfields; i++) { - + /* get the member name */ member_name = H5Tget_member_name(mem_type_id, (unsigned)i); - + strcpy(attr_name, "FIELD_"); sprintf(aux, "%d", (int)i); strcat(attr_name, aux); sprintf(aux, "%s", "_FILL"); strcat(attr_name, aux); - + if ((attr_id = H5Acreate2(did, attr_name, field_types[i], sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; - + if (H5Awrite(attr_id, field_types[i], tmp_buf+field_offset[i]) < 0) goto out; - + if (H5Aclose(attr_id) < 0) goto out; - + free(member_name); } - + /* terminate access to the data space. */ if (H5Sclose(sid) < 0) goto out; - + /* end access to the dataset */ if (H5Dclose(did) < 0) goto out; } - + /* release the datatype. */ if (H5Tclose( mem_type_id ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY { @@ -260,45 +260,45 @@ out: H5Tclose(mem_type_id); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * - * Write functions - * - *------------------------------------------------------------------------- - */ +* +* Write functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5TBappend_records - * - * Purpose: Appends records to a table - * - * Return: Success: 0, Failure: -1 - * - * Programmers: - * Pedro Vicente, pvn@ncsa.uiuc.edu - * Quincey Koziol - * - * Date: November 19, 2001 - * - * Comments: Uses memory offsets - * - * Modifications: April 1, 2004 - * the FIELD_SIZES parameter is used to define the memory type ID - * returned by H5TB_create_type - * - *------------------------------------------------------------------------- - */ +* Function: H5TBappend_records +* +* Purpose: Appends records to a table +* +* Return: Success: 0, Failure: -1 +* +* Programmers: +* Pedro Vicente, pvn@ncsa.uiuc.edu +* Quincey Koziol +* +* Date: November 19, 2001 +* +* Comments: Uses memory offsets +* +* Modifications: April 1, 2004 +* the FIELD_SIZES parameter is used to define the memory type ID +* returned by H5TB_create_type +* +*------------------------------------------------------------------------- +*/ herr_t H5TBappend_records( hid_t loc_id, - const char *dset_name, - hsize_t nrecords, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - const void *buf ) + const char *dset_name, + hsize_t nrecords, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + const void *buf ) { hid_t did; hid_t tid=-1; @@ -307,26 +307,26 @@ herr_t H5TBappend_records( hid_t loc_id, hid_t m_sid=-1; hsize_t nrecords_orig; hsize_t nfields; - + /* get the original number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords_orig ) < 0) return -1; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) goto out; - + /* get the datatypes */ if ((tid = H5Dget_type( did )) < 0) goto out; - + if ((mem_type_id=H5TB_create_type(loc_id,dset_name,type_size,field_offset,field_sizes,tid)) < 0) goto out; - + /* append the records */ if ((H5TB_common_append_records(did, mem_type_id, (size_t)nrecords, nrecords_orig, buf)) < 0) goto out; - + /* close */ if (H5Tclose( tid ) < 0) return -1; @@ -334,9 +334,9 @@ herr_t H5TBappend_records( hid_t loc_id, goto out; if (H5Dclose( did ) < 0) goto out; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -351,36 +351,36 @@ out: } /*------------------------------------------------------------------------- - * Function: H5TBwrite_records - * - * Purpose: Writes records - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 19, 2001 - * - * Comments: Uses memory offsets - * - * Modifications: April 1, 2004 - * the FIELD_SIZES parameter is used to define the memory type ID - * returned by H5TB_create_type - * - *------------------------------------------------------------------------- - */ +* Function: H5TBwrite_records +* +* Purpose: Writes records +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 19, 2001 +* +* Comments: Uses memory offsets +* +* Modifications: April 1, 2004 +* the FIELD_SIZES parameter is used to define the memory type ID +* returned by H5TB_create_type +* +*------------------------------------------------------------------------- +*/ herr_t H5TBwrite_records( hid_t loc_id, - const char *dset_name, - hsize_t start, - hsize_t nrecords, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - const void *buf ) + const char *dset_name, + hsize_t start, + hsize_t nrecords, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + const void *buf ) { - + hid_t did; hid_t tid; hsize_t count[1]; @@ -390,43 +390,43 @@ herr_t H5TBwrite_records( hid_t loc_id, hsize_t mem_size[1]; hsize_t dims[1]; hid_t mem_type_id=-1; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /* get the datatype */ if ((tid = H5Dget_type( did )) < 0) goto out; - + if ((mem_type_id=H5TB_create_type(loc_id,dset_name,type_size,field_offset,field_sizes,tid)) < 0) goto out; - + /* get the dataspace handle */ if ((sid = H5Dget_space( did )) < 0) goto out; - + /* get records */ if (H5Sget_simple_extent_dims( sid, dims, NULL) < 0) goto out; - + if (start + nrecords > dims[0] ) goto out; - + /* define a hyperslab in the dataset of the size of the records */ offset[0] = start; count[0] = nrecords; if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; - + if (H5Dwrite( did, mem_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 0) goto out; - + /* close */ if (H5Sclose( m_sid ) < 0) goto out; @@ -438,9 +438,9 @@ herr_t H5TBwrite_records( hid_t loc_id, return -1; if (H5Dclose( did ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -455,32 +455,32 @@ out: } /*------------------------------------------------------------------------- - * Function: H5TBwrite_fields_name - * - * Purpose: Writes fields - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 21, 2001 - * - * Comments: - * - * Modifications: April 1, 2004 - * the FIELD_SIZES parameter is used to define a memory type ID - * - *------------------------------------------------------------------------- - */ +* Function: H5TBwrite_fields_name +* +* Purpose: Writes fields +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 21, 2001 +* +* Comments: +* +* Modifications: April 1, 2004 +* the FIELD_SIZES parameter is used to define a memory type ID +* +*------------------------------------------------------------------------- +*/ herr_t H5TBwrite_fields_name( hid_t loc_id, - const char *dset_name, - const char *field_names, - hsize_t start, - hsize_t nrecords, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - const void *buf ) + const char *dset_name, + const char *field_names, + hsize_t start, + hsize_t nrecords, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + const void *buf ) { hid_t did; hid_t tid=-1; @@ -496,57 +496,57 @@ herr_t H5TBwrite_fields_name( hid_t loc_id, hssize_t i, j; hid_t preserve_id; size_t size_native; - + /* create xfer properties to preserve initialized data */ if ((preserve_id = H5Pcreate (H5P_DATASET_XFER)) < 0) return -1; if (H5Pset_preserve (preserve_id, 1) < 0) return -1; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) goto out; - + /* get the datatype */ if ((tid = H5Dget_type( did )) < 0) goto out; - + /* get the number of fields */ if (( nfields = H5Tget_nmembers( tid )) < 0) goto out; - + /* create a write id */ if (( write_type_id = H5Tcreate( H5T_COMPOUND, type_size )) < 0) goto out; - + j = 0; - + /* iterate tru the members */ for ( i = 0; i < nfields; i++) { /* get the member name */ member_name = H5Tget_member_name( tid, (unsigned)i ); - + if(H5TB_find_field( member_name, field_names ) > 0 ) { - + /* get the member type */ if(( member_type_id = H5Tget_member_type( tid,(unsigned) i )) < 0) goto out; - + /* convert to native type */ if ((nmtype_id=H5Tget_native_type(member_type_id,H5T_DIR_DEFAULT)) < 0) goto out; - + size_native=H5Tget_size(nmtype_id); - + /* adjust, if necessary */ if (field_sizes[j]!=size_native) { if (H5Tset_size(nmtype_id, field_sizes[j]) < 0) goto out; } - + /* the field in the file is found by its name */ if (field_offset ) { @@ -559,36 +559,36 @@ herr_t H5TBwrite_fields_name( hid_t loc_id, if (H5Tinsert( write_type_id, member_name, (size_t)0, nmtype_id ) < 0) goto out; } - + j++; - + /* close */ if(H5Tclose( member_type_id ) < 0) goto out; if(H5Tclose( nmtype_id ) < 0) goto out; } - + free( member_name ); - + } - + /* get the dataspace handle */ if ((file_space_id = H5Dget_space( did )) < 0) goto out; if ((m_sid = H5Screate_simple(1, &nrecords, NULL)) < 0) goto out; - + /* define a hyperslab in the dataset */ offset[0] = start; count[0] = nrecords; if (H5Sselect_hyperslab( file_space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* write */ if (H5Dwrite( did, write_type_id, m_sid, file_space_id, preserve_id, buf ) < 0) goto out; - + /* close */ if(H5Tclose( write_type_id ) ) goto out; @@ -602,9 +602,9 @@ herr_t H5TBwrite_fields_name( hid_t loc_id, return -1; if(H5Sclose( m_sid ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -617,41 +617,41 @@ out: H5Tclose(tid); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TBwrite_fields_index - * - * Purpose: Writes fields - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 21, 2001 - * - * Comments: Uses memory offsets - * - * Modifications: April 1, 2004 - * the FIELD_SIZES parameter is used to define a memory type ID - * - *------------------------------------------------------------------------- - */ +* Function: H5TBwrite_fields_index +* +* Purpose: Writes fields +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 21, 2001 +* +* Comments: Uses memory offsets +* +* Modifications: April 1, 2004 +* the FIELD_SIZES parameter is used to define a memory type ID +* +*------------------------------------------------------------------------- +*/ herr_t H5TBwrite_fields_index( hid_t loc_id, - const char *dset_name, - hsize_t nfields, - const int *field_index, - hsize_t start, - hsize_t nrecords, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - const void *buf ) + const char *dset_name, + hsize_t nfields, + const int *field_index, + hsize_t start, + hsize_t nrecords, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + const void *buf ) { hid_t did; hid_t tid=-1; @@ -666,50 +666,50 @@ herr_t H5TBwrite_fields_index( hid_t loc_id, hsize_t i, j; hid_t preserve_id; size_t size_native; - + /* create xfer properties to preserve initialized data */ if ((preserve_id = H5Pcreate (H5P_DATASET_XFER)) < 0) return -1; if (H5Pset_preserve (preserve_id, 1) < 0) return -1; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) goto out; - + /* get the datatype */ if ((tid = H5Dget_type( did )) < 0) goto out; - + /* create a write id */ if (( write_type_id = H5Tcreate( H5T_COMPOUND, type_size )) < 0) goto out; - + /* iterate tru the members */ for ( i = 0; i < nfields; i++) { - + j = field_index[i]; - + /* get the member name */ member_name = H5Tget_member_name( tid, (unsigned) j ); - + /* get the member type */ if (( member_type_id = H5Tget_member_type( tid, (unsigned) j )) < 0) goto out; - + /* convert to native type */ if ((nmtype_id = H5Tget_native_type(member_type_id,H5T_DIR_DEFAULT)) < 0) goto out; - + size_native = H5Tget_size(nmtype_id); - + if (field_sizes[i]!=size_native) { if (H5Tset_size(nmtype_id, field_sizes[i]) < 0) goto out; } - + /* the field in the file is found by its name */ if ( field_offset ) { @@ -727,27 +727,27 @@ herr_t H5TBwrite_fields_index( hid_t loc_id, goto out; if(H5Tclose( nmtype_id ) < 0) goto out; - + free( member_name ); - + } - + /* get the dataspace handles */ if ((file_space_id = H5Dget_space( did )) < 0) goto out; if ((m_sid = H5Screate_simple(1, &nrecords, NULL)) < 0) goto out; - + /* define a hyperslab in the dataset */ offset[0] = start; count[0] = nrecords; if (H5Sselect_hyperslab( file_space_id, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* write */ if (H5Dwrite( did, write_type_id, m_sid, file_space_id, preserve_id, buf ) < 0) goto out; - + /* close */ if (H5Tclose( write_type_id ) ) goto out; @@ -761,9 +761,9 @@ herr_t H5TBwrite_fields_index( hid_t loc_id, return -1; if (H5Sclose( m_sid ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -780,68 +780,68 @@ out: /*------------------------------------------------------------------------- - * - * Read functions - * - *------------------------------------------------------------------------- - */ +* +* Read functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5TBread_table - * - * Purpose: Reads a table - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 20, 2001 - * - * Comments: - * - * Modifications: April 1, 2004 - * used a memory type ID returned by H5TB_create_type - * - *------------------------------------------------------------------------- - */ +* Function: H5TBread_table +* +* Purpose: Reads a table +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 20, 2001 +* +* Comments: +* +* Modifications: April 1, 2004 +* used a memory type ID returned by H5TB_create_type +* +*------------------------------------------------------------------------- +*/ herr_t H5TBread_table( hid_t loc_id, - const char *dset_name, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - void *dst_buf ) + const char *dset_name, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + void *dst_buf ) { hid_t did; hid_t ftype_id=-1; hid_t mem_type_id=-1; hid_t sid; hsize_t dims[1]; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /* get the dataspace handle */ if ((sid = H5Dget_space( did )) < 0) goto out; - + /* get dimensions */ if (H5Sget_simple_extent_dims( sid, dims, NULL) < 0) goto out; - + /* get the datatypes */ if ((ftype_id=H5Dget_type (did)) < 0) goto out; - + if ((mem_type_id=H5TB_create_type(loc_id,dset_name,type_size,field_offset,field_sizes,ftype_id)) < 0) goto out; - + /* read */ if (H5Dread( did, mem_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, dst_buf) < 0) goto out; - + /* close */ if (H5Tclose( ftype_id ) < 0) goto out; @@ -851,9 +851,9 @@ herr_t H5TBread_table( hid_t loc_id, goto out; if (H5Dclose( did ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -867,36 +867,36 @@ out: } /*------------------------------------------------------------------------- - * Function: H5TBread_records - * - * Purpose: Reads records - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 19, 2001 - * - * Comments: - * - * Modifications: April 1, 2004 - * the FIELD_SIZES parameter is used to define the memory type ID - * returned by H5TB_create_type - * - *------------------------------------------------------------------------- - */ +* Function: H5TBread_records +* +* Purpose: Reads records +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 19, 2001 +* +* Comments: +* +* Modifications: April 1, 2004 +* the FIELD_SIZES parameter is used to define the memory type ID +* returned by H5TB_create_type +* +*------------------------------------------------------------------------- +*/ herr_t H5TBread_records( hid_t loc_id, - const char *dset_name, - hsize_t start, - hsize_t nrecords, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - void *buf ) + const char *dset_name, + hsize_t start, + hsize_t nrecords, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + void *buf ) { - + hid_t did; hid_t ftype_id; hid_t mem_type_id=-1; @@ -904,22 +904,22 @@ herr_t H5TBread_records( hid_t loc_id, hid_t m_sid=-1; hsize_t nrecords_orig; hsize_t nfields; - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords_orig ) < 0) return -1; - + /* open the dataset */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /* get the datatypes */ if ((ftype_id = H5Dget_type( did )) < 0) goto out; - + if ((mem_type_id=H5TB_create_type(loc_id,dset_name,type_size,field_offset,field_sizes,ftype_id)) < 0) goto out; - + /* read the records */ if ((H5TB_common_read_records(did, mem_type_id, start, (size_t)nrecords, nrecords_orig, buf)) < 0) goto out; @@ -931,9 +931,9 @@ herr_t H5TBread_records( hid_t loc_id, return -1; if (H5Dclose( did ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY { @@ -944,40 +944,40 @@ out: H5Sclose(sid); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TBread_fields_name - * - * Purpose: Reads fields - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 19, 2001 - * - * Comments: - * - * Modifications: April 1, 2004 - * the FIELD_SIZES parameter is used to define the memory type ID - * returned by H5TB_create_type - * - *------------------------------------------------------------------------- - */ +* Function: H5TBread_fields_name +* +* Purpose: Reads fields +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 19, 2001 +* +* Comments: +* +* Modifications: April 1, 2004 +* the FIELD_SIZES parameter is used to define the memory type ID +* returned by H5TB_create_type +* +*------------------------------------------------------------------------- +*/ herr_t H5TBread_fields_name( hid_t loc_id, - const char *dset_name, - const char *field_names, - hsize_t start, - hsize_t nrecords, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - void *buf ) + const char *dset_name, + const char *field_names, + hsize_t start, + hsize_t nrecords, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + void *buf ) { hid_t did; @@ -994,41 +994,41 @@ herr_t H5TBread_fields_name( hid_t loc_id, hsize_t mem_size[1]; size_t size_native; hssize_t i, j; - + /* open the dataset */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) goto out; - + /* get the datatype */ if ((ftype_id = H5Dget_type( did )) < 0) goto out; - + /* get the number of fields */ if (( nfields = H5Tget_nmembers( ftype_id )) < 0) goto out; - + /* create a memory read id */ if (( mem_type_id = H5Tcreate( H5T_COMPOUND, type_size )) < 0) goto out; - + /* iterate tru the members */ for ( i=0,j=0; i<nfields; i++) { /* get the member name */ member_name = H5Tget_member_name( ftype_id, (unsigned)i ); - + if(H5TB_find_field( member_name, field_names ) > 0 ) { /* get the member type */ if (( mtype_id = H5Tget_member_type( ftype_id, (unsigned) i )) < 0) goto out; - + /* convert to native type */ if ((nmtype_id=H5Tget_native_type(mtype_id,H5T_DIR_DEFAULT)) < 0) goto out; - + size_native=H5Tget_size(nmtype_id); - + if (field_sizes[j]!=size_native) { if (H5Tset_size(nmtype_id, field_sizes[j]) < 0) @@ -1045,7 +1045,7 @@ herr_t H5TBread_fields_name( hid_t loc_id, if(H5Tinsert( mem_type_id, member_name, (size_t)0, nmtype_id ) < 0) goto out; } - + /* close */ if(H5Tclose( mtype_id ) < 0) goto out; @@ -1055,26 +1055,26 @@ herr_t H5TBread_fields_name( hid_t loc_id, } free( member_name ); } - + /* get the dataspace handle */ if ((sid = H5Dget_space( did )) < 0) goto out; - + /* define a hyperslab in the dataset */ offset[0] = start; count[0] = nrecords; if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; - + /* read */ if (H5Dread( did, mem_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 0) goto out; - + /* close */ if (H5Tclose( mem_type_id ) ) goto out; @@ -1086,9 +1086,9 @@ herr_t H5TBread_fields_name( hid_t loc_id, goto out; if (H5Dclose( did ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -1100,43 +1100,43 @@ out: H5Sclose(sid); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TBread_fields_index - * - * Purpose: Reads fields - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 19, 2001 - * - * Comments: - * - * Modifications: April 1, 2004 - * the FIELD_SIZES parameter is used to define the memory type ID - * returned by H5TB_create_type - * - *------------------------------------------------------------------------- - */ +* Function: H5TBread_fields_index +* +* Purpose: Reads fields +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 19, 2001 +* +* Comments: +* +* Modifications: April 1, 2004 +* the FIELD_SIZES parameter is used to define the memory type ID +* returned by H5TB_create_type +* +*------------------------------------------------------------------------- +*/ herr_t H5TBread_fields_index( hid_t loc_id, - const char *dset_name, - hsize_t nfields, - const int *field_index, - hsize_t start, - hsize_t nrecords, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - void *buf ) + const char *dset_name, + hsize_t nfields, + const int *field_index, + hsize_t start, + hsize_t nrecords, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + void *buf ) { - + hid_t did; hid_t tid=-1; hid_t read_type_id=-1; @@ -1150,47 +1150,47 @@ herr_t H5TBread_fields_index( hid_t loc_id, hsize_t mem_size[1]; size_t size_native; hsize_t i, j; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) goto out; - + /* get the datatype */ if ((tid = H5Dget_type( did )) < 0) goto out; - + /* create a read id */ if (( read_type_id = H5Tcreate( H5T_COMPOUND, type_size )) < 0) goto out; - + /* iterate tru the members */ for ( i = 0; i < nfields; i++) { j = field_index[i]; - + /* get the member name */ member_name = H5Tget_member_name( tid, (unsigned) j ); - + /* get the member type */ if (( member_type_id = H5Tget_member_type( tid, (unsigned) j )) < 0) goto out; - + /* get the member size */ if (H5Tget_size( member_type_id ) == 0 ) goto out; - + /* convert to native type */ if ((nmtype_id=H5Tget_native_type(member_type_id,H5T_DIR_DEFAULT)) < 0) goto out; - + size_native=H5Tget_size(nmtype_id); - + if (field_sizes[i]!=size_native) { if (H5Tset_size(nmtype_id, field_sizes[i]) < 0) goto out; } - + /* the field in the file is found by its name */ if (field_offset ) { @@ -1202,35 +1202,35 @@ herr_t H5TBread_fields_index( hid_t loc_id, if(H5Tinsert( read_type_id, member_name, (size_t)0, nmtype_id ) < 0) goto out; } - + /* close the member type */ if (H5Tclose( member_type_id ) < 0) goto out; if (H5Tclose( nmtype_id ) < 0) goto out; - + free( member_name ); } - + /* get the dataspace handle */ if ((sid = H5Dget_space( did )) < 0) goto out; - + /* define a hyperslab in the dataset */ offset[0] = start; count[0] = nrecords; if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; - + /* read */ if (H5Dread( did, read_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 0) goto out; - + /* close */ if (H5Sclose( sid ) < 0) goto out; @@ -1242,9 +1242,9 @@ herr_t H5TBread_fields_index( hid_t loc_id, return -1; if (H5Dclose( did ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -1256,40 +1256,40 @@ out: H5Sclose(sid); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * - * Manipulation functions - * - *------------------------------------------------------------------------- - */ +* +* Manipulation functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5TBdelete_record - * - * Purpose: Delete records from middle of table ("pulling up" all the records after it) - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 26, 2001 - * - * Modifications: April 29, 2003 - * - * - *------------------------------------------------------------------------- - */ +* Function: H5TBdelete_record +* +* Purpose: Delete records from middle of table ("pulling up" all the records after it) +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 26, 2001 +* +* Modifications: April 29, 2003 +* +* +*------------------------------------------------------------------------- +*/ herr_t H5TBdelete_record( hid_t loc_id, - const char *dset_name, - hsize_t start, - hsize_t nrecords ) + const char *dset_name, + hsize_t start, + hsize_t nrecords ) { - + hsize_t nfields; hsize_t ntotal_records; hsize_t read_start; @@ -1306,24 +1306,24 @@ herr_t H5TBdelete_record( hid_t loc_id, size_t *src_offset; size_t *src_sizes; hsize_t dims[1]; - + /*------------------------------------------------------------------------- * first we get information about type size and offsets on disk *------------------------------------------------------------------------- */ - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &ntotal_records ) < 0) return -1; - + src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t)); src_sizes = (size_t *)malloc((size_t)nfields * sizeof(size_t)); - + if (src_offset == NULL ) return -1; if (src_sizes == NULL ) return -1; - + /* get field info */ if (H5TBget_field_info( loc_id, dset_name, NULL, src_sizes, src_offset, &src_size ) < 0) return -1; @@ -1331,53 +1331,53 @@ herr_t H5TBdelete_record( hid_t loc_id, /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /*------------------------------------------------------------------------- * read the records after the deleted one(s) *------------------------------------------------------------------------- */ - + read_start = start + nrecords; read_nrecords = ntotal_records - read_start; if ( read_nrecords ) { tmp_buf = (unsigned char *)calloc((size_t) read_nrecords, src_size ); - + if (tmp_buf == NULL ) return -1; - + /* read the records after the deleted one(s) */ if (H5TBread_records( loc_id, dset_name, read_start, read_nrecords, src_size, src_offset, src_sizes, tmp_buf ) < 0) return -1; - + /*------------------------------------------------------------------------- * write the records in another position *------------------------------------------------------------------------- */ - + /* get the datatype */ if ((tid = H5Dget_type( did )) < 0) goto out; - + /* get the dataspace handle */ if ((sid = H5Dget_space( did )) < 0) goto out; - + /* define a hyperslab in the dataset of the size of the records */ offset[0] = start; count[0] = read_nrecords; if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; - + if (H5Dwrite( did, tid, m_sid, sid, H5P_DEFAULT, tmp_buf ) < 0) goto out; - + /* close */ if (H5Sclose( m_sid ) < 0) goto out; @@ -1385,10 +1385,10 @@ herr_t H5TBdelete_record( hid_t loc_id, goto out; if (H5Tclose( tid ) < 0) goto out; - + } /* read_nrecords */ - - + + /*------------------------------------------------------------------------- * change the dataset dimension *------------------------------------------------------------------------- @@ -1396,20 +1396,20 @@ herr_t H5TBdelete_record( hid_t loc_id, dims[0] = ntotal_records - nrecords; if (H5Dset_extent( did, dims ) < 0) goto out; - + /* close dataset */ if (H5Dclose( did ) < 0) return -1; - + if (tmp_buf !=NULL) free( tmp_buf ); free( src_offset ); free( src_sizes ); - - + + return 0; - /* error zone */ + /* error zone */ out: if (tmp_buf !=NULL ) @@ -1421,41 +1421,41 @@ out: H5Sclose(sid); } H5E_END_TRY; return -1; - - + + } /*------------------------------------------------------------------------- - * Function: H5TBinsert_record - * - * Purpose: Inserts records into middle of table ("pushing down" all the records after it) - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 26, 2001 - * - * Comments: Uses memory offsets - * - * Modifications: April 1, 2004 - * the FIELD_SIZES parameter is used to define the memory type ID - * returned by H5TB_create_type - * - *------------------------------------------------------------------------- - */ +* Function: H5TBinsert_record +* +* Purpose: Inserts records into middle of table ("pushing down" all the records after it) +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 26, 2001 +* +* Comments: Uses memory offsets +* +* Modifications: April 1, 2004 +* the FIELD_SIZES parameter is used to define the memory type ID +* returned by H5TB_create_type +* +*------------------------------------------------------------------------- +*/ herr_t H5TBinsert_record( hid_t loc_id, - const char *dset_name, - hsize_t start, - hsize_t nrecords, - size_t type_size, - const size_t *field_offset, - const size_t *field_sizes, - void *buf ) + const char *dset_name, + hsize_t start, + hsize_t nrecords, + size_t type_size, + const size_t *field_offset, + const size_t *field_sizes, + void *buf ) { - + hsize_t nfields; hsize_t ntotal_records; hsize_t read_nrecords; @@ -1469,93 +1469,93 @@ herr_t H5TBinsert_record( hid_t loc_id, hsize_t dims[1]; hsize_t mem_dims[1]; unsigned char *tmp_buf; - + /*------------------------------------------------------------------------- * read the records after the inserted one(s) *------------------------------------------------------------------------- */ - + /* get the dimensions */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &ntotal_records ) < 0) return -1; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) goto out; - + /* get the datatype */ if ((tid = H5Dget_type( did )) < 0) goto out; - + /* create the memory data type. */ if ((mem_type_id=H5TB_create_type(loc_id,dset_name,type_size,field_offset,field_sizes,tid)) < 0) goto out; - + read_nrecords = ntotal_records - start; tmp_buf = (unsigned char *)calloc((size_t) read_nrecords, type_size); - + /* read the records after the inserted one(s) */ if (H5TBread_records( loc_id, dset_name, start, read_nrecords, type_size, field_offset, field_sizes, tmp_buf ) < 0) return -1; - + /* extend the dataset */ dims[0] = ntotal_records + nrecords; - + if (H5Dset_extent(did, dims) < 0) goto out; - + /*------------------------------------------------------------------------- * write the inserted records *------------------------------------------------------------------------- */ - + /* create a simple memory data space */ mem_dims[0] = nrecords; if ((m_sid = H5Screate_simple(1, mem_dims, NULL)) < 0) return -1; - + /* get the file data space */ if ((sid = H5Dget_space( did )) < 0) return -1; - + /* define a hyperslab in the dataset to write the new data */ offset[0] = start; count[0] = nrecords; if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + if (H5Dwrite( did, mem_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 0) goto out; - + /* terminate access to the dataspace */ if (H5Sclose( m_sid ) < 0) goto out; if (H5Sclose( sid ) < 0) goto out; - + /*------------------------------------------------------------------------- * write the "pushed down" records *------------------------------------------------------------------------- */ - + /* create a simple memory data space */ mem_dims[0]=read_nrecords; if ((m_sid = H5Screate_simple( 1, mem_dims, NULL )) < 0) return -1; - + /* get the file data space */ if ((sid = H5Dget_space( did )) < 0) return -1; - + /* define a hyperslab in the dataset to write the new data */ offset[0] = start + nrecords; count[0] = read_nrecords; if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + if (H5Dwrite( did, mem_type_id, m_sid, sid, H5P_DEFAULT, tmp_buf ) < 0) goto out; - + /* close */ if (H5Sclose( m_sid ) < 0) goto out; @@ -1567,11 +1567,11 @@ herr_t H5TBinsert_record( hid_t loc_id, return -1; if (H5Dclose( did ) < 0) return -1; - + free( tmp_buf ); - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -1586,30 +1586,30 @@ out: } /*------------------------------------------------------------------------- - * Function: H5TBadd_records_from - * - * Purpose: Add records from first table to second table - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: December 5, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5TBadd_records_from +* +* Purpose: Add records from first table to second table +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: December 5, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5TBadd_records_from( hid_t loc_id, - const char *dset_name1, - hsize_t start1, - hsize_t nrecords, - const char *dset_name2, - hsize_t start2 ) + const char *dset_name1, + hsize_t start1, + hsize_t nrecords, + const char *dset_name2, + hsize_t start2 ) { hid_t did_1; hid_t tid_1; @@ -1625,75 +1625,75 @@ herr_t H5TBadd_records_from( hid_t loc_id, size_t src_size; size_t *src_offset; size_t *src_sizes; - + /*------------------------------------------------------------------------- * first we get information about type size and offsets on disk *------------------------------------------------------------------------- */ - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name1, &nfields, &ntotal_records ) < 0) return -1; - + src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t)); src_sizes = (size_t *)malloc((size_t)nfields * sizeof(size_t)); - + if (src_offset == NULL ) return -1; - + /* get field info */ if (H5TBget_field_info( loc_id, dset_name1, NULL, src_sizes, src_offset, &src_size ) < 0) return -1; - + /*------------------------------------------------------------------------- * Get information about the first table and read it *------------------------------------------------------------------------- */ - + /* open the 1st dataset. */ if ((did_1 = H5Dopen2(loc_id, dset_name1, H5P_DEFAULT)) < 0) return -1; - + /* get the datatype */ if ((tid_1 = H5Dget_type( did_1 )) < 0) goto out; - + /* get the dataspace handle */ if ((sid_1 = H5Dget_space( did_1 )) < 0) goto out; - + /* get the size of the datatype */ if (( type_size1 = H5Tget_size( tid_1 )) == 0 ) goto out; - + tmp_buf = (unsigned char *)calloc((size_t)nrecords, type_size1 ); - + /* define a hyperslab in the dataset of the size of the records */ offset[0] = start1; count[0] = nrecords; if (H5Sselect_hyperslab( sid_1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((msid_1 = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; - + if (H5Dread( did_1, tid_1, msid_1, sid_1, H5P_DEFAULT, tmp_buf ) < 0) goto out; - + /*------------------------------------------------------------------------- * add to the second table *------------------------------------------------------------------------- */ if (H5TBinsert_record(loc_id,dset_name2,start2,nrecords,src_size,src_offset,src_sizes,tmp_buf ) < 0) goto out; - + /*------------------------------------------------------------------------- * close resources for table 1 *------------------------------------------------------------------------- */ - + if (H5Sclose( msid_1 ) < 0) goto out; if (H5Sclose( sid_1 ) < 0) @@ -1702,13 +1702,13 @@ herr_t H5TBadd_records_from( hid_t loc_id, return -1; if (H5Dclose( did_1 ) < 0) return -1; - + free( tmp_buf ); free( src_offset ); free( src_sizes ); - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -1719,34 +1719,34 @@ out: H5Tclose(tid_1); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TBcombine_tables - * - * Purpose: Combine records from two tables into a third - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: December 10, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5TBcombine_tables +* +* Purpose: Combine records from two tables into a third +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: December 10, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5TBcombine_tables( hid_t loc_id1, - const char *dset_name1, - hid_t loc_id2, - const char *dset_name2, - const char *dset_name3 ) + const char *dset_name1, + hid_t loc_id2, + const char *dset_name2, + const char *dset_name3 ) { - + /* identifiers for the 1st dataset. */ hid_t did_1=-1; hid_t tid_1=-1; @@ -1784,178 +1784,178 @@ herr_t H5TBcombine_tables( hid_t loc_id1, size_t *src_offset; size_t *src_sizes; int has_fill=0; - + /*------------------------------------------------------------------------- * first we get information about type size and offsets on disk *------------------------------------------------------------------------- */ - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id1, dset_name1, &nfields, &nrecords ) < 0) return -1; - + src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t)); src_sizes = (size_t *)malloc((size_t)nfields * sizeof(size_t)); - + if (src_offset == NULL ) return -1; - + /* get field info */ if (H5TBget_field_info( loc_id1, dset_name1, NULL, src_sizes, src_offset, &src_size ) < 0) return -1; - + /*------------------------------------------------------------------------- * get information about the first table *------------------------------------------------------------------------- */ - + /* open the 1st dataset. */ if ((did_1 = H5Dopen2(loc_id1, dset_name1, H5P_DEFAULT)) < 0) goto out; - + /* get the datatype */ if ((tid_1 = H5Dget_type( did_1 )) < 0) goto out; - + /* get the dataspace handle */ if ((sid_1 = H5Dget_space( did_1 )) < 0) goto out; - + /* get creation properties list */ if ((pid_1 = H5Dget_create_plist( did_1 )) < 0) goto out; - + /* get the dimensions */ if (H5TBget_table_info ( loc_id1, dset_name1, &nfields, &nrecords ) < 0) return -1; - + /*------------------------------------------------------------------------- * make the merged table with no data originally *------------------------------------------------------------------------- */ - + /* clone the property list */ if ((pid_3 = H5Pcopy(pid_1)) < 0) goto out; - + /* clone the type id */ if ((tid_3 = H5Tcopy(tid_1)) < 0) goto out; - + /*------------------------------------------------------------------------- * here we do not clone the file space from the 1st dataset, because we want to create * an empty table. Instead we create a new dataspace with zero records and expandable. *------------------------------------------------------------------------- */ dims[0] = 0; - + /* create a simple data space with unlimited size */ if ((sid_3 = H5Screate_simple(1, dims, maxdims)) < 0) return -1; - + /* create the dataset */ if ((did_3 = H5Dcreate2(loc_id1, dset_name3, tid_3, sid_3, H5P_DEFAULT, pid_3, H5P_DEFAULT)) < 0) goto out; - + /*------------------------------------------------------------------------- * attach the conforming table attributes *------------------------------------------------------------------------- */ if (H5TB_attach_attributes("Merge table", loc_id1, dset_name3, nfields, tid_3) < 0) goto out; - + /*------------------------------------------------------------------------- * get attributes *------------------------------------------------------------------------- */ - + type_size = H5Tget_size(tid_3); - + /* alloc fill value attribute buffer */ tmp_fill_buf = (unsigned char *)malloc(type_size); - + /* get the fill value attributes */ has_fill = H5TBAget_fill(loc_id1, dset_name1, did_1, tmp_fill_buf); - + /*------------------------------------------------------------------------- * attach the fill attributes from previous table *------------------------------------------------------------------------- */ if (has_fill == 1 ) { - + if (( sid = H5Screate(H5S_SCALAR)) < 0) goto out; - + for ( i = 0; i < nfields; i++) { - + /* get the member type */ if (( member_type_id = H5Tget_member_type( tid_3, (unsigned) i )) < 0) goto out; - + /* get the member offset */ member_offset = H5Tget_member_offset(tid_3, (unsigned)i); - + strcpy(attr_name, "FIELD_"); sprintf(aux, "%d", (int)i); strcat(attr_name, aux); sprintf(aux, "%s", "_FILL"); strcat(attr_name, aux); - + if ((attr_id = H5Acreate2(did_3, attr_name, member_type_id, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; - + if (H5Awrite(attr_id, member_type_id, tmp_fill_buf+member_offset) < 0) goto out; - + if (H5Aclose(attr_id) < 0) goto out; - + if (H5Tclose(member_type_id) < 0) goto out; } - + /* close data space. */ if (H5Sclose( sid ) < 0) goto out; } - + /*------------------------------------------------------------------------- * read data from 1st table *------------------------------------------------------------------------- */ - + tmp_buf = (unsigned char *)calloc((size_t) nrecords, type_size ); - + /* define a hyperslab in the dataset of the size of the records */ offset[0] = 0; count[0] = nrecords; if (H5Sselect_hyperslab( sid_1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; - + if (H5Dread( did_1, tid_1, m_sid, sid_1, H5P_DEFAULT, tmp_buf ) < 0) goto out; - + /*------------------------------------------------------------------------- * save data from 1st table into new table *------------------------------------------------------------------------- */ - + /* append the records to the new table */ if (H5TBappend_records( loc_id1, dset_name3, nrecords, src_size, src_offset, src_sizes, tmp_buf ) < 0) goto out; - + /*------------------------------------------------------------------------- * release resources from 1st table *------------------------------------------------------------------------- */ - + if (H5Sclose( m_sid ) < 0) goto out; if(H5Sclose( sid_1 ) < 0) @@ -1966,70 +1966,70 @@ herr_t H5TBcombine_tables( hid_t loc_id1, goto out; if(H5Dclose( did_1 ) < 0) goto out; - + /* Release resources. */ free( tmp_buf ); - + /*------------------------------------------------------------------------- * get information about the 2nd table *------------------------------------------------------------------------- */ - + /* open the dataset. */ if ((did_2 = H5Dopen2(loc_id2, dset_name2, H5P_DEFAULT)) < 0) goto out; - + /* get the datatype */ if ((tid_2 = H5Dget_type( did_2 )) < 0) goto out; - + /* get the dataspace handle */ if ((sid_2 = H5Dget_space( did_2 )) < 0) goto out; - + /* get the property list handle */ if ((pid_2 = H5Dget_create_plist( did_2 )) < 0) goto out; - + /* get the dimensions */ if (H5TBget_table_info ( loc_id2, dset_name2, &nfields, &nrecords ) < 0) return -1; - + /*------------------------------------------------------------------------- * read data from 2nd table *------------------------------------------------------------------------- */ - + tmp_buf = (unsigned char *)calloc((size_t) nrecords, type_size ); - + /* define a hyperslab in the dataset of the size of the records */ offset[0] = 0; count[0] = nrecords; if (H5Sselect_hyperslab( sid_2, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; - + if (H5Dread( did_2, tid_2, m_sid, sid_2, H5P_DEFAULT, tmp_buf ) < 0) goto out; - + /*------------------------------------------------------------------------- * save data from 2nd table into new table *------------------------------------------------------------------------- */ - + /* append the records to the new table */ if (H5TBappend_records( loc_id1, dset_name3, nrecords, src_size, src_offset, src_sizes, tmp_buf ) < 0) goto out; - + /*------------------------------------------------------------------------- * release resources from 2nd table *------------------------------------------------------------------------- */ - + if (H5Sclose( m_sid ) < 0) goto out; if (H5Sclose( sid_2 ) < 0) @@ -2040,12 +2040,12 @@ herr_t H5TBcombine_tables( hid_t loc_id1, goto out; if (H5Dclose( did_2 ) < 0) return -1; - + /*------------------------------------------------------------------------- * release resources from 3rd table *------------------------------------------------------------------------- */ - + if (H5Sclose( sid_3 ) < 0) return -1; if (H5Tclose( tid_3 ) < 0) @@ -2054,16 +2054,16 @@ herr_t H5TBcombine_tables( hid_t loc_id1, return -1; if (H5Dclose( did_3 ) < 0) return -1; - + /* Release resources. */ free( tmp_buf ); free( tmp_fill_buf ); free( src_offset ); free( src_sizes ); - + return 0; - - /* error zone */ + + /* error zone */ out: H5E_BEGIN_TRY { @@ -2081,34 +2081,34 @@ out: H5Pclose(pid_3); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TBinsert_field - * - * Purpose: Inserts a field - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: January 30, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5TBinsert_field +* +* Purpose: Inserts a field +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: January 30, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5TBinsert_field( hid_t loc_id, - const char *dset_name, - const char *field_name, - hid_t field_type, - hsize_t position, - const void *fill_data, - const void *buf ) + const char *dset_name, + const char *field_name, + hid_t field_type, + hsize_t position, + const void *fill_data, + const void *buf ) { /* identifiers for the 1st, original dataset */ hid_t did_1; @@ -2148,214 +2148,214 @@ herr_t H5TBinsert_field( hid_t loc_id, unsigned char *tmp_buf; unsigned char *tmp_fill_buf; hsize_t i; - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0) return -1; - + /*------------------------------------------------------------------------- * get information about the old data type *------------------------------------------------------------------------- */ - + /* open the dataset. */ if ((did_1 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /* get creation properties list */ if ((pid_1 = H5Dget_create_plist( did_1 )) < 0) goto out; - + /* get the datatype */ if ((tid_1 = H5Dget_type( did_1 )) < 0) goto out; - + /* get the size of the datatype */ if (( total_size = H5Tget_size( tid_1 )) == 0 ) goto out; - + /* get the dataspace handle */ if ((sid_1 = H5Dget_space( did_1 )) < 0) goto out; - + /* get dimension */ if (H5Sget_simple_extent_dims( sid_1, dims, NULL) < 0) goto out; - + /*------------------------------------------------------------------------- * get attributes *------------------------------------------------------------------------- */ - + /* get the table title */ if ((H5TBAget_title( did_1, table_title )) < 0) goto out; - + /* alloc fill value attribute buffer */ tmp_fill_buf = (unsigned char *)malloc(total_size ); - + /* get the fill value attributes */ if ((H5TBAget_fill( loc_id, dset_name, did_1, tmp_fill_buf )) < 0) goto out; - + /*------------------------------------------------------------------------- * create a new data type *------------------------------------------------------------------------- */ - + /* get the new member size */ member_size = H5Tget_size( field_type ); - + /* create the data type. */ if (( tid_2 = H5Tcreate (H5T_COMPOUND,(size_t)(total_size + member_size) )) < 0) goto out; - + curr_offset = 0; inserted = 0; - + /* insert the old fields, counting with the new one */ for ( i = 0; i < nfields + 1; i++) { idx = i; if (inserted ) idx = i - 1; - + if (i == position ) { /* get the new member size */ new_member_size = H5Tget_size( field_type ); - + /* insert the new field type */ if (H5Tinsert( tid_2, field_name, curr_offset, field_type ) < 0) goto out; - + curr_offset += new_member_size; - + inserted = 1; - + continue; } - + /* get the member name */ member_name = H5Tget_member_name( tid_1, (unsigned)idx ); - + /* get the member type */ if (( member_type_id = H5Tget_member_type( tid_1,(unsigned)idx )) < 0) goto out; - + /* get the member size */ member_size = H5Tget_size( member_type_id ); - + /* insert it into the new type */ if (H5Tinsert( tid_2, member_name, curr_offset, member_type_id ) < 0) goto out; - + curr_offset += member_size; - + free( member_name ); - + /* close the member type */ if(H5Tclose( member_type_id ) < 0) goto out; } /* i */ - + /*------------------------------------------------------------------------- * create a new temporary dataset *------------------------------------------------------------------------- */ - + /* retrieve the size of chunk */ if (H5Pget_chunk(pid_1, 1, dims_chunk) < 0) goto out; - + /* create a new simple data space with unlimited size, using the dimension */ if ((sid_2 = H5Screate_simple( 1, dims, maxdims)) < 0) return -1; - + /* modify dataset creation properties, i.e. enable chunking */ pid_2 = H5Pcreate(H5P_DATASET_CREATE); if (H5Pset_chunk(pid_2, 1, dims_chunk) < 0) return -1; - + /* create the dataset. */ if ((did_2 = H5Dcreate2(loc_id, "new", tid_2, sid_2, H5P_DEFAULT, pid_2, H5P_DEFAULT)) < 0) goto out; - + /*------------------------------------------------------------------------- * read data from 1st table *------------------------------------------------------------------------- */ - + tmp_buf = (unsigned char *)calloc((size_t)nrecords, (size_t)total_size); - + /* define a hyperslab in the dataset of the size of the records */ offset[0] = 0; count[0] = nrecords; if (H5Sselect_hyperslab(sid_1, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((msid_1 = H5Screate_simple(1, mem_size, NULL)) < 0) goto out; - + if (H5Dread(did_1, tid_1, msid_1, H5S_ALL, H5P_DEFAULT, tmp_buf) < 0) goto out; - + /*------------------------------------------------------------------------- * save data from 1st table into new table, using the 1st type id *------------------------------------------------------------------------- */ - + /* write */ if (H5Dwrite( did_2, tid_1, msid_1, H5S_ALL, H5P_DEFAULT, tmp_buf ) < 0) goto out; - + /*------------------------------------------------------------------------- * save the function supplied data of the new field *------------------------------------------------------------------------- */ - + /* create a write id */ if (( write_type_id = H5Tcreate( H5T_COMPOUND, (size_t)new_member_size )) < 0) goto out; - + /* the field in the file is found by its name */ if (H5Tinsert( write_type_id, field_name, (size_t)0, field_type ) < 0) goto out; - + /* create xfer properties to preserve initialized data */ if ((preserve_id = H5Pcreate (H5P_DATASET_XFER)) < 0) goto out; if (H5Pset_preserve (preserve_id, 1) < 0) goto out; - + /* only write if there is something to write */ if ( buf ) { /* create a memory dataspace handle */ if ((msid_2 = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; - + /* write */ if (H5Dwrite( did_2, write_type_id, msid_2, sid_2, preserve_id, buf ) < 0) goto out; - + /* terminate access to the memory dataspace */ if (H5Sclose( msid_2 ) < 0) goto out; } - + /* end access to the property list */ if (H5Pclose( preserve_id ) < 0) goto out; - + /*------------------------------------------------------------------------- * release resources from 1st table *------------------------------------------------------------------------- */ - + if (H5Sclose( msid_1 ) < 0) goto out; if (H5Tclose( tid_1 ) < 0) @@ -2366,13 +2366,13 @@ herr_t H5TBinsert_field( hid_t loc_id, goto out; if (H5Dclose( did_1 ) < 0) goto out; - - + + /*------------------------------------------------------------------------- * release resources from 2nd table *------------------------------------------------------------------------- */ - + if (H5Sclose( sid_2 ) < 0) goto out; if (H5Tclose( tid_2 ) < 0) @@ -2380,112 +2380,112 @@ herr_t H5TBinsert_field( hid_t loc_id, if (H5Pclose( pid_2 ) < 0) goto out; if (H5Dclose( did_2 ) < 0) - goto out; - + goto out; + /*------------------------------------------------------------------------- * delete 1st table *------------------------------------------------------------------------- */ if (H5Ldelete( loc_id, dset_name, H5P_DEFAULT ) < 0) return -1; - + /*------------------------------------------------------------------------- * rename 2nd table *------------------------------------------------------------------------- */ - + if (H5Lmove( loc_id, "new", H5L_SAME_LOC, dset_name, H5P_DEFAULT, H5P_DEFAULT ) < 0) return -1; - + /*------------------------------------------------------------------------- * attach the conforming table attributes *------------------------------------------------------------------------- */ - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0) return -1; - + /* open the dataset. */ if ((did_1 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /* get the datatype */ if ((tid_1 = H5Dget_type( did_1 )) < 0) goto out; - + /* set the attributes */ if (H5TB_attach_attributes( table_title, loc_id, dset_name,(hsize_t) nfields, tid_1 ) < 0) return -1; - + /*------------------------------------------------------------------------- * attach the fill attributes from previous table *------------------------------------------------------------------------- */ - + if (( sid_1 = H5Screate(H5S_SCALAR)) < 0) goto out; - + for ( i = 0; i < nfields-1; i++) { /* get the member type */ if(( member_type_id = H5Tget_member_type( tid_1, (unsigned) i )) < 0) goto out; - + /* get the member offset */ member_offset = H5Tget_member_offset(tid_1, (unsigned)i); - + strcpy(attr_name, "FIELD_"); sprintf(aux, "%d", (int)i); strcat(attr_name, aux); sprintf(aux, "%s", "_FILL"); strcat(attr_name, aux); - + if ((attr_id = H5Acreate2(did_1, attr_name, member_type_id, sid_1, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; - + if (H5Awrite(attr_id, member_type_id, tmp_fill_buf+member_offset) < 0) goto out; - + if (H5Aclose(attr_id) < 0) goto out; - + /* close the member type */ if (H5Tclose(member_type_id) < 0) goto out; } - + /*------------------------------------------------------------------------- * attach the fill attribute from the new field, if present *------------------------------------------------------------------------- */ if (fill_data) { - + strcpy(attr_name, "FIELD_"); sprintf(aux, "%d",(int)(nfields - 1)); strcat(attr_name, aux); sprintf(aux, "%s", "_FILL"); strcat(attr_name, aux); - + /* get the member type */ if ((member_type_id = H5Tget_member_type(tid_1, (unsigned)nfields - 1)) < 0) goto out; - + if ((attr_id = H5Acreate2(did_1, attr_name, member_type_id, sid_1, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; - + if (H5Awrite(attr_id, member_type_id, fill_data) < 0) goto out; - + if (H5Aclose(attr_id) < 0) goto out; - + if (H5Tclose(member_type_id) < 0) goto out; - + } - + /* close */ if (H5Sclose( sid_1 ) < 0) goto out; @@ -2493,13 +2493,13 @@ herr_t H5TBinsert_field( hid_t loc_id, goto out; if (H5Dclose( did_1 ) < 0) goto out; - + /* release resources. */ free ( tmp_buf ); free ( tmp_fill_buf ); - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -2512,33 +2512,33 @@ out: H5Sclose(sid_2); H5Tclose(tid_2); H5Pclose(pid_2); - + } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TBdelete_field - * - * Purpose: Deletes a field - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: January 30, 2002 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5TBdelete_field +* +* Purpose: Deletes a field +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: January 30, 2002 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5TBdelete_field( hid_t loc_id, - const char *dset_name, - const char *field_name ) + const char *dset_name, + const char *field_name ) { /* identifiers for the 1st original dataset */ hid_t did_1; @@ -2574,179 +2574,179 @@ herr_t H5TBdelete_field( hid_t loc_id, hid_t attr_id; hsize_t i; int has_fill=0; - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0) return -1; - + /*------------------------------------------------------------------------- * get information about the old data type *------------------------------------------------------------------------- */ - + /* open the dataset. */ if ((did_1 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /* get creation properties list */ if ((pid_1 = H5Dget_create_plist( did_1 )) < 0) goto out; - + /* get the datatype */ if ((tid_1 = H5Dget_type( did_1 )) < 0) goto out; - + /* get the size of the datatype */ type_size1 = H5Tget_size( tid_1 ); - + /* get the dataspace handle */ if ((sid_1 = H5Dget_space( did_1 )) < 0) goto out; - + /* get dimension */ if (H5Sget_simple_extent_dims( sid_1, dims, NULL) < 0) goto out; - + /*------------------------------------------------------------------------- * create a new data type; first we find the size of the datatype to delete *------------------------------------------------------------------------- */ - + /* check out the field */ for ( i = 0; i < nfields; i++) { /* get the member name */ member_name = H5Tget_member_name( tid_1,(unsigned) i ); - + /* we want to find the field to delete */ if (H5TB_find_field( member_name, field_name ) > 0 ) { /* get the member type */ if (( member_type_id = H5Tget_member_type( tid_1,(unsigned) i )) < 0) goto out; - + /* get the member size */ delete_member_size = H5Tget_size( member_type_id ); - + /* close the member type */ if (H5Tclose( member_type_id ) < 0) goto out; - + free( member_name ); - + break; - + } - + free( member_name ); - + } /* i */ - + /* no field to delete was found */ if (delete_member_size == 0 ) goto out; - + /*------------------------------------------------------------------------- * create a new data type; we now insert all the fields into the new type *------------------------------------------------------------------------- */ - + type_size2 = type_size1 - delete_member_size; - + /* create the data type. */ if (( tid_2 = H5Tcreate (H5T_COMPOUND, type_size2 )) < 0) goto out; - + curr_offset = 0; - + /* alloc fill value attribute buffer */ tmp_fill_buf = (unsigned char *)malloc((size_t) type_size2 ); - + /*------------------------------------------------------------------------- * get attributes from previous table in the process *------------------------------------------------------------------------- */ - + /* get the table title */ if ((H5TBAget_title( did_1, table_title )) < 0) goto out; - + /* insert the old fields except the one to delete */ for ( i = 0; i < nfields; i++) { /* get the member name */ member_name = H5Tget_member_name( tid_1, (unsigned) i ); - + /* we want to skip the field to delete */ if (H5TB_find_field( member_name, field_name ) > 0 ) { free( member_name ); continue; } - + /* get the member type */ if (( member_type_id = H5Tget_member_type( tid_1, (unsigned)i )) < 0) goto out; - + /* get the member size */ member_size = H5Tget_size( member_type_id ); - + /* insert it into the new type */ if (H5Tinsert( tid_2, member_name, curr_offset, member_type_id ) < 0) goto out; - + /*------------------------------------------------------------------------- * get the fill value information *------------------------------------------------------------------------- */ - + strcpy( attr_name, "FIELD_" ); sprintf( aux, "%d", (int)i ); strcat( attr_name, aux ); sprintf( aux, "%s", "_FILL" ); strcat( attr_name, aux ); - + /* check if we have the _FILL attribute */ has_fill = H5LT_find_attribute( did_1, attr_name ); - + /* get it */ if (has_fill == 1 ) { if(H5LT_get_attribute_disk( did_1, attr_name, tmp_fill_buf+curr_offset ) < 0) goto out; } - + curr_offset += member_size; - + free(member_name); - + /* close the member type */ if (H5Tclose(member_type_id) < 0) goto out; } /* i */ - + /*------------------------------------------------------------------------- * create a new temporary dataset *------------------------------------------------------------------------- */ - + /* retrieve the size of chunk */ if (H5Pget_chunk(pid_1, 1, dims_chunk) < 0) goto out; - + /* create a new simple data space with unlimited size, using the dimension */ if ((sid_2 = H5Screate_simple(1, dims, maxdims)) < 0) return -1; - + /* modify dataset creation properties, i.e. enable chunking */ pid_2 = H5Pcreate(H5P_DATASET_CREATE); if (H5Pset_chunk(pid_2, 1, dims_chunk) < 0) return -1; - + /* create the dataset. */ if ((did_2 = H5Dcreate2(loc_id, "new", tid_2, sid_2, H5P_DEFAULT, pid_2, H5P_DEFAULT)) < 0) goto out; - + /*------------------------------------------------------------------------- * we have to read field by field of the old dataset and save it into the new one *------------------------------------------------------------------------- @@ -2755,80 +2755,80 @@ herr_t H5TBdelete_field( hid_t loc_id, { /* get the member name */ member_name = H5Tget_member_name(tid_1, (unsigned)i); - + /* skip the field to delete */ if (H5TB_find_field(member_name, field_name) > 0) { free(member_name); continue; } - + /* get the member type */ if ((member_type_id = H5Tget_member_type(tid_1, (unsigned)i)) < 0) goto out; - + /* get the member size */ member_size = H5Tget_size(member_type_id); - + /* create a read id */ if ((read_type_id = H5Tcreate(H5T_COMPOUND, member_size)) < 0) goto out; - + /* insert it into the new type */ if (H5Tinsert( read_type_id, member_name, (size_t)0, member_type_id ) < 0) goto out; - + tmp_buf = (unsigned char *)calloc((size_t) nrecords, member_size ); - + /* read */ if (H5Dread( did_1, read_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, tmp_buf ) < 0) goto out; - + /* create a write id */ if (( write_type_id = H5Tcreate( H5T_COMPOUND, member_size )) < 0) goto out; - + /* the field in the file is found by its name */ if (H5Tinsert( write_type_id, member_name, (size_t)0, member_type_id ) < 0) goto out; - + /* create xfer properties to preserve initialized data */ if ((preserve_id = H5Pcreate (H5P_DATASET_XFER)) < 0) goto out; if (H5Pset_preserve (preserve_id, 1) < 0) goto out; - + /* write */ if(H5Dwrite( did_2, write_type_id, H5S_ALL, H5S_ALL, preserve_id, tmp_buf ) < 0) goto out; - + /* end access to the property list */ if (H5Pclose( preserve_id ) < 0) goto out; - + /* close the member type */ if (H5Tclose( member_type_id ) < 0) goto out; - + /* close the read type */ if (H5Tclose( read_type_id ) < 0) goto out; - + /* close the write type */ if (H5Tclose( write_type_id ) < 0) goto out; - + /* release resources. */ free( member_name ); free ( tmp_buf ); - + } /* i */ - + /*------------------------------------------------------------------------- * release resources from 1st table *------------------------------------------------------------------------- */ - + if (H5Tclose( tid_1 ) < 0) goto out; if (H5Pclose( pid_1 ) < 0) @@ -2837,13 +2837,13 @@ herr_t H5TBdelete_field( hid_t loc_id, goto out; if (H5Dclose( did_1 ) < 0) goto out; - - + + /*------------------------------------------------------------------------- * release resources from 2nd table *------------------------------------------------------------------------- */ - + if (H5Sclose( sid_2 ) < 0) goto out; if (H5Tclose( tid_2 ) < 0) @@ -2852,104 +2852,104 @@ herr_t H5TBdelete_field( hid_t loc_id, goto out; if (H5Dclose( did_2 ) < 0) goto out; - + /*------------------------------------------------------------------------- * delete 1st table *------------------------------------------------------------------------- */ - + if (H5Ldelete( loc_id, dset_name, H5P_DEFAULT ) < 0) return -1; - + /*------------------------------------------------------------------------- * rename 2nd table *------------------------------------------------------------------------- */ - + if (H5Lmove( loc_id, "new", H5L_SAME_LOC, dset_name, H5P_DEFAULT, H5P_DEFAULT ) < 0) return -1; - + /*------------------------------------------------------------------------- * attach the conforming table attributes *------------------------------------------------------------------------- */ - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0) return -1; - + /* open the dataset. */ if ((did_1 = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /* get the datatype */ if ((tid_1 = H5Dget_type( did_1 )) < 0) goto out; - + /* set the attributes */ if (H5TB_attach_attributes( table_title, loc_id, dset_name, nfields, tid_1 ) < 0) return -1; - + /*------------------------------------------------------------------------- * attach the fill attributes from previous table *------------------------------------------------------------------------- */ - + if (has_fill == 1) { if((sid_1 = H5Screate(H5S_SCALAR)) < 0) goto out; - + for(i = 0; i < nfields; i++) { - + /* get the member type */ if (( member_type_id = H5Tget_member_type( tid_1, (unsigned)i )) < 0) goto out; - + /* get the member offset */ member_offset = H5Tget_member_offset(tid_1, (unsigned)i); - + strcpy(attr_name, "FIELD_"); sprintf(aux, "%d", (int)i); strcat(attr_name, aux); sprintf(aux, "%s", "_FILL"); strcat(attr_name, aux); - + if ((attr_id = H5Acreate2(did_1, attr_name, member_type_id, sid_1, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto out; - + if (H5Awrite(attr_id, member_type_id, tmp_fill_buf+member_offset) < 0) goto out; - + if (H5Aclose(attr_id) < 0) goto out; - + /* close the member type */ if (H5Tclose(member_type_id) < 0) goto out; } - + /* close data space. */ if (H5Sclose(sid_1) < 0) goto out; - + } /*has_fill*/ - + /* release the datatype. */ if (H5Tclose( tid_1 ) < 0) goto out; - + /* end access to the dataset */ if (H5Dclose( did_1 ) < 0) goto out; - + /* Release resources. */ free ( tmp_fill_buf ); - + return 0; - -/* error zone */ + + /* error zone */ out: H5E_BEGIN_TRY { @@ -2961,74 +2961,74 @@ out: H5Sclose(sid_2); H5Tclose(tid_2); H5Pclose(pid_2); - + } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * - * Table attribute functions - * - *------------------------------------------------------------------------- - */ +* +* Table attribute functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5TBAget_title - * - * Purpose: Read the table title - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: January 30, 2001 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5TBAget_title +* +* Purpose: Read the table title +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: January 30, 2001 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5TBAget_title( hid_t loc_id, - char *table_title ) + char *table_title ) { - + /* Get the TITLE attribute */ if(H5LT_get_attribute_disk( loc_id, "TITLE", table_title ) < 0) return -1; - - + + return 0; - + } /*------------------------------------------------------------------------- - * Function: H5TBAget_fill - * - * Purpose: Read the table attribute fill values - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: January 30, 2002 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5TBAget_fill +* +* Purpose: Read the table attribute fill values +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: January 30, 2002 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5TBAget_fill( hid_t loc_id, - const char *dset_name, - hid_t dset_id, - unsigned char *dst_buf ) + const char *dset_name, + hid_t dset_id, + unsigned char *dst_buf ) { - + hsize_t nfields; hsize_t nrecords; char attr_name[255]; @@ -3036,20 +3036,20 @@ herr_t H5TBAget_fill( hid_t loc_id, hsize_t i; size_t *src_offset; int has_fill=0; - + /* get the number of records and fields */ if (H5TBget_table_info ( loc_id, dset_name, &nfields, &nrecords ) < 0) return -1; - + src_offset = (size_t *)malloc((size_t)nfields * sizeof(size_t)); - + if (src_offset == NULL ) return -1; - + /* get field info */ if (H5TBget_field_info( loc_id, dset_name, NULL, NULL, src_offset, NULL ) < 0) goto out; - + for ( i = 0; i < nfields; i++) { strcpy( attr_name, "FIELD_" ); @@ -3057,125 +3057,125 @@ herr_t H5TBAget_fill( hid_t loc_id, strcat( attr_name, aux ); sprintf( aux, "%s", "_FILL" ); strcat( attr_name, aux ); - + /* check if we have the _FILL attribute */ has_fill = H5LT_find_attribute( dset_id, attr_name ); - + /* get it */ if (has_fill == 1 ) { if(H5LT_get_attribute_disk( dset_id, attr_name, dst_buf+src_offset[i] ) < 0) goto out; } - + } - + free( src_offset ); - + return has_fill; - + out: free( src_offset ); return -1; - + } /*------------------------------------------------------------------------- - * - * Inquiry functions - * - *------------------------------------------------------------------------- - */ +* +* Inquiry functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5TBget_table_info - * - * Purpose: Gets the number of records and fields of a table - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 19, 2001 - * - * Comments: - * - * Modifications: - * May 08, 2003 - * In version 2.0 of Table, the number of records is stored as an - * attribute "NROWS" - * November 24, 2008 - * In version 3.0 of Table, "NROWS" was deprecated - * - * - *------------------------------------------------------------------------- - */ +* Function: H5TBget_table_info +* +* Purpose: Gets the number of records and fields of a table +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 19, 2001 +* +* Comments: +* +* Modifications: +* May 08, 2003 +* In version 2.0 of Table, the number of records is stored as an +* attribute "NROWS" +* November 24, 2008 +* In version 3.0 of Table, "NROWS" was deprecated +* +* +*------------------------------------------------------------------------- +*/ herr_t H5TBget_table_info ( hid_t loc_id, - const char *dset_name, - hsize_t *nfields, - hsize_t *nrecords ) + const char *dset_name, + hsize_t *nfields, + hsize_t *nrecords ) { hid_t tid=-1; hid_t sid=-1; hid_t did=-1; int num_members; hsize_t dims[1]; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) return -1; - + /* get the datatype */ if ((tid = H5Dget_type( did )) < 0) goto out; - + /* get the number of members */ if ((num_members = H5Tget_nmembers( tid )) < 0) goto out; - + /*------------------------------------------------------------------------- * get number of nfields *------------------------------------------------------------------------- */ - + if (nfields) { *nfields = num_members; } - - + + /*------------------------------------------------------------------------- * get number of records *------------------------------------------------------------------------- */ - + if (nrecords) { /* get the dataspace handle */ if ((sid = H5Dget_space( did )) < 0) goto out; - + /* get dimension */ if (H5Sget_simple_extent_dims( sid, dims, NULL) < 0) goto out; - + /* terminate access to the dataspace */ if (H5Sclose( sid ) < 0) goto out; - + *nrecords = dims[0]; } - + /* close */ if (H5Tclose( tid ) < 0) goto out; if (H5Dclose( did ) < 0) return -1; - + return 0; - + /* error zone */ out: H5E_BEGIN_TRY @@ -3185,33 +3185,33 @@ out: H5Tclose(tid); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TBget_field_info - * - * Purpose: Get information about fields - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 19, 2001 - * - * Comments: - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5TBget_field_info +* +* Purpose: Get information about fields +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 19, 2001 +* +* Comments: +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5TBget_field_info( hid_t loc_id, - const char *dset_name, - char *field_names[], - size_t *field_sizes, - size_t *field_offsets, - size_t *type_size ) + const char *dset_name, + char *field_names[], + size_t *field_sizes, + size_t *field_offsets, + size_t *type_size ) { hid_t did; /* dataset ID */ hid_t tid; /* file type ID */ @@ -3224,73 +3224,73 @@ herr_t H5TBget_field_info( hid_t loc_id, size_t member_offset; size_t size; hssize_t i; - + /* open the dataset. */ if ((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0) goto out; - + /* get the datatype */ if (( tid = H5Dget_type( did )) < 0) goto out; - + if ((n_tid = H5Tget_native_type(tid,H5T_DIR_DEFAULT)) < 0) goto out; - + /* get the type size */ size = H5Tget_size( n_tid ); - + if ( type_size ) { *type_size = size; } - + /* get the number of members */ if (( nfields = H5Tget_nmembers( tid )) < 0) goto out; - + /* iterate tru the members */ for ( i = 0; i < nfields; i++) { /* get the member name */ member_name = H5Tget_member_name( tid, (unsigned)i ); - + if (field_names ) { strcpy( field_names[i], member_name ); } - + /* get the member type */ if (( m_tid = H5Tget_member_type( tid,(unsigned) i )) < 0) goto out; if ((nm_tid = H5Tget_native_type(m_tid,H5T_DIR_DEFAULT)) < 0) goto out; - + /* get the member size */ member_size = H5Tget_size( nm_tid ); - + if(field_sizes ) { field_sizes[i] = member_size; } - + /* get the member offset */ member_offset = H5Tget_member_offset( n_tid,(unsigned) i ); - + if(field_offsets ) { field_offsets[i] = member_offset; } - + /* close the member types */ if (H5Tclose( m_tid ) < 0) goto out; if (H5Tclose( nm_tid ) < 0) goto out; - + free( member_name ); - + } /* i */ - + /* close */ if (H5Tclose( tid ) < 0) goto out; @@ -3298,10 +3298,10 @@ herr_t H5TBget_field_info( hid_t loc_id, goto out; if (H5Dclose( did ) < 0) return -1; - + return 0; - - /* error zone */ + + /* error zone */ out: H5E_BEGIN_TRY { @@ -3310,36 +3310,36 @@ out: H5Tclose(n_tid); } H5E_END_TRY; return -1; - + } /*------------------------------------------------------------------------- - * - * internal functions - * - *------------------------------------------------------------------------- - */ +* +* internal functions +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5TB_find_field - * - * Purpose: Find a string field - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: November 19, 2001 - * - *------------------------------------------------------------------------- - */ +* Function: H5TB_find_field +* +* Purpose: Find a string field +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: November 19, 2001 +* +*------------------------------------------------------------------------- +*/ static int H5TB_find_field( const char *field, const char *field_list ) { const char *start = field_list; const char *end; - + while ( (end = strstr( start, "," )) != 0 ) { size_t count = end - start; @@ -3347,105 +3347,105 @@ int H5TB_find_field( const char *field, const char *field_list ) return 1; start = end + 1; } - + if(strcmp( start, field ) == 0 ) return 1; - + return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TB_attach_attributes - * - * Purpose: Private function that creates the conforming table attributes; - * Used by H5TBcombine_tables; not used by H5TBmake_table, which does not read - * the fill value attributes from an existing table - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: December 6, 2001 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5TB_attach_attributes +* +* Purpose: Private function that creates the conforming table attributes; +* Used by H5TBcombine_tables; not used by H5TBmake_table, which does not read +* the fill value attributes from an existing table +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: December 6, 2001 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ static herr_t H5TB_attach_attributes( const char *table_title, - hid_t loc_id, - const char *dset_name, - hsize_t nfields, - hid_t tid ) + hid_t loc_id, + const char *dset_name, + hsize_t nfields, + hid_t tid ) { - + char attr_name[255]; char *member_name; char aux[255]; hsize_t i; - + /* attach the CLASS attribute */ if (H5LTset_attribute_string( loc_id, dset_name, "CLASS", TABLE_CLASS ) < 0) goto out; - + /* attach the VERSION attribute */ if (H5LTset_attribute_string( loc_id, dset_name, "VERSION", TABLE_VERSION ) < 0) goto out; - + /* attach the TITLE attribute */ if (H5LTset_attribute_string( loc_id, dset_name, "TITLE", table_title ) < 0) goto out; - + /* attach the FIELD_ name attribute */ for ( i = 0; i < nfields; i++) { - + /* get the member name */ member_name = H5Tget_member_name( tid, (unsigned)i ); - + strcpy( attr_name, "FIELD_" ); sprintf( aux, "%d", (int)i ); strcat( attr_name, aux ); sprintf( aux, "%s", "_NAME" ); strcat( attr_name, aux ); - + /* attach the attribute */ if (H5LTset_attribute_string( loc_id, dset_name, attr_name, member_name ) < 0) goto out; - + free( member_name ); - + } - + return 0; - + out: return -1; - + } /*------------------------------------------------------------------------- - * Function: H5TB_create_type - * - * Purpose: Private function that creates a memory type ID - * - * Return: Success: the memory type ID, Failure: -1 - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: March 31, 2004 - * - * Comments: - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5TB_create_type +* +* Purpose: Private function that creates a memory type ID +* +* Return: Success: the memory type ID, Failure: -1 +* +* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu +* +* Date: March 31, 2004 +* +* Comments: +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ static hid_t H5TB_create_type(hid_t loc_id, @@ -3462,31 +3462,31 @@ hid_t H5TB_create_type(hid_t loc_id, hsize_t nfields; char **fnames; unsigned i; - + /* get the number of fields */ if (H5TBget_table_info(loc_id,dset_name,&nfields,NULL) < 0) return -1; - - if ((fnames=malloc(sizeof(char*)*(size_t)nfields))==NULL) + + if ((fnames = (char**) malloc(sizeof(char*)*(size_t)nfields))==NULL) return -1; - + for ( i = 0; i < nfields; i++) { - if ((fnames[i]=malloc(sizeof(char)*HLTB_MAX_FIELD_LEN))==NULL) + if ((fnames[i] = (char*) malloc(sizeof(char)*HLTB_MAX_FIELD_LEN))==NULL) { free(fnames); return -1; } } - + /* get field info */ if (H5TBget_field_info(loc_id,dset_name,fnames,NULL,NULL,NULL) < 0) goto out; - + /* create the memory data type */ if ((mem_type_id=H5Tcreate(H5T_COMPOUND,type_size)) < 0) goto out; - + /* get each field ID and adjust its size, if necessary */ for ( i = 0; i < nfields; i++) { @@ -3507,15 +3507,15 @@ hid_t H5TB_create_type(hid_t loc_id, if (H5Tclose(nmtype_id) < 0) goto out; } - + for ( i=0; i<nfields; i++) { free (fnames[i]); } free (fnames); - + return mem_type_id; - + /* error zone */ out: H5E_BEGIN_TRY @@ -3531,40 +3531,40 @@ out: if (fnames) free (fnames); return -1; - + } /*------------------------------------------------------------------------- - * - * Functions shared between H5TB and H5PT - * - *------------------------------------------------------------------------- - */ +* +* Functions shared between H5TB and H5PT +* +*------------------------------------------------------------------------- +*/ /*------------------------------------------------------------------------- - * Function: H5TB_common_append_records - * - * Purpose: Common code for reading records shared between H5PT and H5TB - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Nat Furrer, nfurrer@ncsa.uiuc.edu - * James Laird, jlaird@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: Called by H5TBappend_records and H5PTappend_records - * - * Modifications: - * - *------------------------------------------------------------------------- - */ +* Function: H5TB_common_append_records +* +* Purpose: Common code for reading records shared between H5PT and H5TB +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Nat Furrer, nfurrer@ncsa.uiuc.edu +* James Laird, jlaird@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: Called by H5TBappend_records and H5PTappend_records +* +* Modifications: +* +*------------------------------------------------------------------------- +*/ herr_t H5TB_common_append_records( hid_t dataset_id, - hid_t mem_type_id, - size_t nrecords, - hsize_t orig_table_size, - const void * buf) + hid_t mem_type_id, + size_t nrecords, + hsize_t orig_table_size, + const void * buf) { hsize_t count[1]; hsize_t offset[1]; @@ -3572,39 +3572,39 @@ herr_t H5TB_common_append_records( hid_t dataset_id, hid_t m_sid = H5I_BADID; hsize_t dims[1]; hsize_t mem_dims[1]; - + /* extend the dataset */ dims[0] = nrecords + orig_table_size; if (H5Dset_extent(dataset_id, dims) < 0) goto out; - + /* create a simple memory data space */ mem_dims[0] = nrecords; if((m_sid = H5Screate_simple(1, mem_dims, NULL)) < 0) goto out; - + /* get a copy of the new file data space for writing */ if ((sid = H5Dget_space(dataset_id)) < 0) goto out; - + /* define a hyperslab in the dataset */ offset[0] = orig_table_size; count[0] = nrecords; if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* write the records */ if (H5Dwrite( dataset_id, mem_type_id, m_sid, sid, H5P_DEFAULT, buf ) < 0) goto out; - + /* close */ if (H5Sclose( m_sid ) < 0) goto out; if (H5Sclose( sid ) < 0) goto out; - + return 0; - + out: H5E_BEGIN_TRY { @@ -3617,66 +3617,66 @@ out: /*------------------------------------------------------------------------- - * Function: H5TB_common_read_records - * - * Purpose: Common code for reading records shared between H5PT and H5TB - * - * Return: Success: 0, Failure: -1 - * - * Programmer: Nat Furrer, nfurrer@ncsa.uiuc.edu - * James Laird, jlaird@ncsa.uiuc.edu - * - * Date: March 8, 2004 - * - * Comments: Called by H5TBread_records and H5PTread_records - * - * Modifications: - * - * - *------------------------------------------------------------------------- - */ +* Function: H5TB_common_read_records +* +* Purpose: Common code for reading records shared between H5PT and H5TB +* +* Return: Success: 0, Failure: -1 +* +* Programmer: Nat Furrer, nfurrer@ncsa.uiuc.edu +* James Laird, jlaird@ncsa.uiuc.edu +* +* Date: March 8, 2004 +* +* Comments: Called by H5TBread_records and H5PTread_records +* +* Modifications: +* +* +*------------------------------------------------------------------------- +*/ herr_t H5TB_common_read_records( hid_t dataset_id, - hid_t mem_type_id, - hsize_t start, - size_t nrecords, - hsize_t table_size, - void *buf) + hid_t mem_type_id, + hsize_t start, + size_t nrecords, + hsize_t table_size, + void *buf) { hsize_t count[1]; hsize_t offset[1]; hid_t sid = H5I_BADID; hid_t m_sid = H5I_BADID; hsize_t mem_size[1]; - + /* make sure the read request is in bounds */ if (start + nrecords > table_size ) goto out; - + /* get the dataspace handle */ if ((sid = H5Dget_space( dataset_id )) < 0) goto out; - + /* define a hyperslab in the dataset of the size of the records */ offset[0] = start; count[0] = nrecords; if (H5Sselect_hyperslab( sid, H5S_SELECT_SET, offset, NULL, count, NULL) < 0) goto out; - + /* create a memory dataspace handle */ mem_size[0] = count[0]; if ((m_sid = H5Screate_simple( 1, mem_size, NULL )) < 0) goto out; if ((H5Dread( dataset_id, mem_type_id, m_sid, sid, H5P_DEFAULT, buf)) < 0) goto out; - + /* close */ if (H5Sclose( m_sid ) < 0) goto out; if (H5Sclose( sid ) < 0) goto out; - + return 0; - + out: H5E_BEGIN_TRY { diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index cdc2c3b..6951619 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -45,14 +45,12 @@ static int read_data( const char* fname, int ndims, hsize_t *dims, float **buf ) #define DIM3_SIZE 2 #define DIM0 0 #define DIM1 1 -#define DIM2 2 #define DS_1_NAME "ds_a_1" #define DS_11_NAME "ds_a_11" #define DS_2_NAME "ds_a_2" #define DS_21_NAME "ds_a_21" #define DS_22_NAME "ds_a_22" -#define DS_3_NAME "ds_a_3" #define SCALE_1_NAME "Latitude set 0" #define SCALE_11_NAME "Latitude set 1" @@ -1415,6 +1413,10 @@ static int test_simple(void) case 1: /* for DIM 1, we get no valid scales */ if(match_size!=0 && idx!=0) goto out; + break; + default: + assert(0); + break; }/*switch*/ }/*for*/ } @@ -1523,7 +1525,7 @@ static herr_t read_scale(hid_t dset, unsigned dim, hid_t scale_id, void *visitor char *buf=NULL; /* data buffer */ size_t size; int i; - char *data=visitor_data; + char *data = (char*) visitor_data; /* unused */ dset=dset; @@ -2955,7 +2957,7 @@ static int test_errors2(void) hsize_t dimd[2] = {3,3}; /* size of data dataset */ hsize_t dims[1] = {3}; /* size of scale dataset */ char lbuf[255]; /* label buffer */ - size_t label_len; /* label lenght */ + ssize_t label_len; /* label lenght */ int scale_idx; /* scale index */ int nscales; /* number of scales in DIM */ int count; /* visitor data */ @@ -3137,4 +3139,5 @@ out: } H5E_END_TRY; H5_FAILED(); return FAIL; -}
\ No newline at end of file +} + diff --git a/hl/test/test_image.c b/hl/test/test_image.c index 2a365e2..426ae1d 100644 --- a/hl/test/test_image.c +++ b/hl/test/test_image.c @@ -1,17 +1,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +* Copyright by The HDF Group. * +* Copyright by the Board of Trustees of the University of Illinois. * +* All rights reserved. * +* * +* This file is part of HDF5. The full HDF5 copyright notice, including * +* terms governing use, modification, and redistribution, is contained in * +* the files COPYING and Copyright.html. COPYING can be found at the root * +* of the source code distribution tree; Copyright.html can be found at the * +* root level of an installed copy of the electronic HDF5 document set and * +* is linked from the top-level documents page. It can also be found at * +* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * +* access to either file, you may request a copy from help@hdfgroup.org. * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdlib.h> #include <string.h> @@ -61,9 +61,9 @@ static int read_palette(const char* file_name, rgb_t *palette, size_t palette_si unsigned char *image_data = NULL; /*------------------------------------------------------------------------- - * the main program - *------------------------------------------------------------------------- - */ +* the main program +*------------------------------------------------------------------------- +*/ int main(void) { @@ -83,9 +83,9 @@ error: } /*------------------------------------------------------------------------- - * a simple test that generates images and palettes - *------------------------------------------------------------------------- - */ +* a simple test that generates images and palettes +*------------------------------------------------------------------------- +*/ static int test_simple(void) { @@ -94,6 +94,7 @@ static int test_simple(void) hsize_t planes; hid_t fid; int i, j, n, space; + hsize_t u; char interlace[20]; hssize_t npals; @@ -142,7 +143,7 @@ static int test_simple(void) } } - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * define a palette, blue to red tones *------------------------------------------------------------------------- */ @@ -156,7 +157,7 @@ static int test_simple(void) /* Create a new HDF5 file using default properties. */ fid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * Indexed image test *------------------------------------------------------------------------- */ @@ -182,9 +183,9 @@ static int test_simple(void) if ( H5IMread_image( fid, IMAGE1_NAME, buf1_out ) < 0 ) goto out; - for (i = 0; i < height*width*planes; i++) + for (u = 0; u < height*width*planes; u++) { - if ( buf1[i] != buf1_out[i] ) + if ( buf1[u] != buf1_out[u] ) goto out; } @@ -192,7 +193,7 @@ static int test_simple(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * True color image test *------------------------------------------------------------------------- */ @@ -210,16 +211,16 @@ static int test_simple(void) if ( H5IMread_image( fid, IMAGE2_NAME, buf2_out ) < 0 ) goto out; - for (i = 0; i < height*width*planes; i++) + for (u = 0; u < height*width*planes; u++) { - if ( buf2[i] != buf2_out[i] ) + if ( buf2[u] != buf2_out[u] ) goto out; } PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMget_npalettes test *------------------------------------------------------------------------- */ @@ -229,7 +230,7 @@ static int test_simple(void) if ( H5IMget_npalettes( fid, IMAGE1_NAME, &npals ) < 0 ) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMget_palette_info test *------------------------------------------------------------------------- */ @@ -243,7 +244,7 @@ static int test_simple(void) goto out; } - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMget_palette test *------------------------------------------------------------------------- */ @@ -257,7 +258,7 @@ static int test_simple(void) goto out; } - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMis_image test *------------------------------------------------------------------------- */ @@ -268,7 +269,7 @@ static int test_simple(void) if ( H5IMis_image( fid, IMAGE2_NAME ) < 0 ) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * H5IMis_palette test *------------------------------------------------------------------------- */ @@ -276,7 +277,7 @@ static int test_simple(void) if ( H5IMis_palette( fid, PAL_NAME ) < 0 ) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * end tests *------------------------------------------------------------------------- */ @@ -301,9 +302,9 @@ out: /*------------------------------------------------------------------------- - * read sample realistic image data from ASCII files - *------------------------------------------------------------------------- - */ +* read sample realistic image data from ASCII files +*------------------------------------------------------------------------- +*/ static int test_data(void) { @@ -321,7 +322,7 @@ static int test_data(void) printf("Testing read ascii image data and generate images\n"); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * read 8bit image data *------------------------------------------------------------------------- */ @@ -341,7 +342,7 @@ static int test_data(void) TESTING2("attaching palettes"); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * palette #1. rainbow palette. data is contained in "pal_rgb.h" *------------------------------------------------------------------------- */ @@ -358,7 +359,7 @@ static int test_data(void) if (H5IMlink_palette(fid,IMAGE1_NAME,PAL1_NAME)<0) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * palette #2. sepia palette. * read a PAL file and attach the palette to the HDF5 file *------------------------------------------------------------------------- @@ -384,7 +385,7 @@ static int test_data(void) if (H5IMlink_palette(fid,IMAGE1_NAME,PAL2_NAME)<0) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * palette #3. earth palette. * read a PAL file and attach the palette to the HDF5 file *------------------------------------------------------------------------- @@ -413,7 +414,7 @@ static int test_data(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * palette #4. blue-red * make a palette whith blue to red colors *------------------------------------------------------------------------- @@ -434,7 +435,7 @@ static int test_data(void) goto out; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * true color image example with pixel interlace *------------------------------------------------------------------------- */ @@ -469,7 +470,7 @@ static int test_data(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ @@ -488,16 +489,16 @@ out: } - /* - The following test provides an examples of how to generate HDF5 image data from - floating point data. In the example we use real life topographic data - (from the North American hemisphere). In the dataset sea values are represented - as negative numbers and land values are represented as positive numbers. - The example generates 3 HDF5 images, one that generates an image from all the values, - another that generates an image from the land values and another that generates an - image from the sea values. - For the example we used data from MODB, the Mediterranean Oceanic Data Base - http://modb.oce.ulg.ac.be/ +/* +The following test provides an examples of how to generate HDF5 image data from +floating point data. In the example we use real life topographic data +(from the North American hemisphere). In the dataset sea values are represented +as negative numbers and land values are represented as positive numbers. +The example generates 3 HDF5 images, one that generates an image from all the values, +another that generates an image from the land values and another that generates an +image from the sea values. +For the example we used data from MODB, the Mediterranean Oceanic Data Base +http://modb.oce.ulg.ac.be/ */ @@ -519,7 +520,7 @@ static int test_generate(void) printf("Testing read and process data and make indexed images\n"); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * compose the name of the file to open, using the srcdir, if appropriate *------------------------------------------------------------------------- */ @@ -543,40 +544,40 @@ static int test_generate(void) return -1; } -/* -!The first line of the ASCII file contains the dimension of the array : -! IMAX, JMAX, KMAX. The integers are stored with the FORTRAN format I5. -!The second line contains the exclusion value, the minimum and the maximum value of this -! file. These numbers are stored with the FORTRAN format E12.5. -! The remaining lines contains the data of the array, with 5 numbers per line -! (except the last line for each I-line). -! The array is stored in horizontal slices from sea surface to sea bottom and from -! north to south. So the indexes go from : -! -! DO K = KMAX to 1 -! DO J = JMAX to 1 -! DO I = 1 to IMAX -! read -! OD -! OD -! OD -! -! ____________________________ -! / /| (imax,jmax,kmax) -! / sea surface / | -! / / | -! /__________________________ / | -! | | | -! | | | (imax,jmax,1) n -! | | / / -! | | / / -! ^ j | | / w <-----o-----> e -! k | / |__________________________|/ / -! | / (imax,1,1) / -! |----------> s -! i -! -*/ + /* + !The first line of the ASCII file contains the dimension of the array : + ! IMAX, JMAX, KMAX. The integers are stored with the FORTRAN format I5. + !The second line contains the exclusion value, the minimum and the maximum value of this + ! file. These numbers are stored with the FORTRAN format E12.5. + ! The remaining lines contains the data of the array, with 5 numbers per line + ! (except the last line for each I-line). + ! The array is stored in horizontal slices from sea surface to sea bottom and from + ! north to south. So the indexes go from : + ! + ! DO K = KMAX to 1 + ! DO J = JMAX to 1 + ! DO I = 1 to IMAX + ! read + ! OD + ! OD + ! OD + ! + ! ____________________________ + ! / /| (imax,jmax,kmax) + ! / sea surface / | + ! / / | + ! /__________________________ / | + ! | | | + ! | | | (imax,jmax,1) n + ! | | / / + ! | | / / + ! ^ j | | / w <-----o-----> e + ! k | / |__________________________|/ / + ! | / (imax,1,1) / + ! |----------> s + ! i + ! + */ fscanf( f, "%d %d %d", &imax, &jmax, &kmax ); @@ -592,7 +593,7 @@ static int test_generate(void) } fclose( f ); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * we are processing all the data here *------------------------------------------------------------------------- @@ -611,7 +612,7 @@ static int test_generate(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * here we just process the land data *------------------------------------------------------------------------- @@ -633,7 +634,7 @@ static int test_generate(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * transform the data from floating point to unsigned char * here we just process the sea data *------------------------------------------------------------------------- @@ -655,7 +656,7 @@ static int test_generate(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * make a palette and attach it to the datasets *------------------------------------------------------------------------- */ @@ -677,7 +678,7 @@ static int test_generate(void) PASSED(); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ @@ -697,25 +698,25 @@ out: /*------------------------------------------------------------------------- - * read_data - * utility function to read ASCII image data - * the files have a header of the type - * - * components - * n - * height - * n - * width - * n - * - * followed by the image data - * - *------------------------------------------------------------------------- - */ +* read_data +* utility function to read ASCII image data +* the files have a header of the type +* +* components +* n +* height +* n +* width +* n +* +* followed by the image data +* +*------------------------------------------------------------------------- +*/ static int read_data( const char* fname, /*IN*/ - hsize_t *width, /*OUT*/ - hsize_t *height /*OUT*/ ) + hsize_t *width, /*OUT*/ + hsize_t *height /*OUT*/ ) { int i, n; int color_planes; @@ -725,7 +726,7 @@ static int read_data( const char* fname, /*IN*/ char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing data file */ - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * compose the name of the file to open, using "srcdir", if appropriate *------------------------------------------------------------------------- */ @@ -737,7 +738,7 @@ static int read_data( const char* fname, /*IN*/ } strcat(data_file,fname); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * read *------------------------------------------------------------------------- */ @@ -781,17 +782,17 @@ static int read_data( const char* fname, /*IN*/ /*------------------------------------------------------------------------- - * read_palette - * Read an ASCII palette file .PAL into an array - * the files have a header of the type - * - * Parameters: - * fname - name of file to read. - * palette - array of rgb_t to store the read palette. - * palette_size - number of elements in 'palette' array - * - *------------------------------------------------------------------------- - */ +* read_palette +* Read an ASCII palette file .PAL into an array +* the files have a header of the type +* +* Parameters: +* fname - name of file to read. +* palette - array of rgb_t to store the read palette. +* palette_size - number of elements in 'palette' array +* +*------------------------------------------------------------------------- +*/ #define STRING_JASC "JASC-PAL" @@ -803,118 +804,118 @@ static int read_palette(const char* fname, rgb_t *palette, size_t palette_size) { - FILE *file; - char buffer[80]; - unsigned u; - unsigned int red; - unsigned int green; - unsigned int blue; - unsigned nentries; - char *srcdir = getenv("srcdir"); /* the source directory */ - char data_file[512]; /* buffer to hold name of existing data file */ + FILE *file; + char buffer[80]; + unsigned u; + unsigned int red; + unsigned int green; + unsigned int blue; + unsigned nentries; + char *srcdir = getenv("srcdir"); /* the source directory */ + char data_file[512]; /* buffer to hold name of existing data file */ -/*------------------------------------------------------------------------- - * compose the name of the file to open, using "srcdir", if appropriate - *------------------------------------------------------------------------- - */ - strcpy(data_file, ""); - if (srcdir) - { - strcpy(data_file, srcdir); - strcat(data_file, "/"); - } - strcat(data_file,fname); - - /* ensure the given palette is valid */ - if (!palette) - return -1; - - /* open the input file */ - if (!(file = fopen(data_file, "r"))) - { - printf( "Could not open file %s. Try set $srcdir \n", data_file ); - return -1; - } - - /* read the file ident string */ - if (fgets(buffer, sizeof(buffer), file) == NULL) - { - fclose(file); - return -1; - } - - /* ensure it matches the palette file ident string */ - if ( strncmp(buffer, STRING_JASC, sizeof(STRING_JASC) - 1) != 0 && - strncmp(buffer, STRING_CWPAL, sizeof(STRING_CWPAL) - 1) != 0 ) - { - fclose(file); - return -1; - } - - /* read the version string */ - if (fgets(buffer, sizeof(buffer), file) == NULL) - { - fclose(file); - return -1; - } - - /* ensure it matches the palette file version string */ - if ( strncmp(buffer, VERSION_JASC, sizeof(VERSION_JASC) - 1) != 0 && - strncmp(buffer, VERSION_CWPAL, sizeof(VERSION_CWPAL) - 1) != 0 ) - { - fclose(file); - return -1; - } - - /* read the number of colors */ - if (fgets(buffer, sizeof(buffer), file) == NULL) - { - fclose(file); - return -1; - } - - - /* extract the number of colors. + /*------------------------------------------------------------------------- + * compose the name of the file to open, using "srcdir", if appropriate + *------------------------------------------------------------------------- + */ + strcpy(data_file, ""); + if (srcdir) + { + strcpy(data_file, srcdir); + strcat(data_file, "/"); + } + strcat(data_file,fname); + + /* ensure the given palette is valid */ + if (!palette) + return -1; + + /* open the input file */ + if (!(file = fopen(data_file, "r"))) + { + printf( "Could not open file %s. Try set $srcdir \n", data_file ); + return -1; + } + + /* read the file ident string */ + if (fgets(buffer, sizeof(buffer), file) == NULL) + { + fclose(file); + return -1; + } + + /* ensure it matches the palette file ident string */ + if ( strncmp(buffer, STRING_JASC, sizeof(STRING_JASC) - 1) != 0 && + strncmp(buffer, STRING_CWPAL, sizeof(STRING_CWPAL) - 1) != 0 ) + { + fclose(file); + return -1; + } + + /* read the version string */ + if (fgets(buffer, sizeof(buffer), file) == NULL) + { + fclose(file); + return -1; + } + + /* ensure it matches the palette file version string */ + if ( strncmp(buffer, VERSION_JASC, sizeof(VERSION_JASC) - 1) != 0 && + strncmp(buffer, VERSION_CWPAL, sizeof(VERSION_CWPAL) - 1) != 0 ) + { + fclose(file); + return -1; + } + + /* read the number of colors */ + if (fgets(buffer, sizeof(buffer), file) == NULL) + { + fclose(file); + return -1; + } + + + /* extract the number of colors. check for missing version or number of colors in this case it reads the first entry */ - if ( strlen( buffer ) > 4 ) - { - fclose(file); - return -1; - } - - if (sscanf(buffer, "%u", &nentries) != 1) - { - fclose(file); - return -1; - } - - /* ensure there are a sensible number of colors in the palette */ - if ((nentries > 256) || (nentries > palette_size)) - { - fclose(file); - return(-1); - } - - /* read the palette entries */ - for (u = 0; u < nentries; u++) - { - /* extract the red, green and blue color components. */ - if (fscanf(file, "%u %u %u", &red, &green, &blue) != 3) - { - fclose(file); - return -1; - } - /* store this palette entry */ - palette[u].r = (unsigned char)red; - palette[u].g = (unsigned char)green; - palette[u].b = (unsigned char)blue; - } - - /* close file */ - fclose(file); - - return nentries; + if ( strlen( buffer ) > 4 ) + { + fclose(file); + return -1; + } + + if (sscanf(buffer, "%u", &nentries) != 1) + { + fclose(file); + return -1; + } + + /* ensure there are a sensible number of colors in the palette */ + if ((nentries > 256) || (nentries > palette_size)) + { + fclose(file); + return(-1); + } + + /* read the palette entries */ + for (u = 0; u < nentries; u++) + { + /* extract the red, green and blue color components. */ + if (fscanf(file, "%u %u %u", &red, &green, &blue) != 3) + { + fclose(file); + return -1; + } + /* store this palette entry */ + palette[u].r = (unsigned char)red; + palette[u].g = (unsigned char)green; + palette[u].b = (unsigned char)blue; + } + + /* close file */ + fclose(file); + + return nentries; } diff --git a/hl/test/test_lite.c b/hl/test/test_lite.c index 239ad60..6de2e31 100644 --- a/hl/test/test_lite.c +++ b/hl/test/test_lite.c @@ -1,17 +1,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +* Copyright by The HDF Group. * +* Copyright by the Board of Trustees of the University of Illinois. * +* All rights reserved. * +* * +* This file is part of HDF5. The full HDF5 copyright notice, including * +* terms governing use, modification, and redistribution, is contained in * +* the files COPYING and Copyright.html. COPYING can be found at the root * +* of the source code distribution tree; Copyright.html can be found at the * +* root level of an installed copy of the electronic HDF5 document set and * +* is linked from the top-level documents page. It can also be found at * +* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * +* access to either file, you may request a copy from help@hdfgroup.org. * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdlib.h> #include <string.h> @@ -45,358 +45,355 @@ #define ATTR10_NAME "attr float" #define ATTR11_NAME "attr double" -/*Initial input buffer size for testing H5LTtext_to_dtype()*/ -#define BUF_SIZE 1024 - static herr_t make_attributes( hid_t loc_id, const char* obj_name ); /*------------------------------------------------------------------------- - * test dataset functions - *------------------------------------------------------------------------- - */ +* test dataset functions +*------------------------------------------------------------------------- +*/ static int test_dsets( void ) { - int rank = 2; - hsize_t dims[2] = {2,3}; - hid_t file_id; - hid_t dataset_id; - char data_char_in[DIM] = {1,2,3,4,5,6}; - char data_char_out[DIM]; - short data_short_in[DIM] = {1,2,3,4,5,6}; - short data_short_out[DIM]; - int data_int_in[DIM] = {1,2,3,4,5,6}; - int data_int_out[DIM]; - long data_long_in[DIM] = {1,2,3,4,5,6}; - long data_long_out[DIM]; - float data_float_in[DIM] = {1,2,3,4,5,6}; - float data_float_out[DIM]; - double data_double_in[DIM] = {1,2,3,4,5,6}; - double data_double_out[DIM]; - const char *data_string_in = "This is a string"; - char data_string_out[20]; - int i; - - - /* Create a new file using default properties. */ - file_id = H5Fcreate( FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); + int rank = 2; + hsize_t dims[2] = {2,3}; + hid_t file_id; + hid_t dataset_id; + char data_char_in[DIM] = {1,2,3,4,5,6}; + char data_char_out[DIM]; + short data_short_in[DIM] = {1,2,3,4,5,6}; + short data_short_out[DIM]; + int data_int_in[DIM] = {1,2,3,4,5,6}; + int data_int_out[DIM]; + long data_long_in[DIM] = {1,2,3,4,5,6}; + long data_long_out[DIM]; + float data_float_in[DIM] = {1,2,3,4,5,6}; + float data_float_out[DIM]; + double data_double_in[DIM] = {1,2,3,4,5,6}; + double data_double_out[DIM]; + const char *data_string_in = "This is a string"; + char data_string_out[20]; + int i; -/*------------------------------------------------------------------------- - * H5LTmake_dataset test - *------------------------------------------------------------------------- - */ - TESTING("H5LTmake_dataset"); + /* Create a new file using default properties. */ + file_id = H5Fcreate( FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); - /* Make dataset */ - if ( H5LTmake_dataset( file_id, DSET0_NAME, rank, dims, H5T_NATIVE_INT, data_int_in ) < 0 ) - goto out; + /*------------------------------------------------------------------------- + * H5LTmake_dataset test + *------------------------------------------------------------------------- + */ - /* Read dataset using the basic HDF5 API */ + TESTING("H5LTmake_dataset"); - if ( ( dataset_id = H5Dopen2(file_id, DSET0_NAME, H5P_DEFAULT) ) < 0 ) - goto out; + /* Make dataset */ + if ( H5LTmake_dataset( file_id, DSET0_NAME, rank, dims, H5T_NATIVE_INT, data_int_in ) < 0 ) + goto out; - if ( H5Dread ( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_int_out ) < 0 ) - goto out; + /* Read dataset using the basic HDF5 API */ - if ( H5Dclose( dataset_id ) < 0 ) - goto out; + if ( ( dataset_id = H5Dopen2(file_id, DSET0_NAME, H5P_DEFAULT) ) < 0 ) + goto out; - for (i = 0; i < DIM; i++) - { - if ( data_int_in[i] != data_int_out[i] ) { - goto out; - } - } + if ( H5Dread ( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_int_out ) < 0 ) + goto out; - PASSED(); + if ( H5Dclose( dataset_id ) < 0 ) + goto out; -/*------------------------------------------------------------------------- - * read using the LT function H5LTread_dataset - *------------------------------------------------------------------------- - */ + for (i = 0; i < DIM; i++) + { + if ( data_int_in[i] != data_int_out[i] ) { + goto out; + } + } - TESTING("H5LTread_dataset"); + PASSED(); - if ( H5LTread_dataset( file_id, DSET0_NAME, H5T_NATIVE_INT, data_int_out ) < 0 ) - goto out; + /*------------------------------------------------------------------------- + * read using the LT function H5LTread_dataset + *------------------------------------------------------------------------- + */ - for (i = 0; i < DIM; i++) - { - if ( data_int_in[i] != data_int_out[i] ) { - goto out; - } - } + TESTING("H5LTread_dataset"); - PASSED(); + if ( H5LTread_dataset( file_id, DSET0_NAME, H5T_NATIVE_INT, data_int_out ) < 0 ) + goto out; -/*------------------------------------------------------------------------- - * test the H5LTmake_dataset_ functions - *------------------------------------------------------------------------- - */ + for (i = 0; i < DIM; i++) + { + if ( data_int_in[i] != data_int_out[i] ) { + goto out; + } + } + PASSED(); -/*------------------------------------------------------------------------- - * H5LTmake_dataset_char - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * test the H5LTmake_dataset_ functions + *------------------------------------------------------------------------- + */ - TESTING("H5LTmake_dataset_char"); - /* Make dataset char */ - if ( H5LTmake_dataset_char( file_id, DSET1_NAME, rank, dims, data_char_in ) < 0 ) - goto out; + /*------------------------------------------------------------------------- + * H5LTmake_dataset_char + *------------------------------------------------------------------------- + */ - /* Read dataset */ - if ( H5LTread_dataset( file_id, DSET1_NAME, H5T_NATIVE_CHAR, data_char_out ) < 0 ) - goto out; + TESTING("H5LTmake_dataset_char"); - for (i = 0; i < DIM; i++) - { - if ( data_char_in[i] != data_char_out[i] ) { - goto out; - } - } + /* Make dataset char */ + if ( H5LTmake_dataset_char( file_id, DSET1_NAME, rank, dims, data_char_in ) < 0 ) + goto out; + + /* Read dataset */ + if ( H5LTread_dataset( file_id, DSET1_NAME, H5T_NATIVE_CHAR, data_char_out ) < 0 ) + goto out; - /* Read dataset */ - if ( H5LTread_dataset_char( file_id, DSET1_NAME, data_char_out ) < 0 ) - goto out; + for (i = 0; i < DIM; i++) + { + if ( data_char_in[i] != data_char_out[i] ) { + goto out; + } + } - for (i = 0; i < DIM; i++) - { - if ( data_char_in[i] != data_char_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset_char( file_id, DSET1_NAME, data_char_out ) < 0 ) + goto out; - PASSED(); + for (i = 0; i < DIM; i++) + { + if ( data_char_in[i] != data_char_out[i] ) { + goto out; + } + } + PASSED(); -/*------------------------------------------------------------------------- - * H5LTmake_dataset_short - *------------------------------------------------------------------------- - */ - TESTING("H5LTmake_dataset_short"); + /*------------------------------------------------------------------------- + * H5LTmake_dataset_short + *------------------------------------------------------------------------- + */ - /* Make dataset short */ - if ( H5LTmake_dataset_short( file_id, DSET2_NAME, rank, dims, data_short_in ) < 0 ) - goto out; + TESTING("H5LTmake_dataset_short"); - /* Read dataset */ - if ( H5LTread_dataset( file_id, DSET2_NAME, H5T_NATIVE_SHORT, data_short_out ) < 0 ) - goto out; + /* Make dataset short */ + if ( H5LTmake_dataset_short( file_id, DSET2_NAME, rank, dims, data_short_in ) < 0 ) + goto out; - for (i = 0; i < DIM; i++) - { - if ( data_short_in[i] != data_short_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset( file_id, DSET2_NAME, H5T_NATIVE_SHORT, data_short_out ) < 0 ) + goto out; - /* Read dataset */ - if ( H5LTread_dataset_short( file_id, DSET2_NAME, data_short_out ) < 0 ) - goto out; + for (i = 0; i < DIM; i++) + { + if ( data_short_in[i] != data_short_out[i] ) { + goto out; + } + } - for (i = 0; i < DIM; i++) - { - if ( data_short_in[i] != data_short_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset_short( file_id, DSET2_NAME, data_short_out ) < 0 ) + goto out; - PASSED(); + for (i = 0; i < DIM; i++) + { + if ( data_short_in[i] != data_short_out[i] ) { + goto out; + } + } -/*------------------------------------------------------------------------- - * H5LTmake_dataset_int - *------------------------------------------------------------------------- - */ + PASSED(); - TESTING("H5LTmake_dataset_int"); + /*------------------------------------------------------------------------- + * H5LTmake_dataset_int + *------------------------------------------------------------------------- + */ - /* Make dataset int */ - if ( H5LTmake_dataset_int( file_id, DSET3_NAME, rank, dims, data_int_in ) < 0 ) - goto out; + TESTING("H5LTmake_dataset_int"); - /* Read dataset */ - if ( H5LTread_dataset( file_id, DSET3_NAME, H5T_NATIVE_INT, data_int_out ) < 0 ) - goto out; + /* Make dataset int */ + if ( H5LTmake_dataset_int( file_id, DSET3_NAME, rank, dims, data_int_in ) < 0 ) + goto out; - for (i = 0; i < DIM; i++) - { - if ( data_int_in[i] != data_int_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset( file_id, DSET3_NAME, H5T_NATIVE_INT, data_int_out ) < 0 ) + goto out; - /* Read dataset */ - if ( H5LTread_dataset_int( file_id, DSET3_NAME, data_int_out ) < 0 ) - goto out; + for (i = 0; i < DIM; i++) + { + if ( data_int_in[i] != data_int_out[i] ) { + goto out; + } + } - for (i = 0; i < DIM; i++) - { - if ( data_int_in[i] != data_int_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset_int( file_id, DSET3_NAME, data_int_out ) < 0 ) + goto out; - PASSED(); + for (i = 0; i < DIM; i++) + { + if ( data_int_in[i] != data_int_out[i] ) { + goto out; + } + } + PASSED(); -/*------------------------------------------------------------------------- - * H5LTmake_dataset_long - *------------------------------------------------------------------------- - */ - TESTING("H5LTmake_dataset_long"); + /*------------------------------------------------------------------------- + * H5LTmake_dataset_long + *------------------------------------------------------------------------- + */ - /* Make dataset long */ - if ( H5LTmake_dataset_long( file_id, DSET4_NAME, rank, dims, data_long_in ) < 0 ) - goto out; + TESTING("H5LTmake_dataset_long"); - /* Read dataset */ - if ( H5LTread_dataset( file_id, DSET4_NAME, H5T_NATIVE_LONG, data_long_out ) < 0 ) - goto out; + /* Make dataset long */ + if ( H5LTmake_dataset_long( file_id, DSET4_NAME, rank, dims, data_long_in ) < 0 ) + goto out; - for (i = 0; i < DIM; i++) - { - if ( data_long_in[i] != data_long_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset( file_id, DSET4_NAME, H5T_NATIVE_LONG, data_long_out ) < 0 ) + goto out; - /* Read dataset */ - if ( H5LTread_dataset_long( file_id, DSET4_NAME, data_long_out ) < 0 ) - goto out; + for (i = 0; i < DIM; i++) + { + if ( data_long_in[i] != data_long_out[i] ) { + goto out; + } + } - for (i = 0; i < DIM; i++) - { - if ( data_long_in[i] != data_long_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset_long( file_id, DSET4_NAME, data_long_out ) < 0 ) + goto out; - PASSED(); + for (i = 0; i < DIM; i++) + { + if ( data_long_in[i] != data_long_out[i] ) { + goto out; + } + } + PASSED(); -/*------------------------------------------------------------------------- - * H5LTmake_dataset_float - *------------------------------------------------------------------------- - */ - TESTING("H5LTmake_dataset_float"); + /*------------------------------------------------------------------------- + * H5LTmake_dataset_float + *------------------------------------------------------------------------- + */ - /* Make dataset float */ - if ( H5LTmake_dataset_float( file_id, DSET5_NAME, rank, dims, data_float_in ) < 0 ) - goto out; + TESTING("H5LTmake_dataset_float"); - /* Read dataset */ - if ( H5LTread_dataset( file_id, DSET5_NAME, H5T_NATIVE_FLOAT, data_float_out ) < 0 ) - goto out; + /* Make dataset float */ + if ( H5LTmake_dataset_float( file_id, DSET5_NAME, rank, dims, data_float_in ) < 0 ) + goto out; - for (i = 0; i < DIM; i++) - { - if ( data_float_in[i] != data_float_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset( file_id, DSET5_NAME, H5T_NATIVE_FLOAT, data_float_out ) < 0 ) + goto out; - /* Read dataset */ - if ( H5LTread_dataset_float( file_id, DSET5_NAME, data_float_out ) < 0 ) - goto out; + for (i = 0; i < DIM; i++) + { + if ( data_float_in[i] != data_float_out[i] ) { + goto out; + } + } - for (i = 0; i < DIM; i++) - { - if ( data_float_in[i] != data_float_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset_float( file_id, DSET5_NAME, data_float_out ) < 0 ) + goto out; - PASSED(); + for (i = 0; i < DIM; i++) + { + if ( data_float_in[i] != data_float_out[i] ) { + goto out; + } + } + PASSED(); -/*------------------------------------------------------------------------- - * H5LTmake_dataset_double - *------------------------------------------------------------------------- - */ - TESTING("H5LTmake_dataset_double"); + /*------------------------------------------------------------------------- + * H5LTmake_dataset_double + *------------------------------------------------------------------------- + */ - /* Make dataset double */ - if ( H5LTmake_dataset_double( file_id, DSET6_NAME, rank, dims, data_double_in ) < 0 ) - goto out; + TESTING("H5LTmake_dataset_double"); - /* Read dataset */ - if ( H5LTread_dataset( file_id, DSET6_NAME, H5T_NATIVE_DOUBLE, data_double_out ) < 0 ) - goto out; + /* Make dataset double */ + if ( H5LTmake_dataset_double( file_id, DSET6_NAME, rank, dims, data_double_in ) < 0 ) + goto out; - for (i = 0; i < DIM; i++) - { - if ( data_double_in[i] != data_double_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset( file_id, DSET6_NAME, H5T_NATIVE_DOUBLE, data_double_out ) < 0 ) + goto out; - /* Read dataset */ - if ( H5LTread_dataset_double( file_id, DSET6_NAME, data_double_out ) < 0 ) - goto out; + for (i = 0; i < DIM; i++) + { + if ( data_double_in[i] != data_double_out[i] ) { + goto out; + } + } - for (i = 0; i < DIM; i++) - { - if ( data_double_in[i] != data_double_out[i] ) { - goto out; - } - } + /* Read dataset */ + if ( H5LTread_dataset_double( file_id, DSET6_NAME, data_double_out ) < 0 ) + goto out; - PASSED(); + for (i = 0; i < DIM; i++) + { + if ( data_double_in[i] != data_double_out[i] ) { + goto out; + } + } + PASSED(); -/*------------------------------------------------------------------------- - * H5LTmake_dataset_string - *------------------------------------------------------------------------- - */ - TESTING("H5LTmake_dataset_string"); + /*------------------------------------------------------------------------- + * H5LTmake_dataset_string + *------------------------------------------------------------------------- + */ - /* Make dataset string */ - if ( H5LTmake_dataset_string(file_id,DSET7_NAME,data_string_in) < 0 ) - goto out; + TESTING("H5LTmake_dataset_string"); - /* Read dataset */ - if ( H5LTread_dataset_string(file_id,DSET7_NAME,data_string_out) < 0 ) - goto out; + /* Make dataset string */ + if ( H5LTmake_dataset_string(file_id,DSET7_NAME,data_string_in) < 0 ) + goto out; - if ( strcmp(data_string_in,data_string_out) != 0 ) - goto out; + /* Read dataset */ + if ( H5LTread_dataset_string(file_id,DSET7_NAME,data_string_out) < 0 ) + goto out; + if ( strcmp(data_string_in,data_string_out) != 0 ) + goto out; -/*------------------------------------------------------------------------- - * end tests - *------------------------------------------------------------------------- - */ - /* Close the file. */ - H5Fclose( file_id ); + /*------------------------------------------------------------------------- + * end tests + *------------------------------------------------------------------------- + */ + + /* Close the file. */ + H5Fclose( file_id ); - PASSED(); + PASSED(); - return 0; + return 0; out: - /* Close the file. */ - H5_FAILED(); - return -1; + /* Close the file. */ + H5_FAILED(); + return -1; } /*------------------------------------------------------------------------- - * test attribute functions - *------------------------------------------------------------------------- - */ +* test attribute functions +*------------------------------------------------------------------------- +*/ static int test_attr(void) { @@ -477,575 +474,575 @@ out: } /*------------------------------------------------------------------------- - * make_attributes - *------------------------------------------------------------------------- - */ +* make_attributes +*------------------------------------------------------------------------- +*/ static herr_t make_attributes( hid_t loc_id, const char* obj_name ) { - int rank_out; - hsize_t *dims_out = 0; - H5T_class_t type_class; - size_t type_size; - int i; - - char attr_str_in[] = {"My attribute"}; - char attr_str_out[20]; - char attr_char_in[5] = {1,2,3,4,5}; - char attr_char_out[5]; - short attr_short_in[5] = {1,2,3,4,5}; - short attr_short_out[5]; - int attr_int_in[5] = {1,2,3,4,5}; - int attr_int_out[5]; - long attr_long_in[5] = {1,2,3,4,5}; - long attr_long_out[5]; - float attr_float_in[5] = {1,2,3,4,5}; - float attr_float_out[5]; - double attr_double_in[5] = {1,2,3,4,5}; - double attr_double_out[5]; - unsigned char attr_uchar_in[5] = {1,2,3,4,5}; - unsigned char attr_uchar_out[5]; - unsigned short attr_ushort_in[5] = {1,2,3,4,5}; - unsigned short attr_ushort_out[5]; - unsigned int attr_uint_in[5] = {1,2,3,4,5}; - unsigned int attr_uint_out[5]; - unsigned long attr_ulong_in[5] = {1,2,3,4,5}; - unsigned long attr_ulong_out[5]; + int rank_out; + hsize_t *dims_out = 0; + H5T_class_t type_class; + size_t type_size; + int i; + + char attr_str_in[] = {"My attribute"}; + char attr_str_out[20]; + char attr_char_in[5] = {1,2,3,4,5}; + char attr_char_out[5]; + short attr_short_in[5] = {1,2,3,4,5}; + short attr_short_out[5]; + int attr_int_in[5] = {1,2,3,4,5}; + int attr_int_out[5]; + long attr_long_in[5] = {1,2,3,4,5}; + long attr_long_out[5]; + float attr_float_in[5] = {1,2,3,4,5}; + float attr_float_out[5]; + double attr_double_in[5] = {1,2,3,4,5}; + double attr_double_out[5]; + unsigned char attr_uchar_in[5] = {1,2,3,4,5}; + unsigned char attr_uchar_out[5]; + unsigned short attr_ushort_in[5] = {1,2,3,4,5}; + unsigned short attr_ushort_out[5]; + unsigned int attr_uint_in[5] = {1,2,3,4,5}; + unsigned int attr_uint_out[5]; + unsigned long attr_ulong_in[5] = {1,2,3,4,5}; + unsigned long attr_ulong_out[5]; -/*------------------------------------------------------------------------- - * H5LTset_attribute_string test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_string test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_string"); + TESTING("H5LTset_attribute_string"); - /* Set the attribute */ - if ( H5LTset_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_in ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_in ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_string test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_string test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_string"); + TESTING("H5LTget_attribute_string"); - /* Get the attribute */ - if ( H5LTget_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_out ) < 0 ) + return -1; - if ( strcmp( attr_str_in, attr_str_out ) != 0 ) - { - return -1; - } + if ( strcmp( attr_str_in, attr_str_out ) != 0 ) + { + return -1; + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_char test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_char test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_char"); + TESTING("H5LTset_attribute_char"); - /* Set the attribute */ - if ( H5LTset_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_char test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_char test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_char"); + TESTING("H5LTget_attribute_char"); - /* Get the attribute */ - if ( H5LTget_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_char_in[i] != attr_char_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_char_in[i] != attr_char_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR2_NAME, H5T_NATIVE_CHAR, attr_char_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR2_NAME, H5T_NATIVE_CHAR, attr_char_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_char_in[i] != attr_char_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_char_in[i] != attr_char_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_short test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_short test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_short"); + TESTING("H5LTset_attribute_short"); - /* Set the attribute */ - if ( H5LTset_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_short test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_short test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_short"); + TESTING("H5LTget_attribute_short"); - /* Get the attribute */ - if ( H5LTget_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_short_in[i] != attr_short_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_short_in[i] != attr_short_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR3_NAME, H5T_NATIVE_SHORT, attr_short_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR3_NAME, H5T_NATIVE_SHORT, attr_short_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_short_in[i] != attr_short_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_short_in[i] != attr_short_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_int test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_int test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_int"); + TESTING("H5LTset_attribute_int"); - /* Set the attribute */ - if ( H5LTset_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_int test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_int test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_int"); + TESTING("H5LTget_attribute_int"); - /* Get the attribute */ - if ( H5LTget_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_int_in[i] != attr_int_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_int_in[i] != attr_int_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR4_NAME, H5T_NATIVE_INT, attr_int_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR4_NAME, H5T_NATIVE_INT, attr_int_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_int_in[i] != attr_int_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_int_in[i] != attr_int_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_long test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_long test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_long"); + TESTING("H5LTset_attribute_long"); - /* Set the attribute */ - if ( H5LTset_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_long test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_long test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_long"); + TESTING("H5LTget_attribute_long"); - /* Get the attribute */ - if ( H5LTget_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_long_in[i] != attr_long_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_long_in[i] != attr_long_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR5_NAME, H5T_NATIVE_LONG, attr_long_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR5_NAME, H5T_NATIVE_LONG, attr_long_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_long_in[i] != attr_long_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_long_in[i] != attr_long_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_uchar test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_uchar test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_uchar"); + TESTING("H5LTset_attribute_uchar"); - /* Set the attribute */ - if ( H5LTset_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_uchar test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_uchar test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_uchar"); + TESTING("H5LTget_attribute_uchar"); - /* Get the attribute */ - if ( H5LTget_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_uchar_in[i] != attr_uchar_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_uchar_in[i] != attr_uchar_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR6_NAME, H5T_NATIVE_UCHAR, attr_uchar_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR6_NAME, H5T_NATIVE_UCHAR, attr_uchar_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_uchar_in[i] != attr_uchar_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_uchar_in[i] != attr_uchar_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_ushort test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_ushort test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_ushort"); + TESTING("H5LTset_attribute_ushort"); - /* Set the attribute */ - if ( H5LTset_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_ushort test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_ushort test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_ushort"); + TESTING("H5LTget_attribute_ushort"); - /* Get the attribute */ - if ( H5LTget_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_ushort_in[i] != attr_ushort_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_ushort_in[i] != attr_ushort_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR7_NAME, H5T_NATIVE_USHORT, attr_ushort_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR7_NAME, H5T_NATIVE_USHORT, attr_ushort_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_ushort_in[i] != attr_ushort_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_ushort_in[i] != attr_ushort_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_int test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_int test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_uint"); + TESTING("H5LTset_attribute_uint"); - /* Set the attribute */ - if ( H5LTset_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_int test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_int test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_uint"); + TESTING("H5LTget_attribute_uint"); - /* Get the attribute */ - if ( H5LTget_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_uint_in[i] != attr_uint_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_uint_in[i] != attr_uint_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR8_NAME, H5T_NATIVE_UINT, attr_uint_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR8_NAME, H5T_NATIVE_UINT, attr_uint_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_uint_in[i] != attr_uint_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_uint_in[i] != attr_uint_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_ulong test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_ulong test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_ulong"); + TESTING("H5LTset_attribute_ulong"); - /* Set the attribute */ - if ( H5LTset_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_long test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_long test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_ulong"); + TESTING("H5LTget_attribute_ulong"); - /* Get the attribute */ - if ( H5LTget_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_ulong_in[i] != attr_ulong_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_ulong_in[i] != attr_ulong_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR9_NAME, H5T_NATIVE_ULONG, attr_ulong_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR9_NAME, H5T_NATIVE_ULONG, attr_ulong_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_ulong_in[i] != attr_ulong_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_ulong_in[i] != attr_ulong_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_float test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_float test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_float"); + TESTING("H5LTset_attribute_float"); - /* Set the attribute */ - if ( H5LTset_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_float test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_float test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_float"); + TESTING("H5LTget_attribute_float"); - /* Get the attribute */ - if ( H5LTget_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_float_in[i] != attr_float_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_float_in[i] != attr_float_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR10_NAME, H5T_NATIVE_FLOAT, attr_float_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR10_NAME, H5T_NATIVE_FLOAT, attr_float_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_float_in[i] != attr_float_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_float_in[i] != attr_float_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTset_attribute_double test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTset_attribute_double test + *------------------------------------------------------------------------- + */ - TESTING("H5LTset_attribute_double"); + TESTING("H5LTset_attribute_double"); - /* Set the attribute */ - if ( H5LTset_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_in, (size_t)5 ) < 0 ) - return -1; + /* Set the attribute */ + if ( H5LTset_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_in, (size_t)5 ) < 0 ) + return -1; - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_double test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_double test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_double"); + TESTING("H5LTget_attribute_double"); - /* Get the attribute */ - if ( H5LTget_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_double_in[i] != attr_double_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_double_in[i] != attr_double_out[i] ) { + return -1; + } + } - /* Get the attribute */ - if ( H5LTget_attribute( loc_id, obj_name, ATTR11_NAME, H5T_NATIVE_DOUBLE, attr_double_out ) < 0 ) - return -1; + /* Get the attribute */ + if ( H5LTget_attribute( loc_id, obj_name, ATTR11_NAME, H5T_NATIVE_DOUBLE, attr_double_out ) < 0 ) + return -1; - for (i = 0; i < 5; i++) - { - if ( attr_double_in[i] != attr_double_out[i] ) { - return -1; - } - } + for (i = 0; i < 5; i++) + { + if ( attr_double_in[i] != attr_double_out[i] ) { + return -1; + } + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_ndims test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_ndims test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_ndims"); + TESTING("H5LTget_attribute_ndims"); - if ( H5LTget_attribute_ndims( loc_id, obj_name, ATTR2_NAME, &rank_out ) < 0 ) - return -1; + if ( H5LTget_attribute_ndims( loc_id, obj_name, ATTR2_NAME, &rank_out ) < 0 ) + return -1; - if ( rank_out != 1 ) { - return -1; - } + if ( rank_out != 1 ) { + return -1; + } - PASSED(); + PASSED(); -/*------------------------------------------------------------------------- - * H5LTget_attribute_info test - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5LTget_attribute_info test + *------------------------------------------------------------------------- + */ - TESTING("H5LTget_attribute_info"); + TESTING("H5LTget_attribute_info"); - dims_out = malloc( sizeof(hsize_t) * rank_out ); + dims_out = (hsize_t*) malloc( sizeof(hsize_t) * rank_out ); - if ( H5LTget_attribute_info( loc_id, obj_name, ATTR2_NAME, dims_out, &type_class, - &type_size) < 0 ) - return -1; + if ( H5LTget_attribute_info( loc_id, obj_name, ATTR2_NAME, dims_out, &type_class, + &type_size) < 0 ) + return -1; - for (i = 0; i < rank_out; i++) - { - if ( dims_out[i] != 5 ) { - return -1; - } - } + for (i = 0; i < rank_out; i++) + { + if ( dims_out[i] != 5 ) { + return -1; + } + } - if ( type_class != H5T_INTEGER ) { - return -1; - } + if ( type_class != H5T_INTEGER ) { + return -1; + } - if ( dims_out ) - free( dims_out ); + if ( dims_out ) + free( dims_out ); - PASSED(); + PASSED(); - return 0; + return 0; } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_integers(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_integers(). +*------------------------------------------------------------------------- +*/ static int test_integers(void) { hid_t dtype; @@ -1094,9 +1091,9 @@ out: } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_fps(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_fps(). +*------------------------------------------------------------------------- +*/ static int test_fps(void) { hid_t dtype; @@ -1145,9 +1142,9 @@ out: } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_strings(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_strings(). +*------------------------------------------------------------------------- +*/ static int test_strings(void) { hid_t dtype; @@ -1231,9 +1228,9 @@ out: } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_opaques(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_opaques(). +*------------------------------------------------------------------------- +*/ static int test_opaques(void) { hid_t dtype; @@ -1280,9 +1277,9 @@ out: } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_enums(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_enums(). +*------------------------------------------------------------------------- +*/ static int test_enums(void) { hid_t dtype; @@ -1321,8 +1318,8 @@ static int test_enums(void) if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) goto out; /*if(strcmp(dt_str, "H5T_ENUM {\n H5T_STD_I32LE;\n \"RED\" 5;\n \"GREEN\" 6;\n \"BLUE\" 7;\n \"WHITE\" 8;\n }")) { - printf("dt=\n%s\n", dt_str); - goto out; + printf("dt=\n%s\n", dt_str); + goto out; }*/ free(dt_str); @@ -1338,9 +1335,9 @@ out: } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_variables(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_variables(). +*------------------------------------------------------------------------- +*/ static int test_variables(void) { hid_t dtype; @@ -1393,9 +1390,9 @@ out: } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_arrays(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_arrays(). +*------------------------------------------------------------------------- +*/ static int test_arrays(void) { hid_t dtype; @@ -1431,8 +1428,8 @@ static int test_arrays(void) if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) goto out; /*if(strcmp(dt_str, "H5T_ARRAY { [5][7][13] H5T_ARRAY { [17][19] H5T_COMPOUND { H5T_STD_I8BE \"arr_compound_1\"; H5T_STD_I32BE \"arr_compound_2\"; } } }")) { - printf("dt=\n%s\n", dt_str); - goto out; + printf("dt=\n%s\n", dt_str); + goto out; }*/ free(dt_str); @@ -1448,9 +1445,9 @@ out: } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_compounds(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_compounds(). +*------------------------------------------------------------------------- +*/ static int test_compounds(void) { hid_t dtype; @@ -1513,9 +1510,9 @@ out: } /*------------------------------------------------------------------------- - * subroutine for test_text_dtype(): test_complicated_compound(). - *------------------------------------------------------------------------- - */ +* subroutine for test_text_dtype(): test_complicated_compound(). +*------------------------------------------------------------------------- +*/ static int test_complicated_compound(void) { hid_t dtype; @@ -1532,8 +1529,8 @@ static int test_complicated_compound(void) /* compose the name of the file to open, using the srcdir, if appropriate */ if(srcdir) { - strcpy(filename, srcdir); - strcat(filename, "/"); + strcpy(filename, srcdir); + strcat(filename, "/"); } strcat(filename, INPUT_FILE); @@ -1541,14 +1538,14 @@ static int test_complicated_compound(void) fp = fopen(filename, "r"); if(fp == NULL) { - printf( "Could not find file %s. Try set $srcdir \n", filename); - goto out; + printf( "Could not find file %s. Try set $srcdir \n", filename); + goto out; } /* This part reads in the input as a string in a slow manner. GNU C - * Library has convenient function getline() but isn't available on - * all machines. - */ + * Library has convenient function getline() but isn't available on + * all machines. + */ if((line = (char*)calloc(size, sizeof(char)))==NULL) goto out; if(fgets(line, (int)size, fp)==NULL) @@ -1593,9 +1590,9 @@ out: } /*------------------------------------------------------------------------- - * test H5LTtext_to_dtype function - *------------------------------------------------------------------------- - */ +* test H5LTtext_to_dtype function +*------------------------------------------------------------------------- +*/ static int test_text_dtype(void) { TESTING("H5LTtext_to_dtype"); @@ -1634,30 +1631,30 @@ out: } /*------------------------------------------------------------------------- - * the main program - *------------------------------------------------------------------------- - */ +* the main program +*------------------------------------------------------------------------- +*/ int main( void ) { - int nerrors=0; + int nerrors=0; - /* test dataset functions */ - nerrors += test_dsets(); + /* test dataset functions */ + nerrors += test_dsets(); - /* test attribute functions */ - nerrors += test_attr(); + /* test attribute functions */ + nerrors += test_attr(); - /* test text-dtype functions */ - nerrors += test_text_dtype(); + /* test text-dtype functions */ + nerrors += test_text_dtype(); - /* check for errors */ - if (nerrors) - goto error; + /* check for errors */ + if (nerrors) + goto error; - return 0; + return 0; error: - return 1; + return 1; } diff --git a/hl/test/test_table.c b/hl/test/test_table.c index bd8dd79..fd08ed9 100644 --- a/hl/test/test_table.c +++ b/hl/test/test_table.c @@ -1,17 +1,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +* Copyright by The HDF Group. * +* Copyright by the Board of Trustees of the University of Illinois. * +* All rights reserved. * +* * +* This file is part of HDF5. The full HDF5 copyright notice, including * +* terms governing use, modification, and redistribution, is contained in * +* the files COPYING and Copyright.html. COPYING can be found at the root * +* of the source code distribution tree; Copyright.html can be found at the * +* root level of an installed copy of the electronic HDF5 document set and * +* is linked from the top-level documents page. It can also be found at * +* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * +* access to either file, you may request a copy from help@hdfgroup.org. * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdlib.h> #include <string.h> @@ -24,28 +24,28 @@ /*------------------------------------------------------------------------- - * Table API test - * - * Functions tested: - * - * H5TBmake_table - * H5TBread_table - * H5TBwrite_records - * H5TBread_records - * H5TBappend_records - * H5TBinsert_record - * H5TBdelete_record - * H5TBcombine_tables - * H5TBwrite_fields_name - * H5TBread_fields_name - * H5TBwrite_fields_index - * H5TBinsert_field - * H5TBdelete_field - * H5TBget_table_info - * H5TBget_field_info - * - *------------------------------------------------------------------------- - */ +* Table API test +* +* Functions tested: +* +* H5TBmake_table +* H5TBread_table +* H5TBwrite_records +* H5TBread_records +* H5TBappend_records +* H5TBinsert_record +* H5TBdelete_record +* H5TBcombine_tables +* H5TBwrite_fields_name +* H5TBread_fields_name +* H5TBwrite_fields_index +* H5TBinsert_field +* H5TBdelete_field +* H5TBget_table_info +* H5TBget_field_info +* +*------------------------------------------------------------------------- +*/ #define TITLE "Title" #define NFIELDS 5 @@ -55,9 +55,9 @@ #define TESTING2(WHAT) {printf("%-70s", "Testing " WHAT); fflush(stdout);} /*------------------------------------------------------------------------- - * structure used for all tests, a particle with properties - *------------------------------------------------------------------------- - */ +* structure used for all tests, a particle with properties +*------------------------------------------------------------------------- +*/ typedef struct particle_t { char name[16]; @@ -68,19 +68,9 @@ typedef struct particle_t } particle_t; /*------------------------------------------------------------------------- - * local auxiliary functions - *------------------------------------------------------------------------- - */ - -static hid_t h5file_open(const char *fname, unsigned flags); -static int cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf ); -static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords, - particle_t *rbuf, particle_t *wbuf); - -/*------------------------------------------------------------------------- - * a subset of particle_t, with latitude and longitude fields - *------------------------------------------------------------------------- - */ +* a subset of particle_t, with latitude and longitude fields +*------------------------------------------------------------------------- +*/ typedef struct position_t { long longi; @@ -88,9 +78,9 @@ typedef struct position_t } position_t; /*------------------------------------------------------------------------- - * a subset of particle_t, with name and pressure fields - *------------------------------------------------------------------------- - */ +* a subset of particle_t, with name and pressure fields +*------------------------------------------------------------------------- +*/ typedef struct namepressure_t { char name[16]; @@ -98,9 +88,9 @@ typedef struct namepressure_t } namepressure_t; /*------------------------------------------------------------------------- - * an extended particle, used in the insert field test - *------------------------------------------------------------------------- - */ +* an extended particle, used in the insert field test +*------------------------------------------------------------------------- +*/ typedef struct particle2_t { char name[16]; @@ -112,9 +102,9 @@ typedef struct particle2_t } particle2_t; /*------------------------------------------------------------------------- - * a particle with one field less, used in the delete field test - *------------------------------------------------------------------------- - */ +* a particle with one field less, used in the delete field test +*------------------------------------------------------------------------- +*/ typedef struct particle3_t { char name[16]; @@ -126,16 +116,16 @@ typedef struct particle3_t /*------------------------------------------------------------------------- - * function to open an HDF5 file and return its file identifier - *------------------------------------------------------------------------- - */ +* function to open an HDF5 file and return its file identifier +*------------------------------------------------------------------------- +*/ static hid_t h5file_open(const char *fname, unsigned flags) { - + hid_t fid; /* identifier for the file */ char *srcdir = getenv("srcdir"); /* the source directory */ char data_file[512]=""; /* buffer to hold name of existing file */ - + /* compose the name of the file to open, using the srcdir, if appropriate */ if (srcdir) { @@ -143,21 +133,21 @@ static hid_t h5file_open(const char *fname, unsigned flags) strcat(data_file,"/"); } strcat(data_file,fname); - + /* open */ if ((fid = H5Fopen(data_file,flags,H5P_DEFAULT))<0) { fprintf(stderr,"Error: Cannot open file <%s>\n",data_file ); exit(1); } - + return fid; } /*------------------------------------------------------------------------- - * function that compares one particle - *------------------------------------------------------------------------- - */ +* function that compares one particle +*------------------------------------------------------------------------- +*/ static int cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf ) { if ( ( strcmp( rbuf[i].name, wbuf[j].name ) != 0 ) || @@ -177,9 +167,9 @@ static int cmp_par(hsize_t i, hsize_t j, particle_t *rbuf, particle_t *wbuf ) } /*------------------------------------------------------------------------- - * function to compare deleted records - *------------------------------------------------------------------------- - */ +* function to compare deleted records +*------------------------------------------------------------------------- +*/ static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords, particle_t *rbuf, particle_t *wbuf) { @@ -204,11 +194,11 @@ static int compare_deleted(hsize_t rrecords, hsize_t dstart, hsize_t drecords, /*------------------------------------------------------------------------- - * the test program - *------------------------------------------------------------------------- - */ +* the test program +*------------------------------------------------------------------------- +*/ -int test_table(hid_t fid, int write) +static int test_table(hid_t fid, int do_write) { hid_t fid1; hid_t fid2; @@ -277,39 +267,39 @@ int test_table(hid_t fid, int write) {"six", 6.0f}, {"seven", 7.0f}, }; - - + + /*------------------------------------------------------------------------- * initialize table parameters * field offsets and sizes used in the fields functions *------------------------------------------------------------------------- */ - + size_t field_offset_pos[2]= { HOFFSET( position_t, longi ), - HOFFSET( position_t, lati ) + HOFFSET( position_t, lati ) }; size_t field_offset_namepre[2]= { HOFFSET( namepressure_t, name ), - HOFFSET( namepressure_t, pressure ) + HOFFSET( namepressure_t, pressure ) }; size_t field_sizes_pos[2]= { sizeof(position_in[0].longi), - sizeof(position_in[0].lati) + sizeof(position_in[0].lati) }; size_t field_sizes_namepre[2]= { sizeof(namepre_in[0].name), - sizeof(namepre_in[0].pressure) + sizeof(namepre_in[0].pressure) }; size_t field_sizes_pre[1]= { sizeof(namepre_in[0].pressure) }; - + /*------------------------------------------------------------------------- * query table test *------------------------------------------------------------------------- @@ -318,7 +308,7 @@ int test_table(hid_t fid, int write) size_t sizes_out[NFIELDS]; size_t offset_out[NFIELDS]; size_t size_out; - + /*------------------------------------------------------------------------- * initialize table parameters * field indexes (zero based) used in the fields functions @@ -329,7 +319,7 @@ int test_table(hid_t fid, int write) int field_index_pos[2] = { 1,4 }; int field_index_namepre[2] = { 0,2 }; int field_index[NFIELDS] = { 0,1,2,3,4 }; - + /*------------------------------------------------------------------------- * initialize table parameters * size and the offsets of struct members in memory @@ -351,48 +341,48 @@ int test_table(hid_t fid, int write) sizeof( rbuf2[0].temperature), sizeof( rbuf2[0].lati), sizeof( rbuf2[0].new_field)}; - /*------------------------------------------------------------------------- - * initialize table parameters - * size and the offsets of struct members in memory - * these are used for the delete field test - *------------------------------------------------------------------------- + /*------------------------------------------------------------------------- + * initialize table parameters + * size and the offsets of struct members in memory + * these are used for the delete field test + *------------------------------------------------------------------------- */ size_t dst_size3 = sizeof( particle3_t ); size_t dst_offset3[NFIELDS-1] = { HOFFSET( particle3_t, name ), HOFFSET( particle3_t, longi ), HOFFSET( particle3_t, temperature ), HOFFSET( particle3_t, lati )}; - + size_t dst_sizes3[NFIELDS-1] = { sizeof( rbuf3[0].name), sizeof( rbuf3[0].longi), sizeof( rbuf3[0].temperature), sizeof( rbuf3[0].lati)}; - - - /*------------------------------------------------------------------------- - * initialize table parameters - * 1) size and the offsets of struct members in memory - * 2) field names - * 3) define a HDF5 type for the fields - *------------------------------------------------------------------------- + + + /*------------------------------------------------------------------------- + * initialize table parameters + * 1) size and the offsets of struct members in memory + * 2) field names + * 3) define a HDF5 type for the fields + *------------------------------------------------------------------------- */ - + size_t type_size_mem = sizeof( particle_t ); size_t field_offset[NFIELDS]= { HOFFSET( particle_t, name ), - HOFFSET( particle_t, longi ), - HOFFSET( particle_t, pressure ), - HOFFSET( particle_t, temperature ), - HOFFSET( particle_t, lati ) + HOFFSET( particle_t, longi ), + HOFFSET( particle_t, pressure ), + HOFFSET( particle_t, temperature ), + HOFFSET( particle_t, lati ) }; size_t field_size[NFIELDS] = { sizeof( rbuf[0].name), - sizeof( rbuf[0].longi), - sizeof( rbuf[0].pressure), - sizeof( rbuf[0].temperature), - sizeof( rbuf[0].lati) + sizeof( rbuf[0].longi), + sizeof( rbuf[0].pressure), + sizeof( rbuf[0].temperature), + sizeof( rbuf[0].lati) }; const char *field_names[NFIELDS] = { "Name","Longitude","Pressure","Temperature","Latitude" }; @@ -404,7 +394,7 @@ int test_table(hid_t fid, int write) field_type[2] = H5T_NATIVE_FLOAT; field_type[3] = H5T_NATIVE_DOUBLE; field_type[4] = H5T_NATIVE_INT; - + /*------------------------------------------------------------------------- * * Functions tested: @@ -414,37 +404,37 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - if (write) + if (do_write) { TESTING2("making table"); - + if (H5TBmake_table(TITLE,fid,"table1",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill,compress,wbuf)<0) goto out; PASSED(); } - + TESTING2("reading table"); - + /*------------------------------------------------------------------------- * read the table *------------------------------------------------------------------------- */ - + if (H5TBread_table(fid,"table1",type_size_mem,field_offset,field_size,rbuf)<0) goto out; - + /* compare the extracted table with the original array */ for( i = 0; i < NRECORDS; i++ ) { if (cmp_par(i,i,rbuf,wbuf)<0) goto out; } - + PASSED(); - - + + /*------------------------------------------------------------------------- * * Functions tested: @@ -453,16 +443,16 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - if (write) + if (do_write) { TESTING2("writing records"); - + /* create an empty table */ if (H5TBmake_table(TITLE,fid,"table2",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill,compress,0)<0) goto out; - + /*------------------------------------------------------------------------- * write records, start at 0, write 8 * pos = 0 1 2 3 4 5 6 7 @@ -474,21 +464,21 @@ int test_table(hid_t fid, int write) if (H5TBwrite_records(fid,"table2",wstart,wrecords,type_size_mem,field_offset, field_size,wbuf)<0) goto out; - + /* read it back */ if (H5TBread_table(fid,"table2",type_size_mem,field_offset,field_size,rbuf)<0) goto out; - + /* compare */ for( i = 0; i < NRECORDS; i++ ) { if (cmp_par(i,i,rbuf,wbuf)<0) goto out; } - + PASSED(); } - + /*------------------------------------------------------------------------- * * Functions tested: @@ -497,32 +487,32 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - + TESTING2("reading records"); - + /*------------------------------------------------------------------------- * read records, start at 0, read 8 * pos = 0 1 2 3 4 5 6 7 * data= 0 1 2 3 4 5 6 7 *------------------------------------------------------------------------- */ - + /*------------------------------------------------------------------------- * for the read test we cannot use "table2" because it has been appended * we use the original "table1" instead *------------------------------------------------------------------------- */ - if(write) + if(do_write) strcpy(tname,"table2"); else strcpy(tname,"table1"); - + rstart=0; rrecords=8; if (H5TBread_records(fid,tname,rstart,rrecords,type_size_mem,field_offset, field_size,rbuf)<0) goto out; - + /* compare */ for( i=(int)rstart; i<(int)rrecords; i++) { @@ -530,7 +520,7 @@ int test_table(hid_t fid, int write) goto out; } PASSED(); - + /*------------------------------------------------------------------------- * * Functions tested: @@ -540,10 +530,10 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - if (write) + if (do_write) { TESTING2("appending records"); - + /*------------------------------------------------------------------------- * append 2 records * pos = 0 1 2 3 4 5 6 7 8 9 @@ -553,15 +543,15 @@ int test_table(hid_t fid, int write) arecords=2; if (H5TBappend_records(fid,"table2",arecords,type_size_mem,field_offset,field_size,abuf)<0) return 1; - + if (H5TBget_table_info(fid,"table2",&rfields,&rrecords)<0) return 1; - + rstart=0; rrecords=NRECORDS+arecords; if (H5TBread_records(fid,"table2",rstart,rrecords,type_size_mem,field_offset, field_size,rbuf)<0) return 1; - + /* compare */ wrecords=8; for( i=(int)rstart; i<(int)wrecords; i++) @@ -576,7 +566,7 @@ int test_table(hid_t fid, int write) } PASSED(); } - + /*------------------------------------------------------------------------- * * Functions tested: @@ -586,10 +576,10 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - if (write) + if (do_write) { TESTING2("inserting records"); - + /*------------------------------------------------------------------------- * insert 2 records * pos = 0 1 2 3 4 5 6 7 8 9 10 11 @@ -599,14 +589,14 @@ int test_table(hid_t fid, int write) istart=1; irecords=2; if (H5TBinsert_record(fid,"table2",istart,irecords,type_size_mem,field_offset,field_size,ibuf)<0) return 1; - + if (H5TBget_table_info(fid,"table2",&rfields,&rrecords)<0) return 1; - + if (H5TBread_records(fid,"table2",rstart,rrecords,type_size_mem,field_offset, field_size,rbuf)<0) return 1; - + /* compare */ for( i=0; i<12; i++) { @@ -636,7 +626,7 @@ int test_table(hid_t fid, int write) } PASSED(); } - + /*------------------------------------------------------------------------- * * Functions tested: @@ -646,17 +636,17 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - if (write) + if (do_write) { TESTING2("deleting records"); - + /*------------------------------------------------------------------------- * Create a table * pos = 0 1 2 3 4 5 6 7 * data= 0 1 2 3 4 5 6 7 *------------------------------------------------------------------------- */ - + for( i=0; i<NRECORDS; i++) { wbufd[i].lati = wbuf[i].lati; @@ -664,15 +654,15 @@ int test_table(hid_t fid, int write) wbufd[i].pressure = wbuf[i].pressure; wbufd[i].temperature = wbuf[i].temperature; strcpy(wbufd[i].name, wbuf[i].name ); - + } - - + + if (H5TBmake_table(TITLE,fid,"table3",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill,compress,wbufd)<0) goto out; - + /*------------------------------------------------------------------------- * Delete records, start at 2, delete 3 * pos = 0 1 2 3 4 @@ -682,21 +672,21 @@ int test_table(hid_t fid, int write) dstart=2; drecords=3; if (H5TBdelete_record(fid,"table3",dstart,drecords)<0) goto out; - + if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0) goto out; - + rstart=0; if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset, field_size,rbuf)<0) goto out; - + /* compare */ nrecords=NRECORDS; assert(rrecords == nrecords-drecords); if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0) goto out; - + /*------------------------------------------------------------------------- * reset compare buffer *------------------------------------------------------------------------- @@ -706,7 +696,7 @@ int test_table(hid_t fid, int write) { wbufd[i] = rbuf[i]; } - + /*------------------------------------------------------------------------- * Delete records, start at 0, delete 2 * pos = 0 1 2 @@ -716,20 +706,20 @@ int test_table(hid_t fid, int write) dstart=0; drecords=2; if (H5TBdelete_record(fid,"table3",dstart,drecords)<0) goto out; - + if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0) goto out; - + rstart=0; if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset, field_size,rbuf)<0) goto out; - + /* Compare */ assert(rrecords == nrecords-drecords); if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0) goto out; - + /*------------------------------------------------------------------------- * reset compare buffer *------------------------------------------------------------------------- @@ -739,7 +729,7 @@ int test_table(hid_t fid, int write) { wbufd[i] = rbuf[i]; } - + /*------------------------------------------------------------------------- * Delete records, start at 1, delete 1 * pos = 0 1 @@ -749,20 +739,20 @@ int test_table(hid_t fid, int write) dstart=1; drecords=1; if (H5TBdelete_record(fid,"table3",dstart,drecords)<0) goto out; - + if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0) goto out; - + rstart=0; if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset, field_size,rbuf)<0) goto out; - + /* Compare */ assert(rrecords == nrecords-drecords); if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0) goto out; - + /*------------------------------------------------------------------------- * reset compare buffer *------------------------------------------------------------------------- @@ -772,7 +762,7 @@ int test_table(hid_t fid, int write) { wbufd[i] = rbuf[i]; } - + /*------------------------------------------------------------------------- * Delete records, start at 0, delete 1 * pos = 0 @@ -782,20 +772,20 @@ int test_table(hid_t fid, int write) dstart=0; drecords=1; if (H5TBdelete_record(fid,"table3",dstart,drecords)<0) goto out; - + if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0) goto out; - + rstart=0; if (H5TBread_records(fid,"table3",rstart,rrecords,type_size_mem,field_offset, field_size,rbuf)<0) goto out; - + /* Compare */ assert(rrecords == nrecords-drecords); if (compare_deleted(rrecords,dstart,drecords,rbuf,wbufd)<0) goto out; - + /*------------------------------------------------------------------------- * reset compare buffer *------------------------------------------------------------------------- @@ -805,11 +795,11 @@ int test_table(hid_t fid, int write) { wbufd[i] = rbuf[i]; } - + /* Read complete table */ if (H5TBread_table(fid,"table3",type_size_mem,field_offset,field_size,rbuf)<0) goto out; - + /* Compare */ for( i=0; i<rrecords; i++) { @@ -828,16 +818,16 @@ int test_table(hid_t fid, int write) dstart=0; drecords=1; if (H5TBdelete_record(fid,"table3",dstart,drecords)<0) goto out; - + if (H5TBget_table_info(fid,"table3",&rfields,&rrecords)<0) goto out; - + if (rrecords) goto out; - + PASSED(); } - + /*------------------------------------------------------------------------- * * Functions tested: @@ -847,11 +837,11 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - - if (write) + + if (do_write) { TESTING2("adding records"); - + /* create 2 tables */ if (H5TBmake_table(TITLE,fid,"table4",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, @@ -861,18 +851,18 @@ int test_table(hid_t fid, int write) field_names,field_offset,field_type, chunk_size,fill,compress,wbuf)<0) goto out; - + /* add the records from "table4" to "table5" */ start1 = 3; nrecords = 2; start2 = 6; if ( H5TBadd_records_from(fid,"table4",start1,nrecords,"table5",start2)<0) goto out; - + /* read final table */ if (H5TBread_table(fid,"table5",type_size_mem,field_offset,field_size,rbuf)<0) goto out; - + /* compare */ for( i = 0; i < NRECORDS+2; i++ ) { @@ -894,10 +884,10 @@ int test_table(hid_t fid, int write) goto out; } } - + PASSED(); } - + /*------------------------------------------------------------------------- * * Functions tested: @@ -907,11 +897,11 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - - if (write) + + if (do_write) { TESTING2("combining tables"); - + /* create 2 tables */ if (H5TBmake_table(TITLE,fid,"table6",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, @@ -921,15 +911,15 @@ int test_table(hid_t fid, int write) field_names,field_offset,field_type, chunk_size,fill,compress,wbuf)<0) goto out; - + /* combine the two tables into a third */ if ( H5TBcombine_tables(fid,"table6",fid,"table7","table8")<0) goto out; - + /* read merged table */ if (H5TBread_table(fid,"table8",type_size_mem,field_offset,field_size,rbufc)<0) goto out; - + /* compare */ for( i = 0; i < NRECORDS*2; i++ ) { @@ -944,16 +934,16 @@ int test_table(hid_t fid, int write) goto out; } } - + /*------------------------------------------------------------------------- * multi file test *------------------------------------------------------------------------- */ - + /* create 2 files using default properties. */ fid1 = H5Fcreate("combine_tables1.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT); fid2 = H5Fcreate("combine_tables2.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT); - + /* create 2 tables, one in each file */ if (H5TBmake_table(TITLE,fid1,"table1",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, @@ -963,15 +953,15 @@ int test_table(hid_t fid, int write) field_names,field_offset,field_type, chunk_size,fill,compress,wbuf)<0) goto out; - + /* combine the two tables into a third */ if ( H5TBcombine_tables(fid1,"table1",fid2,"table2","table3")<0) goto out; - + /* read merged table */ if (H5TBread_table(fid1,"table3",type_size_mem,field_offset,field_size,rbufc)<0) goto out; - + /* compare */ for( i = 0; i < NRECORDS*2; i++ ) { @@ -986,15 +976,15 @@ int test_table(hid_t fid, int write) goto out; } } - + /* close files */ H5Fclose(fid1); H5Fclose(fid2); - + PASSED(); } - - + + /*------------------------------------------------------------------------- * * Functions tested: @@ -1003,39 +993,39 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - if (write) + if (do_write) { TESTING2("writing fields by name"); - + /* make an empty table with fill values */ if (H5TBmake_table(TITLE,fid,"table9",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill1,compress,0)<0) goto out; - + /* write the pressure field starting at record 2 */ start = 2; nrecords = NRECORDS_ADD; if (H5TBwrite_fields_name(fid,"table9","Pressure",start,nrecords,sizeof(float), 0,field_sizes_pre,pressure_in)<0) goto out; - + /* write the new longitude and latitude information starting at record 2 */ start = 2; nrecords = 3; if (H5TBwrite_fields_name(fid,"table9","Latitude,Longitude",start,nrecords,sizeof(position_t), field_offset_pos,field_sizes_pos,position_in)<0) goto out; - + /* read back the all table */ start = 0; nrecords = NRECORDS; if (H5TBread_table(fid,"table9",type_size_mem,field_offset,field_size,rbuf)<0) goto out; - + { - - + + /* compare the read values with the initial values */ for( i = 0; i < NRECORDS; i++ ) { @@ -1054,12 +1044,12 @@ int test_table(hid_t fid, int write) } } } - - - + + + PASSED(); } /*write*/ - + /*------------------------------------------------------------------------- * * Functions tested: @@ -1069,18 +1059,18 @@ int test_table(hid_t fid, int write) *------------------------------------------------------------------------- */ TESTING2("reading fields by name"); - + /*------------------------------------------------------------------------- * write and read the "Pressure" field *------------------------------------------------------------------------- */ - if (write) + if (do_write) { if (H5TBmake_table(TITLE,fid,"table10",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill1,compress,0)<0) goto out; - + /* write the pressure field to all the records */ start = 0; nrecords = NRECORDS; @@ -1088,15 +1078,15 @@ int test_table(hid_t fid, int write) sizeof( float ),0,field_sizes_pre,pressure_in)<0) goto out; } - + /* read the "Pressure" field */ start = 0; nrecords = NRECORDS; if ( H5TBread_fields_name(fid,"table10","Pressure",start,nrecords, sizeof(float),0,field_sizes_pre,pressure_out)<0) goto out; - - + + /* Compare the extracted table with the initial values */ for( i = 0; i < NRECORDS; i++ ) { @@ -1104,12 +1094,12 @@ int test_table(hid_t fid, int write) goto out; } } - + /*------------------------------------------------------------------------- * Write and read the "Latitude,Longitude" fields *------------------------------------------------------------------------- */ - if (write) + if (do_write) { /* Write the new longitude and latitude information to all the records */ start = 0; @@ -1118,15 +1108,15 @@ int test_table(hid_t fid, int write) sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 ) goto out; }/*write*/ - + /* Read the "Latitude,Longitude" fields */ start = 0; nrecords = NRECORDS_ADD; if ( H5TBread_fields_name( fid, "table10", "Latitude,Longitude", start, nrecords, sizeof(position_t), field_offset_pos, field_sizes_pos, position_out ) < 0 ) goto out; - - + + /* Compare the extracted table with the initial values */ for( i = 0; i < NRECORDS_ADD; i++ ) { @@ -1134,13 +1124,13 @@ int test_table(hid_t fid, int write) position_out[i].longi != position_in[i].longi ) goto out; } - - + + /*------------------------------------------------------------------------- * Write and read the "Name,Pressure" fields *------------------------------------------------------------------------- */ - if (write) + if (do_write) { /* Write the new name and pressure information to all the records */ start = 0; @@ -1149,7 +1139,7 @@ int test_table(hid_t fid, int write) sizeof( namepressure_t ), field_offset_namepre, field_sizes_namepre, namepre_in ) < 0 ) goto out; }/*write*/ - + /* Read the "Name,Pressure" fields */ start = 0; nrecords = NRECORDS; @@ -1157,24 +1147,24 @@ int test_table(hid_t fid, int write) start, nrecords, sizeof(namepressure_t), field_offset_namepre, field_sizes_namepre, namepre_out ) < 0 ) goto out; - - + + /* Compare the extracted table with the initial values */ for( i = 0; i < NRECORDS; i++ ) { if ( ( strcmp( namepre_out[i].name, namepre_in[i].name ) != 0 ) || namepre_out[i].pressure != namepre_in[i].pressure ) { - goto out; + goto out; } } - + /* reset buffer */ for( i = 0; i < NRECORDS; i++ ) { strcpy( namepre_out[i].name, "\0" ); namepre_out[i].pressure = -1; } - + /*------------------------------------------------------------------------- * read only 3 records of the "Name,Pressure" fields, starting at record 2 *------------------------------------------------------------------------- @@ -1185,22 +1175,22 @@ int test_table(hid_t fid, int write) start, nrecords, sizeof(namepressure_t), field_offset_namepre, field_sizes_namepre, namepre_out ) < 0 ) goto out; - - + + /* Compare the extracted table with the initial values */ for( i = 0; i < 3; i++ ) { int iistart = (int) start; if ( ( strcmp( namepre_out[i].name, namepre_in[iistart+i].name ) != 0 ) || namepre_out[i].pressure != namepre_in[iistart+i].pressure ) { - goto out; + goto out; } } - - - + + + PASSED(); - + /*------------------------------------------------------------------------- * * Functions tested: @@ -1209,16 +1199,16 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - if (write) + if (do_write) { TESTING2("writing fields by index"); - + /* make an empty table */ if (H5TBmake_table(TITLE,fid,"table11",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill,compress,NULL)<0) goto out; - + /* write the pressure field starting at record 2 */ nfields = 1; start = 2; @@ -1226,8 +1216,8 @@ int test_table(hid_t fid, int write) if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pre, start, nrecords, sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 ) goto out; - - + + /* write the new longitude and latitude information starting at record 2 */ nfields = 2; start = 2; @@ -1235,7 +1225,7 @@ int test_table(hid_t fid, int write) if ( H5TBwrite_fields_index(fid, "table11", nfields, field_index_pos, start, nrecords, sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 ) goto out; - + /* read back the all table */ nfields = 5; start = 0; @@ -1243,7 +1233,7 @@ int test_table(hid_t fid, int write) if ( H5TBread_fields_index(fid, "table11", nfields, field_index, start, nrecords, type_size_mem, field_offset, field_size, rbuf ) < 0 ) goto out; - + /* Compare the extracted table with the initial values */ for( i = 0; i < NRECORDS; i++ ) { @@ -1255,11 +1245,11 @@ int test_table(hid_t fid, int write) goto out; } } - + PASSED(); } - - + + /*------------------------------------------------------------------------- * * Functions tested: @@ -1268,22 +1258,22 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - + TESTING2("reading fields by index"); - - if (write) + + if (do_write) { /* make an empty table */ if (H5TBmake_table(TITLE,fid,"table12",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill,compress,NULL)<0) goto out; - + /*------------------------------------------------------------------------- * write and read the "Pressure" field *------------------------------------------------------------------------- */ - + /* write the pressure field to all the records */ nfields = 1; start = 0; @@ -1292,7 +1282,7 @@ int test_table(hid_t fid, int write) sizeof( float ), 0, field_sizes_pre, pressure_in ) < 0 ) goto out; } - + /* read the "Pressure" field */ nfields = 1; start = 0; @@ -1300,7 +1290,7 @@ int test_table(hid_t fid, int write) if ( H5TBread_fields_index(fid, "table12", nfields, field_index_pre, start, nrecords, sizeof(float), 0, field_sizes_pre, pressure_out ) < 0 ) goto out; - + /* compare the extracted table with the initial values */ for( i = 0; i < NRECORDS; i++ ) { @@ -1308,12 +1298,12 @@ int test_table(hid_t fid, int write) goto out; } } - + /*------------------------------------------------------------------------- * write and read the "Latitude,Longitude" fields *------------------------------------------------------------------------- */ - if (write) + if (do_write) { /* write the new longitude and latitude information to all the records */ nfields = 2; @@ -1323,7 +1313,7 @@ int test_table(hid_t fid, int write) sizeof( position_t ), field_offset_pos, field_sizes_pos, position_in ) < 0 ) goto out; } /*write*/ - + /* read the "Latitude,Longitude" fields */ nfields = 2; start = 0; @@ -1331,22 +1321,22 @@ int test_table(hid_t fid, int write) if ( H5TBread_fields_index(fid, "table12", nfields, field_index_pos, start, nrecords, sizeof(position_t), field_offset_pos, field_sizes_pos, position_out ) < 0 ) goto out; - + /* compare the extracted table with the initial values */ for( i = 0; i < NRECORDS_ADD; i++ ) { if ( position_out[i].lati != position_in[i].lati || position_out[i].longi != position_in[i].longi ) { - goto out; + goto out; } } - + /*------------------------------------------------------------------------- * write and read the "Name,Pressure" fields *------------------------------------------------------------------------- */ - - if (write) + + if (do_write) { /* write the new name and pressure information to all the records */ nfields = 2; @@ -1356,7 +1346,7 @@ int test_table(hid_t fid, int write) sizeof( namepressure_t ), field_offset_namepre, field_sizes_namepre, namepre_in ) < 0 ) goto out; } - + /* read the "Name,Pressure" fields */ nfields = 2; start = 0; @@ -1365,28 +1355,28 @@ int test_table(hid_t fid, int write) start, nrecords, sizeof(namepressure_t), field_offset_namepre, field_sizes_namepre, namepre_out ) < 0 ) goto out; - + /* compare the extracted table with the initial values */ for( i = 0; i < NRECORDS; i++ ) { if ( ( strcmp( namepre_out[i].name, namepre_in[i].name ) != 0 ) || namepre_out[i].pressure != namepre_in[i].pressure ) { - goto out; + goto out; } } - + /* reset buffer */ for( i = 0; i < NRECORDS; i++ ) { strcpy( namepre_out[i].name, "\0" ); namepre_out[i].pressure = -1; } - + /*------------------------------------------------------------------------- * read only 3 records of the "Name,Pressure" fields, starting at record 2 *------------------------------------------------------------------------- */ - + /* write the new name and pressure information to all the records */ nfields = 2; start = 2; @@ -1395,20 +1385,20 @@ int test_table(hid_t fid, int write) start, nrecords, sizeof(namepressure_t), field_offset_namepre, field_sizes_namepre, namepre_out ) < 0 ) goto out; - + /* compare the extracted table with the initial values */ for( i = 0; i < 3; i++ ) { int iistart = (int) start; if ( ( strcmp( namepre_out[i].name, wbuf[iistart+i].name ) != 0 ) || namepre_out[i].pressure != wbuf[iistart+i].pressure ) { - goto out; + goto out; } } - + PASSED(); - - + + /*------------------------------------------------------------------------- * * Functions tested: @@ -1417,27 +1407,27 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - - if (write) + + if (do_write) { TESTING2("inserting fields"); - + /* make a table */ if (H5TBmake_table(TITLE,fid,"table13",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill1,compress,wbuf)<0) goto out; - + /* insert the new field at the end of the field list */ position = NFIELDS; if ( H5TBinsert_field( fid, "table13", "New Field", field_type_new, position, fill1_new, buf_new ) < 0 ) goto out; - + /* read the table */ if ( H5TBread_table( fid, "table13", dst_size2, dst_offset2, dst_sizes2, rbuf2 ) < 0 ) goto out; - + /* compare the extracted table with the original array */ for( i = 0; i < NRECORDS; i++ ) { @@ -1447,12 +1437,12 @@ int test_table(hid_t fid, int write) rbuf2[i].pressure != wbuf[i].pressure || rbuf2[i].temperature != wbuf[i].temperature || rbuf2[i].new_field != buf_new[i] ) { - goto out; + goto out; } } PASSED(); } - + /*------------------------------------------------------------------------- * * Functions tested: @@ -1461,24 +1451,24 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - if (write) + if (do_write) { TESTING2("deleting fields"); - + /* make a table */ if (H5TBmake_table(TITLE,fid,"table14",FIELDS,RECORDS,type_size_mem, field_names,field_offset,field_type, chunk_size,fill,compress,wbuf)<0) goto out; - + /* delete the field */ if ( H5TBdelete_field(fid, "table14", "Pressure" ) < 0 ) goto out; - + /* read the table */ if ( H5TBread_table(fid, "table14", dst_size3, dst_offset3, dst_sizes3, rbuf3 ) < 0 ) goto out; - + /* compare the extracted table with the original array */ for( i = 0; i < NRECORDS; i++ ) { @@ -1486,13 +1476,13 @@ int test_table(hid_t fid, int write) rbuf3[i].lati != wbuf[i].lati || rbuf3[i].longi != wbuf[i].longi || rbuf3[i].temperature != wbuf[i].temperature ) { - goto out; + goto out; } } - + PASSED(); } - + /*------------------------------------------------------------------------- * * Functions tested: @@ -1502,19 +1492,19 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - + TESTING2("getting table info"); - + /* get table info */ if ( H5TBget_table_info (fid, "table1", &rfields, &rrecords ) < 0 ) goto out; - + if ( NFIELDS != rfields || rrecords != NRECORDS ) { goto out; } - + PASSED(); - + /*------------------------------------------------------------------------- * * Functions tested: @@ -1523,36 +1513,36 @@ int test_table(hid_t fid, int write) * *------------------------------------------------------------------------- */ - + TESTING2("getting field info"); - + /* alocate */ - names_out = malloc( sizeof(char*) * (size_t)NFIELDS ); + names_out = (char**) malloc( sizeof(char*) * (size_t)NFIELDS ); for ( i = 0; i < NFIELDS; i++) { - names_out[i] = malloc( sizeof(char) * 255 ); + names_out[i] = (char*) malloc( sizeof(char) * 255 ); } - + /* Get field info */ if ( H5TBget_field_info(fid, "table1", names_out, sizes_out, offset_out, &size_out ) < 0 ) goto out; - + for ( i = 0; i < NFIELDS; i++) { if ( (strcmp( field_names[i], names_out[i] ) != 0)) { goto out; } } - + /* release */ for ( i = 0; i < NFIELDS; i++) { free ( names_out[i] ); } free ( names_out ); - + PASSED(); - + /*------------------------------------------------------------------------- * end *------------------------------------------------------------------------- @@ -1565,77 +1555,77 @@ out: /*------------------------------------------------------------------------- - * the main program - *------------------------------------------------------------------------- - */ +* the main program +*------------------------------------------------------------------------- +*/ int main(void) { hid_t fid; /* identifier for the file */ unsigned flags=H5F_ACC_RDONLY; - + /*------------------------------------------------------------------------- * test1: create a file for the write/read test *------------------------------------------------------------------------- */ - + /* create a file using default properties */ fid=H5Fcreate("test_table.h5",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT); - + puts("Testing table with file creation mode (read/write in native architecture):"); - + /* test, do write */ if (test_table(fid,1)<0) goto out; - + /* close */ H5Fclose(fid); - + /*------------------------------------------------------------------------- * test2: open a file written in test1 on a big-endian machine *------------------------------------------------------------------------- */ puts("Testing table with file open mode (read big-endian data):"); - + fid=h5file_open(TEST_FILE_BE,flags); - + /* test, do not write */ if (test_table(fid,0)<0) goto out; - + /* close */ H5Fclose(fid); - + /*------------------------------------------------------------------------- * test3: open a file written in test1 on a little-endian machine *------------------------------------------------------------------------- */ puts("Testing table with file open mode (read little-endian data):"); - + fid=h5file_open(TEST_FILE_LE,flags); - + /* test, do not write */ if (test_table(fid,0)<0) goto out; - + /* close */ H5Fclose(fid); - + /*------------------------------------------------------------------------- * test4: open a file written in test1 on the Cray T3 machine *------------------------------------------------------------------------- */ puts("Testing table with file open mode (read Cray data):"); - + fid=h5file_open(TEST_FILE_CRAY,flags); - + /* test, do not write */ if (test_table(fid,0)<0) goto out; - + /* close */ H5Fclose(fid); - + return 0; out: H5Fclose(fid); |